X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16.c;h=e184dc1e2e0e4d251b7c17bb866cd3b039dddde7;hb=e8a8ba36af9d47236981affa02532faf42bf304d;hp=3efba94c6286bb39f1286f7c237eb5f1bd23bb67;hpb=94b2c3169aa6501f14ef021317647259b831d185;p=16.git diff --git a/src/lib/modex16.c b/src/lib/modex16.c old mode 100644 new mode 100755 index 3efba94c..e184dc1e --- a/src/lib/modex16.c +++ b/src/lib/modex16.c @@ -20,9 +20,6 @@ * */ -#include -#include -#include #include #include #include @@ -32,6 +29,44 @@ 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; + +///////////////////////////////////////////////////////////////////////////// +// // +// setvideo() - This function Manages the video modes // +// // +///////////////////////////////////////////////////////////////////////////// +void VGAmodeX(sword vq, global_game_variables_t *gv) +{ + union REGS in, out; + + 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->old_mode; + int86(0x10, &in, &out); + break; + case 1: // init the video + // get old video mode + in.h.ah = 0xf; + int86(0x10, &in, &out); + gv->old_mode = out.h.al; + // enter mode + modex__320x240_256__Enter(gv); + break; + case 2: // init the video + // get old video mode + in.h.ah = 0xf; + int86(0x10, &in, &out); + gv->old_mode = out.h.al; + // enter mode + modex__256x192_256__Enter(gv); + break; + } +} static void vgaSetMode(byte mode) @@ -43,57 +78,56 @@ vgaSetMode(byte mode) int86(VIDEO_INT, ®s, ®s); } - /* -========================= 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; idata + (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; } @@ -257,24 +328,46 @@ modexClearRegion(page_t *page, int x, int y, int w, int h, byte color) { 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 +CDrawBmp(byte far* vgamem, page_t* page, int x, int y, bitmap_t *bmp, byte sprite) +{ + byte plane; + word px, py; + word offset=0; + + + /* 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]) + //modexputPixel(page, x+px, y+py, bmp->data[offset]); + vgamem[PAGE_OFFSET(x+px, y+py)] = bmp->data[offset]; + offset+=bmp->width; + } + } + } +} void modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) { @@ -287,7 +380,7 @@ 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; @@ -298,6 +391,10 @@ 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));*/ + //code is a bit slow here __asm { MOV AX, SCREEN_SEG ; go to the VGA memory @@ -346,6 +443,72 @@ modexDrawBmpRegion(page_t *page, int x, int y, } } +void +modex_sparky4_DrawBmpRegion(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 far *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; + +/* 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 { + 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: + 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 modexDrawPlanarBuf(page_t *page, int x, int y, planar_buf_t *bmp) { @@ -943,76 +1106,90 @@ no... wait.... no wwww } void modexputPixel(page_t *page, int x, int y, byte color) -{ +{ word pageOff = (word) page->data; /* Each address accesses four neighboring pixels, so set Write Plane Enable according to which pixel we want to modify. The plane is determined by the two least - significant bits of the x-coordinate: */ - //modexSelectPlane(PLANE(x)); - outp(SC_INDEX, 0x02); - outp(SC_DATA, 0x01 << (x & 3)); + significant bits of the x-coordinate: */ + modexSelectPlane(PLANE(x)); + //outp(SC_INDEX, 0x02); + //outp(SC_DATA, 0x01 << (x & 3)); /* The offset of the pixel into the video segment is offset = (width * y + x) / 4, and write the given color to the plane we selected above. Heed the active page start selection. */ - VGA[(unsigned)((SCREEN_WIDTH/4) * y) + (x / 4) + pageOff] = color; + VGA[(unsigned)((page->width/4) * y) + (x / 4) + pageOff] = color; } -byte modexgetPixel(int x, int y) +byte modexgetPixel(page_t *page, int x, int y) { + word pageOff = (word) page->data; /* Select the plane from which we must read the pixel color: */ outpw(GC_INDEX, 0x04); outpw(GC_INDEX+1, x & 3); - return VGA[(unsigned)((SCREEN_WIDTH/4) * y) + (x / 4) + 0]; + return VGA[(unsigned)((page->width/4) * y) + (x / 4) + pageOff]; } +void modexhlin(page_t *page, word xl, word xh, word y, word color) +{ + word x; + word yy=0; + + for(x=0;x=SCREEN_WIDTH-1){ x=0; yy+=4; } + modexClearRegion(page, x+xl, y+yy, 4, 4, color); + } + //modexputPixel(page, x+xl, y, color); +} + void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str) -{ - word i, s, o, w, j, xp; +{ + word i, s, o, w, j, xp; byte l[1024]; - word addr = (word) l; - word chw=0; - byte c; - + word addr = (word) l; + word chw=0; + byte c; + switch(t) { - case 0: + case 0: w=14; break; - case 1: + case 1: w=8; break; - case 2: + case 2: w=8; break; - case 3: + case 3: w=16; break; - default: + default: t=3; w=16; break; - } + } s=romFonts[t].seg; - o=romFonts[t].off; + o=romFonts[t].off; for(; *str != '\0'; str++) - { - c = (*str); - if((c=='\n'/* || c=="\ -"*/) || chw ->=page->width) - { - chw=0; - y+=w; - continue; - } + { + c = (*str); + if((c=='\n'/* || c=="\ +"*/) || chw +>=page->width) + { + chw=0; + y+=w; + continue; + } //load the letter 'A' __asm { MOV DI, addr @@ -1029,64 +1206,64 @@ void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, cons INC DI DEC CX JNZ L1 - } + } - for(i=0; i>=1; - } + while(j) + { + modexputPixel(page, x+xp+chw, y+i, l[i] & j ? col:bgcol); + xp++; + j>>=1; + } } chw += xp; } -} - +} + void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str) -{ - word i, s, o, w, j, xp; +{ + word i, s, o, w, j, xp; byte l[1024]; - word addr = (word) l; - word chw=0; - byte c; - + word addr = (word) l; + word chw=0; + byte c; + switch(t) { - case 0: + case 0: w=14; break; - case 1: + case 1: w=8; break; - case 2: + case 2: w=8; break; - case 3: + case 3: w=16; break; - default: + default: t=3; w=16; break; - } + } s=romFonts[t].seg; - o=romFonts[t].off; + o=romFonts[t].off; for(; *str != '\0'; str++) - { - c = (*str); - if((c=='\n'/* || c=="\ -"*/)/* || chw>=page->width*/) - { - chw=0; - y+=w; - continue; - } + { + c = (*str); + if((c=='\n'/* || c=="\ +"*/)/* || chw>=page->width*/) + { + chw=0; + y+=w; + continue; + } //load the letter 'A' __asm { MOV DI, addr @@ -1103,24 +1280,39 @@ void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, c INC DI DEC CX JNZ L1 - } + } - for(i=0; i>=1; - } + while(j) + { + //modexputPixel(page, x+xp+chw, y+i, l[i] & j ? col:bgcol); + modexClearRegion(page, (x+xp+chw)*8, (y+i)*8, 8, 8, l[i] & j ? col:bgcol); + xp++; + j>>=1; + } } chw += xp; } } +///////////////////////////////////////////////////////////////////////////// +// // +// cls() - This clears the screen to the specified color, on the VGA or on // +// the Virtual screen. // +// // +///////////////////////////////////////////////////////////////////////////// +void cls(page_t *page, byte color, byte *Where) +{ + //modexClearRegion(page, 0, 0, page->width, 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) {