From 75e062c7753c7dd4229f00932ffa34f87fd7fead Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 6 May 2019 17:23:18 +0100 Subject: [PATCH] Made Caret.cpp ASM-accurate --- msvc2003/devilution/comparer-config.toml | 84 ++++++++++++++++++ src/Caret.cpp | 106 ++++++++++++++--------- 2 files changed, 147 insertions(+), 43 deletions(-) diff --git a/msvc2003/devilution/comparer-config.toml b/msvc2003/devilution/comparer-config.toml index 11f70a16..5bb94155 100644 --- a/msvc2003/devilution/comparer-config.toml +++ b/msvc2003/devilution/comparer-config.toml @@ -187,6 +187,90 @@ addr = 0x408FC0 name = "IsActiveSomeBullet" addr = 0x4095C0 +[[func]] +name = "InitCaret" +addr = 0x409650 + +[[func]] +name = "ActCaret00" +addr = 0x409670 + +[[func]] +name = "ActCaret01" +addr = 0x409680 + +[[func]] +name = "ActCaret02" +addr = 0x409880 + +[[func]] +name = "ActCaret03" +addr = 0x409B80 + +[[func]] +name = "ActCaret04" +addr = 0x409C70 + +[[func]] +name = "ActCaret05" +addr = 0x409E00 + +[[func]] +name = "ActCaret07" +addr = 0x409F60 + +[[func]] +name = "ActCaret08" +addr = 0x40A120 + +[[func]] +name = "ActCaret09" +addr = 0x40A1B0 + +[[func]] +name = "ActCaret10" +addr = 0x40A280 + +[[func]] +name = "ActCaret11" +addr = 0x40A3F0 + +[[func]] +name = "ActCaret12" +addr = 0x40A5A0 + +[[func]] +name = "ActCaret13" +addr = 0x40A650 + +[[func]] +name = "ActCaret14" +addr = 0x40A7E0 + +[[func]] +name = "ActCaret15" +addr = 0x40A8F0 + +[[func]] +name = "ActCaret16" +addr = 0x40A9E0 + +[[func]] +name = "ActCaret17" +addr = 0x40AAA0 + +[[func]] +name = "ActCaret" +addr = 0x40AB50 + +[[func]] +name = "PutCaret" +addr = 0x40ABC0 + +[[func]] +name = "SetCaret" +addr = 0x40AC90 + [[func]] name = "Call_Escape" addr = 0x40DD70 diff --git a/src/Caret.cpp b/src/Caret.cpp index 8ddce54b..126bb890 100644 --- a/src/Caret.cpp +++ b/src/Caret.cpp @@ -34,7 +34,7 @@ void ActCaret01(CARET *crt) {64, 24, 72, 32}, {72, 24, 80, 32}, {80, 24, 88, 32}, - {88, 24, 92, 32}, + {88, 24, 96, 32}, }; if (!crt->act_no) @@ -55,10 +55,10 @@ void ActCaret01(CARET *crt) crt->cond = 0; } - if (crt->direct) - crt->rect = rcRight[crt->ani_no]; - else + if (crt->direct == 0) crt->rect = rcLeft[crt->ani_no]; + else + crt->rect = rcRight[crt->ani_no]; } void ActCaret02(CARET *crt) @@ -88,32 +88,39 @@ void ActCaret02(CARET *crt) case 0: crt->ym -= 0x10; crt->y += crt->ym; + if (++crt->ani_wait > 5) { crt->ani_wait = 0; ++crt->ani_no; } - if ( crt->ani_no > 3 ) + + if (crt->ani_no > 3) crt->cond = 0; + crt->rect = rect_left[crt->ani_no]; break; - case 1: - crt->rect = rect_up[++crt->ani_wait / 2 % 3]; - if (crt->ani_wait > 24) - crt->cond = 0; - break; - case 2: - if ( ++crt->ani_wait > 2 ) + if (++crt->ani_wait > 2) { crt->ani_wait = 0; ++crt->ani_no; } - if ( crt->ani_no > 3 ) + + if (crt->ani_no > 3) crt->cond = 0; + crt->rect = rect_right[crt->ani_no]; break; + + case 1: + crt->rect = rect_up[++crt->ani_wait / 2 % 3]; + + if (crt->ani_wait > 24) + crt->cond = 0; + + break; } } @@ -158,7 +165,7 @@ void ActCaret04(CARET *crt) crt->cond = 0; } - crt->rect = rect[crt->ani_no + 3 * crt->direct]; + crt->rect = rect[3 * crt->direct + crt->ani_no]; } void ActCaret05(CARET *crt) @@ -243,9 +250,10 @@ void ActCaret09(CARET *crt) RECT rcLeft = {0, 80, 16, 96}; RECT rcRight = {48, 64, 64, 80}; - if (++crt->ani_wait <= 4) + if (++crt->ani_wait < 5) crt->y -= 0x800; - if (crt->ani_wait == 32 ) + + if (crt->ani_wait == 32) crt->cond = 0; if (crt->direct == 0) @@ -268,33 +276,37 @@ void ActCaret10(CARET *crt) ++crt->ani_wait; - if (crt->direct) + if (crt->direct == 0) { if (crt->ani_wait < 20) - crt->y -= 0x200; + crt->y -= 0x400; + if (crt->ani_wait == 80) - crt->cond = 0; + crt->cond = 0; } else { if (crt->ani_wait < 20) - crt->y -= 0x400; + crt->y -= 0x200; + if (crt->ani_wait == 80) crt->cond = 0; } - if (crt->direct) - crt->rect = rcRight[crt->ani_wait / 2 % 2]; - else + if (crt->direct == 0) crt->rect = rcLeft[crt->ani_wait / 2 % 2]; + else + crt->rect = rcRight[crt->ani_wait / 2 % 2]; } void ActCaret11(CARET *crt) { + unsigned char deg; + if (!crt->act_no) { crt->act_no = 1; - uint8_t deg = Random(0, 0xFF); + deg = Random(0, 0xFF); crt->xm = 2 * GetCos(deg); crt->ym = 2 * GetSin(deg); } @@ -346,7 +358,7 @@ void ActCaret13(CARET *crt) {0, 0, 0, 0}, }; - if (!crt->act_no) + if (crt->act_no == 0) { crt->act_no = 1; @@ -363,10 +375,12 @@ void ActCaret13(CARET *crt) } } - if (!crt->direct) + switch (crt->direct) { - crt->xm = 4 * crt->xm / 5; - crt->ym = 4 * crt->ym / 5; + case 0: + crt->xm = 4 * crt->xm / 5; + crt->ym = 4 * crt->ym / 5; + break; } crt->x += crt->xm; @@ -502,10 +516,16 @@ CARETFUNCTION gpCaretFuncTbl[] = void ActCaret() { - for (int i = 0; i < CARET_MAX; i++) + int i; + int code; + + for (i = 0; i < CARET_MAX; i++) { if (gCrt[i].cond & 0x80) - gpCaretFuncTbl[gCrt[i].code](&gCrt[i]); + { + code = gCrt[i].code; + gpCaretFuncTbl[code](&gCrt[i]); + } } } @@ -528,18 +548,18 @@ void PutCaret(int fx, int fy) void SetCaret(int x, int y, int code, int dir) { for (int c = 0; c < CARET_MAX; c++) - { - if (!gCrt[c].cond) - { - memset(&gCrt[c], 0, sizeof(CARET)); - gCrt[c].cond = 0x80; - gCrt[c].code = code; - gCrt[c].x = x; - gCrt[c].y = y; - gCrt[c].view_left = gCaretTable[code].view_left; - gCrt[c].view_top = gCaretTable[code].view_top; - gCrt[c].direct = dir; + if (gCrt[c].cond == 0) break; - } - } + + if (c == CARET_MAX) + return; + + memset(&gCrt[c], 0, sizeof(CARET)); + gCrt[c].cond = 0x80; + gCrt[c].code = code; + gCrt[c].x = x; + gCrt[c].y = y; + gCrt[c].view_left = gCaretTable[code].view_left; + gCrt[c].view_top = gCaretTable[code].view_top; + gCrt[c].direct = dir; }