;:ts=8
	far	code
	far	data
;/*  TT8 specific includes  */
;#include        <TT8.h>                 /* Tattletale Model 8 Definitions */
;#include        <tat332.h>              /* 68332 Tattletale (7,8) Hardware Definitions */
;#include        <sim332.h>              /* 68332 System Integration Module Definitions */
;#include        <qsm332.h>              /* 68332 Queued Serial Module Definitions */
;#include        <dio332.h>              /* 68332 Digital I/O Port Pin Definitions */
;#include        <tt8lib.h>              /* definitions and prototypes for Model 8 library */
;
;#include		<stdio.h>
;#include		<stdlib.h>
;
;#include		"eeprom.h"
;#include		"assert.h"
;
;//  allocate the data
;struct setup_variables setup_data;
;
;
;//  eeprom_write_setup_data (address)
;//
;//  Writes the setup variables to the specified address.  The address
;//  is normally 0.  The option for an alternative is here only for
;//  debugging so we can avoid writing any one section many times.
;//
;int eeprom_write_setup_data (short address)  {
# 25 'eeprom.c' 608744302
| .2
	xdef	_eeprom_write_setup_data
_eeprom_write_setup_data:
	movem.l	d2/d3,-(sp)
	move.w	12(sp),d3
;	int temp;
;	int err;
;	ASSERT (address >= 0);
~ err d2 "i"
~~ address d3 "i"
^^^;	ASSERT ((address + sizeof(setup_data)) < UeeSize());
^;
;	err = UeeWriteBlock (address,
^^;							(uchar*)&setup_data,
;							(short) sizeof(setup_data));
	move.w	#82,-(sp)
	pea	_setup_data
	move.w	d3,-(sp)
	jsr	_UeeWriteBlock
	ext.w	d0
	move.w	d0,d2
;	if (err)  {
^^^	tst.w	d2
	add.w	#8,sp
	beq	.10001
;		printf("Error %d writing to UEEPROM address %d\n", err, address);
^	move.w	d3,-(sp)
	move.w	d2,-(sp)
	pea	.1+0
	jsr	_printf
;		return -1;
^	move.l	#-1,d0
	add.w	#8,sp
.3
	movem.l	(sp)+,d2/d3
	rts
;	}
^;//	printf("Write of UEEPROM successful\n");
;	return 0;
.10001
^^	move.l	#0,d0
	bra	.3
;}
^.2
.1
	dc.b	69,114,114,111,114,32,37,100,32,119,114,105,116,105,110
	dc.b	103,32,116,111,32,85,69,69,80,82,79,77,32,97,100
	dc.b	100,114,101,115,115,32,37,100,10,0
	ds	0
;
;
;
;//  eeprom_read_setup_data (short address)
;//
;//  Reads the setup variables from the specified address.  If the read
;//  fails then this routine will set all variables to a default and
;//  return non-zero to indicate the error
;//
;int eeprom_read_setup_data (short address)  {
# 50
| .5
	xdef	_eeprom_read_setup_data
_eeprom_read_setup_data:
	movem.l	d2/d3,-(sp)
	move.w	12(sp),d3
;	int err;
;	ASSERT (address >= 0);
~ err d2 "i"
~~ address d3 "i"
^^;	ASSERT ((address + sizeof(setup_data)) < UeeSize());
^;
;	err = UeeReadBlock(address,
^^;						(uchar*)&setup_data,
;						(short)sizeof(setup_data));
	move.w	#82,-(sp)
	pea	_setup_data
	move.w	d3,-(sp)
	jsr	_UeeReadBlock
	ext.w	d0
	move.w	d0,d2
;	if (err)  {
^^^	tst.w	d2
	add.w	#8,sp
	beq	.10002
;		printf("Error %d reading from UEEPROM address %d\n", err, address);
^	move.w	d3,-(sp)
	move.w	d2,-(sp)
	pea	.4+0
	jsr	_printf
;		printf ("Setup data set to defaults.\n");
^	pea	.4+42
	jsr	_printf
;		eeprom_set_default_setup_data ();
^	jsr	_eeprom_set_default_setup_data
;		return -1;
^	move.l	#-1,d0
	lea	12(sp),sp
.6
	movem.l	(sp)+,d2/d3
	rts
;	}
^;//	printf("Read of UEEPROM successful\n");
;	return 0;
.10002
^^	move.l	#0,d0
	bra	.6
;}
^.5
.4
	dc.b	69,114,114,111,114,32,37,100,32,114,101,97,100,105,110
	dc.b	103,32,102,114,111,109,32,85,69,69,80,82,79,77,32
	dc.b	97,100,100,114,101,115,115,32,37,100,10,0,83,101,116
	dc.b	117,112,32,100,97,116,97,32,115,101,116,32,116,111,32
	dc.b	100,101,102,97,117,108,116,115,46,10,0
	ds	0
;
;
;
;
;//  eeprom_set_default_setup_data
;//
;//  This routine assigns the default variables any time we want to reset
;//  the logger configuration to a standard default.  This is useful mainly
;//  when we first init the EEPROM with a special program.
;//  
;void eeprom_set_default_setup_data (void)  {
# 77
| .8
	xdef	_eeprom_set_default_setup_data
_eeprom_set_default_setup_data:
	movem.l	d2,-(sp)
;	int n;
;
;	for (n = 0;  n < N_ENG_CHANNELS;  n++)
~ n d2 "i"
^^^	move.l	#0,d2
.10005
;		setup_data.eng_rate[n] = 0;
^	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data,a0
	clr.l	(a0,d0.l)
.10003
	add.w	#1,d2
	cmp.w	#4,d2
	blt	.10005
.10004
;		
;	setup_data.science_rate = 128.571426;
^^	move.l	#$43009249,_setup_data+16
;	for (n = 0;  n < N_SCI_CHANNELS;  n++)  {
^	move.l	#0,d2
.10008
;		setup_data.science_gain[n] = 2.5;
^	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data+20,a0
	move.l	d0,a1
	add.l	a0,a1
	move.l	#$40200000,(a1)
;		setup_data.trigger_level[n] = 3.0;
^	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data+48,a0
	move.l	d0,a1
	add.l	a0,a1
	move.l	#$40400000,(a1)
;	}	
^.10006
	add.w	#1,d2
	cmp.w	#4,d2
	blt	.10008
.10007
;		
;	setup_data.science_chans = 0x0;
^^	clr.w	_setup_data+36
;	setup_data.trigger_chans = 0x0;
^	clr.w	_setup_data+38
;	setup_data.t_STA = 0.5;
^	move.l	#$3f000000,_setup_data+40
;	setup_data.t_LTA = 100.0;
^	move.l	#$42c80000,_setup_data+44
;	setup_data.pre_event_time = 10.0;
^	move.l	#$41200000,_setup_data+68
;	setup_data.post_event_time = 100;
^	move.l	#$42c80000,_setup_data+64
;	setup_data.tick_offset = 0;
^	clr.l	_setup_data+78
;	setup_data.science_n_to_average = 1;
^	move.w	#1,_setup_data+76
;//	setup_data.min_disk_write = 1024;
;}
^^.9
	movem.l	(sp)+,d2
	rts
.8
;
;
;
;
;//  eeprom_verify_setup_data ()
;//
;//  Checks all the setup data for error in self consistency or inconsistency
;//  with the available hardware.  Corrects any error which are found
;//
;short eeprom_verify_setup_data (void)  {
# 108
| .10
	xdef	_eeprom_verify_setup_data
_eeprom_verify_setup_data:
;	if (setup_data.science_rate < 127)
^;		return -1;
	move.l	_setup_data+16,d0
	move.l	#$42fe0000,d1
	jsr	.Fcmp#
	bge	.10009
^	move.l	#-1,d0
.11
	rts
;	if (setup_data.science_rate > 258)
.10009
^;		return -2;
	move.l	_setup_data+16,d0
	move.l	#$43810000,d1
	jsr	.Fcmp#
	ble	.10010
^	move.l	#-2,d0
	bra	.11
;	if (setup_data.science_n_to_average < 1)
.10010
^;		return -3;
	cmp.w	#1,_setup_data+76
	bge	.10011
^	move.l	#-3,d0
	bra	.11
;	if (setup_data.science_n_to_average > 4)
.10011
^;		return -4;
	cmp.w	#4,_setup_data+76
	ble	.10012
^	move.l	#-4,d0
	bra	.11
;	//  need to finish
;	return 0;
.10012
^^	move.l	#0,d0
	bra	.11
;}
^.10
;
;
;
;
;//  eeprom_print_setup_data
;//
;//  This would normally be used only during debugging.
;//
;void eeprom_print_setup_data (void)  {
# 128
| .12
	xdef	_eeprom_print_setup_data
_eeprom_print_setup_data:
	movem.l	d2,-(sp)
;    int n, nchans;
;    
;    printf ("Basic science A/D conversion rate: %.3f per second\n", setup_data.science_rate);
~ n d2 "i"
^^^	move.l	_setup_data+16,d0
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.7+0
	jsr	_printf
;    printf ("Number of samples which are then averaged: %d\n", setup_data.science_n_to_average);
^	move.w	_setup_data+76,-(sp)
	pea	.7+52
	jsr	_printf
;    printf ("Trigger STA length: %.3f seconds;  LTA length: %.2f seconds\n",
^;    						 				setup_data.t_STA, setup_data.t_LTA);
	move.l	_setup_data+44,d0
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	move.l	_setup_data+40,d0
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.7+99
	jsr	_printf
;	printf ("Pre-event length: %.2f seconds;  post-event length %.2f seconds\n",
^^;								setup_data.pre_event_time, setup_data.post_event_time);    						 				
	move.l	_setup_data+64,d0
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	move.l	_setup_data+68,d0
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.7+160
	jsr	_printf
	lea	58(sp),sp
;    printf ("Science Channel  |  State  |  Gain  |  Trigger Level  |\n");
^^	pea	.7+225
	jsr	_printf
;    printf ("-------------------------------------------------------\n");
^	pea	.7+282
	jsr	_printf
;    for (n = 0;  n < N_SCI_CHANNELS;  n++)  {
^	move.l	#0,d2
	add.w	#8,sp
.10015
;    	printf ("       %d         |   ", n);
^	move.w	d2,-(sp)
	pea	.7+339
	jsr	_printf
;		if ((0x01 << n)&setup_data.science_chans)
^;			printf ("On ");
	move.l	#1,d0
	asl.w	d2,d0
	and.w	_setup_data+36,d0
	add.w	#6,sp
	beq	.10016
^	pea	.7+362
	jsr	_printf
;		else
	add.w	#4,sp
	bra	.10017
.10016
;			printf ("Off");
^^	pea	.7+366
	jsr	_printf
	add.w	#4,sp
.10017
;		printf ("   |  %4.1f  |    %7.2f      |\n",
^;					setup_data.science_gain[n], setup_data.trigger_level[n]);
	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data+48,a0
	move.l	d0,a1
	add.l	a0,a1
	move.l	(a1),d0
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data+20,a0
	move.l	d0,a1
	add.l	a0,a1
	move.l	(a1),d0
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.7+370
	jsr	_printf
;	}
^^	lea	20(sp),sp
.10013
	add.w	#1,d2
	cmp.w	#4,d2
	blt	.10015
.10014
;    printf ("-------------------------------------------------------\n");
^	pea	.7+402
	jsr	_printf
;	
;	printf ("\nEngineering Channel  |  Time Between Samples  |\n");
^^	pea	.7+459
	jsr	_printf
;	printf ("-----------------------------------------------\n");
^	pea	.7+509
	jsr	_printf
;	for (n = 0;  n < N_ENG_CHANNELS;  n++)  {
^	move.l	#0,d2
	lea	12(sp),sp
.10020
;		printf ("       %d             |       ", n);
^	move.w	d2,-(sp)
	pea	.7+558
	jsr	_printf
;    	if (setup_data.eng_rate[n] == 0)
^;    		printf ("  Off");
	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data,a0
	tst.l	(a0,d0.l)
	add.w	#6,sp
	bne	.10021
^	pea	.7+589
	jsr	_printf
;    	else
	add.w	#4,sp
	bra	.10022
.10021
;    		printf ("%5ld", setup_data.eng_rate[n]);
^^	move.w	d2,d0
	ext.l	d0
	asl.l	#2,d0
	lea	_setup_data,a0
	move.l	(a0,d0.l),-(sp)
	pea	.7+595
	jsr	_printf
	add.w	#8,sp
.10022
;    	printf ("            |\n");
^	pea	.7+600
	jsr	_printf
;    }
^	add.w	#4,sp
.10018
	add.w	#1,d2
	cmp.w	#4,d2
	blt	.10020
.10019
;	printf ("-----------------------------------------------\n");
^	pea	.7+615
	jsr	_printf
;	return;
^	add.w	#4,sp
.13
	movem.l	(sp)+,d2
	rts
;}		    							
^.12
.7
	dc.b	66,97,115,105,99,32,115,99,105,101,110,99,101,32,65
	dc.b	47,68,32,99,111,110,118,101,114,115,105,111,110,32,114
	dc.b	97,116,101,58,32,37,46,51,102,32,112,101,114,32,115
	dc.b	101,99,111,110,100,10,0,78,117,109,98,101,114,32,111
	dc.b	102,32,115,97,109,112,108,101,115,32,119,104,105,99,104
	dc.b	32,97,114,101,32,116,104,101,110,32,97,118,101,114,97
	dc.b	103,101,100,58,32,37,100,10,0,84,114,105,103,103,101
	dc.b	114,32,83,84,65,32,108,101,110,103,116,104,58,32,37
	dc.b	46,51,102,32,115,101,99,111,110,100,115,59,32,32,76
	dc.b	84,65,32,108,101,110,103,116,104,58,32,37,46,50,102
	dc.b	32,115,101,99,111,110,100,115,10,0,80,114,101,45,101
	dc.b	118,101,110,116,32,108,101,110,103,116,104,58,32,37,46
	dc.b	50,102,32,115,101,99,111,110,100,115,59,32,32,112,111
	dc.b	115,116,45,101,118,101,110,116,32,108,101,110,103,116,104
	dc.b	32,37,46,50,102,32,115,101,99,111,110,100,115,10,0
	dc.b	83,99,105,101,110,99,101,32,67,104,97,110,110,101,108
	dc.b	32,32,124,32,32,83,116,97,116,101,32,32,124,32,32
	dc.b	71,97,105,110,32,32,124,32,32,84,114,105,103,103,101
	dc.b	114,32,76,101,118,101,108,32,32,124,10,0,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,10,0,32,32,32,32,32,32
	dc.b	32,37,100,32,32,32,32,32,32,32,32,32,124,32,32
	dc.b	32,0,79,110,32,0,79,102,102,0,32,32,32,124,32
	dc.b	32,37,52,46,49,102,32,32,124,32,32,32,32,37,55
	dc.b	46,50,102,32,32,32,32,32,32,124,10,0,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,10,0,10,69,110,103,105,110
	dc.b	101,101,114,105,110,103,32,67,104,97,110,110,101,108,32
	dc.b	32,124,32,32,84,105,109,101,32,66,101,116,119,101,101
	dc.b	110,32,83,97,109,112,108,101,115,32,32,124,10,0,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,10,0,32,32,32,32,32,32,32,37,100,32,32,32
	dc.b	32,32,32,32,32,32,32,32,32,32,124,32,32,32,32
	dc.b	32,32,32,0,32,32,79,102,102,0,37,53,108,100,0
	dc.b	32,32,32,32,32,32,32,32,32,32,32,32,124,10,0
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,45,45,45,45,45,45,45,45,45,45,45,45,45
	dc.b	45,45,10,0
	ds	0
;
# 162
|
~ _eeprom_verify_setup_data * "(i"
~ _eeprom_print_setup_data * "(v"
~ _eeprom_set_default_setup_data * "(v"
~ _eeprom_write_setup_data * "(i"
~ _eeprom_read_setup_data * "(i"
~ 'setup_variables'
~ 1 13 82
~ eng_rate 0 "[4l"
~ science_rate 16 "f"
~ science_gain 20 "[4f"
~ science_chans 36 "i"
~ trigger_chans 38 "i"
~ t_STA 40 "f"
~ t_LTA 44 "f"
~ trigger_level 48 "[4f"
~ post_event_time 64 "f"
~ pre_event_time 68 "f"
~ min_disk_write 72 "l"
~ science_n_to_average 76 "i"
~ tick_offset 78 "l"
~ _setup_data * ":" 1
~ ''
~ 2 2 8
~ quot 0 "l"
~ rem 4 "l"
~ ''
~ 3 2 4
~ quot 0 "i"
~ rem 2 "i"
~ ldiv_t ":" 2
~ div_t ":" 3
~ '__stdio'
~ 4 8 22
~ _bp 0 "#C"
~ _bend 4 "#C"
~ _buff 8 "#C"
~ _flags 12 "I"
~ _unit 14 "c"
~ _bytbuf 15 "C"
~ _buflen 16 "L"
~ _tmpnum 20 "I"
~ _printf * "(i"
~ FILE ":" 4
~ fpos_t "l"
~ va_list "#c"
~ ''
~ 5 13 46
~ libVersion 0 "l"
~ ramBase 4 "#c"
~ ramSize 8 "l"
~ ramWaits 12 "i"
~ flashBase 14 "#c"
~ flashSize 18 "l"
~ flashWaits 22 "i"
~ heapBot 24 "#v"
~ heapTop 28 "#v"
~ heapCur 32 "#v"
~ statusReg 36 "I"
~ vectorBase 38 "#v"
~ stackPtr 42 "#v"
~ infoAction "c"
~ TT8info ":" 5
~ _UeeWriteBlock * "(c"
~ _UeeReadBlock * "(c"
~ UeeErr "c"
~ ''
~ 6 2 8
~ secs 0 "L"
~ ticks 4 "l"
~ time_tt ":" 6
~ XmdmErr "c"
~ FlashErr "c"
~ ''
~ 7 4 24
~ eSR 0 "I"
~ ePC 2 "L"
~ vectofs 6 "I"
~ states 8 "[8I"
~ ''
~ 8 4 20
~ preamble 0 "[4I"
~ jump 8 "I"
~ target 10 "L"
~ postamble 14 "[3I"
~ ExcCFramePtr "#:" 8
~ ExcCFrame ":" 8
~ ExcStackFrame ":" 7
~ 'tm'
~ 9 10 20
~ tm_sec 0 "i"
~ tm_min 2 "i"
~ tm_hour 4 "i"
~ tm_mday 6 "i"
~ tm_mon 8 "i"
~ tm_year 10 "i"
~ tm_wday 12 "i"
~ tm_yday 14 "i"
~ tm_isdst 16 "i"
~ tm_hsec 18 "i"
~ time_t "L"
~ clock_t "L"
~ wchar_t "c"
~ ptrdiff_t "l"
~ size_t "L"
~ bool "c"
~ vfptr "#(v"
~ ptr "#c"
~ ulpv "#L"
~ ulong "L"
~ uspv "#I"
~ unsint "I"
~ ushort "I"
~ ucpv "#C"
~ uchar "C"
	xref	_printf
	xref	_UeeWriteBlock
	xref	_UeeReadBlock
	xref	.begin
	dseg
	global	_setup_data,82
	end
