| |
johncl
Registered: Aug 2007 Posts: 37 |
Silly Basic question
Something I have always wondered about the "good" old Basic was that for a lot of data you had to use the DATA keyword and type lots of numbers, which you then DIM'ed array variables and read them into. Essentially you stored the data twice! As if Basic wasnt sucking up enough memory as it is.
Why didnt they allow a simple way of accessing the DATA blocks like a pointer?
And for my silly question, are all DATA number values stored as 16 bit values or what format does it have? Is there a cool way of e.g. begin your Basic code with DATA statements with assembly data and then sys this to start it? Or do you always have to READ the DATA values and then POKE them to a certain memory location which you can then SYS call to?
The reason I ask this is that I am just tinkering with a silly game on a good old PET 2001 that is programmed in Basic, and I see that I need a fast screen memory copy which I want to program in assembly (but as normal lines of basic since I want this to single load off tape). |
|
| |
Scout
Registered: Dec 2002 Posts: 1570 |
/me points the way to Lemon64.com ------> /dev/null |
| |
johncl
Registered: Aug 2007 Posts: 37 |
Hehe, well I guessed this might be the wrong forum. However, I did some simple tests. I entered the simple program (using VICE):
0 DATA"ABCDEF"
And checked out the memory at the start of the basic pointer ($0401 on PET and $0801 on C64) to see the format. I noticed that everything is stored as characters - numbers also. So a DATA 0,1 would be stored as DATA_OPCODE, SPACE, ZERO_CHAR, COMMA, ONE_CHAR. Very simple (and stupid) format in other words.
Well I then fired up VICE C128, entered the monitor and wrote a simple program:
.C000 CLC
.C001 INC $D020
.C004 BCC $C001
And read out the byte data which I then poked manually on the C64 on memory locations 2055-2060, and added a SYS 2055 line. The code lists fine (all bytes in this case are normal visual chars) and runs. A fun little experiment. :)
Now I just gotta make an assembly -> PRG that makes basic data statements accordingly. :) |
| |
Graham Account closed
Registered: Dec 2002 Posts: 990 |
Quote:Why didnt they allow a simple way of accessing the DATA blocks like a pointer?
Hint: 8k BASIC ROM
Btw, you instead of
10 DATA "ABCDEF"
you can also use:
10 DATA ABCDEF
and still read it as string. |
| |
johncl
Registered: Aug 2007 Posts: 37 |
Hehe yeah, I guess ROM was expensive stuff, considering that the C64 had all this nice graphics and sound stuff that had no basic support at all (a really strange decision to release it without is my opinion).
About that DATA statement, I tried without the "" around the string but if you replace the chars with assembly code they are actually tokenized as basic commands! So after you change them you get these funny basic programs with a huge DATA statement with lots of basic keywords! So the BASIC LIST is at least smart enough to treat the stuff inside "" as literal chars. :) |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
You can also embed data in REM statements, i.e REM "<data>".
Then you can random access it with PEEK() or SYS.
This requires precise knowledge of the location it appears at, but if the data is fixed early on, just put those REM statements at the beginning of your program and write down the addresses.
If you generate the lines using a program they can also be longer than the normal BASIC line length.
|
| |
johncl
Registered: Aug 2007 Posts: 37 |
Yes good tip there. REM is probably better to use since you can still use DATA statements for other stuff. And thanks for confirming what I thought about line length. From the structure it seemed that an actual line in basic could be much longer.
I did notice that my POKEd DATA line got corrupt if I went to the line and pressed enter again. Some characters are obviously not reproduceable. I wondered about this because it would be quite cool to write assembly code using the character set equivalents and then sys'ing into that DATA or REM line. :)
If I generate that REM statement at another spot in memory I could actually use the built in line relocator in basic to move it into my program. The same trick they used to e.g run C64 Basic programs on an old PET. (Simply by changing the $0401 and $0402 pointers to another place in memory where the "generated" basic is. Oh the fun! :) |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
I'd just do a placeholder space with the REM, and then poke the data in there.
You can even do this:
10 goto 30
20 "<data...>
30 <code> no REM, no trailing ".
Max line length seems to be 255 bytes between the line start addresses.
I'm not sure what happens to embedded 00 bytes though.
EDIT: 00 bytes seems to work, but editing won't work after they are present.
|
| |
enthusi
Registered: May 2004 Posts: 677 |
you still have the adresses for next basic-line IN the code then.
use :
10 ?"ai7qcnbq7xnqmol8u3x2m"
20...
sys1024
for < 1000 byte code |
| |
tlr
Registered: Sep 2003 Posts: 1790 |
Good idea! Let's improve it.
10 POKE648,192
20 ?"<code>";
30 ...
40 POKE648,4:SYS49152 Q: Are all screen codes achievable using PRINT? |
| |
Scout
Registered: Dec 2002 Posts: 1570 |
Okay, i admit...this thread is going beyond the level of lemon64.
Excusez moi!
Oh, and please continue. Me like! :D |
... 5 posts hidden. Click here to view all posts.... |
Previous - 1 | 2 - Next |