1 | #include "gui.hpp" |
2 | #include "cpu.hpp" |
3 | #include "apu.hpp" |
4 | |
5 | namespace APU { |
6 | |
7 | |
8 | Nes_Apu apu; |
9 | Blip_Buffer buf; |
10 | |
11 | const int OUT_SIZE = 4096; |
12 | blip_sample_t outBuf[OUT_SIZE]; |
13 | |
14 | void init() |
15 | { |
16 | buf.sample_rate(96000); |
17 | buf.clock_rate(1789773); |
18 | |
19 | apu.output(&buf); |
20 | apu.dmc_reader(CPU::dmc_read); |
21 | } |
22 | |
23 | void reset() |
24 | { |
25 | apu.reset(); |
26 | buf.clear(); |
27 | } |
28 | |
29 | template <bool write> u8 access(int elapsed, u16 addr, u8 v) |
30 | { |
31 | if (write) |
32 | apu.write_register(elapsed, addr, v); |
33 | else if (addr == apu.status_addr) |
34 | v = apu.read_status(elapsed); |
35 | |
36 | return v; |
37 | } |
38 | template u8 access<0>(int, u16, u8); template u8 access<1>(int, u16, u8); |
39 | |
40 | void run_frame(int elapsed) |
41 | { |
42 | apu.end_frame(elapsed); |
43 | buf.end_frame(elapsed); |
44 | |
45 | if (buf.samples_avail() >= OUT_SIZE) |
46 | GUI::new_samples(outBuf, buf.read_samples(outBuf, OUT_SIZE)); |
47 | } |
48 | |
49 | |
50 | } |
51 | |