yaze 0.2.0
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 {
13namespace app {
14
19namespace emu {
20
21// case SDLK_z:
22// editor.emulator().snes().SetButtonState(1, 0, false);
23// case SDLK_a:
24// editor.emulator().snes().SetButtonState(1, 1, false);
25// case SDLK_RSHIFT:
26// editor.emulator().snes().SetButtonState(1, 2, false);
27// case SDLK_RETURN:
28// editor.emulator().snes().SetButtonState(1, 3, false);
29// case SDLK_UP:
30// editor.emulator().snes().SetButtonState(1, 4, false);
31// case SDLK_DOWN:
32// editor.emulator().snes().SetButtonState(1, 5, false);
33// case SDLK_LEFT:
34// editor.emulator().snes().SetButtonState(1, 6, false);
35// case SDLK_RIGHT:
36// editor.emulator().snes().SetButtonState(1, 7, false);
37// case SDLK_x:
38// editor.emulator().snes().SetButtonState(1, 8, false);
39// case SDLK_s:
40// editor.emulator().snes().SetButtonState(1, 9, false);
41// case SDLK_d:
42// editor.emulator().snes().SetButtonState(1, 10, false);
43// case SDLK_c:
44// editor.emulator().snes().SetButtonState(1, 11, false);
45
47 ImGuiKey a_button = ImGuiKey_Z;
48 ImGuiKey b_button = ImGuiKey_A;
49 ImGuiKey x_button = ImGuiKey_S;
50 ImGuiKey y_button = ImGuiKey_X;
51 ImGuiKey l_button = ImGuiKey_Q;
52 ImGuiKey r_button = ImGuiKey_W;
53 ImGuiKey start_button = ImGuiKey_Enter;
54 ImGuiKey select_button = ImGuiKey_Backspace;
55 ImGuiKey up_button = ImGuiKey_UpArrow;
56 ImGuiKey down_button = ImGuiKey_DownArrow;
57 ImGuiKey left_button = ImGuiKey_LeftArrow;
58 ImGuiKey right_button = ImGuiKey_RightArrow;
59};
60
65class Emulator : public SharedRom {
66 public:
68 std::string emulator_layout = R"(
69 Table id="Emulator" count="2" flags="Resizable|ScrollY" {
70 TableSetupColumn title="CPU",
71 TableSetupColumn title="PPU",
72
73 TableHeadersRow,
74 TableNextColumn,
75
76 CollapsingHeader id="cpuState" title="Register Values" flags="DefaultOpen" {
77 BeginChild id="##CpuState" size="0,100" flags="NoMove|NoScrollbar" {
78 Columns id="registersColumns" count="2" {
79 Text text="A: 0x%04X" data="cpu.A",
80 Text text="D: 0x%04X" data="cpu.D",
81 Text text="X: 0x%04X" data="cpu.X",
82 Text text="DB: 0x%02X" data="cpu.DB",
83 Text text="Y: 0x%04X" data="cpu.Y",
84 Text text="PB: 0x%02X" data="cpu.PB",
85 Text text="PC: 0x%04X" data="cpu.PC",
86 Text text="PS: 0x%02X" data="cpu.status",
87 Text text="SP: 0x%02X" data="cpu.SP",
88 Text text="Cycle: %d" data="snes.cycle_count",
89 }
90 }
91 }
92 CollapsingHeader id="spcState" title="SPC Registers" flags="DefaultOpen" {
93 BeginChild id="##SpcState" size="0,100" flags="NoMove|NoScrollbar" {
94 Columns id="spcRegistersColumns" count="2" {
95 Text text="A: 0x%02X" data="spc.A",
96 Text text="PC: 0x%04X" data="spc.PC",
97 Text text="X: 0x%02X" data="spc.X",
98 Text text="SP: 0x%02X" data="spc.SP",
99 Text text="Y: 0x%02X" data="spc.Y",
100 Text text="PSW: 0x%02X" data="spc.PSW",
101 }
102 }
103 }
104 Function id="CpuInstructionLog",
105
106 TableNextColumn,
107 Function id="SnesPpu",
108 Function id="BreakpointList"
109 }
110 )";
111 const std::map<std::string, void*> data_bindings = {
112 {"cpu.A", &snes_.cpu().A},
113 {"cpu.D", &snes_.cpu().D},
114 {"cpu.X", &snes_.cpu().X},
115 {"cpu.DB", &snes_.cpu().DB},
116 {"cpu.Y", &snes_.cpu().Y},
117 {"cpu.PB", &snes_.cpu().PB},
118 {"cpu.PC", &snes_.cpu().PC},
119 {"cpu.status", &snes_.cpu().status},
120 {"snes.cycle_count", &snes_.mutable_cycles()},
121 {"cpu.SP", &snes_.Memory().mutable_sp()},
122 {"spc.A", &snes_.apu().spc700().A},
123 {"spc.X", &snes_.apu().spc700().X},
124 {"spc.Y", &snes_.apu().spc700().Y},
125 {"spc.PC", &snes_.apu().spc700().PC},
126 {"spc.SP", &snes_.apu().spc700().SP},
127 {"spc.PSW", &snes_.apu().spc700().PSW}};
128 emulator_node_ = gui::zeml::Parse(emulator_layout, data_bindings);
129 Bind(emulator_node_.GetNode("CpuInstructionLog"),
130 [&]() { RenderCpuInstructionLog(snes_.cpu().instruction_log_); });
131 Bind(emulator_node_.GetNode("SnesPpu"), [&]() { RenderSnesPpu(); });
132 Bind(emulator_node_.GetNode("BreakpointList"),
133 [&]() { RenderBreakpointList(); });
134 }
135 void Run();
136
137 auto snes() -> SNES& { return snes_; }
138 auto running() const -> bool { return running_; }
139 void set_audio_buffer(int16_t* audio_buffer) { audio_buffer_ = audio_buffer; }
140 auto set_audio_device_id(SDL_AudioDeviceID audio_device) {
141 audio_device_ = audio_device;
142 }
143 auto wanted_samples() const -> int { return wanted_samples_; }
144
145 private:
146 void RenderNavBar();
147 void HandleEvents();
148
149 void RenderSnesPpu();
151 void RenderMemoryViewer();
152
153 struct Bookmark {
154 std::string name;
155 uint64_t value;
156 };
157 std::vector<Bookmark> bookmarks;
158
160 const std::vector<InstructionEntry>& instructionLog);
161
162 bool step_ = true;
163 bool power_ = false;
164 bool loading_ = false;
165 bool running_ = false;
166 bool turbo_mode_ = false;
167
170
171 uint8_t manual_pb_ = 0;
172 uint16_t manual_pc_ = 0;
173
174 // timing
176 uint64_t last_count;
177 float time_adder = 0.0;
178
180 SDL_AudioDeviceID audio_device_;
181
183 SDL_Texture* ppu_texture_;
184
185 std::vector<uint8_t> rom_data_;
186
188
190};
191
192} // namespace emu
193} // namespace app
194} // namespace yaze
195
196#endif // YAZE_APP_CORE_EMULATOR_H
A class to hold a shared pointer to a Rom object.
Definition rom.h:576
A class for emulating and debugging SNES games.
Definition emulator.h:65
SDL_AudioDeviceID audio_device_
Definition emulator.h:180
std::vector< uint8_t > rom_data_
Definition emulator.h:185
std::vector< Bookmark > bookmarks
Definition emulator.h:157
void RenderCpuInstructionLog(const std::vector< InstructionEntry > &instructionLog)
Definition emulator.cc:506
void set_audio_buffer(int16_t *audio_buffer)
Definition emulator.h:139
auto set_audio_device_id(SDL_AudioDeviceID audio_device)
Definition emulator.h:140
EmulatorKeybindings keybindings_
Definition emulator.h:187
gui::zeml::Node emulator_node_
Definition emulator.h:189
SDL_Texture * ppu_texture_
Definition emulator.h:183
auto running() const -> bool
Definition emulator.h:138
auto snes() -> SNES &
Definition emulator.h:137
auto wanted_samples() const -> int
Definition emulator.h:143
auto apu() -> audio::Apu &
Definition snes.h:71
auto Memory() -> memory::MemoryImpl &
Definition snes.h:72
auto mutable_cycles() -> uint64_t &
Definition snes.h:74
auto cpu() -> Cpu &
Definition snes.h:69
Node Parse(const std::string &yazon_input, const std::map< std::string, void * > &data_bindings)
Parse a zeml string.
Definition zeml.cc:360
Definition common.cc:22
Node for a zeml tree.
Definition zeml.h:125
Node * GetNode(const std::string &searchId)
Definition zeml.h:133