Browse Source

Additional assertions for the return value of mmap_read8 and mmap_read16

Fabian 3 years ago
parent
commit
65a75d4fe3
1 changed files with 6 additions and 3 deletions
  1. 6 3
      src/memory.js

+ 6 - 3
src/memory.js

@@ -3,7 +3,9 @@
 
 CPU.prototype.mmap_read8 = function(addr)
 {
-    return this.memory_map_read8[addr >>> MMAP_BLOCK_BITS](addr);
+    const value = this.memory_map_read8[addr >>> MMAP_BLOCK_BITS](addr);
+    dbg_assert(value >= 0 && value <= 0xFF);
+    return value;
 };
 
 CPU.prototype.mmap_write8 = function(addr, value)
@@ -15,8 +17,9 @@ CPU.prototype.mmap_write8 = function(addr, value)
 CPU.prototype.mmap_read16 = function(addr)
 {
     var fn = this.memory_map_read8[addr >>> MMAP_BLOCK_BITS];
-
-    return fn(addr) | fn(addr + 1 | 0) << 8;
+    const value = fn(addr) | fn(addr + 1 | 0) << 8;
+    dbg_assert(value >= 0 && value <= 0xFFFF);
+    return value;
 };
 
 CPU.prototype.mmap_write16 = function(addr, value)