-
Notifications
You must be signed in to change notification settings - Fork 5
/
PALSTUFF.ASM
565 lines (455 loc) · 10.3 KB
/
PALSTUFF.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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
**************************************************************
*
* INITIATED: APRIL 13,1989
* SOFTWARE: MARK TURMELL
*
* MODIFIED: Shawn Liptak, 7/23/91 -New FADEIN/OUT
* Shawn Liptak, 7/28/91 -Merged with fbstuff
*
* COPYRIGHT (C) 1991 WILLIAMS ELECTRONICS GAMES, INC.
*
**************************************************************
.TITLE 'PALSTUFF.ASM'
.FILE 'PALETTE FADER CONTROL'
.WIDTH 132
.OPTION B,D,L,T
.MNOLIST
.INCLUDE "MPROC.EQU" ;MPROC EQUATES
.INCLUDE "DISP.EQU" ;DISPLAY PROC. EQUATES
.INCLUDE "\VIDEO\SYS\SYS.INC" ;Z UNIT SYSTEM EQUATES
.INCLUDE "BGNDTBL.GLO"
.INCLUDE "IMGTBL.GLO"
.INCLUDE "GAME.EQU"
.include "shawn.hdr" ;Macros
;SYMBOLS EXTERNALLY DEFINED
.REF GETFPAL,PALSET,UNGETPAL,DELPAL,FINDPAL,RANGRAND
.REF IRQSKYE,REACTR,RANDPER
.REF PALSET,PALRAM,EXP2
;SYMBOLS DEFINED IN THIS FILE
.DEF PUMP_RED,COUNT,PUMP_CLDS
.DEF BLAKOUT
.DEF FB_FADEOUT,FB_FADEIN
;EQUATES FIRST ORIGINATED IN THIS FILE
FPALNUM .equ 8
FPALSZ .equ 65*16
;UNINITIALIZED RAM DEFINITIONS
.BSS FADERAM ,FPALSZ*FPALNUM ;Fade mem for palettes
.BSS COUNT ,16
.BSS KPBASE ,32
.bss irqskyeo,16 ;Orignal autoerase color
********************************
* BLAKOUT - BLACK OUT SELECTED PALETTE
* A0=NAME OF PALETTE TO BLACK OUT
BLAKOUT
CALLA FINDPAL
SLL 8,A0
MOVE A0,A1
JRZ NOTALLOC
MOVI FADERAM,A0
MOVI 128,A3
CLR A2
CLRBLP MOVE A2,*A0+,L
DSJS A3,CLRBLP
MOVI FADERAM,A0 ;NOW BLACK OUT PALETTE
MOVI 256,A2
CALLA PALSET ;ERASE PALETTE SLOT
NOTALLOC
RETS
********************************
* CLOUDS BEHIND REPORTER
* PUMP_RED PROCESS
* CYCLE NUCLEAR REACTORS
PUMP_CLDS
SLEEP 3
MOVI EXP2,A0
CALLA ONESND
MOVI CLDSZ,A0
MOVE A0,@KPBASE,L
CALLA FINDPAL
JRZ CREDOUT
SLL 8,A0
MOVE A0,A11 ;NEEDED LATER FOR PALSET
MOVK 7,A10 ;PUMP RED A10 TIMES
MOVI 128,A8
CEDLOOP MOVI FADERAM,A0
ADDK 20H,A8
CALLR DO_MULT
SLEEP 1
DSJ A10,CEDLOOP
CREDOUT
MOVK 7,A10 ;PUMP RED A10 TIMES
CRED2 MOVI FADERAM,A0
SUBI 20H,A8
CALLR DO_MULT
SLEEP 1
DSJ A10,CRED2
MOVI 700,A0
CALLA RANDPER
JRNC PUMP_CLDS
MOVK 10,B0
MOVI 3*60,B1
CALLA RANGRAND
CALLA PRCSLP
JRUC PUMP_CLDS
********************************
* PUMP_RED PROCESS, CYCLE NUCLEAR REACTORS
PUMP_RED
SLEEP 18H
MOVI REACTR,A0
MOVE A0,@KPBASE,L
CALLA FINDPAL
JRZ REDOUT
SLL 8,A0
MOVE A0,A11 ;NEEDED LATER FOR PALSET
MOVI 25,A10 ;PUMP RED A10 TIMES
MOVI 128,A8
REDLOOP MOVI FADERAM,A0
ADDK 10H,A8
CALLR DO_MULT
SLEEP 1
DSJ A10,REDLOOP
REDOUT
MOVK 25,A10 ;PUMP RED A10 TIMES
RED2 MOVI FADERAM,A0
SUBI 10H,A8
CALLR DO_MULT
SLEEP 1
DSJ A10,RED2
JRUC PUMP_RED
DO_MULT
MOVE A8,A2
MMTM SP,A8,A10,A11
; ADDI 32,A0 ;GET TO FIRST COLOR PAST 0
; MOVI 63,A9
;NEXCLR MOVE *A0,A1,W
; ZEXT A1,W
; SRL 10,A1 ;GET RED BITS
MOVE @KPBASE,A1,L ;REACTR,A1
;PARAMS
; A0 - DEST RAM FOR PAL
; A1 - SRC FOR PAL
; A2 - COLOR MULTIPLIER
; EACH COLOR IN PALETTE WILL BE MULTIPLIED BY A2 THEN DIVIDED BY 128
; MMTM SP,A0,A1,A3,A4,A5,A6,A7,A8,A9,A10,A11,A14
MOVE *A1+,A14,W
MOVE A14,*A0+,W
SLL 23,A14 ;TOP BITS OF FIELD ARE FLAGS
SRL 23,A14 ;ONLY 9 BITS NEEDED FOR # COLORS
MOVI >7C00,A4 ;A4 - PRE MULT MASK FOR 5 BITS OF RED
; MOVI >03E0,A6 ;A6 - PRE MULT MASK FOR 5 BITS OF GREEN
; MOVI >001F,A8 ;A8 - PRE MULT MASK FOR 5 BITS OF BLUE
MOVE A4,A9
; MOVE A6,A10
; MOVE A8,A11
SLL 7,A9 ; A9 - POST MULT MAX FOR 5 BITS OF RED
; SLL 7,A10 ;A10 - POST MULT MAX FOR 5 BITS OF GREEN
; SLL 7,A11 ;A11 - POST MULT MAX FOR 5 BITS OF BLUE
FADELPR:
MOVE *A1+,A3,W ;A3 - RED
MOVE A3,A5
ANDI 03FFH,A5
; MOVE A3,A5 ;A5 - GREEN
; MOVE A3,A7 ;A7 - BLUE
AND A4,A3
CMPI 1001H,A3
JRC REDOKR
; AND A6,A5
; AND A8,A7
MPYU A2,A3
; MPYU A2,A5
; MPYU A2,A7
CMP A9,A3
JRLE REDOKR
MOVE A9,A3
REDOKR:
; CMP A10,A5
; JRLE GREENOK
; MOVE A10,A5
;GREENOK:
; CMP A11,A7
; JRLE BLUEOK
; MOVE A11,A7
;BLUEOK:
AND A9,A3
SRL 7,A3
; AND A10,A5
OR A5,A3
; OR A7,A3
; SRL 7,A3
MOVE A3,*A0+,W
DSJS A14,FADELPR
; MMFM SP,A0,A1,A3,A4,A5,A6,A7,A8,A9,A10,A11,A14
; RETS
; CMPI 31,A1
; JRZ ROUT
; CMPI 6,A1
; JRC ROUT
; INC A1
; SLL 10,A1
; MOVE *A0,A2,W
; ANDI 03FFH,A2
; OR A1,A2
; MOVE A2,*A0,W
;ROUT ADDI 16,A0
; DSJS A9,NEXCLR
*SETUP PALETTE TRANSFER
*CALLING PARAMETERS:
*A0= PALSRC = 32 BIT SOURCE ADDRESS OF PALETTE COLOR DATA
*A1= PALDEST = BIT 8-15 DESTINATION PALETTE | BIT 0-7 START COLOR
*A2= PLDCNT = 16 BIT COLOR COUNT
*RETURNS: EQ IF UNABLE TO SETUP TRANSFER, NE IF TRANSFER O.K.
MMFM SP,A8,A10,A11
MOVI FADERAM,A0
MOVE A11,A1
MOVE *A0+,A2
CALLA PALSET
RETS
********************************
* FADEIN - Fade in all selected palettes from black
*
* A0=*Palette list to fade in (autoerase + 0-8 pals)
* A1=Fade delay in ticks
* If 1st entry not neg then it enables autoerase fading
SUBR FADEIN
move a0,a9 ;A9=*Palette list
move a1,a10 ;A10=Fade delay
CREATE 0,fadein
rets
fadein
move a13,a6
addi PDATA,a6
movk FPALNUM,a7
move a9,a11
move *a11+,a0,L ;!-=Autoerase color
jrn fi30
move a0,@irqskyeo ;Save color
fi20 move *a11+,a0,L ;Get * palette
jrz fi70 ;0=End
fi30 calla FINDPAL
jrz fi60
not a0 ;Make neg
fi60 sll 8,a0
move a0,*a6+ ;Save palette #
dsj a7,fi20
fi70 clr a8 ;A8=Brightness
fi100 addk 8,a8
movi FADERAM,a5
move a13,a6
addi PDATA,a6
movk FPALNUM,a7
move a9,a11
move *a11,a1,L
jrn fi200
addk 32,a11
move a8,a2
callr FADEPALAE
fi200 move *a11+,a1,L
jrz fi400
move a5,a0
move a8,a2
callr FADEPAL
move a5,a0 ;*Palette colors
move *a6+,a1 ;Palette #
cmpi -256,a1 ;FF00
jrz fi230
move *a0+,a2 ;#Colors
calla PALSET
fi230 addi FPALSZ,a5
dsj a7,fi200
fi400 move a10,a0
calla PRCSLP
cmpi 128,a8
jrlo fi100
fi800 DIE
********************************
* FADEOUT - Fade out all selected palettes to black
*
* A0=*Palette list to fade out (autoerase + 0-8 pals)
* A1=Fade delay in ticks
* If 1st entry not neg then it enables autoerase fading
SUBR FADEOUT
clr a10
move a10,@COUNT
SUBR FADEOUT2
move a0,a9 ;A9=*Palette list
move a1,a10 ;A10=Fade delay
CREATE 0,fadeout
rets
fadeout
move a13,a6
addi PDATA,a6
movk FPALNUM,a7
move a9,a11
move *a11+,a0,L ;!-=Autoerase color
jrn fo30
move @IRQSKYE,a0 ;Save color
move a0,@irqskyeo
fo20 move *a11+,a0,L ;Get * palette
jrz fo70 ;0=End
fo30 calla FINDPAL
jrnz fo60
not a0 ;Make neg
fo60 sll 8,a0
move a0,*a6+ ;Save palette #
dsj a7,fo20
fo70 movi 128,a8 ;A8=Brightness
fo100 subk 8,a8
movi FADERAM,a5
move a13,a6
addi PDATA,a6
movk FPALNUM,a7
move a9,a11
move *a11,a1,L
jrn fo200
addk 32,a11
move a8,a2
callr FADEPALAE
fo200 move *a11+,a1,L
jrz fo400
move a5,a0
move a8,a2
callr FADEPAL
move a5,a0 ;*Palette colors
move *a6+,a1 ;Palette #
cmpi -256,a1 ;FF00
jrz fo230
move *a0+,a2 ;#Colors
calla PALSET
fo230 addi FPALSZ,a5
dsj a7,fo200
fo400 move a10,a0
calla PRCSLP
move @COUNT,a0
cmp a0,a8
jrgt fo100
fo800 DIE
********************************
* Fade autoerase color
SUBRP FADEPALAE ;A2=Brightness (0-128)
PUSH a3,a4,a5,a6,a7,a8,a9,a10,a11
movi IRQSKYE,a0
movi irqskyeo,a1
movk 1,a14
jruc fp20
********************************
* Fade a palette
* Each color in palette will be multiplied by a2 then divided by 128
* A0=*Ram for pal, A1=*Palette, A2=Brightness (0-128)
SUBRP FADEPAL
PUSH a3,a4,a5,a6,a7,a8,a9,a10,a11
move *a1+,a14 ;# Colors
move a14,*a0+
fp20 sll 23,a14 ;Remove any flags
srl 23,a14 ;9 bits needed for # colors
movi >7c00,a4 ;A4=Mask for 5 bits of red
movi >03e0,a6 ;A6=Mask for 5 bits of green
movk >1f,a8 ;A8=Mask for 5 bits of blue
move a4,a9
move a6,a10
move a8,a11
sll 7,a9 ;A9=post mult max for 5 bits of red
sll 7,a10 ;A10=post mult max for 5 bits of green
sll 7,a11 ;A11=post mult max for 5 bits of blue
fp100 move *a1+,a3
move a3,a5 ;A3=Red
move a3,a7 ;A5=Green
and a4,a3 ;A7=Blue
and a6,a5
and a8,a7
mpyu a2,a3
mpyu a2,a5
mpyu a2,a7
cmp a9,a3
jrle redok
move a9,a3
redok cmp a10,a5
jrle greenok
move a10,a5
greenok cmp a11,a7
jrle blueok
move a11,a7
blueok and a9,a3
and a10,a5
or a5,a3
or a7,a3
srl 7,a3
move a3,*a0+ ;Save color
dsj a14,fp100
PULL a3,a4,a5,a6,a7,a8,a9,a10,a11
rets
**************************************************************************
* FADEIN - Fade a list of palettes from black to their current colors
* A0=*List NOT to fade or 0
FB_FADEIN
mmtm sp,a0,a1,a2,a6,a7,a8,a9,a10
movk 8,a10
jruc fbf10
**************************************************************************
* FADEOUT - Fade a list of palettes down to black
* A0=*List NOT to fade or 0
FB_FADEOUT
mmtm sp,a0,a1,a2,a6,a7,a8,a9,a10
movi -8,a10
fbf10 move a0,a6
;Start proc to fade each palette
clr a9 ;palette slot
movi PALRAM,A2 ;A2=*Palette table
fbf20 move *A2(PALCNT),A1 ;Is palette allocated?
jrz fbf70
move *A2(PALID),A8,L ;Ptr to palette
move A6,A7 ;A6=*List of palettes to skip
jrz fbf60
fbf50 move *A7+,A1,L
jrz fbf60
cmp A1,A8
jreq fbf70 ;Skip pal?
jruc fbf50
fbf60 CREATE 0,fadeonep
fbf70 addi PALRSIZ,A2
addk 1,a9
cmpi NUMPAL,A9
jrlt fbf20
fbfx mmfm sp,a0,a1,a2,a6,a7,a8,a9,a10
rets
**************************************************************************
* fadeonep - Fade one palette (Process)
*
* A8=*Palette to be faded
* A9=Palette slot #
* A10=Add value per fade (!0)
fadeonep
sll 24,a9 ;B8-15 dest pal | B0-7 start color
srl 16,a9
.if YUNIT
move a9,a2
srl 12,a2
sll 14,a2
sll 20,a9
srl 20,a9
add a2,a9
.endif
clr a11 ;For up fade
move a10,a10
jrgt fop20
movi 128,a11 ;For dn fade
fop20
;Set up faded pal in process data space
foplp add a10,a11
cmpi 128,a11
jrhi fopx
move a11,a2 ;A2=Color Multiplier
move a13,a0
addi PDATA,a0 ;A0=Dest Ram for Pal
move a0,a5
move a8,a1 ;A1=Src for Pal
callr FADEPAL
move a5,a0 ;>Move faded palette to palram
move a9,a1
move *a0+,a2 ;Get # colors in palette
calla PALSET ;Set transfer
SLEEP 2
jruc foplp
fopx SLEEP 1 ;give last xfer a chance to go
DIE
.end