home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name grinit -- Initialize graphics (or text) mode
- *
- * Synopsis rmode = grinit(res,palette,backgrd);
- *
- * int rmode Returned video mode or -1 if error
- * int res Graphics mode
- * 0 - Synonym for mode 3
- * 1 - Synonym for mode 4
- * 2 - Synonym for mode 6
- * 3 - 80x25 color text mode
- * 4 - 320x200 4-color (2 palettes)
- * 5 - 320x200 b/w on Color Display
- * 6 - 640x200 b/w on Color Display
- * (EGA only) 13 - 320x200 16-color
- * (EGA only) 14 - 640x200 16-color
- * (EGA only) 15 - 640x350 Monochrome Display
- * (EGA only) 16 - 640x350 4 or 16 of 64 colors
- * (Enhanced Color Display only)
- * int palette Foreground palette for mode 4:
- * 0 - green/red/yellow
- * 1 - cyan/magenta/white
- * 2 - Palette 0 with high intensity
- * background
- * 3 - Palette 1 with high intensity
- * background
- * int backgrd For mode 3, the border color;
- * for mode 4, the background color;
- * for other modes, ignored.
- *
- * Description This function initializes the graphics mode by making a
- * call to SCRESET, and then sets the palette (or possibly
- * the border color) with calls to the BIOS. The external
- * variable b_home (the home plotting position) is
- * initialized. The maximum coordinate values (b_maxx and
- * b_maxy) are also set. In keeping with the IBM
- * definitions, the point coordinates are (x,y), where x=0
- * is the leftmost column and y=0 is the top row.
- *
- * An error occurs if a suitable adapter is not installed.
- * In that event, no reset occurs, the value of the
- * function is -1, and the values of the external variables
- * are undefined.
- *
- * Returns rmode The video mode set, or -1 if error.
- * b_home Initialized to {0,0}.
- * b_maxx Initialized to number of dot columns
- * on the screen.
- * b_maxy Initialized to number of dot rows
- * on the screen.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <bgraph.h>
- #include <bscreen.h>
-
- PT b_home = {0,0}; /* Home plotting position */
- int b_maxx = 0, /* Maximum coordinate values */
- b_maxy = 0; /* plus one. */
-
- int grinit(res,palette,backgrd)
- int res,palette,backgrd;
- {
- int ax,bx,cx,dx,flags; /* General registers for BIOS */
- int mode; /* Returned video mode */
-
- /* Initialize everything. Notice that b_maxx and b_maxy are set */
- /* to one more than the maximum value so that modular arithmetic */
- /* will wrap around for points plotted "off the screen." */
-
- b_home.x =
- b_home.y = 0;
-
- switch (res)
- {
- case 0:
- case 3: /* 80x25 color text mode */
- if (3 == (mode = screset(3)))
- {
- ax = 0x0b00; /* Set up border color. */
- bx = utbyword(0,backgrd % 16);
- bios(16,&ax,&bx,&cx,&dx,&flags);
- }
- break;
-
- case 1:
- case 4: /* 320x200 4-color (2 palettes) */
- if (4 == (mode = screset(4)))
- {
- b_maxx = 320;
- b_maxy = 200;
- backgrd &= 0x000f; /* Set the background color */
- if (palette > 1) /* Set the high intensity bit */
- backgrd |= 0x0010; /* for palettes 2 and 3. */
- palette &= 0x0001; /* Set the palette ..... */
- ax = 0x0b00;
- bx = utbyword(1,palette);
- bios(16,&ax,&bx,&cx,&dx,&flags);
- /* Now the background and pos- */
- /* sibly the high intensity bit */
- ax = 0x0b00;
- bx = utbyword(0,backgrd);
- bios(16,&ax,&bx,&cx,&dx,&flags);
- }
- break;
-
- case 2:
- res = 6;
- case 6: /* 640x200 b/w */
- case 14: /* 640x200 color */
- if (res == (mode = screset(res)))
- {
- b_maxx = 640;
- b_maxy = 200;
- }
- break;
-
- case 5: /* 320x200 b/w on Color Display */
- case 13: /* 320x200 16-color */
- if (res == (mode = screset(res)))
- {
- b_maxx = 320;
- b_maxy = 200;
- }
- break;
-
- case 15: /* 640x350 Monochrome Display */
- case 16: /* 640x350 4 or 16 of 64 colors */
- if (res == (mode = screset(res)))
- {
- b_maxx = 640;
- b_maxy = 350;
- }
- break;
-
- default: /* Unknown value of res */
- mode = -1;
- break;
- }
-
- return(mode);
- }