mirror of
https://github.com/jmarshall23/CnC_Remastered_Collection.git
synced 2026-08-17 08:50:29 +02:00
Inline assembly is now replaced with C.
This commit is contained in:
+40
-119
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user