helpy stuff

This commit is contained in:
Robin Hübner 2018-09-30 22:35:23 +02:00
parent 5be7d9ce1a
commit eb72ec39d8
1 changed files with 12 additions and 2 deletions

View File

@ -397,7 +397,7 @@ struct Chip8Status {
import std.file : read; import std.file : read;
auto buf = read("programs/sqrt.ch8"); auto buf = read("programs/chip8_picture.ch8");
emu_.load(0x200, buf); // do ze load yes, will copy all the data in emu_.load(0x200, buf); // do ze load yes, will copy all the data in
} // loadShortcut } // loadShortcut
@ -602,6 +602,7 @@ struct Chip8 {
bool run_flag; bool run_flag;
bool draw_flag; bool draw_flag;
bool reset_flag;
void load(size_t offset, in void[] data) { void load(size_t offset, in void[] data) {
@ -613,6 +614,8 @@ struct Chip8 {
void reset() { void reset() {
reset_flag = true;
cpu = cpu.init; cpu = cpu.init;
stack = stack.init; stack = stack.init;
ram[0x200 .. $ - 1] = 0; ram[0x200 .. $ - 1] = 0;
@ -629,6 +632,12 @@ struct Chip8 {
void step() { void step() {
// reset if we go OOB
if (cpu.pc >= 0xFFF) {
reset();
return;
}
cpu.opcode = ram[cpu.pc] << 8 | ram[cpu.pc + 1]; cpu.opcode = ram[cpu.pc] << 8 | ram[cpu.pc + 1];
ushort pc_target = cast(ProgramCounter)(cpu.pc + 2u); ushort pc_target = cast(ProgramCounter)(cpu.pc + 2u);
@ -1084,7 +1093,8 @@ struct Emulator {
int w, h; int w, h;
window.windowSize(w, h); window.windowSize(w, h);
if (emu.draw_flag) { if (emu.draw_flag || emu.reset_flag) {
if (emu.reset_flag) emu.reset_flag = false;
buf.update(emu.screen_buf); buf.update(emu.screen_buf);
emu.draw_flag = false; emu.draw_flag = false;
} }