Archived
1
Fork 0

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:
Joshua Goins 2022-03-29 22:07:04 -04:00
parent 13af5fd62a
commit 76bff833b5
3 changed files with 32 additions and 28 deletions

View file

@ -4,6 +4,34 @@
#include <iostream>
#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);
void null_func(const uint16_t opcode) {

View file

@ -13,33 +13,7 @@ inline int to_coord(int x, int y) {
}
struct EmulatorState {
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;
}
void reset();
uint8_t memory[4096] = {};
uint16_t PC = program_begin;

View file

@ -208,6 +208,8 @@ int main(int argc, char* argv[]) {
SDL_GL_MakeCurrent(window, gl_context);
SDL_GL_SetSwapInterval(1);
state.reset();
gladLoadGL();
setup_gfx();