 }
 
 def reset() {
+  joy_reset();
+  gpu_reset();
   cpu_reset();
-  gpu_reset();
 }
 
 def fini() {

let joy_sel_direction = false;

// 1 - Pressed
let joy_state_start = false;
let joy_state_sel = false;
let joy_state_a = false;
let joy_state_b = false;
let joy_state_up = false;

  } else if address == 0xFF47 {
    // BGP – Background Palette (R/W)
    gpu_palette = value;
  } else if address == 0xFF4A {
    // WY – Window Y Position (R/W)
    gpu_wy = value;
  } else if address == 0xFF4B {
    // WX – Window X Position (R/W)
    gpu_wx = value;
  } else if address == 0xFF46 {
    // DMA - DMA Transfer and Start Address (W)

    // FIXME: This is supposed to take 160 × 4 + 4 cycles to complete
    //        4 cycles to begin with 4 cycles per write/read (transfer)

    let src = uint16(value) << 8;
    if src >= 0x8000 and src < 0xE000 {
      let i: uint16 = 0;
      while i < 0xA0 {
        mmu_write8(0xFE00 + i, mmu_read8(src + i));

        i += 1;
      }
    }
  } else if address == 0xFF48 {
    // OBP0 - Object Palette 0 Data (R/W)
    gpu_obj0_palette = value;
  } else if address == 0xFF49 {
    // OBP1 - Object Palette 1 Data (R/W)
    gpu_obj1_palette = value;
  } else {
    printf("warn: unhandled write to GPU register: $%04X ($%02X)\n",
      address, value);
