ref: d641f508f233438f11f46a71867ae059b83488c0
parent: 82454c3a62dd444b37356e619f02f736c9d2cae3
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Nov 13 19:03:34 EST 2019
TextScr.cpp cleanup
--- a/src/TextScr.cpp
+++ b/src/TextScr.cpp
@@ -51,8 +51,10 @@
#endif
// Initialize and end tsc
-BOOL InitTextScript2()
+BOOL InitTextScript2(void)
{
+ int i;
+
#ifdef FIX_BUGS
nod_color = GetCortBoxColor(RGB(0xFF, 0xFF, 0xFE));
#endif
@@ -59,11 +61,11 @@
// Clear flags
gTS.mode = 0;
- g_GameFlags &= ~0x04;
+ g_GameFlags &= ~4;
// Create line surfaces
- for (int i = 0; i < 4; i++)
- MakeSurface_Generic(gRect_line.right, gRect_line.bottom, (SurfaceID)(i + SURFACE_ID_TEXT_LINE1), FALSE);
+ for (i = 0; i < 4; ++i)
+ MakeSurface_Generic(gRect_line.right, gRect_line.bottom, (SurfaceID)(SURFACE_ID_TEXT_LINE1 + i), FALSE);
// Clear text
memset(text, 0, sizeof(text));
@@ -77,15 +79,17 @@
return TRUE;
}
-void EndTextScript()
+void EndTextScript(void)
{
+ int i;
+
// Free TSC buffer
free(gTS.data);
// Release buffers
ReleaseSurface(SURFACE_ID_TEXT_BOX);
- for (int i = 0; i < 4; i++)
- ReleaseSurface((SurfaceID)(i + SURFACE_ID_TEXT_LINE1));
+ for (i = 0; i < 4; ++i)
+ ReleaseSurface((SurfaceID)(SURFACE_ID_TEXT_LINE1 + i));
}
// Decrypt .tsc
@@ -94,20 +98,21 @@
int val1;
int work;
int i;
+ int half;
- int half = size / 2;
+ half = size / 2;
if (pData[half] == 0)
val1 = -7;
else
- val1 = (pData[half] % 256) * -1;
+ val1 = (pData[half] % 0x100) * -1;
- for (i = 0; i < size; i++)
+ for (i = 0; i < size; ++i)
{
work = pData[i];
work += val1;
if (i != half)
- pData[i] = work % 256;
+ pData[i] = work % 0x100;
}
}
@@ -137,6 +142,7 @@
// Decrypt data
EncryptionBinaryData2((unsigned char*)gTS.data, gTS.size);
+
return TRUE;
}
@@ -181,6 +187,7 @@
// Set parameters
gTS.size = head_size + body_size;
strcpy(gTS.path, name);
+
return TRUE;
}
@@ -204,6 +211,8 @@
// Start TSC event
BOOL StartTextScript(int no)
{
+ //int i;
+
// Reset state
gTS.mode = 1;
g_GameFlags |= 5;
@@ -225,10 +234,10 @@
/* This is present in the Linux port, but not the Windows version (1.0.0.6, at least)
// Clear text lines
- for (int i = 0; i < 4; i++)
+ for (i = 0; i < 4; ++i)
{
- gTS.ypos_line[i] = 16 * i;
- CortBox2(&gRect_line, 0x000000, (SurfaceID)(i + SURFACE_ID_TEXT_LINE1));
+ gTS.ypos_line[i] = i * 16;
+ CortBox2(&gRect_line, 0x000000, (SurfaceID)(SURFACE_ID_TEXT_LINE1 + i));
memset(text[i], 0, sizeof(text[0]));
}*/
@@ -265,9 +274,11 @@
BOOL JumpTextScript(int no)
{
+ int i;
+
// Set state
gTS.mode = 1;
- g_GameFlags |= 4u;
+ g_GameFlags |= 4;
gTS.line = 0;
gTS.p_write = 0;
gTS.wait = 4;
@@ -274,10 +285,10 @@
gTS.wait_beam = 0;
// Clear text lines
- for (int i = 0; i < 4; i++)
+ for (i = 0; i < 4; ++i)
{
- gTS.ypos_line[i] = 16 * i;
- CortBox2(&gRect_line, 0x000000, (SurfaceID)(i + SURFACE_ID_TEXT_LINE1));
+ gTS.ypos_line[i] = i * 16;
+ CortBox2(&gRect_line, 0x000000, (SurfaceID)(SURFACE_ID_TEXT_LINE1 + i));
memset(text[i], 0, sizeof(text[0]));
}
@@ -313,7 +324,7 @@
}
// End event
-void StopTextScript()
+void StopTextScript(void)
{
// End TSC and reset flags
gTS.mode = 0;
@@ -323,13 +334,13 @@
}
// Prepare a new line
-void CheckNewLine()
+void CheckNewLine(void)
{
if (gTS.ypos_line[gTS.line % 4] == 48)
{
gTS.mode = 3;
g_GameFlags |= 4;
- CortBox2(&gRect_line, 0, (SurfaceID)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1));
+ CortBox2(&gRect_line, 0, (SurfaceID)(SURFACE_ID_TEXT_LINE1 + (gTS.line % 4)));
memset(text[gTS.line % 4], 0, sizeof(text[0]));
}
}
@@ -357,12 +368,12 @@
offset = 0;
// Trim leading zeroes
- for (i = 0; i < 3; i++)
+ for (i = 0; i < 3; ++i)
{
- if (a / table[i] || bZero != FALSE)
+ if (a / table[i] || bZero)
{
b = a / table[i];
- str[offset] = (char)b + '0';
+ str[offset] = '0' + (char)b;
bZero = TRUE;
a -= b * table[i];
++offset;
@@ -370,11 +381,11 @@
}
// Set last digit of string, and add null terminator
- str[offset] = (char)a + '0';
- str[offset + 1] = 0;
+ str[offset] = '0' + (char)a;
+ str[offset + 1] = '\0';
// Append number to line
- PutText2(6 * gTS.p_write, 0, str, RGB(0xFF, 0xFF, 0xFE), (SurfaceID)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1));
+ PutText2(gTS.p_write * 6, 0, str, RGB(0xFF, 0xFF, 0xFE), (SurfaceID)(SURFACE_ID_TEXT_LINE1 + (gTS.line % 4)));
strcat(text[gTS.line % 4], str);
// Play sound and reset blinking cursor
@@ -382,33 +393,35 @@
gTS.wait_beam = 0;
// Check if should move to next line (prevent a memory overflow, come on guys, this isn't a leftover of pixel trying to make text wrapping)
- gTS.p_write += (unsigned int)strlen(str);
+ gTS.p_write += (int)strlen(str);
if (gTS.p_write >= 35)
{
gTS.p_write = 0;
- gTS.line++;
+ ++gTS.line;
CheckNewLine();
}
}
// Clear text lines
-void ClearTextLine()
+void ClearTextLine(void)
{
+ int i;
+
gTS.line = 0;
gTS.p_write = 0;
gTS.offsetY = 0;
- for (int i = 0; i < 4; i++)
+ for (i = 0; i < 4; ++i)
{
- gTS.ypos_line[i] = 16 * i;
- CortBox2(&gRect_line, 0x000000, (SurfaceID)(i + SURFACE_ID_TEXT_LINE1));
+ gTS.ypos_line[i] = i * 16;
+ CortBox2(&gRect_line, 0x000000, (SurfaceID)(SURFACE_ID_TEXT_LINE1 + i));
memset(text[i], 0, sizeof(text[0]));
}
}
// Draw textbox and whatever else
-void PutTextScript()
+void PutTextScript(void)
{
RECT rcFace;
RECT rcItemBox1;
@@ -448,14 +461,14 @@
RECT rcFrame3 = {0, 16, 244, 24};
PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, gTS.rcText.top - 10, &rcFrame1, SURFACE_ID_TEXT_BOX);
- for (i = 1; i < 7; i++)
- PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, 8 * i + gTS.rcText.top - 10, &rcFrame2, SURFACE_ID_TEXT_BOX);
- PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, 8 * i + gTS.rcText.top - 10, &rcFrame3, SURFACE_ID_TEXT_BOX);
+ for (i = 1; i < 7; ++i)
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) - 122, (i * 8) + gTS.rcText.top - 10, &rcFrame2, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) - 122, (i * 8) + gTS.rcText.top - 10, &rcFrame3, SURFACE_ID_TEXT_BOX);
}
// Draw face picture
- rcFace.left = 48 * (gTS.face % 6);
- rcFace.top = 48 * (gTS.face / 6);
+ rcFace.left = (gTS.face % 6) * 48;
+ rcFace.top = (gTS.face / 6) * 48;
rcFace.right = rcFace.left + 48;
rcFace.bottom = rcFace.top + 48;
@@ -472,18 +485,18 @@
#endif
// Draw text
- if (gTS.face)
+ if (gTS.face != 0)
text_offset = 56;
else
text_offset = 0;
- for (i = 0; i < 4; i++)
- PutBitmap3(&gTS.rcText, text_offset + TEXT_LEFT, gTS.offsetY + gTS.ypos_line[i] + gTS.rcText.top, &gRect_line, (SurfaceID)(i + SURFACE_ID_TEXT_LINE1));
+ for (i = 0; i < 4; ++i)
+ PutBitmap3(&gTS.rcText, TEXT_LEFT + text_offset, gTS.offsetY + gTS.ypos_line[i] + gTS.rcText.top, &gRect_line, (SurfaceID)(SURFACE_ID_TEXT_LINE1 + i));
// Draw NOD cursor
if ((gTS.wait_beam++ % 20 > 12) && gTS.mode == 2)
{
- rect.left = TEXT_LEFT + 6 * gTS.p_write + text_offset;
+ rect.left = TEXT_LEFT + (gTS.p_write * 6) + text_offset;
rect.top = gTS.ypos_line[gTS.line % 4] + gTS.rcText.top + gTS.offsetY;
rect.right = rect.left + 5;
rect.bottom = rect.top + 11;
@@ -509,14 +522,14 @@
SET_RECT(rcItemBox4, 240, 8, 244, 16)
SET_RECT(rcItemBox5, 240, 16, 244, 24)
- if (gTS.item)
+ if (gTS.item != 0)
{
- PutBitmap3(&grcFull, (WINDOW_WIDTH - 80) / 2, WINDOW_HEIGHT - 112, &rcItemBox1, SURFACE_ID_TEXT_BOX);
- PutBitmap3(&grcFull, (WINDOW_WIDTH - 80) / 2, WINDOW_HEIGHT - 96, &rcItemBox2, SURFACE_ID_TEXT_BOX);
- PutBitmap3(&grcFull, (WINDOW_WIDTH + 64) / 2, WINDOW_HEIGHT - 112, &rcItemBox3, SURFACE_ID_TEXT_BOX);
- PutBitmap3(&grcFull, (WINDOW_WIDTH + 64) / 2, WINDOW_HEIGHT - 104, &rcItemBox4, SURFACE_ID_TEXT_BOX);
- PutBitmap3(&grcFull, (WINDOW_WIDTH + 64) / 2, WINDOW_HEIGHT - 96, &rcItemBox4, SURFACE_ID_TEXT_BOX);
- PutBitmap3(&grcFull, (WINDOW_WIDTH + 64) / 2, WINDOW_HEIGHT - 88, &rcItemBox5, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) - 40, WINDOW_HEIGHT - 112, &rcItemBox1, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) - 40, WINDOW_HEIGHT - 96, &rcItemBox2, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) + 32, WINDOW_HEIGHT - 112, &rcItemBox3, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) + 32, WINDOW_HEIGHT - 104, &rcItemBox4, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) + 32, WINDOW_HEIGHT - 96, &rcItemBox4, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) + 32, WINDOW_HEIGHT - 88, &rcItemBox5, SURFACE_ID_TEXT_BOX);
if (gTS.item_y < WINDOW_HEIGHT - 104)
++gTS.item_y;
@@ -523,11 +536,11 @@
if (gTS.item < 1000)
{
- rect.left = 16 * (gTS.item % 16);
+ rect.left = (gTS.item % 16) * 16;
rect.right = rect.left + 16;
- rect.top = 16 * (gTS.item / 16);
+ rect.top = (gTS.item / 16) * 16;
rect.bottom = rect.top + 16;
- PutBitmap3(&grcFull, (WINDOW_WIDTH - 24) / 2, gTS.item_y, &rect, SURFACE_ID_ARMS_IMAGE);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) - 12, gTS.item_y, &rect, SURFACE_ID_ARMS_IMAGE);
}
else
{
@@ -535,7 +548,7 @@
rect.right = rect.left + 32;
rect.top = 16 * ((gTS.item - 1000) / 8);
rect.bottom = rect.top + 16;
- PutBitmap3(&grcFull, (WINDOW_WIDTH - 40) / 2, gTS.item_y, &rect, SURFACE_ID_ITEM_IMAGE);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) - 20, gTS.item_y, &rect, SURFACE_ID_ITEM_IMAGE);
}
}
@@ -550,14 +563,14 @@
else
i = WINDOW_HEIGHT - 96;
- PutBitmap3(&grcFull, (WINDOW_WIDTH + 112) / 2, i, &rect_yesno, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (WINDOW_WIDTH / 2) + 56, i, &rect_yesno, SURFACE_ID_TEXT_BOX);
if (gTS.wait == 16)
- PutBitmap3(&grcFull, 41 * gTS.select + (WINDOW_WIDTH + 102) / 2, WINDOW_HEIGHT - 86, &rect_cur, SURFACE_ID_TEXT_BOX);
+ PutBitmap3(&grcFull, (gTS.select * 41) + (WINDOW_WIDTH / 2) + 51, WINDOW_HEIGHT - 86, &rect_cur, SURFACE_ID_TEXT_BOX);
}
}
// Parse TSC
-int TextScriptProc()
+int TextScriptProc(void)
{
BOOL bExit;
char c[3];
@@ -573,7 +586,7 @@
// Type out (faster if ok or cancel are held)
++gTS.wait;
- if (!(g_GameFlags & 2) && (gKeyCancel | gKeyOk) & gKey)
+ if (!(g_GameFlags & 2) && gKey & (gKeyOk | gKeyCancel))
gTS.wait += 4;
if (gTS.wait < 4)
@@ -584,7 +597,7 @@
// Parsing time
bExit = FALSE;
- while (bExit == FALSE)
+ while (!bExit)
{
if (gTS.data[gTS.p_read] == '<')
{
@@ -702,6 +715,7 @@
w = GetTextScriptNo(gTS.p_read + 9);
x = GetTextScriptNo(gTS.p_read + 14);
y = GetTextScriptNo(gTS.p_read + 19);
+
if (!TransferStage(z, w, x, y))
{
MessageBoxA(ghWnd, "\x83\x58\x83\x65\x81\x5B\x83\x57\x82\xCC\x93\xC7\x82\xDD\x8D\x9E\x82\xDD\x82\xC9\x8E\xB8\x94\x73", "\x83\x47\x83\x89\x81\x5B", MB_OK); // 'ステージの読み込みに失敗' and 'エラー' ('Failed to load stage' and 'Error') in Shift-JIS
@@ -1109,7 +1123,7 @@
x = GetTextScriptNo(gTS.p_read + 9);
y = GetTextScriptNo(gTS.p_read + 14);
z = GetTextScriptNo(gTS.p_read + 19);
- SetNpChar(w, x * 0x200 * 0x10, y * 0x200 * 0x10, 0, 0, z, 0, 0x100);
+ SetNpChar(w, x * 0x200 * 0x10, y * 0x200 * 0x10, 0, 0, z, NULL, 0x100);
gTS.p_read += 23;
}
else if (IS_COMMAND('M','N','P'))
@@ -1140,7 +1154,7 @@
{
z = GetTextScriptNo(gTS.p_read + 4);
- if (z)
+ if (z != 0)
StartBossLife(z);
else
StartBossLife2();
@@ -1182,7 +1196,7 @@
else if (IS_COMMAND('F','A','C'))
{
z = GetTextScriptNo(gTS.p_read + 4);
- if (gTS.face != (signed char)z)
+ if (gTS.face != (signed char)z) // Not sure why these casts are here, but they're needed for the same assembly code to be produced
{
gTS.face = (signed char)z;
gTS.face_x = (WINDOW_WIDTH / 2 - 156) * 0x200;
@@ -1288,16 +1302,16 @@
// Get text to copy
y = x - gTS.p_read;
memcpy(str, &gTS.data[gTS.p_read], y);
- str[y] = 0;
+ str[y] = '\0';
gTS.p_write = x;
// Print text
- PutText2(0, 0, str, RGB(0xFF, 0xFF, 0xFE), (SurfaceID)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1));
+ PutText2(0, 0, str, RGB(0xFF, 0xFF, 0xFE), (SurfaceID)(SURFACE_ID_TEXT_LINE1 + (gTS.line % 4)));
#ifdef FIX_BUGS
strcpy(text[gTS.line % 4], str);
#else
- sprintf(text[gTS.line % 4], str); // No point to using an sprintf here, and it makes Clang mad
+ sprintf(text[gTS.line % 4], str); // No point in using an sprintf here, and it makes Clang mad
#endif
// Check if should move to next line (prevent a memory overflow, come on guys, this isn't a leftover of pixel trying to make text wrapping)
@@ -1326,11 +1340,11 @@
// Print text
if (c[0] == '=')
{
- Surface2Surface(6 * gTS.p_write, 2, &rcSymbol, (SurfaceID)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1), SURFACE_ID_TEXT_BOX);
+ Surface2Surface(gTS.p_write * 6, 2, &rcSymbol, (SurfaceID)(SURFACE_ID_TEXT_LINE1 + (gTS.line % 4)), SURFACE_ID_TEXT_BOX);
}
else
{
- PutText2(6 * gTS.p_write, 0, c, RGB(0xFF, 0xFF, 0xFE), (SurfaceID)(gTS.line % 4 + SURFACE_ID_TEXT_LINE1));
+ PutText2(gTS.p_write * 6, 0, c, RGB(0xFF, 0xFF, 0xFE), (SurfaceID)(SURFACE_ID_TEXT_LINE1 + (gTS.line % 4)));
}
strcat(text[gTS.line % 4], c);
@@ -1345,8 +1359,8 @@
}
else
{
- gTS.p_read++;
- gTS.p_write++;
+ gTS.p_read += 1;
+ gTS.p_write += 1;
}
if (gTS.p_write >= 35)
@@ -1364,16 +1378,16 @@
break;
case 2: // NOD
- if ((gKeyCancel | gKeyOk) & gKeyTrg)
+ if (gKeyTrg & (gKeyOk | gKeyCancel))
gTS.mode = 1;
break;
case 3: // NEW LINE
- for (i = 0; i < 4; i++)
+ for (i = 0; i < 4; ++i)
{
gTS.ypos_line[i] -= 4;
- if (!gTS.ypos_line[i])
+ if (gTS.ypos_line[i] == 0)
gTS.mode = 1;
if (gTS.ypos_line[i] == -16)
@@ -1402,17 +1416,19 @@
gTS.mode = 1;
gTS.wait_beam = 0;
break;
+
case 7: // WAS
if ((gMC.flag & 8) == 0)
- break;
+ break;
gTS.mode = 1;
gTS.wait_beam = 0;
break;
+
case 6: // YNJ
if (gTS.wait < 16)
{
- gTS.wait++;
+ ++gTS.wait;
}
else
{
@@ -1451,14 +1467,17 @@
g_GameFlags &= ~4;
else
g_GameFlags |= 4;
+
return 1;
}
-void RestoreTextScript()
+void RestoreTextScript(void)
{
- for (int i = 0; i < 4; ++i)
+ int i;
+
+ for (i = 0; i < 4; ++i)
{
- CortBox2(&gRect_line, 0x000000, (SurfaceID)(i + SURFACE_ID_TEXT_LINE1));
- PutText2(0, 0, text[i], RGB(0xFF, 0xFF, 0xFE), (SurfaceID)(i + SURFACE_ID_TEXT_LINE1));
+ CortBox2(&gRect_line, 0x000000, (SurfaceID)(SURFACE_ID_TEXT_LINE1 + i));
+ PutText2(0, 0, text[i], RGB(0xFF, 0xFF, 0xFE), (SurfaceID)(SURFACE_ID_TEXT_LINE1 + i));
}
}
--- a/src/TextScr.h
+++ b/src/TextScr.h
@@ -4,63 +4,63 @@
struct TEXT_SCRIPT
{
- //Path (reload when exit teleporter menu/inventory)
+ // Path (reload when exit teleporter menu/inventory)
char path[MAX_PATH];
- //Script buffer
- int size;
+ // Script buffer
+ long size;
char *data;
- //Mode (ex. NOD, WAI)
+ // Mode (ex. NOD, WAI)
signed char mode;
- //Flags
+ // Flags
signed char flags;
- //Current positions (read position in buffer, x position in line)
+ // Current positions (read position in buffer, x position in line)
unsigned int p_read;
int p_write;
- //Current line to write to
+ // Current line to write to
int line;
- //Line y positions
+ // Line y positions
int ypos_line[4];
- //Event stuff
+ // Event stuff
int wait;
int wait_next;
int next_event;
- //Yes/no selected
+ // Yes/no selected
signed char select;
- //Current face
+ // Current face
int face;
int face_x;
- //Current item
+ // Current item
int item;
int item_y;
- //Text rect
+ // Text rect
RECT rcText;
- //..?
+ // ..?
int offsetY;
- //NOD cursor blink
+ // NOD cursor blink
unsigned char wait_beam;
};
-BOOL InitTextScript2();
-void EndTextScript();
+BOOL InitTextScript2(void);
+void EndTextScript(void);
void EncryptionBinaryData2(unsigned char *pData, int size);
BOOL LoadTextScript2(const char *name);
BOOL LoadTextScript_Stage(const char *name);
void GetTextScriptPath(char *path);
BOOL StartTextScript(int no);
-void StopTextScript();
-void PutTextScript();
-int TextScriptProc();
-void RestoreTextScript();
+void StopTextScript(void);
+void PutTextScript(void);
+int TextScriptProc(void);
+void RestoreTextScript(void);