From eb72ec39d84b6dea1231dec70f83d2ff97375098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20H=C3=BCbner?= Date: Sun, 30 Sep 2018 22:35:23 +0200 Subject: [PATCH] helpy stuff --- source/app.d | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/source/app.d b/source/app.d index 26643ba..d64fa55 100644 --- a/source/app.d +++ b/source/app.d @@ -397,7 +397,7 @@ struct Chip8Status { 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 } // loadShortcut @@ -602,6 +602,7 @@ struct Chip8 { bool run_flag; bool draw_flag; + bool reset_flag; void load(size_t offset, in void[] data) { @@ -612,6 +613,8 @@ struct Chip8 { } // load void reset() { + + reset_flag = true; cpu = cpu.init; stack = stack.init; @@ -629,6 +632,12 @@ struct Chip8 { void step() { + // reset if we go OOB + if (cpu.pc >= 0xFFF) { + reset(); + return; + } + cpu.opcode = ram[cpu.pc] << 8 | ram[cpu.pc + 1]; ushort pc_target = cast(ProgramCounter)(cpu.pc + 2u); @@ -1084,7 +1093,8 @@ struct Emulator { int 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); emu.draw_flag = false; }