replaced str2ubyte

This commit is contained in:
Irmen de Jong
2019-01-13 13:50:44 +01:00
parent 30e6bc92e5
commit 98e95b5707
3 changed files with 107 additions and 61 deletions

View File

@@ -190,32 +190,83 @@ asmsub uword2decimal (uword value @ AY) -> clobbers(A,X,Y) -> () {
}
asmsub str2byte (str string @ AY) -> clobbers(Y) -> (byte @ A) {
%asm {{
; -- convert string (address in A/Y) to byte in A
; doesn't use any kernal routines
sta c64.SCRATCH_ZPWORD1
sty c64.SCRATCH_ZPWORD1+1
ldy #0
lda (c64.SCRATCH_ZPWORD1),y
cmp #'-'
beq +
jmp str2ubyte._enter
+ inc c64.SCRATCH_ZPWORD1
bne +
inc c64.SCRATCH_ZPWORD1+1
+ jsr str2ubyte._enter
eor #$ff
sec
adc #0
rts
}}
}
asmsub str2ubyte (str string @ AY) -> clobbers(Y) -> (ubyte @ A) {
%asm {{
; -- convert string (address in A/Y) to ubyte in A
; doesn't use any kernal routines
sta c64.SCRATCH_ZPWORD1
sty c64.SCRATCH_ZPWORD1+1
_enter jsr _numlen ; Y= slen
lda #0
dey
bpl +
rts
+ lda (c64.SCRATCH_ZPWORD1),y
sec
sbc #'0'
dey
bpl +
rts
+ sta c64.SCRATCH_ZPREG ;result
lda (c64.SCRATCH_ZPWORD1),y
sec
sbc #'0'
asl a
sta c64.SCRATCH_ZPB1
asl a
asl a
clc
adc c64.SCRATCH_ZPB1
clc
adc c64.SCRATCH_ZPREG
dey
bpl +
rts
+ sta c64.SCRATCH_ZPREG
lda (c64.SCRATCH_ZPWORD1),y
tay
lda _hundreds-'0',y
clc
adc c64.SCRATCH_ZPREG
rts
_hundreds .byte 0, 100, 200
; @todo this is python code for a str-to-ubyte function that doesn't use the basic rom:
;def str2ubyte(s, slen):
; hundreds_map = {
; 0: 0,
; 1: 100,
; 2: 200
; }
; digitvalue = 0
; result = 0
; if slen==0:
; return digitvalue
; digitvalue = ord(s[slen-1])-48
; slen -= 1
; if slen==0:
; return digitvalue
; result = digitvalue
; digitvalue = 10 * (ord(s[slen-1])-48)
; result += digitvalue
; slen -= 1
; if slen==0:
; return result
; digitvalue = hundreds_map[ord(s[slen-1])-48]
; result += digitvalue
; return result
_numlen
;-- return the length of the numeric string at ZPWORD1, in Y
ldy #0
- lda (c64.SCRATCH_ZPWORD1),y
cmp #'0'
bmi +
cmp #'9'
bpl +
iny
bne -
+ rts
}}
}
asmsub c64flt_FREADSTR (ubyte length @ A) -> clobbers(A,X,Y) -> () = $b7b5 ; @todo needed for (slow) str conversion below
@@ -269,22 +320,6 @@ asmsub str2word(str string @ AY) -> clobbers() -> (word @ AY) {
}}
}
asmsub str2ubyte(str string @ AY) -> clobbers(Y) -> (ubyte @ A) {
%asm {{
;-- convert string (address in A/Y) to ubyte number in A
; @todo don't use the (slow) kernel floating point conversion
jmp str2uword
}}
}
asmsub str2byte(str string @ AY) -> clobbers(Y) -> (byte @ A) {
%asm {{
;-- convert string (address in A/Y) to byte number in A
; @todo don't use the (slow) kernel floating point conversion
jmp str2word
}}
}
; @todo string to 32 bit unsigned integer http://www.6502.org/source/strings/ascii-to-32bit.html