     free(rom);
   }
 
+  // Free External ROM (if needed)
+  if eram != 0 as *uint8 {
+    free(eram);
+  }
+
   // Allocate space in ROM
   rom = malloc(length);
 
   // Read file into ROM
   fread(rom, 1, length, stream);
-}
-
-def dump_rom() {
-  // Gather ROM information
-  // Title
-  let rom_title = malloc(16) as str;
-  strncpy(rom_title, (rom + 0x134) as str, 16);
-
-  // Licensee
-  let licensee = *(rom + 0x14B);
-  if licensee == 0x33 {
-    let licensee_0 = *(rom + 0x0144);
-    let licensee_1 = *(rom + 0x0145);
-
-    printf("warn: unexpected (new) licensee code: %02X %02X\n", licensee_0, licensee_1);
-  }
-
-  // CGB Flag
-  let cgb_mode = *(rom + 0x143);
-
-  // SGB Flag
-  let is_sgb = *(rom + 0x146) == 0x03;
-
-  // Cartridge Type
-  let cart = *(rom + 0x147);
-
-  // ROM Size
-  let rom_size = (32 * 1024) << *(rom + 0x148);
-
-  // External RAM Size
+
+  // Allocate space in external RAM
+  let eram_size = rom_get_ext_ram_size();
+  if eram_size > 0 {
+    eram = malloc(size_t(eram_size));
+
+    // Zero out space
+    memset(eram, 0, size_t(eram_size));
+  }
+}
+
+def rom_get_ext_ram_size(): uint16 {
   let ext_ram_size_code = *(rom + 0x149);
-  let ext_ram_size = (if ext_ram_size_code == 0x01 {
+
+  return (if ext_ram_size_code == 0x01 {
     2;
   } else if ext_ram_size_code == 0x02 {
     8;

  } else {
    0;
  }) * 1024;

  // Destination Code
  let dst_code = *(rom + 0x014A);

let wram: *uint8;   // Work RAM – 8 KiB
let oam: *uint8;    // Sprite Attribute Table (OAM) – 160 B
let hram: *uint8;   // High RAM – 127 B
let eram: *uint8;   // External RAM – (defined by cart)

// CPU: State
let is_running = true;
