André's 8-bit Pages  Projects  Code  Resources  Tools  Forum
(by Google)

Commodore PET ROM descriptions

This page describes the different ROM versions. There are basically three parts of each ROM set - for the BASIC ROM version and for the so-called editor ROM, and then the kernal.

  •  
    2023-07-23 Added a link to an updated ROM 1 patch.
  •  
    2020-10-29 Added link to page with all Commodore ROMs, and info on ROM adapters for 6332/2332 ROMs. Fix some links.
  •  
    2019-09-29 Added info about the garbage collection and other differences.
  •  
    2016-04-24 Updated and added 6540 links.
  •  
    2013-01-04 Added the section about the BASIC differences
  •  
    2011-06-04 Added links section and to create your own MS Basic, and BASIC as scripting language
  •  
    2010-08-28 Added links to history of MS BASIC and Bill Gates' programming tricks.

The Commodore BASIC was originally created by Microsoft, and bought by Commodore for the use in the KIM and PET computers. The original 6502 BASIC was, according to pagetable's analysis, a direct port from the Microsoft 8080 BASIC. It was very generic and for example asked for screen width and memory size on startup. It has since then proliferated into "virtually every 6502-based computer", including the Commodore, the Apple-II or Atari series.

It found its first use in the Commodore BASIC 1 - as found in the original ROMs. In the adoption process Commodore added commands like "OPEN" and other file I/O commands, and also renamed the "OK" prompt to "READY.". They also did some "in place" binary patching to work around bugs that.

Commodore adopted a later version of the BASIC even for the KIM-1. The first KIM, however, were shipped with an early version of the 6502 with a buggy "ROR" instruction. So the KIM BASIC worked around the broken "ROR" bug.

Microsoft later incorporated such changes as well. Commodore went back to Microsoft for an update. In that process Microsoft created the famous "WAIT6502,x" Easter Egg in the BASIC2 version. A comment in the pagetable's MS BASIC history is supposed to be by Bill Gates and says he put the WAIT easter egg there himself (I'd take that with a grain of salt though).

Anyway, the link below is a great analysis of the different MS BASIC versions, including the versions for Apple and Altair and how they relate to each other.

In another link it is discussed whether Bill Gates could write code. In fact I believe he could. To understand the next part you have to know that the ROM contains the BASIC - as written by Microsoft - but also the operating system "kernal" - written by Commodore and used by the BASIC for input/output.

The Commodore (MS) BASIC actually uses the "BIT ABS" opcode often to hide a two-byte opcode in the ABS operand. That was also in the Altair's 8080 BASIC version written by Gates. The (Commodore) kernal did not use this technique, at least not in the first version. In fact it could even be his influence that this technique was later used even in the Commodore kernal. Here's one example:

The "BASIC 1" kernal uses

 F0B6  A9 40     TALK       LDA #$40      
 F0B8  D0 02                BNE ATNOUT    
 F0BA  A9 20     LISTEN     LDA #$20      
 F0BC  48        ATNOUT     PHA           
	
while the "BASIC 4" kernal uses
 F0D2	TALK	LDA #$40
 F0D4		.byte $2C	; BIT $20A9	note: the "LDA #$20" is hidden in the operand!
 F0D5	LISTEN	LDA #$20
 F0D7	ATNOUT	PHA
	
I didn't do a further thorough research though.

Basically there are three different ROM versions that came with the PET computers, the original ROMs, the upgrade ROMs and the 4.0 ROMs. Here are some of the peculiarities of the different ROM versions. (I wished I had more about that; see also the petfaq file)

ROM images can be found in the CBM archive

A reverse engineered BASIC source code for versions 1,2 and 4 can be found in the CBM archive.

Original ROMs ($C000-$FFFF)

Original ROMs, from $c000, powers up *** COMMODORE BASIC ***. To be found in the calculator-style keyboard machines. Horribly broken, especially the IEEE488 did not work. The very low level routines worked, but on top of that a lot had to be fixed. (Note: the VICE emulator includes a patch that allows you to use the BASIC1 ROMs with the IEEE488 disks) In upper/lower case character mode (as opposed to upper case/graphics mode) the upper and lower characters were exchanged (SHIFT for lower case). Arrays could only be 256 elements in size. There are a lot of other bugs...

Note that these ROMs had a kind of copy protection: the BASIC PEEK function could not read out the actual ROM values...

Upgrade ROMs ($C000-$FFFF)

The `upgrade ROMs' were also known as 2.0 or 3.0 ROMs. Start at $c000, power up ### COMMODORE BASIC ### Fix a lot of bugs and make IEEE488 work. Also adds a tiny machine monitor. Those ROMs have most bugs fixed, although there seem to be different levels of bug fixing (the products list says something about ROM versions 2.0-2.3). Try and enter "WAIT 6502,1"...

4.0 ROMs ($B000-$FFFF)

Power up with *** COMMODORE BASIC 4.0 ***. The 4.0 ROMs add the so-called DISK-BASIC with disk operation commands (DLOAD, DSAVE, COPY, SCRATCH, DS$ for the error channel etc). The editor ROM still differs from small screen and large screen versions (board #2 and boards #3 and #4)...

Garbage Collection

The original BASIC garbage collection was horribly slow. Only with BASIC 4 the garbage collection was optimized. Olaf Seibert writes on the CBM-hackers list:

The string garbage collection in the "new ROMs" and the 64 is quadratic
in the number of strings that need to be retained.

Variables are stored in records of 7 or so bytes. 2 for the name and I
think 5 for the value (the space needed for a floating point variable).
Strings had the address to where the actual string text was stored,
between the BASIC program and the top of memory. I think that only in
string arrays, the wasted space was eliminated.

For garbage collection, it would proceed like thus.
To start, it would set the top of used memory to the end of the BASIC
program.
It would make a pass through all string variables and arrays to check
which string variable's string was stored the lowest in memory.  If that
left any room between there and the top of used memory, the space in
between could be reclaimed, by moving the string down (and adjusting the
variable record). Then the top of used memory would be set to the end of
the string, and repeat. If there are N string variables it would need N
passes through them to check each of them.

The change in BASIC 4.0 is that every stored string would have a pointer
back to its variable record (probably also a string length). That way
you can just go once through the stored strings. If the back pointer
points to a record which in turn points back to the string, it is still
in use. If not, it is unused and can be reclaimed. Used strings get
moved down to the top of used memory (if needed) (and the variable
record gets adjusted) and unused ones just get skipped. This needs just
one pass through the stored strings (garbage and to keep).

ROM History

The BASIC ROM is subject to evolutionary changes, and finding the steps and the order they occurred in is difficult. Here are some links with more information on it.

In addition to the BASIC (including the kernel) there are different `editor' ROMs. Those ROMs occupy $e000-$e800 and contain (in the 4.0 ROMs) the screen handling routines. The 4.0 ROMs can be found in machines with and without CRTC, so they had different editor ROMs. Also the business and graphics keyboard differ in layout, so these editor ROMs differ too. The changes for business and graphics layout in the upgrade ROMs are in $e000-$e800 too. Later on there were nationalized keyboard versions with additional ROM in $e900-$efff. In fact the so-called 50Hz and 60Hz versions have different keyboard layouts and thus different editor ROMs.

For keyboards please have a look at keyboards section.

The character ROM is the ROM that is used to produce the characters on the screen. Therefore the scan line number (0-7) is used as address for the ROM (A0-2), then the 7 lower bits of the byte read from the screen memory (A3-A9), then the VIA CA2 line as switch between upper/lower case mode and upper case/graphics mode (A10). This gives a charrom size of 2k.

You will notice that the highest data bit of the character read from the screen RAM is not yet used. It is instead directly fed to an exclusive-OR gate to invert the pixel stream from the character shift register. This inverts the character by hardware.

The newer models have another line from the CRTC to the character ROM, namely CRTC MA13 is used as A11 for the charrom. With this line you can switch to a completely different character set in the charrom. I assume this is used in nationalized machines with different charsets.

The early 6540

The ROMs of the early boards came with 6540 ICs from Commodore as ROMs Those are completely deprecated. Matthew D'Asaro has written an article on them and how to replace them with modern chips

Others have done similar adapters.

The dynamic PET 6332/2332

Recently I got the question how to replace the ROMs in a dynamic PET with a modern chip. In the schematics they are marked as 6332, or later 2332. One has to note that the Commodore 2332 come with a programmable CS1 (pin 20) and CS2 (pin 21), that can act either as high or low. In the later 8032 PET this is actually used to allow for a "/NOROM" signal on the CPU socket (that is otherwise unused by the CPU) to switch off all ROMs using CS2. So the CS1 signal is low and the CS2 signal line is high on all models I checked.

So it is not just using a simple 2532 adapter - a more modern 2732 has a low active chip select at pin 18, and another on pin 20 (doubling as Vpp).

The connections that need to be done are listed in this table:

Signal2332/6332 on the PET boardsocket for 2732 to use as replacement
/CS2020, 18
A111821
CS21No connection
*all othersstraight through
This section contains links concerning Commodore (MS) BASIC and kernal ROMs

Return to Homepage

Last modified: 2023-07-23
follow

Follow my 8-bit tweets on Mastodon (In new window) or Bluesky

discuss

Discuss my site on this 6502.org forum thread

(Forum registration required to post)

hot!

Dive into the retro feeling and build yourself a Micro-PET or a Multi-board Commodore 4032 replica

Need more speed? Speed up your 6502 computer with this 10 MHz 6502 CPU accelerator board

Interested in electronics design? Look at the design lesson I got from Bil Herd, the hardware designer of the C128

Want 64bit? - pimp the 6502 with the 65k processor design!