/[projet1]/users/twilighte/Stormlord/CommonRoutines.s
Defence Force logotype

Contents of /users/twilighte/Stormlord/CommonRoutines.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 412 - (show annotations)
Thu Oct 7 20:50:23 2010 UTC (8 years, 3 months ago) by dbug
File size: 8122 byte(s)
Added Stormlord
1 ;CommonRoutines.s
2
3 AddGraphic
4 clc
5 adc graphic
6 sta graphic
7 lda graphic+1
8 adc #00
9 sta graphic+1
10 rts
11
12 nlScreen lda screen
13 clc
14 adc #40
15 sta screen
16 lda screen+1
17 adc #00
18 sta screen+1
19 rts
20
21 nlBgbuff lda bgbuff
22 clc
23 adc #40
24 sta bgbuff
25 lda bgbuff+1
26 adc #00
27 sta bgbuff+1
28 rts
29
30 ;Sunmoon is 4x64(256)
31 ;But window is 4x15
32 ;Display rolling Sun Moon graphic (in steps of 2 rows at a time to keep colour sync)
33 UpdateSunMoon
34 lda usm_SunMoonYPos
35 clc
36 adc #2
37 and #63
38 sta usm_SunMoonYPos
39 sta usm_RowIndex
40
41 ;If bonus level (MapX==237) then end level on ypos==32
42 lda MapX
43 cmp #237
44 .(
45 bne skip1
46 lda usm_SunMoonYPos
47 cmp #32
48 bcs EndOfBonusLevel
49 jmp skip2
50
51 skip1 ;If Normal level then game over on ypos==00
52
53 lda usm_SunMoonYPos
54 beq TimeOut
55
56 skip2
57 .)
58 UpdateSunMoon_Cont
59 lda #<$A1ED+150*40
60
61 sta usm_screen
62 lda #>$A1ED+150*40
63 sta usm_screen+1
64
65 ldx #15
66 .(
67 loop2 lda usm_RowIndex
68 asl
69 asl
70 adc #<ScorePanelSunMoon
71 sta usm_graphic
72 lda #>ScorePanelSunMoon
73 adc #00
74 sta usm_graphic+1
75
76 ldy #3
77 loop1 lda (usm_graphic),y
78 sta (usm_screen),y
79 dey
80 bpl loop1
81
82 lda usm_RowIndex
83 adc #1
84 and #63
85 sta usm_RowIndex
86 lda usm_screen
87 adc #40
88 sta usm_screen
89 lda usm_screen+1
90 adc #00
91 sta usm_screen+1
92
93 dex
94 bne loop2
95 .)
96 rts
97
98 EndOfBonusLevel
99 ;We're in IRQ here so we must flag main loop
100 lda #GAME_ENDOFBONUS
101 sta GameAction
102 jmp UpdateSunMoon_Cont
103 TimeOut
104 ;We're in IRQ here so we must flag main loop
105 lda #GAME_OUTOFTIME
106 sta GameAction
107 jmp UpdateSunMoon_Cont
108
109
110
111
112 ;A Score to add
113 ;Score is held as 6 digit bcd(3 byte MSB to LSB) but display only handles 5 digit
114 AddScore
115 sed
116 clc
117 ldx #2
118 .(
119 loop1 adc HeroScore,x
120 sta HeroScore,x
121 lda #00
122 dex
123 bpl loop1
124 .)
125 cld
126 rts
127
128 DisplayScore
129 ldx #02
130 .(
131 loop1 lda HeroScore,x
132 and #15
133 ldy LowScoreDigitOffset,x
134 jsr DisplayScoreDecimalDigit
135 cpx #00
136 beq skip1
137 lda HeroScore,x
138 lsr
139 lsr
140 lsr
141 lsr
142 ldy HighScoreDigitOffset,x
143 jsr DisplayScoreDecimalDigit
144 skip1 dex
145 bpl loop1
146 .)
147 rts
148
149 ;A Digit Value 00-09
150 ;X
151 ;Y Screen Offset to digit
152 DisplayScoreDecimalDigit
153 .(
154 stx vector1+1
155 tax
156 lda DecimalGraphicRow0,x
157 eor #128+63
158 sta $A000+18+165*40,y
159 lda DecimalGraphicRow1,x
160 sta $A000+18+166*40,y
161 lda DecimalGraphicRow2,x
162 eor #128+63
163 sta $A000+18+167*40,y
164 lda DecimalGraphicRow3,x
165 sta $A000+18+168*40,y
166 lda DecimalGraphicRow4,x
167 eor #128+63
168 sta $A000+18+169*40,y
169 lda DecimalGraphicRow5,x
170 sta $A000+18+170*40,y
171 lda DecimalGraphicRow6,x
172 eor #128+63
173 sta $A000+18+171*40,y
174 lda DecimalGraphicRow7,x
175 sta $A000+18+172*40,y
176 lda DecimalGraphicRow8,x
177 eor #128+63
178 sta $A000+18+173*40,y
179 lda DecimalGraphicRow9,x
180 sta $A000+18+174*40,y
181 vector1 ldx #00
182 .)
183 rts
184
185 DisplayHighscore
186 ;Convert Highscore BCD to 5 digit 4 bit sequence
187 ldx #2
188 ldy #4
189 .(
190 loop1 lda HighScore,x
191 and #15
192 sta HighScoreDigits,y
193 lda HighScore,x
194 lsr
195 lsr
196 lsr
197 lsr
198 dey
199 bmi skip1
200 sta HighScoreDigits,y
201 dey
202 dex
203 bpl loop1
204 skip1 ;First digit is Difficulty
205 .)
206
207 ;Now display the sequence
208 ldy #4
209 .(
210 loop1 ldx HighScoreDigits,y
211 lda DecimalGraphicRow0,x
212 ; eor #128+63
213 sta $A000+20+108*40,y
214 lda DecimalGraphicRow1,x
215 sta $A000+20+109*40,y
216 lda DecimalGraphicRow2,x
217 ; eor #128+63
218 sta $A000+20+110*40,y
219 lda DecimalGraphicRow3,x
220 sta $A000+20+111*40,y
221 lda DecimalGraphicRow4,x
222 ; eor #128+63
223 sta $A000+20+112*40,y
224 lda DecimalGraphicRow5,x
225 sta $A000+20+113*40,y
226 lda DecimalGraphicRow6,x
227 ; eor #128+63
228 sta $A000+20+114*40,y
229 lda DecimalGraphicRow7,x
230 sta $A000+20+115*40,y
231 lda DecimalGraphicRow8,x
232 ; eor #128+63
233 sta $A000+20+116*40,y
234 lda DecimalGraphicRow9,x
235 sta $A000+20+117*40,y
236 dey
237 bpl loop1
238 .)
239 rts
240
241 HighScoreDigits
242 .dsb 5,0
243 ;First Score Digit is at +$26A
244 ;Lives are at +$377
245 ;Captured at +$392
246 ;Required at +$394
247 DecimalGraphicRow0
248 .byt $5C,$58,$5C,$5C,$70,$7E,$5C,$7E,$5C,$5C
249 DecimalGraphicRow1
250 .byt $76,$58,$76,$76,$70,$76,$76,$46,$76,$76
251 DecimalGraphicRow2
252 .byt $76,$58,$46,$46,$76,$70,$70,$46,$76,$76
253 DecimalGraphicRow3
254 .byt $76,$58,$4C,$46,$76,$70,$70,$4C,$76,$76
255 DecimalGraphicRow4
256 .byt $76,$58,$4C,$5C,$7E,$7C,$7C,$4C,$5C,$5E
257 DecimalGraphicRow5
258 .byt $76,$58,$58,$46,$46,$46,$76,$58,$76,$46
259 DecimalGraphicRow6
260 .byt $76,$58,$58,$46,$46,$46,$76,$58,$76,$46
261 DecimalGraphicRow7
262 .byt $76,$58,$70,$46,$46,$76,$76,$70,$76,$46
263 DecimalGraphicRow8
264 .byt $76,$58,$76,$76,$46,$76,$76,$70,$76,$46
265 DecimalGraphicRow9
266 .byt $5C,$58,$7E,$5C,$46,$5C,$5C,$70,$5C,$46
267
268 DisplayLives
269 ldx HeroLives
270 lda DecimalGraphicRow0,x
271 eor #128+63
272 sta $A000+7+172*40
273 lda DecimalGraphicRow1,x
274 sta $A000+7+173*40
275 lda DecimalGraphicRow2,x
276 eor #128+63
277 sta $A000+7+174*40
278 lda DecimalGraphicRow3,x
279 sta $A000+7+175*40
280 lda DecimalGraphicRow4,x
281 eor #128+63
282 sta $A000+7+176*40
283 lda DecimalGraphicRow5,x
284 sta $A000+7+177*40
285 lda DecimalGraphicRow6,x
286 eor #128+63
287 sta $A000+7+178*40
288 lda DecimalGraphicRow7,x
289 sta $A000+7+179*40
290 lda DecimalGraphicRow8,x
291 eor #128+63
292 sta $A000+7+180*40
293 lda DecimalGraphicRow9,x
294 sta $A000+7+181*40
295 rts
296
297 DisplayCapturedFairies
298 ldx HeroCapturedFairies
299 lda DecimalGraphicRow0,x
300 sta $A000+34+172*40
301 lda DecimalGraphicRow1,x
302 sta $A000+34+173*40
303 lda DecimalGraphicRow2,x
304 sta $A000+34+174*40
305 lda DecimalGraphicRow3,x
306 sta $A000+34+175*40
307 lda DecimalGraphicRow4,x
308 sta $A000+34+176*40
309 lda DecimalGraphicRow5,x
310 sta $A000+34+177*40
311 lda DecimalGraphicRow6,x
312 sta $A000+34+178*40
313 lda DecimalGraphicRow7,x
314 sta $A000+34+179*40
315 lda DecimalGraphicRow8,x
316 sta $A000+34+180*40
317 lda DecimalGraphicRow9,x
318 sta $A000+34+181*40
319 rts
320
321 DisplayRequiredFairies
322 ldx HeroRequiredFairies
323 lda DecimalGraphicRow0,x
324 sta $A000+36+172*40
325 lda DecimalGraphicRow1,x
326 sta $A000+36+173*40
327 lda DecimalGraphicRow2,x
328 sta $A000+36+174*40
329 lda DecimalGraphicRow3,x
330 sta $A000+36+175*40
331 lda DecimalGraphicRow4,x
332 sta $A000+36+176*40
333 lda DecimalGraphicRow5,x
334 sta $A000+36+177*40
335 lda DecimalGraphicRow6,x
336 sta $A000+36+178*40
337 lda DecimalGraphicRow7,x
338 sta $A000+36+179*40
339 lda DecimalGraphicRow8,x
340 sta $A000+36+180*40
341 lda DecimalGraphicRow9,x
342 sta $A000+36+181*40
343 rts
344
345 DisplayHeldObject
346 lda #00
347 ldy HeroHolding
348 .(
349 bmi skip1
350 lda ObjectsMapCode-4,y
351 skip1 sta MomentaryBlock
352 .)
353 lda #23
354 sta dm_CursorX
355 lda #22
356 sta dm_CursorY
357 jsr PlotBlock2Screen
358 lda MomentaryBlock
359 .(
360 beq skip1
361 inc MomentaryBlock
362 skip1 lda #25
363 .)
364 sta dm_CursorX
365 jmp PlotBlock2Screen
366
367 EraseDisplayedObject
368 lda #00
369 sta MomentaryBlock
370 lda #23
371 sta dm_CursorX
372 lda #22
373 sta dm_CursorY
374 jsr PlotBlock2Screen
375 lda #25
376 sta dm_CursorX
377 jmp PlotBlock2Screen
378
379
380
381
382 ;40
383 ;Fetch unique MapID based on Level and MapX
384 ;FetchUniqueMapID
385 ; ;MapX/14
386 ; lda MapX
387 ; ldy #00
388 ; sec
389 ;.(
390 ;loop1 iny
391 ; sbc #14
392 ; bcs loop1
393 ;.)
394 ; tya
395 ; and #15
396 ;
397 ; ;Fetch
398 ;.(
399 ; sta vector1+1
400 ; lda LevelID
401 ; asl
402 ; asl
403 ; asl
404 ; asl
405 ;vector1 ora #00
406 ;.)
407 ; tay
408 ; rts
409
410 GetRandomNumber
411 lda rndRandom+1
412 sta rndTemp
413 lda rndRandom
414 asl
415 rol rndTemp
416 asl
417 rol rndTemp
418 clc
419 adc rndRandom
420 adc VIA_T1CL
421 pha
422 lda rndTemp
423 adc rndRandom+1
424 sta rndRandom+1
425 pla
426 adc #$11
427 sta rndRandom
428 lda rndRandom+1
429 adc #$36
430 sta rndRandom+1
431 rts
432
433 ClearScreen
434 ;Clear Screen down to top of score panel and plot colours
435 lda #<$A000
436 sta screen
437 lda #>$A000
438 sta screen+1
439 ldx #150
440 .(
441 loop2 ldy #39
442 lda #$40
443 loop1 sta (screen),y
444 dey
445 bne loop1
446 lda #7
447 ldy Option_Screen
448 bne skip2
449 txa
450 lsr
451 lda #6
452 bcc skip2
453 lda #3
454 skip2 ldy #00
455 sta (screen),y
456 jsr nlScreen
457 dex
458 bne loop2
459 .)
460 ;Also clear BGBUFF
461 lda #<BackgroundBuffer
462 sta bgbuff
463 lda #>BackgroundBuffer
464 sta bgbuff+1
465 ldx #108
466 .(
467 loop2 ldy #39
468 lda #64
469 loop1 sta (bgbuff),y
470 dey
471 bne loop1
472 jsr nlBgbuff
473 dex
474 bne loop2
475 .)
476 ;Clear top of screen
477
478 rts

  ViewVC Help
Powered by ViewVC 1.1.26