1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\r
6 * Project 16 is free software; you can redistribute it and/or modify
\r
7 * it under the terms of the GNU General Public License as published by
\r
8 * the Free Software Foundation; either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * Project 16 is distributed in the hope that it will be useful,
\r
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 * GNU General Public License for more details.
\r
16 * You should have received a copy of the GNU General Public License
\r
17 * along with this program. If not, see <http://www.gnu.org/licenses/>, or
\r
18 * write to the Free Software Foundation, Inc., 51 Franklin Street,
\r
19 * Fifth Floor, Boston, MA 02110-1301 USA.
\r
26 #include "src/lib/16_vl.h"
\r
28 static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */
\r
30 //===========================================================================
\r
38 void VL_SetScreen (unsigned int crtc, int pelpan)
\r
40 // PROC VL_SetScreen crtc:WORD, pel:WORD
\r
41 // PUBLIC VL_SetScreen
\r
42 word TimeCount = *clockw;
\r
44 mov cx,[TimeCount] // if TimeCount goes up by two, the retrace
\r
45 add cx,2 // period was missed (an interrupt covered it)
\r
47 mov dx,STATUS_REGISTER_1
\r
49 // wait for a display signal to make sure the raster isn't in the middle
\r
55 SetScreen_waitdisplay:
\r
60 test al,1 //1 = display is disabled (HBL / VBL)
\r
61 jnz SetScreen_waitdisplay
\r
80 cmp [TimeCount],cx // will only happen if an interrupt is
\r
81 jae SetScreen_setcrtc // straddling the entire retrace period
\r
83 // when several succesive display not enableds occur,
\r
84 // the bottom of the screen has been hit
\r
88 jnz SetScreen_waitdisplay
\r
94 jnz SetScreen_waitdisplay
\r
100 jnz SetScreen_waitdisplay
\r
106 jnz SetScreen_waitdisplay
\r
112 jnz SetScreen_waitdisplay
\r
116 #ifdef __BORLANDC__
\r
120 #ifdef __BORLANDC__
\r
124 // for some reason, my XT's EGA card doesn't like word outs to the CRTC index...
\r
128 mov al,0ch //start address high register
\r
134 mov al,0dh //start address low register
\r
141 // set horizontal panning
\r
144 // mov al,ATR_PELPAN or 20h
\r
147 mov al,[BYTE PTR pelpan] //pel pan value
\r
149 #ifdef __BORLANDC__
\r
153 #ifdef __BORLANDC__
\r
163 ====================
\r
167 = Line witdh is in WORDS, 40 words is normal width for vgaplanegr
\r
169 ====================
\r
172 void VL_SetLineWidth (unsigned width, global_game_variables_t *gvar)
\r
177 // set wide virtual screen
\r
179 outport (CRTC_INDEX,CRTC_OFFSET+width*256);
\r
182 // set up lookup tables
\r
184 gvar->video.ofs.linewidth = width*2;
\r
188 for (i=0;i<MAXSCANLINES;i++)
\r
190 gvar->video.ofs.ylookup[i]=offset;
\r
191 offset += gvar->video.ofs.linewidth;
\r
196 =============================================================================
\r
200 To avoid snow, do a WaitVBL BEFORE calling these
\r
202 =============================================================================
\r
214 void VL_FillPalette (int red, int green, int blue)
\r
218 outportb (PAL_WRITE_REG,0);
\r
219 for (i=0;i<256;i++)
\r
221 outportb (PAL_DATA_REG,red);
\r
222 outportb (PAL_DATA_REG,green);
\r
223 outportb (PAL_DATA_REG,blue);
\r
227 //===========================================================================
\r
237 void VL_SetColor (int color, int red, int green, int blue)
\r
239 outportb (PAL_WRITE_REG,color);
\r
240 outportb (PAL_DATA_REG,red);
\r
241 outportb (PAL_DATA_REG,green);
\r
242 outportb (PAL_DATA_REG,blue);
\r
245 //===========================================================================
\r
255 void VL_GetColor (int color, int *red, int *green, int *blue)
\r
257 outportb (PAL_READ_REG,color);
\r
258 *red = inportb (PAL_DATA_REG);
\r
259 *green = inportb (PAL_DATA_REG);
\r
260 *blue = inportb (PAL_DATA_REG);
\r
263 //===========================================================================
\r
270 = If fast palette setting has been tested for, it is used
\r
271 = (some cards don't like outsb palette setting)
\r
276 void VL_SetPalette (byte far *palette, video_t *v)
\r
279 boolean fastpalette;
\r
280 fastpalette=v->fastpalette;
\r
282 // outportb (PAL_WRITE_REG,0);
\r
283 // for (i=0;i<768;i++)
\r
284 // outportb(PAL_DATA_REG,*palette++);
\r
287 mov dx,PAL_WRITE_REG
\r
290 mov dx,PAL_DATA_REG
\r
293 test [ss:fastpalette],1
\r
296 // set palette fast for cards that can take it
\r
303 // set palette slowly for some video cards
\r
305 #ifdef __BORLANDC__
\r
309 #ifdef __BORLANDC__
\r
313 #ifdef __BORLANDC__
\r
317 #ifdef __BORLANDC__
\r
327 #ifdef __BORLANDC__
\r
331 #ifdef __BORLANDC__
\r
337 v->fastpalette=fastpalette;
\r
341 //===========================================================================
\r
348 = This does not use the port string instructions,
\r
349 = due to some incompatabilities
\r
354 void VL_GetPalette (byte far *palette)
\r
358 outportb (PAL_READ_REG,0);
\r
359 for (i=0;i<768;i++)
\r
360 *palette++ = inportb(PAL_DATA_REG);
\r
364 //===========================================================================
\r
371 = Fades the current palette to the given color in the given number of steps
\r
376 void VL_FadeOut (int start, int end, int red, int green, int blue, int steps, video_t *v)
\r
378 int i,j,orig,delta;
\r
379 byte far *origptr, far *newptr;
\r
382 VL_GetPalette (&v->palette1[0][0]);
\r
383 _fmemcpy (v->palette2,v->palette1,PALSIZE);
\r
386 // fade through intermediate frames
\r
388 for (i=0;i<steps;i++)
\r
390 origptr = &v->palette1[start][0];
\r
391 newptr = &v->palette2[start][0];
\r
392 for (j=start;j<=end;j++)
\r
396 *newptr++ = orig + delta * i / steps;
\r
398 delta = green-orig;
\r
399 *newptr++ = orig + delta * i / steps;
\r
402 *newptr++ = orig + delta * i / steps;
\r
406 VL_SetPalette (&v->palette2[0][0], v);
\r
412 VL_FillPalette (red,green,blue);
\r
414 v->screenfaded = true;
\r
426 void VL_FadeIn (int start, int end, byte far *palette, int steps, video_t *v)
\r
431 VL_GetPalette (&v->palette1[0][0]);
\r
432 _fmemcpy (&v->palette2[0][0],&v->palette1[0][0],sizeof(v->palette1));
\r
438 // fade through intermediate frames
\r
440 for (i=0;i<steps;i++)
\r
442 for (j=start;j<=end;j++)
\r
444 delta = palette[j]-v->palette1[0][j];
\r
445 v->palette2[0][j] = v->palette1[0][j] + delta * i / steps;
\r
449 VL_SetPalette (&v->palette2[0][0], v);
\r
455 VL_SetPalette (palette, v);
\r
456 v->screenfaded = false;
\r
464 = VL_TestPaletteSet
\r
466 = Sets the palette with outsb, then reads it in and compares
\r
467 = If it compares ok, fastpalette is set to true.
\r
472 void VL_TestPaletteSet (video_t *v)
\r
476 for (i=0;i<768;i++)
\r
477 v->palette1[0][i] = i;
\r
479 v->fastpalette = true;
\r
480 VL_SetPalette (&v->palette1[0][0], v);
\r
481 VL_GetPalette (&v->palette2[0][0]);
\r
482 if (_fmemcmp (&v->palette1[0][0],&v->palette2[0][0],768))
\r
483 v->fastpalette = false;
\r
494 void VL_ColorBorder (int color, video_t *v)
\r
496 union REGS in, out;
\r
501 int86(0x10, &in, &out);
\r
502 v->bordercolor = color;
\r
507 =============================================================================
\r
511 =============================================================================
\r
514 //byte rightmasks[4] = {1,3,7,15};
\r
524 void VL_Plot (int x, int y, int color, global_game_variables_t *gvar)
\r
529 if(!gvar->video.VL_Started) return;
\r
533 //*(byte far *)MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+(gvar->video.ofs.ylookup[y]+(x>>2))) = color;
\r
534 //*(byte far *)MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+((y*gvar->video.page[0].stridew)+(x>>2))) = color;
\r
535 *(byte far *)MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+((y*gvar->video.page[0].stridew)+(x>>2))) = color;
\r
548 void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, global_game_variables_t *gvar)
\r
552 byte leftmask,rightmask;
\r
557 if(!gvar->video.VL_Started) return;
\r
560 leftmask = lclip[x&3];
\r
561 rightmask = rclip[(x+width-1)&3];
\r
562 midbytes = ((x+width+3)>>2) - xbyte - 2;
\r
564 //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+xbyte);
\r
565 dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*gvar->video.page[0].stridew)+xbyte);
\r
570 VGAMAPMASK(leftmask&rightmask);
\r
576 VGAMAPMASK(leftmask);
\r
580 _fmemset (dest,color,midbytes);
\r
583 VGAMAPMASK(rightmask);
\r
598 void VL_Vlin (int x, int y, int height, int color, global_game_variables_t *gvar)
\r
600 byte far *dest,mask;
\r
603 if(!gvar->video.VL_Started) return;
\r
608 //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));
\r
609 dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*gvar->video.page[0].stridew)+(x>>2));
\r
614 //dest += gvar->video.ofs.linewidth;
\r
615 dest += gvar->video.page[0].stridew;
\r
630 void VL_Bar (int x, int y, int width, int height, int color, global_game_variables_t *gvar)
\r
633 byte leftmask,rightmask;
\r
634 int midbytes,linedelta;
\r
638 if(!gvar->video.VL_Started) return;
\r
640 leftmask = lclip[x&3];
\r
641 rightmask = rclip[(x+width-1)&3];
\r
642 midbytes = ((x+width+3)>>2) - (x>>2) - 2;
\r
643 //linedelta = gvar->video.ofs.linewidth-(midbytes+1);
\r
644 linedelta = gvar->video.page[0].stridew-(midbytes+1);
\r
646 //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));
\r
647 dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*gvar->video.page[0].stridew)+(x>>2));
\r
652 VGAMAPMASK(leftmask&rightmask);
\r
656 //dest += gvar->video.ofs.linewidth;
\r
657 dest += gvar->video.page[0].stridew;
\r
665 VGAMAPMASK(leftmask);
\r
669 _fmemset (dest,color,midbytes);
\r
672 VGAMAPMASK(rightmask);
\r
681 //==========================================================================
\r
688 = Draws a block of data to the screen.
\r
693 void VL_MemToScreen (byte far *source, int width, int height, int x, int y, global_game_variables_t *gvar)
\r
695 byte far *screen,far *dest,mask;
\r
699 //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));
\r
700 dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*gvar->video.page[0].stridew)+(x>>2));
\r
703 for (plane = 0; plane<4; plane++)
\r
711 //for (y=0;y<height;y++,screen+=gvar->video.ofs.linewidth,source+=width)
\r
712 for (y=0;y<height;y++,screen+=gvar->video.page[0].stridew,source+=width)
\r
713 _fmemcpy (screen,source,width);
\r
717 //==========================================================================
\r
722 VL_WaitVBL ******** NEW *********
\r
724 Wait for the vertical retrace (returns before the actual vertical sync)
\r
729 void VL_WaitVBL(word num)
\r
731 //PROC VL_WaitVBL num:WORD
\r
732 //PUBLIC VL_WaitVBL
\r
737 #ifdef __BORLANDC__
\r
741 mov dx,STATUS_REGISTER_1
\r
745 // wait for a display signal to make sure the raster isn't in the middle
\r
748 #ifdef __BORLANDC__
\r
752 #ifdef __BORLANDC__
\r
760 #ifdef __BORLANDC__
\r
764 #ifdef __BORLANDC__
\r
777 //===========================================================================
\r
779 #define VGAWRITEMODE(x) asm{
\r
792 #define VGAMAPMASK(x) asm{
\r
801 #define VGAREADMAP(x) asm{
\r
810 #define EGABITMASK(x) asm{
\r
812 mov ax,GC_BITMASK+256*x
\r
817 void VGAWRITEMODE(byte x)
\r
833 void VGAMAPMASK(byte x)
\r
845 void VGAREADMAP(byte x)
\r
857 void VGABITMASK(byte x)
\r
862 mov ax,GC_BITMASK+q
\r
868 //===========================================================================
\r