diff --git a/Makefile b/Makefile index 0df858e..b9839ff 100644 --- a/Makefile +++ b/Makefile @@ -6,11 +6,11 @@ CXXFLAGS = $(CFLAGS) LDLIBS = -lm # /home/relnev/ElectricFence-2.2.2/libefence.a CFLAGS += `sdl-config --cflags` -LDLIBS += -L/usr/X11R6/lib -lX11 -lXext `sdl-config --libs` +LDLIBS += -L/usr/X11R6/lib -lX11 -lXext -lGL `sdl-config --libs` AFLAGS = -g -Iinclude/ -w+macro-params -w+orphan-labels -w+number-overflow -ROOT = main.c math.asm stubs.c stubs2.cpp winapi.c afont.c frustum.c kshape.c map.c maths.c md5.c mem3dc.c mem3dcpp.cpp module.c morph.c object.c shpanim.c sphere.c tables.c vdb.c version.c +ROOT = main.c math.asm mathline.c opengl.c stubs.c stubs2.cpp winapi.c afont.c frustum.c kshape.c map.c maths.c md5.c mem3dc.c mem3dcpp.cpp module.c morph.c object.c shpanim.c sphere.c tables.c vdb.c version.c AVP = ai_sight.c avpview.c bh_agun.c bh_ais.c bh_alien.c bh_binsw.c bh_cable.c bh_corpse.c bh_deathvol.c bh_debri.c bh_dummy.c bh_fan.c bh_far.c bh_fhug.c bh_gener.c bh_ldoor.c bh_lift.c bh_light.c bh_lnksw.c bh_ltfx.c bh_marin.c bh_mission.c bh_near.c bh_pargen.c bh_plachier.c bh_plift.c bh_pred.c bh_queen.c bh_rubberduck.c bh_selfdest.c bh_snds.c bh_spcl.c bh_swdor.c bh_track.c bh_types.c bh_videoscreen.c bh_waypt.c bh_weap.c bh_xeno.c bonusabilities.c cconvars.cpp cdtrackselection.cpp cheatmodes.c comp_map.c comp_shp.c consolelog.cpp davehook.cpp deaths.c decal.c detaillevels.c dynamics.c dynblock.c equipmnt.c equiputl.cpp extents.c game.c game_statistics.c gamecmds.cpp gameflow.c gamevars.cpp hmodel.c hud.c inventry.c language.c lighting.c load_shp.c los.c maps.c mempool.c messagehistory.c missions.cpp movement.c paintball.c particle.c pfarlocs.c pheromon.c player.c pmove.c psnd.c psndproj.c pvisible.c savegame.c scream.cpp secstats.c sfx.c stratdef.c targeting.c track.c triggers.c weapons.c SHAPES = cube.c SUPPORT = consbind.cpp consbtch.cpp coordstr.cpp daemon.cpp r2base.cpp r2pos666.cpp reflist.cpp refobj.cpp scstring.cpp strtab.cpp strutil.c trig666.cpp wrapstr.cpp diff --git a/TODO b/TODO index 8b13789..432e173 100644 --- a/TODO +++ b/TODO @@ -1 +1,4 @@ +* Debug, verify, and reimplant the inline functions in mathline.c to + inline.h + diff --git a/src/fixer.h b/src/fixer.h index ee99063..0c81f88 100644 --- a/src/fixer.h +++ b/src/fixer.h @@ -126,6 +126,9 @@ int GetFileAttributesA(const char *file); int SetFilePointer(HANDLE file, int x, int y, int z); int SetEndOfFile(HANDLE file); +unsigned int timeGetTime(); +unsigned int GetTickCount(); + #ifdef __cplusplus }; #endif diff --git a/src/main.c b/src/main.c index 26ecc90..117477a 100644 --- a/src/main.c +++ b/src/main.c @@ -2,6 +2,9 @@ #include #include +#include +#include + #include "fixer.h" #include "3dc.h" @@ -32,11 +35,75 @@ int InitialiseWindowsSystem() { ScanDrawMode = ScanDrawD3DHardwareRGB; + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + fprintf(stderr, "SDL Init failed: %s\n", SDL_GetError()); + exit(EXIT_FAILURE); + } + + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + + if (SDL_SetVideoMode(640, 480, 0, SDL_OPENGL) == NULL) { + fprintf(stderr, "SDL SetVideoMode failed: %s\n", SDL_GetError()); + SDL_Quit(); + exit(EXIT_FAILURE); + } + + glViewport(0, 0, 640, 480); + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glFrustum(-1, 1, -1, 1, 1, 1000); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + return 0; } +void CheckForWindowsMessages() +{ + SDL_Event event; + + if (SDL_PollEvent(&event)) { + do { + switch(event.type) { + case SDL_KEYDOWN: + break; + case SDL_KEYUP: + break; + case SDL_QUIT: + SDL_Quit(); + exit(17); /* TODO tempy! */ + break; + } + } while (SDL_PollEvent(&event)); + } +} + +void InGameFlipBuffers() +{ + SDL_GL_SwapBuffers(); +} + +void ThisFramesRenderingHasBegun() +{ + fprintf(stderr, "ThisFramesRenderingHasBegun()\n"); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); +} + +void ThisFramesRenderingHasFinished() +{ + fprintf(stderr, "ThisFramesRenderingHasFinished()\n"); +} + int ExitWindowsSystem() { + SDL_Quit(); + return 0; } @@ -176,9 +243,7 @@ int main(int argc, char *argv[]) ThisFramesRenderingHasFinished(); -/* NOT YET InGameFlipBuffers(); -*/ FrameCounterHandler(); { @@ -209,7 +274,7 @@ int main(int argc, char *argv[]) RestartLevel(); } - break; /* TODO -- remove when loop works */ +// break; /* TODO -- remove when loop works */ } AvP.LevelCompleted = thisLevelHasBeenCompleted; diff --git a/src/mathline.c b/src/mathline.c new file mode 100644 index 0000000..ca3546d --- /dev/null +++ b/src/mathline.c @@ -0,0 +1,740 @@ +#include "3dc.h" + +void ADD_LL(LONGLONGCH *a, LONGLONGCH *b, LONGLONGCH *c); +void ADD_LL_PP(LONGLONGCH *c, LONGLONGCH *a); +void SUB_LL(LONGLONGCH *a, LONGLONGCH *b, LONGLONGCH *c); +void SUB_LL_MM(LONGLONGCH *c, LONGLONGCH *a); +void MUL_I_WIDE(int a, int b, LONGLONGCH *c); +int CMP_LL(LONGLONGCH *a, LONGLONGCH *b); +void EQUALS_LL(LONGLONGCH *a, LONGLONGCH *b); +void NEG_LL(LONGLONGCH *a); +void ASR_LL(LONGLONGCH *a, int shift); +void IntToLL(LONGLONGCH *a, int *b); +int MUL_FIXED(int a, int b); +int DIV_FIXED(int a, int b); + +#define DIV_INT(a, b) ((a) / (b)) + +int NarrowDivide(LONGLONGCH *a, int b); +int WideMulNarrowDiv(int a, int b, int c); +void RotateVector_ASM(VECTORCH *v, MATRIXCH *m); +void RotateAndCopyVector_ASM(VECTORCH *v1, VECTORCH *v2, MATRIXCH *m); + +int FloatToInt(float); +#define f2i(a, b) { a = FloatToInt(b); } + +void ADD_LL(LONGLONGCH *a, LONGLONGCH *b, LONGLONGCH *c) +{ +/* + _asm + { + mov esi,a + mov edi,b + mov ebx,c + mov eax,[esi] + mov edx,[esi+4] + add eax,[edi] + adc edx,[edi+4] + mov [ebx],eax + mov [ebx+4],edx + } +*/ + +__asm__("movl 0(%%esi), %%eax \n\t" + "movl 4(%%esi), %%edx \n\t" + "addl 0(%%edi), %%eax \n\t" + "adcl 4(%%edi), %%edx \n\t" + "movl %%eax, 0(%%ebx) \n\t" + "movl %%edx, 4(%%ebx) \n\t" + : + : "S" (a), "D" (b), "b" (c) + : "%eax", "%edx", "memory", "cc" + ); + +/* +__asm__("movl 0(%%esi), %%eax \n\t" + "movl 4(%%esi), %%edx \n\t" + "addl 0(%%edi), %%eax \n\t" + "adcl 4(%%edi), %%edx \n\t" + : "=a" (c->lo32), "=d" (c->hi32) + : "S" (a), "D" (b) + ); +*/ +} + +/* ADD ++ */ + +void ADD_LL_PP(LONGLONGCH *c, LONGLONGCH *a) +{ +/* + _asm + { + mov edi,c + mov esi,a + mov eax,[esi] + mov edx,[esi+4] + add [edi],eax + adc [edi+4],edx + } +*/ +__asm__("movl 0(%%esi), %%eax \n\t" + "movl 4(%%esi), %%edx \n\t" + "addl %%eax, 0(%%edi) \n\t" + "adcl %%edx, 4(%%edi) \n\t" + : + : "D" (c), "S" (a) + : "%eax", "%edx", "memory", "cc" + ); +} + +/* SUB */ + +void SUB_LL(LONGLONGCH *a, LONGLONGCH *b, LONGLONGCH *c) +{ +/* + _asm + { + mov esi,a + mov edi,b + mov ebx,c + mov eax,[esi] + mov edx,[esi+4] + sub eax,[edi] + sbb edx,[edi+4] + mov [ebx],eax + mov [ebx+4],edx + } +*/ +__asm__("movl 0(%%esi), %%eax \n\t" + "movl 4(%%esi), %%edx \n\t" + "subl 0(%%edi), %%eax \n\t" + "sbbl 4(%%edi), %%edx \n\t" + "movl %%eax, 0(%%ebx) \n\t" + "movl %%edx, 4(%%ebx) \n\t" + : + : "S" (a), "D" (b), "b" (c) + : "%eax", "%edx", "memory", "cc" + ); +} + +/* SUB -- */ + +void SUB_LL_MM(LONGLONGCH *c, LONGLONGCH *a) +{ +/* + _asm + { + mov edi,c + mov esi,a + mov eax,[esi] + mov edx,[esi+4] + sub [edi],eax + sbb [edi+4],edx + } +*/ +__asm__("movl 0(%%esi), %%eax \n\t" + "movl 4(%%esi), %%edx \n\t" + "subl %%eax, 0(%%edi) \n\t" + "sbbl %%edx, 4(%%edi) \n\t" + : + : "D" (c), "S" (a) + : "%eax", "%edx", "memory", "cc" + ); +} + +/* + + MUL + + This is the multiply we use, the 32 x 32 = 64 widening version + +*/ + +void MUL_I_WIDE(int a, int b, LONGLONGCH *c) +{ +/* + _asm + { + mov eax,a + mov ebx,c + imul b + mov [ebx],eax + mov [ebx+4],edx + } +*/ +__asm__("imull %2 \n\t" + "movl %%eax, 0(%%ebx) \n\t" + "movl %%edx, 4(%%ebx) \n\t" + : + : "a" (a), "b" (c), "q" (b) + : "%edx", "memory", "cc" + ); +} + +/* + + CMP + + This substitutes for ==, >, <, >=, <= + +*/ + +int CMP_LL(LONGLONGCH *a, LONGLONGCH *b) +{ + int retval; +/* + _asm + { + mov ebx,a + mov ecx,b + mov eax,[ebx] + mov edx,[ebx+4] + sub eax,[ecx] + sbb edx,[ecx+4] + and edx,edx + jne llnz + and eax,eax + je llgs + llnz: + mov retval,1 + and edx,edx + jge llgs + neg retval + llgs: + } +*/ +/* TODO */ +__asm__("movl 0(%%ebx), %%eax \n\t" + "movl 4(%%ebx), %%edx \n\t" + "subl 0(%%ecx), %%eax \n\t" + "sbbl 4(%%ecx), %%edx \n\t" + "xorl %0, %0 \n\t" /* hopefully it doesn't pick %eax or %edx */ + "andl %%edx, %%edx \n\t" + "jne 0 \n\t" /* llnz */ + "andl %%eax, %%eax \n\t" + "je 1 \n" /* llgs */ +"0: \n\t" /* llnz */ + "movl $1, %0 \n\t" + "andl %%edx, %%edx \n\t" + "jge 1 \n\t" /* llgs */ + "negl %0 \n" +"1: \n\t" /* llgs */ + : "=r" (retval) + : "b" (a), "c" (b) + : "%eax", "%edx", "memory", "cc" + ); + + return retval; +} + +/* EQUALS */ + +void EQUALS_LL(LONGLONGCH *a, LONGLONGCH *b) +{ +/* + _asm + { + mov edi,a + mov esi,b + mov eax,[esi] + mov edx,[esi+4] + mov [edi],eax + mov [edi+4],edx + } +*/ +__asm__("movl 0(%%esi), %%eax \n\t" + "movl 4(%%esi), %%edx \n\t" + "movl %%eax, 0(%%edi) \n\t" + "movl %%edx, 4(%%edi) \n\t" + : + : "D" (a), "S" (b) + : "%eax", "%edx", "memory" + ); +} + +/* NEGATE */ + +void NEG_LL(LONGLONGCH *a) +{ +/* + _asm + { + mov esi,a + not dword ptr[esi] + not dword ptr[esi+4] + add dword ptr[esi],1 + adc dword ptr[esi+4],0 + } +*/ +__asm__("notl 0(%%esi) \n\t" + "notl 4(%%esi) \n\t" + "addl $1, 0(%%esi) \n\t" + "adcl $0, 4(%%esi) \n\t" + : + : "S" (a) + : "memory", "cc" + ); +} + +/* ASR */ + +void ASR_LL(LONGLONGCH *a, int shift) +{ +/* + _asm + { + mov esi,a + mov eax,shift + and eax,eax + jle asrdn + asrlp: + sar dword ptr[esi+4],1 + rcr dword ptr[esi],1 + dec eax + jne asrlp + asrdn: + } +*/ +__asm__("andl %%eax, %%eax \n\t" + "jle 0 \n" /* asrdn */ +"1: \n\t" /* asrlp */ + "sarl $1, 4(%%esi) \n\t" + "rcrl $1, 0(%%esi) \n\t" + "decl %%eax \n\t" + "jne 1 \n" +"0: \n\t" + : + : "S" (a), "a" (shift) + : "memory", "cc" + ); + +} + +/* Convert int to LONGLONGCH */ + +void IntToLL(LONGLONGCH *a, int *b) +{ +/* + _asm + { + mov esi,b + mov edi,a + mov eax,[esi] + cdq + mov [edi],eax + mov [edi+4],edx + } +*/ +__asm__("movl 0(%%esi), %%eax \n\t" + "cdq \n\t" + "movl %%eax, 0(%%edi) \n\t" + "movl %%edx, 4(%%edi) \n\t" + : + : "S" (b), "D" (a) + : "%eax", "%edx", "memory", "cc" + ); + +} + +/* + + Fixed Point Multiply. + + + 16.16 * 16.16 -> 16.16 + or + 16.16 * 0.32 -> 0.32 + + A proper version of this function ought to read + 16.16 * 16.16 -> 32.16 + but this would require a long long result + + Algorithm: + + Take the mid 32 bits of the 64 bit result + +*/ + +/* + These functions have been checked for suitability for + a Pentium and look as if they would work adequately. + Might be worth a more detailed look at optimising + them though. +*/ + +int MUL_FIXED(int a, int b) +{ + int retval; +/* + _asm + { + mov eax,a + imul b + shrd eax,edx,16 + mov retval,eax + } +*/ +/* TODO */ +__asm__("imull %2 \n\t" + "shrdl $16, %%edx, %%eax \n\t" + : "=a" (retval) + : "a" (a), "q" (b) + : "%edx", "cc" + ); + return retval; +} + +/* + + Fixed Point Divide - returns a / b + +*/ + +int DIV_FIXED(int a, int b) +{ + int retval; +/* + _asm + { + mov eax,a + cdq + rol eax,16 + mov dx,ax + xor ax,ax + idiv b + mov retval,eax + } +*/ +/* TODO */ +__asm__("cdq \n\t" + "roll $16, %%eax \n\t" + "mov %%ax, %%dx \n\t" + "xor %%ax, %%ax \n\t" + "idivl %2 \n\t" + : "=a" (retval) + : "a" (a), "q" (b) + : "%edx", "cc" + ); + return retval; +} + +/* + + Multiply and Divide Functions. + +*/ + + +/* + + 32/32 division + + This macro is a function on some other platforms + +*/ + +#define DIV_INT(a, b) ((a) / (b)) + +/* + + A Narrowing 64/32 Division + +*/ + +int NarrowDivide(LONGLONGCH *a, int b) +{ + int retval; +/* + _asm + { + mov esi,a + mov eax,[esi] + mov edx,[esi+4] + idiv b + mov retval,eax + } +*/ +__asm__("movl 0(%%esi), %%eax \n\t" + "movl 4(%%esi), %%edx \n\t" + "idivl %%ebx \n\t" + : "=a" (retval) + : "S" (a), "b" (b) + : "%edx", "cc" + ); + return retval; +} + +/* + + This function performs a Widening Multiply followed by a Narrowing Divide. + + a = (a * b) / c + +*/ + +int WideMulNarrowDiv(int a, int b, int c) +{ +#if 0 /* TODO: broken? */ + int retval; +/* + _asm + { + mov eax,a + imul b + idiv c + mov retval,eax + } +*/ +/* TODO */ +__asm__("imull %2 \n\t" + "idivl %3 \n\t" + : "=a" (retval) + : "a" (a), "q" (b), "q" (c) + : "cc" + ); + return retval; +#endif + return (a * b) / c; +} + +/* + + Function to rotate a VECTORCH using a MATRIXCH + + This is the C function + + x = MUL_FIXED(m->mat11, v->vx); + x += MUL_FIXED(m->mat21, v->vy); + x += MUL_FIXED(m->mat31, v->vz); + + y = MUL_FIXED(m->mat12, v->vx); + y += MUL_FIXED(m->mat22, v->vy); + y += MUL_FIXED(m->mat32, v->vz); + + z = MUL_FIXED(m->mat13, v->vx); + z += MUL_FIXED(m->mat23, v->vy); + z += MUL_FIXED(m->mat33, v->vz); + + v->vx = x; + v->vy = y; + v->vz = z; + + This is the MUL_FIXED inline assembler function + + imul edx + shrd eax,edx,16 + + +typedef struct matrixch { + + int mat11; 0 + int mat12; 4 + int mat13; 8 + + int mat21; 12 + int mat22; 16 + int mat23; 20 + + int mat31; 24 + int mat32; 28 + int mat33; 32 + +} MATRIXCH; + +*/ + +#if 0 /* TODO if these are needed */ +static void RotateVector_ASM(VECTORCH *v, MATRIXCH *m) +{ + _asm + { + mov esi,v + mov edi,m + + mov eax,[edi + 0] + imul DWORD PTR [esi + 0] + shrd eax,edx,16 + mov ecx,eax + mov eax,[edi + 12] + imul DWORD PTR [esi + 4] + shrd eax,edx,16 + add ecx,eax + mov eax,[edi + 24] + imul DWORD PTR [esi + 8] + shrd eax,edx,16 + add ecx,eax + + mov eax,[edi + 4] + imul DWORD PTR [esi + 0] + shrd eax,edx,16 + mov ebx,eax + mov eax,[edi + 16] + imul DWORD PTR [esi + 4] + shrd eax,edx,16 + add ebx,eax + mov eax,[edi + 28] + imul DWORD PTR [esi + 8] + shrd eax,edx,16 + add ebx,eax + + mov eax,[edi + 8] + imul DWORD PTR [esi + 0] + shrd eax,edx,16 + mov ebp,eax + mov eax,[edi + 20] + imul DWORD PTR [esi + 4] + shrd eax,edx,16 + add ebp,eax + mov eax,[edi + 32] + imul DWORD PTR [esi + 8] + shrd eax,edx,16 + add ebp,eax + + mov [esi + 0],ecx + mov [esi + 4],ebx + mov [esi + 8],ebp + } +} + +/* + + Here is the same function, this time copying the result to a second vector + +*/ + +static void RotateAndCopyVector_ASM(VECTORCH *v1, VECTORCH *v2, MATRIXCH *m) +{ + _asm + { + mov esi,v1 + mov edi,m + + mov eax,[edi + 0] + imul DWORD PTR [esi + 0] + shrd eax,edx,16 + mov ecx,eax + mov eax,[edi + 12] + imul DWORD PTR [esi + 4] + shrd eax,edx,16 + add ecx,eax + mov eax,[edi + 24] + imul DWORD PTR [esi + 8] + shrd eax,edx,16 + add ecx,eax + + mov eax,[edi + 4] + imul DWORD PTR [esi + 0] + shrd eax,edx,16 + mov ebx,eax + mov eax,[edi + 16] + imul DWORD PTR [esi + 4] + shrd eax,edx,16 + add ebx,eax + mov eax,[edi + 28] + imul DWORD PTR [esi + 8] + shrd eax,edx,16 + add ebx,eax + + mov eax,[edi + 8] + imul DWORD PTR [esi + 0] + shrd eax,edx,16 + mov ebp,eax + mov eax,[edi + 20] + imul DWORD PTR [esi + 4] + shrd eax,edx,16 + add ebp,eax + mov eax,[edi + 32] + imul DWORD PTR [esi + 8] + shrd eax,edx,16 + add ebp,eax + + mov edx,v2 + mov [edx + 0],ecx + mov [edx + 4],ebx + mov [edx + 8],ebp + } +} +#endif + +/* + + Square Root + + Returns the Square Root of a 32-bit number + +*/ + +extern int sqrt_temp1; +extern int sqrt_temp2; + +int SqRoot32(int A) +{ +#if 1 + sqrt_temp1 = A; +/* + _asm + { + finit + fild A + fsqrt + fistp temp2 + fwait + } +*/ + +__asm__("finit \n\t" + "fild sqrt_temp1 \n\t" + "fsqrt \n\t" + "fistp sqrt_temp2 \n\t" + "fwait \n\t" + : + : + : "memory", "cc" + ); + + return sqrt_temp2; +#else +{ /* TODO: clean this please */ + double x = A; + double retvald = sqrt(x); + int retval = retvald; + return retval; +} +#endif +} + + + +/* + + This may look ugly (it is) but it is a MUCH faster way to convert "float" into "int" than + the function call "CHP" used by the WATCOM compiler. + +*/ + +extern float fti_fptmp; +extern int fti_itmp; + +int FloatToInt(float fptmp) +{ +#if 1 + fti_fptmp = fptmp; +/* + _asm + { + fld fptmp + fistp itmp + } +*/ +__asm__("fld fti_fptmp \n\t" + "fistp fti_itmp \n\t" + : + : + : "memory", "cc" + ); + + return fti_itmp; +#else + return fptmp; +#endif +} diff --git a/src/maths.c b/src/maths.c index 32222a1..711d4b4 100644 --- a/src/maths.c +++ b/src/maths.c @@ -1009,7 +1009,7 @@ void MatrixToEuler(MATRIXCH *m, EULER *e) } else CosMatrixPitch = 1; - + SineMatrixYaw = WideMulNarrowDiv( #if j_and_r_change m->mat31 >> m2e_scale, ONE_FIXED_S, CosMatrixPitch); @@ -2090,9 +2090,12 @@ int PointInPolygon(int *point, int *polygon, int c, int ppsize) /* go back to first point */ polyp = polygon; +dx = 0; /* TODO: uninitialized?? */ + /* for each point */ while (0 != c) { + /* is this line straddling the x co-ordinate of the point? */ /* if not it is not worth testing for intersection with the half-line */ /* we must be careful to get the strict and non-stict inequalities */ diff --git a/src/opengl.c b/src/opengl.c new file mode 100644 index 0000000..e24a595 --- /dev/null +++ b/src/opengl.c @@ -0,0 +1,68 @@ +#include +#include +#include + +#include +#include +#include + +#include "fixer.h" + +#include "3dc.h" +#include "platform.h" +#include "module.h" +#include "stratdef.h" +#include "projfont.h" +#include "savegame.h" +#include "krender.h" +#include "kshape.h" +#include "prototyp.h" +#include "d3d_hud.h" + + +extern IMAGEHEADER ImageHeaderArray[]; +extern VIEWDESCRIPTORBLOCK *Global_VDB_Ptr; + +static void *CurrTextureHandle; + +void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDERVERTEX *renderVerticesPtr) +{ + int texoffset; + void *TextureHandle; + int i; + + texoffset = inputPolyPtr->PolyColour & ClrTxDefn; + if (texoffset) { + TextureHandle = (void *)ImageHeaderArray[texoffset].D3DHandle; + } else { + TextureHandle = CurrTextureHandle; + } + + fprintf(stderr, "D3D_ZBufferedGouraudTexturedPolygon_Output(%p, %p)\n", inputPolyPtr, renderVerticesPtr); + fprintf(stderr, "\tRenderPolygon.NumberOfVertices = %d\n", RenderPolygon.NumberOfVertices); + fprintf(stderr, "\ttexoffset = %d (ptr = %p)\n", texoffset, texoffset ? (void *)ImageHeaderArray[texoffset].D3DHandle : CurrTextureHandle); + + glBegin(GL_POLYGON); + for (i = 0; i < RenderPolygon.NumberOfVertices; i++) { + GLfloat x, y, z; + int x1, y1; + RENDERVERTEX *vertices = &renderVerticesPtr[i]; + +/* this is just random garbage */ +// x1 = (vertices->X*(Global_VDB_Ptr->VDB_ProjX+1))/vertices->Z+Global_VDB_Ptr->VDB_CentreX; +// y1 = (vertices->Y*(Global_VDB_Ptr->VDB_ProjY+1))/vertices->Z+Global_VDB_Ptr->VDB_CentreY; + x = vertices->X; + y = vertices->Y; + + x = x/32768.0; + y = y/32768.0; + z = -1+-1.0f/vertices->Z; + + glColor4ub(vertices->R, vertices->G, vertices->B, vertices->A); + glVertex3f(x, y, z); + fprintf(stderr, "Vertex %d: (%f, %f, %f) [%d, %d, %d] (%d, %d, %d, %d)\n", i, x, y, z, vertices->X, vertices->Y, vertices->Z, vertices->R, vertices->G, vertices->B, vertices->A); + } + glEnd(); + + CurrTextureHandle = TextureHandle; +} diff --git a/src/stubs.c b/src/stubs.c index 0048294..a134f99 100644 --- a/src/stubs.c +++ b/src/stubs.c @@ -18,20 +18,11 @@ #include "d3d_hud.h" -extern IMAGEHEADER ImageHeaderArray[]; - /* winmain.c */ BOOL KeepMainRifFile = FALSE; int HWAccel = 1; -/* win_func.cpp */ -void CheckForWindowsMessages() -{ - fprintf(stderr, "CheckForWindowsMessages()\n"); -} - - /* krender.c -- thought this file was unused */ void KDraw_Item_2dTexturePolygon(int *itemptr) { @@ -476,16 +467,6 @@ BOOL UnlockExecuteBufferAndPrepareForUse() return FALSE; } -void ThisFramesRenderingHasBegun() -{ - fprintf(stderr, "ThisFramesRenderingHasBegun()\n"); -} - -void ThisFramesRenderingHasFinished() -{ - fprintf(stderr, "ThisFramesRenderingHasFinished()\n"); -} - void SecondFlushD3DZBuffer() { fprintf(stderr, "SecondFlushD3DZBuffer()\n"); @@ -535,26 +516,6 @@ BOOL EndD3DScene() return FALSE; } -static void *CurrTextureHandle; -void D3D_ZBufferedGouraudTexturedPolygon_Output(POLYHEADER *inputPolyPtr, RENDERVERTEX *renderVerticesPtr) -{ - int texoffset; - void *TextureHandle; - - texoffset = inputPolyPtr->PolyColour & ClrTxDefn; - if (texoffset) { - TextureHandle = (void *)ImageHeaderArray[texoffset].D3DHandle; - } else { - TextureHandle = CurrTextureHandle; - } - - fprintf(stderr, "D3D_ZBufferedGouraudTexturedPolygon_Output(%p, %p)\n", inputPolyPtr, renderVerticesPtr); - fprintf(stderr, "\tRenderPolygon.NumberOfVertices = %d\n", RenderPolygon.NumberOfVertices); - fprintf(stderr, "\ttexoffset = %d (ptr = %p)\n", texoffset, texoffset ? (void *)ImageHeaderArray[texoffset].D3DHandle : CurrTextureHandle); - - CurrTextureHandle = TextureHandle; -} - void D3D_ZBufferedGouraudPolygon_Output(POLYHEADER *inputPolyPtr,RENDERVERTEX *renderVerticesPtr) { fprintf(stderr, "D3D_ZBufferedGouraudPolygon_Output(%p, %p)\n", inputPolyPtr, renderVerticesPtr); diff --git a/src/win95/inline.h b/src/win95/inline.h index f2a7233..52ea527 100644 --- a/src/win95/inline.h +++ b/src/win95/inline.h @@ -1111,7 +1111,7 @@ a = itmp;} #else -#if 0 +#if 1 /* GCC! */ void ADD_LL(LONGLONGCH *a, LONGLONGCH *b, LONGLONGCH *c); void ADD_LL_PP(LONGLONGCH *c, LONGLONGCH *a); void SUB_LL(LONGLONGCH *a, LONGLONGCH *b, LONGLONGCH *c); @@ -1134,10 +1134,12 @@ void RotateAndCopyVector_ASM(VECTORCH *v1, VECTORCH *v2, MATRIXCH *m); int FloatToInt(float); #define f2i(a, b) { a = FloatToInt(b); } -#endif + +#else /* inline stuff */ /* ADD */ + static __inline__ void ADD_LL(LONGLONGCH *a, LONGLONGCH *b, LONGLONGCH *c) { /* @@ -1319,21 +1321,21 @@ static __inline__ int CMP_LL(LONGLONGCH *a, LONGLONGCH *b) } */ /* TODO */ -__asm__("xorl %0, %0 \n\t" - "movl 0(%%ebx), %%eax \n\t" +__asm__("movl 0(%%ebx), %%eax \n\t" "movl 4(%%ebx), %%edx \n\t" "subl 0(%%ecx), %%eax \n\t" "sbbl 4(%%ecx), %%edx \n\t" + "xorl %0, %0 \n\t" /* hopefully it doesn't pick %eax or %edx */ "andl %%edx, %%edx \n\t" - "jne llnz \n\t" + "jne 0 \n\t" /* llnz */ "andl %%eax, %%eax \n\t" - "je llgs \n" -"llnz: \n\t" + "je 1 \n" /* llgs */ +"0: \n\t" /* llnz */ "movl $1, %0 \n\t" "andl %%edx, %%edx \n\t" - "jge llgs \n\t" + "jge 1 \n\t" /* llgs */ "negl %0 \n" -"llgs: \n\t" +"1: \n\t" /* llgs */ : "=r" (retval) : "b" (a), "c" (b) : "%eax", "%edx", "memory", "cc" @@ -1411,13 +1413,13 @@ static __inline__ void ASR_LL(LONGLONGCH *a, int shift) } */ __asm__("andl %%eax, %%eax \n\t" - "jle asrdn \n" -"asrlp: \n\t" + "jle 0 \n" /* asrdn */ +"1: \n\t" /* asrlp */ "sarl $1, 4(%%esi) \n\t" "rcrl $1, 0(%%esi) \n\t" "decl %%eax \n\t" - "jne asrlp \n" -"asrdn: \n\t" + "jne 1 \n" +"0: \n\t" : : "S" (a), "a" (shift) : "memory", "cc" @@ -1589,6 +1591,7 @@ __asm__("movl 0(%%esi), %%eax \n\t" static __inline__ int WideMulNarrowDiv(int a, int b, int c) { +#if 0 /* TODO: broken? */ int retval; /* _asm @@ -1607,6 +1610,8 @@ __asm__("imull %2 \n\t" : "cc" ); return retval; +#endif + return (a * b) / c; } /* @@ -1781,8 +1786,10 @@ static void RotateAndCopyVector_ASM(VECTORCH *v1, VECTORCH *v2, MATRIXCH *m) extern int sqrt_temp1; extern int sqrt_temp2; +#include static __inline__ int SqRoot32(int A) { +#if 0 sqrt_temp1 = A; /* _asm @@ -1806,6 +1813,13 @@ __asm__("finit \n\t" ); return sqrt_temp2; +#endif +{ /* TODO: clean this please */ + double x = A; + double retvald = sqrt(x); + int retval = retvald; + return retval; +} } #endif @@ -1823,6 +1837,7 @@ extern int fti_itmp; static __inline__ int FloatToInt(float fptmp) { +#if 0 fti_fptmp = fptmp; /* _asm @@ -1839,6 +1854,9 @@ __asm__("fld fti_fptmp \n\t" ); return fti_itmp; +#endif + + return fptmp; } /* @@ -1851,6 +1869,8 @@ __asm__("fld fti_fptmp \n\t" a = FloatToInt(b); \ } +#endif + #endif int WideMul2NarrowDiv(int a, int b, int c, int d, int e); diff --git a/src/winapi.c b/src/winapi.c index 6719293..dc3b97e 100644 --- a/src/winapi.c +++ b/src/winapi.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "fixer.h" @@ -182,16 +183,34 @@ int SetEndOfFile(HANDLE file) } /* time in miliseconds */ -int timeGetTime() +struct timeval tv0; + +unsigned int timeGetTime() { - fprintf(stderr, "timeGetTime()\n"); + struct timeval tv1; + int secs, usecs; - return 0; + if (tv0.tv_sec == 0) { + gettimeofday(&tv0, NULL); + + return 0; + } + + gettimeofday(&tv1, NULL); + + secs = tv1.tv_sec - tv0.tv_sec; + usecs = tv1.tv_usec - tv0.tv_usec; + if (usecs < 0) { + usecs += 1000000; + secs--; + } + +printf("Ticks = %u\n", secs * 1000 + (usecs / 1000)); + + return secs * 1000 + (usecs / 1000); } -int GetTickCount() +unsigned int GetTickCount() { - fprintf(stderr, "GetTickCount()\n"); - - return 0; + return timeGetTime(); }