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 "imgui/imgui.h"
5
6#include <cstdint>
7#include <vector>
8
9#include "app/emu/snes.h"
10#include "app/gui/zeml.h"
11#include "app/rom.h"
12
13namespace yaze {
14namespace app {
15
20namespace emu {
21
26class Emulator : public SharedRom {
27 public:
29 std::string emulator_layout = R"(
30 Table id="Emulator" count="2" flags="Resizable|ScrollY" {
31 TableSetupColumn title="CPU",
32 TableSetupColumn title="PPU",
33
34 TableHeadersRow,
35 TableNextColumn,
36
37 CollapsingHeader id="cpuState" title="Register Values" flags="DefaultOpen" {
38 BeginChild id="##CpuState" size="0,100" flags="NoMove|NoScrollbar" {
39 Columns id="registersColumns" count="2" {
40 Text text="A: 0x%04X" data="cpu.A",
41 Text text="D: 0x%04X" data="cpu.D",
42 Text text="X: 0x%04X" data="cpu.X",
43 Text text="DB: 0x%02X" data="cpu.DB",
44 Text text="Y: 0x%04X" data="cpu.Y",
45 Text text="PB: 0x%02X" data="cpu.PB",
46 Text text="PC: 0x%04X" data="cpu.PC",
47 Text text="PS: 0x%02X" data="cpu.status",
48 Text text="SP: 0x%02X" data="cpu.SP",
49 Text text="Cycle: %d" data="snes.cycle_count",
50 }
51 }
52 }
53 CollapsingHeader id="spcState" title="SPC Registers" flags="DefaultOpen" {
54 BeginChild id="##SpcState" size="0,100" flags="NoMove|NoScrollbar" {
55 Columns id="spcRegistersColumns" count="2" {
56 Text text="A: 0x%02X" data="spc.A",
57 Text text="PC: 0x%04X" data="spc.PC",
58 Text text="X: 0x%02X" data="spc.X",
59 Text text="SP: 0x%02X" data="spc.SP",
60 Text text="Y: 0x%02X" data="spc.Y",
61 Text text="PSW: 0x%02X" data="spc.PSW",
62 }
63 }
64 }
65 Function id="CpuInstructionLog",
66
67 TableNextColumn,
68 Function id="SnesPpu",
69 Function id="BreakpointList"
70 }
71 )";
72 const std::map<std::string, void*> data_bindings = {
73 {"cpu.A", &snes_.cpu().A},
74 {"cpu.D", &snes_.cpu().D},
75 {"cpu.X", &snes_.cpu().X},
76 {"cpu.DB", &snes_.cpu().DB},
77 {"cpu.Y", &snes_.cpu().Y},
78 {"cpu.PB", &snes_.cpu().PB},
79 {"cpu.PC", &snes_.cpu().PC},
80 {"cpu.status", &snes_.cpu().status},
81 {"snes.cycle_count", &snes_.mutable_cycles()},
82 {"cpu.SP", &snes_.Memory().mutable_sp()},
83 {"spc.A", &snes_.apu().spc700().A},
84 {"spc.X", &snes_.apu().spc700().X},
85 {"spc.Y", &snes_.apu().spc700().Y},
86 {"spc.PC", &snes_.apu().spc700().PC},
87 {"spc.SP", &snes_.apu().spc700().SP},
88 {"spc.PSW", &snes_.apu().spc700().PSW}};
89 emulator_node_ = gui::zeml::Parse(emulator_layout, data_bindings);
90 Bind(emulator_node_.GetNode("CpuInstructionLog"),
91 [&]() { RenderCpuInstructionLog(snes_.cpu().instruction_log_); });
92 Bind(emulator_node_.GetNode("SnesPpu"), [&]() { RenderSnesPpu(); });
93 Bind(emulator_node_.GetNode("BreakpointList"),
94 [&]() { RenderBreakpointList(); });
95 }
96 void Run();
97
98 auto snes() -> SNES& { return snes_; }
99 auto running() const -> bool { return running_; }
100 void set_audio_buffer(int16_t* audio_buffer) { audio_buffer_ = audio_buffer; }
101 auto set_audio_device_id(SDL_AudioDeviceID audio_device) {
102 audio_device_ = audio_device;
103 }
104 auto wanted_samples() const -> int { return wanted_samples_; }
105
106 private:
107 void RenderNavBar();
108 void HandleEvents();
109
110 void RenderSnesPpu();
112 void RenderMemoryViewer();
113
114 struct Bookmark {
115 std::string name;
116 uint64_t value;
117 };
118 std::vector<Bookmark> bookmarks;
119
121 const std::vector<InstructionEntry>& instructionLog);
122
123 bool step_ = true;
124 bool power_ = false;
125 bool loading_ = false;
126 bool running_ = false;
127 bool turbo_mode_ = false;
128
131
132 uint8_t manual_pb_ = 0;
133 uint16_t manual_pc_ = 0;
134
135 // timing
137 uint64_t last_count;
138 float time_adder = 0.0;
139
141 SDL_AudioDeviceID audio_device_;
142
144 SDL_Texture* ppu_texture_;
145
146 std::vector<uint8_t> rom_data_;
147
149};
150
151} // namespace emu
152} // namespace app
153} // namespace yaze
154
155#endif // YAZE_APP_CORE_EMULATOR_H
A class to hold a shared pointer to a Rom object.
Definition rom.h:585
A class for emulating and debugging SNES games.
Definition emulator.h:26
SDL_AudioDeviceID audio_device_
Definition emulator.h:141
std::vector< uint8_t > rom_data_
Definition emulator.h:146
std::vector< Bookmark > bookmarks
Definition emulator.h:118
void RenderCpuInstructionLog(const std::vector< InstructionEntry > &instructionLog)
Definition emulator.cc:411
void set_audio_buffer(int16_t *audio_buffer)
Definition emulator.h:100
auto set_audio_device_id(SDL_AudioDeviceID audio_device)
Definition emulator.h:101
gui::zeml::Node emulator_node_
Definition emulator.h:148
SDL_Texture * ppu_texture_
Definition emulator.h:144
auto running() const -> bool
Definition emulator.h:99
auto snes() -> SNES &
Definition emulator.h:98
auto wanted_samples() const -> int
Definition emulator.h:104
auto apu() -> audio::Apu &
Definition snes.h:72
auto Memory() -> memory::MemoryImpl &
Definition snes.h:73
auto mutable_cycles() -> uint64_t &
Definition snes.h:75
auto cpu() -> Cpu &
Definition snes.h:70
Node Parse(const std::string &yazon_input, const std::map< std::string, void * > &data_bindings)
Parse a zeml string.
Definition zeml.cc:361
Definition common.cc:21
Node for a zeml tree.
Definition zeml.h:127
Node * GetNode(const std::string &searchId)
Definition zeml.h:135