diff --git a/docs/source/programming.rst b/docs/source/programming.rst index baab45e5f..73b43045a 100644 --- a/docs/source/programming.rst +++ b/docs/source/programming.rst @@ -187,9 +187,13 @@ Values will usually be part of an expression or assignment statement:: byte counter = 42 ; variable of size 8 bits, with initial value 42 -.. todo:: - There must be a way to tell the compiler which variables you require to be in Zeropage: - ``zeropage`` modifier keyword on vardecl perhaps? +*zeropage tag:* +If you add the ``@zp`` tag to the variable declaration, the compiler will prioritize this variable +when selecting variables to put into zero page. If there are enough free locations in the zeropage, +it will then try to fill it with as much other variables as possible (before they will be put in regular memory pages). +Example:: + + byte @zp zeropageCounter = 42 Variables that represent CPU hardware registers diff --git a/docs/source/syntaxreference.rst b/docs/source/syntaxreference.rst index 8527c7d9a..d0daee3dd 100644 --- a/docs/source/syntaxreference.rst +++ b/docs/source/syntaxreference.rst @@ -213,9 +213,11 @@ Variable declarations Variables should be declared with their exact type and size so the compiler can allocate storage for them. You must give them an initial value as well. That value can be a simple literal value, -or an expression. The syntax is:: +or an expression. You can add a ``@zp`` zeropage-tag, to tell the compiler to prioritize it +when selecting variables to be put into zeropage. +The syntax is:: - [ = ] + [ @zp ] [ = ] Various examples:: @@ -228,6 +230,8 @@ Various examples:: byte[5] values = [11, 22, 33, 44, 55] byte[5] values = 255 ; initialize with five 255 bytes + word @zp zpword = 9999 ; prioritize this when selecting vars for zeropage storage + Data types @@ -510,6 +514,13 @@ And this is a loop over the values of the array ``fibonacci_numbers`` where the } +You can inline the loop variable declaration in the for statement, including optional zp-tag:: + + for ubyte @zp fastindex in 10 to 20 { + ; do something + } + + while loop ^^^^^^^^^^ diff --git a/examples/test.p8 b/examples/test.p8 index 4115d6499..23b7076f1 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -5,10 +5,15 @@ ; @todo see problem in looplabelproblem.p8 - ; @todo add docs for '@zp' tag in variable datatype declarations (including forloop loopvars) ; @todo gradle fatJar should include the antlr runtime jar sub start() { + for ubyte @zp fastindex in 10 to 20 { + c64scr.print_ub(fastindex) + c64.CHROUT('\n') + ; do something + } + } }