From d5dd2c9575fdf08192b78a0f6a55931bb7d02339 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Mon, 13 May 2019 23:51:11 +0100 Subject: [PATCH] Made TextScr.cpp almost ASM-accurate TextScriptProc is all that's left, but it's being a pain, so I'm commiting this now, and dealing with the straggler later. --- msvc2003/devilution/comparer-config.toml | 56 ++++++++++++++ src/Draw.cpp | 6 +- src/Draw.h | 2 +- src/GenericLoad.cpp | 20 ++--- src/TextScr.cpp | 93 ++++++++++++++---------- src/TextScr.h | 2 +- 6 files changed, 126 insertions(+), 53 deletions(-) diff --git a/msvc2003/devilution/comparer-config.toml b/msvc2003/devilution/comparer-config.toml index 6225ee1b..e5ca6738 100644 --- a/msvc2003/devilution/comparer-config.toml +++ b/msvc2003/devilution/comparer-config.toml @@ -1062,6 +1062,62 @@ addr = 0x421040 name = "PutStar" addr = 0x4213B0 +[[func]] +name = "InitTextScript2" +addr = 0x4214E0 + +[[func]] +name = "EndTextScript" +addr = 0x421570 + +[[func]] +name = "EncryptionBinaryData2" +addr = 0x4215C0 + +[[func]] +name = "LoadTextScript2" +addr = 0x421660 + +[[func]] +name = "LoadTextScript_Stage" +addr = 0x421750 + +[[func]] +name = "GetTextScriptPath" +addr = 0x4218E0 + +[[func]] +name = "GetTextScriptNo" +addr = 0x421900 + +[[func]] +name = "StartTextScript" +addr = 0x421990 + +[[func]] +name = "JumpTextScript" +addr = 0x421AF0 + +[[func]] +name = "StopTextScript" +addr = 0x421C50 + +[[func]] +name = "CheckNewLine" +addr = 0x421C80 + +[[func]] +name = "SetNumberTextScript" +addr = 0x421D10 + +[[func]] +name = "ClearTextLine" +addr = 0x421E90 + +[[func]] +name = "PutTextScript" +addr = 0x421F10 + [[func]] name = "TextScriptProc" addr = 0x422510 diff --git a/src/Draw.cpp b/src/Draw.cpp index 18744f41..44c28157 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -153,8 +153,10 @@ void ReleaseSurface(int s) } } -BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no) +BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSystem) { + (void)bSystem; + BOOL success = FALSE; #ifdef FIX_BUGS @@ -253,7 +255,7 @@ static bool LoadBitmap(SDL_RWops *fp, Surface_Ids surf_no, bool create_surface) } else { - if (create_surface == false || MakeSurface_Generic(surface->w, surface->h, surf_no)) + if (create_surface == false || MakeSurface_Generic(surface->w, surface->h, surf_no, FALSE)) { if (magnification == 1) { diff --git a/src/Draw.h b/src/Draw.h index abe3269f..4542f4b9 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -60,7 +60,7 @@ BOOL MakeSurface_File(const char *name, Surface_Ids surf_no); BOOL MakeSurface_Resource(const char *res, Surface_Ids surf_no); BOOL ReloadBitmap_File(const char *name, Surface_Ids surf_no); BOOL ReloadBitmap_Resource(const char *res, Surface_Ids surf_no); -BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no); +BOOL MakeSurface_Generic(int bxsize, int bysize, Surface_Ids surf_no, BOOL bSystem); void BackupSurface(Surface_Ids surf_no, RECT *rect); void PutBitmap3(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no); void PutBitmap4(RECT *rcView, int x, int y, RECT *rect, Surface_Ids surf_no); diff --git a/src/GenericLoad.cpp b/src/GenericLoad.cpp index d9d4eb58..eb22e3e6 100644 --- a/src/GenericLoad.cpp +++ b/src/GenericLoad.cpp @@ -197,16 +197,16 @@ BOOL LoadGenericData() } else { - MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_SCREEN_GRAB); - MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_LEVEL_BACKGROUND); - MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_MAP); - MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_CASTS); - MakeSurface_Generic(256, 256, SURFACE_ID_LEVEL_TILESET); - MakeSurface_Generic(160, 16, SURFACE_ID_ROOM_NAME); - MakeSurface_Generic(40, 240, SURFACE_ID_VALUE_VIEW); - MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1); - MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2); - MakeSurface_Generic(WINDOW_WIDTH, 16 * MAX_STRIP, SURFACE_ID_CREDIT_CAST); + MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_SCREEN_GRAB, TRUE); + MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_LEVEL_BACKGROUND, FALSE); + MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_MAP, TRUE); + MakeSurface_Generic(WINDOW_WIDTH, WINDOW_HEIGHT, SURFACE_ID_CASTS, FALSE); + MakeSurface_Generic(256, 256, SURFACE_ID_LEVEL_TILESET, FALSE); + MakeSurface_Generic(160, 16, SURFACE_ID_ROOM_NAME, FALSE); + MakeSurface_Generic(40, 240, SURFACE_ID_VALUE_VIEW, FALSE); + MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_1, FALSE); + MakeSurface_Generic(320, 240, SURFACE_ID_LEVEL_SPRITESET_2, FALSE); + MakeSurface_Generic(WINDOW_WIDTH, 16 * MAX_STRIP, SURFACE_ID_CREDIT_CAST, FALSE); pt_size = 0; pt_size += MakePixToneObject(&gPtpTable[0], 2, 32); diff --git a/src/TextScr.cpp b/src/TextScr.cpp index b5a7bad7..e4f2f112 100644 --- a/src/TextScr.cpp +++ b/src/TextScr.cpp @@ -65,7 +65,7 @@ BOOL InitTextScript2() //Create line surfaces for (int i = 0; i < 4; i++) - MakeSurface_Generic(gRect_line.right, gRect_line.bottom, (Surface_Ids)(i + SURFACE_ID_TEXT_LINE1)); + MakeSurface_Generic(gRect_line.right, gRect_line.bottom, (Surface_Ids)(i + SURFACE_ID_TEXT_LINE1), FALSE); //Clear text memset(text, 0, sizeof(text)); @@ -94,6 +94,8 @@ void EndTextScript() void EncryptionBinaryData2(unsigned char *pData, int size) { int val1; + int work; + int i; int half = size / 2; if (pData[half] == 0) @@ -101,9 +103,9 @@ void EncryptionBinaryData2(unsigned char *pData, int size) else val1 = (pData[half] % 256) * -1; - for (int i = 0; i < size; i++) + for (i = 0; i < size; i++) { - int work = pData[i]; + work = pData[i]; work += val1; if (i != half) @@ -220,7 +222,7 @@ BOOL StartTextScript(int no) gTS.rcText.left = TEXT_LEFT; gTS.rcText.top = WINDOW_HEIGHT - 56; - gTS.rcText.right = WINDOW_WIDTH + 108; + gTS.rcText.right = WINDOW_WIDTH - TEXT_LEFT; 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) @@ -337,6 +339,13 @@ void CheckNewLine() //Type a number into the text buffer void SetNumberTextScript(int index) { + int a; + int b; + int i; + BOOL bZero; + int offset; + char str[5]; + //Get digit table int table[3]; table[0] = 1000; @@ -344,15 +353,13 @@ void SetNumberTextScript(int index) table[2] = 10; //Get number to print - int a = gNumberTextScript[index]; - int b; + a = gNumberTextScript[index]; - char str[5]; - BOOL bZero = false; - int offset = 0; + bZero = FALSE; + offset = 0; //Trim leading zeroes - for (int i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { if (a / table[i] || bZero != FALSE) { @@ -365,7 +372,7 @@ void SetNumberTextScript(int index) } //Set last digit of string, and add null terminator - str[offset] = a + '0'; + str[offset] = (char)a + '0'; str[offset + 1] = 0; //Append number to line @@ -405,6 +412,18 @@ void ClearTextLine() //Draw textbox and whatever else void PutTextScript() { + RECT rcFace; + RECT rcItemBox1; + RECT rcItemBox2; + RECT rcItemBox3; + RECT rcItemBox4; + RECT rcItemBox5; + int i; + RECT rect_yesno; + RECT rect_cur; + RECT rect; + int text_offset; + if (gTS.mode == 0) return; @@ -431,14 +450,12 @@ void PutTextScript() RECT rcFrame3 = {0, 16, 244, 24}; PutBitmap3(&grcFull, WINDOW_WIDTH / 2 - 122, gTS.rcText.top - 10, &rcFrame1, SURFACE_ID_TEXT_BOX); - int i; 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); } //Draw face picture - RECT rcFace; rcFace.left = 48 * (gTS.face % 6); rcFace.top = 48 * (gTS.face / 6); rcFace.right = rcFace.left + 48; @@ -446,23 +463,22 @@ void PutTextScript() if (gTS.face_x < (TEXT_LEFT * 0x200)) gTS.face_x += 0x1000; + PutBitmap3(&gTS.rcText, gTS.face_x / 0x200, gTS.rcText.top - 3, &rcFace, SURFACE_ID_FACE); //Draw text - int text_offset; if (gTS.face) text_offset = 56; else text_offset = 0; - for (int i = 0; i < 4; i++) + for (i = 0; i < 4; i++) PutBitmap3(&gTS.rcText, text_offset + TEXT_LEFT, gTS.offsetY + gTS.ypos_line[i] + gTS.rcText.top, &gRect_line, (Surface_Ids)(i + SURFACE_ID_TEXT_LINE1)); //Draw NOD cursor if ((gTS.wait_beam++ % 20 > 12) && gTS.mode == 2) { - RECT rect; - rect.left = TEXT_LEFT + text_offset + 6 * gTS.p_write; + rect.left = TEXT_LEFT + 6 * gTS.p_write + 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; @@ -482,11 +498,11 @@ void PutTextScript() } //Draw GIT - RECT rcItemBox1 = {0, 0, 72, 16}; - RECT rcItemBox2 = {0, 8, 72, 24}; - RECT rcItemBox3 = {240, 0, 244, 8}; - RECT rcItemBox4 = {240, 8, 244, 16}; - RECT rcItemBox5 = {240, 16, 244, 24}; + SET_RECT(rcItemBox1, 0, 0, 72, 16) + SET_RECT(rcItemBox2, 0, 8, 72, 24) + SET_RECT(rcItemBox3, 240, 0, 244, 8) + SET_RECT(rcItemBox4, 240, 8, 244, 16) + SET_RECT(rcItemBox5, 240, 16, 244, 24) if (gTS.item) { @@ -500,7 +516,6 @@ void PutTextScript() if (gTS.item_y < WINDOW_HEIGHT - 104) ++gTS.item_y; - RECT rect; if (gTS.item < 1000) { rect.left = 16 * (gTS.item % 16); @@ -520,12 +535,11 @@ void PutTextScript() } //Draw Yes / No selection - RECT rect_yesno = {152, 48, 244, 80}; - RECT rect_cur = {112, 88, 128, 104}; + SET_RECT(rect_yesno, 152, 48, 244, 80) + SET_RECT(rect_cur, 112, 88, 128, 104) if (gTS.mode == 6) { - int i; if (gTS.wait < 2) i = (WINDOW_HEIGHT - 96) + (2 - gTS.wait) * 4; else @@ -540,9 +554,13 @@ void PutTextScript() //Parse TSC int TextScriptProc() { - RECT rcSymbol = {64, 48, 72, 56}; - BOOL bExit; + char c[3]; + int w, x, y, z; + int i; + int length; + + RECT rcSymbol = {64, 48, 72, 56}; switch (gTS.mode) { @@ -559,7 +577,6 @@ int TextScriptProc() gTS.wait = 0; //Parsing time - int w, x, y, z; bExit = FALSE; while (bExit == FALSE) @@ -607,13 +624,13 @@ int TextScriptProc() else if (IS_COMMAND('E','Q','+')) { z = GetTextScriptNo(gTS.p_read + 4); - EquipItem(z, true); + EquipItem(z, TRUE); gTS.p_read += 8; } else if (IS_COMMAND('E','Q','-')) { z = GetTextScriptNo(gTS.p_read + 4); - EquipItem(z, false); + EquipItem(z, FALSE); gTS.p_read += 8; } else if (IS_COMMAND('A','M','+')) @@ -696,12 +713,12 @@ int TextScriptProc() } else if (IS_COMMAND('H','M','C')) { - ShowMyChar(false); + ShowMyChar(FALSE); gTS.p_read += 4; } else if (IS_COMMAND('S','M','C')) { - ShowMyChar(true); + ShowMyChar(TRUE); gTS.p_read += 4; } else if (IS_COMMAND('F','L','+')) @@ -732,7 +749,7 @@ int TextScriptProc() { g_GameFlags &= ~2; g_GameFlags |= 1; - gMC.up = false; + gMC.up = FALSE; gMC.shock = 0; gTS.p_read += 4; } @@ -1225,7 +1242,6 @@ int TextScriptProc() else { char str_0[0x40]; - #ifdef JAPANESE sprintf(str_0, "不明のコード:<%c%c%c", gTS.data[gTS.p_read + 1], gTS.data[gTS.p_read + 2], gTS.data[gTS.p_read + 3]); SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "エラー", str_0, NULL); @@ -1256,6 +1272,7 @@ int TextScriptProc() else if (gTS.flags & 0x10) { //SAT/CAT/TUR printing + char str[72]; x = gTS.p_read; //Break if reaches command, or new-line while (gTS.data[x] != '<' && gTS.data[x] != '\r') @@ -1268,8 +1285,7 @@ int TextScriptProc() } //Get text to copy - char str[72]; - int length = x - gTS.p_read; + length = x - gTS.p_read; memcpy(str, &gTS.data[gTS.p_read], length); str[length] = 0; @@ -1290,7 +1306,6 @@ int TextScriptProc() else { //Get text to print - char c[3]; c[0] = gTS.data[gTS.p_read]; if (c[0] & 0x80) @@ -1349,7 +1364,7 @@ int TextScriptProc() break; case 3: //NEW LINE - for (int i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { gTS.ypos_line[i] -= 4; diff --git a/src/TextScr.h b/src/TextScr.h index 1c87e1df..f2dfdac8 100644 --- a/src/TextScr.h +++ b/src/TextScr.h @@ -21,7 +21,7 @@ struct TEXT_SCRIPT //Current positions (read position in buffer, x position in line) unsigned int p_read; - unsigned int p_write; + int p_write; //Current line to write to int line;