~nytpu/ankano unlisted

ref: d2e19612bcef6363dbe24e99a7496981c4b08460 ankano/src/header.asm -rw-r--r-- 3.4 KiB
d2e19612nytpu update game map and remove superfluous allocation from header 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
; header.asm
; initialization and header portion of the cartridge
;
; Copyright (C) 2018-2020 Eldred Habert
; See LICENSE_MIT or <https://opensource.org/licenses/MIT>

INCLUDE "defines.asm"

SECTION "Header", ROM0[$100]
	; the rom's entry point
	; 4 bytes available, sub d8 takes 2, jr r8 takes 2
	sub $11 ; this helps check if we're on cgb more efficiently
	jr EntryPoint

	; the header itself. allocate blank space, as it's taken care of by rgbfix.
	ds $150 - @, 0

EntryPoint:
	; in case there's anything that should be done on boot but not on reset
	ld [hConsoleType], a
Reset::
	di ; disable interrupts while we set up

	; kill sound
	xor a
	ldh [rNR52], a

	; wait for vblank and turn lcd off
.waitVBlank
	ldh a, [rLY]
	cp SCRN_Y
	jr c, .waitVBlank
	xor a
	ldh [rLCDC], a

	ld sp, wStackBottom

	; set up oam dma function in hram
	ld a, BANK(OAMDMA)
	; no need to write bank number to hram var, interrupts aren't active

	ld [rROMB0], a
	ld hl, OAMDMA
	lb bc, OAMDMA.end - OAMDMA, LOW(hOAMDMA)
.copyOAMDMA
	ld a, [hli]
	ldh [c], a
	inc c
	dec b
	jr nz, .copyOAMDMA

	; set all palettes
	ld a, %11100100
	ld [rBGP], a
	ld [OAMF_PAL0], a
	ld [OAMF_PAL1], a

	; You will also need to reset your handlers' variables below
	; I recommend reading through, understanding, and customizing this file
	; in its entirety anyways. This whole file is the "global" game init,
	; so it's strongly tied to your own game.
	; I don't recommend clearing large amounts of RAM, nor to init things
	; here that can be initialized later.

	; reset variables necessary for the vblank handler to function correctly
	xor a
	ldh [hVBlankFlag], a
	ldh [hOAMHigh], a
	ldh [hCanSoftReset], a
	dec a ; ld a, $FF
	ldh [hHeldKeys], a

	; load the rom bank for the intro animation
	; important to do it before enabling interrupts
	ld a, BANK(Intro)
	ldh [hCurROMBank], a
	ld [rROMB0], a

	; select interrupts enabled initially
	ld a, IEF_VBLANK
	ldh [rIE], a
	xor a
	ei ; only takes effect after the following instruction
	ldh [rIF], a ; clears "accumulated" interrupts

	; init shadow regs
	; a is still 0 from previous section, but may need to uncomment this later
	; xor a
	ldh [hSCY], a
	ldh [hSCX], a
	ld a, LCDCF_ON | LCDCF_BGON
	ldh [hLCDC], a
	; And turn the LCD on!
	ldh [rLCDC], a

	; clear oam, so it doesn't display garbage
	; this will get committed to hardware oam after the end of the first
	; frame, but the hardware doesn't display it, so that's fine.
	ld hl, wShadowOAM
	ld c, NB_SPRITES * 4
	xor a
	rst MemsetSmall
	ld a, h ; ld a, HIGH(wShadowOAM)
	ldh [hOAMHigh], a

	; `Intro`'s bank has already been loaded earlier
	jp Intro

SECTION "OAM DMA routine", ROMX
; oam dma prevents access to most memory, but never hram.
; this starts an oam dma transfer, then waits for it to complete.
; it gets copied to hram and is called there from the vblank handler
OAMDMA:
	ldh [rDMA], a
	ld a, NB_SPRITES
.wait
	dec a
	jr nz, .wait
	ret
.end

SECTION "Global vars", HRAM
; copy of the currently-loaded rom bank, so the handlers can restore it
; make sure to always write to it before writing to romb0
hCurROMBank:: db

; 0 if cgb (including dmg mode and gba), non-zero for other models
hConsoleType:: db


SECTION "OAM DMA", HRAM
hOAMDMA::
	ds OAMDMA.end - OAMDMA


SECTION UNION "Shadow OAM", WRAM0,ALIGN[8]
wShadowOAM::
	ds NB_SPRITES * 4


; This ensures that the stack is at the very end of WRAM
SECTION "Stack", WRAM0[$E000 - STACK_SIZE]
	ds STACK_SIZE
wStackBottom: