]> 4ch.mooo.com Git - 16.git/blob - 16/v2/source/ENGINE/VDRIVER.C
attempted font system added
[16.git] / 16 / v2 / source / ENGINE / VDRIVER.C
1 /*\r
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
15 */\r
16 \r
17 #define VDRIVER_H\r
18 \r
19 #include <malloc.h>\r
20 #include <mem.h>\r
21 #include <conio.h>\r
22 #include <math.h>\r
23 #include "verge.h"\r
24 \r
25 #define SWAP(a,b) { a-=b; b+=a; a=b-a; }\r
26 \r
27 // ================================= Data ====================================\r
28 \r
29 char *DriverDesc;\r
30 \r
31 byte *screen,*video,*vscreen;\r
32 byte pal[768], pal2[768];\r
33 byte *translucency_table;\r
34 \r
35 int sx, sy;\r
36 int tx, ty;\r
37 int tsx, tsy;\r
38 int cx1=0,cy1=0,cx2=319,cy2=199;\r
39 \r
40 // Driver function-pointers.\r
41 int (*ShutdownVideo) (int i);\r
42 int (*ShowPage) (void);\r
43 \r
44 // ================================= Code ====================================\r
45 \r
46 void SetPalette(byte *pall)\r
47 { quad i;\r
48 \r
49   outp(0x03c8, 0);\r
50   for (i=0; i<768; i++)\r
51     outp(0x03c9, pall[i]);\r
52 }\r
53 \r
54 void GetPalette()\r
55 { quad i;\r
56 \r
57   outp(0x03c7, 0);\r
58   for (i=0; i<768; i++)\r
59     pal[i]=inp(0x03c9);\r
60 }\r
61 \r
62 void set_intensity(quad n)\r
63 { quad i;\r
64 \r
65   for (i=0; i<768; i++)\r
66     pal2[i] = (pal[i] * n) >> 6;\r
67 \r
68   SetPalette(pal2);\r
69 }\r
70 \r
71 int LFB_ShowPage(void)\r
72 {\r
73   if (key[SCAN_ALT] && key[SCAN_X]) err("Exiting: ALT-X pressed.");\r
74   RenderGUI();\r
75   cpubyte=PFLIP;\r
76   memcpy(video,screen,sx*sy);\r
77   cpubyte=ETC;\r
78   return 0;\r
79 }\r
80 \r
81 void CopySprite(int x, int y, int width, int height, byte *src)\r
82 {\r
83   byte *d;\r
84 \r
85   cpubyte=RENDER;\r
86   d=screen+(y*sx)+x;\r
87   for (; height; height--)\r
88   {\r
89     memcpy(d,src,width);\r
90     src+=width;\r
91     d+=sx;\r
92   }\r
93   cpubyte=ETC;\r
94 }\r
95 \r
96 void TCopySprite(int x, int y, int width, int height, byte *src)\r
97 {\r
98   byte *d, c;\r
99 \r
100   cpubyte=RENDER;\r
101   d=screen+(y*sx)+x;\r
102   for (; height; height--)\r
103   {\r
104     for (x=0; x<width; x++,src++)\r
105     {\r
106       c=*src;\r
107       if (c)\r
108         d[x]=c;\r
109     }\r
110     d+=sx;\r
111   }\r
112   cpubyte=ETC;\r
113 }\r
114 \r
115 void CopySpriteLucent(int x, int y, int width, int height, byte *src)\r
116 {\r
117   byte *d;\r
118 \r
119   cpubyte=RENDER;\r
120   d=screen+(y*sx)+x;\r
121   for (; height; height--)\r
122   {\r
123     for (x=0; x<width; x++,src++)\r
124       d[x]=translucency_table[d[x]|(*src<<8)];\r
125     d+=sx;\r
126   }\r
127   cpubyte=ETC;\r
128 }\r
129 \r
130 void TCopySpriteLucent(int x, int y, int width, int height, byte *src)\r
131 {\r
132   byte *d, c;\r
133 \r
134   cpubyte=RENDER;\r
135   d=screen+(y*sx)+x;\r
136   for (; height; height--)\r
137   {\r
138     for (x=0; x<width; x++,src++)\r
139     {\r
140       c=*src;\r
141       if (c)\r
142         d[x]=translucency_table[d[x]|(c<<8)];\r
143     }\r
144     d+=sx;\r
145   }\r
146   cpubyte=ETC;\r
147 }\r
148 \r
149 void CopySpriteZoom(int x, int y, int sw, int sh, int dw, int dh, byte *src)\r
150 {\r
151   int i,j;\r
152   int xerr,yerr;\r
153   int xadj,yadj;\r
154   byte *d;\r
155 \r
156   cpubyte=RENDER;\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
161   yerr=0;\r
162 \r
163   for (i=0; i<dh; i++)\r
164   {\r
165     xerr=0;\r
166     for (j=0; j<dw; j++)\r
167     {\r
168       d[j]=src[(xerr>>16)];\r
169       xerr+=xadj;\r
170     }\r
171     d+=sx;\r
172     yerr+=yadj;\r
173     src+=(yerr>>16)*sw;\r
174     yerr &= 0xffff;\r
175   }\r
176   cpubyte=ETC;\r
177 }\r
178 \r
179 void TCopySpriteZoom(int x, int y, int sw, int sh, int dw, int dh, byte *src)\r
180 {\r
181   int i,j;\r
182   int xerr,yerr;\r
183   int xadj,yadj;\r
184   byte *d;\r
185   byte c;\r
186 \r
187   cpubyte=RENDER;\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
192   yerr=0;\r
193   for (i=0; i<dh; i++)\r
194   {\r
195     xerr=0;\r
196     for (j=0; j<dw; j++)\r
197     {\r
198       c=src[(xerr>>16)];\r
199       if (c)\r
200         d[j]=c;\r
201       xerr+=xadj;\r
202     }\r
203     d+=sx;\r
204     yerr+=yadj;\r
205     src+=(yerr>>16)*sw;\r
206     yerr &= 0xffff;\r
207   }\r
208   cpubyte=ETC;\r
209 }\r
210 \r
211 void CopySpriteZoomLucent(int x, int y, int sw, int sh, int dw, int dh, byte *src)\r
212 {\r
213   int i,j;\r
214   int xerr,yerr;\r
215   int xadj,yadj;\r
216   byte *d;\r
217 \r
218   cpubyte=RENDER;\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
223   yerr=0;\r
224 \r
225   for (i=0; i<dh; i++)\r
226   {\r
227     xerr=0;\r
228     for (j=0; j<dw; j++)\r
229     {\r
230       d[j]=translucency_table[d[j]|(src[(xerr>>16)]<<8)];\r
231       xerr+=xadj;\r
232     }\r
233     d+=sx;\r
234     yerr+=yadj;\r
235     src+=(yerr>>16)*sw;\r
236     yerr &= 0xffff;\r
237   }\r
238   cpubyte=ETC;\r
239 }\r
240 \r
241 void TCopySpriteZoomLucent(int x, int y, int sw, int sh, int dw, int dh, byte *src)\r
242 {\r
243   int i,j;\r
244   int xerr,yerr;\r
245   int xadj,yadj;\r
246   byte *d;\r
247   byte c;\r
248 \r
249   cpubyte=RENDER;\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
254   yerr=0;\r
255 \r
256   for (i=0; i<dh; i++)\r
257   {\r
258     xerr=0;\r
259     for (j=0; j<dw; j++)\r
260     {\r
261       c=src[(xerr>>16)];\r
262       if (c)\r
263         d[j]=c;\r
264       xerr+=xadj;\r
265     }\r
266     d+=sx;\r
267     yerr+=yadj;\r
268     src+=(yerr>>16)*sw;\r
269     yerr &= 0xffff;\r
270   }\r
271   cpubyte=ETC;\r
272 }\r
273 \r
274 void Silhouette(int x, int y, int width, int height, int color, byte *src)\r
275 {\r
276   byte *d=0;\r
277 \r
278   cpubyte=RENDER;\r
279   if (height<1 || width<1) return;\r
280   d=screen+(y*sx)+x;\r
281   do {\r
282     for (x=0; x<width; x++)\r
283     {\r
284       if (src[x])\r
285         d[x]=color;\r
286     }\r
287     src+=width;\r
288     d+=sx;\r
289   } while (--height);\r
290   cpubyte=ETC;\r
291 }\r
292 \r
293 void SilhouetteZoom(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)\r
294 {\r
295   int xerr=0,yerr=0;\r
296   int xadj=0,yadj=0;\r
297   byte *d=0;\r
298 \r
299   cpubyte=RENDER;\r
300   if (dw<1 || dh<1) return;\r
301   xadj=(sw<<16)/dw;\r
302   yadj=(sh<<16)/dh;\r
303   d=screen+(y*sx)+x;\r
304   yerr=0;\r
305   do {\r
306     xerr=0;\r
307     for (x=0; x<dw; x++)\r
308     {\r
309       if (src[(xerr>>16)])\r
310         d[x]=color;\r
311       xerr+=xadj;\r
312     }\r
313     d+=sx;\r
314     yerr+=yadj;\r
315     src+=(yerr>>16)*sw;\r
316     yerr &= 0xffff;\r
317   } while (--dh);\r
318   cpubyte=ETC;\r
319 }\r
320 \r
321 void SilhouetteLucent(int x, int y, int width, int height, int color, byte *src)\r
322 {\r
323   byte *d=0;\r
324   byte *range=0;\r
325 \r
326   cpubyte=RENDER;\r
327   if (width<1 || height<1) return;\r
328   d=screen+(y*sx)+x;\r
329   range=translucency_table+(color<<8);\r
330   do {\r
331     for (x=0; x<width; x++)\r
332     {\r
333       if (src[x])\r
334         d[x]=range[d[x]];\r
335     }\r
336     src+=width;\r
337     d+=sx;\r
338   } while (--height);\r
339   cpubyte=ETC;\r
340 }\r
341 \r
342 void SilhouetteZoomLucent(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)\r
343 {\r
344   int xerr=0,yerr=0;\r
345   int xadj=0,yadj=0;\r
346   byte *d=0;\r
347   byte *range=0;\r
348 \r
349   cpubyte=RENDER;\r
350   if (dw<1 || dh<1) return;\r
351   xadj=(sw<<16)/dw;\r
352   yadj=(sh<<16)/dh;\r
353   d=screen+(y*sx)+x;\r
354   range=translucency_table+(color<<8);\r
355   yerr=0;\r
356   do {\r
357     xerr=0;\r
358     for (x=0; x<dw; x++)\r
359     {\r
360       if (src[(xerr>>16)])\r
361         d[x]=range[d[x]];\r
362       xerr+=xadj;\r
363     }\r
364     d+=sx;\r
365     yerr+=yadj;\r
366     src+=(yerr>>16)*sw;\r
367     yerr &= 0xffff;\r
368   } while (--dh);\r
369   cpubyte=ETC;\r
370 }\r
371 \r
372 // aen\r
373 void Tint(int x, int y, int width, int height, int color, byte *src)\r
374 {\r
375   byte *d=0;\r
376   byte *range=0;\r
377   byte c=0;\r
378 \r
379   cpubyte=RENDER;\r
380   if (width<1 || height<1) return;\r
381   d=screen+(y*sx)+x;\r
382   range=translucency_table+(color<<8);\r
383   do {\r
384     for (x=0; x<width; x++)\r
385     {\r
386       c=src[x];\r
387       if (c)\r
388         d[x]=range[c];\r
389     }\r
390     src+=width;\r
391     d+=sx;\r
392   } while (--height);\r
393   cpubyte=ETC;\r
394 }\r
395 \r
396 // aen\r
397 void TintZoom(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)\r
398 {\r
399   int xerr=0,yerr=0;\r
400   int xadj=0,yadj=0;\r
401   byte *d=0;\r
402   byte *range=0;\r
403   byte c=0;\r
404 \r
405   cpubyte=RENDER;\r
406   if (dw<1 || dh<1) return;\r
407   xadj=(sw<<16)/dw;\r
408   yadj=(sh<<16)/dh;\r
409   d=screen+(y*sx)+x;\r
410   range=translucency_table+(color<<8);\r
411   yerr=0;\r
412   do {\r
413     xerr=0;\r
414     for (x=0; x<dw; x++)\r
415     {\r
416       c=src[(xerr>>16)];\r
417       if (c)\r
418         d[x]=range[c];\r
419       xerr+=xadj;\r
420     }\r
421     d+=sx;\r
422     yerr+=yadj;\r
423     src+=(yerr>>16)*sw;\r
424     yerr &= 0xffff;\r
425   } while (--dh);\r
426   cpubyte=ETC;\r
427 }\r
428 \r
429 void CopySpriteClip(int x, int y, int width, int height, byte *src)\r
430 {\r
431   byte *s,*d;\r
432   int xl,yl,xs,ys;\r
433 \r
434   cpubyte=RENDER;\r
435   xl=width;\r
436   yl=height;\r
437   xs=ys=0;\r
438   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
439     return;\r
440 \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
445 \r
446   s=src+(ys*width)+xs;\r
447   d=screen+(y*sx)+x;\r
448 \r
449   for (; yl; yl--)\r
450   {\r
451     memcpy(d,s,xl);\r
452     s+=width;\r
453     d+=sx;\r
454   }\r
455   cpubyte=ETC;\r
456 }\r
457 \r
458 void TCopySpriteClip(int x, int y, int width, int height, byte *src)\r
459 {\r
460   byte *s,*d,c;\r
461   int xl,yl,xs,ys;\r
462 \r
463   cpubyte=RENDER;\r
464   xl=width;\r
465   yl=height;\r
466   xs=ys=0;\r
467   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
468     return;\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
474   d=screen+(y*sx)+x;\r
475 \r
476   for (; yl; yl--)\r
477   {\r
478     for (x=0; x<xl; x++)\r
479     {\r
480       c=s[x];\r
481       if (c)\r
482         d[x]=c;\r
483     }\r
484     s+=width;\r
485     d+=sx;\r
486   }\r
487   cpubyte=ETC;\r
488 }\r
489 \r
490 void CopySpriteLucentClip(int x, int y, int width, int height, byte *src)\r
491 {\r
492   byte *s,*d;\r
493   int xl,yl,xs,ys;\r
494 \r
495   cpubyte=RENDER;\r
496   xl=width;\r
497   yl=height;\r
498   xs=ys=0;\r
499   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
500     return;\r
501 \r
502   if (x+xl > cx2) xl=cx2-x+1;\r
503   if (y+yl > cy2) yl=cy2-y+1;\r
504 \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
507 \r
508   s=src+(ys*width)+xs;\r
509   d=screen+(y*sx)+x;\r
510 \r
511   for (; yl; yl--)\r
512   {\r
513     for (x=0; x<xl; x++)\r
514       d[x]=translucency_table[d[x]|(s[x]<<8)];\r
515 \r
516     s+=width;\r
517     d+=sx;\r
518   }\r
519   cpubyte=ETC;\r
520 }\r
521 \r
522 void TCopySpriteLucentClip(int x, int y, int width, int height, byte *src)\r
523 {\r
524   byte *s,*d,c;\r
525   int xl,yl,xs,ys;\r
526 \r
527   cpubyte=RENDER;\r
528   xl=width;\r
529   yl=height;\r
530   xs=ys=0;\r
531   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
532     return;\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
537 \r
538   s=src+(ys*width)+xs;\r
539   d=screen+(y*sx)+x;\r
540 \r
541   for (; yl; yl--)\r
542   {\r
543     for (x=0; x<xl; x++)\r
544     {\r
545       c=s[x];\r
546       if (c)\r
547         d[x]=translucency_table[d[x]|(c<<8)];\r
548     }\r
549     s+=width;\r
550     d+=sx;\r
551   }\r
552   cpubyte=ETC;\r
553 }\r
554 \r
555 void CopySpriteZoomClip(int x, int y, int sw, int sh, int dw, int dh, byte *src)\r
556 {\r
557   int i,j;\r
558   int xerr,yerr;\r
559   int xerr_start, yerr_start;\r
560   int xadj,yadj;\r
561   byte *d;\r
562   int xl,yl,xs,ys;\r
563 \r
564   cpubyte=RENDER;\r
565 \r
566   if (dw<1 || dh<1) return;\r
567   xl=dw;\r
568   yl=dh;\r
569   xs=ys=0;\r
570   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
571     return;\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
576 \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
581 \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
586   {\r
587     xerr = xerr_start;\r
588     for (j=0; j<xl; j++)\r
589     {\r
590       d[j]=src[(xerr>>16)];\r
591       xerr+=xadj;\r
592     }\r
593     d+=sx;\r
594     yerr += yadj;\r
595     src += (yerr>>16)*sw;\r
596     yerr &= 0xffff;\r
597   }\r
598   cpubyte=ETC;\r
599 }\r
600 \r
601 void TCopySpriteZoomClip(int x, int y, int sw, int sh, int dw, int dh, byte *src)\r
602 {\r
603   int i,j;\r
604   int xerr,yerr;\r
605   int xerr_start, yerr_start;\r
606   int xadj,yadj;\r
607   byte *d;\r
608   byte c;\r
609   int xl,yl,xs,ys;\r
610 \r
611   cpubyte=RENDER;\r
612   if (dw<1 || dh<1) return;\r
613 \r
614   xl=dw;\r
615   yl=dh;\r
616   xs=ys=0;\r
617   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
618     return;\r
619 \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
628 \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
633   {\r
634     xerr = xerr_start;\r
635     for (j=0; j<xl; j++)\r
636     {\r
637       c=src[(xerr>>16)];\r
638       if (c)\r
639         d[j]=c;\r
640       xerr+=xadj;\r
641     }\r
642     d+=sx;\r
643     yerr += yadj;\r
644     src += (yerr>>16)*sw;\r
645     yerr &= 0xffff;\r
646   }\r
647   cpubyte=ETC;\r
648 }\r
649 \r
650 void CopySpriteZoomLucentClip(int x, int y, int sw, int sh, int dw, int dh, byte *src)\r
651 {\r
652   int i,j;\r
653   int xerr,yerr;\r
654   int xerr_start, yerr_start;\r
655   int xadj,yadj;\r
656   byte *d;\r
657   int xl,yl,xs,ys;\r
658 \r
659   cpubyte=RENDER;\r
660   if (dw<1 || dh<1) return;\r
661   xl=dw;\r
662   yl=dh;\r
663   xs=ys=0;\r
664 \r
665   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
666     return;\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
675 \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
680   {\r
681     xerr = xerr_start;\r
682     for (j=0; j<xl; j++)\r
683     {\r
684       d[j]=translucency_table[d[j]|(src[(xerr>>16)]<<8)];\r
685       xerr+=xadj;\r
686     }\r
687     d+=sx;\r
688     yerr += yadj;\r
689     src += (yerr>>16)*sw;\r
690     yerr &= 0xffff;\r
691   }\r
692   cpubyte=ETC;\r
693 }\r
694 \r
695 void TCopySpriteZoomLucentClip(int x, int y, int sw, int sh, int dw, int dh, byte *src)\r
696 {\r
697   int i,j;\r
698   int xerr,yerr;\r
699   int xerr_start, yerr_start;\r
700   int xadj,yadj;\r
701   byte *d;\r
702   int c;\r
703   int xl,yl,xs,ys;\r
704 \r
705   cpubyte=RENDER;\r
706   if (dw<1 || dh<1) return;\r
707   xl=dw;\r
708   yl=dh;\r
709   xs=ys=0;\r
710   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
711     return;\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
716 \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
725   {\r
726     xerr = xerr_start;\r
727     for (j=0; j<xl; j++)\r
728     {\r
729       c=src[(xerr>>16)];\r
730       if (c)\r
731         d[j]=translucency_table[d[j]|(c<<8)];\r
732       xerr+=xadj;\r
733     }\r
734     d+=sx;\r
735     yerr += yadj;\r
736     src += (yerr>>16)*sw;\r
737     yerr &= 0xffff;\r
738   }\r
739   cpubyte=ETC;\r
740 }\r
741 \r
742 void SilhouetteClip(int x, int y, int width, int height, int color, byte *src)\r
743 {\r
744   byte *s=0,*d=0;\r
745   int xl=0,yl=0,xs=0,ys=0;\r
746 \r
747   cpubyte=RENDER;\r
748   xl=width;\r
749   yl=height;\r
750   xs=ys=0;\r
751   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
752     return;\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
758   d=screen+(y*sx)+x;\r
759 \r
760   for (; yl; yl--)\r
761   {\r
762     for (x=0; x<xl; x++)\r
763     {\r
764       if (s[x])\r
765         d[x]=color;\r
766     }\r
767     s+=width;\r
768     d+=sx;\r
769   }\r
770   cpubyte=ETC;\r
771 }\r
772 \r
773 void SilhouetteZoomClip(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)\r
774 {\r
775   int xerr=0,yerr=0;\r
776   int xerr_start=0, yerr_start=0;\r
777   int xadj=0,yadj=0;\r
778   byte *d=0;\r
779   int xl=0,yl=0,xs=0,ys=0;\r
780 \r
781   cpubyte=RENDER;\r
782   if (dw<1 || dh<1) return;\r
783 \r
784   xl=dw;\r
785   yl=dh;\r
786   xs=ys=0;\r
787   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
788     return;\r
789 \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
798 \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
803   {\r
804     xerr = xerr_start;\r
805     for (x=0; x<xl; x++)\r
806     {\r
807       if (src[(xerr>>16)])\r
808         d[x]=color;\r
809       xerr+=xadj;\r
810     }\r
811     d+=sx;\r
812     yerr += yadj;\r
813     src += (yerr>>16)*sw;\r
814     yerr &= 0xffff;\r
815   }\r
816   cpubyte=ETC;\r
817 }\r
818 \r
819 void SilhouetteLucentClip(int x, int y, int width, int height, int color, byte *src)\r
820 {\r
821   byte *s=0,*d=0;\r
822   int xl=0,yl=0,xs=0,ys=0;\r
823   byte *range=0;\r
824 \r
825   cpubyte=RENDER;\r
826   xl=width;\r
827   yl=height;\r
828   xs=ys=0;\r
829   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
830     return;\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
835 \r
836   s=src+(ys*width)+xs;\r
837   d=screen+(y*sx)+x;\r
838   range=translucency_table+(color<<8);\r
839   for (; yl; yl--)\r
840   {\r
841     for (x=0; x<xl; x++)\r
842     {\r
843       if (s[x])\r
844         d[x]=range[d[x]];\r
845     }\r
846     s+=width;\r
847     d+=sx;\r
848   }\r
849   cpubyte=ETC;\r
850 }\r
851 \r
852 void SilhouetteZoomLucentClip(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)\r
853 {\r
854   int xerr=0,yerr=0;\r
855   int xerr_start=0, yerr_start=0;\r
856   int xadj=0,yadj=0;\r
857   byte *d=0;\r
858   int xl=0,yl=0,xs=0,ys=0;\r
859   byte *range=0;\r
860 \r
861   cpubyte=RENDER;\r
862   if (dw<1 || dh<1) return;\r
863   xl=dw;\r
864   yl=dh;\r
865   xs=ys=0;\r
866   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
867     return;\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
872 \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
882   {\r
883     xerr = xerr_start;\r
884     for (x=0; x<xl; x++)\r
885     {\r
886       if (src[(xerr>>16)])\r
887         d[x]=range[d[x]];\r
888       xerr+=xadj;\r
889     }\r
890     d+=sx;\r
891     yerr += yadj;\r
892     src += (yerr>>16)*sw;\r
893     yerr &= 0xffff;\r
894   }\r
895   cpubyte=ETC;\r
896 }\r
897 \r
898 // aen\r
899 void TintClip(int x, int y, int width, int height, int color, byte *src)\r
900 {\r
901   byte *s=0,*d=0;\r
902   int xl=0,yl=0,xs=0,ys=0;\r
903   byte *range=0;\r
904   byte c=0;\r
905 \r
906   cpubyte=RENDER;\r
907   xl=width;\r
908   yl=height;\r
909   xs=ys=0;\r
910   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
911     return;\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
916 \r
917   s=src+(ys*width)+xs;\r
918   d=screen+(y*sx)+x;\r
919   range=translucency_table+(color<<8);\r
920   for (; yl; yl--)\r
921   {\r
922     for (x=0; x<xl; x++)\r
923     {\r
924       c=s[x];\r
925       if (c)\r
926         d[x]=range[c];\r
927     }\r
928     s+=width;\r
929     d+=sx;\r
930   }\r
931   cpubyte=ETC;\r
932 }\r
933 \r
934 // aen\r
935 void TintZoomClip(int x, int y, int sw, int sh, int dw, int dh, int color, byte *src)\r
936 {\r
937   int xerr=0,yerr=0;\r
938   int xerr_start=0, yerr_start=0;\r
939   int xadj=0,yadj=0;\r
940   byte *d=0;\r
941   int xl=0,yl=0,xs=0,ys=0;\r
942   byte *range=0;\r
943   byte c=0;\r
944 \r
945   cpubyte=RENDER;\r
946   if (dw<1 || dh<1) return;\r
947   xl=dw;\r
948   yl=dh;\r
949   xs=ys=0;\r
950   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
951     return;\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
956 \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
966   {\r
967     xerr = xerr_start;\r
968     for (x=0; x<xl; x++)\r
969     {\r
970       c=src[(xerr>>16)];\r
971       if (c)\r
972         d[x]=range[c];\r
973       xerr+=xadj;\r
974     }\r
975     d+=sx;\r
976     yerr += yadj;\r
977     src += (yerr>>16)*sw;\r
978     yerr &= 0xffff;\r
979   }\r
980   cpubyte=ETC;\r
981 }\r
982 \r
983 void CopyTile(int x, int y, byte *src)\r
984 {\r
985   CopySpriteClip(x,y,16,16,src);\r
986 }\r
987 \r
988 void TCopyTile(int x, int y, byte *src, byte *matte)\r
989 {\r
990   matte=matte;\r
991   TCopySpriteClip(x,y,16,16,src);\r
992 }\r
993 \r
994 void CopyTileLucent(int x, int y, byte *src)\r
995 {\r
996   CopySpriteLucentClip(x,y,16,16,src);\r
997 }\r
998 \r
999 void TCopyTileLucent(int x, int y, byte *src)\r
1000 {\r
1001   TCopySpriteLucentClip(x,y,16,16,src);\r
1002 }\r
1003 \r
1004 void CopyTileClip(int x, int y, byte *src)\r
1005 {\r
1006   CopySpriteClip(x,y,16,16,src);\r
1007 }\r
1008 \r
1009 void TCopyTileClip(int x, int y, byte *src, byte *matte)\r
1010 {\r
1011   matte=matte;\r
1012   TCopySpriteClip(x,y,16,16,src);\r
1013 }\r
1014 \r
1015 void CopyTileLucentClip(int x, int y, byte *src)\r
1016 {\r
1017   CopySpriteLucentClip(x,y,16,16,src);\r
1018 }\r
1019 \r
1020 void TCopyTileLucentClip(int x, int y, byte *src)\r
1021 {\r
1022   TCopySpriteLucentClip(x,y,16,16,src);\r
1023 }\r
1024 \r
1025 // aen\r
1026 void MapLine(int x, int y, int yofs, word *map)\r
1027 {\r
1028   byte *d;\r
1029   int tilesx,startx;\r
1030   int counter;\r
1031   int span, s;\r
1032 \r
1033   cpubyte=RENDER;\r
1034 \r
1035   // y clipping\r
1036   if (y<0 || y>=tsy) return;\r
1037   // x clipping\r
1038   startx=0;\r
1039   if (x<0) { startx=-x; x=0; }\r
1040 \r
1041   d=screen+(y*sx)+x;\r
1042   tilesx=(tsx/16);\r
1043 \r
1044   // do clipped left tile\r
1045   counter=0;\r
1046   s=tileidx[*map];\r
1047   memcpy(d, vsp+((s<numtiles ? s : 0)*256)+(yofs*16)+startx, 16-startx);\r
1048   d+=16-startx;\r
1049   counter+=16-startx;\r
1050   map++;\r
1051   // do midsection of line\r
1052   for (x=1; x<tilesx; x++,counter+=16)\r
1053   {\r
1054     s=tileidx[*map];\r
1055     memcpy(d, vsp+((s<numtiles ? s : 0)*256)+(yofs*16), 16);\r
1056 \r
1057     d+=16;\r
1058     map++;\r
1059   }\r
1060   // do clipped right tile\r
1061   while (counter<tsx)\r
1062   {\r
1063     span=(tsx-counter);\r
1064     if (span>16) span=16;\r
1065     s=tileidx[*map];\r
1066     memcpy(d, vsp+((s<numtiles ? s : 0)*256)+(yofs*16), span);\r
1067     d+=span;\r
1068     counter+=span;\r
1069     map++;\r
1070   }\r
1071 \r
1072   cpubyte=ETC;\r
1073 }\r
1074 \r
1075 // aen\r
1076 void TMapLine(int x, int y, int yofs, word *map)\r
1077 {\r
1078   byte *s,*d;\r
1079   byte c;\r
1080   int tilesx,startx;\r
1081   int counter;\r
1082   int span;\r
1083 \r
1084   cpubyte=RENDER;\r
1085 \r
1086   // y clipping\r
1087   if (y<0 || y>=tsy) return;\r
1088   // x clipping\r
1089   startx=0;\r
1090   if (x<0) { startx=-x; x=0; }\r
1091 \r
1092   d=screen+(y*sx)+x;\r
1093   tilesx=(tsx/16);\r
1094 \r
1095   // do clipped left tile\r
1096   counter=0;\r
1097   s=vsp+(256*tileidx[*map])+(16*yofs)+startx;\r
1098   for (x=0; x<16-startx; x++)\r
1099   {\r
1100     c=s[x];\r
1101     if (c)\r
1102       d[x]=c;\r
1103   }\r
1104   d+=16-startx;\r
1105   counter+=16-startx;\r
1106   map++;\r
1107   // do midsection of line\r
1108   for (y=1; y<tilesx; y++,counter+=16)\r
1109   {\r
1110     s=vsp+(256*tileidx[*map])+(16*yofs);\r
1111     for (x=0; x<16; x++)\r
1112     {\r
1113       c=s[x];\r
1114       if (c)\r
1115         d[x]=c;\r
1116     }\r
1117     d+=16;\r
1118     map++;\r
1119   }\r
1120   // do clipped right tile\r
1121   while (counter<tsx)\r
1122   {\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
1127     {\r
1128       c=s[x];\r
1129       if (c)\r
1130         d[x]=c;\r
1131     }\r
1132     d+=span;\r
1133     counter+=span;\r
1134     map++;\r
1135   }\r
1136 \r
1137   cpubyte=ETC;\r
1138 }\r
1139 \r
1140 void ClearScreen()\r
1141 {\r
1142   cpubyte=RENDER;\r
1143   memset(screen, 0, sx*sy);\r
1144   cpubyte=ETC;\r
1145 }\r
1146 \r
1147 void SetPixel(int x, int y, int color)\r
1148 {\r
1149   screen[(y*sx)+x]=color;\r
1150 }\r
1151 \r
1152 void SetPixelLucent(int x, int y, int color)\r
1153 {\r
1154   byte *d;\r
1155 \r
1156   cpubyte=RENDER;\r
1157   d=screen+(y*sx)+x;\r
1158   *d=translucency_table[*d|(color<<8)];\r
1159   cpubyte=ETC;\r
1160 }\r
1161 \r
1162 void SetPixelClip(int x, int y, int color)\r
1163 {\r
1164   if (x<cx1 || y<cy1 || x>cx2 || y>cy2) return;\r
1165   screen[(y*sx)+x]=color;\r
1166 }\r
1167 \r
1168 void SetPixelLucentClip(int x, int y, int color)\r
1169 {\r
1170   byte *d;\r
1171 \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
1175 }\r
1176 \r
1177 int GetPixel(int x, int y)\r
1178 {\r
1179   return screen[(y*sx)+x];\r
1180 }\r
1181 \r
1182 int GetPixelClip(int x, int y)\r
1183 {\r
1184   if (x<cx1 || y<cy1 || x>cx2 || y>cy2) return 0;\r
1185   return screen[(y*sx)+x];\r
1186 }\r
1187 \r
1188 void ColorField(int x, int y, char c)\r
1189 {\r
1190   int i;\r
1191 \r
1192   cpubyte=RENDER;\r
1193   i=0;\r
1194   do\r
1195   {\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
1204     i++;\r
1205 \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
1214     i++;\r
1215   } while (i<16);\r
1216   cpubyte=ETC;\r
1217 }\r
1218 \r
1219 void HLine(int x, int y, int x2, int color)\r
1220 {\r
1221   cpubyte=RENDER;\r
1222   if (x2<x) SWAP(x,x2);\r
1223   memset(screen+(y*sx)+x,color,x2-x+1);\r
1224   cpubyte=ETC;\r
1225 }\r
1226 \r
1227 void HLineClip(int x, int y, int x2, int color)\r
1228 {\r
1229   int width;\r
1230 \r
1231   cpubyte=RENDER;\r
1232   if (x2<x) SWAP(x,x2);\r
1233   width=x2-x+1;\r
1234   if (x>cx2 || y>cy2 || x+width<cx1 || y<cy1)\r
1235     return;\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
1239   cpubyte=ETC;\r
1240 }\r
1241 \r
1242 void HLineLucent(int x, int y, int x2, int color)\r
1243 {\r
1244   byte *d;\r
1245   int c;\r
1246 \r
1247   cpubyte=RENDER;\r
1248   if (x2<x) SWAP(x,x2);\r
1249   c=color<<8;\r
1250   d=screen+(y*sx)+x;\r
1251   for (; x<=x2; x++,d++)\r
1252     *d=translucency_table[c|*d];\r
1253   cpubyte=ETC;\r
1254 }\r
1255 \r
1256 void HLineLucentClip(int x, int y, int x2, int color)\r
1257 {\r
1258   byte *d;\r
1259   int c,width;\r
1260 \r
1261   cpubyte=RENDER;\r
1262   if (x2<x) SWAP(x,x2);\r
1263   width=x2-x+1;\r
1264   if (x>cx2 || y>cy2 || x+width<cx1 || y<cy1)\r
1265     return;\r
1266 \r
1267   if (x+width > cx2) width=cx2-x+1;\r
1268   if (x<cx1) { width-=(cx1-x); x=cx1; }\r
1269   c=color<<8;\r
1270   d=screen+(y*sx)+x;\r
1271   for (x=0; x<width; x++,d++)\r
1272     *d=translucency_table[c|*d];\r
1273   cpubyte=ETC;\r
1274 }\r
1275 \r
1276 void VLine(int x, int y, int y2, int color)\r
1277 {\r
1278   byte *d;\r
1279 \r
1280   cpubyte=RENDER;\r
1281   if (y2<y) SWAP(y,y2);\r
1282   d=screen+(y*sx)+x;\r
1283   for (; y<=y2; y++)\r
1284   {\r
1285     *d=color;\r
1286     d+=sx;\r
1287   }\r
1288   cpubyte=ETC;\r
1289 }\r
1290 \r
1291 void VLineClip(int x, int y, int y2, int color)\r
1292 {\r
1293   byte *d;\r
1294   int height;\r
1295 \r
1296   cpubyte=RENDER;\r
1297   if (y2<y) SWAP(y,y2);\r
1298   height=y2-y+1;\r
1299   if (x>cx2 || y>cy2 || x<cx1 || y+height<cy1)\r
1300   {\r
1301     cpubyte=ETC;\r
1302     return;\r
1303   }\r
1304 \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
1309   {\r
1310     *d=color;\r
1311     d+=sx;\r
1312   }\r
1313   cpubyte=ETC;\r
1314 }\r
1315 \r
1316 void VLineLucent(int x, int y, int y2, int color)\r
1317 {\r
1318   byte *d;\r
1319   int c;\r
1320 \r
1321   cpubyte=RENDER;\r
1322   if (y2<y) SWAP(y,y2);\r
1323 \r
1324   c=color<<8;\r
1325   d=screen+(y*sx)+x;\r
1326   for (; y<=y2; y++)\r
1327   {\r
1328     *d=translucency_table[c|*d];\r
1329     d+=sx;\r
1330   }\r
1331   cpubyte=ETC;\r
1332 }\r
1333 \r
1334 void VLineLucentClip(int x, int y, int y2, int color)\r
1335 {\r
1336   byte *d;\r
1337   int c,height;\r
1338 \r
1339   cpubyte=RENDER;\r
1340   if (y2<y) SWAP(y,y2);\r
1341   height=y2-y+1;\r
1342   if (x>cx2 || y>cy2 || x<cx1 || y+height<cy1)\r
1343   {\r
1344     cpubyte=ETC;\r
1345     return;\r
1346   }\r
1347   if (y+height > cy2) height=cy2-y+1;\r
1348   if (y<cy1) { height-=(cy1-y); y=cy1; }\r
1349   c=color<<8;\r
1350   d=screen+(y*sx)+x;\r
1351   for (; height; height--)\r
1352   {\r
1353     *d=translucency_table[c|*d];\r
1354     d+=sx;\r
1355   }\r
1356   cpubyte=ETC;\r
1357 }\r
1358 \r
1359 // all the Line* routine were grabbed/modded from the Abuse source\r
1360 \r
1361 void Line(int x1, int y1, int x2, int y2, int color)\r
1362 {\r
1363   short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;\r
1364   unsigned dcy,dcx;\r
1365 \r
1366   cpubyte=RENDER;\r
1367   if (x1>x2)\r
1368   {\r
1369     SWAP(x1,x2);\r
1370     SWAP(y1,y2);\r
1371   }\r
1372 \r
1373   if (y1>y2)\r
1374   {\r
1375     SWAP(x1,x2);\r
1376     SWAP(y1,y2);\r
1377   }\r
1378   // assume y1<=y2 from above swap operation\r
1379   yi=y2; yc=y1;\r
1380 \r
1381   dcx=x1; dcy=y1;\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
1387   er=0;\r
1388 \r
1389   if (n>m)\r
1390   {\r
1391     xcxi=abs(2*xc*xi);\r
1392     for (i=0;i<=n;i++)\r
1393     {\r
1394       screen[(dcy*sx)+dcx]=color;\r
1395       if (er>0)\r
1396       { dcy+=yi;\r
1397         er-=xcxi;\r
1398       }\r
1399       er+=ycyi;\r
1400       dcx+=xi;\r
1401     }\r
1402   }\r
1403   else\r
1404   {\r
1405     xcyi=abs(2*xc*yi);\r
1406     for (i=0;i<=m;i++)\r
1407     {\r
1408       screen[(dcy*sx)+dcx]=color;\r
1409       if (er>0)\r
1410       { dcx+=xi;\r
1411         er-=ycyi;\r
1412       }\r
1413       er+=xcyi;\r
1414       dcy+=yi;\r
1415     }\r
1416   }\r
1417   cpubyte=ETC;\r
1418 }\r
1419 \r
1420 // grabbed/modded from Abuse source\r
1421 void LineClip(int x1, int y1, int x2, int y2, int color)\r
1422 {\r
1423   short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;\r
1424   unsigned dcy,dcx;\r
1425 \r
1426   cpubyte=RENDER;\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
1430   {\r
1431     cpubyte=ETC;\r
1432     return;\r
1433   }\r
1434 \r
1435   if (x1>x2)\r
1436   {\r
1437     SWAP(x1,x2);\r
1438     SWAP(y1,y2);\r
1439   }\r
1440 \r
1441   // clip the left side\r
1442   if (x1<cx1)\r
1443   { int myy=(y2-y1);\r
1444     int mxx=(x2-x1),b;\r
1445     if (!mxx)\r
1446     {\r
1447       cpubyte=ETC;\r
1448       return;\r
1449     }\r
1450     if (myy)\r
1451     {\r
1452       b=y1-(y2-y1)*x1/mxx;\r
1453       y1=myy*cx1/mxx+b;\r
1454       x1=cx1;\r
1455     }\r
1456     else x1=cx1;\r
1457   }\r
1458 \r
1459   // clip the right side\r
1460   if (x2>cx2)\r
1461   { int myy=(y2-y1);\r
1462     int mxx=(x2-x1),b;\r
1463     if (!mxx)\r
1464     {\r
1465       cpubyte=ETC;\r
1466       return;\r
1467     }\r
1468     if (myy)\r
1469     {\r
1470       b=y1-(y2-y1)*x1/mxx;\r
1471       y2=myy*cx2/mxx+b;\r
1472       x2=cx2;\r
1473     }\r
1474     else x2=cx2;\r
1475   }\r
1476 \r
1477   if (y1>y2)\r
1478   {\r
1479     SWAP(x1,x2);\r
1480     SWAP(y1,y2);\r
1481   }\r
1482 \r
1483   // clip the bottom\r
1484   if (y2>cy2)\r
1485   { int mxx=(x2-x1);\r
1486     int myy=(y2-y1),b;\r
1487     if (!myy)\r
1488     {\r
1489       cpubyte=ETC;\r
1490       return;\r
1491     }\r
1492     if (mxx)\r
1493     {\r
1494       b=y1-(y2-y1)*x1/mxx;\r
1495       x2=(cy2-b)*mxx/myy;\r
1496       y2=cy2;\r
1497     }\r
1498     else y2=cy2;\r
1499   }\r
1500 \r
1501   // clip the top\r
1502   if (y1<cy1)\r
1503   { int mxx=(x2-x1);\r
1504     int myy=(y2-y1),b;\r
1505     if (!myy)\r
1506     {\r
1507       cpubyte=ETC;\r
1508       return;\r
1509     }\r
1510     if (mxx)\r
1511     {\r
1512       b=y1-(y2-y1)*x1/mxx;\r
1513       x1=(cy1-b)*mxx/myy;\r
1514       y1=cy1;\r
1515     }\r
1516     else y1=cy1;\r
1517   }\r
1518 \r
1519   // ???\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
1522   {\r
1523     cpubyte=ETC;\r
1524     return;\r
1525   }\r
1526 \r
1527   if (x1>x2)\r
1528   { xc=x2; xi=x1; }\r
1529   else { xi=x2; xc=x1; }\r
1530 \r
1531   // assume y1<=y2 from above swap operation\r
1532   yi=y2; yc=y1;\r
1533 \r
1534   dcx=x1; dcy=y1;\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
1540   er=0;\r
1541 \r
1542   if (n>m)\r
1543   {\r
1544     xcxi=abs(2*xc*xi);\r
1545     for (i=0;i<=n;i++)\r
1546     {\r
1547       screen[(dcy*sx)+dcx]=color;\r
1548       if (er>0)\r
1549       { dcy+=yi;\r
1550         er-=xcxi;\r
1551       }\r
1552       er+=ycyi;\r
1553       dcx+=xi;\r
1554     }\r
1555   }\r
1556   else\r
1557   {\r
1558     xcyi=abs(2*xc*yi);\r
1559     for (i=0;i<=m;i++)\r
1560     {\r
1561       screen[(dcy*sx)+dcx]=color;\r
1562       if (er>0)\r
1563       { dcx+=xi;\r
1564         er-=ycyi;\r
1565       }\r
1566       er+=xcyi;\r
1567       dcy+=yi;\r
1568     }\r
1569   }\r
1570   cpubyte=ETC;\r
1571   return;\r
1572 }\r
1573 \r
1574 void LineLucent(int x1, int y1, int x2, int y2, int color)\r
1575 {\r
1576   short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;\r
1577   unsigned dcy,dcx;\r
1578   byte *d;\r
1579   int c;\r
1580 \r
1581   cpubyte=RENDER;\r
1582   if (x1>x2)\r
1583   {\r
1584     SWAP(x1,x2);\r
1585     SWAP(y1,y2);\r
1586   }\r
1587   if (y1>y2)\r
1588   {\r
1589     SWAP(x1,x2);\r
1590     SWAP(y1,y2);\r
1591   }\r
1592 \r
1593   // assume y1<=y2 from above swap operation\r
1594   yi=y2; yc=y1;\r
1595   dcx=x1; dcy=y1;\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
1601   er=0;\r
1602 \r
1603   c=color<<8; // for translucency\r
1604   if (n>m)\r
1605   {\r
1606     xcxi=abs(2*xc*xi);\r
1607     for (i=0;i<=n;i++)\r
1608     {\r
1609       d=screen+(dcy*sx)+dcx;\r
1610       *d=translucency_table[c|*d];\r
1611       //screen[(dcy*sx)+dcx]=color;\r
1612       if (er>0)\r
1613       { dcy+=yi;\r
1614         er-=xcxi;\r
1615       }\r
1616       er+=ycyi;\r
1617       dcx+=xi;\r
1618     }\r
1619   }\r
1620   else\r
1621   {\r
1622     xcyi=abs(2*xc*yi);\r
1623     for (i=0;i<=m;i++)\r
1624     {\r
1625       d=screen+(dcy*sx)+dcx;\r
1626       *d=translucency_table[c|*d];\r
1627       //screen[(dcy*sx)+dcx]=color;\r
1628       if (er>0)\r
1629       { dcx+=xi;\r
1630         er-=ycyi;\r
1631       }\r
1632       er+=xcyi;\r
1633       dcy+=yi;\r
1634     }\r
1635   }\r
1636   cpubyte=ETC;\r
1637 }\r
1638 \r
1639 void LineLucentClip(int x1, int y1, int x2, int y2, int color)\r
1640 {\r
1641   short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;\r
1642   unsigned dcy,dcx;\r
1643   byte *d;\r
1644   int c;\r
1645 \r
1646   cpubyte=RENDER;\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
1650   {\r
1651     cpubyte=ETC;\r
1652     return;\r
1653   }\r
1654 \r
1655   if (x1>x2)\r
1656   {\r
1657     SWAP(x1,x2);\r
1658     SWAP(y1,y2);\r
1659   }\r
1660 \r
1661   // clip the left side\r
1662   if (x1<cx1)\r
1663   { int myy=(y2-y1);\r
1664     int mxx=(x2-x1),b;\r
1665     if (!mxx)\r
1666     {\r
1667       cpubyte=ETC;\r
1668       return;\r
1669     }\r
1670     if (myy)\r
1671     {\r
1672       b=y1-(y2-y1)*x1/mxx;\r
1673       y1=myy*cx1/mxx+b;\r
1674       x1=cx1;\r
1675     }\r
1676     else x1=cx1;\r
1677   }\r
1678 \r
1679   // clip the right side\r
1680   if (x2>cx2)\r
1681   { int myy=(y2-y1);\r
1682     int mxx=(x2-x1),b;\r
1683     if (!mxx)\r
1684     {\r
1685       cpubyte=ETC;\r
1686       return;\r
1687     }\r
1688     if (myy)\r
1689     {\r
1690       b=y1-(y2-y1)*x1/mxx;\r
1691       y2=myy*cx2/mxx+b;\r
1692       x2=cx2;\r
1693     }\r
1694     else x2=cx2;\r
1695   }\r
1696 \r
1697   if (y1>y2)\r
1698   {\r
1699     SWAP(x1,x2);\r
1700     SWAP(y1,y2);\r
1701   }\r
1702 \r
1703   // clip the bottom\r
1704   if (y2>cy2)\r
1705   { int mxx=(x2-x1);\r
1706     int myy=(y2-y1),b;\r
1707     if (!myy)\r
1708     {\r
1709       cpubyte=ETC;\r
1710       return;\r
1711     }\r
1712     if (mxx)\r
1713     {\r
1714       b=y1-(y2-y1)*x1/mxx;\r
1715       x2=(cy2-b)*mxx/myy;\r
1716       y2=cy2;\r
1717     }\r
1718     else y2=cy2;\r
1719   }\r
1720 \r
1721   // clip the top\r
1722   if (y1<cy1)\r
1723   { int mxx=(x2-x1);\r
1724     int myy=(y2-y1),b;\r
1725     if (!myy)\r
1726     {\r
1727       cpubyte=ETC;\r
1728       return;\r
1729     }\r
1730     if (mxx)\r
1731     {\r
1732       b=y1-(y2-y1)*x1/mxx;\r
1733       x1=(cy1-b)*mxx/myy;\r
1734       y1=cy1;\r
1735     }\r
1736     else y1=cy1;\r
1737   }\r
1738 \r
1739   // ???\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
1742   {\r
1743     cpubyte=ETC;\r
1744     return;\r
1745   }\r
1746 \r
1747   if (x1>x2)\r
1748   { xc=x2; xi=x1; }\r
1749   else { xi=x2; xc=x1; }\r
1750 \r
1751   // assume y1<=y2 from above swap operation\r
1752   yi=y2; yc=y1;\r
1753 \r
1754   dcx=x1; dcy=y1;\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
1760   er=0;\r
1761 \r
1762   c=color<<8; // for translucency\r
1763   if (n>m)\r
1764   {\r
1765     xcxi=abs(2*xc*xi);\r
1766     for (i=0;i<=n;i++)\r
1767     {\r
1768       d=screen+(dcy*sx)+dcx;\r
1769       *d=translucency_table[c|*d];\r
1770       //screen[(dcy*sx)+dcx]=color;\r
1771       if (er>0)\r
1772       { dcy+=yi;\r
1773         er-=xcxi;\r
1774       }\r
1775       er+=ycyi;\r
1776       dcx+=xi;\r
1777     }\r
1778   }\r
1779   else\r
1780   {\r
1781     xcyi=abs(2*xc*yi);\r
1782     for (i=0;i<=m;i++)\r
1783     {\r
1784       d=screen+(dcy*sx)+dcx;\r
1785       *d=translucency_table[c|*d];\r
1786       //screen[(dcy*sx)+dcx]=color;\r
1787       if (er>0)\r
1788       { dcx+=xi;\r
1789         er-=ycyi;\r
1790       }\r
1791       er+=xcyi;\r
1792       dcy+=yi;\r
1793     }\r
1794   }\r
1795   cpubyte=ETC;\r
1796 }\r
1797 \r
1798 // All the Circle* routines were grabbed/modded from Allegro source\r
1799 \r
1800 void Circle(int x, int y, int radius, int color)\r
1801 {\r
1802   int cx=0;\r
1803   int cy=radius;\r
1804   int df=1-radius;\r
1805   int d_e=3;\r
1806   int d_se=-2*radius+5;\r
1807 \r
1808   cpubyte=RENDER;\r
1809   do\r
1810   {\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
1815 \r
1816     if (cx != cy)\r
1817     {\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
1822     }\r
1823 \r
1824     if (df<0)\r
1825     {\r
1826       df+=d_e;\r
1827       d_e+=2;\r
1828       d_se+=2;\r
1829     }\r
1830     else\r
1831     {\r
1832       df+=d_se;\r
1833       d_e+=2;\r
1834       d_se+=4;\r
1835       cy--;\r
1836     }\r
1837     cx++;\r
1838   } while (cx <= cy);\r
1839   cpubyte=ETC;\r
1840 }\r
1841 \r
1842 void CircleClip(int x, int y, int radius, int color)\r
1843 {\r
1844   int cx=0;\r
1845   int cy=radius;\r
1846   int df=1-radius;\r
1847   int d_e=3;\r
1848   int d_se=-2*radius+5;\r
1849 \r
1850   cpubyte=RENDER;\r
1851   do {\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
1856 \r
1857     if (cx != cy)\r
1858     {\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
1863     }\r
1864 \r
1865     if (df<0)\r
1866     {\r
1867       df+=d_e;\r
1868       d_e+=2;\r
1869       d_se+=2;\r
1870     }\r
1871     else\r
1872     {\r
1873       df+=d_se;\r
1874       d_e+=2;\r
1875       d_se+=4;\r
1876       cy--;\r
1877     }\r
1878     cx++;\r
1879   } while (cx <= cy);\r
1880   cpubyte=ETC;\r
1881 }\r
1882 \r
1883 void CircleLucent(int x, int y, int radius, int color)\r
1884 {\r
1885   int cx=0;\r
1886   int cy=radius;\r
1887   int df=1-radius;\r
1888   int d_e=3;\r
1889   int d_se=-2*radius+5;\r
1890 \r
1891   cpubyte=RENDER;\r
1892 \r
1893   do\r
1894   {\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
1899 \r
1900     if (cx != cy)\r
1901     {\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
1906     }\r
1907 \r
1908     if (df<0)\r
1909     {\r
1910       df+=d_e;\r
1911       d_e+=2;\r
1912       d_se+=2;\r
1913     }\r
1914     else\r
1915     {\r
1916       df+=d_se;\r
1917       d_e+=2;\r
1918       d_se+=4;\r
1919       cy--;\r
1920     }\r
1921     cx++;\r
1922   } while (cx <= cy);\r
1923   cpubyte=ETC;\r
1924 }\r
1925 \r
1926 void CircleLucentClip(int x, int y, int radius, int color)\r
1927 {\r
1928   int cx=0;\r
1929   int cy=radius;\r
1930   int df=1-radius;\r
1931   int d_e=3;\r
1932   int d_se=-2*radius+5;\r
1933 \r
1934   cpubyte=RENDER;\r
1935   do\r
1936   {\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
1941 \r
1942     if (cx != cy)\r
1943     {\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
1948     }\r
1949 \r
1950     if (df<0)\r
1951     {\r
1952       df+=d_e;\r
1953       d_e+=2;\r
1954       d_se+=2;\r
1955     }\r
1956     else\r
1957     {\r
1958       df+=d_se;\r
1959       d_e+=2;\r
1960       d_se+=4;\r
1961       cy--;\r
1962     }\r
1963     cx++;\r
1964   } while (cx <= cy);\r
1965   cpubyte=ETC;\r
1966 }\r
1967 \r
1968 void CircleFill(int x, int y, int radius, int color)\r
1969 {\r
1970   int cx=0;\r
1971   int cy=radius;\r
1972   int df=1-radius;\r
1973   int d_e=3;\r
1974   int d_se=-2*radius+5;\r
1975 \r
1976   cpubyte=RENDER;\r
1977 \r
1978   do\r
1979   {\r
1980     HLine(x-cy,y-cx,x+cy,color);\r
1981     if (cx) HLine(x-cy,y+cx,x+cy,color);\r
1982 \r
1983     if (df<0)\r
1984     {\r
1985       df+=d_e;\r
1986       d_e+=2;\r
1987       d_se+=2;\r
1988     }\r
1989     else\r
1990     {\r
1991       if (cx != cy)\r
1992       {\r
1993         HLine(x-cx,y-cy,x+cx,color);\r
1994         if (cy) HLine(x-cx,y+cy,x+cx,color);\r
1995       }\r
1996       df+=d_se;\r
1997       d_e+=2;\r
1998       d_se+=4;\r
1999       cy--;\r
2000     }\r
2001     cx++;\r
2002   } while (cx <= cy);\r
2003   cpubyte=ETC;\r
2004 }\r
2005 \r
2006 void CircleFillClip(int x, int y, int radius, int color)\r
2007 {\r
2008   int cx=0;\r
2009   int cy=radius;\r
2010   int df=1-radius;\r
2011   int d_e=3;\r
2012   int d_se=-2*radius+5;\r
2013 \r
2014   cpubyte=RENDER;\r
2015   do\r
2016   {\r
2017     HLineClip(x-cy,y-cx,x+cy,color);\r
2018     if (cx) HLineClip(x-cy,y+cx,x+cy,color);\r
2019 \r
2020     if (df<0)\r
2021     {\r
2022       df+=d_e;\r
2023       d_e+=2;\r
2024       d_se+=2;\r
2025     }\r
2026     else\r
2027     {\r
2028       if (cx != cy)\r
2029       {\r
2030         HLineClip(x-cx,y-cy,x+cx,color);\r
2031         if (cy) HLineClip(x-cx,y+cy,x+cx,color);\r
2032       }\r
2033       df+=d_se;\r
2034       d_e+=2;\r
2035       d_se+=4;\r
2036       cy--;\r
2037     }\r
2038     cx++;\r
2039   } while (cx <= cy);\r
2040   cpubyte=ETC;\r
2041 }\r
2042 \r
2043 void CircleFillLucent(int x, int y, int radius, int color)\r
2044 {\r
2045   int cx=0;\r
2046   int cy=radius;\r
2047   int df=1-radius;\r
2048   int d_e=3;\r
2049   int d_se=-2*radius+5;\r
2050 \r
2051   cpubyte=RENDER;\r
2052   do\r
2053   {\r
2054     HLineLucent(x-cy,y-cx,x+cy,color);\r
2055     if (cx) HLineLucent(x-cy,y+cx,x+cy,color);\r
2056 \r
2057     if (df<0)\r
2058     {\r
2059       df+=d_e;\r
2060       d_e+=2;\r
2061       d_se+=2;\r
2062     }\r
2063     else\r
2064     {\r
2065       if (cx != cy)\r
2066       {\r
2067         HLineLucent(x-cx,y-cy,x+cx,color);\r
2068         if (cy) HLineLucent(x-cx,y+cy,x+cx,color);\r
2069       }\r
2070       df+=d_se;\r
2071       d_e+=2;\r
2072       d_se+=4;\r
2073       cy--;\r
2074     }\r
2075     cx++;\r
2076   } while (cx <= cy);\r
2077   cpubyte=ETC;\r
2078 }\r
2079 \r
2080 void CircleFillLucentClip(int x, int y, int radius, int color)\r
2081 {\r
2082   int cx=0;\r
2083   int cy=radius;\r
2084   int df=1-radius;\r
2085   int d_e=3;\r
2086   int d_se=-2*radius+5;\r
2087 \r
2088   cpubyte=RENDER;\r
2089   do\r
2090   {\r
2091     HLineLucentClip(x-cy,y-cx,x+cy,color);\r
2092     if (cx) HLineLucentClip(x-cy,y+cx,x+cy,color);\r
2093 \r
2094     if (df<0)\r
2095     {\r
2096       df+=d_e;\r
2097       d_e+=2;\r
2098       d_se+=2;\r
2099     }\r
2100     else\r
2101     {\r
2102       if (cx != cy)\r
2103       {\r
2104         HLineLucentClip(x-cx,y-cy,x+cx,color);\r
2105         if (cy) HLineLucentClip(x-cx,y+cy,x+cx,color);\r
2106       }\r
2107       df+=d_se;\r
2108       d_e+=2;\r
2109       d_se+=4;\r
2110       cy--;\r
2111     }\r
2112     cx++;\r
2113   } while (cx <= cy);\r
2114   cpubyte=ETC;\r
2115 }\r
2116 \r
2117 void Rect(int x, int y, int x2, int y2, int color)\r
2118 {\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
2123 }\r
2124 \r
2125 void RectClip(int x, int y, int x2, int y2, int color)\r
2126 {\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
2131 }\r
2132 \r
2133 void RectLucent(int x, int y, int x2, int y2, int color)\r
2134 {\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
2139 }\r
2140 \r
2141 void RectLucentClip(int x, int y, int x2, int y2, int color)\r
2142 {\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
2147 }\r
2148 \r
2149 void RectFill(int x, int y, int x2, int y2, int color)\r
2150 {\r
2151   cpubyte=RENDER;\r
2152   if (y2<y) SWAP(y,y2);\r
2153   for (; y<=y2; y++)\r
2154     HLine(x,y,x2,color);\r
2155   cpubyte=ETC;\r
2156 }\r
2157 \r
2158 void RectFillClip(int x, int y, int x2, int y2, int color)\r
2159 {\r
2160   cpubyte=RENDER;\r
2161   if (y2<y) SWAP(y,y2);\r
2162   for (; y<=y2; y++)\r
2163     HLineClip(x,y,x2,color);\r
2164   cpubyte=ETC;\r
2165 }\r
2166 \r
2167 void RectFillLucent(int x, int y, int x2, int y2, int color)\r
2168 {\r
2169   cpubyte=RENDER;\r
2170   if (y2<y) SWAP(y,y2);\r
2171   for (; y<=y2; y++)\r
2172     HLineLucent(x,y,x2,color);\r
2173   cpubyte=ETC;\r
2174 }\r
2175 \r
2176 void RectFillLucentClip(int x, int y, int x2, int y2, int color)\r
2177 {\r
2178   cpubyte=RENDER;\r
2179   if (y2<y) SWAP(y,y2);\r
2180   for (; y<=y2; y++)\r
2181     HLineLucentClip(x,y,x2,color);\r
2182   cpubyte=ETC;\r
2183 }\r
2184 \r
2185 // ============================================================================\r
2186 // =                          aen's wrap blitters                             =\r
2187 // ============================================================================\r
2188 \r
2189 void WrapBlit(quad x, quad y, int wide, int high, byte *src)\r
2190 {\r
2191   int i;\r
2192   int cliph,clipw;\r
2193   int curx,cury;\r
2194   int spanx,spany;\r
2195   byte *source,*dest;\r
2196 \r
2197   cpubyte=RENDER;\r
2198   cliph=cy2-cy1+1;\r
2199   clipw=cx2-cx1+1;\r
2200   y%=high;\r
2201   curx=0;\r
2202 \r
2203   do\r
2204   {\r
2205     x%=curx?1:wide;\r
2206     spanx=wide-x;\r
2207     if (curx+spanx>=clipw)\r
2208       spanx=clipw-curx;\r
2209     source=src+(y*wide)+x;\r
2210     dest=screen+(cy1*sx)+cx1+curx;\r
2211     cury=0;\r
2212 \r
2213     do\r
2214     {\r
2215       spany=high-(cury?0:y);\r
2216       if (cury+spany>=cliph)\r
2217         spany=cliph-cury;\r
2218 \r
2219       for (i=0; i<spany; i++,source+=wide,dest+=sx)\r
2220         memcpy(dest, source, spanx);\r
2221 \r
2222       source=src+x;\r
2223       cury+=spany;\r
2224     } while (cury<cliph);\r
2225     curx+=spanx;\r
2226   } while (curx<clipw);\r
2227   cpubyte=ETC;\r
2228 }\r
2229 \r
2230 void WrapBlitMasked(quad x, quad y, int wide, int high, byte *src)\r
2231 {\r
2232   int i,j,c;\r
2233   int cliph,clipw;\r
2234   int curx,cury;\r
2235   int spanx,spany;\r
2236   byte *source,*dest;\r
2237 \r
2238   cpubyte=RENDER;\r
2239   cliph=cy2-cy1+1;\r
2240   clipw=cx2-cx1+1;\r
2241   y%=high;\r
2242   curx=0;\r
2243 \r
2244   do\r
2245   {\r
2246     x%=curx?1:wide;\r
2247     spanx=wide-x;\r
2248     if (curx+spanx>=clipw)\r
2249       spanx=clipw-curx;\r
2250     source=src+(y*wide)+x;\r
2251     dest=screen+(cy1*sx)+cx1+curx;\r
2252     cury=0;\r
2253 \r
2254     do\r
2255     {\r
2256       spany=high-(cury?0:y);\r
2257       if (cury+spany>=cliph)\r
2258         spany=cliph-cury;\r
2259       for (i=0; i<spany; i++,source+=wide,dest+=sx)\r
2260         for (j=0; j<spanx; j++)\r
2261         {\r
2262           c=source[j];\r
2263           if (c)\r
2264             dest[j]=c;\r
2265         }\r
2266       source=src+x;\r
2267       cury+=spany;\r
2268     } while (cury<cliph);\r
2269     curx+=spanx;\r
2270   } while (curx<clipw);\r
2271   cpubyte=ETC;\r
2272 }\r
2273 \r
2274 void WrapBlitLucent(quad x, quad y, int wide, int high, byte *src)\r
2275 {\r
2276   int i,j;\r
2277   int cliph,clipw;\r
2278   int curx,cury;\r
2279   int spanx,spany;\r
2280   byte *source,*dest;\r
2281 \r
2282   cpubyte=RENDER;\r
2283   cliph=cy2-cy1+1;\r
2284   clipw=cx2-cx1+1;\r
2285   y%=high;\r
2286   curx=0;\r
2287 \r
2288   do\r
2289   {\r
2290     x%=curx?1:wide;\r
2291     spanx=wide-x;\r
2292     if (curx+spanx>=clipw)\r
2293       spanx=clipw-curx;\r
2294     source=src+(y*wide)+x;\r
2295     dest=screen+(cy1*sx)+cx1+curx;\r
2296     cury=0;\r
2297 \r
2298     do\r
2299     {\r
2300       spany=high-(cury?0:y);\r
2301       if (cury+spany>=cliph)\r
2302         spany=cliph-cury;\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
2306       source=src+x;\r
2307       cury+=spany;\r
2308     } while (cury<cliph);\r
2309     curx+=spanx;\r
2310   } while (curx<clipw);\r
2311   cpubyte=ETC;\r
2312 }\r
2313 \r
2314 void WrapBlitLucentMasked(quad x, quad y, int wide, int high, byte *src)\r
2315 {\r
2316   int i,j,c;\r
2317   int cliph,clipw;\r
2318   int curx,cury;\r
2319   int spanx,spany;\r
2320   byte *source,*dest;\r
2321 \r
2322   cpubyte=RENDER;\r
2323   cliph=cy2-cy1+1;\r
2324   clipw=cx2-cx1+1;\r
2325   y%=high;\r
2326   curx=0;\r
2327 \r
2328   do\r
2329   {\r
2330     x%=curx?1:wide;\r
2331     spanx=wide-x;\r
2332     if (curx+spanx>=clipw)\r
2333       spanx=clipw-curx;\r
2334     source=src+(y*wide)+x;\r
2335     dest=screen+(cy1*sx)+cx1+curx;\r
2336     cury=0;\r
2337 \r
2338     do\r
2339     {\r
2340       spany=high-(cury?0:y);\r
2341       if (cury+spany>=cliph)\r
2342         spany=cliph-cury;\r
2343       for (i=0; i<spany; i++,source+=wide,dest+=sx)\r
2344         for (j=0; j<spanx; j++)\r
2345         {\r
2346           c=source[j];\r
2347           if (c)\r
2348             dest[j]=translucency_table[(c<<8)|dest[j]];\r
2349         }\r
2350       source=src+x;\r
2351       cury+=spany;\r
2352     } while (cury<cliph);\r
2353     curx+=spanx;\r
2354   } while (curx<clipw);\r
2355   cpubyte=ETC;\r
2356 }\r
2357 \r
2358 // ============================================================================\r
2359 // =           alias.zip / zero / aen rotational scaler routines              =\r
2360 // ============================================================================\r
2361 \r
2362 void RotScale(int posx, int posy, quad width, quad height, float angle, float scale, byte *src)\r
2363 {\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
2366 \r
2367   int xs,ys,xl,yl;\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
2369   byte *dest,pt;\r
2370   float ft;\r
2371 \r
2372   ft=atan2((float)width,(float)height);\r
2373 \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
2377   W_HEIGHT=W_WIDTH;\r
2378   W_HEIGHT_CENTER=W_HEIGHT>>1;\r
2379   W_WIDTH_CENTER=W_HEIGHT_CENTER; //W_WIDTH/2;\r
2380 \r
2381   sinas=sin(-angle)*65536*scale;\r
2382   cosas=cos(-angle)*65536*scale;\r
2383 \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
2388 \r
2389   // clipping\r
2390   if (W_WIDTH<2 || W_HEIGHT<2) return;\r
2391   xl=W_WIDTH;\r
2392   yl=W_HEIGHT;\r
2393   xs=ys=0;\r
2394   if (posx>cx2 || posy>cy2 || posx+xl<cx1 || posy+yl<cy1)\r
2395     return;\r
2396   if (posx+xl > cx2) xl=cx2-posx+1;\r
2397   if (posy+yl > cy2) yl=cy2-posy+1;\r
2398   if (posx<cx1)\r
2399   {\r
2400     xs=cx1-posx;\r
2401     xl-=xs;\r
2402     posx=cx1;\r
2403 \r
2404     xc+=cosas*xs; // woo!\r
2405     yc-=sinas*xs;\r
2406   }\r
2407   if (posy<cy1)\r
2408   {\r
2409     ys=cy1-posy;\r
2410     yl-=ys;\r
2411     posy=cy1;\r
2412 \r
2413     xc+=sinas*ys; // woo!\r
2414     yc+=cosas*ys;\r
2415   }\r
2416 \r
2417   dest=screen+posx+posy*sx;\r
2418   for (y=0; y<yl; y++)\r
2419   {\r
2420     srcx=xc;\r
2421     srcy=yc;\r
2422 \r
2423     for (x=0; x<xl; x++)\r
2424     {\r
2425       tempx=(srcx>>16);\r
2426       tempy=(srcy>>16);\r
2427 \r
2428       if (tempx>=0 && tempx<width && tempy>=0 && tempy<height)\r
2429       {\r
2430         if ((pt=src[tempx+tempy*width]))\r
2431           dest[x]=pt;\r
2432       }\r
2433 \r
2434       srcx+=cosas;\r
2435       srcy-=sinas;\r
2436     }\r
2437 \r
2438     dest+=sx;\r
2439 \r
2440     xc+=sinas;\r
2441     yc+=cosas;\r
2442   }\r
2443 }\r
2444 \r
2445 // ============================================================================\r
2446 // =                        zero's Mosiac effects                             =\r
2447 // ============================================================================\r
2448 \r
2449 //mosaic routines\r
2450 //TODO-need to asm optimize these badly! they are rather slow!\r
2451 \r
2452 byte FindPalMatchForMosaic(quad r, quad g, quad b)\r
2453 {\r
2454   quad index;\r
2455   quad diffrecord,diff,record;\r
2456   diffrecord=100000;\r
2457   record=100000;\r
2458 \r
2459   for(index=0; index<256; index++)\r
2460   {\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
2463     {\r
2464       diffrecord=diff;\r
2465       if(diff==1) return index;\r
2466       record=index;\r
2467     }\r
2468   }\r
2469   return record;\r
2470 }\r
2471 \r
2472 byte *InitMosaicTable(void)\r
2473 {\r
2474   quad r,g,b;\r
2475   byte *tmp;\r
2476   tmp=(byte *)malloc(262144);\r
2477 \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
2482   return tmp;\r
2483 }\r
2484 \r
2485 void Mosaic(quad xlevel, quad ylevel, byte *tbl, quad xmin, quad ymin, quad xmax, quad ymax)\r
2486 {\r
2487   quad x,y,rtot,btot,gtot,xloop,yloop,xfier,txlevel;\r
2488   byte *src;\r
2489   byte pixel;\r
2490 \r
2491   for(y=ymin; y<ymax; y+=ylevel)\r
2492   {\r
2493     for(x=xmin; x<xmax; x+=xlevel)\r
2494     {\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
2501       {\r
2502         for(xloop=0; xloop<txlevel; xloop++)\r
2503         {\r
2504           rtot+=pal[*src*3];\r
2505           gtot+=pal[*src*3+1];\r
2506           btot+=pal[*src*3+2];\r
2507           src++;\r
2508         }\r
2509         src+=sx-txlevel;\r
2510       }\r
2511       rtot/=xfier;\r
2512       gtot/=xfier;\r
2513       btot/=xfier;\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
2517       {\r
2518         for(xloop=0; xloop<txlevel; xloop++)\r
2519         {\r
2520           *src=pixel;\r
2521           src++;\r
2522         }\r
2523         src+=sx-txlevel;\r
2524       }\r
2525     }\r
2526   }\r
2527 }\r
2528 \r
2529 // ============================================================================\r
2530 // =                           Mord's trifillers                              =\r
2531 // ============================================================================\r
2532 \r
2533 void FlatPoly(int x1, int y1, int x2, int y2, int x3, int y3, char color)\r
2534 {\r
2535   int xstep,xstep2;\r
2536   int xval,xval2;\r
2537   int yon;\r
2538   int swaptemp;\r
2539 \r
2540   if (y1 > y3)\r
2541   {\r
2542     swaptemp=x1; x1=x3; x3=swaptemp;\r
2543     swaptemp=y1; y1=y3; y3=swaptemp;\r
2544   }\r
2545   if (y2 > y3)\r
2546   {\r
2547     swaptemp=x2; x2=x3; x3=swaptemp;\r
2548     swaptemp=y2; y2=y3; y3=swaptemp;\r
2549   }\r
2550   if (y1 > y2)\r
2551   {\r
2552     swaptemp=x1; x1=x2; x2=swaptemp;\r
2553     swaptemp=y1; y1=y2; y2=swaptemp;\r
2554   }\r
2555 \r
2556   xstep2=((x3-x1) << 16) / (y3-y1);\r
2557   xval2=x1 << 16;\r
2558 \r
2559   if (y1 != y2)\r
2560   {\r
2561     xstep = ((x2-x1) << 16) / (y2-y1);\r
2562     xval = x1 << 16;\r
2563     for (yon=y1;yon < y2; yon++)\r
2564     {\r
2565       if ((yon > -1) && (yon < 200))\r
2566       {\r
2567         HLineClip(xval>>16,yon,xval2>>16,color);\r
2568       }\r
2569       xval+=xstep;\r
2570       xval2+=xstep2;\r
2571     }\r
2572   }\r
2573   if (y2 != y3)\r
2574   {\r
2575     xstep = ((x3-x2) << 16) / (y3-y2);\r
2576     xval = x2 << 16;\r
2577     for (yon=y2;yon < y3; yon++)\r
2578     {\r
2579       if ((yon > -1) && (yon < 200))\r
2580       {\r
2581         HLineClip(xval>>16,yon,xval2>>16,color);\r
2582       }\r
2583       xval+=xstep;\r
2584       xval2+=xstep2;\r
2585     }\r
2586   }\r
2587 }\r
2588 \r
2589 char *image;\r
2590 int texw,texh;  // those damn bastards want EVERYTHING!\r
2591 \r
2592 void tmaphline(int x1, int x2, int y, int tx1, int tx2, int ty1, int ty2)\r
2593 {\r
2594   int i;\r
2595   int txstep,txval;\r
2596   int tystep,tyval;\r
2597 \r
2598   if (x1 != x2)\r
2599   {\r
2600     if (x2 < x1)\r
2601     {\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
2605     }\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
2609     txval=tx1<<16;\r
2610     tyval=ty1<<16;\r
2611 \r
2612     for (i=x1;i<x2;i++)\r
2613     {\r
2614       screen[y*sx+i] = image[(tyval>>16)*texw+(txval>>16)];\r
2615       txval+=txstep;\r
2616       tyval+=tystep;\r
2617     }\r
2618   }\r
2619 }\r
2620 \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
2624 {\r
2625   int xstep,xstep2;\r
2626   int xval,xval2;\r
2627   int txstep,txstep2;\r
2628   int tystep,tystep2;\r
2629   int txval,txval2;\r
2630   int tyval,tyval2;\r
2631   int yon;\r
2632   int swaptemp;\r
2633 \r
2634   image=img; texw=tw; texh=th;\r
2635   if (y1 > y3)\r
2636   {\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
2641   }\r
2642   if (y2 > y3)\r
2643   {\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
2648   }\r
2649   if (y1 > y2)\r
2650   {\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
2655   }\r
2656   xstep2=((x3-x1) << 16) / (y3-y1);\r
2657   xval2=x1 << 16;\r
2658   txstep2=((tx3-tx1) << 16) / (y3-y1);\r
2659   txval2=tx1 << 16;\r
2660   tystep2=((ty3-ty1) << 16) / (y3-y1);\r
2661   tyval2=ty1 << 16;\r
2662 \r
2663   if (y1 != y2)\r
2664   {\r
2665     xstep = ((x2-x1) << 16) / (y2-y1);\r
2666     xval = x1 << 16;\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
2671 \r
2672     for (yon=y1;yon < y2; yon++)\r
2673     {\r
2674       if ((yon > -1) && (yon < 200))\r
2675       {\r
2676         tmaphline(xval>>16,xval2>>16,yon,txval>>16,txval2>>16,\r
2677                   tyval>>16,tyval2>>16);\r
2678       }\r
2679       xval+=xstep;\r
2680       xval2+=xstep2;\r
2681       txval+=txstep;\r
2682       txval2+=txstep2;\r
2683       tyval+=tystep;\r
2684       tyval2+=tystep2;\r
2685     }\r
2686   }\r
2687   if (y2 != y3)\r
2688   {\r
2689     xstep = ((x3-x2) << 16) / (y3-y2);\r
2690     xval = x2 << 16;\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
2695 \r
2696     for (yon=y2;yon < y3; yon++)\r
2697     {\r
2698       if ((yon > -1) && (yon < 200))\r
2699       {\r
2700         tmaphline(xval>>16,xval2>>16,yon,txval>>16,txval2>>16,\r
2701                   tyval>>16,tyval2>>16);\r
2702       }\r
2703       xval+=xstep;\r
2704       xval2+=xstep2;\r
2705       txval+=txstep;\r
2706       txval2+=txstep2;\r
2707       tyval+=tystep;\r
2708       tyval2+=tystep2;\r
2709     }\r
2710   }\r
2711 }\r
2712 \r
2713 /*\r
2714 // ============================================================================\r
2715 // =                          aen's ripple-blitter                            =\r
2716 // ============================================================================\r
2717 \r
2718 int thresh;\r
2719 int dispx[64],dispy[64];\r
2720 \r
2721 void InitDisplaceStuff(float xmag, float ymag)\r
2722 {\r
2723   int x, y, *d;\r
2724 \r
2725   xmag=4.0,d=dispx;\r
2726   for (y=0; y<32; y++)\r
2727     *d++=sin(y * (360.0/32) * (3.14/180))*xmag;\r
2728 \r
2729   ymag=3.9,d=dispy;\r
2730   for (x=0; x<32; x++)\r
2731     *d++=cos(x * (360.0/32) * (3.14/180))*ymag;\r
2732 \r
2733   thresh=14;\r
2734 }\r
2735 \r
2736 void CopyTileDisplace(int x, int y, unsigned char *spr)\r
2737 {\r
2738   int i, j;\r
2739   int xx, yy, xt, yt;\r
2740   int xin, yin;\r
2741   byte *dest;\r
2742 \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
2746 \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
2750 \r
2751   for (j=0; j<16; j++)\r
2752   {\r
2753     yy = (j+yin+thresh) & 31;\r
2754     for (i=0; i<16; i++)\r
2755     {\r
2756       xx = (i+xin+thresh) & 31;\r
2757       xt = (i+dispx[yy]) & 15;\r
2758       yt = (j+dispy[xx]) & 15;\r
2759 \r
2760       dest[i]=spr[(yt*16)+xt];\r
2761     }\r
2762     dest+=sx;\r
2763   }\r
2764 }\r
2765 \r
2766 void CopyTileDisplaceClip(int x, int y, unsigned char *spr)\r
2767 {\r
2768   byte *s,*d;\r
2769   int xl,yl,xs,ys;\r
2770   int i, j;\r
2771   int xx, yy, xt, yt;\r
2772   int xin, yin;\r
2773 \r
2774   cpubyte=RENDER;\r
2775   xl=16;\r
2776   yl=16;\r
2777   xs=ys=0;\r
2778   if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
2779     return;\r
2780 \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
2785 \r
2786   s=spr;\r
2787   //if (ys) s+=(ys*width); // only perform mul if necessary ;)\r
2788   //if (xs) s+=xs;\r
2789   d=screen+(y*sx)+x;\r
2790 \r
2791   xin = ((x+xwin)&31)<16 ? 0 : 16; xin += xs;\r
2792   yin = ((y+ywin)&31)<16 ? 0 : 16; yin += ys;\r
2793 \r
2794   //dest=screen+(y*sx)+x;\r
2795 \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
2799 \r
2800   for (j=0; j<yl; j++)\r
2801   {\r
2802     yy = (j+yin+thresh) & 31;\r
2803     for (i=0; i<xl; i++)\r
2804     {\r
2805       xx = (i+xin+thresh) & 31;\r
2806       xt = (i+xs+dispx[yy]) & 15;\r
2807       yt = (j+ys+dispy[xx]) & 15;\r
2808 \r
2809       d[i]=s[(yt*16)+xt];\r
2810     }\r
2811     d+=sx;\r
2812   }\r
2813   cpubyte=ETC;\r
2814 } */\r