-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathplayer.asm
187 lines (162 loc) · 2.94 KB
/
player.asm
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
include "include/hardware.inc"
; Constants
DEF STACK_SIZE EQU $7A
;; Stack starts at $FFFE
; $0000 - $003F: RST handlers.
SECTION "restarts", ROM0[$0000]
ret
REPT 7
nop
ENDR
; $0008
ret
REPT 7
nop
ENDR
; $0010
ret
REPT 7
nop
ENDR
; $0018
ret
REPT 7
nop
ENDR
; $0020
ret
REPT 7
nop
ENDR
; $0028
ret
REPT 7
nop
ENDR
; $0030
ret
REPT 7
nop
ENDR
; $0038
ret
REPT 7
nop
ENDR
; Interrupt addresses
SECTION "Vblank interrupt", ROM0[$0040]
reti
SECTION "LCD controller status interrupt", ROM0[$0048]
;; HACK!!!!!!!!!!!!!
;; there's some sort of bug in the emulator which needs to be fixed,
;; which screws up the program counter immediately after it exits a halt.
;; this nop protects against that for now.
nop
jp isr_wrapper
SECTION "Timer overflow interrupt", ROM0[$0050]
nop
jp isr_wrapper
SECTION "Serial transfer completion interrupt", ROM0[$0058]
reti
SECTION "P10-P13 signal low edge interrupt", ROM0[$0060]
reti
; Reserved stack space
SECTION "Stack", HRAM[$FFFE - STACK_SIZE]
ds STACK_SIZE
; Control starts here, but there's more ROM header several bytes later, so the
; only thing we can really do is immediately jump to after the header
SECTION "Header", ROM0[$0100]
nop
jp $0150
NINTENDO_LOGO
; $0134 - $013E: The title, in upper-case letters, followed by zeroes.
DB "HUGE"
DS 7 ; padding
; $013F - $0142: The manufacturer code. Empty for now
DS 4
DS 1
; $0144 - $0145: "New" Licensee Code, a two character name.
DB "NF"
; Initialization
SECTION "main", ROM0[$0150]
jp _init
isr_wrapper:
push af
push hl
push bc
push de
call hUGE_dosound
pop de
pop bc
pop hl
pop af
reti
_paint_tile:
ld a, b
ld [hl+], a
ld a, c
ld [hl+], a
ret
_init:
xor a
ldh [rIF], a
inc a
ldh [rIE], a
halt
nop
; Set LCD palette for grayscale mode; yes, it has a palette
ld a, %11100100
ldh [$FF47], a
;; Fill with pattern
ld hl, $8000
ld bc, `10000000
call _paint_tile
ld bc, `01000000
call _paint_tile
ld bc, `00100000
call _paint_tile
ld bc, `00010000
call _paint_tile
ld bc, `00001000
call _paint_tile
ld bc, `00000100
call _paint_tile
ld bc, `00000010
call _paint_tile
ld bc, `00000001
call _paint_tile
; Enable sound globally
ld a, $80
ldh [rAUDENA], a
; Enable all channels in stereo
ld a, $FF
ldh [rAUDTERM], a
; Set volume
ld a, $77
ldh [rAUDVOL], a
ld hl, SONG_DESCRIPTOR
call hUGE_init
IF DEF(USE_TIMER)
ld a, TIMER_MODULO
ldh [rTMA], a
ld a, 4 ; 4096 hz
ldh [rTAC], a
ld a, IEF_TIMER
ldh [rIE], a
ei
ELSE
;; Enable the HBlank interrupt on scanline 0
ldh a, [rSTAT]
or a, STATF_LYC
ldh [rSTAT], a
xor a ; ld a, 0
ldh [rLYC], a
ld a, IEF_LCDC
ldh [rIE], a
ei
ENDC
_halt:
; Do nothing, forever
halt
nop
jr _halt