[TI ASM] Direct input and clearing before direct input
Posted: Sat 19 Nov, 2011 11:27 am
Hello everyone, i know there are still a few people who frequent this board even if it's not very active, so i thought i'd pose a little question and hopefully see some familiar faces
Right now, i've got some code (basically, a pause function):...which works fine, but then i thought that there will probably be more instances where the user not releasing 2nd soon enough might cause them to select/do things they didn't want to, so maybe a separate "wait2ndReleased" function might be handy.
The thing is i figure this would eat up a lot of battery power, so maybe i should throw in a halt or two. This code then made me think about how several years ago, it seemed to be common practice to "clear" the port before reading from it. Is there any reason for doing that (apart from maybe reading leftover keypresses)?
So i've got two questions, the first being whether it'd be worthwhile to throw in a halt or two in the w2r routine, the second about clearing the key port before reading from it.
Thanks.
Right now, i've got some code (basically, a pause function):
Code: Select all
;##########################
;#WAIT2ND
;#Wait for the 2nd key to be pressed.
;# If 2nd is currently held, we first
;# wait for it to be released then
;# check if it has been pressed again.
;# Also, displays the gbuf
;#Explanation: b starts off at 2 (see
;# inc b). If 2nd is pressed, we jump to
;# loop2, so the djnz will always drop b
;# to 1, never 0, until we release 2nd.
;# this is so that the player doesn't
;# accidentally skip a message
;##########################
wait2nd:
call drawgbuf
ld b,1
jr w2_loop2
w2_loop:
ld b,0
w2_loop2:
inc b
ld a,$BF ;group 7
out (1),a
in a,(1)
cp 223 ;2nd
jr nz,w2_loop ;if 2nd isn't pressed, repeat loop
djnz w2_loop2
ret
Code: Select all
wait2ndReleased:
ld a,$BF ;group 7
out (1),a
w2R_loop:
in a,(1)
cp 223 ;2nd
jr z,w2R_loop
ret
So i've got two questions, the first being whether it'd be worthwhile to throw in a halt or two in the w2r routine, the second about clearing the key port before reading from it.
Thanks.