]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_vl_1.c
p16 is being worked on a bunch by me wwww [16_ca needs huge amounts of work and I...
[16.git] / src / lib / 16_vl_1.c
index 31c9f38e73a80f50735bac2612278ec9428c3389..7332d5fb5d10795c7a7cb265d50c1036573daba3 100755 (executable)
@@ -3,19 +3,19 @@
  *\r
  * This file is part of Project 16.\r
  *\r
- * Project 16 is free software; you can redistribute it and/or modify\r
+ * Project 16 is free software; you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
  * the Free Software Foundation; either version 3 of the License, or\r
  * (at your option) any later version.\r
  *\r
- * Project 16 is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
+ * Project 16 is distributed in        the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without   even the implied warranty of\r
+ * MERCHANTABILITY or  FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for      more details.\r
  *\r
  * You should have received a copy of the GNU General Public License\r
  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
- * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
+ * write to the Free Software Foundation, Inc., 51 Franklin    Street,\r
  * Fifth Floor, Boston, MA 02110-1301 USA.\r
  *\r
  */\r
@@ -46,7 +46,7 @@ void  VL_SetScreen (unsigned int crtc, int pelpan)
 \r
                mov     dx,STATUS_REGISTER_1\r
 \r
-       // wait for a display signal to make sure the raster isn't in the middle\r
+       // wait for     a display signal to make sure the raster isn't in       the middle\r
        // of a sync\r
 \r
 #ifdef __BORLANDC__\r
@@ -121,7 +121,7 @@ SetScreen_setcrtc:
        __asm {\r
 #endif\r
        // set CRTC start\r
-       // for some reason, my XT's EGA card doesn't like word outs to the CRTC index...\r
+       // for  some reason, my XT's EGA card doesn't like word outs to the CRTC index...\r
 \r
                mov     cx,[crtc]\r
                mov     dx,CRTC_INDEX\r
@@ -141,7 +141,7 @@ SetScreen_setcrtc:
        // set horizontal panning\r
 \r
                mov     dx,ATR_INDEX\r
-//             mov     al,ATR_PELPAN or 20h\r
+//             mov     al,ATR_PELPAN or        20h\r
                out     dx,al\r
                jmp     SetScreen_done\r
                mov     al,[BYTE PTR pelpan]            //pel pan value\r
@@ -164,7 +164,7 @@ SetScreen_done:
 =\r
 = VL_SetLineWidth\r
 =\r
-= Line witdh is in WORDS, 40 words is normal width for vgaplanegr\r
+= Line witdh is in     WORDS, 40 words is normal width for     vgaplanegr\r
 =\r
 ====================\r
 */\r
@@ -185,7 +185,7 @@ void VL_SetLineWidth (unsigned width, ofs_t *ofs)
 \r
        offset = 0;\r
 \r
-       for (i=0;i<MAXSCANLINES;i++)\r
+       for     (i=0;i<MAXSCANLINES;i++)\r
        {\r
                ofs->ylookup[i]=offset;\r
                offset += ofs->linewidth;\r
@@ -216,7 +216,7 @@ void VL_FillPalette (int red, int green, int blue)
        int     i;\r
 \r
        outportb (PAL_WRITE_REG,0);\r
-       for (i=0;i<256;i++)\r
+       for     (i=0;i<256;i++)\r
        {\r
                outportb (PAL_DATA_REG,red);\r
                outportb (PAL_DATA_REG,green);\r
@@ -280,7 +280,7 @@ void VL_SetPalette (byte far *palette, video_t *v)
        fastpalette=v->fastpalette;\r
 \r
 //     outportb (PAL_WRITE_REG,0);\r
-//     for (i=0;i<768;i++)\r
+//     for     (i=0;i<768;i++)\r
 //             outportb(PAL_DATA_REG,*palette++);\r
 \r
        __asm {\r
@@ -293,14 +293,14 @@ void VL_SetPalette (byte far *palette, video_t *v)
                test    [ss:fastpalette],1\r
                jz      slowset\r
 //\r
-// set palette fast for cards that can take it\r
+// set palette fast for        cards that can take it\r
 //\r
                //mov   cx,768\r
                //rep outsb\r
                //jmp   done\r
 \r
 //\r
-// set palette slowly for some video cards\r
+// set palette slowly for      some video cards\r
 //\r
 #ifdef __BORLANDC__\r
        }\r
@@ -356,7 +356,7 @@ void VL_GetPalette (byte far *palette)
        int     i;\r
 \r
        outportb (PAL_READ_REG,0);\r
-       for (i=0;i<768;i++)\r
+       for     (i=0;i<768;i++)\r
                *palette++ = inportb(PAL_DATA_REG);\r
 }\r
 \r
@@ -368,7 +368,7 @@ void VL_GetPalette (byte far *palette)
 =\r
 = VL_FadeOut\r
 =\r
-= Fades the current palette to the given color in the given number of steps\r
+= Fades the current palette to the given color in      the given number of steps\r
 =\r
 =================\r
 */\r
@@ -385,11 +385,11 @@ void VL_FadeOut (int start, int end, int red, int green, int blue, int steps, vi
 //\r
 // fade through intermediate frames\r
 //\r
-       for (i=0;i<steps;i++)\r
+       for     (i=0;i<steps;i++)\r
        {\r
                origptr = &v->palette1[start][0];\r
                newptr = &v->palette2[start][0];\r
-               for (j=start;j<=end;j++)\r
+               for     (j=start;j<=end;j++)\r
                {\r
                        orig = *origptr++;\r
                        delta = red-orig;\r
@@ -437,9 +437,9 @@ void VL_FadeIn (int start, int end, byte far *palette, int steps, video_t *v)
 //\r
 // fade through intermediate frames\r
 //\r
-       for (i=0;i<steps;i++)\r
+       for     (i=0;i<steps;i++)\r
        {\r
-               for (j=start;j<=end;j++)\r
+               for     (j=start;j<=end;j++)\r
                {\r
                        delta = palette[j]-v->palette1[0][j];\r
                        v->palette2[0][j] = v->palette1[0][j] + delta * i / steps;\r
@@ -463,7 +463,7 @@ void VL_FadeIn (int start, int end, byte far *palette, int steps, video_t *v)
 =\r
 = VL_TestPaletteSet\r
 =\r
-= Sets the palette with outsb, then reads it in and compares\r
+= Sets the palette with outsb, then reads it in        and     compares\r
 = If it compares ok, fastpalette is set to true.\r
 =\r
 =================\r
@@ -473,7 +473,7 @@ void VL_TestPaletteSet (video_t *v)
 {\r
        int     i;\r
 \r
-       for (i=0;i<768;i++)\r
+       for     (i=0;i<768;i++)\r
                v->palette1[0][i] = i;\r
 \r
        v->fastpalette = true;\r
@@ -522,7 +522,7 @@ void VL_Plot (int x, int y, int color, ofs_t *ofs)
 =================\r
 */\r
 \r
-void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs)\r
+void VL_Hlin   (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs)\r
 {\r
        unsigned                xbyte;\r
        byte                    far *dest;\r
@@ -540,7 +540,7 @@ void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs
 \r
        if (midbytes<0)\r
        {\r
-       // all in one byte\r
+       // all in       one byte\r
                VGAMAPMASK(leftmask&rightmask);\r
                *dest = color;\r
                VGAMAPMASK(15);\r
@@ -569,7 +569,7 @@ void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs
 =================\r
 */\r
 \r
-void VL_Vlin (int x, int y, int height, int color, ofs_t *ofs)\r
+void VL_Vlin   (int x, int y, int height, int color, ofs_t *ofs)\r
 {\r
        byte    far *dest,mask;\r
        VCLIPDEF\r
@@ -614,7 +614,7 @@ void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs)
 \r
        if (midbytes<0)\r
        {\r
-       // all in one byte\r
+       // all in       one byte\r
                VGAMAPMASK(leftmask&rightmask);\r
                while (height--)\r
                {\r
@@ -643,13 +643,48 @@ void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs)
        VGAMAPMASK(15);\r
 }\r
 \r
+//==========================================================================\r
+\r
+/*\r
+=================\r
+=\r
+= VL_MemToScreen\r
+=\r
+= Draws a block of data to the screen.\r
+=\r
+=================\r
+*/\r
+\r
+void VL_MemToScreen (byte far *source, int width, int height, int x, int y, ofs_t *ofs)\r
+{\r
+       byte    far *screen,far *dest,mask;\r
+       int             plane;\r
+\r
+       width>>=2;\r
+       dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2) );\r
+       mask = 1 << (x&3);\r
+\r
+       for     (plane = 0; plane<4; plane++)\r
+       {\r
+               VGAMAPMASK(mask);\r
+               mask <<= 1;\r
+               if (mask == 16)\r
+                       mask = 1;\r
+\r
+               screen = dest;\r
+               for     (y=0;y<height;y++,screen+=ofs->linewidth,source+=width)\r
+                       _fmemcpy (screen,source,width);\r
+       }\r
+}\r
+\r
+//==========================================================================\r
 \r
 /*\r
 ==============\r
 \r
  VL_WaitVBL                    ******** NEW *********\r
 \r
- Wait for the vertical retrace (returns before the actual vertical sync)\r
+ Wait for      the vertical retrace (returns before the actual vertical sync)\r
 \r
 ==============\r
 */\r
@@ -670,7 +705,7 @@ void VL_WaitVBL(word num)
 \r
                mov     cx,[num]\r
        //\r
-       // wait for a display signal to make sure the raster isn't in the middle\r
+       // wait for     a display signal to make sure the raster isn't in       the middle\r
        // of a sync\r
        //\r
 #ifdef __BORLANDC__\r
@@ -703,23 +738,49 @@ void VL_WaitVBL(word num)
 }\r
 \r
 //===========================================================================\r
+#if 0\r
+#define VGAWRITEMODE(x) asm{\r
+               cli\r
+               mov     dx,GC_INDEX\r
+               mov     al,GC_MODE\r
+               out     dx,al\r
+               inc     dx\r
+               in      al,dx\r
+               and     al,252\r
+               or      al,x\r
+               out     dx,al\r
+               sti\r
+}\r
 \r
-void VGAMAPMASK(byte x)\r
-{\r
-       __asm {\r
-//             cli\r
+#define VGAMAPMASK(x) asm{\r
+               cli\r
                mov     dx,SC_INDEX\r
                mov     al,SC_MAPMASK\r
                mov     ah,x\r
                out     dx,ax\r
-//             sti\r
-       }\r
+               sti\r
 }\r
 \r
+#define VGAREADMAP(x) asm{\r
+               cli\r
+               mov     dx,GC_INDEX\r
+               mov     al,GC_READMAP\r
+               mov     ah,x\r
+               out     dx,ax\r
+               sti\r
+}\r
+\r
+#define EGABITMASK(x) asm{\r
+               mov     dx,GC_INDEX\r
+               mov     ax,GC_BITMASK+256*x\r
+               out     dx,ax\r
+               sti\r
+}\r
+#endif\r
 void VGAWRITEMODE(byte x)\r
 {\r
        __asm {\r
-//             cli\r
+               cli\r
                mov     dx,GC_INDEX\r
                mov     al,GC_MODE\r
                out     dx,al\r
@@ -728,19 +789,42 @@ void VGAWRITEMODE(byte x)
                and     al,252\r
                or      al,x\r
                out     dx,al\r
-//             sti\r
+               sti\r
+       }\r
+}\r
+\r
+void VGAMAPMASK(byte x)\r
+{\r
+       __asm {\r
+               cli\r
+               mov     dx,SC_INDEX\r
+               mov     al,SC_MAPMASK\r
+               mov     ah,x\r
+               out     dx,ax\r
+               sti\r
        }\r
 }\r
 \r
 void VGAREADMAP(byte x)\r
 {\r
        __asm {\r
-//             cli\r
+               cli\r
                mov     dx,GC_INDEX\r
                mov     al,GC_READMAP\r
                mov     ah,x\r
                out     dx,ax\r
-//             sti\r
+               sti\r
+       }\r
+}\r
+\r
+void VGABITMASK(byte x)\r
+{\r
+       word q = 256*x;\r
+       __asm {\r
+               mov     dx,GC_INDEX\r
+               mov     ax,GC_BITMASK+q\r
+               out     dx,ax\r
+               sti\r
        }\r
 }\r
 \r