*************************************************************************************************
*E-MAIL: 	vladi@comcast.net ; noelmarie@comcast.net
*
* Name:		Noel Patterson, Vladi Gergov
* Course:  	ECE 373
* Term: 	Summer 2002
*
* Revision History
*
* First Draft:  07/08/02
*   -Progress:
*
* Most Recent Revision:  07/08/02
* Date Submitted: 06/06/02
*************************************************************************************************

*
* equates
*

out1byt	equ	$FFBB
outa	equ	$FFB8
outcrlf	equ	$FFC4
out1bsp	equ	$FFBE
outstrg	equ	$FFC7
input	equ	$FFAC
outstro equ	$FFCA
upcase	equ	$ffa0

tcnt	equ	$100f

	org	$3000

*
* esc sequence for clear screen
*

clrscrn	fcb	$1b,$5b,$32,$4a,$04

*
* esc sequences for table offset and position
*

init	fcb	$1b,$5b,$33,$39,$3b,$33,$39,$48,$04
gotocur	fcb	$1b,$5b,$34,$30,$3b,$34,$30,$48,$04

tbla	fcb	$4d,$5b,$24,$04
tblb	fcb	$5d,$20,$3d,$20,$24,$04

gotopt	fcb	$1b,$5b,$35,$30,$3b,$34,$30,$48,$04

goto1	fcb	$1b,$5b,$34,$30,$3b,$33,$39,$48,$04
goto2	fcb	$1b,$5b,$34,$31,$3b,$33,$39,$48,$04
goto3	fcb	$1b,$5b,$34,$32,$3b,$33,$39,$48,$04
goto4	fcb	$1b,$5b,$34,$33,$3b,$33,$39,$48,$04
goto5	fcb	$1b,$5b,$34,$34,$3b,$33,$39,$48,$04
goto6	fcb	$1b,$5b,$34,$35,$3b,$33,$39,$48,$04
goto7	fcb	$1b,$5b,$34,$36,$3b,$33,$39,$48,$04
goto8	fcb	$1b,$5b,$34,$37,$3b,$33,$39,$48,$04

pointer	fcb	$1b,$5b,$34,$30,$3b,$34,$30,$48,$04

*
* data / variables / strings / esc sequences
*

	org	$3100
dectbl	fcb	$0,$1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16

	org	$3200
rndtbl	fcb	$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff

	org	$3300
cmptbl	fcb	$1,$1,$1,$1,$1,$1,$1,$1,$1,$1,$1,$1,$1,$1,$1,$1

counter	rmb	1
tblptr	rmb	2

dashes	fcc	"-------------"
	fcb	$04


*
* escape sequence for cursor position ( pointer )
*

*
* main code begins
* this is where we call the differnet code fragments to compleate the table
*
	org	$2000

*
* initializations
*

	sei

	ldx	#rndtbl
	stx	$3400
	ldaa	#16
	staa	counter

*
* calls to functions
*

	jsr	random
	jsr	table
	jsr	move

table	ldy	#rndtbl
	ldx	#clrscrn
	jsr	outstro

	ldx	#init
	jsr	outstro
	jsr 	drwline

	ldx	#goto1
	jsr	outstro
	jsr	drwrow

	ldx	#goto2
	jsr	outstro
	jsr	drwline

	ldx	#goto3
	jsr	outstro
	jsr	drwrow

	ldx	#goto4
	jsr	outstro
	jsr	drwline

	ldx	#goto5
	jsr	outstro
	jsr	drwrow

	ldx	#goto6
	jsr	outstro
	jsr	drwline

	ldx	#goto7
	jsr	outstro
	jsr	drwrow

	ldx	#goto8
	jsr	outstro
	jsr	drwline

	ldx	#gotocur
	jsr	outstro

	rts

*
* cursor movement routines
*

up	ldaa	$3403
	cmpa	#$30
	beq	move
	dec	$3403
	dec	$3403
	ldx	#pointer
	jsr	outstro
	dec	$3301
	dec	$3301
	dec	$3301
	dec	$3301
	jmp	print

down	ldaa	$3403
	cmpa	#$36
	beq	move
	inc	$3403
	inc	$3403
	ldx	#pointer
	jsr	outstro
	inc	$3301
	inc	$3301
	inc	$3301
	inc	$3301
	jmp	print

move	jsr	input
	jsr	upcase
	beq	move
	cmpa	#'W'
	beq	up
	cmpa	#'S'
	beq	down
	cmpa	#'A'
	beq	left
	cmpa	#'D'
	beq	right
	cmpa	#'Q'
	beq 	quit
	cmpa	#$20
	beq	space
	jmp	move

left	ldaa	$3406
	cmpa	#$30
	beq	move
	dec	$3406
	dec	$3406
	dec	$3406
	ldx	#pointer
	jsr	outstro
	dec	$3301
	jmp	print

right	ldaa	$3406
	cmpa	#$39
	beq	move
	inc	$3406
	inc	$3406
	inc	$3406
	ldx	#pointer
	jsr	outstro
	inc	$3301
	jmp	print

space	ldx	#init
	jsr	outstro
	swi

*
* table output code
*

print	ldx	#gotopt
	jsr	outstro
	ldx	#tbla
	jsr	outstro
	ldx	#$3300
	jsr	out1byt
	jsr 	out1byt
	ldx	#tblb
	jsr	outstro
	ldy	#$3300
	ldx	0,y
	jsr	out1byt
	ldx	#pointer
	jsr	outstro
	jmp	move

quit	swi

*
* if drwline is called it will print 13 dashes at the cusor pos and then exit
* if drwrow is called it will print
*

drwline	ldx	#dashes
	jsr	outstro
	rts

drwrow	ldaa	#'|'
	jsr	outa
	ldaa	#$4
	staa	counter

loop	ldx	#dectbl
	ldab	0,y
	abx
	jsr 	out1byt
	ldaa	#'|'
	jsr 	outa
	iny
	dec	counter
	beq	return
	bra 	loop

random	ldy	#rndtbl

newnum	ldab	tcnt
	lsrb
	lsrb
	lsrb
	lsrb
	beq	newnum
	cmpb	#16
	beq	newnum
	ldx	#cmptbl
	abx
	ldaa	0,x
	beq	newnum
	dec	0,x
	stab	0,y
	ldaa	counter
	beq	return
	dec	counter
	iny
	bra	newnum

return	jsr	outcrlf
	rts

*
* eof
*
