-
Notifications
You must be signed in to change notification settings - Fork 0
/
bigass.asm
executable file
·327 lines (254 loc) · 9.71 KB
/
bigass.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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
TIA_BASE_ADDRESS = $40
processor 6502
include "vcs.h"
include "macro.h"
ORIGIN SET 0
ORIGIN_RAM SET 0
;FIXED_BANK = 3 * 2048 ;--> 8K ROM tested OK
;FIXED_BANK = 7 * 2048 ;--> 16K ROM tested OK
FIXED_BANK = 15 * 2048 ; ->> 32K
;FIXED_BANK = 31 * 2048 ; ->> 64K
;FIXED_BANK = 239 * 2048 ;--> 480K ROM tested OK (KK/CC2 compatibility)
;FIXED_BANK = 127 * 2048 ;--> 256K ROM tested OK
;FIXED_BANK = 255 * 2048 ;--> 512K ROM tested OK (CC2 can't handle this)
YES = 1
NO = 0
;-------------------------------------------------------------------------------
COMPILE_ILLEGALOPCODES = 1
RESERVED_FOR_STACK = 12 ; bytes guaranteed not overwritten by variable use
SET_BANK = $3F ; write address to switch ROM banks
SET_BANK_RAM = $3E ; write address to switch RAM banks
RAM_3E = $1000
RAM_SIZE = $400
RAM_WRITE = $400 ; add this to RAM address when doing writes
RND_EOR_VAL = $b4
; Platform constants:
PAL = %10
PAL_50 = PAL|0
PAL_60 = PAL|1
VBLANK_TIM_NTSC = 48 ; NTSC 276 (Desert Falcon does 280, so this should be pretty safe)
VBLANK_TIM_PAL = 85 ;85 ; PAL 312 (we could increase this too, if we want to, but I suppose the used vertical screen size would become very small then)
OVERSCAN_TIM_NTSC = 35 ;24 ;51 ; NTSC 276 (Desert Falcon does 280, so this should be pretty safe)
OVERSCAN_TIM_PAL = 41 ; PAL 312 (we could increase this too, if we want to, but I suppose the used vertical screen size would become very small then)
SCANLINES_NTSC = 276 ; NTSC 276 (Desert Falcon does 280, so this should be pretty safe)
SCANLINES_PAL = 312
;------------------------------------------------------------------------------
; MACRO definitions
ROM_BANK_SIZE = $800
MAC NEWBANK ; bank name
SEG {1}
ORG ORIGIN
RORG $F000
BANK_START SET *
{1} SET ORIGIN / 2048
ORIGIN SET ORIGIN + 2048
_CURRENT_BANK SET {1}
ENDM
MAC DEFINE_1K_SEGMENT ; {seg name}
ALIGN $400
SEGMENT_{1} SET *
BANK_{1} SET _CURRENT_BANK
ENDM
MAC CHECK_BANK_SIZE ; name
.TEMP = * - BANK_START
ECHO {1}, "(2K) SIZE = ", .TEMP, ", FREE=", ROM_BANK_SIZE - .TEMP
#if ( .TEMP ) > ROM_BANK_SIZE
ECHO "BANK OVERFLOW @ ", * - ORIGIN
ERR
#endif
ENDM
MAC CHECK_HALF_BANK_SIZE ; name
; This macro is for checking the first 1K of ROM bank data that is to be copied to RAM.
; Note that these ROM banks can contain 2K, so this macro will generally go 'halfway'
.TEMP = * - BANK_START
ECHO {1}, "(1K) SIZE = ", .TEMP, ", FREE=", ROM_BANK_SIZE/2 - .TEMP
#if ( .TEMP ) > ROM_BANK_SIZE/2
ECHO "HALF-BANK OVERFLOW @ ", * - ORIGIN
ERR
#endif
ENDM
MAC OVERLAY ; {name}
SEG.U OVERLAY_{1}
org Overlay
ENDM
;--------------------------------------------------------------------------
MAC VALIDATE_OVERLAY
LIST OFF
#if * - Overlay > OVERLAY_SIZE
ECHO "Overlay ", {1}, "too big"
ERR
#endif
LIST ON
ENDM
;--------------------------------------------------------------------------
; Macro inserts a page break if the object would overlap a page
MAC OPTIONAL_PAGEBREAK ; { string, size }
LIST OFF
IF (>( * + {2} -1 )) > ( >* )
EARLY_LOCATION SET *
ALIGN 256
ECHO "PAGE BREAK INSERTED FOR ", {1}
ECHO "REQUESTED SIZE = ", {2}
ECHO "WASTED SPACE = ", *-EARLY_LOCATION
ECHO "PAGEBREAK LOCATION = ", *
ENDIF
LIST ON
ENDM
MAC CHECK_PAGE_CROSSING
LIST OFF
#if ( >BLOCK_END != >BLOCK_START )
ECHO "PAGE CROSSING @ ", BLOCK_START
#endif
LIST ON
ENDM
MAC CHECKPAGE
LIST OFF
IF >. != >{1}
ECHO ""
ECHO "ERROR: different pages! (", {1}, ",", ., ")"
ECHO ""
ERR
ENDIF
LIST ON
ENDM
MAC CHECKPAGEX
LIST OFF
IF >. != >{1}
ECHO ""
ECHO "ERROR: different pages! (", {1}, ",", ., ") @ {0}"
ECHO {2}
ECHO ""
ERR
ENDIF
LIST ON
ENDM
MAC CHECKPAGE_BNE
LIST OFF
IF 0;>(. + 2) != >{1}
ECHO ""
ECHO "ERROR: different pages! (", {1}, ",", ., ")"
ECHO ""
ERR
ENDIF
LIST ON
bne {1}
ENDM
MAC CHECKPAGE_BPL
LIST OFF
IF (>(.+2 )) != >{1}
ECHO ""
ECHO "ERROR: different pages! (", {1}, ",", ., ")"
ECHO ""
ERR
ENDIF
LIST ON
bpl {1}
ENDM
MAC ALIGN_FREE
FREE SET FREE - .
align {1}
FREE SET FREE + .
echo "@", ., ":", FREE
ENDM
;--------------------------------------------------------------------------
MAC VECTOR ; just a word pointer to code
.word {1}
ENDM
MAC DEFINE_SUBROUTINE ; name of subroutine
BANK_{1} = _CURRENT_BANK ; bank in which this subroutine resides
SUBROUTINE ; keep everything local
{1} ; entry point
ENDM
;--------------------------------------------------------------------------
MAC NEWRAMBANK ; bank name
SEG.U {1}
ORG ORIGIN_RAM
RORG RAM_3E
BANK_START SET *
{1} SET ORIGIN_RAM / RAM_SIZE
ORIGIN_RAM SET ORIGIN_RAM + RAM_SIZE
ENDM
MAC VALIDATE_RAM_SIZE
#if * - RAM_3E > RAM_SIZE
ERR
#endif
ENDM
MAC NEXT_RANDOM
; update random value:
lda rnd ; 3
lsr ; 2
IFCONST rndHi
ror rndHi ; 5 16 bit LFSR
ENDIF
bcc .skipEOR ; 2/3
eor #RND_EOR_VAL ; 2
.skipEOR
sta rnd ; 3 = 14/19
ENDM
MAC RESYNC
; resync screen, X and Y == 0 afterwards
lda #%10 ; make sure VBLANK is ON
sta VBLANK
ldx #8 ; 5 or more RESYNC_FRAMES
.loopResync
VERTICAL_SYNC
ldy #SCANLINES_NTSC/2 - 2
lda Platform
eor #PAL_50 ; PAL-50?
bne .ntsc
ldy #SCANLINES_PAL/2 - 2
.ntsc
.loopWait
sta WSYNC
sta WSYNC
dey
bne .loopWait
dex
bne .loopResync
ENDM
MAC SET_PLATFORM
; 00 = NTSC
; 01 = NTSC
; 10 = PAL-50
; 11 = PAL-60
lda SWCHB
rol
rol
rol
and #%11
eor #PAL
sta Platform ; P1 difficulty --> TV system (0=NTSC, 1=PAL)
ENDM
;------------------------------------------------------------------------------
#include "zeropage.asm"
;------------------------------------------------------------------------------
; OVERLAYS!
; These variables are overlays, and should be managed with care
; That is, variables are ALREADY DEFINED, and we're reusing RAM for other purposes
; EACH OF THESE ARE VARIABLES (TEMPORARY) USED BY ONE ROUTINE (AND IT'S SUBROUTINES)
; THAT IS, LOCAL VARIABLES. USE 'EM FREELY, THEY COST NOTHING
; TOTAL SPACE USED BY ANY OVERLAY GROUP SHOULD BE <= SIZE OF 'Overlay'
OVERLAY TitleScreen
title_colour_table ds 2
VALIDATE_OVERLAY "TitleScreen"
OVERLAY BitmapHandler
bitmap_colour_table ds 2
VALIDATE_OVERLAY "BitmapHandler"
;------------------------------------------------------------------------------
;##############################################################################
;------------------------------------------------------------------------------
NEWRAMBANK BANK_DRAW_BUFFERS
; VARS DEFINED IN ROM_SHADOW_OF_BANK_DRAW_BUFFERS
; SELF-MODIFYING SUBROUTINES MAY BE PRESENT IN THIS BANK TOO!
VALIDATE_RAM_SIZE
;------------------------------------------------------------------------------
;##############################################################################
;------------------------------------------------------------------------------
;ORIGIN SET 0
include "BANK_GENERIC.asm"
include "titleScreen.asm"
include "BANK_INITBANK.asm" ; MUST be after banks that include levels -- otherwise MAX_LEVELBANK is not calculated properly
include "bitmap.asm"
; MUST BE LAST...
include "BANK_FIXED.asm"
;END