home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <dos.h>
-
- /************************************************************************/
- /* This is a main routine which is used to test all the functions */
- /* provided in the examples. This program allows the operator to */
- /* select the function to be demonstrated and will call the approriate */
- /* sample routine. To quit select any number outside the range. */
- /************************************************************************/
-
- main()
- {
- select_demo();
- }
- #include "progc000.c"
- #include "progc001.c"
- #include "progc002.c"
- #include "progc003.c"
- #include "progc004.c"
- #include "progc005.c"
-
- /************************************************************************/
- /* Test low level example: Get_Cursor_Address */
- /************************************************************************/
-
- test_GCA()
- {
- printf("\nCursor address = %X hex",get_cursor_address());
- }
-
- /************************************************************************/
- /* Test BIOS example: BIOS_Palette */
- /************************************************************************/
-
- test_BP()
- {
- #define MONO 5
- #define VMONO 7
- if (get_display_type() == MONO || get_display_type() == VMONO)
- set_mode(7); /* Example uses values for color*/
- /* color display, cannot use */
- else /* with mono displays */
- BIOS_Palette();
- }
-
- #include "progc006.c"
-
- /************************************************************************/
- /* Time how long it takes to get 32000 retraces */
- /************************************************************************/
-
- wait_4_horiz()
- {
- int i;
- long int count, ticks();
- printf("\n...counting");
- count = ticks(); /* Get current tick */
- for (i = 0; i < 32000; i++)
- horizontal_retrace(); /* Wait for start of */
- /* next retrace */
- count = ticks() - count;
- printf("\n32,000 horizontal retraces took %ld ticks",count);
- printf("\nThat is %d Hz horizontal rate",
- (32000 * (long)91)/(5 * count));
- }
-
- #include "progc007.c"
- #include "progc009.c"
- #include "progc010.c"
- #include "progc011.c"
- #include "progc012.c"
- #include "progc013.c"
- #include "progc014.c"
-
- /************************************************************************/
- /* Test low level exammple: Clear screen using BIOS scroll */
- /************************************************************************/
-
- test_BC()
- {
- BIOS_Clear();
- }
- #include "progc020.c"
-
- /************************************************************************/
- /* Fetch current mode using BIOS function F */
- /************************************************************************/
-
- print_BIOS_mode()
- {
- /* Print current video mode */
- printf("\nCurrent video mode is %x hex", BIOS_get_mode());
- }
-
- #include "progc021.c"
- #include "progc022.c"
- #include "progc023.c"
- #include "progc024.c"
- #include "progc025.c"
- #include "progc026.c"
- #include "progc027.c"
-
- /************************************************************************/
- /* Test BIOS example to get type display attached to EGA */
- /************************************************************************/
-
- test_BIOS_display()
- {
- static char *types[] =
- {"Unknown", "Unknown", "Unknown", "Enhanced",
- "Color", "Monochrome", "Unknown", "Monochrome",
- "Color"};
- int index;
- index = BIOS_get_display(); /* Get display type */
- /* Print the type */
- if (index < 7)
- printf("\n%s Display attached to EGA", types[index]);
- else if (index < 9)
- printf("\n%s Display attached to VGA", types[index]);
- else
- printf("\EGA/VGA are not installed");
- }
-
- #include "progc028.c"
- #include "progc029.c"
-
- /************************************************************************/
- /* Test BIOS call to get memory size */
- /************************************************************************/
-
- test_BIOS_RAM()
- {
- int memory; /* Declare variables */
- memory = BIOS_get_mem(); /* Get memory size */
- printf("\n%dKBytes of Memory Available", memory); /*Print it */
- }
-
- #include "progc030.c"
- #include "progc031.c"
- #include "progc032.c"
-
- #include "progc040.c"
-
- /************************************************************************/
- /* Test BIOS function example which sets cursor in upper right */
- /************************************************************************/
-
- test_BIOS_SCP()
- {
- cls();
- BIOS_set_curs_pos(0,79); /* Set cursor to upper right */
- printf("This string starts at upper right");
- }
-
- #include "progc041.c"
-
- /************************************************************************/
- /* Test BIOS function example which gets current cursor position */
- /************************************************************************/
-
- test_BIOS_GCP()
- {
- int pos;
- pos = BIOS_get_cursor_pos(0,79);/* Set cursor to upper right */
- printf("\nCursor at row=%d col=%d", pos >> 8, pos & 0x00FF);
- }
-
- #include "progc042.c"
-
- /************************************************************************/
- /* Test BIOS function example which sets current cursor size */
- /************************************************************************/
-
- test_BIOS_SCS()
- {
- char far *p = 0; /* Declare pointer to BIOS area */
- if (p[0x485] > 8) /* Check char height */
- BIOS_set_curs_size(10,11); /* Set cursor size to underline */
- else
- BIOS_set_curs_size( 6, 7); /* Set cursor size to underline */
- }
-
- /************************************************************************/
- /* Test BIOS function to get current cursor size */
- /************************************************************************/
-
- test_BIOS_GCS()
- {
- int size; /* Declare variables */
- size = BIOS_get_curs_size(); /* Get size */
- printf("\nCursor starts at %d and stops at %d",
- size >> 8, size & 0x00FF); /* Print the values */
- }
-
- #include "progc043.c"
-
- /************************************************************************/
- /* Test BIOS example of text window scroll */
- /************************************************************************/
-
- test_BIOS_ST()
- {
- int i,j;
- for (i = 0; i < 25; i++) /* Fill screen with data */
- {
- printf("\n");
- for (j = 0; j < 40; j++)
- printf("%1d",i%10);
- }
- getchar(); /* Wait for <Enter> */
- BIOS_Scroll_Text(1,3,12,19, -6);/* Scroll text window down */
- }
-
- #include "progc044.c"
-
- /************************************************************************/
- /* Test BIOS example of page scroll */
- /************************************************************************/
-
- test_BIOS_SP()
- {
- int i;
- for (i = 0; i < 25; i++) /* Fill screen with data */
- printf("\nThis is line %d",i);
- getchar(); /* Wait for <Enter> */
- BIOS_Scroll_Page( -6); /* Scroll text page down by 6 */
- }
-
- #include "progc045.c"
-
- /************************************************************************/
- /* Test BIOS examples of character write */
- /************************************************************************/
-
- test_BIOS_WC()
- {
- BIOS_Char_9(); getchar();
- BIOS_Char_A(); getchar();
- BIOS_Char_E(); getchar();
- BIOS_Char_13();
- }
-
- #include "progc046.c"
-
- /************************************************************************/
- /* Test the BIOS example of inverting character attribute */
- /************************************************************************/
-
- test_BIOS_IA()
- {
- int row, col; /* Declare local variables */
- for (row = 0; row < 12; row++) /* Loop over 12 rows */
- for (col = 0; col < 80; col++) /* Loop over 80 columns */
- { /* Set cursor position and */
- set_cursor_position(row, col);
- BIOS_invert(); /* invert attribute */
- }
- }
-
- #include "progc047.c"
-
- /************************************************************************/
- /* Test the BIOS example of blink enable/disable */
- /************************************************************************/
-
- test_BIOS_B()
- {
- #define DISABLE 0
- BIOS_blink(DISABLE);
- }
-
- #include "progc048.c"
-
- /************************************************************************/
- /* Test the BIOS example of string write */
- /************************************************************************/
-
- test_BIOS_WS()
- {
- BIOS_write_string();
- }
-
- #include "progc049.c"
-
- /************************************************************************/
- /* Test the BIOS example of get pointer to ROM based character generator*/
- /************************************************************************/
-
- test_BIOS_GCG()
- {
- int long char_gen, BIOS_get_rom_cg();
- char_gen = BIOS_get_rom_cg();
- printf("\nCharacter generator pointer = %lx", char_gen);
- }
-
- #include "progc050.c"
-
- /************************************************************************/
- /* Test the BIOS example of overwrite first 32 characters with a box */
- /************************************************************************/
-
- test_BIOS_WCG()
- {
- int i;
- for (i = 0; i < 64; i++) write_char(i, 24, i);
- BIOS_Write_CG();
- }
-
- #include "progc051.c"
-
- /************************************************************************/
- /* Test the BIOS example of downloading two character generators */
- /************************************************************************/
-
- test_BIOS_512()
- {
- static char seta[256][32]; /* Buffer for char gen */
- static char setb[256][32]; /* Buffer for char gen */
- int i, j;
-
- /*--- Read the first set and 'italicize' it into second */
-
- read_char_gen(seta); /* Read old character generator */
- read_char_gen(setb); /* Read old character generator */
- for (i = 0; i < 255; i++) /* Create a new char set */
- for (j = 0; j < 4; j++) /* from the old by 'italisizing'*/
- {
- setb[i][j] = setb[i][j] >> 1;
- setb[i][j+10] = setb[i][j+10] << 1;
- }
-
- /* Download the two character generators using BIOS funciton */
-
- BIOS_512_Set(seta, setb);
- }
-
- #include "progc052.c"
-
- #include "progc053.c"
-
- /************************************************************************/
- /* Test BIOS example for setting 43 lines */
- /************************************************************************/
-
- test_BIOS_43()
- {
- int i, mode;
- mode = get_mode(); /* Get current mode */
- BIOS_43_lines(); /* Set 43 text mode */
- for (i = 0; i < 43; i++) /* Fill screen with text*/
- printf("\nThis is line %d in 43 line text mode",i);
- getchar(); /* Wait for <Enter> key */
- set_mode(mode); /* Restore all by */
- } /* setting mode */
-
- #include "progc054.c"
-
- #include "progc055.c"
-
- #include "progc056.c"
-
- /************************************************************************/
- /* Test BIOS example of reading characters */
- /************************************************************************/
-
- test_BIOS_RC()
- {
- printf("\Character read using BIOS is: %2x(hex)",
- BIOS_read_char(24, 0));
- }
-
- #include "progc057.c"
-
- /************************************************************************/
- /* Test BIOS example of reading attributes */
- /************************************************************************/
-
- test_BIOS_RA()
- {
- printf("\Attribute read using BIOS is: %2x(hex)",
- BIOS_read_attr(24, 0));
- }
-
- /************************************************************************/
- /* Routine to use to setup a graphics mode and call demo routine */
- /************************************************************************/
-
- /************************************************************************/
- /* Routine to use to setup a graphics mode and call demo routine */
- /************************************************************************/
-
- do_demo_routine()
- {
- #define MONO 5
- #define VMONO 7
- #define COLOR 4
- #define ENHANCED 3
- #define VCOLOR 8
- int type;
-
- /* Get display type and select mode accordingly */
-
- type = get_display_type(); /* Get display type */
- switch (type) /* Set mode according to*/
- { /* type of display */
- case VMONO:
- case MONO:
- set_mode(0x0F);
- break;
- case COLOR:
- set_mode(0x0E);
- break;
- case VCOLOR:
- case ENHANCED:
- set_mode(0x10);
- break;
- }
-
- /* Call procedure to perform the example */
-
- demo_routine(); /* Draw the example */
- getchar(); /* Wait for <Enter> */
-
- /* Restore the original mode */
-
- if (type == MONO) setmode(7); /* Restore text mode */
- else setmode(3);
- exit(0); /* Quit */
- }
-
- demo_routine()
- {
- /* This is where we would call our test routine */
- }
-
- /************************************************************************/
- /* Test BIOS example of pixel write */
- /************************************************************************/
-
- test_BIOS_PW()
- {
- cls();
- BIOS_Pixel_Write();
- }
-
- #include "progc080.c"
- #include "progc081.c"
-
- /************************************************************************/
- /* Test BIOS example of pixel read */
- /************************************************************************/
-
- test_BIOS_PR()
- {
- int x, y;
- for (x = 0, y = 19; x < 10; x++)
- printf(" %2d", BIOS_Pixel_Read(x,y));
- }
-
- #include "progc082.c"
- #include "progc083.c"
- #include "progc084.c"
- #include "progc085.c"
-
- /************************************************************************/
- /* Test slow line demo routine */
- /************************************************************************/
-
- slow_radial_lines()
- {
- int i;
- cls();
- for (i = 0; i < 640; i += 20) slow_line(320,100,i, 0,i/20);
- for (i = 0; i < 640; i += 20) slow_line(320,100,i,199,i/20);
- for (i = 0; i < 200; i += 10) slow_line(320,100,0, i,i/10);
- for (i = 0; i < 200; i += 10) slow_line(320,100,639,i,i/10);
- }
-
- /************************************************************************/
- /* Draw a moving line in each quadrant of the screen. Each of the */
- /* four lines has a different color and the endpoints of the line will */
- /* 'bounce' of the edges of the corresponding quadrant. */
- /************************************************************************/
-
- #define M 100
- #define N 10
- #define MAXX 319
- #define MAXY 174 /* Change this to 100 for Color Monitor */
-
- lines_demo()
- {
- int i, j, k, p[4], d[4], c1 = 8,c2 = 9,c3 =10,c4 =11;
- int l, n;
- long x0,y0,x1,y1,ticks();
- if (kbhit()) return;
-
- cls(); /* Clear screen */
-
- /****************************************************************/
- /* start a next set of four lines, picking semirandom starting */
- /* point at p and moving with speed d. */
- /****************************************************************/
-
- while(!kbhit())
- {
- x0=ticks(); x1=ticks()*33; y0=ticks()*23; y1=ticks()*7;
- p[0] = (x0 * 320) & 255; /*initial points of the line*/
- p[1] = (y0 * 175) & 127;
- p[2] = p[0] + 15 + (p[0] & 7);
- p[3] = p[1] + 15 + (p[0] & 7);
- d[0] = 5 + x0 & 7; /*initial motion vector */
- d[1] = 7 + x1 & 7;
- d[2] = 5 + y0 & 7;
- d[3] = 7 + y1 & 7;
- cls();
-
- /* pick four semirandom colors */
-
- if (get_display_type() == MONO || get_display_type() == VMONO)
- c1 = c2 = c3 = c4 = 15;
- else
- {
- c1 = (++c1) & 15;
- if (c1 == 13) c1 = 8;
- c2 = c1 + 1; c3 = c1 + 2; c4 = c1 + 3;
- }
-
- /****************************************************************/
- /* draw the line (and the three mirror images) and then compute */
- /* new position */
- /****************************************************************/
-
- for (n = 0; n < M && !kbhit(); n++)
- {
- i = p[0]; j = p[1]; k = p[2]; l = p[3];
- line(i,j,k,l,c1);
-
- i = 639 - i; k = 639 - k;
- line(i,j,k,l,c2);
-
- j = 349 - j; l = 349 - l;
- line(i,j,k,l,c3);
-
- i = 639 - i; k = 639 - k;
- line(i,j,k,l,c4);
-
- /* update position of the line */
-
- move(p, d);
- }
- for (x0 = ticks(); ticks() - x0 < 18;); /*Take a rest*/
- }
- return;
- }
-
- move(p, d)
- int p[4], d[4];
- {
- /****************************************************************/
- /* update two end points of a line (four coordinates) with the */
- /* values specified in d. Should the resulting points fall */
- /* outside the bounds, 'bounce' them of the sides. */
- /****************************************************************/
-
- int i;
- /*reverse motion if lines fall outside the bounds */
- if ((p[0] + d[0]) < 0) d[0] = -d[0];
- if ((p[0] + d[0]) > MAXX) d[0] = -d[0];
- if ((p[1] + d[1]) < 0) d[1] = -d[1];
- if ((p[1] + d[1]) > MAXY) d[1] = -d[1];
- if ((p[2] + d[2]) < 0) d[2] = -d[2];
- if ((p[2] + d[2]) > MAXX) d[2] = -d[2];
- if ((p[3] + d[3]) < 0) d[3] = -d[3];
- if ((p[3] + d[3]) > MAXY) d[3] = -d[3];
- /*compute next endpoints of the line */
- for (i = 0; i < 4; i ++)
- p[i] = p[i] + d[i];
- }
-
- #include "progc086.c"
-
- /************************************************************************/
- /* Test slow pattern line routine */
- /************************************************************************/
-
- slow_pattern_radials()
- {
- int i;
- cls();
- for(i= 0; i < 640; i += 20)slow_pattern_line(320,100,i, 0,i/20,0x0F0F);
- for(i= 0; i < 640; i += 20)slow_pattern_line(320,100,i,199,i/20,0x0F0F);
- for(i= 0; i < 200; i += 10)slow_pattern_line(320,100,0, i,i/20,0x0F0F);
- for(i= 0; i < 200; i += 10)slow_pattern_line(320,100,639,i,i/20,0x0F0F);
- }
-
-
- #include "progc087.c"
- #include "progc088.c"
- #include "progc089.c"
- #include "progc090.c"
- #include "progc095.c"
-
- /************************************************************************/
- /* Test the demo routine 'slow_bitblt' */
- /* Copy a 100x100 block from upper left corner of the screen */
- /* and move it successively 10 times, two pixels at a time */
- /************************************************************************/
-
- test_slow_bitblt()
- {
- #define COPY 0
- int i;
- for (i = 0; i < 10; i += 2) /* Copy next block */
- slow_bitblt(0, 0, 320 + i, 100 + i, 100, 100, COPY);
- }
-
- #include "progc091.c"
- #include "progc092.c"
- #include "progc093.c"
- #include "progc094.c"
-
- /************************************************************************/
- /* This is a main routine which is used to test all the functions */
- /* provided in the examples. This program allows the operator to */
- /* select the function to be demonstrated and will call the approriate */
- /* sample routine. To quit select any number outside the displayed */
- /* range */
- /************************************************************************/
-
- select_demo()
- {
- int select, i, j;
- char buffer[10];
- typedef int (*FnPtr)();
- struct Demo_Table
- {
- char *prompt;
- FnPtr proc;
- };
-
- #define MAX_PROC 83
- static struct Demo_Table demo_table[MAX_PROC] = {
- "Write_Reg (cursor start to 1)", write_curs_start,
- "Write_Reg_Set (load mode 0, 3 or 7)", select_mode_x,
- "Read Reg (cursor address)", read_cursor_address,
- "Read Reg (feature bits)", read_feature,
- "Read Reg (switches)", read_switches,
- "Read Reg (low level cursor addr)", test_GCA,
- "Write Palette (invert B & W)", invert_B_n_W,
- "Write Palette (BIOS call)", test_BP,
- "Vert Retrace (count)", wait_4_vert,
- "Horiz Retrace (count)", wait_4_horiz,
-
- "Smooth horiz (use cursor keys & ESC)", smooth_horizontal,
- "Smooth vert (use cursor keys & ESC)", smooth_vertical,
- "Clear Screen (fill memory)", cls,
- "Clear Screen (use BIOS call)", test_BC,
- "Video BIOS (print string)", test_video_BIOS,
- "Set Mode (lib)", test_set_mode,
- "Get Cursor Position (test BIOS)", test_BIOS_GCP,
- "Get Mode (from library fn)", print_mode,
- "Get Mode (from BIOS)", print_BIOS_mode,
-
- "Get Mode (from BIOS data area)", print_data_mode,
- "Get Rows & Cols (library fn)", print_rows_cols,
- "Get Rows & Cols (from BIOS data area)",print_data_rc,
- "Get Page Size (library fn)", print_page_size,
- "Get Page Size (from BIOS data area)", print_data_page_size,
- "Get Display Type (library fn)", print_display_type,
- "Get Display Type (BIOS help)", test_BIOS_display,
- "Get Scanlines (lib)", print_scanlines,
- "Get Memory Size (library fn)", print_memory_size,
- "Get Memory Size (BIOS call)", test_BIOS_RAM,
-
- "Get Primary (library fn)", print_primary,
- "Get Primary (from BIOS data area)", print_data_primary,
- "Get Second (library fn)", print_if_second,
- "Set Curs Pos (library fn)", cursor_in_middle,
- "Set Curs Pos (test BIOS example)", test_BIOS_SCP,
- "Set Curs Size (library fn)", demo_cursor_size,
- "Set Curs Size (test BIOS example)", test_BIOS_SCS,
- "Get Curs Size (library fn)", print_cursor_size,
- "Get Curs Size (test BIOS fn)", test_BIOS_GCS,
- "Scroll text (scroll window using lib)",sample_scroll_text,
-
- "Scroll text (scroll window using BIOS)",test_BIOS_ST,
- "Scroll page (scroll lines using lib)", sample_scroll_page,
- "Scroll page (scroll lines using BIOS)",test_BIOS_SP,
- "Write char (library fn)", write_one_char,
- "Write char (test four BIOS calls)", test_BIOS_WC,
- "Write attrib (library fn)", make_reverse,
- "Write attrib (use BIOS to invert)", test_BIOS_IA,
- "Read char (library fn)", print_10_chars,
- "Read char (test BIOS call)", test_BIOS_RC,
- "Read attrib (library fn)", print_10_attr,
-
- "Read attrib (test BIOS call)", test_BIOS_RA,
- "Text Blink (library fn)", demo_text_blink,
- "Text Blink (BIOS fn)", test_BIOS_B,
- "Write String (library fn)", print_hello,
- "Write String (BIOS example)", test_BIOS_WS,
- "Read Char Gen (library fn)", italicize,
- "Read Char Gen (test BIOS example)", test_BIOS_GCG,
- "Write Char Gen (library fn)", replace_a,
- "Write Char Gen (test BIOS example)", test_BIOS_WCG,
- "512 Set (library fn)", print_512_chars,
-
- "512 Set (test BIOS example)", test_BIOS_512,
- "Split Screen (use cursor keys)", demo_split_screen,
- "Set 43 Lines (library function)", demo_43_lines,
- "Set 43 Lines (test BIOS example)", test_BIOS_43,
- "Drawing text boxes", boxed_hello,
- "Smooth text scroll", smooth_text_scroll,
- "Pixel Write (16 boxes using lib)", pixel_box16,
- "Pixel Write (BIOS box)", test_BIOS_PW,
- "Pixel Read (10 values using lib)", read_10_pixels,
- "Pixel Read (10 values using BIOS)", test_BIOS_PR,
-
- "Scanline (lib draw triangle)", fill_triag,
- "Solid box (lib 16 boxes)", solid_box16,
- "Line (lib radial lines)", radial_lines,
- "Line (lib lines demo)", lines_demo,
- "Slow line (slow radial lines)", slow_radial_lines,
- "Patterned line (slow radials)", slow_pattern_radials,
- "Patterned line (slow triangle)", pattern_triag,
- "Patterned line (slow checkers)", checkers,
- "Arc", arc_demo,
- "BITBLT (lib slide down_right)", slide_block,
-
- "BITBLT (test slow slide)", test_slow_bitblt,
- "Graphics Cursor (use arrow keys)", demo_cursor,
- "Screen Dump (save into PICTURE.xxx)", save_screen,
- "Screen Load (lib load PICTURE.xxx)", restore_screen
- };
-
- /****************************************************************/
- /* Here we print all prompts and user selects which routine */
- /* to do next. 0 to do all, out of range to quit */
- /****************************************************************/
-
- select = 0;
- while(1)
- {
- if (select == -1)
- for (j = 0; j <= MAX_PROC; j += 22)
- {
- for (i = 0; i < 22 && i + j < MAX_PROC; i++)
- printf("\n%3d: %s",i+j+1,demo_table[i+j].prompt);
- if (j < MAX_PROC - 22) getchar();
- }
- printf("\nEnter test (0 = all, -1 = list, 99 = quit): ");
- gets(buffer);
- sscanf(buffer,"%d",&select);
-
- /********************************************************/
- /* User wants to quit so oblige */
- /********************************************************/
-
- if (select > MAX_PROC || select < -1)
- exit(0);
-
- /********************************************************/
- /* A single function has been selected so wait for */
- /* Enter key, call the sample procedure, wait for Enter */
- /* agin (so user can marvel at the display). */
- /********************************************************/
-
- else if (select > 0)
- {
- set_cursor_position(24,0);
- printf("\nPress <Enter> to '%d: %s'",
- select, demo_table[select-1].prompt);
- getchar();
- (*(demo_table[select-1].proc))();
- getchar();
- select++;
- }
-
- /********************************************************/
- /* Loop throgh all the samples one a time and wait for */
- /* Enter key to be pressed at the start of each sample */
- /* and after each sample is done. */
- /********************************************************/
-
- else if (select == 0)
- for (i = 0; i < MAX_PROC; i++)
- {
- set_cursor_position(24,0);
- printf("\nPress <Enter> to '%d: %s'",
- i+1,demo_table[i].prompt);
- getchar();
- (*(demo_table[i].proc))();
- getchar();
- }
- else
- {
- }
- }
-
- }