X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fmodex16.c;h=5c0cab2c0031bc35accfac37ab355a60a6c1b114;hb=6340f73596b16d6b718e3ddca2b09f13ce521f6d;hp=63231108b1968d7f7d3b4606ac29bdf863714ab4;hpb=2eb78909ad7e8079fbec7dbe794fe0eac01e15de;p=16.git diff --git a/src/lib/modex16.c b/src/lib/modex16.c index 63231108..5c0cab2c 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,101 +86,66 @@ 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 */ + struct vga_mode_params cm; int CRTParmCount; - /* common mode X initiation stuff~ */ - modexsetBaseXMode(gv->video.page); + + vgaSetMode(VGA_256_COLOR_MODE); + vga_enable_256color_modex(); + update_state_from_vga(); + vga_read_crtc_mode(&cm); 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; + 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 + + // 320x240 mode 60Hz + cm.horizontal_total=0x5f + 5; /* CRTC[0] -5 */ + cm.horizontal_display_end=0x4f + 1; /* CRTC[1] -1 */ + cm.horizontal_blank_start=0x50 + 1; /* CRTC[2] */ + cm.horizontal_blank_end=0x82 + 1; /* CRTC[3] bit 0-4 & CRTC[5] bit 7 */ + cm.horizontal_start_retrace=0x54;/* CRTC[4] */ + cm.horizontal_end_retrace=0x80; /* CRTC[5] bit 0-4 */ + //cm.horizontal_start_delay_after_total=0x3e; /* CRTC[3] bit 5-6 */ + //cm.horizontal_start_delay_after_retrace=0x41; /* CRTC[5] bit 5-6 */ + cm.vertical_total = 0x20D + 2; + cm.vertical_start_retrace = 0x1EA; + cm.vertical_end_retrace = 0x1EC; + cm.vertical_display_end = 480; + cm.vertical_blank_start = 0x1E7 + 1; + cm.vertical_blank_end = 0x206 + 1; + cm.clock_select = 0; /* misc register = 0xE3 25MHz */ + cm.vsync_neg = 1; + cm.hsync_neg = 1; + break; + case 2: // TODO: 160x120 according to ModeX_160x120regs + return; + case 3: // TODO: 160x120 according to ModeX_320x200regs + return; + case 4: // TODO: 160x120 according to ModeX_192x144regs + return; + case 5: // TODO: 160x120 according to ModeX_256x192regs + return; + default: + return; + } - /* send the CRTParms */ - for(i=0; ivideo.page[0].tilesw = gv->video.page[0].sw/TILEWH; @@ -193,39 +158,8 @@ modexEnter(sword vq, global_game_variables_t *gv) 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); - - /* 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 */ + /* TODO restore original mode and palette */ + vgaSetMode(TEXT_MODE); } page_t @@ -394,248 +328,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; - //const int px, py; - int i; - const int px=x-page->dx; - const int py=y-page->dy; - for(plane=0; plane < 4; plane++) { - i=(rw/4)+((p->pwidth)*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+=p->pwidth]), rw/4); - //} - } - x=px; - y=py; - } -} - - -/*temp*/ -void -modexDrawPBuf(page_t *page, int x, int y, planar_buf_t *p, boolean sprite) -{ - int plane; - int i; -// byte near *buff; - const int px=x; - const int 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 @@ -1193,47 +886,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' @@ -1253,26 +925,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) @@ -1377,7 +1034,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