]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_vl.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.c
index 24e3342ed0fe67efbba8d6fde36f65f6df8cb2bd..be84166c458c8c7fe5cad431a4a91b037a38de12 100755 (executable)
@@ -30,10 +30,179 @@ byte far* VGA=(byte far*) 0xA0000000;   /* this points to video memory. */
 static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette);\r
 static byte tmppal[PAL_SIZE];\r
 \r
+//===========================================================================\r
+\r
+/*\r
+=======================\r
+=\r
+= VL_Startup\r
+=\r
+=======================\r
+*/\r
+\r
+void   VL_Startup (global_game_variables_t *gvar)\r
+{\r
+       __asm   cld;\r
+\r
+       VGAmodeX(1/*TODO other modes*/, 1, gvar);\r
+       VL_LoadPalFileCore(gvar->video.palette, gvar);\r
+       //Quit ("Improper video card!  If you really have a VGA card that I am not\ndetecting it!", gvar);\r
+}\r
+\r
+\r
+\r
+/*\r
+=======================\r
+=\r
+= VL_Shutdown\r
+=\r
+=======================\r
+*/\r
+\r
+void   VL_Shutdown (global_game_variables_t *gvar)\r
+{\r
+       VGAmodeX(0, 1, gvar);\r
+}\r
+\r
+/*\r
+=======================\r
+=\r
+= VL_SetVGAPlaneMode\r
+=\r
+=======================\r
+*/\r
+#if 0\r
+void   VL_SetVGAPlaneMode (global_game_variables_t *gvar)\r
+{\r
+       VL_vgaSetMode(VGA_256_COLOR_MODE);\r
+       VL_DePlaneVGA ();\r
+       VGAMAPMASK(15);\r
+       VL_SetLineWidth (40, &gvar->video.ofs);\r
+}\r
+#endif\r
+\r
+//===========================================================================\r
+\r
+/*\r
+=================\r
+=\r
+= VL_ClearVideo\r
+=\r
+= Fill the entire video buffer with a given color\r
+=\r
+=================\r
+*/\r
+\r
+void VL_ClearVideo (byte color)\r
+{\r
+       __asm {\r
+               mov     dx,GC_INDEX\r
+               mov     al,GC_MODE\r
+               out     dx,al\r
+               inc     dx\r
+               in      al,dx\r
+               and     al,0xfc                         // write mode 0 to store directly to video\r
+               out     dx,al\r
+\r
+               mov     dx,SC_INDEX\r
+               mov     ax,SC_MAPMASK+15*256\r
+               out     dx,ax                           // write through all four planes\r
+\r
+               mov     ax,SCREENSEG\r
+               mov     es,ax\r
+               mov     al,[color]\r
+               mov     ah,al\r
+               mov     cx,0x8000                       // 0x8000 words, clearing 8 video bytes/word\r
+               xor     di,di\r
+               rep     stosw\r
+       }\r
+}\r
+\r
+/*\r
+=============================================================================\r
+\r
+                       VGA REGISTER MANAGEMENT ROUTINES\r
+\r
+=============================================================================\r
+*/\r
+\r
+\r
+/*\r
+=================\r
+=\r
+= VL_DePlaneVGA\r
+=\r
+=================\r
+*/\r
+#if 0\r
+void VL_DePlaneVGA (void)\r
+{\r
+\r
+//\r
+// change CPU addressing to non linear mode\r
+//\r
+\r
+//\r
+// turn off chain 4 and odd/even\r
+//\r
+       outportb (SC_INDEX,SC_MEMMODE);\r
+       outportb (SC_INDEX+1,(inportb(SC_INDEX+1)&~8)|4);\r
+\r
+       outportb (SC_INDEX,SC_MAPMASK);         // leave this set throughought\r
+\r
+//\r
+// turn off odd/even and set write mode 0\r
+//\r
+       outportb (GC_INDEX,GC_MODE);\r
+       outportb (GC_INDEX+1,inportb(GC_INDEX+1)&~0x13);\r
+\r
+//\r
+// turn off chain\r
+//\r
+       outportb (GC_INDEX,GC_MISCELLANEOUS);\r
+       outportb (GC_INDEX+1,inportb(GC_INDEX+1)&~2);\r
+\r
+//\r
+// clear the entire buffer space, because int 10h only did 16 k / plane\r
+//\r
+       VL_ClearVideo (0);\r
+\r
+//\r
+// change CRTC scanning from doubleword to byte mode, allowing >64k scans\r
+//\r
+       outportb (CRTC_INDEX,CRTC_UNDERLINE);\r
+       outportb (CRTC_INDEX+1,inportb(CRTC_INDEX+1)&~0x40);\r
+\r
+       outportb (CRTC_INDEX,CRTC_MODE);\r
+       outportb (CRTC_INDEX+1,inportb(CRTC_INDEX+1)|0x40);\r
+}\r
+#endif\r
+//===========================================================================\r
+\r
+/*\r
+====================\r
+=\r
+= VL_SetSplitScreen\r
+=\r
+====================\r
+*/\r
+\r
+void VL_SetSplitScreen (int linenum)\r
+{\r
+       VL_WaitVBL (1);\r
+       linenum=linenum*2-1;\r
+       outportb (CRTC_INDEX,CRTC_LINECOMPARE);\r
+       outportb (CRTC_INDEX+1,linenum % 256);\r
+       outportb (CRTC_INDEX,CRTC_OVERFLOW);\r
+       outportb (CRTC_INDEX+1, 1+16*(linenum/256));\r
+       outportb (CRTC_INDEX,CRTC_MAXSCANLINE);\r
+       outportb (CRTC_INDEX+1,inportb(CRTC_INDEX+1) & (255-64));\r
+}\r
+\r
 /////////////////////////////////////////////////////////////////////////////\r
-//                                                                                                                                                                                                                                             //\r
-// setvideo() - This function Manages the video modes                                                                                          //\r
-//                                                                                                                                                                                                                                             //\r
+//                                                                                                                     //\r
+// setvideo() - This function Manages the video modes                                          //\r
+//                                                                                                                     //\r
 /////////////////////////////////////////////////////////////////////////////\r
 void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv)\r
 {\r
@@ -60,22 +229,26 @@ void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv)
                        // get old video mode\r
                        //in.h.ah = 0xf;\r
                        //int86(0x10, &in, &out);\r
-                       gv->video.old_mode = vgaGetMode();//out.h.al;\r
+                       gv->video.old_mode = VL_vgaGetMode();//out.h.al;\r
                        // enter mode\r
                        modexEnter(vq, cmem, gv);\r
                break;\r
        }\r
 }\r
 \r
-static void\r
-vgaSetMode(byte mode)\r
+//---------------------------------------------------\r
+//\r
+// Use the bios to set the current video mode\r
+//\r
+\r
+/*static */void\r
+VL_vgaSetMode(byte mode)\r
 {\r
        union REGS regs;\r
 \r
        regs.h.ah = SET_MODE;\r
        regs.h.al = mode;\r
        int86(VIDEO_INT, &regs, &regs);\r
-  //int10_setmode(mode);\r
 }\r
 \r
 //---------------------------------------------------\r
@@ -83,8 +256,8 @@ vgaSetMode(byte mode)
 // Use the bios to get the current video mode\r
 //\r
 \r
-byte/*FIXME: why long? "long" is 32-bit datatype, VGA modes are 8-bit numbers. */\r
-vgaGetMode()\r
+byte\r
+VL_vgaGetMode(void)\r
 {\r
        return int10_getmode();\r
 }\r
@@ -92,11 +265,11 @@ vgaGetMode()
 /* -========================= Entry  Points ==========================- */\r
 void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)\r
 {\r
-       word i;\r
+       //word i;\r
        struct vga_mode_params cm;\r
        //int CRTParmCount;\r
 \r
-       vgaSetMode(VGA_256_COLOR_MODE);\r
+       VL_vgaSetMode(VGA_256_COLOR_MODE);\r
        vga_enable_256color_modex();\r
 \r
        update_state_from_vga();\r
@@ -158,27 +331,33 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)
        vga_state.vga_stride = cm.offset * 2;\r
        vga_write_crtc_mode(&cm,0);\r
 \r
-       /* clear video memory */\r
+       // clear video memory //\r
        switch (cmem)\r
        {\r
-               case 1: {\r
-                       /* clear video memory */\r
-                       dword far*ptr=(dword far*)vga_state.vga_graphics_ram;//VGA;       /* used for faster screen clearing */\r
+               case 1:\r
+               {\r
+#if 0\r
+                       dword far*ptr=(dword far*)vga_state.vga_graphics_ram;//VGA;       // used for faster screen clearing //\r
                        vga_write_sequencer(2/*map mask register*/,0xf/*all 4 planes*/);\r
                        for(i = 0;i < 0x4000; i++) ptr[i] = 0x0000; // 0x4000 x dword = 64KB\r
-                       /* fix up the palette and everything */\r
-                       modexPalBlack();        //reset the palette~\r
+                       // fix up the palette and everything //\r
+                       modexPalBlack();        //reset the palette~//\r
+#endif\r
+                       //\r
+                       // clear the entire buffer space, because int 10h only did 16 k / plane\r
+                       //\r
+                       VL_ClearVideo (0);\r
                }\r
                break;\r
        }\r
-//     VL_SetLineWidth (cm.offset, &gv->video.ofs);\r
+       VL_SetLineWidth (cm.offset, &gv->video.ofs);\r
        gv->video.VL_Started=1;\r
 }\r
 \r
-void\r
-modexLeave() {\r
-       /* VGAmodeX restores original mode and palette */\r
-       vgaSetMode(TEXT_MODE);\r
+void modexLeave(void)\r
+{\r
+       // VGAmodeX restores original mode and palette\r
+       VL_vgaSetMode(TEXT_MODE);\r
 }\r
 \r
 page_t\r
@@ -644,14 +823,15 @@ fadePalette(sbyte fade, sbyte start, word iter, byte *palette) {
 }\r
 \r
 \r
-/* save and load */\r
-void\r
-modexPalSave(byte *palette) {\r
+// save and load\r
+void modexPalSave(byte *palette)\r
+{\r
        int  i;\r
 \r
-       outp(PAL_READ_REG, 0);    /* start at palette entry 0 */\r
-       for(i=0; i<PAL_SIZE; i++) {\r
-       palette[i] = inp(PAL_DATA_REG); /* read the palette data */\r
+       outp(PAL_READ_REG, 0);                  // start at palette entry 0\r
+       for(i=0; i<PAL_SIZE; i++)\r
+       {\r
+               palette[i] = inp(PAL_DATA_REG); // read the palette data\r
        }\r
 }\r
 \r
@@ -696,18 +876,18 @@ modexLoadPalFile(byte *filename, byte *palette) {
        fclose(file);\r
 }\r
 \r
-void VL_LoadPalFile(const char *filename, byte *palette)\r
+void VL_LoadPalFile(const char *filename, byte *palette, global_game_variables_t *gvar)\r
 {\r
-       VL_LoadPalFilewithoffset(filename, palette, 8);\r
-       VL_LoadPalFileCore(palette);\r
+       VL_LoadPalFilewithoffset(filename, palette, 8, gvar);\r
+//     VL_LoadPalFileCore(palette);\r
 }\r
 \r
-void VL_LoadPalFileCore(byte *palette)\r
+void VL_LoadPalFileCore(byte *palette, global_game_variables_t *gvar)\r
 {\r
-       VL_LoadPalFilewithoffset("data/16.pal", palette, 0);\r
+       VL_LoadPalFilewithoffset("data/16.pal", palette, 0, gvar);\r
 }\r
 \r
-void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o)\r
+void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o, global_game_variables_t *gvar)\r
 {\r
        int fd;\r
 \r
@@ -716,15 +896,24 @@ void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o)
                read(fd,palette,        PAL_SIZE);\r
                close(fd);\r
 \r
-               VL_UpdatePaletteWrite(palette, o);\r
+               VL_UpdatePaletteWrite(palette, o, gvar);\r
        }\r
 }\r
 \r
-void VL_UpdatePaletteWrite(byte *palette, word o)\r
+void VL_UpdatePaletteWrite(byte *palette, word o, global_game_variables_t *gvar)\r
 {\r
        word i;\r
        vga_palette_lseek(/*1+*/o);\r
-       for (i=o;i < 256-o;i++) vga_palette_write(palette[(i*3)+0]>>2,palette[(i*3)+1]>>2,palette[(i*3)+2]>>2);\r
+       //for (i=o;i < 256-o;i++)\r
+       for (i=0;i < 256-o;i++)\r
+               vga_palette_write(palette[(i*3)+0]>>2,palette[(i*3)+1]>>2,palette[(i*3)+2]>>2);\r
+\r
+       VL_PaletteSync(gvar);\r
+}\r
+\r
+void VL_PaletteSync(global_game_variables_t *gvar)\r
+{\r
+       modexPalSave(&gvar->video.palette);\r
 }\r
 \r
 void\r
@@ -1035,7 +1224,7 @@ void modexpdump(page_t *pee)
                }\r
        }\r
 }\r
-\r
+#if 0\r
 /////////////////////////////////////////////////////////////////////////////\r
 //                                                                                                                                              //\r
 // cls() - This clears the screen to the specified color, on the VGA or on //\r
@@ -1050,7 +1239,7 @@ void modexcls(page_t *page, byte color, byte *Where)
        //_fmemset(VGA, color, 16000);\r
        _fmemset(Where, color, page->stridew*page->height);\r
 }\r
-\r
+#endif\r
 //\r
 // pattern filler from joncampbell123's code\r
 //\r