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))
34 /* Values for the VIC address register to switch between the two pages */
35 #define PAGE1 ((SCREEN1 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
36 #define PAGE2 ((SCREEN2 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
40 /* Use static local variables for speed */
41 #pragma staticlocals (1);
45 static const unsigned char sinustable[0x100] = {
46 0x80, 0x7d, 0x7a, 0x77, 0x74, 0x70, 0x6d, 0x6a,
47 0x67, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52,
48 0x4f, 0x4d, 0x4a, 0x47, 0x44, 0x41, 0x3f, 0x3c,
49 0x39, 0x37, 0x34, 0x32, 0x2f, 0x2d, 0x2b, 0x28,
50 0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a, 0x18,
51 0x16, 0x15, 0x13, 0x11, 0x10, 0x0f, 0x0d, 0x0c,
52 0x0b, 0x0a, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,
53 0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x01,
54 0x01, 0x01, 0x01, 0x01, 0x02, 0x02, 0x02, 0x03,
55 0x03, 0x04, 0x05, 0x06, 0x06, 0x07, 0x08, 0x0a,
56 0x0b, 0x0c, 0x0d, 0x0f, 0x10, 0x11, 0x13, 0x15,
57 0x16, 0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x22, 0x24,
58 0x26, 0x28, 0x2b, 0x2d, 0x2f, 0x32, 0x34, 0x37,
59 0x39, 0x3c, 0x3f, 0x41, 0x44, 0x47, 0x4a, 0x4d,
60 0x4f, 0x52, 0x55, 0x58, 0x5b, 0x5e, 0x61, 0x64,
61 0x67, 0x6a, 0x6d, 0x70, 0x74, 0x77, 0x7a, 0x7d,
62 0x80, 0x83, 0x86, 0x89, 0x8c, 0x90, 0x93, 0x96,
63 0x99, 0x9c, 0x9f, 0xa2, 0xa5, 0xa8, 0xab, 0xae,
64 0xb1, 0xb3, 0xb6, 0xb9, 0xbc, 0xbf, 0xc1, 0xc4,
65 0xc7, 0xc9, 0xcc, 0xce, 0xd1, 0xd3, 0xd5, 0xd8,
66 0xda, 0xdc, 0xde, 0xe0, 0xe2, 0xe4, 0xe6, 0xe8,
67 0xea, 0xeb, 0xed, 0xef, 0xf0, 0xf1, 0xf3, 0xf4,
68 0xf5, 0xf6, 0xf8, 0xf9, 0xfa, 0xfa, 0xfb, 0xfc,
69 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xff, 0xff, 0xff,
70 0xff, 0xff, 0xff, 0xff, 0xfe, 0xfe, 0xfe, 0xfd,
71 0xfd, 0xfc, 0xfb, 0xfa, 0xfa, 0xf9, 0xf8, 0xf6,
72 0xf5, 0xf4, 0xf3, 0xf1, 0xf0, 0xef, 0xed, 0xeb,
73 0xea, 0xe8, 0xe6, 0xe4, 0xe2, 0xe0, 0xde, 0xdc,
74 0xda, 0xd8, 0xd5, 0xd3, 0xd1, 0xce, 0xcc, 0xc9,
75 0xc7, 0xc4, 0xc1, 0xbf, 0xbc, 0xb9, 0xb6, 0xb3,
76 0xb1, 0xae, 0xab, 0xa8, 0xa5, 0xa2, 0x9f, 0x9c,
77 0x99, 0x96, 0x93, 0x90, 0x8c, 0x89, 0x86, 0x83
82 static unsigned char *scrn;
86 static void doplasma (void)
88 unsigned char xbuf[40];
89 unsigned char ybuf[25];
91 unsigned char c1a,c1b;
92 unsigned char c2a,c2b;
93 unsigned char c1A,c1B;
94 unsigned char c2A,c2B;
98 for (ii = 0; ii < 25; ++ii) {
99 ybuf[ii] = (sinustable[c1a] + sinustable[c1b]);
107 for (i = 0; i < 40; ++i) {
108 xbuf[i] = (sinustable[c2a] + sinustable[c2b]);
114 for (ii = 0; ii < 25; ++ii) {
115 /* Unrolling the following loop will give a speed increase of
116 * nearly 100% (~24fps), but it will also increase the code
119 for (i = 0; i < 40; ++i, ++scrn) {
120 *scrn = (xbuf[i] + ybuf[ii]);
127 static void makechar (void)
129 static const unsigned char bittab[8] = {
130 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
132 unsigned char i, ii, b, s;
136 for (c = 0; c < 0x100; ++c) {
138 for (i = 0; i < 8; ++i){
140 for (ii = 0; ii < 8; ++ii) {
141 if ((rand() & 0xFF) > s) {
145 ((unsigned char*)CHARSET) [(c*8) + i] = b;
147 if ((c & 0x07) == 0) {
157 unsigned char border;
158 unsigned char background;
171 #if defined(__C128__)
173 unsigned char initflag;
174 unsigned char graphflag;
178 cprintf ("Making charset, mompls");
181 /* Set the border and background colors */
182 border = bordercolor (COLOR_BLUE);
183 background = bgcolor (COLOR_BLUE);
184 text = textcolor (COLOR_BLACK);
187 #if defined(__C64__) || defined(__C128__)
188 /* Move the VIC 16K block */
189 block = inb (&CIA2.pra);
190 outb (&CIA2.pra, (block & 0xFC) | ((SCREEN1 >> 14) ^ 0x03));
192 #if defined(__C128__)
193 /* Save and change some flags, so that kernal/basic interupt handler will
194 * not interfere with our routine.
196 initflag = *(unsigned char*) 0xA04;
197 *(unsigned char*) 0xA04 &= 0xFE;
198 graphflag = *(unsigned char*) 0xD8;
199 *(unsigned char*) 0xD8 = 0xFF;
202 /* Remember the VIC address register */
205 /* Run the demo until a key was hit */
208 /* Build page 1, then make it visible */
209 scrn = (unsigned char*)SCREEN1;
211 outb (&VIC.addr, PAGE1);
213 /* Build page 2, then make it visible */
214 scrn = (unsigned char*)SCREEN2;
216 outb (&VIC.addr, PAGE2);
223 /* Switch back the VIC screen */
226 #if defined(__C64__) || defined(__C128__)
227 /* Move back the VIC 16K block */
228 outb (&CIA2.pra, block);
230 #if defined(__C128__)
231 /* Restore the flags */
232 *(unsigned char*) 0xA04 = initflag;
233 *(unsigned char*) 0xD8 = graphflag;
236 /* Fetch the character from the keyboard buffer and discard it */
239 /* Reset screen colors */
240 bordercolor (border);
241 bgcolor (background);
245 /* Calculate stats */
246 sec = (t * 10) / CLK_TCK;
249 fps = (f * (CLK_TCK * 10)) / t;
254 gotoxy (0, 0); cprintf ("time : %lu.%us", sec, sec10);
255 gotoxy (0, 1); cprintf ("frames: %lu", f);
256 gotoxy (0, 2); cprintf ("fps : %lu.%u", fps, fps10);
258 /* Wait for a key, then end */
259 cputsxy (0, 4, "Press any key when done...");