[TI ASM] Direct input and clearing before direct input

Got questions? Got answers? Go here for both.

Moderator: MaxCoderz Staff

Post Reply
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

[TI ASM] Direct input and clearing before direct input

Post by chickendude »

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):

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
...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.

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
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.
King Harold
Calc King
Posts: 1513
Joined: Sat 05 Aug, 2006 7:22 am

Re: [TI ASM] Direct input and clearing before direct input

Post by King Harold »

The keypad thingy maintains a set of active groups, so if anything was already active, you're now reading from 2 (or more) groups at the same time. Typically group $BF or $7F or $FE would be the last active group (from scanning the entire keypad), and in none of those cases would 2nd clash with any other key ($7F has no keys, $FE only has 4 while 2nd is at the 6th bit).
But just in case, I'd throw in a quick ld a,$FF \ out (1),a

Halts should work yes
chickendude
Extreme Poster
Posts: 340
Joined: Fri 07 Jul, 2006 2:39 pm

Re: [TI ASM] Direct input and clearing before direct input

Post by chickendude »

Thanks, i figure it'll almost never be an issue, only if you want to read keys which share the same value in two different groups. Honestly, it doesn't really matter to me if you can also use another unintended key, so long as it doesn't overlap with a key you are using. I remember playing certain games back in the day and finding out that certain keys would do things, like the graph keys would move you (maybe it was falldown?), i dunno. Anyway, thanks for the response :)
Post Reply