X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16.c;h=ea059d82d2c58837413e8dba0e2adc643c697cdb;hb=ddf0f7c950011c570d0c0a35ad9b2dea8d5d1160;hp=624a96d683366ec3e105636e6511d821d7b2dd6a;hpb=c3104b1494bd0f31ce49e3365d36e4ace02e69c7;p=16.git diff --git a/src/lib/modex16.c b/src/lib/modex16.c index 624a96d6..ea059d82 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 - modex__320x240_256__Enter(gv); + 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,33 +69,125 @@ 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 -modex__320x240_256__Enter(global_game_variables_t *gv) +modexEnter(sword vq, global_game_variables_t *gv) { word i; dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */ - word CRTParms[] = { -// 0x5f00, /* horizontal total */ -// 0x3f01, /* horizontal display enable end */ - 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 */ -// 0x2013, /* offset/logical width */ - 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]); - /* width and height */ - //TODO WWWW + int CRTParmCount; + /* common mode X initiation stuff~ */ + modexsetBaseXMode(gv->video.page); + + 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=192; + gv->video.page[0].sh=144; + + /* 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=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() { + /* TODO restore original mode and palette */ + 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); @@ -114,40 +205,32 @@ modex__320x240_256__Enter(global_game_variables_t *gv) /* 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 */ - - /* send the CRTParms */ - for(i=0; isw; + 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; @@ -345,7 +428,6 @@ modexDrawBmp(page_t *page, int x, int y, bitmap_t *bmp) { 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) { @@ -414,10 +496,27 @@ 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; +modexDrawPlanarBuf(page_t *page, int x, int y, planar_buf_t *bmp) { + /* TODO - adapt from test code */ + int plane; + for(plane=0; plane < 4; plane++) + { + //fack + } +} + + +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; @@ -428,11 +527,6 @@ modex_sparky4_DrawBmpRegion(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 MOV ES, AX @@ -454,7 +548,17 @@ modex_sparky4_DrawBmpRegion(page_t *page, int x, int y, 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 @@ -478,24 +582,7 @@ modex_sparky4_DrawBmpRegion(page_t *page, int x, int y, DEC planeCounter JNZ PLANE_LOOP ; do all 4 planes } -} - -void -modexDrawPlanarBuf(page_t *page, int x, int y, planar_buf_t *bmp) { - /* TODO - adapt from test code */ - int plane; - for(plane=0; plane < 4; plane++) - { - //fack - } -} - - -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); -} +}//backup!*/ void modexDrawSpriteRegion(page_t *page, int x, int y, @@ -569,7 +656,6 @@ modexDrawSpriteRegion(page_t *page, int x, int y, } } - /* 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 * regions and the memory areas do not overlap. @@ -1112,7 +1198,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); @@ -1268,6 +1354,21 @@ 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; paly