[A83] thorough explanation of direct input


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

[A83] thorough explanation of direct input




Here is a more complete example of direct input, the previous might have been 
a little confusing.  When I set up a program, I put labels that I call often 
towards the bottom of the code.  You should set up a label somewhere in your 
program as follows:

directinput:
    ld  a,0ffh          ; loads 0ffh into a
    out (1),a           ; and then outputs a to port 1 (keyport) to reset the 
keyport
    ld  a,b         ;loads predetermined value b (a key group) into 
accumulator
    out (1),a       ;necessary syntax
    in  a,(1)       ;....
    ret         ;returns to where it was called from

Then, in your program if you wanted to enable the arrows, and the top row 
(2ndmodedel), you would put:

#include "keys.inc"

directinputloop:
    ld b,KeyRow_Pad
    call directinput
    cp kLeft
    jp z,moveleft
    cp kRight
    jp z,moveright
    ld b,KeyRow_Top
    call directinput
    cp kDel
    ret z
    cp kMode
    call z,turncalcoff
    cp k2nd
    jp z,secondpress
    jp directinputloop


moveleft:
    ld a,(xpos)
    sub a,2
    jp z,directinputloop
    ld (xpos),a
    jp directinputloop

moveright:
    ld a,(xpos)
    add a,2
    cp 96-8
    jp z,directinputloop
    ld (xpos),a
    jp directinputloop
    
turncalcoff:
    ld      a,1                     ; turn off calc
    out     (3),a                   ; by outputting 1 into port 3
    ei                              ;enable interupts
    halt                            ;halt
    ret                     ;returns to where it was called from (in loop)

secondpress:
    bcall(_clrlcdf)
    bcall(_homeup)
    ld hl,txt2nd
    bcall(_puts)
    bcall(_getkey)
    jp directinputloop

txt2nd:
    .db "You pressed 2nd"
.end
END

Hope that clears things up.

-Cole South