-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathinit.s
275 lines (245 loc) · 8.76 KB
/
init.s
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
scriptCodeStart:
scriptCodeEnd = scriptCodeStart+SCRIPTAREASIZE
; Initialize registers/variables at startup. This code is called only once and can be
; disposed after that.
;
; Parameters: -
; Returns: -
; Modifies: A,X,Y,temp vars
InitAll: ldx #STACKSTART
txs
lda ntscFlag
beq IsPAL
lda #60 ;Compensate game clock speed for NTSC
sta timeMaxTbl+3 ;(otherwise no compensation)
IsPAL: lda $d030 ;Enable extra IRQ for turbo switching for C128 & SCPU
cmp #$ff ;(or rather, disable it on plain C64)
bne UseTurbo
lda $d0bc
bpl UseTurbo
NoTurbo: ldx #$02
NoTurboCopyLoop:lda NoTurboCode,x
sta Irq4_Irq6Jump,x
dex
bpl NoTurboCopyLoop
UseTurbo:
; Initialize zeropage variables
Is128: ldx #$90-joystick-1
lda #$00
InitZP: sta joystick,x
dex
bpl InitZP
; Initialize playroutine / raster IRQ variables
sta ntFiltPos
sta ntFiltTime
lda #$7f
sta ntInitSong
lda #$0f
sta ntMasterVol
; Load options file
lda #F_OPTIONS ;This is the last file and will cache all
jsr MakeFileName_Direct ;directory entries
jsr OpenFile
ldy #$00
LoadOptions: jsr GetByte
bcs LoadOptionsDone
sta difficulty,y
iny
bcc LoadOptions
LoadOptionsDone:
; Initialize panel text printing
lda #9
sta textLeftMargin
lda #REDRAW_ITEM+REDRAW_AMMO+REDRAW_SCORE
sta panelUpdateFlags
;Initialize the sprite multiplexing system
InitSprites: ldx #MAX_SPR
lda #$01
sta temp1
ISpr_Loop: txa
sta sprOrder,x
lda #$ff
sta sprY,x
cpx #MAX_SPR
beq ISpr_OrValueOk
lda temp1
sta sprOrTbl,x
sta sprOrTbl+MAX_SPR,x
eor #$ff
sta sprAndTbl,x
sta sprAndTbl+MAX_SPR,x
asl temp1
bne ISpr_OrValueOk
lda #$01
sta temp1
ISpr_OrValueOk: dex
bpl ISpr_Loop
ldx #MAX_CACHESPRITES-1
ISpr_ClearCacheInUse:
lda #$00
sta cacheSprAge,x
lda #$ff
sta cacheSprFile,x
dex
bpl ISpr_ClearCacheInUse
sta sprFileNum
; Setup memory allocation and preloaded sprites
lda #<fileAreaStart
sta freeMemLo
lda #>fileAreaStart
sta freeMemHi
ldx #2
ISpr_Preloaded: lda preloadedLo,x
sta fileLo+C_COMMON,x
sta zpDestLo
sta zpBitsLo
lda preloadedHi,x
sta zpDestHi
sta zpBitsHi
sta fileHi+C_COMMON,x
lda preloadedNumObjects,x
sta fileNumObjects+C_COMMON,x
txa
clc
adc #C_COMMON
tay
stx temp1
jsr LF_Relocate3
ldx temp1
dex
bpl ISpr_Preloaded
; Fade out loading music now
lda fastLoadMode
beq InitVideo
FadeMusicLoop: lda musicData+$8c
beq InitVideo
dec musicData+$8c
ldx #$06
FadeMusicDelay: jsr WaitBottom
dex
bne FadeMusicDelay
bpl FadeMusicLoop
; Initialize video registers and screen memory
InitVideo: jsr WaitBottom
jsr InitScroll
sta newFrame
sta firstSortSpr
sta screen
sta $d011
sta $d01b ;Sprites on top of BG
sta $d01d ;Sprite X-expand off
sta $d017 ;Sprite Y-expand off
sta $d026 ;Set sprite multicolors
lda #$0a
sta $d025
lda #$ff ;Set all sprites multicolor
sta $d01c
ldx #$10
IVid_SpriteY: dex
dex
sta $d001,x ;Set all sprites on & to the bottom
bne IVid_SpriteY
sta $d015 ;All sprites on and to the bottom
jsr WaitBottom ;(some C64's need to "warm up" sprites
;to avoid one frame flash when they're
stx $d015 ;actually used for the first time)
IVid_CopyTextChars:
lda textCharsCopy,x
sta textChars+$100,x
lda textCharsCopy+$100,x
sta textChars+$200,x
lda textCharsCopy+$200,x
sta textChars+$300,x
inx
bne IVid_CopyTextChars
ldx #79
IVid_InitScorePanel:
lda scorePanelColors,x
sta colors+PANELROW*40,x
dex
bpl IVid_InitScorePanel
lda #ITEM_FISTS ;Show fists even before game start
sta itemIndex
; Initialize raster IRQs
; Relies on loader init to have already disabled the timer interrupt
InitRaster: sei
ldy #$35
sty irqSave01
dey
sty $01
lda #$00
ldx #$3f
IR_EmptySprite: sta emptySprite,x ;Clear the data of the empty sprite
dex
bpl IR_EmptySprite
inc $01
sta $d01a ;IRQs disabled until screen is ready to be shown
lda #<Irq1 ;Set initial IRQ vector
sta $fffe
lda #>Irq1
sta $ffff
lda #IRQ1_LINE ;Line where next IRQ happens
sta $d012
lda fastLoadMode ;If not using serial fastloading, disable MinSprY/MaxSprY writing
bmi IR_UseFastLoad
lda #$2c
sta Irq1_StoreMinSprY
sta Irq1_StoreMaxSprY
IR_UseFastLoad: cli
; Initializations are complete. Start the main program
lda #<EP_TITLE ;Load and execute the title screen
ldx #>EP_TITLE
ldy #$00
jmp ExecScriptParam
NoTurboCode: jmp Irq6_LevelUpdate
; Scorepanel color data (overwritten)
scorePanelColors:
dc.b 11
ds.b 7,1
dc.b 11
ds.b 22,1
dc.b 11
ds.b 7,1
dc.b 11
ds.b 9,11
dc.b 8
ds.b 7,15
dc.b 11
ds.b 4,1
dc.b 11
dc.b 8
ds.b 7,15
ds.b 9,11
; Scorepanel chars & scorepanel screen data (overwritten)
textCharsCopy: incbin bg/scorescr.chr
ds.b 40,32
dc.b 103
ds.b 7,32
dc.b 103
ds.b 22,32
dc.b 103
ds.b 7,32
dc.b 103
dc.b 96
ds.b 7,97
dc.b 98
dc.b 120
ds.b 7,122
dc.b 99
ds.b 4,32
dc.b 100
dc.b 121
ds.b 7,122
dc.b 101
ds.b 7,97
dc.b 102
incbin bg/healthbar.chr
ds.b 8,EMPTYSPRITEFRAME
; Preloaded spritefile data
preloadedLo: dc.b <sprCommon, <sprItem, <sprWeapon
preloadedHi: dc.b >sprCommon, >sprItem, >sprWeapon
preloadedNumObjects:
incbin sprcommon.hdr
incbin spritem.hdr
incbin sprweapon.hdr
org scriptCodeEnd