Home > CBM > BASIC > Keywords > Pointer 180 Subpages: (divide), (equal), (less), (minus), (more), (multiply), (plus), (power), Abs, And, Append, Asc, Atn, Auto, Backup, Bank, Begin, Bend, Bload, Boot, Box, Bsave, Bump, Catalog, Char, Chr, Circle, Close, Clr, Cmd, Collect, Collision, Color, Concat, Cont, Copy, Cos, Data, Dclear, Dclose, Dec, Def, Delete, Dim, Directory, Dispose, Dload, Do, Dopen, Draw, Ds, Ds string, Dsave, Dverify, El, Else, End, Envelope, Er, Err, Exit, Exp, Fast, Fetch, Filter, Fn, For, Fre, Get, Get num, Getkey, Go, Gosub, Goto, Graphic, Gshape, Header, Help, Hex, If, Input, Input num, Instr, Int, Joy, Key, Left, Len, Let, List, Load, Locate, Log, Loop, Mid, Monitor, Movspr, New, Next, Not, Off, On, Open, Or, Paint, Peek, Pen, Pi, Play, Poke, Pos, Pot, Print, Print num, Pudef, Quit, Rclr, Rdot, Read, Record, Rem, Rename, Renumber, Restore, Resume, Return, Rgr, Right, Rlum, Rnd, Rreg, Rspcolor, Rsppos, Rsprite, Run, Rwindow, Save, Scale, Scnclr, Scratch, Sgn, Sin, Sleep, Slow, Sound, Spc, Sprcolor, Sprdef, Sprite, Sprsav, Sqr, Sshape, St, Stash, Step, Stop, Str, Swap, Sys, Tab, Tan, Tempo, Then, Ti, Ti string, To, Trap, Troff, Tron, Until, Using, Usr, Val, Verify, Vol, Wait, While, Width, Window, Xor |
| Keyword | Abbreviation | Token (hex) | Version(s) | Classification | | POINTER | PO{Shift+I} | CE 0A | 7.0 | Function |
POINTER ( variable ) | Parameters | Type | Legal Value(s) | Default Value | Note(s) | | variable | Variable Name | any legal name | | user-functions are not allowed |
| Returns | Type | Value(s) | Note(s) | | address | Unsigned Integer | 0 to 65535 | |
Finds the address in RAM where a variable is stored. The POINTER function finds the given variable in RAM and returns the address of its data. The returned address does not point to the leading bytes which name the variable (or for arrays, that give the dimensions). It useful to pass the address of a variable to an ML program so it does not need to search for it, and also your BASIC code won't need to convert the value inside the variable into high and low bytes. POINTER is also useful for loading/saving variable data to a file or REU. POINTER does not return the bank where the variable is stored. On the C128, this is always in BANK 1. On the Plus/4, it doesn't matter; there is only one bank as far as BASIC is concerned (need to verify this!). If you are religous about defining all variables before any are used, you can even assign the value of POINTER to another variable. Then you can pass that variable to your ML program or use it to load/save the data. This is dangerous with arrays because whenever you create a scalar (non-array) variable, all they arrays get moved around in memory. POINTER is less useful with strings. The address returned will point to the string descriptor. The descriptor tells the length of the string and is followed by another two bytes (also called a pointer) which tell where the actual characters of the string can be found. Also, string data gets shuffled around when BASIC performs garbage collection or the string is assigned a new value. POINTER does not work at all with user-functions (see DEF). For arrays, you must specify an element in the array. If you want to load/save an entire array, use the first ("zeroth") element. See examples. If the variable does not exist, or is a reserved variable, POINTER returns zero. If you omit variable, supply a literal value, or user-function name, then SYNTAX ERROR is generated. Examples:
CLR : A = 1 : DIM B(9,9) :REM define scalar 'A' and 10x10 array 'B'
READY.
PRINT POINTER(A)
1026
READY.
PRINT POINTER(B)
0 scalar B does not exist
READY.
PRINT POINTER(B(0,0)) : REM first element of array
1040
READY.
C = 1 : REM create new scalar 'C', this moves all arrays!
READY.
PRINT POINTER(B(0,0))
1047 it looks like C is 7 bytes in size
READY.
BANK 1: STASH 500,POINTER(B(0,0)), 0,0 : REM save array to REU address 0
READY.
C = POINTER(B(0,0)) : REM save pointer to make BSAVE easier
READY.
BSAVE "ARRAY B", B1, P(C) TO P(C+500)
SAVING 0:ARRAY B
READY.
|
© H2Obsession, 2014 |