From: sparky4 Date: Thu, 10 Nov 2022 21:53:13 +0000 (-0600) Subject: got pcxtest.exe to compile and work X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=8a04643047887934be90690e6a1254b403b17fc9;p=16.git got pcxtest.exe to compile and work --- diff --git a/16/modex16/16render.c b/16/modex16/16render.c new file mode 100755 index 00000000..6d78f253 --- /dev/null +++ b/16/modex16/16render.c @@ -0,0 +1,436 @@ +/* Project 16 Source Code~ + * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover + * + * This file is part of Project 16. + * + * Project 16 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Project 16 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see , or + * write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301 USA. + * + */ +/* + * Render data code~ + */ + +#include "16/modex16/16render.h" + +//TODO! ADD CLIPPING!! +//memory management needs to be added +//void +//modexDrawBmpRegion (page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp) +void modexDrawPBufRegion (page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *p, boolean sprite) +{ + word plane; + int i; + const int px=x+page[0].dx; + const int py=y+page[0].dy; + const int prw = rw/4; + int prh; + + //fine tuning + rx+=1; + ry+=1; + + //^^; + #define PEEE rx-prw + #define PE (p->pwidth) + if(rhheight) prh = (PE*(ry-4)); + else if(rh==p->height) prh = (PE*(ry)); + y=py; + x=px; + //printf("%d,%d p(%d,%d) r(%d,%d) rwh(%d,%d)\n", x, y, px, py, rx, ry, rw, rh); + for(plane=0; plane < 4; plane++) { + i=PEEE+prh; + modexSelectPlane(PLANE(plane-1)); + for(; y < py+rh; y++) { + _fmemcpy(page->data + (((page->width/4) * (y)) + ((x) / 4)), &(p->plane[plane][i]), prw); + i+=PE; + } + x=px; + y=py; + } +} + + +/*temp*/ +void +modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite) +{ + modexDrawPBufRegion (page, x, x, 0, 0, p->width, p->height, p, sprite); + /* + sword plane; + int i; +// byte near *buff; + const int px=x+page[0].dx; + const int py=y+page[0].dy; + x=px; + y=py; +// buff = _nmalloc(p->pwidth+1); + // TODO Make this fast. It's SLOOOOOOW +// for(plane=0; plane < 4; plane++) { +// i=0; +// modexSelectPlane(PLANE(plane+x)); +// for(px = plane; px < p->width; px+=4) { +// offset=px; +// for(py=0; pyheight/2; py++) { +// //SELECT_ALL_PLANES(); +// if(!sprite || p->plane[offset]) +// page->data = &(p->plane[offset][i++]); +// offset+=p->width; +// offset++; +// } +// } +// } + for(plane=0; plane < 4; plane++) { + i=0; + modexSelectPlane(PLANE(plane-1)); + for(; y < py+p->height; y++) { + //for(px=0; px < p->width; px++) { + //printf("%02X ", (int) p->plane[plane][i++]); +// _fmemcpy(buff, &(p->plane[plane][i+=p->pwidth]), p->pwidth); +// printf("buff %u==%s\n", y, *buff); +// _fmemcpy(page->data + (((page->width/4) * (y+page[0].dy)) + ((x+page[0].dx) / 4)), buff, p->pwidth); + _fmemcpy(page->data + (((page->width/4) * y) + (x / 4)), &(p->plane[plane][i+=p->pwidth]), p->pwidth); + //} + } +//getch(); + x=px; + y=py; + } +// _nfree(buff);*/ +} + +void +oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite) +{ + byte plane; + word px, py; + word offset; + + /* TODO Make this fast. It's SLOOOOOOW */ + for(plane=0; plane < 4; plane++) { + modexSelectPlane(PLANE(plane+x)); + for(px = plane; px < bmp->width; px+=4) { + offset=px; + for(py=0; pyheight; py++) { + if(!sprite || bmp->data[offset]) + page[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset]; + offset+=bmp->width; + } + } + } +} + +//* normal versions *// +void +modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) { + /* draw the region (the entire freakin bitmap) */ + modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawBmpRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, bitmap_t *bmp) { + word poffset = (word)page->data + y*(page->width/4) + x/4; + byte *data = bmp->data;//+bmp->offset; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter=0; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, SC_MAPMASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + MOVSB ; copy the pixel + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} + +void +modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) { + /* draw the whole sprite */ + modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawSpriteRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, bitmap_t *bmp) { + word poffset = (word)page->data + y*(page->width/4) + x/4; + byte *data = bmp->data;//+bmp->offset; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter=0; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, SC_MAPMASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + LODSB + DEC SI + CMP AL, 0 + JNE DRAW_PIXEL ; draw non-zero pixels + + INC DI ; skip the transparent pixel + ADD SI, 1 + JMP NEXT_PIXEL + DRAW_PIXEL: + MOVSB ; copy the pixel + NEXT_PIXEL: + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} + +//* planar buffer versions *// +void +modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp) { + /* draw the region (the entire freakin bitmap) */ + modexDrawBmpPBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawBmpPBufRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, planar_buf_t *bmp) { + word poffset = (word) page->data + y*(page->width/4) + x/4; + byte *data = (byte *)bmp->plane[0]; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter=0; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, SC_MAPMASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + + + + + + + + + + MOVSB ; copy the pixel + + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} + +void +modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp) { + /* draw the whole sprite */ + modexDrawSpritePBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawSpritePBufRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, planar_buf_t *bmp) { + word poffset = (word)page->data + y*(page->width/4) + x/4; + byte *data = (byte *)bmp->plane[0]; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter=0; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, SC_MAPMASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + LODSB + DEC SI + CMP AL, 0 + JNE DRAW_PIXEL ; draw non-zero pixels + + INC DI ; skip the transparent pixel + ADD SI, 1 + JMP NEXT_PIXEL + DRAW_PIXEL: + MOVSB ; copy the pixel + NEXT_PIXEL: + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} diff --git a/16/modex16/16render.h b/16/modex16/16render.h new file mode 100755 index 00000000..269caf8f --- /dev/null +++ b/16/modex16/16render.h @@ -0,0 +1,46 @@ +/* Project 16 Source Code~ + * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover + * + * This file is part of Project 16. + * + * Project 16 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * Project 16 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see , or + * write to the Free Software Foundation, Inc., 51 Franklin Street, + * Fifth Floor, Boston, MA 02110-1301 USA. + * + */ + +#ifndef __RENDER_H__ +#define __RENDER_H__ + +//#include "16/src/lib/omodex16.h" +//#include "16/modex16/modex16.h" +#include "src/lib/16_vl.h" + +#ifndef SC_MAPMASK +#define SC_MAPMASK 2 +#endif + +void modexDrawPBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *p, boolean sprite); +void modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite); /*temp*/ +void oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite); +void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp); +void modexDrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp); +void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp); +void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp); +void modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp); /*pbuf version*/ +void modexDrawBmpPBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *bmp); +void modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp); +void modexDrawSpritePBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *bmp); + +#endif diff --git a/16/modex16/modex16.h b/16/modex16/modex16.h index 5ce666df..ff4913f6 100755 --- a/16/modex16/modex16.h +++ b/16/modex16/modex16.h @@ -12,6 +12,8 @@ #define PLANE(x) (1<< (x&3)) #define SELECT_ALL_PLANES() outpw(0x03c4, 0xff02) +#ifndef PAGET +#define PAGET typedef struct { byte far* data; /* the data for the page */ word dx; /* col we are viewing on the virtual screen */ @@ -19,6 +21,7 @@ typedef struct { word width; /* virtual width of the page */ word height; /* virtual height of the page */ } page_t; +#endif /* -============================ Functions =============================- */ /* mode switching, page, and plane functions */ diff --git a/bcexmm.dsk b/bcexmm.dsk index 51df3d27..7d4ebdbe 100755 Binary files a/bcexmm.dsk and b/bcexmm.dsk differ diff --git a/bcexmm.exe b/bcexmm.exe index d2eb4e5a..6be78ddc 100755 Binary files a/bcexmm.exe and b/bcexmm.exe differ diff --git a/bcexmm.prj b/bcexmm.prj index 0d244058..30f77aff 100755 Binary files a/bcexmm.prj and b/bcexmm.prj differ diff --git a/data/maryai.pcx b/data/maryai.pcx new file mode 100755 index 00000000..dfc4ade2 Binary files /dev/null and b/data/maryai.pcx differ diff --git a/makefile b/makefile index 929fd8e9..b7c3b5c5 100755 --- 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) diff --git a/src/lib/16_tdef.h b/src/lib/16_tdef.h index 083f2fc2..75ff0f24 100755 --- a/src/lib/16_tdef.h +++ b/src/lib/16_tdef.h @@ -207,6 +207,8 @@ typedef struct{ sword tileplayerposscreeny; /* player position on screen */ /* needed for scroll and map system to work accordingly */ } pagetileinfo_t; +#ifndef PAGET +#define PAGET typedef struct { nibble/*word*/ id; /* the Identification number of the page~ For layering~ */ byte far* data; /* the data for the page */ @@ -225,6 +227,7 @@ typedef struct { //TODO: find where they are used sword delta; // How much should we shift the page for smooth scrolling } page_t; +#endif //from 16_in //========================================================================== diff --git a/src/lib/16_vl.c b/src/lib/16_vl.c index df741a2b..1207c846 100755 --- a/src/lib/16_vl.c +++ b/src/lib/16_vl.c @@ -880,10 +880,10 @@ void modexPalSave(byte *palette) } -/*byte * +byte * modexNewPal() { byte *ptr; - ptr = mAlloc(PAL_SIZE); + ptr = malloc(PAL_SIZE); // handle errors if(!ptr) { @@ -891,7 +891,71 @@ modexNewPal() { } return ptr; -}*/ +} + +static struct pcxHeader { + byte id; + byte version; + byte encoding; + byte bpp; + word xmin; + word ymin; + word xmax; + word ymax; + word hres; + word vres; + byte pal16[48]; + byte res1; + word bpplane; + word palType; + word hScreenSize; + word vScreenSize; + byte padding[54]; +} head; + + +static void loadPcxStage1(FILE *file, bitmap_t *result) { + long bufSize; + int index; + byte count, val; + long int pos; + + /* read the header */ + fread(&head, sizeof(char), sizeof(struct pcxHeader), file); + + /* get the width and height */ + result->width = head.xmax - head.xmin + 1; + result->height = head.ymax - head.ymin + 1; + + /* make sure this is 8bpp */ + if(head.bpp != 8) { + printf("I only know how to handle 8bpp pcx files!\n"); + fclose(file); + exit(-2); + } +} + +void loadPcxPalette(FILE *file, bitmap_t *result) { + byte val; + int index; + + /* handle the palette */ + fseek(file, -769, SEEK_END); + val = fgetc(file); + result->palette = modexNewPal(); + if(head.version == 5 && val == 12) { + /* use the vga palette */ + for(index=0; !feof(file) && index < PAL_SIZE; index++) { + val = fgetc(file); + result->palette[index] = val >> 2; + } + } else { + /* use the 16 color palette */ + for(index=0; index<48; index++) { + result->palette[index] = head.pal16[index]; + } + } +} void @@ -920,6 +984,422 @@ modexLoadPalFile(byte *filename, byte *palette) { fclose(file); } +bitmap_t +bitmapLoadPcx(char *filename) { + FILE *file; + bitmap_t result; + long bufSize; + int index; + byte count, val; + + /* open the PCX file for reading */ + file = fopen(filename, "rb"); + if(!file) { + printf("Could not open %s for reading.\n", filename); + exit(-2); + } + + /* load the first part of the pcx file */ + loadPcxStage1(file, &result); + + /* allocate the buffer */ + bufSize = result.width * result.height; + result.data = malloc(bufSize); + if(!result.data) { + printf("Could not allocate memory for bitmap data."); + fclose(file); + exit(-1); + } + + /* read the buffer in */ + index = 0; + do { + /* get the run length and the value */ + count = fgetc(file); + if(0xC0 == (count & 0xC0)) { /* this is the run count */ + count &= 0x3f; + val = fgetc(file); + } else { + val = count; + count = 1; + } + + /* write the pixel the specified number of times */ + for(; count && index < bufSize; count--,index++) { + result.data[index] = val; + } + } while(index < bufSize); + + loadPcxPalette(file, &result); + + fclose(file); + + return result; +} + + +tileset_t +bitmapLoadPcxTiles(char *filename, word twidth, word theight) { + tileset_t ts; + FILE *file; + bitmap_t result; + int i; + + /* open the PCX file for reading */ + file = fopen(filename, "rb"); + if(!file) { + printf("Could not open %s for reading.\n", filename); + exit(-2); + } + + /* load the first part of the pcx file */ + loadPcxStage1(file, &result); + + /* get the number of tiles and set up the result structure */ + ts.twidth = twidth; + ts.theight = theight; + ts.ntiles = (result.width/twidth) * (result.height/theight); + ts.palette = result.palette; + + /* allocate the pixel storage for the tiles */ + ts.data = malloc(sizeof(byte*) * ts.ntiles); + ts.data[0] = malloc(sizeof(byte) * ts.ntiles * twidth * theight); + for(i=1; i < ts.ntiles; i++) { + ts.data[i] = ts.data[i-1] + twidth * theight; + } + + /* finish off the file */ + loadPcxPalette(file, &result); + + fclose(file); + + return ts; +} + +void +oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite) +{ + byte plane; + word px, py; + word offset; + + /* TODO Make this fast. It's SLOOOOOOW */ + for(plane=0; plane < 4; plane++) { + modexSelectPlane(PLANE(plane+x)); + for(px = plane; px < bmp->width; px+=4) { + offset=px; + for(py=0; pyheight; py++) { + if(!sprite || bmp->data[offset]) + page[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset]; + offset+=bmp->width; + } + } + } +} + +//* normal versions *// +void +modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) { + /* draw the region (the entire freakin bitmap) */ + modexDrawBmpRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawBmpRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, bitmap_t *bmp) { + word poffset = (word)page->data + y*(page->width/4) + x/4; + byte *data = bmp->data;//+bmp->offset; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter=0; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, SC_MAPMASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + MOVSB ; copy the pixel + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} + +void +modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) { + /* draw the whole sprite */ + modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawSpriteRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, bitmap_t *bmp) { + word poffset = (word)page->data + y*(page->width/4) + x/4; + byte *data = bmp->data;//+bmp->offset; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter=0; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, SC_MAPMASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + LODSB + DEC SI + CMP AL, 0 + JNE DRAW_PIXEL ; draw non-zero pixels + + INC DI ; skip the transparent pixel + ADD SI, 1 + JMP NEXT_PIXEL + DRAW_PIXEL: + MOVSB ; copy the pixel + NEXT_PIXEL: + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} + +//* planar buffer versions *// +void +modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp) { + /* draw the region (the entire freakin bitmap) */ + modexDrawBmpPBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawBmpPBufRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, planar_buf_t *bmp) { + word poffset = (word) page->data + y*(page->width/4) + x/4; + byte *data = (byte *)bmp->plane[0]; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter=0; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, SC_MAPMASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + + + + + + + + + + MOVSB ; copy the pixel + + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} + +void +modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp) { + /* draw the whole sprite */ + modexDrawSpritePBufRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); +} + +void +modexDrawSpritePBufRegion(page_t *page, int x, int y, + int rx, int ry, int rw, int rh, planar_buf_t *bmp) { + word poffset = (word)page->data + y*(page->width/4) + x/4; + byte *data = (byte *)bmp->plane[0]; + word bmpOffset = (word) data + ry * bmp->width + rx; + word width = rw; + word height = rh; + byte plane = 1 << ((byte) x & 0x03); + word scanCount = width/4 + (width%4 ? 1 :0); + word nextPageRow = page->width/4 - scanCount; + word nextBmpRow = (word) bmp->width - width; + word rowCounter=0; + byte planeCounter = 4; + + __asm { + MOV AX, SCREEN_SEG ; go to the VGA memory + MOV ES, AX + + MOV DX, SC_INDEX ; point at the map mask register + MOV AL, SC_MAPMASK ; + OUT DX, AL ; + + PLANE_LOOP: + MOV DX, SC_DATA ; select the current plane + MOV AL, plane ; + OUT DX, AL ; + + ;-- begin plane painting + MOV AX, height ; start the row counter + MOV rowCounter, AX ; + MOV DI, poffset ; go to the first pixel + MOV SI, bmpOffset ; go to the bmp pixel + ROW_LOOP: + MOV CX, width ; count the columns + SCAN_LOOP: + LODSB + DEC SI + CMP AL, 0 + JNE DRAW_PIXEL ; draw non-zero pixels + + INC DI ; skip the transparent pixel + ADD SI, 1 + JMP NEXT_PIXEL + DRAW_PIXEL: + MOVSB ; copy the pixel + NEXT_PIXEL: + SUB CX, 3 ; we skip the next 3 + ADD SI, 3 ; skip the bmp pixels + LOOP SCAN_LOOP ; finish the scan + + MOV AX, nextPageRow + ADD DI, AX ; go to the next row on screen + MOV AX, nextBmpRow + ADD SI, AX ; go to the next row on bmp + + DEC rowCounter + JNZ ROW_LOOP ; do all the rows + ;-- end plane painting + + MOV AL, plane ; advance to the next plane + SHL AL, 1 ; + AND AL, 0x0f ; mask the plane properly + MOV plane, AL ; store the plane + + INC bmpOffset ; start bmp at the right spot + + DEC planeCounter + JNZ PLANE_LOOP ; do all 4 planes + } +} + #define COREPALSIZE 9//27 //3*9 void VLL_LoadPalFilewithoffset(const char *filename, byte *palette, word o, word palsize, global_game_variables_t *gvar) diff --git a/src/lib/16_vl.h b/src/lib/16_vl.h index 2390cf8d..0612a9bf 100755 --- a/src/lib/16_vl.h +++ b/src/lib/16_vl.h @@ -204,8 +204,21 @@ void modexFlashOff(word fade, byte *palette); /* palette loading and saving */ void VL_SetPalette (byte far *palette, video_t *v); void modexPalSave(byte *palette); -//byte *modexNewPal(); +byte *modexNewPal(); void modexLoadPalFile(char *filename, byte *palette); +static void loadPcxStage1(FILE *file, bitmap_t *result); +void loadPcxPalette(FILE *file, bitmap_t *result); +bitmap_t bitmapLoadPcx(char *filename); +tileset_t bitmapLoadPcxTiles(char *filename, word twidth, word theight); +void oldDrawBmp(byte far* page, int x, int y, bitmap_t *bmp, byte sprite); +void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp); +void modexDrawBmpRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp); +void modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp); +void modexDrawSpriteRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, bitmap_t *bmp); +void modexDrawBmpPBuf(page_t *page, int x, int y, planar_buf_t *bmp); /*pbuf version*/ +void modexDrawBmpPBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *bmp); +void modexDrawSpritePBuf(page_t *page, int x, int y, planar_buf_t *bmp); +void modexDrawSpritePBufRegion(page_t *page, int x, int y, int rx, int ry, int rw, int rh, planar_buf_t *bmp); void VL_LoadPalFile(const char *filename, byte *palette, global_game_variables_t *gvar); void VL_LoadPalFileCore(byte *palette, global_game_variables_t *gvar); void VL_SetCorePal(global_game_variables_t *gvar); diff --git a/src/pcxtest.c b/src/pcxtest.c index a29c6175..1c3aa9c9 100755 --- a/src/pcxtest.c +++ b/src/pcxtest.c @@ -24,8 +24,8 @@ #include #include #include "src/lib/16_vl.h" -#include "16/src/lib/bitmap.h" -#include "16/src/lib/16render.h" +//#include "16/modex16/bitmap.h" +//#include "16/modex16/16render.h" #include "src/lib/16_in.h" #include "src/lib/16_tail.h" @@ -64,7 +64,8 @@ void main() { } //0000 PCXBMP = bitmapLoadPcx("data/koishi~~.pcx"); - PCXBMP = bitmapLoadPcx("data/chikyuu.pcx", &gvar); +//0000 PCXBMP = bitmapLoadPcx("data/chikyuu.pcx"/*, &gvar*/); + PCXBMP = bitmapLoadPcx("data/maryai.pcx"); // PCXBMP = bitmapLoadPcx("data/koishi^^.pcx"); // PCXBMP = bitmapLoadPcx("16/PCX_LIB/chikyuu.pcx"); //---- p = planar_buf_from_bitmap(PCXBMPPTR); diff --git a/src/pcxtest2.c b/src/pcxtest2.c index 5dd8505f..dadb2c45 100755 --- a/src/pcxtest2.c +++ b/src/pcxtest2.c @@ -24,7 +24,7 @@ #include #include #include "src/lib/16_vl.h" -#include "16/src/lib/bitmap.h" +//#include "16/src/lib/bitmap.h" //----#include "src/lib/planar.h" static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ @@ -85,7 +85,8 @@ void main() { } //0000 bmp = bitmapLoadPcx("data/koishi~~.pcx"); - bmp = bitmapLoadPcx("data/chikyuu.pcx", &gvar); +//0000 bmp = bitmapLoadPcx("data/chikyuu.pcx"/*, &gvar*/); + bmp = bitmapLoadPcx("data/maryai.pcx"/*, &gvar*/); // bmp = bitmapLoadPcx("data/koishi^^.pcx"); // bmp = bitmapLoadPcx("16/PCX_LIB/chikyuu.pcx"); //---- p = planar_buf_from_bitmap(&bmp); diff --git a/src/scroll.c b/src/scroll.c index 10ef02fd..4eb61a3d 100755 --- a/src/scroll.c +++ b/src/scroll.c @@ -37,7 +37,7 @@ extern boolean pagenorendermap; unsigned int i; //#ifdef FADE static word paloffset=0; - byte *gvar.video.dpal; +//--00 byte *gvar.video.dpal; //#endif // byte *ptr; byte *mappalptr;