home *** CD-ROM | disk | FTP | other *** search
- /*
- TURBO C WINDOWS 1.0
- by
- Craig Arnush
-
- These are TURBO C WINDOWS 1.0 by Craig Arnush. It is not
- necessary, although highly useful, that you make use of the
- SCREEN.H file included here. It has all sorts of helpful
- definitions.
- This file is by no means yet complete, I am planning on
- writing scanning utilities to stay within the windows. I will
- also be coming up with some documentation to make this whole
- thing a little more understandable. Be patient.
- If you find this useful, I would greatly appreciate your
- comments and/or donations to help me in writing all of these
- utilities. Suggestions are especially helpful as they tell me
- what you're looking for. Please address all correspondence to:
-
- Craig Arnush
- 6018 Via Sonoma
- RPV, CA 90274
-
- */
-
- #include <stdio.h>
- #include <stdarg.h>
- #include <dos.h>
- #include <mem.h>
- #include <string.h>
- #include <alloc.h>
- #include "screen.h"
-
- char colorcard, snow;
- char far *displayptr;
-
- struct scrptr
- {
- char x1, y1, x2, y2, oldx, oldy;
- char *s;
- } windows[16];
- char totwins;
-
- struct screenelement
- {
- char character;
- char color;
- };
-
- int egainstalled(void) /* Tests for EGA */
- {
- 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 */
-
- int shiftstat(void) /* get the shift status */
- { /* returns 1st status byte in */
- return(*(int far *)0x00000417L); /* lo byte of int, and 2nd in hi */
- }
-
- char wherex(void)
- {
- return(*(char far *)(colorcard ? 0x00000450L : 0x00000452L) + 1);
- }
-
- char wherey(void)
- {
- return(*(char far *)(colorcard ? 0x00000451L : 0x00000453L) + 1);
- }
-
- int getkey(void) /* get char & scan code from kb */
- {
- int key, lo, hi;
-
- key = bioskey(0);
- lo = key & 0x00FF;
- hi = (key & 0xFF00) >> 8;
- return((lo == 0) ? hi + 1000 : lo);
- } /* getkey */
-
- void clrscr(char color) /* Clears the screen */
- {
- char i, j;
- int offset;
-
- for (i = (windows[totwins].x1 + 1); i <= (windows[totwins].x2 - 1); ++i)
- for (j = (windows[totwins].y1 + 1); j <= (windows[totwins].y2 - 1); ++j)
- {
- offset = ((j-1) * 160) + ((i-1) << 1);
- *(displayptr + offset) = 0x20; /* " " */
- *(displayptr + ++offset) = color;
- }
- } /* clrscr */
-
- void gotoxyabs(int col, int row)
- {
- union REGS reg;
-
- reg.h.ah = 2;
- reg.h.bh = 0;
- reg.h.dh = --row;
- reg.h.dl = --col;
- int86(0X10, ®, ®);
- }
-
- void scroll(char color, char direction)
- {
- union REGS reg;
-
- if (direction == UP)
- reg.x.ax = 0x0601;
- else if (direction == DN)
- reg.x.ax = 0x0701;
- reg.h.ch = windows[totwins].y1;
- reg.h.cl = windows[totwins].x1;
- reg.h.dh = windows[totwins].y2 - 2;
- reg.h.dl = windows[totwins].x2 - 2;
- reg.h.bh = color;
- int86(0x10, ®, ®);
- }
-
- void gotoxy(int col, int row) /* Move to column, row */
- {
- col = windows[totwins].x1 + col - 1;
- if (col >= windows[totwins].x2)
- return;
- row = (int) windows[totwins].y1 + row - 1;
- if (row >= windows[totwins].y2)
- return;
- gotoxyabs(col, row);
- } /* gotoxy */
-
- void putonscreen(char c, char color, char x, char y)
- {
- *(int far *)(displayptr+((y-1)*160)+((x-1) << 1)) = ((color << 8) + c);
- }
-
- void border(void)
- {
- char i, x1, y1, x2, y2;
-
- x1 = windows[totwins].x1;
- y1 = windows[totwins].y1;
- x2 = windows[totwins].x2;
- y2 = windows[totwins].y2;
- putonscreen('┌', 0x1F, x1, y1);
- putonscreen('┐', 0x1F, x2, y1);
- putonscreen('└', 0x1F, x1, y2);
- putonscreen('┘', 0x1F, x2, y2);
- for (i = (x1 + 1); i < x2; ++i)
- {
- putonscreen('─', 0x1F, i, y1);
- putonscreen('─', 0x1F, i, y2);
- }
- for (i = (y1 + 1); i < y2; ++i)
- {
- putonscreen('│', 0x1F, x1, i);
- putonscreen('│', 0x1F, x2, i);
- }
- }
-
- void openwindow(char x1, char y1, char x2, char y2)
- {
- char i, j;
- int scrofs, savofs;
-
- if (totwins < 16)
- {
- ++totwins;
- windows[totwins].x1 = x1;
- windows[totwins].y1 = y1;
- windows[totwins].x2 = x2;
- windows[totwins].y2 = y2;
- windows[totwins].oldx = wherex();
- windows[totwins].oldy = wherey();
- windows[totwins].s = (char *) malloc((x2-x1+1) * (y2-y1+1) * 2);
- savofs = 0;
- for (i = x1; i <= x2; ++i)
- for (j = y1; j <= y2; ++j)
- {
- scrofs = ((j-1) * 160) + ((i-1) << 1);
- *(windows[totwins].s + savofs++) = *(displayptr + scrofs++);
- *(windows[totwins].s + savofs++) = *(displayptr + scrofs);
- }
- border();
- clrscr(0x07);
- gotoxy(1, 1);
- }
- }
-
- void closewindow(void)
- {
- char i, j;
- int scrofs, savofs;
-
- if (totwins > 0)
- {
- savofs = 0;
- for (i = windows[totwins].x1; i <= windows[totwins].x2; ++i)
- for (j = windows[totwins].y1; j <= windows[totwins].y2; ++j)
- {
- scrofs = ((j-1) * 160) + ((i-1) << 1);
- *(displayptr + scrofs++) = *(windows[totwins].s + savofs++);
- *(displayptr + scrofs) = *(windows[totwins].s + savofs++);
- }
- gotoxyabs(windows[totwins].oldx, windows[totwins].oldy);
- free(windows[totwins].s);
- --totwins;
- }
- }
-
- void setcursor(int startline, int endline) /* Sets the shape of the cursor */
- {
- union REGS reg;
-
- reg.h.ah = 1;
- reg.x.cx = (startline << 8) + endline;
- int86(0X10, ®, ®);
- } /* setcursor */
-
- void colorscr(char color) /* colors the screen */
- {
- char i, j;
-
- for (i = (windows[totwins].x1 + 1); i <= (windows[totwins].x2 - 1); ++i)
- for (j = (windows[totwins].y1 + 1); j <= (windows[totwins].y2 - 1); ++j)
- *(displayptr + ((j-1) * 160) + ((i-1) << 1) + 1) = color;
- } /* colorscr */
-
- void writef(char color, char *msg, ...)
- {
- char *output;
- va_list argptr;
- char i, tx, ty;
-
- output = "";
- va_start(argptr, msg);
- vsprintf(output, msg, argptr);
- va_end(argptr);
- tx = wherex();
- ty = wherey();
- i = 0;
- while (output[i] != '\0')
- {
- if (output[i] == '\n')
- {
- tx = windows[totwins].x1 + 1;
- ++ty;
- }
- else
- putonscreen(output[i], color, tx++, ty);
- if (tx >= windows[totwins].x2)
- {
- tx = windows[totwins].x1 + 1;
- ++ty;
- }
- if (ty >= windows[totwins].y2)
- {
- scroll(color, UP);
- ty = windows[totwins].y2 - 1;
- }
- ++i;
- }
- gotoxyabs(tx, ty);
- }
-
- void initdisplay(void)
- /* Initializes various global variables - must be called before using the
- above procedures and functions.
- */
- {
- union REGS reg;
-
- reg.h.ah = 15;
- int86(0X10, ®, ®);
- colorcard = (reg.h.al != 7);
- snow = (!egainstalled() && colorcard);
- displayptr = (char far *)(colorcard ? 0xB8000000L : 0xB0000000L);
- windows[0].x1 = 0;
- windows[0].y1 = 0;
- windows[0].x2 = 81;
- windows[0].y2 = 26;
- windows[0].s = (char *) displayptr;
- totwins = 0;
- } /* initdisplay */
-
- /*----------------------*/
- main()
- {
- initdisplay();
- openwindow(10, 5, 50, 15);
- gotoxyabs(11, 10);
- getkey();
- writef(0x17, "Now is the time for all good men to come to the aid of their countries!");
- gotoxyabs(11, 14);
- getkey();
- writef(0x17, "This sentence is written for the sole purpose of testing the scroll.\n");
- getkey();
- closewindow();
- }