Merge pull request #62 from Clownacy/master

Made TextScr.cpp as ASM-accurate as possible for now, and added a bugfix
This commit is contained in:
Cucky 2019-02-12 08:36:15 -05:00 committed by GitHub
commit f302c55978
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 429 additions and 388 deletions

View file

@ -1,2 +1,5 @@
Main.cpp : void SystemTask() Main.cpp : void SystemTask()
Pixel intended for the second alternate up key to be the plus key, Japanese keyboards have the plus key where the semi-colon key is, causing errors on other keyboard layouts) Pixel intended for the second alternate up key to be the plus key, Japanese keyboards have the plus key where the semi-colon key is, causing errors on other keyboard layouts)
SelStage.cpp : int StageSelectLoop(int *p_event)
The screencap that serves as the menu's background was being drawn with transparency enabled. This can cause moving sprites (like the text) to leave a trail.

View file

@ -165,7 +165,12 @@ int StageSelectLoop(int *p_event)
if (tscRet == 2) if (tscRet == 2)
return 2; return 2;
#ifdef FIX_BUGS
PutBitmap4(&rcView, 0, 0, &rcView, 10);
#else
// The original accidentally drew the screencap with transparency enabled
PutBitmap3(&rcView, 0, 0, &rcView, 10); PutBitmap3(&rcView, 0, 0, &rcView, 10);
#endif
PutStageSelectObject(); PutStageSelectObject();
PutTextScript(); PutTextScript();

View file

@ -34,6 +34,8 @@
#define TSC_BUFFER_SIZE 0x5000 #define TSC_BUFFER_SIZE 0x5000
#define TEXT_LEFT (WINDOW_WIDTH / 2 - 108)
TEXT_SCRIPT gTS; TEXT_SCRIPT gTS;
int gNumberTextScript[4]; int gNumberTextScript[4];
@ -42,7 +44,7 @@ char text[0x100];
RECT gRect_line = {0, 0, 216, 16}; RECT gRect_line = {0, 0, 216, 16};
//Initialize and end tsc //Initialize and end tsc
bool InitTextScript2() BOOL InitTextScript2()
{ {
//Clear flags //Clear flags
gTS.mode = 0; gTS.mode = 0;
@ -57,7 +59,11 @@ bool InitTextScript2()
//Allocate script buffer //Allocate script buffer
gTS.data = (char*)malloc(TSC_BUFFER_SIZE); gTS.data = (char*)malloc(TSC_BUFFER_SIZE);
return gTS.data != nullptr;
if (gTS.data == NULL)
return FALSE;
else
return TRUE;
} }
void EndTextScript() void EndTextScript()
@ -77,15 +83,18 @@ void EncryptionBinaryData2(uint8_t *pData, int size)
int val1; int val1;
int half = size / 2; int half = size / 2;
if (pData[half]) if (pData[half] == 0)
val1 = -pData[half];
else
val1 = -7; val1 = -7;
else
val1 = (pData[half] % 256) * -1;
for (int i = 0; i < size; i++) for (int i = 0; i < size; i++)
{ {
if ( i != half ) int work = pData[i];
pData[i] += val1; work += val1;
if (i != half)
pData[i] = work % 256;
} }
} }
@ -162,14 +171,16 @@ void GetTextScriptPath(char *path)
//Get 4 digit number from TSC data //Get 4 digit number from TSC data
int GetTextScriptNo(int a) int GetTextScriptNo(int a)
{ {
return gTS.data[a + 3] - 48 int b = 0;
+ 10 * gTS.data[a + 2] - 480 b += (gTS.data[a++] - '0') * 1000;
+ 100 * gTS.data[a + 1] - 4800 b += (gTS.data[a++] - '0') * 100;
+ 1000 * gTS.data[a] - 48000; b += (gTS.data[a++] - '0') * 10;
b += gTS.data[a] - '0';
return b;
} }
//Start TSC event //Start TSC event
bool StartTextScript(int no) BOOL StartTextScript(int no)
{ {
//Reset state //Reset state
gTS.mode = 1; gTS.mode = 1;
@ -185,34 +196,41 @@ bool StartTextScript(int no)
gMC.shock = 0; gMC.shock = 0;
gTS.rcText = {WINDOW_WIDTH / 2 - 108, WINDOW_HEIGHT - 56, WINDOW_WIDTH + 108, WINDOW_HEIGHT - 8}; gTS.rcText.left = TEXT_LEFT;
gTS.rcText.top = WINDOW_HEIGHT - 56;
gTS.rcText.right = WINDOW_WIDTH + 108;
gTS.rcText.bottom = gTS.rcText.top + 48;
/* This is present in the Linux port, but not the Windows version (1.0.0.6, at least)
//Clear text lines //Clear text lines
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
gTS.ypos_line[i] = 16 * i; gTS.ypos_line[i] = 16 * i;
CortBox2(&gRect_line, 0x000000, i + 30); CortBox2(&gRect_line, 0x000000, i + 30);
memset(&text[i * 0x40], 0, 0x40); memset(&text[i * 0x40], 0, 0x40);
} }*/
//Find where event starts //Find where event starts
for (gTS.p_read = 0; ; gTS.p_read++) gTS.p_read = 0;
while (1)
{ {
//Check if we are still in the proper range //Check if we are still in the proper range
if (!gTS.data[gTS.p_read]) if (gTS.data[gTS.p_read] == '\0')
return false; return FALSE;
//Check if we are at an event //Check if we are at an event
if (gTS.data[gTS.p_read] != '#') if (gTS.data[gTS.p_read] == '#')
continue; {
//Check if this is our event //Check if this is our event
int event_no = GetTextScriptNo(++gTS.p_read); int event_no = GetTextScriptNo(++gTS.p_read);
if (no == event_no) if (no == event_no)
break; break;
if (no < event_no) if (no < event_no)
return false; return FALSE;
}
++gTS.p_read;
} }
//Advance until new-line //Advance until new-line
@ -220,10 +238,10 @@ bool StartTextScript(int no)
++gTS.p_read; ++gTS.p_read;
++gTS.p_read; ++gTS.p_read;
return true; return TRUE;
} }
bool JumpTextScript(int no) BOOL JumpTextScript(int no)
{ {
//Set state //Set state
gTS.mode = 1; gTS.mode = 1;
@ -242,23 +260,26 @@ bool JumpTextScript(int no)
} }
//Find where event starts //Find where event starts
for (gTS.p_read = 0; ; gTS.p_read++) gTS.p_read = 0;
while(1)
{ {
//Check if we are still in the proper range //Check if we are still in the proper range
if (!gTS.data[gTS.p_read]) if (gTS.data[gTS.p_read] == '\0')
return false; return FALSE;
//Check if we are at an event //Check if we are at an event
if (gTS.data[gTS.p_read] != '#') if (gTS.data[gTS.p_read] == '#')
continue; {
//Check if this is our event //Check if this is our event
int event_no = GetTextScriptNo(++gTS.p_read); int event_no = GetTextScriptNo(++gTS.p_read);
if (no == event_no) if (no == event_no)
break; break;
if (no < event_no) if (no < event_no)
return false; return FALSE;
}
++gTS.p_read;
} }
//Advance until new-line //Advance until new-line
@ -266,7 +287,7 @@ bool JumpTextScript(int no)
++gTS.p_read; ++gTS.p_read;
++gTS.p_read; ++gTS.p_read;
return true; return TRUE;
} }
//End event //End event
@ -282,7 +303,7 @@ void StopTextScript()
//Prepare a new line //Prepare a new line
void CheckNewLine() void CheckNewLine()
{ {
if (gTS.ypos_line[gTS.line % 4] == 48) if (gTS.ypos_line[gTS.line % 4] == '0')
{ {
gTS.mode = 3; gTS.mode = 3;
g_GameFlags |= 4; g_GameFlags |= 4;
@ -305,24 +326,24 @@ void SetNumberTextScript(int index)
int b; int b;
char str[5]; char str[5];
bool bZero = false; BOOL bZero = false;
int offset = 0; int offset = 0;
//Trim leading zeroes
for (int i = 0; i < 3; i++) for (int i = 0; i < 3; i++)
{ {
if (a / table[i] || bZero) if (a / table[i] || bZero != FALSE)
{ {
//Do whatever the fuck this is
b = a / table[i]; b = a / table[i];
str[offset] = b + 0x30; str[offset] = (char)b + '0';
bZero = true; bZero = TRUE;
a -= b * table[i]; a -= b * table[i];
++offset; ++offset;
} }
} }
//Set last digit of string, and add null terminator //Set last digit of string, and add null terminator
str[offset] = a + 0x30; str[offset] = a + '0';
str[offset + 1] = 0; str[offset + 1] = 0;
//Append number to line //Append number to line
@ -336,7 +357,7 @@ void SetNumberTextScript(int index)
//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) //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 += strlen(str); gTS.p_write += strlen(str);
if (gTS.p_write > 34) if (gTS.p_write >= 35)
{ {
gTS.p_write = 0; gTS.p_write = 0;
gTS.line++; gTS.line++;
@ -362,18 +383,22 @@ void ClearTextLine()
//Draw textbox and whatever else //Draw textbox and whatever else
void PutTextScript() void PutTextScript()
{ {
if (gTS.mode && (gTS.flags & 1)) if (gTS.mode == 0)
{ return;
if ((gTS.flags & 1) == 0)
return;
//Set textbox position //Set textbox position
if (gTS.flags & 0x20) if (gTS.flags & 0x20)
{ {
gTS.rcText.top = 32; gTS.rcText.top = 32;
gTS.rcText.bottom = 80; gTS.rcText.bottom = gTS.rcText.top + 48;
} }
else else
{ {
gTS.rcText.top = WINDOW_HEIGHT - 56; gTS.rcText.top = WINDOW_HEIGHT - 56;
gTS.rcText.bottom = WINDOW_HEIGHT - 8; gTS.rcText.bottom = gTS.rcText.top + 48;
} }
//Draw textbox //Draw textbox
@ -383,21 +408,21 @@ void PutTextScript()
RECT rcFrame2 = {0, 8, 244, 16}; RECT rcFrame2 = {0, 8, 244, 16};
RECT rcFrame3 = {0, 16, 244, 24}; RECT rcFrame3 = {0, 16, 244, 24};
PutBitmap3(&grcFull, gTS.rcText.left - 14, gTS.rcText.top - 10, &rcFrame1, 26); PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, gTS.rcText.top - 10, &rcFrame1, 26);
int i; int i;
for (i = 1; i < 7; i++) for (i = 1; i < 7; i++)
PutBitmap3(&grcFull, gTS.rcText.left - 14, 8 * i + gTS.rcText.top - 10, &rcFrame2, 26); PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, 8 * i + gTS.rcText.top - 10, &rcFrame2, 26);
PutBitmap3(&grcFull, gTS.rcText.left - 14, 8 * i + gTS.rcText.top - 10, &rcFrame3, 26); PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, 8 * i + gTS.rcText.top - 10, &rcFrame3, 26);
} }
//Draw face picture //Draw face picture
RECT rcFace; RECT rcFace;
rcFace.left = 48 * (gTS.face % 6); rcFace.left = 48 * (gTS.face % 6);
rcFace.top = 48 * (gTS.face / 6); rcFace.top = 48 * (gTS.face / 6);
rcFace.right = 48 * (gTS.face % 6) + 48; rcFace.right = rcFace.left + 48;
rcFace.bottom = 48 * (gTS.face / 6) + 48; rcFace.bottom = rcFace.top + 48;
if (gTS.face_x < (gTS.rcText.left << 9)) if (gTS.face_x < (TEXT_LEFT * 0x200))
gTS.face_x += 0x1000; gTS.face_x += 0x1000;
PutBitmap3(&gTS.rcText, gTS.face_x / 0x200, gTS.rcText.top - 3, &rcFace, 27); PutBitmap3(&gTS.rcText, gTS.face_x / 0x200, gTS.rcText.top - 3, &rcFace, 27);
@ -409,14 +434,14 @@ void PutTextScript()
text_offset = 0; text_offset = 0;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
PutBitmap3(&gTS.rcText, text_offset + gTS.rcText.left, gTS.offsetY + gTS.ypos_line[i] + gTS.rcText.top, &gRect_line, i + 30); PutBitmap3(&gTS.rcText, text_offset + TEXT_LEFT, gTS.offsetY + gTS.ypos_line[i] + gTS.rcText.top, &gRect_line, i + 30);
//Draw NOD cursor //Draw NOD cursor
if ((gTS.wait_beam++ % 20 > 12) && gTS.mode == 2) if ((gTS.wait_beam++ % 20 > 12) && gTS.mode == 2)
{ {
RECT rect; RECT rect;
rect.left = gTS.rcText.left + text_offset + 6 * gTS.p_write; rect.left = TEXT_LEFT + text_offset + 6 * gTS.p_write;
rect.top = gTS.rcText.top + gTS.ypos_line[gTS.line % 4] + gTS.offsetY; rect.top = gTS.ypos_line[gTS.line % 4] + gTS.rcText.top + gTS.offsetY;
rect.right = rect.left + 5; rect.right = rect.left + 5;
rect.bottom = rect.top + 11; rect.bottom = rect.top + 11;
CortBox(&rect, 0xFFFFFE); CortBox(&rect, 0xFFFFFE);
@ -442,21 +467,21 @@ void PutTextScript()
++gTS.item_y; ++gTS.item_y;
RECT rect; RECT rect;
if (gTS.item >= 1000) if (gTS.item < 1000)
{ {
rect.left = 32 * ((gTS.item - 1000) % 8); rect.left = 16 * (gTS.item % 16);
rect.right = 32 * ((gTS.item - 1000) % 8) + 32; rect.right = rect.left + 16;
rect.top = 16 * ((gTS.item - 1000) / 8); rect.top = 16 * (gTS.item / 16);
rect.bottom = 16 * ((gTS.item - 1000) / 8) + 16; rect.bottom = rect.top + 16;
PutBitmap3(&grcFull, (WINDOW_WIDTH - 40) / 2, gTS.item_y, &rect, 8); PutBitmap3(&grcFull, (WINDOW_WIDTH - 24) / 2, gTS.item_y, &rect, 12);
} }
else else
{ {
rect.left = 16 * (gTS.item % 16); rect.left = 32 * ((gTS.item - 1000) % 8);
rect.right = 16 * (gTS.item % 16) + 16; rect.right = rect.left + 32;
rect.top = 16 * (gTS.item / 16); rect.top = 16 * ((gTS.item - 1000) / 8);
rect.bottom = 16 * (gTS.item / 16) + 16; rect.bottom = rect.top + 16;
PutBitmap3(&grcFull, (WINDOW_WIDTH - 24) / 2, gTS.item_y, &rect, 12); PutBitmap3(&grcFull, (WINDOW_WIDTH - 40) / 2, gTS.item_y, &rect, 8);
} }
} }
@ -464,19 +489,18 @@ void PutTextScript()
RECT rect_yesno = {152, 48, 244, 80}; RECT rect_yesno = {152, 48, 244, 80};
RECT rect_cur = {112, 88, 128, 104}; RECT rect_cur = {112, 88, 128, 104};
if (gTS.mode == 6 ) if (gTS.mode == 6)
{ {
int i; int i;
if (gTS.wait > 1) if (gTS.wait < 2)
i = WINDOW_HEIGHT - 96; i = (WINDOW_HEIGHT - 96) + (2 - gTS.wait) * 4;
else else
i = WINDOW_HEIGHT - 88 - gTS.wait * 4; i = WINDOW_HEIGHT - 96;
PutBitmap3(&grcFull, (WINDOW_WIDTH + 112) / 2, i, &rect_yesno, 26); PutBitmap3(&grcFull, (WINDOW_WIDTH + 112) / 2, i, &rect_yesno, 26);
if (gTS.wait == 16) if (gTS.wait == 16)
PutBitmap3(&grcFull, 41 * gTS.select + (WINDOW_WIDTH + 102) / 2, WINDOW_HEIGHT - 86, &rect_cur, 26); PutBitmap3(&grcFull, 41 * gTS.select + (WINDOW_WIDTH + 102) / 2, WINDOW_HEIGHT - 86, &rect_cur, 26);
} }
}
} }
//Parse TSC //Parse TSC
@ -484,7 +508,7 @@ int TextScriptProc()
{ {
RECT rcSymbol = {64, 48, 72, 56}; RECT rcSymbol = {64, 48, 72, 56};
bool bExit; BOOL bExit;
switch (gTS.mode) switch (gTS.mode)
{ {
@ -502,111 +526,11 @@ int TextScriptProc()
//Parsing time //Parsing time
int w, x, y, z; int w, x, y, z;
bExit = false; bExit = FALSE;
while (!bExit) while (bExit == FALSE)
{ {
if (gTS.data[gTS.p_read] != '<') if (gTS.data[gTS.p_read] == '<')
{
if (gTS.data[gTS.p_read] == '\r')
{
//Go to new-line
gTS.p_read += 2;
gTS.p_write = 0;
if (gTS.flags & 1)
{
++gTS.line;
CheckNewLine();
}
}
else if (gTS.flags & 0x10)
{
//SAT/CAT/TUR printing
for (x = gTS.p_read; ; x++)
{
//Break if reaches command, or new-line
if (gTS.data[x] == '<' || gTS.data[x] == '\r')
break;
//Skip if SHIFT-JIS
if (gTS.data[x] & 0x80)
++x;
}
//Get text to copy
char str[72];
int length = x - gTS.p_read;
memcpy(str, &gTS.data[gTS.p_read], length);
str[length] = 0;
gTS.p_write = x;
//Print text
PutText2(0, 0, str, 0xFFFFFE, gTS.line % 4 + 30);
sprintf(&text[gTS.line % 4 * 0x40], str);
//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_read += length;
if (gTS.p_write > 34)
CheckNewLine();
bExit = true;
}
else
{
//Get text to print
char c[3];
c[0] = gTS.data[gTS.p_read];
if (!(c[0] & 0x80))
{
c[1] = 0;
}
else
{
c[1] = gTS.data[gTS.p_read + 1];
c[2] = 0;
}
//Print text
if (c[0] == '=')
{
Surface2Surface(6 * gTS.p_write, 2, &rcSymbol, gTS.line % 4 + 30, 26);
}
else
{
PutText2(6 * gTS.p_write, 0, c, 0xFFFFFE, gTS.line % 4 + 30);
}
strcat(&text[gTS.line % 4 * 0x40], c);
PlaySoundObject(2, 1);
gTS.wait_beam = 0;
//Offset read and write positions
if (!(c[0] & 0x80))
{
gTS.p_read++;
gTS.p_write++;
}
else
{
gTS.p_read += 2;
gTS.p_write += 2;
}
if (gTS.p_write > 34)
{
CheckNewLine();
gTS.p_write = 0;
++gTS.line;
CheckNewLine();
}
bExit = true;
}
}
else
{ {
if (IS_COMMAND('E','N','D')) if (IS_COMMAND('E','N','D'))
{ {
@ -614,7 +538,7 @@ int TextScriptProc()
gMC.cond &= ~1; gMC.cond &= ~1;
g_GameFlags |= 3; g_GameFlags |= 3;
gTS.face = 0; gTS.face = 0;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('L','I','+')) else if (IS_COMMAND('L','I','+'))
{ {
@ -724,7 +648,7 @@ int TextScriptProc()
{ {
x = GetTextScriptNo(gTS.p_read + 4); x = GetTextScriptNo(gTS.p_read + 4);
y = GetTextScriptNo(gTS.p_read + 9); y = GetTextScriptNo(gTS.p_read + 9);
SetMyCharPosition(x << 13, y << 13); SetMyCharPosition(x * 0x200 * 0x10, y * 0x200 * 0x10);
gTS.p_read += 13; gTS.p_read += 13;
} }
else if (IS_COMMAND('H','M','C')) else if (IS_COMMAND('H','M','C'))
@ -784,7 +708,7 @@ int TextScriptProc()
{ {
gTS.mode = 2; gTS.mode = 2;
gTS.p_read += 4; gTS.p_read += 4;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('C','L','R')) else if (IS_COMMAND('C','L','R'))
{ {
@ -799,41 +723,41 @@ int TextScriptProc()
if (gTS.flags & 0x40) if (gTS.flags & 0x40)
gTS.flags |= 0x10; gTS.flags |= 0x10;
gTS.p_read += 4; gTS.p_read += 4;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('M','S','2')) else if (IS_COMMAND('M','S','2'))
{ {
ClearTextLine(); ClearTextLine();
gTS.flags |= 0x21;
gTS.flags &= ~0x12; gTS.flags &= ~0x12;
gTS.flags |= 0x21;
if (gTS.flags & 0x40) if (gTS.flags & 0x40)
gTS.flags |= 0x10; gTS.flags |= 0x10;
gTS.face = 0; gTS.face = 0;
gTS.p_read += 4; gTS.p_read += 4;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('M','S','3')) else if (IS_COMMAND('M','S','3'))
{ {
ClearTextLine(); ClearTextLine();
gTS.flags |= 0x23;
gTS.flags &= ~0x10; gTS.flags &= ~0x10;
gTS.flags |= 0x23;
if (gTS.flags & 0x40) if (gTS.flags & 0x40)
gTS.flags |= 0x10; gTS.flags |= 0x10;
gTS.p_read += 4; gTS.p_read += 4;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('W','A','I')) else if (IS_COMMAND('W','A','I'))
{ {
gTS.mode = 4; gTS.mode = 4;
gTS.wait_next = GetTextScriptNo(gTS.p_read + 4); gTS.wait_next = GetTextScriptNo(gTS.p_read + 4);
gTS.p_read += 8; gTS.p_read += 8;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('W','A','S')) else if (IS_COMMAND('W','A','S'))
{ {
gTS.mode = 7; gTS.mode = 7;
gTS.p_read += 4; gTS.p_read += 4;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('T','U','R')) else if (IS_COMMAND('T','U','R'))
{ {
@ -868,7 +792,7 @@ int TextScriptProc()
PlaySoundObject(5, 1); PlaySoundObject(5, 1);
gTS.wait = 0; gTS.wait = 0;
gTS.select = 0; gTS.select = 0;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('F','L','J')) else if (IS_COMMAND('F','L','J'))
{ {
@ -959,7 +883,7 @@ int TextScriptProc()
else if (IS_COMMAND('S','P','S')) else if (IS_COMMAND('S','P','S'))
{ {
SetNoise(2, x); SetNoise(2, x);
gTS.p_read += 8; gTS.p_read += 4;
} }
else if (IS_COMMAND('C','P','S')) else if (IS_COMMAND('C','P','S'))
{ {
@ -983,7 +907,7 @@ int TextScriptProc()
StartFadeIn(z); StartFadeIn(z);
gTS.mode = 5; gTS.mode = 5;
gTS.p_read += 8; gTS.p_read += 8;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('F','A','O')) else if (IS_COMMAND('F','A','O'))
{ {
@ -991,7 +915,7 @@ int TextScriptProc()
StartFadeOut(z); StartFadeOut(z);
gTS.mode = 5; gTS.mode = 5;
gTS.p_read += 8; gTS.p_read += 8;
bExit = true; bExit = TRUE;
} }
else if (IS_COMMAND('M','N','A')) else if (IS_COMMAND('M','N','A'))
{ {
@ -1043,23 +967,27 @@ int TextScriptProc()
else if (IS_COMMAND('M','L','P')) else if (IS_COMMAND('M','L','P'))
{ {
gTS.p_read += 4; gTS.p_read += 4;
bExit = true; bExit = TRUE;
int tscRet = MiniMapLoop(); switch (MiniMapLoop())
if (tscRet == 0) {
case 0:
return 0; return 0;
if (tscRet == 2) case 2:
return 2; return 2;
} }
}
else if (IS_COMMAND('S','L','P')) else if (IS_COMMAND('S','L','P'))
{ {
bExit = true; bExit = TRUE;
int selRet = StageSelectLoop(&z); switch (StageSelectLoop(&z))
if (selRet == 0) {
case 0:
return 0; return 0;
if (selRet == 2) case 2:
return 2; return 2;
}
JumpTextScript(z); JumpTextScript(z);
g_GameFlags &= ~3; g_GameFlags &= ~3;
@ -1112,7 +1040,7 @@ int TextScriptProc()
x = GetTextScriptNo(gTS.p_read + 9); x = GetTextScriptNo(gTS.p_read + 9);
y = GetTextScriptNo(gTS.p_read + 14); y = GetTextScriptNo(gTS.p_read + 14);
z = GetTextScriptNo(gTS.p_read + 19); z = GetTextScriptNo(gTS.p_read + 19);
SetNpChar(w, x << 13, y << 13, 0, 0, z, 0, 0x100); SetNpChar(w, x * 0x200 * 0x10, y * 0x200 * 0x10, 0, 0, z, 0, 0x100);
gTS.p_read += 23; gTS.p_read += 23;
} }
else if (IS_COMMAND('M','N','P')) else if (IS_COMMAND('M','N','P'))
@ -1121,7 +1049,7 @@ int TextScriptProc()
x = GetTextScriptNo(gTS.p_read + 9); x = GetTextScriptNo(gTS.p_read + 9);
y = GetTextScriptNo(gTS.p_read + 14); y = GetTextScriptNo(gTS.p_read + 14);
z = GetTextScriptNo(gTS.p_read + 19); z = GetTextScriptNo(gTS.p_read + 19);
MoveNpChar(w, x << 13, y << 13, z); MoveNpChar(w, x * 0x200 * 0x10, y * 0x200 * 0x10, z);
gTS.p_read += 23; gTS.p_read += 23;
} }
else if (IS_COMMAND('S','M','P')) else if (IS_COMMAND('S','M','P'))
@ -1185,20 +1113,20 @@ int TextScriptProc()
else if (IS_COMMAND('F','A','C')) else if (IS_COMMAND('F','A','C'))
{ {
z = GetTextScriptNo(gTS.p_read + 4); z = GetTextScriptNo(gTS.p_read + 4);
if (gTS.face != z) if (gTS.face != (signed char)z)
{ {
gTS.face = z; gTS.face = (signed char)z;
gTS.face_x = (gTS.rcText.left - 48) << 9; gTS.face_x = (WINDOW_WIDTH / 2 - 156) * 0x200;
} }
gTS.p_read += 8; gTS.p_read += 8;
} }
else if (IS_COMMAND('F','A','C')) else if (IS_COMMAND('F','A','C'))
{ {
z = GetTextScriptNo(gTS.p_read + 4); z = GetTextScriptNo(gTS.p_read + 4);
if (gTS.face != z) if (gTS.face != (signed char)z)
{ {
gTS.face = z; gTS.face = (signed char)z;
gTS.face_x = (gTS.rcText.left - 48) << 9; gTS.face_x = (WINDOW_WIDTH / 2 - 156) * 0x200;
} }
gTS.p_read += 8; gTS.p_read += 8;
} }
@ -1234,13 +1162,17 @@ int TextScriptProc()
} }
else if (IS_COMMAND('X','X','1')) else if (IS_COMMAND('X','X','1'))
{ {
bExit = true; bExit = TRUE;
z = GetTextScriptNo(gTS.p_read + 4); z = GetTextScriptNo(gTS.p_read + 4);
int islRet = Scene_DownIsland(z);
if (islRet == 0) switch (Scene_DownIsland(z))
{
case 0:
return 0; return 0;
if (islRet == 2) case 2:
return 2; return 2;
}
gTS.p_read += 8; gTS.p_read += 8;
} }
else if (IS_COMMAND('E','S','C')) else if (IS_COMMAND('E','S','C'))
@ -1254,6 +1186,107 @@ int TextScriptProc()
return 1; return 1;
} }
} }
else
{
if (gTS.data[gTS.p_read] == '\r')
{
//Go to new-line
gTS.p_read += 2;
gTS.p_write = 0;
if (gTS.flags & 1)
{
++gTS.line;
CheckNewLine();
}
}
else if (gTS.flags & 0x10)
{
//SAT/CAT/TUR printing
x = gTS.p_read;
//Break if reaches command, or new-line
while (gTS.data[x] != '<' && gTS.data[x] != '\r')
{
//Skip if SHIFT-JIS
if (gTS.data[x] & 0x80)
++x;
++x;
}
//Get text to copy
char str[72];
int length = x - gTS.p_read;
memcpy(str, &gTS.data[gTS.p_read], length);
str[length] = 0;
gTS.p_write = x;
//Print text
PutText2(0, 0, str, 0xFFFFFE, gTS.line % 4 + 30);
sprintf(&text[gTS.line % 4 * 0x40], str);
//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_read += length;
if (gTS.p_write >= 35)
CheckNewLine();
bExit = TRUE;
}
else
{
//Get text to print
char c[3];
c[0] = gTS.data[gTS.p_read];
if (c[0] & 0x80)
{
c[1] = gTS.data[gTS.p_read + 1];
c[2] = 0;
}
else
{
c[1] = 0;
}
//Print text
if (c[0] == '=')
{
Surface2Surface(6 * gTS.p_write, 2, &rcSymbol, gTS.line % 4 + 30, 26);
}
else
{
PutText2(6 * gTS.p_write, 0, c, 0xFFFFFE, gTS.line % 4 + 30);
}
strcat(&text[gTS.line % 4 * 0x40], c);
PlaySoundObject(2, 1);
gTS.wait_beam = 0;
//Offset read and write positions
if (c[0] & 0x80)
{
gTS.p_read += 2;
gTS.p_write += 2;
}
else
{
gTS.p_read++;
gTS.p_write++;
}
if (gTS.p_write >= 35)
{
CheckNewLine();
gTS.p_write = 0;
++gTS.line;
CheckNewLine();
}
bExit = TRUE;
}
}
} }
break; break;
@ -1276,35 +1309,39 @@ int TextScriptProc()
break; break;
case 4: //WAI case 4: //WAI
if (gTS.wait_next != 9999) if (gTS.wait_next == 9999)
{ break;
if (gTS.wait != 9999) if (gTS.wait != 9999)
++gTS.wait; ++gTS.wait;
if (gTS.wait >= gTS.wait_next) if (gTS.wait < gTS.wait_next)
{ break;
gTS.mode = 1; gTS.mode = 1;
gTS.wait_beam = 0; gTS.wait_beam = 0;
}
}
break; break;
case 5: //FAI/FAO case 5: //FAI/FAO
if (!GetFadeActive()) if (GetFadeActive())
{ break;
gTS.mode = 1; gTS.mode = 1;
gTS.wait_beam = 0; gTS.wait_beam = 0;
}
break; break;
case 7: //WAS case 7: //WAS
if (gMC.flag & 8) if ((gMC.flag & 8) == 0)
{ break;
gTS.mode = 1; gTS.mode = 1;
gTS.wait_beam = 0; gTS.wait_beam = 0;
}
break; break;
case 6: //YNJ case 6: //YNJ
if (gTS.wait >= 16) if (gTS.wait < 16)
{
gTS.wait++;
}
else
{ {
//Select option //Select option
if (gKeyTrg & gKeyOk) if (gKeyTrg & gKeyOk)
@ -1334,16 +1371,12 @@ int TextScriptProc()
PlaySoundObject(1, 1); PlaySoundObject(1, 1);
} }
} }
else
{
gTS.wait++;
}
break; break;
} }
if (gTS.mode) if (gTS.mode == 0)
g_GameFlags |= 4;
else
g_GameFlags &= ~4; g_GameFlags &= ~4;
else
g_GameFlags |= 4;
return 1; return 1;
} }

View file

@ -54,13 +54,13 @@ struct TEXT_SCRIPT
uint8_t wait_beam; uint8_t wait_beam;
}; };
bool InitTextScript2(); BOOL InitTextScript2();
void EndTextScript(); void EndTextScript();
void EncryptionBinaryData2(uint8_t *pData, int size); void EncryptionBinaryData2(uint8_t *pData, int size);
bool LoadTextScript2(const char *name); bool LoadTextScript2(const char *name);
bool LoadTextScript_Stage(char *name); bool LoadTextScript_Stage(char *name);
void GetTextScriptPath(char *path); void GetTextScriptPath(char *path);
bool StartTextScript(int no); BOOL StartTextScript(int no);
void StopTextScript(); void StopTextScript();
void PutTextScript(); void PutTextScript();
int TextScriptProc(); int TextScriptProc();