Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ファミコンエミュレータで ゲームプログラミング

ファミコンエミュレータで ゲームプログラミング

Presentation about how to paint a background on the famikon at Open Source UN conference 2018, KAWAGOE. It was a 5 minutes lightning talk. 2018/04/14

Daniel Sangorrin

April 14, 2018
Tweet

More Decks by Daniel Sangorrin

Other Decks in Technology

Transcript

  1. ファミコンエミュレータで
    ゲームプログラミング
    Daniel Sangorrin ( ダニエル )
    @daromart
    @daromart
    Open Source UN conference 2018
    KAWAGOE
    2018/04/14

    View full-size slide

  2. 6502 アセンブリ
    https://skilldrick.github.io/easy6502/

    View full-size slide

  3. WINE + FCEUX

    Fceux available in Linux

    But no debug functionality

    WINE to run the Win32 version
    $ sudo dpkg --add-architecture i386
    $ wget -nc https://dl.winehq.org/wine-builds/Release.key
    $ sudo apt-key add Release.key
    $ sudo apt-add-repository https://dl.winehq.org/wine-
    builds/ubuntu/
    $ sudo apt-get update
    $ sudo apt-get install --install-recommends winehq-stable
    [Alt] sudo apt-get install --install-recommends winehq-devel
    $ wine fceux xxx.nes

    View full-size slide

  4. cc65

    Install the cc65 compiler
    $ git clone https://github.com/cc65/cc65.git
    $ cd cc65
    $ make
    $ sudo porg -lp cc65 make install PREFIX=/usr
    $ porg -f cc65
    /usr/bin/*65
    /usr/share/cc65/*
    $ which cc65
    /usr/bin/cc65 <- C compiler
    $ which ca65
    /usr/bin/ca65 <- ASM compiler

    View full-size slide

  5. Hello World
    $ git clone https://github.com/cirla/nesdev.git
    $ cd nesdev
    $ git checkout hello_world
    $ ls
    reset.s: initialization of the NES
    hello_world.c: contains main called from reset.s
    hello_world.cfg: linker script (describes the CPU memory map used)
    sprites.chr: file with sprites (Bitmap ROM)
    $ make
    -> hello_world.nes
    $ wine fceux.exe hello_world.nes
    -> shows a hello world

    View full-size slide

  6. コードでいうと
    const unsigned char nametable[7*8]={
    0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    0x00,0x00,0x05,0x06,0x07,0x00,0x00,
    0x00,0x00,0x15,0x16,0x17,0x00,0x00,
    0x00,0x00,0x15,0x16,0x0b,0x00,0x00,
    0x00,0x00,0x15,0x16,0x17,0x00,0x00,
    0x00,0x00,0x15,0x16,0x17,0x00,0x00,
    0x00,0x14,0x14,0x14,0x14,0x14,0x00,
    0x00,0x00,0x00,0x00,0x00,0x00,0x00
    };

    View full-size slide

  7. UnRLE
    void Draw_Background(void) {
    PPU_ADDRESS = 0x20; // nametable 0 address (0x2000)
    PPU_ADDRESS = 0x00;
    UnRLE(N2); // uncompress
    }

    View full-size slide

  8. main
    void main (void) {
    PPU_CTRL = 0;
    PPU_MASK = 0;
    Draw_Background();
    PPU_ADDRESS = 0x3f;
    PPU_ADDRESS = 0x00;
    for( index = 0; index < sizeof(PALETTE); ++index ){
    PPU_DATA = PALETTE[index];
    }
    PPU_ADDRESS = 0;
    PPU_ADDRESS = 0;
    SCROLL = 0;
    SCROLL = 0;
    Wait_Vblank();
    PPU_CTRL = 0x90;
    PPU_MASK = 0x1e;
    while (1);
    }
    _Wait_Vblank:
    lda $2002
    bpl _Wait_Vblank
    rts

    View full-size slide

  9. References

    http://nesdev.com/

    http://hp.vector.co.jp/authors/VA042397/inde
    x.html

    https://nesdoug.com/

    https://en.wikibooks.org/wiki/6502_Assembl
    y

    https://timcheeseman.com/nesdev

    View full-size slide