implemented last remaining codegen for word-byte division and remainders.

This commit is contained in:
Irmen de Jong 2021-03-25 22:02:45 +01:00
parent d840975054
commit 4cae2c56ec
3 changed files with 38 additions and 45 deletions

View File

@ -1 +1 @@
6.4-SNAPSHOT 6.4

View File

@ -1051,20 +1051,47 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
} }
"/" -> { "/" -> {
if(dt==DataType.UWORD) { if(dt==DataType.UWORD) {
TODO("uwordvar / bytevar") asmgen.out("""
lda $name
ldy $name+1
sta P8ZP_SCRATCH_W1
sty P8ZP_SCRATCH_W1+1
lda $otherName
ldy #0
jsr math.divmod_uw_asm
sta $name
sty $name+1
""")
} else { } else {
TODO("wordvar / bytevar") asmgen.out("""
lda $name
ldy $name+1
sta P8ZP_SCRATCH_W1
sty P8ZP_SCRATCH_W1+1
lda $otherName
ldy #0
jsr math.divmod_w_asm
sta $name
sty $name+1
""")
} }
} }
"%" -> { "%" -> {
if(valueDt!=DataType.UBYTE || dt!=DataType.UWORD) if(valueDt!=DataType.UBYTE || dt!=DataType.UWORD)
throw AssemblyError("% expects unsigned operands") throw AssemblyError("remainder of signed integers is not properly defined/implemented, use unsigned instead")
if(dt==DataType.UWORD) { asmgen.out("""
TODO("uwordvar % ubytevar") lda $name
} else { ldy $name+1
TODO("wordvar % ubytevar") sta P8ZP_SCRATCH_W1
} sty P8ZP_SCRATCH_W1+1
} lda $otherName
ldy #0
jsr math.divmod_uw_asm
lda P8ZP_SCRATCH_W2
sta $name
lda P8ZP_SCRATCH_W2+1
sta $name+1
""") }
"<<" -> { "<<" -> {
asmgen.out(""" asmgen.out("""
ldy $otherName ldy $otherName

View File

@ -5,41 +5,7 @@ main {
sub start() { sub start() {
word wvar txt.print("hello")
word wvar2
uword uwvar
uword uwvar2
byte bvar
byte bvar2
ubyte ubvar
uwvar result
uwvar = 49999
uwvar2 = 1234
result = uwvar / uwvar2
txt.print_uw(result)
result = uwvar % uwvar2
txt.print_uw(result)
; uwvar %= uwvar2
; wvar /= bvar
; uwvar /= bvar
; uwvar %= ubvar
; ubyte[] array = [1,2,3,4]
; ubyte ix
;
; ubyte a = array[1] + array[ix]
; a = array[ix] + array[ix]
; a = array[ix+1] + array[ix]
; uword multiple=0
; a = array[lsb(multiple)] + array[ix]
; str filename = "titlescreen.bin" ; str filename = "titlescreen.bin"
; ubyte success = cx16.vload(filename, 8, 0, $0000) ; ubyte success = cx16.vload(filename, 8, 0, $0000)