X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_vl_1.c;h=b92bdd14cebc255a279a648e7d182b3c43ca8650;hb=eefd43fada99517f9ad662510392e898412ec867;hp=a6928b27a3d5d6f84796b08fa6e9fc13f1f276cc;hpb=424d6f05d9aaa0000302df70be10c2598886a030;p=16.git diff --git a/src/lib/16_vl_1.c b/src/lib/16_vl_1.c index a6928b27..b92bdd14 100755 --- a/src/lib/16_vl_1.c +++ b/src/lib/16_vl_1.c @@ -1,21 +1,21 @@ /* Project 16 Source Code~ - * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover + * Copyright (C) 2012-2019 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover * * This file is part of Project 16. * - * Project 16 is free software; you can redistribute it and/or modify + * 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 * (at your option) any later version. * - * Project 16 is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * Project 16 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see , or - * write to the Free Software Foundation, Inc., 51 Franklin Street, + * write to the Free Software Foundation, Inc., 51 Franklin Street, * Fifth Floor, Boston, MA 02110-1301 USA. * */ @@ -25,6 +25,175 @@ #include #include "src/lib/16_vl.h" +static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */ +//#define VGASTRIDEVARIABLE vga_state.vga_stride +#define VGASTRIDEVARIABLE gvar->video.page[0].stridew + +//=========================================================================== + +//============== +// +// VL_SetScreen +// +//============== + +void VL_SetScreen (unsigned int crtc, int pelpan) +{ +// PROC VL_SetScreen crtc:WORD, pel:WORD +// PUBLIC VL_SetScreen + word TimeCount = *clockw; + __asm { + mov cx,[TimeCount] // if TimeCount goes up by two, the retrace + add cx,2 // period was missed (an interrupt covered it) + + mov dx,STATUS_REGISTER_1 + + // wait for a display signal to make sure the raster isn't in the middle + // of a sync + +#ifdef __BORLANDC__ + } +#endif +SetScreen_waitdisplay: +#ifdef __BORLANDC__ + __asm { +#endif + in al,dx + test al,1 //1 = display is disabled (HBL / VBL) + jnz SetScreen_waitdisplay + +#ifdef __BORLANDC__ + } +#endif +SetScreen_loop: +#ifdef __BORLANDC__ + __asm { +#endif + sti + jmp SetScreen_skip1 + cli +#ifdef __BORLANDC__ + } +#endif +SetScreen_skip1: +#ifdef __BORLANDC__ + __asm { +#endif + cmp [TimeCount],cx // will only happen if an interrupt is + jae SetScreen_setcrtc // straddling the entire retrace period + + // when several succesive display not enableds occur, + // the bottom of the screen has been hit + + in al,dx + test al,8 + jnz SetScreen_waitdisplay + test al,1 + jz SetScreen_loop + + in al,dx + test al,8 + jnz SetScreen_waitdisplay + test al,1 + jz SetScreen_loop + + in al,dx + test al,8 + jnz SetScreen_waitdisplay + test al,1 + jz SetScreen_loop + + in al,dx + test al,8 + jnz SetScreen_waitdisplay + test al,1 + jz SetScreen_loop + + in al,dx + test al,8 + jnz SetScreen_waitdisplay + test al,1 + jz SetScreen_loop + +#ifdef __BORLANDC__ + } +#endif +SetScreen_setcrtc: +#ifdef __BORLANDC__ + __asm { +#endif + // set CRTC start + // for some reason, my XT's EGA card doesn't like word outs to the CRTC index... + + mov cx,[crtc] + mov dx,CRTC_INDEX + mov al,0ch //start address high register + out dx,al + inc dx + mov al,ch + out dx,al + dec dx + mov al,0dh //start address low register + out dx,al + mov al,cl + inc dx + out dx,al + + + // set horizontal panning + + mov dx,ATR_INDEX +// mov al,ATR_PELPAN or 20h + out dx,al + jmp SetScreen_done + mov al,[BYTE PTR pelpan] //pel pan value + out dx,al +#ifdef __BORLANDC__ + } +#endif +SetScreen_done: +#ifdef __BORLANDC__ + __asm { +#endif +// sti + +// ret + } +} + +/* +==================== += += VL_SetLineWidth += += Line witdh is in WORDS, 40 words is normal width for vgaplanegr += +==================== +*/ +#if 0 +void VL_SetLineWidth (unsigned width, global_game_variables_t *gvar) +{ + int i,offset; + +// +// set wide virtual screen +// + outport (CRTC_INDEX,CRTC_OFFSET+width*256); + +// +// set up lookup tables +// + gvar->video.ofs.linewidth = width*2; + + offset = 0; + + for (i=0;ivideo.ofs.ylookup[i]=offset; + offset += gvar->video.ofs.linewidth; + } +} +#endif /* ============================================================================= @@ -49,7 +218,7 @@ void VL_FillPalette (int red, int green, int blue) int i; outportb (PAL_WRITE_REG,0); - for (i=0;i<256;i++) + for (i=0;i<256;i++) { outportb (PAL_DATA_REG,red); outportb (PAL_DATA_REG,green); @@ -113,7 +282,7 @@ void VL_SetPalette (byte far *palette, video_t *v) fastpalette=v->fastpalette; // outportb (PAL_WRITE_REG,0); -// for (i=0;i<768;i++) +// for (i=0;i<768;i++) // outportb(PAL_DATA_REG,*palette++); __asm { @@ -126,14 +295,14 @@ void VL_SetPalette (byte far *palette, video_t *v) test [ss:fastpalette],1 jz slowset // -// set palette fast for cards that can take it +// set palette fast for cards that can take it // //mov cx,768 //rep outsb //jmp done // -// set palette slowly for some video cards +// set palette slowly for some video cards // #ifdef __BORLANDC__ } @@ -189,7 +358,7 @@ void VL_GetPalette (byte far *palette) int i; outportb (PAL_READ_REG,0); - for (i=0;i<768;i++) + for (i=0;i<768;i++) *palette++ = inportb(PAL_DATA_REG); } @@ -201,7 +370,7 @@ void VL_GetPalette (byte far *palette) = = VL_FadeOut = -= Fades the current palette to the given color in the given number of steps += Fades the current palette to the given color in the given number of steps = ================= */ @@ -218,11 +387,11 @@ void VL_FadeOut (int start, int end, int red, int green, int blue, int steps, vi // // fade through intermediate frames // - for (i=0;ipalette1[start][0]; newptr = &v->palette2[start][0]; - for (j=start;j<=end;j++) + for (j=start;j<=end;j++) { orig = *origptr++; delta = red-orig; @@ -270,9 +439,9 @@ void VL_FadeIn (int start, int end, byte far *palette, int steps, video_t *v) // // fade through intermediate frames // - for (i=0;ipalette1[0][j]; v->palette2[0][j] = v->palette1[0][j] + delta * i / steps; @@ -296,7 +465,7 @@ void VL_FadeIn (int start, int end, byte far *palette, int steps, video_t *v) = = VL_TestPaletteSet = -= Sets the palette with outsb, then reads it in and compares += Sets the palette with outsb, then reads it in and compares = If it compares ok, fastpalette is set to true. = ================= @@ -306,7 +475,7 @@ void VL_TestPaletteSet (video_t *v) { int i; - for (i=0;i<768;i++) + for (i=0;i<768;i++) v->palette1[0][i] = i; v->fastpalette = true; @@ -316,6 +485,25 @@ void VL_TestPaletteSet (video_t *v) v->fastpalette = false; } +/* +================== += += VL_ColorBorder += +================== +*/ + +void VL_ColorBorder (int color, video_t *v) +{ + union REGS in, out; + + in.h.ah = 0x10; + in.h.al = 0x01; + in.h.bh = color; + int86(0x10, &in, &out); + v->bordercolor = color; +} + /* ============================================================================= @@ -335,14 +523,18 @@ void VL_TestPaletteSet (video_t *v) ================= */ -void VL_Plot (int x, int y, int color, ofs_t *ofs) +void VL_Plot (int x, int y, int color, global_game_variables_t *gvar) { byte mask; VCLIPDEF + if(!gvar->video.VL_Started) return; + mask = pclip[x&3]; VGAMAPMASK(mask); - *(byte far *)MK_FP(SCREENSEG,ofs->bufferofs+(ofs->ylookup[y]+(x>>2))) = color; + //*(byte far *)MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+(gvar->video.ofs.ylookup[y]+(x>>2))) = color; + //*(byte far *)MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+((y*VGASTRIDEVARIABLE)+(x>>2))) = color; + *(byte far *)MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+((y*VGASTRIDEVARIABLE)+(x>>2))) = color; VGAMAPMASK(15); } @@ -355,7 +547,7 @@ void VL_Plot (int x, int y, int color, ofs_t *ofs) ================= */ -void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs) +void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, global_game_variables_t *gvar) { unsigned xbyte; byte far *dest; @@ -364,16 +556,19 @@ void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs LRCLIPDEF + if(!gvar->video.VL_Started) return; + xbyte = x>>2; leftmask = lclip[x&3]; rightmask = rclip[(x+width-1)&3]; midbytes = ((x+width+3)>>2) - xbyte - 2; - dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+xbyte); + //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+xbyte); + dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+xbyte); if (midbytes<0) { - // all in one byte + // all in one byte VGAMAPMASK(leftmask&rightmask); *dest = color; VGAMAPMASK(15); @@ -402,20 +597,24 @@ void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs ================= */ -void VL_Vlin (int x, int y, int height, int color, ofs_t *ofs) +void VL_Vlin (int x, int y, int height, int color, global_game_variables_t *gvar) { byte far *dest,mask; VCLIPDEF + if(!gvar->video.VL_Started) return; + mask = pclip[x&3]; VGAMAPMASK(mask); - dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2)); + //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2)); + dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(x>>2)); while (height--) { *dest = color; - dest += ofs->linewidth; + //dest += gvar->video.ofs.linewidth; + dest += VGASTRIDEVARIABLE; } VGAMAPMASK(15); @@ -430,7 +629,7 @@ void VL_Vlin (int x, int y, int height, int color, ofs_t *ofs) ================= */ -void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs) +void VL_Bar (int x, int y, int width, int height, int color, global_game_variables_t *gvar) { byte far *dest; byte leftmask,rightmask; @@ -438,21 +637,26 @@ void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs) LRCLIPDEF + if(!gvar->video.VL_Started) return; + leftmask = lclip[x&3]; rightmask = rclip[(x+width-1)&3]; midbytes = ((x+width+3)>>2) - (x>>2) - 2; - linedelta = ofs->linewidth-(midbytes+1); + //linedelta = gvar->video.ofs.linewidth-(midbytes+1); + linedelta = VGASTRIDEVARIABLE-(midbytes+1); - dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2)); + //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2)); + dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(x>>2)); if (midbytes<0) { - // all in one byte + // all in one byte VGAMAPMASK(leftmask&rightmask); while (height--) { *dest = color; - dest += ofs->linewidth; + //dest += gvar->video.ofs.linewidth; + dest += VGASTRIDEVARIABLE; } VGAMAPMASK(15); return; @@ -476,13 +680,50 @@ void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs) VGAMAPMASK(15); } +//========================================================================== + +/* +================= += += VL_MemToScreen += += Draws a block of data to the screen. += +================= +*/ + +void VL_MemToScreen (byte far *source, int width, int height, int x, int y, global_game_variables_t *gvar) +{ + byte far *screen,far *dest,mask; + int plane; + + width>>=2; + //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2)); + dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(x>>2)); + mask = 1 << (x&3); + + for (plane = 0; plane<4; plane++) + { + VGAMAPMASK(mask); + mask <<= 1; + if (mask == 16) + mask = 1; + + screen = dest; + //for (y=0;yvideo.ofs.linewidth,source+=width) + for (y=0;y