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