OSDN Git Service

updated copyleft and need to test and fix newer version of open watcom
[proj16/16.git] / src / lib / 16_vl_1.c
index 31c9f38..519c984 100755 (executable)
@@ -1,21 +1,21 @@
 /* Project 16 Source Code~\r
- * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ * Copyright (C) 2012-2022 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
  *\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
@@ -26,6 +26,8 @@
 #include "src/lib/16_vl.h"\r
 \r
 static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */\r
+//#define VGASTRIDEVARIABLE    vga_state.vga_stride\r
+#define VGASTRIDEVARIABLE      gvar->video.page[0].stridew\r
 \r
 //===========================================================================\r
 \r
@@ -46,7 +48,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 +123,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 +143,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,12 +166,12 @@ 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
-\r
-void VL_SetLineWidth (unsigned width, ofs_t *ofs)\r
+#if 0\r
+void VL_SetLineWidth (unsigned width, global_game_variables_t *gvar)\r
 {\r
        int i,offset;\r
 \r
@@ -181,17 +183,17 @@ void VL_SetLineWidth (unsigned width, ofs_t *ofs)
 //\r
 // set up lookup tables\r
 //\r
-       ofs->linewidth = width*2;\r
+       gvar->video.ofs.linewidth = width*2;\r
 \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
+               gvar->video.ofs.ylookup[i]=offset;\r
+               offset += gvar->video.ofs.linewidth;\r
        }\r
 }\r
-\r
+#endif\r
 /*\r
 =============================================================================\r
 \r
@@ -216,7 +218,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 +282,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 +295,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 +358,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 +370,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 +387,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 +439,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 +465,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 +475,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
@@ -483,6 +485,25 @@ void VL_TestPaletteSet (video_t *v)
                v->fastpalette = false;\r
 }\r
 \r
+/*\r
+==================\r
+=\r
+= VL_ColorBorder\r
+=\r
+==================\r
+*/\r
+\r
+void VL_ColorBorder (int color, video_t *v)\r
+{\r
+       union REGS in, out;\r
+\r
+       in.h.ah = 0x10;\r
+       in.h.al = 0x01;\r
+       in.h.bh = color;\r
+       int86(0x10, &in, &out);\r
+       v->bordercolor = color;\r
+}\r
+\r
 \r
 /*\r
 =============================================================================\r
@@ -502,14 +523,18 @@ void VL_TestPaletteSet (video_t *v)
 =================\r
 */\r
 \r
-void VL_Plot (int x, int y, int color, ofs_t *ofs)\r
+void VL_Plot (int x, int y, int color, global_game_variables_t *gvar)\r
 {\r
        byte mask;\r
        VCLIPDEF\r
 \r
+       if(!gvar->video.VL_Started) return;\r
+\r
        mask = pclip[x&3];\r
        VGAMAPMASK(mask);\r
-       *(byte far *)MK_FP(SCREENSEG,ofs->bufferofs+(ofs->ylookup[y]+(x>>2))) = color;\r
+       //*(byte far *)MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+(gvar->video.ofs.ylookup[y]+(x>>2))) = color;\r
+       //*(byte far *)MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+((y*VGASTRIDEVARIABLE)+(x>>2))) = color;\r
+       *(byte far *)MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+((y*VGASTRIDEVARIABLE)+(x>>2))) = color;\r
        VGAMAPMASK(15);\r
 }\r
 \r
@@ -522,7 +547,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, global_game_variables_t *gvar)\r
 {\r
        unsigned                xbyte;\r
        byte                    far *dest;\r
@@ -531,16 +556,19 @@ void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs
 \r
        LRCLIPDEF\r
 \r
+       if(!gvar->video.VL_Started) return;\r
+\r
        xbyte = x>>2;\r
        leftmask = lclip[x&3];\r
        rightmask = rclip[(x+width-1)&3];\r
        midbytes = ((x+width+3)>>2) - xbyte - 2;\r
 \r
-       dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+xbyte);\r
+       //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+xbyte);\r
+       dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+xbyte);\r
 \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,20 +597,24 @@ 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, global_game_variables_t *gvar)\r
 {\r
        byte    far *dest,mask;\r
        VCLIPDEF\r
 \r
+       if(!gvar->video.VL_Started) return;\r
+\r
        mask = pclip[x&3];\r
        VGAMAPMASK(mask);\r
 \r
-       dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2));\r
+       //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));\r
+       dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(x>>2));\r
 \r
        while (height--)\r
        {\r
                *dest = color;\r
-               dest += ofs->linewidth;\r
+               //dest += gvar->video.ofs.linewidth;\r
+               dest += VGASTRIDEVARIABLE;\r
        }\r
 \r
        VGAMAPMASK(15);\r
@@ -597,7 +629,7 @@ void VL_Vlin (int x, int y, int height, int color, ofs_t *ofs)
 =================\r
 */\r
 \r
-void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs)\r
+void VL_Bar (int x, int y, int width, int height, int color, global_game_variables_t *gvar)\r
 {\r
        byte    far *dest;\r
        byte    leftmask,rightmask;\r
@@ -605,21 +637,26 @@ void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs)
 \r
        LRCLIPDEF\r
 \r
+       if(!gvar->video.VL_Started) return;\r
+\r
        leftmask = lclip[x&3];\r
        rightmask = rclip[(x+width-1)&3];\r
        midbytes = ((x+width+3)>>2) - (x>>2) - 2;\r
-       linedelta = ofs->linewidth-(midbytes+1);\r
+       //linedelta = gvar->video.ofs.linewidth-(midbytes+1);\r
+       linedelta = VGASTRIDEVARIABLE-(midbytes+1);\r
 \r
-       dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2));\r
+       //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));\r
+       dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(x>>2));\r
 \r
        if (midbytes<0)\r
        {\r
-       // all in one byte\r
+       // all in       one byte\r
                VGAMAPMASK(leftmask&rightmask);\r
                while (height--)\r
                {\r
                        *dest = color;\r
-                       dest += ofs->linewidth;\r
+                       //dest += gvar->video.ofs.linewidth;\r
+                       dest += VGASTRIDEVARIABLE;\r
                }\r
                VGAMAPMASK(15);\r
                return;\r
@@ -643,13 +680,50 @@ 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, global_game_variables_t *gvar)\r
+{\r
+       byte    far *screen,far *dest,mask;\r
+       int             plane;\r
+\r
+       width>>=2;\r
+       //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));\r
+       dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(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+=gvar->video.ofs.linewidth,source+=width)\r
+               for     (y=0;y<height;y++,screen+=VGASTRIDEVARIABLE,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 +744,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 +777,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 +828,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