Address of a variable: Difference between revisions
Content added Content deleted
(→{{header|Commodore BASIC}}: Add example for C64) |
|||
Line 567: | Line 567: | ||
210 PRINT "AFTER: X="XCHR$(20)",Y="Y</syntaxhighlight> |
210 PRINT "AFTER: X="XCHR$(20)",Y="Y</syntaxhighlight> |
||
{{works with|BASIC|2.0 (C-64)}} |
{{works with|BASIC|2.0 (VIC-20, C-64)}} |
||
With older machines, there's no built-in mechanism in BASIC to find a variable's address, but you can use the internal state of the BASIC interpreter to achieve similar results. |
With older machines, there's no built-in mechanism in BASIC to find a variable's address, but you can use the internal state of the BASIC interpreter to achieve similar results. Here's a VIC-20/C-64 version that works the same as the above C-128 program: |
||
⚫ | |||
Here's a C-64 version that works the same as the above C-128 program: |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
110 SYS 45195 X:POKE 249,PEEK(71):POKE250,PEEK(72) |
|||
140 : T = PEEK(PY+I) |
|||
150 : POKE PY+I,PEEK(PX+I) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
170 : T = PEEK(PY+I) |
|||
180 : POKE PY+I,PEEK(PX+I) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
It also works on the VIC-20 if you change the <tt>SYS</tt> address to 53387, and with a few other adjustments the same idea will work on other Commodore machines. |
|||
They same idea should work on other Commodore computers as well, though at least the address being <tt>PEEK</tt>ed will have to change. |
|||
{{Out}} |
{{Out}} |
||