.include "keypad.h65" Export kp, init, read_irq, read ExportZp kp, _DEBUG_VAL .zeropage _COLUMN: .res 1 ; for storing stuff _DEBUG_VAL: .res 1 ; for storing the last char DEBUG .bss ; reserve space or ringbuffer RBUF_MEM_START: .res kp::BUF_SIZE RBUF_MEM_END = RBUF_MEM_START + kp::BUF_SIZE - 1 .define RBUF_NAME "keypad" .include "buffer.h65" .code .proc init ; todo remove later and test lda #$ff sta kp::KP_IO+IO::DDRA stz kp::KP_IO+IO::RA ; INIT KEYPAD ; todo: use masks lda #%11110000; kp::KP_IO+IO::RA 0-3 output sta kp::KP_IO+IO::DDRA ; output 0, key press will pull input pin low stz kp::KP_IO+IO::RA stz kp::KP_IO+IO::ACR ; lda #%00010000 ; set CA1 to interrupt on pos. edge ; todo: use masks lda #IO::PCR::CA1_IP_AE sta kp::KP_IO+IO::PCR jsr rb_keypad_init ; init keybuffer lda #(IO::IRQ::IRQ | IO::IRQ::CA1) ; enable interrupt for CA1 on kp::KP_IO sta kp::KP_IO+IO::IER rts .endproc read = rb_keypad_read ;******************************************************************************** ; @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 ;******************************************************************************** .proc read_irq ; test each "row" and check which column is 1 ; TODO dont check every column if the value has been found lda #%11100000 ldx #$00 jsr @kp_read_column lda #%11010000 ldx #$04 jsr @kp_read_column lda #%10110000 ldx #$08 jsr @kp_read_column lda #%01110000 ldx #$0c jsr @kp_read_column stz kp::KP_IO+IO::RA lda kp::KP_IO+IO::RA ; clear interrupt flag again beceause it might be set again through the above tests rts @kp_read_column: sta kp::KP_IO+IO::RA lda kp::KP_IO+IO::RA sta _COLUMN ; store result in zeropage so that bbr can be used bbr0 _COLUMN,@kp_write ; row 1 inx bbr1 _COLUMN,@kp_write ; row 3 inx bbr2 _COLUMN,@kp_write ; row 2 inx bbr3 _COLUMN,@kp_write ; row 4 rts @kp_write: lda VALUES,x ; TODO use ringbuffer sta _DEBUG_VAL jsr rb_keypad_write rts .endproc .rodata VALUES: .byte "174*" .byte "2850" .byte "396#" .byte "ACBD" ; keypad conencted so that ; row 1 = PA0 ; row 2 = PA2 ; row 3 = PA1 ; row 4 = PA3