match cpu registers on reset to hardware, cleanup
This commit is contained in:
@@ -21,8 +21,8 @@ void Cpu::Reset(bool hard) {
|
|||||||
PB = 0;
|
PB = 0;
|
||||||
D = 0;
|
D = 0;
|
||||||
DB = 0;
|
DB = 0;
|
||||||
E = 0;
|
E = 1;
|
||||||
status = 0;
|
status = 0x34;
|
||||||
irq_wanted_ = false;
|
irq_wanted_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,24 +34,6 @@ void Cpu::Reset(bool hard) {
|
|||||||
int_delay_ = false;
|
int_delay_ = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Cpu::Update(UpdateMode mode, int stepCount) {
|
|
||||||
int cycles = (mode == UpdateMode::Run) ? clock.GetCycleCount() : stepCount;
|
|
||||||
|
|
||||||
// Execute the calculated number of cycles
|
|
||||||
for (int i = 0; i < cycles; i++) {
|
|
||||||
if (IsBreakpoint(PC)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch and execute an instruction
|
|
||||||
ExecuteInstruction(ReadByte((PB << 16) + PC));
|
|
||||||
|
|
||||||
if (mode == UpdateMode::Step) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Cpu::RunOpcode() {
|
void Cpu::RunOpcode() {
|
||||||
if (reset_wanted_) {
|
if (reset_wanted_) {
|
||||||
reset_wanted_ = false;
|
reset_wanted_ = false;
|
||||||
|
|||||||
@@ -36,18 +36,12 @@ class InstructionEntry {
|
|||||||
std::string instruction; // Human-readable instruction text
|
std::string instruction; // Human-readable instruction text
|
||||||
};
|
};
|
||||||
|
|
||||||
const int kCpuClockSpeed = 21477272; // 21.477272 MHz
|
|
||||||
|
|
||||||
class Cpu : public Loggable, public core::ExperimentFlags {
|
class Cpu : public Loggable, public core::ExperimentFlags {
|
||||||
public:
|
public:
|
||||||
explicit Cpu(memory::Memory& mem, Clock& vclock,
|
explicit Cpu(memory::Memory& mem, Clock& vclock,
|
||||||
memory::CpuCallbacks& callbacks)
|
memory::CpuCallbacks& callbacks)
|
||||||
: memory(mem), clock(vclock), callbacks_(callbacks) {}
|
: memory(mem), clock(vclock), callbacks_(callbacks) {}
|
||||||
enum class UpdateMode { Run, Step, Pause };
|
|
||||||
|
|
||||||
void Init(bool verbose = false) { clock.SetFrequency(kCpuClockSpeed); }
|
|
||||||
void Reset(bool hard = false);
|
void Reset(bool hard = false);
|
||||||
void Update(UpdateMode mode = UpdateMode::Run, int stepCount = 1);
|
|
||||||
|
|
||||||
void RunOpcode();
|
void RunOpcode();
|
||||||
|
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ void Emulator::Run() {
|
|||||||
wanted_samples_ = 48000 / (snes_.Memory().pal_timing() ? 50 : 60);
|
wanted_samples_ = 48000 / (snes_.Memory().pal_timing() ? 50 : 60);
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
|
||||||
countFreq = SDL_GetPerformanceFrequency();
|
count_frequency = SDL_GetPerformanceFrequency();
|
||||||
lastCount = SDL_GetPerformanceCounter();
|
last_count = SDL_GetPerformanceCounter();
|
||||||
timeAdder = 0.0;
|
time_adder = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderNavBar();
|
RenderNavBar();
|
||||||
@@ -75,14 +75,14 @@ void Emulator::Run() {
|
|||||||
if (running_) {
|
if (running_) {
|
||||||
HandleEvents();
|
HandleEvents();
|
||||||
|
|
||||||
uint64_t curCount = SDL_GetPerformanceCounter();
|
uint64_t current_count = SDL_GetPerformanceCounter();
|
||||||
uint64_t delta = curCount - lastCount;
|
uint64_t delta = current_count - last_count;
|
||||||
lastCount = curCount;
|
last_count = current_count;
|
||||||
float seconds = delta / (float)countFreq;
|
float seconds = delta / (float)count_frequency;
|
||||||
timeAdder += seconds;
|
time_adder += seconds;
|
||||||
// allow 2 ms earlier, to prevent skipping due to being just below wanted
|
// allow 2 ms earlier, to prevent skipping due to being just below wanted
|
||||||
while (timeAdder >= wanted_frames_ - 0.002) {
|
while (time_adder >= wanted_frames_ - 0.002) {
|
||||||
timeAdder -= wanted_frames_;
|
time_adder -= wanted_frames_;
|
||||||
|
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
if (turbo_mode_) {
|
if (turbo_mode_) {
|
||||||
@@ -220,9 +220,9 @@ void Emulator::RenderNavBar() {
|
|||||||
|
|
||||||
// About Debugger logic
|
// About Debugger logic
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemHovered()) {
|
if (ImGui::IsItemHovered()) {
|
||||||
ImGui::SetTooltip("About Debugger");
|
ImGui::SetTooltip("About Debugger");
|
||||||
}
|
}
|
||||||
SameLine();
|
SameLine();
|
||||||
ImGui::Checkbox("Logging", snes_.cpu().mutable_log_instructions());
|
ImGui::Checkbox("Logging", snes_.cpu().mutable_log_instructions());
|
||||||
|
|
||||||
|
|||||||
@@ -133,9 +133,9 @@ class Emulator : public SharedRom {
|
|||||||
uint16_t manual_pc_ = 0;
|
uint16_t manual_pc_ = 0;
|
||||||
|
|
||||||
// timing
|
// timing
|
||||||
uint64_t countFreq;
|
uint64_t count_frequency;
|
||||||
uint64_t lastCount;
|
uint64_t last_count;
|
||||||
float timeAdder = 0.0;
|
float time_adder = 0.0;
|
||||||
|
|
||||||
int16_t* audio_buffer_;
|
int16_t* audio_buffer_;
|
||||||
SDL_AudioDeviceID audio_device_;
|
SDL_AudioDeviceID audio_device_;
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ uint8_t input_read(Input* input) {
|
|||||||
|
|
||||||
void SNES::Init(std::vector<uint8_t>& rom_data) {
|
void SNES::Init(std::vector<uint8_t>& rom_data) {
|
||||||
// Initialize the CPU, PPU, and APU
|
// Initialize the CPU, PPU, and APU
|
||||||
cpu_.Init();
|
|
||||||
ppu_.Init();
|
ppu_.Init();
|
||||||
apu_.Init();
|
apu_.Init();
|
||||||
|
|
||||||
|
|||||||
@@ -25,39 +25,6 @@ class PpuInterface {
|
|||||||
// Memory Interactions
|
// Memory Interactions
|
||||||
virtual void Write(uint16_t address, uint8_t data) = 0;
|
virtual void Write(uint16_t address, uint8_t data) = 0;
|
||||||
virtual uint8_t Read(uint16_t address) const = 0;
|
virtual uint8_t Read(uint16_t address) const = 0;
|
||||||
|
|
||||||
// Rendering Controls
|
|
||||||
virtual void RenderFrame() = 0;
|
|
||||||
virtual void RenderScanline() = 0;
|
|
||||||
virtual void RenderBackground(int layer) = 0;
|
|
||||||
virtual void RenderSprites() = 0;
|
|
||||||
|
|
||||||
// State Management
|
|
||||||
virtual void Init() = 0;
|
|
||||||
virtual void Reset() = 0;
|
|
||||||
virtual void Update(double deltaTime) = 0;
|
|
||||||
virtual void UpdateClock(double deltaTime) = 0;
|
|
||||||
virtual void UpdateInternalState(int cycles) = 0;
|
|
||||||
|
|
||||||
// Data Access
|
|
||||||
virtual const std::vector<uint8_t>& GetFrameBuffer() const = 0;
|
|
||||||
virtual std::shared_ptr<gfx::Bitmap> GetScreen() const = 0;
|
|
||||||
|
|
||||||
// Mode and Setting Updates
|
|
||||||
virtual void UpdateModeSettings() = 0;
|
|
||||||
virtual void UpdateTileData() = 0;
|
|
||||||
virtual void UpdateTileMapData() = 0;
|
|
||||||
virtual void UpdatePaletteData() = 0;
|
|
||||||
|
|
||||||
// Layer Composition
|
|
||||||
virtual void ApplyEffects() = 0;
|
|
||||||
virtual void ComposeLayers() = 0;
|
|
||||||
|
|
||||||
// Display Output
|
|
||||||
virtual void DisplayFrameBuffer() = 0;
|
|
||||||
|
|
||||||
// Notification (Observer pattern)
|
|
||||||
virtual void Notify(uint32_t address, uint8_t data) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Enum representing different background modes
|
// Enum representing different background modes
|
||||||
@@ -289,8 +256,6 @@ struct BackgroundLayer {
|
|||||||
bool enabled; // Whether the background layer is enabled
|
bool enabled; // Whether the background layer is enabled
|
||||||
};
|
};
|
||||||
|
|
||||||
const int kPpuClockSpeed = 5369318; // 5.369318 MHz
|
|
||||||
|
|
||||||
class Ppu : public SharedRom {
|
class Ppu : public SharedRom {
|
||||||
public:
|
public:
|
||||||
// Initializes the PPU with the necessary resources and dependencies
|
// Initializes the PPU with the necessary resources and dependencies
|
||||||
@@ -298,7 +263,6 @@ class Ppu : public SharedRom {
|
|||||||
|
|
||||||
// Initialize the frame buffer
|
// Initialize the frame buffer
|
||||||
void Init() {
|
void Init() {
|
||||||
clock_.SetFrequency(kPpuClockSpeed);
|
|
||||||
frame_buffer_.resize(256 * 240, 0);
|
frame_buffer_.resize(256 * 240, 0);
|
||||||
pixelOutputFormat = 1;
|
pixelOutputFormat = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user