home *** CD-ROM | disk | FTP | other *** search
- /* Code from 86World column in Micro Cornucopia Issue #40 */
-
- /* VIDEO.C - a few video subroutines to make writing C programs a bit simpler
-
- a line of code for printing something will look like this:
-
- at(2,20); in(RED,WHITE); cprintf("Just Like English!");
-
- Of course, you can omit the at() or in() (or both) if you like.
-
- NOTE: In order for this package to work, you must link in the file
- MCMVSMEM.OBJ from the Turbo C distribution disk.
-
- Also remember that you must somehow force VIDEO.C to recompile
- whenever you switch memory models. This is because I haven't
- specifically declared all the routines and variables as 'far'
- (I hate using extra space and code unless I have to). If you
- like, you can do so yourself, then you can link the same OBJ
- with any memory model.
-
- To use the following routines in your own program, just put the
- files video.c, video.h, and mcmvsmem.obj in your working directory,
- add the line '#include "video.h" to the top of your program, call
- initvideo() at the beginning of main(), and make a project file that
- makes reference to all three files. See kbdtest.c and kbdtest.prj
- for examples
-
- As usual: permission granted to use this for whatever you want to,
- commercial, private, obscene, or otherwise.
-
- Laine Stump, 12/13/87
- */
- #include <stdarg.h>
- #include <stdio.h>
- #include <dos.h>
- #include <mem.h>
- #include <string.h>
- #include "video.h"
-
- char snow, curcolor;
- int currow, curcol;
- char far *screen;
-
- struct character
- {
- char ch;
- char color;
- };
-
- void scroll(int lines, int x1, int y1, int x2, int y2)
- /* Scrolls the screen between x1,y1 and x2,y2. Scrolling is up if
- lines is positive, down if it is negative */
- {
- union REGS reg;
-
- if (lines < 0)
- {
- reg.h.ah = 7;
- lines = (-lines);
- }
- else
- reg.h.ah = 6;
- reg.h.al = lines;
- reg.h.bh = curcolor;
- reg.x.cx = (y1 << 8) + x1;
- reg.x.dx = (y2 << 8) + x2;
- int86(0X10, ®, ®);
- } /* scroll */
-
- int egainstalled(void)
- /* returns true if EGA is installed */
- {
- union REGS reg;
-
- reg.x.ax = 0x1200;
- reg.x.bx = 0x0010;
- reg.x.cx = 0xFFFF;
- int86(0X10, ®, ®);
- return((reg.x.cx == 0xFFFF) ? 0 : 1);
- } /* egainstalled */
-
- void cursorsize(int startline, int endline)
- /* Sets the size of the cursor */
- {
- union REGS reg;
-
- reg.h.ah = 1;
- reg.x.cx = (startline << 8) + endline;
- int86(0X10, ®, ®);
- } /* cursorsize */
-
- void clearscreen(void)
- /* clears the screen to curcolor and positions cursor at(0,0) */
- {
- scroll(0, 0, 0, 79, 24);
- at(0,0);
- } /* clearscreen */
-
- void at(int row, int col)
- /* places the cursor at a specific row and column */
- {
- union REGS reg;
-
- currow = row; /* for use by cprintf */
- curcol = col;
- reg.h.ah = 2;
- reg.h.bh = 0;
- reg.x.dx = (row << 8) + col;
- int86(0X10, ®, ®);
- } /* at */
-
- void in(char forecolor, char backcolor)
- /* sets current color to 'color' */
- {
- curcolor = forecolor | (backcolor << 4);
- } /* in */
-
- void cprintf(va_list arg_list, ...)
- /* Prints a string in video memory at current location in current color
- then advances cursor to end of string. This cprintf replaces the
- standard cprintf in UNIX c. It is functionally identical, except
- that it will use the color set by the function in(). */
- {
- va_list arg_ptr;
- char *format;
- char output[81];
- struct character buffer[80];
- int counter, len;
- unsigned size;
-
- va_start(arg_ptr, arg_list);
- format = arg_list;
- vsprintf(output, format, arg_ptr);
- len = strlen(output);
- size = len << 1;
- setmem(buffer, size, curcolor);
- for (counter = 0; counter < len; counter++)
- buffer[counter].ch = output[counter];
- movescreenmem((char far *)(buffer),
- screen + (currow * 160) + (curcol << 1), size, snow);
- at(currow,curcol+len);
- } /* cprintf */
-
- void initvideo(void)
- /* determines what type of video is in use and sets screen pointer,
- then sets colors to lightgray on black and clears screen
- Variable snow is needed by movescreenmem routine contained in
- the file MCMVSMEM.C (.OBJ) that comes with Turbo C.
- */
- {
- union REGS reg;
-
- reg.h.ah = 15;
- int86(0X10, ®, ®);
- snow = (!egainstalled() && reg.h.al != 7);
- screen = (char far *)((reg.h.al != 7) ? 0xB8000000L : 0xB0000000L);
- in(LIGHTGRAY,BLACK); clearscreen();
- } /* initvideo */