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)
70 static const unsigned char bittab[8] = {
71 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
74 register unsigned char i, ii, b, bc;
79 for (font = (char*)CHARSET; font != (char*)(CHARSET+(1*8)); ++font) {
82 for (font = (char*)(CHARSET+(64*8)); font != (char*)(CHARSET+(256*8)); ++font) {
87 for (c = 0; c < 0x40; ++c) {
89 for (i = 0; i < 8; i++){
91 for (ii = 0; ii < 8; ii++) {
95 b += bittab[(ii + (i & 1)) & 0x7];
98 ((unsigned char*)CHARSET + (1 * 8)) [(c * 8) + i] = b;
100 if ((c & 0x07) == 0) {
108 static void fire (unsigned screenbase)
110 register char* screen;
111 register char* buffer;
114 screen = (char*) screenbase;
115 buffer = (char*) BUFFER;
117 while (buffer != (char*) (BUFFER + (24 * 40))) {
118 c = (buffer[40-1] + buffer[40-1] + buffer[40] + buffer[41]) / 4;
122 *screen = *buffer = c;
127 screen = (char*) (screenbase + (23 * 40));
128 buffer = (char*) (BUFFER + (23 * 40));
130 for(; buffer != (char*)(BUFFER+(25*40)); ++screen, ++buffer) {
131 *screen = *buffer = 0x30 + (inb (&SID.noise) >> 4);
139 unsigned char border;
140 unsigned char background;
154 #if defined(__C128__)
156 unsigned char initflag;
157 unsigned char graphflag;
160 /* Noise on channel 3 for random numbers */
161 outb (&SID.v3.freq, 0xffff);
162 outb (&SID.v3.ctrl, 0x80);
165 cprintf ("Making charset, mompls");
168 /* Set the border and background colors */
169 border = bordercolor (COLOR_BLACK);
170 background = bgcolor (COLOR_BLACK);
171 text = textcolor (COLOR_BLACK);
174 for(i = 0; i != 0x400; i++) {
175 *((char *)(i + BUFFER)) = 0;
176 *((char *)(i + SCREEN1)) = 0;
177 *((char *)(i + SCREEN2)) = 0;
178 outb ((char*)(i + COLORRAM), COLOR_YELLOW);
181 #if defined(__C64__) || defined(__C128__)
182 /* Move the VIC 16K block */
183 block = inb (&CIA2.pra);
184 outb (&CIA2.pra, (block & 0xFC) | ((SCREEN1 >> 14) ^ 0x03));
186 #if defined(__C128__)
187 /* Save and change some flags, so that kernal/basic interupt handler will
188 * not interfere with our routine.
190 initflag = *(unsigned char*) 0xA04;
191 *(unsigned char*) 0xA04 &= 0xFE;
192 graphflag = *(unsigned char*) 0xD8;
193 *(unsigned char*) 0xD8 = 0xFF;
196 /* Remember the VIC address register */
199 /* Run the demo until a key was hit */
202 /* Build page 1, then make it visible */
205 outb (&VIC.addr, PAGE1);
207 /* Build page 2, then make it visible */
210 outb (&VIC.addr, PAGE2);
217 /* Switch back the VIC screen */
220 #if defined(__C64__) || defined(__C128__)
221 /* Move back the VIC 16K block */
222 outb (&CIA2.pra, block);
224 #if defined(__C128__)
225 /* Restore the flags */
226 *(unsigned char*) 0xA04 = initflag;
227 *(unsigned char*) 0xD8 = graphflag;
230 /* Fetch the character from the keyboard buffer and discard it */
233 /* Reset screen colors */
234 bordercolor (border);
235 bgcolor (background);
239 /* Calculate stats */
240 sec = (t * 10) / CLK_TCK;
243 fps = (f * (CLK_TCK * 10)) / t;
248 gotoxy (0, 0); cprintf ("time : %lu.%us", sec, sec10);
249 gotoxy (0, 1); cprintf ("frames: %lu", f);
250 gotoxy (0, 2); cprintf ("fps : %lu.%u", fps, fps10);
252 /* Wait for a key, then end */
253 cputsxy (0, 4, "Press any key when done...");