2006-04-23 06:44:19 +00:00
|
|
|
// A.ASM replacement using C
|
|
|
|
// Mainly by Ken Silverman, with things melded with my port by
|
|
|
|
// Jonathon Fowler (jonof@edgenetwork.org)
|
|
|
|
//
|
|
|
|
// "Build Engine & Tools" Copyright (c) 1993-1997 Ken Silverman
|
|
|
|
// Ken Silverman's official web site: "http://www.advsys.net/ken"
|
|
|
|
// See the included license file "BUILDLIC.TXT" for license info.
|
|
|
|
|
|
|
|
#include "a.h"
|
|
|
|
|
2006-09-10 17:40:34 +00:00
|
|
|
#ifdef ENGINE_USING_A_C
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
int krecip(int num); // from engine.c
|
2006-04-23 06:44:19 +00:00
|
|
|
|
|
|
|
#define BITSOFPRECISION 3
|
|
|
|
#define BITSOFPRECISIONPOW 8
|
|
|
|
|
2008-04-25 11:21:08 +00:00
|
|
|
extern intptr_t asm1, asm2, asm3, asm4;
|
|
|
|
extern int fpuasm, globalx3, globaly3;
|
2006-04-23 06:44:19 +00:00
|
|
|
extern void *reciptable;
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
static int bpl, transmode = 0;
|
|
|
|
static int glogx, glogy, gbxinc, gbyinc, gpinc;
|
2006-04-23 06:44:19 +00:00
|
|
|
static char *gbuf, *gpal, *ghlinepal, *gtrans;
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Global variable functions
|
2007-12-12 17:42:14 +00:00
|
|
|
void setvlinebpl(int dabpl) { bpl = dabpl; }
|
2008-04-25 11:21:08 +00:00
|
|
|
void fixtransluscence(intptr_t datransoff) { gtrans = (char *)datransoff; }
|
2006-04-23 06:44:19 +00:00
|
|
|
void settransnormal(void) { transmode = 0; }
|
|
|
|
void settransreverse(void) { transmode = 1; }
|
|
|
|
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Ceiling/floor horizontal line functions
|
2008-04-25 11:21:08 +00:00
|
|
|
void sethlinesizes(int logx, int logy, intptr_t bufplc)
|
2006-04-24 19:04:22 +00:00
|
|
|
{ glogx = logx; glogy = logy; gbuf = (char *)bufplc; }
|
2006-04-23 06:44:19 +00:00
|
|
|
void setpalookupaddress(char *paladdr) { ghlinepal = paladdr; }
|
2007-12-12 17:42:14 +00:00
|
|
|
void setuphlineasm4(int bxinc, int byinc) { gbxinc = bxinc; gbyinc = byinc; }
|
2008-04-25 11:21:08 +00:00
|
|
|
void hlineasm4(int cnt, int skiploadincs, int paloffs, unsigned int by, unsigned int bx, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char *palptr;
|
|
|
|
|
|
|
|
palptr = (char *)&ghlinepal[paloffs];
|
|
|
|
if (!skiploadincs) { gbxinc = asm1; gbyinc = asm2; }
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>=0;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
*((char *)p) = palptr[gbuf[((bx>>(32-glogx))<<glogy)+(by>>(32-glogy))]];
|
|
|
|
bx -= gbxinc;
|
|
|
|
by -= gbyinc;
|
|
|
|
p--;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Sloped ceiling/floor vertical line functions
|
2008-04-25 11:21:08 +00:00
|
|
|
void setupslopevlin(int logylogx, intptr_t bufplc, int pinc)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
glogx = (logylogx&255); glogy = (logylogx>>8);
|
|
|
|
gbuf = (char *)bufplc; gpinc = pinc;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
2008-04-25 11:21:08 +00:00
|
|
|
void slopevlin(intptr_t p, int i, intptr_t slopaloffs, int cnt, int bx, int by)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
int *slopalptr, bz, bzinc;
|
|
|
|
unsigned int u, v;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
bz = asm3; bzinc = (asm1>>3);
|
2008-05-10 01:29:37 +00:00
|
|
|
slopalptr = (int*)slopaloffs;
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>0;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
i = krecip(bz>>6); bz += bzinc;
|
|
|
|
u = bx+globalx3*i;
|
|
|
|
v = by+globaly3*i;
|
2008-04-25 11:21:08 +00:00
|
|
|
(*(char *)p) = *(char *)(((intptr_t)slopalptr[0])+gbuf[((u>>(32-glogx))<<glogy)+(v>>(32-glogy))]);
|
2006-04-24 19:04:22 +00:00
|
|
|
slopalptr--;
|
|
|
|
p += gpinc;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Wall,face sprite/wall sprite vertical line functions
|
2007-12-12 17:42:14 +00:00
|
|
|
void setupvlineasm(int neglogy) { glogy = neglogy; }
|
2008-04-25 11:21:08 +00:00
|
|
|
void vlineasm1(int vinc, intptr_t paloffs, int cnt, unsigned int vplc, intptr_t bufplc, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
gbuf = (char *)bufplc;
|
|
|
|
gpal = (char *)paloffs;
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>=0;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
*((char *)p) = gpal[gbuf[vplc>>glogy]];
|
|
|
|
p += bpl;
|
|
|
|
vplc += vinc;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
void setupmvlineasm(int neglogy) { glogy = neglogy; }
|
2008-04-25 11:21:08 +00:00
|
|
|
void mvlineasm1(int vinc, intptr_t paloffs, int cnt, unsigned int vplc, intptr_t bufplc, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char ch;
|
|
|
|
|
|
|
|
gbuf = (char *)bufplc;
|
|
|
|
gpal = (char *)paloffs;
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>=0;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[vplc>>glogy]; if (ch != 255) *((char *)p) = gpal[ch];
|
|
|
|
p += bpl;
|
|
|
|
vplc += vinc;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
void setuptvlineasm(int neglogy) { glogy = neglogy; }
|
2008-04-25 11:21:08 +00:00
|
|
|
void tvlineasm1(int vinc, intptr_t paloffs, int cnt, unsigned int vplc, intptr_t bufplc, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char ch;
|
|
|
|
|
|
|
|
gbuf = (char *)bufplc;
|
|
|
|
gpal = (char *)paloffs;
|
|
|
|
if (transmode)
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>=0;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[vplc>>glogy];
|
|
|
|
if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)];
|
|
|
|
p += bpl;
|
|
|
|
vplc += vinc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>=0;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[vplc>>glogy];
|
|
|
|
if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]];
|
|
|
|
p += bpl;
|
|
|
|
vplc += vinc;
|
|
|
|
}
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Floor sprite horizontal line functions
|
2007-12-12 17:42:14 +00:00
|
|
|
void msethlineshift(int logx, int logy) { glogx = logx; glogy = logy; }
|
2008-04-25 11:21:08 +00:00
|
|
|
void mhline(intptr_t bufplc, unsigned int bx, int cntup16, int junk, unsigned int by, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char ch;
|
|
|
|
|
|
|
|
gbuf = (char *)bufplc;
|
|
|
|
gpal = (char *)asm3;
|
2006-11-13 23:12:47 +00:00
|
|
|
for (cntup16>>=16;cntup16>0;cntup16--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[((bx>>(32-glogx))<<glogy)+(by>>(32-glogy))];
|
|
|
|
if (ch != 255) *((char *)p) = gpal[ch];
|
|
|
|
bx += asm1;
|
|
|
|
by += asm2;
|
|
|
|
p++;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2007-12-12 17:42:14 +00:00
|
|
|
void tsethlineshift(int logx, int logy) { glogx = logx; glogy = logy; }
|
2008-04-25 11:21:08 +00:00
|
|
|
void thline(intptr_t bufplc, unsigned int bx, int cntup16, int junk, unsigned int by, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char ch;
|
|
|
|
|
|
|
|
gbuf = (char *)bufplc;
|
|
|
|
gpal = (char *)asm3;
|
|
|
|
if (transmode)
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
for (cntup16>>=16;cntup16>0;cntup16--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[((bx>>(32-glogx))<<glogy)+(by>>(32-glogy))];
|
|
|
|
if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)];
|
|
|
|
bx += asm1;
|
|
|
|
by += asm2;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
for (cntup16>>=16;cntup16>0;cntup16--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[((bx>>(32-glogx))<<glogy)+(by>>(32-glogy))];
|
|
|
|
if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]];
|
|
|
|
bx += asm1;
|
|
|
|
by += asm2;
|
|
|
|
p++;
|
|
|
|
}
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Rotatesprite vertical line functions
|
2008-04-25 11:21:08 +00:00
|
|
|
void setupspritevline(intptr_t paloffs, int bxinc, int byinc, int ysiz)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
gpal = (char *)paloffs;
|
|
|
|
gbxinc = bxinc;
|
|
|
|
gbyinc = byinc;
|
|
|
|
glogy = ysiz;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
2008-04-25 11:21:08 +00:00
|
|
|
void spritevline(int bx, int by, int cnt, intptr_t bufplc, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
gbuf = (char *)bufplc;
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>1;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
(*(char *)p) = gpal[gbuf[(bx>>16)*glogy+(by>>16)]];
|
|
|
|
bx += gbxinc;
|
|
|
|
by += gbyinc;
|
|
|
|
p += bpl;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2006-04-24 19:04:22 +00:00
|
|
|
//Rotatesprite vertical line functions
|
2008-04-25 11:21:08 +00:00
|
|
|
void msetupspritevline(intptr_t paloffs, int bxinc, int byinc, int ysiz)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
gpal = (char *)paloffs;
|
|
|
|
gbxinc = bxinc;
|
|
|
|
gbyinc = byinc;
|
|
|
|
glogy = ysiz;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
2008-04-25 11:21:08 +00:00
|
|
|
void mspritevline(int bx, int by, int cnt, intptr_t bufplc, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char ch;
|
|
|
|
|
|
|
|
gbuf = (char *)bufplc;
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>1;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[(bx>>16)*glogy+(by>>16)];
|
2007-12-12 17:42:14 +00:00
|
|
|
if (ch != 255)(*(char *)p) = gpal[ch];
|
2006-04-24 19:04:22 +00:00
|
|
|
bx += gbxinc;
|
|
|
|
by += gbyinc;
|
|
|
|
p += bpl;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2008-04-25 11:21:08 +00:00
|
|
|
void tsetupspritevline(intptr_t paloffs, int bxinc, int byinc, int ysiz)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
gpal = (char *)paloffs;
|
|
|
|
gbxinc = bxinc;
|
|
|
|
gbyinc = byinc;
|
|
|
|
glogy = ysiz;
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
2008-04-25 11:21:08 +00:00
|
|
|
void tspritevline(int bx, int by, int cnt, intptr_t bufplc, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
char ch;
|
|
|
|
|
|
|
|
gbuf = (char *)bufplc;
|
|
|
|
if (transmode)
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>1;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[(bx>>16)*glogy+(by>>16)];
|
|
|
|
if (ch != 255) *((char *)p) = gtrans[(*((char *)p))+(gpal[ch]<<8)];
|
|
|
|
bx += gbxinc;
|
|
|
|
by += gbyinc;
|
|
|
|
p += bpl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-11-13 23:12:47 +00:00
|
|
|
for (;cnt>1;cnt--)
|
2006-04-24 19:04:22 +00:00
|
|
|
{
|
|
|
|
ch = gbuf[(bx>>16)*glogy+(by>>16)];
|
|
|
|
if (ch != 255) *((char *)p) = gtrans[((*((char *)p))<<8)+gpal[ch]];
|
|
|
|
bx += gbxinc;
|
|
|
|
by += gbyinc;
|
|
|
|
p += bpl;
|
|
|
|
}
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2008-04-25 11:21:08 +00:00
|
|
|
void setupdrawslab(int dabpl, intptr_t pal)
|
2006-04-24 19:04:22 +00:00
|
|
|
{ bpl = dabpl; gpal = (char *)pal; }
|
2006-04-23 06:44:19 +00:00
|
|
|
|
2008-04-25 11:21:08 +00:00
|
|
|
void drawslab(int dx, int v, int dy, int vi, intptr_t vptr, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
int x;
|
2006-04-24 19:04:22 +00:00
|
|
|
|
|
|
|
while (dy > 0)
|
|
|
|
{
|
2007-12-12 17:42:14 +00:00
|
|
|
for (x=0;x<dx;x++) *(char *)(p+x) = gpal[(int)(*(char *)((v>>16)+vptr))];
|
2006-04-24 19:04:22 +00:00
|
|
|
p += bpl; v += vi; dy--;
|
|
|
|
}
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
2008-04-25 11:21:08 +00:00
|
|
|
void stretchhline(intptr_t p0, int u, int cnt, int uinc, intptr_t rptr, intptr_t p)
|
2006-04-23 06:44:19 +00:00
|
|
|
{
|
2006-04-24 19:04:22 +00:00
|
|
|
p0 = p-(cnt<<2);
|
|
|
|
do
|
|
|
|
{
|
|
|
|
p--;
|
|
|
|
*(char *)p = *(char *)((u>>16)+rptr); u -= uinc;
|
2007-12-12 17:42:14 +00:00
|
|
|
}
|
|
|
|
while (p > p0);
|
2006-04-23 06:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void mmxoverlay() { }
|
|
|
|
|
2006-09-10 17:40:34 +00:00
|
|
|
#endif
|
2006-04-23 06:44:19 +00:00
|
|
|
/*
|
|
|
|
* vim:ts=4:
|
|
|
|
*/
|
|
|
|
|