ref: f04872b91bf98edcce130faf9756e1fc71eb2ede
parent: d4d82d0ba8f15bef00b3a3b8b0d50f10f7fb7fa8
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon May 13 10:17:03 EDT 2019
Made MyChar.cpp ASM-accurate See #74
--- a/msvc2003/devilution/comparer-config.toml
+++ b/msvc2003/devilution/comparer-config.toml
@@ -516,6 +516,94 @@
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
--- a/src/MyChar.cpp
+++ b/src/MyChar.cpp
@@ -44,7 +44,7 @@
gMC.unit = 0;
}
-void AnimationMyChar(bool bKey)
+void AnimationMyChar(BOOL bKey)
{
RECT rcLeft[12] = {
{0, 0, 16, 16},
@@ -76,84 +76,83 @@
{112, 16, 128, 32},
};
- if (!(gMC.cond & 2))
+ if (gMC.cond & 2)
+ return;
+
+ if (gMC.flag & 8)
{
- if (gMC.flag & 8)
+ if (gMC.cond & 1)
{
- if (gMC.cond & 1)
+ gMC.ani_no = 11;
+ }
+ else if (gKey & gKeyUp && (gKeyRight | gKeyLeft) & gKey && bKey)
+ {
+ gMC.cond |= 4;
+
+ if (++gMC.ani_wait > 4)
{
- gMC.ani_no = 11;
+ gMC.ani_wait = 0;
+ if (++gMC.ani_no == 7 || gMC.ani_no == 9)
+ PlaySoundObject(24, 1);
}
- else if (gKey & gKeyUp && (gKeyRight | gKeyLeft) & gKey && bKey)
- {
- gMC.cond |= 4;
- if (++gMC.ani_wait > 4)
- {
- gMC.ani_wait = 0;
- if (++gMC.ani_no == 7 || gMC.ani_no == 9)
- PlaySoundObject(24, 1);
- }
+ if (gMC.ani_no > 9 || gMC.ani_no < 6)
+ gMC.ani_no = 6;
+ }
+ else if ((gKeyRight | gKeyLeft) & gKey && bKey)
+ {
+ gMC.cond |= 4;
- if (gMC.ani_no > 9 || gMC.ani_no < 6)
- gMC.ani_no = 6;
- }
- else if ((gKeyRight | gKeyLeft) & gKey && bKey)
+ if (++gMC.ani_wait > 4)
{
- gMC.cond |= 4;
-
- if (++gMC.ani_wait > 4)
- {
- gMC.ani_wait = 0;
- if (++gMC.ani_no == 2 || gMC.ani_no == 4)
- PlaySoundObject(24, 1);
- }
-
- if (gMC.ani_no > 4 || gMC.ani_no < 1)
- gMC.ani_no = 1;
- }
- else if (gKey & gKeyUp && bKey)
- {
- if (gMC.cond & 4)
+ gMC.ani_wait = 0;
+ if (++gMC.ani_no == 2 || gMC.ani_no == 4)
PlaySoundObject(24, 1);
-
- gMC.cond &= ~4;
- gMC.ani_no = 5;
}
- else
- {
- if (gMC.cond & 4)
- PlaySoundObject(24, 1);
- gMC.cond &= ~4;
- gMC.ani_no = 0;
- }
+ if (gMC.ani_no > 4 || gMC.ani_no < 1)
+ gMC.ani_no = 1;
}
- else if (gMC.up)
+ else if (gKey & gKeyUp && bKey)
{
- gMC.ani_no = 6;
+ if (gMC.cond & 4)
+ PlaySoundObject(24, 1);
+
+ gMC.cond &= ~4;
+ gMC.ani_no = 5;
}
- else if (gMC.down)
- {
- gMC.ani_no = 10;
- }
- else if (gMC.ym <= 0)
- {
- gMC.ani_no = 3;
- }
else
{
- gMC.ani_no = 1;
- }
+ if (gMC.cond & 4)
+ PlaySoundObject(24, 1);
- if (gMC.direct)
- gMC.rect = rcRight[gMC.ani_no];
+ gMC.cond &= ~4;
+ gMC.ani_no = 0;
+ }
+ }
+ else if (gMC.up)
+ {
+ gMC.ani_no = 6;
+ }
+ else if (gMC.down)
+ {
+ gMC.ani_no = 10;
+ }
+ else
+ {
+ if (gMC.ym > 0)
+ gMC.ani_no = 1;
else
- gMC.rect = rcLeft[gMC.ani_no];
+ gMC.ani_no = 3;
}
+
+ 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,498 +162,539 @@
void PutMyChar(int fx, int fy)
{
- if ((gMC.cond & 0x80) && !(gMC.cond & 2))
- {
- // Draw weapon
- gMC.rect_arms.left = 24 * (gArmsData[gSelectedArms].code % 13);
- gMC.rect_arms.right = gMC.rect_arms.left + 24;
- gMC.rect_arms.top = 96 * (gArmsData[gSelectedArms].code / 13);
- gMC.rect_arms.bottom = gMC.rect_arms.top + 16;
+ int arms_offset_y;
- if (gMC.direct == 2)
- {
- gMC.rect_arms.top += 16;
- gMC.rect_arms.bottom += 16;
- }
+ if ((gMC.cond & 0x80) == 0 || (gMC.cond & 2))
+ return;
- int arms_offset_y;
- if (gMC.up)
- {
- arms_offset_y = -4;
- gMC.rect_arms.top += 32;
- gMC.rect_arms.bottom += 32;
- }
- else if (gMC.down)
- {
- arms_offset_y = 4;
- gMC.rect_arms.top += 64;
- gMC.rect_arms.bottom += 64;
- }
- else
- {
- arms_offset_y = 0;
- }
+ // Draw weapon
+ gMC.rect_arms.left = 24 * (gArmsData[gSelectedArms].code % 13);
+ gMC.rect_arms.right = gMC.rect_arms.left + 24;
+ gMC.rect_arms.top = 96 * (gArmsData[gSelectedArms].code / 13);
+ gMC.rect_arms.bottom = gMC.rect_arms.top + 16;
- if (gMC.ani_no == 1 || gMC.ani_no == 3 || gMC.ani_no == 6 || gMC.ani_no == 8)
- ++gMC.rect_arms.top;
+ if (gMC.direct == 2)
+ {
+ gMC.rect_arms.top += 16;
+ gMC.rect_arms.bottom += 16;
+ }
- 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
- 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);
+ if (gMC.up)
+ {
+ arms_offset_y = -4;
+ gMC.rect_arms.top += 32;
+ gMC.rect_arms.bottom += 32;
+ }
+ else if (gMC.down)
+ {
+ arms_offset_y = 4;
+ gMC.rect_arms.top += 64;
+ gMC.rect_arms.bottom += 64;
+ }
+ else
+ {
+ arms_offset_y = 0;
+ }
- if (!((gMC.shock >> 1) & 1))
- {
- // Draw player
- RECT rect = gMC.rect;
- if (gMC.equip & 0x40)
- {
- rect.top += 32;
- rect.bottom += 32;
- }
+ if (gMC.ani_no == 1 || gMC.ani_no == 3 || gMC.ani_no == 6 || gMC.ani_no == 8)
+ ++gMC.rect_arms.top;
- PutBitmap3(&grcGame, (gMC.x - gMC.view.left) / 0x200 - fx / 0x200, (gMC.y - gMC.view.top) / 0x200 - fy / 0x200, &rect, SURFACE_ID_MY_CHAR);
+ 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);
- // Draw air tank
- RECT rcBubble[2] = {
- {56, 96, 80, 120},
- {80, 96, 104, 120},
- };
+ if ((gMC.shock / 2) % 2)
+ return;
- ++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);
- 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);
- }
+ // Draw player
+ RECT rect = gMC.rect;
+ if (gMC.equip & 0x40)
+ {
+ rect.top += 32;
+ rect.bottom += 32;
}
+
+ PutBitmap3(&grcGame, (gMC.x - gMC.view.left) / 0x200 - fx / 0x200, (gMC.y - gMC.view.top) / 0x200 - fy / 0x200, &rect, SURFACE_ID_MY_CHAR);
+
+ // Draw air tank
+ RECT rcBubble[2] = {
+ {56, 96, 80, 120},
+ {80, 96, 104, 120},
+ };
+
+ ++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 / 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 / 2) % 2], SURFACE_ID_CARET);
}
-void ActMyChar_Normal(bool bKey)
+void ActMyChar_Normal(BOOL bKey)
{
- if (!(gMC.cond & 2))
+ // Get speeds and accelerations
+ int max_move; // Unused
+ int max_dash;
+ int gravity1;
+ int gravity2;
+ int jump;
+ int dash1;
+ int dash2;
+ int resist;
+
+ int a;
+ int x;
+
+ if (gMC.cond & 2)
+ return;
+
+ if (gMC.flag & 0x100)
{
- // Get speeds and accelerations
- int max_dash;
- int gravity1;
- int gravity2;
- int jump;
- int dash1;
- int dash2;
- int resist;
+ max_dash = 0x196;
+ max_move = 0x2FF;
+ gravity1 = 0x28;
+ gravity2 = 0x10;
+ jump = 0x280;
+ dash1 = 0x2A;
+ dash2 = 0x10;
+ resist = 0x19;
+ }
+ else
+ {
+ max_dash = 0x32C;
+ max_move = 0x5FF;
+ gravity1 = 0x50;
+ gravity2 = 0x20;
+ jump = 0x500;
+ dash1 = 0x55;
+ dash2 = 0x20;
+ resist = 0x33;
+ }
- if (gMC.flag & 0x100)
+ // Don't create "?" effect
+ gMC.ques = 0;
+
+ // If can't control player, stop boosting
+ if (!bKey)
+ gMC.boost_sw = 0;
+
+ // Movement on the ground
+ if (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20)
+ {
+ // Stop boosting and refuel
+ gMC.boost_sw = 0;
+
+ if (gMC.equip & 1)
{
- max_dash = 0x196;
- gravity1 = 0x28;
- gravity2 = 0x10;
- jump = 0x280;
- dash1 = 0x2A;
- dash2 = 0x10;
- resist = 0x19;
+ gMC.boost_cnt = 50;
}
+ else if (gMC.equip & 0x20)
+ {
+ gMC.boost_cnt = 50;
+ }
else
{
- max_dash = 0x32C;
- gravity1 = 0x50;
- gravity2 = 0x20;
- jump = 0x500;
- dash1 = 0x55;
- dash2 = 0x20;
- resist = 0x33;
+ gMC.boost_cnt = 0;
}
- // Don't create "?" effect
- gMC.ques = 0;
-
- // If can't control player, stop boosting
- if (!bKey)
- gMC.boost_sw = 0;
-
- // Movement on the ground
- if (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20)
+ // Move in direction held
+ if (bKey)
{
- // Stop boosting and refuel
- gMC.boost_sw = 0;
-
- if (gMC.equip & 1)
+ if (gKeyTrg == gKeyDown && gKey == gKeyDown && (gMC.cond & 1) == 0 && (g_GameFlags & 4) == 0)
{
- gMC.boost_cnt = 50;
+ gMC.cond |= 1;
+ gMC.ques = 1;
}
- else if (gMC.equip & 0x20)
+ else if (gKey == gKeyDown)
{
- gMC.boost_cnt = 50;
+
}
else
{
- gMC.boost_cnt = 0;
+ if (gKey & gKeyLeft && gMC.xm > -max_dash)
+ gMC.xm -= dash1;
+ if (gKey & gKeyRight && gMC.xm < max_dash)
+ gMC.xm += dash1;
+
+ if (gKey & gKeyLeft)
+ gMC.direct = 0;
+ if (gKey & gKeyRight)
+ gMC.direct = 2;
}
+ }
- // Move in direction held
- if (bKey)
+ // Friction
+ if (!(gMC.cond & 0x20))
+ {
+ if (gMC.xm < 0)
{
- if (gKeyTrg != gKeyDown || gKey != gKeyDown || (gMC.cond & 1) || g_GameFlags & 4)
- {
- if (gKey != gKeyDown)
- {
- if (gKey & gKeyLeft && gMC.xm > -max_dash)
- gMC.xm -= dash1;
- if (gKey & gKeyRight && gMC.xm < max_dash)
- gMC.xm += dash1;
-
- if (gKey & gKeyLeft)
- gMC.direct = 0;
- if (gKey & gKeyRight)
- gMC.direct = 2;
- }
- }
+ if (gMC.xm > -resist)
+ gMC.xm = 0;
else
- {
- gMC.cond |= 1;
- gMC.ques = 1;
- }
+ gMC.xm += resist;
}
-
- // Friction
- if (!(gMC.cond & 0x20))
+ if (gMC.xm > 0)
{
- if (gMC.xm < 0)
- {
- if (gMC.xm <= -resist)
- gMC.xm += resist;
- else
- gMC.xm = 0;
- }
- if (gMC.xm > 0)
- {
- if (gMC.xm >= resist)
- gMC.xm -= resist;
- else
- gMC.xm = 0;
- }
+ if (gMC.xm < resist)
+ gMC.xm = 0;
+ else
+ gMC.xm -= resist;
}
}
- else
+ }
+ else
+ {
+ // Start boosting
+ if (bKey)
{
- // Start boosting
- if (bKey)
+ if (gMC.equip & 0x21 && gKeyTrg & gKeyJump && gMC.boost_cnt)
{
- if (gMC.equip & 0x21 && gKeyTrg & gKeyJump && gMC.boost_cnt)
+ // Booster 0.8
+ if (gMC.equip & 1)
{
- // Booster 0.8
- if (gMC.equip & 1)
+ gMC.boost_sw = 1;
+ if (gMC.ym > 0x100)
+ gMC.ym /= 2;
+ }
+
+ // Booster 2.0
+ if (gMC.equip & 0x20)
+ {
+ if (gKey & gKeyUp)
{
+ gMC.boost_sw = 2;
+ gMC.xm = 0;
+ gMC.ym = -0x5FF;
+ }
+ else if (gKey & gKeyLeft)
+ {
gMC.boost_sw = 1;
- if (gMC.ym > 0x100)
- gMC.ym /= 2;
+ gMC.ym = 0;
+ gMC.xm = -0x5FF;
}
-
- // Booster 2.0
- if (gMC.equip & 0x20)
+ else if (gKey & gKeyRight)
{
- if (gKey & gKeyUp)
- {
- gMC.boost_sw = 2;
- gMC.xm = 0;
- gMC.ym = -0x5FF;
- }
- else if (gKey & gKeyLeft)
- {
- gMC.boost_sw = 1;
- gMC.ym = 0;
- gMC.xm = -0x5FF;
- }
- else if (gKey & gKeyRight)
- {
- gMC.boost_sw = 1;
- gMC.ym = 0;
- gMC.xm = 0x5FF;
- }
- else if (gKey & gKeyDown)
- {
- gMC.boost_sw = 3;
- gMC.xm = 0;
- gMC.ym = 0x5FF;
- }
- else
- {
- gMC.boost_sw = 2;
- gMC.xm = 0;
- gMC.ym = -0x5FF;
- }
+ gMC.boost_sw = 1;
+ gMC.ym = 0;
+ gMC.xm = 0x5FF;
}
+ else if (gKey & gKeyDown)
+ {
+ gMC.boost_sw = 3;
+ gMC.xm = 0;
+ gMC.ym = 0x5FF;
+ }
+ else
+ {
+ gMC.boost_sw = 2;
+ gMC.xm = 0;
+ gMC.ym = -0x5FF;
+ }
}
-
- // Move left and right
- if (gKey & gKeyLeft && gMC.xm > -max_dash)
- gMC.xm -= dash2;
- if (gKey & gKeyRight && gMC.xm < max_dash)
- gMC.xm += dash2;
-
- if (gKey & gKeyLeft)
- gMC.direct = 0;
- if (gKey & gKeyRight)
- gMC.direct = 2;
}
- // Slow down when stopped boosting (Booster 2.0)
- if (gMC.equip & 0x20 && gMC.boost_sw && (!(gKey & gKeyJump) || !gMC.boost_cnt))
- {
- if (gMC.boost_sw == 1)
- gMC.xm /= 2;
- else if (gMC.boost_sw == 2)
- gMC.ym /= 2;
- }
+ // Move left and right
+ if (gKey & gKeyLeft && gMC.xm > -max_dash)
+ gMC.xm -= dash2;
+ if (gKey & gKeyRight && gMC.xm < max_dash)
+ gMC.xm += dash2;
- // Stop boosting
- if (!gMC.boost_cnt || !(gKey & gKeyJump))
- gMC.boost_sw = 0;
+ if (gKey & gKeyLeft)
+ gMC.direct = 0;
+ if (gKey & gKeyRight)
+ gMC.direct = 2;
}
- // Jumping
- if (bKey)
+ // Slow down when stopped boosting (Booster 2.0)
+ if (gMC.equip & 0x20 && gMC.boost_sw && (!(gKey & gKeyJump) || !gMC.boost_cnt))
{
- // Look up and down
- gMC.up = (gKey & gKeyUp) != 0;
- gMC.down = gKey & gKeyDown && !(gMC.flag & 8);
+ if (gMC.boost_sw == 1)
+ gMC.xm /= 2;
+ else if (gMC.boost_sw == 2)
+ gMC.ym /= 2;
+ }
- if (gKeyTrg & gKeyJump
- && (gMC.flag & 8 || gMC.flag & 0x10 || gMC.flag & 0x20)
- && !(gMC.flag & 0x2000))
+ // Stop boosting
+ if (!gMC.boost_cnt || !(gKey & gKeyJump))
+ gMC.boost_sw = 0;
+ }
+
+ // Jumping
+ if (bKey)
+ {
+ // Look up and down
+ 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))
+ {
+ 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)
- gMC.cond &= ~1;
+ // Stop interacting when moved
+ if (bKey && (gKeyShot | gKeyJump | gKeyUp | gKeyRight | gKeyLeft) & gKey)
+ gMC.cond &= ~1;
- // Booster losing fuel
- if (gMC.boost_sw && gMC.boost_cnt)
- --gMC.boost_cnt;
+ // Booster losing fuel
+ if (gMC.boost_sw && gMC.boost_cnt)
+ --gMC.boost_cnt;
- // Wind / current forces
- if (gMC.flag & 0x1000)
- gMC.xm -= 0x88;
- if (gMC.flag & 0x2000)
- gMC.ym -= 0x80;
- if (gMC.flag & 0x4000)
- gMC.xm += 0x88;
- if (gMC.flag & 0x8000)
- gMC.ym += 0x55;
+ // Wind / current forces
+ if (gMC.flag & 0x1000)
+ gMC.xm -= 0x88;
+ if (gMC.flag & 0x2000)
+ gMC.ym -= 0x80;
+ if (gMC.flag & 0x4000)
+ gMC.xm += 0x88;
+ if (gMC.flag & 0x8000)
+ gMC.ym += 0x55;
- // Booster 2.0 forces and effects
- if (gMC.equip & 0x20 && gMC.boost_sw)
+ // Booster 2.0 forces and effects
+ if (gMC.equip & 0x20 && gMC.boost_sw)
+ {
+ if (gMC.boost_sw == 1)
{
- if (gMC.boost_sw == 1)
- {
- // Go up when going into a wall
- if (gMC.flag & 5)
- gMC.ym = -0x100;
+ // Go up when going into a wall
+ if (gMC.flag & 5)
+ gMC.ym = -0x100;
- // Move in direction facing
+ // Move in direction facing
+ if (!gMC.direct)
+ gMC.xm -= 0x20;
+ if (gMC.direct == 2)
+ gMC.xm += 0x20;
+
+ // Boost particles (and sound)
+ if (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1)
+ {
if (!gMC.direct)
- gMC.xm -= 0x20;
+ SetCaret(gMC.x + 0x400, gMC.y + 0x400, 7, 2);
if (gMC.direct == 2)
- gMC.xm += 0x20;
+ SetCaret(gMC.x - 0x400, gMC.y + 0x400, 7, 0);
- // Boost particles (and sound)
- if (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1)
- {
- if (!gMC.direct)
- SetCaret(gMC.x + 0x400, gMC.y + 0x400, 7, 2);
- if (gMC.direct == 2)
- SetCaret(gMC.x - 0x400, gMC.y + 0x400, 7, 0);
-
- PlaySoundObject(113, 1);
- }
- }
- else if (gMC.boost_sw == 2)
- {
- // Move upwards
- gMC.ym -= 0x20;
-
- // Boost particles (and sound)
- if (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1)
- {
- SetCaret(gMC.x, gMC.y + 0xC00, 7, 3);
- PlaySoundObject(113, 1);
- }
- }
- else if (gMC.boost_sw == 3 && (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1))
- {
- // Boost particles (and sound)
- SetCaret(gMC.x, gMC.y - 0xC00, 7, 1);
PlaySoundObject(113, 1);
}
}
- // Upwards wind/current
- else if (gMC.flag & 0x2000)
+ else if (gMC.boost_sw == 2)
{
- gMC.ym += gravity1;
- }
- // Booster 0.8
- else if (gMC.equip & 1 && gMC.boost_sw && gMC.ym > -0x400)
- {
- // Upwards force
+ // Move upwards
gMC.ym -= 0x20;
- if (!(gMC.boost_cnt % 3))
+ // Boost particles (and sound)
+ if (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1)
{
- SetCaret(gMC.x, gMC.hit.bottom / 2 + gMC.y, 7, 3);
+ SetCaret(gMC.x, gMC.y + 0xC00, 7, 3);
PlaySoundObject(113, 1);
}
-
- // Bounce off of ceiling
- if (gMC.flag & 2)
- gMC.ym = 0x200;
}
- // Gravity while jump is held
- else if (gMC.ym < 0 && bKey && gKey & gKeyJump)
+ else if (gMC.boost_sw == 3 && (gKeyTrg & gKeyJump || gMC.boost_cnt % 3 == 1))
{
- gMC.ym += gravity2;
+ // Boost particles (and sound)
+ SetCaret(gMC.x, gMC.y - 0xC00, 7, 1);
+ PlaySoundObject(113, 1);
}
- // Normal gravity
- else
- {
- gMC.ym += gravity1;
- }
+ }
+ // Upwards wind/current
+ else if (gMC.flag & 0x2000)
+ {
+ gMC.ym += gravity1;
+ }
+ // Booster 0.8
+ else if (gMC.equip & 1 && gMC.boost_sw && gMC.ym > -0x400)
+ {
+ // Upwards force
+ gMC.ym -= 0x20;
- // Keep player on slopes
- if (bKey && !(gKeyTrg & gKeyJump))
+ if (!(gMC.boost_cnt % 3))
{
- if (gMC.flag & 0x10 && gMC.xm < 0)
- gMC.ym = -gMC.xm;
- if (gMC.flag & 0x20 && gMC.xm > 0)
- gMC.ym = gMC.xm;
- if (gMC.flag & 8 && gMC.flag & 0x80000 && gMC.xm < 0)
- gMC.ym = 0x400;
- if (gMC.flag & 8 && gMC.flag & 0x10000 && gMC.xm > 0)
- gMC.ym = 0x400;
- if (gMC.flag & 8 && gMC.flag & 0x20000 && gMC.flag & 0x40000)
- gMC.ym = 0x400;
+ SetCaret(gMC.x, gMC.hit.bottom / 2 + gMC.y, 7, 3);
+ PlaySoundObject(113, 1);
}
- // Limit speed
- if (!(gMC.flag & 0x100) || gMC.flag & 0xF000)
- {
- 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;
- }
+ // Bounce off of ceiling
+ if (gMC.flag & 2)
+ gMC.ym = 0x200;
+ }
+ // Gravity while jump is held
+ else if (gMC.ym < 0 && bKey && gKey & gKeyJump)
+ {
+ gMC.ym += gravity2;
+ }
+ // Normal gravity
+ else
+ {
+ gMC.ym += gravity1;
+ }
+
+ // Keep player on slopes
+ if (!bKey || !(gKeyTrg & gKeyJump))
+ {
+ if (gMC.flag & 0x10 && gMC.xm < 0)
+ gMC.ym = -gMC.xm;
+ if (gMC.flag & 0x20 && gMC.xm > 0)
+ gMC.ym = gMC.xm;
+ if (gMC.flag & 8 && gMC.flag & 0x80000 && gMC.xm < 0)
+ gMC.ym = 0x400;
+ if (gMC.flag & 8 && gMC.flag & 0x10000 && gMC.xm > 0)
+ gMC.ym = 0x400;
+ if (gMC.flag & 8 && gMC.flag & 0x20000 && gMC.flag & 0x40000)
+ gMC.ym = 0x400;
+ }
+
+ if (0)
+ {
+ // 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.
+ }
+
+ // Limit speed
+ if ((gMC.flag & 0x100) && (gMC.flag & 0xF000) == 0)
+ {
+ if (gMC.xm < -0x2FF)
+ gMC.xm = -0x2FF;
+ if (gMC.xm > 0x2FF)
+ gMC.xm = 0x2FF;
+ if (gMC.ym < -0x2FF)
+ gMC.ym = -0x2FF;
+ 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)
+ {
+ int dir;
+ if (gMC.flag & 0x800)
+ dir = 2;
else
- {
- if (gMC.xm < -0x2FF)
- gMC.xm = -0x2FF;
- if (gMC.xm > 0x2FF)
- gMC.xm = 0x2FF;
- if (gMC.ym < -0x2FF)
- gMC.ym = -0x2FF;
- if (gMC.ym > 0x2FF)
- gMC.ym = 0x2FF;
- }
+ dir = 0;
- // Water splashing
- if (!gMC.sprash && gMC.flag & 0x100)
+ if ((gMC.flag & 8) == 0 && gMC.ym > 0x200)
{
- int dir;
- if (gMC.flag & 0x800)
- dir = 2;
- else
- dir = 0;
+ 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) - gMC.ym / 2, dir, 0, 0);
+ }
- if (gMC.flag & 8 || gMC.ym <= 0x200)
+ PlaySoundObject(56, 1);
+ }
+ else
+ {
+ if (gMC.xm > 0x200 || gMC.xm < -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);
-
- PlaySoundObject(56, 1);
+ x = gMC.x + (Random(-8, 8) * 0x200);
+ SetNpChar(73, x, gMC.y, gMC.xm + Random(-0x200, 0x200), Random(-0x200, 0x80), dir, 0, 0);
}
- }
- 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);
PlaySoundObject(56, 1);
}
-
- gMC.sprash = 1;
}
- if (!(gMC.flag & 0x100))
- gMC.sprash = 0;
+ gMC.sprash = 1;
+ }
- // Spike damage
- if (gMC.flag & 0x400)
- DamageMyChar(10);
+ if (!(gMC.flag & 0x100))
+ gMC.sprash = 0;
- // Camera
- if (gMC.direct)
- {
- 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)
- {
+ // Spike damage
+ if (gMC.flag & 0x400)
+ DamageMyChar(10);
+
+ // Camera
+ 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;
+ if (gMC.index_y < -0x8000)
+ gMC.index_y = -0x8000;
+ }
+ else if (gKey & gKeyDown && bKey)
+ {
+ gMC.index_y += 0x200;
+ if (gMC.index_y > 0x8000)
+ gMC.index_y = 0x8000;
+ }
+ else
+ {
+ if (gMC.index_y > 0x200)
gMC.index_y -= 0x200;
- if (gMC.index_y < -0x8000)
- gMC.index_y = -0x8000;
- }
- else if (gKey & gKeyDown && bKey)
- {
+ if (gMC.index_y < -0x200)
gMC.index_y += 0x200;
- if (gMC.index_y > 0x8000)
- gMC.index_y = 0x8000;
- }
- else
- {
- if (gMC.index_y > 0x200)
- gMC.index_y -= 0x200;
- if (gMC.index_y < -0x200)
- gMC.index_y += 0x200;
- }
+ }
- gMC.tgt_x = gMC.x + gMC.index_x;
- gMC.tgt_y = gMC.y + gMC.index_y;
+ gMC.tgt_x = gMC.x + gMC.index_x;
+ 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;
+ // Change position
+ 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;
+ }
+
+ gMC.y += gMC.ym;
}
-void ActMyChar_Stream(bool bKey)
+void ActMyChar_Stream(BOOL bKey)
{
- gMC.up = false;
- gMC.down = false;
+ gMC.up = FALSE;
+ gMC.down = FALSE;
if (bKey)
{
@@ -666,17 +706,18 @@
if (gKey & gKeyRight)
gMC.xm += 0x100;
}
- else if (gMC.xm > 0x7F || gMC.xm < -0x7F)
+ else if (gMC.xm < 0x80 && gMC.xm > -0x80)
{
- if (gMC.xm > 0)
- gMC.xm -= 0x80;
- else if (gMC.xm < 0)
- gMC.xm += 0x80;
+ gMC.xm = 0;
}
- else
+ else if (gMC.xm > 0)
{
- gMC.xm = 0;
+ gMC.xm -= 0x80;
}
+ else if (gMC.xm < 0)
+ {
+ gMC.xm += 0x80;
+ }
if (gKey & (gKeyDown | gKeyUp))
{
@@ -686,43 +727,34 @@
if (gKey & gKeyDown)
gMC.ym += 0x100;
}
- else if (gMC.ym > 0x7F || gMC.ym < -0x7F)
+ else if (gMC.ym < 0x80 && gMC.ym > -0x80)
{
- if (gMC.ym > 0)
- gMC.ym -= 0x80;
- else if (gMC.ym < 0)
- gMC.ym += 0x80;
+ gMC.ym = 0;
}
- else
+ else if (gMC.ym > 0)
{
- 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)
- gMC.xm -= 0x80;
- else if (gMC.xm < 0)
- gMC.xm += 0x80;
- }
- else
- {
+ 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;
- if (gMC.ym > 0x7F || gMC.ym < -0x3F)
- {
- if (gMC.ym > 0)
- gMC.ym -= 0x80;
- else if (gMC.ym < 0)
- gMC.ym += 0x80;
- }
- else
- {
+ 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;
}
if (gMC.ym < -0x200 && gMC.flag & 2)
@@ -785,8 +817,12 @@
}
else
{
- if (gMC.flag & 0x100)
+ if ((gMC.flag & 0x100) == 0)
{
+ gMC.air = 1000;
+ }
+ else
+ {
if (--gMC.air <= 0)
{
if (GetNPCFlag(4000))
@@ -799,19 +835,15 @@
// 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,41 +856,38 @@
}
}
-void ActMyChar(bool bKey)
+void ActMyChar(BOOL bKey)
{
- if (gMC.cond & 0x80)
- {
- if (gMC.exp_wait)
- --gMC.exp_wait;
+ if ((gMC.cond & 0x80) == 0)
+ return;
- if (gMC.shock)
- {
- --gMC.shock;
- }
- else if (gMC.exp_count)
- {
- SetValueView(&gMC.x, &gMC.y, gMC.exp_count);
- gMC.exp_count = 0;
- }
+ if (gMC.exp_wait)
+ --gMC.exp_wait;
- switch (gMC.unit)
- {
- case 0:
- if (!(g_GameFlags & 4) && bKey)
- AirProcess();
- ActMyChar_Normal(bKey);
- break;
+ if (gMC.shock)
+ {
+ --gMC.shock;
+ }
+ else if (gMC.exp_count)
+ {
+ SetValueView(&gMC.x, &gMC.y, gMC.exp_count);
+ gMC.exp_count = 0;
+ }
- case 1:
- ActMyChar_Stream(bKey);
- break;
+ switch (gMC.unit)
+ {
+ case 0:
+ if (!(g_GameFlags & 4) && bKey)
+ AirProcess();
+ ActMyChar_Normal(bKey);
+ break;
- default:
- break;
- }
-
- gMC.cond &= ~0x20;
+ case 1:
+ ActMyChar_Stream(bKey);
+ break;
}
+
+ gMC.cond &= ~0x20;
}
void GetMyCharPosition(int *x, int *y)
@@ -871,8 +900,8 @@
{
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 @@
return gMC.unit;
}
-void SetMyCharDirect(uint8_t dir)
+void SetMyCharDirect(unsigned char dir)
{
- switch (dir)
+ if (dir == 3)
{
- case 3:
- gMC.cond |= 1;
- break;
+ gMC.cond |= 1;
+ }
+ else
+ {
+ gMC.cond &= ~1;
- default:
- gMC.cond &= ~1;
-
- if (dir < 10)
- {
- gMC.direct = dir;
- break;
- }
-
+ if (dir < 10)
+ {
+ gMC.direct = dir;
+ }
+ else
+ {
for (int i = 0; i < NPC_MAX; i++)
- {
if (gNPC[i].code_event == dir)
- {
- if (gMC.x <= gNPC[i].x)
- gMC.direct = 2;
- else
- gMC.direct = 0;
break;
- }
- }
- break;
+
+ if (i == NPC_MAX)
+ return;
+
+ if (gMC.x > gNPC[i].x)
+ gMC.direct = 0;
+ else
+ gMC.direct = 2;
+ }
}
gMC.xm = 0;
- AnimationMyChar(false);
+ AnimationMyChar(FALSE);
}
-void ChangeMyUnit(uint8_t a)
+void ChangeMyUnit(unsigned char a)
{
gMC.unit = a;
}
@@ -942,7 +970,7 @@
gMC.y += 0x4000;
}
-void EquipItem(int flag, bool b)
+void EquipItem(int flag, BOOL b)
{
if (b)
gMC.equip |= flag;
@@ -960,17 +988,19 @@
noise_freq = freq;
noise_no = no;
- if (no == 1)
+ switch (noise_no)
{
- ChangeSoundFrequency(40, noise_freq);
- ChangeSoundFrequency(41, noise_freq + 100);
- PlaySoundObject(40, -1);
- PlaySoundObject(41, -1);
+ case 1:
+ ChangeSoundFrequency(40, noise_freq);
+ ChangeSoundFrequency(41, noise_freq + 100);
+ PlaySoundObject(40, -1);
+ PlaySoundObject(41, -1);
+ break;
+
+ case 2:
+ PlaySoundObject(58, -1);
+ break;
}
- else if (no == 2)
- {
- PlaySoundObject(58, -1);
- }
}
void CutNoise()
@@ -983,16 +1013,18 @@
void ResetNoise()
{
- if (noise_no == 1)
+ switch (noise_no)
{
- ChangeSoundFrequency(40, noise_freq);
- ChangeSoundFrequency(41, noise_freq + 100);
- PlaySoundObject(40, -1);
- PlaySoundObject(41, -1);
- }
- else if (noise_no == 2)
- {
- PlaySoundObject(58, -1);
+ case 1:
+ ChangeSoundFrequency(40, noise_freq);
+ ChangeSoundFrequency(41, noise_freq + 100);
+ PlaySoundObject(40, -1);
+ PlaySoundObject(41, -1);
+ break;
+
+ case 2:
+ PlaySoundObject(58, -1);
+ break;
}
}
--- a/src/MyChar.h
+++ b/src/MyChar.h
@@ -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,21 +30,21 @@
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;
};
@@ -51,20 +51,20 @@
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();