6502-OS/spicode.s65

155 lines
2.7 KiB
Plaintext
Raw Normal View History

2023-12-08 22:56:35 +01:00
.include "system.h65"
2023-12-16 02:41:19 +01:00
.include "string.h65"
2023-12-08 22:56:35 +01:00
.include "lcd.h65"
.include "math.h65"
2023-12-09 23:33:42 +01:00
.include "keypad.h65"
2023-12-16 02:41:19 +01:00
.include "chars.h65"
.import homeloop:absolute
2023-12-08 22:56:35 +01:00
.import home:absolute
.segment "SPI"
.export CODE_START
CODE_START:
2023-12-09 23:33:42 +01:00
.assert * = $5000, error, "SPI Code not at $5000"
2023-12-16 02:41:19 +01:00
jsr lcd::clear
lda #'>'
2023-12-08 22:56:35 +01:00
jsr lcd::print_char
2023-12-16 02:41:19 +01:00
jsr rb_test_init
2023-12-09 23:33:42 +01:00
stz kp::_DEBUG_VAL
2023-12-16 02:41:19 +01:00
ldy #0
2023-12-09 23:33:42 +01:00
@loop:
lda kp::_DEBUG_VAL
2023-12-16 02:41:19 +01:00
pha
stz kp::_DEBUG_VAL
pla
beq @loop
cmp #'*'
jeq homeloop
cmp #'#'
beq @print
tya
pha
iny
jsr rb_test_write
pla
ora #$30
jsr lcd::print_char
2023-12-09 23:33:42 +01:00
bra @loop
2023-12-08 22:56:35 +01:00
2023-12-10 12:10:55 +01:00
2023-12-16 02:41:19 +01:00
@print:
@printloop:
lda #'r'
jsr lcd::print_char
jsr @print_state
2023-12-10 12:10:55 +01:00
2023-12-16 02:41:19 +01:00
jsr rb_test_read
beq @empty
ora #$30
jsr lcd::print_char
2023-12-08 22:56:35 +01:00
2023-12-16 02:41:19 +01:00
lda #';'
jsr lcd::print_char
2023-12-08 22:56:35 +01:00
2023-12-16 02:41:19 +01:00
bra @printloop
@empty:
lda #'E'
jsr lcd::print_char
lda #';'
jsr lcd::print_char
bra @loop
@print_state:
lda #'('
jsr lcd::print_char
lda RB_READ
ora #$30
jsr lcd::print_char
lda RB_WRITE
ora #$30
jsr lcd::print_char
lda #')'
jsr lcd::print_char
2023-12-08 22:56:35 +01:00
rts
2023-12-16 02:41:19 +01:00
2023-12-08 22:56:35 +01:00
2023-12-12 14:44:35 +01:00
2023-12-16 02:41:19 +01:00
TEST_MEMSIZE = $A
2023-12-12 14:44:35 +01:00
2023-12-16 02:41:19 +01:00
RBUF_MEM_START:
.res TEST_MEMSIZE
RBUF_MEM_END:
.define RBUF_NAME "test"
.define _RBUF_NAME .concat("rb_", RBUF_NAME)
RB_WRITE = RBUF_MEM_START ; write pointer, relative to RB_WRITE
RB_READ = RBUF_MEM_START + 1 ; read ponter, relative to RB_START
RB_START = RBUF_MEM_START + 2
RB_LENGTH = RBUF_MEM_END - RBUF_MEM_START - 2
.if RB_LENGTH < 1
.fatal "buffer size too small, must be at least 1"
.endif
.if RB_LENGTH > $ff
.fatal "buffer size too large, must be <= $ff"
.endif
; .out .sprintf("Buffer: %x -> %x (len=%x)", RBUF_MEM_START, RBUF_MEM_END, RB_LENGTH)
.proc rb_test_init
stz RB_WRITE
stz RB_READ
2023-12-12 14:44:35 +01:00
rts
.endproc
2023-12-16 02:41:19 +01:00
.proc rb_test_read
ldx RB_READ
cpx RB_WRITE
beq @rb_read_rts ; if buffer empty
lda RB_START,x
inx ; increment RB_READ pointer, not using macro bec. of unknown Pz
cpx #RB_LENGTH
beq @read_wrap
stx RB_READ
@rb_read_rts:
rts
@read_wrap: ; ptr == RB_LENGTH -> ptr = 0
stz RB_READ
; make sure Pz is not set
ldx #$01
rts
.endproc
2023-12-12 14:44:35 +01:00
2023-12-16 02:41:19 +01:00
.proc rb_test_write
; lda kp_VALUES, x ; load the char in a
ldx RB_WRITE
sta RB_START,x
inx ; increment write pointer
cpx #RB_LENGTH
beq @write_wrap
stx RB_WRITE
@check_buf_full: ; increment read if buffer is full
cpx RB_READ
beq @read_inc
rts
@write_wrap: ; ptr == RB_LENGTH -> ptr = 0
stz RB_WRITE
2023-12-12 14:44:35 +01:00
ldx #0
2023-12-16 02:41:19 +01:00
bra @check_buf_full
@read_inc:
ldx RB_READ
inx
cpx #RB_LENGTH
beq @read_wrap
stx RB_READ
rts
@read_wrap: ; ptr == RB_LENGTH -> ptr = 0
stz RB_READ
2023-12-09 23:33:42 +01:00
rts
.endproc
2023-12-08 22:56:35 +01:00