Skip to content

Commit

Permalink
Passed blarrg's cgb_sound tests, and other sound things 🔊 (#286)
Browse files Browse the repository at this point in the history
* Got registers in the blarrgg CGB test passing

* Passed blargg CGB Length tests

* Move the frame sequencer into it's own file, so that it can be used by
channels

* Got through a lot of the trigger tests

* Fixed registers tests as well need to finish triggers

* Starting to solve isEnabeld to finally pass triggers

* Re-fixed isEnabledStatus

* Literally on the last trigger test for sound

* Left a note, and fixed debugger stepping

* Still stuck :(

* Left another note

* Fixed frame sequencer being flipped, and fixed NR52 writing

* Left a note to look at binjgb

* FINALLY PASSED THE SOUND TRIGGER TEST!!!

* Fixed channel 2 trigger

* Passed all trigger tests

* Passes sweep #2

* Passed more sweep tests

* Soe updates still failing 5

* Finally Passed the sweep subtest :D

* Passed sweep details

* Started fixing some things, and left notes for later

* Fixing up period timing

* Fixed up negative periods on channels

* ONE LAST WAVE CHANNEL TEST!!!

* FINISHED BLARGG CGB SOUND TEST!!!

* Updated all the tests

* Added hotkeys to help

* Logged out some buffers

* Moved around some more crackling debug logic

* Removed all the debug output, and fixd the crackling a little bit

* Fixed up the tests

* Fixed up package-lock
  • Loading branch information
torch2424 authored Apr 27, 2019
1 parent ce1c1c8 commit 06dee7a
Show file tree
Hide file tree
Showing 22 changed files with 102,608 additions and 102,243 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ lib/**/*.js linguist-vendored=false
dist/wasm/*.wasm linguist-vendored=false
dist/wasm/*.wast linguist-vendored=false
dist/wasm/*.wat linguist-vendored=false
docs/wasm/*.wasm linguist-vendored=false
docs/wasm/*.wast linguist-vendored=false
docs/wasm/*.wat linguist-vendored=false
**/*.wasm linguist-vendored=false
**/*.wast linguist-vendored=false
**/*.wat linguist-vendored=false
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,14 @@ These are all currently known passing tests (by me), there may be more test roms

[Repo with all blargg's tests and source](https://github.com/retrio/gb-test-roms)

cpu_instrs, instr_timing, mem_timing, mem_timing-2, halt_bug
cpu_instrs, instr_timing, mem_timing, mem_timing-2, halt_bug, cgb_sound

![Cpu Instructions all tests passing](./test/accuracy/testroms/blargg/cpu_instrs/cpu_instrs.golden.png)
![Instruction timing all tests passing](./test/accuracy/testroms/blargg/instr_timing/instr_timing.golden.png)
![Memory timing all tests passing](./test/accuracy/testroms/blargg/mem_timing/mem_timing.golden.png)
![Memory timing 2 all tests passing](./test/accuracy/testroms/blargg/mem_timing-2/mem_timing-2.golden.png)
![halt bug all tests passing](./test/accuracy/testroms/blargg/halt_bug/halt_bug.golden.png)
![cgb sound all tests passing](./test/accuracy/testroms/blargg/cgb_sound/cgb_sound.golden.png)

### Mooneye

Expand Down
13 changes: 12 additions & 1 deletion core/memory/readTraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Memory } from './memory';
import { Cpu } from '../cpu/index';
import { Graphics } from '../graphics/graphics';
import { Lcd } from '../graphics/index';
import { batchProcessAudio, SoundRegisterReadTraps } from '../sound/index';
import { batchProcessAudio, SoundRegisterReadTraps, Channel3 } from '../sound/index';
import { eightBitStoreIntoGBMemory } from './store';
import { eightBitLoadFromGBMemory } from './load';
import { Joypad, getJoypadState } from '../joypad/index';
Expand Down Expand Up @@ -90,10 +90,21 @@ export function checkReadTraps(offset: i32): i32 {
batchProcessAudio();
return SoundRegisterReadTraps(offset);
}

// FF27 - FF2F not used
// http://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware#Register_Reading
// Always read as 0xFF
if (offset >= 0xff27 && offset <= 0xff2f) {
return 0xff;
}

// Final Wave Table for Channel 3
if (offset >= 0xff30 && offset <= 0xff3f) {
batchProcessAudio();

if (Channel3.isEnabled) {
return Channel3.handleWaveRamRead();
}
return -1;
}

Expand Down
10 changes: 9 additions & 1 deletion core/memory/writeTraps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Memory } from './memory';
import { Cpu } from '../cpu/index';
import { Graphics } from '../graphics/graphics';
import { Palette, writeColorPaletteToMemory, Lcd } from '../graphics/index';
import { batchProcessAudio, SoundRegisterWriteTraps } from '../sound/index';
import { batchProcessAudio, SoundRegisterWriteTraps, Channel3 } from '../sound/index';
import { Timers, batchProcessTimers } from '../timers/index';
import { Serial } from '../serial/serial';
import { Interrupts } from '../interrupts/index';
Expand Down Expand Up @@ -110,9 +110,17 @@ export function checkWriteTraps(offset: i32, value: i32): boolean {
}

// FF27 - FF2F not used

// Final Wave Table for Channel 3
if (offset >= 0xff30 && offset <= 0xff3f) {
batchProcessAudio();

// Need to handle the write if channel 3 is enabled
if (Channel3.isEnabled) {
Channel3.handleWaveRamWrite(value);
return false;
}
return true;
}

// Other Memory effects fomr read/write to Lcd/Graphics
Expand Down
2 changes: 1 addition & 1 deletion core/sound/accumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export function accumulateSound(numberOfCycles: i32): void {

// Do Some downsampling magic
let downSampleCycleCounter = Sound.downSampleCycleCounter;
downSampleCycleCounter += numberOfCycles * Sound.downSampleCycleMultiplier;
downSampleCycleCounter += numberOfCycles;
let maxDownSampleCycles = Sound.maxDownSampleCycles();
if (downSampleCycleCounter >= maxDownSampleCycles) {
// Reset the downsample counter
Expand Down
Loading

0 comments on commit 06dee7a

Please sign in to comment.