--- /dev/null
+/*****************************************************************************\r
+ * plasma test program for cc65. *\r
+ * *\r
+ * (w)2001 by groepaz/hitmen *\r
+ * *\r
+ * Cleanup and porting by Ullrich von Bassewitz. *\r
+ * *\r
+ *****************************************************************************/\r
+\r
+\r
+\r
+#include <stdlib.h>\r
+#include <time.h>\r
+#include <conio.h>\r
+\r
+\r
+\r
+#if defined(__C64__)\r
+# define SCREEN1 0xE000\r
+# define SCREEN2 0xE400\r
+# define CHARSET 0xE800\r
+# define outb(addr,val) (*(addr)) = (val)\r
+# define inb(addr) (*(addr))\r
+#elif defined(__CBM510__)\r
+# define SCREEN1 0xF000\r
+# define SCREEN2 0xF400\r
+# define CHARSET 0xE000\r
+# define outb(addr,val) pokebsys ((unsigned)(addr), val)\r
+# define inb(addr) peekbsys ((unsigned)(addr))\r
+#endif\r
+\r
+\r
+\r
+/* Values for the VIC address register to switch between the two pages */\r
+#define PAGE1 ((SCREEN1 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)\r
+#define PAGE2 ((SCREEN2 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)\r
+\r
+\r
+\r
+/* Use static local variables for speed */\r
+#pragma staticlocals (1);\r
+\r
+\r
+\r
+static const unsigned char sinustable[0x100] = {\r
+ 0x80, 0x7d, 0x7a, 0x77, 0x74, 0x70, 0x6d, 0x6a,\r
+ 0x67, 0x64, 0x61, 0x5e, 0x5b, 0x58, 0x55, 0x52,\r
+ 0x4f, 0x4d, 0x4a, 0x47, 0x44, 0x41, 0x3f, 0x3c,\r
+ 0x39, 0x37, 0x34, 0x32, 0x2f, 0x2d, 0x2b, 0x28,\r
+ 0x26, 0x24, 0x22, 0x20, 0x1e, 0x1c, 0x1a, 0x18,\r
+ 0x16, 0x15, 0x13, 0x11, 0x10, 0x0f, 0x0d, 0x0c,\r
+ 0x0b, 0x0a, 0x08, 0x07, 0x06, 0x06, 0x05, 0x04,\r
+ 0x03, 0x03, 0x02, 0x02, 0x02, 0x01, 0x01, 0x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d1, 0xce, 0xcc, 0xc9,\r
+ 0xc7, 0xc4, 0xc1, 0xbf, 0xbc, 0xb9, 0xb6, 0xb3,\r
+ 0xb1, 0xae, 0xab, 0xa8, 0xa5, 0xa2, 0x9f, 0x9c,\r
+ 0x99, 0x96, 0x93, 0x90, 0x8c, 0x89, 0x86, 0x83\r
+};\r
+\r
+\r
+\r
+static unsigned char *scrn;\r
+\r
+\r
+\r
+static void doplasma (void)\r
+{\r
+ unsigned char xbuf[40];\r
+ unsigned char ybuf[25];\r
+ unsigned char i,ii;\r
+ unsigned char c1a,c1b;\r
+ unsigned char c2a,c2b;\r
+ unsigned char c1A,c1B;\r
+ unsigned char c2A,c2B;\r
+\r
+ c1a = c1A;\r
+ c1b = c1B;\r
+ for (ii = 0; ii < 25; ++ii) {\r
+ ybuf[ii] = (sinustable[c1a] + sinustable[c1b]);\r
+ c1a += 4;\r
+ c1b += 9;\r
+ }\r
+ c1A += 3;\r
+ c1B -= 5;\r
+ c2a = c2A;\r
+ c2b = c2B;\r
+ for (i = 0; i < 40; ++i) {\r
+ xbuf[i] = (sinustable[c2a] + sinustable[c2b]);\r
+ c2a += 3;\r
+ c2b += 7;\r
+ }\r
+ c2A += 2;\r
+ c2B -= 3;\r
+ for (ii = 0; ii < 25; ++ii) {\r
+ for (i = 0; i < 40; ++i, ++scrn) {\r
+ *scrn = (xbuf[i] + ybuf[ii]);\r
+ }\r
+ }\r
+}\r
+\r
+\r
+\r
+static void makechar (void)\r
+{\r
+ static const unsigned char bittab[8] = {\r
+ 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80\r
+ };\r
+ unsigned char i, ii, b, s;\r
+ unsigned c;\r
+\r
+ gotoxy (0, 1);\r
+ for (c = 0; c < 0x100; ++c) {\r
+ s = sinustable[c];\r
+ for (i = 0; i < 8; ++i){\r
+ b = 0;\r
+ for (ii = 0; ii < 8; ++ii) {\r
+ if ((rand() & 0xFF) > s) {\r
+ b |= bittab[ii];\r
+ }\r
+ }\r
+ ((unsigned char*)CHARSET) [(c*8) + i] = b;\r
+ }\r
+ if ((c & 0x07) == 0) {\r
+ cputc ('.');\r
+ }\r
+ }\r
+}\r
+\r
+\r
+\r
+int main (void)\r
+{\r
+ unsigned char border;\r
+ unsigned char background;\r
+ unsigned char text;\r
+ unsigned char v;\r
+ clock_t t;\r
+ unsigned long f = 0;\r
+ unsigned long sec;\r
+ unsigned sec10;\r
+ unsigned long fps;\r
+ unsigned fps10;\r
+\r
+\r
+ clrscr ();\r
+ cprintf ("Making charset, mompls");\r
+ makechar();\r
+\r
+ /* Set the border and background colors */\r
+ border = bordercolor (COLOR_BLUE);\r
+ background = bgcolor (COLOR_BLUE);\r
+ text = textcolor (COLOR_BLACK);\r
+ clrscr ();\r
+\r
+#if defined(__C64__)\r
+ /* Move the VIC 16K block */\r
+ outb (&CIA2.pra, 0x00);\r
+#endif\r
+\r
+ /* Remember the VIC address register */\r
+ v = inb (&VIC.addr);\r
+\r
+ /* Run the demo until a key was hit */\r
+ t = clock ();\r
+ while (!kbhit()) {\r
+ /* Build page 1, then make it visible */\r
+ scrn = (unsigned char*)SCREEN1;\r
+ doplasma();\r
+ outb (&VIC.addr, PAGE1);\r
+\r
+ /* Build page 2, then make it visible */\r
+ scrn = (unsigned char*)SCREEN2;\r
+ doplasma();\r
+ outb (&VIC.addr, PAGE2);\r
+\r
+ /* Count frames */\r
+ f += 2;\r
+ };\r
+ t = clock() - t;\r
+\r
+ /* Switch back the VIC screen */\r
+ outb (&VIC.addr, v);\r
+\r
+#if defined(__C64__)\r
+ /* Move back the VIC 16K block */\r
+ outb (&CIA2.pra, 0x03);\r
+#endif\r
+\r
+ /* Fetch the character from the keyboard buffer and discard it */\r
+ (void) cgetc();\r
+\r
+ /* Reset screen colors */\r
+ bordercolor (border);\r
+ bgcolor (background);\r
+ textcolor (text);\r
+ clrscr();\r
+\r
+ /* Calculate stats */\r
+ sec = (t * 10) / CLK_TCK;\r
+ sec10 = sec % 10;\r
+ sec /= 10;\r
+ fps = (f * (CLK_TCK * 10)) / t;\r
+ fps10 = fps % 10;\r
+ fps /= 10;\r
+\r
+ /* Output stats */\r
+ gotoxy (0, 0); cprintf ("time : %lu.%us", sec, sec10);\r
+ gotoxy (0, 1); cprintf ("frames: %lu", f);\r
+ gotoxy (0, 2); cprintf ("fps : %lu.%u", fps, fps10);\r
+\r
+ /* Wait for a key, then end */\r
+ cputsxy (0, 4, "Press any key when done...");\r
+ (void) cgetc ();\r
+\r
+ /* Done */\r
+ return EXIT_SUCCESS;\r
+}\r
+\r
+\r