-
Notifications
You must be signed in to change notification settings - Fork 1
/
C64Intro.c
534 lines (362 loc) · 12.8 KB
/
C64Intro.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
//Bar code from Type 79
//http://www.psxdev.net/forum/viewtopic.php?f=69&t=378
#include <sys/types.h>
#include <libps.h>
#include <stdio.h>
#include <stdlib.h> //for srand and rand
#include <string.h>
// constants for interface
#define PADLup (1<<12)
#define PADLdown (1<<14)
#define PADLleft (1<<15)
#define PADLright (1<<13)
#define PADRup (1<< 4)
#define PADRdown (1<< 6)
#define PADRleft (1<< 7)
#define PADRright (1<< 5)
#define PADi (1<< 9)
#define PADj (1<<10)
#define PADk (1<< 8)
#define PADl (1<< 3)
#define PADm (1<< 1)
#define PADn (1<< 2)
#define PADo (1<< 0)
#define PADh (1<<11)
#define PADL1 PADn
#define PADL2 PADo
#define PADR1 PADl
#define PADR2 PADm
#define PADstart PADh
#define PADselect PADk
//512 ,240, NTSC
//640 ,256 PAL
#define DISPLAY_MODE MODE_PAL
#define SCREEN_WIDTH 512
#define SCREEN_HEIGHT 256
#define ORDERING_TABLE_LENGTH 10
#define MAX_NO_PACKETS 3000
#define setRGB( xline, xr, xg, xb) (xline).r = (xr); (xline).b = (xb); (xline).g = (xg)
#define C64LINES 20
//#define DEBUG 1
#ifdef DEBUG
#define debug printf
#else
#define debug //
#endif
#define typeSpeed 25
/*
from http://www.godot64.de/german/epalet.htm
C64
Color Red Green Blue
black 0x00 0x00 0x00 1
white 0xff 0xff 0xff 2
red 0x88 0x00 0x00 3
cyan 0xaa 0xff 0xee 4
purple 0xcc 0x44 0xcc 5
green 0x00 0xcc 0x55 6
blue 0x00 0x00 0xaa 7
yellow 0xee 0xee 0x77 8
orange 0xdd 0x88 0x55 9
brown 0x66 0x44 0x00 10
l,red 0xff 0x77 0x77 11
d,gray 0x33 0x33 0x33 12
gray 0x77 0x77 0x77 13
lgreen 0xaa 0xff 0x66 14
l,blue 0x00 0x88 0xff 15
l,gray 0xbb 0xbb 0xbb 16
*/
GsOT OT[2];
GsOT_TAG OrderingTable[2][1<<ORDERING_TABLE_LENGTH];
PACKET GPUOutputPacket[2][(MAX_NO_PACKETS * 24)];
unsigned char currentBuffer;
GsBOXF myLines[C64LINES];
GsBOXF fadeBox;
GsBOXF c64InBox;
GsBOXF c64OutBox;
int typingCounter;
int LoadCounter;
int dispCounter = 1;
char loadString[SCREEN_HEIGHT*SCREEN_HEIGHT];
void initSystem(void);
void display(void);
void initBoxes(void);
void drawBoxes(void);
void c64Screen(void);
// low-level pad buffers: never need to touch
volatile u_char *bb0, *bb1;
u_long PadStatus; // for the pad
// call once only in program initialisation
void PadInit (void)
{
GetPadBuf(&bb0, &bb1);
}
// call once per VSync(0)
// puts controller pad status into unsigned long integer
// please refer to the manuals if you want explanation
// of the internals of this function
u_long PadRead(void)
{
return(~(*(bb0+3) | *(bb0+2) << 8 | *(bb1+3) << 16 | *(bb1+2) << 24));
}
int main()
{
PadStatus = 0; // set up controller pad
PadInit();
initSystem();
debug("initSystem\n");
initBoxes();
debug("initBoxes\n");
FntLoad(960, 256);
FntOpen(c64InBox.x, c64InBox.y+4, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 1024);
typingCounter=0;
LoadCounter = 0;
srand(rand());
do
{
char loadImg[] = "Sony Net Yaroze .::::.\nCommodore 64 Intro .::::::::.\nBy Gwald @XPCOIN :::::::::::\n ':::::::::::..\n :::::::::::::::'\n ':::::::::::.\n .::::::::::::'\n .:::::::::::...\n ::::::::::::::'\n .:::. '::::::::''::::,\n .::::::::. ':::::' ':::,\n .::::':::::::. ::::: ':::,\n .:::::' ':::::::::. ::::: '::\n .:::::' ':::::::::.::::: ':\n .::::'' ':::::::::::::: \n .::'' ':::::::::::: \n ..:::: ':::::::::' \n..''''':' ':::::.'\nASCII Art by LGB from: chris.com";
debug("LoadCounter %d\n",LoadCounter);
if(LoadCounter < 200) //fade and load screen
{
c64Screen();
}
else if(LoadCounter < 300)
{
// drawBoxes();
GsSortBoxFill(&c64OutBox,&OT[currentBuffer], 4);
//GsSortBoxFill(&c64InBox,&OT[currentBuffer], 1);
}
else if(LoadCounter < 500) //loading screen
{
c64Screen();
FntPrint("~cDDF\n OK\n\n SEARCHING\n FOUND PSX GAME!");
} else if(LoadCounter < 1000)
{
GsSortBoxFill(&c64OutBox,&OT[currentBuffer], 4);
}
else if(LoadCounter < 850)
{
drawBoxes();
} else if(LoadCounter < 3000)
{
GsSortBoxFill(&c64InBox,&OT[currentBuffer], 4);
drawBoxes();
LoadCounter++;
typingCounter=0;
if(typingCounter % 2 == 0)
{
dispCounter++;
loadImg[dispCounter]=0;
}
typingCounter++;
setRGB( c64InBox, 0, 0, 0);
FntPrint(loadImg);
}
else if(LoadCounter < 3200)
{
drawBoxes();
} else if(LoadCounter < 3210)
{
}
else // restart
{
LoadCounter =0;
dispCounter= 0;
typingCounter=0;
strcpy(loadString," ");
loadString[0]=0;
setRGB( c64InBox, 53, 53, 192); // back to blue
}
LoadCounter++;
PadStatus = PadRead(); // read the pad
display();
}while(!(PadStatus & PADselect) || !(PadStatus & PADstart));
}
void initBoxes(void)
{
int i;
fadeBox.w=SCREEN_WIDTH+1;
fadeBox.h=SCREEN_HEIGHT;
fadeBox.x=0;
fadeBox.y=0;
fadeBox.attribute = 0;
// fadeBox.attribute += (1<<30) + (2<<28);
// setRGB( fadeBox, 0x0, 0x0, 0x0);
c64OutBox.w=SCREEN_WIDTH;
c64OutBox.h=SCREEN_HEIGHT;
c64OutBox.x=0;
c64OutBox.y=0;
c64OutBox.attribute = 0;
setRGB( c64OutBox, 136, 136, 214);
c64InBox.w=SCREEN_WIDTH*.70;
c64InBox.h=SCREEN_HEIGHT*.70;
c64InBox.x=(SCREEN_WIDTH-c64InBox.w)/2;
c64InBox.y=(SCREEN_HEIGHT-c64InBox.h)/2;
c64InBox.attribute = 0;
setRGB( c64InBox, 53, 53, 192);
myLines[0].w=SCREEN_WIDTH+1;
myLines[0].h=SCREEN_HEIGHT/C64LINES;
myLines[0].x=0;
myLines[0].y=0;
for(i=1; i<C64LINES; i++)
{
myLines[i]=myLines[0];
myLines[i].y=i*myLines[0].h;
}
}
void c64Screen(void)
{
debug("typingCounter = %u\n", typingCounter);
GsSortBoxFill(&c64OutBox,&OT[currentBuffer], 4);
GsSortBoxFill(&c64InBox,&OT[currentBuffer], 1);
//To change the colour of FntPrint's output, insert the sequence "~crgb"
//in your string, where r, g and b are colour values from '0' to '9'.
FntPrint("~cDDF **** COMMODORE 64 BASIC V2 ****\n\n");
FntPrint("~cDDF 64k RAM SYSTEM 38911 BASIC BYTES FREE\n\n");
FntPrint("~cDDF READY.\n ");
debug("string = %s\n",loadString);
if(typingCounter == typeSpeed)
{
strcpy(loadString,"~cDDF ");
strcat(loadString,"L");
}else if(typingCounter == typeSpeed*2)
{
strcat(loadString,"O");
}else if(typingCounter == typeSpeed*3)
{
strcat(loadString,"A");
}else if(typingCounter == typeSpeed*4)
{
strcat(loadString,"D");
}
else if(typingCounter == typeSpeed*5)
{
strcat(loadString,"\n");
}
else if(typingCounter == typeSpeed*6)
{
strcat(loadString," PRESS PLAY ON TAPE");
}
typingCounter++;
FntPrint(loadString);
debug("string = %s\n",loadString);
/*
int fadeCounter = 0;
if(fadeCounter >= 10 )
{
debug("fadeCounter %d\n",fadeCounter);
//for (tTemp1=0; tTemp1<256; tTemp1++)
{
// if(rand()%2 == 1) //increment 1/40 time
fadeCounter--;
fadeBox.attribute = 0;
fadeBox.attribute += (1<<30) + (2<<28);
setRGB( fadeBox, fadeCounter, fadeCounter, fadeCounter);
// set the colour of the box to go from transparent to opaque
GsSortBoxFill(&fadeBox, &OT[currentBuffer],0);
// (see Lib Ref page 148) Send rectangle to ordering table at
// front
}
}
*/
}
void drawBoxes(void)
{
int i;
for(i=0; i<C64LINES; i++)
{
switch(rand()%16)
{
// white 0xff 0xff 0xff 2
case 1:
setRGB(myLines[i], 0xff, 0xff, 0xff);
break;
// red 0x88 0x00 0x00 3
case 2:
setRGB(myLines[i], 0x88,0,0);
break;
// cyan 0xaa 0xff 0xee 4
case 3:
setRGB(myLines[i], 0xaa,0xff,0xee);
break;
// purple 0xcc 0x44 0xcc 5
case 4:
setRGB(myLines[i], 0xcc,0x44,0xcc);
break;
// green 0x00 0xcc 0x55 6
case 5:
setRGB(myLines[i], 0,0xcc,0x55);
break;
// blue 0x00 0x00 0xaa 7
case 6:
setRGB(myLines[i], 0,0,0xaa);
break;
// yellow 0xee 0xee 0x77 8
case 7:
setRGB(myLines[i], 0xee,0xee,0x77);
break;
// orange 0xdd 0x88 0x55 9
case 8:
setRGB(myLines[i], 0xdd,0x88,0x55);
break;
// brown 0x66 0x44 0x00 10
case 9:
setRGB(myLines[i], 0x66,0x44,0);
break;
// l,red 0xff 0x77 0x77 11
case 10:
setRGB(myLines[i], 0xff,0x77,0x77);
break;
// d,gray 0x33 0x33 0x33 12
case 11:
setRGB(myLines[i], 0x33,0x33,0x33);
break;
// gray 0x77 0x77 0x77 13
case 12:
setRGB(myLines[i], 0x77,0x77,0x77);
break;
// lgreen 0xaa 0xff 0x66 14
case 13:
setRGB(myLines[i], 0xaa,0xff,0x66);
break;
// l,blue 0x00 0x88 0xff 15
case 14:
setRGB(myLines[i], 0,0x88,0xff);
break;
// l,gray 0xbb 0xbb 0xbb 16
case 15:
setRGB(myLines[i], 0xbb,0xbb,0xbb);
break;
// black 0x00 0x00 0x00 1
default:
setRGB( myLines[i], 0x0, 0x0, 0x0);
break;
}
GsSortBoxFill(&myLines[i],&OT[currentBuffer], 10);
}
}
void initSystem(void)
{
SetVideoMode(DISPLAY_MODE);
GsInitGraph(SCREEN_WIDTH, SCREEN_HEIGHT,GsNONINTER|GsOFSGPU,0,0);
GsDefDispBuff(0,0,0,SCREEN_HEIGHT);
OT[0].length = ORDERING_TABLE_LENGTH;
OT[1].length = ORDERING_TABLE_LENGTH;
OT[0].org=OrderingTable[0];
OT[1].org=OrderingTable[1];
GsClearOt(0,0,&OT[0]);
GsClearOt(0,0,&OT[1]);
currentBuffer=GsGetActiveBuff();
GsSetWorkBase((PACKET*)GPUOutputPacket[currentBuffer]);
}
void display(void)
{
FntFlush(-1);
DrawSync(0);
VSync(0);
GsSwapDispBuff();
GsSortClear(0,0,0,&OT[currentBuffer]);
GsDrawOt(&OT[currentBuffer]);
currentBuffer=GsGetActiveBuff();
GsSetWorkBase((PACKET*)GPUOutputPacket[currentBuffer]);
GsClearOt(0, 0, &OT[currentBuffer]);
}