1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2022 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
29 //#define VGASTRIDEVARIABLE vga_state.vga_stride
\r
30 #define VGASTRIDEVARIABLE gvar->video.page[0].stridew
\r
32 //===========================================================================
\r
40 void VL_SetScreen (unsigned int crtc, int pelpan)
\r
42 // PROC VL_SetScreen crtc:WORD, pel:WORD
\r
43 // PUBLIC VL_SetScreen
\r
44 word TimeCount = *clockw;
\r
46 mov cx,[TimeCount] // if TimeCount goes up by two, the retrace
\r
47 add cx,2 // period was missed (an interrupt covered it)
\r
49 mov dx,STATUS_REGISTER_1
\r
51 // wait for a display signal to make sure the raster isn't in the middle
\r
57 SetScreen_waitdisplay:
\r
62 test al,1 //1 = display is disabled (HBL / VBL)
\r
63 jnz SetScreen_waitdisplay
\r
82 cmp [TimeCount],cx // will only happen if an interrupt is
\r
83 jae SetScreen_setcrtc // straddling the entire retrace period
\r
85 // when several succesive display not enableds occur,
\r
86 // the bottom of the screen has been hit
\r
90 jnz SetScreen_waitdisplay
\r
96 jnz SetScreen_waitdisplay
\r
102 jnz SetScreen_waitdisplay
\r
108 jnz SetScreen_waitdisplay
\r
114 jnz SetScreen_waitdisplay
\r
118 #ifdef __BORLANDC__
\r
122 #ifdef __BORLANDC__
\r
126 // for some reason, my XT's EGA card doesn't like word outs to the CRTC index...
\r
130 mov al,0ch //start address high register
\r
136 mov al,0dh //start address low register
\r
143 // set horizontal panning
\r
146 // mov al,ATR_PELPAN or 20h
\r
149 mov al,[BYTE PTR pelpan] //pel pan value
\r
151 #ifdef __BORLANDC__
\r
155 #ifdef __BORLANDC__
\r
165 ====================
\r
169 = Line witdh is in WORDS, 40 words is normal width for vgaplanegr
\r
171 ====================
\r
174 void VL_SetLineWidth (unsigned width, global_game_variables_t *gvar)
\r
179 // set wide virtual screen
\r
181 outport (CRTC_INDEX,CRTC_OFFSET+width*256);
\r
184 // set up lookup tables
\r
186 gvar->video.ofs.linewidth = width*2;
\r
190 for (i=0;i<MAXSCANLINES;i++)
\r
192 gvar->video.ofs.ylookup[i]=offset;
\r
193 offset += gvar->video.ofs.linewidth;
\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
496 void VL_ColorBorder (int color, video_t *v)
\r
498 union REGS in, out;
\r
503 int86(0x10, &in, &out);
\r
504 v->bordercolor = color;
\r
509 =============================================================================
\r
513 =============================================================================
\r
516 //byte rightmasks[4] = {1,3,7,15};
\r
526 void VL_Plot (int x, int y, int color, global_game_variables_t *gvar)
\r
531 if(!gvar->video.VL_Started) return;
\r
535 //*(byte far *)MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+(gvar->video.ofs.ylookup[y]+(x>>2))) = color;
\r
536 //*(byte far *)MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+((y*VGASTRIDEVARIABLE)+(x>>2))) = color;
\r
537 *(byte far *)MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+((y*VGASTRIDEVARIABLE)+(x>>2))) = color;
\r
550 void VL_Hlin (unsigned x, unsigned y, unsigned width, unsigned color, global_game_variables_t *gvar)
\r
554 byte leftmask,rightmask;
\r
559 if(!gvar->video.VL_Started) return;
\r
562 leftmask = lclip[x&3];
\r
563 rightmask = rclip[(x+width-1)&3];
\r
564 midbytes = ((x+width+3)>>2) - xbyte - 2;
\r
566 //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+xbyte);
\r
567 dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+xbyte);
\r
572 VGAMAPMASK(leftmask&rightmask);
\r
578 VGAMAPMASK(leftmask);
\r
582 _fmemset (dest,color,midbytes);
\r
585 VGAMAPMASK(rightmask);
\r
600 void VL_Vlin (int x, int y, int height, int color, global_game_variables_t *gvar)
\r
602 byte far *dest,mask;
\r
605 if(!gvar->video.VL_Started) return;
\r
610 //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));
\r
611 dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(x>>2));
\r
616 //dest += gvar->video.ofs.linewidth;
\r
617 dest += VGASTRIDEVARIABLE;
\r
632 void VL_Bar (int x, int y, int width, int height, int color, global_game_variables_t *gvar)
\r
635 byte leftmask,rightmask;
\r
636 int midbytes,linedelta;
\r
640 if(!gvar->video.VL_Started) return;
\r
642 leftmask = lclip[x&3];
\r
643 rightmask = rclip[(x+width-1)&3];
\r
644 midbytes = ((x+width+3)>>2) - (x>>2) - 2;
\r
645 //linedelta = gvar->video.ofs.linewidth-(midbytes+1);
\r
646 linedelta = VGASTRIDEVARIABLE-(midbytes+1);
\r
648 //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));
\r
649 dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(x>>2));
\r
654 VGAMAPMASK(leftmask&rightmask);
\r
658 //dest += gvar->video.ofs.linewidth;
\r
659 dest += VGASTRIDEVARIABLE;
\r
667 VGAMAPMASK(leftmask);
\r
671 _fmemset (dest,color,midbytes);
\r
674 VGAMAPMASK(rightmask);
\r
683 //==========================================================================
\r
690 = Draws a block of data to the screen.
\r
695 void VL_MemToScreen (byte far *source, int width, int height, int x, int y, global_game_variables_t *gvar)
\r
697 byte far *screen,far *dest,mask;
\r
701 //dest = MK_FP(SCREENSEG,gvar->video.ofs.bufferofs+gvar->video.ofs.ylookup[y]+(x>>2));
\r
702 dest = MK_FP(SCREENSEG,BDOFSCONV gvar->video.BOFS+(y*VGASTRIDEVARIABLE)+(x>>2));
\r
705 for (plane = 0; plane<4; plane++)
\r
713 //for (y=0;y<height;y++,screen+=gvar->video.ofs.linewidth,source+=width)
\r
714 for (y=0;y<height;y++,screen+=VGASTRIDEVARIABLE,source+=width)
\r
715 _fmemcpy (screen,source,width);
\r
719 //==========================================================================
\r
724 VL_WaitVBL ******** NEW *********
\r
726 Wait for the vertical retrace (returns before the actual vertical sync)
\r
731 void VL_WaitVBL(word num)
\r
733 //PROC VL_WaitVBL num:WORD
\r
734 //PUBLIC VL_WaitVBL
\r
739 #ifdef __BORLANDC__
\r
743 mov dx,STATUS_REGISTER_1
\r
747 // wait for a display signal to make sure the raster isn't in the middle
\r
750 #ifdef __BORLANDC__
\r
754 #ifdef __BORLANDC__
\r
762 #ifdef __BORLANDC__
\r
766 #ifdef __BORLANDC__
\r
779 //===========================================================================
\r
781 #define VGAWRITEMODE(x) asm{
\r
794 #define VGAMAPMASK(x) asm{
\r
803 #define VGAREADMAP(x) asm{
\r
812 #define EGABITMASK(x) asm{
\r
814 mov ax,GC_BITMASK+256*x
\r
819 void VGAWRITEMODE(byte x)
\r
835 void VGAMAPMASK(byte x)
\r
847 void VGAREADMAP(byte x)
\r
859 void VGABITMASK(byte x)
\r
864 mov ax,GC_BITMASK+q
\r
870 //===========================================================================
\r