]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_vl.c
updated the copyleft wwww i am not deAD! i just been 2 busy last 6 monthes
[16.git] / src / lib / 16_vl.c
index db066c727762adb2565e5968dd2e9af2512b28b2..e2000348d7ecf673c569525661a96a5cca4ad7c4 100755 (executable)
@@ -1,5 +1,5 @@
 /* Project 16 Source Code~\r
- * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ * Copyright (C) 2012-2018 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
  *\r
  * This file is part of Project 16.\r
  *\r
@@ -28,7 +28,7 @@
 byte far* VGA=(byte far*) 0xA0000000;   /* this points to video memory. */\r
 \r
 static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette);\r
-static byte tmppal[PAL_SIZE];\r
+/*static */byte tmppal[PAL_SIZE];\r
 \r
 //===========================================================================\r
 \r
@@ -45,7 +45,8 @@ void  VL_Startup (global_game_variables_t *gvar)
        __asm   cld;\r
 \r
        VGAmodeX(1/*TODO other modes*/, 1, gvar);\r
-       VL_LoadPalFileCore(gvar->video.palette, gvar);\r
+//--   VL_LoadPalFileCore(gvar->video.palette, gvar);\r
+       VL_SetCorePal(gvar);\r
        //Quit ("Improper video card!  If you really have a VGA card that I am not\ndetecting it!", gvar);\r
 }\r
 \r
@@ -282,7 +283,7 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)
        switch(vq)\r
        {\r
                case 1:\r
-//             case 8: //320x240 no buffer\r
+               case 8: //320x240 no buffer\r
                        //CRTParmCount = sizeof(ModeX_320x240regs) / sizeof(ModeX_320x240regs[0]);\r
                        /*for(i=0; i<CRTParmCount; i++) {\r
                                outpw(CRTC_INDEX, ModeX_320x240regs[i]);\r
@@ -545,6 +546,9 @@ void modexHiganbanaPageSetup(global_game_variables_t *gvar)
                gvar->video.page[1].dx=gvar->video.page[1].dy=TILEWH;   // 1 tile size buffer\r
        gvar->video.page[2].dx=gvar->video.page[2].dy=\r
                gvar->video.page[3].dx=gvar->video.page[3].dy=0;                // cache pages are buffer wwww\r
+\r
+       gvar->video.page[0].tlx=gvar->mv[0].tx*TILEWH;\r
+       gvar->video.page[0].tly=gvar->mv[0].ty*TILEWH;\r
 }\r
 \r
 //\r
@@ -567,14 +571,14 @@ modexShowPage(page_t *page) {
        low_address  = LOW_ADDRESS  | (offset << 8);\r
 \r
        /* wait for appropriate timing and then program CRTC */\r
-//+=+=                                                                         while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE));\r
+//+=+=                                                                         while ((inp(STATUS_REGISTER_1) & DISPLAY_ENABLE));\r
        outpw(CRTC_INDEX, high_address);\r
        outpw(CRTC_INDEX, low_address);\r
        outp(CRTC_INDEX, 0x13);\r
        outp(CRTC_DATA, crtcOffset);\r
 \r
        /* wait for one retrace */\r
-//+=+=                                                                         while (!(inp(INPUT_STATUS_1) & VRETRACE));\r
+//+=+=                                                                         while (!(inp(STATUS_REGISTER_1) & VRETRACE));\r
 \r
        /* do PEL panning here */\r
        outp(AC_INDEX, 0x33);\r
@@ -609,14 +613,14 @@ VL_ShowPage(page_t *page, boolean vsync, boolean sr)
        low_address  = LOW_ADDRESS  | (offset << 8);\r
 \r
        // wait for appropriate timing and then program CRTC\r
-       if(vsync) while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE));\r
+       if(vsync) while ((inp(STATUS_REGISTER_1) & DISPLAY_ENABLE));\r
        outpw(CRTC_INDEX, high_address);\r
        outpw(CRTC_INDEX, low_address);\r
        outp(CRTC_INDEX, 0x13);\r
        outp(CRTC_DATA, crtcOffset);\r
 \r
        // wait for one retrace\r
-       if(vsync) while (!(inp(INPUT_STATUS_1) & VRETRACE));\r
+       if(vsync) while (!(inp(STATUS_REGISTER_1) & VRETRACE));\r
 \r
        // do PEL panning here\r
        outp(AC_INDEX, 0x33);\r
@@ -879,11 +883,11 @@ void modexPalSave(byte *palette)
 /*byte *\r
 modexNewPal() {\r
        byte *ptr;\r
-       ptr = m a l l o c(PAL_SIZE);\r
+       ptr = mAlloc(PAL_SIZE);\r
 \r
        // handle errors\r
        if(!ptr) {\r
-               printf("Could not allocate palette.\n");\r
+               printf("Could not Allocate palette.\n");\r
        }\r
 \r
        return ptr;\r
@@ -916,36 +920,60 @@ modexLoadPalFile(byte *filename, byte *palette) {
        fclose(file);\r
 }\r
 \r
-void VL_LoadPalFile(const char *filename, byte *palette, global_game_variables_t *gvar)\r
-{\r
-       VL_LoadPalFilewithoffset(filename, palette, 9, gvar);\r
-//     VL_LoadPalFileCore(palette);\r
-}\r
-\r
-void VL_LoadPalFileCore(byte *palette, global_game_variables_t *gvar)\r
-{\r
-       VL_LoadPalFilewithoffset("data/16.pal", palette, 0, gvar);\r
-}\r
+#define COREPALSIZE 9//27      //3*9\r
 \r
-void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o, global_game_variables_t *gvar)\r
+void VLL_LoadPalFilewithoffset(const char *filename, byte *palette, word o, word palsize, global_game_variables_t *gvar)\r
 {\r
        int fd;\r
+       byte *newpalette;\r
 \r
        fd = open(filename,O_RDONLY|O_BINARY);\r
        if (fd >= 0) {\r
-               read(fd,palette,        PAL_SIZE);\r
+               read(fd,palette,        palsize*3);\r
                close(fd);\r
 \r
-               VL_UpdatePaletteWrite(palette, o, gvar);\r
+               if(palsize==COREPALSIZE) newpalette = palette; else{    //if core then load it\r
+               newpalette = &palette[3];                       //skip overscan color\r
+               if(!o) o++;\r
+               }\r
+               VL_UpdatePaletteWrite(newpalette, o, palsize, gvar);\r
        }\r
 }\r
 \r
-void VL_UpdatePaletteWrite(byte *palette, word o, global_game_variables_t *gvar)\r
+//++++//\r
+void VL_SetCorePal(global_game_variables_t *gvar)\r
+{\r
+       byte *palette = &corepal;\r
+       word i;\r
+\r
+       vga_palette_lseek(0);\r
+       for (i=0;i < COREPALSIZE;i++)\r
+               vga_palette_write(palette[(i*3)+0]>>2,\r
+                                                 palette[(i*3)+1]>>2,\r
+                                                 palette[(i*3)+2]>>2);\r
+\r
+       VL_PaletteSync(gvar);\r
+}\r
+\r
+void VL_LoadPalFile(const char *filename, byte *palette, global_game_variables_t *gvar)\r
+{\r
+       VLL_LoadPalFilewithoffset(filename, palette,\r
+               0,                      //overwrite core/system palette\r
+//             COREPALSIZE,    //preserved core/system palette\r
+               PAL_SIZE/3, gvar);\r
+}\r
+\r
+void VL_LoadPalFileCore(byte *palette, global_game_variables_t *gvar)\r
+{\r
+       VLL_LoadPalFilewithoffset("data/16.pal", palette, 0, COREPALSIZE, gvar);\r
+}\r
+\r
+void VL_UpdatePaletteWrite(byte *palette, word o, word p, global_game_variables_t *gvar)\r
 {\r
        word i;\r
-       vga_palette_lseek(/*1+*/o);\r
-       //for (i=o;i < 256-o;i++)\r
-       for (i=0;i < 256-o;i++)\r
+\r
+       vga_palette_lseek(o);\r
+       for (i=0;i < p-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
@@ -1029,12 +1057,17 @@ VL_modexPalScramble(byte *p)
 }\r
 \r
 word\r
-modexPalOverscan(word col)\r
+VL_modexPalOverscan(byte *p, word col)\r
 {\r
+       int i;\r
        //modexWaitBorder();\r
        vga_wait_for_vsync();\r
        outp(PAL_WRITE_REG, 0);  /* start at the beginning of palette */\r
-       outp(PAL_DATA_REG, col);\r
+       for(i=col; i<(3+col); i++)\r
+       {\r
+               outp(PAL_DATA_REG, p[i]);\r
+       }\r
+//     modexPalSave(p);\r
        return col;\r
 }\r
 \r
@@ -1107,7 +1140,7 @@ void modexDrawChar(page_t *page, int x/*for planar selection only*/, word t, wor
        }\r
 }\r
 \r
-void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col, word bgcol, boolean sw, const byte *str)\r
+void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word color, word bgcolor, boolean vidsw, const byte *str)\r
 {\r
        word s, o, w;\r
        word x_draw;\r
@@ -1116,14 +1149,14 @@ void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col,
        word addrr;\r
        byte c;\r
 \r
-       switch(sw)\r
+       switch(vidsw)\r
        {\r
                case 0:\r
                        printf("%s\n", str);\r
                break;\r
                case 1:\r
                        if(tlsw){ x-=page->tlx; y-=page->tly; }\r
-                       x_draw = x/4;\r
+                       x_draw = x>>2;\r
                        addrq = (page->stridew) * y + (word)(x_draw) +\r
                                ((word)page->data);\r
                        addrr = addrq;\r
@@ -1149,7 +1182,7 @@ void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col,
                        // no need for inline assembly!\r
                        // NTS: It might even be faster to just let the modexDrawChar point directly at ROM font than to copy per char! --J.C.\r
                                _fmemcpy(romFontsData.l,MK_FP(s,o+(w*c))/*ROM font location*/,w/*char size*/);\r
-                               modexDrawChar(page, x_draw/*for mode X planar use*/, t, col, bgcol, addrr);\r
+                               modexDrawChar(page, x_draw/*for mode X planar use*/, t, color, bgcolor, addrr);\r
                                x_draw += 8; /* track X for edge of screen */\r
                                addrr += 2; /* move 8 pixels over (2 x 4 planar pixels per byte) */\r
                        }\r
@@ -1251,8 +1284,14 @@ void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, c
        }\r
 }\r
 \r
+//     short hand of modexprint\r
+void VL_print(const byte *str, nibble pagenum, global_game_variables_t *gvar)\r
+{\r
+       modexprint(&(gvar->video.page[pagenum]), gvar->video.print.x, gvar->video.print.y, gvar->video.print.t, gvar->video.print.tlsw, gvar->video.print.color, gvar->video.print.bgcolor, gvar->video.VL_Started, str);\r
+}\r
+\r
 /* palette dump on display! */\r
-void modexpdump(page_t *pee)\r
+void modexpdump(nibble pagenum, global_game_variables_t *gvar)\r
 {\r
        int mult=(QUADWH);\r
        int palq=(mult)*TILEWH;\r
@@ -1260,10 +1299,11 @@ void modexpdump(page_t *pee)
        int palx, paly;\r
        for(paly=TILEWH*8; paly<palq+TILEWH*8; paly+=mult){\r
                for(palx=TILEWH*12; palx<palq+TILEWH*12; palx+=mult){\r
-                               modexClearRegion(pee, palx+TILEWH, paly+TILEWH, mult, mult, palcol);\r
+                               modexClearRegion(&gvar->video.page[pagenum], palx+TILEWH, paly+TILEWH, mult, mult, palcol);\r
                        palcol++;\r
                }\r
        }\r
+       modexPalSave(gvar->video.palette);\r
 }\r
 #if 0\r
 /////////////////////////////////////////////////////////////////////////////\r
@@ -1333,11 +1373,11 @@ void VL_PatternDraw(video_t *video, word pn, boolean sw, boolean allsw)
 \r
 void\r
 modexWaitBorder() {\r
-       while(inp(INPUT_STATUS_1)  & 8)  {\r
+       while(inp(STATUS_REGISTER_1)  & 8)  {\r
        // spin\r
        }\r
 \r
-       while(!(inp(INPUT_STATUS_1)  & 8))  {\r
+       while(!(inp(STATUS_REGISTER_1)  & 8))  {\r
        //spin\r
        }\r
 }\r
@@ -1345,7 +1385,7 @@ modexWaitBorder() {
 void\r
 modexWaitBorder_start()\r
 {\r
-       while(inp(INPUT_STATUS_1)  & 8)  {\r
+       while(inp(STATUS_REGISTER_1)  & 8)  {\r
        // spin\r
        }\r
 \r
@@ -1354,7 +1394,7 @@ modexWaitBorder_start()
 void\r
 modexWaitBorder_end()\r
 {\r
-       while(!(inp(INPUT_STATUS_1)  & 8))  {\r
+       while(!(inp(STATUS_REGISTER_1)  & 8))  {\r
        // spin\r
        }\r
 \r
@@ -1374,17 +1414,25 @@ void VL_PrintmodexmemInfo(video_t *v)
 //     printf("========================================\n");\r
        printf("  Virtual Screen: %dx", v->page[0].width);      printf("%d      ", v->page[0].height);  printf("Tile: %dx", v->page[0].ti.tilesw);              printf("%d", v->page[0].ti.tilesh);     printf("=((Virtual Screen)/16)\n");\r
        printf("          Screen: %dx", v->page[0].sw);         printf("%d      ", v->page[0].sh);              printf("Tile: %dx", v->page[0].ti.tw);                  printf("%d", v->page[0].ti.th);         printf("=((Screen)/16)\n");\r
-\r
-       printf("  Free Video Memory: %u\n", v->vmem_remain);\r
-       printf("  page");\r
-       for(i=0; i<v->num_of_pages;i++)\r
+       printf("  vga_stride: %u ", vga_state.vga_stride);\r
+       printf("pagestride: %u ", v->page[0].stridew);\r
+       printf("draw_stride: %u ", vga_state.vga_draw_stride);\r
+       printf("draw_stride_limit: %u\n", vga_state.vga_draw_stride_limit);\r
+\r
+       if(v->vmem_remain)\r
+               printf("  Free Video Memory: %u\n", v->vmem_remain);\r
+       if(v->num_of_pages)\r
        {\r
-               printf("        [%u]=", i);\r
-               printf("(%Fp)", (v->page[i].data));\r
-               printf(" size=%u        ", v->page[i].pagesize);\r
-               printf("w=%-3lu  h=%-3lu ", (unsigned long)v->page[i].width, (unsigned long)v->page[i].height);\r
-               printf("sw=%-3lu  sh=%-3lu ", (unsigned long)v->page[i].sw, (unsigned long)v->page[i].sh);\r
-               printf("pi=%u", v->page[i].pi);\r
-               printf("\n");\r
+       printf("  page");\r
+               for(i=0; i<v->num_of_pages;i++)\r
+               {\r
+                       printf("        [%u]=", i);\r
+                       printf("(%Fp)", (v->page[i].data));\r
+                       printf(" size=%u        ", v->page[i].pagesize);\r
+                       printf("w=%-3lu  h=%-3lu ", (unsigned long)v->page[i].width, (unsigned long)v->page[i].height);\r
+                       printf("sw=%-3lu  sh=%-3lu ", (unsigned long)v->page[i].sw, (unsigned long)v->page[i].sh);\r
+                       printf("pi=%u", v->page[i].pi);\r
+                       printf("\n");\r
+               }\r
        }\r
 }\r