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
29 =============================================================================
\r
33 To avoid snow, do a WaitVBL BEFORE calling these
\r
35 =============================================================================
\r
47 void VL_FillPalette (int red, int green, int blue)
\r
51 outportb (PAL_WRITE_REG,0);
\r
54 outportb (PAL_DATA_REG,red);
\r
55 outportb (PAL_DATA_REG,green);
\r
56 outportb (PAL_DATA_REG,blue);
\r
60 //===========================================================================
\r
70 void VL_SetColor (int color, int red, int green, int blue)
\r
72 outportb (PAL_WRITE_REG,color);
\r
73 outportb (PAL_DATA_REG,red);
\r
74 outportb (PAL_DATA_REG,green);
\r
75 outportb (PAL_DATA_REG,blue);
\r
78 //===========================================================================
\r
88 void VL_GetColor (int color, int *red, int *green, int *blue)
\r
90 outportb (PAL_READ_REG,color);
\r
91 *red = inportb (PAL_DATA_REG);
\r
92 *green = inportb (PAL_DATA_REG);
\r
93 *blue = inportb (PAL_DATA_REG);
\r
96 //===========================================================================
\r
103 = If fast palette setting has been tested for, it is used
\r
104 = (some cards don't like outsb palette setting)
\r
109 void VL_SetPalette (byte far *palette, video_t *v)
\r
112 boolean fastpalette;
\r
113 fastpalette=v->fastpalette;
\r
115 // outportb (PAL_WRITE_REG,0);
\r
116 // for (i=0;i<768;i++)
\r
117 // outportb(PAL_DATA_REG,*palette++);
\r
120 mov dx,PAL_WRITE_REG
\r
123 mov dx,PAL_DATA_REG
\r
126 test [ss:fastpalette],1
\r
129 // set palette fast for cards that can take it
\r
136 // set palette slowly for some video cards
\r
138 #ifdef __BORLANDC__
\r
142 #ifdef __BORLANDC__
\r
146 #ifdef __BORLANDC__
\r
150 #ifdef __BORLANDC__
\r
160 #ifdef __BORLANDC__
\r
164 #ifdef __BORLANDC__
\r
170 v->fastpalette=fastpalette;
\r
174 //===========================================================================
\r
181 = This does not use the port string instructions,
\r
182 = due to some incompatabilities
\r
187 void VL_GetPalette (byte far *palette)
\r
191 outportb (PAL_READ_REG,0);
\r
192 for (i=0;i<768;i++)
\r
193 *palette++ = inportb(PAL_DATA_REG);
\r
197 //===========================================================================
\r
204 = Fades the current palette to the given color in the given number of steps
\r
209 void VL_FadeOut (int start, int end, int red, int green, int blue, int steps, video_t *v)
\r
211 int i,j,orig,delta;
\r
212 byte far *origptr, far *newptr;
\r
215 VL_GetPalette (&v->palette1[0][0]);
\r
216 _fmemcpy (v->palette2,v->palette1,PALSIZE);
\r
219 // fade through intermediate frames
\r
221 for (i=0;i<steps;i++)
\r
223 origptr = &v->palette1[start][0];
\r
224 newptr = &v->palette2[start][0];
\r
225 for (j=start;j<=end;j++)
\r
229 *newptr++ = orig + delta * i / steps;
\r
231 delta = green-orig;
\r
232 *newptr++ = orig + delta * i / steps;
\r
235 *newptr++ = orig + delta * i / steps;
\r
239 VL_SetPalette (&v->palette2[0][0], v);
\r
245 VL_FillPalette (red,green,blue);
\r
247 v->screenfaded = true;
\r
259 void VL_FadeIn (int start, int end, byte far *palette, int steps, video_t *v)
\r
264 VL_GetPalette (&v->palette1[0][0]);
\r
265 _fmemcpy (&v->palette2[0][0],&v->palette1[0][0],sizeof(v->palette1));
\r
271 // fade through intermediate frames
\r
273 for (i=0;i<steps;i++)
\r
275 for (j=start;j<=end;j++)
\r
277 delta = palette[j]-v->palette1[0][j];
\r
278 v->palette2[0][j] = v->palette1[0][j] + delta * i / steps;
\r
282 VL_SetPalette (&v->palette2[0][0], v);
\r
288 VL_SetPalette (palette, v);
\r
289 v->screenfaded = false;
\r
297 = VL_TestPaletteSet
\r
299 = Sets the palette with outsb, then reads it in and compares
\r
300 = If it compares ok, fastpalette is set to true.
\r
305 void VL_TestPaletteSet (video_t *v)
\r
309 for (i=0;i<768;i++)
\r
310 v->palette1[0][i] = i;
\r
312 v->fastpalette = true;
\r
313 VL_SetPalette (&v->palette1[0][0], v);
\r
314 VL_GetPalette (&v->palette2[0][0]);
\r
315 if (_fmemcmp (&v->palette1[0][0],&v->palette2[0][0],768))
\r
316 v->fastpalette = false;
\r
321 =============================================================================
\r
325 =============================================================================
\r
328 //byte rightmasks[4] = {1,3,7,15};
\r
338 void VL_Plot (int x, int y, int color, ofs_t *ofs)
\r
345 *(byte far *)MK_FP(SCREENSEG,ofs->bufferofs+(ofs->ylookup[y]+(x>>2))) = color;
\r
358 void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs)
\r
362 byte leftmask,rightmask;
\r
368 leftmask = lclip[x&3];
\r
369 rightmask = rclip[(x+width-1)&3];
\r
370 midbytes = ((x+width+3)>>2) - xbyte - 2;
\r
372 dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+xbyte);
\r
377 VGAMAPMASK(leftmask&rightmask);
\r
383 VGAMAPMASK(leftmask);
\r
387 _fmemset (dest,color,midbytes);
\r
390 VGAMAPMASK(rightmask);
\r
405 void VL_Vlin (int x, int y, int height, int color, ofs_t *ofs)
\r
407 byte far *dest,mask;
\r
413 dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2));
\r
418 dest += ofs->linewidth;
\r
433 void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs)
\r
436 byte leftmask,rightmask;
\r
437 int midbytes,linedelta;
\r
441 leftmask = lclip[x&3];
\r
442 rightmask = rclip[(x+width-1)&3];
\r
443 midbytes = ((x+width+3)>>2) - (x>>2) - 2;
\r
444 linedelta = ofs->linewidth-(midbytes+1);
\r
446 dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2));
\r
451 VGAMAPMASK(leftmask&rightmask);
\r
455 dest += ofs->linewidth;
\r
463 VGAMAPMASK(leftmask);
\r
467 _fmemset (dest,color,midbytes);
\r
470 VGAMAPMASK(rightmask);
\r
483 VL_WaitVBL ******** NEW *********
\r
485 Wait for the vertical retrace (returns before the actual vertical sync)
\r
490 void VL_WaitVBL(word num)
\r
492 //PROC VL_WaitVBL num:WORD
\r
493 //PUBLIC VL_WaitVBL
\r
498 #ifdef __BORLANDC__
\r
502 mov dx,STATUS_REGISTER_1
\r
506 // wait for a display signal to make sure the raster isn't in the middle
\r
509 #ifdef __BORLANDC__
\r
513 #ifdef __BORLANDC__
\r
521 #ifdef __BORLANDC__
\r
525 #ifdef __BORLANDC__
\r
538 //===========================================================================
\r
540 void VGAMAPMASK(byte x)
\r
552 void VGAWRITEMODE(byte x)
\r
568 void VGAREADMAP(byte x)
\r
580 //===========================================================================
\r