]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_vl.c
XCROLL broken
[16.git] / src / lib / 16_vl.c
index a0b587236b909dcad7b9bd71de40bb3334f6916b..2078def23a770eaa6b92ec95fb614e946df96462 100755 (executable)
@@ -43,12 +43,18 @@ void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv)
        {\r
                case 0: // deinit the video\r
                        // change to the video mode we were in before we switched to mode 13h\r
-                       modexLeave();\r
-                       in.h.ah = 0x00;\r
-                       in.h.al = gv->video.old_mode;\r
-                       int86(0x10, &in, &out);\r
+                       if(gv->video.VL_Started)\r
+                       {\r
+                               modexLeave();\r
+                               in.h.ah = 0x00;\r
+                               in.h.al = gv->video.old_mode;\r
+                               int86(0x10, &in, &out);\r
+                       }\r
+                       gv->video.VL_Started=0;\r
                break;\r
                default: // init the video\r
+                       if(gv->video.VL_Started)\r
+                               return;\r
                        // get old video mode\r
                        //in.h.ah = 0xf;\r
                        //int86(0x10, &in, &out);\r
@@ -158,16 +164,13 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv)
                        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
                }\r
                break;\r
        }\r
-\r
-//     gv->video.page[0].ti.tw = gv->video.page[0].sw/TILEWH;\r
-//     gv->video.page[0].ti.th = gv->video.page[0].sh/TILEWH;\r
-\r
-       //TODO MAKE FLEXIBLE~\r
-//     gv->video.page[0].ti.tilemidposscreenx = gv->video.page[0].ti.tilesw;\r
-//     gv->video.page[0].ti.tilemidposscreeny = (gv->video.page[0].ti.tilesh/2)+1;\r
+//     VL_SetLineWidth (cm.offset, &gv->video.ofs);\r
+       gv->video.VL_Started=1;\r
 }\r
 \r
 void\r
@@ -279,7 +282,7 @@ void modexCalcVmemRemain(video_t *video)
 \r
 void VL_Initofs(video_t *video)\r
 {\r
-       if(!video->bgps)\r
+       if(!video->vga_state.bgps)\r
        {\r
                video->ofs.offscreen_ofs =      video->page[0].pagesize+video->page[1].pagesize;//(vga_state.vga_stride * vga_state.vga_height);\r
                video->ofs.pattern_ofs =        (uint16_t)video->page[2].data;\r
@@ -309,12 +312,12 @@ void modexHiganbanaPageSetup(video_t *video)
 \r
        VL_Initofs(video);\r
        //doslib origi var\r
-       video->omemptr=                 vga_state.vga_graphics_ram;\r
-       video->vga_draw_stride= vga_state.vga_draw_stride;\r
-       video->vga_draw_stride_limit=   vga_state.vga_draw_stride_limit;\r
+       video->vga_state.omemptr=                       vga_state.vga_graphics_ram;\r
+       video->vga_state.vga_draw_stride=       vga_state.vga_draw_stride;\r
+       video->vga_state.vga_draw_stride_limit= vga_state.vga_draw_stride_limit;\r
        //sprite render switch and bgpreservation switch\r
-       video->rss=             1;\r
-       video->bgps=    1;\r
+       video->vga_state.rss=           1;\r
+       video->vga_state.bgps=  1;\r
 \r
        //setup the buffersize\r
        video->page[0].dx=video->page[0].dy=\r
@@ -414,20 +417,20 @@ modexSelectPlane(byte plane) {
 }\r
 \r
 void\r
-modexClearRegion(page_t *page, int x, int y, int w, int h, byte  color) {\r
+modexClearRegion(page_t *page, int x, int y, int w, int h, byte color)\r
+{\r
        word pageOff = (word) page->data;\r
-       word xoff=x/4;     /* xoffset that begins each row */\r
-       word scanCount=w/4;  /* number of iterations per row (excluding right clip)*/\r
-       word poffset = pageOff + y*(page->stridew) + xoff; /* starting offset */\r
-       word nextRow = page->stridew-scanCount-1;  /* loc of next row */\r
-       byte lclip[] = {0x0f, 0x0e, 0x0c, 0x08};  /* clips for rectangles not on 4s */\r
-       byte rclip[] = {0x00, 0x01, 0x03, 0x07};\r
+       word xoff=(x>>2);                                                       // xoffset that begins each row\r
+       word poffset = pageOff + y*(page->stridew) + xoff;      // starting offset\r
+       word scanCount=w>>2;                                            // number of iterations per row (excluding right clip)\r
+       word nextRow = page->stridew-scanCount-1;               // loc of next row\r
+       LRCLIPDEF\r
        byte left = lclip[x&0x03];\r
        byte right = rclip[(x+w)&0x03];\r
 \r
-       /* handle the case which requires an extra group */\r
+       // handle the case which requires an extra group\r
        if((x & 0x03) && !((x+w) & 0x03)) {\r
-         right=0x0f;\r
+               right=0x0f;\r
        }\r
 \r
        //printf("modexClearRegion(x=%u, y=%u, w=%u, h=%u, left=%u, right=%u)\n", x, y, w, h, left, right);\r
@@ -497,17 +500,16 @@ modexCopyPageRegion(page_t *dest, page_t *src,
                        word dx, word dy,\r
                        word width, word height)\r
 {\r
-       word doffset = (word)dest->data + dy*(dest->stridew) + dx/4;\r
-       word soffset = (word)src->data + sy*(src->stridew) + sx/4;\r
-       word scans   = vga_state.vga_stride;                            //++++0000 the quick and dirty fix of the major issue with p16 video display wwww\r
+       word doffset = (word)dest->data + dy*(dest->stridew) + (dx>>2);\r
+       word soffset = (word)src->data + sy*(src->stridew) + (sx>>2);\r
+       word scans      = vga_state.vga_stride+8;                               //++++0000 the quick and dirty fix of the major issue with p16 video display wwww\r
        word nextSrcRow = src->stridew - scans - 1;\r
        word nextDestRow = dest->stridew - scans - 1;\r
-       byte lclip[] = {0x0f, 0x0e, 0x0c, 0x08};  /* clips for rectangles not on 4s */\r
-       byte rclip[] = {0x00, 0x01, 0x03, 0x07};\r
+       LRCLIPDEF\r
        byte left = lclip[sx&0x03];\r
        byte right = rclip[(sx+width)&0x03];\r
 \r
-       /* handle the case which requires an extra group */\r
+       // handle the case which requires an extra group\r
        if((sx & 0x03) && !((sx+width) & 0x03)) {\r
                right=0x0f;\r
        }\r
@@ -584,6 +586,7 @@ modexCopyPageRegion(page_t *dest, page_t *src,
        }\r
 }\r
 \r
+//check 16_vl_1.c\r
 \r
 /* fade and flash */\r
 void\r
@@ -649,41 +652,39 @@ modexPalSave(byte *palette) {
 }\r
 \r
 \r
-byte *\r
+/*byte *\r
 modexNewPal() {\r
        byte *ptr;\r
-       ptr = malloc(PAL_SIZE);\r
+       ptr = m a l l o c(PAL_SIZE);\r
 \r
-       /* handle errors */\r
+       // handle errors\r
        if(!ptr) {\r
                printf("Could not allocate palette.\n");\r
        }\r
 \r
        return ptr;\r
-}\r
+}*/\r
 \r
 \r
 void\r
-modexLoadPalFile(byte *filename, byte **palette) {\r
+modexLoadPalFile(byte *filename, byte *palette) {\r
        FILE *file;\r
        byte *ptr;\r
 \r
-       /* free the palette if it exists */\r
-       if(*palette) {\r
-       free(*palette);\r
-       }\r
+       // free the palette if it exists\r
+       //if(*palette) { free(*palette); }\r
 \r
-       /* allocate the new palette */\r
-       *palette = modexNewPal();\r
+       // allocate the new palette\r
+       //*palette = modexNewPal();\r
 \r
-       /* open the file */\r
+       // open the file\r
        file = fopen(filename, "rb");\r
        if(!file) {\r
-       printf("Could not open palette file: %s\n", filename);\r
+               printf("Could not open palette file: %s\n", filename);\r
        }\r
 \r
        /* read the file */\r
-       ptr = *palette;\r
+       ptr = palette;\r
        while(!feof(file)) {\r
        *ptr++ = fgetc(file);\r
        }\r
@@ -693,21 +694,29 @@ modexLoadPalFile(byte *filename, byte **palette) {
 \r
 \r
 void VL_LoadPalFile(const char *filename, byte *palette)\r
+{\r
+       VL_LoadPalFilewithoffset(filename, palette, 0);\r
+}\r
+\r
+void VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o)\r
 {\r
        int fd;\r
 \r
        fd = open(filename,O_RDONLY|O_BINARY);\r
        if (fd >= 0) {\r
-               word i;\r
-\r
                read(fd,palette,        PAL_SIZE);\r
                close(fd);\r
 \r
-               vga_palette_lseek(0);\r
-               for (i=0;i < 256;i++) vga_palette_write(palette[(i*3)+0]>>2,palette[(i*3)+1]>>2,palette[(i*3)+2]>>2);\r
+               VL_UpdatePaletteWrite(palette, o);\r
        }\r
 }\r
 \r
+void VL_UpdatePaletteWrite(byte *palette, word o)\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
+}\r
 \r
 void\r
 modexSavePalFile(char *filename, byte *pal) {\r
@@ -780,104 +789,16 @@ modexPalUpdate0(byte *p)
        }\r
 }\r
 \r
-void\r
+word\r
 modexPalOverscan(word col)\r
 {\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
+       return col;\r
 }\r
-\r
-//color checker~\r
-//i want to make another vesion that checks the palette when the palette is being appened~\r
-void modexchkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/)\r
-{\r
-               byte *pal;\r
-               word zz=0;\r
-               pal = modexNewPal();\r
-               modexPalSave(pal);\r
-               //printf("q: %02d\n", (*q));\r
-               printf("chkcolor start~\n");\r
-               printf("1                                  (*z): %d\n", (*z)/3);\r
-               printf("1                                  (*i): %d\n", (*i)/3);\r
-//               printf("1 offset of color in palette  (*q): %d\n", (*q)/3);\r
-               printf("wwwwwwwwwwwwwwww\n");\r
-               //check palette for dups\r
-               for(; (*z)<PAL_SIZE; (*z)+=3)\r
-               {\r
-                       //printf("\n            z: %d\n", (*z));\r
-                       //printf("                q: %d\n", (*q));\r
-                       //printf("                z+q: %d\n\n", ((*z)+(*q)));\r
-                       //if((*z)%3==0)\r
-                       //{\r
-//----                   if(pal[(*z)]==pal[(*z)+3] && pal[(*z)+1]==pal[(*z)+4] && pal[(*z)+2]==pal[(*z)+5])\r
-                               if((*z)==(*i))\r
-                               {\r
-//                                       printf("\n%d  [%02d][%02d][%02d]\n", (*z), pal[(*z)], pal[(*z)+1], pal[(*z)+2]);\r
-//                                       printf("%d      [%02d][%02d][%02d]\n\n", (*z)+3, pal[(*z)+3], pal[(*z)+4], pal[(*z)+5]);\r
-//0000                           (*z)-=3;\r
-                                       break;\r
-                               }\r
-                               else for(zz=0; zz<(*q); zz+=3)\r
-                               {\r
-                                       //printf("zz: %02d\n", zz/3);\r
-                                       if(zz%3==0)\r
-                                       {\r
-                                               if(pal[((*z)+(*q))]==pal[((*z)+(*q))+3] && pal[((*z)+(*q))+1]==pal[((*z)+(*q))+4] && pal[((*z)+(*q))+2]==pal[((*z)+(*q))+5])    //break if duplicate colors found in palette because it have reached the end of the current data of the palette\r
-                                               {\r
-//                                                       (*z)-=3;\r
-//                                                       (*i)-=3;\r
-//                                                       printf("\nzq1:%d[%02d][%02d][%02d]\n", (zz+q), pal[(zz+q)], pal[(zz+q)+1], pal[(zz+q)+2]);\r
-//                                                       printf("zq2:%d[%02d][%02d][%02d]\n\n", (zz+q)+3, pal[(zz+q)+3], pal[(zz+q)+4], pal[(zz+q)+5]);\r
-                                                       break;\r
-                                               }\r
-                                               else if(pal[zz]==pal[((*z)+(*q))] && pal[zz+1]==pal[((*z)+(*q))+1] && pal[zz+2]==pal[((*z)+(*q))+2])\r
-                                               {\r
-//                                                       printf("\n\nwwwwwwwwwwwwwwww\n");\r
-//                                                       printf("      zq: %d  [%02d][%02d][%02d] value that is needing to be changed~\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);\r
-//                                                       printf("      zz: %d  [%02d][%02d][%02d] value that the previous value is going to change to~\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);\r
-//                                                       //printf("      zv: %d  [%02d][%02d][%02d] wwww\n", (zz-z+q)/3, pal[(zz-z+q)], pal[(zz-z+q)+1], pal[(zz-z+q)+2]);\r
-//                                                       printf("      z : %d  [%02d][%02d][%02d] offset value~\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);\r
-//++++                                           (*i)--;\r
-//                                                       (*z)--;\r
-                                                       //expand dong here\r
-/*\r
-planned features that i plan to implement~\r
-image that has values on the pallete list!\r
-wwww\r
-no... wait.... no wwww\r
-*/\r
-                                                       //for(zzii=0; zzii<3; zzii++)\r
-                                                       //{\r
-                                                               //printf("z+q: %d\n\n", ((*z)+(*q)));\r
-                                                               a[(((*z)+(*q)))]=zz;\r
-                                                       //}\r
-                                                       (*aa)=(((*z)+(*q)));\r
-                                                       printf("!!                                        a[%02d]: %d\n", (((*z)+(*q))/3), zz/3);\r
-//                                                       printf("\n              aa: %d\n\n", (*aa));\r
-//                                                       printf("      a[%02d]=(%02d) offset array i think the palette should be updated again~\n", ((*z)+(*q))/3, a[((*z)+(*q))/3]);\r
-//                                                       printf("wwwwwwwwwwwwwwww\n\n");\r
-                                               }\r
-                                               /*else\r
-                                               {\r
-                                                       printf("================\n");\r
-                                                       printf("zq: %d  [%02d][%02d][%02d]\n", ((*z)+(*q))/3, pal[((*z)+(*q))], pal[((*z)+(*q))+1], pal[((*z)+(*q))+2]);\r
-                                                       printf("zz: %d  [%02d][%02d][%02d]\n", (zz)/3, pal[zz], pal[zz+1], pal[zz+2]);\r
-                                                       printf("z : %d  [%02d][%02d][%02d]\n", (*z)/3, pal[(*z)], pal[(*z)+1], pal[(*z)+2]);\r
-                                                       printf("================\n");\r
-                                               }*/\r
-                                               //printf("[%d]", (zz+q));\r
-                                       }\r
-                               }\r
-               }\r
-               printf("wwwwwwwwwwwwwwww\n");\r
-               printf("2                                  (*z): %d\n", (*z)/3);\r
-               printf("2                                  (*i): %d\n", (*i)/3);\r
-//               printf("2 offset of color in palette  (*q): %d\n", (*q)/3);\r
-               printf("chkcolor end~\n");\r
-               free(pal);\r
-}\r
+//check 16_vl_1.c\r
 \r
 void modexputPixel(page_t *page, int x, int y, byte color)\r
 {\r
@@ -946,40 +867,54 @@ void modexDrawChar(page_t *page, int x/*for planar selection only*/, word t, wor
        }\r
 }\r
 \r
-void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str)\r
+void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col, word bgcol, boolean sw, const byte *str)\r
 {\r
        word s, o, w;\r
-       word x_draw = x;\r
+       word x_draw;\r
        //word addr = (word) romFontsData.l;\r
-       word addrq = (page->stridew) * y + (x / 4) + ((word)page->data);\r
-       word addrr = addrq;\r
+       word addrq;\r
+       word addrr;\r
        byte c;\r
 \r
-       s=romFonts[t].seg;\r
-       o=romFonts[t].off;\r
-       w=romFonts[t].charSize;\r
-       romFontsData.chw=0;\r
-\r
-       for(; *str != '\0'; str++)\r
-       {\r
-       c = (*str);\r
-       if(c=='\n')\r
+       switch(sw)\r
        {\r
-               x = x_draw;\r
-               romFontsData.chw = 0;\r
-               addrq += (page->stridew) * 8;\r
-               addrr = addrq;\r
-               y += 8;\r
-               continue;\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
+                       addrq = (page->stridew) * y + (word)(x_draw) +\r
+                               ((word)page->data);\r
+                       addrr = addrq;\r
+                       s=romFonts[t].seg;\r
+                       o=romFonts[t].off;\r
+                       w=romFonts[t].charSize;\r
+                       romFontsData.chw=0;\r
+\r
+                       for(; *str != '\0'; str++)\r
+                       {\r
+                               c = (*str);\r
+                               if(c=='\n')\r
+                               {\r
+                                       x = x_draw;\r
+                                       romFontsData.chw = 0;\r
+                                       addrq += (page->stridew) * 8;\r
+                                       addrr = addrq;\r
+                                       y += 8;\r
+                                       continue;\r
+                               }\r
 \r
-       // load the character into romFontsData.l\r
-       // 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
-               x_draw += 8; /* track X for edge of screen */\r
-               addrr += 2; /* move 8 pixels over (2 x 4 planar pixels per byte) */\r
+                       // load the character into romFontsData.l\r
+                       // 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
+                               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
+                       //printf("print xy:%dx%d        tlxy:%dx%d\n", x, y, page->tlx, page->tly);\r
+               break;\r
        }\r
 }\r
 \r
@@ -1083,8 +1018,8 @@ void modexpdump(page_t *pee)
        int palq=(mult)*TILEWH;\r
        int palcol=0;\r
        int palx, paly;\r
-       for(paly=0; paly<palq; paly+=mult){\r
-               for(palx=0; palx<palq; palx+=mult){\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
                        palcol++;\r
                }\r
@@ -1185,6 +1120,8 @@ modexWaitBorder_end()
 \r
 }\r
 \r
+//===========================================================================\r
+\r
 //\r
 // printings of video memory information\r
 //\r