Ano-Tech Computers
Enter keyword:

C64: BASIC program storage in RAM
Problem:
How is a BASIC program stored in the Commodore 64?
 
Solution:
The BASIC program code always* starts with a byte #$00 at $0800, followed by one or more records in the following format:

NEXT LOW (byte)
NEXT HIGH (byte)
BASIC line number LOW (byte)
BASIC line number HIGH (byte)
Bytecode ASCIIZ string, bytes > #$80 are instruction codes

Example code:
0800: 00 0c 08 01 00 9e 20 34
0808: 30 39 36 00 00 00

Code breakdown:
0800: 00 # Always* zero
0801: 0c 08 # Next record begins at $080c
0803: 01 00 # Line number 1
0805: 9e 20 34 30 39 36 # SYS 4096
080b: 00 # ASCIIZ string terminator
080c: 00 00 # Next record begins at $0000 (End of program)

*) The first byte is always zero in the code I have examined. If this byte is changed, the BASIC interpreter will yield syntax errors but still run the code that follows.

 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles