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

Bitbox console

Avatar for makapuf makapuf
January 19, 2018

Bitbox console

Avatar for makapuf

makapuf

January 19, 2018

Other Decks in Programming

Transcript

  1. Retrocoding Low level coding, direct hardware access 2D skills (code

    / art) Simple, yet challenging The game is … in making games! No OS, raw “speed” (no frameworks !)
  2. Consoles : specs Console CPU RAM Storage Graphics Openness PS4

    8x1,6 GHz 18x GPU 8 G 500GB+ BluRay 1080p50 nope RasPi 3 ARM v8 4x 1,2GHz VCore IV 1 G microSD 1080p30 Binary blob Complex to build Cannot source Parts Attiny Pong 16Mhz 128 2KB Tv 80x40 Open, single purpose NES 8bit 6502 1.79 MHz 2k 32-1024 kB carts 256x224 56colors tiles/sprites Completely known now legality Antique / extra flash carts Emulators UzeBox 8bit AVR 28MHz 4k 64k flash SD card 256x224 all software Open / DIY Emulator SNES 16bits 3.5MHz 192k carts 240x224 (tv) 32k cols Completely known now Antique / extra flash cards legality Emulators Bitbox 32b ARM 168MHz 192k 1MB flash microsd 640x480 (800x600) 15k colors openHW / GPL / simple to build
  3. One standard chip no FPGA (expensive) ← not anymore, opening

    (still hard) no external RAM / Flash as cheap as possible simply sourceable Current / known interfaces Off the shelf peripherals, Languages, Compilers Current connectors & components DIY OK for double sided PCB and surface mount Doable by an individual in his basement (no BGA) Goals : DIY Hardware
  4. Community • Presentation at FOSDEM (3x), Capitole du libre, ...

    • 8 contributors (GitHub), many contributed programs ! • DIY bitboxes • Documentation : improved Wiki – Central Software list • + 10 games + 3 public WIP + 1 emulator + 3D demos / engines + 2 music programs + other programs …
  5. Micro controller STM32 F405 • STM32F405VGT6 from ST Microelectronics –

    STM32 : 32-bit ARM – DMA , Timers, GPIO, DAC – SDIO, USB, SWD debug port → low level HW interfaces available • Direct Signal Synthesis : – Write to a u16 location in memory : change DAC values (3*5 bits Video, 2*8bits Audio) – Toggle this at 32kHz (sound), 25MHz (VGA)
  6. Video Signals : color VGA (5 wires) Component YPbPr (3

    wires) PAL / SECAM / NTSC SVideo : Luma/ Chroma (2fils) Composite (1fil)
  7. The Bitbox hardware • Principles : Open, DIY, VGA Out,

    stm32, USB Power, all plugs on bitbox • 168MHz, 1024k Flash, 192k RAM • 640x480 (800x600) / 32k colors (15bpp) • Stereo sound • 2 USB host ports • 10-pin Extension port • 1 microSD slot • 5x6,5cm (32 cm²) • 60 components
  8. The Bitbox /2 • Same principles : VGA Out, stm32,

    USB Power, all plugs on bitbox • 168MHz, 1024k Flash, 192k RAM → 84MHz, 512k, 96k • 640x480 (800x600) / 32k colors (15bpp) → 320x240 (400x300) 256c (8bpp) • Stereo sound → mono • 2 → 1 USB host ports • 10-pin Extension port PWR + SPI/I2C/UART/SWD→ 6 (PWR+UART/SWD) • 1 microSD slot → (int)1/2=0 • 5x6,5cm (32 cm²) → 2,5 x 5cm (12,5cm² / 2sq. in.) • 60 components → 30 components half cost
  9. Programming • Program on PC – Program in standard C

    (not that complex !) – Compile – Compile emulator with SDL (test on PC!) – Load .bin to SD or write directly with USB cable – On-chip debugging with a $5 probe • Toolchain used : GCC / GDB arm-none-eabi-gcc – Compilers available on raw Linux ubuntu ubuntu , windows , haiku , mac : ✔ ✔ ✔ ✔
  10. Software stack the hardware. YOUR GAME (setup clock tree, DMA,

    GPIO, DAC + timers, SD+Fat filesystem, USB host protocol / HID report parsing * ) * Not always fun
  11. the full(er) Software Stack YOUR GAME the hardware. VGA USB

    Sound SDIO/FAT board init Libraries (no OS) included to simplify & concentrate on games. NIH syndrome : don’t use them !
  12. Kernel : bitbox.h SDK / API Small set of Low

    level drivers = a set of optional libraries No dependency, Open Source No specific algorithms (blitter, engine, mixer …) NOT an OS : one process, raw memory access. All programmed in C • Audio : snd_buffer(void *buffer) • Video : graph_line(void *line_buffer) • SD : FAT32 fatfs lib f_open, f_read… • USB HID : interface – Gamepad : u16 buttons[2] (1 bit/button) + u8 analog x/y – Mouse : int8 X,Y,buttons – Keyboard : u8 mod, char[6] keys
  13. Buffer modes • 640x480 16bpp > 600 k : too

    large ! – Reduce resolution (eg 320x240) → 170 k ! – Reduce color depth @8bpp → 70k \o/ • Usage : include lib/framebuffer.c/.h – Declare VGA_BPP + VGA_MODE in makefile – Write pixels to VRAM • Other mode : Text mode – Write letters to VRAM, kernel will write letters on screen – Usage : include textmode, define VGA_MODE + FONTSIZE – Also provides a font attribute array (each letter : bg/fg colors)
  14. Tiles and sprites • EVERY 2D 8bit and 16-bit game

    console hardware worked like that – NES, SNES, GB, GBA, Megadrive, NeoGeo ... • Sometimes coupled with different palettes per tile • Can store tilemap in ram (vram), tileset in flash (rom) • Allows large levels • Can couple the visual grid with logical grid
  15. Tiles and sprites Engine Composing a simple scene with a

    simple API different objects with render line func (in C) rectangles sprites (u16, c8, p4, rle) tilemaps (RAM and Flash) Stored in RAM or Flash Blit top down (z order) keeping track of blit progress Create tilemaps, tilesets, instanciate : from code ?
  16. Workflow • Draw tiles / spritesheets with GIMP • Compose

    levels with Tiled Map editor : – Tilemap – Tilesets, tile names and properties – Sprites references (sevral compression types : RLE, 16c, couples ...) – Sprites positions, Animations • Export to binary files + .c/.h data readable from engine / code with scripts • Compile in game (or load from SD to RAM) (add to GAME_BIN variable in makefile) • Create game logic (.c) : – obj=new_sprite (sprite_data, …) ; obj2=new_tmap(tset, tmap) – reference data from Flash with .h created (or load in ram) – move/animate objects by changing coordinates / frames – Write inside VRAM tilemaps, move them (Scrolling) – Make higher-level state machine (menu, in-level, intro, death animation ...)
  17. full motion video streaming uSD → buffer → screen lines

    1 frame stored compressed in RAM ! no interframe compression line decompression 7 cycles per pixel develop a new codec : btc4 256c palette 4x4 squares (16 pixels) : 2 colors/square (1bpp) 2 index u8 + 16 bits = 2bpp ! 640x360 = 57kB : in RAM ! python encoder, speed and quality can be improved Stream compression : reduces SD throughput
  18. Simplified workflow 1)Draw 256x256 BMP image with Gimp 2)Put on

    sd card 3)Play (platformer/shooter/runner/...) NO CODE ??
  19. Simplified workflow Draw 256x256 image with Gimp tileset 4 level

    tilemaps sprites Minimap : Terrain types, sprites, levels ... songs enemy types : animation, movement collision type, die action, alt collision ...