home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-

New Paste :: Recent Pastes:: Add Line Numbers

A Paste by Anonymous
TOFISRA equ    $D1
TOFM    equ    $80
TMSK2     equ    $1024
TFLG2     equ    $1025
PORTB    equ    $1004
PORTC    equ    $1003
X1    equ    %00000001
X2    equ    %00000010
X3    equ    %00000100
XS    equ    %00000111
Y1    equ    %11110001
Y2    equ    %11110010
Y3    equ    %11110100
Y4    equ    %11111000
YS    equ    %00001111
BUFSIZ    equ    20
OUTA    equ    $ffb8  ;?????
table    fcb    $31, $32, $33, $34, $35, $36, $37, $38, $39, $2A, $30, $23

    org    $DFD0
inptr    rmb    2
outptr    rmb    2
buffer    rmb    BUFSIZ
keystate    rmb    1
row    rmb    1
column    rmb    1

    org    $D000
init    sei            ;disable interrupts during setup
    ldx    #tofisr        ;install our interrupt
    stx    TOFISRA    ;   service routine
    clr    keystate   
    ldaa    #0
    staa    PORTB    ; code to set 3 output pins driving X1-3 to zero here
    ;staa    PORTC
    ldaa    TMSK2
    oraa    #TOFM    ;enable TOF interrupt
    staa    TMSK2
    ldx    #buffer
    stx    inptr    ;code to initialize circular buffer for key codes here
    stx    outptr
    cli            ;let them start

main    ldx    outptr
    cpx    inptr        ;poll buffer looking for keys
    beq    main
    ldaa    0,x
    jsr    OUTA    ; code to extract key code from buffer and send to screen here
    cpx    #buffer + BUFSIZ
    bne    fine
    ldx    #buffer
fine    stx    outptr
    bra    main

tofisr    ;clr    keypress    ;0 indicates no keypress
    ldaa    keystate
    cmpa    #0
    beq    state0
    cmpa    #1
    beq    state1
    cmpa    #2
    beq    state2a
    cmpa    #3
    beq    state3a
    bra    state0    ;error catch
state2a    jmp    state2
state3a    jmp    state3    
; place code to read port containing Y1-4 values here
; compare to %1111 on those bits
; if not all 1s inc keypress to show key being pressed

;place keystate breakout code here to go to state0 - state4

state0    ldaa    PORTC
    anda    #%00001111
    cmpa    #YS    ;no key pressed?
    beq    donei
    ;inc    keypress
    ldaa    #1
    staa    keystate    ;make and set next state decision
donei    jmp    tofrtn

state1    ldaa    PORTC
    anda    #%00001111
    cmpa    #YS    ;no key pressed?
    beq    donej
    ;inc    keypress
    ldaa    #2
    staa    keystate    ;make and set next state decision
    ldaa    PORTC
    anda    #%00001111
    cmpa    #~Y1
    beq    set1
    cmpa    #~Y2
    beq    set2
    cmpa    #~Y3
    beq    set3
    ldaa    #3
    bra    join4
set1    ldaa    #0
    bra    join4
set2    ldaa    #1
    bra    join4
set3    ldaa    #2
join4    staa    row
    ldab    #~X1
    stab    PORTB
    ldaa    PORTC
    anda    #%00001111
    cmpa    #YS
    bne    found1
    ldab    #~X2
    stab    PORTB
    ldaa    PORTC
    anda    #%00001111
    cmpa    #YS
    bne    found2
    ldaa    #2
    bra    joinf
found1    ldaa    #0
    bra    joinf
found2    ldaa    #1
joinf    staa    column
    ldaa    #0
    staa    PORTB
    ldaa    row
    adda    row
    adda    column
    ldx    #table
    ldaa    0,x    ;decode key ~~~~~~~~~~~~~~~~~
    ldx    inptr
    staa    0,x
    cpx    #buffer + BUFSIZ
    bne    fine2
    ldx    #buffer
fine2    stx    inptr
    bra    donep
donej    ldaa    #0            ; if next state is 2 decode key and place in buffer
    staa    keystate
donep    bra    tofrtn

state2    ldaa    PORTC    
    anda    #%00001111        ;make and set next state decision
    cmpa    #YS    ;key pressed?
    bne    donek
    ldaa    #3
    staa    keystate
donek    bra    tofrtn

state3    ldaa    PORTC    ;make and set next state decision
    anda    #%00001111
    cmpa    #YS        ;key pressed?
    bne    donem
    ldaa    #0
    staa    keystate
    bra    donen
donem    ldaa    #2
    staa    keystate
donen    bra     tofrtn

tofrtn    ldaa    #TOFM
    staa    TFLG2    ;clear TOF event