aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ahoy/emulator.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/ahoy/emulator.c b/src/ahoy/emulator.c
index cffc4a9..f774b54 100644
--- a/src/ahoy/emulator.c
+++ b/src/ahoy/emulator.c
@@ -66,6 +66,8 @@ emuinit(struct u8view prog, const char *fn)
void
emutick(void)
{
+ if ((size_t)c8.PC + 1 >= lengthof(mem))
+ diex("%s: attempted to read instruction beyond end of RAM", filename);
opexec((mem[c8.PC] << 8) | mem[c8.PC + 1]);
c8.PC += 2;
}
@@ -209,8 +211,10 @@ opexec(uint16_t op)
unsigned y = (op & 0x00F0) >> 4;
unsigned n = (op & 0x000F) >> 0;
+ if (c8.I + n > lengthof(mem))
+ diex("%s: attempted to draw sprite beyond bounds of RAM", filename);
+
for (unsigned i = 0; i < n; i++) {
- /* TODO: bounds check? */
uint8_t spr_row = mem[c8.I + i];
uint8_t scr_row = c8.V[y] + i;
uint64_t msk;