mattcurrie/mgbdis

Error on BIOS disassembly

kdridi opened this issue · 1 comments

I tried to disassemble the BIOS using this (nice) tool.

I create the cartridge using this python3 script

#!/usr/bin/env python3

code = bytearray([
    0x31, 0xFE, 0xFF, 0xAF, 0x21, 0xFF, 0x9F, 0x32, 0xCB, 0x7C, 0x20, 0xFB, 0x21, 0x26, 0xFF, 0x0E,
    0x11, 0x3E, 0x80, 0x32, 0xE2, 0x0C, 0x3E, 0xF3,  -- snip --
])

rom = code + bytearray([0x00] * (32768 - len(code)))

with open("bios.gb", "wb") as out_file:
  out_file.write(rom)

The mgbdis creates some files but when I looked in bank_000.asm, I found is an error

; Disassembly of "bios.gb"
; This file was created with:
; mgbdis v1.4 - Game Boy ROM disassembler by Matt Currie and contributors.
; https://github.com/mattcurrie/mgbdis

SECTION "ROM Bank $000", ROM0[$0]

RST_00::
    ld sp, $fffe
    xor a
    ld hl, $9fff

jr_000_0007:
    ld [hl-], a

RST_08::
    bit 7, h
    jr nz, jr_000_0007

    ld hl, $ff26
    db $0e  ;  <<<<<<<<<<<<<< ERROR

RST_10::
    ld de, $803e
    ld [hl-], a
    ld [c], a
    inc c
    ld a, $f3

The tool seems to skip the disassembly of the 0x09 opcode (LD c, n) that has to consume an other byte.

For disassembling boot ROMs you will want to remove the default symbols on the lines linked below, as they force mgbdis to have instructions starting at those addresses:

mgbdis/mgbdis.py

Lines 21 to 47 in b41f5c8

'00:0000 RST_00',
'00:0000 .code:8',
'00:0008 RST_08',
'00:0008 .code:8',
'00:0010 RST_10',
'00:0010 .code:8',
'00:0018 RST_18',
'00:0018 .code:8',
'00:0020 RST_20',
'00:0020 .code:8',
'00:0028 RST_28',
'00:0028 .code:8',
'00:0030 RST_30',
'00:0030 .code:8',
'00:0038 RST_38',
'00:0038 .code:8',
'00:0040 VBlankInterrupt',
'00:0040 .code:8',
'00:0048 LCDCInterrupt',
'00:0048 .code:8',
'00:0050 TimerOverflowInterrupt',
'00:0050 .code:8',
'00:0058 SerialTransferCompleteInterrupt',
'00:0058 .code:8',
'00:0060 JoypadTransitionInterrupt',
'00:0060 .code:8',

It would be nice if there was an option to disable these for cases where they aren't relevant :)

(Also note I've just edited your issue to remove the bulk of the boot ROM file).