X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_vl.c;h=70edfb8d7199017c3edd93b2ce5d37698e81055e;hb=6e25378c841d61961c4a907eea70ad65e826c73f;hp=ceed6410caf53475675ba0da8c4c0d26ce88308a;hpb=320be82ab5e414d1b771b295403218b614ed9d13;p=16.git diff --git a/src/lib/16_vl.c b/src/lib/16_vl.c index ceed6410..70edfb8d 100755 --- a/src/lib/16_vl.c +++ b/src/lib/16_vl.c @@ -1,5 +1,5 @@ /* Project 16 Source Code~ - * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover + * Copyright (C) 2012-2022 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover * * This file is part of Project 16. * @@ -28,7 +28,7 @@ byte far* VGA=(byte far*) 0xA0000000; /* this points to video memory. */ static void fadePalette(sbyte fade, sbyte start, word iter, byte *palette); -static byte tmppal[PAL_SIZE]; +/*static */byte tmppal[PAL_SIZE]; //=========================================================================== @@ -45,7 +45,8 @@ void VL_Startup (global_game_variables_t *gvar) __asm cld; VGAmodeX(1/*TODO other modes*/, 1, gvar); - VL_LoadPalFileCore(gvar->video.palette, gvar); +//-- VL_LoadPalFileCore(gvar->video.palette, gvar); + VL_SetCorePal(gvar); //Quit ("Improper video card! If you really have a VGA card that I am not\ndetecting it!", gvar); } @@ -320,15 +321,7 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv) case 2: // TODO: 160x120 according to ModeX_160x120regs return; case 3: // TODO: 160x120 according to ModeX_320x200regs - gv->video.page[0].sw = vga_state.vga_width = 300; // VGA lib currently does not update this - gv->video.page[0].sh = vga_state.vga_height = 200; // VGA lib currently does not update this - // virtual width and height. match screen, at first // - gv->video.page[0].height = gv->video.page[0].sh; - gv->video.page[0].width = gv->video.page[0].sw; - - cm.offset = (vga_state.vga_width / (4 * 2)); // 320 wide (40 x 4 pixel groups x 2) - //return; - break; + return; case 4: // TODO: 160x120 according to ModeX_192x144regs return; case 5: // TODO: 160x120 according to ModeX_256x192regs @@ -359,7 +352,9 @@ void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv) } break; } - VL_SetLineWidth (cm.offset, gv); +//-- VL_SetLineWidth (cm.offset, gv); + //gv->video.ofs.displayofs = 0; + //gv->video.ofs.bufferofs = gv->video.page[0].width*gv->video.page[0].height;//gvar->video.page[0].pagesize; gv->video.curr_mode=vq; gv->video.VL_Started=1; } @@ -375,7 +370,6 @@ page_t modexDefaultPage(page_t *p) { page_t page; - /* default page values */ //page.data = VGA; //page.data = (byte far *)(vga_state.vga_graphics_ram); @@ -396,18 +390,16 @@ modexDefaultPage(page_t *p) page.pagesize = (word)(page.stridew)*page.height; page.pi=page.width*4; page.id = 0; - if(ggvv->video.curr_mode = 1) { page.width += TILEWHD; page.height += TILEWHD; } - return page; } #endif page_t -modexDefaultPage(page_t *p, video_t *v) +modexDefaultPage(page_t *p, global_game_variables_t *gvar) { page_t page; @@ -421,7 +413,7 @@ modexDefaultPage(page_t *p, video_t *v) page.sh = p->sh; page.width = p->sw; page.height = p->sh; - if(v->curr_mode == 1) + if(gvar->video.curr_mode == 1) { page.width += TILEWHD; page.height += TILEWHD; } page.ti.tw = page.sw/TILEWH; @@ -522,38 +514,41 @@ void VL_Initofs(video_t *video) } } -void modexHiganbanaPageSetup(video_t *video) +void modexHiganbanaPageSetup(global_game_variables_t *gvar) { - video->vmem_remain=65535U; - video->num_of_pages=0; - (video->page[0]) = modexDefaultPage(&(video->page[0]), video); video->num_of_pages++; //video->page[0].width += (TILEWHD); video->page[0].height += (TILEWHD); - (video->page[1]) = modexNextPage(&(video->page[0])); video->num_of_pages++; -//0000 (video->page[2]) = modexNextPageFlexibleSize(&(video->page[1]), (video->page[0]).width, TILEWH*4); video->num_of_pages++; -//0000 (video->page[3]) = (video->page[2]); video->num_of_pages++; -//// (video->page[2]) = modexNextPageFlexibleSize(&(video->page[1]), TILEWH*4, TILEWH*4); video->num_of_pages++; -//// (video->page[3]) = modexNextPageFlexibleSize(&(video->page[2]), video->page[0].sw, 208); video->num_of_pages++; - (video->page[2]) = modexNextPageFlexibleSize(&(video->page[1]), video->page[0].width, 96); video->num_of_pages++; - (video->page[3]) = modexNextPageFlexibleSize(&(video->page[2]), video->page[0].width, 96); video->num_of_pages++; - modexCalcVmemRemain(video); - - video->sp=video->p = 0; //showpage - video->dorender = 1; //render - video->vh=video->page[0].height+video->page[1].height+video->page[2].height+video->page[3].height; - - VL_Initofs(video); + gvar->video.vmem_remain=65535U; + gvar->video.num_of_pages=0; + (gvar->video.page[0]) = modexDefaultPage(&(gvar->video.page[0]), gvar); gvar->video.num_of_pages++; //gvar->video.page[0].width += (TILEWHD); gvar->video.page[0].height += (TILEWHD); + (gvar->video.page[1]) = modexNextPage(&(gvar->video.page[0])); gvar->video.num_of_pages++; +//0000 (gvar->video.page[2]) = modexNextPageFlexibleSize(&(gvar->video.page[1]), (gvar->video.page[0]).width, TILEWH*4); gvar->video.num_of_pages++; +//0000 (gvar->video.page[3]) = (gvar->video.page[2]); gvar->video.num_of_pages++; +//// (gvar->video.page[2]) = modexNextPageFlexibleSize(&(gvar->video.page[1]), TILEWH*4, TILEWH*4); gvar->video.num_of_pages++; +//// (gvar->video.page[3]) = modexNextPageFlexibleSize(&(gvar->video.page[2]), gvar->video.page[0].sw, 208); gvar->video.num_of_pages++; + (gvar->video.page[2]) = modexNextPageFlexibleSize(&(gvar->video.page[1]), gvar->video.page[0].width, 96); gvar->video.num_of_pages++; + (gvar->video.page[3]) = modexNextPageFlexibleSize(&(gvar->video.page[2]), gvar->video.page[0].width, 96); gvar->video.num_of_pages++; + modexCalcVmemRemain(&gvar->video); + + gvar->video.sp=gvar->video.p = 0; //showpage + gvar->video.dorender = 1; //render + gvar->video.vh=gvar->video.page[0].height+gvar->video.page[1].height+gvar->video.page[2].height+gvar->video.page[3].height; + + VL_Initofs(&gvar->video); //doslib origi var - video->vga_state.omemptr= vga_state.vga_graphics_ram; - video->vga_state.vga_draw_stride= vga_state.vga_draw_stride; - video->vga_state.vga_draw_stride_limit= vga_state.vga_draw_stride_limit; + gvar->video.vga_state.omemptr= vga_state.vga_graphics_ram; + gvar->video.vga_state.vga_draw_stride= vga_state.vga_draw_stride; + gvar->video.vga_state.vga_draw_stride_limit= vga_state.vga_draw_stride_limit; //sprite render switch and bgpreservation switch - video->vga_state.rss= 1; - video->vga_state.bgps= 1; + gvar->video.vga_state.rss= 1; + gvar->video.vga_state.bgps= 1; //setup the buffersize - video->page[0].dx=video->page[0].dy= - video->page[1].dx=video->page[1].dy=TILEWH; // 1 tile size buffer - video->page[2].dx=video->page[2].dy= - video->page[3].dx=video->page[3].dy=0; // cache pages are buffer wwww + gvar->video.page[0].dx=gvar->video.page[0].dy= + gvar->video.page[1].dx=gvar->video.page[1].dy=TILEWH; // 1 tile size buffer + gvar->video.page[2].dx=gvar->video.page[2].dy= + gvar->video.page[3].dx=gvar->video.page[3].dy=0; // cache pages are buffer wwww + + gvar->video.page[0].tlx=gvar->mv[0].tx*TILEWH; + gvar->video.page[0].tly=gvar->mv[0].ty*TILEWH; } // @@ -576,14 +571,14 @@ modexShowPage(page_t *page) { low_address = LOW_ADDRESS | (offset << 8); /* wait for appropriate timing and then program CRTC */ -//+=+= while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE)); +//+=+= while ((inp(STATUS_REGISTER_1) & DISPLAY_ENABLE)); outpw(CRTC_INDEX, high_address); outpw(CRTC_INDEX, low_address); outp(CRTC_INDEX, 0x13); outp(CRTC_DATA, crtcOffset); /* wait for one retrace */ -//+=+= while (!(inp(INPUT_STATUS_1) & VRETRACE)); +//+=+= while (!(inp(STATUS_REGISTER_1) & VRETRACE)); /* do PEL panning here */ outp(AC_INDEX, 0x33); @@ -618,14 +613,14 @@ VL_ShowPage(page_t *page, boolean vsync, boolean sr) low_address = LOW_ADDRESS | (offset << 8); // wait for appropriate timing and then program CRTC - if(vsync) while ((inp(INPUT_STATUS_1) & DISPLAY_ENABLE)); + if(vsync) while ((inp(STATUS_REGISTER_1) & DISPLAY_ENABLE)); outpw(CRTC_INDEX, high_address); outpw(CRTC_INDEX, low_address); outp(CRTC_INDEX, 0x13); outp(CRTC_DATA, crtcOffset); // wait for one retrace - if(vsync) while (!(inp(INPUT_STATUS_1) & VRETRACE)); + if(vsync) while (!(inp(STATUS_REGISTER_1) & VRETRACE)); // do PEL panning here outp(AC_INDEX, 0x33); @@ -885,18 +880,82 @@ void modexPalSave(byte *palette) } -/*byte * +byte * modexNewPal() { byte *ptr; - ptr = m a l l o c(PAL_SIZE); + ptr = malloc(PAL_SIZE); // handle errors if(!ptr) { - printf("Could not allocate palette.\n"); + printf("Could not Allocate palette.\n"); } return ptr; -}*/ +} +// old library +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 @@ -925,36 +984,477 @@ modexLoadPalFile(byte *filename, byte *palette) { fclose(file); } -void VL_LoadPalFile(const char *filename, byte *palette, global_game_variables_t *gvar) -{ - VL_LoadPalFilewithoffset(filename, palette, 9, gvar); -// VL_LoadPalFileCore(palette); +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; } -void VL_LoadPalFileCore(byte *palette, global_game_variables_t *gvar) + +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) { - VL_LoadPalFilewithoffset("data/16.pal", palette, 0, gvar); + 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 VL_LoadPalFilewithoffset(const char *filename, byte *palette, word o, global_game_variables_t *gvar) +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 + } +} +// end of old library + +#define COREPALSIZE 9//27 //3*9 + +void VLL_LoadPalFilewithoffset(const char *filename, byte *palette, word o, word palsize, global_game_variables_t *gvar) { int fd; + byte *newpalette; fd = open(filename,O_RDONLY|O_BINARY); if (fd >= 0) { - read(fd,palette, PAL_SIZE); + read(fd,palette, palsize*3); close(fd); - VL_UpdatePaletteWrite(palette, o, gvar); + if(palsize==COREPALSIZE) newpalette = palette; else{ //if core then load it + newpalette = &palette[3]; //skip overscan color + if(!o) o++; + } + VL_UpdatePaletteWrite(newpalette, o, palsize, gvar); } } -void VL_UpdatePaletteWrite(byte *palette, word o, global_game_variables_t *gvar) +//++++// +void VL_SetCorePal(global_game_variables_t *gvar) +{ + byte *palette = &corepal; + word i; + + vga_palette_lseek(0); + for (i=0;i < COREPALSIZE;i++) + vga_palette_write(palette[(i*3)+0]>>2, + palette[(i*3)+1]>>2, + palette[(i*3)+2]>>2); + + VL_PaletteSync(gvar); +} + +void VL_LoadPalFile(const char *filename, byte *palette, global_game_variables_t *gvar) +{ + VLL_LoadPalFilewithoffset(filename, palette, + 0, //overwrite core/system palette +// COREPALSIZE, //preserved core/system palette + PAL_SIZE/3, gvar); +} + +void VL_LoadPalFileCore(byte *palette, global_game_variables_t *gvar) +{ + VLL_LoadPalFilewithoffset("data/16.pal", palette, 0, COREPALSIZE, gvar); +} + +void VL_UpdatePaletteWrite(byte *palette, word o, word p, global_game_variables_t *gvar) { word i; - vga_palette_lseek(/*1+*/o); - //for (i=o;i < 256-o;i++) - for (i=0;i < 256-o;i++) + + vga_palette_lseek(o); + for (i=0;i < p-o;i++) vga_palette_write(palette[(i*3)+0]>>2,palette[(i*3)+1]>>2,palette[(i*3)+2]>>2); VL_PaletteSync(gvar); @@ -1038,14 +1538,20 @@ VL_modexPalScramble(byte *p) } word -modexPalOverscan(word col) +VL_modexPalOverscan(byte *p, word col) { + int i; //modexWaitBorder(); vga_wait_for_vsync(); outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */ - outp(PAL_DATA_REG, col); + for(i=col; i<(3+col); i++) + { + outp(PAL_DATA_REG, p[i]); + } +// modexPalSave(p); return col; } + //check 16_vl_1.c void modexputPixel(page_t *page, int x, int y, byte color) @@ -1115,7 +1621,7 @@ void modexDrawChar(page_t *page, int x/*for planar selection only*/, word t, wor } } -void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col, word bgcol, boolean sw, const byte *str) +void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word color, word bgcolor, boolean vidsw, const byte *str) { word s, o, w; word x_draw; @@ -1124,14 +1630,14 @@ void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col, word addrr; byte c; - switch(sw) + switch(vidsw) { case 0: printf("%s\n", str); break; case 1: if(tlsw){ x-=page->tlx; y-=page->tly; } - x_draw = x/4; + x_draw = x>>2; addrq = (page->stridew) * y + (word)(x_draw) + ((word)page->data); addrr = addrq; @@ -1157,7 +1663,7 @@ void modexprint(page_t *page, sword x, sword y, word t, boolean tlsw, word col, // no need for inline assembly! // NTS: It might even be faster to just let the modexDrawChar point directly at ROM font than to copy per char! --J.C. _fmemcpy(romFontsData.l,MK_FP(s,o+(w*c))/*ROM font location*/,w/*char size*/); - modexDrawChar(page, x_draw/*for mode X planar use*/, t, col, bgcol, addrr); + modexDrawChar(page, x_draw/*for mode X planar use*/, t, color, bgcolor, addrr); x_draw += 8; /* track X for edge of screen */ addrr += 2; /* move 8 pixels over (2 x 4 planar pixels per byte) */ } @@ -1259,8 +1765,14 @@ void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, c } } +// short hand of modexprint +void VL_print(const byte *str, nibble pagenum, global_game_variables_t *gvar) +{ + modexprint(&(gvar->video.page[pagenum]), gvar->video.print.x, gvar->video.print.y, gvar->video.print.t, gvar->video.print.tlsw, gvar->video.print.color, gvar->video.print.bgcolor, gvar->video.VL_Started, str); +} + /* palette dump on display! */ -void modexpdump(page_t *pee) +void modexpdump(nibble pagenum, global_game_variables_t *gvar) { int mult=(QUADWH); int palq=(mult)*TILEWH; @@ -1268,10 +1780,11 @@ void modexpdump(page_t *pee) int palx, paly; for(paly=TILEWH*8; palyvideo.page[pagenum], palx+TILEWH, paly+TILEWH, mult, mult, palcol); palcol++; } } + modexPalSave(gvar->video.palette); } #if 0 ///////////////////////////////////////////////////////////////////////////// @@ -1341,11 +1854,11 @@ void VL_PatternDraw(video_t *video, word pn, boolean sw, boolean allsw) void modexWaitBorder() { - while(inp(INPUT_STATUS_1) & 8) { + while(inp(STATUS_REGISTER_1) & 8) { // spin } - while(!(inp(INPUT_STATUS_1) & 8)) { + while(!(inp(STATUS_REGISTER_1) & 8)) { //spin } } @@ -1353,7 +1866,7 @@ modexWaitBorder() { void modexWaitBorder_start() { - while(inp(INPUT_STATUS_1) & 8) { + while(inp(STATUS_REGISTER_1) & 8) { // spin } @@ -1362,7 +1875,7 @@ modexWaitBorder_start() void modexWaitBorder_end() { - while(!(inp(INPUT_STATUS_1) & 8)) { + while(!(inp(STATUS_REGISTER_1) & 8)) { // spin } @@ -1382,17 +1895,25 @@ void VL_PrintmodexmemInfo(video_t *v) // printf("========================================\n"); printf(" Virtual Screen: %dx", v->page[0].width); printf("%d ", v->page[0].height); printf("Tile: %dx", v->page[0].ti.tilesw); printf("%d", v->page[0].ti.tilesh); printf("=((Virtual Screen)/16)\n"); printf(" Screen: %dx", v->page[0].sw); printf("%d ", v->page[0].sh); printf("Tile: %dx", v->page[0].ti.tw); printf("%d", v->page[0].ti.th); printf("=((Screen)/16)\n"); - - printf(" Free Video Memory: %u\n", v->vmem_remain); - printf(" page"); - for(i=0; inum_of_pages;i++) + printf(" vga_stride: %u ", vga_state.vga_stride); + printf("pagestride: %u ", v->page[0].stridew); + printf("draw_stride: %u ", vga_state.vga_draw_stride); + printf("draw_stride_limit: %u\n", vga_state.vga_draw_stride_limit); + + if(v->vmem_remain) + printf(" Free Video Memory: %u\n", v->vmem_remain); + if(v->num_of_pages) { - printf(" [%u]=", i); - printf("(%Fp)", (v->page[i].data)); - printf(" size=%u ", v->page[i].pagesize); - printf("w=%-3lu h=%-3lu ", (unsigned long)v->page[i].width, (unsigned long)v->page[i].height); - printf("sw=%-3lu sh=%-3lu ", (unsigned long)v->page[i].sw, (unsigned long)v->page[i].sh); - printf("pi=%u", v->page[i].pi); - printf("\n"); + printf(" page"); + for(i=0; inum_of_pages;i++) + { + printf(" [%u]=", i); + printf("(%Fp)", (v->page[i].data)); + printf(" size=%u ", v->page[i].pagesize); + printf("w=%-3lu h=%-3lu ", (unsigned long)v->page[i].width, (unsigned long)v->page[i].height); + printf("sw=%-3lu sh=%-3lu ", (unsigned long)v->page[i].sw, (unsigned long)v->page[i].sh); + printf("pi=%u", v->page[i].pi); + printf("\n"); + } } }