mirror of
https://github.com/irmen/prog8.git
synced 2024-09-07 19:54:26 +00:00
assignments
This commit is contained in:
parent
d6432df90d
commit
783db2f88b
@ -350,6 +350,65 @@ byte_assignment_to_bytearray:
|
||||
; barr1[ubarr2[X]] = barr2[ubarr1[Y]] ; todo via evaluation-- check generated asm...
|
||||
|
||||
|
||||
byte_assignment_to_membytearray:
|
||||
|
||||
mbarr1[3] = 42
|
||||
mbarr1[3] = b2
|
||||
mbarr1[3] = mbyte2
|
||||
mbarr1[3] = barr1[2]
|
||||
mbarr1[3] = barr1[X]
|
||||
mbarr1[3] = barr1[b]
|
||||
mbarr1[3] = barr1[ub]
|
||||
mbarr1[3] = barr1[mbyte2]
|
||||
mbarr1[3] = barr1[mubyte2]
|
||||
|
||||
mbarr1[Y] = 42
|
||||
mbarr1[Y] = b2
|
||||
mbarr1[Y] = mbyte2
|
||||
mbarr1[Y] = barr1[2]
|
||||
mbarr1[Y] = barr1[X]
|
||||
mbarr1[Y] = barr1[b]
|
||||
mbarr1[Y] = barr1[ub]
|
||||
mbarr1[Y] = barr1[mbyte2]
|
||||
mbarr1[Y] = barr1[mubyte2]
|
||||
|
||||
mbarr1[b2] = 42
|
||||
mbarr1[b2] = b2
|
||||
mbarr1[b2] = mbyte2
|
||||
mbarr1[b2] = barr1[2]
|
||||
mbarr1[b2] = barr1[X]
|
||||
mbarr1[b2] = barr1[b]
|
||||
mbarr1[b2] = barr1[ub]
|
||||
mbarr1[b2] = barr1[mbyte2]
|
||||
mbarr1[b2] = barr1[mubyte2]
|
||||
|
||||
mbarr1[ub2] = 42
|
||||
mbarr1[ub2] = b2
|
||||
mbarr1[ub2] = mbyte2
|
||||
mbarr1[ub2] = barr1[2]
|
||||
mbarr1[ub2] = barr1[X]
|
||||
mbarr1[ub2] = barr1[b]
|
||||
mbarr1[ub2] = barr1[ub]
|
||||
mbarr1[ub2] = barr1[mbyte2]
|
||||
mbarr1[ub2] = barr1[mubyte2]
|
||||
|
||||
mbarr1[mubyte2] = 42
|
||||
mbarr1[mubyte2] = b2
|
||||
mbarr1[mubyte2] = mbyte2
|
||||
mbarr1[mubyte2] = barr1[2]
|
||||
|
||||
; mbarr1[mubyte2] = string[X] ;;todo via evaluation
|
||||
; mbarr1[mubyte2] = string[b] ;todo via evaluation
|
||||
; mbarr1[mubyte2] = string[ub] ;todo via evaluation
|
||||
; mbarr1[mubyte2] = string[mbyte2] ;todo via evaluation
|
||||
; mbarr1[mubyte2] = string[mubyte2] ;todo via evaluation
|
||||
; mbarr1[mubyte2] = ubarr1[X] ;todo via evaluation
|
||||
; mbarr1[mubyte2] = ubarr1[b] ;todo via evaluation
|
||||
; mbarr1[mubyte2] = ubarr1[ub] ;todo via evaluation
|
||||
; mbarr1[mubyte2] = ubarr1[mbyte2] ;todo via evaluation
|
||||
; mbarr1[mubyte2] = ubarr1[mubyte2] ;todo via evaluation
|
||||
; mbarr1[ubarr2[X]] = barr2[ubarr1[Y]] ; todo via evaluation-- check generated asm...
|
||||
|
||||
|
||||
|
||||
|
||||
@ -368,21 +427,21 @@ uword_assignment_to_uwordvar:
|
||||
uw = string[4]
|
||||
uw = ubarr1[2]
|
||||
uw = uwarr1[2]
|
||||
;uw = string[X] ; todo via evaluation
|
||||
;uw = string[b] ; todo via evaluation
|
||||
;uw = string[ub] ; todo via evaluation
|
||||
;uw = string[mbyte2] ; todo via evaluation
|
||||
;uw = string[mubyte2] ; todo via evaluation
|
||||
; uw = ubarr1[X] ;; todo via evaluation
|
||||
; uw = ubarr1[b] ;; todo via evaluation
|
||||
; uw = ubarr1[ub] ; todo via evaluation
|
||||
; uw = ubarr1[mbyte2] ; todo via evaluation
|
||||
; uw = ubarr1[mubyte2] ; todo via evaluation
|
||||
; uw = uwarr1[X] ; todo via evaluation
|
||||
; uw = uwarr1[b] ; todo via evaluation
|
||||
; uw = uwarr1[ub] ; todo via evaluation
|
||||
; uw = uwarr1[mbyte2] ; todo via evaluation
|
||||
; uw = uwarr1[mubyte2] ; todo via evaluation
|
||||
uw = string[X]
|
||||
uw = string[b]
|
||||
uw = string[ub]
|
||||
uw = string[mbyte2]
|
||||
uw = string[mubyte2]
|
||||
uw = ubarr1[X]
|
||||
uw = ubarr1[b]
|
||||
uw = ubarr1[ub]
|
||||
uw = ubarr1[mbyte2]
|
||||
uw = ubarr1[mubyte2]
|
||||
uw = uwarr1[X]
|
||||
uw = uwarr1[b]
|
||||
uw = uwarr1[ub]
|
||||
uw = uwarr1[mbyte2]
|
||||
uw = uwarr1[mubyte2]
|
||||
|
||||
|
||||
uword_assignment_to_uwordmem:
|
||||
@ -397,21 +456,21 @@ uword_assignment_to_uwordmem:
|
||||
muword = string[4]
|
||||
muword = ubarr1[2]
|
||||
muword = uwarr1[2]
|
||||
; muword = string[X] ; todo via evaluation
|
||||
; muword = string[b] ; todo via evaluation
|
||||
; muword = string[ub] ; todo via evaluation
|
||||
; muword = string[mbyte2] ; todo via evaluation
|
||||
; muword = string[mubyte2] ; todo via evaluation
|
||||
; muword = ubarr1[X] ; todo via evaluation
|
||||
; muword = ubarr1[b] ; todo via evaluation
|
||||
; muword = ubarr1[ub] ; todo via evaluation
|
||||
; muword = ubarr1[mbyte2] ; todo via evaluation
|
||||
; muword = ubarr1[mubyte2] ; todo via evaluation
|
||||
; muword = uwarr1[X] ; todo via evaluation
|
||||
; muword = uwarr1[b] ; todo via evaluation
|
||||
; muword = uwarr1[ub] ; todo via evaluation
|
||||
; muword = uwarr1[mbyte2] ; todo via evaluation
|
||||
; muword = uwarr1[mubyte2] ; todo via evaluation
|
||||
; muword = string[X]
|
||||
; muword = string[b]
|
||||
; muword = string[ub]
|
||||
; muword = string[mbyte2]
|
||||
; muword = string[mubyte2]
|
||||
; muword = ubarr1[X]
|
||||
; muword = ubarr1[b]
|
||||
; muword = ubarr1[ub]
|
||||
; muword = ubarr1[mbyte2]
|
||||
; muword = ubarr1[mubyte2]
|
||||
; muword = uwarr1[X]
|
||||
; muword = uwarr1[b]
|
||||
; muword = uwarr1[ub]
|
||||
; muword = uwarr1[mbyte2]
|
||||
; muword = uwarr1[mubyte2]
|
||||
|
||||
|
||||
uword_assignment_to_uwordarray:
|
||||
@ -521,26 +580,29 @@ word_assignment_to_wordvar:
|
||||
w = barr1[2]
|
||||
w = warr1[2]
|
||||
|
||||
; w = string[X] ; todo via evaluation
|
||||
; w = string[b] ; todo via evaluation
|
||||
; w = string[ub] ; todo via evaluation
|
||||
; w = string[mbyte2] ; todo via evaluation
|
||||
; w = string[mubyte2] ; todo via evaluation
|
||||
; w = barr1[X] ;; todo via evaluation
|
||||
; w = ubarr1[X] ;; todo via evaluation
|
||||
; w = barr1[b] ;; todo via evaluation
|
||||
; w = ubarr1[b] ;; todo via evaluation
|
||||
; w = barr1[ub] ; todo via evaluation
|
||||
; w = ubarr1[ub] ; todo via evaluation
|
||||
; w = barr1[mbyte2] ; todo via evaluation
|
||||
; w = ubarr1[mbyte2] ; todo via evaluation
|
||||
; w = barr1[mubyte2] ; todo via evaluation
|
||||
; w = ubarr1[mubyte2] ; todo via evaluation
|
||||
; w = warr1[X] ; todo via evaluation
|
||||
; w = warr1[b] ; todo via evaluation
|
||||
; w = warr1[ub] ; todo via evaluation
|
||||
; w = warr1[mbyte2] ; todo via evaluation
|
||||
; w = warr1[mubyte2] ; todo via evaluation
|
||||
w = string[X]
|
||||
w = string[b]
|
||||
w = string[ub]
|
||||
w = string[mbyte2]
|
||||
w = string[mubyte2]
|
||||
|
||||
|
||||
; @todo these:
|
||||
w = barr1[X]
|
||||
w = ubarr1[X]
|
||||
w = barr1[b]
|
||||
w = ubarr1[b]
|
||||
w = barr1[ub]
|
||||
w = ubarr1[ub]
|
||||
w = barr1[mbyte2]
|
||||
w = ubarr1[mbyte2]
|
||||
w = barr1[mubyte2]
|
||||
w = ubarr1[mubyte2]
|
||||
w = warr1[X]
|
||||
w = warr1[b]
|
||||
w = warr1[ub]
|
||||
w = warr1[mbyte2]
|
||||
w = warr1[mubyte2]
|
||||
|
||||
|
||||
word_assignment_to_wordmem:
|
||||
@ -559,26 +621,31 @@ word_assignment_to_wordmem:
|
||||
mword = barr1[2]
|
||||
mword = warr1[2]
|
||||
|
||||
; mword = string[X] ; todo via evaluation
|
||||
; mword = string[b] ; todo via evaluation
|
||||
; mword = string[ub] ; todo via evaluation
|
||||
; mword = string[mbyte2] ; todo via evaluation
|
||||
; mword = string[mubyte2] ; todo via evaluation
|
||||
; mword = barr1[X] ;; todo via evaluation
|
||||
; mword = ubarr1[X] ;; todo via evaluation
|
||||
; mword = barr1[b] ;; todo via evaluation
|
||||
; mword = ubarr1[b] ;; todo via evaluation
|
||||
; mword = barr1[ub] ; todo via evaluation
|
||||
; mword = ubarr1[ub] ; todo via evaluation
|
||||
; mword = barr1[mbyte2] ; todo via evaluation
|
||||
; mword = ubarr1[mbyte2] ; todo via evaluation
|
||||
; mword = barr1[mubyte2] ; todo via evaluation
|
||||
; mword = ubarr1[mubyte2] ; todo via evaluation
|
||||
; mword = warr1[X] ; todo via evaluation
|
||||
; mword = warr1[b] ; todo via evaluation
|
||||
; mword = warr1[ub] ; todo via evaluation
|
||||
; mword = warr1[mbyte2] ; todo via evaluation
|
||||
; mword = warr1[mubyte2] ; todo via evaluation
|
||||
|
||||
; @todo these:
|
||||
mword = string[X]
|
||||
mword = string[b]
|
||||
mword = string[ub]
|
||||
mword = string[mbyte2]
|
||||
mword = string[mubyte2]
|
||||
mword = barr1[X]
|
||||
mword = ubarr1[X]
|
||||
mword = barr1[b]
|
||||
mword = ubarr1[b]
|
||||
mword = barr1[ub]
|
||||
mword = ubarr1[ub]
|
||||
mword = barr1[mbyte2]
|
||||
mword = ubarr1[mbyte2]
|
||||
mword = barr1[mubyte2]
|
||||
mword = ubarr1[mubyte2]
|
||||
mword = warr1[X]
|
||||
mword = warr1[b]
|
||||
mword = warr1[ub]
|
||||
mword = warr1[mbyte2]
|
||||
mword = warr1[mubyte2]
|
||||
|
||||
|
||||
; @todo assignment to word array
|
||||
|
||||
|
||||
;; all possible assignments to a FLOAT VARIABLE
|
||||
|
@ -693,8 +693,7 @@ data class AssignTarget(val register: Register?,
|
||||
if(dt!=null)
|
||||
return dt
|
||||
}
|
||||
|
||||
throw FatalAstException("cannot determine datatype of assignment target $this")
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
@ -897,7 +896,7 @@ class ArrayIndexedExpression(val identifier: IdentifierReference?,
|
||||
else -> throw FatalAstException("invalid dt")
|
||||
}
|
||||
}
|
||||
throw FatalAstException("cannot get indexed element on $target")
|
||||
return null
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
|
@ -768,15 +768,15 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
when(indexVar) {
|
||||
"X" -> {
|
||||
loadX = ""
|
||||
loadXWord = " txa | asl a | tax |"
|
||||
loadXWord = " txa | asl a | tax |"
|
||||
}
|
||||
"Y" -> {
|
||||
loadX = " tya | tax |"
|
||||
loadXWord = " tya | asl a | tax |"
|
||||
loadXWord = " tya | asl a | tax |"
|
||||
}
|
||||
"A" -> {
|
||||
loadX = " tax |"
|
||||
loadXWord = " asl a | tax |"
|
||||
loadXWord = " asl a | tax |"
|
||||
}
|
||||
else -> {
|
||||
// the indexvar is a real variable, not a register
|
||||
@ -912,6 +912,52 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAYFromWordIndexedByVar(idxVarInstr: Instruction, readArrayInstr: Instruction): String {
|
||||
// AY = readWordArrayInstr [ idxVarInstr ]
|
||||
return when(idxVarInstr.callLabel) {
|
||||
"A" ->
|
||||
"""
|
||||
stx ${C64Zeropage.SCRATCH_B1}
|
||||
asl a
|
||||
tax
|
||||
lda ${readArrayInstr.callLabel},x
|
||||
ldy ${readArrayInstr.callLabel}+1,x
|
||||
ldx ${C64Zeropage.SCRATCH_B1}
|
||||
"""
|
||||
"X" ->
|
||||
"""
|
||||
stx ${C64Zeropage.SCRATCH_B1}
|
||||
txa
|
||||
asl a
|
||||
tax
|
||||
lda ${readArrayInstr.callLabel},x
|
||||
ldy ${readArrayInstr.callLabel}+1,x
|
||||
ldx ${C64Zeropage.SCRATCH_B1}
|
||||
"""
|
||||
"Y" ->
|
||||
"""
|
||||
stx ${C64Zeropage.SCRATCH_B1}
|
||||
tya
|
||||
asl a
|
||||
tax
|
||||
lda ${readArrayInstr.callLabel},x
|
||||
ldy ${readArrayInstr.callLabel}+1,x
|
||||
ldx ${C64Zeropage.SCRATCH_B1}
|
||||
"""
|
||||
else ->
|
||||
"""
|
||||
stx ${C64Zeropage.SCRATCH_B1}
|
||||
lda ${idxVarInstr.callLabel}
|
||||
asl a
|
||||
tax
|
||||
lda ${readArrayInstr.callLabel},x
|
||||
ldy ${readArrayInstr.callLabel}+1,x
|
||||
ldx ${C64Zeropage.SCRATCH_B1}
|
||||
"""
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun storeAToIndexedByVar(idxVarInstr: Instruction, writeArrayInstr: Instruction): String {
|
||||
// writeArrayInstr [ idxVarInstr ] = A
|
||||
return when (idxVarInstr.callLabel) {
|
||||
@ -924,20 +970,20 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
|
||||
private val patterns = listOf(
|
||||
// -------------- simple conversions ----------------
|
||||
// convert ubyte to uword
|
||||
AsmPattern(listOf(Opcode.UB2UWORD, Opcode.POP_VAR_WORD)) {
|
||||
" lda #0 | sta ${ESTACK_HI+1},x"
|
||||
},
|
||||
// convert byte to word (sign extended)
|
||||
AsmPattern(listOf(Opcode.B2WORD, Opcode.POP_VAR_WORD)) {
|
||||
"""
|
||||
lda ${ESTACK_LO+1},x
|
||||
ora #${'$'}7f
|
||||
bmi +
|
||||
lda #0
|
||||
+ sta ${ESTACK_HI+1},x
|
||||
"""
|
||||
},
|
||||
// // convert ubyte to uword
|
||||
// AsmPattern(listOf(Opcode.UB2UWORD, Opcode.POP_VAR_WORD)) {
|
||||
// " lda #0 | sta ${ESTACK_HI+1},x"
|
||||
// },
|
||||
// // convert byte to word (sign extended)
|
||||
// AsmPattern(listOf(Opcode.B2WORD, Opcode.POP_VAR_WORD)) {
|
||||
// """
|
||||
// lda ${ESTACK_LO+1},x
|
||||
// ora #${'$'}7f
|
||||
// bmi +
|
||||
// lda #0
|
||||
//+ sta ${ESTACK_HI+1},x
|
||||
// """
|
||||
// },
|
||||
|
||||
|
||||
// ----------- push value from array on the stack -------------
|
||||
@ -1280,11 +1326,50 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
val index = segment[0].arg!!.integerValue().toHex()
|
||||
" lda ${segment[1].callLabel}+$index | sta ${segment[3].callLabel} | lda #0 | sta ${segment[3].callLabel}+1"
|
||||
},
|
||||
// var = ubytearray[index var]
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.UB2UWORD, Opcode.POP_VAR_WORD)) { segment ->
|
||||
val loadA = loadAFromIndexedByVar(segment[0], segment[1])
|
||||
" $loadA | sta ${segment[3].callLabel} | lda #0 | sta ${segment[3].callLabel}+1"
|
||||
},
|
||||
// var = ubytearray[index mem]
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.UB2UWORD, Opcode.POP_VAR_WORD),
|
||||
listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.UB2UWORD, Opcode.POP_VAR_WORD)) { segment ->
|
||||
"""
|
||||
lda ${segment[0].arg!!.integerValue().toHex()}
|
||||
sta ${segment[3].callLabel}
|
||||
lda #0
|
||||
sta ${segment[3].callLabel}+1
|
||||
"""
|
||||
},
|
||||
// var = (u)wordarray[index_byte]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_VAR_WORD)) { segment ->
|
||||
val index = segment[0].arg!!.integerValue()*2
|
||||
" lda ${segment[1].callLabel}+$index | sta ${segment[2].callLabel} | lda ${segment[1].callLabel}+${index+1} | sta ${segment[2].callLabel}+1"
|
||||
},
|
||||
// var = (u)wordarray[index var]
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_VAR_WORD)) { segment ->
|
||||
val loadAY = loadAYFromWordIndexedByVar(segment[0], segment[1])
|
||||
"""
|
||||
$loadAY
|
||||
sta ${segment[2].callLabel}
|
||||
sty ${segment[2].callLabel}+1
|
||||
"""
|
||||
},
|
||||
// var = (u)wordarray[index mem]
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_VAR_WORD),
|
||||
listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_VAR_WORD)) { segment ->
|
||||
"""
|
||||
lda ${segment[0].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
lda ${segment[1].callLabel},y
|
||||
sta ${segment[2].callLabel}
|
||||
lda ${segment[1].callLabel}+1,y
|
||||
sta ${segment[2].callLabel}+1
|
||||
"""
|
||||
},
|
||||
// mem = (u)word value
|
||||
AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_MEM_WORD)) { segment ->
|
||||
"""
|
||||
@ -1429,6 +1514,49 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
sty ${segment[2].callLabel}+${index+1}
|
||||
"""
|
||||
},
|
||||
// uwordarray[index mem] = (u)word value
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_WORD, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
listOf(Opcode.PUSH_WORD, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val value = segment[0].arg!!.integerValue().toHex()
|
||||
"""
|
||||
lda ${segment[1].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
lda #<$value
|
||||
sta ${segment[2].callLabel},y
|
||||
lda #>$value
|
||||
sta ${segment[2].callLabel}+1,y
|
||||
"""
|
||||
},
|
||||
// uwordarray[index mem] = mem (u)word
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
"""
|
||||
lda ${segment[1].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
lda ${segment[0].arg!!.integerValue().toHex()}
|
||||
sta ${segment[2].callLabel},y
|
||||
lda ${(segment[0].arg!!.integerValue()+1).toHex()}
|
||||
sta ${segment[2].callLabel}+1,y
|
||||
"""
|
||||
},
|
||||
// uwordarray[index mem] = (u)word var
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
"""
|
||||
lda ${segment[1].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
lda ${segment[0].callLabel}
|
||||
sta ${segment[2].callLabel},y
|
||||
lda ${segment[0].callLabel}+1
|
||||
sta ${segment[2].callLabel}+1,y
|
||||
"""
|
||||
},
|
||||
// uwordarray[index] = ubytevar
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.UB2UWORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val index = segment[2].arg!!.integerValue()*2
|
||||
@ -1436,9 +1564,73 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
"A" -> " sta ${segment[3].callLabel}+$index | lda #0 | sta ${segment[3].callLabel}+${index+1}"
|
||||
"X" -> " stx ${segment[3].callLabel}+$index | lda #0 | sta ${segment[3].callLabel}+${index+1}"
|
||||
"Y" -> " sty ${segment[3].callLabel}+$index | lda #0 | sta ${segment[3].callLabel}+${index+1}"
|
||||
else -> " lda ${segment[0].callLabel} | sta ${segment[2].callLabel}+$index | lda #0 | sta ${segment[3].callLabel}+${index+1}"
|
||||
else -> " lda ${segment[0].callLabel} | sta ${segment[3].callLabel}+$index | lda #0 | sta ${segment[3].callLabel}+${index+1}"
|
||||
}
|
||||
},
|
||||
// uwordarray[index mem] = ubytevar
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_VAR_BYTE, Opcode.UB2UWORD, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
listOf(Opcode.PUSH_VAR_BYTE, Opcode.UB2UWORD, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
when(segment[0].callLabel) {
|
||||
"A" ->
|
||||
"""
|
||||
pha
|
||||
lda ${segment[2].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
pla
|
||||
sta ${segment[3].callLabel},y
|
||||
lda #0
|
||||
sta ${segment[3].callLabel}+1,y
|
||||
"""
|
||||
"X" ->
|
||||
"""
|
||||
lda ${segment[2].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
txa
|
||||
sta ${segment[3].callLabel},y
|
||||
lda #0
|
||||
sta ${segment[3].callLabel}+1,y
|
||||
"""
|
||||
"Y" ->
|
||||
"""
|
||||
lda ${segment[2].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
stx ${C64Zeropage.SCRATCH_B1}
|
||||
tax
|
||||
tya
|
||||
sta ${segment[3].callLabel},x
|
||||
lda #0
|
||||
sta ${segment[3].callLabel}+1,x
|
||||
ldx ${C64Zeropage.SCRATCH_B1}
|
||||
"""
|
||||
else ->
|
||||
"""
|
||||
lda ${segment[2].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
lda ${segment[0].callLabel}
|
||||
sta ${segment[3].callLabel},y
|
||||
lda #0
|
||||
sta ${segment[3].callLabel}+1,y
|
||||
"""
|
||||
}
|
||||
},
|
||||
// uwordarray[index mem] = ubyte mem
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_MEM_UB, Opcode.UB2UWORD, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
listOf(Opcode.PUSH_MEM_UB, Opcode.UB2UWORD, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
"""
|
||||
lda ${segment[2].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
lda ${segment[0].arg!!.integerValue().toHex()}
|
||||
sta ${segment[3].callLabel},y
|
||||
lda #0
|
||||
sta ${segment[3].callLabel}+1,y
|
||||
"""
|
||||
},
|
||||
// uwordarray[index] = mem ubyte
|
||||
AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.UB2UWORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val index = segment[2].arg!!.integerValue()*2
|
||||
@ -1460,8 +1652,8 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
"""
|
||||
lda ${segment[0].arg!!.integerValue().toHex()}
|
||||
ldy ${(segment[0].arg!!.integerValue()+1).toHex()}
|
||||
sta ${segment[3].callLabel}+$index
|
||||
sty ${segment[3].callLabel}+${index+1}
|
||||
sta ${segment[2].callLabel}+$index
|
||||
sty ${segment[2].callLabel}+${index+1}
|
||||
"""
|
||||
},
|
||||
// uwordarray2[index2] = ubytearray1[index1]
|
||||
@ -1486,25 +1678,113 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
sta ${segment[3].callLabel}+${index2+1}
|
||||
"""
|
||||
},
|
||||
// uwordarray[indexvar]v = (u)word value
|
||||
// uwordarray[indexvar] = (u)word value
|
||||
AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val value = segment[0].arg!!.integerValue().toHex()
|
||||
val store = when(segment[1].callLabel) {
|
||||
"A" -> {
|
||||
TODO("$segment")
|
||||
}
|
||||
"X" -> {
|
||||
TODO("$segment")
|
||||
}
|
||||
"Y" -> {
|
||||
TODO("$segment")
|
||||
}
|
||||
else -> {
|
||||
TODO("$segment")
|
||||
}
|
||||
val loadIndexY = when(segment[1].callLabel) {
|
||||
"A" -> " asl a | tay"
|
||||
"X" -> " txa | asl a | tay"
|
||||
"Y" -> " tya | asl a | tay"
|
||||
else -> " lda ${segment[1].callLabel} | asl a | tay"
|
||||
}
|
||||
" $loadIndexY | lda #<$value | sta ${segment[2].callLabel},y | lda #>$value | sta ${segment[2].callLabel}+1,y"
|
||||
},
|
||||
// uwordarray[indexvar] = ubyte var
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.UB2UWORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val loadValueOnStack = when(segment[0].callLabel) {
|
||||
"A" -> " pha"
|
||||
"X" -> " txa | pha"
|
||||
"Y" -> " tya | pha"
|
||||
else -> " lda ${segment[0].callLabel} | pha"
|
||||
}
|
||||
val loadIndexY = when(segment[2].callLabel) {
|
||||
"A" -> " asl a | tay"
|
||||
"X" -> " txa | asl a | tay"
|
||||
"Y" -> " tya | asl a | tay"
|
||||
else -> " lda ${segment[2].callLabel} | asl a | tay"
|
||||
}
|
||||
" $loadValueOnStack | $loadIndexY | pla | sta ${segment[3].callLabel},y | lda #0 | sta ${segment[3].callLabel}+1,y"
|
||||
},
|
||||
// uwordarray[indexvar] = uword var
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val loadIndexY = when(segment[1].callLabel) {
|
||||
"A" -> " asl a | tay"
|
||||
"X" -> " txa | asl a | tay"
|
||||
"Y" -> " tya | asl a | tay"
|
||||
else -> " lda ${segment[1].callLabel} | asl a | tay"
|
||||
}
|
||||
" $loadIndexY | lda ${segment[0].callLabel} | sta ${segment[2].callLabel},y | lda ${segment[0].callLabel}+1 | sta ${segment[2].callLabel}+1,y"
|
||||
},
|
||||
// uwordarray[indexvar] = mem ubyte
|
||||
AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.UB2UWORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val loadIndexY = when(segment[2].callLabel) {
|
||||
"A" -> " asl a | tay"
|
||||
"X" -> " txa | asl a | tay"
|
||||
"Y" -> " tya | asl a | tay"
|
||||
else -> " lda ${segment[2].callLabel} | asl a | tay"
|
||||
}
|
||||
" $loadIndexY | lda ${segment[0].arg!!.integerValue().toHex()} | sta ${segment[3].callLabel},y | lda #0 | sta ${segment[3].callLabel}+1,y"
|
||||
},
|
||||
// uwordarray[indexvar] = mem uword
|
||||
AsmPattern(listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val loadIndexY = when(segment[1].callLabel) {
|
||||
"A" -> " asl a | tay"
|
||||
"X" -> " txa | asl a | tay"
|
||||
"Y" -> " tya | asl a | tay"
|
||||
else -> " lda ${segment[1].callLabel} | asl a | tay"
|
||||
}
|
||||
" $loadIndexY | lda ${segment[0].arg!!.integerValue().toHex()} | sta ${segment[2].callLabel},y | lda ${(segment[0].arg!!.integerValue()+1).toHex()} | sta ${segment[2].callLabel}+1,y"
|
||||
},
|
||||
// uwordarray2[indexvar] = ubytearay[index]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.UB2UWORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment->
|
||||
val index = segment[0].arg!!.integerValue()
|
||||
val loadIndex2Y = when(segment[3].callLabel) {
|
||||
"A" -> " asl a | tay"
|
||||
"X" -> " txa | asl a | tay"
|
||||
"Y" -> " tya | asl a | tay"
|
||||
else -> " lda ${segment[3].callLabel} | asl a | tay"
|
||||
}
|
||||
" $loadIndex2Y | lda ${segment[1].callLabel}+$index | sta ${segment[4].callLabel},y | lda #0 | sta ${segment[4].callLabel}+1,y"
|
||||
},
|
||||
// uwordarray2[indexvar] = uwordarray[index]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment->
|
||||
val index = segment[0].arg!!.integerValue()*2
|
||||
val loadIndex2Y = when(segment[2].callLabel) {
|
||||
"A" -> " asl a | tay"
|
||||
"X" -> " txa | asl a | tay"
|
||||
"Y" -> " tya | asl a | tay"
|
||||
else -> " lda ${segment[2].callLabel} | asl a | tay"
|
||||
}
|
||||
" $loadIndex2Y | lda ${segment[1].callLabel}+$index | sta ${segment[3].callLabel},y | lda ${segment[1].callLabel}+${index+1} | sta ${segment[3].callLabel}+1,y"
|
||||
},
|
||||
// uwordarray2[index mem] = ubytearray1[index1]
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.UB2UWORD, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.UB2UWORD, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment->
|
||||
val index1 = segment[0].arg!!.integerValue()
|
||||
"""
|
||||
|
||||
lda ${segment[3].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
lda ${segment[1].callLabel}+$index1
|
||||
sta ${segment[4].callLabel},y
|
||||
lda #0
|
||||
sta ${segment[4].callLabel}+1,y
|
||||
"""
|
||||
},
|
||||
// uwordarray2[index mem] = uwordarray1[index1]
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment->
|
||||
val index1 = segment[0].arg!!.integerValue()
|
||||
"""
|
||||
lda ${segment[2].arg!!.integerValue().toHex()}
|
||||
asl a
|
||||
tay
|
||||
lda ${segment[1].callLabel}+$index1
|
||||
sta ${segment[3].callLabel},y
|
||||
lda ${segment[1].callLabel}+${index1+1}
|
||||
sta ${segment[3].callLabel}+1,y
|
||||
"""
|
||||
},
|
||||
|
||||
@ -1952,4 +2232,5 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
// }
|
||||
|
||||
)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user