aboutsummaryrefslogtreecommitdiff
path: root/init.gbasm
blob: 08fab8fdce736ce2cef449cc35655d320b5cabd2 (plain)
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
.DB $01, $02, $04, $08, $10, $20, $40, $80

.PADTO 0x0040
VBlank:
	JP $mem_vblank_jump_instruction

.PADTO 0x0048
STAT:
	JP $mem_stat_jump_instruction

.PADTO 0x0100
Start:
	JP =Initialize_RAM

.PADTO 0x0104
Header:
.Nintendo_Logo: ; The Nintendo logo must be stored in bytes 0x104-133
	.DB $CE,$ED,$66,$66,$CC,$0D,$00,$0B,$03,$73,$00,$83,$00,$0C,$00,$0D
	.DB $00,$08,$11,$1F,$88,$89,$00,$0E,$DC,$CC,$6E,$E6,$DD,$DD,$D9,$99
	.DB $BB,$BB,$67,$63,$6E,$0E,$EC,$CC,$DD,$DC,$99,$9F,$BB,$B9,$33,$3E

.PADTO 0x0134

.Title:
	.DB $50, $79, $6f, $6e, $20, $41, $64, $76
.PADTO 0x13f

.Manufacturer_code:
.PADTO 0x143

.CGB_Flag: .DB $69
.Licensee_code_new: .DB $00, $00
.SGB_Flag: .DB $00
.MBC: .DB $01
.ROM_size: .DB $00 ; Will be set after assembly by build scripts
.RAM_size: .DB $00 ; The .sav cartridge kind of ram
.Destination_code: .DB $01 ; Overseas
.Licensee_code_old: .DB $00
.Version_number: .DB $42
.Header_checksum: .DB $00 ; Will be set after assembly by build scripts
.Global_checksum: .DB $00, $00 ; Will be set after assembly by build scripts

Initialize_RAM:
LD SP, $fffe

; LCDC
XOR A
LD $reg_lcd_controller, A

; Disable Interrupts
LD A, $00
LD $reg_interrupt_enable, A
Empty_WRAM:
	LD HL, $C000
	.loop:
		XOR A
		LD (HL+), A
		LD A, $D0
		CP H
		JR NZ, =.loop

	CALL =VBlank_Wait

Empty_VRAM: ; (Clear screen)
	LD HL, $VRAM_start ; We set the HL register to the start of VRAM
	Empty_VRAM.loop:
		XOR A
		LD (HL+), A 						; We set the memory pointed to by HL to 0 and increase HL
		LD A, $a0
		CP H        						; Until h has reached $a0 ($a0000 is the end of VRAM)
		JR NZ, =Empty_VRAM.loop

	; BG Palette
	LD A, $palette_normal
	LD $reg_bg_palette, A
	LD $mem_prepared_color_palette, A

	; OBJ0 Palette
	LD A, $obj_palette_normal
	LD $reg_obj0_palette, A

	; OBJ1 Palette (frozen, shadow)
	LD A, $obj_palette_frozen
	LD $reg_obj1_palette, A

	; Interrupt jmp instruction
	LD A, $c3 ; Unconditional imm16 jump
	LD ($mem_vblank_jump_instruction), A
	LD ($mem_stat_jump_instruction), A


Initialize_Window_GUI:
	LD A, $48
	LD $reg_window_y, A
	LD A, $6f
	LD $reg_window_x, A
	LD HL, $9d80
	.top_bar_loop:
		LD A, $10
		LD (HL+), A

		LD A, L
		CP $94
		LD $reg_lcd_status, A
		JR NZ, =.top_bar_loop

	LD HL, $9c80
	LD BC, $00a0
	LD DE, =Dialogue_Box_Tilemap_data
	CALL =memcpy

	LD HL, $9c00
	LD BC, $0080
	LD DE, =Cost_Window_Tilemap_data
	CALL =memcpy

Copy_OAM_DMA_Transfer_Routine_To_HRAM:
	LD HL, $OAM_DMA_Transfer_routine
	LD DE, =OAM_DMA_Transfer_routine_src
	LD BC, $000a
	CALL =memcpy

	JP =Entrypoint

OAM_DMA_Transfer_routine_src:
	LD A, high($mem_oam_buffer)
	LD ($46), A
	LD A, $28        ; delay for a total of 4×40 = 160 M-cycles
	.wait:
	    DEC A						             ; 1 M-cycle
	    JR NZ, =.wait    ; 3 M-cycles
	    RET
	.end: