yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
apu.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EMU_APU_H_
2#define YAZE_APP_EMU_APU_H_
3
4#include <cstdint>
5#include <iostream>
6#include <vector>
7#include <array>
8
9#include "app/emu/audio/dsp.h"
12
13namespace yaze {
14namespace app {
15namespace emu {
16namespace audio {
17
18using namespace memory;
19
20typedef struct Timer {
21 uint8_t cycles;
22 uint8_t divider;
23 uint8_t target;
24 uint8_t counter;
25 bool enabled;
27
53class Apu {
54 public:
55 Apu(MemoryImpl &memory) : memory_(memory) {}
56
57 void Init();
58 void Reset();
59
60 void RunCycles(uint64_t cycles);
61 uint8_t SpcRead(uint16_t address);
62 void SpcWrite(uint16_t address, uint8_t data);
63 void SpcIdle(bool waiting);
64
65 void Cycle();
66
67 uint8_t Read(uint16_t address);
68 void Write(uint16_t address, uint8_t data);
69
70 auto dsp() -> Dsp & { return dsp_; }
71 auto spc700() -> Spc700 & { return spc700_; }
72
73 // Port buffers (equivalent to $2140 to $2143 for the main CPU)
74 std::array<uint8_t, 6> in_ports_; // includes 2 bytes of ram
75 std::array<uint8_t, 4> out_ports_;
76 std::vector<uint8_t> ram = std::vector<uint8_t>(0x10000, 0);
77
78 private:
79 bool rom_readable_ = false;
80
81 uint8_t dsp_adr_ = 0;
82 uint32_t cycles_ = 0;
83
85 std::array<Timer, 3> timer_;
86
88 [&](uint16_t adr, uint8_t val) { SpcWrite(adr, val); },
89 [&](uint16_t adr) { return SpcRead(adr); },
90 [&](bool waiting) { SpcIdle(waiting); },
91 };
94};
95
96} // namespace audio
97} // namespace emu
98} // namespace app
99} // namespace yaze
100
101#endif
The Apu class represents the Audio Processing Unit (APU) of a system.
Definition apu.h:53
ApuCallbacks callbacks_
Definition apu.h:87
MemoryImpl & memory_
Definition apu.h:84
void SpcWrite(uint16_t address, uint8_t data)
Definition apu.cc:197
uint8_t Read(uint16_t address)
Definition apu.cc:101
void SpcIdle(bool waiting)
Definition apu.cc:202
Apu(MemoryImpl &memory)
Definition apu.h:55
uint8_t SpcRead(uint16_t address)
Definition apu.cc:192
void Write(uint16_t address, uint8_t data)
Definition apu.cc:138
std::array< Timer, 3 > timer_
Definition apu.h:85
std::array< uint8_t, 6 > in_ports_
Definition apu.h:74
auto dsp() -> Dsp &
Definition apu.h:70
std::array< uint8_t, 4 > out_ports_
Definition apu.h:75
std::vector< uint8_t > ram
Definition apu.h:76
void RunCycles(uint64_t cycles)
Definition apu.cc:66
auto spc700() -> Spc700 &
Definition apu.h:71
The Spc700 class represents the SPC700 processor.
Definition spc700.h:72
Implementation of the Memory interface for emulating memory in a SNES system.
Definition memory.h:102
struct yaze::app::emu::audio::Timer Timer
Definition common.cc:22