1 /*****************************************************************************
2 * fire test program for cc65. *
4 * (w)2002 by groepaz/hitmen *
6 * Cleanup and porting by Ullrich von Bassewitz. *
8 *****************************************************************************/
12 /* sync page-flipping to vertical blank */
16 #include <string.h> /* for memset */
23 # define BUFFER 0x0400
24 # define SCREEN1 0xE000
25 # define SCREEN2 0xE400
26 # define CHARSET 0xE800
27 # define COLORRAM 0xD800
28 # define outb(addr,val) (*(addr)) = (val)
29 # define inb(addr) (*(addr))
30 #elif defined(__C128__)
31 # define SCREEN1 0xE000
32 # define SCREEN2 0xE400
33 # define CHARSET 0xE800
34 # define COLORRAM 0xD800
35 # define outb(addr,val) (*(addr)) = (val)
36 # define inb(addr) (*(addr))
37 #elif defined(__CBM510__)
38 # define BUFFER 0xF800
39 # define SCREEN1 0xF000
40 # define SCREEN2 0xF400
41 # define CHARSET 0xE000
42 # define COLORRAM 0xD400
43 # define outb(addr,val) pokebsys ((unsigned)(addr), val)
44 # define inb(addr) peekbsys ((unsigned)(addr))
49 /* Values for the VIC address register to switch between the two pages */
50 #define PAGE1 ((SCREEN1 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
51 #define PAGE2 ((SCREEN2 >> 6) & 0xF0) | ((CHARSET >> 10) & 0x0E)
55 /* Use static local variables for speed */
56 #pragma staticlocals (1);
61 # define waitvsync() while(VIC.ctrl1 < 0x80) {}
68 static void makechar (void)
72 static const unsigned char bittab[8] = {
73 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
75 unsigned char i, ii, b;
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) {
92 for (i = 0; i < 8; i++){
94 for (ii = 0; ii < 8; ii++) {
98 b += bittab[(ii + (i & 1)) & 0x7];
101 ((unsigned char*)CHARSET + (1 * 8)) [(c * 8) + i] = b;
103 if ((c & 0x07) == 0) {
111 static void fire (unsigned screenbase)
113 register char* screen;
114 register char* buffer;
117 screen = (char*) screenbase;
118 buffer = (char*) BUFFER;
120 while (buffer != (char*) (BUFFER + (24 * 40))) {
121 c = (buffer[40-1] + buffer[40-1] + buffer[40] + buffer[41]) / 4;
125 *screen = *buffer = c;
130 screen = (char*) (screenbase + (23 * 40));
131 buffer = (char*) (BUFFER + (23 * 40));
133 for(; buffer != (char*)(BUFFER+(25*40)); ++screen, ++buffer) {
134 *screen = *buffer = 0x30 + (inb (&SID.noise) >> 4);
142 unsigned char border;
143 unsigned char background;
157 #if defined(__C128__)
159 unsigned char initflag;
160 unsigned char graphflag;
163 /* Noise on channel 3 for random numbers */
164 outb (&SID.v3.freq, 0xffff);
165 outb (&SID.v3.ctrl, 0x80);
168 cprintf ("Making charset, mompls");
171 /* Set the border and background colors */
172 border = bordercolor (COLOR_BLACK);
173 background = bgcolor (COLOR_BLACK);
174 text = textcolor (COLOR_BLACK);
177 for(i = 0; i != 0x400; i++) {
178 *((char *)(i + BUFFER)) = 0;
179 *((char *)(i + SCREEN1)) = 0;
180 *((char *)(i + SCREEN2)) = 0;
181 outb ((char*)(i + COLORRAM), COLOR_YELLOW);
184 #if defined(__C64__) || defined(__C128__)
185 /* Move the VIC 16K block */
186 block = inb (&CIA2.pra);
187 outb (&CIA2.pra, (block & 0xFC) | ((SCREEN1 >> 14) ^ 0x03));
189 #if defined(__C128__)
190 /* Save and change some flags, so that kernal/basic interupt handler will
191 * not interfere with our routine.
193 initflag = *(unsigned char*) 0xA04;
194 *(unsigned char*) 0xA04 &= 0xFE;
195 graphflag = *(unsigned char*) 0xD8;
196 *(unsigned char*) 0xD8 = 0xFF;
199 /* Remember the VIC address register */
202 /* Run the demo until a key was hit */
205 /* Build page 1, then make it visible */
208 outb (&VIC.addr, PAGE1);
210 /* Build page 2, then make it visible */
213 outb (&VIC.addr, PAGE2);
220 /* Switch back the VIC screen */
223 #if defined(__C64__) || defined(__C128__)
224 /* Move back the VIC 16K block */
225 outb (&CIA2.pra, block);
227 #if defined(__C128__)
228 /* Restore the flags */
229 *(unsigned char*) 0xA04 = initflag;
230 *(unsigned char*) 0xD8 = graphflag;
233 /* Fetch the character from the keyboard buffer and discard it */
236 /* Reset screen colors */
237 bordercolor (border);
238 bgcolor (background);
242 /* Calculate stats */
243 sec = (t * 10) / CLK_TCK;
246 fps = (f * (CLK_TCK * 10)) / t;
251 gotoxy (0, 0); cprintf ("time : %lu.%us", sec, sec10);
252 gotoxy (0, 1); cprintf ("frames: %lu", f);
253 gotoxy (0, 2); cprintf ("fps : %lu.%u", fps, fps10);
255 /* Wait for a key, then end */
256 cputsxy (0, 4, "Press any key when done...");