Compare commits

...

2 Commits

Author SHA1 Message Date
matthias@rpi
182b8a2d75 add spi code space 2023-11-13 19:14:39 +01:00
matthias@rpi
3b41b47ccd use PA fpr keypad 2023-11-13 19:14:18 +01:00
4 changed files with 87 additions and 38 deletions

View File

@ -1,6 +1,8 @@
MEMORY { MEMORY {
RAM_ZP: start = $0000, size = $100, type = rw, file = "", fill = yes; RAM_ZP: start = $0000, size = $100, type = rw, file = "", fill = yes;
RAM: start = $0100, size = $5eff, type = rw, file = "", fill = yes; # RAM: start = $0100, size = $5eff, type = rw, file = "", fill = yes;
RAM: start = $0100, size = $4eff, type = rw, file = "", fill = yes;
SPI: start = $5000, size = $1000, type = rw, file = "spi.bin", fill = no;
VIA1: start = $6000, size = $600f, type = rw, file = "", fill = yes; VIA1: start = $6000, size = $600f, type = rw, file = "", fill = yes;
VIA2: start = $7000, size = $700f, type = rw, file = "", fill = yes; VIA2: start = $7000, size = $700f, type = rw, file = "", fill = yes;
ROM: start = $8000, size = $8000, type = ro, file = %O, fill = yes; ROM: start = $8000, size = $8000, type = ro, file = %O, fill = yes;
@ -13,4 +15,5 @@ SEGMENTS {
CODE: load = ROM, type = ro; CODE: load = ROM, type = ro;
RODATA: load = ROM, type = ro; RODATA: load = ROM, type = ro;
RESET_VECTOR: load = ROM, type = ro, start = $FFFA; RESET_VECTOR: load = ROM, type = ro, start = $FFFA;
SPI: load = SPI, type = rw;
} }

View File

@ -44,24 +44,25 @@ SPI_IO = IO2
;******************************************************************************** ;********************************************************************************
; Interrupts ; Interrupts
;******************************************************************************** ;********************************************************************************
.zeropage
IRQ_VAR: .res 1
.code .code
nmi: nmi:
lda #'%' lda #'%'
jsr lcd_char jsr lcd_char
rti rti
irq: irq:
IRQ_VAR = 0
; read IRFs, while bit 7 ist set handle interrupts ; read IRFs, while bit 7 ist set handle interrupts
@irq_io1: ; @irq_io1:
lda SPI_IO+IO::IFR ; lda SPI_IO+IO::IFR
sta IRQ_VAR ; sta IRQ_VAR
bbr7 IRQ_VAR,@irq_io2 ; bbr7 IRQ_VAR,@irq_io2
bbs2 IRQ_VAR,@irq_spi_p ; check SR
@irq_io2: @irq_io2:
; lda IO2+IO::IFR lda IO2+IO::IFR
; sta IRQ_VAR sta IRQ_VAR
; bbr7 IRQ_VAR,@irq_return bbr7 IRQ_VAR,@irq_return
; bbs4 IRQ_VAR,@irq_keypad ; check CB1 bbs1 IRQ_VAR,@irq_keypad ; check CB1
bbs2 IRQ_VAR,@irq_spi_p ; check SR
; this should never be reached ; this should never be reached
jsr lcd_clear jsr lcd_clear
Print str_irq_unknown Print str_irq_unknown
@ -76,9 +77,9 @@ IRQ_VAR = 0
@irq_spi_p: @irq_spi_p:
jsr spi_p_read jsr spi_p_read
bra @irq_return bra @irq_return
@irq_dht: ; @irq_dht:
lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag ; lda IO1 + IO::T1CL ;T1L2 ; clear interrupt flag
bra @irq_return ; bra @irq_return
@irq_return: @irq_return:
rti rti
@ -88,15 +89,16 @@ IRQ_VAR = 0
reset: reset:
jsr lcd_init jsr lcd_init
; jsr kp_init
jsr spi_p_init
lda #$ff lda #$ff
sta IO1 + IO::DDRA sta IO1 + IO::DDRA
DEBUG_LED_OFF 0 DEBUG_LED_OFF 0
DEBUG_LED_OFF 1 DEBUG_LED_OFF 1
jsr kp_init
jsr spi_p_init
; ; INIT DHT ; ; INIT DHT
; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2 ; lda #%11000010 ; enable interrupt for Timer 1 and CA1 on IO2
; sta IER2 ; sta IER2
@ -128,7 +130,26 @@ reset:
jeq print_1 jeq print_1
cmp #'D' cmp #'D'
jeq print_2 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) cmp #'*' ; print home menu again if not visible (message 1 and 2 jmp to home)
jeq return_home jeq return_home
@ -147,7 +168,11 @@ print_2:
jmp home jmp home
.rodata .rodata
message_1: .asciiz " Powered by ......6502...... **** www.quintern.xyz" message_1:
.byte " Powered by "
.byte "......6502......"
.byte " **** "
.asciiz "www.quintern.xyz"
message_2: message_2:
.byte " Hello " .byte " Hello "
.byte " there " .byte " there "

View File

@ -4,7 +4,7 @@
; @device 4x4 Matrix Keypad ; @device 4x4 Matrix Keypad
; @details ; @details
; The LCD must be connected to a W65C22N Interface Chip: ; The LCD must be connected to a W65C22N Interface Chip:
; - IO.RB0-7 -> ; - IO.RA0-7 ->
; @requires KP_IO: Base Address of IO Chip ; @requires KP_IO: Base Address of IO Chip
; @depends IO-W65C22N ; @depends IO-W65C22N
;******************************************************************************** ;********************************************************************************
@ -30,22 +30,23 @@ RBUF_MEM_END = RBUF_MEM_START + KP_BUF_SIZE - 1
.proc kp_init .proc kp_init
; todo remove later and test ; todo remove later and test
lda #$ff lda #$ff
sta KP_IO+IO::DDRB sta KP_IO+IO::DDRA
stz KP_IO+IO::RB stz KP_IO+IO::RA
; INIT KEYPAD ; INIT KEYPAD
; todo: use masks ; todo: use masks
lda #%00001111; KP_IO+IO::RB 0-3 output lda #%11110000; KP_IO+IO::RA 0-3 output
sta KP_IO+IO::DDRB sta KP_IO+IO::DDRA
stz KP_IO+IO::RB ; KP_IO+IO::RB 4-7 1 so keypad press can be detected ; output 0, key press will pull input pin low
stz KP_IO+IO::RA
stz KP_IO+IO::ACR 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 ; todo: use masks
lda #IO::PCR::CB1_IP_AE lda #IO::PCR::CA1_IP_AE
sta KP_IO+IO::PCR sta KP_IO+IO::PCR
jsr rb_keypad_init ; init keybuffer 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 sta KP_IO+IO::IER
rts rts
.endproc .endproc
@ -60,23 +61,24 @@ RBUF_MEM_END = RBUF_MEM_START + KP_BUF_SIZE - 1
.proc kp_read_on_irq .proc kp_read_on_irq
; test each "row" and check which column is 1 ; test each "row" and check which column is 1
; todo dont check every column if the value has been found ; todo dont check every column if the value has been found
lda #%00001110 lda #%11100000
ldx #$00 ldx #$00
jsr @kp_read_column jsr @kp_read_column
lda #%00001101 lda #%11010000
ldx #$08 ldx #$08
jsr @kp_read_column jsr @kp_read_column
lda #%00001011 lda #%10110000
ldx #$04 ldx #$04
jsr @kp_read_column jsr @kp_read_column
lda #%00000111 lda #%01110000
ldx #$0c ldx #$0c
jsr @kp_read_column 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 rts
@kp_read_column: @kp_read_column:
sta KP_IO+IO::RB sta KP_IO+IO::RA
lda KP_IO+IO::RB lda KP_IO+IO::RA
sta _KP_COLUMN ; store result in zeropage so that bbr can be used sta _KP_COLUMN ; store result in zeropage so that bbr can be used
bbr4 _KP_COLUMN,@kp_write bbr4 _KP_COLUMN,@kp_write
inx inx

View File

@ -6,6 +6,7 @@
;******************************************************************************** ;********************************************************************************
.include "system/system.s65" .include "system/system.s65"
.include "programs/print_slow.s65"
.ifndef INCLUDE_SPI .ifndef INCLUDE_SPI
INCLUDE_SPI = 1 INCLUDE_SPI = 1
@ -14,7 +15,24 @@ INCLUDE_SPI = 1
.bss .bss
SPI_PAGES_WRITTEN: .res 1 SPI_PAGES_WRITTEN: .res 1
SPI_BYTES_WRITTEN: .res 1 SPI_BYTES_WRITTEN: .res 1
SPI_CODE_START: .res $1000 .segment "SPI"
SPI_CODE_START: ; .res $1000
lda $1000
sta $1000
lda $1000
sta $1000
lda $1000
sta $1000
lda IO1 + IO::RA
lda IO1 + IO::RA
bra SPI_CODE_START
; jsr lcd_clear
; PrintSlow msg,20
; jmp home
; msg:
; .asciiz "YO DAS WAR SPI"
.code .code
.struct SPI_P_Pins .struct SPI_P_Pins
@ -54,8 +72,9 @@ SPI_CODE_START: .res $1000
DEBUG_LED_ON 0 DEBUG_LED_ON 0
; print received byte ; print received byte
lda SPI_IO + IO::SR lda SPI_IO + IO::SR
jsr lcd_char sta SPI_CODE_START,x
inc SPI_BYTES_WRITTEN inc SPI_BYTES_WRITTEN
jsr lcd_char
rts rts
.endproc .endproc