X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16.c;h=0aa6904b1daa289ca79646d456cb9a4f5122ef17;hb=900779b8b2ce8c05c3df897d3ae3fa5d8cb414c6;hp=fe358fcee744b89a9eb8bf272d7367271f5376e8;hpb=71e03faf012169d05f67873dacded16f79b6e59e;p=16.git diff --git a/src/lib/modex16.c b/src/lib/modex16.c index fe358fce..0aa6904b 100755 --- a/src/lib/modex16.c +++ b/src/lib/modex16.c @@ -1,11 +1,11 @@ /* Project 16 Source Code~ - * Copyright (C) 2012-2015 sparky4 & pngwen & andrius4669 + * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 * * 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 + * the Free Software Foundation; either verson 3 of the License, or * (at your option) any later version. * * Project 16 is distributed in the hope that it will be useful, @@ -35,7 +35,7 @@ static byte tmppal[PAL_SIZE]; // setvideo() - This function Manages the video modes // // // ///////////////////////////////////////////////////////////////////////////// -void VGAmodeX(sword vq, global_game_variables_t *gv) +void VGAmodeX(sword vq, boolean cmem, global_game_variables_t *gv) { union REGS in, out; @@ -54,7 +54,7 @@ void VGAmodeX(sword vq, global_game_variables_t *gv) //int86(0x10, &in, &out); gv->video.old_mode = vgaGetMode();//out.h.al; // enter mode - modexEnter(vq, gv); + modexEnter(vq, cmem, gv); break; } } @@ -86,32 +86,68 @@ vgaGetMode() } /* -========================= Entry Points ==========================- */ -void -modexEnter(sword vq, global_game_variables_t *gv) +void modexEnter(sword vq, boolean cmem, global_game_variables_t *gv) { word i; dword far*ptr=(dword far*)VGA; /* used for faster screen clearing */ int CRTParmCount; /* common mode X initiation stuff~ */ - modexsetBaseXMode(gv->video.page); + modexsetBaseXMode(); switch(vq) { case 1: - CRTParmCount = sizeof(ModeX_320x240regs) / sizeof(ModeX_320x240regs[0]); + //CRTParmCount = sizeof(ModeX_320x240regs) / sizeof(ModeX_320x240regs[0]); /* width and height */ - gv->video.page[0].sw=320; - gv->video.page[0].sh=240; + gv->video.page[0].sw=vga_state.vga_width = 320; // VGA lib currently does not update this + gv->video.page[0].sh=vga_state.vga_height = 240; // VGA lib currently does not update this /* send the CRTParms */ - for(i=0; ivideo.page[0].tilesw = gv->video.page[0].sw/TILEWH; @@ -193,8 +215,8 @@ modexEnter(sword vq, global_game_variables_t *gv) void modexLeave() { - /* TODO restore original mode and palette */ - vgaSetMode(TEXT_MODE); + /* TODO restore original mode and palette */ + vgaSetMode(TEXT_MODE); } // setBaseXMode() does the initialization to make the VGA ready to @@ -202,30 +224,12 @@ modexLeave() { // 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) +modexsetBaseXMode() { - 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 */ + vga_enable_256color_modex(); + update_state_from_vga(); } page_t @@ -394,247 +398,7 @@ modexClearRegion(page_t *page, int x, int y, int w, int h, byte color) { } } -//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) -{ - int plane; - int px, py, i; - px=x; - py=y; - for(plane=0; plane < 4; plane++) { - i=(rx/4)+((rx/4)*ry); - modexSelectPlane(PLANE(plane+x)); - for(; y < py+rh; 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)), &(p->plane[plane][i+=rw]), rw/4); - //} - } - x=px; - y=py; - } -} - - -/*temp*/ -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; - } - } - } -} - -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 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 -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; - 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 - } -} +/* moved to src/lib/modex16/16render.c */ /* 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 @@ -1192,47 +956,26 @@ void modexhlin(page_t *page, word xl, word xh, word y, word 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) +void modexprint(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str, boolean q) { - word i, s, o, w, j, xp; - byte l[1024]; - word addr = (word) l; - word chw=0; + word s, o, w; + word addr = (word) romFontsData.l; byte c; - //byte near *bakapee; - - switch(t) - { - case 0: - w=14; - break; - case 1: - w=8; - break; - case 2: - w=8; - break; - case 3: - w=16; - break; - default: - t=3; - w=16; - break; - } s=romFonts[t].seg; o=romFonts[t].off; + w=romFonts[t].charSize; + romFontsData.chw=0; for(; *str != '\0'; str++) { c = (*str); if((c=='\n'/* || c=="\ -"*/) || chw +"*/) || romFontsData.chw >=page->width) { - chw=0; - y+=w; + romFontsData.chw=0; + y+=romFonts[t].charSize; continue; } //load the letter 'A' @@ -1252,26 +995,11 @@ 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) - { - modexputPixel(page, x+xp+chw, y+i, l[i] & j ? col:bgcol); - xp++; - j>>=1; - } - } - chw += xp; + modexDrawCharPBuf(page, x, y, t, col, bgcol, q); + + //if(!q) getch(); } - //_nfree(bakapee); } void modexprintbig(page_t *page, word x, word y, word t, word col, word bgcol, const byte *str) @@ -1376,7 +1104,7 @@ void cls(page_t *page, byte color, byte *Where) /* set map mask to all 4 planes */ outpw(SC_INDEX, 0xff02); //_fmemset(VGA, color, 16000); - _fmemset(Where, color, page->width*(page->height)); + _fmemset(Where, color, page->width*(page->height)/4); } void