6502-OS/system/keypad.s65

102 lines
2.5 KiB
Plaintext
Raw Normal View History

2023-10-26 19:51:20 +02:00
;********************************************************************************
2023-10-28 03:48:27 +02:00
; @module keypad4x4
2023-10-26 19:51:20 +02:00
; @type driver
; @device 4x4 Matrix Keypad
; @details
2023-10-28 03:48:27 +02:00
; The LCD must be connected to a W65C22N Interface Chip:
; - IO.RB0-7 ->
2023-10-26 19:51:20 +02:00
; @requires KP_IO: Base Address of IO Chip
2023-10-30 22:11:24 +01:00
; @depends IO-W65C22N
2023-10-26 19:51:20 +02:00
;********************************************************************************
2023-10-30 22:11:24 +01:00
2023-10-26 19:51:20 +02:00
.ifndef INCLUDE_KEYPAD
INCLUDE_KEYPAD = 1
.ifndef KP_IO
.fatal "KP_IO is not defined: set it to the base address of the IO chip of the Keypad"
.endif
2023-10-30 22:11:24 +01:00
RBUF_MEM_START = $200
RBUF_MEM_END = $2ff
.define RBUF_NAME "keypad"
.include "buffer.s65"
2023-10-26 19:51:20 +02:00
2023-10-30 22:11:24 +01:00
KB_VAR = $05
KB_LAST = $06
2023-10-26 19:51:20 +02:00
2023-10-30 22:11:24 +01:00
.proc kp_init
; todo remove
stz KB_LAST
; todo remove later
lda #$ff
sta KP_IO+IO_DDRB
stz KP_IO+IO_RB
2023-10-26 19:51:20 +02:00
; INIT KEYPAD
lda #%00001111; KP_IO+IO_RB 0-3 output
sta KP_IO+IO_DDRB
stz KP_IO+IO_RB ; KP_IO+IO_RB 4-7 1 so keypad press can be detected
stz KP_IO+IO_ACR
2023-10-30 22:11:24 +01:00
; lda #%00010000 ; set CB1 to interrupt on pos. edge
lda #IO_PCR_CB1_IP_AE
2023-10-26 19:51:20 +02:00
sta KP_IO+IO_PCR
2023-10-30 22:11:24 +01:00
jsr rb_keypad_init ; init keybuffer
lda #%10010000 ; enable interrupt for CB1 on KP_IO
sta KP_IO+IO_IER
2023-10-26 19:51:20 +02:00
rts
2023-10-30 22:11:24 +01:00
.endproc
2023-10-26 19:51:20 +02:00
;********************************************************************************
2023-10-30 22:11:24 +01:00
; @function Read which key is pressed on the keypad
; @details
; Checks which key is pressed and stores it in the keybuffer
; The value stored in the keybuffer is the offset which must be added to
; kp_VALUES to retrieve the key that was pressed
2023-10-26 19:51:20 +02:00
;********************************************************************************
2023-10-30 22:11:24 +01:00
.proc kp_read_on_irq
; test each "row" and check which column is 1
2023-10-26 19:51:20 +02:00
lda #%00001110
ldx #$00
2023-10-30 22:11:24 +01:00
jsr @kp_read_column
2023-10-26 19:51:20 +02:00
lda #%00001101
ldx #$04
2023-10-30 22:11:24 +01:00
jsr @kp_read_column
2023-10-26 19:51:20 +02:00
lda #%00001011
ldx #$08
2023-10-30 22:11:24 +01:00
jsr @kp_read_column
2023-10-26 19:51:20 +02:00
lda #%00000111
ldx #$0c
2023-10-30 22:11:24 +01:00
jsr @kp_read_column
bra @kp_read_rts
@kp_read_column:
2023-10-26 19:51:20 +02:00
sta KP_IO+IO_RB
lda KP_IO+IO_RB
sta KB_VAR ; store result in zeropage so that bbr can be used
2023-10-30 22:11:24 +01:00
bbr4 KB_VAR,@kp_write
2023-10-26 19:51:20 +02:00
inx
2023-10-30 22:11:24 +01:00
bbr5 KB_VAR,@kp_write
2023-10-26 19:51:20 +02:00
inx
2023-10-30 22:11:24 +01:00
bbr6 KB_VAR,@kp_write
2023-10-26 19:51:20 +02:00
inx
2023-10-30 22:11:24 +01:00
bbr7 KB_VAR,@kp_write
2023-10-26 19:51:20 +02:00
rts
2023-10-30 22:11:24 +01:00
@kp_write:
; temporary: store last keypress in KB_LAST, TODO: remove
lda kp_VALUES,x
sta KB_LAST
txa
jsr rb_keypad_write
@kp_read_rts:
stz KP_IO+IO_RB
; lda KP_IO+IO_RB ; read to definetly clear the interrupt flag
rts
.endproc
.segment "RODATA"
2023-10-26 19:51:20 +02:00
kp_VALUES:
; TODO change to literal
.byte "123A", "456B", "789C", "*0#D"
.endif