Format fix 2005/sykes/README.md

This commit is contained in:
Cody Boone Ferguson committed 2023-04-29 05:37:02 -07:00
1 parent 7ccf7c75ec
commit 594958b67f
1 file changed
+148 -91
+148 -91
View File
@@ -1,10 +1,6 @@
# Best emulator # Best emulator
Stephen Sykes Stephen Sykes
Maxisat
Laivalahdenportti 2
00810, Helsinki
Finland
<sds@maxisat.fi> <sds@maxisat.fi>
<https://web.archive.org/web/20160316092728/http://www.stephensykes.com/> <https://web.archive.org/web/20160316092728/http://www.stephensykes.com/>
@@ -24,34 +20,54 @@ make
```sh ```sh
./sykes pet.rom ./sykes pet.rom
# type in the following for an old Easter egg:
WAIT 6502,12
``` ```
Also try:
```
./sykes chess
```
for some good [chess](https://en.wikipedia.org/wiki/Chess) fun.
## Judges' remarks: ## Judges' remarks:
For those who fondly remember their first PET, this entry will start you For those who fondly remember their first
down memory lane ... starting with $C000 of course! [PET](https://en.wikipedia.org/wiki/Commodore_PET), this entry will start you
down memory lane ... starting with `$C000` of course!
We encourage you to try and grok the obfuscated expression on line 56, We encourage you to try and grok the obfuscated expression on [line
after C pre-processor gets finished with it! 56](https://github.com/ioccc-src/temp-test-ioccc/blob/master/2005/sykes/sykes.c#L56),
after the C pre-processor gets finished with it!
We download the ROM contents to use the emulator in PET mode as follows: We downloaded the [ROM](https://en.wikipedia.org/wiki/ROM_image) contents to use
the [emulator](https://en.wikipedia.org/wiki/Emulator) in
[PET](https://en.wikipedia.org/wiki/Commodore_PET) mode as follows:
wget http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/basic-2-c000.901465-01.bin ```sh
wget http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/basic-2-d000.901465-02.bin wget http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/basic-2-c000.901465-01.bin
wget http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/edit-2-n.901447-24.bin wget http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/basic-2-d000.901465-02.bin
wget http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/kernal-2.901465-03.bin wget http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/edit-2-n.901447-24.bin
wget http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/kernal-2.901465-03.bin
```
We then created: We then created:
dd bs=2k count=1 if=/dev/zero of=nullfill.bin ```sh
dd bs=2k count=1 if=/dev/zero of=nullfill.bin
```
For your convenience, we have added the above mentioned files to this entry directory. For your convenience, we have added the above mentioned files to this entry directory.
They are used to form the pet.rom file. They are used to form the `pet.rom` file.
## Author's remarks: ## Author's remarks:
This program is not only a complete 6502 processor emulator, but also an This program is not only a complete [Motorola 6502
emulation of the Commodore PET 2001. processor](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulator](https://en.wikipedia.org/wiki/Emulator), but also an emulation of the
[Commodore PET 2001](https://en.wikipedia.org/wiki/Commodore_PET).
This is the second version of the same entry, but this one takes care to This is the second version of the same entry, but this one takes care to
not include any possibly copyrighted items in the info files, to be sure not include any possibly copyrighted items in the info files, to be sure
@@ -59,7 +75,9 @@ to not infringe the rules.
### Test ### Test
Compile the program, then test the 6502 emulation like this: Compile the program, then test the
[6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulation](https://en.wikipedia.org/wiki/Emulator) like this:
```sh ```sh
./sykes 6502test ./sykes 6502test
@@ -71,38 +89,31 @@ control-C.
### PET EMULATION ### PET EMULATION
Cast your mind back to 1977... a little company called Commodore Cast your mind back to 1977... a little company called
introduced the "PET", the Personal Electronic Transactor. [Commodore](https://en.wikipedia.org/wiki/Commodore_International) introduced
the [PET](https://en.wikipedia.org/wiki/Commodore_PET), the Personal Electronic
Transactor.
The machine was a hit, and history was made. The [machine](https://en.wikipedia.org/wiki/Computer) was a hit, and
[history](https://en.wikipedia.org/wiki/History) was made.
Now you can re-live those wonderful times with this PET emulator! Now you can relive those wonderful times with this
[PET](https://en.wikipedia.org/wiki/Commodore_PET) emulator!
To emulate the PET, you must download the pet rom. Use the script Make sure you have a [terminal
provided (fetchrom), it will fetch the parts from right place, and will window](https://en.wikipedia.org/wiki/Terminal_emulator) of 40x25 chars or
compile it into the file pet.rom. bigger, and then run the emulator like this:
Or if you don't have wget, navigate to here:
<http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/>
and fetch the files basic-2-c000.901465-01.bin,
basic-2-d000.901465-02.bin, edit-2-n.901447-24.bin,
kernal-2.901465-03.bin. Concatenate them in that order into one pet.rom
file, adding a 2048 byte filler in between the edit-2 and kernal-2
files. The resulting file should be 16384 bytes.
Make sure you have a terminal window of 40x25 chars or bigger, and then
run the emulator like this:
```sh ```sh
./sykes pet.rom ./sykes pet.rom
``` ```
You should see the startup message. Try typing in some BASIC - for You should see the startup message. Try typing in some
instance: [BASIC](https://en.wikipedia.org/wiki/BASIC) - for instance:
PRINT "HELLO, WORLD" ```
PRINT "HELLO, WORLD"
```
There is an optional numeric parameter, which controls the speed. For a There is an optional numeric parameter, which controls the speed. For a
slower cursor blink, try slower cursor blink, try
@@ -117,10 +128,11 @@ and for faster
./sykes pet.rom 2 ./sykes pet.rom 2
``` ```
the default is 4. The default is 4.
The control keys are as follows: The control keys are as follows:
```
^A HOME ^A HOME
^L CLR ^L CLR
^R RVS ^R RVS
@@ -130,13 +142,17 @@ The control keys are as follows:
^F cursor forward ^F cursor forward
^B cursor back ^B cursor back
^N cursor down ^N cursor down
```
Supplied also is a short demo program written in BASIC. Try typing Supplied also is a short demo program written in
[BASIC](https://en.wikipedia.org/wiki/BASIC). Try typing
LOAD "DEMO" ```
RUN LOAD "DEMO"
RUN
```
Many other old programs will run in this emulator too. Files with a .PRG Many other old programs will run in this emulator too. Files with a `.PRG`
extension should work. (Look, for instance, here: extension should work. (Look, for instance, here:
<http://www.zimmers.net/anonftp/pub/cbm/pet/ALLFILES.html>, <http://www.zimmers.net/anonftp/pub/cbm/pet/ALLFILES.html>,
or try this one: <http://www.zimmers.net/anonftp/pub/cbm/pet/games/english/dungeon.prg>) or try this one: <http://www.zimmers.net/anonftp/pub/cbm/pet/games/english/dungeon.prg>)
@@ -144,24 +160,34 @@ The filenames must be upper case in order to be loaded by the emulator.
You can save programs too - try You can save programs too - try
10 PRINT "HELLO!" ```
SAVE "HELLO" 10 PRINT "HELLO!"
NEW SAVE "HELLO"
NEW
LOAD "HELLO" LOAD "HELLO"
RUN RUN
```
You also might try typing this to see an ancient easter egg: You also might try typing this to see an ancient [Easter egg][]:
WAIT 6502,12 ```
WAIT 6502,12
```
[Easter egg]: https://en.wikipedia.org/wiki/Easter_egg_(media)#Software
### 6502 EMULATION ### 6502 EMULATION
The program is basically a 6502 emulator, and it does NOT need the The program is basically a
commodore rom to work. [6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulator](https://en.wikipedia.org/wiki/Emulator), and it does NOT need the
[commodore](https://en.wikipedia.org/wiki/Commodore_PET)
[rom](https://en.wikipedia.org/wiki/ROM_image) to work.
Supplied as a demonstration is a compiled-for-6502 version a chess Supplied as a demonstration is a
program (heh, I found a use for a previous losing entry :). Try: compiled-for-[6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
version a chess program (heh, I found a use for a previous losing entry :) ). Try:
```sh ```sh
./sykes chess ./sykes chess
@@ -170,73 +196,104 @@ program (heh, I found a use for a previous losing entry :). Try:
It works as you would expect (it plays very badly). There's no castling It works as you would expect (it plays very badly). There's no castling
or en-passant, and to win you must actually take the opponent's king. or en-passant, and to win you must actually take the opponent's king.
You can write your own programs too, any 6502 assembler should work. You can write your own programs too, any [6502
assembler](https://en.wikibooks.org/wiki/6502_Assembly) should work.
The emulator loads the supplied file at $C000, and starts execution from The [emulator](https://en.wikipedia.org/wiki/Emulator) loads the supplied file
that address also (the reset vector is ignored). 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. 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 Key presses appear when they occur in memory location `$A2`, and are
with $80 - this is a way of indicating a fresh character. The program [OR](https://en.wikipedia.org/wiki/Bitwise_operation#OR)ed
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 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. [AND](https://en.wikipedia.org/wiki/Bitwise_operation#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 The
want to disable interrupts (with SEI) if you do not need this. [6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulator](https://en.wikipedia.org/wiki/Emulator) receives an interrupt 60
times a second or so, you may want to disable interrupts (with the `SEI`
instruction) if you do not need this.
In 6502 emulation mode the special PET character codes are not used and In
the screen understands normal ASCII. [6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulation](https://en.wikipedia.org/wiki/Emulator) mode the special
[PET](https://en.wikipedia.org/wiki/Commodore_PET) character codes are not used and
the screen understands normal
[ASCII](https://en.wikipedia.org/wiki/ASCII#Character_set).
Lastly, the before emulation starts, the low byte from a time() call is Lastly, the before [emulation](https://en.wikipedia.org/wiki/Emulator) starts,
placed at address 0 - this can be used as a random seed. the low byte from a `time()` call is placed at address 0 - this can be used as a
random seed.
### Technical description ### Technical description
Most of the program comprises the 6502 emulator. Curses is used for the Most of the program comprises the
[6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulator](https://en.wikipedia.org/wiki/Emulator). `curses` is used for the
screen and keyboard handling. screen and keyboard handling.
Much of the obfuscation comes from the need to squeeze in the 6502 Much of the obfuscation comes from the need to squeeze in the
emulation as well as faking enough of the PET hardware for it to work. [6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulation](https://en.wikipedia.org/wiki/Emulator) as well as faking enough of
the [PET](https://en.wikipedia.org/wiki/Commodore_PET) hardware for it to work.
If the supplied file is exactly 16384 bytes, the emulator assumes it is If the supplied file is exactly 16384 bytes, the
a PET rom, and goes into PET emulation mode. Otherwise some PET specific [emulator](https://en.wikipedia.org/wiki/Emulator) assumes it is a
features are skipped during normal 6502 emulation. [PET](https://en.wikipedia.org/wiki/Commodore_PET)
[rom](https://en.wikipedia.org/wiki/ROM_image), and goes into PET emulation
mode. Otherwise some PET specific features are skipped during normal
[6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulation](https://en.wikipedia.org/wiki/Emulator).
The main processing all happens in a heroic expression containing no The main processing all happens in a heroic expression containing no
less than 64 ternery operators (after cpp) starting on line 56. This less than 64 ternary operators (after `cpp`) starting on line 56. This
decodes the 6502 instructions according to a table and executes them. decodes the
[6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
instructions according to a table and executes them.
The addressing mode is decoded in a similar expression starting on line The addressing mode is decoded in a similar expression starting on line
53. 53.
### Bugs ### Bugs
The machine emulated is an older 40 column PET, so 80 column programs The machine emulated is an older 40 column
[PET](https://en.wikipedia.org/wiki/Commodore_PET), so 80 column programs
will not show correctly. will not show correctly.
There is no emulation of PET graphics characters. There is no [emulation](https://en.wikipedia.org/wiki/Emulator) of
[PET](https://en.wikipedia.org/wiki/Commodore_PET) graphics characters.
The parameter controls the speed of the 60Hz "jiffy clock", and not the 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 - processor speed. This means many games may run too fast to be usable -
it really depends on the speed of your machine. it really depends on the speed of your machine.
Although the PET emulator can do LOAD and SAVE, it cannot VERIFY or OPEN Although the PET [emulator](https://en.wikipedia.org/wiki/Emulator) can do LOAD
and CLOSE files. and SAVE, it cannot VERIFY or OPEN and CLOSE files.
The PET hardware emulation is not at all complete - features such as the The [PET](https://en.wikipedia.org/wiki/Commodore_PET) hardware
hardware timers are completely missing. Some programs will not run [emulation](https://en.wikipedia.org/wiki/Emulator) is not at all complete -
correctly. 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 The
of the "undocumented" instructions. [6502](https://en.wikipedia.org/wiki/MOS_Technology_6502#Technical_description)
[emulation](https://en.wikipedia.org/wiki/Emulator) does not include the seldom
used decimal mode, or any of the "undocumented" instructions.
### IMPORTANT NOTE ### IMPORTANT NOTE
I think it is great fun to run the PET emulation and mess around with I think it is great fun to run the
Microsoft BASIC. However, this obviously needs the rom file to work. My [PET](https://en.wikipedia.org/wiki/Commodore_PET)
[emulation](https://en.wikipedia.org/wiki/Emulator) and mess around with
[Microsoft](https://en.wikipedia.org/wiki/Microsoft)
[BASIC](https://en.wikipedia.org/wiki/BASIC). However, this obviously needs the
[rom](https://en.wikipedia.org/wiki/ROM_image) file to work. My
program is original and completely free of any copyright, but, of program is original and completely free of any copyright, but, of
course, the pet rom is not my work. So I ask the user to download it course, the `pet.rom` is not my work. So I ask the user to download it
from the internet. This is to avoid directly infringing any copyright. from the Internet. This is to avoid directly infringing any copyright.
### Finally ### Finally