mirror of
https://github.com/irmen/prog8.git
synced 2025-04-03 19:29:43 +00:00
asm fixes
This commit is contained in:
parent
5361379187
commit
98a8ff4587
@ -43,10 +43,10 @@ sub start() {
|
||||
memory uword muword2 = $d004
|
||||
memory float mfloat = $c006
|
||||
memory float mfloat2 = $d006
|
||||
memory byte[3] mbarr1 = $e000
|
||||
memory ubyte[3] mubarr1 = $e100
|
||||
memory word[3] mwarr1 = $e100
|
||||
memory uword[3] muwarr1 = $e100
|
||||
memory byte[mubyte2] mbarr1 = $e000
|
||||
memory ubyte[mubyte2] mubarr1 = $e100
|
||||
memory word[mubyte2] mwarr1 = $e100
|
||||
memory uword[mubyte2] muwarr1 = $e100
|
||||
|
||||
str string = "hello"
|
||||
str_p stringp = "hello"
|
||||
@ -57,8 +57,8 @@ sub start() {
|
||||
byte_assignment_to_register:
|
||||
A = 42
|
||||
A = X
|
||||
A = ub
|
||||
A = mubyte
|
||||
A = ub2
|
||||
A = mubyte2
|
||||
A = AY[4]
|
||||
A = ubarr1[2]
|
||||
A = string[4]
|
||||
@ -73,33 +73,318 @@ byte_assignment_to_register:
|
||||
A = AY[ub]
|
||||
A = ubmatrix1[1,2]
|
||||
;A = ubmatrix1[1,Y] ; todo via evaluation
|
||||
A = ubmatrix1[X,2] ; todo via evaluation TODO fix error constant y dimension of index should have been const-folded with x into one value
|
||||
;A = ubmatrix1[X,2] ; todo via evaluation
|
||||
;A = ubmatrix1[X,Y] ; todo via evaluation
|
||||
;A = ubmatrix1[1,b2] ; todo via evaluation
|
||||
;A = ubmatrix1[X,b2] ; todo via evaluation
|
||||
A = ubmatrix1[b2,2] ; todo FIX ERROR constant y dimension of index should have been const-folded with x into one value
|
||||
;A = ubmatrix1[b2,2] ; todo via evaluation
|
||||
;A = ubmatrix1[b2,X] ; todo via evaluation
|
||||
;A = ubmatrix1[b,b2] ; todo via evaluation
|
||||
;A = ubmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
;byte_assignment_to_bytevar:
|
||||
; b = 42
|
||||
; b = b2
|
||||
; b = mbyte
|
||||
; b = barr1[2]
|
||||
; b = bmatrix1[1,2]
|
||||
;
|
||||
; ub = 42
|
||||
; ub = X
|
||||
; ub = ub2
|
||||
; ub = mubyte
|
||||
; ub = ubarr1[2]
|
||||
; ub = ubmatrix1[1,2]
|
||||
; ub = string[4]
|
||||
; ub = AY[4]
|
||||
;
|
||||
;
|
||||
;; all possible assignments to a WORD VARIABLE (not array)
|
||||
ubyte_assignment_to_ubytevar:
|
||||
ub = 42
|
||||
ub = X
|
||||
ub = ub2
|
||||
ub = mubyte2
|
||||
ub = AY[4]
|
||||
ub = ubarr1[2]
|
||||
ub = string[4]
|
||||
ub = string[X]
|
||||
ub = string[b]
|
||||
ub = string[ub]
|
||||
ub = ubarr1[X]
|
||||
ub = ubarr1[b]
|
||||
ub = ubarr1[ub]
|
||||
ub = AY[Y]
|
||||
ub = AY[b]
|
||||
ub = AY[ub]
|
||||
ub = ubmatrix1[1,2]
|
||||
;ub = ubmatrix1[1,Y] ; todo via evaluation
|
||||
;ub = ubmatrix1[X,2] ; todo via evaluation
|
||||
;ub = ubmatrix1[X,Y] ; todo via evaluation
|
||||
;ub = ubmatrix1[1,b2] ; todo via evaluation
|
||||
;ub = ubmatrix1[X,b2] ; todo via evaluation
|
||||
;ub = ubmatrix1[b2,2] ; todo via evaluation
|
||||
;ub = ubmatrix1[b2,X] ; todo via evaluation
|
||||
;ub = ubmatrix1[b,b2] ; todo via evaluation
|
||||
;ub = ubmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
|
||||
ubyte_assignment_to_ubytemem:
|
||||
mubyte = 42
|
||||
mubyte = X
|
||||
mubyte = ub2
|
||||
mubyte = mubyte2
|
||||
mubyte = AY[4]
|
||||
mubyte = ubarr1[2]
|
||||
mubyte = string[4]
|
||||
mubyte = string[X]
|
||||
mubyte = string[b]
|
||||
mubyte = string[ub]
|
||||
mubyte = ubarr1[X]
|
||||
mubyte = ubarr1[b]
|
||||
mubyte = ubarr1[ub]
|
||||
mubyte = AY[Y]
|
||||
mubyte = AY[b]
|
||||
mubyte = AY[ub]
|
||||
mubyte = ubmatrix1[1,2]
|
||||
;mubyte = ubmatrix1[1,Y] ; todo via evaluation
|
||||
;mubyte = ubmatrix1[X,2] ; todo via evaluation
|
||||
;mubyte = ubmatrix1[X,Y] ; todo via evaluation
|
||||
;mubyte = ubmatrix1[1,b2] ; todo via evaluation
|
||||
;mubyte = ubmatrix1[X,b2] ; todo via evaluation
|
||||
;mubyte = ubmatrix1[b2,2] ; todo via evaluation
|
||||
;mubyte = ubmatrix1[b2,X] ; todo via evaluation
|
||||
;mubyte = ubmatrix1[b,b2] ; todo via evaluation
|
||||
;mubyte = ubmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
byte_assignment_to_bytevar:
|
||||
b = -42
|
||||
b = b2
|
||||
b = mbyte2
|
||||
b = barr1[2]
|
||||
b = barr1[X]
|
||||
b = barr1[b]
|
||||
b = barr1[ub]
|
||||
b = bmatrix1[1,2]
|
||||
;b = bmatrix1[1,Y] ; todo via evaluation
|
||||
;b = bmatrix1[X,2] ; todo via evaluation
|
||||
;b = bmatrix1[X,Y] ; todo via evaluation
|
||||
;b = bmatrix1[1,b2] ; todo via evaluation
|
||||
;b = bmatrix1[X,b2] ; todo via evaluation
|
||||
;b = bmatrix1[b2,2] ; todo via evaluation
|
||||
;b = bmatrix1[b2,X] ; todo via evaluation
|
||||
;b = bmatrix1[b,b2] ; todo via evaluation
|
||||
;b = bmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
|
||||
byte_assignment_to_bytemem:
|
||||
mbyte = -42
|
||||
mbyte = b2
|
||||
mbyte = mbyte2
|
||||
mbyte = barr1[2]
|
||||
mbyte = barr1[X]
|
||||
mbyte = barr1[b]
|
||||
mbyte = barr1[ub]
|
||||
mbyte = bmatrix1[1,2]
|
||||
;mbyte = bmatrix1[1,Y] ; todo via evaluation
|
||||
;mbyte = bmatrix1[X,2] ; todo via evaluation
|
||||
;mbyte = bmatrix1[X,Y] ; todo via evaluation
|
||||
;mbyte = bmatrix1[1,b2] ; todo via evaluation
|
||||
;mbyte = bmatrix1[X,b2] ; todo via evaluation
|
||||
;mbyte = bmatrix1[b2,2] ; todo via evaluation
|
||||
;mbyte = bmatrix1[b2,X] ; todo via evaluation
|
||||
;mbyte = bmatrix1[b,b2] ; todo via evaluation
|
||||
;mbyte = bmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
|
||||
ubyte_assignment_to_ubytearray:
|
||||
ubarr2[3] = 42
|
||||
ubarr2[3] = X
|
||||
ubarr2[3] = ub2
|
||||
ubarr2[3] = mubyte2
|
||||
ubarr2[3] = AY[4]
|
||||
ubarr2[3] = ubarr1[2]
|
||||
ubarr2[3] = string[4]
|
||||
ubarr2[3] = string[X]
|
||||
ubarr2[3] = string[b]
|
||||
ubarr2[3] = string[ub]
|
||||
ubarr2[3] = ubarr1[X]
|
||||
ubarr2[3] = ubarr1[b]
|
||||
ubarr2[3] = ubarr1[ub]
|
||||
ubarr2[3] = AY[Y]
|
||||
ubarr2[3] = AY[b]
|
||||
ubarr2[3] = AY[ub]
|
||||
AY[3] = 42
|
||||
AY[3] = X
|
||||
AY[3] = ub2
|
||||
AY[3] = mubyte2
|
||||
AY[3] = ubarr1[2]
|
||||
AY[3] = string[4]
|
||||
AY[3] = string[X]
|
||||
AY[3] = string[b]
|
||||
AY[3] = string[ub]
|
||||
AY[3] = ubarr1[X]
|
||||
AY[3] = ubarr1[b]
|
||||
AY[3] = ubarr1[ub]
|
||||
AY[3] = ubmatrix1[1,2]
|
||||
string[4] = 42
|
||||
string[4] = 'B'
|
||||
string[4] = X
|
||||
string[4] = ub2
|
||||
string[4] = mubyte2
|
||||
string[4] = AY[4]
|
||||
string[4] = ubarr1[2]
|
||||
string[4] = string[3]
|
||||
ubarr2[3] = ubmatrix1[1,2]
|
||||
;ubarr2[3] = ubmatrix1[1,Y] ; todo via evaluation
|
||||
;ubarr2[3] = ubmatrix1[X,2] ; todo via evaluation
|
||||
;ubarr2[3] = ubmatrix1[X,Y] ; todo via evaluation
|
||||
;ubarr2[3] = ubmatrix1[1,b2] ; todo via evaluation
|
||||
;ubarr2[3] = ubmatrix1[X,b2] ; todo via evaluation
|
||||
;ubarr2[3] = ubmatrix1[b2,2] ; todo via evaluation
|
||||
;ubarr2[3] = ubmatrix1[b2,X] ; todo via evaluation
|
||||
;ubarr2[3] = ubmatrix1[b,b2] ; todo via evaluation
|
||||
;ubarr2[3] = ubmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
|
||||
ubarr2[Y] = 42
|
||||
ubarr2[Y] = X
|
||||
ubarr2[Y] = ub2
|
||||
ubarr2[Y] = mubyte2
|
||||
ubarr2[Y] = AY[4]
|
||||
ubarr2[Y] = ubarr1[2]
|
||||
ubarr2[Y] = string[4]
|
||||
ubarr2[Y] = string[X]
|
||||
ubarr2[Y] = string[b]
|
||||
ubarr2[Y] = string[ub]
|
||||
ubarr2[Y] = ubarr1[X]
|
||||
ubarr2[Y] = ubarr1[b]
|
||||
ubarr2[Y] = ubarr1[ub]
|
||||
ubarr2[Y] = AY[Y]
|
||||
ubarr2[Y] = AY[b]
|
||||
ubarr2[Y] = AY[ub]
|
||||
AY[Y] = 42
|
||||
AY[Y] = X
|
||||
AY[Y] = ub2
|
||||
AY[Y] = mubyte2
|
||||
AY[Y] = ubarr1[2]
|
||||
AY[Y] = string[4]
|
||||
AY[Y] = string[X]
|
||||
AY[Y] = string[b]
|
||||
AY[Y] = string[ub]
|
||||
AY[Y] = ubarr1[X]
|
||||
AY[Y] = ubarr1[b]
|
||||
AY[Y] = ubarr1[ub]
|
||||
AY[Y] = ubmatrix1[1,2]
|
||||
string[Y] = 42
|
||||
string[Y] = 'B'
|
||||
string[Y] = X
|
||||
string[Y] = ub2
|
||||
string[Y] = mubyte2
|
||||
string[Y] = AY[4]
|
||||
string[Y] = ubarr1[2]
|
||||
string[Y] = string[Y]
|
||||
ubarr2[Y] = ubmatrix1[1,2]
|
||||
;ubarr2[Y] = ubmatrix1[1,Y] ; todo via evaluation
|
||||
;ubarr2[Y] = ubmatrix1[X,2] ; todo via evaluation
|
||||
;ubarr2[Y] = ubmatrix1[X,Y] ; todo via evaluation
|
||||
;ubarr2[Y] = ubmatrix1[1,b2] ; todo via evaluation
|
||||
;ubarr2[Y] = ubmatrix1[X,b2] ; todo via evaluation
|
||||
;ubarr2[Y] = ubmatrix1[b2,2] ; todo via evaluation
|
||||
;ubarr2[Y] = ubmatrix1[b2,X] ; todo via evaluation
|
||||
;ubarr2[Y] = ubmatrix1[b,b2] ; todo via evaluation
|
||||
;ubarr2[Y] = ubmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
|
||||
ubarr2[ub2] = 42
|
||||
ubarr2[ub2] = X
|
||||
ubarr2[ub2] = ub2
|
||||
ubarr2[ub2] = mubyte2
|
||||
ubarr2[ub2] = AY[4]
|
||||
ubarr2[ub2] = ubarr1[2]
|
||||
ubarr2[ub2] = string[4]
|
||||
ubarr2[ub2] = string[X]
|
||||
ubarr2[ub2] = string[b]
|
||||
ubarr2[ub2] = string[ub]
|
||||
ubarr2[ub2] = ubarr1[X]
|
||||
ubarr2[ub2] = ubarr1[b]
|
||||
ubarr2[ub2] = ubarr1[ub]
|
||||
ubarr2[ub2] = AY[Y]
|
||||
ubarr2[ub2] = AY[b]
|
||||
ubarr2[ub2] = AY[ub]
|
||||
AY[ub2] = 42
|
||||
AY[ub2] = X
|
||||
AY[ub2] = ub2
|
||||
AY[ub2] = mubyte2
|
||||
AY[ub2] = ubarr1[2]
|
||||
AY[ub2] = string[4]
|
||||
AY[ub2] = string[X]
|
||||
AY[ub2] = string[b]
|
||||
AY[ub2] = string[ub]
|
||||
AY[ub2] = ubarr1[X]
|
||||
AY[ub2] = ubarr1[b]
|
||||
AY[ub2] = ubarr1[ub]
|
||||
AY[ub2] = ubmatrix1[1,2]
|
||||
string[ub2] = 42
|
||||
string[ub2] = 'B'
|
||||
string[ub2] = X
|
||||
string[ub2] = ub2
|
||||
string[ub2] = mubyte2
|
||||
string[ub2] = AY[4]
|
||||
string[ub2] = ubarr1[2]
|
||||
string[ub2] = string[ub2]
|
||||
ubarr2[ub2] = ubmatrix1[1,2]
|
||||
;ubarr2[ub2] = ubmatrix1[1,Y] ; todo via evaluation
|
||||
;ubarr2[ub2] = ubmatrix1[X,2] ; todo via evaluation
|
||||
;ubarr2[ub2] = ubmatrix1[X,Y] ; todo via evaluation
|
||||
;ubarr2[ub2] = ubmatrix1[1,b2] ; todo via evaluation
|
||||
;ubarr2[ub2] = ubmatrix1[X,b2] ; todo via evaluation
|
||||
;ubarr2[ub2] = ubmatrix1[b2,2] ; todo via evaluation
|
||||
;ubarr2[ub2] = ubmatrix1[b2,X] ; todo via evaluation
|
||||
;ubarr2[ub2] = ubmatrix1[b,b2] ; todo via evaluation
|
||||
;ubarr2[ub2] = ubmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
ubarr2[mubyte2] = 42
|
||||
ubarr2[mubyte2] = X
|
||||
ubarr2[mubyte2] = ub2
|
||||
ubarr2[mubyte2] = mubyte2
|
||||
ubarr2[mubyte2] = AY[4]
|
||||
ubarr2[mubyte2] = ubarr1[2]
|
||||
ubarr2[mubyte2] = string[4]
|
||||
ubarr2[mubyte2] = string[X]
|
||||
ubarr2[mubyte2] = string[b]
|
||||
ubarr2[mubyte2] = string[ub]
|
||||
ubarr2[mubyte2] = ubarr1[X]
|
||||
ubarr2[mubyte2] = ubarr1[b]
|
||||
ubarr2[mubyte2] = ubarr1[ub]
|
||||
ubarr2[mubyte2] = AY[Y]
|
||||
ubarr2[mubyte2] = AY[b]
|
||||
ubarr2[mubyte2] = AY[ub]
|
||||
AY[mubyte2] = 42
|
||||
AY[mubyte2] = X
|
||||
AY[mubyte2] = ub2
|
||||
AY[mubyte2] = mubyte2
|
||||
AY[mubyte2] = ubarr1[2]
|
||||
AY[mubyte2] = string[4]
|
||||
AY[mubyte2] = string[X]
|
||||
AY[mubyte2] = string[b]
|
||||
AY[mubyte2] = string[ub]
|
||||
AY[mubyte2] = ubarr1[X]
|
||||
AY[mubyte2] = ubarr1[b]
|
||||
AY[mubyte2] = ubarr1[ub]
|
||||
AY[mubyte2] = ubmatrix1[1,2]
|
||||
string[mubyte2] = 42
|
||||
string[mubyte2] = 'B'
|
||||
string[mubyte2] = X
|
||||
string[mubyte2] = ub2
|
||||
string[mubyte2] = mubyte2
|
||||
string[mubyte2] = AY[4]
|
||||
string[mubyte2] = ubarr1[2]
|
||||
string[mubyte2] = string[mubyte2]
|
||||
ubarr2[mubyte2] = ubmatrix1[1,2]
|
||||
;ubarr2[mubyte2] = ubmatrix1[1,Y] ; todo via evaluation
|
||||
;ubarr2[mubyte2] = ubmatrix1[X,2] ; todo via evaluation
|
||||
;ubarr2[mubyte2] = ubmatrix1[X,Y] ; todo via evaluation
|
||||
;ubarr2[mubyte2] = ubmatrix1[1,b2] ; todo via evaluation
|
||||
;ubarr2[mubyte2] = ubmatrix1[X,b2] ; todo via evaluation
|
||||
;ubarr2[mubyte2] = ubmatrix1[b2,2] ; todo via evaluation
|
||||
;ubarr2[mubyte2] = ubmatrix1[b2,X] ; todo via evaluation
|
||||
;ubarr2[mubyte2] = ubmatrix1[b,b2] ; todo via evaluation
|
||||
;ubarr2[mubyte2] = ubmatrix1[ub,ub2] ; todo via evaluation
|
||||
|
||||
ubarr1[ubarr2[X]] = ubarr2[ubarr1[Y]] ; todo via evaluation
|
||||
|
||||
|
||||
|
||||
byte_assignment_to_bytearray:
|
||||
; @todo
|
||||
|
||||
|
||||
|
||||
|
||||
; all possible assignments to a WORD VARIABLE (not array)
|
||||
;
|
||||
;word_assignment_to_registerpair:
|
||||
; AY = 42
|
||||
|
@ -730,10 +730,10 @@ class AstChecker(private val namespace: INameScope,
|
||||
val arraysize = target.arrayspec?.size()
|
||||
if(arraysize!=null) {
|
||||
// check out of bounds
|
||||
if((arrayIndexedExpression.arrayspec.y as? LiteralValue)?.asIntegerValue != null) {
|
||||
val index = (arrayIndexedExpression.arrayspec.x as? LiteralValue)?.asIntegerValue
|
||||
if(index != null && (arrayIndexedExpression.arrayspec.y as? LiteralValue)?.asIntegerValue != null) {
|
||||
throw FatalAstException("constant y dimension of index should have been const-folded with x into one value ${arrayIndexedExpression.arrayspec.position}")
|
||||
}
|
||||
val index = (arrayIndexedExpression.arrayspec.x as? LiteralValue)?.asIntegerValue
|
||||
if(index!=null && (index<0 || index>=arraysize))
|
||||
checkResult.add(ExpressionError("arrayspec index out of bounds", arrayIndexedExpression.arrayspec.position))
|
||||
} else if(target.datatype in StringDatatypes) {
|
||||
|
@ -912,10 +912,69 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
|
||||
class AsmPattern(val sequence: List<Opcode>, val altSequence: List<Opcode>?=null, val asm: (List<Instruction>)->String?)
|
||||
|
||||
private fun loadAFromIndexedByVar(idxVarInstr: Instruction, readArrayInstr: Instruction): String {
|
||||
val setupPtr: String
|
||||
val loadByte: String
|
||||
when (readArrayInstr.callLabel) {
|
||||
"AX" -> {
|
||||
setupPtr = "sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
loadByte = when (idxVarInstr.callLabel) {
|
||||
"A" -> "tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "txa | tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${idxVarInstr.callLabel} | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
"AY" -> {
|
||||
setupPtr = " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
loadByte = when (idxVarInstr.callLabel) {
|
||||
"A" -> "tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "txa | tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${idxVarInstr.callLabel} | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
"XY" -> {
|
||||
setupPtr = " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
loadByte = when (idxVarInstr.callLabel) {
|
||||
"A" -> "tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "txa | tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${idxVarInstr.callLabel} | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
when (idxVarInstr.callLabel) {
|
||||
"A" -> {
|
||||
setupPtr = ""
|
||||
loadByte = "tay | lda ${readArrayInstr.callLabel},y"
|
||||
}
|
||||
"X" -> {
|
||||
setupPtr = ""
|
||||
loadByte = "txa | tay | lda ${readArrayInstr.callLabel},y"
|
||||
}
|
||||
"Y" -> {
|
||||
setupPtr = ""
|
||||
loadByte = "lda ${readArrayInstr.callLabel},y"
|
||||
}
|
||||
else -> {
|
||||
setupPtr = ""
|
||||
loadByte = "ldy ${idxVarInstr.callLabel} | lda ${readArrayInstr.callLabel},y"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "$setupPtr | $loadByte"
|
||||
}
|
||||
|
||||
private fun storeAToIndexedByVar(idxVarInstr: Instruction, readArrayInstr: Instruction): String {
|
||||
TODO("storeAToIndexedByVar $readArrayInstr [ $idxVarInstr ]")
|
||||
}
|
||||
|
||||
private val patterns = listOf(
|
||||
|
||||
// ----------- assignment to BYTE VARIABLE ----------------
|
||||
// var = bytevalue
|
||||
// var = (u)bytevalue
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.POP_VAR_BYTE)) { segment ->
|
||||
when (segment[1].callLabel) {
|
||||
"A", "X", "Y" ->
|
||||
@ -966,7 +1025,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
else -> " lda ${segment[0].arg!!.integerValue().toHex()} | sta ${segment[1].callLabel}"
|
||||
}
|
||||
},
|
||||
// var = bytearray[index]
|
||||
// var = (u)bytearray[index]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment ->
|
||||
val index = segment[0].arg!!.integerValue()
|
||||
when(segment[1].callLabel) {
|
||||
@ -997,75 +1056,19 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
}
|
||||
}
|
||||
},
|
||||
// var = bytearray[indexvar]
|
||||
// var = (u)bytearray[indexvar]
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment ->
|
||||
// TODO reuse: load byte in A
|
||||
val setupPtr: String
|
||||
val loadByte: String
|
||||
when(segment[1].callLabel) {
|
||||
"AX" -> {
|
||||
setupPtr = "sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
loadByte = when (segment[0].callLabel) {
|
||||
"A" -> "tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "txa | tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${segment[0].callLabel} | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
"AY" -> {
|
||||
setupPtr = " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
loadByte = when (segment[0].callLabel) {
|
||||
"A" -> "tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "txa | tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${segment[0].callLabel} | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
"XY" -> {
|
||||
setupPtr = " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
loadByte = when (segment[0].callLabel) {
|
||||
"A" -> "tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "txa | tay | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${segment[0].callLabel} | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
when (segment[0].callLabel) {
|
||||
"A" -> {
|
||||
setupPtr = ""
|
||||
loadByte = "tay | lda ${segment[1].callLabel},y"
|
||||
}
|
||||
"X" -> {
|
||||
setupPtr = ""
|
||||
loadByte = "txa | tay | lda ${segment[1].callLabel},y"
|
||||
}
|
||||
"Y" -> {
|
||||
setupPtr = ""
|
||||
loadByte = "lda ${segment[1].callLabel},y"
|
||||
}
|
||||
else -> {
|
||||
setupPtr = ""
|
||||
loadByte = "ldy ${segment[0].callLabel} | lda ${segment[1].callLabel},y"
|
||||
}
|
||||
}
|
||||
}
|
||||
val loadByteA = loadAFromIndexedByVar(segment[0], segment[1])
|
||||
when(segment[2].callLabel) {
|
||||
"A" -> " $loadByteA"
|
||||
"X" -> " $loadByteA | tax"
|
||||
"Y" -> " $loadByteA | tya"
|
||||
else -> " $loadByteA | sta ${segment[2].callLabel}"
|
||||
}
|
||||
|
||||
// store A in target
|
||||
val storeByte = when(segment[2].callLabel) {
|
||||
"A" -> ""
|
||||
"X" -> "tax"
|
||||
"Y" -> "tya"
|
||||
else -> "sta ${segment[2].callLabel}"
|
||||
}
|
||||
|
||||
" $setupPtr | $loadByte | $storeByte"
|
||||
},
|
||||
|
||||
|
||||
// ----------- assignment to MEMORY BYTE ----------------
|
||||
// @todo mem=mem
|
||||
// ----------- assignment to BYTE MEMORY ----------------
|
||||
// mem = (u)byte value
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.POP_MEM_BYTE)) { segment ->
|
||||
" lda #${segment[0].arg!!.integerValue().toHex()} | sta ${segment[1].arg!!.integerValue().toHex()}"
|
||||
@ -1079,7 +1082,13 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
else -> " lda ${segment[0].callLabel} | sta ${segment[1].arg!!.integerValue().toHex()}"
|
||||
}
|
||||
},
|
||||
// mem = (u)bytearray[indexvalue]
|
||||
// mem = mem (u)byte
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_MEM_B, Opcode.POP_MEM_BYTE),
|
||||
listOf(Opcode.PUSH_MEM_UB, Opcode.POP_MEM_BYTE)) { segment ->
|
||||
" lda ${segment[0].arg!!.integerValue().toHex()} | sta ${segment[1].arg!!.integerValue().toHex()}"
|
||||
},
|
||||
// mem = (u)bytearray[index]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_MEM_BYTE)) { segment ->
|
||||
val address = segment[2].arg!!.integerValue().toHex()
|
||||
val index = segment[0].arg!!.integerValue()
|
||||
@ -1090,11 +1099,129 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
else -> " lda ${segment[1].callLabel}+$index | sta $address"
|
||||
}
|
||||
},
|
||||
// mem = (u)bytearray[indexvar]
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_MEM_BYTE)) { segment->
|
||||
val loadByteA = loadAFromIndexedByVar(segment[0], segment[1])
|
||||
" $loadByteA | sta ${segment[2].arg!!.integerValue().toHex()}"
|
||||
},
|
||||
|
||||
|
||||
// ----------- assignment to BYTE ARRAY ----------------
|
||||
// bytearray[index] = (u)byte value
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()
|
||||
val value = segment[0].arg!!.integerValue().toHex()
|
||||
when(segment[2].callLabel) {
|
||||
"AX" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda #$value | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"AY" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda #$value | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"XY" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda #$value | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> " lda #$value | sta ${segment[2].callLabel}+$index"
|
||||
}
|
||||
},
|
||||
// bytearray[index] = (u)bytevar
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()
|
||||
val saveValue: String
|
||||
val loadValue: String
|
||||
when(segment[0].callLabel) {
|
||||
"A" -> {
|
||||
saveValue = ""
|
||||
loadValue = ""
|
||||
}
|
||||
"X" -> {
|
||||
saveValue = ""
|
||||
loadValue = "txa"
|
||||
}
|
||||
"Y" -> {
|
||||
// TODO optimize to tya if array is a variable instead of registerpair
|
||||
saveValue = "sty ${C64Zeropage.SCRATCH_B1}"
|
||||
loadValue = "lda ${C64Zeropage.SCRATCH_B1}"
|
||||
}
|
||||
else -> {
|
||||
saveValue = ""
|
||||
loadValue = "lda ${segment[0].callLabel}"
|
||||
}
|
||||
}
|
||||
when(segment[2].callLabel) {
|
||||
"AX" -> " $saveValue | sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | $loadValue | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"AY" -> " $saveValue | sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | $loadValue | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"XY" -> " $saveValue | stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | $loadValue | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> " $loadValue | sta ${segment[2].callLabel}+$index"
|
||||
}
|
||||
},
|
||||
// bytearray[index] = mem(u)byte
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE),
|
||||
listOf(Opcode.PUSH_MEM_UB, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()
|
||||
when(segment[2].callLabel) {
|
||||
"AX" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda ${segment[0].arg!!.integerValue().toHex()} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"AY" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda ${segment[0].arg!!.integerValue().toHex()} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"XY" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda ${segment[0].arg!!.integerValue().toHex()} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> " lda ${segment[0].arg!!.integerValue().toHex()} | sta ${segment[2].callLabel}+$index"
|
||||
}
|
||||
},
|
||||
// bytearray[index var] = (u)byte value
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val storeA = storeAToIndexedByVar(segment[1], segment[2])
|
||||
" lda #${segment[0].arg!!.integerValue().toHex()} | $storeA"
|
||||
},
|
||||
// (u)bytearray2[index2] = (u)bytearray1[index1]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment->
|
||||
val index1 = segment[0].arg!!.integerValue()
|
||||
val index2 = segment[2].arg!!.integerValue()
|
||||
when(segment[1].callLabel) {
|
||||
"AX" -> when(segment[3].callLabel) {
|
||||
"AX", "AY", "XY" -> throw AssemblyError("reading AND writing from registerpair arrays not supported due to register overlap")
|
||||
else ->
|
||||
"""
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
stx ${C64Zeropage.SCRATCH_W1+1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
sta ${segment[3].callLabel}+$index2
|
||||
"""
|
||||
}
|
||||
"AY" -> when(segment[3].callLabel) {
|
||||
"AX", "AY", "XY" -> throw AssemblyError("reading AND writing from registerpair arrays not supported due to register overlap")
|
||||
else ->
|
||||
"""
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
sta ${segment[3].callLabel}+$index2
|
||||
"""
|
||||
}
|
||||
"XY" -> when(segment[3].callLabel) {
|
||||
"AX", "AY", "XY" -> throw AssemblyError("reading AND writing from registerpair arrays not supported due to register overlap")
|
||||
else ->
|
||||
"""
|
||||
stx ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
sta ${segment[3].callLabel}+$index2
|
||||
"""
|
||||
}
|
||||
else ->
|
||||
when(segment[3].callLabel) {
|
||||
"AX" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | lda ${segment[1].callLabel}+$index1 | ldy #$index2 | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"AY" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | lda ${segment[1].callLabel}+$index1 | ldy #$index2 | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"XY" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | lda ${segment[1].callLabel}+$index1 | ldy #$index2 | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> " lda ${segment[1].callLabel}+$index1 | sta ${segment[3].callLabel}+$index2"
|
||||
}
|
||||
}
|
||||
},
|
||||
// (u)bytearray2[index2] = (u)bytearray[indexvar]
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val loadByteA = loadAFromIndexedByVar(segment[0], segment[1])
|
||||
val index2 = segment[2].arg!!.integerValue()
|
||||
" $loadByteA | sta ${segment[3].callLabel}+$index2"
|
||||
},
|
||||
|
||||
|
||||
// ----------- assignment to WORD VARIABLE ----------------
|
||||
// @todo var=var
|
||||
// var = wordvalue
|
||||
AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_VAR_WORD)) { segment ->
|
||||
val number = segment[0].arg!!.integerValue().toHex()
|
||||
@ -1533,250 +1660,141 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
ldy #>${segment[1].arg!!.integerValue().toHex()}
|
||||
jsr prog8_lib.copy_float
|
||||
"""
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ---- @todo assignment to arrays follow below ----------
|
||||
|
||||
|
||||
// // assignment: bytearray[memory (u)byte] = byte
|
||||
// AsmPattern(
|
||||
// listOf(Opcode.PUSH_BYTE, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_BYTE),
|
||||
// listOf(Opcode.PUSH_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
// TODO("$segment")
|
||||
// },
|
||||
//
|
||||
|
||||
// assignment: bytearray[idxbyte] = byte
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()
|
||||
val value = segment[0].arg!!.integerValue().toHex()
|
||||
when(segment[2].callLabel) {
|
||||
"AX" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda #$value | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"AY" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda #$value | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"XY" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda #$value | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> " lda #$value | sta ${segment[2].callLabel}+$index"
|
||||
}
|
||||
},
|
||||
// assignment: bytearray[idxbyte] = bytevar
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()
|
||||
val saveValue: String
|
||||
val loadValue: String
|
||||
when(segment[0].callLabel) {
|
||||
"A" -> {
|
||||
saveValue = ""
|
||||
loadValue = ""
|
||||
}
|
||||
"X" -> {
|
||||
saveValue = ""
|
||||
loadValue = "txa"
|
||||
}
|
||||
"Y" -> {
|
||||
saveValue = "sty ${C64Zeropage.SCRATCH_B1}"
|
||||
loadValue = "lda ${C64Zeropage.SCRATCH_B1}"
|
||||
}
|
||||
else -> {
|
||||
saveValue = ""
|
||||
loadValue = "lda ${segment[0].callLabel}"
|
||||
}
|
||||
}
|
||||
when(segment[2].callLabel) {
|
||||
"AX" -> " $saveValue | sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | $loadValue | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"AY" -> " $saveValue | sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | $loadValue | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"XY" -> " $saveValue | stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | $loadValue | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> " $loadValue | sta ${segment[2].callLabel}+$index"
|
||||
}
|
||||
},
|
||||
// // assignment: bytearray[idxvar] = bytevar
|
||||
// AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
// TODO("$segment")
|
||||
// },
|
||||
//
|
||||
// // assignment: bytearray[mem (u)byte] = bytevar
|
||||
// AsmPattern(
|
||||
// listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_BYTE),
|
||||
// listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
// TODO("$segment")
|
||||
// },
|
||||
|
||||
// assignment: bytearray[memory (u)byte] = byte
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_BYTE, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_BYTE),
|
||||
listOf(Opcode.PUSH_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
TODO("$segment")
|
||||
},
|
||||
|
||||
// assignment: bytearray[idxvar] = byte
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
TODO("$segment")
|
||||
},
|
||||
// assignment: bytearray[idxvar] = bytevar
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
TODO("$segment")
|
||||
},
|
||||
|
||||
// assignment: bytearray[mem (u)byte] = bytevar
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_BYTE),
|
||||
listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
TODO("$segment")
|
||||
},
|
||||
|
||||
// assignment: bytearray[idxbyte] = membyte
|
||||
AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()
|
||||
TODO("registerpair array") // same as below???
|
||||
" lda ${segment[0].arg!!.integerValue().toHex()} | sta ${segment[2].callLabel}+$index "
|
||||
},
|
||||
// assignment: bytearray[idxbyte] = memubyte
|
||||
AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()
|
||||
when(segment[2].callLabel) {
|
||||
"AX" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda ${segment[0].arg!!.integerValue().toHex()} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"AY" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda ${segment[0].arg!!.integerValue().toHex()} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"XY" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda ${segment[0].arg!!.integerValue().toHex()} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> " lda ${segment[0].arg!!.integerValue().toHex()} | sta ${segment[2].callLabel}+$index"
|
||||
}
|
||||
},
|
||||
// assignment: wordarray[idxbyte] = word
|
||||
AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()*2
|
||||
"""
|
||||
lda #<${segment[0].arg!!.integerValue().toHex()}
|
||||
ldy #>${segment[0].arg!!.integerValue().toHex()}
|
||||
sta ${segment[2].callLabel}+$index
|
||||
sty ${segment[2].callLabel}+${index+1}
|
||||
"""
|
||||
},
|
||||
|
||||
// assignment: wordarray[memory (u)byte] = word
|
||||
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 ->
|
||||
TODO("$segment")
|
||||
},
|
||||
|
||||
// assignment: wordarray[indexvar] = word
|
||||
AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
TODO("$segment")
|
||||
},
|
||||
// assignment: wordarray[idxbyte] = wordvar
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()*2
|
||||
when(segment[0].callLabel) {
|
||||
"AX" -> " sta ${segment[2].callLabel}+$index | stx ${segment[2].callLabel}+${index+1}"
|
||||
"AY" -> " sta ${segment[2].callLabel}+$index | sty ${segment[2].callLabel}+${index+1}"
|
||||
"XY" -> " stx ${segment[2].callLabel}+$index | sty ${segment[2].callLabel}+${index+1}"
|
||||
else ->
|
||||
"""
|
||||
lda ${segment[0].callLabel}
|
||||
ldy ${segment[0].callLabel}+1
|
||||
sta ${segment[2].callLabel}+$index
|
||||
sty ${segment[2].callLabel}+${index+1}
|
||||
"""
|
||||
}
|
||||
},
|
||||
// assignment: wordarray[indexvar] = wordvar
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
TODO("$segment")
|
||||
},
|
||||
// assignment: wordarray[idxbyte] = mem(u)word
|
||||
AsmPattern(
|
||||
listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue()*2
|
||||
"""
|
||||
lda ${segment[0].arg!!.integerValue().toHex()}
|
||||
ldy ${(segment[0].arg!!.integerValue()+1).toHex()}
|
||||
sta ${segment[2].callLabel}+$index
|
||||
sty ${segment[2].callLabel}+${index+1}
|
||||
"""
|
||||
},
|
||||
|
||||
|
||||
// assignment: bytearray2[index2] = bytearray1[index1]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment->
|
||||
val index1 = segment[0].arg!!.integerValue()
|
||||
val index2 = segment[2].arg!!.integerValue()
|
||||
when(segment[1].callLabel) {
|
||||
"AX" -> when(segment[3].callLabel) {
|
||||
"AX", "AY", "XY" -> throw AssemblyError("reading AND writing from registerpair arrays not supported due to register overlap")
|
||||
else ->
|
||||
"""
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
stx ${C64Zeropage.SCRATCH_W1+1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
sta ${segment[3].callLabel}+$index2
|
||||
"""
|
||||
}
|
||||
"AY" -> when(segment[3].callLabel) {
|
||||
"AX", "AY", "XY" -> throw AssemblyError("reading AND writing from registerpair arrays not supported due to register overlap")
|
||||
else ->
|
||||
"""
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
sta ${segment[3].callLabel}+$index2
|
||||
"""
|
||||
}
|
||||
"XY" -> when(segment[3].callLabel) {
|
||||
"AX", "AY", "XY" -> throw AssemblyError("reading AND writing from registerpair arrays not supported due to register overlap")
|
||||
else ->
|
||||
"""
|
||||
stx ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
sta ${segment[3].callLabel}+$index2
|
||||
"""
|
||||
}
|
||||
else ->
|
||||
when(segment[3].callLabel) {
|
||||
"AX" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | lda ${segment[1].callLabel}+$index1 | ldy #$index2 | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"AY" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | lda ${segment[1].callLabel}+$index1 | ldy #$index2 | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"XY" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | lda ${segment[1].callLabel}+$index1 | ldy #$index2 | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> " lda ${segment[1].callLabel}+$index1 | sta ${segment[3].callLabel}+$index2"
|
||||
}
|
||||
}
|
||||
},
|
||||
// assignment: wordarrayw[index2] = wordarray1[index1]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment->
|
||||
val index1 = segment[0].arg!!.integerValue()*2
|
||||
val index2 = segment[2].arg!!.integerValue()*2
|
||||
"""
|
||||
lda ${segment[1].callLabel}+$index1
|
||||
ldy ${segment[1].callLabel}+${index1+1}
|
||||
sta ${segment[3].callLabel}+$index2
|
||||
sty ${segment[3].callLabel}+${index2+1}
|
||||
"""
|
||||
},
|
||||
|
||||
// assignment: floatarray[idxbyte] = float
|
||||
AsmPattern(listOf(Opcode.PUSH_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment ->
|
||||
val floatConst = getFloatConst(segment[0].arg!!)
|
||||
val index = segment[1].arg!!.integerValue() * Mflpt5.MemorySize
|
||||
"""
|
||||
lda #<$floatConst
|
||||
ldy #>$floatConst
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
lda #<(${segment[2].callLabel}+$index)
|
||||
ldy #>(${segment[2].callLabel}+$index)
|
||||
jsr prog8_lib.copy_float
|
||||
"""
|
||||
},
|
||||
// assignment: floatarray[idxbyte] = floatvar
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue() * Mflpt5.MemorySize
|
||||
"""
|
||||
lda #<${segment[0].callLabel}
|
||||
ldy #>${segment[0].callLabel}
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
lda #<(${segment[2].callLabel}+$index)
|
||||
ldy #>(${segment[2].callLabel}+$index)
|
||||
jsr prog8_lib.copy_float
|
||||
"""
|
||||
},
|
||||
// assignment: floatarray[idxbyte] = memfloat
|
||||
AsmPattern(listOf(Opcode.PUSH_MEM_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment ->
|
||||
val index = segment[1].arg!!.integerValue() * Mflpt5.MemorySize
|
||||
"""
|
||||
lda #<${segment[0].arg!!.integerValue().toHex()}
|
||||
ldy #>${segment[0].arg!!.integerValue().toHex()}
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
lda #<(${segment[2].callLabel}+$index)
|
||||
ldy #>(${segment[2].callLabel}+$index)
|
||||
jsr prog8_lib.copy_float
|
||||
"""
|
||||
}
|
||||
// // assignment: wordarray[idxbyte] = word
|
||||
// AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
// val index = segment[1].arg!!.integerValue()*2
|
||||
// """
|
||||
// lda #<${segment[0].arg!!.integerValue().toHex()}
|
||||
// ldy #>${segment[0].arg!!.integerValue().toHex()}
|
||||
// sta ${segment[2].callLabel}+$index
|
||||
// sty ${segment[2].callLabel}+${index+1}
|
||||
// """
|
||||
// },
|
||||
//
|
||||
// // assignment: wordarray[memory (u)byte] = word
|
||||
// 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 ->
|
||||
// TODO("$segment")
|
||||
// },
|
||||
//
|
||||
// // assignment: wordarray[indexvar] = word
|
||||
// AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
// TODO("$segment")
|
||||
// },
|
||||
// // assignment: wordarray[idxbyte] = wordvar
|
||||
// AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
// val index = segment[1].arg!!.integerValue()*2
|
||||
// when(segment[0].callLabel) {
|
||||
// "AX" -> " sta ${segment[2].callLabel}+$index | stx ${segment[2].callLabel}+${index+1}"
|
||||
// "AY" -> " sta ${segment[2].callLabel}+$index | sty ${segment[2].callLabel}+${index+1}"
|
||||
// "XY" -> " stx ${segment[2].callLabel}+$index | sty ${segment[2].callLabel}+${index+1}"
|
||||
// else ->
|
||||
// """
|
||||
// lda ${segment[0].callLabel}
|
||||
// ldy ${segment[0].callLabel}+1
|
||||
// sta ${segment[2].callLabel}+$index
|
||||
// sty ${segment[2].callLabel}+${index+1}
|
||||
// """
|
||||
// }
|
||||
// },
|
||||
// // assignment: wordarray[indexvar] = wordvar
|
||||
// AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
// TODO("$segment")
|
||||
// },
|
||||
// // assignment: wordarray[idxbyte] = mem(u)word
|
||||
// AsmPattern(
|
||||
// listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD),
|
||||
// listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment ->
|
||||
// val index = segment[1].arg!!.integerValue()*2
|
||||
// """
|
||||
// lda ${segment[0].arg!!.integerValue().toHex()}
|
||||
// ldy ${(segment[0].arg!!.integerValue()+1).toHex()}
|
||||
// sta ${segment[2].callLabel}+$index
|
||||
// sty ${segment[2].callLabel}+${index+1}
|
||||
// """
|
||||
// },
|
||||
//
|
||||
//
|
||||
// // assignment: wordarrayw[index2] = wordarray1[index1]
|
||||
// AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment->
|
||||
// val index1 = segment[0].arg!!.integerValue()*2
|
||||
// val index2 = segment[2].arg!!.integerValue()*2
|
||||
// """
|
||||
// lda ${segment[1].callLabel}+$index1
|
||||
// ldy ${segment[1].callLabel}+${index1+1}
|
||||
// sta ${segment[3].callLabel}+$index2
|
||||
// sty ${segment[3].callLabel}+${index2+1}
|
||||
// """
|
||||
// },
|
||||
//
|
||||
// // assignment: floatarray[idxbyte] = float
|
||||
// AsmPattern(listOf(Opcode.PUSH_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment ->
|
||||
// val floatConst = getFloatConst(segment[0].arg!!)
|
||||
// val index = segment[1].arg!!.integerValue() * Mflpt5.MemorySize
|
||||
// """
|
||||
// lda #<$floatConst
|
||||
// ldy #>$floatConst
|
||||
// sta ${C64Zeropage.SCRATCH_W1}
|
||||
// sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
// lda #<(${segment[2].callLabel}+$index)
|
||||
// ldy #>(${segment[2].callLabel}+$index)
|
||||
// jsr prog8_lib.copy_float
|
||||
// """
|
||||
// },
|
||||
// // assignment: floatarray[idxbyte] = floatvar
|
||||
// AsmPattern(listOf(Opcode.PUSH_VAR_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment ->
|
||||
// val index = segment[1].arg!!.integerValue() * Mflpt5.MemorySize
|
||||
// """
|
||||
// lda #<${segment[0].callLabel}
|
||||
// ldy #>${segment[0].callLabel}
|
||||
// sta ${C64Zeropage.SCRATCH_W1}
|
||||
// sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
// lda #<(${segment[2].callLabel}+$index)
|
||||
// ldy #>(${segment[2].callLabel}+$index)
|
||||
// jsr prog8_lib.copy_float
|
||||
// """
|
||||
// },
|
||||
// // assignment: floatarray[idxbyte] = memfloat
|
||||
// AsmPattern(listOf(Opcode.PUSH_MEM_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment ->
|
||||
// val index = segment[1].arg!!.integerValue() * Mflpt5.MemorySize
|
||||
// """
|
||||
// lda #<${segment[0].arg!!.integerValue().toHex()}
|
||||
// ldy #>${segment[0].arg!!.integerValue().toHex()}
|
||||
// sta ${C64Zeropage.SCRATCH_W1}
|
||||
// sty ${C64Zeropage.SCRATCH_W1+1}
|
||||
// lda #<(${segment[2].callLabel}+$index)
|
||||
// ldy #>(${segment[2].callLabel}+$index)
|
||||
// jsr prog8_lib.copy_float
|
||||
// """
|
||||
// }
|
||||
|
||||
)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user