+++ /dev/null
-/*\r
-Copyright (C) 1998 BJ Eirich (aka vecna)\r
-This program is free software; you can redistribute it and/or\r
-modify it under the terms of the GNU General Public License\r
-as published by the Free Software Foundation; either version 2\r
-of the License, or (at your option) any later version.\r
-This program is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
-See the GNU General Public Lic\r
-See the GNU General Public License for more details.\r
-You should have received a copy of the GNU General Public License\r
-along with this program; if not, write to the Free Software\r
-Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
-*/\r
-\r
-#include <pc.h>\r
-#include <dpmi.h>\r
-#include <go32.h>\r
-\r
-#include <dpmi.h>\r
-#include <sys\nearptr.h>\r
-#include "verge.h"\r
-\r
-// ================================= Data ====================================\r
-\r
-byte *vesascreen, *vesascreenx; // virscr | realscr\r
-\r
-// ================================= Code ====================================\r
-\r
-void VESASetMode(int mode)\r
-{\r
- REGISTERS r;\r
- SET_AX(r, mode);\r
- INTERRUPT(0x10, r);\r
-}\r
-\r
-int VESAShutdown(void)\r
-{\r
- VESASetMode(0x3);\r
- free(vesascreen);\r
- return 0;\r
-}\r
-\r
-void VESASetBank(int bank)\r
-{\r
- REGISTERS r;\r
- SET_AX(r, 0x4f05);\r
- SET_BX(r, 0);\r
- SET_DX(r, bank);\r
- INTERRUPT(0x10, r);\r
-}\r
-\r
-int VESAShowPage(void)\r
-{ byte *s,*d;\r
- int y,bytes,bank;\r
- int span;\r
-\r
- RenderGUI();\r
- cpubyte=PFLIP;\r
-\r
- s=vesascreen+(16*tsx)+16;\r
- d=vesascreenx;\r
-\r
- bank=0;\r
- bytes=65536;\r
- VESASetBank(bank++);\r
-\r
- for (y=sy; y; y--)\r
- {\r
- if (bytes >= sx)\r
- { memcpy(d,s,sx);\r
- bytes-=sx;\r
- s+=sx;\r
- d+=sx;\r
- }\r
- else\r
- { memcpy(d,s,bytes);\r
- s+=bytes;\r
- span=sx-bytes;\r
-\r
- VESASetBank(bank++);\r
- d=vesascreenx;\r
- bytes=65536;\r
-\r
- memcpy(d,s,span);\r
- bytes-=span;\r
- s+=span;\r
- d+=span;\r
- }\r
- s+=32;\r
- }\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESACopySprite(int x, int y, int width, int height, byte *src)\r
-{\r
- cpubyte=RENDER;\r
-\r
- asm("movl %3, %%edx \n\t"\r
- "movl %4, %%esi \n\t"\r
-"csl0: \n\t"\r
- "movl %1, %%eax \n\t"\r
- "imul $672, %%eax \n\t"\r
- "addl %0, %%eax \n\t"\r
- "addl _vesascreen, %%eax \n\t"\r
- "movl %%eax, %%edi \n\t"\r
- "movl %2, %%ecx \n\t"\r
- "shrl $2, %%ecx \n\t"\r
- "repz \n\t"\r
- "movsl \n\t"\r
- "incl %1 \n\t"\r
- "decl %%edx \n\t"\r
- "jnz csl0 \n\t"\r
- :\r
- : "m" (x), "m" (y), "m" (width), "m" (height), "m" (src)\r
- : "eax","edx","esi","edi","ecx","cc" );\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESACCopySprite(int x,int y,int width,int height,byte *src)\r
-{\r
- byte *s,*d;\r
- int xl,yl,xs,ys;\r
- int cx1=0, cy1=0, cx2=tsx-1, cy2=tsy-1;\r
-\r
- cpubyte=RENDER;\r
-\r
- xl=width;\r
- yl=height;\r
- xs=ys=0;\r
-\r
- if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
- return 0;\r
-\r
- if (x+xl > cx2) xl=cx2-x+1;\r
- if (y+yl > cy2) yl=cy2-y+1;\r
-\r
- if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }\r
- if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }\r
-\r
- s=src;\r
- if (xs+ys) s+=(ys*width)+xs;\r
- d=vesascreen+(y*tsx)+x;\r
-\r
- for (; yl; yl--)\r
- {\r
- memcpy(d,s,xl);\r
- s+=width;\r
- d+=tsx;\r
- }\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESATCCopySprite(int x,int y,int width,int height,byte *src)\r
-{\r
- byte *s,*d,c;\r
- int xl,yl,xs,ys;\r
- int cx1=0, cy1=0, cx2=tsx-1, cy2=tsy-1;\r
-\r
- cpubyte=RENDER;\r
-\r
- xl=width;\r
- yl=height;\r
- xs=ys=0;\r
-\r
- if (x>cx2 || y>cy2 || x+xl<cx1 || y+yl<cy1)\r
- return 0;\r
-\r
- if (x+xl > cx2) xl=cx2-x+1;\r
- if (y+yl > cy2) yl=cy2-y+1;\r
-\r
- if (x<cx1) { xs=cx1-x; xl-=xs; x=cx1; }\r
- if (y<cy1) { ys=cy1-y; yl-=ys; y=cy1; }\r
-\r
- s=src;\r
- if (xs+ys) s+=(ys*width)+xs;\r
- d=vesascreen+(y*tsx)+x;\r
-\r
- for (; yl; yl--)\r
- {\r
- for (x=0; x<xl; x++)\r
- {\r
- c=s[x];\r
- if (c)\r
- d[x]=c;\r
- }\r
- s+=width;\r
- d+=tsx;\r
- }\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESACopyTile(int x, int y, byte *spr)\r
-{\r
- int h;\r
- byte *d;\r
-\r
- cpubyte=RENDER;\r
-\r
- h=16;\r
-\r
- d=vesascreen+(y*tsx)+x;\r
- for (; h; h--)\r
- {\r
- memcpy(d, spr, 16);\r
- spr+=16;\r
- d+=tsx;\r
- }\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESATCopySprite(int x, int y, int width, int height, byte *src)\r
-{\r
- cpubyte=RENDER;\r
-\r
- asm("movl %3, %%ecx \n\t"\r
- "movl %4, %%esi \n\t"\r
-"tcsl0: \n\t"\r
- "movl %1, %%eax \n\t"\r
- "imul $672, %%eax \n\t"\r
- "addl %0, %%eax \n\t"\r
- "addl _vesascreen, %%eax \n\t"\r
- "movl %%eax, %%edi \n\t"\r
- "movl %2, %%edx \n\t"\r
-"drawloop: \n\t"\r
- "lodsb \n\t"\r
- "orb %%al, %%al \n\t"\r
- "jz nodraw \n\t"\r
- "stosb \n\t"\r
- "decl %%edx \n\t"\r
- "jz endline \n\t"\r
- "jmp drawloop \n\t"\r
-"nodraw: \n\t"\r
- "incl %%edi \n\t"\r
- "decl %%edx \n\t"\r
- "jnz drawloop \n\t"\r
-"endline: \n\t"\r
- "incl %1 \n\t"\r
- "decl %%ecx \n\t"\r
- "jnz tcsl0 \n\t"\r
- :\r
- : "m" (x), "m" (y), "m" (width), "m" (height), "m" (src)\r
- : "eax","edx","esi","edi","ecx","cc" );\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESATCopyTile(int x, int y, byte *spr, byte *matte)\r
-{\r
- cpubyte=RENDER;\r
- asm("movl $16, %%ecx \n\t"\r
- "movl %2, %%esi \n\t"\r
- "movl %1, %%edi \n\t"\r
- "imul $672, %%edi \n\t"\r
- "addl %0, %%edi \n\t"\r
- "addl _vesascreen, %%edi \n\t"\r
- "movl %3, %%edx \n\t"\r
-"tctl0: \n\t"\r
- "movl (%%edi), %%eax \n\t"\r
- "andl (%%edx), %%eax \n\t"\r
- "orl (%%esi), %%eax \n\t"\r
- "movl %%eax, (%%edi) \n\t"\r
- "movl 4(%%edi), %%eax \n\t"\r
- "andl 4(%%edx), %%eax \n\t"\r
- "orl 4(%%esi), %%eax \n\t"\r
- "movl %%eax, 4(%%edi) \n\t"\r
- "movl 8(%%edi), %%eax \n\t"\r
- "andl 8(%%edx), %%eax \n\t"\r
- "orl 8(%%esi), %%eax \n\t"\r
- "movl %%eax, 8(%%edi) \n\t"\r
- "movl 12(%%edi), %%eax \n\t"\r
- "andl 12(%%edx), %%eax \n\t"\r
- "orl 12(%%esi), %%eax \n\t"\r
- "movl %%eax, 12(%%edi) \n\t"\r
- "addl $16, %%esi \n\t"\r
- "addl $672, %%edi \n\t"\r
- "addl $16, %%edx \n\t"\r
- "decl %%ecx \n\t"\r
- "jnz tctl0 \n\t"\r
- :\r
- : "m" (x), "m" (y), "m" (spr), "m" (matte)\r
- : "eax","ecx","edx","esi","edi","cc" );\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESAScaleSprite(int x, int y, int w, int h, int tw, int th, byte *s)\r
-{\r
- int i,j,xm,ym,xd,yd,sx,sy=0,xs,ys,dys=0;\r
- unsigned char *d;\r
-\r
- cpubyte=RENDER;\r
-\r
- if (!tw || !th) return 0;\r
- tw += sgn(tw); th += sgn(th);\r
- xm = abs(tw); ym = abs(th);\r
- xs = (w<<16)/xm; ys = (h<<16)/ym;\r
- xd = sgn(tw); yd = sgn(th);\r
-\r
- if (tw>0 && th>0) dys=tsx-xm;\r
- else if (tw>0 && th<0) dys=(0-tsx)-xm;\r
- else if (tw<0 && th>0) dys=tsx+xm;\r
- else if (tw<0 && th<0) dys=(0-tsx)+xm;\r
-\r
- d = vesascreen+(y*tsx)+x;\r
- for (i=0;i<ym;++i) {\r
- sx=0;\r
- for (j=0;j<xm;++j) {\r
- *d=s[(sx>>16)];\r
- d+=xd;\r
- sx+=xs;\r
- }\r
- d+=dys;\r
- sy+=ys;\r
- s+=(sy>>16)*w;\r
- sy&=0xffff;\r
- }\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESARenderMAPLine(int x, int y, int yofs, word *map)\r
-{\r
- cpubyte=RENDER;\r
- // ...\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESATRenderMAPLine(int x, int y, int yofs, word *map)\r
-{\r
- cpubyte=RENDER;\r
- // ...\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESAColorField(int x, int y, byte c)\r
-{\r
- cpubyte=RENDER;\r
- // ...\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESAClearScreen()\r
-{\r
- cpubyte=RENDER;\r
- memset(vesascreen+(672*16)+16,0,(672*480));\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESAPutPixel(int x, int y, int color)\r
-{\r
- cpubyte=RENDER;\r
-\r
- if (x<cx1 || y<cy1 || x>cx2 || y>cy2)\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
-\r
- x+=16;\r
- y+=16;\r
-\r
- vesascreen[(y*tsx)+x]=color;\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESAGetPixel(int x, int y)\r
-{\r
- cpubyte=RENDER;\r
-\r
- if (x<cx1 || y<cy1 || x>cx2 || y>cy2)\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
-\r
- x+=16;\r
- y+=16;\r
-\r
- cpubyte=ETC;\r
- return vesascreen[(y*tsx)+x];\r
- return 0;\r
-}\r
-\r
-int VESAHLine(int x, int y, int x2, int color)\r
-{\r
- byte *d;\r
- int width;\r
-\r
- cpubyte=RENDER;\r
-\r
- // swap?\r
- if (x2<x) { int t=x2; x=x2; x2=t; }\r
-\r
- width=x2-x+1;\r
- if (x>cx2 || y>cy2 || x+width<cx1 || y<cy1)\r
- return 0;\r
-\r
- if (x+width > cx2) width=cx2-x+1;\r
- if (x<cx1) { width-=(cx1-x); x=cx1; }\r
-\r
- x+=16;\r
- y+=16;\r
- x2+=16;\r
-\r
- d=vesascreen+(y*tsx)+x;\r
- memset(d,color,width);\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESAVLine(int x, int y, int y2, int color)\r
-{\r
- byte *d;\r
- int height;\r
-\r
- cpubyte=RENDER;\r
-\r
- // swap?\r
- if (y2<y) { int t=y2; x=y2; y2=t; }\r
-\r
- height=y2-y+1;\r
- if (x>cx2 || y>cy2 || x<cx1 || y+height<cy1)\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
-\r
- if (y+height > cy2) height=cy2-y+1;\r
- if (y<cy1) { height-=(cy1-y); y=cy1; }\r
-\r
- x+=16;\r
- y+=16;\r
- y2+=16;\r
-\r
- d=vesascreen+(y*tsx)+x;\r
- for (; height; height--)\r
- {\r
- *d=color;\r
- d+=tsx;\r
- }\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESALine(int x1, int y1, int x2, int y2, int color)\r
-{\r
- short i,xc,yc,er,n,m,xi,yi,xcxi,ycyi,xcyi;\r
- unsigned dcy,dcx;\r
-\r
- cpubyte=RENDER;\r
-\r
- // check to see if the line is completly clipped off\r
- if ((x1<cx1 && x2<cx1) || (x1>cx2 && x2>cx2)\r
- || (y1<cy1 && y2<cy1) || (y1>cy2 && y2>cy2))\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
-\r
- if (x1>x2)\r
- {\r
- i=x1; x1=x2; x2=i;\r
- i=y1; y1=y2; y2=i;\r
- }\r
-\r
- // clip the left side\r
- if (x1<cx1)\r
- { int myy=(y2-y1);\r
- int mxx=(x2-x1),b;\r
- if (!mxx)\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
- if (myy)\r
- {\r
- b=y1-(y2-y1)*x1/mxx;\r
- y1=myy*cx1/mxx+b;\r
- x1=cx1;\r
- }\r
- else x1=cx1;\r
- }\r
-\r
- // clip the right side\r
- if (x2>cx2)\r
- { int myy=(y2-y1);\r
- int mxx=(x2-x1),b;\r
- if (!mxx)\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
- if (myy)\r
- {\r
- b=y1-(y2-y1)*x1/mxx;\r
- y2=myy*cx2/mxx+b;\r
- x2=cx2;\r
- }\r
- else x2=cx2;\r
- }\r
-\r
- if (y1>y2)\r
- {\r
- i=x1; x1=x2; x2=i;\r
- i=y1; y1=y2; y2=i;\r
- }\r
-\r
- // clip the bottom\r
- if (y2>cy2)\r
- { int mxx=(x2-x1);\r
- int myy=(y2-y1),b;\r
- if (!myy)\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
- if (mxx)\r
- {\r
- b=y1-(y2-y1)*x1/mxx;\r
- x2=(cy2-b)*mxx/myy;\r
- y2=cy2;\r
- }\r
- else y2=cy2;\r
- }\r
-\r
- // clip the top\r
- if (y1<cy1)\r
- { int mxx=(x2-x1);\r
- int myy=(y2-y1),b;\r
- if (!myy)\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
- if (mxx)\r
- {\r
- b=y1-(y2-y1)*x1/mxx;\r
- x1=(cy1-b)*mxx/myy;\r
- y1=cy1;\r
- }\r
- else y1=cy1;\r
- }\r
-\r
- // ???\r
- // see if it got cliped into the box, out out\r
- if (x1<cx1 || x2<cx1 || x1>cx2 || x2>cx2 || y1<cy1 || y2 <cy1 || y1>cy2 || y2>cy2)\r
- {\r
- cpubyte=ETC;\r
- return 0;\r
- }\r
-\r
- if (x1>x2)\r
- { xc=x2; xi=x1; }\r
- else { xi=x2; xc=x1; }\r
-\r
- x1+=16;y1+=16; // aen; adjust these here??\r
- x2+=16;y2+=16;\r
-\r
- // assume y1<=y2 from above swap operation\r
- yi=y2; yc=y1;\r
-\r
- dcx=x1; dcy=y1;\r
- xc=(x2-x1); yc=(y2-y1);\r
- if (xc<0) xi=-1; else xi=1;\r
- if (yc<0) yi=-1; else yi=1;\r
- n=abs(xc); m=abs(yc);\r
- ycyi=abs(2*yc*xi);\r
- er=0;\r
-\r
- if (n>m)\r
- {\r
- xcxi=abs(2*xc*xi);\r
- for (i=0;i<=n;i++)\r
- {\r
- vesascreen[(dcy*tsx)+dcx]=color;\r
- if (er>0)\r
- { dcy+=yi;\r
- er-=xcxi;\r
- }\r
- er+=ycyi;\r
- dcx+=xi;\r
- }\r
- }\r
- else\r
- {\r
- xcyi=abs(2*xc*yi);\r
- for (i=0;i<=m;i++)\r
- {\r
- vesascreen[(dcy*tsx)+dcx]=color;\r
- if (er>0)\r
- { dcx+=xi;\r
- er-=ycyi;\r
- }\r
- er+=xcyi;\r
- dcy+=yi;\r
- }\r
- }\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESACircle(int x, int y, int radius, int color)\r
-{\r
- int cx=0;\r
- int cy=radius;\r
- int df=1-radius;\r
- int d_e=3;\r
- int d_se=-2*radius+5;\r
-\r
- cpubyte=RENDER;\r
-\r
- do {\r
- VESAPutPixel(x+cx,y+cy,color);\r
- if (cx) VESAPutPixel(x-cx,y+cy,color);\r
- if (cy) VESAPutPixel(x+cx,y-cy,color);\r
- if ((cx) && (cy)) VESAPutPixel(x-cx,y-cy,color);\r
-\r
- if (cx != cy)\r
- {\r
- VESAPutPixel(x+cy,y+cx,color);\r
- if (cx) VESAPutPixel(x+cy,y-cx,color);\r
- if (cy) VESAPutPixel(x-cy,y+cx,color);\r
- if (cx && cy) VESAPutPixel(x-cy,y-cx,color);\r
- }\r
-\r
- if (df<0)\r
- {\r
- df+=d_e;\r
- d_e+=2;\r
- d_se+=2;\r
- }\r
- else\r
- {\r
- df+=d_se;\r
- d_e+=2;\r
- d_se+=4;\r
- cy--;\r
- }\r
-\r
- cx++;\r
-\r
- } while (cx <= cy);\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESACircleFill(int x, int y, int radius, int color)\r
-{\r
- int cx=0;\r
- int cy=radius;\r
- int df=1-radius;\r
- int d_e=3;\r
- int d_se=-2*radius+5;\r
-\r
- cpubyte=RENDER;\r
-\r
- do {\r
- VESAHLine(x-cy,y-cx,x+cy,color);\r
- if (cx) VESAHLine(x-cy,y+cx,x+cy,color);\r
-\r
- if (df<0)\r
- {\r
- df+=d_e;\r
- d_e+=2;\r
- d_se+=2;\r
- }\r
- else\r
- {\r
- if (cx != cy)\r
- {\r
- VESAHLine(x-cx,y-cy,x+cx,color);\r
- if (cy) VESAHLine(x-cx,y+cy,x+cx,color);\r
- }\r
-\r
- df+=d_se;\r
- d_e+=2;\r
- d_se+=4;\r
- cy--;\r
- }\r
-\r
- cx++;\r
-\r
- } while (cx <= cy);\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-int VESARect(int x, int y, int x2, int y2, int color)\r
-{\r
- VESAHLine(x,y,x2,color);\r
- VESAHLine(x,y2,x2,color);\r
- VESAVLine(x,y+1,y2-1,color);\r
- VESAVLine(x2,y+1,y2-1,color);\r
- return 0;\r
-}\r
-\r
-int VESARectFill(int x, int y, int x2, int y2, int color)\r
-{\r
- cpubyte=RENDER;\r
-\r
- if (y2<y) { int t=y2; y=y2; y2=t; }\r
-\r
- for (; y<=y2; y++)\r
- VESAHLine(x,y,x2,color);\r
-\r
- cpubyte=ETC;\r
- return 0;\r
-}\r
-\r
-void InitVESA(void)\r
-{\r
- REGISTERS r;\r
-\r
- SET_BX(r, 0x0101);\r
- SET_AX(r, 0x4f02);\r
- INTERRUPT(0x10, r);\r
-\r
- vesascreenx = (byte *) 0xA0000 + __djgpp_conventional_base;\r
- vesascreen = (byte *) valloc(344064, "vesascreen", 0);\r
- memset(vesascreen, 0, 344064);\r
-\r
- sx=640; sy=480;\r
- tsx=672; tsy=512;\r
- tx=40; ty=30;\r
- cx1=0; cy1=0;\r
- cx2=sx-1;cy2=sy-1;\r
-\r
- // Mode successfuly set, now lets set up the driver.\r
- ShutdownVideo = VESAShutdown;\r
- ShowPage = VESAShowPage;\r
- CopySprite = VESACopySprite;\r
- TCopySprite = VESATCopySprite;\r
- CCopySprite = VESACCopySprite;\r
- TCCopySprite = VESATCCopySprite;\r
- CopyTile = VESACopyTile;\r
- TCopyTile = VESATCopyTile;\r
- ScaleSprite = VESAScaleSprite;\r
- RenderMAPLine = VESARenderMAPLine;\r
- TRenderMAPLine = VESATRenderMAPLine;\r
- ColorField = VESAColorField;\r
- ClearScreen = VESAClearScreen;\r
- PutPixel = VESAPutPixel;\r
- GetPixel = VESAGetPixel;\r
- HLine = VESAHLine;\r
- VLine = VESAVLine;\r
- Line = VESALine;\r
- Circle = VESACircle;\r
- CircleFill = VESACircleFill;\r
- Rect = VESARect;\r
- RectFill = VESARectFill;\r
- DriverDesc = "640x480 (VESA, Banked)";\r
-}\r