Accessing Memory#

Reading Memory locations#

In Basic, we use PEEK(addr) to read a memory location. This example read the first joystick

100 STICK = PEEK(632)
110 IF STICK = 15 THEN PRINT "centered"
120 IF STICK = 14 THEN PRINT "up"
130 IF STICK = 13 THEN PRINT "down"

In Forth, there are two words to read memory. @ (called FETCH) reads a 16bit value from a memory location and places the value on the stack. C@ (called C-FETCH) reads a 8bit value (a byte).

Both words need (=consume) the address on the stack.

@  ( addr -- 16b )
C@ ( addr --  8b )
In the Atari, Memory location 632 (STICK0/$278) is the shadow register for the first joystick port (PORTA/54016). So the above BASIC example would be in FORTH:

&632 C@
DUP 15 = IF ." centered " THEN
DUP 14 = IF ." up " THEN
    13 = IF ." down " THEN

Writing memory locations#

The counterpart to @ (FETCH) and C@ (C-FETCH) are ! (STORE) and C! (C-STORE). These words take a value and an address from the stack and store the value at the address. The Stack comments for this words are:

!   ( 16b addr -- )
C!  (  8b addr -- )

The below BASIC line changes the background color of the screen to black, writing the value 0 in memory location 709 (COLOR1):

100 POKE 709,0

In Forth, we write

0 709 C!

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-7) was last changed on 03-Feb-2023 16:21 by Carsten Strotmann  
G’day (anonymous guest) My Prefs
© 2010-2021 AtariWiki
All content in the Wiki is licensed under Creative Commons Share Alike License, unless otherwise noted.
JSPWiki v2.8.3