Files
ioccc/2005/sykes/README.md
T
Landon Curt Noll a78d78ccff fix use of temp-test-ioccc
Regarding use of `temp-test-ioccc` in current repo files:

We will ignore files under `tmp/` as they are going away.

We will ignore files under `bin/` as they will have their default `REPO_URL` value changed during the later parts of the **Great Fork Merge**.

We will ignore `*.html` files as the above changes to `bin/` tool will also change them during the later parts of the **Great Fork Merge**.

We will ignore `sitemap.xml` as the it will change during the later parts of the **Great Fork Merge**.

So this leaves for our consideration the files printed by this command:

```sh
find * -type f ! -name '*.html' ! -name sitemap.xml ! -path 'tmp/*' ! -path 'bin/*' -print0 | xargs -0 grep -l 'temp-test-ioccc'
```

We see 5 (3 sir), 3 cases:

* README.md index.md

The reference to `temp-test-ioccc` will be removed when a given section goes away as part of the later parts of the **Great Fork Merge**.

Nothing needs to be dome here other than to add some **XXX** comments to help remind us of what needs to be done in later parts of the **Great Fork Merge**.

* bugs.md faq.md news.md var.mk

The use of `temp-test-ioccc` is outside of a blob.

Here `https://github.com/ioccc-src/temp-test-ioccc/` may be be replaced by `https://github.com/ioccc-src/winner/` in anticipation of the **Great Fork Merge**.

There is an exception: The historic discussion abouts the history of the `temp-test-ioccc` repo needs to retain their `https://github.com/ioccc-src/temp-test-ioccc/` strings in `faq.md` and `news.md`.

* 2005/sykes/README.md

The markdown links that start with `https://github.com/ioccc-src/temp-test-ioccc/blob/master/` should instead start with `%%REPO_URL%%/`.

After the **Great Fork Merge**, the `%%REPO_URL%%/` value will refer to `https://github.com/ioccc-src/winner/blob/master/` instead.

* 2020/ferguson1/snake.1

There is not a tool to "pre-process" cat pages like there is for markdown files: no should there be.

The cat page refers to a markdown file when instead it should refer to a HTML page.

In this case we suggest that `https://github.com/ioccc-src/temp-test-ioccc/blob/` be replaced by `https://www.isthe.com/`, and `.md` be replaced by `.html` in anticipation of what it will need to be after the **Great Fork Merge**.

* YYYY/entry_dir/*.sh

The shell scripts references by the above command are "helper shell scripts.   Like man pages, there is no "pre-processor" for shell scripts, nor should there be.

Looking at these helper shell script files in detail:

```sh
find * -name '*.sh' ! -path 'tmp/*' ! -path 'bin/*' -print0 | xargs -0 grep 'temp-test-ioccc/blob/master'
```

We see that they all make references to `faq.md#something.`.

This is wrong in 2 ways:

0) They should not refer to the markdown file `faq.md` but rather to the HTML file `faq.html`.

1) They punctuate a literal string (with one exception) by adding a final period (".") to a string that requires somebody to copy and paste and exclude the final period (".").

Since these echo commands are suggesting that the user view something within the FAQ, we recommend that `echo "Tip: see https://github.com/ioccc-src/temp-test-ioccc/blob/master/faq.md#` be replaced by `echo "Tip: see https://www.ioccc.org/faq.html#` AND that the final period (".") be removed.  Thus they too will anticipate what they will need to be after the **Great Fork Merge**.
2024-05-30 11:17:04 -07:00

10 KiB

To build:

    make

Bugs and (Mis)features:

The current status of this entry is:

    STATUS: INABIAF - please **DO NOT** fix

For more detailed information see 2005/sykes in bugs.html.

To use:

    ./sykes binary_file

Try:

    ./try.sh

Judges' remarks:

For those who fondly remember their first 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, after the C pre-processor gets finished with it!

We downloaded the ROM contents to use the emulator in PET mode as follows:

    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/basic-2-d000.901465-02.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:

    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. They were used to form the pet.rom file.

Author's remarks:

This program is not only a complete Motorola 6502 processor emulator, but also an emulation of the Commodore PET 2001.

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 to not infringe the rules.

Test

Compile the program, then test the 6502 emulation like this:

    ./sykes 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 relive 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:

    ./sykes 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

    ./sykes pet.rom 6

and for faster

    ./sykes 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

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.zimmers.net/anonftp/pub/cbm/pet/ALLFILES.html

or try this one:

http://www.zimmers.net/anonftp/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 a chess program (heh, I found a use for a previous losing entry :) ). Try:

    ./sykes chess

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.

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. Key presses appear when they occur in memory location $A2, and are ORed 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 the SEI instruction) 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, before emulation starts, the low byte from a time(3) call is placed at address 0 - this can be used as a random seed.

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 ternary 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 NOTE

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. So I ask the user to download it from the Internet. This is to avoid directly infringing any copyright.

Finally

What does this do?

    ./sykes pet.rom -1

Have fun!