yaze 0.3.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"
13#include "app/rom.h"
14
15namespace yaze {
16namespace gfx {
17class IRenderer;
18} // namespace gfx
19
24namespace emu {
25
26// REMOVED: EmulatorKeybindings (ImGuiKey-based)
27// Now using ui::InputHandler with SDL_GetKeyboardState() for proper continuous polling
28
33class Emulator {
34 public:
35 Emulator() = default;
36 ~Emulator();
37 void Initialize(gfx::IRenderer* renderer, const std::vector<uint8_t>& rom_data);
38 void Run(Rom* rom);
39 void Cleanup();
40
41 // Card visibility for emulator UI panels
46
47 auto snes() -> Snes& { return snes_; }
48 auto running() const -> bool { return running_; }
50
51 // Audio backend access
53 void set_audio_buffer(int16_t* audio_buffer) { audio_buffer_ = audio_buffer; }
54 auto set_audio_device_id(SDL_AudioDeviceID audio_device) {
55 audio_device_ = audio_device;
56 }
57 auto wanted_samples() const -> int { return wanted_samples_; }
59
60 // Render access
62 void* ppu_texture() { return ppu_texture_; }
63
64 // Turbo mode
65 bool is_turbo_mode() const { return turbo_mode_; }
66 void set_turbo_mode(bool turbo) { turbo_mode_ = turbo; }
67
68 // Debugger access
72 bool is_debugging() const { return debugging_; }
73 void set_debugging(bool debugging) { debugging_ = debugging; }
74 bool is_initialized() const { return initialized_; }
75 bool is_snes_initialized() const { return snes_initialized_; }
76
77 // AI Agent Integration API
78 bool IsEmulatorReady() const { return snes_.running() && !rom_data_.empty(); }
79 double GetCurrentFPS() const { return current_fps_; }
80 uint64_t GetCurrentCycle() { return snes_.mutable_cycles(); }
81 uint16_t GetCPUPC() { return snes_.cpu().PC; }
82 uint8_t GetCPUB() { return snes_.cpu().DB; }
83 void StepSingleInstruction() { snes_.cpu().RunOpcode(); }
84 void SetBreakpoint(uint32_t address) { snes_.cpu().SetBreakpoint(address); }
85 void ClearAllBreakpoints() { snes_.cpu().ClearBreakpoints(); }
86 std::vector<uint32_t> GetBreakpoints() { return snes_.cpu().GetBreakpoints(); }
87
88 // Performance monitoring for AI agents
90 double fps;
91 uint64_t cycles;
94 uint16_t cpu_pc;
95 uint8_t cpu_pb;
96 };
98 return {
100 .cycles = snes_.mutable_cycles(),
101 .audio_frames_queued = SDL_GetQueuedAudioSize(audio_device_) / (wanted_samples_ * 4),
102 .is_running = running_,
103 .cpu_pc = snes_.cpu().PC,
104 .cpu_pb = snes_.cpu().PB
105 };
106 }
107
108 private:
109 void RenderNavBar();
111
112 void RenderSnesPpu();
114 void RenderMemoryViewer();
117 void RenderAIAgentPanel();
118 void RenderSaveStates();
120 void RenderApuDebugger();
121
122 struct Bookmark {
123 std::string name;
124 uint64_t value;
125 };
126 std::vector<Bookmark> bookmarks;
127
129 const std::vector<InstructionEntry>& instructionLog);
130
131 bool step_ = true;
132 bool power_ = false;
133 bool loading_ = false;
134 bool running_ = false;
135 bool turbo_mode_ = false;
136
139
140 uint8_t manual_pb_ = 0;
141 uint16_t manual_pc_ = 0;
142
143 // timing
145 uint64_t last_count;
146 double time_adder = 0.0;
147
148 // FPS tracking
150 double fps_timer_ = 0.0;
151 double current_fps_ = 0.0;
152
154 SDL_AudioDeviceID audio_device_;
155
156 // Audio backend abstraction
157 std::unique_ptr<audio::IAudioBackend> audio_backend_;
158
160 bool initialized_ = false;
161 bool snes_initialized_ = false;
162 bool debugging_ = false;
164 void* ppu_texture_ = nullptr;
165
166 // Card visibility states
167 bool show_cpu_debugger_ = false;
169 bool show_ppu_viewer_ = false;
170 bool show_audio_mixer_ = false;
171
172 // Debugger infrastructure
175
176 std::vector<uint8_t> rom_data_;
177
178 // Input handling (abstracted for SDL2/SDL3/custom backends)
180};
181
182} // namespace emu
183} // namespace yaze
184
185#endif // YAZE_APP_CORE_EMULATOR_H
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:71
Manages CPU and SPC700 breakpoints for debugging.
A class for emulating and debugging SNES games.
Definition emulator.h:33
bool & show_ppu_viewer()
Definition emulator.h:44
gfx::IRenderer * renderer()
Definition emulator.h:61
void Initialize(gfx::IRenderer *renderer, const std::vector< uint8_t > &rom_data)
Definition emulator.cc:47
BreakpointManager & breakpoint_manager()
Definition emulator.h:69
void RenderModernCpuDebugger()
Definition emulator.cc:521
std::unique_ptr< audio::IAudioBackend > audio_backend_
Definition emulator.h:157
auto wanted_samples() const -> int
Definition emulator.h:57
bool is_debugging() const
Definition emulator.h:72
void set_turbo_mode(bool turbo)
Definition emulator.h:66
bool is_initialized() const
Definition emulator.h:74
void * ppu_texture()
Definition emulator.h:62
bool IsEmulatorReady() const
Definition emulator.h:78
bool & show_audio_mixer()
Definition emulator.h:45
double GetCurrentFPS() const
Definition emulator.h:79
void set_debugging(bool debugging)
Definition emulator.h:73
void set_audio_buffer(int16_t *audio_buffer)
Definition emulator.h:53
void RenderMemoryViewer()
Definition emulator.cc:516
void SetBreakpoint(uint32_t address)
Definition emulator.h:84
void set_renderer(gfx::IRenderer *renderer)
Definition emulator.h:58
uint64_t GetCurrentCycle()
Definition emulator.h:80
uint64_t count_frequency
Definition emulator.h:144
void RenderKeyboardConfig()
Definition emulator.cc:763
debug::DisassemblyViewer disassembly_viewer_
Definition emulator.h:174
void StepSingleInstruction()
Definition emulator.h:83
std::vector< uint8_t > rom_data_
Definition emulator.h:176
auto set_audio_device_id(SDL_AudioDeviceID audio_device)
Definition emulator.h:54
bool & show_memory_viewer()
Definition emulator.h:43
input::InputManager & input_manager()
Definition emulator.h:71
void RenderPerformanceMonitor()
Definition emulator.cc:737
bool is_turbo_mode() const
Definition emulator.h:65
debug::DisassemblyViewer & disassembly_viewer()
Definition emulator.h:70
void RenderAIAgentPanel()
Definition emulator.cc:742
void RenderBreakpointList()
Definition emulator.cc:511
BreakpointManager breakpoint_manager_
Definition emulator.h:173
uint64_t last_count
Definition emulator.h:145
std::vector< Bookmark > bookmarks
Definition emulator.h:126
input::InputManager input_manager_
Definition emulator.h:179
void set_running(bool running)
Definition emulator.h:49
uint16_t GetCPUPC()
Definition emulator.h:81
SDL_AudioDeviceID audio_device_
Definition emulator.h:154
bool is_snes_initialized() const
Definition emulator.h:75
bool & show_cpu_debugger()
Definition emulator.h:42
uint16_t manual_pc_
Definition emulator.h:141
void RenderCpuInstructionLog(const std::vector< InstructionEntry > &instructionLog)
Definition emulator.cc:747
void ClearAllBreakpoints()
Definition emulator.h:85
void Run(Rom *rom)
Definition emulator.cc:134
audio::IAudioBackend * audio_backend()
Definition emulator.h:52
auto snes() -> Snes &
Definition emulator.h:47
auto running() const -> bool
Definition emulator.h:48
uint8_t GetCPUB()
Definition emulator.h:82
void RenderEmulatorInterface()
Definition emulator.cc:347
EmulatorMetrics GetMetrics()
Definition emulator.h:97
int16_t * audio_buffer_
Definition emulator.h:153
gfx::IRenderer * renderer_
Definition emulator.h:163
std::vector< uint32_t > GetBreakpoints()
Definition emulator.h:86
auto mutable_cycles() -> uint64_t &
Definition snes.h:76
bool running() const
Definition snes.h:70
auto cpu() -> Cpu &
Definition snes.h:71
Abstract audio backend interface.
Advanced disassembly viewer with sparse storage and interactive features.
Defines an abstract interface for all rendering operations.
Definition irenderer.h:35
Main namespace for the application.