1 /*****************************************************************************\
2 ** plasma test program for cc65. **
4 ** (w)2001 by groepaz/hitmen **
6 ** Cleanup and porting by Ullrich von Bassewitz. **
8 \*****************************************************************************/
19 #if defined(__C64__) || defined(__C128__)
20 # define SCREEN1 0xE000
21 # define SCREEN2 0xE400
22 # define CHARSET 0xE800
23 # define outb(addr,val) (*(addr)) = (val)
24 # define inb(addr) (*(addr))
25 #elif defined(__CBM510__)
26 # define SCREEN1 0xF000
27 # define SCREEN2 0xF400
28 # define CHARSET 0xE000
29 # define outb(addr,val) pokebsys ((unsigned)(addr), val)
30 # define inb(addr) peekbsys ((unsigned)(addr))
31 #elif defined(__PLUS4__)
32 # define SCREEN1 0x6400
33 # define SCREEN2 0x6C00
34 # define CHARSET 0x7000
35 # define outb(addr,val) (*(addr)) = (val)
36 # define inb(addr) (*(addr))
41 /* Values for the VIC address register to switch between the two pages */
42 #if defined(__PLUS4__)
43 #define PAGE1 ((SCREEN1 >> 8) & 0xF8)
44 #define PAGE2 ((SCREEN2 >> 8) & 0xF8)
45 #define CHARADR ((CHARSET >> 8) & 0xFC)
47 #define PAGE1 ((SCREEN1 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
48 #define PAGE2 ((SCREEN2 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
53 /* Use static local variables for speed */
54 #pragma static-locals (1);
58 static const unsigned char sinustable[0x100] = {
59 0x80, 0x7d, 0x7a, 0x77, 0x74, 0x70, 0x6d, 0x6a,
60 0x67, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52,
61 0x4f, 0x4d, 0x4a, 0x47, 0x44, 0x41, 0x3f, 0x3c,
62 0x39, 0x37, 0x34, 0x32, 0x2f, 0x2d, 0x2b, 0x28,
63 0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a, 0x18,
64 0x16, 0x15, 0x13, 0x11, 0x10, 0x0f, 0x0d, 0x0c,
65 0x0b, 0x0a, 0x08, 0x07, 0x06, 0x06, 0x05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c9,
88 0xc7, 0xc4, 0xc1, 0xbf, 0xbc, 0xb9, 0xb6, 0xb3,
89 0xb1, 0xae, 0xab, 0xa8, 0xa5, 0xa2, 0x9f, 0x9c,
90 0x99, 0x96, 0x93, 0x90, 0x8c, 0x89, 0x86, 0x83
95 static void doplasma (register unsigned char* scrn)
97 unsigned char xbuf[40];
98 unsigned char ybuf[25];
99 unsigned char c1a,c1b;
100 unsigned char c2a,c2b;
101 unsigned char c1A,c1B;
102 unsigned char c2A,c2B;
103 register unsigned char i, ii;
107 for (ii = 0; ii < 25; ++ii) {
108 ybuf[ii] = (sinustable[c1a] + sinustable[c1b]);
116 for (i = 0; i < 40; ++i) {
117 xbuf[i] = (sinustable[c2a] + sinustable[c2b]);
123 for (ii = 0; ii < 25; ++ii) {
124 /* Unrolling the following loop will give a speed increase of
125 ** nearly 100% (~24fps), but it will also increase the code
128 for (i = 0; i < 40; ++i, ++scrn) {
129 *scrn = (xbuf[i] + ybuf[ii]);
136 static void makechar (void)
138 static const unsigned char bittab[8] = {
139 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
141 unsigned char i, ii, b, s;
145 for (c = 0; c < 0x100; ++c) {
147 for (i = 0; i < 8; ++i){
149 for (ii = 0; ii < 8; ++ii) {
150 if ((rand() & 0xFF) > s) {
154 ((unsigned char*)CHARSET) [(c*8) + i] = b;
156 if ((c & 0x07) == 0) {
166 unsigned char border;
167 unsigned char background;
181 #if defined(__C128__)
183 unsigned char initflag;
184 unsigned char graphflag;
186 #if defined(__PLUS4__)
192 cprintf ("Making charset, mompls");
195 /* Set the border and background colors */
196 border = bordercolor (COLOR_BLUE);
197 background = bgcolor (COLOR_BLUE);
198 text = textcolor (COLOR_BLACK);
201 #if defined(__C64__) || defined(__C128__)
202 /* Move the VIC 16K block */
203 block = inb (&CIA2.pra);
204 outb (&CIA2.pra, (block & 0xFC) | ((SCREEN1 >> 14) ^ 0x03));
206 #if defined(__C128__)
207 /* Save and change some flags, so that kernal/basic interrupt handler will
208 ** not interfere with our routine.
210 initflag = *(unsigned char*) 0xA04;
211 *(unsigned char*) 0xA04 &= 0xFE;
212 graphflag = *(unsigned char*) 0xD8;
213 *(unsigned char*) 0xD8 = 0xFF;
216 /* Remember the VIC address register */
217 #if defined(__PLUS4__)
218 v = inb (&TED.char_addr);
219 v2 = inb (&TED.video_addr);
224 #if defined(__PLUS4__)
225 for (i=0;i<1000;i++) {
226 ((unsigned char *) (SCREEN1-0x0400))[i] = 0;
227 ((unsigned char *) (SCREEN2-0x0400))[i] = 0;
229 outb (&TED.char_addr, CHARADR);
232 /* Run the demo until a key was hit */
235 /* Build page 1, then make it visible */
236 doplasma ((unsigned char*)SCREEN1);
237 #if defined(__PLUS4__)
238 outb (&TED.video_addr, PAGE1);
240 outb (&VIC.addr, PAGE1);
243 /* Build page 2, then make it visible */
244 doplasma ((unsigned char*)SCREEN2);
245 #if defined(__PLUS4__)
246 outb (&TED.video_addr, PAGE2);
248 outb (&VIC.addr, PAGE2);
256 /* Switch back the VIC screen */
257 #if defined(__PLUS4__)
258 outb (&TED.video_addr, v2);
259 outb (&TED.char_addr, v);
264 #if defined(__C64__) || defined(__C128__)
265 /* Move back the VIC 16K block */
266 outb (&CIA2.pra, block);
268 #if defined(__C128__)
269 /* Restore the flags */
270 *(unsigned char*) 0xA04 = initflag;
271 *(unsigned char*) 0xD8 = graphflag;
274 /* Fetch the character from the keyboard buffer and discard it */
277 /* Reset screen colors */
278 bordercolor (border);
279 bgcolor (background);
283 /* Calculate stats */
284 sec = (t * 10) / CLK_TCK;
287 fps = (f * (CLK_TCK * 10)) / t;
292 gotoxy (0, 0); cprintf ("time : %lu.%us", sec, sec10);
293 gotoxy (0, 1); cprintf ("frames: %lu", f);
294 gotoxy (0, 2); cprintf ("fps : %lu.%u", fps, fps10);
296 if (doesclrscrafterexit ()) {
297 cputsxy (0, 4, "Press any key when done...");