yaze 0.3.2
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 <vector>
6#include <array>
7
8#include "app/emu/audio/dsp.h"
11
12namespace yaze {
13namespace emu {
14
15// Forward declaration
16namespace debug {
18}
19
20typedef struct Timer {
21 uint8_t cycles;
22 uint8_t divider;
23 uint8_t target;
24 uint8_t counter;
25 bool enabled;
26} Timer;
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 uint64_t GetCycles() const { return cycles_; }
74
75 // Audio debugging
79 uint8_t GetStatus() const { return ram[0x00]; }
80 uint8_t GetControl() const { return ram[0x01]; }
81 void GetSamples(int16_t *buffer, int count, bool loop = false) {
82 dsp_.GetSamples(buffer, count, loop);
83 }
84 void WriteDma(uint16_t address, const uint8_t *data, int count) {
85 for (int i = 0; i < count; i++) {
86 ram[address + i] = data[i];
87 }
88 }
89
90 // Port buffers (equivalent to $2140 to $2143 for the main CPU)
91 std::array<uint8_t, 6> in_ports_; // includes 2 bytes of ram
92 std::array<uint8_t, 4> out_ports_;
93 std::vector<uint8_t> ram = std::vector<uint8_t>(0x10000, 0);
94
95 private:
96 bool rom_readable_ = false;
97
98 uint8_t dsp_adr_ = 0;
99 uint32_t cycles_ = 0;
100
101 // IPL ROM transfer tracking for proper termination
102 uint8_t transfer_size_ = 0;
103 bool in_transfer_ = false;
104
106 std::array<Timer, 3> timer_;
107
108 // Audio debugging
110
112 [&](uint16_t adr, uint8_t val) { SpcWrite(adr, val); },
113 [&](uint16_t adr) { return SpcRead(adr); },
114 [&](bool waiting) { SpcIdle(waiting); },
115 };
118};
119
120} // namespace emu
121} // namespace yaze
122
123#endif
The Apu class represents the Audio Processing Unit (APU) of a system.
Definition apu.h:53
bool in_transfer_
Definition apu.h:103
std::array< Timer, 3 > timer_
Definition apu.h:106
uint8_t SpcRead(uint16_t address)
Definition apu.cc:334
uint8_t Read(uint16_t address)
Definition apu.cc:186
uint32_t cycles_
Definition apu.h:99
ApuCallbacks callbacks_
Definition apu.h:111
auto dsp() -> Dsp &
Definition apu.h:70
MemoryImpl & memory_
Definition apu.h:105
debug::ApuHandshakeTracker * handshake_tracker_
Definition apu.h:109
void Write(uint16_t address, uint8_t data)
Definition apu.cc:233
void SpcIdle(bool waiting)
Definition apu.cc:344
uint8_t dsp_adr_
Definition apu.h:98
auto spc700() -> Spc700 &
Definition apu.h:71
void Init()
Definition apu.cc:45
void Reset()
Definition apu.cc:52
uint8_t transfer_size_
Definition apu.h:102
void set_handshake_tracker(debug::ApuHandshakeTracker *tracker)
Definition apu.h:76
void RunCycles(uint64_t cycles)
Definition apu.cc:84
Spc700 spc700_
Definition apu.h:117
void SpcWrite(uint16_t address, uint8_t data)
Definition apu.cc:339
void WriteDma(uint16_t address, const uint8_t *data, int count)
Definition apu.h:84
std::vector< uint8_t > ram
Definition apu.h:93
uint8_t GetControl() const
Definition apu.h:80
std::array< uint8_t, 4 > out_ports_
Definition apu.h:92
Apu(MemoryImpl &memory)
Definition apu.h:55
void GetSamples(int16_t *buffer, int count, bool loop=false)
Definition apu.h:81
uint64_t GetCycles() const
Definition apu.h:73
uint8_t GetStatus() const
Definition apu.h:79
bool rom_readable_
Definition apu.h:96
std::array< uint8_t, 6 > in_ports_
Definition apu.h:91
void Cycle()
Definition apu.cc:161
void GetSamples(int16_t *sample_data, int samples_per_frame, bool pal_timing)
Definition dsp.cc:667
Implementation of the Memory interface for emulating memory in a SNES system.
Definition memory.h:118
The Spc700 class represents the SPC700 processor.
Definition spc700.h:69
IPL ROM handshake tracker.
Main namespace for the application.
bool enabled
Definition apu.h:25
uint8_t counter
Definition apu.h:24
uint8_t divider
Definition apu.h:22
uint8_t target
Definition apu.h:23
uint8_t cycles
Definition apu.h:21