Add STRVAL

This commit is contained in:
Rikard Nordgren committed 2025-03-19 17:04:33 +01:00
1 parent 382b382847
commit 47fa7a393c
8 files changed
+75 -21

No files matched your search

+53
View File
@@ -0,0 +1,53 @@
;; #LAYOUT# STD * #TAKE
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
;; #LAYOUT# * BASIC_0 #TAKE
;; #LAYOUT# * * #IGNORE
;
; Math package - converts string to FAC1
;
; Input:
; - .A needs to be loaded with string length
; - string address in $22/$23
;
; See also:
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
; - https://www.c64-wiki.com/wiki/STRVAL
;
!ifdef CONFIG_MEMORY_MODEL_38K {
; Only supported model for now since needs CHRGOT and FIN
STRVAL:
ldx TXTPTR ; Save TXTPTR
stx FBUFPT
ldx TXTPTR+1
stx FBUFPT+1
ldx INDEX ; Move string address into TXTPTR
stx TXTPTR
ldx INDEX+1
stx TXTPTR+1
pha ; Save string length
tay
lda (INDEX),Y
sta TEMPF1 ; Save byte after string
lda #0
sta (INDEX),Y ; NULL terminate string
jsr CHRGOT
jsr FIN
pla ; Retrieve string length
tay
lda TEMPF1
sta (INDEX),Y ; Restore byte after string
ldx FBUFPT ; Restore TXTPTR
stx TXTPTR
ldx FBUFPT+1
stx TXTPTR+1
rts
}
+4
View File
@@ -0,0 +1,4 @@
This is an important floating point math routine, documented in many places.
Example code utilizing this routine:
- https://github.com/irmen/prog8/blob/master/compiler/res/prog8lib/c64flt.p8