Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Nametable

Slide 9

Slide 9 text

コードでいうと 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 };

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

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