Note: There are 4 info files - this description assumes they are named as follows: info = pet.rom info_1 = 6502test info_2 = DEMO info_3 = wumpus ---- This program is not only a complete 6502 processor emulator, but also an emulation of the Commodore PET 2001. ---- Test ---- Compile the program, then test the 6502 emulation like this: ./prog 6502test A basic test is done for each instruction and addressing mode, all tests should pass. At the end of the tests, it loops forever - break out with control-C. ---- PET EMULATION ---- Cast your mind back to 1977... a little company called Commodore introduced the "PET", the Personal Electronic Transactor. The machine was a hit, and history was made. Now you can re-live those wonderful times with this PET emulator! Make sure you have a terminal window of 40x25 chars or bigger, and then run the emulator like this: ./prog pet.rom You should see the startup message. Try typing in some BASIC - for instance: PRINT "HELLO, WORLD" There is an optional numeric parameter, which controls the speed. For a slower cursor blink, try ./prog pet.rom 6 and for faster ./prog pet.rom 2 the default is 4. The control keys are as follows: ^A HOME ^L CLR ^R RVS ^E OFF ^Y INST ^X STOP (break) ^F cursor forward ^B cursor back ^N cursor down ^P cursor up Supplied also is a short demo program written in BASIC. Try typing LOAD "DEMO" RUN Many other old programs will run in this emulator too. Files with a .PRG extension should work. (Look, for instance, here: http://www.funet.fi/pub/cbm/pet/ALLFILES.html, or try this one: http://www.funet.fi/pub/cbm/pet/games/english/dungeon.prg ) The filenames must be upper case in order to be loaded by the emulator. You can save programs too - try 10 PRINT "HELLO!" SAVE "HELLO" NEW LOAD "HELLO" RUN You also might try typing this to see an ancient easter egg: WAIT 6502,12 ---- 6502 EMULATION ---- The program is basically a 6502 emulator, and it does NOT need the commodore rom to work. Supplied as a demonstration is a compiled-for-6502 version of the 1994 IOCCC winner dodsond2. Try: ./prog wumpus You can write your own programs too, any 6502 assembler should work. The emulator loads the supplied file at $C000, and starts execution from that address also (the reset vector is ignored). The screen memory begins at $8000, and is 40 columns * 25 rows. Keypresses appear when they occur in memory location $A2, and are OR'd with $80 - this is a way of indicating a fresh character. The program can frequently check this byte, and when it sees a new character, it can AND it with $7F to indicate that it has been read. The 6502 emulator receives an interrupt 60 times a second or so, you may want to disable interrupts (with SEI) if you do not need this. In 6502 emulation mode the special PET character codes are not used and the screen understands normal ASCII. Lastly, the before emulation starts, the low byte from a time() call is placed at address 0 - this is used as a random seed by the example program. ---- Technical description: ---- Most of the program comprises the 6502 emulator. Curses is used for the screen and keyboard handling. Much of the obfuscation comes from the need to squeeze in the 6502 emulation as well as faking enough of the PET hardware for it to work. If the supplied file is exactly 16384 bytes, the emulator assumes it is a PET rom, and goes into PET emulation mode. Otherwise some PET specific features are skipped during normal 6502 emulation. The main processing all happens in a heroic expression containing no less than 64 ternery operators (after cpp) starting on line 56. This decodes the 6502 instructions according to a table and executes them. The addressing mode is decoded in a similar expression starting on line 53. ---- Bugs ---- The machine emulated is an older 40 column PET, so 80 column programs will not show correctly. There is no emulation of PET graphics characters. The parameter controls the speed of the 60Hz "jiffy clock", and not the processor speed. This means many games may run too fast to be usable - it really depends on the speed of your machine. Although the PET emulator can do LOAD and SAVE, it cannot VERIFY or OPEN and CLOSE files. The PET hardware emulation is not at all complete - features such as the hardware timers are completely missing. Some programs will not run correctly. The 6502 emulation does not include the seldom used decimal mode, or any of the "undocumented" instructions. ---- IMPORTANT NOTES ---- I think it is great fun to run the PET emulation and mess around with Microsoft BASIC. However, this obviously needs the rom file to work. My program is original and completely free of any copyright, but, of course, the pet rom is not my work. Technically I don't break rule #7, but it may be seen as abuse! Note that the pet rom is distributed freely with the open VICE emulator, and therefore I think it should be ok to put it on the IOCCC website should you choose this entry to win. Alternatively it would be easy to include instructions on how and from where to get the rom file, or to include code to download it in the build script. Or we can discuss another solution! ---- Finally: ---- What does ./prog pet.rom -1 do? Have fun!