Skip to content

Fix the sound timer, sprite wrapping under clip quirks, the quirked jump address, and Fx0A waiting for release - #51

Open
HarianthK wants to merge 1 commit into
craigthomas:mainfrom
HarianthK:fix-sound-clip-and-keywait
Open

HarianthK wants to merge 1 commit into
craigthomas:mainfrom
HarianthK:fix-sound-clip-and-keywait

Conversation

@HarianthK

Copy link
Copy Markdown

I ran Timendus' test suite through Chip8CPU with no window, using a small stand-in for pygame and a plain screen object, and found four things. Each is fixed here with a unit test.

Sound timer. decrement_timers had self.sound -= 1 if self.delay > 0 else 0, so the sound timer only counted down while the delay timer was running. A program that sets only the sound timer buzzed forever. One character.

Clipping. With clip_quirks on, a sprite whose start position lay past the edge was not drawn at all, because the position was only wrapped when clipping was off. The start always wraps around the screen; clipping only decides what happens to the part that hangs over. That is the ERR2 the quirks test shows on its clipping row. Fixed in both draw_normal and draw_extended.

Quirked jump. With jump_quirks on, Bxnn added only the low byte of the address to Vx, so jump0 0xE00 with vE at 0x9C landed at 0x09C instead of 0xE9C. The whole twelve bit address counts; its top nibble both names the register and is part of the address. The existing unit test encoded the low byte reading, so it changes with this, with the jump row of the quirks test as the reference.

Fx0A. Execution resumed when a key went down. The original hardware moves on when the key is released, and the keypad test's third check reports NOT RELEASED for this. The key is now remembered on press (decode_keypress_and_continue) and the register written on release (decode_keyrelease_and_continue, called from a new KEYUP branch in the emulator loop).

Results

Test Before After
Quirks as CHIP-8 (logic_quirks, clip_quirks) clipping ERR2 every row but display wait, which is not implemented
Quirks as SUPER-CHIP (shift, index, jump, clip) crashed on an unknown opcode at 0x09C every row
Quirks as XO-CHIP clipping ERR2 every row
Keypad, Fx0A NOT RELEASED ALL GOOD
Opcode and flags tests pass pass

python -m unittest passes, 140 tests including the five new ones. The harness that ran the suite is a throwaway and not included.

…ump address, and Fx0A waiting for release

Four things, found by running Timendus' test suite through the CPU
with no window.

The sound timer only counted down while the delay timer was above zero,
a one character slip, so a program that set the sound timer on its own
buzzed forever.

With clip quirks on, a sprite whose start lay past the edge was not
drawn at all. The starting position always wraps around the screen;
clipping only decides what happens to the part that hangs over. This
is the ERR2 the quirks test showed on its clipping row.

With jump quirks on, Bxnn added only the low byte of the address to the
register, so jump0 0xE00 with vE at 0x9C landed at 0x09C rather than
0xE9C. The whole twelve bit address counts, including the nibble that
names the register. The existing unit test encoded the low byte
reading and is updated, with the quirks test's jump row as the
reference.

Fx0A resumed when a key went down. The original hardware moves on when
the key is released, which the keypad test checks for. The key is now
remembered on press and the register written on release, with a KEYUP
handler in the emulator loop.

With these the quirks test passes every row as SUPER-CHIP and XO-CHIP,
and every row but display wait as CHIP-8, which was never implemented.
The opcode, flags and keypad tests pass. Five unit tests added, and
all 140 pass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant