MWHEEL: Can anyone give an example on the usage of this variable? The docs don't have one.
POINTER(): The docs say, "Returns the memory address of the internal structure representing a BASIC variable." Can someone define "internal structure", or tell me where I can find info on this?
Thanks.
POINTER() and MWHEEL Questions
Re: POINTER() and MWHEEL Questions
MWHEEL contains the mouse wheel movement +127/-128 since it was last retrieved. Mouse wheel support is not available in the last release; it’s currently only in the Github master branch
Re: POINTER() and MWHEEL Questions
POINTER() returns the memory address where a BASIC variable's value is stored. The way a variable's value is stored in memory is different from what you get when you PRINT it, which is what the docs mean when it says "internal structure".
For precise information on variables, you can check C64-Wiki, which I'll summarize here:
For precise information on variables, you can check C64-Wiki, which I'll summarize here:
- All variable values are 5 bytes.
- Floating point numbers: 1 byte exponent, 4 bytes (MSB first) mantissa.
- Integers: 2 bytes (MSB first) for signed 16-bit integer, 3 zero bytes.
- Strings: 1 byte for length, 2 bytes (LSB first) pointer to characters, 2 zero bytes.
- Arrays: Structure is the same as non-array variables, except each value in the array is stored without needing the padding bytes. (For example, an array of 5 integers will consume only 10 bytes of memory.)
- If you DIM AY(5), remember to use POINTER(AY(0)) to get the starting address of the array. If you accidentally use POINTER(AY) instead, you'll get the address for a plain AY variable and not the AY array.
Re: POINTER() and MWHEEL Questions
That's because, as outlined in my previous post, the characters of the string are not stored at the address you get from POINTER(). Instead, a string variable contains one byte for the string length, and then a 16-bit pointer to another memory address which contains the actual characters within the string:
Re: POINTER() and MWHEEL Questions
Yep, you sure did. Don't know why it didn't click the first time. Thanks for breaking it down.
Couple things I noticed is that the pointer address changes depending on the length of the string, or whether you do it as a program or immediate mode. Examples:
PROGRAM IMMEDIATE A$="MORTAR" = $0825 $0805 A$="MORTAR TIME" = $082A $0805
Curious that the address doesn't change in Immediate mode.
Re: POINTER() and MWHEEL Questions
BASIC stores all of the variables in memory after the tokenized program, so for example:
And now if a new variable is added in direct mode after running this program:
(Please note, I did say all named variables have values that are 5 bytes, but that value will be preceeded by two bytes for the variable's name (two characters) and type (bit 7 from both characters), so that's why B$'s value is 7 bytes after A$'s value.)
If you clear the program, then create a new variable in direct mode:
10 A$ = "IT'S MORBIN' TIME!" 20 PRINT HEX$(POINTER(A$)) READY. RUN 0834 READY.Look what happens when a space in line 10 is removed:
10 A$= "IT'S MORBIN' TIME!" 20 PRINT HEX$(POINTER(A$)) READY. RUN 0833 READY.A$'s location moved by one byte, because we changed the size of the program by one byte.
And now if a new variable is added in direct mode after running this program:
B$ = "BAYBEEEEEE!" READY. PRINT HEX$(POINTER(B$)) 083A READY.B$ is placed in the next available space in variable memory, which is right after A$.
(Please note, I did say all named variables have values that are 5 bytes, but that value will be preceeded by two bytes for the variable's name (two characters) and type (bit 7 from both characters), so that's why B$'s value is 7 bytes after A$'s value.)
If you clear the program, then create a new variable in direct mode:
NEW READY. A$ = "THEY SEE ME MORBIN'" READY. PRINT HEX$(POINTER(A$)) 0805 READY....now you get address $0805, since now the current BASIC program is just a blank program, and A$ is a new variable created after our tokenized blank BASIC program.
Re: POINTER() and MWHEEL Questions
Gotcha. But, what if the program size doesn't change, just the string size, as noted previously?
Re: POINTER() and MWHEEL Questions
If you start with this:
10 A$ = "CHEESEBURGER"...and you later change that line to this:
10 A$ = "BACON CHEESEBURGER"...then that still counts as changing the program size, because line 10 now has six more characters in it, which means your entire program is now six bytes larger than before.
Re: POINTER() and MWHEEL Questions
Doh! It takes a bit, but I finally got it. Thanks again.