home *** CD-ROM | disk | FTP | other *** search
- /* ------------------------------------------------------ */
- /* SCREEN.C */
- /* erste Veröffentlichung: Ausgabe 2'88 */
- /* (c) 1988 G.Rühwald & PASCAL International */
- /* ------------------------------------------------------ */
- #include <stdlib.h>
- #include <dos.h>
- #include "screen.h"
-
-
- /* Attribut für normale Schrift ins Highbyte ------------ */
-
- int attribut = ATT_NORMAL << 8;
-
- /* Zeiger auf Bildschirmspeicher einrichten ------------- */
-
- #define MK_FP(Seg,Offs) \
- ((void far *)(((unsigned long)(Seg)<<16)|(Offs)))
- int far *screenpointer = ((int far *)
- MK_FP(SCREEN_SEGMENT,0x0000));
-
- /* In dieser Struktur werden die Fenster gespeichert ---- */
-
- struct windows { int xa, ya, xe, ye;
- int *screen_zeig;
- };
-
- struct windows window[MAX_WINDOWS];
- int window_num = NOWIN;
-
- /* ------------------------------------------------------ */
- void set_attribut(att)
- unsigned char att;
- {
- attribut = att << 8;
- }
-
- /* ------------------------------------------------------ */
- void make_relativ(x,y)
- int *x, *y;
- {
- *x += window[window_num].xa;
- *y += window[window_num].ya;
- }
-
- /* ------------------------------------------------------ */
- void set_cursor(x,y)
- int x, y;
- { union REGS regs;
-
- if (window_num != NOWIN) make_relativ(&x, &y);
- regs.h.ah = 2;
- regs.h.dh = y-1;
- regs.h.dl = x-1;
- regs.h.bh = 0;
- int86(0x10, ®s, ®s);
- }
-
- /* ------------------------------------------------------ */
- void cursor(mode)
- int mode;
- { union REGS regs;
-
- switch(mode)
- {
- case 0 : { regs.h.cl = 0x00; regs.h.ch = 0x0F; break; }
- case 1 : { regs.h.cl = 0x07; regs.h.ch = 0x07; break; }
- case 2 : { regs.h.cl = 0x07; regs.h.ch = 0x06; break; }
- case 8 : { regs.h.cl = 0x08; regs.h.ch = 0x00; break; }
- }
- regs.h.ah = 1;
- int86(0x10, ®s, ®s);
- }
-
- /* ------------------------------------------------------ */
- void printxy(x,y,c)
- int x, y;
- unsigned char c;
- {
- if (window_num != NOWIN) make_relativ(&x, &y);
- *(screenpointer + SCREEN_OFFSET(x,y)) =
- (((int) c) | attribut);
- }
-
- /* ------------------------------------------------------ */
- void printsxy(x, y, str)
- int x, y;
- char *str;
- {
- for (; *str != '\0'; x++, str++)
- printxy(x, y, (unsigned)*str);
- }
-
- /* ------------------------------------------------------ */
- unsigned char readxy(x, y)
- int x, y;
- {
- if (window_num != NOWIN) make_relativ(&x, &y);
- return((unsigned char)*(screenpointer +
- SCREEN_OFFSET(x,y)));
- }
-
- /* ------------------------------------------------------ */
- void readsxy(x, y, length, str)
- int x, y, length;
- char *str;
- {
- int i;
-
- for(i = 0; i<= length; i++, str++, x++)
- *str = (signed) readxy(x, y);
- *str = '\0';
- }
-
- /* ------------------------------------------------------ */
- void clrscr(xanf, yanf, xend, yend)
- int xanf, yanf, xend, yend;
- {
- register x, y;
- int alt_attribut;
-
- alt_attribut = attribut;
- attribut = 7*256;
- for(x = xanf; x <= xend; x++)
- for(y = yanf; y <= yend; y++)
- printxy(x,y,' ');
- attribut = alt_attribut;
- }
-
- /* ------------------------------------------------------ */
- void open_window(xa, ya, xe, ye, rahmen)
- int xa, ya, xe, ye, rahmen;
- {
- unsigned char oben_links, oben_rechts, unten_links,
- unten_rechts, oben_unten, seite;
- register x, y;
- int *zeiger;
- int screen_length, alt_window_num;
- char buffer[81];
- char *bufp = buffer;
-
- switch (rahmen)
- {
- /* ohne Rahmen */
- case 0 : { oben_links = oben_rechts
- = unten_links = unten_rechts
- = oben_unten = seite = ' ';
- break;
- }
- /* einfache Linie */
- case 1 : { oben_links = 218; oben_rechts = 191;
- unten_links = 192; unten_rechts = 217;
- oben_unten = 196; seite = 179;
- break;
- }
- /* doppelte Linie */
- case 2 : { oben_links = 201; oben_rechts = 187;
- unten_links = 200; unten_rechts = 188;
- oben_unten = 205; seite = 186;
- break;
- }
- }
- window_num++;
- window[window_num].xa = xa;
- window[window_num].ya = ya;
- window[window_num].xe = xe;
- window[window_num].ye = ye;
- /* Speicherplatz auf dem Heap allokieren */
- screen_length = (xe-xa+1) * (ye-ya+1);
- zeiger = window[window_num].screen_zeig
- = calloc(screen_length,2);
-
- alt_window_num = window_num;
- window_num = NOWIN;
- for(x = xa; x <= xe; x++)
- for (y = ya; y <= ye; y++)
- *(zeiger++) = readxy(x, y);
-
- /* String für Ober-/Unterkante-Fenster fertigmachen */
- for (x =xa; x < xe; x++, bufp++) *bufp = oben_unten;
- *bufp = '\0';
- clrscr(xa+1,ya+1,xe-1,ye-1);
-
- /* Rahmen zeichnen */
- printxy(xa, ya, oben_links);
- printsxy(xa+1, ya, buffer);
- printxy(xe, ya, oben_rechts);
- for(x = ya+1; x < ye; x++)
- { printxy(xa,x,seite);
- printxy(xe,x,seite);
- }
- printxy(xa,ye,unten_links);
- printsxy(xa+1,ye,buffer);
- printxy(xe,ye,unten_rechts);
-
- window_num = alt_window_num;
- }
-
- /* ------------------------------------------------------ */
- void close_window()
- {
- int *zeiger;
- register x, y;
- int xa,ya,xe,ye,alt_window_num;
-
- xa=window[window_num].xa;
- ya=window[window_num].ya;
- xe=window[window_num].xe;
- ye=window[window_num].ye;
- zeiger=window[window_num].screen_zeig;
-
- alt_window_num = window_num;
- window_num = NOWIN;
-
- for(x = xa; x <= xe; x++)
- for(y = ya; y <= ye; y++)
- printxy(x,y,*(zeiger++));
-
- window_num = alt_window_num;
- free(window[window_num].screen_zeig);
- window_num--;
- }
- /* ------------------------------------------------------ */
- /* Ende von SCREEN.C */