Compare commits

...

4 Commits

Author SHA1 Message Date
2c41506765 wip 2023-12-09 23:33:42 +01:00
e9c9f978a2 fix import 2023-12-09 23:33:22 +01:00
151e57e9be fix setline 2023-12-09 23:33:15 +01:00
3c09810aa8 fix setline 2023-12-09 23:32:43 +01:00
4 changed files with 87 additions and 53 deletions

View File

@ -23,8 +23,8 @@ status_str: .res 17 ; 16 + null
Print MENU
@print_status:
Strf FMT_STATUS,status_str,trans_pages,trans_bytes,status
lda #(lcd::CMD_SET_ADDRESS | lcd::LINE4)
jsr lcd::_cmd
lda #lcd::LINE4
jsr lcd::set_position
Print status_str
@loop:
; check if a byte has been transferred
@ -39,11 +39,11 @@ status_str: .res 17 ; 16 + null
bra @read_keypad
@byte_written:
sta trans_bytes
bra @print_status
; bra @print_status
bra @read_keypad
@page_written:
sta trans_pages
bra @print_status
@read_keypad:
lda kp::_DEBUG_VAL
beq @loop

View File

@ -1,12 +1,13 @@
.include "system.h65"
.include "lcd.h65"
.include "math.h65"
.include "keypad.h65"
.import home:absolute
.segment "SPI"
.export CODE_START
Export
CODE_START:
.assert * = $5000, error, "SPI Code not at $5000"
lda '$'
jsr lcd::print_char
lda #<TEST_FMT
@ -25,45 +26,17 @@ CODE_START:
sta ARG6
jsr strf
Print TEST_OUT
@spiloop:
bbs4 ASDA,dasdZQ
lda IO1 + IO::RA
lda IO2 + IO::RA
jeq @spiloop
bge @spiloop
nop
bra @spiloop
bro @spiloop
jmp home
lda €asdaasd
lda €$ff
lds €asda
stz kp::_DEBUG_VAL
@loop:
lda kp::_DEBUG_VAL
jeq home
bra @loop
lds #($ff | asd)
lda #'c'
lda #(jk:)
; TODO allocate zp memory
fmt_idx = $30
out_idx = $31
;********************************************************************************
; @function Format a string
; @details
; If there is no value to be read, the Pz will be set
; Formats:
; - u: unsigned decimal integer (1 byte)
; - U: unsigned decimal integer (2 bytes)
; @param ARG0-1: Format string address
; @param ARG2-3: Output string address
; @param ARG4+: Additional parameters
; @returns
; @modifies: A, Y
;********************************************************************************
.proc strf
stz out_idx
stz fmt_idx
ldy #0 ; position in string
ldx #0 ; index of format args
@loop:
ldy fmt_idx
@ -81,7 +54,7 @@ out_idx = $31
@percent: ; check for format in next position
iny
sty fmt_idx
lda (ARG0),y
lda (ARG0),y ; next char
beq @null
; formats
cmp #'x'
@ -124,26 +97,68 @@ out_idx = $31
; @param A: Number to convert
; @returns A: Most significant digit
; @returns X: Least significant digit
; @modifies X,Y,A
; @modifies A,X,Y
;********************************************************************************
.proc int8_to_hex_str
pha
and #%00001111
tay
ldx HEX_CHARS,y
ldx HEX_CHARS_UPPER,y
pla
div A,16
and #%00001111
tay
lda HEX_CHARS,y
lda HEX_CHARS_UPPER,y
rts
.endproc
HEX_CHARS: .byte "0123456789ABCDEF"
;********************************************************************************
; @function Convert any int into hex
; @param ARG2-3: Address of output string
; @param Y: Offset onto output string
; @param A: Number of digits to convert
; @param X: Offset onto ARG4 = start of int (big endian)
; @returns Y: New offset onto output string
; @returns A: 0
; @returns X: Offset onto ARG4 = past the end of number
; @modifies X,Y,A
;********************************************************************************
.proc int_to_hex_str
cmp #0
@loop:
beq @rts ; check done
; load next byte
pha
lda ARG4,x
inx
phx
pha ; copy byte
div A,16 ; get first 4 bits = first digit
and #%00001111
phy
tay
lda HEX_CHARS_LOWER,y
ply
sta (ARG2),y
iny
pla ; get copy
and #%00001111 ; lower 4 bits = second digit
phy
tay
lda HEX_CHARS_LOWER,y
ply
sta (ARG2),y
iny
plx
pla
dec
@rts:
rts
.endproc
TEST_FMT: .asciiz "%x -> %x -> %x:)"
TEST_OUT: .asciiz "TESTOUT"
HEX_CHARS_UPPER: .byte "0123456789ABCDEF"
HEX_CHARS_LOWER: .byte "0123456789abcdef"

View File

@ -20,7 +20,7 @@ INCLUDE_LCD = 1
.scope lcd
LCD_IO = IO1
Import lcd,init,clear,print,print_char,_cmd
Import lcd,init,clear,print,print_char,set_position
;********************************************************************************
; @macro Print a null-terminated string

View File

@ -152,14 +152,33 @@ charcount: .res 1
;; @returns A: the cursor position
;;********************************************************************************
.proc set_position
cmp #$40
bge @invalid
sta charcount
pha
cmp #$60
bge @invalid
cmp #$50
bge @line4
cmp #$40
bge @line2
cmp #$20
bge @invalid
cmp #$10
bge @line3
bra @set
; @line1: ; starts at $00, charcount at $00
@line2: ; starts at $40, charcount at $10
sbc #$30 ; carry is already set
bra @set
@line3: ; starts at $10, charcount at $20
add #$10
bra @set
@line4: ; starts at $50, charcount at $30
sbc #$20
@set:
sta charcount
pla
ora #lcd::CMD_SET_ADDRESS
jsr _cmd
pla
@rts:
and #(<~lcd::CMD_SET_ADDRESS) ; return original argument
rts
@invalid:
lda $14
@ -167,7 +186,7 @@ charcount: .res 1
lda #(lcd::CMD_SET_ADDRESS | (lcd::LINE2 + 4))
jsr _cmd
lda #(lcd::LINE2 + 4)
bra @rts
rts
.endproc