]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/modex16/16render.c
modex draw char use rom font height, do not assume 8.
[16.git] / src / lib / modex16 / 16render.c
index 89ba13dcd153e03375c64b27c692314ca2907d5c..77598fa55ee14c9616bfbdff3d5b206b29719459 100755 (executable)
@@ -1,5 +1,5 @@
 /* Project 16 Source Code~\r
- * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669\r
+ * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123\r
  *\r
  * This file is part of Project 16.\r
  *\r
 //modexDrawBmpRegion   (page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp)\r
 void modexDrawPBufRegion       (page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *p, boolean sprite)\r
 {\r
-       sword plane;\r
+       word plane;\r
        int i;\r
-       const int px=x;//-page->dx;\r
-       const int py=y;//-page->dy;\r
-       #define PEEE ((rw)/4)-rx\r
-       //-(rx/4)\r
-       #define PEEEE ((p->pwidth)*(ry))\r
-       //y=py;\r
-       //x=px;\r
+       const int px=x+page->dx;\r
+       const int py=y+page->dy;\r
+       const int prw = rw/4;\r
+       int prh;\r
+\r
+       //fine tuning\r
+       rx+=1;\r
+       ry+=1;\r
+\r
+       //^^;\r
+       #define PEEE    rx-prw\r
+       #define PE              (p->pwidth)\r
+       if(rh<p->height) prh = (PE*(ry-4));\r
+       else if(rh==p->height) prh = (PE*(ry));\r
+       y=py;\r
+       x=px;\r
        //printf("%d,%d p(%d,%d) r(%d,%d) rwh(%d,%d)\n", x, y, px, py, rx, ry, rw, rh);\r
        for(plane=0; plane < 4; plane++) {\r
-               i=PEEE+PEEEE;\r
-               //printf("PEEE=%d ", PEEE);\r
-               //printf("PEEEE=%d ", PEEEE);\r
-               //printf("i=%d\n", i);\r
-               modexSelectPlane(PLANE(plane+x));\r
+               i=PEEE+prh;\r
+               modexSelectPlane(PLANE(plane-1));\r
                for(; y < py+rh; y++) {\r
-                       //for(px=0; px < p->width; px++) {\r
-                               //printf("%02X ", (int) p->plane[plane][i++]);\r
-//                           _fmemcpy(buff, &(p->plane[plane][i+=p->pwidth]), p->pwidth);\r
-//                           printf("buff %u==%s\n", y, *buff);\r
-                               _fmemcpy(page->data + (((page->width/4) * y) + (x / 4)), &(p->plane[plane][i+=p->pwidth]), (rw/4));\r
-                       //}\r
-                       //if(plane==3) IN_Ack();\r
+                               _fmemcpy(page->data + (((page->width/4) * (y)) + ((x) / 4)), &(p->plane[plane][i]), prw);\r
+                               i+=PE;\r
                }\r
-               /*printf("y%d=%d ", plane, y);\r
-               if(plane==3) printf("y%d=%d\n", plane, y);*/\r
                x=px;\r
                y=py;\r
-               }\r
+       }\r
 }\r
 \r
 \r
@@ -68,7 +67,9 @@ void modexDrawPBufRegion      (page_t *page, int x, int y, int rx, int ry, int rw, in
 void\r
 modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite)\r
 {\r
-       int plane;\r
+       modexDrawPBufRegion     (page, x, x, 0, 0, p->width, p->height, p, sprite);\r
+       /*\r
+       sword plane;\r
        int i;\r
 //     byte near *buff;\r
        const int px=x+page->dx;\r
@@ -93,20 +94,21 @@ modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite)
 //     }\r
        for(plane=0; plane < 4; plane++) {\r
                i=0;\r
-               modexSelectPlane(PLANE(plane+x));\r
+               modexSelectPlane(PLANE(plane-1));\r
                for(; y < py+p->height; y++) {\r
                        //for(px=0; px < p->width; px++) {\r
                                //printf("%02X ", (int) p->plane[plane][i++]);\r
-//                             _fmemcpy(buff, &(p->plane[plane][i+=p->pwidth]), p->pwidth);\r
-//                             printf("buff %u==%s\n", y, *buff);\r
-//                             _fmemcpy(page->data + (((page->width/4) * (y+page->dy)) + ((x+page->dx) / 4)), buff, p->pwidth);\r
+//                             _fmemcpy(buff, &(p->plane[plane][i+=p->pwidth]), p->pwidth);\r
+//                             printf("buff %u==%s\n", y, *buff);\r
+//                             _fmemcpy(page->data + (((page->width/4) * (y+page->dy)) + ((x+page->dx) / 4)), buff, p->pwidth);\r
                                _fmemcpy(page->data + (((page->width/4) * y) + (x / 4)), &(p->plane[plane][i+=p->pwidth]), p->pwidth);\r
                        //}\r
                }\r
+//getch();\r
                x=px;\r
                y=py;\r
        }\r
-//     _nfree(buff);\r
+//     _nfree(buff);*/\r
 }\r
 \r
 void\r
@@ -287,10 +289,10 @@ void
 modexDrawBmpPBufRegion(page_t *page, int x, int y,\r
                   int rx, int ry, int rw, int rh, planar_buf_t *bmp) {\r
        word poffset = (word) page->data  + y*(page->width/4) + x/4;\r
-       byte *data = *bmp->plane;//+bmp->offset;\r
+       byte *data = bmp->plane[0];\r
        word bmpOffset = (word) data + ry * bmp->width + rx;\r
-       word width = rw/4;\r
-       word height = rh/4;\r
+       word width = rw;\r
+       word height = rh;\r
        byte plane = 1 << ((byte) x & 0x03);\r
        word scanCount = width/4 + (width%4 ? 1 :0);\r
        word nextPageRow = page->width/4 - scanCount;\r
@@ -319,7 +321,17 @@ modexDrawBmpPBufRegion(page_t *page, int x, int y,
        ROW_LOOP:\r
                MOV CX, width      ; count the columns\r
        SCAN_LOOP:\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
                MOVSB              ; copy the pixel\r
+\r
                SUB CX, 3              ; we skip the next 3\r
                ADD SI, 3              ; skip the bmp pixels\r
                LOOP SCAN_LOOP    ; finish the scan\r
@@ -332,6 +344,7 @@ modexDrawBmpPBufRegion(page_t *page, int x, int y,
                DEC rowCounter\r
                JNZ ROW_LOOP        ; do all the rows\r
                ;-- end plane painting\r
+\r
                MOV AL, plane      ; advance to the next plane\r
                SHL AL, 1              ;\r
                AND AL, 0x0f        ; mask the plane properly\r
@@ -354,10 +367,10 @@ void
 modexDrawSpritePBufRegion(page_t *page, int x, int y,\r
                      int rx, int ry, int rw, int rh, planar_buf_t *bmp) {\r
        word poffset = (word)page->data + y*(page->width/4) + x/4;\r
-       byte *data = *bmp->plane;//+bmp->offset;\r
+       byte *data = bmp->plane[0];\r
        word bmpOffset = (word) data + ry * bmp->width + rx;\r
-       word width = rw/4;\r
-       word height = rh/4;\r
+       word width = rw;\r
+       word height = rh;\r
        byte plane = 1 << ((byte) x & 0x03);\r
        word scanCount = width/4 + (width%4 ? 1 :0);\r
        word nextPageRow = page->width/4 - scanCount;\r
@@ -421,3 +434,40 @@ modexDrawSpritePBufRegion(page_t *page, int x, int y,
                JNZ PLANE_LOOP    ; do all 4 planes\r
     }\r
 }\r
+\r
+void modexDrawChar(page_t *page, int x/*for planar selection only*/, word t, word col, word bgcol, word addr)\r
+{\r
+       /* vertical drawing routine by joncampbell123.\r
+        *\r
+        * optimize for VGA mode X planar memory to minimize the number of times we do I/O write to map mask register.\r
+        * so, we enumerate over columns (not rows!) to draw every 4th pixel. bit masks are used because of the font bitmap.\r
+        *\r
+        * NTS: addr defines what VGA memory address we use, "x" is redundant except to specify which of the 4 pixels we select in the map mask register. */\r
+       word rows = romFonts[t].charSize;\r
+       word drawaddr;\r
+       word colm, row;\r
+       byte fontbyte;\r
+       byte plane;\r
+       byte m1,m2;\r
+\r
+       plane = x & 3;\r
+       m1 = 0x80; // left half\r
+       m2 = 0x08; // right half\r
+       for (colm=0;colm < 4;colm++) {\r
+               drawaddr = addr;\r
+               modexSelectPlane(PLANE(plane));\r
+               for (row=0;row < rows;row++) {\r
+                       fontbyte = romFontsData.l[row];\r
+                       vga_state.vga_graphics_ram[drawaddr  ] = (fontbyte & m1) ? col : bgcol;\r
+                       vga_state.vga_graphics_ram[drawaddr+1] = (fontbyte & m2) ? col : bgcol;\r
+                       drawaddr += page->width >> 2;\r
+               }\r
+\r
+               m1 >>= 1;\r
+               m2 >>= 1;\r
+               if ((++plane) == 4) {\r
+                       addr++;\r
+                       plane = 0;\r
+               }\r
+       }\r
+}\r