From 173663380b1467ecac7ad58e06ea4ed60930a25e Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 20 Jul 2019 22:37:16 +0200 Subject: [PATCH] slight optimization for creating the asmpatterns list --- .../compiler/target/c64/codegen/AsmGen.kt | 2 +- .../target/c64/codegen/AsmPatterns.kt | 822 +++++++++--------- 2 files changed, 414 insertions(+), 410 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index b08c4aa74..726dc5645 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -536,7 +536,7 @@ class AsmGen(private val options: CompilationOptions, private val program: Inter } // add any matching patterns from the big list - for(pattern in patterns) { + for(pattern in Patterns.patterns) { if(pattern.sequence.size > segment.size || (pattern.altSequence!=null && pattern.altSequence.size > segment.size)) continue // don't accept patterns that don't fit val opcodesList = opcodes.subList(0, pattern.sequence.size) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmPatterns.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmPatterns.kt index a3b33ff7e..d2a2d3923 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmPatterns.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmPatterns.kt @@ -109,19 +109,23 @@ internal fun optimizedIntMultiplicationsOnStack(mulIns: Instruction, amount: Int return null } -internal val patterns = listOf( +object Patterns { + internal val patterns = mutableListOf() + + init { + // ----------- assignment to BYTE VARIABLE ---------------- // var = (u)bytevalue - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.POP_VAR_BYTE)) { segment -> when (segment[1].callLabel) { "A", "X", "Y" -> " ld${segment[1].callLabel!!.toLowerCase()} #${hexVal(segment[0])}" else -> " lda #${hexVal(segment[0])} | sta ${segment[1].callLabel}" } - }, + }) // var = other var - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> when (segment[1].callLabel) { "A" -> when (segment[0].callLabel) { @@ -152,18 +156,18 @@ internal val patterns = listOf( else -> " lda ${segment[0].callLabel} | sta ${segment[1].callLabel}" } } - }, + }) // var = mem (u)byte - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.POP_VAR_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.POP_VAR_BYTE)) { segment -> when (segment[1].callLabel) { "A", "X", "Y" -> " ld${segment[1].callLabel!!.toLowerCase()} ${hexVal(segment[0])}" else -> " lda ${hexVal(segment[0])} | sta ${segment[1].callLabel}" } - }, + }) // var = (u)bytearray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> val index = intVal(segment[0]) when (segment[2].callLabel) { "A", "X", "Y" -> @@ -171,9 +175,9 @@ internal val patterns = listOf( else -> " lda ${segment[1].callLabel}+$index | sta ${segment[2].callLabel}" } - }, + }) // var = (u)bytearray[indexvar] - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> val loadByteA = loadAFromIndexedByVar(segment[0], segment[1]) when (segment[2].callLabel) { "A" -> " $loadByteA" @@ -181,9 +185,9 @@ internal val patterns = listOf( "Y" -> " $loadByteA | tay" else -> " $loadByteA | sta ${segment[2].callLabel}" } - }, + }) // var = (u)bytearray[mem index var] - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_VAR_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> val loadByteA = " ldy ${hexVal(segment[0])} | lda ${segment[1].callLabel},y" @@ -193,42 +197,42 @@ internal val patterns = listOf( "Y" -> " $loadByteA | tay" else -> " $loadByteA | sta ${segment[2].callLabel}" } - }, + }) // ----------- assignment to BYTE MEMORY ---------------- // mem = (u)byte value - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.POP_MEM_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.POP_MEM_BYTE)) { segment -> " lda #${hexVal(segment[0])} | sta ${hexVal(segment[1])}" - }, + }) // mem = (u)bytevar - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.POP_MEM_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.POP_MEM_BYTE)) { segment -> when (segment[0].callLabel) { "A" -> " sta ${hexVal(segment[1])}" "X" -> " stx ${hexVal(segment[1])}" "Y" -> " sty ${hexVal(segment[1])}" else -> " lda ${segment[0].callLabel} | sta ${hexVal(segment[1])}" } - }, + }) // mem = mem (u)byte - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.POP_MEM_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.POP_MEM_BYTE)) { segment -> " lda ${hexVal(segment[0])} | sta ${hexVal(segment[1])}" - }, + }) // mem = (u)bytearray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_MEM_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_MEM_BYTE)) { segment -> val address = hexVal(segment[2]) val index = intVal(segment[0]) " 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 -> +patterns.add(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 ${hexVal(segment[2])}" - }, + }) // mem = (u)bytearray[mem index var] - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_MEM_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.POP_MEM_BYTE)) { segment -> """ @@ -236,18 +240,18 @@ internal val patterns = listOf( lda ${segment[1].callLabel},y sta ${hexVal(segment[2])} """ - }, + }) // ----------- assignment to BYTE ARRAY ---------------- // bytearray[index] = (u)byte value - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val index = intVal(segment[1]) val value = hexVal(segment[0]) " 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 -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val index = intVal(segment[1]) when (segment[0].callLabel) { "A" -> " sta ${segment[2].callLabel}+$index" @@ -255,22 +259,22 @@ internal val patterns = listOf( "Y" -> " sty ${segment[2].callLabel}+$index" else -> " lda ${segment[0].callLabel} | sta ${segment[2].callLabel}+$index" } - }, + }) // bytearray[index] = mem(u)byte - AsmPattern( +patterns.add(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 = intVal(segment[1]) " lda ${hexVal(segment[0])} | 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 -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val storeA = storeAToIndexedByVar(segment[1], segment[2]) " lda #${hexVal(segment[0])} | $storeA" - }, + }) // (u)bytearray[index var] = (u)bytevar - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val storeA = storeAToIndexedByVar(segment[1], segment[2]) when (segment[0].callLabel) { "A" -> " $storeA" @@ -278,25 +282,25 @@ internal val patterns = listOf( "Y" -> " tya | $storeA" else -> " lda ${segment[0].callLabel} | $storeA" } - }, + }) // (u)bytearray[index var] = mem (u)byte - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_UB, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE), listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val storeA = storeAToIndexedByVar(segment[1], segment[2]) " lda ${hexVal(segment[0])} | $storeA" - }, + }) // bytearray[index mem] = (u)byte value - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> """ lda #${hexVal(segment[0])} ldy ${hexVal(segment[1])} sta ${segment[2].callLabel},y """ - }, + }) // bytearray[index mem] = (u)byte var - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val loadY = " ldy ${hexVal(segment[1])}" when (segment[0].callLabel) { "A" -> " $loadY | sta ${segment[2].callLabel},y" @@ -304,9 +308,9 @@ internal val patterns = listOf( "Y" -> " tya | $loadY | sta ${segment[2].callLabel},y" else -> " lda ${segment[0].callLabel} | $loadY | sta ${segment[2].callLabel},y" } - }, + }) // bytearray[index mem] = mem(u)byte - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> """ @@ -314,22 +318,22 @@ internal val patterns = listOf( lda ${hexVal(segment[0])} sta ${segment[2].callLabel},y """ - }, + }) // (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 -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val index1 = intVal(segment[0]) val index2 = intVal(segment[2]) " 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 -> +patterns.add(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 = intVal(segment[2]) " $loadByteA | sta ${segment[3].callLabel}+$index2" - }, + }) // (u)bytearray[index2] = (u)bytearray[mem ubyte] - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val index2 = intVal(segment[2]) @@ -338,43 +342,43 @@ internal val patterns = listOf( lda ${segment[1].callLabel},y sta ${segment[3].callLabel}+$index2 """ - }, + }) // (u)bytearray2[idxvar2] = (u)bytearray1[index1] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> +patterns.add(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 = intVal(segment[0]) " lda ${segment[1].callLabel}+$index1 | $storeA" - }, + }) // (u)bytearray2[idxvar2] = (u)bytearray1[idxvar] - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val loadA = loadAFromIndexedByVar(segment[0], segment[1]) val storeA = storeAToIndexedByVar(segment[2], segment[3]) " $loadA | $storeA" - }, + }) // (u)bytearray2[idxvar2] = (u)bytearray1[mem ubyte] - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val storeA = storeAToIndexedByVar(segment[2], segment[3]) " ldy ${hexVal(segment[0])} | lda ${segment[1].callLabel},y | $storeA" - }, + }) // (u)bytearray2[index mem] = (u)bytearray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val index1 = intVal(segment[0]) """ lda ${segment[1].callLabel}+$index1 ldy ${hexVal(segment[2])} sta ${segment[3].callLabel},y """ - }, + }) // ----------- assignment to WORD VARIABLE ---------------- // var = wordvalue - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_VAR_WORD)) { segment -> val number = hexVal(segment[0]) """ lda #<$number @@ -382,40 +386,40 @@ internal val patterns = listOf( sta ${segment[1].callLabel} sty ${segment[1].callLabel}+1 """ - }, + }) // var = ubytevar - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_VAR_WORD)) { segment -> when (segment[0].callLabel) { "A" -> " sta ${segment[2].callLabel} | lda #0 | sta ${segment[2].callLabel}+1" "X" -> " stx ${segment[2].callLabel} | lda #0 | sta ${segment[2].callLabel}+1" "Y" -> " sty ${segment[2].callLabel} | lda #0 | sta ${segment[2].callLabel}+1" else -> " lda ${segment[0].callLabel} | sta ${segment[2].callLabel} | lda #0 | sta ${segment[2].callLabel}+1" } - }, + }) // var = other var - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_VAR_WORD)) { segment -> """ lda ${segment[0].callLabel} ldy ${segment[0].callLabel}+1 sta ${segment[1].callLabel} sty ${segment[1].callLabel}+1 """ - }, + }) // var = address-of other var - AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_VAR_WORD)) { segment -> """ lda #<${segment[0].callLabel} ldy #>${segment[0].callLabel} sta ${segment[1].callLabel} sty ${segment[1].callLabel}+1 """ - }, + }) // var = mem ubyte - AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.POP_VAR_WORD)) { segment -> " lda ${hexVal(segment[0])} | sta ${segment[2].callLabel} | lda #0 | sta ${segment[2].callLabel}+1" - }, + }) // var = mem (u)word - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_W, Opcode.POP_VAR_WORD), listOf(Opcode.PUSH_MEM_UW, Opcode.POP_VAR_WORD)) { segment -> """ @@ -424,19 +428,19 @@ internal val patterns = listOf( lda ${hexValPlusOne(segment[0])} sta ${segment[1].callLabel}+1 """ - }, + }) // var = ubytearray[index_byte] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_VAR_WORD)) { segment -> val index = hexVal(segment[0]) " 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.CAST_UB_TO_UW, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, 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( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_VAR_WORD), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_VAR_WORD)) { segment -> """ @@ -445,23 +449,23 @@ internal val patterns = listOf( 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 -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_VAR_WORD)) { segment -> val index = intVal(segment[0]) * 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 -> +patterns.add(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( +patterns.add(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 -> """ @@ -473,44 +477,44 @@ internal val patterns = listOf( 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 -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_MEM_WORD)) { segment -> """ lda #<${hexVal(segment[0])} ldy #>${hexVal(segment[0])} sta ${hexVal(segment[1])} sty ${hexValPlusOne(segment[1])} """ - }, + }) // mem uword = ubyte var - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> when (segment[0].callLabel) { "A" -> " sta ${hexVal(segment[2])} | lda #0 | sta ${hexValPlusOne(segment[2])}" "X" -> " stx ${hexVal(segment[2])} | lda #0 | sta ${hexValPlusOne(segment[2])}" "Y" -> " sty ${hexVal(segment[2])} | lda #0 | sta ${hexValPlusOne(segment[2])}" else -> " lda ${segment[0].callLabel} || sta ${hexVal(segment[2])} | lda #0 | sta ${hexValPlusOne(segment[2])}" } - }, + }) // mem uword = mem ubyte - AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> """ lda ${hexVal(segment[0])} sta ${hexVal(segment[2])} lda #0 sta ${hexValPlusOne(segment[2])} """ - }, + }) // mem uword = uword var - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_MEM_WORD)) { segment -> " lda ${segment[0].callLabel} | ldy ${segment[0].callLabel}+1 | sta ${hexVal(segment[1])} | sty ${hexValPlusOne(segment[1])}" - }, + }) // mem uword = address-of var - AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_MEM_WORD)) { segment -> " lda #<${segment[0].callLabel} | ldy #>${segment[0].callLabel} | sta ${hexVal(segment[1])} | sty ${hexValPlusOne(segment[1])}" - }, + }) // mem (u)word = mem (u)word - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_UW, Opcode.POP_MEM_WORD), listOf(Opcode.PUSH_MEM_W, Opcode.POP_MEM_WORD)) { segment -> """ @@ -519,9 +523,9 @@ internal val patterns = listOf( sta ${hexVal(segment[1])} sty ${hexValPlusOne(segment[1])} """ - }, + }) // mem uword = ubytearray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> val index = intVal(segment[0]) """ lda ${segment[1].callLabel}+$index @@ -529,27 +533,27 @@ internal val patterns = listOf( sta ${hexVal(segment[3])} sty ${hexValPlusOne(segment[3])} """ - }, + }) // mem uword = bytearray[index] (sign extended) - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> val index = intVal(segment[0]) """ lda ${segment[1].callLabel}+$index sta ${hexVal(segment[3])} ${signExtendA(hexValPlusOne(segment[3]))} """ - }, + }) // mem uword = bytearray[index var] (sign extended) - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> val loadA = loadAFromIndexedByVar(segment[0], segment[1]) """ $loadA sta ${hexVal(segment[3])} ${signExtendA(hexValPlusOne(segment[3]))} """ - }, + }) // mem uword = bytearray[mem (u)byte] (sign extended) - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> """ @@ -557,14 +561,14 @@ internal val patterns = listOf( sta ${hexVal(segment[3])} ${signExtendA(hexValPlusOne(segment[3]))} """ - }, + }) // mem uword = ubytearray[index var] - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> val loadA = loadAFromIndexedByVar(segment[0], segment[1]) " $loadA | sta ${hexVal(segment[3])} | lda #0 | sta ${hexValPlusOne(segment[3])}" - }, + }) // mem uword = ubytearray[mem (u)bute] - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.POP_MEM_WORD)) { segment -> """ @@ -573,9 +577,9 @@ internal val patterns = listOf( lda #0 sta ${hexValPlusOne(segment[3])} """ - }, + }) // mem uword = (u)wordarray[indexvalue] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_MEM_WORD)) { segment -> val index = intVal(segment[0]) * 2 """ lda ${segment[1].callLabel}+$index @@ -583,18 +587,18 @@ internal val patterns = listOf( sta ${hexVal(segment[2])} sty ${hexValPlusOne(segment[2])} """ - }, + }) // mem uword = (u)wordarray[index var] - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_MEM_WORD)) { segment -> val loadAY = loadAYFromWordIndexedByVar(segment[0], segment[1]) """ $loadAY sta ${hexVal(segment[2])} sty ${hexValPlusOne(segment[2])} """ - }, + }) // mem uword = (u)wordarray[mem index] - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_MEM_WORD), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_WORD, Opcode.POP_MEM_WORD)) { segment -> """ @@ -606,59 +610,59 @@ internal val patterns = listOf( lda ${segment[1].callLabel}+1,y sta ${hexValPlusOne(segment[2])} """ - }, + }) // word var = bytevar (sign extended) - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> """ lda ${segment[0].callLabel} sta ${segment[2].callLabel} ${signExtendA(segment[2].callLabel + "+1")} """ - }, + }) // mem word = bytevar (sign extended) - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> """ lda ${segment[0].callLabel} sta ${hexVal(segment[2])} ${signExtendA(hexValPlusOne(segment[2]))} """ - }, + }) // mem word = mem byte (sign extended) - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.POP_MEM_WORD)) { segment -> """ lda ${hexVal(segment[0])} sta ${hexVal(segment[2])} ${signExtendA(hexValPlusOne(segment[2]))} """ - }, + }) // var = membyte (sign extended) - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> """ lda ${hexVal(segment[0])} sta ${segment[2].callLabel} ${signExtendA(segment[2].callLabel + "+1")} """ - }, + }) // var = bytearray[index_byte] (sign extended) - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> val index = hexVal(segment[0]) """ lda ${segment[1].callLabel}+$index sta ${segment[3].callLabel} ${signExtendA(segment[3].callLabel + "+1")} """ - }, + }) // var = bytearray[index var] (sign extended) - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> val loadByteA = loadAFromIndexedByVar(segment[0], segment[1]) """ $loadByteA sta ${segment[3].callLabel} ${signExtendA(segment[3].callLabel + "+1")} """ - }, + }) // var = bytearray[mem (u)byte] (sign extended) - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD), listOf(Opcode.PUSH_MEM_UB, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.POP_VAR_WORD)) { segment -> """ @@ -666,11 +670,11 @@ internal val patterns = listOf( sta ${segment[3].callLabel} ${signExtendA(segment[3].callLabel + "+1")} """ - }, + }) // ----------- assignment to UWORD ARRAY ---------------- // uwordarray[index] = (u)word value - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[1]) * 2 val value = hexVal(segment[0]) """ @@ -679,9 +683,9 @@ internal val patterns = listOf( sta ${segment[2].callLabel}+$index sty ${segment[2].callLabel}+${index + 1} """ - }, + }) // uwordarray[index mem] = (u)word value - AsmPattern( +patterns.add(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 = hexVal(segment[0]) @@ -694,9 +698,9 @@ internal val patterns = listOf( lda #>$value sta ${segment[2].callLabel}+1,y """ - }, + }) // uwordarray[index mem] = mem (u)word - AsmPattern( +patterns.add(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 -> """ @@ -708,9 +712,9 @@ internal val patterns = listOf( lda ${hexValPlusOne(segment[0])} sta ${segment[2].callLabel}+1,y """ - }, + }) // uwordarray[index mem] = (u)word var - AsmPattern( +patterns.add(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 -> """ @@ -722,9 +726,9 @@ internal val patterns = listOf( lda ${segment[0].callLabel}+1 sta ${segment[2].callLabel}+1,y """ - }, + }) // uwordarray[index mem] = address-of var - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> """ @@ -736,9 +740,9 @@ internal val patterns = listOf( lda #>${segment[0].callLabel} sta ${segment[2].callLabel}+1,y """ - }, + }) // uwordarray[index] = ubytevar - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[2]) * 2 when (segment[0].callLabel) { "A" -> " sta ${segment[3].callLabel}+$index | lda #0 | sta ${segment[3].callLabel}+${index + 1}" @@ -746,9 +750,9 @@ internal val patterns = listOf( "Y" -> " sty ${segment[3].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}" } - }, + }) // wordarray[index] = bytevar (extend sign) - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[2]) * 2 when (segment[0].callLabel) { "A" -> @@ -775,9 +779,9 @@ internal val patterns = listOf( ${signExtendA(segment[3].callLabel + "+${index + 1}")} """ } - }, + }) // wordarray[index mem] = bytevar (extend sign) - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> when (segment[0].callLabel) { @@ -822,9 +826,9 @@ internal val patterns = listOf( ${signExtendA(segment[3].callLabel + "+1,y")} """ } - }, + }) // wordarray[memory (u)byte] = ubyte mem - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> """ @@ -835,18 +839,18 @@ internal val patterns = listOf( sta ${segment[3].callLabel},y ${signExtendA(segment[3].callLabel + "+1,y")} """ - }, + }) // wordarray[index] = mem byte (extend sign) - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[2]) * 2 """ lda ${hexVal(segment[0])} sta ${segment[3].callLabel}+$index ${signExtendA(segment[3].callLabel + "+${index + 1}")} """ - }, + }) // wordarray2[index2] = bytearray1[index1] (extend sign) - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index1 = intVal(segment[0]) val index2 = segment[3].arg!!.integerValue() * 2 """ @@ -854,9 +858,9 @@ internal val patterns = listOf( sta ${segment[4].callLabel}+$index2 ${signExtendA(segment[4].callLabel + "+${index2 + 1}")} """ - }, + }) // wordarray2[mem (u)byte] = bytearray1[index1] (extend sign) - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index1 = intVal(segment[0]) @@ -868,10 +872,10 @@ internal val patterns = listOf( sta ${segment[4].callLabel},y ${signExtendA(segment[4].callLabel + "+1,y")} """ - }, + }) // wordarray[indexvar] = byte var (sign extended) - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val loadValueOnStack = when (segment[0].callLabel) { "A" -> " pha" "X" -> " txa | pha" @@ -891,9 +895,9 @@ internal val patterns = listOf( sta ${segment[3].callLabel},y ${signExtendA(segment[3].callLabel + "+1,y")} """ - }, + }) // wordarray[indexvar] = byte mem (sign extended) - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_W, 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" @@ -906,9 +910,9 @@ internal val patterns = listOf( sta ${segment[3].callLabel},y ${signExtendA(segment[3].callLabel + "+1,y")} """ - }, + }) // wordarray[index] = mem word - AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[1]) * 2 """ lda ${hexVal(segment[0])} @@ -916,9 +920,9 @@ internal val patterns = listOf( lda ${hexValPlusOne(segment[0])} sta ${segment[2].callLabel}+$index+1 """ - }, + }) // wordarray2[indexvar] = bytearay[index] (sign extended) - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_W, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[0]) val loadIndex2Y = when (segment[3].callLabel) { "A" -> " asl a | tay" @@ -933,9 +937,9 @@ internal val patterns = listOf( lda ${segment[1].callLabel}+$index+1 sta ${segment[4].callLabel}+1,y """ - }, + }) // uwordarray[mem (u)byte] = mem word - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> """ @@ -947,10 +951,10 @@ internal val patterns = listOf( lda ${hexValPlusOne(segment[0])} sta ${segment[2].callLabel}+1,y """ - }, + }) // uwordarray[index mem] = ubytevar - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> when (segment[0].callLabel) { @@ -998,9 +1002,9 @@ internal val patterns = listOf( sta ${segment[3].callLabel}+1,y """ } - }, + }) // uwordarray[index mem] = ubyte mem - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> """ @@ -1012,9 +1016,9 @@ internal val patterns = listOf( lda #0 sta ${segment[3].callLabel}+1,y """ - }, + }) // uwordarray[index] = mem ubyte - AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[2]) * 2 """ lda ${hexVal(segment[0])} @@ -1022,19 +1026,19 @@ internal val patterns = listOf( lda #0 sta ${segment[3].callLabel}+${index + 1} """ - }, + }) // uwordarray[index] = (u)wordvar - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[1]) * 2 " lda ${segment[0].callLabel} | sta ${segment[2].callLabel}+$index | lda ${segment[0].callLabel}+1 | sta ${segment[2].callLabel}+${index + 1}" - }, + }) // uwordarray[index] = address-of var - AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[1]) * 2 " lda #<${segment[0].callLabel} | ldy #>${segment[0].callLabel} | sta ${segment[2].callLabel}+$index | sty ${segment[2].callLabel}+${index + 1}" - }, + }) // uwordarray[index] = mem uword - AsmPattern(listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[1]) * 2 """ lda ${hexVal(segment[0])} @@ -1042,9 +1046,9 @@ internal val patterns = listOf( sta ${segment[2].callLabel}+$index sty ${segment[2].callLabel}+${index + 1} """ - }, + }) // uwordarray2[index2] = ubytearray1[index1] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index1 = intVal(segment[0]) val index2 = segment[3].arg!!.integerValue() * 2 """ @@ -1053,9 +1057,9 @@ internal val patterns = listOf( lda #0 sta ${segment[4].callLabel}+${index2 + 1} """ - }, + }) // uwordarray2[index2] = (u)wordarray1[index1] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index1 = intVal(segment[0]) val index2 = intVal(segment[2]) * 2 """ @@ -1064,9 +1068,9 @@ internal val patterns = listOf( sta ${segment[3].callLabel}+$index2 sta ${segment[3].callLabel}+${index2 + 1} """ - }, + }) // uwordarray[indexvar] = (u)word value - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val value = hexVal(segment[0]) val loadIndexY = when (segment[1].callLabel) { "A" -> " asl a | tay" @@ -1075,9 +1079,9 @@ internal val patterns = listOf( 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.CAST_UB_TO_UW, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val loadValueOnStack = when (segment[0].callLabel) { "A" -> " pha" "X" -> " txa | pha" @@ -1091,9 +1095,9 @@ internal val patterns = listOf( 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 -> +patterns.add(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" @@ -1101,9 +1105,9 @@ internal val patterns = listOf( 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] = address-of var - AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, 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" @@ -1111,9 +1115,9 @@ internal val patterns = listOf( else -> " lda ${segment[1].callLabel} | asl a | tay" } " $loadIndexY | lda #<${segment[0].callLabel} | sta ${segment[2].callLabel},y | lda #>${segment[0].callLabel} | sta ${segment[2].callLabel}+1,y" - }, + }) // uwordarray[indexvar] = mem ubyte - AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_UW, 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" @@ -1121,9 +1125,9 @@ internal val patterns = listOf( else -> " lda ${segment[2].callLabel} | asl a | tay" } " $loadIndexY | lda ${hexVal(segment[0])} | sta ${segment[3].callLabel},y | lda #0 | sta ${segment[3].callLabel}+1,y" - }, + }) // uwordarray[indexvar] = mem (u)word - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val loadIndexY = when (segment[1].callLabel) { @@ -1133,9 +1137,9 @@ internal val patterns = listOf( else -> " lda ${segment[1].callLabel} | asl a | tay" } " $loadIndexY | lda ${hexVal(segment[0])} | sta ${segment[2].callLabel},y | lda ${hexValPlusOne(segment[0])} | sta ${segment[2].callLabel}+1,y" - }, + }) // uwordarray2[indexvar] = ubytearay[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[0]) val loadIndex2Y = when (segment[3].callLabel) { "A" -> " asl a | tay" @@ -1144,9 +1148,9 @@ internal val patterns = listOf( 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 -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index = intVal(segment[0]) * 2 val loadIndex2Y = when (segment[2].callLabel) { "A" -> " asl a | tay" @@ -1155,9 +1159,9 @@ internal val patterns = listOf( 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( +patterns.add(AsmPattern( listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_MEM_B, Opcode.WRITE_INDEXED_VAR_WORD), listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_UW, Opcode.PUSH_MEM_UB, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val index1 = intVal(segment[0]) @@ -1170,9 +1174,9 @@ internal val patterns = listOf( lda #0 sta ${segment[4].callLabel}+1,y """ - }, + }) // uwordarray2[index mem] = uwordarray1[index1] - AsmPattern( +patterns.add(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 = intVal(segment[0]) @@ -1185,12 +1189,12 @@ internal val patterns = listOf( lda ${segment[1].callLabel}+${index1 + 1} sta ${segment[3].callLabel}+1,y """ - }, + }) // ----------- assignment to FLOAT VARIABLE ---------------- // floatvar = ubytevar - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> val loadByteA = when (segment[0].callLabel) { "A" -> "" "X" -> "txa" @@ -1204,9 +1208,9 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.ub2float """ - }, + }) // floatvar = uwordvar - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> """ lda ${segment[0].callLabel} sta ${C64Zeropage.SCRATCH_W1} @@ -1216,9 +1220,9 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.uw2float """ - }, + }) // floatvar = bytevar - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> val loadByteA = when (segment[0].callLabel) { "A" -> "" "X" -> "txa" @@ -1232,9 +1236,9 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.b2float """ - }, + }) // floatvar = wordvar - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> """ lda ${segment[0].callLabel} sta ${C64Zeropage.SCRATCH_W1} @@ -1244,9 +1248,9 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.w2float """ - }, + }) // floatvar = float value - AsmPattern(listOf(Opcode.PUSH_FLOAT, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_FLOAT, Opcode.POP_VAR_FLOAT)) { segment -> val floatConst = getFloatConst(segment[0].arg!!) """ lda #<$floatConst @@ -1257,9 +1261,9 @@ internal val patterns = listOf( ldy #>${segment[1].callLabel} jsr c64flt.copy_float """ - }, + }) // floatvar = float var - AsmPattern(listOf(Opcode.PUSH_VAR_FLOAT, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_FLOAT, Opcode.POP_VAR_FLOAT)) { segment -> """ lda #<${segment[0].callLabel} ldy #>${segment[0].callLabel} @@ -1269,9 +1273,9 @@ internal val patterns = listOf( ldy #>${segment[1].callLabel} jsr c64flt.copy_float """ - }, + }) // floatvar = mem float - AsmPattern(listOf(Opcode.PUSH_MEM_FLOAT, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_FLOAT, Opcode.POP_VAR_FLOAT)) { segment -> """ lda #<${hexVal(segment[0])} ldy #>${hexVal(segment[0])} @@ -1281,9 +1285,9 @@ internal val patterns = listOf( ldy #>${segment[1].callLabel} jsr c64flt.copy_float """ - }, + }) // floatvar = mem byte - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> """ lda ${hexVal(segment[0])} sta ${C64Zeropage.SCRATCH_B1} @@ -1291,9 +1295,9 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.b2float """ - }, + }) // floatvar = mem ubyte - AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> """ lda ${hexVal(segment[0])} sta ${C64Zeropage.SCRATCH_B1} @@ -1301,9 +1305,9 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.ub2float """ - }, + }) // floatvar = mem word - AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.CAST_W_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.CAST_W_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> """ lda ${hexVal(segment[0])} sta ${C64Zeropage.SCRATCH_W1} @@ -1313,9 +1317,9 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.w2float """ - }, + }) // floatvar = mem uword - AsmPattern(listOf(Opcode.PUSH_MEM_UW, Opcode.CAST_UW_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UW, Opcode.CAST_UW_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> """ lda ${hexVal(segment[0])} sta ${C64Zeropage.SCRATCH_W1} @@ -1325,10 +1329,10 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.uw2float """ - }, + }) // floatvar = bytearray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> val index = intVal(segment[0]) """ lda ${segment[1].callLabel}+$index @@ -1337,9 +1341,9 @@ internal val patterns = listOf( ldy #>${segment[3].callLabel} jsr c64flt.b2float """ - }, + }) // floatvar = ubytearray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> val index = intVal(segment[0]) """ lda ${segment[1].callLabel}+$index @@ -1348,9 +1352,9 @@ internal val patterns = listOf( ldy #>${segment[3].callLabel} jsr c64flt.ub2float """ - }, + }) // floatvar = wordarray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.CAST_W_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.CAST_W_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> val index = intVal(segment[0]) * 2 """ lda ${segment[1].callLabel}+$index @@ -1361,9 +1365,9 @@ internal val patterns = listOf( ldy #>${segment[3].callLabel} jsr c64flt.w2float """ - }, + }) // floatvar = uwordarray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.CAST_UW_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.CAST_UW_TO_F, Opcode.POP_VAR_FLOAT)) { segment -> val index = intVal(segment[0]) * 2 """ lda ${segment[1].callLabel}+$index @@ -1374,9 +1378,9 @@ internal val patterns = listOf( ldy #>${segment[3].callLabel} jsr c64flt.uw2float """ - }, + }) // floatvar = floatarray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_FLOAT, Opcode.POP_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_FLOAT, Opcode.POP_VAR_FLOAT)) { segment -> val index = intVal(segment[0]) * MachineDefinition.Mflpt5.MemorySize """ lda #<${segment[1].callLabel}+$index @@ -1387,10 +1391,10 @@ internal val patterns = listOf( ldy #>${segment[2].callLabel} jsr c64flt.copy_float """ - }, + }) // memfloat = float value - AsmPattern(listOf(Opcode.PUSH_FLOAT, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_FLOAT, Opcode.POP_MEM_FLOAT)) { segment -> val floatConst = getFloatConst(segment[0].arg!!) """ lda #<$floatConst @@ -1401,9 +1405,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[1])} jsr c64flt.copy_float """ - }, + }) // memfloat = float var - AsmPattern(listOf(Opcode.PUSH_VAR_FLOAT, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_FLOAT, Opcode.POP_MEM_FLOAT)) { segment -> """ lda #<${segment[0].callLabel} ldy #>${segment[0].callLabel} @@ -1413,9 +1417,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[1])} jsr c64flt.copy_float """ - }, + }) // memfloat = ubytevar - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_UB_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> val loadByteA = when (segment[0].callLabel) { "A" -> "" "X" -> "txa" @@ -1429,9 +1433,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.ub2float """ - }, + }) // memfloat = uwordvar - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> """ lda ${segment[0].callLabel} sta ${C64Zeropage.SCRATCH_W1} @@ -1441,9 +1445,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.uw2float """ - }, + }) // memfloat = bytevar - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CAST_B_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> val loadByteA = when (segment[0].callLabel) { "A" -> "" "X" -> "txa" @@ -1457,9 +1461,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.b2float """ - }, + }) // memfloat = wordvar - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> """ lda ${segment[0].callLabel} sta ${C64Zeropage.SCRATCH_W1} @@ -1469,9 +1473,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.w2float """ - }, + }) // memfloat = mem byte - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.CAST_B_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> """ lda ${hexVal(segment[0])} sta ${C64Zeropage.SCRATCH_B1} @@ -1479,9 +1483,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.b2float """ - }, + }) // memfloat = mem ubyte - AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UB, Opcode.CAST_UB_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> """ lda ${hexVal(segment[0])} sta ${C64Zeropage.SCRATCH_B1} @@ -1489,9 +1493,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.ub2float """ - }, + }) // memfloat = mem word - AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.CAST_W_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.CAST_W_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> """ lda ${hexVal(segment[0])} sta ${C64Zeropage.SCRATCH_W1} @@ -1501,9 +1505,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.w2float """ - }, + }) // memfloat = mem uword - AsmPattern(listOf(Opcode.PUSH_MEM_UW, Opcode.CAST_UW_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_UW, Opcode.CAST_UW_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> """ lda ${hexVal(segment[0])} sta ${C64Zeropage.SCRATCH_W1} @@ -1513,9 +1517,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.uw2float """ - }, + }) // memfloat = mem float - AsmPattern(listOf(Opcode.PUSH_MEM_FLOAT, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_FLOAT, Opcode.POP_MEM_FLOAT)) { segment -> """ lda #<${hexVal(segment[0])} ldy #>${hexVal(segment[0])} @@ -1525,9 +1529,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[1])} jsr c64flt.copy_float """ - }, + }) // memfloat = bytearray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_B_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> val index = intVal(segment[0]) """ lda ${segment[1].callLabel}+$index @@ -1536,9 +1540,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[3])} jsr c64flt.b2float """ - }, + }) // memfloat = ubytearray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.CAST_UB_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> val index = intVal(segment[0]) """ lda ${segment[1].callLabel}+$index @@ -1547,9 +1551,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[3])} jsr c64flt.ub2float """ - }, + }) // memfloat = wordarray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.CAST_W_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.CAST_W_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> val index = intVal(segment[0]) * 2 """ lda ${segment[1].callLabel}+$index @@ -1560,9 +1564,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[3])} jsr c64flt.w2float """ - }, + }) // memfloat = uwordarray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.CAST_UW_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.CAST_UW_TO_F, Opcode.POP_MEM_FLOAT)) { segment -> val index = intVal(segment[0]) * 2 """ lda ${segment[1].callLabel}+$index @@ -1573,9 +1577,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[3])} jsr c64flt.uw2float """ - }, + }) // memfloat = floatarray[index] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_FLOAT, Opcode.POP_MEM_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_FLOAT, Opcode.POP_MEM_FLOAT)) { segment -> val index = intVal(segment[0]) * MachineDefinition.Mflpt5.MemorySize """ lda #<${segment[1].callLabel}+$index @@ -1586,9 +1590,9 @@ internal val patterns = listOf( ldy #>${hexVal(segment[2])} jsr c64flt.copy_float """ - }, + }) // floatarray[idxbyte] = float - AsmPattern(listOf(Opcode.PUSH_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment -> val floatConst = getFloatConst(segment[0].arg!!) val index = intVal(segment[1]) * MachineDefinition.Mflpt5.MemorySize """ @@ -1600,9 +1604,9 @@ internal val patterns = listOf( ldy #>(${segment[2].callLabel}+$index) jsr c64flt.copy_float """ - }, + }) // floatarray[idxbyte] = floatvar - AsmPattern(listOf(Opcode.PUSH_VAR_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment -> val index = intVal(segment[1]) * MachineDefinition.Mflpt5.MemorySize """ lda #<${segment[0].callLabel} @@ -1613,9 +1617,9 @@ internal val patterns = listOf( ldy #>(${segment[2].callLabel}+$index) jsr c64flt.copy_float """ - }, + }) // floatarray[idxbyte] = memfloat - AsmPattern(listOf(Opcode.PUSH_MEM_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment -> val index = intVal(segment[1]) * MachineDefinition.Mflpt5.MemorySize """ lda #<${hexVal(segment[0])} @@ -1626,9 +1630,9 @@ internal val patterns = listOf( ldy #>(${segment[2].callLabel}+$index) jsr c64flt.copy_float """ - }, + }) // floatarray[idx2] = floatarray[idx1] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_FLOAT, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_FLOAT)) { segment -> val index1 = intVal(segment[0]) * MachineDefinition.Mflpt5.MemorySize val index2 = intVal(segment[2]) * MachineDefinition.Mflpt5.MemorySize """ @@ -1640,101 +1644,101 @@ internal val patterns = listOf( ldy #>(${segment[3].callLabel}+$index2) jsr c64flt.copy_float """ - }, + }) // ---------- some special operations ------------------ // var word = AX register pair - AsmPattern(listOf(Opcode.PUSH_REGAX_WORD, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_REGAX_WORD, Opcode.POP_VAR_WORD)) { segment -> """ sta ${segment[1].callLabel} stx ${segment[1].callLabel}+1 """ - }, + }) // var word = AY register pair - AsmPattern(listOf(Opcode.PUSH_REGAY_WORD, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_REGAY_WORD, Opcode.POP_VAR_WORD)) { segment -> """ sta ${segment[1].callLabel} sty ${segment[1].callLabel}+1 """ - }, + }) // var word = XY register pair - AsmPattern(listOf(Opcode.PUSH_REGXY_WORD, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_REGXY_WORD, Opcode.POP_VAR_WORD)) { segment -> """ stx ${segment[1].callLabel} sty ${segment[1].callLabel}+1 """ - }, + }) // mem word = AX register pair - AsmPattern(listOf(Opcode.PUSH_REGAX_WORD, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_REGAX_WORD, Opcode.POP_MEM_WORD)) { segment -> """ sta ${hexVal(segment[1])} stx ${hexValPlusOne(segment[1])} """ - }, + }) // mem word = AY register pair - AsmPattern(listOf(Opcode.PUSH_REGAY_WORD, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_REGAY_WORD, Opcode.POP_MEM_WORD)) { segment -> """ sta ${hexVal(segment[1])} sty ${hexValPlusOne(segment[1])} """ - }, + }) // mem word = XY register pair - AsmPattern(listOf(Opcode.PUSH_REGXY_WORD, Opcode.POP_MEM_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_REGXY_WORD, Opcode.POP_MEM_WORD)) { segment -> """ stx ${hexVal(segment[1])} sty ${hexValPlusOne(segment[1])} """ - }, + }) // AX register pair = word value - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_REGAX_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_REGAX_WORD)) { segment -> val value = hexVal(segment[0]) " lda #<$value | ldx #>$value" - }, + }) // AY register pair = word value - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_REGAY_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_REGAY_WORD)) { segment -> val value = hexVal(segment[0]) " lda #<$value | ldy #>$value" - }, + }) // XY register pair = word value - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_REGXY_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.POP_REGXY_WORD)) { segment -> val value = hexVal(segment[0]) " ldx #<$value | ldy #>$value" - }, + }) // AX register pair = word var - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_REGAX_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_REGAX_WORD)) { segment -> " lda ${segment[0].callLabel} | ldx ${segment[0].callLabel}+1" - }, + }) // AY register pair = word var - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_REGAY_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_REGAY_WORD)) { segment -> " lda ${segment[0].callLabel} | ldy ${segment[0].callLabel}+1" - }, + }) // XY register pair = word var - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_REGXY_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.POP_REGXY_WORD)) { segment -> " ldx ${segment[0].callLabel} | ldy ${segment[0].callLabel}+1" - }, + }) // AX register pair = mem word - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_UW, Opcode.POP_REGAX_WORD), listOf(Opcode.PUSH_MEM_W, Opcode.POP_REGAX_WORD)) { segment -> " lda ${hexVal(segment[0])} | ldx ${hexValPlusOne(segment[0])}" - }, + }) // AY register pair = mem word - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_UW, Opcode.POP_REGAY_WORD), listOf(Opcode.PUSH_MEM_W, Opcode.POP_REGAY_WORD)) { segment -> " lda ${hexVal(segment[0])} | ldy ${hexValPlusOne(segment[0])}" - }, + }) // XY register pair = mem word - AsmPattern( +patterns.add(AsmPattern( listOf(Opcode.PUSH_MEM_UW, Opcode.POP_REGXY_WORD), listOf(Opcode.PUSH_MEM_W, Opcode.POP_REGXY_WORD)) { segment -> " ldx ${hexVal(segment[0])} | ldy ${hexValPlusOne(segment[0])}" - }, + }) // byte var = wordvar as (u)byte - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_UB, Opcode.POP_VAR_BYTE), +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_UB, Opcode.POP_VAR_BYTE), listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_B, Opcode.POP_VAR_BYTE)) { segment -> when (segment[2].callLabel) { "A" -> " lda ${segment[0].callLabel}" @@ -1742,9 +1746,9 @@ internal val patterns = listOf( "Y" -> " ldy ${segment[0].callLabel}" else -> " lda ${segment[0].callLabel} | sta ${segment[2].callLabel}" } - }, + }) // byte var = uwordvar as (u)byte - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_UB, Opcode.POP_VAR_BYTE), +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_UB, Opcode.POP_VAR_BYTE), listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_B, Opcode.POP_VAR_BYTE)) { segment -> when (segment[2].callLabel) { "A" -> " lda ${segment[0].callLabel}" @@ -1752,72 +1756,72 @@ internal val patterns = listOf( "Y" -> " ldy ${segment[0].callLabel}" else -> " lda ${segment[0].callLabel} | sta ${segment[2].callLabel}" } - }, + }) // byte var = msb(word var) - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.MSB, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.MSB, Opcode.POP_VAR_BYTE)) { segment -> when (segment[2].callLabel) { "A" -> " lda ${segment[0].callLabel}+1" "X" -> " ldx ${segment[0].callLabel}+1" "Y" -> " ldy ${segment[0].callLabel}+1" else -> " lda ${segment[0].callLabel}+1 | sta ${segment[2].callLabel}" } - }, + }) // push word var as (u)byte - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_UB), +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_UB), listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_W_TO_B)) { segment -> " lda ${segment[0].callLabel} | sta $ESTACK_LO_HEX,x | dex " - }, + }) // push uword var as (u)byte - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_UB), +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_UB), listOf(Opcode.PUSH_VAR_WORD, Opcode.CAST_UW_TO_B)) { segment -> " lda ${segment[0].callLabel} | sta $ESTACK_LO_HEX,x | dex " - }, + }) // push msb(word var) - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.MSB)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.MSB)) { segment -> " lda ${segment[0].callLabel}+1 | sta $ESTACK_LO_HEX,x | dex " - }, + }) // set a register pair to a certain memory address (of a variable) - AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_REGAX_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_REGAX_WORD)) { segment -> " lda #<${segment[0].callLabel} | ldx #>${segment[0].callLabel} " - }, - AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_REGAY_WORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_REGAY_WORD)) { segment -> " lda #<${segment[0].callLabel} | ldy #>${segment[0].callLabel} " - }, - AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_REGXY_WORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_ADDR_HEAPVAR, Opcode.POP_REGXY_WORD)) { segment -> " ldx #<${segment[0].callLabel} | ldy #>${segment[0].callLabel} " - }, + }) // push memory byte | bytevalue - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_BYTE, Opcode.BITOR_BYTE), +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_BYTE, Opcode.BITOR_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.PUSH_BYTE, Opcode.BITOR_BYTE)) { segment -> " lda ${hexVal(segment[0])} | ora #${hexVal(segment[1])} | sta $ESTACK_LO_HEX,x | dex " - }, + }) // push memory byte & bytevalue - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_BYTE, Opcode.BITAND_BYTE), +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_BYTE, Opcode.BITAND_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.PUSH_BYTE, Opcode.BITAND_BYTE)) { segment -> " lda ${hexVal(segment[0])} | and #${hexVal(segment[1])} | sta $ESTACK_LO_HEX,x | dex " - }, + }) // push memory byte ^ bytevalue - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_BYTE, Opcode.BITXOR_BYTE), +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_BYTE, Opcode.BITXOR_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.PUSH_BYTE, Opcode.BITXOR_BYTE)) { segment -> " lda ${hexVal(segment[0])} | eor #${hexVal(segment[1])} | sta $ESTACK_LO_HEX,x | dex " - }, + }) // push var byte | bytevalue - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.BITOR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.BITOR_BYTE)) { segment -> " lda ${segment[0].callLabel} | ora #${hexVal(segment[1])} | sta $ESTACK_LO_HEX,x | dex " - }, + }) // push var byte & bytevalue - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.BITAND_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.BITAND_BYTE)) { segment -> " lda ${segment[0].callLabel} | and #${hexVal(segment[1])} | sta $ESTACK_LO_HEX,x | dex " - }, + }) // push var byte ^ bytevalue - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.BITXOR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.BITXOR_BYTE)) { segment -> " lda ${segment[0].callLabel} | eor #${hexVal(segment[1])} | sta $ESTACK_LO_HEX,x | dex " - }, + }) // push memory word | wordvalue - AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_WORD, Opcode.BITOR_WORD), +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_WORD, Opcode.BITOR_WORD), listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_WORD, Opcode.BITOR_WORD)) { segment -> """ lda ${hexVal(segment[0])} @@ -1828,9 +1832,9 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, + }) // push memory word & wordvalue - AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_WORD, Opcode.BITAND_WORD), +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_WORD, Opcode.BITAND_WORD), listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_WORD, Opcode.BITAND_WORD)) { segment -> """ lda ${hexVal(segment[0])} @@ -1841,9 +1845,9 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, + }) // push memory word ^ wordvalue - AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_WORD, Opcode.BITXOR_WORD), +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_WORD, Opcode.BITXOR_WORD), listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_WORD, Opcode.BITXOR_WORD)) { segment -> """ lda ${hexVal(segment[0])} @@ -1854,9 +1858,9 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, + }) // push var word | wordvalue - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_WORD, Opcode.BITOR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_WORD, Opcode.BITOR_WORD)) { segment -> """ lda ${segment[0].callLabel} ora #<${hexVal(segment[1])} @@ -1866,9 +1870,9 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, + }) // push var word & wordvalue - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_WORD, Opcode.BITAND_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_WORD, Opcode.BITAND_WORD)) { segment -> """ lda ${segment[0].callLabel} and #<${hexVal(segment[1])} @@ -1878,9 +1882,9 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, + }) // push var word ^ wordvalue - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_WORD, Opcode.BITXOR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_WORD, Opcode.BITXOR_WORD)) { segment -> """ lda ${segment[0].callLabel} eor #<${hexVal(segment[1])} @@ -1890,33 +1894,33 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, + }) // push var byte & var byte - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.BITAND_BYTE, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.BITAND_BYTE, Opcode.POP_VAR_BYTE)) { segment -> """ lda ${segment[0].callLabel} and ${segment[1].callLabel} sta ${segment[3].callLabel} """ - }, + }) // push var byte | var byte - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.BITOR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.BITOR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> """ lda ${segment[0].callLabel} ora ${segment[1].callLabel} sta ${segment[3].callLabel} """ - }, + }) // push var byte ^ var byte - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.BITXOR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.BITXOR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> """ lda ${segment[0].callLabel} eor ${segment[1].callLabel} sta ${segment[3].callLabel} """ - }, + }) // push var word & var word - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_WORD, Opcode.BITAND_WORD, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_WORD, Opcode.BITAND_WORD, Opcode.POP_VAR_WORD)) { segment -> """ lda ${segment[0].callLabel} and ${segment[1].callLabel} @@ -1925,9 +1929,9 @@ internal val patterns = listOf( and ${segment[1].callLabel}+1 sta ${segment[3].callLabel}+1 """ - }, + }) // push var word | var word - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_WORD, Opcode.BITOR_WORD, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_WORD, Opcode.BITOR_WORD, Opcode.POP_VAR_WORD)) { segment -> """ lda ${segment[0].callLabel} ora ${segment[1].callLabel} @@ -1936,9 +1940,9 @@ internal val patterns = listOf( ora ${segment[1].callLabel}+1 sta ${segment[3].callLabel}+1 """ - }, + }) // push var word ^ var word - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_WORD, Opcode.BITXOR_WORD, Opcode.POP_VAR_WORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_WORD, Opcode.BITXOR_WORD, Opcode.POP_VAR_WORD)) { segment -> """ lda ${segment[0].callLabel} eor ${segment[1].callLabel} @@ -1947,10 +1951,10 @@ internal val patterns = listOf( eor ${segment[1].callLabel}+1 sta ${segment[3].callLabel}+1 """ - }, + }) // bytearray[consti3] = bytearray[consti1] ^ bytearray[consti2] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.BITXOR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val i1 = segment[5].arg!!.integerValue() val i2 = segment[0].arg!!.integerValue() @@ -1960,9 +1964,9 @@ internal val patterns = listOf( eor ${segment[3].callLabel}+$i3 sta ${segment[6].callLabel}+$i1 """ - }, + }) // warray[consti3] = warray[consti1] ^ warray[consti2] - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.BITXOR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val i1 = segment[5].arg!!.integerValue() * 2 val i2 = segment[0].arg!!.integerValue() * 2 @@ -1975,9 +1979,9 @@ internal val patterns = listOf( eor ${segment[3].callLabel}+${i3 + 1} sta ${segment[6].callLabel}+${i1 + 1} """ - }, + }) - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD)) { segment -> """ lda ${segment[0].callLabel} sta $ESTACK_LO_HEX,x @@ -1985,8 +1989,8 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD)) { segment -> """ lda #${hexVal(segment[0])} sta $ESTACK_LO_HEX,x @@ -1994,8 +1998,8 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.MKWORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.MKWORD)) { segment -> """ lda ${segment[0].callLabel} sta $ESTACK_LO_HEX,x @@ -2003,73 +2007,73 @@ internal val patterns = listOf( sta $ESTACK_HI_HEX,x dex """ - }, - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD, Opcode.POP_VAR_WORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD, Opcode.POP_VAR_WORD)) { segment -> """ lda ${segment[0].callLabel} sta ${segment[3].callLabel} lda ${segment[1].callLabel} sta ${segment[3].callLabel}+1 """ - }, - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.MKWORD, Opcode.POP_VAR_WORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.MKWORD, Opcode.POP_VAR_WORD)) { segment -> """ lda ${segment[0].callLabel} sta ${segment[3].callLabel} lda #${hexVal(segment[1])} sta ${segment[3].callLabel}+1 """ - }, - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD, Opcode.POP_VAR_WORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD, Opcode.POP_VAR_WORD)) { segment -> """ lda #${hexVal(segment[0])} sta ${segment[3].callLabel} lda ${segment[1].callLabel} sta ${segment[3].callLabel}+1 """ - }, - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD, Opcode.CAST_UW_TO_W, Opcode.POP_VAR_WORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.MKWORD, Opcode.CAST_UW_TO_W, Opcode.POP_VAR_WORD)) { segment -> """ lda ${segment[0].callLabel} sta ${segment[4].callLabel} lda ${segment[1].callLabel} sta ${segment[4].callLabel}+1 """ - }, + }) // more efficient versions of x+1 and x-1 to avoid pushing the 1 on the stack - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.ADD_B), listOf(Opcode.PUSH_BYTE, Opcode.ADD_UB)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.ADD_B), listOf(Opcode.PUSH_BYTE, Opcode.ADD_UB)) { segment -> val amount = segment[0].arg!!.integerValue() if (amount in 1..2) { " inc $ESTACK_LO_PLUS1_HEX,x | ".repeat(amount) } else null - }, - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.ADD_UW), listOf(Opcode.PUSH_WORD, Opcode.ADD_W)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.ADD_UW), listOf(Opcode.PUSH_WORD, Opcode.ADD_W)) { segment -> val amount = segment[0].arg!!.integerValue() if (amount in 1..2) { " inc $ESTACK_LO_PLUS1_HEX,x | bne + | inc $ESTACK_HI_PLUS1_HEX,x |+ | ".repeat(amount) } else null - }, - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.SUB_B), listOf(Opcode.PUSH_BYTE, Opcode.SUB_UB)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.SUB_B), listOf(Opcode.PUSH_BYTE, Opcode.SUB_UB)) { segment -> val amount = segment[0].arg!!.integerValue() if (amount in 1..2) { " dec $ESTACK_LO_PLUS1_HEX,x | ".repeat(amount) } else null - }, - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.SUB_UW), listOf(Opcode.PUSH_WORD, Opcode.SUB_W)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.SUB_UW), listOf(Opcode.PUSH_WORD, Opcode.SUB_W)) { segment -> val amount = segment[0].arg!!.integerValue() if (amount in 1..2) { " lda $ESTACK_LO_PLUS1_HEX,x | bne + | dec $ESTACK_HI_PLUS1_HEX,x |+ | dec $ESTACK_LO_PLUS1_HEX,x | ".repeat(amount) } else null - }, + }) // @todo optimize 8 and 16 bit adds and subs (avoid stack use altogether on most common operations) - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_B), listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_UB)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_B), listOf(Opcode.PUSH_VAR_BYTE, Opcode.CMP_UB)) { segment -> // this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz) val cmpval = segment[1].arg!!.integerValue() when (segment[0].callLabel) { @@ -2086,8 +2090,8 @@ internal val patterns = listOf( " lda ${segment[0].callLabel} | cmp #$cmpval " } } - }, - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_W), listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_UW)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_W), listOf(Opcode.PUSH_VAR_WORD, Opcode.CMP_UW)) { segment -> // this pattern is encountered as part of the loop bound condition in for loops (var + cmp + jz/jnz) """ lda ${segment[0].callLabel} @@ -2099,9 +2103,9 @@ internal val patterns = listOf( lda #0 + """ - }, + }) - AsmPattern(listOf(Opcode.RRESTOREX, Opcode.LINE, Opcode.RSAVEX), listOf(Opcode.RRESTOREX, Opcode.RSAVEX)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.RRESTOREX, Opcode.LINE, Opcode.RSAVEX), listOf(Opcode.RRESTOREX, Opcode.RSAVEX)) { segment -> """ sta ${C64Zeropage.SCRATCH_REG} pla @@ -2109,26 +2113,26 @@ internal val patterns = listOf( pha lda ${C64Zeropage.SCRATCH_REG} """ - }, + }) // various optimizable integer multiplications - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.MUL_B), listOf(Opcode.PUSH_BYTE, Opcode.MUL_UB)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.MUL_B), listOf(Opcode.PUSH_BYTE, Opcode.MUL_UB)) { segment -> val amount = segment[0].arg!!.integerValue() val result = optimizedIntMultiplicationsOnStack(segment[1], amount) result ?: " lda #${hexVal(segment[0])} | sta $ESTACK_LO_HEX,x | dex | jsr prog8_lib.mul_byte" - }, - AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.MUL_W), listOf(Opcode.PUSH_WORD, Opcode.MUL_UW)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_WORD, Opcode.MUL_W), listOf(Opcode.PUSH_WORD, Opcode.MUL_UW)) { segment -> val amount = segment[0].arg!!.integerValue() val result = optimizedIntMultiplicationsOnStack(segment[1], amount) if (result != null) result else { val value = hexVal(segment[0]) " lda #<$value | sta $ESTACK_LO_HEX,x | lda #>$value | sta $ESTACK_HI_HEX,x | dex | jsr prog8_lib.mul_word" } - }, + }) // various variable or memory swaps - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.POP_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.POP_VAR_BYTE, Opcode.POP_VAR_BYTE)) { segment -> val var1 = segment[0].callLabel val var2 = segment[1].callLabel val var3 = segment[2].callLabel @@ -2142,8 +2146,8 @@ internal val patterns = listOf( sty $var2 """ } else null - }, - AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_WORD, Opcode.POP_VAR_WORD, Opcode.POP_VAR_WORD)) { segment -> + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_WORD, Opcode.PUSH_VAR_WORD, Opcode.POP_VAR_WORD, Opcode.POP_VAR_WORD)) { segment -> val var1 = segment[0].callLabel val var2 = segment[1].callLabel val var3 = segment[2].callLabel @@ -2162,8 +2166,8 @@ internal val patterns = listOf( sty $var2+1 """ } else null - }, - AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_MEM_B, Opcode.POP_MEM_BYTE, Opcode.POP_MEM_BYTE), + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_B, Opcode.PUSH_MEM_B, Opcode.POP_MEM_BYTE, Opcode.POP_MEM_BYTE), listOf(Opcode.PUSH_MEM_UB, Opcode.PUSH_MEM_UB, Opcode.POP_MEM_BYTE, Opcode.POP_MEM_BYTE)) { segment -> val addr1 = segment[0].arg!!.integerValue() val addr2 = segment[1].arg!!.integerValue() @@ -2178,8 +2182,8 @@ internal val patterns = listOf( sty ${addr2.toHex()} """ } else null - }, - AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_MEM_W, Opcode.POP_MEM_WORD, Opcode.POP_MEM_WORD), + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_MEM_W, Opcode.PUSH_MEM_W, Opcode.POP_MEM_WORD, Opcode.POP_MEM_WORD), listOf(Opcode.PUSH_MEM_UW, Opcode.PUSH_MEM_UW, Opcode.POP_MEM_WORD, Opcode.POP_MEM_WORD)) { segment -> val addr1 = segment[0].arg!!.integerValue() val addr2 = segment[1].arg!!.integerValue() @@ -2199,8 +2203,8 @@ internal val patterns = listOf( sty ${(addr2 + 1).toHex()} """ } else null - }, - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val i1 = segment[0].arg!!.integerValue() val i2 = segment[2].arg!!.integerValue() @@ -2219,8 +2223,8 @@ internal val patterns = listOf( sty $array2+$i2 """ } else null - }, - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_BYTE)) { segment -> val vi1 = segment[0].callLabel val vi2 = segment[2].callLabel @@ -2244,8 +2248,8 @@ internal val patterns = listOf( $storeIn2 """ } else null - }, - AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD, Opcode.PUSH_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val i1 = segment[0].arg!!.integerValue() * 2 val i2 = segment[2].arg!!.integerValue() * 2 @@ -2269,8 +2273,8 @@ internal val patterns = listOf( sty $array2+${i2 + 1} """ } else null - }, - AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_WORD, + }) +patterns.add(AsmPattern(listOf(Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.READ_INDEXED_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD, Opcode.PUSH_VAR_BYTE, Opcode.WRITE_INDEXED_VAR_WORD)) { segment -> val vi1 = segment[0].callLabel val vi2 = segment[2].callLabel @@ -2312,9 +2316,9 @@ internal val patterns = listOf( ldx ${C64Zeropage.SCRATCH_REG_X} """ } else null - }, + }) - AsmPattern(listOf(Opcode.DUP_W, Opcode.CMP_UW), +patterns.add(AsmPattern(listOf(Opcode.DUP_W, Opcode.CMP_UW), listOf(Opcode.DUP_W, Opcode.CMP_W)) { segment -> """ lda $ESTACK_HI_PLUS1_HEX,x @@ -2326,10 +2330,10 @@ internal val patterns = listOf( ; lda #0 not necessary? + """ - }, - AsmPattern(listOf(Opcode.DUP_B, Opcode.CMP_UB), + }) +patterns.add(AsmPattern(listOf(Opcode.DUP_B, Opcode.CMP_UB), listOf(Opcode.DUP_B, Opcode.CMP_B)) { segment -> """ lda $ESTACK_LO_PLUS1_HEX,x | cmp #${segment[1].arg!!.integerValue().toHex()} """ - } - -) + }) + } +}