Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Silly Basic question
2007-11-08 14:07
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).
2007-11-08 14:46
Scout

Registered: Dec 2002
Posts: 1570
/me points the way to Lemon64.com ------> /dev/null
2007-11-08 15:14
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. :)
2007-11-08 16:17
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.
2007-11-08 19:56
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. :)
2007-11-08 20:22
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.
2007-11-08 20:49
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! :)
2007-11-08 20:58
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.
2007-11-08 21:38
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
2007-11-08 21:46
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?
2007-11-08 21:57
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
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
sln.pixelrat
Jazzcat/Onslaught
Murphy/Exceed
Urban Space Cowboy
Guests online: 147
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Graphicians
1 Mirage  (9.8)
2 Archmage  (9.7)
3 Pal  (9.6)
4 Carrion  (9.6)
5 Sulevi  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.053 sec.