 let joy_state_right = false;
 
 def joy_reset() {
-  joy_sel_button = false;
-  joy_sel_direction = false;
+  joy_sel_button = true;
+  joy_sel_direction = true;
 
   joy_state_start = false;
   joy_state_sel = false;

}

def gpu_render_scanline() {
  // if not gpu_lcd_enable {
  //   return;
  // }

  // if gpu_window_enable {
  //   printf("WINDOW IS ENABLED\n");
  // }

  if not gpu_bg_enable {
    // Background not enabled
    // FIXME: Should we do anything special here?

    return;
  }

  // Line (to be rendered)
  // With a high SCY value, the line wraps around
  let line = (int64(gpu_line) + int64(gpu_scy)) & 0xFF;

  // Tile Map (Offset)
  // The tile map is 32x32 (1024 bytes) and is an index into the tile data
  // A single tile map cell corresponds to an 8x8 cell in the framebuffer
  //  map 0 ~ line 0..7
  //  map 31 ~ line 8..13
  let map: int64 = if (gpu_bg_tm_select) { 0x1C00; } else { 0x1800; };
  map += (line >> 3) << 5;

  let i: int64 = 0;
  let x = gpu_scx % 8;
  let offset = int64(gpu_scx) >> 3;
  let y = line % 8;

  let i = 0;
  while i < 160 {
    if (x == 8) {
      // New Tile
      x = 0;
      offset = (offset + 1) % 32;
    }

    // Tile Map
    let tile: int16;
    if gpu_td_select {
      tile = int16(*(vram + map + offset));
    } else {
      tile = int16(int8(*(vram + map + offset))) + 256;
    }

    // Tile Data
    // tile = 0;
    let td_address: int16 = tile * 16 + int16(y) * 2;

    // Make a bitmask for the pixel being rendered
    let pixel_mask = 0x80 >> (x % 8);

    // Check the color bits for that pixel
    let palette_lo = if *(vram + td_address) & pixel_mask != 0 { 1; } else { 0; };
    let palette_hi = if *(vram + td_address + 1) & pixel_mask != 0 { 1; } else { 0; };

    // Combine them into a single index from 0 to 3
    let palette_index = uint8((palette_hi << 1) | palette_lo);

    // Palette
    let color = (gpu_palette >> (palette_index * 2)) & 0x3;

    // Push pixel to framebuffer
    *(gpu_framebuffer + (int64(gpu_line) * 160) + i) = color;

    x += 1;
    i += 1;
  }
}


  } else if address == 0xFF47 {
    // BGP – Background Palette (R/W)
    return gpu_palette;
  } else if address == 0xFF4A {
    // WY – Window Y Position (R/W)
    return gpu_wy;
  } else if address == 0xFF4B {
    // WX – Window X Position (R/W)
    return gpu_wx;
  } else if address == 0xFF48 {
    // OBP0 - Object Palette 0 Data (R/W)
    return gpu_obj0_palette;
  } else if address == 0xFF49 {
    // OBP1 - Object Palette 1 Data (R/W)
    return gpu_obj1_palette;
  }

  printf("warn: unhandled read from GPU register: $%04X\n", address);
