Made MyChar.cpp ASM-accurate

See #74
This commit is contained in:
Clownacy 2019-05-13 14:17:03 +01:00
parent d4d82d0ba8
commit f04872b91b
3 changed files with 743 additions and 623 deletions

View file

@ -515,6 +515,94 @@ addr = 0x414B20
name = "SetMapping"
addr = 0x414B40
[[func]]
name = "InitMyChar"
addr = 0x414B50
[[func]]
name = "AnimationMyChar"
addr = 0x414BF0
[[func]]
name = "ShowMyChar"
addr = 0x415220
[[func]]
name = "PutMyChar"
addr = 0x415250
[[func]]
name = "ActMyChar_Normal"
addr = 0x4156C0
[[func]]
name = "ActMyChar_Stream"
addr = 0x416470
[[func]]
name = "ActMyChar"
addr = 0x4168C0
[[func]]
name = "AirProcess"
addr = 0x416990
[[func]]
name = "GetMyCharPosition"
addr = 0x416AA0
[[func]]
name = "SetMyCharPosition"
addr = 0x416AC0
[[func]]
name = "MoveMyChar"
addr = 0x416B30
[[func]]
name = "ZeroMyCharXMove"
addr = 0x416B50
[[func]]
name = "GetUnitMyChar"
addr = 0x416B60
[[func]]
name = "SetMyCharDirect"
addr = 0x416B70
[[func]]
name = "ChangeMyUnit"
addr = 0x416C40
[[func]]
name = "PitMyChar"
addr = 0x416C50
[[func]]
name = "EquipItem"
addr = 0x416C70
[[func]]
name = "ResetCheck"
addr = 0x416CA0
[[func]]
name = "SetNoise"
addr = 0x416CC0
[[func]]
name = "CutNoise"
addr = 0x416D40
[[func]]
name = "ResetNoise"
addr = 0x416D80
[[func]]
name = "SleepNoise"
addr = 0x416DF0
[[func]]
name = "ResetMyCharFlag"
addr = 0x416E20

View file

@ -44,7 +44,7 @@ void InitMyChar()
gMC.unit = 0;
}
void AnimationMyChar(bool bKey)
void AnimationMyChar(BOOL bKey)
{
RECT rcLeft[12] = {
{0, 0, 16, 16},
@ -76,8 +76,9 @@ void AnimationMyChar(bool bKey)
{112, 16, 128, 32},
};
if (!(gMC.cond & 2))
{
if (gMC.cond & 2)
return;
if (gMC.flag & 8)
{
if (gMC.cond & 1)
@ -137,23 +138,21 @@ void AnimationMyChar(bool bKey)
{
gMC.ani_no = 10;
}
else if (gMC.ym <= 0)
else
{
if (gMC.ym > 0)
gMC.ani_no = 1;
else
gMC.ani_no = 3;
}
else
{
gMC.ani_no = 1;
}
if (gMC.direct)
gMC.rect = rcRight[gMC.ani_no];
else
if (gMC.direct == 0)
gMC.rect = rcLeft[gMC.ani_no];
}
else
gMC.rect = rcRight[gMC.ani_no];
}
void ShowMyChar(bool bShow)
void ShowMyChar(BOOL bShow)
{
if (bShow)
gMC.cond &= ~2;
@ -163,8 +162,11 @@ void ShowMyChar(bool bShow)
void PutMyChar(int fx, int fy)
{
if ((gMC.cond & 0x80) && !(gMC.cond & 2))
{
int arms_offset_y;
if ((gMC.cond & 0x80) == 0 || (gMC.cond & 2))
return;
// Draw weapon
gMC.rect_arms.left = 24 * (gArmsData[gSelectedArms].code % 13);
gMC.rect_arms.right = gMC.rect_arms.left + 24;
@ -177,7 +179,6 @@ void PutMyChar(int fx, int fy)
gMC.rect_arms.bottom += 16;
}
int arms_offset_y;
if (gMC.up)
{
arms_offset_y = -4;
@ -198,23 +199,24 @@ void PutMyChar(int fx, int fy)
if (gMC.ani_no == 1 || gMC.ani_no == 3 || gMC.ani_no == 6 || gMC.ani_no == 8)
++gMC.rect_arms.top;
if (gMC.direct)
PutBitmap3(
&grcGame,
(gMC.x - gMC.view.left) / 0x200 - fx / 0x200,
(gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y,
&gMC.rect_arms,
SURFACE_ID_ARMS);
else
if (gMC.direct == 0)
PutBitmap3(
&grcGame,
(gMC.x - gMC.view.left) / 0x200 - fx / 0x200 - 8,
(gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y,
&gMC.rect_arms,
SURFACE_ID_ARMS);
else
PutBitmap3(
&grcGame,
(gMC.x - gMC.view.left) / 0x200 - fx / 0x200,
(gMC.y - gMC.view.top) / 0x200 - fy / 0x200 + arms_offset_y,
&gMC.rect_arms,
SURFACE_ID_ARMS);
if ((gMC.shock / 2) % 2)
return;
if (!((gMC.shock >> 1) & 1))
{
// Draw player
RECT rect = gMC.rect;
if (gMC.equip & 0x40)
@ -233,18 +235,15 @@ void PutMyChar(int fx, int fy)
++gMC.bubble;
if (gMC.equip & 0x10 && gMC.flag & 0x100)
PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble >> 1) & 1], SURFACE_ID_CARET);
PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble / 2) % 2], SURFACE_ID_CARET);
else if (gMC.unit == 1)
PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble >> 1) & 1], SURFACE_ID_CARET);
}
}
PutBitmap3(&grcGame, gMC.x / 0x200 - 12 - fx / 0x200, gMC.y / 0x200 - 12 - fy / 0x200, &rcBubble[(gMC.bubble / 2) % 2], SURFACE_ID_CARET);
}
void ActMyChar_Normal(bool bKey)
{
if (!(gMC.cond & 2))
void ActMyChar_Normal(BOOL bKey)
{
// Get speeds and accelerations
int max_move; // Unused
int max_dash;
int gravity1;
int gravity2;
@ -253,9 +252,16 @@ void ActMyChar_Normal(bool bKey)
int dash2;
int resist;
int a;
int x;
if (gMC.cond & 2)
return;
if (gMC.flag & 0x100)
{
max_dash = 0x196;
max_move = 0x2FF;
gravity1 = 0x28;
gravity2 = 0x10;
jump = 0x280;
@ -266,6 +272,7 @@ void ActMyChar_Normal(bool bKey)
else
{
max_dash = 0x32C;
max_move = 0x5FF;
gravity1 = 0x50;
gravity2 = 0x20;
jump = 0x500;
@ -303,9 +310,16 @@ void ActMyChar_Normal(bool bKey)
// Move in direction held
if (bKey)
{
if (gKeyTrg != gKeyDown || gKey != gKeyDown || (gMC.cond & 1) || g_GameFlags & 4)
if (gKeyTrg == gKeyDown && gKey == gKeyDown && (gMC.cond & 1) == 0 && (g_GameFlags & 4) == 0)
{
if (gKey != gKeyDown)
gMC.cond |= 1;
gMC.ques = 1;
}
else if (gKey == gKeyDown)
{
}
else
{
if (gKey & gKeyLeft && gMC.xm > -max_dash)
gMC.xm -= dash1;
@ -318,29 +332,23 @@ void ActMyChar_Normal(bool bKey)
gMC.direct = 2;
}
}
else
{
gMC.cond |= 1;
gMC.ques = 1;
}
}
// Friction
if (!(gMC.cond & 0x20))
{
if (gMC.xm < 0)
{
if (gMC.xm <= -resist)
gMC.xm += resist;
else
if (gMC.xm > -resist)
gMC.xm = 0;
else
gMC.xm += resist;
}
if (gMC.xm > 0)
{
if (gMC.xm >= resist)
gMC.xm -= resist;
else
if (gMC.xm < resist)
gMC.xm = 0;
else
gMC.xm -= resist;
}
}
}
@ -425,17 +433,30 @@ void ActMyChar_Normal(bool bKey)
if (bKey)
{
// Look up and down
gMC.up = (gKey & gKeyUp) != 0;
gMC.down = gKey & gKeyDown && !(gMC.flag & 8);
if (gKey & gKeyUp)
gMC.up = TRUE;
else
gMC.up = FALSE;
if (gKey & gKeyDown && (gMC.flag & 8) == 0)
gMC.down = TRUE;
else
gMC.down = FALSE;
if (gKeyTrg & gKeyJump
&& (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20)
&& !(gMC.flag & 0x2000))
&& (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20))
{
if (gMC.flag & 0x2000)
{
// Another weird empty case needed for accurate assembly
}
else
{
gMC.ym = -jump;
PlaySoundObject(15, 1);
}
}
}
// Stop interacting when moved
if (bKey && (gKeyShot | gKeyJump | gKeyUp | gKeyRight | gKeyLeft) & gKey)
@ -533,7 +554,7 @@ void ActMyChar_Normal(bool bKey)
}
// Keep player on slopes
if (bKey && !(gKeyTrg & gKeyJump))
if (!bKey || !(gKeyTrg & gKeyJump))
{
if (gMC.flag & 0x10 && gMC.xm < 0)
gMC.ym = -gMC.xm;
@ -547,19 +568,15 @@ void ActMyChar_Normal(bool bKey)
gMC.ym = 0x400;
}
// Limit speed
if (!(gMC.flag & 0x100) || gMC.flag & 0xF000)
if (0)
{
if (gMC.xm < -0x5FF)
gMC.xm = -0x5FF;
if (gMC.xm > 0x5FF)
gMC.xm = 0x5FF;
if (gMC.ym < -0x5FF)
gMC.ym = -0x5FF;
if (gMC.ym > 0x5FF)
gMC.ym = 0x5FF;
// There used to be an if here that didn't do anything, but the compiler optimised it out.
// We only know this was here because empty ifs mess with the register usage.
// Since there's no code, we have no idea what the original condition actually was.
}
else
// Limit speed
if ((gMC.flag & 0x100) && (gMC.flag & 0xF000) == 0)
{
if (gMC.xm < -0x2FF)
gMC.xm = -0x2FF;
@ -570,6 +587,17 @@ void ActMyChar_Normal(bool bKey)
if (gMC.ym > 0x2FF)
gMC.ym = 0x2FF;
}
else
{
if (gMC.xm < -0x5FF)
gMC.xm = -0x5FF;
if (gMC.xm > 0x5FF)
gMC.xm = 0x5FF;
if (gMC.ym < -0x5FF)
gMC.ym = -0x5FF;
if (gMC.ym > 0x5FF)
gMC.ym = 0x5FF;
}
// Water splashing
if (!gMC.sprash && gMC.flag & 0x100)
@ -580,23 +608,29 @@ void ActMyChar_Normal(bool bKey)
else
dir = 0;
if (gMC.flag & 8 || gMC.ym <= 0x200)
if ((gMC.flag & 8) == 0 && gMC.ym > 0x200)
{
if (gMC.xm > 0x200 || gMC.xm < -0x200)
for (a = 0; a < 8; a++)
{
for (int a = 0; a < 8; a++)
SetNpChar(73, gMC.x + (Random(-8, 8) << 9), gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80), dir, 0, 0);
x = gMC.x + (Random(-8, 8) * 0x200);
SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80) - gMC.ym / 2, dir, 0, 0);
}
PlaySoundObject(56, 1);
}
}
else
{
for (int a = 0; a < 8; a++)
SetNpChar(73, gMC.x + (Random(-8, 8) << 9), gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80) - gMC.ym / 2, dir, 0, 0);
if (gMC.xm > 0x200 || gMC.xm < -0x200)
{
for (a = 0; a < 8; a++)
{
x = gMC.x + (Random(-8, 8) * 0x200);
SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80), dir, 0, 0);
}
PlaySoundObject(56, 1);
}
}
gMC.sprash = 1;
}
@ -609,18 +643,18 @@ void ActMyChar_Normal(bool bKey)
DamageMyChar(10);
// Camera
if (gMC.direct)
{
gMC.index_x += 0x200;
if (gMC.index_x > 0x8000)
gMC.index_x = 0x8000;
}
else
if (gMC.direct == 0)
{
gMC.index_x -= 0x200;
if (gMC.index_x < -0x8000)
gMC.index_x = -0x8000;
}
else
{
gMC.index_x += 0x200;
if (gMC.index_x > 0x8000)
gMC.index_x = 0x8000;
}
if (gKey & gKeyUp && bKey)
{
gMC.index_y -= 0x200;
@ -645,16 +679,22 @@ void ActMyChar_Normal(bool bKey)
gMC.tgt_y = gMC.y + gMC.index_y;
// Change position
if (gMC.xm > resist || gMC.xm < -resist)
gMC.x += gMC.xm;
gMC.y += gMC.ym;
if (gMC.xm <= resist && gMC.xm >= -resist)
{
// Okay, this is getting stupid. Why the HELL is the code written like this?
}
else
{
gMC.x += gMC.xm;
}
void ActMyChar_Stream(bool bKey)
gMC.y += gMC.ym;
}
void ActMyChar_Stream(BOOL bKey)
{
gMC.up = false;
gMC.down = false;
gMC.up = FALSE;
gMC.down = FALSE;
if (bKey)
{
@ -666,17 +706,18 @@ void ActMyChar_Stream(bool bKey)
if (gKey & gKeyRight)
gMC.xm += 0x100;
}
else if (gMC.xm > 0x7F || gMC.xm < -0x7F)
{
if (gMC.xm > 0)
gMC.xm -= 0x80;
else if (gMC.xm < 0)
gMC.xm += 0x80;
}
else
else if (gMC.xm < 0x80 && gMC.xm > -0x80)
{
gMC.xm = 0;
}
else if (gMC.xm > 0)
{
gMC.xm -= 0x80;
}
else if (gMC.xm < 0)
{
gMC.xm += 0x80;
}
if (gKey & (gKeyDown | gKeyUp))
{
@ -686,44 +727,35 @@ void ActMyChar_Stream(bool bKey)
if (gKey & gKeyDown)
gMC.ym += 0x100;
}
else if (gMC.ym > 0x7F || gMC.ym < -0x7F)
{
if (gMC.ym > 0)
gMC.ym -= 0x80;
else if (gMC.ym < 0)
gMC.ym += 0x80;
}
else
else if (gMC.ym < 0x80 && gMC.ym > -0x80)
{
gMC.ym = 0;
}
else if (gMC.ym > 0)
{
gMC.ym -= 0x80;
}
else if (gMC.ym < 0)
{
gMC.ym += 0x80;
}
}
else
{
if (gMC.xm > 0x7F || gMC.xm < -0x3F)
{
if (gMC.xm > 0)
if (gMC.xm < 0x80 && gMC.xm > -0x40)
gMC.xm = 0;
else if (gMC.xm > 0)
gMC.xm -= 0x80;
else if (gMC.xm < 0)
gMC.xm += 0x80;
}
else
{
gMC.xm = 0;
}
if (gMC.ym > 0x7F || gMC.ym < -0x3F)
{
if (gMC.ym > 0)
if (gMC.ym < 0x80 && gMC.ym > -0x40)
gMC.ym = 0;
else if (gMC.ym > 0)
gMC.ym -= 0x80;
else if (gMC.ym < 0)
gMC.ym += 0x80;
}
else
{
gMC.ym = 0;
}
}
if (gMC.ym < -0x200 && gMC.flag & 2)
SetCaret(gMC.x, gMC.y - gMC.hit.top, 13, 5);
@ -785,7 +817,11 @@ void AirProcess()
}
else
{
if (gMC.flag & 0x100)
if ((gMC.flag & 0x100) == 0)
{
gMC.air = 1000;
}
else
{
if (--gMC.air <= 0)
{
@ -799,19 +835,15 @@ void AirProcess()
// Drown
StartTextScript(41);
if (gMC.direct)
SetCaret(gMC.x, gMC.y, 8, 2);
else
if (gMC.direct == 0)
SetCaret(gMC.x, gMC.y, 8, 0);
else
SetCaret(gMC.x, gMC.y, 8, 2);
gMC.cond &= ~0x80;
}
}
}
else
{
gMC.air = 1000;
}
if (gMC.flag & 0x100)
{
@ -824,10 +856,11 @@ void AirProcess()
}
}
void ActMyChar(bool bKey)
{
if (gMC.cond & 0x80)
void ActMyChar(BOOL bKey)
{
if ((gMC.cond & 0x80) == 0)
return;
if (gMC.exp_wait)
--gMC.exp_wait;
@ -852,14 +885,10 @@ void ActMyChar(bool bKey)
case 1:
ActMyChar_Stream(bKey);
break;
default:
break;
}
gMC.cond &= ~0x20;
}
}
void GetMyCharPosition(int *x, int *y)
{
@ -871,8 +900,8 @@ void SetMyCharPosition(int x, int y)
{
gMC.x = x;
gMC.y = y;
gMC.tgt_x = x;
gMC.tgt_y = y;
gMC.tgt_x = gMC.x;
gMC.tgt_y = gMC.y;
gMC.index_x = 0;
gMC.index_y = 0;
gMC.xm = 0;
@ -897,42 +926,41 @@ int GetUnitMyChar()
return gMC.unit;
}
void SetMyCharDirect(uint8_t dir)
void SetMyCharDirect(unsigned char dir)
{
switch (dir)
if (dir == 3)
{
case 3:
gMC.cond |= 1;
break;
default:
}
else
{
gMC.cond &= ~1;
if (dir < 10)
{
gMC.direct = dir;
break;
}
for (int i = 0; i < NPC_MAX; i++)
{
if (gNPC[i].code_event == dir)
{
if (gMC.x <= gNPC[i].x)
gMC.direct = 2;
else
{
for (int i = 0; i < NPC_MAX; i++)
if (gNPC[i].code_event == dir)
break;
if (i == NPC_MAX)
return;
if (gMC.x > gNPC[i].x)
gMC.direct = 0;
break;
else
gMC.direct = 2;
}
}
break;
}
gMC.xm = 0;
AnimationMyChar(false);
AnimationMyChar(FALSE);
}
void ChangeMyUnit(uint8_t a)
void ChangeMyUnit(unsigned char a)
{
gMC.unit = a;
}
@ -942,7 +970,7 @@ void PitMyChar()
gMC.y += 0x4000;
}
void EquipItem(int flag, bool b)
void EquipItem(int flag, BOOL b)
{
if (b)
gMC.equip |= flag;
@ -960,16 +988,18 @@ void SetNoise(int no, int freq)
noise_freq = freq;
noise_no = no;
if (no == 1)
switch (noise_no)
{
case 1:
ChangeSoundFrequency(40, noise_freq);
ChangeSoundFrequency(41, noise_freq + 100);
PlaySoundObject(40, -1);
PlaySoundObject(41, -1);
}
else if (no == 2)
{
break;
case 2:
PlaySoundObject(58, -1);
break;
}
}
@ -983,16 +1013,18 @@ void CutNoise()
void ResetNoise()
{
if (noise_no == 1)
switch (noise_no)
{
case 1:
ChangeSoundFrequency(40, noise_freq);
ChangeSoundFrequency(41, noise_freq + 100);
PlaySoundObject(40, -1);
PlaySoundObject(41, -1);
}
else if (noise_no == 2)
{
break;
case 2:
PlaySoundObject(58, -1);
break;
}
}

View file

@ -6,11 +6,11 @@
struct MYCHAR
{
uint8_t cond;
unsigned char cond;
unsigned int flag;
int direct;
int up;
int down;
BOOL up;
BOOL down;
int unit;
int equip;
int x;
@ -30,41 +30,41 @@ struct MYCHAR
int level;
int exp_wait;
int exp_count;
uint8_t shock;
uint8_t no_life;
uint8_t rensha;
uint8_t bubble;
int16_t life;
int16_t star;
int16_t max_life;
int16_t a;
unsigned char shock;
unsigned char no_life;
unsigned char rensha;
unsigned char bubble;
short life;
short star;
short max_life;
short a;
int lifeBr;
int lifeBr_count;
int air;
int air_get;
int8_t sprash;
int8_t ques;
int8_t boost_sw;
signed char sprash;
signed char ques;
signed char boost_sw;
int boost_cnt;
};
extern MYCHAR gMC;
void InitMyChar();
void AnimationMyChar(bool bKey);
void ShowMyChar(bool bShow);
void AnimationMyChar(BOOL bKey);
void ShowMyChar(BOOL bShow);
void PutMyChar(int fx, int fy);
void ActMyChar_Normal(bool bKey);
void ActMyChar(bool bKey);
void ActMyChar_Normal(BOOL bKey);
void ActMyChar(BOOL bKey);
void GetMyCharPosition(int *x, int *y);
void SetMyCharPosition(int x, int y);
void MoveMyChar(int x, int y);
void ZeroMyCharXMove();
int GetUnitMyChar();
void SetMyCharDirect(uint8_t dir);
void ChangeMyUnit(uint8_t a);
void SetMyCharDirect(unsigned char dir);
void ChangeMyUnit(unsigned char a);
void PitMyChar();
void EquipItem(int flag, bool b);
void EquipItem(int flag, BOOL b);
void ResetCheck();
void SetNoise(int no, int freq);
void CutNoise();