72 lines
1.7 KiB
ArmAsm
72 lines
1.7 KiB
ArmAsm
; Input Module
|
|
; ---------------------------------------------------------------------------
|
|
|
|
INCDIR "c:/Users/capitano/Documents/giochino/"
|
|
INCLUDE "custom.i"
|
|
|
|
; XDEF ReadInput
|
|
; XDEF LastKey
|
|
|
|
; SECTION Code,CODE_C
|
|
|
|
; ReadInput
|
|
; Returns: d0 = Raw Keycode (or 0 if no key)
|
|
; Preserves: d1-a6
|
|
ReadInput:
|
|
movem.l d1-d2/a0,-(sp)
|
|
|
|
; Check if LastKey is still pending (not yet processed)
|
|
move.b LastKey,d0
|
|
cmp.b #0,d0
|
|
bne.s .done ; Still has unprocessed key, don't read new one
|
|
|
|
; Simple keyboard matrix scan for keys '1' and '2'
|
|
; Key '1' = Row 0, Column 1 (raw code $01)
|
|
; Key '2' = Row 0, Column 2 (raw code $02)
|
|
|
|
lea $bfe001,a0 ; CIAA base
|
|
|
|
; Set all rows to output, columns to input
|
|
move.b #$ff,$bfe201 ; CIAA DDRA (all output)
|
|
move.b #$00,$bfe301 ; CIAA DDRB (all input)
|
|
|
|
; Scan Row 0 (contains keys 1 and 2)
|
|
move.b #$fe,$bfe001 ; Set row 0 low (active), others high
|
|
nop
|
|
nop ; Small delay for signal to settle
|
|
|
|
move.b $bfe101,d1 ; Read columns from Port B
|
|
not.b d1 ; Invert (pressed = 1)
|
|
|
|
; Check column 1 (key '1')
|
|
btst #1,d1
|
|
bne.s .key1
|
|
|
|
; Check column 2 (key '2')
|
|
btst #2,d1
|
|
bne.s .key2
|
|
|
|
; No key pressed
|
|
moveq #0,d0
|
|
bra.s .done
|
|
|
|
.key1:
|
|
move.b #$01,d0
|
|
move.b d0,LastKey
|
|
bra.s .done
|
|
|
|
.key2:
|
|
move.b #$02,d0
|
|
move.b d0,LastKey
|
|
|
|
.done:
|
|
movem.l (sp)+,d1-d2/a0
|
|
rts
|
|
|
|
; TODO: Implement proper keyboard reading later
|
|
; The keyboard reading via CIA is complex and error-prone
|
|
|
|
; SECTION Data,DATA_C
|
|
|
|
LastKey: dc.b 0
|