shithub: cstory

Download patch

ref: 75e062c7753c7dd4229f00932ffa34f87fd7fead
parent: 0eaca9966c1af506719ec94f0daad24782966dab
author: Clownacy <Clownacy@users.noreply.github.com>
date: Mon May 6 13:23:18 EDT 2019

Made Caret.cpp ASM-accurate

--- a/msvc2003/devilution/comparer-config.toml
+++ b/msvc2003/devilution/comparer-config.toml
@@ -188,6 +188,90 @@
 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
 
--- a/src/Caret.cpp
+++ b/src/Caret.cpp
@@ -34,7 +34,7 @@
 		{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 @@
 			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 @@
 		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 @@
 			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 @@
 	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 @@
 
 	++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 @@
 		{0, 0, 0, 0},
 	};
 	
-	if (!crt->act_no)
+	if (crt->act_no == 0)
 	{
 		crt->act_no = 1;
 		
@@ -363,10 +375,12 @@
 		}
 	}
 	
-	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 @@
 
 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 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;
 }