Made Ending.cpp ASM-accurate

This commit is contained in:
Clownacy 2019-05-13 20:43:43 +01:00
parent d3af5e372f
commit c9d5b3d03a
13 changed files with 287 additions and 174 deletions

View file

@ -355,6 +355,70 @@ addr = 0x40AD60
name = "DefaultConfigData"
addr = 0x40AE30
[[func]]
name = "ActionStripper"
addr = 0x40CF90
[[func]]
name = "PutStripper"
addr = 0x40D010
[[func]]
name = "SetStripper"
addr = 0x40D150
[[func]]
name = "RestoreStripper"
addr = 0x40D240
[[func]]
name = "ActionIllust"
addr = 0x40D2D0
[[func]]
name = "PutIllust"
addr = 0x40D350
[[func]]
name = "ReloadIllust"
addr = 0x40D3A0
[[func]]
name = "InitCreditScript"
addr = 0x40D3E0
[[func]]
name = "ReleaseCreditScript"
addr = 0x40D410
[[func]]
name = "StartCreditScript"
addr = 0x40D440
[[func]]
name = "ActionCredit"
addr = 0x40D5C0
[[func]]
name = "ActionCredit_Read"
addr = 0x40D620
[[func]]
name = "GetScriptNumber"
addr = 0x40DB00
[[func]]
name = "SetCreditIllust"
addr = 0x40DB40
[[func]]
name = "CutCreditIllust"
addr = 0x40DB60
[[func]]
name = "Scene_DownIsland"
addr = 0x40DB70
[[func]]
name = "Call_Escape"
addr = 0x40DD70

View file

@ -391,7 +391,7 @@ int CampLoop()
if (gKeyTrg & KEY_ESCAPE)
{
switch (Call_Escape(hWnd))
switch (Call_Escape(ghWnd))
{
case 0:
return 0;
@ -433,7 +433,7 @@ int CampLoop()
}
}
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
return 0;
}

View file

@ -39,20 +39,27 @@ void ActionStripper()
// Draw casts
void PutStripper()
{
RECT rc;
for (int s = 0; s < MAX_STRIP; s++)
{
if (Strip[s].flag & 0x80)
{
// Draw text
RECT rc = {0, 16 * s, 320, 16 * s + 16};
PutBitmap3(&grcFull, (Strip[s].x + ((WINDOW_WIDTH - 320) << 8)) / 0x200, Strip[s].y / 0x200, &rc, SURFACE_ID_CREDIT_CAST);
rc.left = 0;
rc.right = 320;
rc.top = s * 0x10;
rc.bottom = rc.top + 0x10;
PutBitmap3(&grcFull, (Strip[s].x / 0x200) + ((WINDOW_WIDTH - 320) / 2), (Strip[s].y / 0x200), &rc, SURFACE_ID_CREDIT_CAST);
// Draw character
rc.left = 24 * (Strip[s].cast % 13);
rc.right = rc.left + 24;
rc.top = 24 * (Strip[s].cast / 13);
rc.bottom = rc.top + 24;
PutBitmap3(&grcFull, (Strip[s].x + ((WINDOW_WIDTH - 320) << 8)) / 0x200 - 24, Strip[s].y / 0x200 - 8, &rc, SURFACE_ID_CASTS);
PutBitmap3(&grcFull, (Strip[s].x / 0x200) + ((WINDOW_WIDTH - 320) / 2) - 24, (Strip[s].y / 0x200) - 8, &rc, SURFACE_ID_CASTS);
}
}
}
@ -60,10 +67,16 @@ void PutStripper()
// Create a cast object
void SetStripper(int x, int y, const char *text, int cast)
{
for (int s = 0; s < MAX_STRIP; s++)
{
RECT rc;
int s;
for (s = 0; s < MAX_STRIP; s++)
if (!(Strip[s].flag & 0x80))
{
break;
if (s == MAX_STRIP)
return;
// Initialize cast property
Strip[s].flag = 0x80;
Strip[s].x = x;
@ -72,22 +85,29 @@ void SetStripper(int x, int y, const char *text, int cast)
strcpy(Strip[s].str, text);
// Draw text
RECT rc = {0, 16 * s, 320, 16 * s + 16};
rc.left = 0;
rc.right = 320;
rc.top = s * 0x10;
rc.bottom = rc.top + 0x10;
CortBox2(&rc, 0, SURFACE_ID_CREDIT_CAST);
PutText2(0, 16 * s, text, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_CREDIT_CAST);
break;
}
}
PutText2(0, rc.top, text, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_CREDIT_CAST);
}
// Regenerate cast text
void RestoreStripper()
{
RECT rc;
for (int s = 0; s < MAX_STRIP; s++)
{
if (Strip[s].flag & 0x80)
{
RECT rc = {0, 16 * s, 320, 16 * s + 16};
rc.left = 0;
rc.right = 320;
rc.top = s * 0x10;
rc.bottom = rc.top + 0x10;
CortBox2(&rc, 0, SURFACE_ID_CREDIT_CAST);
PutText2(0, rc.top, Strip[s].str, RGB(0xFF, 0xFF, 0xFE), SURFACE_ID_CREDIT_CAST);
}
@ -121,8 +141,13 @@ void ActionIllust()
void PutIllust()
{
RECT rcIllust = {0, 0, 160, 240};
#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240
// Widescreen edit
RECT rcClip = {(WINDOW_WIDTH - 320) / 2, 0, WINDOW_WIDTH, WINDOW_HEIGHT};
PutBitmap3(&rcClip, (Illust.x + ((WINDOW_WIDTH - 320) << 8)) / 0x200, (WINDOW_HEIGHT - 240) / 2, &rcIllust, SURFACE_ID_CREDITS_IMAGE);
PutBitmap3(&rcClip, (Illust.x / 0x200) + ((WINDOW_WIDTH - 320) / 2), (WINDOW_HEIGHT - 240) / 2, &rcIllust, SURFACE_ID_CREDITS_IMAGE);
#else
PutBitmap3(&grcFull, (Illust.x / 0x200) + ((WINDOW_WIDTH - 320) / 2), (WINDOW_HEIGHT - 240) / 2, &rcIllust, SURFACE_ID_CREDITS_IMAGE);
#endif
}
// Load illustration
@ -151,8 +176,10 @@ void ReleaseCreditScript()
}
}
const char *credit_script = "Credit.tsc";
// Start playing credits
bool StartCreditScript()
BOOL StartCreditScript()
{
// Clear previously existing credits data
if (Credit.pData)
@ -163,22 +190,22 @@ bool StartCreditScript()
// Open file
char path[PATH_LENGTH];
sprintf(path, "%s/%s", gDataPath, "Credit.tsc");
sprintf(path, "%s/%s", gDataPath, credit_script);
Credit.size = GetFileSizeLong(path);
if (Credit.size == -1)
return false;
return FALSE;
// Allocate buffer data
Credit.pData = (char*)malloc(Credit.size);
if (Credit.pData == NULL)
return false;
return FALSE;
FILE *fp = fopen(path, "rb");
if (fp == NULL)
{
printf("Couldn't open %s", path);
return false;
free(Credit.pData);
return FALSE;
}
// Read data
@ -199,78 +226,116 @@ bool StartCreditScript()
// Modify cliprect
grcGame.left = WINDOW_WIDTH / 2;
#if WINDOW_WIDTH != 320 || WINDOW_HEIGHT != 240
// These three are non-vanilla: for wide/tallscreen support
grcGame.right = ((WINDOW_WIDTH - 320) / 2) + 320;
grcGame.top = (WINDOW_HEIGHT - 240) / 2;
grcGame.bottom = ((WINDOW_HEIGHT - 240) / 2) + 240;
#endif
// Reload casts
if (!ReloadBitmap_File("casts", SURFACE_ID_CASTS))
return false;
return FALSE;
// Clear casts
memset(Strip, 0, sizeof(Strip));
return true;
return TRUE;
}
// Get number from text (4 digit)
int GetScriptNumber(const char *text)
{
return 1000 * text[0] - 48000 +
100 * text[1] - 4800 +
10 * text[2] - 480 +
text[3] - 48;
return (text[0] - '0') * 1000 +
(text[1] - '0') * 100 +
(text[2] - '0') * 10 +
text[3] - '0';
}
// Parse credits
void ActionCredit_Read()
{
while (Credit.offset < Credit.size)
{
// Get character
unsigned char character = Credit.pData[Credit.offset];
int a, b, len;
switch (character)
char text[40];
while (1)
{
if (Credit.offset >= Credit.size)
break;
switch (Credit.pData[Credit.offset])
{
case '[': // Create cast
// Get the range for the cast text
a = ++Credit.offset;
++Credit.offset;
a = Credit.offset;
while (Credit.pData[a] != ']')
{
if (IsShiftJIS(Credit.pData[a]))
a += 2;
else
a++;
a += 1;
}
len = a - Credit.offset;
// Copy the text to the cast text
char text[40];
memcpy(text, &Credit.pData[Credit.offset], a - Credit.offset);
memcpy(text, &Credit.pData[Credit.offset], len);
text[len] = 0;
// Get cast id
Credit.offset = a + 1;
len = GetScriptNumber(&Credit.pData[a + 1]);
Credit.offset = a;
len = GetScriptNumber(&Credit.pData[++Credit.offset]);
// Create cast object
SetStripper(Credit.start_x, (WINDOW_HEIGHT << 9) + 0x1000, text, len);
SetStripper(Credit.start_x, (WINDOW_HEIGHT * 0x200) + (8 * 0x200), text, len);
// Change offset
Credit.offset += 4;
return;
case '-': // Wait for X amount of frames
++Credit.offset;
Credit.wait = GetScriptNumber(&Credit.pData[Credit.offset]);
Credit.offset += 4;
Credit.mode = 2;
return;
case '+': // Change casts x-position
++Credit.offset;
Credit.start_x = GetScriptNumber(&Credit.pData[Credit.offset]) * 0x200;
Credit.offset += 4;
return;
case '/': // Stop credits
Credit.mode = 0;
return;
case '!': // Change music
++Credit.offset;
a = GetScriptNumber(&Credit.pData[Credit.offset]);
Credit.offset += 4;
ChangeMusic(a);
return;
case '~': // Start fading out music
++Credit.offset;
SetOrganyaFadeout();
return;
case 'j': // Jump to label
++Credit.offset;
// Get number
b = GetScriptNumber(&Credit.pData[++Credit.offset]);
b = GetScriptNumber(&Credit.pData[Credit.offset]);
// Change offset
Credit.offset += 4;
// Jump to specific label
if (1)
{
while (Credit.offset < Credit.size)
{
if (Credit.pData[Credit.offset] == 'l')
@ -279,7 +344,7 @@ void ActionCredit_Read()
a = GetScriptNumber(&Credit.pData[++Credit.offset]);
Credit.offset += 4;
if (b == a)
return;
break;
}
else if (IsShiftJIS(Credit.pData[Credit.offset]))
{
@ -290,17 +355,15 @@ void ActionCredit_Read()
++Credit.offset;
}
}
}
return;
case '~': // Start fading out music
++Credit.offset;
SetOrganyaFadeout();
return;
case 'f': // Flag jump
++Credit.offset;
// Read numbers XXXX:YYYY
a = GetScriptNumber(&Credit.pData[++Credit.offset]);
a = GetScriptNumber(&Credit.pData[Credit.offset]);
Credit.offset += 5;
b = GetScriptNumber(&Credit.pData[Credit.offset]);
Credit.offset += 4;
@ -316,7 +379,7 @@ void ActionCredit_Read()
a = GetScriptNumber(&Credit.pData[++Credit.offset]);
Credit.offset += 4;
if (b == a)
return;
break;
}
else if (IsShiftJIS(Credit.pData[Credit.offset]))
{
@ -330,49 +393,32 @@ void ActionCredit_Read()
}
return;
case '+': // Change casts x-position
Credit.start_x = GetScriptNumber(&Credit.pData[++Credit.offset]) << 9;
Credit.offset += 4;
return;
case '-': // Wait for X amount of frames
Credit.wait = GetScriptNumber(&Credit.pData[++Credit.offset]);
Credit.offset += 4;
Credit.mode = 2;
return;
case '/': // Stop credits
Credit.mode = 0;
return;
case '!': // Change music
a = GetScriptNumber(&Credit.pData[++Credit.offset]);
Credit.offset += 4;
ChangeMusic(a);
return;
}
default:
// Progress through file
++Credit.offset;
break;
}
}
}
// Update credits
void ActionCredit()
{
if (Credit.offset < Credit.size)
{
if (Credit.offset >= Credit.size)
return;
// Update script, or if waiting, decrement the wait value
if (Credit.mode == 1)
switch (Credit.mode)
{
case 1:
ActionCredit_Read();
}
else if (Credit.mode == 2 && --Credit.wait <= 0)
{
break;
case 2:
if (--Credit.wait <= 0)
Credit.mode = 1;
}
}
}
// Change illustration
void SetCreditIllust(int a)
@ -388,7 +434,7 @@ void CutCreditIllust()
}
// Scene of the island falling
int Scene_DownIsland(int mode)
int Scene_DownIsland(int hWnd, int mode)
{
// Setup background
RECT rc_frame = {(WINDOW_WIDTH - 160) / 2, (WINDOW_HEIGHT - 80) / 2, (WINDOW_WIDTH + 160) / 2, (WINDOW_HEIGHT + 80) / 2};
@ -410,12 +456,14 @@ int Scene_DownIsland(int mode)
// Escape menu
if (gKey & 0x8000)
{
int escRet = Call_Escape(hWnd);
if (escRet == 0)
switch (Call_Escape(hWnd))
{
case 0:
return 0;
if (escRet == 2)
case 2:
return 2;
}
}
switch (mode)
{
@ -425,33 +473,27 @@ int Scene_DownIsland(int mode)
break;
case 1:
if (wait >= 350)
{
if (wait >= 500)
{
if (wait >= 600)
{
// End scene
if (wait == 750)
wait = 900;
}
else
{
// Move down slow
sprite.y += 0xC;
}
}
else
{
// Move down slower
sprite.y += 0x19;
}
}
else
if (wait < 350)
{
// Move down at normal speed
sprite.y += 0x33;
}
else if (wait < 500)
{
// Move down slower
sprite.y += 0x19;
}
else if (wait < 600)
{
// Move down slow
sprite.y += 0xC;
}
else if (wait == 750)
{
// End scene
wait = 900;
}
break;
}

View file

@ -1,5 +1,7 @@
#pragma once
#include "WindowsWrapper.h"
struct CREDIT
{
int size;
@ -42,8 +44,8 @@ void PutIllust();
void ReloadIllust(int a);
void InitCreditScript();
void ReleaseCreditScript();
bool StartCreditScript();
BOOL StartCreditScript();
void ActionCredit();
void SetCreditIllust(int a);
void CutCreditIllust();
int Scene_DownIsland(int mode);
int Scene_DownIsland(int hWnd, int mode);

View file

@ -141,7 +141,7 @@ int ModeOpening()
// Escape menu
if (gKey & KEY_ESCAPE)
{
int escRet = Call_Escape(hWnd);
int escRet = Call_Escape(ghWnd);
if (escRet == 0)
return 0;
if (escRet == 2)
@ -193,7 +193,7 @@ int ModeOpening()
PutTextScript();
PutFramePerSecound();
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
return 0;
++gCounter;
@ -204,7 +204,7 @@ int ModeOpening()
{
CortBox(&grcGame, 0x000000);
PutFramePerSecound();
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
return 0;
}
return 2;
@ -335,7 +335,7 @@ int ModeTitle()
if (gKey & KEY_ESCAPE)
{
int escRet = Call_Escape(hWnd);
int escRet = Call_Escape(ghWnd);
if (escRet == 0)
return 0;
if (escRet == 2)
@ -420,7 +420,7 @@ int ModeTitle()
PutFramePerSecound();
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
return 0;
}
@ -433,7 +433,7 @@ int ModeTitle()
{
CortBox(&grcGame, 0);
PutFramePerSecound();
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
return 0;
}
@ -479,7 +479,7 @@ int ModeAction()
// Escape menu
if (gKey & KEY_ESCAPE)
{
int escRet = Call_Escape(hWnd);
int escRet = Call_Escape(ghWnd);
if (escRet == 0)
return 0;
if (escRet == 2)
@ -614,7 +614,7 @@ int ModeAction()
PutTextScript();
PutFramePerSecound();
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
break;
++gCounter;
}

View file

@ -2,16 +2,18 @@
#include <stdio.h>
#include "WindowsWrapper.h"
#include "CommonDefines.h"
#include "Tags.h"
bool GetCompileVersion(int *v1, int *v2, int *v3, int *v4)
BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4)
{
*v1 = 1;
*v2 = 0;
*v3 = 0;
*v4 = 6;
return true;
return TRUE;
}
long GetFileSizeLong(const char *path)
@ -29,7 +31,7 @@ long GetFileSizeLong(const char *path)
return len;
}
bool CheckFileExists(const char *name)
BOOL CheckFileExists(const char *name)
{
char path[PATH_LENGTH];
sprintf(path, "%s/%s", gModulePath, name);
@ -38,17 +40,17 @@ bool CheckFileExists(const char *name)
if (file)
{
fclose(file);
return true;
return TRUE;
}
return false;
return FALSE;
}
bool IsShiftJIS(unsigned char c)
BOOL IsShiftJIS(unsigned char c)
{
if (c > 0x80 && c < 0xA0)
return true;
return TRUE;
if (c < 0xE0 || c >= 0xF0)
return false;
return true;
return FALSE;
return TRUE;
}

View file

@ -1,6 +1,8 @@
#pragma once
bool GetCompileVersion(int *v1, int *v2, int *v3, int *v4);
#include "WindowsWrapper.h"
BOOL GetCompileVersion(int *v1, int *v2, int *v3, int *v4);
long GetFileSizeLong(const char *path);
bool CheckFileExists(const char *name);
bool IsShiftJIS(unsigned char c);
BOOL CheckFileExists(const char *name);
BOOL IsShiftJIS(unsigned char c);

View file

@ -32,7 +32,7 @@ char gDataPath[PATH_LENGTH];
int gJoystickButtonTable[8];
int hWnd; // Placeholder until we restore the WinAPI code
int ghWnd; // Placeholder until we restore the WinAPI code
bool gbUseJoystick = false;
bool bFps = false;
@ -350,7 +350,7 @@ int main(int argc, char *argv[])
PutBitmap3(&clip_rect, (WINDOW_WIDTH - 64) / 2, (WINDOW_HEIGHT - 8) / 2, &loading_rect, SURFACE_ID_LOADING);
// Draw to screen
if (Flip_SystemTask(hWnd))
if (Flip_SystemTask(ghWnd))
{
// Initialize sound
InitDirectSound();

View file

@ -1,6 +1,6 @@
#pragma once
extern int hWnd;
extern int ghWnd;
void PutFramePerSecound();
int GetFramePerSecound();

View file

@ -95,7 +95,7 @@ int MiniMapLoop()
if (gKey & KEY_ESCAPE)
{
switch (Call_Escape(hWnd))
switch (Call_Escape(ghWnd))
{
case 0:
return 0;
@ -115,7 +115,7 @@ int MiniMapLoop()
CortBox(&rcView, 0);
PutFramePerSecound();
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
return 0;
}
@ -139,7 +139,7 @@ int MiniMapLoop()
if (gKey & KEY_ESCAPE)
{
switch (Call_Escape(hWnd))
switch (Call_Escape(ghWnd))
{
case 0:
return 0;
@ -170,7 +170,7 @@ int MiniMapLoop()
PutBitmap3(&grcGame, my_x + rcView.left + 1, my_y + rcView.top + 1, &my_rect, SURFACE_ID_TEXT_BOX);
PutFramePerSecound();
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
return 0;
}
@ -180,7 +180,7 @@ int MiniMapLoop()
if (gKey & KEY_ESCAPE)
{
switch (Call_Escape(hWnd))
switch (Call_Escape(ghWnd))
{
case 0:
return 0;
@ -200,7 +200,7 @@ int MiniMapLoop()
CortBox(&rcView, 0);
PutFramePerSecound();
if (!Flip_SystemTask(hWnd))
if (!Flip_SystemTask(ghWnd))
return 0;
}

View file

@ -254,12 +254,12 @@ BOOL InitializeGame()
InitFlags();
if (!TransferStage(13, 200, 10, 8))
{
// TODO - restore this when hWnd is available
// TODO - restore this when ghWnd is available
/*#if defined(NONPORTABLE) && defined(WINDOWS)
#ifdef JAPANESE
MessageBoxA(hWnd, "ステージの読み込みに失敗", "エラー", MB_OK);
MessageBoxA(ghWnd, "ステージの読み込みに失敗", "エラー", MB_OK);
#else
MessageBoxA(hWnd, "Failed to load stage", "Error", MB_OK);
MessageBoxA(ghWnd, "Failed to load stage", "Error", MB_OK);
#endif
#else*/
#ifdef JAPANESE

View file

@ -151,7 +151,7 @@ int StageSelectLoop(int *p_event)
if (gKey & KEY_ESCAPE)
{
int escRet = Call_Escape(hWnd);
int escRet = Call_Escape(ghWnd);
if (escRet == 0)
return 0;
if (escRet == 2)
@ -193,7 +193,7 @@ int StageSelectLoop(int *p_event)
PutFramePerSecound();
}
while (Flip_SystemTask(hWnd));
while (Flip_SystemTask(ghWnd));
return 0;
}

View file

@ -21,6 +21,7 @@
#include "Game.h"
#include "Generic.h"
#include "KeyControl.h"
#include "Main.h"
#include "Map.h"
#include "MapName.h"
#include "MiniMap.h"
@ -682,7 +683,7 @@ int TextScriptProc()
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Error", "Failed to load stage", NULL);
#endif
//MessageBoxA(hWnd, "ステージの読み込みに失敗", "エラー", 0);
//MessageBoxA(ghWnd, "ステージの読み込みに失敗", "エラー", 0);
return 0;
}
}
@ -1207,7 +1208,7 @@ int TextScriptProc()
bExit = TRUE;
z = GetTextScriptNo(gTS.p_read + 4);
switch (Scene_DownIsland(z))
switch (Scene_DownIsland(ghWnd, z))
{
case 0:
return 0;