home *** CD-ROM | disk | FTP | other *** search
- /* Console control for a character-oriented screen --
- This version is set up for the Microsoft C compiler.
-
- The coordinates used for input to all functions are in the
- graphics coordinate space, with the origin as (0,0) at the
- lower left.
-
- copyright (c) 1987-88 D.M.Auslander
-
- Created: 10-July-87
- Updates:
- 15-July-87, DMA, fix CGA1 color table
- 18-Aug-88, adapt for Microsoft C Compiler
-
- This version is set up for various graphic modes on the IBM.
- The control "defines" are:
- CGA1 color graphics adapter, 640x200, monochrome
- CGA2 color graphics adapter, 320x200, color
- EGA enhanced graphics adapter, 640x320, color
- VGA video graphics array, 640x480, color
- */
-
- #include <stdio.h>
- #include <graph.h>
- #include <dos.h>
-
-
- #define EGA
-
- #ifdef EGA
- static int srow = 350, scol = 640,smode = _ERESCOLOR,rmode = 3;
- static int crow = 25, ccol = 80; /* Size of character screen */
- /* Output color map */
- static int c_out[] =
- {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
- #endif
-
- #ifdef CGA1
- static int srow = 200, scol = 640,smode = _HRESBW,rmode = 3;
- static int crow = 25, ccol = 80; /* Size of character screen */
- /* Output color map */
- static int c_out[] = {0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
- #endif
-
- #ifdef CGA2
- static int srow = 200, scol = 320,smode = _MRES4COLOR,rmode = 3;
- static int crow = 25, ccol = 80; /* Size of character screen */
- /* Output color map */
- static int c_out[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};
- #endif
-
- static float sht = 20.0, swdth = 20.0; /* Screen height and width (cm) */
-
- init_scr() /* Initialize the screen
- ---------- */
- {
- _setvideomode(smode);
- }
-
- rst_scr() /* Restore the screen to its original state
- ---------- */
- {
- _setvideomode(_DEFAULTMODE);
- }
-
- mv_cur(x,y) /* Move the cursor to a location specified in the **graphic**
- ----------- coordinate space. Origin is lower left. */
- float x,y;
- {
- int r,c;
-
- r = (sht - y) * (crow -1) / sht + 1.5; /* Compute row/col coordinates */
- c = x * (ccol - 1) / swdth + 1.5;
- _settextposition(r,c); /* Move the cursor */
- }
-
- pstr(s) /* Write the string to the screen at the
- ------- current cursor location */
- char *s;
- {
- fputs(s,stdout);
- }
-
- drawl(x1,y1,x2,y2,color) /* Draw a line from (x1,y1) to (x2,y2)
- ------------------------ */
- float x1,y1,x2,y2;
- int color;
- {
- int xi1,xi2,yi1,yi2,dx,dy,incx = 1, incy = 1, reg,i,n,ix,iy;
- int clr;
-
- yi1 = (sht - y1) * (srow -1) / sht + 1.5; /* Compute row/col coordinates */
- xi1 = x1 * (scol - 1) / swdth + 1.5;
- yi2 = (sht - y2) * (srow -1) / sht + 1.5; /* Compute row/col coordinates */
- xi2 = x2 * (scol - 1) / swdth + 1.5;
-
- sclim(&xi1,&yi1,&xi2,&yi2); /* Limit values to inside the screen */
-
- clr = _setcolor(c_out[color]);
- _moveto(xi1,yi1);
- _lineto(xi2,yi2);
- _setcolor(clr); /* Set color back to default */
- }
-
- sclim(x1,y1,x2,y2) /* Limit values to inside the screen
- ---------------------- */
- int *x1,*x2,*y1,*y2;
- {
- *x1 = ilim(*x1,1,scol);
- *x2 = ilim(*x2,1,scol);
- *y1 = ilim(*y1,1,srow);
- *y2 = ilim(*y2,1,srow);
- }
-
- ilim(x,xmin,xmax) /* Limit value of x to <xmin,xmax>
- ----------------- */
- int x,xmin,xmax;
- {
- if(x < xmin)return(xmin);
- if(x > xmax)return(xmax);
- return(x);
- }
-
- /* Register definitions for DOS calls -- structure definitions are
- in dos.h
- */
-
- static struct WORDREGS wregs; /* Word registers */
- static struct BYTEREGS bregs; /* Byte registers */
- static union REGS r;
-
- char_in() /* Check for a character from the keyboard
- --------- Return 0 if no character or the ASCII code if a character
- is detected */
-
- {
- if(kbhit())
- {
- r.h.ah = 7; /* Get a character */
- intdos(&r,&r); /* Call DOS */
- if(r.h.al != 0)return(r.h.al & 0x7f); /* Return character value */
- else
- { /* Get extended code */
- r.h.ah = 7;
- intdos(&r,&r); /* Call again */
- return(r.h.al | 0x80 & 0xff);
- /* Set high bit for extended codes */
- }
- }
- return(0); /* No character ready */
- }
-