OSDN Git Service

got pcxtest.exe to compile and work
authorsparky4 <sparky4@cock.li>
Thu, 10 Nov 2022 21:53:13 +0000 (15:53 -0600)
committersparky4 <sparky4@cock.li>
Thu, 10 Nov 2022 21:53:13 +0000 (15:53 -0600)
14 files changed:
16/modex16/16render.c [new file with mode: 0755]
16/modex16/16render.h [new file with mode: 0755]
16/modex16/modex16.h
bcexmm.dsk
bcexmm.exe
bcexmm.prj
data/maryai.pcx [new file with mode: 0755]
makefile
src/lib/16_tdef.h
src/lib/16_vl.c
src/lib/16_vl.h
src/pcxtest.c
src/pcxtest2.c
src/scroll.c

diff --git a/16/modex16/16render.c b/16/modex16/16render.c
new file mode 100755 (executable)
index 0000000..6d78f25
--- /dev/null
@@ -0,0 +1,436 @@
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2017 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
+ * 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
+ *\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
+ * Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ */\r
+/*\r
+ * Render data code~\r
+ */\r
+\r
+#include "16/modex16/16render.h"\r
+\r
+//TODO! ADD CLIPPING!!\r
+//memory management needs to be added\r
+//void\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
+       word plane;\r
+       int i;\r
+       const int px=x+page[0].dx;\r
+       const int py=y+page[0].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+prh;\r
+               modexSelectPlane(PLANE(plane-1));\r
+               for(; y < py+rh; y++) {\r
+                               _fmemcpy(page->data + (((page->width/4) * (y)) + ((x) / 4)), &(p->plane[plane][i]), prw);\r
+                               i+=PE;\r
+               }\r
+               x=px;\r
+               y=py;\r
+       }\r
+}\r
+\r
+\r
+/*temp*/\r
+void\r
+modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite)\r
+{\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[0].dx;\r
+       const int py=y+page[0].dy;\r
+       x=px;\r
+       y=py;\r
+//     buff = _nmalloc(p->pwidth+1);\r
+       // TODO Make this fast.  It's SLOOOOOOW\r
+//     for(plane=0; plane < 4; plane++) {\r
+//             i=0;\r
+//             modexSelectPlane(PLANE(plane+x));\r
+//             for(px = plane; px < p->width; px+=4) {\r
+//                     offset=px;\r
+//                     for(py=0; py<p->height/2; py++) {\r
+//                             //SELECT_ALL_PLANES();\r
+//                             if(!sprite || p->plane[offset])\r
+//                                     page->data = &(p->plane[offset][i++]);\r
+//                             offset+=p->width;\r
+//                             offset++;\r
+//                     }\r
+//             }\r
+//     }\r
+       for(plane=0; plane < 4; plane++) {\r
+               i=0;\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[0].dy)) + ((x+page[0].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
+}\r
+\r
+void\r
+oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite)\r
+{\r
+       byte plane;\r
+       word px, py;\r
+       word offset;\r
+\r
+       /* TODO Make this fast.  It's SLOOOOOOW */\r
+       for(plane=0; plane < 4; plane++) {\r
+               modexSelectPlane(PLANE(plane+x));\r
+               for(px = plane; px < bmp->width; px+=4) {\r
+                       offset=px;\r
+                       for(py=0; py<bmp->height; py++) {\r
+                       if(!sprite || bmp->data[offset])\r
+                               page[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset];\r
+                       offset+=bmp->width;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+//* normal versions *//\r
+void\r
+modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) {\r
+    /* draw the region (the entire freakin bitmap) */\r
+    modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
+}\r
+\r
+void\r
+modexDrawBmpRegion(page_t *page, int x, int y,\r
+                  int rx, int ry, int rw, int rh, bitmap_t *bmp) {\r
+       word poffset = (word)page->data + y*(page->width/4) + x/4;\r
+       byte *data = bmp->data;//+bmp->offset;\r
+       word bmpOffset = (word) data + ry * bmp->width + rx;\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
+       word nextBmpRow = (word) bmp->width - width;\r
+       word rowCounter=0;\r
+       byte planeCounter = 4;\r
+\r
+    __asm {\r
+               MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+               MOV ES, AX\r
+\r
+               MOV DX, SC_INDEX        ; point at the map mask register\r
+               MOV AL, SC_MAPMASK      ;\r
+               OUT DX, AL            ;\r
+\r
+       PLANE_LOOP:\r
+               MOV DX, SC_DATA  ; select the current plane\r
+               MOV AL, plane      ;\r
+               OUT DX, AL            ;\r
+\r
+               ;-- begin plane painting\r
+               MOV AX, height    ; start the row counter\r
+               MOV rowCounter, AX      ;\r
+               MOV DI, poffset  ; go to the first pixel\r
+               MOV SI, bmpOffset       ; go to the bmp pixel\r
+       ROW_LOOP:\r
+               MOV CX, width      ; count the columns\r
+       SCAN_LOOP:\r
+               MOVSB              ; copy the pixel\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
+\r
+               MOV AX, nextPageRow\r
+               ADD DI, AX            ; go to the next row on screen\r
+               MOV AX, nextBmpRow\r
+               ADD SI, AX            ; go to the next row on bmp\r
+\r
+               DEC rowCounter\r
+               JNZ ROW_LOOP        ; do all the rows\r
+               ;-- end plane painting\r
+               MOV AL, plane      ; advance to the next plane\r
+               SHL AL, 1              ;\r
+               AND AL, 0x0f        ; mask the plane properly\r
+               MOV plane, AL      ; store the plane\r
+\r
+               INC bmpOffset      ; start bmp at the right spot\r
+\r
+               DEC planeCounter\r
+               JNZ PLANE_LOOP    ; do all 4 planes\r
+    }\r
+}\r
+\r
+void\r
+modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) {\r
+    /* draw the whole sprite */\r
+    modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
+}\r
+\r
+void\r
+modexDrawSpriteRegion(page_t *page, int x, int y,\r
+                     int rx, int ry, int rw, int rh, bitmap_t *bmp) {\r
+       word poffset = (word)page->data + y*(page->width/4) + x/4;\r
+       byte *data = bmp->data;//+bmp->offset;\r
+       word bmpOffset = (word) data + ry * bmp->width + rx;\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
+       word nextBmpRow = (word) bmp->width - width;\r
+       word rowCounter=0;\r
+       byte planeCounter = 4;\r
+\r
+    __asm {\r
+               MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+               MOV ES, AX\r
+\r
+               MOV DX, SC_INDEX        ; point at the map mask register\r
+               MOV AL, SC_MAPMASK      ;\r
+               OUT DX, AL            ;\r
+\r
+       PLANE_LOOP:\r
+               MOV DX, SC_DATA  ; select the current plane\r
+               MOV AL, plane      ;\r
+               OUT DX, AL            ;\r
+\r
+               ;-- begin plane painting\r
+               MOV AX, height    ; start the row counter\r
+               MOV rowCounter, AX      ;\r
+               MOV DI, poffset  ; go to the first pixel\r
+               MOV SI, bmpOffset       ; go to the bmp pixel\r
+       ROW_LOOP:\r
+               MOV CX, width      ; count the columns\r
+       SCAN_LOOP:\r
+               LODSB\r
+               DEC SI\r
+               CMP AL, 0\r
+               JNE DRAW_PIXEL    ; draw non-zero pixels\r
+\r
+               INC DI            ; skip the transparent pixel\r
+               ADD SI, 1\r
+               JMP NEXT_PIXEL\r
+       DRAW_PIXEL:\r
+               MOVSB              ; copy the pixel\r
+       NEXT_PIXEL:\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
+\r
+               MOV AX, nextPageRow\r
+               ADD DI, AX            ; go to the next row on screen\r
+               MOV AX, nextBmpRow\r
+               ADD SI, AX            ; go to the next row on bmp\r
+\r
+               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
+               MOV plane, AL      ; store the plane\r
+\r
+               INC bmpOffset      ; start bmp at the right spot\r
+\r
+               DEC planeCounter\r
+               JNZ PLANE_LOOP    ; do all 4 planes\r
+    }\r
+}\r
+\r
+//* planar buffer versions *//\r
+void\r
+modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp) {\r
+    /* draw the region (the entire freakin bitmap) */\r
+    modexDrawBmpPBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
+}\r
+\r
+void\r
+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 = (byte *)bmp->plane[0];\r
+       word bmpOffset = (word) data + ry * bmp->width + rx;\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
+       word nextBmpRow = (word) bmp->width - width;\r
+       word rowCounter=0;\r
+       byte planeCounter = 4;\r
+\r
+    __asm {\r
+               MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+               MOV ES, AX\r
+\r
+               MOV DX, SC_INDEX        ; point at the map mask register\r
+               MOV AL, SC_MAPMASK      ;\r
+               OUT DX, AL            ;\r
+\r
+       PLANE_LOOP:\r
+               MOV DX, SC_DATA  ; select the current plane\r
+               MOV AL, plane      ;\r
+               OUT DX, AL            ;\r
+\r
+               ;-- begin plane painting\r
+               MOV AX, height    ; start the row counter\r
+               MOV rowCounter, AX      ;\r
+               MOV DI, poffset  ; go to the first pixel\r
+               MOV SI, bmpOffset       ; go to the bmp pixel\r
+       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
+\r
+               MOV AX, nextPageRow\r
+               ADD DI, AX            ; go to the next row on screen\r
+               MOV AX, nextBmpRow\r
+               ADD SI, AX            ; go to the next row on bmp\r
+\r
+               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
+               MOV plane, AL      ; store the plane\r
+\r
+               INC bmpOffset      ; start bmp at the right spot\r
+\r
+               DEC planeCounter\r
+               JNZ PLANE_LOOP    ; do all 4 planes\r
+    }\r
+}\r
+\r
+void\r
+modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp) {\r
+    /* draw the whole sprite */\r
+    modexDrawSpritePBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
+}\r
+\r
+void\r
+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 = (byte *)bmp->plane[0];\r
+       word bmpOffset = (word) data + ry * bmp->width + rx;\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
+       word nextBmpRow = (word) bmp->width - width;\r
+       word rowCounter=0;\r
+       byte planeCounter = 4;\r
+\r
+    __asm {\r
+               MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+               MOV ES, AX\r
+\r
+               MOV DX, SC_INDEX        ; point at the map mask register\r
+               MOV AL, SC_MAPMASK      ;\r
+               OUT DX, AL            ;\r
+\r
+       PLANE_LOOP:\r
+               MOV DX, SC_DATA  ; select the current plane\r
+               MOV AL, plane      ;\r
+               OUT DX, AL            ;\r
+\r
+               ;-- begin plane painting\r
+               MOV AX, height    ; start the row counter\r
+               MOV rowCounter, AX      ;\r
+               MOV DI, poffset  ; go to the first pixel\r
+               MOV SI, bmpOffset       ; go to the bmp pixel\r
+       ROW_LOOP:\r
+               MOV CX, width      ; count the columns\r
+       SCAN_LOOP:\r
+               LODSB\r
+               DEC SI\r
+               CMP AL, 0\r
+               JNE DRAW_PIXEL    ; draw non-zero pixels\r
+\r
+               INC DI            ; skip the transparent pixel\r
+               ADD SI, 1\r
+               JMP NEXT_PIXEL\r
+       DRAW_PIXEL:\r
+               MOVSB              ; copy the pixel\r
+       NEXT_PIXEL:\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
+\r
+               MOV AX, nextPageRow\r
+               ADD DI, AX            ; go to the next row on screen\r
+               MOV AX, nextBmpRow\r
+               ADD SI, AX            ; go to the next row on bmp\r
+\r
+               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
+               MOV plane, AL      ; store the plane\r
+\r
+               INC bmpOffset      ; start bmp at the right spot\r
+\r
+               DEC planeCounter\r
+               JNZ PLANE_LOOP    ; do all 4 planes\r
+    }\r
+}\r
diff --git a/16/modex16/16render.h b/16/modex16/16render.h
new file mode 100755 (executable)
index 0000000..269caf8
--- /dev/null
@@ -0,0 +1,46 @@
+/* Project 16 Source Code~\r
+ * Copyright (C) 2012-2017 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
+ * 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
+ *\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
+ * Fifth Floor, Boston, MA 02110-1301 USA.\r
+ *\r
+ */\r
+\r
+#ifndef __RENDER_H__\r
+#define __RENDER_H__\r
+\r
+//#include "16/src/lib/omodex16.h"\r
+//#include "16/modex16/modex16.h"\r
+#include "src/lib/16_vl.h"\r
+\r
+#ifndef SC_MAPMASK\r
+#define SC_MAPMASK     2\r
+#endif\r
+\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
+void modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite); /*temp*/\r
+void oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite);\r
+void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp);\r
+void modexDrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);\r
+void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp);\r
+void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);\r
+void modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp); /*pbuf version*/\r
+void modexDrawBmpPBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *bmp);\r
+void modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp);\r
+void modexDrawSpritePBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *bmp);\r
+\r
+#endif\r
index 5ce666d..ff4913f 100755 (executable)
@@ -12,6 +12,8 @@
 #define PLANE(x) (1<< (x&3))\r
 #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02)\r
 \r
+#ifndef PAGET\r
+#define PAGET\r
 typedef struct {\r
     byte far* data;    /* the data for the page */\r
     word dx;           /* col we are viewing on the virtual screen */\r
@@ -19,6 +21,7 @@ typedef struct {
     word width;                /* virtual width of the page */\r
     word height;       /* virtual height of the page */\r
 } page_t;\r
+#endif\r
 \r
 /* -============================ Functions =============================- */\r
 /* mode switching, page, and plane functions */\r
index 51df3d2..7d4ebdb 100755 (executable)
Binary files a/bcexmm.dsk and b/bcexmm.dsk differ
index d2eb4e5..6be78dd 100755 (executable)
Binary files a/bcexmm.exe and b/bcexmm.exe differ
index 0d24405..30f77af 100755 (executable)
Binary files a/bcexmm.prj and b/bcexmm.prj differ
diff --git a/data/maryai.pcx b/data/maryai.pcx
new file mode 100755 (executable)
index 0000000..dfc4ade
Binary files /dev/null and b/data/maryai.pcx differ
index 929fd8e..b7c3b5c 100755 (executable)
--- a/makefile
+++ b/makefile
@@ -306,7 +306,7 @@ vrstest.exe:        vrstest.$(OBJ) $(16LIB) gfx.lib $(DOSLIB)
 palettec.exe:  palettec.$(OBJ) $(16LIB) gfx.lib $(DOSLIB)
 palettel.exe:          palettel.$(OBJ) $(16LIB) gfx.lib $(DOSLIB)
 palbomb.exe:   palbomb.$(OBJ) $(16LIB) gfx.lib $(DOSLIB)
-pcxtest2.exe:  pcxtest2.$(OBJ) gfx.lib $(DOSLIB)
+pcxtest2.exe:  pcxtest2.$(OBJ) gfx.lib $(DOSLIB) $(16LIB)
 #planrpcx.exe: planrpcx.$(OBJ) gfx.lib
 maptest.exe:   maptest.$(OBJ) 16_map.$(OBJ) 16_head.$(OBJ) gfx.lib $(DOSLIB) $(16LIB)
 fmemtest.exe:  fmemtest.$(OBJ)
index 083f2fc..75ff0f2 100755 (executable)
@@ -207,6 +207,8 @@ typedef struct{
        sword tileplayerposscreeny;     /* player position on screen */ /* needed for scroll and map system to work accordingly */\r
 } pagetileinfo_t;\r
 \r
+#ifndef PAGET\r
+#define PAGET\r
 typedef struct {\r
        nibble/*word*/ id;      /* the Identification number of the page~ For layering~ */\r
        byte far* data; /* the data for the page */\r
@@ -225,6 +227,7 @@ typedef struct {
 //TODO: find where they are used\r
        sword delta;                    // How much should we shift the page for smooth scrolling\r
 } page_t;\r
+#endif\r
 \r
 //from 16_in\r
 //==========================================================================\r
index df741a2..1207c84 100755 (executable)
@@ -880,10 +880,10 @@ void modexPalSave(byte *palette)
 }\r
 \r
 \r
-/*byte *\r
+byte *\r
 modexNewPal() {\r
        byte *ptr;\r
-       ptr = mAlloc(PAL_SIZE);\r
+       ptr = malloc(PAL_SIZE);\r
 \r
        // handle errors\r
        if(!ptr) {\r
@@ -891,7 +891,71 @@ modexNewPal() {
        }\r
 \r
        return ptr;\r
-}*/\r
+}\r
+\r
+static struct pcxHeader {\r
+    byte id;\r
+    byte version;\r
+    byte encoding;\r
+    byte bpp;\r
+    word xmin;\r
+    word ymin;\r
+    word xmax;\r
+    word ymax;\r
+    word hres;\r
+    word vres;\r
+    byte pal16[48];\r
+    byte res1;\r
+    word bpplane;\r
+    word palType;\r
+    word hScreenSize;\r
+    word vScreenSize;\r
+    byte padding[54];\r
+} head;\r
+\r
+\r
+static void loadPcxStage1(FILE *file, bitmap_t *result) {\r
+    long bufSize;\r
+    int index;\r
+    byte count, val;\r
+    long int pos;\r
+\r
+    /* read the header */\r
+    fread(&head, sizeof(char), sizeof(struct pcxHeader), file);\r
+\r
+    /* get the width and height */\r
+    result->width = head.xmax - head.xmin + 1;\r
+    result->height = head.ymax - head.ymin + 1;\r
+\r
+    /* make sure this  is 8bpp */\r
+    if(head.bpp != 8) {\r
+       printf("I only know how to handle 8bpp pcx files!\n");\r
+       fclose(file);\r
+       exit(-2);\r
+    }\r
+}\r
+\r
+void loadPcxPalette(FILE *file, bitmap_t *result) {\r
+    byte val;\r
+    int index;\r
+\r
+    /* handle the palette */\r
+    fseek(file, -769, SEEK_END);\r
+    val = fgetc(file);\r
+    result->palette = modexNewPal();\r
+    if(head.version == 5 && val == 12) {\r
+       /* use the vga palette */\r
+       for(index=0; !feof(file) && index < PAL_SIZE; index++) {\r
+           val = fgetc(file);\r
+           result->palette[index] = val >> 2;\r
+       }\r
+    } else {\r
+       /* use the 16 color palette */\r
+       for(index=0; index<48; index++) {\r
+           result->palette[index]  = head.pal16[index];\r
+       }\r
+    }\r
+}\r
 \r
 \r
 void\r
@@ -920,6 +984,422 @@ modexLoadPalFile(byte *filename, byte *palette) {
        fclose(file);\r
 }\r
 \r
+bitmap_t\r
+bitmapLoadPcx(char *filename) {\r
+    FILE *file;\r
+    bitmap_t result;\r
+    long bufSize;\r
+    int index;\r
+    byte count, val;\r
+\r
+    /* open the PCX file for reading */\r
+    file = fopen(filename, "rb");\r
+    if(!file) {\r
+       printf("Could not open %s for reading.\n", filename);\r
+       exit(-2);\r
+    }\r
+\r
+    /* load the first part of the pcx file */\r
+    loadPcxStage1(file, &result);\r
+\r
+    /* allocate the buffer */\r
+    bufSize = result.width * result.height;\r
+    result.data = malloc(bufSize);\r
+    if(!result.data) {\r
+       printf("Could not allocate memory for bitmap data.");\r
+       fclose(file);\r
+       exit(-1);\r
+    }\r
+\r
+    /*  read the buffer in */\r
+    index = 0;\r
+    do {\r
+       /* get the run length and the value */\r
+       count = fgetc(file);\r
+       if(0xC0 ==  (count & 0xC0)) { /* this is the run count */\r
+           count &= 0x3f;\r
+           val = fgetc(file);\r
+       } else {\r
+           val = count;\r
+           count = 1;\r
+       }\r
+\r
+       /* write the pixel the specified number of times */\r
+       for(; count && index < bufSize; count--,index++)  {\r
+           result.data[index] = val;\r
+       }\r
+    } while(index < bufSize);\r
+\r
+    loadPcxPalette(file, &result);\r
+\r
+    fclose(file);\r
+\r
+    return result;\r
+}\r
+\r
+\r
+tileset_t\r
+bitmapLoadPcxTiles(char *filename, word twidth, word theight) {\r
+    tileset_t ts;\r
+    FILE *file;\r
+    bitmap_t result;\r
+    int i;\r
+\r
+    /* open the PCX file for reading */\r
+    file = fopen(filename, "rb");\r
+    if(!file) {\r
+       printf("Could not open %s for reading.\n", filename);\r
+       exit(-2);\r
+    }\r
+\r
+    /* load the first part of the pcx file */\r
+    loadPcxStage1(file, &result);\r
+\r
+    /* get the number of tiles and set up the result structure */\r
+    ts.twidth = twidth;\r
+    ts.theight = theight;\r
+    ts.ntiles = (result.width/twidth) * (result.height/theight);\r
+    ts.palette = result.palette;\r
+\r
+    /* allocate the pixel storage for the tiles */\r
+    ts.data = malloc(sizeof(byte*) * ts.ntiles);\r
+    ts.data[0] = malloc(sizeof(byte) * ts.ntiles * twidth * theight);\r
+    for(i=1; i < ts.ntiles; i++) {\r
+       ts.data[i] = ts.data[i-1] + twidth * theight;\r
+    }\r
+\r
+    /* finish off the file */\r
+    loadPcxPalette(file, &result);\r
+\r
+    fclose(file);\r
+\r
+    return ts;\r
+}\r
+\r
+void\r
+oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite)\r
+{\r
+       byte plane;\r
+       word px, py;\r
+       word offset;\r
+\r
+       /* TODO Make this fast.  It's SLOOOOOOW */\r
+       for(plane=0; plane < 4; plane++) {\r
+               modexSelectPlane(PLANE(plane+x));\r
+               for(px = plane; px < bmp->width; px+=4) {\r
+                       offset=px;\r
+                       for(py=0; py<bmp->height; py++) {\r
+                       if(!sprite || bmp->data[offset])\r
+                               page[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset];\r
+                       offset+=bmp->width;\r
+                       }\r
+               }\r
+       }\r
+}\r
+\r
+//* normal versions *//\r
+void\r
+modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) {\r
+    /* draw the region (the entire freakin bitmap) */\r
+    modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
+}\r
+\r
+void\r
+modexDrawBmpRegion(page_t *page, int x, int y,\r
+                  int rx, int ry, int rw, int rh, bitmap_t *bmp) {\r
+       word poffset = (word)page->data + y*(page->width/4) + x/4;\r
+       byte *data = bmp->data;//+bmp->offset;\r
+       word bmpOffset = (word) data + ry * bmp->width + rx;\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
+       word nextBmpRow = (word) bmp->width - width;\r
+       word rowCounter=0;\r
+       byte planeCounter = 4;\r
+\r
+    __asm {\r
+               MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+               MOV ES, AX\r
+\r
+               MOV DX, SC_INDEX        ; point at the map mask register\r
+               MOV AL, SC_MAPMASK      ;\r
+               OUT DX, AL            ;\r
+\r
+       PLANE_LOOP:\r
+               MOV DX, SC_DATA  ; select the current plane\r
+               MOV AL, plane      ;\r
+               OUT DX, AL            ;\r
+\r
+               ;-- begin plane painting\r
+               MOV AX, height    ; start the row counter\r
+               MOV rowCounter, AX      ;\r
+               MOV DI, poffset  ; go to the first pixel\r
+               MOV SI, bmpOffset       ; go to the bmp pixel\r
+       ROW_LOOP:\r
+               MOV CX, width      ; count the columns\r
+       SCAN_LOOP:\r
+               MOVSB              ; copy the pixel\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
+\r
+               MOV AX, nextPageRow\r
+               ADD DI, AX            ; go to the next row on screen\r
+               MOV AX, nextBmpRow\r
+               ADD SI, AX            ; go to the next row on bmp\r
+\r
+               DEC rowCounter\r
+               JNZ ROW_LOOP        ; do all the rows\r
+               ;-- end plane painting\r
+               MOV AL, plane      ; advance to the next plane\r
+               SHL AL, 1              ;\r
+               AND AL, 0x0f        ; mask the plane properly\r
+               MOV plane, AL      ; store the plane\r
+\r
+               INC bmpOffset      ; start bmp at the right spot\r
+\r
+               DEC planeCounter\r
+               JNZ PLANE_LOOP    ; do all 4 planes\r
+    }\r
+}\r
+\r
+void\r
+modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) {\r
+    /* draw the whole sprite */\r
+    modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
+}\r
+\r
+void\r
+modexDrawSpriteRegion(page_t *page, int x, int y,\r
+                     int rx, int ry, int rw, int rh, bitmap_t *bmp) {\r
+       word poffset = (word)page->data + y*(page->width/4) + x/4;\r
+       byte *data = bmp->data;//+bmp->offset;\r
+       word bmpOffset = (word) data + ry * bmp->width + rx;\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
+       word nextBmpRow = (word) bmp->width - width;\r
+       word rowCounter=0;\r
+       byte planeCounter = 4;\r
+\r
+    __asm {\r
+               MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+               MOV ES, AX\r
+\r
+               MOV DX, SC_INDEX        ; point at the map mask register\r
+               MOV AL, SC_MAPMASK      ;\r
+               OUT DX, AL            ;\r
+\r
+       PLANE_LOOP:\r
+               MOV DX, SC_DATA  ; select the current plane\r
+               MOV AL, plane      ;\r
+               OUT DX, AL            ;\r
+\r
+               ;-- begin plane painting\r
+               MOV AX, height    ; start the row counter\r
+               MOV rowCounter, AX      ;\r
+               MOV DI, poffset  ; go to the first pixel\r
+               MOV SI, bmpOffset       ; go to the bmp pixel\r
+       ROW_LOOP:\r
+               MOV CX, width      ; count the columns\r
+       SCAN_LOOP:\r
+               LODSB\r
+               DEC SI\r
+               CMP AL, 0\r
+               JNE DRAW_PIXEL    ; draw non-zero pixels\r
+\r
+               INC DI            ; skip the transparent pixel\r
+               ADD SI, 1\r
+               JMP NEXT_PIXEL\r
+       DRAW_PIXEL:\r
+               MOVSB              ; copy the pixel\r
+       NEXT_PIXEL:\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
+\r
+               MOV AX, nextPageRow\r
+               ADD DI, AX            ; go to the next row on screen\r
+               MOV AX, nextBmpRow\r
+               ADD SI, AX            ; go to the next row on bmp\r
+\r
+               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
+               MOV plane, AL      ; store the plane\r
+\r
+               INC bmpOffset      ; start bmp at the right spot\r
+\r
+               DEC planeCounter\r
+               JNZ PLANE_LOOP    ; do all 4 planes\r
+    }\r
+}\r
+\r
+//* planar buffer versions *//\r
+void\r
+modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp) {\r
+    /* draw the region (the entire freakin bitmap) */\r
+    modexDrawBmpPBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
+}\r
+\r
+void\r
+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 = (byte *)bmp->plane[0];\r
+       word bmpOffset = (word) data + ry * bmp->width + rx;\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
+       word nextBmpRow = (word) bmp->width - width;\r
+       word rowCounter=0;\r
+       byte planeCounter = 4;\r
+\r
+    __asm {\r
+               MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+               MOV ES, AX\r
+\r
+               MOV DX, SC_INDEX        ; point at the map mask register\r
+               MOV AL, SC_MAPMASK      ;\r
+               OUT DX, AL            ;\r
+\r
+       PLANE_LOOP:\r
+               MOV DX, SC_DATA  ; select the current plane\r
+               MOV AL, plane      ;\r
+               OUT DX, AL            ;\r
+\r
+               ;-- begin plane painting\r
+               MOV AX, height    ; start the row counter\r
+               MOV rowCounter, AX      ;\r
+               MOV DI, poffset  ; go to the first pixel\r
+               MOV SI, bmpOffset       ; go to the bmp pixel\r
+       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
+\r
+               MOV AX, nextPageRow\r
+               ADD DI, AX            ; go to the next row on screen\r
+               MOV AX, nextBmpRow\r
+               ADD SI, AX            ; go to the next row on bmp\r
+\r
+               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
+               MOV plane, AL      ; store the plane\r
+\r
+               INC bmpOffset      ; start bmp at the right spot\r
+\r
+               DEC planeCounter\r
+               JNZ PLANE_LOOP    ; do all 4 planes\r
+    }\r
+}\r
+\r
+void\r
+modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp) {\r
+    /* draw the whole sprite */\r
+    modexDrawSpritePBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp);\r
+}\r
+\r
+void\r
+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 = (byte *)bmp->plane[0];\r
+       word bmpOffset = (word) data + ry * bmp->width + rx;\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
+       word nextBmpRow = (word) bmp->width - width;\r
+       word rowCounter=0;\r
+       byte planeCounter = 4;\r
+\r
+    __asm {\r
+               MOV AX, SCREEN_SEG      ; go to the VGA memory\r
+               MOV ES, AX\r
+\r
+               MOV DX, SC_INDEX        ; point at the map mask register\r
+               MOV AL, SC_MAPMASK      ;\r
+               OUT DX, AL            ;\r
+\r
+       PLANE_LOOP:\r
+               MOV DX, SC_DATA  ; select the current plane\r
+               MOV AL, plane      ;\r
+               OUT DX, AL            ;\r
+\r
+               ;-- begin plane painting\r
+               MOV AX, height    ; start the row counter\r
+               MOV rowCounter, AX      ;\r
+               MOV DI, poffset  ; go to the first pixel\r
+               MOV SI, bmpOffset       ; go to the bmp pixel\r
+       ROW_LOOP:\r
+               MOV CX, width      ; count the columns\r
+       SCAN_LOOP:\r
+               LODSB\r
+               DEC SI\r
+               CMP AL, 0\r
+               JNE DRAW_PIXEL    ; draw non-zero pixels\r
+\r
+               INC DI            ; skip the transparent pixel\r
+               ADD SI, 1\r
+               JMP NEXT_PIXEL\r
+       DRAW_PIXEL:\r
+               MOVSB              ; copy the pixel\r
+       NEXT_PIXEL:\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
+\r
+               MOV AX, nextPageRow\r
+               ADD DI, AX            ; go to the next row on screen\r
+               MOV AX, nextBmpRow\r
+               ADD SI, AX            ; go to the next row on bmp\r
+\r
+               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
+               MOV plane, AL      ; store the plane\r
+\r
+               INC bmpOffset      ; start bmp at the right spot\r
+\r
+               DEC planeCounter\r
+               JNZ PLANE_LOOP    ; do all 4 planes\r
+    }\r
+}\r
+\r
 #define COREPALSIZE 9//27      //3*9\r
 \r
 void VLL_LoadPalFilewithoffset(const char *filename, byte *palette, word o, word palsize, global_game_variables_t *gvar)\r
index 2390cf8..0612a9b 100755 (executable)
@@ -204,8 +204,21 @@ void modexFlashOff(word fade, byte *palette);
 /* palette loading and saving */\r
 void VL_SetPalette (byte far *palette, video_t *v);\r
 void modexPalSave(byte *palette);\r
-//byte *modexNewPal();\r
+byte *modexNewPal();\r
 void modexLoadPalFile(char *filename, byte *palette);\r
+static void loadPcxStage1(FILE *file, bitmap_t *result);\r
+void loadPcxPalette(FILE *file, bitmap_t *result);\r
+bitmap_t bitmapLoadPcx(char *filename);\r
+tileset_t bitmapLoadPcxTiles(char *filename, word twidth, word theight);\r
+void oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite);\r
+void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp);\r
+void modexDrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);\r
+void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp);\r
+void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp);\r
+void modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp); /*pbuf version*/\r
+void modexDrawBmpPBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *bmp);\r
+void modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp);\r
+void modexDrawSpritePBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *bmp);\r
 void VL_LoadPalFile(const char *filename, byte *palette, global_game_variables_t *gvar);\r
 void VL_LoadPalFileCore(byte *palette, global_game_variables_t *gvar);\r
 void VL_SetCorePal(global_game_variables_t *gvar);\r
index a29c617..1c3aa9c 100755 (executable)
@@ -24,8 +24,8 @@
 #include <dos.h>\r
 #include <string.h>\r
 #include "src/lib/16_vl.h"\r
-#include "16/src/lib/bitmap.h"\r
-#include "16/src/lib/16render.h"\r
+//#include "16/modex16/bitmap.h"\r
+//#include "16/modex16/16render.h"\r
 #include "src/lib/16_in.h"\r
 \r
 #include "src/lib/16_tail.h"\r
@@ -64,7 +64,8 @@ void main() {
        }\r
 \r
 //0000 PCXBMP = bitmapLoadPcx("data/koishi~~.pcx");\r
-       PCXBMP = bitmapLoadPcx("data/chikyuu.pcx", &gvar);\r
+//0000 PCXBMP = bitmapLoadPcx("data/chikyuu.pcx"/*, &gvar*/);\r
+       PCXBMP = bitmapLoadPcx("data/maryai.pcx");\r
 //     PCXBMP = bitmapLoadPcx("data/koishi^^.pcx");\r
 //     PCXBMP = bitmapLoadPcx("16/PCX_LIB/chikyuu.pcx");\r
 //---- p = planar_buf_from_bitmap(PCXBMPPTR);\r
index 5dd8505..dadb2c4 100755 (executable)
@@ -24,7 +24,7 @@
 #include <dos.h>\r
 #include <string.h>\r
 #include "src/lib/16_vl.h"\r
-#include "16/src/lib/bitmap.h"\r
+//#include "16/src/lib/bitmap.h"\r
 //----#include "src/lib/planar.h"\r
 \r
 static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */\r
@@ -85,7 +85,8 @@ void main() {
        }\r
 \r
 //0000 bmp = bitmapLoadPcx("data/koishi~~.pcx");\r
-       bmp = bitmapLoadPcx("data/chikyuu.pcx", &gvar);\r
+//0000 bmp = bitmapLoadPcx("data/chikyuu.pcx"/*, &gvar*/);\r
+       bmp = bitmapLoadPcx("data/maryai.pcx"/*, &gvar*/);\r
 //     bmp = bitmapLoadPcx("data/koishi^^.pcx");\r
 //     bmp = bitmapLoadPcx("16/PCX_LIB/chikyuu.pcx");\r
 //---- p = planar_buf_from_bitmap(&bmp);\r
index 10ef02f..4eb61a3 100755 (executable)
@@ -37,7 +37,7 @@ extern boolean pagenorendermap;
 unsigned int i;\r
 //#ifdef FADE\r
        static word paloffset=0;\r
-       byte *gvar.video.dpal;\r
+//--00 byte *gvar.video.dpal;\r
 //#endif\r
 //     byte *ptr;\r
        byte *mappalptr;\r