yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
apu_dsp_test.cc
Go to the documentation of this file.
1#include <gtest/gtest.h>
2
3#include "app/emu/audio/apu.h"
5
6namespace yaze {
7namespace emu {
8
9class ApuDspTest : public ::testing::Test {
10 protected:
13
14 void SetUp() override {
15 std::vector<uint8_t> dummy_rom(0x200000, 0);
16 mem.Initialize(dummy_rom);
17 apu = new Apu(mem);
18 apu->Init();
19 apu->Reset();
20 }
21
22 void TearDown() override { delete apu; }
23};
24
25TEST_F(ApuDspTest, DspRegistersReadWriteMirror) {
26 // Select register 0x0C (MVOLL)
27 apu->Write(0xF2, 0x0C);
28 apu->Write(0xF3, 0x7F);
29 // Read back
30 apu->Write(0xF2, 0x0C);
31 uint8_t mvoll = apu->Read(0xF3);
32 EXPECT_EQ(mvoll, 0x7F);
33
34 // Select register 0x1C (MVOLR)
35 apu->Write(0xF2, 0x1C);
36 apu->Write(0xF3, 0x40);
37 apu->Write(0xF2, 0x1C);
38 uint8_t mvolr = apu->Read(0xF3);
39 EXPECT_EQ(mvolr, 0x40);
40}
41
42TEST_F(ApuDspTest, TimersEnableAndReadback) {
43 // Enable timers 0 and 1, clear in-ports, map IPL off for RAM access
44 apu->Write(0xF1, 0x03);
45
46 // Set timer targets
47 apu->Write(0xFA, 0x04); // timer0 target
48 apu->Write(0xFB, 0x02); // timer1 target
49
50 // Run enough SPC cycles via APU cycle stepping
51 for (int i = 0; i < 10000; ++i) {
52 apu->Cycle();
53 }
54
55 // Read counters (auto-clears)
56 uint8_t t0 = apu->Read(0xFD);
57 uint8_t t1 = apu->Read(0xFE);
58 // Should be within 0..15 and non-zero under these cycles
59 EXPECT_LE(t0, 0x0F);
60 EXPECT_LE(t1, 0x0F);
61}
62
63TEST_F(ApuDspTest, GetSamplesReturnsSilenceAfterReset) {
64 int16_t buffer[2 * 256]{};
65 apu->dsp().GetSamples(buffer, 256, /*pal=*/false);
66 for (int i = 0; i < 256; ++i) {
67 EXPECT_EQ(buffer[i * 2 + 0], 0);
68 EXPECT_EQ(buffer[i * 2 + 1], 0);
69 }
70}
71
72} // namespace emu
73} // namespace yaze
74
void TearDown() override
void SetUp() override
The Apu class represents the Audio Processing Unit (APU) of a system.
Definition apu.h:53
void Write(uint16_t address, uint8_t data)
Definition apu.cc:233
void Init()
Definition apu.cc:45
void Reset()
Definition apu.cc:52
Implementation of the Memory interface for emulating memory in a SNES system.
Definition memory.h:118
void Initialize(const std::vector< uint8_t > &romData, bool verbose=false)
Definition memory.cc:12
TEST_F(ApuDspTest, DspRegistersReadWriteMirror)
Main namespace for the application.