12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592 |
- /* Catacomb Armageddon Source Code
- * Copyright (C) 1993-2014 Flat Rock Software
- *
- * This program 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 2 of the License, or
- * (at your option) any later version.
- *
- * This program 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, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
- // ID_VW.C
- #include "ID_HEADS.H"
- /*
- =============================================================================
- LOCAL CONSTANTS
- =============================================================================
- */
- #define VIEWWIDTH 40
- #define PIXTOBLOCK 4 // 16 pixels to an update block
- /*
- =============================================================================
- GLOBAL VARIABLES
- =============================================================================
- */
- cardtype videocard; // set by VW_Startup
- grtype grmode; // CGAgr, EGAgr, VGAgr
- unsigned bufferofs; // hidden area to draw to before displaying
- unsigned displayofs; // origin of the visable screen
- unsigned panx,pany; // panning adjustments inside port in pixels
- unsigned pansx,pansy; // panning adjustments inside port in screen
- // block limited pixel values (ie 0/8 for ega x)
- unsigned panadjust; // panx/pany adjusted by screen resolution
- unsigned screenseg; // normally 0xa000 / 0xb800
- unsigned linewidth;
- unsigned ylookup[VIRTUALHEIGHT];
- unsigned fontnumber; // 0 based font number for drawing
- boolean screenfaded;
- pictabletype _seg *pictable;
- pictabletype _seg *picmtable;
- spritetabletype _seg *spritetable;
- int bordercolor;
- /*
- =============================================================================
- LOCAL VARIABLES
- =============================================================================
- */
- void VWL_MeasureString (char far *string, word *width, word *height,
- fontstruct _seg *font);
- void VWL_DrawCursor (void);
- void VWL_EraseCursor (void);
- void VWL_DBSetup (void);
- void VWL_UpdateScreenBlocks (void);
- int bordercolor;
- int cursorvisible;
- int cursornumber,cursorwidth,cursorheight,cursorx,cursory;
- memptr cursorsave;
- unsigned cursorspot;
- //===========================================================================
- /*
- =======================
- =
- = VW_Startup
- =
- =======================
- */
- static char *ParmStrings[] = {"HIDDENCARD",""};
- void VW_Startup (void)
- {
- int i;
- asm cld;
- videocard = 0;
- for (i = 1;i < _argc;i++)
- if (US_CheckParm(_argv[i],ParmStrings) == 0)
- {
- videocard = EGAcard;
- break;
- }
- if (!videocard)
- videocard = VW_VideoID ();
- #if GRMODE == EGAGR
- grmode = EGAGR;
- if (videocard != EGAcard && videocard != VGAcard)
- Quit ("Improper video card! If you really have an EGA/VGA card that I am not \n"
- "detecting, use the -HIDDENCARD command line parameter!");
- EGAWRITEMODE(0);
- #endif
- #if GRMODE == CGAGR
- grmode = CGAGR;
- if (videocard < CGAcard || videocard > VGAcard)
- Quit ("Improper video card! If you really have a CGA card that I am not \n"
- "detecting, use the -HIDDENCARD command line parameter!");
- MM_GetPtr (&(memptr)screenseg,0x10000l); // grab 64k for floating screen
- #endif
- cursorvisible = 0;
- }
- //===========================================================================
- /*
- =======================
- =
- = VW_Shutdown
- =
- =======================
- */
- void VW_Shutdown (void)
- {
- VW_SetScreenMode (TEXTGR);
- #if GRMODE == EGAGR
- VW_SetLineWidth (80);
- #endif
- }
- //===========================================================================
- /*
- ========================
- =
- = VW_SetScreenMode
- = Call BIOS to set TEXT / CGAgr / EGAgr / VGAgr
- =
- ========================
- */
- void VW_SetScreenMode (int grmode)
- {
- switch (grmode)
- {
- case TEXTGR: _AX = 3;
- geninterrupt (0x10);
- screenseg=0xb000;
- break;
- case CGAGR: _AX = 4;
- geninterrupt (0x10); // screenseg is actually a main mem buffer
- break;
- case EGA320GR: // MDM start (GAMERS EDGE)
- MaxX=320;
- MaxY=200;
- _AX = 0xd|128;
- geninterrupt (0x10);
- screenseg=0xa000;
- break;
- case EGA640GR:
- MaxX=640;
- MaxY=200;
- _AX = 0xe|128;
- geninterrupt (0x10);
- screenseg=0xa000;
- break; // MDM end (GAMERS EDGE)
- case EGAGR: _AX = 0xd;
- MaxX=320;
- MaxY=200;
- geninterrupt (0x10);
- screenseg=0xa000;
- break;
- #ifdef VGAGAME
- case VGAGR:{
- char extern VGAPAL; // deluxepaint vga pallet .OBJ file
- void far *vgapal = &VGAPAL;
- SetCool256 (); // custom 256 color mode
- screenseg=0xa000;
- _ES = FP_SEG(vgapal);
- _DX = FP_OFF(vgapal);
- _BX = 0;
- _CX = 0x100;
- _AX = 0x1012;
- geninterrupt(0x10); // set the deluxepaint pallet
- break;
- #endif
- }
- VW_SetLineWidth(SCREENWIDTH);
- }
- /*
- =============================================================================
- SCREEN FADES
- =============================================================================
- */
- char colors[7][17]=
- {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0,0,0,1,2,3,4,5,6,7,0},
- {0,0,0,0,0,0,0,0,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0},
- {0,1,2,3,4,5,6,7,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0},
- {0,1,2,3,4,5,6,7,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0},
- {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f}};
- void VW_ColorBorder (int color)
- {
- _AH=0x10;
- _AL=1;
- _BH=color;
- geninterrupt (0x10);
- bordercolor = color;
- }
- void VW_SetPalette(byte *palette)
- {
- byte p;
- word i;
- for (i = 0;i < 15;i++)
- {
- p = palette[i];
- colors[0][i] = 0;
- colors[1][i] = (p > 0x10)? (p & 0x0f) : 0;
- colors[2][i] = (p > 0x10)? p : 0;
- colors[3][i] = p;
- colors[4][i] = (p > 0x10)? 0x1f : p;
- colors[5][i] = 0x1f;
- }
- }
- void VW_SetDefaultColors(void)
- {
- #if GRMODE == EGAGR
- colors[3][16] = bordercolor;
- _ES=FP_SEG(&colors[3]);
- _DX=FP_OFF(&colors[3]);
- _AX=0x1002;
- geninterrupt(0x10);
- screenfaded = false;
- #endif
- }
- void VW_FadeOut(void)
- {
- #if GRMODE == EGAGR
- int i;
- for (i=3;i>=0;i--)
- {
- colors[i][16] = bordercolor;
- _ES=FP_SEG(&colors[i]);
- _DX=FP_OFF(&colors[i]);
- _AX=0x1002;
- geninterrupt(0x10);
- VW_WaitVBL(6);
- }
- screenfaded = true;
- #endif
- }
- void VW_FadeIn(void)
- {
- #if GRMODE == EGAGR
- int i;
- for (i=0;i<4;i++)
- {
- colors[i][16] = bordercolor;
- _ES=FP_SEG(&colors[i]);
- _DX=FP_OFF(&colors[i]);
- _AX=0x1002;
- geninterrupt(0x10);
- VW_WaitVBL(6);
- }
- screenfaded = false;
- #endif
- }
- void VW_FadeUp(void)
- {
- #if GRMODE == EGAGR
- int i;
- for (i=3;i<6;i++)
- {
- colors[i][16] = bordercolor;
- _ES=FP_SEG(&colors[i]);
- _DX=FP_OFF(&colors[i]);
- _AX=0x1002;
- geninterrupt(0x10);
- VW_WaitVBL(6);
- }
- screenfaded = true;
- #endif
- }
- void VW_FadeDown(void)
- {
- #if GRMODE == EGAGR
- int i;
- for (i=5;i>2;i--)
- {
- colors[i][16] = bordercolor;
- _ES=FP_SEG(&colors[i]);
- _DX=FP_OFF(&colors[i]);
- _AX=0x1002;
- geninterrupt(0x10);
- VW_WaitVBL(6);
- }
- screenfaded = false;
- #endif
- }
- /*
- ========================
- =
- = VW_SetAtrReg
- =
- = Sets an attribute (pallete / border) register
- = Does NOT vsync!
- =
- ========================
- */
- void VW_SetAtrReg (int reg, int value)
- {
- asm cli
- asm mov dx,STATUS_REGISTER_1
- asm in al,dx
- asm mov dx,ATR_INDEX
- asm mov al,BYTE PTR [reg]
- asm out dx,al
- asm mov al,BYTE PTR [value]
- asm out dx,al
- asm mov dx,0x3da
- asm in al,dx
- asm mov dx,ATR_INDEX
- asm mov al,0x20
- asm out dx,al
- asm sti
- }
- //===========================================================================
- /*
- ====================
- =
- = VW_SetLineWidth
- =
- = Must be an even number of bytes
- =
- ====================
- */
- void VW_SetLineWidth (int width)
- {
- int i,offset;
- #if GRMODE == EGAGR
- //
- // set wide virtual screen
- //
- asm mov dx,CRTC_INDEX
- asm mov al,CRTC_OFFSET
- asm mov ah,[BYTE PTR width]
- asm shr ah,1
- asm out dx,ax
- #endif
- //
- // set up lookup tables
- //
- linewidth = width;
- offset = 0;
- for (i=0;i<VIRTUALHEIGHT;i++)
- {
- ylookup[i]=offset;
- offset += width;
- }
- }
- //===========================================================================
- /*
- ====================
- =
- = VW_SetSplitScreen
- =
- ====================
- */
- void VW_SetSplitScreen (int linenum)
- {
- VW_WaitVBL (1);
- if (videocard==VGAcard)
- linenum=linenum*2-1;
- outportb (CRTC_INDEX,CRTC_LINECOMPARE);
- outportb (CRTC_INDEX+1,linenum % 256);
- outportb (CRTC_INDEX,CRTC_OVERFLOW);
- outportb (CRTC_INDEX+1, 1+16*(linenum/256));
- if (videocard==VGAcard)
- {
- outportb (CRTC_INDEX,CRTC_MAXSCANLINE);
- outportb (CRTC_INDEX+1,inportb(CRTC_INDEX+1) & (255-64));
- }
- }
- //===========================================================================
- /*
- ====================
- =
- = VW_ClearVideo
- =
- ====================
- */
- void VW_ClearVideo (int color)
- {
- #if GRMODE == EGAGR
- EGAWRITEMODE(2);
- EGAMAPMASK(15);
- #endif
- asm mov es,[screenseg]
- asm xor di,di
- asm mov cx,0xffff
- asm mov al,[BYTE PTR color]
- asm rep stosb
- asm stosb
- #if GRMODE == EGAGR
- EGAWRITEMODE(0);
- #endif
- }
- //===========================================================================
- #if NUMPICS>0
- /*
- ====================
- =
- = VW_DrawPic
- =
- = X in bytes, y in pixels, chunknum is the #defined picnum
- =
- ====================
- */
- void VW_DrawPic(unsigned x, unsigned y, unsigned chunknum)
- {
- int picnum = chunknum - STARTPICS;
- memptr source;
- unsigned dest,width,height;
- source = grsegs[chunknum];
- dest = ylookup[y]+x+bufferofs;
- width = pictable[picnum].width;
- height = pictable[picnum].height;
- VW_MemToScreen(source,dest,width,height);
- }
- // MDM (GAMERS EDGE) begin
- /*
- ====================
- =
- = VW_DrawPic2x - Same as VW_DrawPic, but doubles pixels horizontally
- = (Great for drawing 320 graphics on 640 screen!)
- =
- = X in bytes, y in pixels, chunknum is the #defined picnum
- =
- ====================
- */
- void VW_DrawPic2x(unsigned x, unsigned y, unsigned chunknum)
- {
- int picnum = chunknum - STARTPICS;
- memptr source;
- unsigned dest,width,height;
- source = grsegs[chunknum];
- dest = ylookup[y]+x+bufferofs;
- width = pictable[picnum].width;
- height = pictable[picnum].height;
- VW_MemToScreen2x(source,dest,width,height);
- }
- // MDM (GAMERS EDGE) end
- #endif
- #if NUMPICM>0
- /*
- ====================
- =
- = VW_DrawMPic
- =
- = X in bytes, y in pixels, chunknum is the #defined picnum
- =
- ====================
- */
- void VW_DrawMPic(unsigned x, unsigned y, unsigned chunknum)
- {
- int picnum = chunknum - STARTPICM;
- memptr source;
- unsigned dest,width,height;
- source = grsegs[chunknum];
- dest = ylookup[y]+x+bufferofs;
- width = picmtable[picnum].width;
- height = picmtable[picnum].height;
- VW_MaskBlock(source,0,dest,width,height,width*height);
- }
- void VW_ClipDrawMPic(unsigned x, int y, unsigned chunknum)
- {
- int picnum = chunknum - STARTPICM;
- memptr source;
- unsigned dest,width,ofs,plane;
- int height;
- source = grsegs[chunknum];
- width = picmtable[picnum].width;
- height = picmtable[picnum].height;
- plane = width*height;
- ofs = 0;
- if (y<0)
- {
- ofs= -y*width;
- height+=y;
- y=0;
- }
- else if (y+height>216)
- {
- height-=(y-216);
- }
- dest = ylookup[y]+x+bufferofs;
- if (height<1)
- return;
- VW_MaskBlock(source,ofs,dest,width,height,plane);
- }
- #endif
- //===========================================================================
- #if NUMSPRITES>0
- /*
- ====================
- =
- = VW_DrawSprite
- =
- = X and Y in pixels, it will match the closest shift possible
- =
- = To do:
- = Add vertical clipping!
- = Make the shifts act as center points, rather than break points
- =
- ====================
- */
- void VW_DrawSprite(int x, int y, unsigned chunknum)
- {
- spritetabletype far *spr;
- spritetype _seg *block;
- unsigned dest,shift;
- spr = &spritetable[chunknum-STARTSPRITES];
- block = (spritetype _seg *)grsegs[chunknum];
- y+=spr->orgy>>G_P_SHIFT;
- x+=spr->orgx>>G_P_SHIFT;
- #if GRMODE == EGAGR
- shift = (x&7)/2;
- #endif
- #if GRMODE == CGAGR
- shift = 0;
- #endif
- dest = bufferofs + ylookup[y];
- if (x>=0)
- dest += x/SCREENXDIV;
- else
- dest += (x+1)/SCREENXDIV;
- VW_MaskBlock (block,block->sourceoffset[shift],dest,
- block->width[shift],spr->height,block->planesize[shift]);
- }
- #endif
- /*
- ==================
- =
- = VW_Hlin
- =
- ==================
- */
- #if GRMODE == EGAGR
- unsigned char leftmask[8] = {0xff,0x7f,0x3f,0x1f,0xf,7,3,1};
- unsigned char rightmask[8] = {0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
- void VW_Hlin(unsigned xl, unsigned xh, unsigned y, unsigned color)
- {
- unsigned dest,xlb,xhb,maskleft,maskright,mid;
- xlb=xl/8;
- xhb=xh/8;
- EGAWRITEMODE(2);
- EGAMAPMASK(15);
- maskleft = leftmask[xl&7];
- maskright = rightmask[xh&7];
- mid = xhb-xlb-1;
- dest = bufferofs+ylookup[y]+xlb;
- if (xlb==xhb)
- {
- //
- // entire line is in one byte
- //
- maskleft&=maskright;
- asm mov es,[screenseg]
- asm mov di,[dest]
- asm mov dx,GC_INDEX
- asm mov al,GC_BITMASK
- asm mov ah,[BYTE PTR maskleft]
- asm out dx,ax // mask off pixels
- asm mov al,[BYTE PTR color]
- asm xchg al,[es:di] // load latches and write pixels
- goto done;
- }
- asm mov es,[screenseg]
- asm mov di,[dest]
- asm mov dx,GC_INDEX
- asm mov bh,[BYTE PTR color]
- //
- // draw left side
- //
- asm mov al,GC_BITMASK
- asm mov ah,[BYTE PTR maskleft]
- asm out dx,ax // mask off pixels
- asm mov al,bh
- asm mov bl,[es:di] // load latches
- asm stosb
- //
- // draw middle
- //
- asm mov ax,GC_BITMASK + 255*256
- asm out dx,ax // no masking
- asm mov al,bh
- asm mov cx,[mid]
- asm rep stosb
- //
- // draw right side
- //
- asm mov al,GC_BITMASK
- asm mov ah,[BYTE PTR maskright]
- asm out dx,ax // mask off pixels
- asm xchg bh,[es:di] // load latches and write pixels
- done:
- EGABITMASK(255);
- EGAWRITEMODE(0);
- }
- #endif
- #if GRMODE == CGAGR
- unsigned char pixmask[4] = {0xc0,0x30,0x0c,0x03};
- unsigned char leftmask[4] = {0xff,0x3f,0x0f,0x03};
- unsigned char rightmask[4] = {0xc0,0xf0,0xfc,0xff};
- unsigned char colorbyte[4] = {0,0x55,0xaa,0xff};
- //
- // could be optimized for rep stosw
- //
- void VW_Hlin(unsigned xl, unsigned xh, unsigned y, unsigned color)
- {
- unsigned dest,xlb,xhb,mid;
- byte maskleft,maskright;
- color = colorbyte[color]; // expand 2 color bits to 8
- xlb=xl/4;
- xhb=xh/4;
- maskleft = leftmask[xl&3];
- maskright = rightmask[xh&3];
- mid = xhb-xlb-1;
- dest = bufferofs+ylookup[y]+xlb;
- asm mov es,[screenseg]
- if (xlb==xhb)
- {
- //
- // entire line is in one byte
- //
- maskleft&=maskright;
- asm mov ah,[maskleft]
- asm mov bl,[BYTE PTR color]
- asm and bl,[maskleft]
- asm not ah
- asm mov di,[dest]
- asm mov al,[es:di]
- asm and al,ah // mask out pixels
- asm or al,bl // or in color
- asm mov [es:di],al
- return;
- }
- asm mov di,[dest]
- asm mov bh,[BYTE PTR color]
- //
- // draw left side
- //
- asm mov ah,[maskleft]
- asm mov bl,bh
- asm and bl,[maskleft]
- asm not ah
- asm mov al,[es:di]
- asm and al,ah // mask out pixels
- asm or al,bl // or in color
- asm stosb
- //
- // draw middle
- //
- asm mov al,bh
- asm mov cx,[mid]
- asm rep stosb
- //
- // draw right side
- //
- asm mov ah,[maskright]
- asm mov bl,bh
- asm and bl,[maskright]
- asm not ah
- asm mov al,[es:di]
- asm and al,ah // mask out pixels
- asm or al,bl // or in color
- asm stosb
- }
- #endif
- /*
- ==================
- =
- = VW_Bar
- =
- = Pixel addressable block fill routine
- =
- ==================
- */
- #if GRMODE == CGAGR
- void VW_Bar (unsigned x, unsigned y, unsigned width, unsigned height,
- unsigned color)
- {
- unsigned xh = x+width-1;
- while (height--)
- VW_Hlin (x,xh,y++,color);
- }
- #endif
- #if GRMODE == EGAGR
- void VW_Bar (unsigned x, unsigned y, unsigned width, unsigned height,
- unsigned color)
- {
- unsigned dest,xh,xlb,xhb,maskleft,maskright,mid;
- xh = x+width-1;
- xlb=x/8;
- xhb=xh/8;
- EGAWRITEMODE(2);
- EGAMAPMASK(15);
- maskleft = leftmask[x&7];
- maskright = rightmask[xh&7];
- mid = xhb-xlb-1;
- dest = bufferofs+ylookup[y]+xlb;
- if (xlb==xhb)
- {
- //
- // entire line is in one byte
- //
- maskleft&=maskright;
- asm mov es,[screenseg]
- asm mov di,[dest]
- asm mov dx,GC_INDEX
- asm mov al,GC_BITMASK
- asm mov ah,[BYTE PTR maskleft]
- asm out dx,ax // mask off pixels
- asm mov ah,[BYTE PTR color]
- asm mov dx,[linewidth]
- yloop1:
- asm mov al,ah
- asm xchg al,[es:di] // load latches and write pixels
- asm add di,dx // down to next line
- asm dec [height]
- asm jnz yloop1
- goto done;
- }
- asm mov es,[screenseg]
- asm mov di,[dest]
- asm mov bh,[BYTE PTR color]
- asm mov dx,GC_INDEX
- asm mov si,[linewidth]
- asm sub si,[mid] // add to di at end of line to get to next scan
- asm dec si
- //
- // draw left side
- //
- yloop2:
- asm mov al,GC_BITMASK
- asm mov ah,[BYTE PTR maskleft]
- asm out dx,ax // mask off pixels
- asm mov al,bh
- asm mov bl,[es:di] // load latches
- asm stosb
- //
- // draw middle
- //
- asm mov ax,GC_BITMASK + 255*256
- asm out dx,ax // no masking
- asm mov al,bh
- asm mov cx,[mid]
- asm rep stosb
- //
- // draw right side
- //
- asm mov al,GC_BITMASK
- asm mov ah,[BYTE PTR maskright]
- asm out dx,ax // mask off pixels
- asm mov al,bh
- asm xchg al,[es:di] // load latches and write pixels
- asm add di,si // move to start of next line
- asm dec [height]
- asm jnz yloop2
- done:
- EGABITMASK(255);
- EGAWRITEMODE(0);
- }
- #endif
- //==========================================================================
- /*
- ==================
- =
- = VW_MeasureString
- =
- ==================
- */
- #if NUMFONT+NUMFONTM>0
- void
- VWL_MeasureString (char far *string, word *width, word *height, fontstruct _seg *font)
- {
- *height = font->height-1; // MDM (GAMERS EDGE) - squeeze font vertically...
- for (*width = 0;*string;string++)
- *width += font->width[*((byte far *)string)]; // proportional width
- }
- void VW_MeasurePropString (char far *string, word *width, word *height)
- {
- VWL_MeasureString(string,width,height,(fontstruct _seg *)grsegs[STARTFONT+fontnumber]);
- }
- void VW_MeasureMPropString (char far *string, word *width, word *height)
- {
- VWL_MeasureString(string,width,height,(fontstruct _seg *)grsegs[STARTFONTM+fontnumber]);
- }
- #endif
- /*
- =============================================================================
- CGA stuff
- =============================================================================
- */
- #if GRMODE == CGAGR
- #define CGACRTCWIDTH 40
- /*
- ==========================
- =
- = VW_CGAFullUpdate
- =
- ==========================
- */
- void VW_CGAFullUpdate (void)
- {
- byte *update;
- boolean halftile;
- unsigned x,y,middlerows,middlecollumns;
- displayofs = bufferofs+panadjust;
- asm mov ax,0xb800
- asm mov es,ax
- asm mov si,[displayofs]
- asm xor di,di
- asm mov bx,100 // pairs of scan lines to copy
- asm mov dx,[linewidth]
- asm sub dx,80
- asm mov ds,[screenseg]
- asm test si,1
- asm jz evenblock
- //
- // odd source
- //
- asm mov ax,39 // words accross screen
- copytwolineso:
- asm movsb
- asm mov cx,ax
- asm rep movsw
- asm movsb
- asm add si,dx
- asm add di,0x2000-80 // go to the interlaced bank
- asm movsb
- asm mov cx,ax
- asm rep movsw
- asm movsb
- asm add si,dx
- asm sub di,0x2000 // go to the non interlaced bank
- asm dec bx
- asm jnz copytwolineso
- asm jmp blitdone
- //
- // even source
- //
- evenblock:
- asm mov ax,40 // words accross screen
- copytwolines:
- asm mov cx,ax
- asm rep movsw
- asm add si,dx
- asm add di,0x2000-80 // go to the interlaced bank
- asm mov cx,ax
- asm rep movsw
- asm add si,dx
- asm sub di,0x2000 // go to the non interlaced bank
- asm dec bx
- asm jnz copytwolines
- blitdone:
- asm mov ax,ss
- asm mov ds,ax
- asm mov es,ax
- asm xor ax,ax // clear out the update matrix
- asm mov cx,UPDATEWIDE*UPDATEHIGH/2
- asm mov di,[baseupdateptr]
- asm rep stosw
- updateptr = baseupdateptr;
- *(unsigned *)(updateptr + UPDATEWIDE*PORTTILESHIGH) = UPDATETERMINATE;
- }
- #endif
- /*
- =============================================================================
- CURSOR ROUTINES
- These only work in the context of the double buffered update routines
- =============================================================================
- */
- /*
- ====================
- =
- = VWL_DrawCursor
- =
- = Background saves, then draws the cursor at cursorspot
- =
- ====================
- */
- void VWL_DrawCursor (void)
- {
- cursorspot = bufferofs + ylookup[cursory+pansy]+(cursorx+pansx)/SCREENXDIV;
- VW_ScreenToMem(cursorspot,cursorsave,cursorwidth,cursorheight);
- VWB_DrawSprite(cursorx,cursory,cursornumber);
- }
- //==========================================================================
- /*
- ====================
- =
- = VWL_EraseCursor
- =
- ====================
- */
- void VWL_EraseCursor (void)
- {
- VW_MemToScreen(cursorsave,cursorspot,cursorwidth,cursorheight);
- VW_MarkUpdateBlock ((cursorx+pansx)&SCREENXMASK,cursory+pansy,
- ( (cursorx+pansx)&SCREENXMASK)+cursorwidth*SCREENXDIV-1,
- cursory+pansy+cursorheight-1);
- }
- //==========================================================================
- /*
- ====================
- =
- = VW_ShowCursor
- =
- ====================
- */
- void VW_ShowCursor (void)
- {
- cursorvisible++;
- }
- //==========================================================================
- /*
- ====================
- =
- = VW_HideCursor
- =
- ====================
- */
- void VW_HideCursor (void)
- {
- cursorvisible--;
- }
- //==========================================================================
- /*
- ====================
- =
- = VW_MoveCursor
- =
- ====================
- */
- #define MAXCURSORX (319-24)
- #define MAXCURSORY (199-24)
- void VW_MoveCursor (int x, int y)
- {
- if (x>MAXCURSORX)
- x=MAXCURSORX;
- if (y>MAXCURSORY)
- y=MAXCURSORY; // catacombs hack to keep cursor on screen
- cursorx = x;
- cursory = y;
- }
- //==========================================================================
- /*
- ====================
- =
- = VW_SetCursor
- =
- = Load in a sprite to be used as a cursor, and allocate background save space
- =
- ====================
- */
- void VW_SetCursor (int spritenum)
- {
- VW_FreeCursor ();
- cursornumber = spritenum;
- CA_CacheGrChunk (spritenum);
- MM_SetLock (&grsegs[spritenum],true);
- cursorwidth = spritetable[spritenum-STARTSPRITES].width+1;
- cursorheight = spritetable[spritenum-STARTSPRITES].height;
- MM_GetPtr (&cursorsave,cursorwidth*cursorheight*5);
- MM_SetLock (&cursorsave,true);
- }
- /*
- ====================
- =
- = VW_FreeCursor
- =
- = Frees the memory used by the cursor and its background save
- =
- ====================
- */
- void VW_FreeCursor (void)
- {
- if (cursornumber)
- {
- MM_SetLock (&grsegs[cursornumber],false);
- MM_SetPurge (&grsegs[cursornumber],3);
- MM_SetLock (&cursorsave,false);
- MM_FreePtr (&cursorsave);
- cursornumber = 0;
- }
- }
- /*
- =============================================================================
- Double buffer management routines
- =============================================================================
- */
- /*
- ======================
- =
- = VW_InitDoubleBuffer
- =
- ======================
- */
- void VW_InitDoubleBuffer (void)
- {
- #if GRMODE == EGAGR
- VW_SetScreen (displayofs+panadjust,0); // no pel pan
- #endif
- }
- /*
- ======================
- =
- = VW_FixRefreshBuffer
- =
- = Copies the view page to the buffer page on page flipped refreshes to
- = avoid a one frame shear around pop up windows
- =
- ======================
- */
- void VW_FixRefreshBuffer (void)
- {
- #if GRMODE == EGAGR
- VW_ScreenToScreen (displayofs,bufferofs,PORTTILESWIDE*4*CHARWIDTH,
- (PORTTILESHIGH-1)*16);
- #endif
- }
- /*
- ======================
- =
- = VW_QuitDoubleBuffer
- =
- ======================
- */
- void VW_QuitDoubleBuffer (void)
- {
- }
- /*
- =======================
- =
- = VW_MarkUpdateBlock
- =
- = Takes a pixel bounded block and marks the tiles in bufferblocks
- = Returns 0 if the entire block is off the buffer screen
- =
- =======================
- */
- int VW_MarkUpdateBlock (int x1, int y1, int x2, int y2)
- {
- // MDM (GAMERS EDGE) begin - NOT NEEDED FOR 3D ENGINE
- #if 0
- int x,y,xt1,yt1,xt2,yt2,nextline;
- byte *mark;
- xt1 = x1>>PIXTOBLOCK;
- yt1 = y1>>PIXTOBLOCK;
- xt2 = x2>>PIXTOBLOCK;
- yt2 = y2>>PIXTOBLOCK;
- if (xt1<0)
- xt1=0;
- else if (xt1>=UPDATEWIDE-1)
- return 0;
- if (yt1<0)
- yt1=0;
- else if (yt1>UPDATEHIGH)
- return 0;
- if (xt2<0)
- return 0;
- else if (xt2>=UPDATEWIDE-1)
- xt2 = UPDATEWIDE-2;
- if (yt2<0)
- return 0;
- else if (yt2>=UPDATEHIGH)
- yt2 = UPDATEHIGH-1;
- mark = updateptr + uwidthtable[yt1] + xt1;
- nextline = UPDATEWIDE - (xt2-xt1) - 1;
- for (y=yt1;y<=yt2;y++)
- {
- for (x=xt1;x<=xt2;x++)
- *mark++ = 1; // this tile will need to be updated
- mark += nextline;
- }
- #endif
- // MDM (GAMERS EDGE) end
- return 1;
- }
- /*
- ===========================
- =
- = VW_UpdateScreen
- =
- = Updates any changed areas of the double buffer and displays the cursor
- =
- ===========================
- */
- void VW_UpdateScreen (void)
- {
- if (cursorvisible>0)
- VWL_DrawCursor();
- #if GRMODE == EGAGR
- VWL_UpdateScreenBlocks();
- asm mov ax,ds
- asm mov es,ax
- asm mov di,[updateptr] // cat3d patch
- asm xor ax,ax // clear out the update matrix
- asm mov cx,UPDATEWIDE*UPDATEHIGH/2
- asm rep stosw
- *(unsigned *)(updateptr + UPDATEWIDE*PORTTILESHIGH) = UPDATETERMINATE;
- asm cli
- asm mov cx,[displayofs]
- asm add cx,[panadjust]
- asm mov dx,CRTC_INDEX
- asm mov al,0ch // start address high register
- asm out dx,al
- asm inc dx
- asm mov al,ch
- asm out dx,al
- asm dec dx
- asm mov al,0dh // start address low register
- asm out dx,al
- asm mov al,cl
- asm inc dx
- asm out dx,al
- asm sti
- #endif
- #if GRMODE == CGAGR
- VW_CGAFullUpdate();
- #endif
- if (cursorvisible>0)
- VWL_EraseCursor();
- }
- void VWB_DrawTile8 (int x, int y, int tile)
- {
- x+=pansx;
- y+=pansy;
- if (VW_MarkUpdateBlock (x&SCREENXMASK,y,(x&SCREENXMASK)+7,y+7))
- VW_DrawTile8 (x/SCREENXDIV,y,tile);
- }
- void VWB_DrawTile8M (int x, int y, int tile)
- {
- int xb;
- x+=pansx;
- y+=pansy;
- xb = x/SCREENXDIV; // use intermediate because VW_DT8M is macro
- // if (VW_MarkUpdateBlock (x&SCREENXMASK,y,(x&SCREENXMASK)+7,y+7)) // MDM (GAMER EDGE)
- VW_DrawTile8M (xb,y,tile); // statement prevents drawing chars past 42
- }
- void VWB_DrawTile16 (int x, int y, int tile)
- {
- x+=pansx;
- y+=pansy;
- if (VW_MarkUpdateBlock (x&SCREENXMASK,y,(x&SCREENXMASK)+15,y+15))
- VW_DrawTile16 (x/SCREENXDIV,y,tile);
- }
- void VWB_DrawTile16M (int x, int y, int tile)
- {
- int xb;
- x+=pansx;
- y+=pansy;
- xb = x/SCREENXDIV; // use intermediate because VW_DT16M is macro
- if (VW_MarkUpdateBlock (x&SCREENXMASK,y,(x&SCREENXMASK)+15,y+15))
- VW_DrawTile16M (xb,y,tile);
- }
- #if NUMPICS
- void VWB_DrawPic (int x, int y, int chunknum)
- {
- // mostly copied from drawpic
- int picnum = chunknum - STARTPICS;
- memptr source;
- unsigned dest,width,height;
- x+=pansx;
- y+=pansy;
- x/= SCREENXDIV;
- source = grsegs[chunknum];
- dest = ylookup[y]+x+bufferofs;
- width = pictable[picnum].width;
- height = pictable[picnum].height;
- if (VW_MarkUpdateBlock (x*SCREENXDIV,y,(x+width)*SCREENXDIV-1,y+height-1))
- VW_MemToScreen(source,dest,width,height);
- }
- #endif
- #if NUMPICM>0
- void VWB_DrawMPic(int x, int y, int chunknum)
- {
- // mostly copied from drawmpic
- int picnum = chunknum - STARTPICM;
- memptr source;
- unsigned dest,width,height;
- x+=pansx;
- y+=pansy;
- x/=SCREENXDIV;
- source = grsegs[chunknum];
- dest = ylookup[y]+x+bufferofs;
- width = picmtable[picnum].width;
- height = picmtable[picnum].height;
- if (VW_MarkUpdateBlock (x*SCREENXDIV,y,(x+width)*SCREENXDIV-1,y+height-1))
- VW_MaskBlock(source,0,dest,width,height,width*height);
- }
- #endif
- void VWB_Bar (int x, int y, int width, int height, int color)
- {
- x+=pansx;
- y+=pansy;
- if (VW_MarkUpdateBlock (x,y,x+width,y+height-1) )
- VW_Bar (x,y,width,height,color);
- }
- #if NUMFONT
- void VWB_DrawPropString (char far *string)
- {
- int x,y;
- x = px+pansx;
- y = py+pansy;
- VW_DrawPropString (string);
- VW_MarkUpdateBlock(x,y,x+bufferwidth*8-1,y+bufferheight-1);
- }
- #endif
- #if NUMFONTM
- void VWB_DrawMPropString (char far *string)
- {
- int x,y;
- x = px+pansx;
- y = py+pansy;
- VW_DrawMPropString (string);
- VW_MarkUpdateBlock(x,y,x+bufferwidth*8-1,y+bufferheight-1);
- }
- #endif
- #if NUMSPRITES
- void VWB_DrawSprite(int x, int y, int chunknum)
- {
- spritetabletype far *spr;
- spritetype _seg *block;
- unsigned dest,shift,width,height;
- x+=pansx;
- y+=pansy;
- spr = &spritetable[chunknum-STARTSPRITES];
- block = (spritetype _seg *)grsegs[chunknum];
- y+=spr->orgy>>G_P_SHIFT;
- x+=spr->orgx>>G_P_SHIFT;
- #if GRMODE == EGAGR
- shift = (x&7)/2;
- #endif
- #if GRMODE == CGAGR
- shift = 0;
- #endif
- dest = bufferofs + ylookup[y];
- if (x>=0)
- dest += x/SCREENXDIV;
- else
- dest += (x+1)/SCREENXDIV;
- width = block->width[shift];
- height = spr->height;
- if (VW_MarkUpdateBlock (x&SCREENXMASK,y,(x&SCREENXMASK)+width*SCREENXDIV-1
- ,y+height-1))
- VW_MaskBlock (block,block->sourceoffset[shift],dest,
- width,height,block->planesize[shift]);
- }
- #endif
- void VWB_Plot (int x, int y, int color)
- {
- x+=pansx;
- y+=pansy;
- if (VW_MarkUpdateBlock (x,y,x,y))
- VW_Plot(x,y,color);
- }
- void VWB_Hlin (int x1, int x2, int y, int color)
- {
- x1+=pansx;
- x2+=pansx;
- y+=pansy;
- if (VW_MarkUpdateBlock (x1,y,x2,y))
- VW_Hlin(x1,x2,y,color);
- }
- void VWB_Vlin (int y1, int y2, int x, int color)
- {
- x+=pansx;
- y1+=pansy;
- y2+=pansy;
- if (VW_MarkUpdateBlock (x,y1,x,y2))
- VW_Vlin(y1,y2,x,color);
- }
- //===========================================================================
|