A86: evil routine


[Prev][Next][Index][Thread]

A86: evil routine




Please forgive me for posting a monster...
Although right now it is a monster without a heartbeat.  It won't work,
and I don't know why.
This code is supposed to check if the user is at homescreen, ret if not,
then check if they pressed MORE, ret if not.  Then it draws a title bar
and a little box, puts the current decimal precision in the box, and
waits for a keypress (I disabled sqrtkeyinstalled flag before getting to
that point so I can use _getkey).  Then it loads that to the _fmtDigits
location and quits.
But it never gets past detecting kMORE.  It always either crashes or
rets unless I help it out in the debugger and inject a keycode into
register A before it pushes AF.  After that it does just fine.  My
problem is that it cannot detect the MORE key.  I've tried detecting it
through A, through the _ASM_REG_A, through someplace like _kbdscancode
(I don't remember); nothing works.  I do know that if the keycode is in
A when my sqrtKEY is run, it gets trashed to $12 by _POPOP1, but I don't
even know if that is where the keycode is.  I think it comes from
_ASM_REG_A, but that always seems to be $00.  Any suggestions?

Thanks for putting up with all this crap,
Cassady Roop


sqrtkeycode:
	.db $8e,$28				;asm prog token
	call _POPOP1
	ld a, (_ASM_REG_A)
	push af
	ld a, (_CXCURAPP)
	cp $01					;is it the homescreen?
	jp nz, sqrt_pop_quit			;if not, quit
	pop af
	cp $00
	ret z					;if it is zero, then no key was pressed
	cp kMORE				;kMORE= kNEXT
	jp nz, sqrt_quit			;if not, quit
	res sqrtkeyinstalled, (IY+sqrtflags)	;disable, so I can use _getkey in
this routine
	ld hl, $FC00
	ld de, _plotSScreen
	ld bc, 1024
	ldir					;save the screen
	ld hl, $FC00
	ld b, 128
sqrt_blackloop:
	ld (hl), $FF				;8 darkened pixels
	inc hl
	djnz sqrt_blackloop			;loop until 8 rows are done
drawBox:				;draw box around precision indicator
	ld hl, $FC90			;start of row 9
	ld (hl), $FE
	ld hl, $FC90			;row 9
	ld b, 7				;b rows of the following:
	ld de, $0010			;one row's worth of bytes
drawboxleft:				;draw the right side of the box
	add hl, de			;next row
	ld (hl), %10000010		;draw bit 7, bit 2 dark, others light
	djnz drawboxleft						
	ld hl, $FC90							
	ld b, 7
drawboxbottom:				;draw bottom side
	ld hl, $FD00
	ld (hl), $FE
	ld hl, $0902
	ld (_pencol), hl
	ld a, (_fmtDigits)		;current precision value
	cp $FF					ff= float
	jr z, sqrt_isFloat
	call AtoDEC			;display the number of digits, inside the box
	jr sqrt_keyloop
sqrt_isFloat:				;if it is FF, don't disp 255, disp 'F'
	ld a, 70			;'F' for Float
	call _vputmap			;disp it
sqrt_keyloop:
	call _getkey			;safe because I disabled sqrtkey
	cp kF1
	jr z, set_float
	cp kF2
	jr z, set_ten
	cp kF3
	jr z, set_eleven
	cp kF4
	jr z, set_twelve
	cp kF5
	jr z, set_thirteen
	cp $1C						;is it below numeric range?
	jp m, sqrt_keyloop			;not a valid keypress
	cp $26						;is it above numeric range?
	jp p, sqrt_keyloop			;not a valid keypress
	sub k0					;subtract _getkey value
	jr sqrt_finish
set_float:
	ld a, $FF
	jr sqrt_finish
set_ten:
	ld a, $0A
	jr sqrt_finish
set_eleven:
	ld a, $0B
	jr sqrt_finish
set_twelve:
	ld a, $0C
	jr sqrt_finish
set_thirteen:
	ld a, $0D
sqrt_finish:
	ld (_fmtDigits), a			;write new value to memory
	set sqrtkeyinstalled, (IY+sqrtflags)	;re-enable this routine
	ld hl, _plotSScreen
	ld de, $FC00
	ld bc, 1024
	ldir					;copy the screen back
	ld a, kMORE				;last key that was pressed
	ret			;or _jforcecmdnochar, but it never makes it this far anyway...
sqrt_pop_quit:
	pop af
	cp a
	ret
sqrt_quit:
	cp a
	ret
AtoDEC:			;displays A in decimal w/no leading zeroes
        ld h, 0
	ld l, a
        ld b, 3
        ld de, num_spot+2
atodecmain:
        call _hldiv10
        add a, $30
        ld (de), a
        dec de
        djnz atodecmain
        ld hl, num_spot
	xor a
	add a, 48		;char code for zero
	cp (hl)
	jr nz, atodecdisp
	inc hl
	cp (hl)
	jr nz, atodecdisp
	inc hl
atodecdisp:
        call _vputs
        ret
num_spot:
	.db $00,$00,$00,0

sqrtkeycode_end: