mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 04:30:03 +00:00
removed support for indexing on register pairs
This commit is contained in:
parent
6d21274090
commit
625791e5e8
@ -50,12 +50,12 @@ sub start() {
|
||||
|
||||
; all possible assignments to a BYTE VARIABLE (not array)
|
||||
|
||||
|
||||
byte_assignment_to_register:
|
||||
A = 42
|
||||
A = X
|
||||
A = ub2
|
||||
A = mubyte2
|
||||
A = AY[4]
|
||||
A = ubarr1[2]
|
||||
A = string[4]
|
||||
A = string[X]
|
||||
@ -64,16 +64,12 @@ byte_assignment_to_register:
|
||||
A = ubarr1[X]
|
||||
A = ubarr1[b]
|
||||
A = ubarr1[ub]
|
||||
A = AY[Y]
|
||||
A = AY[b]
|
||||
A = AY[ub]
|
||||
|
||||
ubyte_assignment_to_ubytevar:
|
||||
ub = 42
|
||||
ub = X
|
||||
ub = ub2
|
||||
ub = mubyte2
|
||||
ub = AY[4]
|
||||
ub = ubarr1[2]
|
||||
ub = string[4]
|
||||
ub = string[X]
|
||||
@ -82,9 +78,6 @@ ubyte_assignment_to_ubytevar:
|
||||
ub = ubarr1[X]
|
||||
ub = ubarr1[b]
|
||||
ub = ubarr1[ub]
|
||||
ub = AY[Y]
|
||||
ub = AY[b]
|
||||
ub = AY[ub]
|
||||
|
||||
|
||||
ubyte_assignment_to_ubytemem:
|
||||
@ -92,7 +85,6 @@ ubyte_assignment_to_ubytemem:
|
||||
mubyte = X
|
||||
mubyte = ub2
|
||||
mubyte = mubyte2
|
||||
mubyte = AY[4]
|
||||
mubyte = ubarr1[2]
|
||||
mubyte = string[4]
|
||||
mubyte = string[X]
|
||||
@ -101,9 +93,6 @@ ubyte_assignment_to_ubytemem:
|
||||
mubyte = ubarr1[X]
|
||||
mubyte = ubarr1[b]
|
||||
mubyte = ubarr1[ub]
|
||||
mubyte = AY[Y]
|
||||
mubyte = AY[b]
|
||||
mubyte = AY[ub]
|
||||
|
||||
byte_assignment_to_bytevar:
|
||||
b = -42
|
||||
@ -130,7 +119,6 @@ ubyte_assignment_to_ubytearray:
|
||||
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]
|
||||
@ -139,27 +127,11 @@ ubyte_assignment_to_ubytearray:
|
||||
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]
|
||||
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]
|
||||
|
||||
@ -168,7 +140,6 @@ ubyte_assignment_to_ubytearray:
|
||||
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]
|
||||
@ -177,27 +148,11 @@ ubyte_assignment_to_ubytearray:
|
||||
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]
|
||||
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]
|
||||
|
||||
@ -206,7 +161,6 @@ ubyte_assignment_to_ubytearray:
|
||||
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]
|
||||
@ -215,27 +169,11 @@ ubyte_assignment_to_ubytearray:
|
||||
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]
|
||||
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]
|
||||
|
||||
@ -243,7 +181,6 @@ ubyte_assignment_to_ubytearray:
|
||||
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]
|
||||
@ -252,27 +189,11 @@ ubyte_assignment_to_ubytearray:
|
||||
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]
|
||||
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]
|
||||
|
||||
|
@ -738,9 +738,8 @@ class AstChecker(private val namespace: INameScope,
|
||||
}
|
||||
} else
|
||||
checkResult.add(SyntaxError("indexing requires a variable to act upon", arrayIndexedExpression.position))
|
||||
} else if(reg==Register.A || reg==Register.X || reg==Register.Y) {
|
||||
checkResult.add(SyntaxError("indexing on registers requires register pair variable", arrayIndexedExpression.position))
|
||||
}
|
||||
} else
|
||||
checkResult.add(SyntaxError("indexing on register variable is not possible, use a regular array variable instead", arrayIndexedExpression.position))
|
||||
|
||||
// check index value 0..255
|
||||
val regx = (arrayIndexedExpression.arrayspec.x as? RegisterExpr)?.register
|
||||
|
@ -914,114 +914,22 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
|
||||
private fun loadAFromIndexedByVar(idxVarInstr: Instruction, readArrayInstr: Instruction): String {
|
||||
// A = readArrayInstr [ idxVarInstr ]
|
||||
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 when (idxVarInstr.callLabel) {
|
||||
"A" -> " tay | lda ${readArrayInstr.callLabel},y"
|
||||
"X" -> " txa | tay | lda ${readArrayInstr.callLabel},y"
|
||||
"Y" -> " lda ${readArrayInstr.callLabel},y"
|
||||
else -> " ldy ${idxVarInstr.callLabel} | lda ${readArrayInstr.callLabel},y"
|
||||
}
|
||||
return "$setupPtr | $loadByte"
|
||||
}
|
||||
|
||||
private fun storeAToIndexedByVar(idxVarInstr: Instruction, writeArrayInstr: Instruction): String {
|
||||
// writeArrayInstr [ idxVarInstr ] = A
|
||||
val setupPtr: String
|
||||
val storeByte: String
|
||||
when(writeArrayInstr.callLabel) {
|
||||
"AX" -> {
|
||||
setupPtr = "sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
storeByte= when (idxVarInstr.callLabel) {
|
||||
"A" -> "tay | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "stx ${C64Zeropage.SCRATCH_B1} | ldy ${C64Zeropage.SCRATCH_B1} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${idxVarInstr.callLabel} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
"AY" -> {
|
||||
setupPtr = "sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
storeByte= when (idxVarInstr.callLabel) {
|
||||
"A" -> "tay | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "stx ${C64Zeropage.SCRATCH_B1} | ldy ${C64Zeropage.SCRATCH_B1} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${idxVarInstr.callLabel} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
"XY" -> {
|
||||
setupPtr = "stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1 + 1} "
|
||||
storeByte= when (idxVarInstr.callLabel) {
|
||||
"A" -> "tay | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> "stx ${C64Zeropage.SCRATCH_B1} | ldy ${C64Zeropage.SCRATCH_B1} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"Y" -> "sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
else -> "ldy ${idxVarInstr.callLabel} | sta (${C64Zeropage.SCRATCH_W1}),y"
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
when (idxVarInstr.callLabel) {
|
||||
"A" -> {
|
||||
setupPtr = ""
|
||||
storeByte = "tay | sta ${writeArrayInstr.callLabel},y"
|
||||
}
|
||||
"X" -> {
|
||||
setupPtr = ""
|
||||
storeByte = "sta ${C64Zeropage.SCRATCH_B1} | ldy ${C64Zeropage.SCRATCH_B1} | sta ${writeArrayInstr.callLabel},y"
|
||||
}
|
||||
"Y" -> {
|
||||
setupPtr = ""
|
||||
storeByte = "sta ${writeArrayInstr.callLabel},y"
|
||||
}
|
||||
else -> {
|
||||
setupPtr = ""
|
||||
storeByte = "ldy ${idxVarInstr.callLabel} | sta ${writeArrayInstr.callLabel},y"
|
||||
}
|
||||
}
|
||||
}
|
||||
return when (idxVarInstr.callLabel) {
|
||||
"A" -> " tay | sta ${writeArrayInstr.callLabel},y"
|
||||
"X" -> " sta ${C64Zeropage.SCRATCH_B1} | ldy ${C64Zeropage.SCRATCH_B1} | sta ${writeArrayInstr.callLabel},y"
|
||||
"Y" -> " sta ${writeArrayInstr.callLabel},y"
|
||||
else -> " ldy ${idxVarInstr.callLabel} | sta ${writeArrayInstr.callLabel},y"
|
||||
}
|
||||
return "$setupPtr | $storeByte"
|
||||
}
|
||||
|
||||
private val patterns = listOf(
|
||||
@ -1081,32 +989,11 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
// 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) {
|
||||
"AX" -> when(segment[2].callLabel) {
|
||||
"A" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | tax"
|
||||
"Y" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | tay"
|
||||
else -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta ${segment[2].callLabel}"
|
||||
}
|
||||
"AY" -> when(segment[2].callLabel) {
|
||||
"A" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | tax"
|
||||
"Y" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | tay"
|
||||
else -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta ${segment[2].callLabel}"
|
||||
}
|
||||
"XY" -> when(segment[2].callLabel) {
|
||||
"A" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y"
|
||||
"X" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | tax"
|
||||
"Y" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | tay"
|
||||
else -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta ${segment[2].callLabel}"
|
||||
}
|
||||
when (segment[2].callLabel) {
|
||||
"A", "X", "Y" ->
|
||||
" ld${segment[2].callLabel!!.toLowerCase()} ${segment[1].callLabel}+$index"
|
||||
else ->
|
||||
when (segment[2].callLabel) {
|
||||
"A", "X", "Y" ->
|
||||
" ld${segment[2].callLabel!!.toLowerCase()} ${segment[1].callLabel}+$index"
|
||||
else ->
|
||||
" lda ${segment[1].callLabel}+$index | sta ${segment[2].callLabel}"
|
||||
}
|
||||
" lda ${segment[1].callLabel}+$index | sta ${segment[2].callLabel}"
|
||||
}
|
||||
},
|
||||
// var = (u)bytearray[indexvar]
|
||||
@ -1115,7 +1002,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
when(segment[2].callLabel) {
|
||||
"A" -> " $loadByteA"
|
||||
"X" -> " $loadByteA | tax"
|
||||
"Y" -> " $loadByteA | tya"
|
||||
"Y" -> " $loadByteA | tay"
|
||||
else -> " $loadByteA | sta ${segment[2].callLabel}"
|
||||
}
|
||||
},
|
||||
@ -1145,12 +1032,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
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()
|
||||
when(segment[1].callLabel) {
|
||||
"AX" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta $address"
|
||||
"AY" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta $address"
|
||||
"XY" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta $address"
|
||||
else -> " lda ${segment[1].callLabel}+$index | sta $address"
|
||||
}
|
||||
" 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->
|
||||
@ -1164,42 +1046,16 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
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"
|
||||
}
|
||||
" 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"
|
||||
"A" -> " sta ${segment[2].callLabel}+$index"
|
||||
"X" -> " stx ${segment[2].callLabel}+$index"
|
||||
"Y" -> " sty ${segment[2].callLabel}+$index"
|
||||
else -> " lda ${segment[0].callLabel} | sta ${segment[2].callLabel}+$index"
|
||||
}
|
||||
},
|
||||
// bytearray[index] = mem(u)byte
|
||||
@ -1207,12 +1063,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
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"
|
||||
}
|
||||
" 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 ->
|
||||
@ -1223,48 +1074,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
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"
|
||||
}
|
||||
}
|
||||
" 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 ->
|
||||
@ -1293,28 +1103,7 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
val storeA = storeAToIndexedByVar(segment[2], segment[3])
|
||||
val index1 = segment[0].arg!!.integerValue()
|
||||
val loadValue = when (segment[1].callLabel) {
|
||||
"AX" -> """
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
stx ${C64Zeropage.SCRATCH_W1 + 1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
"""
|
||||
"AY" -> """
|
||||
sta ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1 + 1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
"""
|
||||
"XY" -> """
|
||||
stx ${C64Zeropage.SCRATCH_W1}
|
||||
sty ${C64Zeropage.SCRATCH_W1 + 1}
|
||||
ldy #$index1
|
||||
lda (${C64Zeropage.SCRATCH_W1}),y
|
||||
"""
|
||||
else -> " lda ${segment[1].callLabel}+$index1 "
|
||||
}
|
||||
" $loadValue | $storeA "
|
||||
" lda ${segment[1].callLabel}+$index1 | $storeA"
|
||||
},
|
||||
// (u)bytearray2[idxvar2] = (u)bytearray1[idxvar1]
|
||||
AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment ->
|
||||
@ -1462,17 +1251,11 @@ class AsmGen(val options: CompilationOptions, val program: IntermediateProgram,
|
||||
// var = ubytearray[index_byte]
|
||||
AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.UB2UWORD, Opcode.POP_VAR_WORD)) { segment ->
|
||||
val index = segment[0].arg!!.integerValue().toHex()
|
||||
when(segment[1].callLabel) {
|
||||
"AX" -> " sta ${C64Zeropage.SCRATCH_W1} | stx ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta ${segment[3].callLabel} | lda #0 | sta ${segment[3].callLabel}+1"
|
||||
"AY" -> " sta ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta ${segment[3].callLabel} | lda #0 | sta ${segment[3].callLabel}+1"
|
||||
"XY" -> " stx ${C64Zeropage.SCRATCH_W1} | sty ${C64Zeropage.SCRATCH_W1+1} | ldy #$index | lda (${C64Zeropage.SCRATCH_W1}),y | sta ${segment[3].callLabel} | lda #0 | sta ${segment[3].callLabel}+1"
|
||||
else ->
|
||||
when(segment[3].callLabel) {
|
||||
"AX" -> " lda ${segment[1].callLabel}+$index | ldx #0"
|
||||
"AY" -> " lda ${segment[1].callLabel}+$index | ldy #0"
|
||||
"XY" -> " ldx ${segment[1].callLabel}+$index | ldy #0"
|
||||
else -> " lda ${segment[1].callLabel}+$index | sta ${segment[3].callLabel} | lda #0 | sta ${segment[3].callLabel}+1"
|
||||
}
|
||||
when(segment[3].callLabel) {
|
||||
"AX" -> " lda ${segment[1].callLabel}+$index | ldx #0"
|
||||
"AY" -> " lda ${segment[1].callLabel}+$index | ldy #0"
|
||||
"XY" -> " ldx ${segment[1].callLabel}+$index | ldy #0"
|
||||
else -> " lda ${segment[1].callLabel}+$index | sta ${segment[3].callLabel} | lda #0 | sta ${segment[3].callLabel}+1"
|
||||
}
|
||||
},
|
||||
// var = bytearray[index_byte] (sign extended)
|
||||
|
Loading…
x
Reference in New Issue
Block a user