From 0f9e167df39a2ead4d214b569b7ddeb2b458c6f5 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 25 Aug 2020 00:59:02 +0200 Subject: [PATCH] proper name --- .../compiler/target/c64/codegen/AsmGen.kt | 2 +- .../target/c64/codegen/ExpressionsAsmGen.kt | 2 +- .../codegen/assignment/AssignmentAsmGen.kt | 4 +- .../assignment/AugmentableAssignmentAsmGen.kt | 40 +++++++++---------- examples/plasma.p8 | 18 +++++++-- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt index fa90acf52..2a311fb51 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AsmGen.kt @@ -517,7 +517,7 @@ internal class AsmGen(private val program: Program, return fixNameSymbols(name) } - internal fun loadByteFromPointerIntoA2(pointervar: IdentifierReference): Pair { + internal fun loadByteFromPointerIntoA(pointervar: IdentifierReference): Pair { // returns if the pointer is already on the ZP itself or not (in which case SCRATCH_W1 is used as intermediary) val sourceName = asmIdentifierName(pointervar) val vardecl = pointervar.targetVarDecl(program.namespace)!! diff --git a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt index a01135a05..2926b627c 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/ExpressionsAsmGen.kt @@ -145,7 +145,7 @@ internal class ExpressionsAsmGen(private val program: Program, private val asmge } is IdentifierReference -> { // the identifier is a pointer variable, so read the value from the address in it - asmgen.loadByteFromPointerIntoA2(expr.addressExpression as IdentifierReference) + asmgen.loadByteFromPointerIntoA(expr.addressExpression as IdentifierReference) asmgen.out(" sta $ESTACK_LO_HEX,x | dex") } else -> { diff --git a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt index cf45d6197..ed6144919 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AssignmentAsmGen.kt @@ -802,7 +802,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen } else if (identifier != null) { when(target.kind) { TargetStorageKind.VARIABLE -> { - asmgen.loadByteFromPointerIntoA2(identifier) + asmgen.loadByteFromPointerIntoA(identifier) asmgen.out(" sta ${target.asmVarname}") } TargetStorageKind.MEMORY -> { @@ -813,7 +813,7 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen throw AssemblyError("no asm gen for assign memory byte $identifier to array ${target.asmVarname} ") } TargetStorageKind.REGISTER -> { - asmgen.loadByteFromPointerIntoA2(identifier) + asmgen.loadByteFromPointerIntoA(identifier) when(target.register!!) { RegisterOrPair.A -> {} RegisterOrPair.X -> asmgen.out(" tax") diff --git a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt index 0d5dd586c..d8d68cfc5 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt @@ -193,8 +193,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, else -> { println("warning: slow stack evaluation used (1): ${memory.addressExpression::class.simpleName} at ${memory.addressExpression.position}") // TODO optimize... asmgen.translateExpression(memory.addressExpression) + // TODO buggy?: asmgen.out(" jsr prog8_lib.read_byte_from_address_on_stack | sta ${C64Zeropage.SCRATCH_B1}") - // the original memory byte's value is now in the scratch B1 location. when { valueLv != null -> inplaceModification_byte_litval_to_variable(C64Zeropage.SCRATCH_B1.toHex(), DataType.UBYTE, operator, valueLv.toInt()) ident != null -> inplaceModification_byte_variable_to_variable(C64Zeropage.SCRATCH_B1.toHex(), DataType.UBYTE, operator, ident) @@ -368,7 +368,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, when (operator) { // note: ** (power) operator requires floats. "+" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" clc | adc $ESTACK_LO_PLUS1_HEX,x") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -376,7 +376,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "-" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" sec | sbc $ESTACK_LO_PLUS1_HEX,x") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -394,7 +394,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, "<<" -> TODO("ubyte asl") ">>" -> TODO("ubyte lsr") "&" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" and $ESTACK_LO_PLUS1_HEX,x") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -402,7 +402,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "^" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" xor $ESTACK_LO_PLUS1_HEX,x") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -410,7 +410,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "|" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" ora $ESTACK_LO_PLUS1_HEX,x") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -427,7 +427,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, when (operator) { // note: ** (power) operator requires floats. "+" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" clc | adc $otherName") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -435,7 +435,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "-" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" sec | sbc $otherName") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -453,7 +453,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, "<<" -> TODO("ubyte asl") ">>" -> TODO("ubyte lsr") "&" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" and $otherName") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -461,7 +461,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "^" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" xor $otherName") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -469,7 +469,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "|" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" ora $otherName") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -484,7 +484,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, when (operator) { // note: ** (power) operator requires floats. "+" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" clc | adc #$value") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -492,7 +492,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "-" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" sec | sbc #$value") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -516,7 +516,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, } "<<" -> { if (value > 0) { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) repeat(value) { asmgen.out(" asl a") } if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -526,7 +526,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, } ">>" -> { if (value > 0) { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) repeat(value) { asmgen.out(" lsr a") } if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -535,7 +535,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, } } "&" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" and #$value") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -543,7 +543,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "^" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" xor #$value") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -551,7 +551,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, asmgen.out(" sta (${C64Zeropage.SCRATCH_W1}),y") } "|" -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(pointervar) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar) asmgen.out(" ora #$value") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") @@ -1113,7 +1113,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, sta $addr""") } is IdentifierReference -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(mem.addressExpression as IdentifierReference) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(mem.addressExpression as IdentifierReference) asmgen.out(""" beq + lda #1 @@ -1187,7 +1187,7 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, sta $addr""") } is IdentifierReference -> { - val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA2(memory.addressExpression as IdentifierReference) + val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(memory.addressExpression as IdentifierReference) asmgen.out(" eor #255") if(ptrOnZp) asmgen.out(" sta ($sourceName),y") diff --git a/examples/plasma.p8 b/examples/plasma.p8 index 1a504fcbf..68e3b02df 100644 --- a/examples/plasma.p8 +++ b/examples/plasma.p8 @@ -71,11 +71,23 @@ main { } c2A += 2 c2B -= 3 + uword @zp scrptr = screen for y in 24 downto 0 { for x in 39 downto 0 { - @(screen) = xbuf[x] + ybuf[y] - screen++ - } + @(scrptr) = xbuf[x] + @(scrptr) += ybuf[y] + ;@(scrptr) = xbuf[x] + ybuf[y] +; %asm {{ +; ldy x +; lda xbuf,y +; ldy y +; clc +; adc ybuf,y +; ldy #0 +; sta (scrptr),y +; }} + scrptr++ + } } }