1 /*****************************************************************************
2 * fire test program for cc65. *
4 * (w)2002 by groepaz/hitmen *
6 * Cleanup and porting by Ullrich von Bassewitz. *
7 * 2004-06-08, Greg King *
9 *****************************************************************************/
13 /* sync page-flipping to vertical blank */
17 #include <string.h> /* for memset */
24 # define BUFFER 0x0400
25 # define SCREEN1 0xE000
26 # define SCREEN2 0xE400
27 # define CHARSET 0xE800
28 # define COLORRAM 0xD800
29 # define outb(addr,val) (*(addr) = (val))
30 # define inb(addr) (*(addr))
31 #elif defined(__C128__)
32 # define BUFFER 0x0400
33 # define SCREEN1 0xE000
34 # define SCREEN2 0xE400
35 # define CHARSET 0xE800
36 # define COLORRAM 0xD800
37 # define outb(addr,val) (*(addr) = (val))
38 # define inb(addr) (*(addr))
39 #elif defined(__CBM510__)
40 # define BUFFER 0xF800
41 # define SCREEN1 0xF000
42 # define SCREEN2 0xF400
43 # define CHARSET 0xE000
44 # define COLORRAM 0xD400
45 # define outb(addr,val) pokebsys ((unsigned)(addr), val)
46 # define inb(addr) peekbsys ((unsigned)(addr))
51 /* Values for the VIC address register to switch between the two pages */
52 #define PAGE1 ((SCREEN1 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
53 #define PAGE2 ((SCREEN2 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
57 /* Use static local variables for speed */
58 #pragma static-locals (1);
63 # define waitvsync() while ((signed char)VIC.ctrl1 >= 0)
70 static void makechar (void)
72 static const unsigned char bittab[8] = {
73 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
76 register unsigned char i, ii, b, bc;
81 for (font = (char*)CHARSET; font != (char*)(CHARSET+(1*8)); ++font) {
84 for (font = (char*)(CHARSET+(64*8)); font != (char*)(CHARSET+(256*8)); ++font) {
89 for (c = 0; c < 0x40; ++c) {
91 for (i = 0; i < 8; i++){
93 for (ii = 0; ii < 8; ii++) {
97 b += bittab[(ii + (i & 1)) & 0x7];
100 ((unsigned char*)CHARSET + (1 * 8)) [(c * 8) + i] = b;
102 if ((c & 0x07) == 0) {
110 static void fire (unsigned screenbase)
112 register char* screen;
113 register char* buffer;
116 screen = (char*) screenbase;
117 buffer = (char*) BUFFER;
119 while (buffer != (char*) (BUFFER + (24 * 40))) {
120 c = (buffer[40-1] + buffer[40-1] + buffer[40] + buffer[41]) / 4;
124 *screen = *buffer = c;
129 screen = (char*) (screenbase + (23 * 40));
130 buffer = (char*) (BUFFER + (23 * 40));
132 for(; buffer != (char*)(BUFFER+(25*40)); ++screen, ++buffer) {
133 *screen = *buffer = 0x30 + (inb (&SID.noise) >> 4);
141 unsigned char border;
142 unsigned char background;
156 #if defined(__C128__)
158 unsigned char initflag;
159 unsigned char graphflag;
162 /* Noise on channel 3 for random numbers */
163 outb (&SID.v3.freq, 0xffff);
164 outb (&SID.v3.ctrl, 0x80);
167 cprintf ("Making charset, mompls");
170 /* Set the border and background colors */
171 border = bordercolor (COLOR_BLACK);
172 background = bgcolor (COLOR_BLACK);
173 text = textcolor (COLOR_BLACK);
176 for(i = 0; i != 0x400; i++) {
177 *((char *)(i + BUFFER)) = 0;
178 *((char *)(i + SCREEN1)) = 0;
179 *((char *)(i + SCREEN2)) = 0;
180 outb ((char*)(i + COLORRAM), COLOR_YELLOW);
183 #if defined(__C64__) || defined(__C128__)
184 /* Move the VIC 16K block */
185 block = inb (&CIA2.pra);
186 outb (&CIA2.pra, (block & 0xFC) | ((SCREEN1 >> 14) ^ 0x03));
188 #if defined(__C128__)
189 /* Save and change some flags, so that kernal/basic interrupt handler will
190 * not interfere with our routine.
192 initflag = *(unsigned char*) 0xA04;
193 *(unsigned char*) 0xA04 &= 0xFE;
194 graphflag = *(unsigned char*) 0xD8;
195 *(unsigned char*) 0xD8 = 0xFF;
198 /* Remember the VIC address register */
201 /* Run the demo until a key was hit */
204 /* Build page 1, then make it visible */
207 outb (&VIC.addr, PAGE1);
209 /* Build page 2, then make it visible */
212 outb (&VIC.addr, PAGE2);
219 /* Switch back the VIC screen */
222 #if defined(__C64__) || defined(__C128__)
223 /* Move back the VIC 16K block */
224 outb (&CIA2.pra, block);
226 #if defined(__C128__)
227 /* Restore the flags */
228 *(unsigned char*) 0xA04 = initflag;
229 *(unsigned char*) 0xD8 = graphflag;
232 /* Fetch the character from the keyboard buffer and discard it */
235 /* Reset screen colors */
236 bordercolor (border);
237 bgcolor (background);
241 /* Calculate stats */
242 sec = (t * 10) / CLK_TCK;
245 fps = (f * (CLK_TCK * 10)) / t;
250 gotoxy (0, 0); cprintf ("time : %lu.%us", sec, sec10);
251 gotoxy (0, 1); cprintf ("frames: %lu", f);
252 gotoxy (0, 2); cprintf ("fps : %lu.%u", fps, fps10);
254 /* Wait for a key, then end */
255 cputsxy (0, 4, "Press any key when done...");