diff --git a/benchmark-program/Makefile b/benchmark-program/Makefile index 0699fde60..6aa339874 100644 --- a/benchmark-program/Makefile +++ b/benchmark-program/Makefile @@ -1,12 +1,10 @@ -.PHONY: all clean emu +.PHONY: clean run -all: benchmark.prg +run: + prog8c -target cx16 benchmark.p8 + x16emu -run -prg benchmark.prg -warp clean: rm -f *.prg *.PRG *.asm *.vice-* *.BIN *.PAL *.zip *.7z -emu: benchmark.prg - x16emu -run -prg $< -warp -benchmark.prg: benchmark.p8 b_3d.p8 b_adpcm.p8 b_circles.p8 b_life.p8 b_mandelbrot.p8 b_maze.p8 b_queens.p8 b_textelite.p8 - prog8c $< -target cx16 diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index 516366c63..c06385c5f 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -36,10 +36,9 @@ class AsmGen6502(val prefixSymbols: Boolean, private val lastGeneratedLabelSeque when(node) { is PtAsmSub, is PtSub -> node.name = "p8s_${node.name}" is PtBlock -> node.name = "p8b_${node.name}" - is PtLabel -> if(!node.name.startsWith(PtLabel.GeneratedLabelPrefix)) node.name = "p8l_${node.name}" + is PtLabel -> if(!node.name.startsWith(PtLabel.GeneratedLabelPrefix)) node.name = "p8l_${node.name}" // don't prefix autogenerated labels is PtConstant -> node.name = "p8c_${node.name}" is PtVariable, is PtMemMapped, is PtSubroutineParameter -> node.name = "p8v_${node.name}" - else -> node.name = "p8_${node.name}" } } diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt index daa8d164a..205975700 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmOptimizer.kt @@ -3,6 +3,7 @@ package prog8.codegen.cpu6502 import prog8.code.StConstant import prog8.code.StMemVar import prog8.code.SymbolTable +import prog8.code.ast.PtLabel import prog8.code.core.IMachineDefinition @@ -361,15 +362,16 @@ or *_afterif labels. This gets generated after certain if conditions, and only the branch instruction is needed in these cases. */ + val autoLabelPrefix = PtLabel.GeneratedLabelPrefix if(first=="beq +" && second=="lda #1" && third=="+") { - if((fourth.startsWith("beq label_") || fourth.startsWith("bne label_")) && + if((fourth.startsWith("beq $autoLabelPrefix") || fourth.startsWith("bne $autoLabelPrefix")) && (fourth.endsWith("_shortcut") || fourth.endsWith("_afterif") || fourth.endsWith("_shortcut:") || fourth.endsWith("_afterif:"))) { mods.add(Modification(lines[0].index, true, null)) mods.add(Modification(lines[1].index, true, null)) mods.add(Modification(lines[2].index, true, null)) } - else if(fourth.startsWith("label_") && (fourth.endsWith("_shortcut") || fourth.endsWith("_shortcut:"))) { - if((fifth.startsWith("beq label_") || fifth.startsWith("bne label_")) && + else if(fourth.startsWith(autoLabelPrefix) && (fourth.endsWith("_shortcut") || fourth.endsWith("_shortcut:"))) { + if((fifth.startsWith("beq $autoLabelPrefix") || fifth.startsWith("bne $autoLabelPrefix")) && (fifth.endsWith("_shortcut") || fifth.endsWith("_afterif") || fifth.endsWith("_shortcut:") || fifth.endsWith("_afterif:"))) { mods.add(Modification(lines[0].index, true, null)) mods.add(Modification(lines[1].index, true, null)) diff --git a/docs/source/comparing.rst b/docs/source/comparing.rst index adc343245..0ef027d3a 100644 --- a/docs/source/comparing.rst +++ b/docs/source/comparing.rst @@ -41,6 +41,9 @@ Data types - strings and arrays are mutable: you can change their contents, but always keep the original storage size in mind to avoid overwriting memory outside of the buffer. - maximum string length is 255 characters + a trailing 0 byte. - maximum storage size for arrays is 256 bytes (512 for split word arrays) , the maximum number of elements in the array depends on the size of a single element value. + you can use larger "arrays" via pointer indexing, see below at Pointers. One way of obtaining a piece of memory to store + such an "array" is by using ``memory()`` builtin function. + Variables --------- @@ -72,7 +75,7 @@ Pointers You have to deal with the uword manually if the object it points to is something different. - Note that there is the ``peekw`` builtin function that *does* allow you to directy obtain the *word* value at the given memory location. So if you use this, you can use uword pointers as pointers to word values without much hassle. -- "dereferencing" a uword pointer is done via array indexing (where index value can be 0-65535!) or via the memory read operator ``@(ptr)``, or ``peek/peekw(ptr)``. +- "dereferencing" a uword pointer is done via array indexing ``ptr[index]`` (where index value can be 0-65535!) or via the memory read operator ``@(ptr)``, or ``peek/peekw(ptr)``. - Pointers don't have to be a variable, you can immediately access the value of a given memory location using ``@($d020)`` for instance. Reading is done by assigning it to a variable, writing is done by just assigning the new value to it. diff --git a/docs/source/todo.rst b/docs/source/todo.rst index b23078ca8..e52c5173a 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -47,6 +47,7 @@ Future Things and Ideas IR/VM ----- +- constants are not retained in the IR file, they should. (need to be able to make asm labels from them eventually) - implement missing operators in AssignmentGen (array shifts etc) - support %align on code chunks - fix call() return value handling diff --git a/examples/test.p8 b/examples/test.p8 index 24249f7d9..8b2c77b76 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,19 +1,7 @@ -%import sprites -%import textio -%option no_sysinit -%zeropage basicsafe - -main $0810 { +main { sub start() { - ubyte sprite - - for sprite in 1 to 99 { - sys.wait(1) - sprites.init(sprite, 0, 0, sprites.SIZE_8, sprites.SIZE_8, sprites.COLORS_256, 0) - sprites.pos(sprite, 10 + sprite*10, 10+sprite*4) - } - - sprites.reset(1, 100) - + ubyte @shared v1, v2 + if v1==0 and v2 & 3 !=0 + v1++ } }