1 /* X-DEMO.C - a Mode "X" Demo */
\r
2 /* By Matt Pritchard, 14 Apr, 1993 */
\r
10 #define MAX_SHAPES 32
\r
11 #define MAX_SPRITES 64
\r
13 /* routines in this file */
\r
15 void demo_res (int, int, int);
\r
17 void error_out (char*);
\r
18 void load_shapes (void);
\r
19 int int_sqrt (int, int);
\r
20 void page_demo (void);
\r
22 /* Structures for Sprites */
\r
26 unsigned char Image[512];
\r
40 } Obj [MAX_SPRITES];
\r
46 int main(int argc, char *argv[])
\r
53 dos_print ("Unknown Argument: ");
\r
54 dos_print (makefp argv[argc]);
\r
66 demo_res ( Mode_320x200, 320, 200 );
\r
67 demo_res ( Mode_320x400, 320, 400 );
\r
69 demo_res ( Mode_360x200, 360, 200 );
\r
70 demo_res ( Mode_360x400, 360, 400 );
\r
72 demo_res ( Mode_320x240, 320, 240 );
\r
73 demo_res ( Mode_320x480, 320, 480 );
\r
75 demo_res ( Mode_360x240, 360, 240 );
\r
76 demo_res ( Mode_360x480, 360, 480 );
\r
81 dos_print ("This Mode X Demo is Finished");
\r
87 /* Demonstrate a given resolution */
\r
90 void demo_res (int Screen_Mode, int X_max, int Y_max)
\r
93 char *Error1 = "Failure while calling SET_MODEX";
\r
94 char *Error2 = "Failure during READ_PIXEL test";
\r
96 char *Abort_Msg = "Demo aborted by User";
\r
98 char *Demo_Msg = " This is a MODE X demo ";
\r
99 char *Scrn_Msg = "Screen Resolution is by ";
\r
100 char *Cont_Msg = "Press <ANY KEY> to Continue";
\r
102 char *Line_Msg = "LINE TEST";
\r
103 char *Fill_Msg = "FILL TEST";
\r
104 char *Pixel_Msg = "PIXEL TEST";
\r
108 int x1, y1, x2, y2 = 0;
\r
110 int X_Center, gap = 0;
\r
113 if (set_modex (Screen_Mode) == 0)
\r
115 error_out (Error1);
\r
118 X_Center = X_max / 2;
\r
125 for (z = 0; z <= 3; z++)
\r
128 draw_line (x1+z, y1+z, x2-z, y1+z, y);
\r
129 draw_line (x1+z, y1+z, x1+z, y2-z, y);
\r
130 draw_line (x1+z, y2-z, x2-z, y2-z, y);
\r
131 draw_line (x2-z, y1+z, x2-z, y2-z, y);
\r
134 for (x = 0; x < (X_max / 10); x++)
\r
136 tgprintc (48 + ((x+1) % 10), x*10+1, 1, 9 + ((x/8) % 7) );
\r
137 draw_line (x*10+9, 0, x*10+9, 3, c_bWHITE);
\r
140 for (y = 0; y < (Y_max / 10); y++)
\r
142 tgprintc (48 + ((y+1) % 10), 1, y*10+1, 9 + ((y/10) % 7) );
\r
143 draw_line (0, y*10+9, 3, y*10+9, c_bWHITE);
\r
146 for (x = 0; x <= 63; x++)
\r
148 z = 15 + (x * 3 / 4);
\r
149 set_dac_register (64+x, z, z, z);
\r
150 set_dac_register (128+x, 0, z, z);
\r
152 draw_line (103-x, 60, 40+x, 123, 64+x);
\r
153 draw_line (40, 60+x, 103, 123-x, 128+x);
\r
157 tprint_str (Line_Msg, 9, 37, 130, c_BLUE);
\r
161 for (x = 0; x <= 9; x++)
\r
163 fill_block (120, y, 120+x, y+gap, 64+x);
\r
164 fill_block (140 - (15-x), y, 150+x, y+gap, 230+x);
\r
165 fill_block (170 - (15-x), y, 170, y+gap, 128+x);
\r
170 tprint_str (Fill_Msg, 9, 110, 46, c_GREEN);
\r
172 for (x = 190; x <= 250; x+=2)
\r
174 for (y = 60; y <= 122; y+=2)
\r
176 z = (x+x+y+y) & 0xff;
\r
177 set_point (x, y, z);
\r
181 tprint_str (Pixel_Msg, 10, 182, 130, c_RED);
\r
183 for (x = 190; x <= 250; x+=2)
\r
185 for (y = 60; y <= 122; y+=2)
\r
187 z = (x+x+y+y) & 0xff;
\r
188 if (read_point(x, y) != z)
\r
190 error_out (Error2);
\r
195 print_str (Demo_Msg, 23, X_Center - 92, 20, c_bRED, c_BLUE);
\r
197 x = X_Center - 124;
\r
198 print_str (Scrn_Msg, 28, x, 30, c_bGREEN, c_BLACK);
\r
200 sprintf (Text, "%3d", X_max);
\r
201 print_str (Text, 3, x+168, 30, c_bPURPLE, c_BLACK);
\r
203 sprintf (Text, "%3d", Y_max);
\r
204 print_str (Text, 3, x + 224, 30, c_bWHITE, c_BLACK);
\r
206 for (x = 0; x <= 15; x++)
\r
208 set_dac_register (230+x, 63-x*4, 0, 15+x*3);
\r
209 draw_line (30+x, Y_max-6-x, X_max-20-x, Y_max-6-x, 230+x);
\r
212 tprint_str (Cont_Msg, 27, X_Center - 103, Y_max-18, c_YELLOW);
\r
214 if (get_key () == Ky_ESC)
\r
216 error_out (Abort_Msg);
\r
224 /* Wait for a Keystroke */
\r
234 c = scan_keyboard ();
\r
242 /* Error Handling Routine */
\r
245 void error_out (char * text)
\r
248 set_video_mode (3);
\r
250 exit (EXIT_SUCCESS);
\r
255 /* Routine to generate random sprites */
\r
258 void load_shapes ()
\r
261 unsigned char Grid[33][33];
\r
263 char *Error1 = "Bad Shape Selected Error";
\r
268 int X_Width, Y_Width, Center, S_Width;
\r
269 int Hollow_X, Hollow_Y;
\r
271 for (Shape = 0; Shape < MAX_SHAPES; Shape++)
\r
273 for (y = 0; y <= 32; y++)
\r
275 for (x = 0; x <= 32; x++)
\r
277 Grid[x][y] = c_BLACK;
\r
281 Style = random_int (6);
\r
282 Color = 1 + random_int (15);
\r
294 X_Width = 3 + random_int(30);
\r
295 Y_Width = 3 + random_int(30);
\r
297 } while ( (X_Width * Y_Width) >= 512);
\r
299 for (x = 1; x <= X_Width; x++)
\r
301 for (y = 1; y <= Y_Width; y++)
\r
303 Grid[x][y] = Color;
\r
316 X_Width = 6 + random_int(27);
\r
317 Y_Width = 6 + random_int(27);
\r
318 } while ( (X_Width * Y_Width) >= 512);
\r
320 for (y = 1; y <= Y_Width; y++)
\r
322 for (x = 1; x <= X_Width; x++)
\r
324 Grid[x][y] = Color;
\r
328 Hollow_X = 1 + random_int ((X_Width / 2) -1);
\r
329 Hollow_Y = 1 + random_int ((Y_Width / 2) -1);
\r
331 for (y = Hollow_Y+1; y <= Y_Width-Hollow_Y; y++)
\r
333 for (x = Hollow_X+1; x <= X_Width-Hollow_X; x++)
\r
335 Grid[x][y] = c_BLACK;
\r
343 /* SOLID DIAMOND */
\r
349 X_Width = 3 + 2 * random_int(10);
\r
351 Center = X_Width / 2;
\r
353 for (y = 0; y <= Center; y++)
\r
355 for (x = 0; x <= y; x++)
\r
357 Grid [Center-x+1][y+1] = Color;
\r
358 Grid [Center+x+1][y+1] = Color;
\r
359 Grid [Center-x+1][Y_Width-y] = Color;
\r
360 Grid [Center+x+1][Y_Width-y] = Color;
\r
368 /* HOLLOW DIAMOND */
\r
374 X_Width = 3 + 2 * random_int(10);
\r
376 Center = X_Width / 2;
\r
377 S_Width = random_int (Center);
\r
379 for (y = 0; y <= Center; y++)
\r
381 for (x = 0; x <= y; x++)
\r
383 if ( x+(Center-y) >= S_Width )
\r
385 Grid [Center-x+1][y+1] = Color;
\r
386 Grid [Center+x+1][y+1] = Color;
\r
387 Grid [Center-x+1][Y_Width-y] = Color;
\r
388 Grid [Center+x+1][Y_Width-y] = Color;
\r
403 X_Width = 7 + 2 * random_int (8);
\r
405 Center = 1 + X_Width / 2;
\r
407 for (y = 1; y <= Y_Width; y++)
\r
409 for (x = 1; x <= X_Width; x++)
\r
411 z = int_sqrt(Center-x, Center-y);
\r
414 Grid[x][y] = 150 + Color * 2 + z * 3;
\r
427 X_Width = 7 + 2 * random_int (8);
\r
429 Center = 1 + X_Width / 2;
\r
430 S_Width = random_int (X_Width);
\r
432 for (y = 1; y <= Y_Width; y++)
\r
434 for (x = 1; x <= X_Width; x++)
\r
436 z = int_sqrt(Center-x, Center-y);
\r
437 if ( (z < Center) && (z >= S_Width) )
\r
439 Grid[x][y] = 150 + Color * 2 + z * 3;
\r
451 error_out (Error1);
\r
459 for (y = 1; y <= Y_Width; y++)
\r
461 for (x = 1; x <= X_Width; x++)
\r
463 Img[Shape].Image[z] = Grid[x][y];
\r
468 Img[Shape].X_Width = X_Width;
\r
469 Img[Shape].Y_Width = Y_Width;
\r
477 /* Quickie Psuedo Integer Square Root Routine */
\r
480 int int_sqrt ( int x, int y )
\r
483 int Sqr_Table[12] = {1, 4, 9, 6, 25, 36, 49, 64, 81, 100, 121, 144};
\r
487 d = (x * x) + (y * y);
\r
490 while ( d >= Sqr_Table[r] )
\r
500 /* The Bit Sprite Demo */
\r
506 char *Error1 = "Failure during SET_VGA_MODEX (0, 320, 200, 2) call";
\r
508 int Last_Objects[2], Visible_Objects;
\r
510 int Screen_X = 384;
\r
511 int Screen_Y = 224;
\r
515 int x1, y1, x2, y2;
\r
517 int Sprite_X, Sprite_Y;
\r
521 int View_X, View_Y, View_Max, View_Cnt, View_XD, View_YD;
\r
522 int Set_Color, Prev_Color, S_Dir, P_Dir;
\r
524 int Demo_Running = True;
\r
528 pee = set_vga_modex(Mode_320x200, Screen_X, Screen_Y, 3);
\r
531 set_video_mode (3);
\r
532 dos_print (Error1);
\r
533 fprintf(stdout, "return value is %d\n", pee);
\r
534 //error_out (Error1);
\r
535 exit (EXIT_SUCCESS);
\r
538 set_active_page (0);
\r
539 clear_vga_screen (c_BLACK);
\r
541 print_str ("This is a Test of the Following Functions:", 99, 10, 9, c_bWHITE, c_BLACK);
\r
543 draw_line (10, 18, 350, 18, c_YELLOW);
\r
544 print_str ("SET_ACTIVE_PAGE", 99, 10, 20, c_bBLUE, c_BLACK);
\r
545 print_str ("SET_DISPLAY_PAGE", 99, 10, 30, c_GREEN, c_BLACK);
\r
546 print_str ("SET_DAC_REGISTER", 99, 10, 40, c_RED, c_BLACK);
\r
547 print_str ("CLEAR_VGA_SCREEN", 99, 10, 50, c_CYAN, c_BLACK);
\r
549 print_str ("TDRAW_BITMAP", 99, 10, 60, c_PURPLE, c_BLACK);
\r
550 print_str ("COPY_PAGE", 99, 10, 70, c_GREEN, c_BLACK);
\r
551 print_str ("COPY_BITMAP", 99, 10, 80, c_CYAN, c_BLACK);
\r
553 print_str ("GPRINTC", 99, 10, 90, c_BLUE, c_BLACK);
\r
554 print_str ("TGPRINTC", 99, 10, 100, c_GREEN, c_BLACK);
\r
555 print_str ("SET_WINDOW", 99, 10, 110, c_RED, c_BLACK);
\r
557 print_str ("VIRTUAL SCREEN SIZES", 20, 190, 20, c_bBLUE, c_BLACK);
\r
558 print_str (" SMOOTH SCROLLING", 20, 190, 30, c_GREEN, c_BLACK);
\r
559 print_str (" SPRITE ANIMATION", 20, 190, 40, c_CYAN, c_BLACK);
\r
560 print_str (" PAGE FLIPPING", 20, 190, 50, c_RED, c_BLACK);
\r
561 print_str (" COLOR CYCLING", 20, 190, 60, c_PURPLE, c_BLACK);
\r
563 for (x = 0; x <=60; x++)
\r
565 set_dac_register (50 + x, 3 + x, 0, 60 - x);
\r
566 set_dac_register (150 + x, 3 + x, 0, 60 - x);
\r
571 for (x = 0; x <= (Screen_X / 2); x++)
\r
573 draw_line (Screen_X / 2 - 1, Screen_Y / 4, x, Screen_Y - 1, c + 50);
\r
574 draw_line (Screen_X / 2, Screen_Y / 4, Screen_X - x - 1, Screen_Y - 1, c + 50);
\r
576 if ((c == 0) || (c == 60) ) { dc = -dc;}
\r
579 tprint_str ("Press <ANY KEY> to Continue", 99, 72, 190, c_bWHITE);
\r
580 tprint_str ("< > = Faster < > = Slower", 99, 72, 204, c_bGREEN);
\r
581 tprint_str ("< > = Fewer Shapes < > = More Shapes", 99, 32, 218, c_bCYAN);
\r
583 tgprintc (43, 80, 204, c_YELLOW);
\r
584 tgprintc (45, 200, 204, c_YELLOW);
\r
586 tgprintc (25, 40, 218, c_YELLOW);
\r
587 tgprintc (24, 200, 218, c_YELLOW);
\r
592 for (x = 0; x < MAX_SPRITES; x++)
\r
595 Obj[x].X_Dir = random_int(7) - 3;
\r
596 Obj[x].Y_Dir = random_int(7) - 3;
\r
597 } while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );
\r
599 Obj[x].Shape = x % MAX_SHAPES;
\r
601 Sprite_X = Img[Obj[x].Shape].X_Width;
\r
602 Sprite_Y = Img[Obj[x].Shape].Y_Width;
\r
604 Obj[x].X_pos = 1 + random_int(Screen_X - Sprite_X - 2);
\r
605 Obj[x].Y_pos = 1 + random_int(Screen_Y - Sprite_Y - 2);
\r
607 Obj[x].Last_X[0] = Obj[x].X_pos;
\r
608 Obj[x].Last_X[1] = Obj[x].X_pos;
\r
609 Obj[x].Last_Y[0] = Obj[x].Y_pos;
\r
610 Obj[x].Last_Y[1] = Obj[x].Y_pos;
\r
628 Visible_Objects = MAX_SPRITES / 2;
\r
629 Last_Objects[0] = 0;
\r
630 Last_Objects[1] = 0;
\r
632 while (Demo_Running)
\r
635 set_active_page (Current_Page);
\r
637 /* Erase Old Images */
\r
639 for (x = 0; x <= Last_Objects[Current_Page]; x++)
\r
643 x1 = Obj[x].Last_X[Current_Page];
\r
644 y1 = Obj[x].Last_Y[Current_Page];
\r
645 x2 = x1 + Img[y].X_Width -1;
\r
646 y2 = y1 + Img[y].Y_Width -1;
\r
651 copy_bitmap (z, x1, y1, x2, y2, Current_Page, x1, y1);
\r
654 /* Draw new images */
\r
656 for (x = 0; x <= Visible_Objects; x++)
\r
658 Sprite_X = Img[Obj[x].Shape].X_Width;
\r
659 Sprite_Y = Img[Obj[x].Shape].Y_Width;
\r
666 New_X = Obj[x].X_pos + Obj[x].X_Dir;
\r
668 if (( New_X < 0 ) || (New_X + Sprite_X > Screen_X) )
\r
670 Obj[x].X_Dir = -Obj[x].X_Dir;
\r
671 if (random_int(20) == 1)
\r
675 Obj[x].X_Dir = random_int(7) - 3;
\r
676 Obj[x].Y_Dir = random_int(7) - 3;
\r
677 } while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );
\r
682 Obj[x].X_pos = Obj[x].X_pos + Obj[x].X_Dir;
\r
688 New_Y = Obj[x].Y_pos + Obj[x].Y_Dir;
\r
690 if ( (New_Y < 0) || (New_Y + Sprite_Y > Screen_Y) )
\r
692 Obj[x].Y_Dir = -Obj[x].Y_Dir;
\r
693 if (random_int(20) == 1)
\r
697 Obj[x].X_Dir = random_int(7) - 3;
\r
698 Obj[x].Y_Dir = random_int(7) - 3;
\r
699 } while ( (Obj[x].X_Dir == 0) && (Obj[x].Y_Dir == 0) );
\r
705 Obj[x].Y_pos = Obj[x].Y_pos + Obj[x].Y_Dir;
\r
709 tdraw_bitmap ((char far*) &Img[Obj[x].Shape], Obj[x].X_pos, Obj[x].Y_pos, Sprite_X, Sprite_Y);
\r
711 Obj[x].Last_X[Current_Page] = Obj[x].X_pos;
\r
712 Obj[x].Last_Y[Current_Page] = Obj[x].Y_pos;
\r
716 Last_Objects[Current_Page] = Visible_Objects;
\r
719 /* Pan Screen Back & Forth */
\r
722 if (View_Cnt >= View_Max)
\r
725 if ( (View_X == 0) || (View_X == 39) ) {View_XD = -View_XD;}
\r
729 if ( (View_Y == 0) || (View_Y == 39) ) {View_YD = -View_YD;}
\r
732 set_window (Current_Page, View_X, View_Y);
\r
738 set_display_page (Current_Page);
\r
743 set_dac_register (50 + Prev_Color, 3 + Prev_Color, 0, 60 - Prev_Color);
\r
744 set_dac_register (50 + Set_Color, Set_Color, 10, 63 - Set_Color);
\r
746 set_dac_register (150 + Prev_Color, 3 + Prev_Color, 0, 60 - Prev_Color);
\r
747 set_dac_register (150 + Set_Color, 63, 63, Set_Color);
\r
750 if ( (Set_Color == 60) || (Set_Color == 0) ) {S_Dir = -S_Dir;}
\r
752 Prev_Color+= P_Dir;
\r
753 if ( (Prev_Color == 60) || (Prev_Color == 0) ) {P_Dir = -P_Dir;}
\r
755 /* Check for Keystroke */
\r
757 Current_Page = Current_Page ^ 0x01;
\r
759 code = scan_keyboard ();
\r
761 if (code == Ky_ESC) {Demo_Running = False;}
\r
763 if (code == Ky_Plus)
\r
765 if (View_Max < 12) {View_Max++;}
\r
768 if (code == Ky_Minus)
\r
770 if (View_Max > 1) {View_Max--;}
\r
771 if (View_Cnt >= View_Max) {View_Cnt = 0;}
\r
776 if (Visible_Objects < MAX_SPRITES-1) {Visible_Objects++;}
\r
779 if (code == Ky_Down)
\r
781 if (Visible_Objects > 0) {Visible_Objects--;}
\r