Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions .github/workflows/rom-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ on:

jobs:
rom-tests:
# Every step below is a make target, so `make -C test-framework check`
# runs this same job locally, with the same flags, before pushing.
name: run-roms
runs-on: ubuntu-24.04

Expand All @@ -35,16 +37,35 @@ jobs:
# The verdict engine and header decoder are pure Python; these run even
# when the ROM list is empty, so the job still checks something useful.
- name: Unit tests
run: python3 -m unittest discover -s test-framework/tests -v
run: make -C test-framework unit-tests

- name: Run ROM tests
run: |
python3 test-framework/run_tests.py \
--rom-list test-framework/roms-ci.txt \
--baseline test-framework/baseline.json \
--json test-framework/results.json \
--junit test-framework/results.xml \
--github --no-color
make -C test-framework smoke SMOKE_EXTRA="\
--json results.json \
--junit results.xml \
--github --no-color"

# The test ROMs (blargg's suites, Bisqwit's ppu_read_buffer, nestest) are
# not stored in this repository (none carries a licence -- see
# test-framework/roms/README.md). They are downloaded from a pinned
# christopherpow/nes-test-roms commit and checked against the
# SHA-256 of every file in testroms.json, so the bytes CI runs are the
# bytes the baseline was recorded from.
- name: Cache test ROMs
uses: actions/cache@v6.1.0
with:
path: test-framework/roms/external
key: testroms-${{ hashFiles('test-framework/testroms.json') }}

# Unlike the smoke sweep above, these ROMs report their own verdict;
# `make testroms` carries the flags that reads it (see the Makefile).
- name: Run test ROMs (nes-test-roms)
run: |
make -C test-framework testroms TESTROM_EXTRA="\
--json testroms-results.json \
--junit testroms-results.xml \
--github --no-color"

- name: Upload results
if: always()
Expand All @@ -54,4 +75,6 @@ jobs:
path: |
test-framework/results.json
test-framework/results.xml
test-framework/testroms-results.json
test-framework/testroms-results.xml
if-no-files-found: ignore
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,43 @@ Note that no commercial ROM is (or should ever be) committed to the repository,
so the list used by CI only contains license-clean ROMs. Point the framework at
your own local collection when testing a change.

## Test ROMs

Alongside the game sweep, CI runs the NESdev test suites — blargg's CPU, PPU,
APU and MMC3 tests, Bisqwit's PPU read-buffer test and kevtris's **nestest**,
112 ROMs from [nes-test-roms](https://github.com/christopherpow/nes-test-roms).
These do not need any heuristic: they exercise documented hardware behaviour
and report whether they passed, which the framework reads straight out of the
emulated machine (blargg's status byte at `$6000`, the result byte of his
2005-era runtime at `$F8` or `$F0`, nestest's result bytes at `$02`/`$03`).

```sh
make -C test-framework testroms
```

That fetches the ROMs if they are not already there and runs them:

```
[PASS] m0 16-special.nes
[FAIL] m0 09-even_odd_frames.nes
-> blargg test failed (code 2): FD Pattern ----- should not skip
any clocks 09-even_odd_frames Failed #2
```

The test ROMs are **not** stored in this repository. None of them ships a
licence, and rNES is BSD-3-Clause, so they are downloaded
from a pinned commit on GitHub and verified against a recorded SHA-256 rather
than redistributed here. See
[test-framework/roms/README.md](./test-framework/roms/README.md).

Everything CI checks is available as a single target, so a change can be
verified before it is pushed:

```sh
make -C test-framework check # strict build, unit tests, both ROM suites
make -C test-framework help # list every target
```

See the [test framework documentation](./test-framework/README.md) for the
complete list of options, the failure heuristics and the CI setup.

Expand Down
41 changes: 41 additions & 0 deletions src/apu.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,8 @@ static void frm_seq_clock(void)
/* PS: We do nothing in Step 3 */
} else if (apu.frm_seq.cycles == frm_cycles[apu.type][4]) {
/* Step 4 */
frm_QuarterFrame();
frm_HalfFrame();
apu.frm_seq.cycles = 0;
return;
}
Expand Down Expand Up @@ -901,6 +903,44 @@ void apu_reset(void)
audio_play();
}

/**
* Soft reset: what the APU does when the console's reset button is pressed.
*
* Unlike apu_reset() (power-on), a reset leaves most of the APU alone:
* - $4015 is cleared, silencing every channel;
* - $4017 is rewritten with the last value written to it, so the frame
* counter keeps its mode and restarts, and the frame IRQ flag is cleared;
* - the pulse and noise length counters are zeroed and un-halted, while the
* triangle is left as it was.
*
* https://www.nesdev.org/wiki/CPU_power_up_state
* Verified by blargg's apu_reset tests (4015_cleared, 4017_written,
* irq_flag_cleared, len_ctrs_enabled).
*/
void apu_soft_reset(void)
{
int ch;

for (ch = 0; ch < 2; ch++) {
apu.PWM[ch].lc.counter = 0;
apu.PWM[ch].lc.halt = 0;
apu.PWM[ch].lc.enable = 0;
}
apu.noise.lc.counter = 0;
apu.noise.lc.halt = 0;
apu.noise.lc.enable = 0;
/* The triangle keeps its length counter; it is only disabled */
apu.triangle.lc.enable = 0;

apu.status.reg.raw = 0;
apu.dmc.dma.bytes_remaining = 0;
apu.dmc.irq_flag = 0;

apu.frm_seq.irq_flag = 0;
cpu_clear_irq();
apu_reg_write(REG_FRM_SEQ, apu.frm_seq.last_write);
}

/**
* Read one byte (8 bits) from the specified register
* @param [in] reg Register address
Expand Down Expand Up @@ -1043,6 +1083,7 @@ void apu_reg_write(uint16_t reg, uint8_t value)
break;

case REG_FRM_SEQ:
apu.frm_seq.last_write = value;
if ((value & 0x80) == 0)
apu.frm_seq.mode = 0;
else
Expand Down
3 changes: 3 additions & 0 deletions src/include/apu.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ struct _apu_frm_seq {
uint8_t irq_inhibit;
/** IRQ internal flag */
uint8_t irq_flag;
/** Last value written to $4017, rewritten on reset */
uint8_t last_write;
/** APU cycles */
uint32_t cycles;
};
Expand Down Expand Up @@ -417,6 +419,7 @@ struct _apu_t {
int apu_init(void);
int apu_destroy(void);
void apu_reset(void);
void apu_soft_reset(void);
uint8_t apu_reg_read(uint16_t reg);
void apu_reg_write(uint16_t reg, uint8_t value);
void apu_clock(void);
Expand Down
6 changes: 5 additions & 1 deletion src/include/ppu.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,12 @@ struct _ppu {
struct _OAM_sprite sprites[TOTAL_SPRITES_AUX];
uint8_t mem[TOTAL_SPRITES_AUX * sizeof(struct _OAM_sprite)];
} OAM_aux;
/** Dynamic latch */
/** Open-bus decay register (the "dynamic latch") */
uint8_t gen_latch;
/** Frames left before each decay group falls back to zero */
uint8_t decay_timer[3];
/** Read buffer behind $2007 */
uint8_t vram_buffer;
/** Game cartridge */
cartridge_t *cartridge;
/** Video standard */
Expand Down
Loading
Loading