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: _numlen
;def str2ubyte(s, slen): ;-- return the length of the numeric string at ZPWORD1, in Y
; hundreds_map = { ldy #0
; 0: 0, - lda (c64.SCRATCH_ZPWORD1),y
; 1: 100, cmp #'0'
; 2: 200 bmi +
; } cmp #'9'
; digitvalue = 0 bpl +
; result = 0 iny
; if slen==0: bne -
; return digitvalue + rts
; 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
asmsub c64flt_FREADSTR (ubyte length @ A) -> clobbers(A,X,Y) -> () = $b7b5 ; @todo needed for (slow) str conversion below 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 ; @todo string to 32 bit unsigned integer http://www.6502.org/source/strings/ascii-to-32bit.html

View File

@ -3,7 +3,7 @@
<component name="NewModuleRootManager" inherit-compiler-output="true"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" /> <orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>
</module> </module>

View File

@ -5,29 +5,40 @@
sub start() { sub start() {
c64scr.print_ub(c64utils.str2ubyte("1"))
inlinecall(1,2,3) c64.CHROUT('\n')
ubyte r = inlinesub(3,4,5) c64scr.print_ub(c64utils.str2ubyte("12"))
c64scr.print_ub(r) c64.CHROUT('\n')
c64scr.print_ub(c64utils.str2ubyte("123"))
c64.CHROUT('\n')
c64scr.print_ub(c64utils.str2ubyte("1234"))
c64.CHROUT('\n')
c64scr.print_ub(c64utils.str2ubyte("12xyz"))
c64.CHROUT('\n') c64.CHROUT('\n')
}
sub inlinecall(byte b1, byte b2, byte b3) {
float f=3.1415
c64scr.print("this is inlinecall!\n")
c64flt.print_f(f)
f*=2.0
c64flt.print_f(f)
c64.CHROUT('\n') c64.CHROUT('\n')
c64scr.print("end of inlinecall!\n")
}
sub inlinesub(ubyte b1, ubyte b2, ubyte b3) -> ubyte { c64scr.print_ub(c64utils.str2byte("1"))
c64scr.print("this is inlinesub!\n") c64.CHROUT('\n')
ubyte qq = b1+b2 c64scr.print_ub(c64utils.str2byte("12"))
qq += b3 c64.CHROUT('\n')
c64scr.print("end of inlinesub!\n") c64scr.print_ub(c64utils.str2byte("123"))
return qq c64.CHROUT('\n')
c64scr.print_ub(c64utils.str2byte("1234"))
c64.CHROUT('\n')
c64scr.print_ub(c64utils.str2ubyte("12xyz"))
c64.CHROUT('\n')
c64.CHROUT('\n')
c64scr.print_b(c64utils.str2byte("-1"))
c64.CHROUT('\n')
c64scr.print_b(c64utils.str2byte("-12"))
c64.CHROUT('\n')
c64scr.print_b(c64utils.str2byte("-123"))
c64.CHROUT('\n')
c64scr.print_b(c64utils.str2byte("-1234"))
c64.CHROUT('\n')
c64scr.print_b(c64utils.str2byte("-12xyz"))
c64.CHROUT('\n')
} }
} }