     gpu_sprite_size = testb(value, 2);
     gpu_sprite_enable = testb(value, 1);
     gpu_bg_enable = testb(value, 0);
+  } else if address == 0xFF42 {
+    // SCY – Scroll Y (R/W)
+    gpu_scy = value;
+  } else if address == 0xFF43 {
+    // SCX – Scroll X (R/W)
+    gpu_scx = value;
+  } else if address == 0xFF45 {
+    // LYC – LY Compare (R/W)
+    gpu_line_compare = value;
+  } else if address == 0xFF47 {
+    // BGP – Background Palette (R/W)
+    gpu_palette = value;
   } else {
     printf("warn: unhandled write to GPU register: $%04X ($%02X)\n",
       address, value);


def cpu_step(): uint8 {
  // IF HALT; just return 4 (cycles)
  if HALT {
    return 4;
  }

  // Get next opcode
  let opcode = mmu_next8();

  // Check if valid/known instruction
  if *((optable as *int64) + opcode) == 0 {


  // Move to the selected line (to be rendered) and scroll Y
  mapo += (((int64(gpu_line) + int64(gpu_scy)) & 255) >> 3) << 5;

  // Tile line offset (X-scrolling)
  let lineo = gpu_scx >> 3;
