8 #include "fixed32.hpp"
\r
10 #include "xprim.hpp"
\r
12 #include "xblitbuf.hpp"
\r
15 #define ROTATE_DEMO 1
\r
16 #define MONSTER_DEMO_ONE 1
\r
17 #define MONSTER_DEMO_TWO 1
\r
25 blitbuf sprite_image, blit_image;
\r
29 load_blitbufPCX("monster.pcx", &sprite_image);
\r
30 aligned_bitblitX(0, 20, &sprite_image);
\r
33 blit_image.image = NULL;
\r
40 scale_blitbuf(120 + (i << 1), (i << 1), &sprite_image, &blit_image);
\r
41 boxX((99 - i), (119 - i), (220 + i), (120 + i), 0);
\r
42 vanilla_bitblitX(100 - i, 120 - i, &blit_image);
\r
50 scale_blitbuf(i, 2, &sprite_image, &blit_image);
\r
52 putpixelX(159 - (i >> 1), 119, 0);
\r
53 putpixelX(159 - (i >> 1), 120, 0);
\r
54 putpixelX(160 + (i >> 1), 119, 0);
\r
55 putpixelX(160 + (i >> 1), 120, 0);
\r
57 vanilla_bitblitX(160 - (i >> 1), 119, &blit_image);
\r
62 filledboxX(156, 119, 163, 120, 0);
\r
63 putpixelX(159, 120, 1);
\r
65 putpixelX(159, 120, 0);
\r
67 filledboxX(156, 119, 163, 120, 0);
\r
68 clear_blitbuf(&sprite_image);
\r
69 clear_blitbuf(&blit_image);
\r
73 return (end - begin);
\r
81 blitbuf sprite_image, blit_image;
\r
85 load_blitbufPCX("monster.pcx", &sprite_image);
\r
86 aligned_bitblitX(0, 20, &sprite_image);
\r
89 blit_image.image = NULL;
\r
93 vertical_scale_blitbuf((i << 1), &sprite_image, &blit_image);
\r
94 boxX(0, (119 - i), 319, (120 + i), 0);
\r
95 aligned_bitblitX(0, 120 - i, &blit_image);
\r
99 filledboxX(0, 120, 319, 120, 0);
\r
103 scale_blitbuf(i, 1, &blit_image, &sprite_image);
\r
105 putpixelX(159 - (i >> 1), 119, 0);
\r
106 putpixelX(159 - (i >> 1), 120, 0);
\r
107 putpixelX(160 + (i >> 1), 119, 0);
\r
108 putpixelX(160 + (i >> 1), 120, 0);
\r
110 vanilla_bitblitX(160 - (i >> 1), 119, &sprite_image);
\r
115 filledboxX(156, 119, 163, 120, 0);
\r
116 putpixelX(159, 120, 1);
\r
118 putpixelX(159, 120, 0);
\r
119 filledboxX(156, 119, 163, 120, 0);
\r
120 clear_blitbuf(&sprite_image);
\r
121 clear_blitbuf(&blit_image);
\r
131 #define V_HEIGHT 50
\r
132 #define BUF_WIDTH 80
\r
133 #define BUF_HEIGHT 56
\r
134 #define REWIND (V_WIDTH * 3)
\r
135 #define BUF_SIZE (BUF_WIDTH * BUF_HEIGHT)
\r
137 unsigned char fire_pal[768] = {
\r
138 0, 0, 0, 0, 0, 24, 0, 0, 24, 0, 0, 28,
\r
139 0, 0, 32, 0, 0, 32, 0, 0, 36, 0, 0, 40,
\r
140 8, 0, 40, 16, 0, 36, 24, 0, 36, 32, 0, 32,
\r
141 40, 0, 28, 48, 0, 28, 56, 0, 24, 64, 0, 20,
\r
142 72, 0, 20, 80, 0, 16, 88, 0, 16, 96, 0, 12,
\r
143 104, 0, 8, 112, 0, 8, 120, 0, 4, 128, 0, 0,
\r
144 128, 0, 0, 132, 0, 0, 136, 0, 0, 140, 0, 0,
\r
145 144, 0, 0, 144, 0, 0, 148, 0, 0, 152, 0, 0,
\r
146 156, 0, 0, 160, 0, 0, 160, 0, 0, 164, 0, 0,
\r
147 168, 0, 0, 172, 0, 0, 176, 0, 0, 180, 0, 0,
\r
148 184, 4, 0, 188, 4, 0, 192, 8, 0, 196, 8, 0,
\r
149 200, 12, 0, 204, 12, 0, 208, 16, 0, 212, 16, 0,
\r
150 216, 20, 0, 220, 20, 0, 224, 24, 0, 228, 24, 0,
\r
151 232, 28, 0, 236, 28, 0, 240, 32, 0, 244, 32, 0,
\r
152 252, 36, 0, 252, 36, 0, 252, 40, 0, 252, 40, 0,
\r
153 252, 44, 0, 252, 44, 0, 252, 48, 0, 252, 48, 0,
\r
154 252, 52, 0, 252, 52, 0, 252, 56, 0, 252, 56, 0,
\r
155 252, 60, 0, 252, 60, 0, 252, 64, 0, 252, 64, 0,
\r
156 252, 68, 0, 252, 68, 0, 252, 72, 0, 252, 72, 0,
\r
157 252, 76, 0, 252, 76, 0, 252, 80, 0, 252, 80, 0,
\r
158 252, 84, 0, 252, 84, 0, 252, 88, 0, 252, 88, 0,
\r
159 252, 92, 0, 252, 96, 0, 252, 96, 0, 252, 100, 0,
\r
160 252, 100, 0, 252, 104, 0, 252, 104, 0, 252, 108, 0,
\r
161 252, 108, 0, 252, 112, 0, 252, 112, 0, 252, 116, 0,
\r
162 252, 116, 0, 252, 120, 0, 252, 120, 0, 252, 124, 0,
\r
163 252, 124, 0, 252, 128, 0, 252, 128, 0, 252, 132, 0,
\r
164 252, 132, 0, 252, 136, 0, 252, 136, 0, 252, 140, 0,
\r
165 252, 140, 0, 252, 144, 0, 252, 144, 0, 252, 148, 0,
\r
166 252, 152, 0, 252, 152, 0, 252, 156, 0, 252, 156, 0,
\r
167 252, 160, 0, 252, 160, 0, 252, 164, 0, 252, 164, 0,
\r
168 252, 168, 0, 252, 168, 0, 252, 172, 0, 252, 172, 0,
\r
169 252, 176, 0, 252, 176, 0, 252, 180, 0, 252, 180, 0,
\r
170 252, 184, 0, 252, 184, 0, 252, 188, 0, 252, 188, 0,
\r
171 252, 192, 0, 252, 192, 0, 252, 196, 0, 252, 196, 0,
\r
172 252, 200, 0, 252, 200, 0, 252, 204, 0, 252, 208, 0,
\r
173 252, 208, 0, 252, 208, 0, 252, 208, 0, 252, 208, 0,
\r
174 252, 212, 0, 252, 212, 0, 252, 212, 0, 252, 212, 0,
\r
175 252, 216, 0, 252, 216, 0, 252, 216, 0, 252, 216, 0,
\r
176 252, 216, 0, 252, 220, 0, 252, 220, 0, 252, 220, 0,
\r
177 252, 220, 0, 252, 224, 0, 252, 224, 0, 252, 224, 0,
\r
178 252, 224, 0, 252, 228, 0, 252, 228, 0, 252, 228, 0,
\r
179 252, 228, 0, 252, 228, 0, 252, 232, 0, 252, 232, 0,
\r
180 252, 232, 0, 252, 232, 0, 252, 236, 0, 252, 236, 0,
\r
181 252, 236, 0, 252, 236, 0, 252, 240, 0, 252, 240, 0,
\r
182 252, 240, 0, 252, 240, 0, 252, 240, 0, 252, 244, 0,
\r
183 252, 244, 0, 252, 244, 0, 252, 244, 0, 252, 248, 0,
\r
184 252, 248, 0, 252, 248, 0, 252, 248, 0, 252, 252, 0,
\r
185 252, 252, 4, 252, 252, 8, 252, 252, 12, 252, 252, 16,
\r
186 252, 252, 20, 252, 252, 24, 252, 252, 28, 252, 252, 32,
\r
187 252, 252, 36, 252, 252, 40, 252, 252, 40, 252, 252, 44,
\r
188 252, 252, 48, 252, 252, 52, 252, 252, 56, 252, 252, 60,
\r
189 252, 252, 64, 252, 252, 68, 252, 252, 72, 252, 252, 76,
\r
190 252, 252, 80, 252, 252, 84, 252, 252, 84, 252, 252, 88,
\r
191 252, 252, 92, 252, 252, 96, 252, 252, 100, 252, 252, 104,
\r
192 252, 252, 108, 252, 252, 112, 252, 252, 116, 252, 252, 120,
\r
193 252, 252, 124, 252, 252, 124, 252, 252, 128, 252, 252, 132,
\r
194 252, 252, 136, 252, 252, 140, 252, 252, 144, 252, 252, 148,
\r
195 252, 252, 152, 252, 252, 156, 252, 252, 160, 252, 252, 164,
\r
196 252, 252, 168, 252, 252, 168, 252, 252, 172, 252, 252, 176,
\r
197 252, 252, 180, 252, 252, 184, 252, 252, 188, 252, 252, 192,
\r
198 252, 252, 196, 252, 252, 200, 252, 252, 204, 252, 252, 208,
\r
199 252, 252, 208, 252, 252, 212, 252, 252, 216, 252, 252, 220,
\r
200 252, 252, 224, 252, 252, 228, 252, 252, 232, 252, 252, 236,
\r
201 252, 252, 240, 252, 252, 244, 252, 252, 248, 252, 252, 252
\r
204 unsigned char *screen;
\r
205 unsigned char *flamebuf_ptr;
\r
206 unsigned char *flamebuf;
\r
207 unsigned char temp;
\r
208 unsigned short int i, j, skip;
\r
209 unsigned char temp_byte;
\r
211 set_paletteX(fire_pal);
\r
212 set_write_plane(ALL_PLANES);
\r
213 flamebuf = new unsigned char[BUF_SIZE];
\r
216 // Initialize the video buffer to 0's
\r
217 memset(flamebuf, 0, BUF_SIZE);
\r
220 // Transform current buffer
\r
221 flamebuf_ptr = flamebuf;
\r
222 i = (BUF_HEIGHT - 2);
\r
224 *flamebuf_ptr = (*(flamebuf_ptr + BUF_WIDTH) +
\r
225 *(flamebuf_ptr + (BUF_WIDTH - 1)) +
\r
226 *(flamebuf_ptr + (BUF_WIDTH + 1)) +
\r
227 *(flamebuf_ptr + (BUF_WIDTH * 2))) >> 2;
\r
229 flamebuf_ptr += BUF_WIDTH;
\r
230 temp = *flamebuf_ptr;
\r
232 *flamebuf_ptr -= 12;
\r
233 } else if (temp > 3) {
\r
234 *flamebuf_ptr -= 4;
\r
238 flamebuf_ptr += (1 - BUF_WIDTH);
\r
240 j = (BUF_WIDTH - 2);
\r
242 *flamebuf_ptr = (*(flamebuf_ptr + BUF_WIDTH) +
\r
243 *(flamebuf_ptr + (BUF_WIDTH - 1)) +
\r
244 *(flamebuf_ptr + (BUF_WIDTH + 1)) +
\r
245 *(flamebuf_ptr + (BUF_WIDTH * 2))) >> 2;
\r
247 flamebuf_ptr += BUF_WIDTH;
\r
248 temp = *flamebuf_ptr;
\r
250 *flamebuf_ptr -= 12;
\r
251 } else if (temp > 3) {
\r
252 *flamebuf_ptr -= 4;
\r
256 flamebuf_ptr += (1 - BUF_WIDTH);
\r
259 *flamebuf_ptr = (*(flamebuf_ptr + BUF_WIDTH) +
\r
260 *(flamebuf_ptr + (BUF_WIDTH - 1)) +
\r
261 *(flamebuf_ptr + (BUF_WIDTH * 2)) +
\r
262 *(flamebuf_ptr + (BUF_WIDTH * 2) +
\r
263 (BUF_WIDTH - 1))) >> 2;
\r
265 flamebuf_ptr += BUF_WIDTH;
\r
266 temp = *flamebuf_ptr;
\r
268 *flamebuf_ptr -= 12;
\r
269 } else if (temp > 3) {
\r
270 *flamebuf_ptr -= 4;
\r
274 flamebuf_ptr += (1 - BUF_WIDTH);
\r
277 // Set new bottom line with random white or black
\r
279 flamebuf_ptr = flamebuf + (BUF_WIDTH * (BUF_HEIGHT - 2));
\r
284 // We change the value 1/4 of the time
\r
285 if ((rand() & 0x03) == 3) {
\r
286 temp = (255 - temp);
\r
289 *(flamebuf_ptr + BUF_WIDTH) = temp;
\r
290 *flamebuf_ptr++ = temp;
\r
293 // Write the buffer to the screen
\r
294 // wait_for_retrace();
\r
295 screen = RowsX[40];
\r
296 flamebuf_ptr = flamebuf;
\r
301 temp_byte = *flamebuf_ptr++;
\r
302 *screen = temp_byte;
\r
304 *screen = temp_byte;
\r
306 *screen = temp_byte;
\r
308 *screen++ = temp_byte;
\r
326 unsigned char pal[768];
\r
327 COORD x1, y1, x2, y2;
\r
328 Iangle theta1, theta2;
\r
329 Fixed32 trigSin, trigCos;
\r
330 blitbuf blit_image, sprite_image;
\r
331 clock_t begin, end;
\r
332 short int x, y, temp, done;
\r
333 long i, time1, time2, time3, count, mtime;
\r
337 set320x240x256_X();
\r
342 temp = loadfontX("vga8x8.fnt");
\r
345 putstringX(0, 0, "Hello!", 2);
\r
353 get_BIOSpaletteX(pal, 0);
\r
354 set_paletteX(pal, 0);
\r
357 for (x=0; x < 320; x++) {
\r
358 for (y=0; y < 240; y++) {
\r
359 putpixelX(x, y, (x & 0xFF));
\r
366 wait_for_retrace();
\r
373 load_blitbufPCX("spock.pcx", &blit_image);
\r
374 scale_blitbuf(160, 100, &blit_image);
\r
375 aligned_bitblitX(0, 0, &blit_image);
\r
383 scale_blitbuf(224, 140, &blit_image);
\r
384 aligned_bitblitX(0, 0, &blit_image);
\r
388 greyscale_blitbuf(&blit_image);
\r
390 aligned_bitblitX(0, 0, &blit_image);
\r
398 scale_blitbuf(160, 100, &blit_image);
\r
399 aligned_bitblitX(0, 0, &blit_image);
\r
403 clear_blitbuf(&blit_image);
\r
404 load_blitbufPCX("spock.pcx", &blit_image);
\r
405 greyscale_blitbuf(&blit_image);
\r
406 smooth64_paletteX(1, 0, 1);
\r
407 aligned_bitblitX(0, 0, &blit_image);
\r
411 flip_vertical_blitbuf(&blit_image);
\r
412 aligned_bitblitX(0, 0, &blit_image);
\r
416 clear_blitbuf(&blit_image);
\r
417 load_blitbufPCX("spock.pcx", &blit_image);
\r
418 aligned_bitblitX(0, 0, &blit_image);
\r
430 brighten_paletteX(1, 1, 1);
\r
434 brighten_paletteX(-1, -1, -1);
\r
438 stretch_paletteX(11, 11, 11);
\r
442 stretch_paletteX(24, 24, 24);
\r
447 save_blitbufPCX("dump.pcx", &blit_image);
\r
452 load_blitbufPCX("spock.pcx", &blit_image);
\r
456 brighten_paletteX(1, 0, 0);
\r
460 brighten_paletteX(0, 1, 0);
\r
464 brighten_paletteX(0, 0, 1);
\r
468 brighten_paletteX(-1, 0, 0);
\r
472 brighten_paletteX(0, -1, 0);
\r
476 brighten_paletteX(0, 0, -1);
\r
488 for (i=0; i < 10000; i++) {
\r
494 lineX(x1, y1, x2, y2, (i & 0x3F));
\r
499 time1 = (end - begin);
\r
503 for (i=0; i < 10000; i++) {
\r
509 temp = ((x1 + x2 + y1 + y2) & 0x3F);
\r
514 time2 = (end - begin);
\r
518 for (i=0; i < 120; i++) {
\r
519 filledboxX(i, i, (319-i), (239-i), (i & 0x3F));
\r
524 load_blitbufPCX("buddha.pcx", &sprite_image);
\r
525 transparent_bitblitX(100, 100, &sprite_image);
\r
530 clear_blitbuf(&blit_image);
\r
531 scale_blitbuf(152, 168, &sprite_image);
\r
532 alloc_blitbuf(&blit_image, 152, 168);
\r
535 aligned_bitblitX(84, 36, &sprite_image);
\r
546 ptr1 = sprite_image.image;
\r
547 ptr2 = blit_image.image;
\r
552 CosSin(theta2, &trigCos, &trigSin);
\r
553 scale_scanline(ptr1, ptr2, 152, 152, (trigCos >> 10) + 88);
\r
555 memcpy(ptr2+152, ptr2, 152);
\r
569 aligned_bitblitX(84, 36, &blit_image);
\r
578 clear_blitbuf(&blit_image);
\r
579 clear_blitbuf(&sprite_image);
\r
586 #if MONSTER_DEMO_ONE
\r
587 mtime = monster_demo1();
\r
590 #if MONSTER_DEMO_TWO
\r
597 Fixed32 c1, c2, c3, a1, a2, a3;
\r
599 c1 = INT_TO_FIXED(50);
\r
600 c2 = INT_TO_FIXED(70);
\r
601 c3 = INT_TO_FIXED(50 * 70);
\r
603 a1 = FixedMul(c1, c2);
\r
604 a2 = FixedMulASM(c1, c2);
\r
606 printf("MUL C version = %d\n", FIXED_TO_INT(a1));
\r
607 printf("MUL ASM version = %d\n", FIXED_TO_INT(a2));
\r
611 a1 = FixedDiv(c3, c1);
\r
612 a2 = FixedDivASM(c3, c1);
\r
614 printf("DIV C version = %d\n", FIXED_TO_INT(a1));
\r
615 printf("DIV ASM version = %d\n", FIXED_TO_INT(a2));
\r
620 temp = (time1 - time2);
\r
621 printf("10000 lines took %4d ticks\n", time1);
\r
622 printf("rand() overhead = %4d ticks\n", time2);
\r
623 printf("Time in lineX = %4d ticks\n", temp);
\r
624 printf("%d lines per second!\n\n", (10000 * 1000) / (55 * temp));
\r
626 temp = (end-begin);
\r
627 printf("Buddha = %4d blits\n", count);
\r
628 printf(" = %4d per second\n", (count * 1000) / (55 * temp));
\r
629 printf("Buddha = %4d scanline stretches\n", (count * 168));
\r
630 printf(" = %4d per second!\n\n", (count * 168000) / (55 * temp));
\r
632 printf("Monster took %d ticks for 99 frames\n", mtime);
\r