-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswscroller.c
549 lines (446 loc) · 15.8 KB
/
swscroller.c
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
#include "swscroller.h"
#include "support/gcc8_c_support.h"
#include <proto/exec.h>
#include <proto/graphics.h>
#include <exec/execbase.h>
#include <hardware/custom.h>
//#include "utilsasm.h"
#include <hardware/intbits.h>
#include "utils.h"
#define BPLSIZE 80*257
#define BPLDEPTH 1
#define ZMCPSIZE 340*4
#define COPBPL1HIGH 57
#define COPBPL1LOW 59
#define COPBPL2HIGH 61
#define COPBPL2LOW 63
#define COPBPL3HIGH 65
#define COPBPL3LOW 67
#define COPCOLOR 68
#define COPCOLORDIM 72
ULONG *Sw_ScreenBuffer2;
ULONG *Sw_ScreenBuffer1;
UWORD *Sw_DrawBuffer;
UWORD *Sw_ViewBufferP1;
UWORD *Sw_ViewBufferP2;
UWORD *Sw_ViewBufferP3;
UWORD SwScrollerFinished = 0;
volatile UWORD FrameCountBufferDraw = 2;
volatile UWORD Sw_BlitFrame = 0;
UWORD *Sw_ViewCopper;
UWORD *Sw_DrawCopper;
UWORD *Sw_FontBuffer;
UWORD *Sw_XMaskLeft;
UWORD *Sw_XMaskRight;
UBYTE *Sw_ClColorDim;
//INCBIN( Sw_ClColorDim, "data/swscroller/clcolordim.raw")
UWORD *Sw_font;
ULONG Sw_ClsSprites[] = { 0x001200000, 0x001220000,0x001240000,0x001260000, 0x001280000,
0x0012a0000, 0x0012c0000, 0x0012e0000, 0x001300000, 0x001320000, 0x001340000,
0x001360000, 0x001380000, 0x0013a0000, 0x0013c0000, 0x0013e0000 };
ULONG Sw_ClScreen[] = { 0x001fc0000, 0x001060000, 0x0009683f0, 0x0008e2c81, 0x000902ac1,
0x00092003c, 0x0009400d4, 0x001020000, 0x001040000, 0x001080000, 0x0010a0000,
0x00100a200 };
ULONG Sw_ClColor[] = { 0x1800000,0x1820ff0,0x1840000, 0x1860ff0,
0x1800000,0x1820aa0,0x1840550, 0x1860ff0,
0x1800000,0x1820550,0x1840aa0, 0x1860ff0,
0x1800000,0x1820f00,0x1840000, 0x1860f00
};
char Sw_text[] =
"Void proudly presents "
"this Greetro from "
"Space. Too many "
"times we left out the "
"Greetings in our "
"Productions. Time to "
"fix this! Greetings go "
"to the mighty: "
" "
" ALCATRAZ "
" ANDROMEDA "
" ATLANTIS "
" BITBENDAZ "
" DEKADENCE "
" ECHTZEIT "
" GHOSTOWN "
" INSANE "
" LOGICOMA "
" NAH-KOLOR "
" PACIFIC "
" PLANET JAZZ "
" RAM JAM "
" SPACEBALLS "
" "
" AND.... "
" "
" "
" "
" "
" "
" "
" "
" "
" ";
void Sw_Run() {
Sw_WritePlainText();
Sw_DrawScreen3();
}
int Sw_framecountscreen = 0;
int Sw_framecount = 49;
int Sw_textoffset = 0;
void Sw_WritePlainText() {
if(Sw_framecount == 50) {
Sw_framecount = 0;
Utils_FillLong( (ULONG *) Sw_FontBuffer, 0, 20, 50, 0);
Utils_WriteLine( Sw_font, (ULONG) Sw_FontBuffer, Sw_text+Sw_textoffset);
Sw_textoffset += 40;
if( Sw_textoffset >= 32*40) {
Sw_textoffset = 0;
SwScrollerFinished = 1;
}
}
Sw_framecount++;
}
UWORD Sw_CopyLines[] = { 189, 54, 138, 223, 1, 119, 155, 34, 101, 206, 1, 73, 172, 22, 91, 240, 1 };
UWORD Sw_BlitFinished = 0;
void Sw_DrawScreen3() {
while ( Sw_BlitFrame == 0)
{
}
int *bp = 0x200;
*bp = 0;
Sw_BlitFinished = 0;
Sw_BlitFrame = 0;
//Prepare
WaitBlit();
custom->bltamod = 0;
custom->bltbmod = 0;
custom->bltdmod = 0;
custom->bltafwm = 0xffff;
custom->bltalwm = 0xffff;
custom->bltcon1 = 0;
custom->bltcon0 = 0x09f0;
//Fontblit
custom->bltapt = (void *) ((ULONG) Sw_FontBuffer+80*(Sw_framecount-1));
custom->bltdpt = Sw_DrawBuffer+40*255;
custom->bltsize = 64+40;
//Copy
WaitBlit();
custom->bltamod = 0;
custom->bltdmod = 0;
custom->bltapt = Sw_ViewBufferP1;
custom->bltdpt = Sw_DrawBuffer;
custom->bltsize = 64*Sw_CopyLines[Sw_framecountscreen]+40;
//Generate Right Part of Screen Part 1
//Copy unaltered part to screen using Sw_XMasRight
WaitBlit();
custom->bltcon0 = 0x0d30; // No Shift, Channels A+B+D, Minterm: Set if Channel A = 1 and Channel B = 0
custom->bltafwm = 0xffff;
custom->bltamod = 40; // Skip Left Part of Screen
custom->bltdmod = 40; // Skip Left Part of Screen
custom->bltapt = Sw_ViewBufferP1+Sw_CopyLines[Sw_framecountscreen]*40+60;
custom->bltdpt = Sw_DrawBuffer+Sw_CopyLines[Sw_framecountscreen]*40+20;
ULONG bltbpd = Sw_XMaskRight;
bltbpd += Sw_CopyLines[Sw_framecountscreen]*40;
custom->bltbpt = bltbpd;
custom->bltsize = (255-Sw_CopyLines[Sw_framecountscreen])*64+20;
//Generate Right Part of Screen Part 2
//Copy moved part to screen using Sw_XMaskRight and merge with unmoved on conflicting pixel
WaitBlit();
custom->bltcon0 = 0xffea; // Shift A Channel 15 but actual -1 (Sourceline), Channels A+B+C+D, Minterm: Set if (Channel A = 1 and Channel B = 1) or Channel C = 1
custom->bltcon1 = 0xf000; // Shift B Channel 15 but actual -1 (Sourceline)
custom->bltalwm = 0xfffe;
custom->bltcmod = 38; // Skip Left Part of Screen
custom->bltbmod = -2;
custom->bltamod = 38; // Skip Left Part of Screen
custom->bltdmod = 38; // Skip Left Part of Screen
custom->bltapt = Sw_ViewBufferP1+Sw_CopyLines[Sw_framecountscreen]*40+60;
bltbpd = Sw_XMaskRight;
bltbpd += Sw_CopyLines[Sw_framecountscreen]*40;
custom->bltbpt = bltbpd;
custom->bltcpt = Sw_DrawBuffer+Sw_CopyLines[Sw_framecountscreen]*40-1+20;
custom->bltdpt = Sw_DrawBuffer+Sw_CopyLines[Sw_framecountscreen]*40-1+20;
custom->bltsize = (255-Sw_CopyLines[Sw_framecountscreen])*64+21;
//Generate Left Part of Screen Part 1
//Copy unaltered part to screen using Sw_XMaskLeft
WaitBlit();
custom->bltafwm = 0xffff;
custom->bltalwm = 0xffff;
custom->bltcon0 = 0x0d30; // No Shift, Channels A+B+D, Minterm: Set if Channel A = 1 and Channel B = 0
custom->bltbmod = 0;
custom->bltcon1 = 0;
custom->bltamod = 40; // Skip Right Part of Screen
custom->bltdmod = 40; // Skip Right Part of Screen
custom->bltapt = Sw_ViewBufferP1+Sw_CopyLines[Sw_framecountscreen]*40+40;
custom->bltdpt = Sw_DrawBuffer+Sw_CopyLines[Sw_framecountscreen]*40;
bltbpd = Sw_XMaskLeft;
bltbpd += Sw_CopyLines[Sw_framecountscreen]*40;
custom->bltbpt = bltbpd;
custom->bltsize = (255-Sw_CopyLines[Sw_framecountscreen])*64+20;
//Generate Left Part of Screen Part 2
//Copy moved part to screen using Sw_XMaskLeft and merge with unmoved on conflicting pixel
WaitBlit();
custom->bltcon0 = 0x1fea; // Shift A Channel 1 (Sourceline), Channels A+B+C+D, Minterm: Set if (Channel A = 1 and Channel B = 1) or Channel C = 1
custom->bltcon1 = 0x1000; // Shift B Channel 1
custom->bltafwm = 0x7fff;
custom->bltcmod = 40; // Skip Right Part of Screen
custom->bltamod = 40; // Skip Right Part of Screen
custom->bltdmod = 40; // Skip Right Part of Screen
custom->bltapt = Sw_ViewBufferP1+Sw_CopyLines[Sw_framecountscreen]*40+40;
bltbpd = Sw_XMaskLeft;
bltbpd += Sw_CopyLines[Sw_framecountscreen]*40;
custom->bltbpt = bltbpd;
custom->bltcpt = Sw_DrawBuffer+Sw_CopyLines[Sw_framecountscreen]*40;
custom->bltdpt = Sw_DrawBuffer+Sw_CopyLines[Sw_framecountscreen]*40;
custom->bltsize = (255-Sw_CopyLines[Sw_framecountscreen])*64+20;
WaitBlit();
Sw_BlitFinished = 1;
custom->color[0] = 0x00;
if(++Sw_framecountscreen == 17) Sw_framecountscreen = 0;
}
UWORD Sw_ClColorDimPos = 0;
UWORD Sw_ClColorDimLength = 111;
UWORD * Sw_ClBuild() {
ULONG *retval = AllocMem( ZMCPSIZE, MEMF_CHIP);
if( retval == 0) {
Write( Output(), "Allocation of Ram for Copper failed.\n", 40);
Exit(1);
}
ULONG *cl = retval;
ULONG *clpartinstruction;
clpartinstruction = Sw_ClsSprites;
for(int i=0; i<16;i++)
*cl++ = *clpartinstruction++;
clpartinstruction = Sw_ClScreen;
for(int i=0; i<12;i++)
*cl++ = *clpartinstruction++;
*cl++ = 0x00e00000;
*cl++ = 0x00e20000;
*cl++ = 0x00e40000;
*cl++ = 0x00e60000;
*cl++ = 0x00e80000;
*cl++ = 0x00ea0000;
clpartinstruction = Sw_ClColor;
for(int i=0; i<4;i++)
{
*cl++ = *clpartinstruction++;
}
clpartinstruction = Sw_ClColorDim;
for(int i=0; i<Sw_ClColorDimLength;i++)
{
*cl++ = *clpartinstruction++;
}
*cl++ = 0x20bffffe;
*cl++ = 0x009c8010;
*cl++ = 0xfffffffe;
return (UWORD *) retval;
}
struct Interrupt *Sw_Vbint;
UWORD Sw_ScreenBufferOffset = 0;
UWORD Sw_InitComplete = 0;
UWORD Sw_MusicDelay = 50;
void Sw_VblankHandler() {
custom->intreq = 0x0020;
if(Sw_MusicDelay > 0) {
Sw_MusicDelay--;
} else {
//p61Music();
}
if( Sw_InitComplete == 1) {
if( FrameCountBufferDraw == 2) {
FrameCountBufferDraw = 0;
Sw_BlitFrame = 1;
if(Sw_ScreenBufferOffset == 0) {
Sw_ScreenBufferOffset = 2;
} else {
Sw_ScreenBufferOffset = 0;
}
}
else
{
FrameCountBufferDraw++;
}
Sw_SetBplPointers();
Sw_SetColors();
}
}
ULONG *Sw_ScreenBufferList[15];
UWORD debugpal[] = { 0x0000, 0x0fff };
void Sw_LoadResources() {
BPTR filehandler = Open("font.fnt", MODE_OLDFILE);
if( filehandler == 0) {
Write(Output(), "Error loading font.fnt\n", 24);
}
Sw_font = AllocMem(38000, MEMF_CHIP);
if(Sw_font == 0) {
Write(Output(), "Cannot allocate Memory for Sw_font.\n", 37);
Exit(1);
}
ULONG readlength = Read( filehandler, Sw_font, 38000);
if( readlength == 0) {
Write(Output(), "Cannot read Sw_font.\n", 37);
Exit(1);
}
filehandler = Open("xmaskleft.raw", MODE_OLDFILE);
if( filehandler == 0) {
Write(Output(), "Error loading xmaskleft.raw\n", 29);
}
Sw_XMaskLeft = AllocMem(10240, MEMF_CHIP);
if(Sw_XMaskLeft == 0) {
Write(Output(), "Cannot allocate Memory for xmaskleft.raw\n", 42);
Exit(1);
}
readlength = Read( filehandler, Sw_XMaskLeft, 10240);
if( readlength == 0) {
Write(Output(), "Cannot read xmaskleft.raw\n", 27);
Exit(1);
}
filehandler = Open("xmaskright.raw", MODE_OLDFILE);
if( filehandler == 0) {
Write(Output(), "Error loading xmaskright.raw\n", 29);
}
Sw_XMaskRight = AllocMem(10240, MEMF_CHIP);
if(Sw_XMaskRight == 0) {
Write(Output(), "Cannot allocate Memory for xmaskleft.raw\n", 42);
Exit(1);
}
readlength = Read( filehandler, Sw_XMaskRight, 10240);
if( readlength == 0) {
Write(Output(), "Cannot read xmaskleft.raw\n", 27);
Exit(1);
}
filehandler = Open("clcolordim.raw", MODE_OLDFILE);
if( filehandler == 0) {
Write(Output(), "Error loading clcolordimg.raw\n", 29);
}
Sw_ClColorDim = AllocMem(22644, MEMF_CHIP);
if(Sw_ClColorDim == 0) {
Write(Output(), "Cannot allocate Memory for clcolordim.raw\n", 43);
Exit(1);
}
readlength = Read( filehandler, Sw_ClColorDim, 22644);
if( readlength == 0) {
Write(Output(), "Cannot read clcolordim.raw\n", 29);
Exit(1);
}
}
int Sw_PrepareDisplay() {
SwScrollerFinished = 0;
debug_register_palette( debugpal, "debug.pal", 2, 0);
Sw_FontBuffer = AllocMem( 80*50, MEMF_CHIP);
debug_register_bitmap( Sw_FontBuffer, "fontbuffer.bpl", 512, 50, 1, 0);
Utils_FillLong( (ULONG *)Sw_FontBuffer, 0x0, 50, 20,0);
Sw_ScreenBuffer2 = AllocMem(BPLSIZE*BPLDEPTH, MEMF_CHIP);
if(Sw_ScreenBuffer2 == 0) {
Write(Output(), "Cannot allocate Memory for Bitplane2.\n", 38);
Exit(1);
}
debug_register_bitmap( Sw_ScreenBuffer2, "screenbuffer2.bpl", 512, 257, 1, 0);
Utils_FillLong( (ULONG *) Sw_ScreenBuffer2, 0, 256, 20,0);
Sw_ScreenBuffer1 = AllocMem(BPLSIZE*BPLDEPTH, MEMF_CHIP);
if(Sw_ScreenBuffer1 == 0) {
Write(Output(), "Cannot allocate Memory for Bitplane2.\n", 38);
Exit(1);
}
debug_register_bitmap( Sw_ScreenBuffer1, "screenbuffer1.bpl", 512, 257, 1, 0);
Utils_FillLong( (ULONG *) Sw_ScreenBuffer1, 0, 256, 20,0);
Sw_ViewCopper = Sw_ClBuild( );
Sw_DrawCopper = Sw_ClBuild( );
Sw_SwapCl();
if ((Sw_Vbint = AllocMem(sizeof(struct Interrupt),
MEMF_PUBLIC|MEMF_CLEAR))) {
Sw_Vbint->is_Node.ln_Type = NT_INTERRUPT;
Sw_Vbint->is_Node.ln_Pri = -60;
Sw_Vbint->is_Node.ln_Name = "VertB-Example";
Sw_Vbint->is_Data = NULL;
Sw_Vbint->is_Code = Sw_VblankHandler;
}
AddIntServer( INTB_COPER, Sw_Vbint);
//SetBplPointers(); //Set Buffer 2
/*
Fr1 Fr2 Fr3 Fr4 dB bp1 bp2 bp3
66% 33% 3 2 1 1
33% 66% 3 2 2 1
0% 100% 3 2 2 2
0% 66 33 1 3 2 2
0 33 66 1 3 3 2
0 0 100 1 3 3 3
0 0 66 33 2 1 3 3
0 0 33 66 2 1 1 3
0 0 0 100 2 1 1 1
*/
Sw_ScreenBufferList[0] = Sw_ScreenBuffer1;
Sw_ScreenBufferList[1] = Sw_ScreenBuffer2;
Sw_ScreenBufferList[2] = Sw_ScreenBuffer2;
Sw_ScreenBufferList[3] = Sw_ScreenBuffer1;
Sw_InitComplete = 1;
return 0;
}
void Sw_Cleanup() {
FreeMem( Sw_ScreenBuffer1, BPLSIZE*BPLDEPTH);
FreeMem( Sw_ScreenBuffer2, BPLSIZE*BPLDEPTH);
FreeMem( Sw_FontBuffer, 80*50);
FreeMem( Sw_font, 38000);
FreeMem( Sw_XMaskLeft, 10240);
FreeMem( Sw_XMaskRight, 10240);
FreeMem( Sw_ClColorDim, 22644);
RemIntServer( INTB_COPER, Sw_Vbint);
}
void Sw_SetBplPointers() {
/* Frame Movement
Dim Full LDr LP1(Dim) LP2(Full) LDr LP1(Dim) LP2(Full)
Bf3 Bf2 Bf1
Bf3 Bf2 Bf2
Fr1 x Fr2 Fr1 x Bf1 Bf3 Bf2
x Fr1 Fr2 Fr1 Fr1 Bf1 Bf3 Bf3
Fr2 Fr1 Fr3 Fr2 Fr1 Bf2 Bf1 Bf3
x Fr2 Fr3 Fr2 Fr2 Bf2 Bf1 Bf1 (repeat)
Fr3 Fr2 Fr4 Fr3 Fr2 Bf3 Bf2 Bf1
x Fr3 Fr4 Fr3 Fr3 Bf3 Bf2 Bf2*/
Sw_DrawBuffer = (UWORD *)Sw_ScreenBufferList[Sw_ScreenBufferOffset];
Sw_ViewBufferP1 = (UWORD *)Sw_ScreenBufferList[Sw_ScreenBufferOffset+1];
Sw_ViewBufferP2 = (UWORD *)Sw_ScreenBufferList[Sw_ScreenBufferOffset+1]+40;
UWORD highword = (ULONG)Sw_ViewBufferP1 >> 16;
UWORD lowword = (ULONG)Sw_ViewBufferP1 & 0xffff;
UWORD *copword = (UWORD *) Sw_DrawCopper;
copword[COPBPL1LOW] = lowword;
copword[COPBPL1HIGH] = highword;
highword = (ULONG)Sw_ViewBufferP2 >> 16;
lowword = (ULONG)Sw_ViewBufferP2 & 0xffff;
copword[COPBPL2LOW] = lowword;
copword[COPBPL2HIGH] = highword;
}
UWORD ColPos = 0;
void Sw_ClearColors() {
ULONG *cl;
UWORD *copword = Sw_DrawCopper;
cl = (ULONG *) &copword[COPCOLOR];
*cl++ = 0x1820000;
*cl++ = 0x1840000;
*cl++ = 0x1860000;
*cl++ = 0xfffffffe;
}
void Sw_SetColors() {
ULONG *cl;
UWORD *copword = Sw_DrawCopper;
cl = (ULONG *) &copword[COPCOLOR];
for(int i=0;i<4;i++) {
*cl++ = Sw_ClColor[FrameCountBufferDraw*4+i];
}
if( ColPos == 12) {
ColPos = 0;
}
ULONG *clpartinstruction;
clpartinstruction = Sw_ClColorDim + Sw_ClColorDimPos;
Sw_ClColorDimPos += Sw_ClColorDimLength*4;
if(Sw_ClColorDimPos >= Sw_ClColorDimLength*51*4) {
Sw_ClColorDimPos = 0;
}
for(int i=0; i<Sw_ClColorDimLength;i++)
{
*cl++ = *clpartinstruction++;
}
}
void Sw_SwapCl() {
custom->cop1lc = (ULONG) Sw_DrawCopper;
}