home *** CD-ROM | disk | FTP | other *** search
- /* MCGA.C */
- /* (C) 1989 TOOLBOX */
- /* Dieses Modul liefert die Grundlage für die */
- /* Programmierung des Modus 13h der VGA- Karte */
- /* Implementation in Turbo-C */
-
- #include "mcga.h"
- #include <stdio.h>
- #include <dos.h>
- #include <string.h>
- #include <mem.h>
- #include <io.h>
- #include <math.h>
-
- char far *scrbase;
-
- typedef struct { char r,g,b;} onereg;
- typedef onereg TColorRegBuf[256];
-
-
- /* Setzt einen Punkt in der Farbe color */
-
- void plot(x,y,color)
- int x,y,color;
- {
- *(scrbase+y*320+x) = (char)color;
- ;}
-
-
- /* Testet die Farbe eines Punktes */
- int getdotcolor (x,y)
- int x,y;
- {
- union REGS regs;
-
- regs.x.ax = 13;
- regs.x.cx = x;
- regs.x.dx = y;
- int86(0*10,®s,®s);
- return (regs.h.al);
- }
-
-
- /* Setzt den 320*200 Punkte Modus mit 256 Farben */
- void initgraphic()
- {
- union REGS regs;
-
- scrbase = MK_FP(0xA000,0);
- regs.h.ah = 0;
- regs.h.al = 0x13;
- int86(0x10,®s,®s);
- }
-
- /* Zurück in den Textmodus */
- void exitgraphic()
- {
- union REGS regs;
-
- regs.h.ah = 0;
- regs.h.al = 3;
- int86(0x10,®s,®s);
- }
-
-
- /* Schreibt einen String an die Cursorposition */
- void print (line,color)
- char *line;
- int color;
-
- {
- int i;
- union REGS regs;
-
- for( i = 0; i < strlen(line); i++) {
- regs.h.ah = 14;
- regs.h.al = line[i];
- regs.h.bl = color;
- int86(0x10,®s,®s);
- }
- }
-
-
- /* Setzt den Cursor auf x,y */
- void setcursor (x,y)
- int x,y;
- {
- union REGS regs;
-
- regs.h.ah = 2;
- regs.h.bh = 0;
- regs.h.dh = y;
- regs.h.dl = x;
- int86(0x10,®s,®s);
- }
-
-
- /* Liest x-Position des Cursors */
- int cursorx(void)
- {
- union REGS regs;
-
- regs.h.ah = 3;
- regs.h.bh = 0;
- int86(0x10,®s,®s);
- return(regs.h.dl);
- }
-
- /* Liest y-Position des Cursors */
- int cursory(void)
- {
- union REGS regs;
-
- regs.h.ah = 3;
- regs.h.bh = 0;
- int86(0x10,®s,®s);
- return(regs.h.dh);
- }
-
-
- /* Löscht den Bildschirm mit der Farbe color */
- void clearscreen(color)
- int color;
-
- {
- setmem(scrbase,32000,color);
- setmem((scrbase+32000),32000,color);
- }
-
-
- /* Zeichnet gefüllte Box in der Farbe color */
- void colorbox (x1,y1,x2,y2,color)
- int x1,y1,x2,y2,color;
- {
- int i,d;
-
- d = x2-x1;
- for(i = y1; i <= y2; i++) {
- setmem((scrbase+i*320+x1),d,color);
- }
- }
-
-
- /* Sichert den Bildschirm in die Datei "filename" */
- void mcgasave (filename)
- char *filename;
-
- {
- FILE *file;
- size_t res;
-
- file = fopen(filename,"wb");
- if (file != NULL) {
- res = fwrite(scrbase,(size_t)32000,(size_t)2,file);
- fclose(file);
- }
- }
-
-
- /* Lädt einen Bildschirm aus der Datei "filename" */
- void mcgaload (filename)
- char *filename;
- {
- FILE *file;
- size_t res;
-
-
- file = fopen(filename,"rb");
- if (file != NULL) {
- res = fread(scrbase,(size_t)32000,(size_t)2,file);
- fclose(file);
- }
- }
-
-
- /* Linie in Farbe color zeichen */
- void line(x1,y1,x2,y2,color)
-
- int x1,y1,x2,y2,color;
-
- {
-
- int deltax,deltay,zaehler,abweichung,x,y;
-
- abweichung=0;
- deltax=x2-x1;
- deltay=y2-y1;
- if (deltay<0)
- {
- swap(x1,x2);
- swap(y1,y2);
- deltay=-deltay;
- deltax=-deltax;
- }
- plot(x1,y1,color);
- x=x1;
- y=y1;
- if (deltax>=0)
- if (deltax<deltay)
- for (zaehler=1;zaehler<=deltay-1;zaehler++)
- if (abweichung<0)
- {
- x++;
- y++;
- plot(x,y,color);
- abweichung=abweichung+deltay-deltax;
- }
- else {
- y++;
- plot(x,y,color);
- abweichung=abweichung-deltax;
- }
- else
- for (zaehler=1;zaehler<=deltax-1;zaehler++)
- if (abweichung<=0)
- {
- x++;
- plot(x,y,color);
- abweichung=abweichung+deltay;
- }
- else {
- x++;
- y++;
- plot(x,y,color);
- abweichung=abweichung+deltay-deltax;
- }
- else
- if (abs(deltax)>=deltay)
- for (zaehler=1;zaehler<=(abs(deltax)-1);zaehler++)
- if (abweichung<=0)
- {
- --x;
- plot(x,y,color);
- abweichung=abweichung+deltay;
- }
- else {
- --x;
- y++;
- plot(x,y,color);
- abweichung=abweichung+deltax+deltay;
- }
- else
- for (zaehler=1;zaehler<=deltay-1;zaehler++)
- if (abweichung<0)
- {
- --x;
- y++;
- plot(x,y,color);
- abweichung=abweichung+deltax+deltay;
- }
- else {
- y++;
- plot(x,y,color);
- abweichung=abweichung+deltax;
- }
- plot(x2,y2,color);
- }
-
-
-
- /* Zeichnet Box in der Farbe color */
- void box(x1,y1,x2,y2,color)
- int x1,y1,x2,y2,color;
-
- {
- line(x1,y1,x2,y1,color);
- line(x1,y2,x2,y2,color);
- line(x1,y1,x1,y2,color);
- line(x2,y1,x2,y2,color);
- }
-
-
- /* Setzt ein Farbregister */
- void setcolor(nr,red,green,blue)
- int nr,red,green,blue;
-
- {
- union REGS r;
-
- r.h.ah = 0x10;
- r.h.al = 0x10;
- r.x.bx = nr;
- r.h.dh = red;
- r.h.ch = green;
- r.h.cl = blue;
-
- int86(0x10,&r,&r);
- }
-
-
- /* Liest ein Farbregister */
- void readcolor(nr,red,green,blue)
- int nr;
- int *red,*green,*blue;
-
- {
- union REGS r;
-
- r.h.ah = 0x10;
- r.h.al = 0x15;
- r.x.bx = nr;
- int86(0x10,&r,&r);
- *red = r.h.dh;
- *green = r.h.ch;
- *blue = r.h.cl;
- }
-
-
- /* Setzt einen Block von Farbregistern */
- void setcolorblock(startnr,buf,nr)
- int startnr, nr;
- void *buf;
-
- {
- struct REGPACK r;
-
- r.r_ax = 0x10*256 + 0x12;
- r.r_bx = startnr;
- r.r_es = FP_SEG(buf);
- r.r_dx = FP_OFF(buf);
- r.r_cx = nr;
-
- intr(0x10,&r);
- }
-
- /* Liest einen Block von Farbregistern */
- void readcolorblock(startnr,buf,nr)
- int startnr, nr;
- void *buf;
-
- {
- struct REGPACK r;
-
- r.r_ax = 0x10*256 + 0x12;
- r.r_bx = startnr;
- r.r_es = FP_SEG(buf);
- r.r_dx = FP_OFF(buf);
- r.r_cx = nr;
-
- intr(0x10,&r);
- }
-