home *** CD-ROM | disk | FTP | other *** search
- /*
- * TITLE scrn1.c
- *
- * AUTHOR Tim Spencer - Compuserve [73657,1400]
- * DATE March 13, 1987
- */
-
- #include "dos.h"
- #include "video.h"
-
-
- /************************************************************************
- scrn_init - Initializes the structure used to pass the screen buffer
- address, offset(logical cursor), status port address, and
- the boolean cga_card value to the assembler functions
- that handle writing/reading directly to/from the screen.
-
- Example: SCRN *scrn; declare scrn to be type SCRN
- scrn_init(&scrn); initialize the structure scrn
-
- Important: A structure of type SCRN **must** be declared and initialized
- as in this example before using any other scrn_xxx functions.
- Otherwise, your computer will surely lock up.
- *************************************************************************/
- void scrn_init(scrn)
- SCRN *scrn; /* pointer to the structure */
- {
- int cols; /* not used, but must be declared for vid_state() */
- int mode; /* current mode - mono, CO80, etc. */
- int card; /* card type...mono, cga, ega... */
-
- switch( (mode = vid_state(&cols)) ) { /* get current video mode... */
- /* and make sure it's 80 columns */
- case MONO_MODE:
- case BW80_MODE:
- case CO80_MODE:
- break; /* no problem */
-
- default: /* sorry, no graphics or 40 cols allowed */
- vid_init(BW80_MODE);
- break;
- }
-
- /* now set up screen buffer address and status port in SCRN structure */
-
- if ((card = vcard_type()) == MONO_ADAPTER) {
- scrn->segment = MONO_SEG;
- scrn->stat_port = MONO_BASE + CRT_STATUS;
- scrn->cga_card = FALSE;
- }
- else
- {
- scrn->segment = COLOR_SEG;
- scrn->stat_port = COLOR_BASE + CRT_STATUS;
- scrn->cga_card = (card == CGA_ADAPTER) ? TRUE : FALSE ;
- }
-
- scrn->offset = 0; /* set initial segment offset */
- scrn->attrib = 7; /* set initial attribute to normal */
- vid_page(0); /* force page zero */
- }
-
-
-
-
-
-
-
- /************************************************************************
- scrn_pos - Sets the logical cursor position, or offset within the
- screen buffer, to the specified row and column. The real
- cursor is not affected.
-
- Example: int row = 10, col = 20;
- scrn_pos(row, col, &scrn); set to row 10, column 20
- *************************************************************************/
-
- void scrn_pos(row,col,scrn)
- int row, col;
- SCRN *scrn;
- {
- scrn->offset = (row * 80 + col) << 1 ;
- }
-
-
-
-
-
-
- /************************************************************************
- scrn_color - set the foreground and background color for direct screen
- writes. Remains in effect until changed.
-
- Example: scrn_color(BLUE, WHITE, &scrn); set blue on white text
-
- Foreground colors may be OR'd to the constants HIGHLIGHT and/or BLINK.
- For example, scrn_color(RED|BLINK|HIGHLIGHT, WHITE, scrn); sets blinking,
- highlighted, red text on a white background.
- *************************************************************************/
-
- void scrn_color(fore, back, scrn)
- int fore, back;
- SCRN *scrn;
- {
- scrn->attrib = ((back << 4) | fore);
- }
-
-
-
-
-
- /************************************************************************
- scrn_attrib - Provided for easy setting of monochrome attributes. Can
- be used to modify current color selection.
-
- Example: scrn_attrib(INVERSE, &scrn);
- *************************************************************************/
-
- void scrn_attrib(attribute, scrn)
- int attribute;
- SCRN *scrn;
- {
- scrn->attrib = attribute;
- }
-
-
-
-
-
-
-
-
- /************************************************************************
- vid_state - get current video mode (see video.h for modes)
-
- Example: vid_mode = vstate(&cols);
-
- Puts current screen width into cols and returns current mode, i.e. CO80.
- *************************************************************************/
-
- int vid_state(pcol)
- int *pcol ;
- {
- union REGS inregs, outregs;
-
- inregs.h.ah = V_GET_MODE; /* get mode function 15 */
- int86(VIDEO_INT,&inregs,&outregs) ;
-
- *pcol = (outregs.h.ah);
-
- return(outregs.x.ax & 0xff);
- }
-
-
-
-
-
- /************************************************************************
- vid_init - select monitor mode (see video.h for modes)
-
- Example: vid_init(CO80); set color/80 columns
- *************************************************************************/
-
- void vid_init(mode)
- int mode;
- {
- union REGS inregs, outregs;
-
- inregs.h.ah = V_SET_MODE; /* set mode function (00h) */
- inregs.h.al = (char)mode; /* mode number goes in al */
-
- int86(VIDEO_INT, &inregs, &outregs);
-
- }
-
-
-
-
-
-
- /************************************************************************
- vid_page - sets the current page number, 0 through 7.
-
- Example: vid_page(0); set page to zero
- *************************************************************************/
-
- void vid_page(new_page) /* set display page */
- int new_page ; /* new page number */
- {
- union REGS inregs, outregs;
-
- inregs.h.ah = V_SETPAGE; /* select display page function */
- inregs.h.al = (char)new_page & 0x07 ; /* force new page to be <= 7 */
- int86(VIDEO_INT,&inregs,&outregs) ;
- }
-
-
-
-
-
-
- /************************************************************************
- scrn_set_cga - sets the structure member 'cga_card' to false (zero) or
- true (non-zero). If set to true, all subsequent direct screen
- reads and writes will check for horizontal retrace. If set to
- false, retrace checking will be bypassed.
-
- Example: #define TRUE = 1
- #define FALSE = 0
- .
- .
- .
- scrn_set_cga(TRUE, &sc); enables retrace checking
- *************************************************************************/
-
- void scrn_set_cga(tf, scrn)
- int tf;
- SCRN *scrn;
- {
- if (tf)
- scrn->cga_card = 1;
- else
- scrn->cga_card = 0;
- }
-
-