From 93fc21a61ee772b2b39f83b4423180c06e51498c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jo=C3=A3o=20Magalh=C3=A3es?= <joamag@gmail.com>
Date: Tue, 25 Apr 2023 09:44:26 +0100
Subject: [PATCH] chore: more secure options

---
 frontends/sdl/README.md | 12 ++++++------
 src/rom.rs              |  6 ++++++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/frontends/sdl/README.md b/frontends/sdl/README.md
index efa465e9..0cd39b9b 100644
--- a/frontends/sdl/README.md
+++ b/frontends/sdl/README.md
@@ -32,9 +32,9 @@ cargo run --features debug
 
 ## Features
 
-| Provider | Description                                                                                       |
-| -------- | ------------------------------------------------------------------------------------------------- |
-| `debug`  | Activates the base `debug` feature from Boytacean.                                                |
-| `secure` | Additional safety instructions are executed to make sure the machine does no run "out of tracks". |
-| `slow`   | Runs the emulator at a very slow page 60x slower to allow visual debugging.                       |
-| `cpulog` | Prints a log of the CPU instruction executed.                                                     |
+| Provider | Description                                                                                                                                |
+| -------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
+| `debug`  | Activates the base `debug` feature from Boytacean.                                                                                         |
+| `secure` | Additional safety instructions are executed to make sure the machine does no run "out of tracks", making sure to run many `panic()` calls. |
+| `slow`   | Runs the emulator at a very slow page 60x slower to allow visual debugging.                                                                |
+| `cpulog` | Prints a log of the CPU instruction executed.                                                                                              |
diff --git a/src/rom.rs b/src/rom.rs
index bdad478d..46d32d04 100644
--- a/src/rom.rs
+++ b/src/rom.rs
@@ -601,6 +601,8 @@ pub static MBC1: Mbc = Mbc {
     },
     write_ram: |rom: &mut Cartridge, addr: u16, value: u8| {
         if !rom.ram_enabled {
+            #[cfg(feature = "secure")]
+            panic!("Attempt to write to ERAM while write protect is active");
             debugln!("Attempt to write to ERAM while write protect is active");
             return;
         }
@@ -657,6 +659,8 @@ pub static MBC3: Mbc = Mbc {
     },
     write_ram: |rom: &mut Cartridge, addr: u16, value: u8| {
         if !rom.ram_enabled {
+            #[cfg(feature = "secure")]
+            panic!("Attempt to write to ERAM while write protect is active");
             debugln!("Attempt to write to ERAM while write protect is active");
             return;
         }
@@ -709,6 +713,8 @@ pub static MBC5: Mbc = Mbc {
     },
     write_ram: |rom: &mut Cartridge, addr: u16, value: u8| {
         if !rom.ram_enabled {
+            #[cfg(feature = "secure")]
+            panic!("Attempt to write to ERAM while write protect is active");
             debugln!("Attempt to write to ERAM while write protect is active");
             return;
         }
-- 
GitLab