CBM/PET BASIC

Topics related to older 6502-based hardware and systems including (but not limited to) the MOS Technology KIM-1, Synertek SYM-1, and Rockwell AIM-65.
Post Reply
Mats
Posts: 111
Joined: 24 Aug 2003

CBM/PET BASIC

Post by Mats »

A rather detailed memory map of the CBM8032/PET ROM can be found in:

http://www.zimmers.net/anonftp/pub/cbm/ ... t/d/petdis

But what about RAM usage? RAM for BASIC use starts at $0400. Is there somewhere a good/detailed description of how BASIC uses RAM and especially where in RAM the different pointers to "START/END of code" and "START/END of variables" are situated.

I have developped a utility to move data back and forward between a PC and an 8032 using the User Port (Between PET ram and a PC ASCII-HEX file on harddisk) and I would like to use this interface to store BASIC programs on the PC harddisk. I.e. to do what the PET system does when the "load" and "save" commands for casset tape storage are typed! A rather tricky "hacking" deep into the CBM software!
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

The zero-page pointer TXTTAB points to the start of the token area. For the Commodore 64, this is $0801, for example. BASIC 2.0 seems to put TXTTAB at location $002B.

Start of BASIC variables is pointed to by the VARTAB ($002D) pointer.

Start of Arrays is pointed to by the ARYTAB ($002F) pointer.

The END of arrays is pointed to by the STREND ($0031) pointer. Judging by the pointer's name, it also looks like the START of string space as well.

FRETOP is the last pointer at $0033, which is the end of the string space.

MEMSIZ ($0037) is the largest address usable by BASIC. In the case of the Commodore 64, this value is $A000.

Although these are for BASIC 2.0 on the Commodore 64, I doubt that their locations would change that much. If they do change, I'm sure they'll be kept adjacent, so some peeking around with a debugger ought to show patterns that suggest the proper base address for this "structure" of pointers.

Hope this helps.

SOURCE: http://www.ludd.luth.se/~watchman/fairl ... -memo.html
fachat
Posts: 1123
Joined: 05 Jul 2005
Location: near Heidelberg, Germany
Contact:

Post by fachat »

On the ROMs page of my petindex site (http://www.6502.org/users/andre/petindex/roms.html) you find links to the disassemblies of the PET ROMs as well as a memory map for the BASIC4.

The BASIC stores the text and variables in separate sections. First is the basic text, then come the basic variables as an array, then the basic arrays.
The strings on the other hand are stored from the end of the available memory down. When the string area reaches the array area a string garbage collection is done.

Code: Select all

 TXTTAB	0028-0029	40-41	Pointer: Start of BASIC	Text
 VARTAB	002A-002B	42-43	Pointer: Start of BASIC	Variables
 ARYTAB	002C-002D	44-45	Pointer: Start of BASIC Arrays
 STREND	002E-002F	46-47	Pointer End of BASIC Arrays (+1)
 FRETOP	0030-0031	48-49	Pointer: Bottom of String Storage
 FRESPC	0032-0033	50-51	Utility String Pointer
 MEMSIZ	0034-0035	52-53	Pointer: Highest Address Used by BASIC
BTW: In this (German) article http://www.heise.de/newsticker/meldung/61292/ about Microsoft's birthday there is a link to a scan of a document describing the original MS Basic storage layout, by Bill Gates. You will recognize what you see :)

Concerning your "Loading" or "Saving" PET programs on the PC. BASIC only stores the basic text, i.e. TXTTAB-VARTAB. All variables are created on runtime.

After loading the BASIC recalculates the line links between the basic lines ("pointer to next line" in B.Gates description). At least it does for the C64, not sure about the PET.

Not sure what exactly you want to achieve.

André
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

fachat wrote:
BTW: In this (German) article http://www.heise.de/newsticker/meldung/61292/ about Microsoft's birthday there is a link to a scan of a document describing the original MS Basic storage layout, by Bill Gates. You will recognize what you see :)
Fascinating! Thanks for the link.
Post Reply