Properly reset emulator state on program start
This doesn't change anything functionally, it just makes the screen black before you load a ROM.
This commit is contained in:
parent
13af5fd62a
commit
76bff833b5
3 changed files with 32 additions and 28 deletions
28
src/emu.cpp
28
src/emu.cpp
|
@ -4,6 +4,34 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
void EmulatorState::reset() {
|
||||||
|
for (int i = 0; i < 4096; i++)
|
||||||
|
memory[i] = 0;
|
||||||
|
|
||||||
|
PC = program_begin;
|
||||||
|
|
||||||
|
for (int i = 0; i < 12; i++)
|
||||||
|
stack[i] = 0;
|
||||||
|
|
||||||
|
stack_pointer = 0;
|
||||||
|
|
||||||
|
I = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
v[i] = 0;
|
||||||
|
|
||||||
|
delay_timer = 0;
|
||||||
|
sound_timer = 0;
|
||||||
|
|
||||||
|
for (int y = 0; y < screen_height; y++) {
|
||||||
|
for (int x = 0; x < screen_width; x++) {
|
||||||
|
pixels[to_coord(x, y)] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
draw_dirty = true;
|
||||||
|
}
|
||||||
|
|
||||||
typedef void (*cpu_func)(const uint16_t opcode);
|
typedef void (*cpu_func)(const uint16_t opcode);
|
||||||
|
|
||||||
void null_func(const uint16_t opcode) {
|
void null_func(const uint16_t opcode) {
|
||||||
|
|
28
src/emu.hpp
28
src/emu.hpp
|
@ -13,33 +13,7 @@ inline int to_coord(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EmulatorState {
|
struct EmulatorState {
|
||||||
void reset() {
|
void reset();
|
||||||
for(int i = 0; i < 4096; i++)
|
|
||||||
memory[i] = 0;
|
|
||||||
|
|
||||||
PC = program_begin;
|
|
||||||
|
|
||||||
for(int i = 0; i < 12; i++)
|
|
||||||
stack[i] = 0;
|
|
||||||
|
|
||||||
stack_pointer = 0;
|
|
||||||
|
|
||||||
I = 0;
|
|
||||||
|
|
||||||
for(int i = 0; i < 16; i++)
|
|
||||||
v[i] = 0;
|
|
||||||
|
|
||||||
delay_timer = 0;
|
|
||||||
sound_timer = 0;
|
|
||||||
|
|
||||||
for(int y = 0; y < screen_height; y++) {
|
|
||||||
for(int x = 0; x < screen_width; x++) {
|
|
||||||
pixels[to_coord(x, y)] = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
draw_dirty = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t memory[4096] = {};
|
uint8_t memory[4096] = {};
|
||||||
uint16_t PC = program_begin;
|
uint16_t PC = program_begin;
|
||||||
|
|
|
@ -208,6 +208,8 @@ int main(int argc, char* argv[]) {
|
||||||
SDL_GL_MakeCurrent(window, gl_context);
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
SDL_GL_SetSwapInterval(1);
|
SDL_GL_SetSwapInterval(1);
|
||||||
|
|
||||||
|
state.reset();
|
||||||
|
|
||||||
gladLoadGL();
|
gladLoadGL();
|
||||||
setup_gfx();
|
setup_gfx();
|
||||||
|
|
||||||
|
|
Reference in a new issue