👾 令和時代のゲームボーイ開発

011714704c4a925e542d426d4cdaa4e3?s=47 giginet
September 07, 2019

👾 令和時代のゲームボーイ開発

011714704c4a925e542d426d4cdaa4e3?s=128

giginet

September 07, 2019
Tweet

Transcript

  1. @giginet

  2. None
  3. ྩ࿨࣌୅ͷ ήʔϜϘʔΠ։ൃ

  4. Game boy • 1989೥ൃച • Z80ϕʔεͷCPUʢශऑʣ Z80(CPU) https://ja.wikipedia.org/wiki/Z80

  5. update_game:: ld HL, READ_INPUT ld A, [HL] cp $00 jr

    nz, .continue_update_1 call read_joypad .continue_update_1: call pipes_update call player_update call player_set_position call pipes_set_position ld HL, FADE_IN_ACTIVE ld A, [HL] cp $00 jr z, .call_fade_in cp $02 jr z, .call_fade_out jr .call_parallax .call_fade_in: call fade_in jr .call_parallax .call_fade_out:
  6. update_game:: ld HL, READ_INPUT ld A, [HL] cp $00 jr

    nz, .continue_update_1 call read_joypad .continue_update_1: call pipes_update call player_update call player_set_position call pipes_set_position ld HL, FADE_IN_ACTIVE ld A, [HL] cp $00 jr z, .call_fade_in cp $02 jr z, .call_fade_out jr .call_parallax .call_fade_in: call fade_in jr .call_parallax .call_fade_out:
  7. GBDK • GBDK(Game boy Development Kit) • http://gbdk.sourceforge.net/ • ήʔϜϘʔΠͷήʔϜΛCݴޠͰྑ͍ײ͡ʹ࡞Ε

    Δ΍ͭ • macOSͰಈ͘Α͏ʹforkͨ͠΍ͭ giginet/GBDK
  8. #include <gb/gb.h> #include <stdio.h> unsigned char pixels[] = {255, 255,

    195, 189, 189, 195, 189, 195, 189, 195, 189, 195, 195, 189, 255, 255}; int main() { int x = 100, y = 100; SPRITES_8x8; set_sprite_data(0, 8, pixels); set_sprite_tile(0, 0); move_sprite(0, x, y); SHOW_SPRITES; while(1) { if(joypad() & J_RIGHT) move_sprite(0, ++x, y); if(joypad() & J_LEFT) move_sprite(0, --x, y); if(joypad() & J_UP) move_sprite(0, x, --y); if(joypad() & J_DOWN) move_sprite(0, x, ++y); delay(10); } return 0; } ඳը ϝΠϯϧʔϓ ը૾σʔλ
  9. GBDK $ lcc -o rom game.gb

  10. None
  11. None
  12. giginet/docker-gbdk $ docker pull giginet/gbdk $ docker run -it --rm

    -v `pwd`:/gbdk giginet/gbdk /opt/gbdk/bin/lcc -o / gbdk/rom.gb /gbdk/game.c $ open rom.gb
  13. None
  14. 0x00 0x01 0x10 0x11

  15. 0x00 0x01 0x10 0x11 8px 8px

  16. 0x00 0x01 0x10 0x11 00 11 11 01 11 01

    11 01 0b01111111 0x7f 0x6a 0b01101010 0 1 1 1 1 1 1 1 0 1 1 0 1 0 1 0
  17. 8px 8px

  18. unsigned char giginyan[] = {255, 255, 254, 254, 252, 253,

    252, 253, 254, 253, 254, 253, 254, 253, 255, 254...
  19. use image::RgbaImage; use std::vec; use crate::sprite::{Sprite, Pixel}; use crate::chopper::Chopper; fn

    load_sprite(image: &RgbaImage) -> Sprite { let width = image.width(); let height = image.height(); let pixels = (0..width).map( |x| { return (0..height).map( |y| { let raw_pixel = image.get_pixel(x, y); return Pixel::from_raw(raw_pixel.data); }) .collect::<Vec<Pixel>>(); }) .collect::<Vec<Vec<Pixel>>>(); return Sprite { pixels: pixels }; } fn squash(chunk: &Vec<&Pixel>) -> [u8; 2] { fn clamp(i: u8) -> u8 { if i > 0 { return 1; } return 0; giginet/gb-sprite-generator
  20. giginet/gb-sprite-generator $ cargo run ./assets >1 pixels.h

  21. giginet/gb-sprite-generator unsigned char player[] = {255, 255, 254, 254, 252,

    253, 252, 253, 254, 253, 254, 253, 254, 253, 255, 254... unsigned char bullet[] = {255, 255, 195, 189, 189, 195, 189, 195, 189, 195, 189, 195, 195, 189, 255, 255};
  22. SPRITES_8x8; // ϐΫηϧσʔλΛఆٛ set_sprite_data(0, 8, giginyan); set_sprite_tile(0, 0); // ը૾Λඳը

    move_sprite(0, 100, 100); SHOW_SPRITES;
  23. None
  24. None
  25. None
  26. None
  27. None
  28. None
  29. None
  30. mikeryan/ems-flasher $ ems-flasher --write rom.gb

  31. None
  32. ❌ ❌

  33. giginet/modern-gb

  34. ͝ਗ਼ௌ ͋Γ͕ͱ͏͍͟͝·ͨ͠