This commit is contained in:
matthias@arch 2023-12-09 23:33:42 +01:00
parent e9c9f978a2
commit 2c41506765

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
;********************************************************************************
; @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
HEX_CHARS: .byte "0123456789ABCDEF"
TEST_FMT: .asciiz "%x -> %x -> %x:)"
TEST_OUT: .asciiz "TESTOUT"
HEX_CHARS_UPPER: .byte "0123456789ABCDEF"
HEX_CHARS_LOWER: .byte "0123456789abcdef"