Skip to content

msinger/binutils-sm83

Repository files navigation

Binutils for GameBoy
====================


Build binutils like this:

  ./configure --target=sm83-gb-coff
  make all
  # as root:
  make install


Example file:

  ; Handler for RST28 instruction (max. 8 bytes)
  .section .rst28
    ret

  ; Handler for interrupt 4 (joypad) (max. 8 bytes)
  .section .irq4
    reti

  ; Entry point (max. 4 bytes)
  .section .entry
    nop
    jp start

  ; GameBoy Header
  .section .hdrlogo
    .db 0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, 0x03, 0x73, 0x00, 0x83, 0x00, 0x0C, 0x00, 0x0D
    .db 0x00, 0x08, 0x11, 0x1F, 0x88, 0x89, 0x00, 0x0E, 0xDC, 0xCC, 0x6E, 0xE6, 0xDD, 0xDD, 0xD9, 0x99
    .db 0xBB, 0xBB, 0x67, 0x63, 0x6E, 0x0E, 0xEC, 0xCC, 0xDD, 0xDC, 0x99, 0x9F, 0xBB, 0xB9, 0x33, 0x3E
  .section .hdrname
    .db "hram-rw"
  .section .hdrgc
    .db "TEST"
  .section .hdrcgb
    .db 0x00
  .section .hdrmc
    .db "ZZ"
  .section .hdrsgb
    .db 0x00
  .section .hdrtype
    .db 0x08
  .section .hdrrom
    .db 0x00
  .section .hdrram
    .db 0x02
  .section .hdrdest
    .db 0x01
  .section .hdrver
    .db 0x00

  ; Code for Bank 0 (starts at 0x150)
  .section .bank0
  start:
  .global start
    di

    call foo  ; call routine in bank 1

    ; Copy routine for initializing HRAM
    ld c, _ehdata
    ld hl, __load_stop_hdata - 1
  loop:
    ld a, _hdata - 1
    dec c
    cp c
    jp z, loop2  ; jumps to address 0xff80
    ld a, (hld)
    ld (c), a
    jr loop

  ; Code loaded into HRAM (starts at 0xff80)
  .section .hdata
  loop2:
    jr loop2

  ; Code for Bank 1 (starts at 0x4000)
  .section bank1
  foo:
    rst 0x28  ; call reset 0x28 handler
    ret


Build example with:

  sm83-gb-coff-as -o example.o example.s
  sm83-gb-coff-ld -o example.gb example.o

Then use rgbfix from the Rednex Game Boy Development System (rgbds):
  rgbfix -fhg example.gb