summaryrefslogtreecommitdiff
path: root/main.asm
blob: e9e36d2ce055e8962f9b7ca24ff7ca90899a3c49 (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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
;    TLL - A version of the Spectrum game TLL for the Super Nintendo
;
;    Copyright (C) 2018  Ian Cowburn (ianc@noddybox.co.uk)
;
;    This program is free software: you can redistribute it and/or modify
;    it under the terms of the GNU General Public License as published by
;    the Free Software Foundation, either version 3 of the License, or
;    (at your option) any later version.
;
;    This program is distributed in the hope that it will be useful,
;    but WITHOUT ANY WARRANTY; without even the implied warranty of
;    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;    GNU General Public License for more details.
;
;    You should have received a copy of the GNU General Public License
;    along with this program.  If not, see <http://www.gnu.org/licenses/>.
;
;    -------------------------------------------------------------------------
;
;    Main
;
	processor	65c816

	option  output-file,"main.lib"
	option	output-format,lib
	option	+address24

	org	$8000
	bank	0

	; Initialise SNES
	;
	include "snes.inc"
	include "macros.inc"
	import	"tiles.lib",labels
	import	"maps.lib",labels

	sei
	clc
	xce

	INDEX16
	ldx     #$1fff
	txs

	ACC8
	INDEX8
	jsr	InitSNES
	cli

	; Clear VRAM
	;
	lda	#$80
	sta	VMAIN
	stz	VMADDL
	stz	VMADDH
	DMA	9,zero,$18,0

	; Clear OAM
	;
ClearOAM:
	stz	OAMADDL
	stz	OAMADDH
	INDEX16
	ldx	#0
.loop
	stz	OAMDATA
	stz	OAMDATA
	inx
	cpx	#544/2
	bne	loop
	INDEX8

	; Copy 4-colour tiles
	;
	stz	VMADDL
	stz	VMADDH
	DMA	1,Col4Tiles,$18,Col4TilesLen

	; Copy 16-colour tiles
	;
	stz	VMADDL
	lda	#$10
	sta	VMADDH
	DMA	1,Col16Tiles,$18,Col16TilesLen

	; Copy sprites
	;
	stz	VMADDL
	lda	#$a0
	sta	VMADDH
	DMA	1,SpriteData,$18,SpriteDataLen

	; Copy palette
	;
	stz	CGADD
	DMA	0,PaletteData,$22,PaletteDataLen
	lda	#$80
	sta	CGADD
	DMA	0,PaletteData,$22,PaletteDataLen

	; Copy BG3
	;
copybg3:
	INDEX16
	ldx	#$0
	ldy	#32*32
	stz	VMADDL
	lda	#$40
	sta	VMADDH
.loop
	lda	BG3Map,x
	sta	VMDATAL
	lda	#$20
	sta	VMDATAH
	inx
	dey
	bne	loop
	INDEX8

	; Initialise the screen
	;
	lda	#$09
	sta	BGMODE
	lda	#$1f
	sta	TM

	lda	#$11
	sta	BG12NBA
	stz	BG34NBA

	lda	#$61
	sta	BG1SC
	lda	#$81
	sta	BG2SC
	lda	#$40
	sta	BG3SC

	lda	#-52
	sta	BG3HOFS
	stz	BG3HOFS
	lda	#-32
	sta	BG3VOFS
	stz	BG3VOFS

	lda	#$0f
	sta	INIDISP

	lda	#$81
	sta	NMITIMEN

	; Loop forever.
Forever:
	jmp Forever

InitSNES:
 	lda 	#$8F
 	sta 	INIDISP
 	stz 	OBSEL
 	stz 	OAMADDL
 	stz 	OAMADDH
 	stz 	BGMODE
 	stz 	MOSAIC
 	stz 	BG1SC
 	stz 	BG2SC
 	stz 	BG3SC
 	stz 	BG4SC
 	stz 	BG12NBA
 	stz 	BG34NBA
 	stz 	BG1VOFS
 	stz 	BG1VOFS
 	stz 	BG2VOFS
 	stz 	BG2VOFS
 	stz 	BG3VOFS
 	stz 	BG3VOFS
 	stz 	BG4VOFS
 	stz 	BG4VOFS
 	stz 	BG1HOFS
 	stz 	BG1HOFS
 	stz 	BG2HOFS
 	stz 	BG2HOFS
 	stz 	BG3HOFS
 	stz 	BG3HOFS
 	stz 	BG4HOFS
 	stz 	BG4HOFS
 	lda 	#$80
 	sta 	VMAIN
 	stz 	VMADDL
 	stz 	VMADDH
 	stz 	M7SEL
 	stz 	M7A
 	lda 	#$01
 	sta 	M7A
 	stz 	M7B
 	stz 	M7B
 	stz 	M7C
 	stz 	M7C
 	stz 	M7D
 	sta 	M7D
 	stz 	M7X
 	stz 	M7X
 	stz 	M7Y
 	stz 	M7Y
 	stz 	CGADD
 	stz 	W12SEL
 	stz 	W34SEL
 	stz 	WOBJSEL
 	stz 	WH0
 	stz 	WH1
 	stz 	WH2
 	stz 	WH3
 	stz 	WBGLOG
 	stz 	WOBJLOG
 	sta 	TM
 	stz 	TS
 	stz 	TMW
 	stz 	TSW
 	lda 	#$30
 	sta 	CGWSEL
 	stz 	CGADSUB
 	lda 	#$E0
 	sta 	COLDATA
 	stz 	SETINI
 	stz 	NMITIMEN
 	lda 	#$FF
 	sta 	WRIO
 	stz 	WRMPYA
 	stz 	WRMPYB
 	stz 	WRDIVL
 	stz 	WRDIVH
 	stz 	WRDIVB
 	stz 	HTIMEL
 	stz 	HTIMEH
 	stz 	VTIMEL
 	stz 	VTIMEH
 	stz 	MDMAEN
 	stz 	HDMAEN
 	stz 	MEMSEL
	rts


; IRQ vectors
;

vbl_handler:
	rti

irq_handler:
	rti

zero:
	db	0