3 #include "ID_HEADS.H"
\r
5 #define SCREENWIDTH 80
\r
11 #define SCREENXMASK (~3)
\r
12 #define SCREENXPLUS (3)
\r
13 #define SCREENXDIV (4)
\r
15 #define VIEWWIDTH 80
\r
17 #define PIXTOBLOCK 4 // 16 pixels to an update block
\r
19 #define UNCACHEGRCHUNK(chunk) {MM_FreePtr(&grsegs[chunk]);grneeded[chunk]&=~ca_levelbit;}
\r
21 byte update[UPDATEHIGH][UPDATEWIDE];
\r
23 //==========================================================================
\r
25 pictabletype _seg *pictable;
\r
29 byte fontcolor,backcolor;
\r
31 int bufferwidth,bufferheight;
\r
34 //==========================================================================
\r
36 void VWL_UpdateScreenBlocks (void);
\r
38 //==========================================================================
\r
40 void VW_DrawPropString (char far *string)
\r
42 fontstruct far *font;
\r
43 int width,step,height,i;
\r
44 byte far *source, far *dest, far *origdest;
\r
47 font = (fontstruct far *)grsegs[STARTFONT+fontnumber];
\r
48 height = bufferheight = font->height;
\r
49 dest = origdest = MK_FP(SCREENSEG,bufferofs+ylookup[py]+(px>>2));
\r
53 while ((ch = *string++)!=0)
\r
55 width = step = font->width[ch];
\r
56 source = ((byte far *)font)+font->location[ch];
\r
61 asm mov ah,[BYTE PTR fontcolor]
\r
64 asm mov dx,[linewidth]
\r
72 asm mov [es:di],ah // draw color
\r
91 bufferheight = height;
\r
92 bufferwidth = ((dest+1)-origdest)*4;
\r
96 void VW_DrawColorPropString (char far *string)
\r
98 fontstruct far *font;
\r
99 int width,step,height,i;
\r
100 byte far *source, far *dest, far *origdest;
\r
103 font = (fontstruct far *)grsegs[STARTFONT+fontnumber];
\r
104 height = bufferheight = font->height;
\r
105 dest = origdest = MK_FP(SCREENSEG,bufferofs+ylookup[py]+(px>>2));
\r
109 while ((ch = *string++)!=0)
\r
111 width = step = font->width[ch];
\r
112 source = ((byte far *)font)+font->location[ch];
\r
117 asm mov ah,[BYTE PTR fontcolor]
\r
119 asm mov cx,[height]
\r
120 asm mov dx,[linewidth]
\r
121 asm lds si,[source]
\r
128 asm mov [es:di],ah // draw color
\r
134 asm rcr cx,1 // inc font color
\r
154 bufferheight = height;
\r
155 bufferwidth = ((dest+1)-origdest)*4;
\r
159 //==========================================================================
\r
170 void VL_MungePic (byte far *source, unsigned width, unsigned height)
\r
172 unsigned x,y,plane,size,pwidth;
\r
173 byte _seg *temp, far *dest, far *srcline;
\r
175 size = width*height;
\r
178 MS_Quit ("VL_MungePic: Not divisable by 4!");
\r
181 // copy the pic to a temp buffer
\r
183 MM_GetPtr (&(memptr)temp,size);
\r
184 _fmemcpy (temp,source,size);
\r
187 // munge it back into the original buffer
\r
192 for (plane=0;plane<4;plane++)
\r
195 for (y=0;y<height;y++)
\r
197 for (x=0;x<pwidth;x++)
\r
198 *dest++ = *(srcline+x*4+plane);
\r
203 MM_FreePtr (&(memptr)temp);
\r
206 void VWL_MeasureString (char far *string, word *width, word *height
\r
207 , fontstruct _seg *font)
\r
209 *height = font->height;
\r
210 for (*width = 0;*string;string++)
\r
211 *width += font->width[*((byte far *)string)]; // proportional width
\r
214 void VW_MeasurePropString (char far *string, word *width, word *height)
\r
216 VWL_MeasureString(string,width,height,(fontstruct _seg *)grsegs[STARTFONT+fontnumber]);
\r
219 void VW_MeasureMPropString (char far *string, word *width, word *height)
\r
221 VWL_MeasureString(string,width,height,(fontstruct _seg *)grsegs[STARTFONTM+fontnumber]);
\r
227 =============================================================================
\r
229 Double buffer management routines
\r
231 =============================================================================
\r
236 =======================
\r
238 = VW_MarkUpdateBlock
\r
240 = Takes a pixel bounded block and marks the tiles in bufferblocks
\r
241 = Returns 0 if the entire block is off the buffer screen
\r
243 =======================
\r
246 int VW_MarkUpdateBlock (int x1, int y1, int x2, int y2)
\r
248 int x,y,xt1,yt1,xt2,yt2,nextline;
\r
251 xt1 = x1>>PIXTOBLOCK;
\r
252 yt1 = y1>>PIXTOBLOCK;
\r
254 xt2 = x2>>PIXTOBLOCK;
\r
255 yt2 = y2>>PIXTOBLOCK;
\r
259 else if (xt1>=UPDATEWIDE)
\r
264 else if (yt1>UPDATEHIGH)
\r
269 else if (xt2>=UPDATEWIDE)
\r
270 xt2 = UPDATEWIDE-1;
\r
274 else if (yt2>=UPDATEHIGH)
\r
275 yt2 = UPDATEHIGH-1;
\r
277 mark = updateptr + uwidthtable[yt1] + xt1;
\r
278 nextline = UPDATEWIDE - (xt2-xt1) - 1;
\r
280 for (y=yt1;y<=yt2;y++)
\r
282 for (x=xt1;x<=xt2;x++)
\r
283 *mark++ = 1; // this tile will need to be updated
\r
291 void VWB_DrawTile8 (int x, int y, int tile)
\r
293 if (VW_MarkUpdateBlock (x,y,x+7,y+7))
\r
294 LatchDrawChar(x,y,tile);
\r
297 void VWB_DrawTile8M (int x, int y, int tile)
\r
299 if (VW_MarkUpdateBlock (x,y,x+7,y+7))
\r
300 VL_MemToScreen (((byte far *)grsegs[STARTTILE8M])+tile*64,8,8,x,y);
\r
304 void VWB_DrawPic (int x, int y, int chunknum)
\r
306 int picnum = chunknum - STARTPICS;
\r
307 unsigned width,height;
\r
311 width = pictable[picnum].width;
\r
312 height = pictable[picnum].height;
\r
314 if (VW_MarkUpdateBlock (x,y,x+width-1,y+height-1))
\r
315 VL_MemToScreen (grsegs[chunknum],width,height,x,y);
\r
320 void VWB_DrawPropString (char far *string)
\r
324 VW_DrawPropString (string);
\r
325 VW_MarkUpdateBlock(x,py,px-1,py+bufferheight-1);
\r
329 void VWB_Bar (int x, int y, int width, int height, int color)
\r
331 if (VW_MarkUpdateBlock (x,y,x+width,y+height-1) )
\r
332 VW_Bar (x,y,width,height,color);
\r
335 void VWB_Plot (int x, int y, int color)
\r
337 if (VW_MarkUpdateBlock (x,y,x,y))
\r
338 VW_Plot(x,y,color);
\r
341 void VWB_Hlin (int x1, int x2, int y, int color)
\r
343 if (VW_MarkUpdateBlock (x1,y,x2,y))
\r
344 VW_Hlin(x1,x2,y,color);
\r
347 void VWB_Vlin (int y1, int y2, int x, int color)
\r
349 if (VW_MarkUpdateBlock (x,y1,x,y2))
\r
350 VW_Vlin(y1,y2,x,color);
\r
353 void VW_UpdateScreen (void)
\r
355 VH_UpdateScreen ();
\r
360 =============================================================================
\r
364 =============================================================================
\r
368 =====================
\r
372 =====================
\r
375 void LatchDrawPic (unsigned x, unsigned y, unsigned picnum)
\r
377 unsigned wide, height, source;
\r
379 wide = pictable[picnum-STARTPICS].width;
\r
380 height = pictable[picnum-STARTPICS].height;
\r
381 source = latchpics[2+picnum-LATCHPICS_LUMP_START];
\r
383 VL_LatchToScreen (source,wide/4,height,x*8,y);
\r
387 //==========================================================================
\r
390 ===================
\r
394 ===================
\r
397 void LoadLatchMem (void)
\r
399 int i,j,p,m,width,height,start,end;
\r
406 latchpics[0] = freelatch;
\r
407 CA_CacheGrChunk (STARTTILE8);
\r
408 src = (byte _seg *)grsegs[STARTTILE8];
\r
409 destoff = freelatch;
\r
411 for (i=0;i<NUMTILE8;i++)
\r
413 VL_MemToLatch (src,8,8,destoff);
\r
417 UNCACHEGRCHUNK (STARTTILE8);
\r
419 #if 0 // ran out of latch space!
\r
423 src = (byte _seg *)grsegs[STARTTILE16];
\r
424 latchpics[1] = destoff;
\r
426 for (i=0;i<NUMTILE16;i++)
\r
428 CA_CacheGrChunk (STARTTILE16+i);
\r
429 src = (byte _seg *)grsegs[STARTTILE16+i];
\r
430 VL_MemToLatch (src,16,16,destoff);
\r
433 UNCACHEGRCHUNK (STARTTILE16+i);
\r
440 start = LATCHPICS_LUMP_START;
\r
441 end = LATCHPICS_LUMP_END;
\r
443 for (i=start;i<=end;i++)
\r
445 latchpics[2+i-start] = destoff;
\r
446 CA_CacheGrChunk (i);
\r
447 width = pictable[i-STARTPICS].width;
\r
448 height = pictable[i-STARTPICS].height;
\r
449 VL_MemToLatch (grsegs[i],width,height,destoff);
\r
450 destoff += width/4 *height;
\r
457 //==========================================================================
\r
460 ===================
\r
464 = returns true if aborted
\r
466 ===================
\r
469 extern ControlInfo c;
\r
471 boolean FizzleFade (unsigned source, unsigned dest,
\r
472 unsigned width,unsigned height, unsigned frames, boolean abortable)
\r
475 unsigned drawofs,pagedelta;
\r
476 byte mask,maskb[8] = {1,2,4,8};
\r
477 unsigned x,y,p,frame;
\r
480 pagedelta = dest-source;
\r
483 pixperframe = 64000/frames;
\r
490 if (abortable && IN_CheckAck () )
\r
493 asm mov es,[screenseg]
\r
495 for (p=0;p<pixperframe;p++)
\r
498 // seperate random value into x/y pair
\r
500 asm mov ax,[WORD PTR rndval]
\r
501 asm mov dx,[WORD PTR rndval+2]
\r
504 asm mov [BYTE PTR y],bl // low 8 bits - 1 = y xoordinate
\r
507 asm mov [BYTE PTR x],ah // next 9 bits = x xoordinate
\r
508 asm mov [BYTE PTR x+1],dl
\r
510 // advance to next random element
\r
518 asm mov [WORD PTR rndval],ax
\r
519 asm mov [WORD PTR rndval+2],dx
\r
521 if (x>width || y>height)
\r
523 drawofs = source+ylookup[y] + (x>>2);
\r
530 mask = maskb[mask];
\r
533 asm mov di,[drawofs]
\r
535 asm add di,[pagedelta]
\r
538 if (rndval == 1) // entire sequence has been completed
\r
542 while (TimeCount<frame) // don't go too fast
\r