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:
|
2023-11-13 19:14:18 +01:00
|
|
|
; - IO.RA0-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-11-11 12:13:47 +01:00
|
|
|
.zeropage
|
|
|
|
_KP_COLUMN: .res 1 ; for storing stuff
|
2023-10-26 19:51:20 +02:00
|
|
|
|
2023-11-11 12:13:47 +01:00
|
|
|
.bss ; reserve space or ringbuffer
|
|
|
|
KP_BUF_SIZE = 10
|
|
|
|
RBUF_MEM_START: .res KP_BUF_SIZE
|
|
|
|
RBUF_MEM_END = RBUF_MEM_START + KP_BUF_SIZE - 1
|
2023-10-30 22:11:24 +01:00
|
|
|
.define RBUF_NAME "keypad"
|
|
|
|
.include "buffer.s65"
|
2023-10-26 19:51:20 +02:00
|
|
|
|
2023-11-11 12:13:47 +01:00
|
|
|
.code
|
2023-10-30 22:11:24 +01:00
|
|
|
.proc kp_init
|
2023-11-01 13:13:23 +01:00
|
|
|
; todo remove later and test
|
2023-10-30 22:11:24 +01:00
|
|
|
lda #$ff
|
2023-11-13 19:14:18 +01:00
|
|
|
sta KP_IO+IO::DDRA
|
|
|
|
stz KP_IO+IO::RA
|
2023-10-26 19:51:20 +02:00
|
|
|
|
|
|
|
; INIT KEYPAD
|
2023-11-01 13:13:23 +01:00
|
|
|
; todo: use masks
|
2023-11-13 19:14:18 +01:00
|
|
|
lda #%11110000; KP_IO+IO::RA 0-3 output
|
|
|
|
sta KP_IO+IO::DDRA
|
|
|
|
; output 0, key press will pull input pin low
|
|
|
|
stz KP_IO+IO::RA
|
2023-11-01 13:13:23 +01:00
|
|
|
stz KP_IO+IO::ACR
|
2023-10-26 19:51:20 +02:00
|
|
|
|
2023-11-13 19:14:18 +01:00
|
|
|
; lda #%00010000 ; set CA1 to interrupt on pos. edge
|
2023-11-01 13:13:23 +01:00
|
|
|
; todo: use masks
|
2023-11-13 19:14:18 +01:00
|
|
|
lda #IO::PCR::CA1_IP_AE
|
2023-11-01 13:13:23 +01:00
|
|
|
sta KP_IO+IO::PCR
|
2023-10-30 22:11:24 +01:00
|
|
|
jsr rb_keypad_init ; init keybuffer
|
2023-11-13 19:14:18 +01:00
|
|
|
lda #(IO::IRQ::IRQ | IO::IRQ::CA1) ; enable interrupt for CA1 on KP_IO
|
2023-11-01 13:13:23 +01:00
|
|
|
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-11-01 13:13:23 +01:00
|
|
|
; todo dont check every column if the value has been found
|
2023-11-13 19:14:18 +01:00
|
|
|
lda #%11100000
|
2023-10-26 19:51:20 +02:00
|
|
|
ldx #$00
|
2023-10-30 22:11:24 +01:00
|
|
|
jsr @kp_read_column
|
2023-11-13 19:14:18 +01:00
|
|
|
lda #%11010000
|
2023-11-09 12:08:09 +01:00
|
|
|
ldx #$08
|
2023-10-30 22:11:24 +01:00
|
|
|
jsr @kp_read_column
|
2023-11-13 19:14:18 +01:00
|
|
|
lda #%10110000
|
2023-11-09 12:08:09 +01:00
|
|
|
ldx #$04
|
2023-10-30 22:11:24 +01:00
|
|
|
jsr @kp_read_column
|
2023-11-13 19:14:18 +01:00
|
|
|
lda #%01110000
|
2023-10-26 19:51:20 +02:00
|
|
|
ldx #$0c
|
2023-10-30 22:11:24 +01:00
|
|
|
jsr @kp_read_column
|
2023-11-13 19:14:18 +01:00
|
|
|
stz KP_IO+IO::RA
|
|
|
|
lda KP_IO+IO::RA ; todo: verify that this is necessary so that rows 1-3 dont refire immediately after they are armed again because of stz
|
2023-11-01 13:13:23 +01:00
|
|
|
rts
|
2023-10-30 22:11:24 +01:00
|
|
|
@kp_read_column:
|
2023-11-13 19:14:18 +01:00
|
|
|
sta KP_IO+IO::RA
|
|
|
|
lda KP_IO+IO::RA
|
2023-11-11 12:13:47 +01:00
|
|
|
sta _KP_COLUMN ; store result in zeropage so that bbr can be used
|
|
|
|
bbr4 _KP_COLUMN,@kp_write
|
2023-10-26 19:51:20 +02:00
|
|
|
inx
|
2023-11-11 12:13:47 +01:00
|
|
|
bbr5 _KP_COLUMN,@kp_write
|
2023-10-26 19:51:20 +02:00
|
|
|
inx
|
2023-11-11 12:13:47 +01:00
|
|
|
bbr6 _KP_COLUMN,@kp_write
|
2023-10-26 19:51:20 +02:00
|
|
|
inx
|
2023-11-11 12:13:47 +01:00
|
|
|
bbr7 _KP_COLUMN,@kp_write
|
2023-10-26 19:51:20 +02:00
|
|
|
rts
|
2023-10-30 22:11:24 +01:00
|
|
|
@kp_write:
|
2023-11-11 12:13:47 +01:00
|
|
|
lda _KP_VALUES,x
|
2023-10-30 22:11:24 +01:00
|
|
|
jsr rb_keypad_write
|
|
|
|
rts
|
|
|
|
.endproc
|
|
|
|
|
2023-11-11 12:13:47 +01:00
|
|
|
.rodata
|
|
|
|
_KP_VALUES:
|
2023-10-26 19:51:20 +02:00
|
|
|
; TODO change to literal
|
|
|
|
.byte "123A", "456B", "789C", "*0#D"
|
|
|
|
.endif
|