mirror of
https://github.com/irmen/prog8.git
synced 2024-11-19 11:32:17 +00:00
replaced str2ubyte
This commit is contained in:
parent
30e6bc92e5
commit
98e95b5707
@ -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
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -5,29 +5,40 @@
|
||||
|
||||
sub start() {
|
||||
|
||||
|
||||
inlinecall(1,2,3)
|
||||
ubyte r = inlinesub(3,4,5)
|
||||
c64scr.print_ub(r)
|
||||
c64scr.print_ub(c64utils.str2ubyte("1"))
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_ub(c64utils.str2ubyte("12"))
|
||||
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')
|
||||
}
|
||||
|
||||
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')
|
||||
c64scr.print("end of inlinecall!\n")
|
||||
}
|
||||
|
||||
sub inlinesub(ubyte b1, ubyte b2, ubyte b3) -> ubyte {
|
||||
c64scr.print("this is inlinesub!\n")
|
||||
ubyte qq = b1+b2
|
||||
qq += b3
|
||||
c64scr.print("end of inlinesub!\n")
|
||||
return qq
|
||||
c64scr.print_ub(c64utils.str2byte("1"))
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_ub(c64utils.str2byte("12"))
|
||||
c64.CHROUT('\n')
|
||||
c64scr.print_ub(c64utils.str2byte("123"))
|
||||
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')
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user