Re: A83: test run
[Prev][Next][Index][Thread]
Re: A83: test run
; Nice to see someone codes with comments :)
; I think the code for input is a bit bulky ; seperate routines for 0 and 1
; for example. This code does similar stuff but slightly more cleanly.
call _getkey
pop de
sub 142 ; value is now 0,1, any other invalid
ld d,a ; save in D temporarily
and $FE ; look at bits 7..1. If any are non
jr nz,Invalid ; zero then it can't be 0 or 1
ld a,d ; A := D + E * 2
add a,e
add a,e
ld e,a ; put back in D
add a,'0' ; convert to ASCII character '0' or
'1'
;
; or more trickily :)
;
sub 142 ; 0,1 valid 2-$FF invalid
srl A ; Carry set if 1. Zero if the
; original value was 0 or 1.
jr nz,Invalid
ld a,e ; A := E
adc a,e ; A := (previous E) + E + Carry
ld e,a ; copy back to E
and $01 ; bit 0 is the new digit input
add a,'0' ; A now '0' or '1'.
; A useful trick for binary output is something like the following
; (and it saves 2 bytes, handy on a TI83)
ld b,8 ; 8 characters out
_Loop:
ld a,'0' ; output a 'Zero'.
rlc e ; shift byte right, most significant
; bit is now in the carry
adc a,0 ; A is now '0' or '1' depending on
carry
call _putc
djnz _Loop ; Do it 8 times.
ret