yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
emulator.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_EMULATOR_H
2#define YAZE_APP_CORE_EMULATOR_H
3
4#include <cstdint>
5#include <vector>
6
7#include "app/emu/snes.h"
8#include "app/gui/zeml.h"
9#include "app/rom.h"
10#include "imgui/imgui.h"
11
12namespace yaze {
13
18namespace emu {
19
21 ImGuiKey a_button = ImGuiKey_Z;
22 ImGuiKey b_button = ImGuiKey_A;
23 ImGuiKey x_button = ImGuiKey_S;
24 ImGuiKey y_button = ImGuiKey_X;
25 ImGuiKey l_button = ImGuiKey_Q;
26 ImGuiKey r_button = ImGuiKey_W;
27 ImGuiKey start_button = ImGuiKey_Enter;
28 ImGuiKey select_button = ImGuiKey_Backspace;
29 ImGuiKey up_button = ImGuiKey_UpArrow;
30 ImGuiKey down_button = ImGuiKey_DownArrow;
31 ImGuiKey left_button = ImGuiKey_LeftArrow;
32 ImGuiKey right_button = ImGuiKey_RightArrow;
33};
34
39class Emulator : public SharedRom {
40 public:
42 std::string emulator_layout = R"(
43 Table id="Emulator" count="2" flags="Resizable|ScrollY" {
44 TableSetupColumn title="CPU",
45 TableSetupColumn title="PPU",
46
47 TableHeadersRow,
48 TableNextColumn,
49
50 CollapsingHeader id="cpuState" title="Register Values" flags="DefaultOpen" {
51 BeginChild id="##CpuState" size="0,100" flags="NoMove|NoScrollbar" {
52 Columns id="registersColumns" count="2" {
53 Text text="A: 0x%04X" data="cpu.A",
54 Text text="D: 0x%04X" data="cpu.D",
55 Text text="X: 0x%04X" data="cpu.X",
56 Text text="DB: 0x%02X" data="cpu.DB",
57 Text text="Y: 0x%04X" data="cpu.Y",
58 Text text="PB: 0x%02X" data="cpu.PB",
59 Text text="PC: 0x%04X" data="cpu.PC",
60 Text text="PS: 0x%02X" data="cpu.status",
61 Text text="SP: 0x%02X" data="cpu.SP",
62 Text text="Cycle: %d" data="snes.cycle_count",
63 }
64 }
65 }
66 CollapsingHeader id="spcState" title="SPC Registers" flags="DefaultOpen" {
67 BeginChild id="##SpcState" size="0,100" flags="NoMove|NoScrollbar" {
68 Columns id="spcRegistersColumns" count="2" {
69 Text text="A: 0x%02X" data="spc.A",
70 Text text="PC: 0x%04X" data="spc.PC",
71 Text text="X: 0x%02X" data="spc.X",
72 Text text="SP: 0x%02X" data="spc.SP",
73 Text text="Y: 0x%02X" data="spc.Y",
74 Text text="PSW: 0x%02X" data="spc.PSW",
75 }
76 }
77 }
78 Function id="CpuInstructionLog",
79
80 TableNextColumn,
81 Function id="SnesPpu",
82 Function id="BreakpointList"
83 }
84 )";
85 const std::map<std::string, void*> data_bindings = {
86 {"cpu.A", &snes_.cpu().A},
87 {"cpu.D", &snes_.cpu().D},
88 {"cpu.X", &snes_.cpu().X},
89 {"cpu.DB", &snes_.cpu().DB},
90 {"cpu.Y", &snes_.cpu().Y},
91 {"cpu.PB", &snes_.cpu().PB},
92 {"cpu.PC", &snes_.cpu().PC},
93 {"cpu.status", &snes_.cpu().status},
94 {"snes.cycle_count", &snes_.mutable_cycles()},
95 {"cpu.SP", &snes_.Memory().mutable_sp()},
96 {"spc.A", &snes_.apu().spc700().A},
97 {"spc.X", &snes_.apu().spc700().X},
98 {"spc.Y", &snes_.apu().spc700().Y},
99 {"spc.PC", &snes_.apu().spc700().PC},
100 {"spc.SP", &snes_.apu().spc700().SP},
101 {"spc.PSW", &snes_.apu().spc700().PSW}};
102 emulator_node_ = gui::zeml::Parse(emulator_layout, data_bindings);
103 Bind(emulator_node_.GetNode("CpuInstructionLog"),
104 [&]() { RenderCpuInstructionLog(snes_.cpu().instruction_log_); });
105 Bind(emulator_node_.GetNode("SnesPpu"), [&]() { RenderSnesPpu(); });
106 Bind(emulator_node_.GetNode("BreakpointList"),
107 [&]() { RenderBreakpointList(); });
108 }
109 void Run();
110
111 auto snes() -> Snes& { return snes_; }
112 auto running() const -> bool { return running_; }
113 void set_audio_buffer(int16_t* audio_buffer) { audio_buffer_ = audio_buffer; }
114 auto set_audio_device_id(SDL_AudioDeviceID audio_device) {
115 audio_device_ = audio_device;
116 }
117 auto wanted_samples() const -> int { return wanted_samples_; }
118
119 private:
120 void RenderNavBar();
121 void HandleEvents();
122
123 void RenderSnesPpu();
125 void RenderMemoryViewer();
126
127 struct Bookmark {
128 std::string name;
129 uint64_t value;
130 };
131 std::vector<Bookmark> bookmarks;
132
134 const std::vector<InstructionEntry>& instructionLog);
135
136 bool step_ = true;
137 bool power_ = false;
138 bool loading_ = false;
139 bool running_ = false;
140 bool turbo_mode_ = false;
141
144
145 uint8_t manual_pb_ = 0;
146 uint16_t manual_pc_ = 0;
147
148 // timing
150 uint64_t last_count;
151 float time_adder = 0.0;
152
154 SDL_AudioDeviceID audio_device_;
155
157 SDL_Texture* ppu_texture_;
158
159 std::vector<uint8_t> rom_data_;
160
162
164};
165
166} // namespace emu
167} // namespace yaze
168
169#endif // YAZE_APP_CORE_EMULATOR_H
SharedRom()=default
auto wanted_samples() const -> int
Definition emulator.h:117
SDL_Texture * ppu_texture_
Definition emulator.h:157
EmulatorKeybindings keybindings_
Definition emulator.h:161
gui::zeml::Node emulator_node_
Definition emulator.h:163
void set_audio_buffer(int16_t *audio_buffer)
Definition emulator.h:113
void RenderMemoryViewer()
Definition emulator.cc:420
uint64_t count_frequency
Definition emulator.h:149
std::vector< uint8_t > rom_data_
Definition emulator.h:159
auto set_audio_device_id(SDL_AudioDeviceID audio_device)
Definition emulator.h:114
void RenderBreakpointList()
Definition emulator.cc:358
uint64_t last_count
Definition emulator.h:150
std::vector< Bookmark > bookmarks
Definition emulator.h:131
SDL_AudioDeviceID audio_device_
Definition emulator.h:154
uint16_t manual_pc_
Definition emulator.h:146
void RenderCpuInstructionLog(const std::vector< InstructionEntry > &instructionLog)
Definition emulator.cc:503
auto snes() -> Snes &
Definition emulator.h:111
auto running() const -> bool
Definition emulator.h:112
int16_t * audio_buffer_
Definition emulator.h:153
SNES Emulation and debugging tools.
Definition apu.cc:13
Node Parse(const std::string &yazon_input, const std::map< std::string, void * > &data_bindings)
Parse a zeml string.
Definition zeml.cc:359
Main namespace for the application.
Definition controller.cc:18
Node for a zeml tree.
Definition zeml.h:124