shithub: pokered

Download patch

ref: 6bd86e10c32cd7b464425adfc01621f3ff6726aa
parent: c9c59dc34323a5e0b1886db5f845c8d41620826e
author: Rangi <remy.oukaour+rangi42@gmail.com>
date: Fri Jul 3 09:03:21 EDT 2020

Reorganize home header

--- a/home.asm
+++ b/home.asm
@@ -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
+SECTION "NULL", ROM0
+NULL::
 
-; 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
+INCLUDE "home/header.asm"
 
 
-SECTION "Home", ROM0
+SECTION "High 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
-
+INCLUDE "home/lcd.asm"
+INCLUDE "home/clear_sprites.asm"
 INCLUDE "home/copy.asm"
 
 
-SECTION "Entry", ROM0
+SECTION "Home", 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
-
-
+INCLUDE "home/start.asm"
 INCLUDE "home/joypad.asm"
 INCLUDE "data/maps/map_header_pointers.asm"
 INCLUDE "home/overworld.asm"
--- /dev/null
+++ b/home/clear_sprites.asm
@@ -1,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
--- /dev/null
+++ b/home/header.asm
@@ -1,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
--- /dev/null
+++ b/home/lcd.asm
@@ -1,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
--- /dev/null
+++ b/home/start.asm
@@ -1,0 +1,10 @@
+_Start::
+	cp GBC
+	jr z, .gbc
+	xor a
+	jr .ok
+.gbc
+	ld a, 0
+.ok
+	ld [wGBC], a
+	jp Init
--- a/layout.link
+++ b/layout.link
@@ -1,59 +1,43 @@
 ROM0
 	org $0000
-	"rst 00"
-
+	"NULL"
+	org $0000
+	"rst0"
 	org $0008
-	"rst 08"
-
+	"rst8"
 	org $0010
-	"rst 10"
-
+	"rst10"
 	org $0018
-	"rst 18"
-
+	"rst18"
 	org $0020
-	"rst 20"
-
+	"rst20"
 	org $0028
-	"rst 28"
-
+	"rst28"
 	org $0030
-	"rst 30"
-
+	"rst30"
 	org $0038
-	"rst 38"
-
+	"rst38"
 	org $0040
 	"vblank"
-
 	org $0048
-	"hblank"
-
+	"lcd"
 	org $0050
 	"timer"
-
 	org $0058
 	"serial"
-
 	org $0060
 	"joypad"
 	; $0061
-	"Home"
-
+	"High Home"
 	org $100
-	"Entry"
-	; $0104
 	"Header"
-
 	org $150
-	"Main"
+	"Home"
 
 ROMX $1
-	org $4000
 	"bank1"
 
 ROMX $2
-	org $4000
 	"Sound Effect Headers 1"
 	"Music Headers 1"
 	"Sound Effects 1"
@@ -61,22 +45,18 @@
 	"Music 1"
 
 ROMX $3
-	org $4000
 	"bank3"
 
 ROMX $4
-	org $4000
 	"NPC Sprites 1"
 	"Graphics (BANK 4)"
 	"Battle (BANK 4)"
 
 ROMX $5
-	org $4000
 	"NPC Sprites 2"
 	"Battle (BANK 5)"
 
 ROMX $6
-	org $4000
 	"Maps 1"
 	"bank6_1"
 	"Maps 2"
@@ -83,7 +63,6 @@
 	"bank6_2"
 
 ROMX $7
-	org $4000
 	"Maps 3"
 	"bank7_1"
 	"Maps 4"
@@ -90,7 +69,6 @@
 	"bank7_2"
 
 ROMX $8
-	org $4000
 	"Sound Effect Headers 2"
 	"Music Headers 2"
 	"Sound Effects 2"
@@ -100,44 +78,35 @@
 	"Music 2"
 
 ROMX $9
-	org $4000
 	"Pics 1"
 	"Battle (BANK 9)"
 
 ROMX $A
-	org $4000
 	"Pics 2"
 	"Battle (BANK A)"
 
 ROMX $B
-	org $4000
 	"Pics 3"
 	"Battle (BANK B)"
 
 ROMX $C
-	org $4000
 	"Pics 4"
 	"Battle (BANK C)"
 
 ROMX $D
-	org $4000
 	"Pics 5"
 	"Battle (BANK D)"
 
 ROMX $E
-	org $4000
 	"bankE"
 
 ROMX $F
-	org $4000
 	"bankF"
 
 ROMX $10
-	org $4000
 	"bank10"
 
 ROMX $11
-	org $4000
 	"Maps 5"
 	"bank11_1"
 	"Maps 6"
@@ -144,24 +113,20 @@
 	"bank11_2"
 
 ROMX $12
-	org $4000
 	"Maps 7"
 	"bank12"
 	"Maps 8"
 
 ROMX $13
-	org $4000
 	"Pics 6"
 	"Maps 9"
 	"bank13"
 
 ROMX $14
-	org $4000
 	"Maps 10"
 	"bank14"
 
 ROMX $15
-	org $4000
 	"Maps 11"
 	"bank15_1"
 	"Maps 12"
@@ -168,7 +133,6 @@
 	"bank15_2"
 
 ROMX $16
-	org $4000
 	"Maps 13"
 	"bank16_1"
 	"Maps 14"
@@ -175,7 +139,6 @@
 	"bank16_2"
 
 ROMX $17
-	org $4000
 	"Maps 15"
 	"bank17_1"
 	"Maps 16"
@@ -182,7 +145,6 @@
 	"bank17_2"
 
 ROMX $18
-	org $4000
 	"Maps 17"
 	"bank18_1"
 	"Maps 18"
@@ -189,24 +151,19 @@
 	"bank18_2"
 
 ROMX $19
-	org $4000
 	"Tilesets 1"
 
 ROMX $1A
-	org $4000
 	"bank1A"
 	"Tilesets 2"
 
 ROMX $1B
-	org $4000
 	"Tilesets 3"
 
 ROMX $1C
-	org $4000
 	"bank1C"
 
 ROMX $1D
-	org $4000
 	"Maps 19"
 	"bank1D_1"
 	"Maps 20"
@@ -215,11 +172,9 @@
 	"bank1D_3"
 
 ROMX $1E
-	org $4000
 	"bank1E"
 
 ROMX $1F
-	org $4000
 	"Sound Effect Headers 3"
 	"Music Headers 3"
 	"Sound Effects 3"
@@ -227,81 +182,60 @@
 	"Music 3"
 
 ROMX $20
-	org $4000
 	"Text 1"
 
 ROMX $21
-	org $4000
 	"Text 2"
 
 ROMX $22
-	org $4000
 	"Text 3"
 
 ROMX $23
-	org $4000
 	"Text 4"
 
 ROMX $24
-	org $4000
 	"Text 5"
 
 ROMX $25
-	org $4000
 	"Text 6"
 
 ROMX $26
-	org $4000
 	"Text 7"
 
 ROMX $27
-	org $4000
 	"Text 8"
 
 ROMX $28
-	org $4000
 	"Text 9"
 
 ROMX $29
-	org $4000
 	"Text 10"
 
 ROMX $2A
-	org $4000
 	"Text 11"
 
 ROMX $2B
-	org $4000
 	"Pokedex Text"
 
 ROMX $2C
-	org $4000
 	"Move Names"
 
 WRAM0
-	org $c000
 	"WRAM Bank 0"
-
 	org $c100
 	"Sprite State Data"
 	"OAM Buffer"
-
 	org $dfff
 	"Stack"
 
-SRAM 0
-	org $a000
+SRAM $0
 	"Sprite Buffers"
 
-SRAM 1
-	org $a000
+SRAM $1
 	"Save Data"
 
-SRAM 2
-	org $a000
+SRAM $2
 	"Saved Boxes 1"
 
-SRAM 3
-	org $a000
+SRAM $3
 	"Saved Boxes 2"
-