Skip to content

Commit 06dee7a

Browse files
authored
Passed blarrg's cgb_sound tests, and other sound things 🔊 (#286)
* 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
1 parent ce1c1c8 commit 06dee7a

22 files changed

+102608
-102243
lines changed

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ lib/**/*.js linguist-vendored=false
99
dist/wasm/*.wasm linguist-vendored=false
1010
dist/wasm/*.wast linguist-vendored=false
1111
dist/wasm/*.wat linguist-vendored=false
12+
docs/wasm/*.wasm linguist-vendored=false
13+
docs/wasm/*.wast linguist-vendored=false
14+
docs/wasm/*.wat linguist-vendored=false
1215
**/*.wasm linguist-vendored=false
1316
**/*.wast linguist-vendored=false
1417
**/*.wat linguist-vendored=false

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,14 @@ These are all currently known passing tests (by me), there may be more test roms
156156

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

159-
cpu_instrs, instr_timing, mem_timing, mem_timing-2, halt_bug
159+
cpu_instrs, instr_timing, mem_timing, mem_timing-2, halt_bug, cgb_sound
160160

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

167168
### Mooneye
168169

core/memory/readTraps.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Memory } from './memory';
22
import { Cpu } from '../cpu/index';
33
import { Graphics } from '../graphics/graphics';
44
import { Lcd } from '../graphics/index';
5-
import { batchProcessAudio, SoundRegisterReadTraps } from '../sound/index';
5+
import { batchProcessAudio, SoundRegisterReadTraps, Channel3 } from '../sound/index';
66
import { eightBitStoreIntoGBMemory } from './store';
77
import { eightBitLoadFromGBMemory } from './load';
88
import { Joypad, getJoypadState } from '../joypad/index';
@@ -90,10 +90,21 @@ export function checkReadTraps(offset: i32): i32 {
9090
batchProcessAudio();
9191
return SoundRegisterReadTraps(offset);
9292
}
93+
9394
// FF27 - FF2F not used
95+
// http://gbdev.gg8.se/wiki/articles/Gameboy_sound_hardware#Register_Reading
96+
// Always read as 0xFF
97+
if (offset >= 0xff27 && offset <= 0xff2f) {
98+
return 0xff;
99+
}
100+
94101
// Final Wave Table for Channel 3
95102
if (offset >= 0xff30 && offset <= 0xff3f) {
96103
batchProcessAudio();
104+
105+
if (Channel3.isEnabled) {
106+
return Channel3.handleWaveRamRead();
107+
}
97108
return -1;
98109
}
99110

core/memory/writeTraps.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Memory } from './memory';
22
import { Cpu } from '../cpu/index';
33
import { Graphics } from '../graphics/graphics';
44
import { Palette, writeColorPaletteToMemory, Lcd } from '../graphics/index';
5-
import { batchProcessAudio, SoundRegisterWriteTraps } from '../sound/index';
5+
import { batchProcessAudio, SoundRegisterWriteTraps, Channel3 } from '../sound/index';
66
import { Timers, batchProcessTimers } from '../timers/index';
77
import { Serial } from '../serial/serial';
88
import { Interrupts } from '../interrupts/index';
@@ -110,9 +110,17 @@ export function checkWriteTraps(offset: i32, value: i32): boolean {
110110
}
111111

112112
// FF27 - FF2F not used
113+
113114
// Final Wave Table for Channel 3
114115
if (offset >= 0xff30 && offset <= 0xff3f) {
115116
batchProcessAudio();
117+
118+
// Need to handle the write if channel 3 is enabled
119+
if (Channel3.isEnabled) {
120+
Channel3.handleWaveRamWrite(value);
121+
return false;
122+
}
123+
return true;
116124
}
117125

118126
// Other Memory effects fomr read/write to Lcd/Graphics

core/sound/accumulator.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function accumulateSound(numberOfCycles: i32): void {
7171

7272
// Do Some downsampling magic
7373
let downSampleCycleCounter = Sound.downSampleCycleCounter;
74-
downSampleCycleCounter += numberOfCycles * Sound.downSampleCycleMultiplier;
74+
downSampleCycleCounter += numberOfCycles;
7575
let maxDownSampleCycles = Sound.maxDownSampleCycles();
7676
if (downSampleCycleCounter >= maxDownSampleCycles) {
7777
// Reset the downsample counter

0 commit comments

Comments
 (0)