Skip to content

Commit

Permalink
Reorganize home header
Browse files Browse the repository at this point in the history
  • Loading branch information
Rangi42 committed Jul 3, 2020
1 parent c9c59dc commit 6bd86e1
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 187 deletions.
112 changes: 8 additions & 104 deletions home.asm
Original file line number Diff line number Diff line change
@@ -1,118 +1,22 @@
INCLUDE "constants.asm"


; The rst vectors are unused.
SECTION "rst 00", ROM0
rst $38
SECTION "rst 08", ROM0
rst $38
SECTION "rst 10", ROM0
rst $38
SECTION "rst 18", ROM0
rst $38
SECTION "rst 20", ROM0
rst $38
SECTION "rst 28", ROM0
rst $38
SECTION "rst 30", ROM0
rst $38
SECTION "rst 38", ROM0
rst $38

; Hardware interrupts
SECTION "vblank", ROM0
jp VBlank
SECTION "hblank", ROM0
rst $38
SECTION "timer", ROM0
jp Timer
SECTION "serial", ROM0
jp Serial
SECTION "joypad", ROM0
reti
SECTION "NULL", ROM0
NULL::

INCLUDE "home/header.asm"

SECTION "Home", ROM0

DisableLCD::
xor a
ld [rIF], a
ld a, [rIE]
ld b, a
res 0, a
ld [rIE], a

.wait
ld a, [rLY]
cp LY_VBLANK
jr nz, .wait

ld a, [rLCDC]
and $ff ^ rLCDC_ENABLE_MASK
ld [rLCDC], a
ld a, b
ld [rIE], a
ret

EnableLCD::
ld a, [rLCDC]
set rLCDC_ENABLE, a
ld [rLCDC], a
ret

ClearSprites::
xor a
ld hl, wOAMBuffer
ld b, 40 * 4
.loop
ld [hli], a
dec b
jr nz, .loop
ret

HideSprites::
ld a, 160
ld hl, wOAMBuffer
ld de, 4
ld b, 40
.loop
ld [hl], a
add hl, de
dec b
jr nz, .loop
ret
SECTION "High Home", ROM0

INCLUDE "home/lcd.asm"
INCLUDE "home/clear_sprites.asm"
INCLUDE "home/copy.asm"


SECTION "Entry", ROM0

nop
jp Start


SECTION "Header", ROM0

; The header is generated by rgbfix.
; The space here is allocated to prevent code from being overwritten.

ds $150 - $104


SECTION "Main", ROM0

Start::
cp GBC
jr z, .gbc
xor a
jr .ok
.gbc
ld a, 0
.ok
ld [wGBC], a
jp Init

SECTION "Home", ROM0

INCLUDE "home/start.asm"
INCLUDE "home/joypad.asm"
INCLUDE "data/maps/map_header_pointers.asm"
INCLUDE "home/overworld.asm"
Expand Down
21 changes: 21 additions & 0 deletions home/clear_sprites.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ClearSprites::
xor a
ld hl, wOAMBuffer
ld b, 40 * 4
.loop
ld [hli], a
dec b
jr nz, .loop
ret

HideSprites::
ld a, 160
ld hl, wOAMBuffer
ld de, 4
ld b, 40
.loop
ld [hl], a
add hl, de
dec b
jr nz, .loop
ret
57 changes: 57 additions & 0 deletions home/header.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
; rst vectors (unused)

SECTION "rst0", ROM0[$0000]
rst $38

SECTION "rst8", ROM0[$0008]
rst $38

SECTION "rst10", ROM0[$0010]
rst $38

SECTION "rst18", ROM0[$0018]
rst $38

SECTION "rst20", ROM0[$0020]
rst $38

SECTION "rst28", ROM0[$0028]
rst $38

SECTION "rst30", ROM0[$0030]
rst $38

SECTION "rst38", ROM0[$0038]
rst $38


; Game Boy hardware interrupts

SECTION "vblank", ROM0[$0040]
jp VBlank

SECTION "lcd", ROM0[$0048]
rst $38

SECTION "timer", ROM0[$0050]
jp Timer

SECTION "serial", ROM0[$0058]
jp Serial

SECTION "joypad", ROM0[$0060]
reti


SECTION "Header", ROM0[$0100]

Start::
; Nintendo requires all Game Boy ROMs to begin with a nop ($00) and a jp ($C3)
; to the starting address.
nop
jp _Start

; The Game Boy cartridge header data is patched over by rgbfix.
; This makes sure it doesn't get used for anything else.

ds $0150 - @, $00
25 changes: 25 additions & 0 deletions home/lcd.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
DisableLCD::
xor a
ld [rIF], a
ld a, [rIE]
ld b, a
res 0, a
ld [rIE], a

.wait
ld a, [rLY]
cp LY_VBLANK
jr nz, .wait

ld a, [rLCDC]
and $ff ^ rLCDC_ENABLE_MASK
ld [rLCDC], a
ld a, b
ld [rIE], a
ret

EnableLCD::
ld a, [rLCDC]
set rLCDC_ENABLE, a
ld [rLCDC], a
ret
10 changes: 10 additions & 0 deletions home/start.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
_Start::
cp GBC
jr z, .gbc
xor a
jr .ok
.gbc
ld a, 0
.ok
ld [wGBC], a
jp Init
Loading

0 comments on commit 6bd86e1

Please sign in to comment.