Inline assembly is now replaced with C.

This commit is contained in:
Justin Marshall
2020-06-22 09:01:10 -07:00
parent 332c36efa3
commit fd24e73e0f
11 changed files with 734 additions and 2900 deletions
+1
View File
@@ -725,3 +725,4 @@ add_executable(RedAlert ${src_io} ${src_win32lib} ${src_redalert} ${src_external
set_target_properties(RedAlert PROPERTIES OUTPUT_NAME "RedAlert" LINK_FLAGS "/PDB:\"RedAlert.pdb\" /SUBSYSTEM:WINDOWS" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/../" )
target_include_directories(RedAlert PRIVATE ./external/xml/;./external/devil/;./external/;./redalert/win32lib;./external/lua/;./external/imgui;./external/dxsdk/Include;./external/ffmpeg-win32/include;./external/sdl2/include;./win32lib;./external/openal/include)
target_link_libraries(RedAlert "opengl32.lib" "winmm.lib" "Ws2_32.lib" "${CMAKE_SOURCE_DIR}/external/devil/ilu.lib" "${CMAKE_SOURCE_DIR}/external/devil/DevIL.lib" "${CMAKE_SOURCE_DIR}/external/sdl2/lib/x86/SDL2.lib" "${CMAKE_SOURCE_DIR}/external/openal/out/build/x86-Release/OpenAL32.lib")
+40 -119
View File
@@ -437,129 +437,50 @@ void Move_Point(short& x, short& y, register DirType dir, unsigned short distanc
y += -( sinTable[dir] * distance ) / SHRT_MAX;
}
int __cdecl calcx(signed short param1, short distance)
{
__asm {
//#pragma aux calcx parm [ax] [bx] \
movzx eax, [param1]
mov bx, [distance]
imul bx
shl ax, 1
rcl dx, 1
mov al, ah
mov ah, dl
cwd
}
}
int __cdecl calcy(signed short param1, short distance)
{
__asm {
//#pragma aux calcy parm [ax] [bx] \
movzx eax, [param1]
mov bx, [distance]
imul bx
shl ax, 1
rcl dx, 1
mov al, ah
mov ah, dl
cwd
neg eax
}
}
// This is from Coord.cpp from chronoshift.
void Normal_Move_Point(short& x, short& y, register DirType dir, unsigned short distance)
{
static unsigned char const CosTable[256] = {
0x00,0x03,0x06,0x09,0x0c,0x0f,0x12,0x15,
0x18,0x1b,0x1e,0x21,0x24,0x27,0x2a,0x2d,
0x30,0x33,0x36,0x39,0x3b,0x3e,0x41,0x43,
0x46,0x49,0x4b,0x4e,0x50,0x52,0x55,0x57,
0x59,0x5b,0x5e,0x60,0x62,0x64,0x65,0x67,
0x69,0x6b,0x6c,0x6e,0x6f,0x71,0x72,0x74,
0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7b,
0x7c,0x7d,0x7d,0x7e,0x7e,0x7e,0x7e,0x7e,
0x7f,0x7e,0x7e,0x7e,0x7e,0x7e,0x7d,0x7d,
0x7c,0x7b,0x7b,0x7a,0x79,0x78,0x77,0x76,
0x75,0x74,0x72,0x71,0x70,0x6e,0x6c,0x6b,
0x69,0x67,0x66,0x64,0x62,0x60,0x5e,0x5b,
0x59,0x57,0x55,0x52,0x50,0x4e,0x4b,0x49,
0x46,0x43,0x41,0x3e,0x3b,0x39,0x36,0x33,
0x30,0x2d,0x2a,0x27,0x24,0x21,0x1e,0x1b,
0x18,0x15,0x12,0x0f,0x0c,0x09,0x06,0x03,
0x00,0xfd,0xfa,0xf7,0xf4,0xf1,0xee,0xeb,
0xe8,0xe5,0xe2,0xdf,0xdc,0xd9,0xd6,0xd3,
0xd0,0xcd,0xca,0xc7,0xc5,0xc2,0xbf,0xbd,
0xba,0xb7,0xb5,0xb2,0xb0,0xae,0xab,0xa9,
0xa7,0xa5,0xa2,0xa0,0x9e,0x9c,0x9a,0x99,
0x97,0x95,0x94,0x92,0x91,0x8f,0x8e,0x8c,
0x8b,0x8a,0x89,0x88,0x87,0x86,0x85,0x85,
0x84,0x83,0x83,0x82,0x82,0x82,0x82,0x82,
0x82,0x82,0x82,0x82,0x82,0x82,0x83,0x83,
0x84,0x85,0x85,0x86,0x87,0x88,0x89,0x8a,
0x8b,0x8c,0x8e,0x8f,0x90,0x92,0x94,0x95,
0x97,0x99,0x9a,0x9c,0x9e,0xa0,0xa2,0xa5,
0xa7,0xa9,0xab,0xae,0xb0,0xb2,0xb5,0xb7,
0xba,0xbd,0xbf,0xc2,0xc5,0xc7,0xca,0xcd,
0xd0,0xd3,0xd6,0xd9,0xdc,0xdf,0xe2,0xe5,
0xe8,0xeb,0xee,0xf1,0xf4,0xf7,0xfa,0xfd,
// These tables are 7bit fixed point lookup tables representing the values of sine and cosine radian values.
static const int8_t _cosinetable[256] = {
0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45,
48, 51, 54, 57, 59, 62, 65, 67, 70, 73, 75, 78, 80, 82, 85, 87,
89, 91, 94, 96, 98, 100, 101, 103, 105, 107, 108, 110, 111, 113, 114, 116,
117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 125, 126, 126, 126, 126, 126,
127, 126, 126, 126, 126, 126, 125, 125, 124, 123, 123, 122, 121, 120, 119, 118,
117, 116, 114, 113, 112, 110, 108, 107, 105, 103, 102, 100, 98, 96, 94, 91,
89, 87, 85, 82, 80, 78, 75, 73, 70, 67, 65, 62, 59, 57, 54, 51,
48, 45, 42, 39, 36, 33, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3,
0, -3, -6, -9, -12, -15, -18, -21, -24, -27, -30, -33, -36, -39, -42, -45,
-48, -51, -54, -57, -59, -62, -65, -67, -70, -73, -75, -78, -80, -82, -85, -87,
-89, -91, -94, -96, -98, -100, -102, -103, -105, -107, -108, -110, -111, -113, -114, -116,
-117, -118, -119, -120, -121, -122, -123, -123, -124, -125, -125, -126, -126, -126, -126, -126,
-126, -126, -126, -126, -126, -126, -125, -125, -124, -123, -123, -122, -121, -120, -119, -118,
-117, -116, -114, -113, -112, -110, -108, -107, -105, -103, -102, -100, -98, -96, -94, -91,
-89, -87, -85, -82, -80, -78, -75, -73, -70, -67, -65, -62, -59, -57, -54, -51,
-48, -45, -42, -39, -36, -33, -30, -27, -24, -21, -18, -15, -12, -9, -6, -3
};
static unsigned char const SinTable[256] = {
0x7f,0x7e,0x7e,0x7e,0x7e,0x7e,0x7d,0x7d,
0x7c,0x7b,0x7b,0x7a,0x79,0x78,0x77,0x76,
0x75,0x74,0x72,0x71,0x70,0x6e,0x6c,0x6b,
0x69,0x67,0x66,0x64,0x62,0x60,0x5e,0x5b,
0x59,0x57,0x55,0x52,0x50,0x4e,0x4b,0x49,
0x46,0x43,0x41,0x3e,0x3b,0x39,0x36,0x33,
0x30,0x2d,0x2a,0x27,0x24,0x21,0x1e,0x1b,
0x18,0x15,0x12,0x0f,0x0c,0x09,0x06,0x03,
0x00,0xfd,0xfa,0xf7,0xf4,0xf1,0xee,0xeb,
0xe8,0xe5,0xe2,0xdf,0xdc,0xd9,0xd6,0xd3,
0xd0,0xcd,0xca,0xc7,0xc5,0xc2,0xbf,0xbd,
0xba,0xb7,0xb5,0xb2,0xb0,0xae,0xab,0xa9,
0xa7,0xa5,0xa2,0xa0,0x9e,0x9c,0x9a,0x99,
0x97,0x95,0x94,0x92,0x91,0x8f,0x8e,0x8c,
0x8b,0x8a,0x89,0x88,0x87,0x86,0x85,0x85,
0x84,0x83,0x83,0x82,0x82,0x82,0x82,0x82,
0x82,0x82,0x82,0x82,0x82,0x82,0x83,0x83,
0x84,0x85,0x85,0x86,0x87,0x88,0x89,0x8a,
0x8b,0x8c,0x8e,0x8f,0x90,0x92,0x94,0x95,
0x97,0x99,0x9a,0x9c,0x9e,0xa0,0xa2,0xa5,
0xa7,0xa9,0xab,0xae,0xb0,0xb2,0xb5,0xb7,
0xba,0xbd,0xbf,0xc2,0xc5,0xc7,0xca,0xcd,
0xd0,0xd3,0xd6,0xd9,0xdc,0xdf,0xe2,0xe5,
0xe8,0xeb,0xee,0xf1,0xf4,0xf7,0xfa,0xfd,
0x00,0x03,0x06,0x09,0x0c,0x0f,0x12,0x15,
0x18,0x1b,0x1e,0x21,0x24,0x27,0x2a,0x2d,
0x30,0x33,0x36,0x39,0x3b,0x3e,0x41,0x43,
0x46,0x49,0x4b,0x4e,0x50,0x52,0x55,0x57,
0x59,0x5b,0x5e,0x60,0x62,0x64,0x65,0x67,
0x69,0x6b,0x6c,0x6e,0x6f,0x71,0x72,0x74,
0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7b,
0x7c,0x7d,0x7d,0x7e,0x7e,0x7e,0x7e,0x7e,
static const int8_t _sintable[256] = {
127, 126, 126, 126, 126, 126, 125, 125, 124, 123, 123, 122, 121, 120, 119, 118,
117, 116, 114, 113, 112, 110, 108, 107, 105, 103, 102, 100, 98, 96, 94, 91,
89, 87, 85, 82, 80, 78, 75, 73, 70, 67, 65, 62, 59, 57, 54, 51,
48, 45, 42, 39, 36, 33, 30, 27, 24, 21, 18, 15, 12, 9, 6, 3,
0, -3, -6, -9, -12, -15, -18, -21, -24, -27, -30, -33, -36, -39, -42, -45,
-48, -51, -54, -57, -59, -62, -65, -67, -70, -73, -75, -78, -80, -82, -85, -87,
-89, -91, -94, -96, -98, -100, -102, -103, -105, -107, -108, -110, -111, -113, -114, -116,
-117, -118, -119, -120, -121, -122, -123, -123, -124, -125, -125, -126, -126, -126, -126, -126,
-126, -126, -126, -126, -126, -126, -125, -125, -124, -123, -123, -122, -121, -120, -119, -118,
-117, -116, -114, -113, -112, -110, -108, -107, -105, -103, -102, -100, -98, -96, -94, -91,
-89, -87, -85, -82, -80, -78, -75, -73, -70, -67, -65, -62, -59, -57, -54, -51,
-48, -45, -42, -39, -36, -33, -30, -27, -24, -21, -18, -15, -12, -9, -6, -3,
0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45,
48, 51, 54, 57, 59, 62, 65, 67, 70, 73, 75, 78, 80, 82, 85, 87,
89, 91, 94, 96, 98, 100, 101, 103, 105, 107, 108, 110, 111, 113, 114, 116,
117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 125, 126, 126, 126, 126, 126
};
distance = distance; // Keep LINT quiet.
//
// Have to declare table as unsigned otherwise MSVC complains, but we need to treat the actual values as signed.
//
static const char* _sin_table = (char*)&SinTable[0];
static const char* _cos_table = (char*)&CosTable[0];
x += calcx(_cos_table[dir], distance);
y += calcy(_sin_table[dir] / 2, distance);
// The division by 128 is for a shift of 7 bits for a fixed point chop to int.
// Note that this function uses 7 bit accuracy, not 8 bit like the fixed class.
x += (_cosinetable[dir] * distance) / 128;
y -= (_sintable[dir] * distance) / 128;
}
+2 -2
View File
@@ -206,8 +206,8 @@ inline ShapeFlags_Type operator ~(ShapeFlags_Type);
void __cdecl Set_Bit(void * array, int bit, int value);
int __cdecl Get_Bit(void const * array, int bit);
int __cdecl First_True_Bit(void const * array);
int __cdecl First_False_Bit(void const * array);
int __cdecl First_True_Bit(void const * array, int size);
int __cdecl First_False_Bit(void const * array, int size);
int __cdecl Bound(int original, int min, int max);
#if (0)
+3 -1
View File
@@ -1561,7 +1561,9 @@ extern int _MCAPI mc_in_source (void);
extern int _MCAPI mc_is_active (void);
extern MCSL _MCAPI mc_line (void);
extern char * _MCAPI mc_location_text (void);
#define mc_load_debugger() _asm int 3
// jmarshall - added debug break.
#define mc_load_debugger() __debugbreak()
// jmarshall end
extern unsigned long _MCAPI mc_memory_leaked (void);
extern char * _MCAPI mc_memrec_text (MEMRECP);
extern MEMRECP _MCAPI mc_memrec (void);
+248 -851
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -361,7 +361,7 @@ class BooleanVectorClass
int First_False(void) const {
if (LastIndex != -1) Fixup(-1);
int retval = First_False_Bit(&BitArray[0]);
int retval = First_False_Bit(&BitArray[0], BitArray.Length());
if (retval < BitCount) return(retval);
/*
@@ -375,7 +375,7 @@ class BooleanVectorClass
int First_True(void) const {
if (LastIndex != -1) Fixup(-1);
int retval = First_True_Bit(&BitArray[0]);
int retval = First_True_Bit(&BitArray[0], BitArray.Length());
if (retval < BitCount) return(retval);
/*
File diff suppressed because it is too large Load Diff
+24 -10
View File
@@ -32,6 +32,7 @@
#include <stdlib.h>
#include <time.h>
#include "misc.h"
#include <assert.h>
@@ -50,6 +51,7 @@ extern "C" unsigned long RandNumb = 0x12349876;
int IRandom(int minval, int maxval)
{
#if 0 // jmarshall - not used.
int num,mask;
// Keep minval and maxval straight.
@@ -63,12 +65,17 @@ int IRandom(int minval, int maxval)
while( (num = (rand() & mask) + minval) > maxval ) ;
return(num);
#else
assert(!"Random function not implmented!");
return 0;
#endif
}
unsigned char Random(void)
{
#if 0 // jmarshall - not used.
__asm {
lea esi, [RandNumb] //; get offset in segment of RandNumb
xor eax,eax
@@ -84,22 +91,29 @@ unsigned char Random(void)
mov al,[esi] //; reload byte 1 of RandNumb
xor al,[esi+1] //; xor with byte 2 of RandNumb
}
#else
assert(!"Random function not implmented!");
return 0;
#endif
}
int Get_Random_Mask(int maxval)
{
__asm {
bsr ecx,[maxval] // ; put bit position of highest bit in ecx
mov eax, 1 // ; set one bit on in eax
jz invalid // ; if BSR shows maxval==0, return eax=1
inc ecx // ; get one bit higher than count showed
shl eax,cl // ; move our EAX bit into position
dec eax // ; dec it to create the mask.
invalid:
}
#if 0 // jmarshall - not used.
bool v1; // zf
DWORD v2; // ecx
int result; // eax
v1 = !_BitScanReverse((DWORD*)&v2, maxval);
result = 1;
if (!v1)
result = (1 << (v2 + 1)) - 1;
return result;
#else
return 0;
#endif
}
+2 -2
View File
@@ -126,10 +126,10 @@ void __cdecl Set_Bit(void * array, int bit, int value);
int __cdecl Get_Bit(void const * array, int bit);
//#pragma aux First_True_Bit parm [esi]
int __cdecl First_True_Bit(void const * array);
int __cdecl First_True_Bit(void const * array, int size);
//#pragma aux First_False_Bit parm [esi]
int __cdecl First_False_Bit(void const * array);
int __cdecl First_False_Bit(void const * array, int size);
//#pragma aux Bound parm [eax] [ebx] [ecx]
int __cdecl Bound(int original, int min, int max);
-26
View File
@@ -833,31 +833,8 @@ extern int Load_Interpolated_Palettes(char const *filename, BOOL add=FALSE);
* HISTORY: *
* 05/27/1994 JLB : Created. *
*=============================================================================================*/
int Distance_Coord(COORDINATE coord1, COORDINATE coord2);
#pragma aux Distance_Coord parm [eax] [ebx] \
modify [edx ebx] \
value [eax] = \
"mov dx,ax" \
"sub dx,bx" \
"jg okx" \
"neg dx" \
"okx:" \
"shr eax,16" \
"shr ebx,16" \
"sub ax,bx" \
"jg oky" \
"neg ax" \
"oky:" \
"cmp ax,dx" \
"jg ok" \
"xchg ax,dx" \
"ok:" \
"shr dx,1" \
"add ax,dx"
inline int Distance(COORDINATE coord1, COORDINATE coord2)
{
#ifdef NEVER
int diff1, diff2;
diff1 = Coord_Y(coord1) - Coord_Y(coord2);
@@ -868,9 +845,6 @@ inline int Distance(COORDINATE coord1, COORDINATE coord2)
return(diff1 + (diff2>>1));
}
return(diff2 + (diff1>>1));
#else
return(Distance_Coord(coord1, coord2));
#endif
}
+2 -2
View File
@@ -372,7 +372,7 @@ class BooleanVectorClass
int First_False(void) const {
if (LastIndex != -1) Fixup(-1);
int retval = First_False_Bit(&BitArray[0]);
int retval = First_False_Bit(&BitArray[0], BitArray.Length());
if (retval < BitCount) return(retval);
/*
@@ -386,7 +386,7 @@ class BooleanVectorClass
int First_True(void) const {
if (LastIndex != -1) Fixup(-1);
int retval = First_True_Bit(&BitArray[0]);
int retval = First_True_Bit(&BitArray[0], BitArray.Length());
if (retval < BitCount) return(retval);
/*