elaborate pointervar indexing a bit more in the docs

This commit is contained in:
Irmen de Jong 2021-12-07 22:25:14 +01:00
parent dcf487bdc1
commit c812b5ee09
4 changed files with 24 additions and 1 deletions

View File

@ -294,6 +294,11 @@ This way you can set the second character on the second row from the top like th
top5screenrows[41] = '!'
**Array indexing on a pointer variable:**
An uword variable can be used in limited scenarios as a 'pointer' to a byte in memory at a specific,
dynamic, location. You can use array indexing on a pointer variable to use it as a byte array at
a dynamic location in memory: currently this is equivalent to directly referencing the bytes in
memory at the given index. See also :ref:`pointervars_programming`
Strings
^^^^^^^
@ -368,6 +373,7 @@ address you specified, and setting the varible will directly modify that memory
const byte max_age = 2000 - 1974 ; max_age will be the constant value 26
&word SCREENCOLORS = $d020 ; a 16-bit word at the addres $d020-$d021
.. _pointervars_programming:
Direct access to memory locations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -361,6 +361,8 @@ should be the *memory address* where the value is located::
&ubyte[5*40] top5screenrows = $0400 ; works for array as well
.. _pointervars:
Direct access to memory locations
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Instead of defining a memory mapped name for a specific memory location, you can also
@ -370,7 +372,7 @@ directly access the memory. Enclose a numeric expression or literal with ``@(...
@($d020) = 0 ; set the c64 screen border to black ("poke 53280,0")
@(vic+$20) = 6 ; a dynamic expression to 'calculate' the address
The array indexing notation is syntactic sugar for such a direct memory access expression::
The array indexing notation on a uword 'pointer variable' is syntactic sugar for such a direct memory access expression::
pointervar[999] = 0 ; equivalent to @(pointervar+999) = 0
@ -420,6 +422,9 @@ Syntax is familiar with brackets: ``arrayvar[x]`` ::
array[2] ; the third byte in the array (index is 0-based)
string[4] ; the fifth character (=byte) in the string
Note: you can also use array indexing on a 'pointer variable', which is basically an uword variable
containing a memory address. Currently this is equivalent to directly referencing the bytes in
memory at the given index. See :ref:`pointervars`
String
^^^^^^

View File

@ -21,6 +21,7 @@ Future
- improve testability further, add more tests
- use more of Result<> and Either<> to handle errors/ nulls better
- can we get rid of pieces of asmgen.AssignmentAsmGen by just reusing the AugmentableAssignment ? generated code should not suffer
- add a switch to not create the globals-initialization logic, but instead create a smaller program (that can only run once though)
- c64: make the graphics.BITMAP_ADDRESS configurable (VIC banking)
- optimize several inner loops in gfx2 even further?
- add modes 2 and 3 to gfx2 (lowres 4 color and 16 color)?

View File

@ -4,5 +4,16 @@
main {
sub start() {
uword array = $8000
array[0] = 10
array[1] = 20
array[2] = 30
txt.print_ub(@($8000))
txt.spc()
txt.print_ub(@($8001))
txt.spc()
txt.print_ub(@($8002))
txt.spc()
}
}