2 Copyright (C) 1998 BJ Eirich (aka vecna)
\r
3 This program is free software; you can redistribute it and/or
\r
4 modify it under the terms of the GNU General Public License
\r
5 as published by the Free Software Foundation; either version 2
\r
6 of the License, or (at your option) any later version.
\r
7 This program is distributed in the hope that it will be useful,
\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\r
10 See the GNU General Public Lic
\r
11 See the GNU General Public License for more details.
\r
12 You should have received a copy of the GNU General Public License
\r
13 along with this program; if not, write to the Free Software
\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
25 #define SWAP(a,b) { a-=b; b+=a; a=b-a; }
\r
27 // ================================= Data ====================================
\r
31 byte *screen,*video,*vscreen;
\r
32 byte pal[768], pal2[768];
\r
33 byte *translucency_table;
\r
38 int cx1=0,cy1=0,cx2=319,cy2=199;
\r
40 // Driver function-pointers.
\r
41 int (*ShutdownVideo) (int i);
\r
42 int (*ShowPage) (void);
\r
44 // ================================= Code ====================================
\r
46 void SetPalette(byte *pall)
\r
50 for (i=0; i<768; i++)
\r
51 outp(0x03c9, pall[i]);
\r
58 for (i=0; i<768; i++)
\r
62 void set_intensity(quad n)
\r
65 for (i=0; i<768; i++)
\r
66 pal2[i] = (pal[i] * n) >> 6;
\r
71 int LFB_ShowPage(void)
\r
73 if (key[SCAN_ALT] && key[SCAN_X]) err("Exiting: ALT-X pressed.");
\r
76 memcpy(video,screen,sx*sy);
\r
81 void CopySprite(int x, int y, int width, int height, byte *src)
\r
87 for (; height; height--)
\r
89 memcpy(d,src,width);
\r
96 void TCopySprite(int x, int y, int width, int height, byte *src)
\r
102 for (; height; height--)
\r
104 for (x=0; x<width; x++,src++)
\r
115 void CopySpriteLucent(int x, int y, int width, int height, byte *src)
\r
121 for (; height; height--)
\r
123 for (x=0; x<width; x++,src++)
\r
124 d[x]=translucency_table[d[x]|(*src<<8)];
\r
130 void TCopySpriteLucent(int x, int y, int width, int height, byte *src)
\r
136 for (; height; height--)
\r
138 for (x=0; x<width; x++,src++)
\r
142 d[x]=translucency_table[d[x]|(c<<8)];
\r
149 void CopySpriteZoom(int x, int y, int sw, int sh, int dw, int dh, byte *src)
\r
157 if (dw<1 || dh<1) return;
\r
158 xadj = (sw<<16)/dw;
\r
159 yadj = (sh<<16)/dh;
\r
160 d = screen+(y*sx)+x;
\r
163 for (i=0; i<dh; i++)
\r
166 for (j=0; j<dw; j++)
\r
168 d[j]=src[(xerr>>16)];
\r
173 src+=(yerr>>16)*sw;
\r
179 void TCopySpriteZoom(int x, int y, int sw, int sh, int dw, int dh, byte *src)
\r
188 if (dw<1 || dh<1) return;
\r
189 xadj = (sw<<16)/dw;
\r
190 yadj = (sh<<16)/dh;
\r
191 d = screen+(y*sx)+x;
\r
193 for (i=0; i<dh; i++)
\r
196 for (j=0; j<dw; j++)
\r
205 src+=(yerr>>16)*sw;
\r
211 void CopySpriteZoomLucent(int x, int y, int sw, int sh, int dw, int dh, byte *src)
\r
219 if (dw<1 || dh<1) return;
\r
220 xadj = (sw<<16)/dw;
\r
221 yadj = (sh<<16)/dh;
\r
222 d = screen+(y*sx)+x;
\r
225 for (i=0; i<dh; i++)
\r
228 for (j=0; j<dw; j++)
\r
230 d[j]=translucency_table[d[j]|(src[(xerr>>16)]<<8)];
\r
235 src+=(yerr>>16)*sw;
\r
241 void TCopySpriteZoomLucent(int x, int y, int sw, int sh, int dw, int dh, byte *src)
\r
250 if (dw<1 || dh<1) return;
\r
251 xadj = (sw<<16)/dw;
\r
252 yadj = (sh<<16)/dh;
\r
253 d = screen+(y*sx)+x;
\r
256 for (i=0; i<dh; i++)
\r
259 for (j=0; j<dw; j++)
\r
268 src+=(yerr>>16)*sw;
\r
274 void Silhouette(int x, int y, int width, int height, int color, byte *src)
\r
279 if (height<1 || width<1) return;
\r
282 for (x=0; x<width; x++)
\r
289 } while (--height);
\r
293 void SilhouetteZoom(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)
\r
300 if (dw<1 || dh<1) return;
\r
307 for (x=0; x<dw; x++)
\r
309 if (src[(xerr>>16)])
\r
315 src+=(yerr>>16)*sw;
\r
321 void SilhouetteLucent(int x, int y, int width, int height, int color, byte *src)
\r
327 if (width<1 || height<1) return;
\r
329 range=translucency_table+(color<<8);
\r
331 for (x=0; x<width; x++)
\r
338 } while (--height);
\r
342 void SilhouetteZoomLucent(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)
\r
350 if (dw<1 || dh<1) return;
\r
354 range=translucency_table+(color<<8);
\r
358 for (x=0; x<dw; x++)
\r
360 if (src[(xerr>>16)])
\r
366 src+=(yerr>>16)*sw;
\r
373 void Tint(int x, int y, int width, int height, int color, byte *src)
\r
380 if (width<1 || height<1) return;
\r
382 range=translucency_table+(color<<8);
\r
384 for (x=0; x<width; x++)
\r
392 } while (--height);
\r
397 void TintZoom(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)
\r
406 if (dw<1 || dh<1) return;
\r
410 range=translucency_table+(color<<8);
\r
414 for (x=0; x<dw; x++)
\r
423 src+=(yerr>>16)*sw;
\r
429 void CopySpriteClip(int x, int y, int width, int height, byte *src)
\r
438 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
441 if (x+xl > cx2) xl=cx2-x+1;
\r
442 if (y+yl > cy2) yl=cy2-y+1;
\r
443 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
444 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
446 s=src+(ys*width)+xs;
\r
458 void TCopySpriteClip(int x, int y, int width, int height, byte *src)
\r
467 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
469 if (x+xl > cx2) xl=cx2-x+1;
\r
470 if (y+yl > cy2) yl=cy2-y+1;
\r
471 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
472 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
473 s=src+(ys*width)+xs;
\r
478 for (x=0; x<xl; x++)
\r
490 void CopySpriteLucentClip(int x, int y, int width, int height, byte *src)
\r
499 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
502 if (x+xl > cx2) xl=cx2-x+1;
\r
503 if (y+yl > cy2) yl=cy2-y+1;
\r
505 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
506 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
508 s=src+(ys*width)+xs;
\r
513 for (x=0; x<xl; x++)
\r
514 d[x]=translucency_table[d[x]|(s[x]<<8)];
\r
522 void TCopySpriteLucentClip(int x, int y, int width, int height, byte *src)
\r
531 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
533 if (x+xl > cx2) xl=cx2-x+1;
\r
534 if (y+yl > cy2) yl=cy2-y+1;
\r
535 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
536 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
538 s=src+(ys*width)+xs;
\r
543 for (x=0; x<xl; x++)
\r
547 d[x]=translucency_table[d[x]|(c<<8)];
\r
555 void CopySpriteZoomClip(int x, int y, int sw, int sh, int dw, int dh, byte *src)
\r
559 int xerr_start, yerr_start;
\r
566 if (dw<1 || dh<1) return;
\r
570 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
572 if (x+xl > cx2) xl=cx2-x+1;
\r
573 if (y+yl > cy2) yl=cy2-y+1;
\r
574 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
575 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
577 xadj = (sw<<16)/dw;
\r
578 yadj = (sh<<16)/dh;
\r
579 xerr_start = xadj * xs;
\r
580 yerr_start = yadj * ys;
\r
582 if (ys) src+=((yerr_start>>16)*sw);
\r
583 d = screen+(y*sx)+x;
\r
584 yerr = yerr_start & 0xffff;
\r
585 for (i=0; i<yl; i++)
\r
588 for (j=0; j<xl; j++)
\r
590 d[j]=src[(xerr>>16)];
\r
595 src += (yerr>>16)*sw;
\r
601 void TCopySpriteZoomClip(int x, int y, int sw, int sh, int dw, int dh, byte *src)
\r
605 int xerr_start, yerr_start;
\r
612 if (dw<1 || dh<1) return;
\r
617 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
620 if (x+xl > cx2) xl=cx2-x+1;
\r
621 if (y+yl > cy2) yl=cy2-y+1;
\r
622 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
623 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
624 xadj = (sw<<16)/dw;
\r
625 yadj = (sh<<16)/dh;
\r
626 xerr_start = xadj * xs;
\r
627 yerr_start = yadj * ys;
\r
629 if (ys) src+=((yerr_start>>16)*sw);
\r
630 d = screen+(y*sx)+x;
\r
631 yerr = yerr_start & 0xffff;
\r
632 for (i=0; i<yl; i++)
\r
635 for (j=0; j<xl; j++)
\r
644 src += (yerr>>16)*sw;
\r
650 void CopySpriteZoomLucentClip(int x, int y, int sw, int sh, int dw, int dh, byte *src)
\r
654 int xerr_start, yerr_start;
\r
660 if (dw<1 || dh<1) return;
\r
665 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
667 if (x+xl > cx2) xl=cx2-x+1;
\r
668 if (y+yl > cy2) yl=cy2-y+1;
\r
669 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
670 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
671 xadj = (sw<<16)/dw;
\r
672 yadj = (sh<<16)/dh;
\r
673 xerr_start = xadj * xs;
\r
674 yerr_start = yadj * ys;
\r
676 if (ys) src+=((yerr_start>>16)*sw);
\r
677 d = screen+(y*sx)+x;
\r
678 yerr = yerr_start & 0xffff;
\r
679 for (i=0; i<yl; i++)
\r
682 for (j=0; j<xl; j++)
\r
684 d[j]=translucency_table[d[j]|(src[(xerr>>16)]<<8)];
\r
689 src += (yerr>>16)*sw;
\r
695 void TCopySpriteZoomLucentClip(int x, int y, int sw, int sh, int dw, int dh, byte *src)
\r
699 int xerr_start, yerr_start;
\r
706 if (dw<1 || dh<1) return;
\r
710 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
712 if (x+xl > cx2) xl=cx2-x+1;
\r
713 if (y+yl > cy2) yl=cy2-y+1;
\r
714 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
715 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
717 xadj = (sw<<16)/dw;
\r
718 yadj = (sh<<16)/dh;
\r
719 xerr_start = xadj * xs;
\r
720 yerr_start = yadj * ys;
\r
721 if (ys) src+=((yerr_start>>16)*sw);
\r
722 d = screen+(y*sx)+x;
\r
723 yerr = yerr_start & 0xffff;
\r
724 for (i=0; i<yl; i++)
\r
727 for (j=0; j<xl; j++)
\r
731 d[j]=translucency_table[d[j]|(c<<8)];
\r
736 src += (yerr>>16)*sw;
\r
742 void SilhouetteClip(int x, int y, int width, int height, int color, byte *src)
\r
745 int xl=0,yl=0,xs=0,ys=0;
\r
751 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
753 if (x+xl > cx2) xl=cx2-x+1;
\r
754 if (y+yl > cy2) yl=cy2-y+1;
\r
755 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
756 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
757 s=src+(ys*width)+xs;
\r
762 for (x=0; x<xl; x++)
\r
773 void SilhouetteZoomClip(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)
\r
776 int xerr_start=0, yerr_start=0;
\r
779 int xl=0,yl=0,xs=0,ys=0;
\r
782 if (dw<1 || dh<1) return;
\r
787 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
790 if (x+xl > cx2) xl=cx2-x+1;
\r
791 if (y+yl > cy2) yl=cy2-y+1;
\r
792 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
793 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
794 xadj = (sw<<16)/dw;
\r
795 yadj = (sh<<16)/dh;
\r
796 xerr_start = xadj * xs;
\r
797 yerr_start = yadj * ys;
\r
799 if (ys) src+=((yerr_start>>16)*sw);
\r
800 d = screen+(y*sx)+x;
\r
801 yerr = yerr_start & 0xffff;
\r
802 for (y=0; y<yl; y++)
\r
805 for (x=0; x<xl; x++)
\r
807 if (src[(xerr>>16)])
\r
813 src += (yerr>>16)*sw;
\r
819 void SilhouetteLucentClip(int x, int y, int width, int height, int color, byte *src)
\r
822 int xl=0,yl=0,xs=0,ys=0;
\r
829 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
831 if (x+xl > cx2) xl=cx2-x+1;
\r
832 if (y+yl > cy2) yl=cy2-y+1;
\r
833 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
834 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
836 s=src+(ys*width)+xs;
\r
838 range=translucency_table+(color<<8);
\r
841 for (x=0; x<xl; x++)
\r
852 void SilhouetteZoomLucentClip(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)
\r
855 int xerr_start=0, yerr_start=0;
\r
858 int xl=0,yl=0,xs=0,ys=0;
\r
862 if (dw<1 || dh<1) return;
\r
866 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
868 if (x+xl > cx2) xl=cx2-x+1;
\r
869 if (y+yl > cy2) yl=cy2-y+1;
\r
870 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
871 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
873 xadj = (sw<<16)/dw;
\r
874 yadj = (sh<<16)/dh;
\r
875 xerr_start = xadj * xs;
\r
876 yerr_start = yadj * ys;
\r
877 if (ys) src+=((yerr_start>>16)*sw);
\r
878 d = screen+(y*sx)+x;
\r
879 range=translucency_table+(color<<8);
\r
880 yerr = yerr_start & 0xffff;
\r
881 for (y=0; y<yl; y++)
\r
884 for (x=0; x<xl; x++)
\r
886 if (src[(xerr>>16)])
\r
892 src += (yerr>>16)*sw;
\r
899 void TintClip(int x, int y, int width, int height, int color, byte *src)
\r
902 int xl=0,yl=0,xs=0,ys=0;
\r
910 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
912 if (x+xl > cx2) xl=cx2-x+1;
\r
913 if (y+yl > cy2) yl=cy2-y+1;
\r
914 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
915 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
917 s=src+(ys*width)+xs;
\r
919 range=translucency_table+(color<<8);
\r
922 for (x=0; x<xl; x++)
\r
935 void TintZoomClip(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)
\r
938 int xerr_start=0, yerr_start=0;
\r
941 int xl=0,yl=0,xs=0,ys=0;
\r
946 if (dw<1 || dh<1) return;
\r
950 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
952 if (x+xl > cx2) xl=cx2-x+1;
\r
953 if (y+yl > cy2) yl=cy2-y+1;
\r
954 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
955 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
957 xadj = (sw<<16)/dw;
\r
958 yadj = (sh<<16)/dh;
\r
959 xerr_start = xadj * xs;
\r
960 yerr_start = yadj * ys;
\r
961 if (ys) src+=((yerr_start>>16)*sw);
\r
962 d = screen+(y*sx)+x;
\r
963 range=translucency_table+(color<<8);
\r
964 yerr = yerr_start & 0xffff;
\r
965 for (y=0; y<yl; y++)
\r
968 for (x=0; x<xl; x++)
\r
977 src += (yerr>>16)*sw;
\r
983 void CopyTile(int x, int y, byte *src)
\r
985 CopySpriteClip(x,y,16,16,src);
\r
988 void TCopyTile(int x, int y, byte *src, byte *matte)
\r
991 TCopySpriteClip(x,y,16,16,src);
\r
994 void CopyTileLucent(int x, int y, byte *src)
\r
996 CopySpriteLucentClip(x,y,16,16,src);
\r
999 void TCopyTileLucent(int x, int y, byte *src)
\r
1001 TCopySpriteLucentClip(x,y,16,16,src);
\r
1004 void CopyTileClip(int x, int y, byte *src)
\r
1006 CopySpriteClip(x,y,16,16,src);
\r
1009 void TCopyTileClip(int x, int y, byte *src, byte *matte)
\r
1012 TCopySpriteClip(x,y,16,16,src);
\r
1015 void CopyTileLucentClip(int x, int y, byte *src)
\r
1017 CopySpriteLucentClip(x,y,16,16,src);
\r
1020 void TCopyTileLucentClip(int x, int y, byte *src)
\r
1022 TCopySpriteLucentClip(x,y,16,16,src);
\r
1026 void MapLine(int x, int y, int yofs, word *map)
\r
1029 int tilesx,startx;
\r
1036 if (y<0 || y>=tsy) return;
\r
1039 if (x<0) { startx=-x; x=0; }
\r
1041 d=screen+(y*sx)+x;
\r
1044 // do clipped left tile
\r
1047 memcpy(d, vsp+((s<numtiles ? s : 0)*256)+(yofs*16)+startx, 16-startx);
\r
1049 counter+=16-startx;
\r
1051 // do midsection of line
\r
1052 for (x=1; x<tilesx; x++,counter+=16)
\r
1055 memcpy(d, vsp+((s<numtiles ? s : 0)*256)+(yofs*16), 16);
\r
1060 // do clipped right tile
\r
1061 while (counter<tsx)
\r
1063 span=(tsx-counter);
\r
1064 if (span>16) span=16;
\r
1066 memcpy(d, vsp+((s<numtiles ? s : 0)*256)+(yofs*16), span);
\r
1076 void TMapLine(int x, int y, int yofs, word *map)
\r
1080 int tilesx,startx;
\r
1087 if (y<0 || y>=tsy) return;
\r
1090 if (x<0) { startx=-x; x=0; }
\r
1092 d=screen+(y*sx)+x;
\r
1095 // do clipped left tile
\r
1097 s=vsp+(256*tileidx[*map])+(16*yofs)+startx;
\r
1098 for (x=0; x<16-startx; x++)
\r
1105 counter+=16-startx;
\r
1107 // do midsection of line
\r
1108 for (y=1; y<tilesx; y++,counter+=16)
\r
1110 s=vsp+(256*tileidx[*map])+(16*yofs);
\r
1111 for (x=0; x<16; x++)
\r
1120 // do clipped right tile
\r
1121 while (counter<tsx)
\r
1123 span=(tsx-counter);
\r
1124 if (span>16) span=16;
\r
1125 s=vsp+(256*tileidx[*map])+(16*yofs);
\r
1126 for (x=0; x<span; x++)
\r
1140 void ClearScreen()
\r
1143 memset(screen, 0, sx*sy);
\r
1147 void SetPixel(int x, int y, int color)
\r
1149 screen[(y*sx)+x]=color;
\r
1152 void SetPixelLucent(int x, int y, int color)
\r
1157 d=screen+(y*sx)+x;
\r
1158 *d=translucency_table[*d|(color<<8)];
\r
1162 void SetPixelClip(int x, int y, int color)
\r
1164 if (x<cx1 || y<cy1 || x>cx2 || y>cy2) return;
\r
1165 screen[(y*sx)+x]=color;
\r
1168 void SetPixelLucentClip(int x, int y, int color)
\r
1172 if (x<cx1 || y<cy1 || x>cx2 || y>cy2) return;
\r
1173 d=screen+(y*sx)+x;
\r
1174 *d=translucency_table[*d|(color<<8)];
\r
1177 int GetPixel(int x, int y)
\r
1179 return screen[(y*sx)+x];
\r
1182 int GetPixelClip(int x, int y)
\r
1184 if (x<cx1 || y<cy1 || x>cx2 || y>cy2) return 0;
\r
1185 return screen[(y*sx)+x];
\r
1188 void ColorField(int x, int y, char c)
\r
1196 SetPixelClip(x+0, y+i, 0);
\r
1197 SetPixelClip(x+2, y+i, 0);
\r
1198 SetPixelClip(x+4, y+i, 0);
\r
1199 SetPixelClip(x+6, y+i, 0);
\r
1200 SetPixelClip(x+8, y+i, 0);
\r
1201 SetPixelClip(x+10, y+i, 0);
\r
1202 SetPixelClip(x+12, y+i, 0);
\r
1203 SetPixelClip(x+14, y+i, 0);
\r
1206 SetPixelClip(x+0 +1, y+i, 0);
\r
1207 SetPixelClip(x+2 +1, y+i, 0);
\r
1208 SetPixelClip(x+4 +1, y+i, 0);
\r
1209 SetPixelClip(x+6 +1, y+i, 0);
\r
1210 SetPixelClip(x+8 +1, y+i, 0);
\r
1211 SetPixelClip(x+10 +1, y+i, 0);
\r
1212 SetPixelClip(x+12 +1, y+i, 0);
\r
1213 SetPixelClip(x+14 +1, y+i, 0);
\r
1219 void HLine(int x, int y, int x2, int color)
\r
1222 if (x2<x) SWAP(x,x2);
\r
1223 memset(screen+(y*sx)+x,color,x2-x+1);
\r
1227 void HLineClip(int x, int y, int x2, int color)
\r
1232 if (x2<x) SWAP(x,x2);
\r
1234 if (x>cx2 || y>cy2 || x+width<cx1 || y<cy1)
\r
1236 if (x+width > cx2) width=cx2-x+1;
\r
1237 if (x<cx1) { width-=(cx1-x); x=cx1; }
\r
1238 memset(screen+(y*sx)+x,color,width);
\r
1242 void HLineLucent(int x, int y, int x2, int color)
\r
1248 if (x2<x) SWAP(x,x2);
\r
1250 d=screen+(y*sx)+x;
\r
1251 for (; x<=x2; x++,d++)
\r
1252 *d=translucency_table[c|*d];
\r
1256 void HLineLucentClip(int x, int y, int x2, int color)
\r
1262 if (x2<x) SWAP(x,x2);
\r
1264 if (x>cx2 || y>cy2 || x+width<cx1 || y<cy1)
\r
1267 if (x+width > cx2) width=cx2-x+1;
\r
1268 if (x<cx1) { width-=(cx1-x); x=cx1; }
\r
1270 d=screen+(y*sx)+x;
\r
1271 for (x=0; x<width; x++,d++)
\r
1272 *d=translucency_table[c|*d];
\r
1276 void VLine(int x, int y, int y2, int color)
\r
1281 if (y2<y) SWAP(y,y2);
\r
1282 d=screen+(y*sx)+x;
\r
1283 for (; y<=y2; y++)
\r
1291 void VLineClip(int x, int y, int y2, int color)
\r
1297 if (y2<y) SWAP(y,y2);
\r
1299 if (x>cx2 || y>cy2 || x<cx1 || y+height<cy1)
\r
1305 if (y+height > cy2) height=cy2-y+1;
\r
1306 if (y<cy1) { height-=(cy1-y); y=cy1; }
\r
1307 d=screen+(y*sx)+x;
\r
1308 for (; height; height--)
\r
1316 void VLineLucent(int x, int y, int y2, int color)
\r
1322 if (y2<y) SWAP(y,y2);
\r
1325 d=screen+(y*sx)+x;
\r
1326 for (; y<=y2; y++)
\r
1328 *d=translucency_table[c|*d];
\r
1334 void VLineLucentClip(int x, int y, int y2, int color)
\r
1340 if (y2<y) SWAP(y,y2);
\r
1342 if (x>cx2 || y>cy2 || x<cx1 || y+height<cy1)
\r
1347 if (y+height > cy2) height=cy2-y+1;
\r
1348 if (y<cy1) { height-=(cy1-y); y=cy1; }
\r
1350 d=screen+(y*sx)+x;
\r
1351 for (; height; height--)
\r
1353 *d=translucency_table[c|*d];
\r
1359 // all the Line* routine were grabbed/modded from the Abuse source
\r
1361 void Line(int x1, int y1, int x2, int y2, int color)
\r
1363 short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;
\r
1378 // assume y1<=y2 from above swap operation
\r
1382 xc=(x2-x1); yc=(y2-y1);
\r
1383 if (xc<0) xi=-1; else xi=1;
\r
1384 if (yc<0) yi=-1; else yi=1;
\r
1385 n=abs(xc); m=abs(yc);
\r
1386 ycyi=abs(2*yc*xi);
\r
1391 xcxi=abs(2*xc*xi);
\r
1392 for (i=0;i<=n;i++)
\r
1394 screen[(dcy*sx)+dcx]=color;
\r
1405 xcyi=abs(2*xc*yi);
\r
1406 for (i=0;i<=m;i++)
\r
1408 screen[(dcy*sx)+dcx]=color;
\r
1420 // grabbed/modded from Abuse source
\r
1421 void LineClip(int x1, int y1, int x2, int y2, int color)
\r
1423 short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;
\r
1427 // check to see if the line is completly clipped off
\r
1428 if ((x1<cx1 && x2<cx1) || (x1>cx2 && x2>cx2)
\r
1429 || (y1<cy1 && y2<cy1) || (y1>cy2 && y2>cy2))
\r
1441 // clip the left side
\r
1443 { int myy=(y2-y1);
\r
1444 int mxx=(x2-x1),b;
\r
1452 b=y1-(y2-y1)*x1/mxx;
\r
1459 // clip the right side
\r
1461 { int myy=(y2-y1);
\r
1462 int mxx=(x2-x1),b;
\r
1470 b=y1-(y2-y1)*x1/mxx;
\r
1483 // clip the bottom
\r
1485 { int mxx=(x2-x1);
\r
1486 int myy=(y2-y1),b;
\r
1494 b=y1-(y2-y1)*x1/mxx;
\r
1495 x2=(cy2-b)*mxx/myy;
\r
1503 { int mxx=(x2-x1);
\r
1504 int myy=(y2-y1),b;
\r
1512 b=y1-(y2-y1)*x1/mxx;
\r
1513 x1=(cy1-b)*mxx/myy;
\r
1520 // see if it got cliped into the box, out out
\r
1521 if (x1<cx1 || x2<cx1 || x1>cx2 || x2>cx2 || y1<cy1 || y2 <cy1 || y1>cy2 || y2>cy2)
\r
1529 else { xi=x2; xc=x1; }
\r
1531 // assume y1<=y2 from above swap operation
\r
1535 xc=(x2-x1); yc=(y2-y1);
\r
1536 if (xc<0) xi=-1; else xi=1;
\r
1537 if (yc<0) yi=-1; else yi=1;
\r
1538 n=abs(xc); m=abs(yc);
\r
1539 ycyi=abs(2*yc*xi);
\r
1544 xcxi=abs(2*xc*xi);
\r
1545 for (i=0;i<=n;i++)
\r
1547 screen[(dcy*sx)+dcx]=color;
\r
1558 xcyi=abs(2*xc*yi);
\r
1559 for (i=0;i<=m;i++)
\r
1561 screen[(dcy*sx)+dcx]=color;
\r
1574 void LineLucent(int x1, int y1, int x2, int y2, int color)
\r
1576 short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;
\r
1593 // assume y1<=y2 from above swap operation
\r
1596 xc=(x2-x1); yc=(y2-y1);
\r
1597 if (xc<0) xi=-1; else xi=1;
\r
1598 if (yc<0) yi=-1; else yi=1;
\r
1599 n=abs(xc); m=abs(yc);
\r
1600 ycyi=abs(2*yc*xi);
\r
1603 c=color<<8; // for translucency
\r
1606 xcxi=abs(2*xc*xi);
\r
1607 for (i=0;i<=n;i++)
\r
1609 d=screen+(dcy*sx)+dcx;
\r
1610 *d=translucency_table[c|*d];
\r
1611 //screen[(dcy*sx)+dcx]=color;
\r
1622 xcyi=abs(2*xc*yi);
\r
1623 for (i=0;i<=m;i++)
\r
1625 d=screen+(dcy*sx)+dcx;
\r
1626 *d=translucency_table[c|*d];
\r
1627 //screen[(dcy*sx)+dcx]=color;
\r
1639 void LineLucentClip(int x1, int y1, int x2, int y2, int color)
\r
1641 short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;
\r
1647 // check to see if the line is completly clipped off
\r
1648 if ((x1<cx1 && x2<cx1) || (x1>cx2 && x2>cx2)
\r
1649 || (y1<cy1 && y2<cy1) || (y1>cy2 && y2>cy2))
\r
1661 // clip the left side
\r
1663 { int myy=(y2-y1);
\r
1664 int mxx=(x2-x1),b;
\r
1672 b=y1-(y2-y1)*x1/mxx;
\r
1679 // clip the right side
\r
1681 { int myy=(y2-y1);
\r
1682 int mxx=(x2-x1),b;
\r
1690 b=y1-(y2-y1)*x1/mxx;
\r
1703 // clip the bottom
\r
1705 { int mxx=(x2-x1);
\r
1706 int myy=(y2-y1),b;
\r
1714 b=y1-(y2-y1)*x1/mxx;
\r
1715 x2=(cy2-b)*mxx/myy;
\r
1723 { int mxx=(x2-x1);
\r
1724 int myy=(y2-y1),b;
\r
1732 b=y1-(y2-y1)*x1/mxx;
\r
1733 x1=(cy1-b)*mxx/myy;
\r
1740 // see if it got cliped into the box, out out
\r
1741 if (x1<cx1 || x2<cx1 || x1>cx2 || x2>cx2 || y1<cy1 || y2 <cy1 || y1>cy2 || y2>cy2)
\r
1749 else { xi=x2; xc=x1; }
\r
1751 // assume y1<=y2 from above swap operation
\r
1755 xc=(x2-x1); yc=(y2-y1);
\r
1756 if (xc<0) xi=-1; else xi=1;
\r
1757 if (yc<0) yi=-1; else yi=1;
\r
1758 n=abs(xc); m=abs(yc);
\r
1759 ycyi=abs(2*yc*xi);
\r
1762 c=color<<8; // for translucency
\r
1765 xcxi=abs(2*xc*xi);
\r
1766 for (i=0;i<=n;i++)
\r
1768 d=screen+(dcy*sx)+dcx;
\r
1769 *d=translucency_table[c|*d];
\r
1770 //screen[(dcy*sx)+dcx]=color;
\r
1781 xcyi=abs(2*xc*yi);
\r
1782 for (i=0;i<=m;i++)
\r
1784 d=screen+(dcy*sx)+dcx;
\r
1785 *d=translucency_table[c|*d];
\r
1786 //screen[(dcy*sx)+dcx]=color;
\r
1798 // All the Circle* routines were grabbed/modded from Allegro source
\r
1800 void Circle(int x, int y, int radius, int color)
\r
1806 int d_se=-2*radius+5;
\r
1811 SetPixel(x+cx,y+cy,color);
\r
1812 if (cx) SetPixel(x-cx,y+cy,color);
\r
1813 if (cy) SetPixel(x+cx,y-cy,color);
\r
1814 if ((cx) && (cy)) SetPixel(x-cx,y-cy,color);
\r
1818 SetPixel(x+cy,y+cx,color);
\r
1819 if (cx) SetPixel(x+cy,y-cx,color);
\r
1820 if (cy) SetPixel(x-cy,y+cx,color);
\r
1821 if (cx && cy) SetPixel(x-cy,y-cx,color);
\r
1838 } while (cx <= cy);
\r
1842 void CircleClip(int x, int y, int radius, int color)
\r
1848 int d_se=-2*radius+5;
\r
1852 SetPixelClip(x+cx,y+cy,color);
\r
1853 if (cx) SetPixelClip(x-cx,y+cy,color);
\r
1854 if (cy) SetPixelClip(x+cx,y-cy,color);
\r
1855 if ((cx) && (cy)) SetPixelClip(x-cx,y-cy,color);
\r
1859 SetPixelClip(x+cy,y+cx,color);
\r
1860 if (cx) SetPixelClip(x+cy,y-cx,color);
\r
1861 if (cy) SetPixelClip(x-cy,y+cx,color);
\r
1862 if (cx && cy) SetPixelClip(x-cy,y-cx,color);
\r
1879 } while (cx <= cy);
\r
1883 void CircleLucent(int x, int y, int radius, int color)
\r
1889 int d_se=-2*radius+5;
\r
1895 SetPixelLucent(x+cx,y+cy,color);
\r
1896 if (cx) SetPixelLucent(x-cx,y+cy,color);
\r
1897 if (cy) SetPixelLucent(x+cx,y-cy,color);
\r
1898 if ((cx) && (cy)) SetPixelLucent(x-cx,y-cy,color);
\r
1902 SetPixelLucent(x+cy,y+cx,color);
\r
1903 if (cx) SetPixelLucent(x+cy,y-cx,color);
\r
1904 if (cy) SetPixelLucent(x-cy,y+cx,color);
\r
1905 if (cx && cy) SetPixelLucent(x-cy,y-cx,color);
\r
1922 } while (cx <= cy);
\r
1926 void CircleLucentClip(int x, int y, int radius, int color)
\r
1932 int d_se=-2*radius+5;
\r
1937 SetPixelLucentClip(x+cx,y+cy,color);
\r
1938 if (cx) SetPixelLucentClip(x-cx,y+cy,color);
\r
1939 if (cy) SetPixelLucentClip(x+cx,y-cy,color);
\r
1940 if ((cx) && (cy)) SetPixelLucentClip(x-cx,y-cy,color);
\r
1944 SetPixelLucentClip(x+cy,y+cx,color);
\r
1945 if (cx) SetPixelLucentClip(x+cy,y-cx,color);
\r
1946 if (cy) SetPixelLucentClip(x-cy,y+cx,color);
\r
1947 if (cx && cy) SetPixelLucentClip(x-cy,y-cx,color);
\r
1964 } while (cx <= cy);
\r
1968 void CircleFill(int x, int y, int radius, int color)
\r
1974 int d_se=-2*radius+5;
\r
1980 HLine(x-cy,y-cx,x+cy,color);
\r
1981 if (cx) HLine(x-cy,y+cx,x+cy,color);
\r
1993 HLine(x-cx,y-cy,x+cx,color);
\r
1994 if (cy) HLine(x-cx,y+cy,x+cx,color);
\r
2002 } while (cx <= cy);
\r
2006 void CircleFillClip(int x, int y, int radius, int color)
\r
2012 int d_se=-2*radius+5;
\r
2017 HLineClip(x-cy,y-cx,x+cy,color);
\r
2018 if (cx) HLineClip(x-cy,y+cx,x+cy,color);
\r
2030 HLineClip(x-cx,y-cy,x+cx,color);
\r
2031 if (cy) HLineClip(x-cx,y+cy,x+cx,color);
\r
2039 } while (cx <= cy);
\r
2043 void CircleFillLucent(int x, int y, int radius, int color)
\r
2049 int d_se=-2*radius+5;
\r
2054 HLineLucent(x-cy,y-cx,x+cy,color);
\r
2055 if (cx) HLineLucent(x-cy,y+cx,x+cy,color);
\r
2067 HLineLucent(x-cx,y-cy,x+cx,color);
\r
2068 if (cy) HLineLucent(x-cx,y+cy,x+cx,color);
\r
2076 } while (cx <= cy);
\r
2080 void CircleFillLucentClip(int x, int y, int radius, int color)
\r
2086 int d_se=-2*radius+5;
\r
2091 HLineLucentClip(x-cy,y-cx,x+cy,color);
\r
2092 if (cx) HLineLucentClip(x-cy,y+cx,x+cy,color);
\r
2104 HLineLucentClip(x-cx,y-cy,x+cx,color);
\r
2105 if (cy) HLineLucentClip(x-cx,y+cy,x+cx,color);
\r
2113 } while (cx <= cy);
\r
2117 void Rect(int x, int y, int x2, int y2, int color)
\r
2119 HLine(x,y,x2,color);
\r
2120 HLine(x,y2,x2,color);
\r
2121 VLine(x,y+1,y2-1,color);
\r
2122 VLine(x2,y+1,y2-1,color);
\r
2125 void RectClip(int x, int y, int x2, int y2, int color)
\r
2127 HLineClip(x,y,x2,color);
\r
2128 HLineClip(x,y2,x2,color);
\r
2129 VLineClip(x,y+1,y2-1,color);
\r
2130 VLineClip(x2,y+1,y2-1,color);
\r
2133 void RectLucent(int x, int y, int x2, int y2, int color)
\r
2135 HLineLucent(x,y,x2,color);
\r
2136 HLineLucent(x,y2,x2,color);
\r
2137 VLineLucent(x,y+1,y2-1,color);
\r
2138 VLineLucent(x2,y+1,y2-1,color);
\r
2141 void RectLucentClip(int x, int y, int x2, int y2, int color)
\r
2143 HLineLucentClip(x,y,x2,color);
\r
2144 HLineLucentClip(x,y2,x2,color);
\r
2145 VLineLucentClip(x,y+1,y2-1,color);
\r
2146 VLineLucentClip(x2,y+1,y2-1,color);
\r
2149 void RectFill(int x, int y, int x2, int y2, int color)
\r
2152 if (y2<y) SWAP(y,y2);
\r
2153 for (; y<=y2; y++)
\r
2154 HLine(x,y,x2,color);
\r
2158 void RectFillClip(int x, int y, int x2, int y2, int color)
\r
2161 if (y2<y) SWAP(y,y2);
\r
2162 for (; y<=y2; y++)
\r
2163 HLineClip(x,y,x2,color);
\r
2167 void RectFillLucent(int x, int y, int x2, int y2, int color)
\r
2170 if (y2<y) SWAP(y,y2);
\r
2171 for (; y<=y2; y++)
\r
2172 HLineLucent(x,y,x2,color);
\r
2176 void RectFillLucentClip(int x, int y, int x2, int y2, int color)
\r
2179 if (y2<y) SWAP(y,y2);
\r
2180 for (; y<=y2; y++)
\r
2181 HLineLucentClip(x,y,x2,color);
\r
2185 // ============================================================================
\r
2186 // = aen's wrap blitters =
\r
2187 // ============================================================================
\r
2189 void WrapBlit(quad x, quad y, int wide, int high, byte *src)
\r
2195 byte *source,*dest;
\r
2207 if (curx+spanx>=clipw)
\r
2209 source=src+(y*wide)+x;
\r
2210 dest=screen+(cy1*sx)+cx1+curx;
\r
2215 spany=high-(cury?0:y);
\r
2216 if (cury+spany>=cliph)
\r
2219 for (i=0; i<spany; i++,source+=wide,dest+=sx)
\r
2220 memcpy(dest, source, spanx);
\r
2224 } while (cury<cliph);
\r
2226 } while (curx<clipw);
\r
2230 void WrapBlitMasked(quad x, quad y, int wide, int high, byte *src)
\r
2236 byte *source,*dest;
\r
2248 if (curx+spanx>=clipw)
\r
2250 source=src+(y*wide)+x;
\r
2251 dest=screen+(cy1*sx)+cx1+curx;
\r
2256 spany=high-(cury?0:y);
\r
2257 if (cury+spany>=cliph)
\r
2259 for (i=0; i<spany; i++,source+=wide,dest+=sx)
\r
2260 for (j=0; j<spanx; j++)
\r
2268 } while (cury<cliph);
\r
2270 } while (curx<clipw);
\r
2274 void WrapBlitLucent(quad x, quad y, int wide, int high, byte *src)
\r
2280 byte *source,*dest;
\r
2292 if (curx+spanx>=clipw)
\r
2294 source=src+(y*wide)+x;
\r
2295 dest=screen+(cy1*sx)+cx1+curx;
\r
2300 spany=high-(cury?0:y);
\r
2301 if (cury+spany>=cliph)
\r
2303 for (i=0; i<spany; i++,source+=wide,dest+=sx)
\r
2304 for (j=0; j<spanx; j++)
\r
2305 dest[j]=translucency_table[(source[j]<<8)|dest[j]];
\r
2308 } while (cury<cliph);
\r
2310 } while (curx<clipw);
\r
2314 void WrapBlitLucentMasked(quad x, quad y, int wide, int high, byte *src)
\r
2320 byte *source,*dest;
\r
2332 if (curx+spanx>=clipw)
\r
2334 source=src+(y*wide)+x;
\r
2335 dest=screen+(cy1*sx)+cx1+curx;
\r
2340 spany=high-(cury?0:y);
\r
2341 if (cury+spany>=cliph)
\r
2343 for (i=0; i<spany; i++,source+=wide,dest+=sx)
\r
2344 for (j=0; j<spanx; j++)
\r
2348 dest[j]=translucency_table[(c<<8)|dest[j]];
\r
2352 } while (cury<cliph);
\r
2354 } while (curx<clipw);
\r
2358 // ============================================================================
\r
2359 // = alias.zip / zero / aen rotational scaler routines =
\r
2360 // ============================================================================
\r
2362 void RotScale(int posx, int posy, quad width, quad height, float angle, float scale, byte *src)
\r
2364 // new! shamelessly ripped off from alias.zip
\r
2365 // except the atan2 stuff which i had to make up myself AEN so there :p
\r
2368 int sinas,cosas,xc,yc,srcx,srcy,x,y,tempx,tempy,T_WIDTH_CENTER,T_HEIGHT_CENTER,W_WIDTH_CENTER,W_HEIGHT_CENTER,W_HEIGHT,W_WIDTH;
\r
2372 ft=atan2((float)width,(float)height);
\r
2374 T_WIDTH_CENTER=width>>1;
\r
2375 T_HEIGHT_CENTER=height>>1;
\r
2376 W_WIDTH=((float)width/scale*sin(ft) + (float)height/scale*cos(ft));
\r
2378 W_HEIGHT_CENTER=W_HEIGHT>>1;
\r
2379 W_WIDTH_CENTER=W_HEIGHT_CENTER; //W_WIDTH/2;
\r
2381 sinas=sin(-angle)*65536*scale;
\r
2382 cosas=cos(-angle)*65536*scale;
\r
2384 xc=T_WIDTH_CENTER*65536 - (W_HEIGHT_CENTER*(cosas+sinas));
\r
2385 yc=T_HEIGHT_CENTER*65536 - (W_WIDTH_CENTER*(cosas-sinas));
\r
2386 posx-=W_WIDTH_CENTER;
\r
2387 posy-=W_HEIGHT_CENTER;
\r
2390 if (W_WIDTH<2 || W_HEIGHT<2) return;
\r
2394 if (posx>cx2 || posy>cy2 || posx+xl<cx1 || posy+yl<cy1)
\r
2396 if (posx+xl > cx2) xl=cx2-posx+1;
\r
2397 if (posy+yl > cy2) yl=cy2-posy+1;
\r
2404 xc+=cosas*xs; // woo!
\r
2413 xc+=sinas*ys; // woo!
\r
2417 dest=screen+posx+posy*sx;
\r
2418 for (y=0; y<yl; y++)
\r
2423 for (x=0; x<xl; x++)
\r
2428 if (tempx>=0 && tempx<width && tempy>=0 && tempy<height)
\r
2430 if ((pt=src[tempx+tempy*width]))
\r
2445 // ============================================================================
\r
2446 // = zero's Mosiac effects =
\r
2447 // ============================================================================
\r
2450 //TODO-need to asm optimize these badly! they are rather slow!
\r
2452 byte FindPalMatchForMosaic(quad r, quad g, quad b)
\r
2455 quad diffrecord,diff,record;
\r
2456 diffrecord=100000;
\r
2459 for(index=0; index<256; index++)
\r
2461 diff=abs(r-pal[index*3])+abs(g-pal[index*3+1])+abs(b-pal[index*3+2])+1;
\r
2462 if(diff<diffrecord)
\r
2465 if(diff==1) return index;
\r
2472 byte *InitMosaicTable(void)
\r
2476 tmp=(byte *)malloc(262144);
\r
2478 for(r=0; r<64; r++)
\r
2479 for(g=0; g<64; g++)
\r
2480 for(b=0; b<64; b++)
\r
2481 tmp[r*4096+g*64+b]=FindPalMatchForMosaic(r,g,b);
\r
2485 void Mosaic(quad xlevel, quad ylevel, byte *tbl, quad xmin, quad ymin, quad xmax, quad ymax)
\r
2487 quad x,y,rtot,btot,gtot,xloop,yloop,xfier,txlevel;
\r
2491 for(y=ymin; y<ymax; y+=ylevel)
\r
2493 for(x=xmin; x<xmax; x+=xlevel)
\r
2495 rtot=0; gtot=0; btot=0;
\r
2496 src=y*sx+x+screen;
\r
2497 if(ymax-y<ylevel) ylevel=ymax-y;
\r
2498 if(xmax-x<xlevel) txlevel=xmax-x; else txlevel=xlevel;
\r
2499 xfier=ylevel*txlevel;
\r
2500 for(yloop=0; yloop<ylevel; yloop++)
\r
2502 for(xloop=0; xloop<txlevel; xloop++)
\r
2504 rtot+=pal[*src*3];
\r
2505 gtot+=pal[*src*3+1];
\r
2506 btot+=pal[*src*3+2];
\r
2514 pixel=tbl[rtot*4096+gtot*64+btot];
\r
2515 src=y*sx+x+screen;
\r
2516 for(yloop=0; yloop<ylevel; yloop++)
\r
2518 for(xloop=0; xloop<txlevel; xloop++)
\r
2529 // ============================================================================
\r
2530 // = Mord's trifillers =
\r
2531 // ============================================================================
\r
2533 void FlatPoly(int x1, int y1, int x2, int y2, int x3, int y3, char color)
\r
2542 swaptemp=x1; x1=x3; x3=swaptemp;
\r
2543 swaptemp=y1; y1=y3; y3=swaptemp;
\r
2547 swaptemp=x2; x2=x3; x3=swaptemp;
\r
2548 swaptemp=y2; y2=y3; y3=swaptemp;
\r
2552 swaptemp=x1; x1=x2; x2=swaptemp;
\r
2553 swaptemp=y1; y1=y2; y2=swaptemp;
\r
2556 xstep2=((x3-x1) << 16) / (y3-y1);
\r
2561 xstep = ((x2-x1) << 16) / (y2-y1);
\r
2563 for (yon=y1;yon < y2; yon++)
\r
2565 if ((yon > -1) && (yon < 200))
\r
2567 HLineClip(xval>>16,yon,xval2>>16,color);
\r
2575 xstep = ((x3-x2) << 16) / (y3-y2);
\r
2577 for (yon=y2;yon < y3; yon++)
\r
2579 if ((yon > -1) && (yon < 200))
\r
2581 HLineClip(xval>>16,yon,xval2>>16,color);
\r
2590 int texw,texh; // those damn bastards want EVERYTHING!
\r
2592 void tmaphline(int x1, int x2, int y, int tx1, int tx2, int ty1, int ty2)
\r
2602 i=x1; x1=x2; x2=i;
\r
2603 i=tx1; tx1=tx2; tx2=i;
\r
2604 i=ty1; ty1=ty2; ty2=i;
\r
2606 if ((x1 > sx) || (x2 < 0)) return;
\r
2607 txstep=((tx2-tx1)<<16)/(x2-x1);
\r
2608 tystep=((ty2-ty1)<<16)/(x2-x1);
\r
2612 for (i=x1;i<x2;i++)
\r
2614 screen[y*sx+i] = image[(tyval>>16)*texw+(txval>>16)];
\r
2621 void TMapPoly(int x1, int y1, int x2, int y2, int x3, int y3,
\r
2622 int tx1, int ty1, int tx2, int ty2, int tx3, int ty3,
\r
2623 int tw, int th, char *img)
\r
2627 int txstep,txstep2;
\r
2628 int tystep,tystep2;
\r
2634 image=img; texw=tw; texh=th;
\r
2637 swaptemp=x1; x1=x3; x3=swaptemp;
\r
2638 swaptemp=y1; y1=y3; y3=swaptemp;
\r
2639 swaptemp=tx1; tx1=tx3; tx3=swaptemp;
\r
2640 swaptemp=ty1; ty1=ty3; ty3=swaptemp;
\r
2644 swaptemp=x2; x2=x3; x3=swaptemp;
\r
2645 swaptemp=y2; y2=y3; y3=swaptemp;
\r
2646 swaptemp=tx2; tx2=tx3; tx3=swaptemp;
\r
2647 swaptemp=ty2; ty2=ty3; ty3=swaptemp;
\r
2651 swaptemp=x1; x1=x2; x2=swaptemp;
\r
2652 swaptemp=y1; y1=y2; y2=swaptemp;
\r
2653 swaptemp=tx1; tx1=tx2; tx2=swaptemp;
\r
2654 swaptemp=ty1; ty1=ty2; ty2=swaptemp;
\r
2656 xstep2=((x3-x1) << 16) / (y3-y1);
\r
2658 txstep2=((tx3-tx1) << 16) / (y3-y1);
\r
2660 tystep2=((ty3-ty1) << 16) / (y3-y1);
\r
2665 xstep = ((x2-x1) << 16) / (y2-y1);
\r
2667 txstep = ((tx2-tx1) << 16) / (y2-y1);
\r
2668 txval = tx1 << 16;
\r
2669 tystep = ((ty2-ty1) << 16) / (y2-y1);
\r
2670 tyval = ty1 << 16;
\r
2672 for (yon=y1;yon < y2; yon++)
\r
2674 if ((yon > -1) && (yon < 200))
\r
2676 tmaphline(xval>>16,xval2>>16,yon,txval>>16,txval2>>16,
\r
2677 tyval>>16,tyval2>>16);
\r
2689 xstep = ((x3-x2) << 16) / (y3-y2);
\r
2691 txstep = ((tx3-tx2) << 16) / (y3-y2);
\r
2692 txval = tx2 << 16;
\r
2693 tystep = ((ty3-ty2) << 16) / (y3-y2);
\r
2694 tyval = ty2 << 16;
\r
2696 for (yon=y2;yon < y3; yon++)
\r
2698 if ((yon > -1) && (yon < 200))
\r
2700 tmaphline(xval>>16,xval2>>16,yon,txval>>16,txval2>>16,
\r
2701 tyval>>16,tyval2>>16);
\r
2714 // ============================================================================
\r
2715 // = aen's ripple-blitter =
\r
2716 // ============================================================================
\r
2719 int dispx[64],dispy[64];
\r
2721 void InitDisplaceStuff(float xmag, float ymag)
\r
2726 for (y=0; y<32; y++)
\r
2727 *d++=sin(y * (360.0/32) * (3.14/180))*xmag;
\r
2730 for (x=0; x<32; x++)
\r
2731 *d++=cos(x * (360.0/32) * (3.14/180))*ymag;
\r
2736 void CopyTileDisplace(int x, int y, unsigned char *spr)
\r
2739 int xx, yy, xt, yt;
\r
2743 xin = ((x+xwin)&31)<16 ? 0 : 16;
\r
2744 yin = ((y+ywin)&31)<16 ? 0 : 16;
\r
2745 dest=screen+(y*sx)+x;
\r
2747 // in the yy and xx calcs, +y and +x keep the start position correct
\r
2748 // within the 32 element lookup tables (ie. so they flow continuously
\r
2749 // across the 16x16 images).
\r
2751 for (j=0; j<16; j++)
\r
2753 yy = (j+yin+thresh) & 31;
\r
2754 for (i=0; i<16; i++)
\r
2756 xx = (i+xin+thresh) & 31;
\r
2757 xt = (i+dispx[yy]) & 15;
\r
2758 yt = (j+dispy[xx]) & 15;
\r
2760 dest[i]=spr[(yt*16)+xt];
\r
2766 void CopyTileDisplaceClip(int x, int y, unsigned char *spr)
\r
2771 int xx, yy, xt, yt;
\r
2778 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
2781 if (x+xl > cx2) xl=cx2-x+1;
\r
2782 if (y+yl > cy2) yl=cy2-y+1;
\r
2783 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
2784 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
2787 //if (ys) s+=(ys*width); // only perform mul if necessary ;)
\r
2789 d=screen+(y*sx)+x;
\r
2791 xin = ((x+xwin)&31)<16 ? 0 : 16; xin += xs;
\r
2792 yin = ((y+ywin)&31)<16 ? 0 : 16; yin += ys;
\r
2794 //dest=screen+(y*sx)+x;
\r
2796 // in the yy and xx calcs, +y and +x keep the start position correct
\r
2797 // within the 32 element lookup tables (ie. so they flow continuously
\r
2798 // across the 16x16 images).
\r
2800 for (j=0; j<yl; j++)
\r
2802 yy = (j+yin+thresh) & 31;
\r
2803 for (i=0; i<xl; i++)
\r
2805 xx = (i+xin+thresh) & 31;
\r
2806 xt = (i+xs+dispx[yy]) & 15;
\r
2807 yt = (j+ys+dispy[xx]) & 15;
\r
2809 d[i]=s[(yt*16)+xt];
\r