mirror of
https://github.com/irmen/prog8.git
synced 2024-11-26 11:49:22 +00:00
preparing conv.bin and hex string to number
This commit is contained in:
parent
5060f0bb19
commit
26fc5ff5e2
@ -221,7 +221,7 @@ private fun writeAssembly(programAst: Program, errors: ErrorReporter, outputDir:
|
||||
programAst.processAstBeforeAsmGeneration(errors)
|
||||
errors.handle()
|
||||
|
||||
// printAst(programAst)
|
||||
printAst(programAst) // TODO
|
||||
|
||||
CompilationTarget.instance.machine.initializeZeropage(compilerOptions)
|
||||
val assembly = CompilationTarget.instance.asmGenerator(
|
||||
|
@ -941,9 +941,13 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
||||
bne -""")
|
||||
}
|
||||
}
|
||||
"&" -> TODO("bitand (u)wordvar bytevar")
|
||||
"^" -> TODO("bitxor (u)wordvar bytevar")
|
||||
"|" -> TODO("bitor (u)wordvar bytevar")
|
||||
"&" -> {
|
||||
asmgen.out(" lda $otherName | and $name | sta $name")
|
||||
if(dt in WordDatatypes)
|
||||
asmgen.out(" lda #0 | sta $name+1")
|
||||
}
|
||||
"^" -> asmgen.out(" lda $otherName | eor $name | sta $name")
|
||||
"|" -> asmgen.out(" lda $otherName | ora $name | sta $name")
|
||||
else -> throw AssemblyError("invalid operator for in-place modification $operator")
|
||||
}
|
||||
}
|
||||
@ -1164,7 +1168,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
||||
remainderWord()
|
||||
}
|
||||
"<<" -> {
|
||||
asmgen.translateExpression(value)
|
||||
asmgen.translateExpression(value) // TODO huh is this okay? wasn't this done above already?
|
||||
asmgen.out("""
|
||||
inx
|
||||
ldy P8ESTACK_LO,x
|
||||
@ -1176,7 +1180,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
||||
+""")
|
||||
}
|
||||
">>" -> {
|
||||
asmgen.translateExpression(value)
|
||||
asmgen.translateExpression(value) // TODO huh is this okay? wasn't this done above already?
|
||||
if(dt==DataType.UWORD) {
|
||||
asmgen.out("""
|
||||
inx
|
||||
@ -1201,9 +1205,13 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
||||
+""")
|
||||
}
|
||||
}
|
||||
"&" -> TODO("bitand (u)word (u)byte on stack")
|
||||
"^" -> TODO("bitxor (u)word (u)byte on stack")
|
||||
"|" -> TODO("bitor (u)word (u)byte on stack")
|
||||
"&" -> {
|
||||
asmgen.out(" lda P8ESTACK_LO+1,x | and $name | sta $name")
|
||||
if(dt in WordDatatypes)
|
||||
asmgen.out(" lda #0 | sta $name+1")
|
||||
}
|
||||
"^" -> asmgen.out(" lda P8ESTACK_LO+1,x | eor $name | sta $name")
|
||||
"|" -> asmgen.out(" lda P8ESTACK_LO+1,x | ora $name | sta $name")
|
||||
else -> throw AssemblyError("invalid operator for in-place modification $operator")
|
||||
}
|
||||
}
|
||||
|
102
examples/test.p8
102
examples/test.p8
@ -6,36 +6,38 @@ main {
|
||||
|
||||
sub start() {
|
||||
|
||||
str num1 = "01234"
|
||||
str num2 = @"01234"
|
||||
str hex1 = "a04E"
|
||||
str hex2 = "$a04E"
|
||||
str hex3 = @"a04E"
|
||||
str hex4 = @"$a04E"
|
||||
str hex1 = "a4E"
|
||||
str hex2 = "$a4E"
|
||||
str hex3 = @"a4E"
|
||||
str hex4 = @"$a4E"
|
||||
str bin1 = "111111010010"
|
||||
str bin2 = "%111111010010"
|
||||
|
||||
; txt.print(num1)
|
||||
; txt.chrout('\n')
|
||||
; txt.print(num2)
|
||||
; txt.chrout('\n')
|
||||
; txt.print(hex1)
|
||||
; txt.chrout('\n')
|
||||
; txt.print(hex2)
|
||||
; txt.chrout('\n')
|
||||
; txt.print(hex3)
|
||||
; txt.chrout('\n')
|
||||
; txt.print(hex4)
|
||||
; txt.chrout('\n')
|
||||
txt.print(hex1)
|
||||
txt.chrout('=')
|
||||
txt.print_uwhex(conv2.hex2uword(hex1), true)
|
||||
txt.chrout('\n')
|
||||
txt.print(hex2)
|
||||
txt.chrout('=')
|
||||
txt.print_uwhex(conv2.hex2uword(hex2), true)
|
||||
txt.chrout('\n')
|
||||
txt.print(hex3)
|
||||
txt.chrout('=')
|
||||
txt.print_uwhex(conv2.hex2uword(hex3), true)
|
||||
txt.chrout('\n')
|
||||
txt.print(hex4)
|
||||
txt.chrout('=')
|
||||
txt.print_uwhex(conv2.hex2uword(hex4), true)
|
||||
txt.chrout('\n')
|
||||
txt.print(bin1)
|
||||
txt.chrout('=')
|
||||
txt.print_uwbin(conv2.bin2uword(bin1), true)
|
||||
txt.chrout('\n')
|
||||
txt.print(bin2)
|
||||
txt.chrout('=')
|
||||
txt.print_uwbin(conv2.bin2uword(bin2), true)
|
||||
txt.chrout('\n')
|
||||
|
||||
ubyte cc
|
||||
for cc in 0 to len(hex3)-1 {
|
||||
@($0410+cc) = hex3[cc]
|
||||
txt.setchr(16+cc,2,hex3[cc])
|
||||
}
|
||||
|
||||
for cc in 0 to len(hex4)-1 {
|
||||
@($0420+cc) = hex4[cc]
|
||||
txt.setchr(32+cc,2,hex4[cc])
|
||||
}
|
||||
|
||||
testX()
|
||||
}
|
||||
@ -55,3 +57,47 @@ _saveX .byte 0
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
conv2 {
|
||||
|
||||
sub hex2uword(uword strptr) -> uword {
|
||||
uword result = 0
|
||||
while @(strptr) {
|
||||
if @(strptr)!='$' {
|
||||
ubyte add = 0
|
||||
if @(strptr) <= 6 or @(strptr) > '9'
|
||||
add = 9
|
||||
result = (result << 4) | (add + @(strptr) & $0f)
|
||||
}
|
||||
strptr++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
asmsub bin2uword(uword strptr @AY) -> uword @AY {
|
||||
%asm {{
|
||||
sta P8ZP_SCRATCH_W2
|
||||
sty P8ZP_SCRATCH_W2+1
|
||||
ldy #0
|
||||
sty P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
_loop lda (P8ZP_SCRATCH_W2),y
|
||||
beq _stop
|
||||
cmp #'%'
|
||||
beq +
|
||||
asl P8ZP_SCRATCH_W1
|
||||
rol P8ZP_SCRATCH_W1+1
|
||||
and #1
|
||||
ora P8ZP_SCRATCH_W1
|
||||
sta P8ZP_SCRATCH_W1
|
||||
+ inc P8ZP_SCRATCH_W2
|
||||
bne _loop
|
||||
inc P8ZP_SCRATCH_W2+1
|
||||
bne _loop
|
||||
_stop lda P8ZP_SCRATCH_W1
|
||||
ldy P8ZP_SCRATCH_W1+1
|
||||
rts
|
||||
}}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user