;:ts=8
	far	code
	far	data
;#include	"camtt.h"
;
;#define		MOTOR_PERIOD		5	// Half the period in ms
;#define		CW					0
;#define		CCW					1
;#define		PWR_CAL				710
;#define		STRB1_CAL			32760L
;#define		STRB2_CAL			32760L
;#define		STRB3_CAL			32760L
;#define		STRB4_CAL			32760L
;
;enum {CHAN_CTRL, LINK_CTRL, MAX_COUNT, TRANS_COUNT, FINAL_TRANS_TIME, LAST_TRANS_TIME};
;
;/* Host Service Request */
;#define		Initialize		1
;
;/* Host Sequence */
;#define         SingleNoLinks		0
;#define		ContinuousNoLinks	1
;#define         SingleLinks		2
;#define		ContinuousLinks		3
;
;/* PAC Pin Action Control (input) */
;#define         NoDetect	   	0x00
;#define         DetRising               0x04
;#define         DetFalling              0x08
;#define         DetEither               0x0c
;#define         NoChangePAC             0x10
;
;/* TBS Time Base/Directionality Control */
;#define         InputChan               0x00
;#define         CapTCR1			0x00
;#define         CapTCR2			0x40
;
;/********************* Function Prototypes *******************/
;
;void motor_step(int steps, int dir);
;void	SetupTPUCount(short chan);
;long	GetTPUCount(short chan);
;
;
;/*********************** Global Variables *********************/
;
;
;
;/*********************************************************************************
;	main
;*******************************************************************************/
;
;void main(void)
;{
# 50 'camtt10.c' 752583914
^| .2
	xdef	_main
_main:
	link	a6,#.3
;	char charbuf[10];
;	char adbuf[20];
;
;	InitTT8(NO_WATCHDOG, TT8_TPU);   /* setup Model 8 for running C programs */
~ charbuf -10 "[10c"
^^^^	move.w	#-1,-(sp)
	move.w	#-1,-(sp)
	jsr	_InitTT8
;	TPUGetPin(0);					// Photo Mult. 1
^	clr.w	-(sp)
	jsr	_TPUGetPin
;	TPUGetPin(1);					// Photo Mult. 2
^	move.w	#1,-(sp)
	jsr	_TPUGetPin
;	TPUGetPin(2);				// Hall Sig.
^	move.w	#2,-(sp)
	jsr	_TPUGetPin
;  	TPUSetPin(3, 0);			// Mot Phase 1
^	clr.w	-(sp)
	move.w	#3,-(sp)
	jsr	_TPUSetPin
;  	TPUSetPin(4, 0);			// Mot Phase 2
^	clr.w	-(sp)
	move.w	#4,-(sp)
	jsr	_TPUSetPin
;  	TPUSetPin(5, 0);			// Strobe 4
^	clr.w	-(sp)
	move.w	#5,-(sp)
	jsr	_TPUSetPin
;  	TPUSetPin(6, 0);			// Strobe 3
^	clr.w	-(sp)
	move.w	#6,-(sp)
	jsr	_TPUSetPin
;  	TPUSetPin(7, 0);			// Strobe 2
^	clr.w	-(sp)
	move.w	#7,-(sp)
	jsr	_TPUSetPin
;  	TPUSetPin(8, 0);			// Strobe 1
^	clr.w	-(sp)
	move.w	#8,-(sp)
	jsr	_TPUSetPin
;
;  	PConfOutp(D,3);				// Motor Enable
^^;			PConfOutpD3
	dc.w	$8b8
	dc.w	$3
	dc.w	$fc16
	dc.w	$8f8
	dc.w	$3
	dc.w	$fc17
;  	PClear(D,3);
^;			PClearD3
	dc.w	$8b8
	dc.w	$3
	dc.w	$fc15
;  	PConfOutp(D,4);				// Turn CPU off
^;			PConfOutpD4
	dc.w	$8b8
	dc.w	$4
	dc.w	$fc16
	dc.w	$8f8
	dc.w	$4
	dc.w	$fc17
;  	PSet(D,4);
^;			PSetD4
	dc.w	$8f8
	dc.w	$4
	dc.w	$fc15
;  	PConfOutp(D,5);				// Turn Camera off
^;			PConfOutpD5
	dc.w	$8b8
	dc.w	$5
	dc.w	$fc16
	dc.w	$8f8
	dc.w	$5
	dc.w	$fc17
;  	PSet(D,5);
^;			PSetD5
	dc.w	$8f8
	dc.w	$5
	dc.w	$fc15
;
;//*************** Setup TPU Counters for Photomults **************
;
;
;	SetupTPUCount(1);
^^^^^	move.w	#1,-(sp)
	jsr	_SetupTPUCount
;
;// ****************** Main Program Loop ***********************
;
;	PutStr("\nH2O Camera Tattletale Program v1.0\n\n\n");
^^^^	pea	.1+0
	jsr	_PutStr
;
;  	while(1)		// Wait for commands
^^	lea	40(sp),sp
.10001
;  	{
^;
;		PutStr("\n\nEnter command: ");
^^	pea	.1+39
	jsr	_PutStr
;		gets(charbuf);
^	pea	-10(a6)
	jsr	_gets
;
;		if(!strcmp(charbuf, "mot"))
^^;		{
	lea	-10(a6),a0
	lea	.1+57,a1
.4	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.5
	tst.b	d0
	bne.s	.4
.5	sub.b	-(a1),d0
	ext.w	d0
	add.w	#8,sp
	bne	.10003
^;			motor_step(500, CW);
^	clr.w	-(sp)
	move.w	#500,-(sp)
	jsr	_motor_step
;			motor_step(500, CCW);
^	move.w	#1,-(sp)
	move.w	#500,-(sp)
	jsr	_motor_step
;		}
^;
;		else if(!strcmp(charbuf, "reset"))			ResetToMon();
	add.w	#8,sp
	bra	.10004
.10003
^^	lea	-10(a6),a0
	lea	.1+61,a1
.6	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.7
	tst.b	d0
	bne.s	.6
.7	sub.b	-(a1),d0
	ext.w	d0
	bne	.10005
;			ResetToMon
	dc.w	$13fc
	dc.w	$c1
	dc.w	$e0
	dc.w	$0
	dc.w	$4e70
;
;		else if(!strcmp(charbuf, "strb1on"))		TPUSetPin(8,1);
	bra	.10006
.10005
^^	lea	-10(a6),a0
	lea	.1+67,a1
.8	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.9
	tst.b	d0
	bne.s	.8
.9	sub.b	-(a1),d0
	ext.w	d0
	bne	.10007
	move.w	#1,-(sp)
	move.w	#8,-(sp)
	jsr	_TPUSetPin
;		else if(!strcmp(charbuf, "strb2on"))		TPUSetPin(7,1);
	add.w	#4,sp
	bra	.10008
.10007
^	lea	-10(a6),a0
	lea	.1+75,a1
.10	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.11
	tst.b	d0
	bne.s	.10
.11	sub.b	-(a1),d0
	ext.w	d0
	bne	.10009
	move.w	#1,-(sp)
	move.w	#7,-(sp)
	jsr	_TPUSetPin
;		else if(!strcmp(charbuf, "strb3on"))		TPUSetPin(6,1);
	add.w	#4,sp
	bra	.10010
.10009
^	lea	-10(a6),a0
	lea	.1+83,a1
.12	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.13
	tst.b	d0
	bne.s	.12
.13	sub.b	-(a1),d0
	ext.w	d0
	bne	.10011
	move.w	#1,-(sp)
	move.w	#6,-(sp)
	jsr	_TPUSetPin
;		else if(!strcmp(charbuf, "strb4on"))		TPUSetPin(5,1);
	add.w	#4,sp
	bra	.10012
.10011
^	lea	-10(a6),a0
	lea	.1+91,a1
.14	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.15
	tst.b	d0
	bne.s	.14
.15	sub.b	-(a1),d0
	ext.w	d0
	bne	.10013
	move.w	#1,-(sp)
	move.w	#5,-(sp)
	jsr	_TPUSetPin
;		else if(!strcmp(charbuf, "strb1off"))		TPUSetPin(8,0);
	add.w	#4,sp
	bra	.10014
.10013
^	lea	-10(a6),a0
	lea	.1+99,a1
.16	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.17
	tst.b	d0
	bne.s	.16
.17	sub.b	-(a1),d0
	ext.w	d0
	bne	.10015
	clr.w	-(sp)
	move.w	#8,-(sp)
	jsr	_TPUSetPin
;		else if(!strcmp(charbuf, "strb2off"))		TPUSetPin(7,0);
	add.w	#4,sp
	bra	.10016
.10015
^	lea	-10(a6),a0
	lea	.1+108,a1
.18	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.19
	tst.b	d0
	bne.s	.18
.19	sub.b	-(a1),d0
	ext.w	d0
	bne	.10017
	clr.w	-(sp)
	move.w	#7,-(sp)
	jsr	_TPUSetPin
;		else if(!strcmp(charbuf, "strb3off"))		TPUSetPin(6,0);
	add.w	#4,sp
	bra	.10018
.10017
^	lea	-10(a6),a0
	lea	.1+117,a1
.20	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.21
	tst.b	d0
	bne.s	.20
.21	sub.b	-(a1),d0
	ext.w	d0
	bne	.10019
	clr.w	-(sp)
	move.w	#6,-(sp)
	jsr	_TPUSetPin
;		else if(!strcmp(charbuf, "strb4off"))		TPUSetPin(5,0);
	add.w	#4,sp
	bra	.10020
.10019
^	lea	-10(a6),a0
	lea	.1+126,a1
.22	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.23
	tst.b	d0
	bne.s	.22
.23	sub.b	-(a1),d0
	ext.w	d0
	bne	.10021
	clr.w	-(sp)
	move.w	#5,-(sp)
	jsr	_TPUSetPin
;
;		else if(!strcmp(charbuf, "cpuon"))			PClear(D,4);
	add.w	#4,sp
	bra	.10022
.10021
^^	lea	-10(a6),a0
	lea	.1+135,a1
.24	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.25
	tst.b	d0
	bne.s	.24
.25	sub.b	-(a1),d0
	ext.w	d0
	bne	.10023
;			PClearD4
	dc.w	$8b8
	dc.w	$4
	dc.w	$fc15
;		else if(!strcmp(charbuf, "cpuoff"))			PSet(D,4);
	bra	.10024
.10023
^	lea	-10(a6),a0
	lea	.1+141,a1
.26	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.27
	tst.b	d0
	bne.s	.26
.27	sub.b	-(a1),d0
	ext.w	d0
	bne	.10025
;			PSetD4
	dc.w	$8f8
	dc.w	$4
	dc.w	$fc15
;		else if(!strcmp(charbuf, "camon"))			PClear(D,5);
	bra	.10026
.10025
^	lea	-10(a6),a0
	lea	.1+148,a1
.28	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.29
	tst.b	d0
	bne.s	.28
.29	sub.b	-(a1),d0
	ext.w	d0
	bne	.10027
;			PClearD5
	dc.w	$8b8
	dc.w	$5
	dc.w	$fc15
;		else if(!strcmp(charbuf, "camoff"))			PSet(D,5);
	bra	.10028
.10027
^	lea	-10(a6),a0
	lea	.1+154,a1
.30	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.31
	tst.b	d0
	bne.s	.30
.31	sub.b	-(a1),d0
	ext.w	d0
	bne	.10029
;			PSetD5
	dc.w	$8f8
	dc.w	$5
	dc.w	$fc15
;
;		else if(!strcmp(charbuf, "pwr"))
	bra	.10030
.10029
^^;			printf("\nPower = %6.2f V\n", (float)AtoDReadWord(0)/PWR_CAL);
	lea	-10(a6),a0
	lea	.1+161,a1
.32	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.33
	tst.b	d0
	bne.s	.32
.33	sub.b	-(a1),d0
	ext.w	d0
	bne	.10031
^	clr.w	-(sp)
	jsr	_AtoDReadWord
	add.w	#2,sp
	ext.l	d0
	jsr	.Fflt#
	move.l	#$44318000,d1
	jsr	.Fdiv#
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.1+165
	jsr	_printf
;
;		else if(!strcmp(charbuf, "strb1volt"))
	lea	12(sp),sp
	bra	.10032
.10031
^^;			printf("\nStrobe 1 Volt = %7.2f V\n", (float)AtoDReadWord(1)/STRB1_CAL);
	lea	-10(a6),a0
	lea	.1+183,a1
.34	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.35
	tst.b	d0
	bne.s	.34
.35	sub.b	-(a1),d0
	ext.w	d0
	bne	.10033
^	move.w	#1,-(sp)
	jsr	_AtoDReadWord
	add.w	#2,sp
	ext.l	d0
	jsr	.Fflt#
	move.l	#$46fff000,d1
	jsr	.Fdiv#
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.1+193
	jsr	_printf
;
;		else if(!strcmp(charbuf, "strb2volt"))
	lea	12(sp),sp
	bra	.10034
.10033
^^;			printf("\nStrobe 2 Volt = %7.2f V\n", (float)AtoDReadWord(2)/STRB2_CAL);
	lea	-10(a6),a0
	lea	.1+219,a1
.36	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.37
	tst.b	d0
	bne.s	.36
.37	sub.b	-(a1),d0
	ext.w	d0
	bne	.10035
^	move.w	#2,-(sp)
	jsr	_AtoDReadWord
	add.w	#2,sp
	ext.l	d0
	jsr	.Fflt#
	move.l	#$46fff000,d1
	jsr	.Fdiv#
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.1+229
	jsr	_printf
;
;		else if(!strcmp(charbuf, "strb3volt"))
	lea	12(sp),sp
	bra	.10036
.10035
^^;			printf("\nStrobe 3 Volt = %7.2f V\n", (float)AtoDReadWord(3)/STRB3_CAL);
	lea	-10(a6),a0
	lea	.1+255,a1
.38	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.39
	tst.b	d0
	bne.s	.38
.39	sub.b	-(a1),d0
	ext.w	d0
	bne	.10037
^	move.w	#3,-(sp)
	jsr	_AtoDReadWord
	add.w	#2,sp
	ext.l	d0
	jsr	.Fflt#
	move.l	#$46fff000,d1
	jsr	.Fdiv#
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.1+265
	jsr	_printf
;
;		else if(!strcmp(charbuf, "strb4volt"))
	lea	12(sp),sp
	bra	.10038
.10037
^^;			printf("\nStrobe 4 Volt = %7.2f V\n", (float)AtoDReadWord(4)/STRB4_CAL);
	lea	-10(a6),a0
	lea	.1+291,a1
.40	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.41
	tst.b	d0
	bne.s	.40
.41	sub.b	-(a1),d0
	ext.w	d0
	bne	.10039
^	move.w	#4,-(sp)
	jsr	_AtoDReadWord
	add.w	#2,sp
	ext.l	d0
	jsr	.Fflt#
	move.l	#$46fff000,d1
	jsr	.Fdiv#
	jsr	.ftod#
	move.l	d1,-(sp)
	move.l	d0,-(sp)
	pea	.1+301
	jsr	_printf
;
;		else if(!strcmp(charbuf, "hallsig"))
	lea	12(sp),sp
	bra	.10040
.10039
^^;			printf("\nHall Sig. = %d\n", TPUGetPin(2));
	lea	-10(a6),a0
	lea	.1+327,a1
.42	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.43
	tst.b	d0
	bne.s	.42
.43	sub.b	-(a1),d0
	ext.w	d0
	bne	.10041
^	move.w	#2,-(sp)
	jsr	_TPUGetPin
	add.w	#2,sp
	move.w	d0,-(sp)
	pea	.1+335
	jsr	_printf
;
;		else if(!strcmp(charbuf, "pm1"))
	add.w	#6,sp
	bra	.10042
.10041
^^;		{
	lea	-10(a6),a0
	lea	.1+352,a1
.44	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.45
	tst.b	d0
	bne.s	.44
.45	sub.b	-(a1),d0
	ext.w	d0
	bne	.10043
^;			SetupTPUCount(0);
^	clr.w	-(sp)
	jsr	_SetupTPUCount
;			DelayMilliSecs(1000L);
^	pea	1000
	jsr	_DelayMilliSecs
;			printf("\nPM1 count = %ld\n", GetTPUCount(0));
^	clr.w	-(sp)
	jsr	_GetTPUCount
	add.w	#2,sp
	move.l	d0,-(sp)
	pea	.1+356
	jsr	_printf
;		}
^;
;		else if(!strcmp(charbuf, "pm2"))
	lea	14(sp),sp
	bra	.10044
.10043
^^;		{
	lea	-10(a6),a0
	lea	.1+374,a1
.46	move.b	(a0)+,d0
	cmp.b	(a1)+,d0
	bne.s	.47
	tst.b	d0
	bne.s	.46
.47	sub.b	-(a1),d0
	ext.w	d0
	bne	.10045
^;			SetupTPUCount(1);
^	move.w	#1,-(sp)
	jsr	_SetupTPUCount
;			DelayMilliSecs(1000L);
^	pea	1000
	jsr	_DelayMilliSecs
;			printf("\nPM2 count = %ld\n", GetTPUCount(1));
^	move.w	#1,-(sp)
	jsr	_GetTPUCount
	add.w	#2,sp
	move.l	d0,-(sp)
	pea	.1+378
	jsr	_printf
;		}
^;
;
;		else	PutStr("\nWhat?");
	lea	14(sp),sp
	bra	.10046
.10045
^^^	pea	.1+396
	jsr	_PutStr
	add.w	#4,sp
.10046
.10044
.10042
.10040
.10038
.10036
.10034
.10032
.10030
.10028
.10026
.10024
.10022
.10020
.10018
.10016
.10014
.10012
.10010
.10008
.10006
.10004
;
;    }
^^	bra	.10001
;
;}	/* main() */
^^.2
.3	equ	-10
.1
	dc.b	10,72,50,79,32,67,97,109,101,114,97,32,84,97,116
	dc.b	116,108,101,116,97,108,101,32,80,114,111,103,114,97,109
	dc.b	32,118,49,46,48,10,10,10,0,10,10,69,110,116,101
	dc.b	114,32,99,111,109,109,97,110,100,58,32,0,109,111,116
	dc.b	0,114,101,115,101,116,0,115,116,114,98,49,111,110,0
	dc.b	115,116,114,98,50,111,110,0,115,116,114,98,51,111,110
	dc.b	0,115,116,114,98,52,111,110,0,115,116,114,98,49,111
	dc.b	102,102,0,115,116,114,98,50,111,102,102,0,115,116,114
	dc.b	98,51,111,102,102,0,115,116,114,98,52,111,102,102,0
	dc.b	99,112,117,111,110,0,99,112,117,111,102,102,0,99,97
	dc.b	109,111,110,0,99,97,109,111,102,102,0,112,119,114,0
	dc.b	10,80,111,119,101,114,32,61,32,37,54,46,50,102,32
	dc.b	86,10,0,115,116,114,98,49,118,111,108,116,0,10,83
	dc.b	116,114,111,98,101,32,49,32,86,111,108,116,32,61,32
	dc.b	37,55,46,50,102,32,86,10,0,115,116,114,98,50,118
	dc.b	111,108,116,0,10,83,116,114,111,98,101,32,50,32,86
	dc.b	111,108,116,32,61,32,37,55,46,50,102,32,86,10,0
	dc.b	115,116,114,98,51,118,111,108,116,0,10,83,116,114,111
	dc.b	98,101,32,51,32,86,111,108,116,32,61,32,37,55,46
	dc.b	50,102,32,86,10,0,115,116,114,98,52,118,111,108,116
	dc.b	0,10,83,116,114,111,98,101,32,52,32,86,111,108,116
	dc.b	32,61,32,37,55,46,50,102,32,86,10,0,104,97,108
	dc.b	108,115,105,103,0,10,72,97,108,108,32,83,105,103,46
	dc.b	32,61,32,37,100,10,0,112,109,49,0,10,80,77,49
	dc.b	32,99,111,117,110,116,32,61,32,37,108,100,10,0,112
	dc.b	109,50,0,10,80,77,50,32,99,111,117,110,116,32,61
	dc.b	32,37,108,100,10,0,10,87,104,97,116,63,0
	ds	0
;
;
;/***************************************************/
;
;void motor_step(int steps, int dir)
;{
# 152
^| .49
	xdef	_motor_step
_motor_step:
	movem.l	d2/d3,-(sp)
	move.w	12(sp),d3
;	int step;
;
;	if(dir)		// CW rotation
~ step d2 "i"
~~ steps d3 "i"
~~ dir 10 "i"
^^^;	{
	tst.w	14(sp)
	beq	.10047
^;		TPUSetPin(3, 0);	// Clear PH1
^	clr.w	-(sp)
	move.w	#3,-(sp)
	jsr	_TPUSetPin
;		TPUSetPin(4, 0);	// Clear PH2
^	clr.w	-(sp)
	move.w	#4,-(sp)
	jsr	_TPUSetPin
;		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;		PSet(D,3);			// Turn motor driver on
^;			PSetD3
	dc.w	$8f8
	dc.w	$3
	dc.w	$fc15
;		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;
;		for(step=0; step<steps; step++)
^^	move.l	#0,d2
	lea	16(sp),sp
	bra	.10051
.10050
;		{
^;  			DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;			TPUSetPin(4, 1);	// Set PH2
^	move.w	#1,-(sp)
	move.w	#4,-(sp)
	jsr	_TPUSetPin
;	 		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;	  		TPUSetPin(3, 1);	// Set PH1
^	move.w	#1,-(sp)
	move.w	#3,-(sp)
	jsr	_TPUSetPin
;	  		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;	  		TPUSetPin(4, 0);	// Clear PH2
^	clr.w	-(sp)
	move.w	#4,-(sp)
	jsr	_TPUSetPin
;	  		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;	  		TPUSetPin(3, 0);	// Clear PH1
^	clr.w	-(sp)
	move.w	#3,-(sp)
	jsr	_TPUSetPin
;		}
^	lea	32(sp),sp
.10048
	add.w	#1,d2
.10051
	cmp.w	d3,d2
	blt	.10050
.10049
;		PClear(D,3);			// Turn motor driver on
^;			PClearD3
	dc.w	$8b8
	dc.w	$3
	dc.w	$fc15
;	}
^;
;	else		// CCW rotation
	bra	.10052
.10047
;	{
^^^;		TPUSetPin(3, 0);	// Clear PH1
^	clr.w	-(sp)
	move.w	#3,-(sp)
	jsr	_TPUSetPin
; 		TPUSetPin(4, 0);	// Clear PH2
^	clr.w	-(sp)
	move.w	#4,-(sp)
	jsr	_TPUSetPin
;		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;		PSet(D,3);			// Turn motor driver on
^;			PSetD3
	dc.w	$8f8
	dc.w	$3
	dc.w	$fc15
;		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;
;		for(step=0; step<steps; step++)
^^	move.l	#0,d2
	lea	16(sp),sp
	bra	.10056
.10055
;		{
^;	  		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;			TPUSetPin(3, 1);	// Set PH1
^	move.w	#1,-(sp)
	move.w	#3,-(sp)
	jsr	_TPUSetPin
;	 		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;	  		TPUSetPin(4, 1);	// Set PH2
^	move.w	#1,-(sp)
	move.w	#4,-(sp)
	jsr	_TPUSetPin
;	  		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;	  		TPUSetPin(3, 0);	// Clear PH1
^	clr.w	-(sp)
	move.w	#3,-(sp)
	jsr	_TPUSetPin
;	  		DelayMilliSecs(MOTOR_PERIOD);
^	pea	5
	jsr	_DelayMilliSecs
;	  		TPUSetPin(4, 0);	// Clear PH2
^	clr.w	-(sp)
	move.w	#4,-(sp)
	jsr	_TPUSetPin
;		}
^	lea	32(sp),sp
.10053
	add.w	#1,d2
.10056
	cmp.w	d3,d2
	blt	.10055
.10054
;		PClear(D,3);		// Turn motor driver on
^;			PClearD3
	dc.w	$8b8
	dc.w	$3
	dc.w	$fc15
;	}
^.10052
;
;}
^^.50
	movem.l	(sp)+,d2/d3
	rts
.49
;
;
;//**************************************************************************
;// Setup channel for count input
;//**************************************************************************
;
;void	SetupTPUCount(short chan){
# 207
| .51
	xdef	_SetupTPUCount
_SetupTPUCount:
	movem.l	d2,-(sp)
	move.w	8(sp),d2
;
;	// SETUP CHANNEL
;	TPUGetPin(chan);		//Set pin as input
~~ chan d2 "i"
^^^	move.w	d2,-(sp)
	jsr	_TPUGetPin
;
;	CHANPRIOR(chan,Disabled);
^^	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-482,a0
	sub.l	d0,a0
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	swap	d0
	add.w	d0,d0
	move.l	#3,d1
	asl.w	d0,d1
	not.w	d1
	move.w	(a0),d0
	and.w	d1,d0
	move.w	d2,d1
	ext.l	d1
	divs.w	#8,d1
	swap	d1
	add.w	d1,d1
	add.w	#2,sp
	move.w	d0,-(sp)
	move.l	#0,d0
	asl.w	d1,d0
	move.w	(sp)+,d1
	or.w	d0,d1
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-482,a0
	sub.l	d0,a0
	move.w	d1,(a0)
;	*CISR ^= (1 << chan );		// Clear any pending interrupt
^	move.l	#1,d0
	asl.w	d2,d0
	move.w	-480,d1
	eor.w	d1,d0
	move.w	d0,-480
;	*CIER &= ~(1 << chan);		// disable interrupt
^	move.l	#1,d0
	asl.w	d2,d0
	not.w	d0
	and.w	d0,-502
;	FUNSEL(chan,ITC);		// select input capture function
^	move.w	d2,d0
	ext.l	d0
	divs.w	#4,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-494,a0
	sub.l	d0,a0
	move.w	d2,d0
	ext.l	d0
	divs.w	#4,d0
	swap	d0
	asl.w	#2,d0
	move.l	#15,d1
	asl.w	d0,d1
	not.w	d1
	move.w	(a0),d0
	and.w	d1,d0
	move.w	d2,d1
	ext.l	d1
	divs.w	#4,d1
	swap	d1
	asl.w	#2,d1
	move.w	d0,-(sp)
	move.l	#10,d0
	asl.w	d1,d0
	move.w	(sp)+,d1
	or.w	d0,d1
	move.w	d2,d0
	ext.l	d0
	divs.w	#4,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-494,a0
	sub.l	d0,a0
	move.w	d1,(a0)
;
;	PRAM[chan][CHAN_CTRL]	= DetRising;	// what to count (edges)
^^	move.w	d2,d0
	ext.l	d0
	asl.l	#4,d0
	move.l	#-256,a0
	move.w	#4,(a0,d0.l)
;	PRAM[chan][LINK_CTRL]	= 0x0E;		// no links
^	move.w	d2,d0
	ext.l	d0
	asl.l	#4,d0
	move.l	#-256,a0
	move.w	#14,2(a0,d0.l)
;	PRAM[chan][MAX_COUNT]	= 0xFFFF;	// maximum count
^	move.w	d2,d0
	ext.l	d0
	asl.l	#4,d0
	move.l	#-256,a0
	move.w	#65535,4(a0,d0.l)
;
;	HOSTSEQ(chan,ContinuousNoLinks); // continuous count, no links
^^	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-490,a0
	sub.l	d0,a0
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	swap	d0
	add.w	d0,d0
	move.l	#3,d1
	asl.w	d0,d1
	not.w	d1
	move.w	(a0),d0
	and.w	d1,d0
	move.w	d2,d1
	ext.l	d1
	divs.w	#8,d1
	swap	d1
	add.w	d1,d1
	move.w	d0,-(sp)
	move.l	#1,d0
	asl.w	d1,d0
	move.w	(sp)+,d1
	or.w	d0,d1
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-490,a0
	sub.l	d0,a0
	move.w	d1,(a0)
;
;	HOSTSERVREQ(chan,Initialize);	// init
^^	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	swap	d0
	add.w	d0,d0
	move.l	#1,d1
	asl.w	d0,d1
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-486,a0
	sub.l	d0,a0
	move.w	d1,(a0)
;
;	CHANPRIOR(chan,MiddlePrior);	// priority
^^	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-482,a0
	sub.l	d0,a0
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	swap	d0
	add.w	d0,d0
	move.l	#3,d1
	asl.w	d0,d1
	not.w	d1
	move.w	(a0),d0
	and.w	d1,d0
	move.w	d2,d1
	ext.l	d1
	divs.w	#8,d1
	swap	d1
	add.w	d1,d1
	move.w	d0,-(sp)
	move.l	#2,d0
	asl.w	d1,d0
	move.w	(sp)+,d1
	or.w	d0,d1
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-482,a0
	sub.l	d0,a0
	move.w	d1,(a0)
;
;	while(HOSTSERVSTAT(chan)&3) 	// poll until service ends (00)
^^.10057
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	add.w	d0,d0
	ext.l	d0
	move.l	#-486,a0
	sub.l	d0,a0
	move.w	d2,d0
	ext.l	d0
	divs.w	#8,d0
	swap	d0
	add.w	d0,d0
	move.l	#3,d1
	asl.w	d0,d1
	move.w	(a0),d0
	and.w	d1,d0
	and.w	#3,d0
	beq	.10058
;		;
^	bra	.10057
.10058
;
;	}
^^.52
	movem.l	(sp)+,d2
	rts
.51
;
;
;//**************************************************************************
;// Get current channel count
;//**************************************************************************
;
;long	GetTPUCount(short chan){
# 237
| .53
	xdef	_GetTPUCount
_GetTPUCount:
	movem.l	d2,-(sp)
	move.w	8(sp),d2
;
;	// Poll Interrupt Bit to check for overflow
;	if ( ((*CISR & (1 << chan )) != 0) )
~~ chan d2 "i"
^^^;	  {					// if overflow
	move.l	#1,d0
	asl.w	d2,d0
	and.w	-480,d0
	beq	.10059
^;	   *CISR ^= (1 << chan );		// Clear interrupt bit
^	move.l	#1,d0
	asl.w	d2,d0
	move.w	-480,d1
	eor.w	d1,d0
	move.w	d0,-480
;	   PRAM[chan][TRANS_COUNT] = 0;	// reset count
^	move.w	d2,d0
	ext.l	d0
	asl.l	#4,d0
	move.l	#-256,a0
	clr.w	6(a0,d0.l)
;	  }
^;	return(PRAM[chan][TRANS_COUNT]);	// get count
.10059
^	move.w	d2,d0
	ext.l	d0
	asl.l	#4,d0
	move.l	#-256,a0
	move.l	d0,-(sp)
	move.l	#0,d0
	move.l	(sp)+,d1
	move.w	6(a0,d1.l),d0
.54
	movem.l	(sp)+,d2
	rts
;	}
^.53
;
# 246
|
~ _main * "(v"
~ _GetTPUCount * "(l"
~ _SetupTPUCount * "(v"
~ _motor_step * "(v"
~ ''
~ 1 18 66
~ 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"
~ clibVersion 46 "l"
~ mlibVersion 50 "l"
~ libBuildDate 54 "#c"
~ clibBuildDate 58 "#c"
~ mlibBuildDate 62 "#c"
~ infoAction "c"
~ TT8info ":" 1
~ _InitTT8 * "(v"
~ _PutStr * "(v"
~ _TPUGetPin * "(i"
~ _TPUSetPin * "(v"
~ UeeErr "c"
~ ''
~ 2 2 8
~ secs 0 "L"
~ ticks 4 "l"
~ _DelayMilliSecs * "(v"
~ time_tt ":" 2
~ XmdmErr "c"
~ FlashErr "c"
~ ''
~ 3 4 24
~ eSR 0 "I"
~ ePC 2 "L"
~ vectofs 6 "I"
~ states 8 "[8I"
~ '_Regs'
~ 4 3 96
~ sysRegs 0 "[8L"
~ dataRegs 32 "[8L"
~ addrRegs 64 "[8L"
~ '_ExcInfo'
~ 5 2 120
~ regs 0 ":" 4
~ esf 96 ":" 3
~ ExcInfoPtr "#:" 5
~ ExcInfo ":" 5
~ RegsPtr "#:" 4
~ Regs ":" 4
~ ''
~ 6 4 20
~ preamble 0 "[4I"
~ jump 8 "I"
~ target 10 "L"
~ postamble 14 "[3I"
~ ExcCFramePtr "#:" 6
~ ExcCFrame ":" 6
~ ExcStackFrame ":" 3
~ _AtoDReadWord * "(i"
~ PSPErr "c"
~ _PRAM "[8I"
~ bool "c"
~ vfptr "#(v"
~ ptr "#c"
~ ulpv "#L"
~ ulong "L"
~ uspv "#I"
~ unsint "I"
~ ushort "I"
~ ucpv "#C"
~ uchar "C"
~ sig_atomic_t "c"
~ jmp_buf "[60c"
~ 'lconv'
~ 7 18 48
~ decimal_point 0 "#c"
~ thousands_sep 4 "#c"
~ grouping 8 "#c"
~ int_curr_symbol 12 "#c"
~ currency_symbol 16 "#c"
~ mon_decimal_point 20 "#c"
~ mon_thousands_sep 24 "#c"
~ mon_grouping 28 "#c"
~ positive_sign 32 "#c"
~ negative_sign 36 "#c"
~ int_frac_digits 40 "c"
~ frac_digits 41 "c"
~ p_cs_precedes 42 "c"
~ p_sep_by_space 43 "c"
~ n_cs_precedes 44 "c"
~ n_sep_by_space 45 "c"
~ p_sign_posn 46 "c"
~ n_sign_posn 47 "c"
~ lconv ":" 7
~ 'tm'
~ 8 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"
~ ''
~ 9 2 8
~ quot 0 "l"
~ rem 4 "l"
~ ''
~ 10 2 4
~ quot 0 "i"
~ rem 2 "i"
~ ldiv_t ":" 9
~ div_t ":" 10
~ '__stdio'
~ 11 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"
~ _gets * "(#c"
~ _printf * "(i"
~ FILE ":" 11
~ fpos_t "l"
~ wchar_t "c"
~ ptrdiff_t "l"
~ size_t "L"
~ va_list "#c"
	xref	_InitTT8
	xref	_PutStr
	xref	_TPUGetPin
	xref	_TPUSetPin
	xref	_DelayMilliSecs
	xref	_AtoDReadWord
	xref	_gets
	xref	_printf
	xref	.begin
	dseg
	end
