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
193 gvar->video.ofs.displayofs = 0;
\r
194 gvar->video.ofs.bufferofs = gvar->video.page[0].width*gvar->video.page[0].height;//gvar->video.page[0].pagesize;
\r
198 =============================================================================
\r
202 To avoid snow, do a WaitVBL BEFORE calling these
\r
204 =============================================================================
\r
216 void VL_FillPalette (int red, int green, int blue)
\r
220 outportb (PAL_WRITE_REG,0);
\r
221 for (i=0;i<256;i++)
\r
223 outportb (PAL_DATA_REG,red);
\r
224 outportb (PAL_DATA_REG,green);
\r
225 outportb (PAL_DATA_REG,blue);
\r
229 //===========================================================================
\r
239 void VL_SetColor (int color, int red, int green, int blue)
\r
241 outportb (PAL_WRITE_REG,color);
\r
242 outportb (PAL_DATA_REG,red);
\r
243 outportb (PAL_DATA_REG,green);
\r
244 outportb (PAL_DATA_REG,blue);
\r
247 //===========================================================================
\r
257 void VL_GetColor (int color, int *red, int *green, int *blue)
\r
259 outportb (PAL_READ_REG,color);
\r
260 *red = inportb (PAL_DATA_REG);
\r
261 *green = inportb (PAL_DATA_REG);
\r
262 *blue = inportb (PAL_DATA_REG);
\r
265 //===========================================================================
\r
272 = If fast palette setting has been tested for, it is used
\r
273 = (some cards don't like outsb palette setting)
\r
278 void VL_SetPalette (byte far *palette, video_t *v)
\r
281 boolean fastpalette;
\r
282 fastpalette=v->fastpalette;
\r
284 // outportb (PAL_WRITE_REG,0);
\r
285 // for (i=0;i<768;i++)
\r
286 // outportb(PAL_DATA_REG,*palette++);
\r
289 mov dx,PAL_WRITE_REG
\r
292 mov dx,PAL_DATA_REG
\r
295 test [ss:fastpalette],1
\r
298 // set palette fast for cards that can take it
\r
305 // set palette slowly for some video cards
\r
307 #ifdef __BORLANDC__
\r
311 #ifdef __BORLANDC__
\r
315 #ifdef __BORLANDC__
\r
319 #ifdef __BORLANDC__
\r
329 #ifdef __BORLANDC__
\r
333 #ifdef __BORLANDC__
\r
339 v->fastpalette=fastpalette;
\r
343 //===========================================================================
\r
350 = This does not use the port string instructions,
\r
351 = due to some incompatabilities
\r
356 void VL_GetPalette (byte far *palette)
\r
360 outportb (PAL_READ_REG,0);
\r
361 for (i=0;i<768;i++)
\r
362 *palette++ = inportb(PAL_DATA_REG);
\r
366 //===========================================================================
\r
373 = Fades the current palette to the given color in the given number of steps
\r
378 void VL_FadeOut (int start, int end, int red, int green, int blue, int steps, video_t *v)
\r
380 int i,j,orig,delta;
\r
381 byte far *origptr, far *newptr;
\r
384 VL_GetPalette (&v->palette1[0][0]);
\r
385 _fmemcpy (v->palette2,v->palette1,PALSIZE);
\r
388 // fade through intermediate frames
\r
390 for (i=0;i<steps;i++)
\r
392 origptr = &v->palette1[start][0];
\r
393 newptr = &v->palette2[start][0];
\r
394 for (j=start;j<=end;j++)
\r
398 *newptr++ = orig + delta * i / steps;
\r
400 delta = green-orig;
\r
401 *newptr++ = orig + delta * i / steps;
\r
404 *newptr++ = orig + delta * i / steps;
\r
408 VL_SetPalette (&v->palette2[0][0], v);
\r
414 VL_FillPalette (red,green,blue);
\r
416 v->screenfaded = true;
\r
428 void VL_FadeIn (int start, int end, byte far *palette, int steps, video_t *v)
\r
433 VL_GetPalette (&v->palette1[0][0]);
\r
434 _fmemcpy (&v->palette2[0][0],&v->palette1[0][0],sizeof(v->palette1));
\r
440 // fade through intermediate frames
\r
442 for (i=0;i<steps;i++)
\r
444 for (j=start;j<=end;j++)
\r
446 delta = palette[j]-v->palette1[0][j];
\r
447 v->palette2[0][j] = v->palette1[0][j] + delta * i / steps;
\r
451 VL_SetPalette (&v->palette2[0][0], v);
\r
457 VL_SetPalette (palette, v);
\r
458 v->screenfaded = false;
\r
466 = VL_TestPaletteSet
\r
468 = Sets the palette with outsb, then reads it in and compares
\r
469 = If it compares ok, fastpalette is set to true.
\r
474 void VL_TestPaletteSet (video_t *v)
\r
478 for (i=0;i<768;i++)
\r
479 v->palette1[0][i] = i;
\r
481 v->fastpalette = true;
\r
482 VL_SetPalette (&v->palette1[0][0], v);
\r
483 VL_GetPalette (&v->palette2[0][0]);
\r
484 if (_fmemcmp (&v->palette1[0][0],&v->palette2[0][0],768))
\r
485 v->fastpalette = false;
\r
490 =============================================================================
\r
494 =============================================================================
\r
497 //byte rightmasks[4] = {1,3,7,15};
\r
507 void VL_Plot (int x, int y, int color, ofs_t *ofs)
\r
514 *(byte far *)MK_FP(SCREENSEG,ofs->bufferofs+(ofs->ylookup[y]+(x>>2))) = color;
\r
527 void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, ofs_t *ofs)
\r
531 byte leftmask,rightmask;
\r
537 leftmask = lclip[x&3];
\r
538 rightmask = rclip[(x+width-1)&3];
\r
539 midbytes = ((x+width+3)>>2) - xbyte - 2;
\r
541 dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+xbyte);
\r
546 VGAMAPMASK(leftmask&rightmask);
\r
552 VGAMAPMASK(leftmask);
\r
556 _fmemset (dest,color,midbytes);
\r
559 VGAMAPMASK(rightmask);
\r
574 void VL_Vlin (int x, int y, int height, int color, ofs_t *ofs)
\r
576 byte far *dest,mask;
\r
582 dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2));
\r
587 dest += ofs->linewidth;
\r
602 void VL_Bar (int x, int y, int width, int height, int color, ofs_t *ofs)
\r
605 byte leftmask,rightmask;
\r
606 int midbytes,linedelta;
\r
610 leftmask = lclip[x&3];
\r
611 rightmask = rclip[(x+width-1)&3];
\r
612 midbytes = ((x+width+3)>>2) - (x>>2) - 2;
\r
613 linedelta = ofs->linewidth-(midbytes+1);
\r
615 dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2));
\r
620 VGAMAPMASK(leftmask&rightmask);
\r
624 dest += ofs->linewidth;
\r
632 VGAMAPMASK(leftmask);
\r
636 _fmemset (dest,color,midbytes);
\r
639 VGAMAPMASK(rightmask);
\r
648 //==========================================================================
\r
655 = Draws a block of data to the screen.
\r
660 void VL_MemToScreen (byte far *source, int width, int height, int x, int y, ofs_t *ofs)
\r
662 byte far *screen,far *dest,mask;
\r
666 dest = MK_FP(SCREENSEG,ofs->bufferofs+ofs->ylookup[y]+(x>>2) );
\r
669 for (plane = 0; plane<4; plane++)
\r
677 for (y=0;y<height;y++,screen+=ofs->linewidth,source+=width)
\r
678 _fmemcpy (screen,source,width);
\r
682 //==========================================================================
\r
687 VL_WaitVBL ******** NEW *********
\r
689 Wait for the vertical retrace (returns before the actual vertical sync)
\r
694 void VL_WaitVBL(word num)
\r
696 //PROC VL_WaitVBL num:WORD
\r
697 //PUBLIC VL_WaitVBL
\r
702 #ifdef __BORLANDC__
\r
706 mov dx,STATUS_REGISTER_1
\r
710 // wait for a display signal to make sure the raster isn't in the middle
\r
713 #ifdef __BORLANDC__
\r
717 #ifdef __BORLANDC__
\r
725 #ifdef __BORLANDC__
\r
729 #ifdef __BORLANDC__
\r
742 //===========================================================================
\r
744 #define VGAWRITEMODE(x) asm{
\r
757 #define VGAMAPMASK(x) asm{
\r
766 #define VGAREADMAP(x) asm{
\r
775 #define EGABITMASK(x) asm{
\r
777 mov ax,GC_BITMASK+256*x
\r
782 void VGAWRITEMODE(byte x)
\r
798 void VGAMAPMASK(byte x)
\r
810 void VGAREADMAP(byte x)
\r
822 void VGABITMASK(byte x)
\r
827 mov ax,GC_BITMASK+q
\r
833 //===========================================================================
\r