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
18 #include <sys\nearptr.h>
\r
21 // ================================= Data ====================================
\r
23 byte *screen, *screenx; // virscr | realscr
\r
25 // ================================= Code ====================================
\r
27 void SetMode(int mode)
\r
34 int Mode13hShutdown(void)
\r
41 void xShowPage(int startofs)
\r
43 asm("movl _screen, %%esi \n\t"
\r
44 "addl %0, %%esi \n\t"
\r
45 "movl _screenx, %%edi \n\t"
\r
46 "movl $200, %%eax \n\t"
\r
48 "movl $80, %%ecx \n\t"
\r
51 "addl $32, %%esi \n\t"
\r
56 : "esi", "edi", "cc", "eax", "ecx");
\r
59 int Mode13hShowPage(void)
\r
63 xShowPage((16*352)+16);
\r
68 int Mode13hCopySprite(int x, int y, int width, int height, byte *src)
\r
72 asm("movl %3, %%edx \n\t"
\r
73 "movl %4, %%esi \n\t"
\r
75 "movl %1, %%eax \n\t"
\r
76 "imul $352, %%eax \n\t"
\r
77 "addl %0, %%eax \n\t"
\r
78 "addl _screen, %%eax \n\t"
\r
79 "movl %%eax, %%edi \n\t"
\r
80 "movl %2, %%ecx \n\t"
\r
81 "shrl $2, %%ecx \n\t"
\r
88 : "m" (x), "m" (y), "m" (width), "m" (height), "m" (src)
\r
89 : "eax","edx","esi","edi","ecx","cc" );
\r
94 int Mode13hCopyTile(int x, int y, byte *spr)
\r
98 asm("movl $16, %%ecx \n\t"
\r
99 "movl %2, %%esi \n\t"
\r
100 "movl %1, %%edi \n\t"
\r
101 "imul $352, %%edi \n\t"
\r
102 "addl %0, %%edi \n\t"
\r
103 "addl _screen, %%edi \n\t"
\r
105 "movl (%%edi), %%eax \n\t"
\r
106 "andl $0, %%eax \n\t"
\r
107 "orl (%%esi), %%eax \n\t"
\r
108 "movl %%eax, (%%edi) \n\t"
\r
109 "movl 4(%%edi), %%eax \n\t"
\r
110 "andl $0, %%eax \n\t"
\r
111 "orl 4(%%esi), %%eax \n\t"
\r
112 "movl %%eax, 4(%%edi) \n\t"
\r
113 "movl 8(%%edi), %%eax \n\t"
\r
114 "andl $0, %%eax \n\t"
\r
115 "orl 8(%%esi), %%eax \n\t"
\r
116 "movl %%eax, 8(%%edi) \n\t"
\r
117 "movl 12(%%edi), %%eax \n\t"
\r
118 "andl $0, %%eax \n\t"
\r
119 "orl 12(%%esi), %%eax \n\t"
\r
120 "movl %%eax, 12(%%edi) \n\t"
\r
121 "addl $16, %%esi \n\t"
\r
122 "addl $352, %%edi \n\t"
\r
126 : "m" (x), "m" (y), "m" (spr)
\r
127 : "eax","ecx","esi","edi","cc" );
\r
132 int Mode13hTCopySprite(int x, int y, int width, int height, byte *src)
\r
136 asm("movl %3, %%ecx \n\t"
\r
137 "movl %4, %%esi \n\t"
\r
139 "movl %1, %%eax \n\t"
\r
140 "imul $352, %%eax \n\t"
\r
141 "addl %0, %%eax \n\t"
\r
142 "addl _screen, %%eax \n\t"
\r
143 "movl %%eax, %%edi \n\t"
\r
144 "movl %2, %%edx \n\t"
\r
147 "orb %%al, %%al \n\t"
\r
152 "jmp drawloop \n\t"
\r
156 "jnz drawloop \n\t"
\r
162 : "m" (x), "m" (y), "m" (width), "m" (height), "m" (src)
\r
163 : "eax","edx","esi","edi","ecx","cc" );
\r
169 int Mode13hTCopyTile(int x, int y, byte *spr, byte *matte)
\r
172 asm("movl $16, %%ecx \n\t"
\r
173 "movl %2, %%esi \n\t"
\r
174 "movl %1, %%edi \n\t"
\r
175 "imul $352, %%edi \n\t"
\r
176 "addl %0, %%edi \n\t"
\r
177 "addl _screen, %%edi \n\t"
\r
178 "movl %3, %%edx \n\t"
\r
180 "movl (%%edi), %%eax \n\t"
\r
181 "andl (%%edx), %%eax \n\t"
\r
182 "orl (%%esi), %%eax \n\t"
\r
183 "movl %%eax, (%%edi) \n\t"
\r
184 "movl 4(%%edi), %%eax \n\t"
\r
185 "andl 4(%%edx), %%eax \n\t"
\r
186 "orl 4(%%esi), %%eax \n\t"
\r
187 "movl %%eax, 4(%%edi) \n\t"
\r
188 "movl 8(%%edi), %%eax \n\t"
\r
189 "andl 8(%%edx), %%eax \n\t"
\r
190 "orl 8(%%esi), %%eax \n\t"
\r
191 "movl %%eax, 8(%%edi) \n\t"
\r
192 "movl 12(%%edi), %%eax \n\t"
\r
193 "andl 12(%%edx), %%eax \n\t"
\r
194 "orl 12(%%esi), %%eax \n\t"
\r
195 "movl %%eax, 12(%%edi) \n\t"
\r
196 "addl $16, %%esi \n\t"
\r
197 "addl $352, %%edi \n\t"
\r
198 "addl $16, %%edx \n\t"
\r
202 : "m" (x), "m" (y), "m" (spr), "m" (matte)
\r
203 : "eax","ecx","edx","esi","edi","cc" );
\r
209 int Mode13hCCopySprite(int x,int y,int width,int height,byte *src)
\r
213 int cx1=0, cy1=0, cx2=tsx-1, cy2=tsy-1;
\r
221 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
224 if (x+xl > cx2) xl=cx2-x+1;
\r
225 if (y+yl > cy2) yl=cy2-y+1;
\r
227 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
228 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
231 if (ys) s+=(ys*width); // only perform mul if necessary ;)
\r
233 d=screen+(y*tsx)+x;
\r
246 int Mode13hTCCopySprite(int x,int y,int width,int height,byte *src)
\r
250 int cx1=0, cy1=0, cx2=tsx-1, cy2=tsy-1;
\r
258 if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)
\r
261 if (x+xl > cx2) xl=cx2-x+1;
\r
262 if (y+yl > cy2) yl=cy2-y+1;
\r
264 if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }
\r
265 if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }
\r
268 if (ys) s+=(ys*width); // only perform mul if necessary ;)
\r
270 d=screen+(y*tsx)+x;
\r
274 for (x=0; x<xl; x++)
\r
288 int Mode13hScaleSprite(int x, int y, int w, int h, int tw, int th, byte *s)
\r
289 { int i,j,xm,ym,xd,yd,sx,sy=0,xs,ys,dys=0;
\r
294 if (!tw || !th) return 0;
\r
295 tw += sgn(tw); th += sgn(th);
\r
296 xm = abs(tw); ym = abs(th);
\r
297 xs = (w<<16)/xm; ys = (h<<16)/ym;
\r
298 xd = sgn(tw); yd = sgn(th);
\r
300 if (tw>0 && th>0) dys=tsx-xm;
\r
301 else if (tw>0 && th<0) dys=(0-tsx)-xm;
\r
302 else if (tw<0 && th>0) dys=tsx+xm;
\r
303 else if (tw<0 && th<0) dys=(0-tsx)+xm;
\r
305 d = screen+(y*tsx)+x;
\r
306 for (i=0;i<ym;++i) {
\r
308 for (j=0;j<xm;++j) {
\r
322 int Mode13hRenderMAPLine(int x, int y, int yofs, word *map)
\r
325 asm("movl %1, %%edi \n\t"
\r
326 "imul $352, %%edi \n\t"
\r
327 "addl %0, %%edi \n\t"
\r
328 "addl _screen, %%edi \n\t"
\r
329 "movl $22, %%ebx \n\t"
\r
330 "movl %3, %%ecx \n\t"
\r
332 "movw (%%ecx), %%ax \n\t"
\r
333 "movzwl %%ax, %%edx \n\t"
\r
334 "shll $1, %%edx \n\t"
\r
335 "addl _tileidx, %%edx \n\t"
\r
336 "movw (%%edx), %%ax \n\t"
\r
337 "movzwl %%ax, %%esi \n\t"
\r
338 "shll $8, %%esi \n\t"
\r
339 "addl _vsp, %%esi \n\t"
\r
340 "movl %2, %%eax \n\t"
\r
341 "shll $4, %%eax \n\t"
\r
342 "addl %%eax, %%esi \n\t"
\r
343 "movl (%%esi), %%eax \n\t"
\r
344 "movl %%eax, (%%edi) \n\t"
\r
345 "movl 4(%%esi), %%eax \n\t"
\r
346 "movl %%eax, 4(%%edi) \n\t"
\r
347 "movl 8(%%esi), %%eax \n\t"
\r
348 "movl %%eax, 8(%%edi) \n\t"
\r
349 "movl 12(%%esi), %%eax \n\t"
\r
350 "movl %%eax, 12(%%edi) \n\t"
\r
351 "addl $16, %%edi \n\t"
\r
352 "addl $2, %%ecx \n\t"
\r
354 "jnz tileloop \n\t"
\r
356 : "m" (x), "m" (y), "m" (yofs), "m" (map)
\r
357 : "eax","ebx","ecx","edx","esi","edi","cc" );
\r
363 int Mode13hTRenderMAPLine(int x, int y, int yofs, word *map)
\r
366 asm("movl %1, %%edi \n\t"
\r
367 "imul $352, %%edi \n\t"
\r
368 "addl %0, %%edi \n\t"
\r
369 "addl _screen, %%edi \n\t"
\r
370 "movl $22, %%ebx \n\t"
\r
371 "movl %3, %%ecx \n\t"
\r
373 "movw (%%ecx), %%ax \n\t"
\r
374 "movzwl %%ax, %%edx \n\t"
\r
375 "shll $1, %%edx \n\t"
\r
376 "addl _tileidx, %%edx \n\t"
\r
377 "movw (%%edx), %%ax \n\t"
\r
378 "orw %%ax, %%ax \n\t"
\r
380 "movzwl %%ax, %%esi \n\t"
\r
381 "shll $8, %%esi \n\t"
\r
382 "movl %%esi, %%edx \n\t"
\r
383 "addl _vspmask, %%edx \n\t"
\r
384 "addl _vsp, %%esi \n\t"
\r
385 "movl %2, %%eax \n\t"
\r
386 "shll $4, %%eax \n\t"
\r
387 "addl %%eax, %%esi \n\t"
\r
388 "addl %%eax, %%edx \n\t"
\r
389 "movl (%%edi), %%eax \n\t"
\r
390 "andl (%%edx), %%eax \n\t"
\r
391 "orl (%%esi), %%eax \n\t"
\r
392 "movl %%eax, (%%edi) \n\t"
\r
393 "movl 4(%%edi), %%eax \n\t"
\r
394 "andl 4(%%edx), %%eax \n\t"
\r
395 "orl 4(%%esi), %%eax \n\t"
\r
396 "movl %%eax, 4(%%edi) \n\t"
\r
397 "movl 8(%%edi), %%eax \n\t"
\r
398 "andl 8(%%edx), %%eax \n\t"
\r
399 "orl 8(%%esi), %%eax \n\t"
\r
400 "movl %%eax, 8(%%edi) \n\t"
\r
401 "movl 12(%%edi), %%eax \n\t"
\r
402 "andl 12(%%edx), %%eax \n\t"
\r
403 "orl 12(%%esi), %%eax \n\t"
\r
404 "movl %%eax, 12(%%edi) \n\t"
\r
406 "addl $16, %%edi \n\t"
\r
407 "addl $2, %%ecx \n\t"
\r
409 "jnz tileloop1 \n\t"
\r
411 : "m" (x), "m" (y), "m" (yofs), "m" (map)
\r
412 : "eax","ebx","ecx","edx","esi","edi","cc" );
\r
418 int Mode13hColorField(int x, int y, byte c)
\r
421 asm("movl %1, %%eax \n\t"
\r
422 "imul $352, %%eax \n\t"
\r
423 "addl %0, %%eax \n\t"
\r
424 "addl _screen, %%eax \n\t"
\r
425 "movl %%eax, %%edi \n\t"
\r
426 "movl $8, %%ecx \n\t"
\r
427 "movb %2, %%al \n\t"
\r
445 "addl $336, %%edi \n\t"
\r
462 "addl $336, %%edi \n\t"
\r
464 "jnz lineloop1 \n\t"
\r
466 : "m" (x), "m" (y), "m" (c)
\r
467 : "eax","edi","ecx","cc" );
\r
472 int Mode13hClearScreen()
\r
475 memset(screen+(352*16)+16,0,(352*200));
\r
480 int Mode13hPutPixel(int x, int y, int color)
\r
484 if (x<cx1 || y<cy1 || x>cx2 || y>cy2)
\r
493 screen[(y*tsx)+x]=color;
\r
499 int Mode13hGetPixel(int x, int y)
\r
503 if (x<cx1 || y<cy1 || x>cx2 || y>cy2)
\r
513 return screen[(y*tsx)+x];
\r
516 int Mode13hHLine(int x, int y, int x2, int color)
\r
523 if (x2<x) { int t=x2; x=x2; x2=t; }
\r
526 if (x>cx2 || y>cy2 || x+width<cx1 || y<cy1)
\r
529 if (x+width > cx2) width=cx2-x+1;
\r
530 if (x<cx1) { width-=(cx1-x); x=cx1; }
\r
536 d=screen+(y*tsx)+x;
\r
537 memset(d,color,width);
\r
543 int Mode13hVLine(int x, int y, int y2, int color)
\r
550 if (y2<y) { int t=y2; x=y2; y2=t; }
\r
553 if (x>cx2 || y>cy2 || x<cx1 || y+height<cy1)
\r
559 if (y+height > cy2) height=cy2-y+1;
\r
560 if (y<cy1) { height-=(cy1-y); y=cy1; }
\r
566 d=screen+(y*tsx)+x;
\r
567 for (; height; height--)
\r
577 int Mode13hLine(int x1, int y1, int x2, int y2, int color)
\r
579 short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;
\r
584 // check to see if the line is completly clipped off
\r
585 if ((x1<cx1 && x2<cx1) || (x1>cx2 && x2>cx2)
\r
586 || (y1<cy1 && y2<cy1) || (y1>cy2 && y2>cy2))
\r
598 // clip the left side
\r
609 b=y1-(y2-y1)*x1/mxx;
\r
616 // clip the right side
\r
627 b=y1-(y2-y1)*x1/mxx;
\r
651 b=y1-(y2-y1)*x1/mxx;
\r
652 x2=(cy2-b)*mxx/myy;
\r
669 b=y1-(y2-y1)*x1/mxx;
\r
670 x1=(cy1-b)*mxx/myy;
\r
677 // see if it got cliped into the box, out out
\r
678 if (x1<cx1 || x2<cx1 || x1>cx2 || x2>cx2 || y1<cy1 || y2 <cy1 || y1>cy2 || y2>cy2)
\r
686 else { xi=x2; xc=x1; }
\r
688 x1+=16;y1+=16; // aen; adjust these here??
\r
691 // assume y1<=y2 from above swap operation
\r
695 xc=(x2-x1); yc=(y2-y1);
\r
696 if (xc<0) xi=-1; else xi=1;
\r
697 if (yc<0) yi=-1; else yi=1;
\r
698 n=abs(xc); m=abs(yc);
\r
707 screen[(dcy*tsx)+dcx]=color;
\r
721 screen[(dcy*tsx)+dcx]=color;
\r
735 int Mode13hCircle(int x, int y, int radius, int color)
\r
740 int d_se=-2*radius+5;
\r
745 Mode13hPutPixel(x+cx,y+cy,color);
\r
746 if (cx) Mode13hPutPixel(x-cx,y+cy,color);
\r
747 if (cy) Mode13hPutPixel(x+cx,y-cy,color);
\r
748 if ((cx) && (cy)) Mode13hPutPixel(x-cx,y-cy,color);
\r
752 Mode13hPutPixel(x+cy,y+cx,color);
\r
753 if (cx) Mode13hPutPixel(x+cy,y-cx,color);
\r
754 if (cy) Mode13hPutPixel(x-cy,y+cx,color);
\r
755 if (cx && cy) Mode13hPutPixel(x-cy,y-cx,color);
\r
774 } while (cx <= cy);
\r
780 int Mode13hCircleFill(int x, int y, int radius, int color)
\r
785 int d_se=-2*radius+5;
\r
790 Mode13hHLine(x-cy,y-cx,x+cy,color);
\r
791 if (cx) Mode13hHLine(x-cy,y+cx,x+cy,color);
\r
803 Mode13hHLine(x-cx,y-cy,x+cx,color);
\r
804 if (cy) Mode13hHLine(x-cx,y+cy,x+cx,color);
\r
815 } while (cx <= cy);
\r
821 int Mode13hRect(int x, int y, int x2, int y2, int color)
\r
823 Mode13hHLine(x,y,x2,color);
\r
824 Mode13hHLine(x,y2,x2,color);
\r
825 Mode13hVLine(x,y+1,y2-1,color);
\r
826 Mode13hVLine(x2,y+1,y2-1,color);
\r
830 int Mode13hRectFill(int x, int y, int x2, int y2, int color)
\r
834 if (y2<y) { int t=y2; y=y2; y2=t; }
\r
837 Mode13hHLine(x,y,x2,color);
\r
843 void InitMode13h(void)
\r
847 screenx=(byte *) 0xA0000 + __djgpp_conventional_base;
\r
848 screen=(byte *) malloc(95744);
\r
849 memset(screen, 0, 95744);
\r
857 // Mode successfuly set, now lets set up the driver.
\r
858 ShutdownVideo = Mode13hShutdown;
\r
859 ShowPage = Mode13hShowPage;
\r
860 CopySprite = Mode13hCopySprite;
\r
861 TCopySprite = Mode13hTCopySprite;
\r
862 CCopySprite = Mode13hCCopySprite;
\r
863 TCCopySprite = Mode13hTCCopySprite;
\r
864 CopyTile = Mode13hCopyTile;
\r
865 TCopyTile = Mode13hTCopyTile;
\r
866 ScaleSprite = Mode13hScaleSprite;
\r
867 RenderMAPLine = Mode13hRenderMAPLine;
\r
868 TRenderMAPLine = Mode13hTRenderMAPLine;
\r
869 ColorField = Mode13hColorField;
\r
870 ClearScreen = Mode13hClearScreen;
\r
871 PutPixel = Mode13hPutPixel;
\r
872 GetPixel = Mode13hGetPixel;
\r
873 HLine = Mode13hHLine;
\r
874 VLine = Mode13hVLine;
\r
875 Line = Mode13hLine;
\r
876 Circle = Mode13hCircle;
\r
877 CircleFill = Mode13hCircleFill;
\r
878 Rect = Mode13hRect;
\r
879 RectFill = Mode13hRectFill;
\r
880 DriverDesc = "320x200 (Mode 13h, linear)";
\r