X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16.c;h=5cec70c919a773f2332ee697b7da5937da3c1ff7;hb=5d052fa67f70bfa48bdd3cc1db3ba15802ec27c9;hp=27ad067757bf51701e7c4775c43e015a2daf2cae;hpb=18e9a8fb1179c8843a3dc67cbb8f69250265858f;p=16.git diff --git a/src/lib/modex16.c b/src/lib/modex16.c index 27ad0677..5cec70c9 100755 --- a/src/lib/modex16.c +++ b/src/lib/modex16.c @@ -29,7 +29,6 @@ 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]; -//int old_mode; ///////////////////////////////////////////////////////////////////////////// // // @@ -40,23 +39,23 @@ void VGAmodeX(sword vq, global_game_variables_t *gv) { union REGS in, out; - if(!vq) - { // deinit the video - // change to the video mode we were in before we switched to mode 13h - modexLeave(); - in.h.ah = 0x00; - in.h.al = gv->old_mode; - int86(0x10, &in, &out); - - } - else if(vq==1) - { // init the video - // get old video mode - in.h.ah = 0xf; - int86(0x10, &in, &out); - gv->old_mode = out.h.al; - // enter mode - modexEnter(); + switch (vq) + { + case 0: // deinit the video + // change to the video mode we were in before we switched to mode 13h + modexLeave(); + in.h.ah = 0x00; + in.h.al = gv->video.old_mode; + int86(0x10, &in, &out); + break; + default: // init the video + // get old video mode + //in.h.ah = 0xf; + //int86(0x10, &in, &out); + gv->video.old_mode = vgaGetMode();//out.h.al; + // enter mode + modexEnter(vq, gv); + break; } } @@ -70,57 +69,127 @@ vgaSetMode(byte mode) int86(VIDEO_INT, ®s, ®s); } +//--------------------------------------------------- +// +// Use the bios to get the current video mode +// + +long +vgaGetMode() +{ + union REGS rg; + + rg.h.ah = 0x0f; + int86(VIDEO_INT, &rg, &rg); + + return rg.h.al; +} /* -========================= Entry Points ==========================- */ void -modexEnter() { - word i; - dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */ - word CRTParms[] = { - 0x0d06, /* vertical total */ - 0x3e07, /* overflow (bit 8 of vertical counts) */ - 0x4109, /* cell height (2 to double-scan */ - 0xea10, /* v sync start */ - 0xac11, /* v sync end and protect cr0-cr7 */ - 0xdf12, /* vertical displayed */ - 0x0014, /* turn off dword mode */ - 0xe715, /* v blank start */ - 0x0616, /* v blank end */ - 0xe317 /* turn on byte mode */ - }; - int CRTParmCount = sizeof(CRTParms) / sizeof(CRTParms[0]); - - /* TODO save current video mode and palette */ - vgaSetMode(VGA_256_COLOR_MODE); - - /* disable chain4 mode */ - outpw(SC_INDEX, 0x0604); - - /* synchronous reset while setting Misc Output */ - outpw(SC_INDEX, 0x0100); - - /* select 25 MHz dot clock & 60 Hz scanning rate */ - outp(MISC_OUTPUT, 0xe3); - - /* undo reset (restart sequencer) */ - outpw(SC_INDEX, 0x0300); - - /* reprogram the CRT controller */ - outp(CRTC_INDEX, 0x11); /* VSync End reg contains register write prot */ - outp(CRTC_DATA, 0x7f); /* get current write protect on varios regs */ - - /* send the CRTParms */ - for(i=0; ivideo.page); - /* clear video memory */ - outpw(SC_INDEX, 0x0f02); - for(i=0; i<0x8000; i++) { - ptr[i] = 0x0000; - } -} + switch(vq) + { + case 1: + CRTParmCount = sizeof(ModeX_320x240regs) / sizeof(ModeX_320x240regs[0]); + /* width and height */ + gv->video.page[0].sw=320; + gv->video.page[0].sh=240; + + /* send the CRTParms */ + for(i=0; ivideo.page[0].sw=120; + gv->video.page[0].sh=160; + + /* send the CRTParms */ + for(i=0; ivideo.page[0].sw=320; + gv->video.page[0].sh=200; + + /* send the CRTParms */ + for(i=0; ivideo.page[0].sw=192; + gv->video.page[0].sh=144; + + /* send the CRTParms */ + for(i=0; ivideo.page[0].sw=256; + gv->video.page[0].sh=192; + + /* send the CRTParms */ + for(i=0; ivideo.page[0].tilesw = gv->video.page[0].sw/TILEWH; + gv->video.page[0].tilesh = gv->video.page[0].sh/TILEWH; + //TODO MAKE FLEXIBLE~ + gv->video.page[0].tilemidposscreenx = gv->video.page[0].tilesw; + gv->video.page[0].tilemidposscreeny = (gv->video.page[0].tilesh/2)+1; + #define PAGE_SIZE (word)(gv->video.page[0].sw/4 * gv->video.page[0].sh) +} void modexLeave() { @@ -128,18 +197,58 @@ modexLeave() { vgaSetMode(TEXT_MODE); } +// setBaseXMode() does the initialization to make the VGA ready to +// accept any combination of configuration register settings. This +// involves enabling writes to index 0 to 7 of the CRT controller (port +// 0x3D4), by clearing the most significant bit (bit 7) of index 0x11. +void +modexsetBaseXMode(page_t *page) +{ + word temp; + /* TODO save current video mode and palette */ + vgaSetMode(VGA_256_COLOR_MODE); + + /* disable chain4 mode */ + outpw(SC_INDEX, 0x0604); + + /* synchronous reset while setting Misc Output */ + outpw(SC_INDEX, 0x0100); + + /* select 25 MHz dot clock & 60 Hz scanning rate */ + outp(MISC_OUTPUT, 0xe3); + + /* undo reset (restart sequencer) */ + outpw(SC_INDEX, 0x0300); + + /* reprogram the CRT controller */ + outp(CRTC_INDEX, 0x11); /* VSync End reg contains register write prot */ +// temp = inp(CRTC_DATA) & 0x7F; +// outp(CRTC_INDEX, 0x11); + outp(CRTC_DATA, 0x7f); /* get current write protect on varios regs */ +// outp(CRTC_DATA, temp); /* get current write protect on varios regs */ +} page_t -modexDefaultPage() { +modexDefaultPage(page_t *p) +{ page_t page; /* default page values */ page.data = VGA; page.dx = 0; page.dy = 0; - page.width = SCREEN_WIDTH; - page.height = SCREEN_HEIGHT; - page.id = 0; + page.sw = p->sw; + page.sh = p->sh; + page.width = p->sw; + page.height = p->sh; + page.tw = page.sw/TILEWH; + page.th = page.sh/TILEWH; + page.tilemidposscreenx = page.tw/2; + page.tilemidposscreeny = (page.th/2)+1; + page.tilesw=p->tilesw; + page.tilesh=p->tilesh; + //pageSize = p->sw*p->sh; + page.id = 0; return page; } @@ -151,30 +260,35 @@ page_t modexNextPage(page_t *p) { page_t result; - result.data = p->data + (p->width/4)*p->height; /* compute the offset */ + result.data = p->data + (p->width/4)*p->height; result.dx = 0; result.dy = 0; result.width = p->width; result.height = p->height; - result.id = p->id+1; + result.tw = p->width/TILEWH; + result.th = p->height/TILEWH; + result.id = p->id+1; - return result; + return result; +// return modexNextPageFlexibleSize(&p, p->width, p->height); } //next page with defined dimentions~ page_t -modexNextPage0(page_t *p, word x, word y) +modexNextPageFlexibleSize(page_t *p, word x, word y) { - page_t result; - - result.data = p->data + (p->width/4)*p->height; /* compute the offset */ - result.dx = 0; - result.dy = 0; - result.width = x; - result.height = y; - result.id = p->id+1; - - return result; + page_t result; + + result.data = p->data + (p->width/4)*p->height; /* compute the offset */ + result.dx = 0; + result.dy = 0; + result.width = x; + result.height = y; + result.tw = p->width/TILEWH; + result.th = p->height/TILEWH; + result.id = p->id+1; + + return result; } @@ -280,41 +394,124 @@ modexClearRegion(page_t *page, int x, int y, int w, int h, byte color) { } } +//TODO! ADD CLIPPING!! +//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) +{ + int plane; + int px, py, i; +// byte near *buff; + px=x; + py=y; +// 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=(rx/4)+((rx/4)*ry); + modexSelectPlane(PLANE(plane+x)); + 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->dy)) + ((x+page->dx) / 4)), buff, p->pwidth); + _fmemcpy(page->data + (((page->width/4) * (y+page->dy)) + ((x+page->dx) / 4)), &(p->plane[plane][i+=p->pwidth]), p->pwidth); + //} + } + x=px; + y=py; + } +// _nfree(buff); +} + +/*void +DrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite) +{ + int plane; + int px, py, i; +// byte near *buff; + px=x; + py=y; +// 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+x)); + 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->dy)) + ((x+page->dx) / 4)), buff, p->pwidth); + _fmemcpy(page->data + (((page->width/4) * (y+page->dy)) + ((x+page->dx) / 4)), &(p->plane[plane][i+=p->pwidth]), p->pwidth); + //} + } + 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; - } - } - } + 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; + } + } + } } - 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; + byte far *data = bmp->data;//+bmp->offset; word bmpOffset = (word) data + ry * bmp->width + rx; word width = rw; word height = rh; @@ -325,9 +522,9 @@ modexDrawBmpRegion(page_t *page, int x, int y, word rowCounter; byte planeCounter = 4; - printf("bmp->data=%Fp\n",bmp->data); +/* printf("bmp->data=%Fp\n",bmp->data); printf("*bmp->data=%Fp\n",*(bmp->data)); - printf("&bmp->data=%Fp\n",&(bmp->data)); + printf("&bmp->data=%Fp\n",&(bmp->data));*/ //code is a bit slow here __asm { @@ -377,7 +574,6 @@ modexDrawBmpRegion(page_t *page, int x, int y, } } - void modexDrawPlanarBuf(page_t *page, int x, int y, planar_buf_t *bmp) { /* TODO - adapt from test code */ @@ -395,7 +591,7 @@ modexDrawSprite(page_t *page, int x, int y, bitmap_t *bmp) { modexDrawSpriteRegion(page, x, y, 0, 0, bmp->width, bmp->height, bmp); } -void +/*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; @@ -465,8 +661,79 @@ modexDrawSpriteRegion(page_t *page, int x, int y, DEC planeCounter JNZ PLANE_LOOP ; do all 4 planes } -} +}//backup!*/ +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 huge *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; + 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, MAP_MASK ; + 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 + } +} /* copy a region of video memory from one page to another. * It assumes that the left edge of the tile is the same on both @@ -883,6 +1150,14 @@ modexPalUpdate0(byte *p) } } +void +modexPalOverscan(byte *p, word col) +{ + modexWaitBorder(); + outp(PAL_WRITE_REG, 0); /* start at the beginning of palette */ + outp(PAL_DATA_REG, col); +} + //color checker~ //i want to make another vesion that checks the palette when the palette is being appened~ void chkcolor(bitmap_t *bmp, word *q, word *a, word *aa, word *z, word *i/*, word *offset*/) @@ -1010,7 +1285,7 @@ void modexhlin(page_t *page, word xl, word xh, word y, word color) for(x=0;x=SCREEN_WIDTH-1){ x=0; yy+=4; } + if(x+4>=page[0].sw-1){ x=0; yy+=4; } modexClearRegion(page, x+xl, y+yy, 4, 4, color); } //modexputPixel(page, x+xl, y, color); @@ -1023,6 +1298,7 @@ void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, cons word addr = (word) l; word chw=0; byte c; + //byte near *bakapee; switch(t) { @@ -1075,9 +1351,14 @@ void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, cons DEC CX JNZ L1 } - + //bakapee = _nmalloc(sizeof(byte)*8); +//TODO: OPTIMIZE THIS!!!! for(i=0; idata + (((page->width/4) * (y+page->dy+i)) + ((x+page->dx+chw) / 4)), bakapee, 8);*/ j=1<<8; xp=0; while(j) @@ -1089,6 +1370,7 @@ void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, cons } chw += xp; } + //_nfree(bakapee); } void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str) @@ -1166,6 +1448,36 @@ void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, c } } +/* palette dump on display! */ +void pdump(page_t *pee) +{ + int mult=(QUADWH); + int palq=(mult)*TILEWH; + int palcol=0; + int palx, paly; + for(paly=0; palywidth, page->height, color); + /* set map mask to all 4 planes */ + outpw(SC_INDEX, 0xff02); + //_fmemset(VGA, color, 16000); + _fmemset(Where, color, page->width*(page->height)); +} + void modexWaitBorder() { while(inp(INPUT_STATUS_1) & 8) {