diff --git a/src/main/fragment/mos6502-common/_deref_pwuc1=_deref_pwuc1_plus_1.asm b/src/main/fragment/mos6502-common/_deref_pwuc1=_deref_pwuc1_plus_1.asm new file mode 100644 index 000000000..39191f06b --- /dev/null +++ b/src/main/fragment/mos6502-common/_deref_pwuc1=_deref_pwuc1_plus_1.asm @@ -0,0 +1,4 @@ +inc {c1} +bne !+ +inc {c1}+1 +!: \ No newline at end of file diff --git a/src/main/fragment/mos6502-common/vwum1=pwuz2_derefidx_vbuyy_minus_vwum3.asm b/src/main/fragment/mos6502-common/vwum1=pwuz2_derefidx_vbuyy_minus_vwum3.asm new file mode 100644 index 000000000..3d75e0276 --- /dev/null +++ b/src/main/fragment/mos6502-common/vwum1=pwuz2_derefidx_vbuyy_minus_vwum3.asm @@ -0,0 +1,8 @@ +sec +lda ({z2}),y +sbc {m3} +sta {m1} +iny +lda ({z2}),y +sbc {m3}+1 +sta {m1}+1 \ No newline at end of file diff --git a/src/main/fragment/mos6502-common/vwum1_neq__deref_pwuz2_then_la1.asm b/src/main/fragment/mos6502-common/vwum1_neq__deref_pwuz2_then_la1.asm new file mode 100644 index 000000000..49b5ef587 --- /dev/null +++ b/src/main/fragment/mos6502-common/vwum1_neq__deref_pwuz2_then_la1.asm @@ -0,0 +1,8 @@ +ldy #1 +lda {m1}+1 +cmp ({z2}),y +bne {la1} +dey +lda {m1} +cmp ({z2}),y +bne {la1} \ No newline at end of file diff --git a/src/main/fragment/mos6502-common/vwum1_neq_pwuz2__derefidx_vbuyy_then_la1.asm b/src/main/fragment/mos6502-common/vwum1_neq_pwuz2__derefidx_vbuyy_then_la1.asm new file mode 100644 index 000000000..484bf9be8 --- /dev/null +++ b/src/main/fragment/mos6502-common/vwum1_neq_pwuz2__derefidx_vbuyy_then_la1.asm @@ -0,0 +1,7 @@ +lda {m1} +cmp ({z2}),y +bne {la1} +iny +lda {m1} +cmp ({z2}),y +bne {la1} \ No newline at end of file diff --git a/src/main/fragment/mos6502-common/vwuz1=pwuz1_derefidx_vbuyy_minus_vwum2.asm b/src/main/fragment/mos6502-common/vwuz1=pwuz1_derefidx_vbuyy_minus_vwum2.asm new file mode 100644 index 000000000..562c568b6 --- /dev/null +++ b/src/main/fragment/mos6502-common/vwuz1=pwuz1_derefidx_vbuyy_minus_vwum2.asm @@ -0,0 +1,10 @@ +sec +lda ({z1}),y +sbc {m2} +pha +iny +lda ({z1}),y +sbc {m2}+1 +sta {z1}+1 +pla +sta {z1} \ No newline at end of file diff --git a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentTemplate.java b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentTemplate.java index ca54e6d10..ba01f7a99 100644 --- a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentTemplate.java +++ b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentTemplate.java @@ -8,6 +8,7 @@ import dk.camelot64.kickc.model.TargetCpu; import dk.camelot64.kickc.model.statements.StatementSource; import dk.camelot64.kickc.model.symbols.Label; import dk.camelot64.kickc.model.symbols.ProgramScope; +import dk.camelot64.kickc.model.symbols.Scope; import dk.camelot64.kickc.model.symbols.Variable; import dk.camelot64.kickc.model.types.SymbolType; import dk.camelot64.kickc.model.values.ConstantInteger; @@ -74,6 +75,34 @@ public class AsmFragmentTemplate { this.targetCpu = targetCpu; } + /** + * Create a load/store variable + * + * @param name The name + * @param type The type + * @param scope The scope + * @param memoryArea The memory area (zeropage/main memory) + * @param dataSegment The data segment (in main memory) + * @return The new PHI-master variable + */ + public static Variable createLoadStore(String name, SymbolType type, Scope scope, Variable.MemoryArea memoryArea, String dataSegment) { + return new Variable(name, Variable.Kind.LOAD_STORE, type, scope, memoryArea, dataSegment, null); + } + + /** + * Create a PHI master variable + * + * @param name The name + * @param type The type + * @param scope The scope + * @param memoryArea The memory area (zeropage/main memory) + * @param dataSegment The data segment (in main memory) + * @return The new PHI-master variable + */ + public static Variable createPhiMaster(String name, SymbolType type, Scope scope, Variable.MemoryArea memoryArea, String dataSegment) { + return new Variable(name, Variable.Kind.PHI_MASTER, type, scope, memoryArea, dataSegment, null); + } + /** * Initialize the fields that require parsing the ASM (bodyAsm, clobber, cycles). */ @@ -84,7 +113,7 @@ public class AsmFragmentTemplate { ProgramScope scope = new ProgramScope(); LinkedHashMap bindings = new LinkedHashMap<>(); { - Variable master = Variable.createPhiMaster("z", SymbolType.BYTE, scope, Variable.MemoryArea.ZEROPAGE_MEMORY, null); + Variable master = createPhiMaster("z", SymbolType.BYTE, scope, Variable.MemoryArea.ZEROPAGE_MEMORY, null); Variable v1 = Variable.createPhiVersion(master, 1); v1.setName("z1"); Variable v2 = Variable.createPhiVersion(master, 2); v2.setName("z2"); Variable v3 = Variable.createPhiVersion(master, 3); v3.setName("z3"); @@ -105,12 +134,12 @@ public class AsmFragmentTemplate { if(signature.contains("z6")) bindings.put("z6", v6); } { - Variable v1 = Variable.createLoadStore("m1", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); - Variable v2 = Variable.createLoadStore("m2", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); - Variable v3 = Variable.createLoadStore("m3", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); - Variable v4 = Variable.createLoadStore("m4", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); - Variable v5 = Variable.createLoadStore("m5", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); - Variable v6 = Variable.createLoadStore("m6", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); + Variable v1 = createLoadStore("m1", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); + Variable v2 = createLoadStore("m2", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); + Variable v3 = createLoadStore("m3", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); + Variable v4 = createLoadStore("m4", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); + Variable v5 = createLoadStore("m5", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); + Variable v6 = createLoadStore("m6", SymbolType.BYTE, scope, Variable.MemoryArea.MAIN_MEMORY, null); v1.setAllocation(new Registers.RegisterMainMem(v1.getVariableRef(), 1, null)); v2.setAllocation(new Registers.RegisterMainMem(v2.getVariableRef(), 1, null)); v3.setAllocation(new Registers.RegisterMainMem(v3.getVariableRef(), 1, null)); diff --git a/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java b/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java index 72b0cf784..c0f5f6c38 100644 --- a/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java +++ b/src/main/java/dk/camelot64/kickc/model/symbols/Variable.java @@ -140,34 +140,6 @@ public class Variable implements Symbol { return new Variable(name, Kind.INTERMEDIATE, SymbolType.VAR, scope, MemoryArea.ZEROPAGE_MEMORY, dataSegment, null); } - /** - * Create a load/store variable - * - * @param name The name - * @param type The type - * @param scope The scope - * @param memoryArea The memory area (zeropage/main memory) - * @param dataSegment The data segment (in main memory) - * @return The new PHI-master variable - */ - public static Variable createLoadStore(String name, SymbolType type, Scope scope, Variable.MemoryArea memoryArea, String dataSegment) { - return new Variable(name, Kind.LOAD_STORE, type, scope, memoryArea, dataSegment, null); - } - - /** - * Create a PHI master variable - * - * @param name The name - * @param type The type - * @param scope The scope - * @param memoryArea The memory area (zeropage/main memory) - * @param dataSegment The data segment (in main memory) - * @return The new PHI-master variable - */ - public static Variable createPhiMaster(String name, SymbolType type, Scope scope, Variable.MemoryArea memoryArea, String dataSegment) { - return new Variable(name, Kind.PHI_MASTER, type, scope, memoryArea, dataSegment, null); - } - /** * Create a version of a PHI master variable * @@ -519,10 +491,6 @@ public class Variable implements Symbol { this.memoryArea = memoryArea; } - public boolean isMemoryAreaZp() { - return MemoryArea.ZEROPAGE_MEMORY.equals(getMemoryArea()); - } - public boolean isMemoryAreaMain() { return MemoryArea.MAIN_MEMORY.equals(getMemoryArea()); }