6502-OS/programs/spi-menu.s65

132 lines
2.9 KiB
Plaintext
Raw Permalink Normal View History

2023-12-08 22:56:35 +01:00
.include "spi.h65"
.include "string.h65"
.include "keypad.h65"
.include "lcd.h65"
2023-12-16 02:41:19 +01:00
.include "chars.h65"
2023-12-08 22:56:35 +01:00
.import home:absolute
2023-12-27 16:56:14 +01:00
.import CODE_START: absolute
.import __SPI_SIZE__
2023-12-08 00:13:02 +01:00
2023-12-08 22:56:35 +01:00
.export spi_menu
2023-12-08 00:13:02 +01:00
.bss
2024-08-08 20:15:28 +02:00
trans_bytes: .res 2 ;; used to check if screen needs to be updated
2023-12-27 16:56:14 +01:00
status_char: .res 1
2024-08-08 20:15:28 +02:00
status_str: .res 17 ;; space for 16 + null
2023-12-08 00:13:02 +01:00
.code
2024-08-08 20:15:28 +02:00
;;********************************************************************************
;; @brief Receive code via SPI and execute it
;; @ingroup applications
;;********************************************************************************
2023-12-08 00:13:02 +01:00
.proc spi_menu
stz trans_bytes
2023-12-27 16:56:14 +01:00
stz trans_bytes+1
2023-12-08 00:13:02 +01:00
@print_menu:
2023-12-08 22:56:35 +01:00
jsr lcd::clear
2023-12-08 00:13:02 +01:00
Print MENU
2023-12-27 16:56:14 +01:00
@update_status:
lda spi_p::status
cmp #spi_p::STATUS::ERROR
beq @status_ERROR
cmp #spi_p::STATUS::DONE
beq @status_DONE
2023-12-31 01:58:47 +01:00
cmp #spi_p::STATUS::XFER
beq @status_XFER
cmp #spi_p::STATUS::XFER_SIZEL
beq @status_XFER_SIZEL
cmp #spi_p::STATUS::XFER_SIZEH
beq @status_XFER_SIZEH
@status_UNKNOWN:
lda #'?'
bra @update_status_end
2023-12-27 16:56:14 +01:00
@status_ERROR:
lda #'E'
bra @update_status_end
@status_DONE:
lda #'O'
bra @update_status_end
2023-12-31 01:58:47 +01:00
@status_XFER_SIZEL:
lda #'1'
bra @update_status_end
@status_XFER_SIZEH:
lda #'2'
bra @update_status_end
2023-12-27 16:56:14 +01:00
@status_XFER:
lda #'X'
@update_status_end:
sta status_char
2023-12-08 00:13:02 +01:00
@print_status:
2023-12-09 23:32:43 +01:00
lda #lcd::LINE4
jsr lcd::set_position
2023-12-31 01:58:47 +01:00
Strf "%x%x/%x%x|%x%x|%c",status_str,trans_bytes+1,trans_bytes,spi_p::recv_size+1,spi_p::recv_size,spi_p::buffer_size+1,spi_p::buffer_size,status_char
2023-12-16 02:41:19 +01:00
PrintNC status_str
2023-12-08 00:13:02 +01:00
@loop:
2023-12-31 01:58:47 +01:00
wai
2023-12-08 00:13:02 +01:00
; check if a byte has been transferred
2023-12-27 16:56:14 +01:00
@check_received:
lda spi_p::recv_bytes
2023-12-08 00:13:02 +01:00
cmp trans_bytes
2023-12-22 02:17:36 +01:00
beq @read_keypad
2023-12-27 16:56:14 +01:00
@byte_received:
2023-12-22 02:17:36 +01:00
sta trans_bytes
2023-12-27 16:56:14 +01:00
lda spi_p::recv_bytes+1
2023-12-31 01:58:47 +01:00
sta trans_bytes+1
jmp @update_status
2023-12-08 00:13:02 +01:00
@read_keypad:
2023-12-08 22:56:35 +01:00
lda kp::_DEBUG_VAL
2023-12-08 00:13:02 +01:00
beq @loop
; TODO debug
sta 0
2023-12-08 22:56:35 +01:00
stz kp::_DEBUG_VAL
2023-12-08 00:13:02 +01:00
lda 0
cmp #'*'
beq @return_home
cmp #'A'
beq @spi_begin
cmp #'B'
beq @spi_end
cmp #'C'
beq @spi_jump
2023-12-31 01:58:47 +01:00
cmp #'D'
beq @spi_jump2
jmp @update_status ; any other key
2023-12-08 00:13:02 +01:00
@spi_begin:
2023-12-27 16:56:14 +01:00
lda #<CODE_START
sta ARG0
lda #>CODE_START
sta ARG1
lda #<__SPI_SIZE__
sta ARG2
lda #>__SPI_SIZE__
sta ARG3
jsr spi_p::begin_read
2023-12-08 00:13:02 +01:00
jmp @print_menu
@spi_end:
2023-12-31 01:58:47 +01:00
jsr spi_p::end_read
2023-12-08 00:13:02 +01:00
jmp @print_menu
@spi_jump:
2023-12-31 01:58:47 +01:00
jsr spi_p::end_read
2023-12-08 22:56:35 +01:00
jsr lcd::clear
2023-12-31 01:58:47 +01:00
Print "---START SPI---"
2023-12-27 16:56:14 +01:00
jmp CODE_START
2023-12-31 01:58:47 +01:00
@spi_jump2:
jsr spi_p::end_read
jsr lcd::clear
Printf " >>> %x%x >>> ", spi_p::buffer_ptr+1, spi_p::buffer_ptr
jmp (spi_p::buffer_ptr)
2023-12-08 00:13:02 +01:00
@return_home:
2023-12-31 01:58:47 +01:00
jsr spi_p::end_read
2023-12-08 00:13:02 +01:00
jmp home
.endproc
.rodata
MENU:
2023-12-20 12:27:54 +01:00
.byte "A> Beg. Transfer"
2023-12-08 00:13:02 +01:00
.byte "B> Stop Transfer"
.asciiz "C> Jump Home <*"
; .asciiz "0b0p Status: X"
BEGIN: .asciiz "---BEGIN SPI---"
START: .asciiz "---START SPI---"