diff --git a/main.s65 b/main.s65 index bde877d..aa50cfd 100644 --- a/main.s65 +++ b/main.s65 @@ -44,24 +44,25 @@ SPI_IO = IO2 ;******************************************************************************** ; Interrupts ;******************************************************************************** +.zeropage +IRQ_VAR: .res 1 .code nmi: lda #'%' jsr lcd_char rti irq: -IRQ_VAR = 0 ; read IRFs, while bit 7 ist set handle interrupts -@irq_io1: - lda SPI_IO+IO::IFR - sta IRQ_VAR - bbr7 IRQ_VAR,@irq_io2 - bbs2 IRQ_VAR,@irq_spi_p ; check SR +; @irq_io1: +; lda SPI_IO+IO::IFR +; sta IRQ_VAR + ; bbr7 IRQ_VAR,@irq_io2 @irq_io2: - ; lda IO2+IO::IFR - ; sta IRQ_VAR - ; bbr7 IRQ_VAR,@irq_return - ; bbs4 IRQ_VAR,@irq_keypad ; check CB1 + lda IO2+IO::IFR + sta IRQ_VAR + bbr7 IRQ_VAR,@irq_return + bbs1 IRQ_VAR,@irq_keypad ; check CB1 + bbs2 IRQ_VAR,@irq_spi_p ; check SR ; this should never be reached jsr lcd_clear Print str_irq_unknown @@ -76,9 +77,9 @@ IRQ_VAR = 0 @irq_spi_p: jsr spi_p_read bra @irq_return -@irq_dht: - lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag - bra @irq_return +; @irq_dht: +; lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag +; bra @irq_return @irq_return: rti @@ -88,15 +89,16 @@ IRQ_VAR = 0 reset: jsr lcd_init - ; jsr kp_init - - jsr spi_p_init - lda #$ff sta IO1 + IO::DDRA DEBUG_LED_OFF 0 DEBUG_LED_OFF 1 + jsr kp_init + + jsr spi_p_init + + ; ; INIT DHT ; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2 ; sta IER2 @@ -128,7 +130,26 @@ reset: jeq print_1 cmp #'D' jeq print_2 - + cmp #'0' + bne @l1 + DEBUG_LED_OFF 0 + jmp home +@l1: + cmp #'#' + bne @l2 + DEBUG_LED_ON 0 + jmp home +@l2: + cmp #'8' + bne @l3 + DEBUG_LED_OFF 1 + jmp home +@l3: + cmp #'9' + bne @l4 + DEBUG_LED_ON 1 + jmp home +@l4: cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home) jeq return_home @@ -147,7 +168,11 @@ print_2: jmp home .rodata -message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz" +message_1: + .byte " Powered by " + .byte "......6502......" + .byte " **** " + .asciiz "www.quintern.xyz" message_2: .byte " Hello " .byte " there " diff --git a/system/keypad.s65 b/system/keypad.s65 index ea9d628..42107ee 100644 --- a/system/keypad.s65 +++ b/system/keypad.s65 @@ -4,7 +4,7 @@ ; @device 4x4 Matrix Keypad ; @details ; The LCD must be connected to a W65C22N Interface Chip: -; - IO.RB0-7 -> +; - IO.RA0-7 -> ; @requires KP_IO: Base Address of IO Chip ; @depends IO-W65C22N ;******************************************************************************** @@ -30,22 +30,23 @@ RBUF_MEM_END = RBUF_MEM_START + KP_BUF_SIZE - 1 .proc kp_init ; todo remove later and test lda #$ff - sta KP_IO+IO::DDRB - stz KP_IO+IO::RB + sta KP_IO+IO::DDRA + stz KP_IO+IO::RA ; INIT KEYPAD ; todo: use masks - 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 + 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 stz KP_IO+IO::ACR - ; lda #%00010000 ; set CB1 to interrupt on pos. edge + ; lda #%00010000 ; set CA1 to interrupt on pos. edge ; todo: use masks - lda #IO::PCR::CB1_IP_AE + lda #IO::PCR::CA1_IP_AE sta KP_IO+IO::PCR jsr rb_keypad_init ; init keybuffer - lda #(IO::IRQ::IRQ | IO::IRQ::CB1) ; enable interrupt for CB1 on KP_IO + lda #(IO::IRQ::IRQ | IO::IRQ::CA1) ; enable interrupt for CA1 on KP_IO sta KP_IO+IO::IER rts .endproc @@ -60,23 +61,24 @@ RBUF_MEM_END = RBUF_MEM_START + KP_BUF_SIZE - 1 .proc kp_read_on_irq ; test each "row" and check which column is 1 ; todo dont check every column if the value has been found - lda #%00001110 + lda #%11100000 ldx #$00 jsr @kp_read_column - lda #%00001101 + lda #%11010000 ldx #$08 jsr @kp_read_column - lda #%00001011 + lda #%10110000 ldx #$04 jsr @kp_read_column - lda #%00000111 + lda #%01110000 ldx #$0c jsr @kp_read_column - stz KP_IO+IO::RB ; todo why all zero? + 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 rts @kp_read_column: - sta KP_IO+IO::RB - lda KP_IO+IO::RB + sta KP_IO+IO::RA + lda KP_IO+IO::RA sta _KP_COLUMN ; store result in zeropage so that bbr can be used bbr4 _KP_COLUMN,@kp_write inx