- implement test spooling

- LoadInAreaTSets back to UNIMPLEMENTED
This commit is contained in:
Ilya Shurumov 2020-04-11 21:04:02 +06:00
parent 63be8e1ce4
commit 5241105487
2 changed files with 248 additions and 15 deletions

View File

@ -1,5 +1,10 @@
#include "THISDUST.H"
#ifndef PSX
#include <SDL.h>
#endif // !PSX
#include <STRINGS.H>
#include "LIBETC.H"
#include "PAD.H"
#include "SPOOL.H"
@ -109,6 +114,131 @@ unsigned short *newmodels;
struct SPOOLQ spooldata[48];
#ifndef PSX
#include <assert.h>
typedef void(*data_callbackFn)(void);
typedef void(*ready_callbackFn)(unsigned char intr, unsigned char *result);
data_callbackFn g_dataCallbackPC = NULL;
ready_callbackFn g_readyCallbackPC = NULL;
char g_sectorData[2048] = { 0 };
bool g_isSectorDataRead = false;
extern char g_CurrentLevelFileName[64];
//-----------------------------------------------------
// copies read sector data to addr
//-----------------------------------------------------
void getLevSectorPC(char* dest, int count)
{
assert(count <= 2048);
memcpy(dest, g_sectorData, count);
g_isSectorDataRead = true;
if (g_dataCallbackPC)
g_dataCallbackPC();
}
SDL_Thread* levelSpoolerPCThread = NULL;
int levelSpoolerSeekCmd = 0;
int levelSpoolerPCFunc(void* data)
{
//Print incoming data
printf("----- Running SPOOLER thread -----\n");
ready_callbackFn readyCb = g_readyCallbackPC;
FILE* fp = fopen(g_CurrentLevelFileName, "rb");
if (!fp)
{
char errPrint[1024];
sprintf(errPrint, "Cannot open '%s'\n", g_CurrentLevelFileName);
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "ERROR", errPrint, NULL);
if (readyCb)
readyCb(0, { 0x0 });
return -1;
}
do
{
if (levelSpoolerSeekCmd != 0)
{
int sector = levelSpoolerSeekCmd;
if (sector == -1)
{
printf("CdlPause\n", sector);
levelSpoolerSeekCmd = 0;
break;
}
printf("CdlReadS: at %d\n", sector);
// seek
fseek(fp, sector * 2048, SEEK_SET);
readyCb = g_readyCallbackPC;
levelSpoolerSeekCmd = 0;
}
// clear sector before proceed
ClearMem(g_sectorData, sizeof(g_sectorData));
fread(g_sectorData, 1, 2048, fp);
g_isSectorDataRead = false;
if (readyCb)
{
readyCb(1, { 0x0 });
}
else
{
printf("readyCb = NULL\n");
break;
}
} while (true);
printf("----- SPOOLER thread DON. -----\n");
fclose(fp);
return 0;
}
//-----------------------------------------------------
// reads sector from LEV file
//-----------------------------------------------------
void startReadLevSectorsPC(int sector)
{
levelSpoolerSeekCmd = sector;
/*
if (levelSpoolerPCThread)
{
int returnValue;
SDL_WaitThread(levelSpoolerPCThread, &returnValue);
levelSpoolerPCThread = NULL;
}
*/
if (!levelSpoolerPCThread)
{
levelSpoolerPCThread = SDL_CreateThread(levelSpoolerPCFunc, "Spooler", NULL);
if (NULL == levelSpoolerPCThread)
{
printf("SDL_CreateThread failed: %s\n", SDL_GetError());
}
}
}
#endif // !PSX
// decompiled code
// original method signature:
// void /*$ra*/ test_changemode()
@ -147,8 +277,14 @@ void test_changemode(void)
if (spoolpos_reading == spoolcounter)
{
switch_spooltype = 0;
#ifdef PSX
CdReadyCallback(0);
CdControlF(CdlPause, 0);
#else
g_readyCallbackPC = NULL;
levelSpoolerSeekCmd = -1;
#endif // PSX
}
else if (current_sector == spooldata[spoolpos_reading].sector)
{
@ -160,7 +296,11 @@ void test_changemode(void)
{
sectors_to_read = spool_regioninfo[spool_regionpos + 1].nsectors;
sectors_this_chunk = (spooldata[spoolpos_reading].nsectors);
#ifdef PSX
CdReadyCallback(ready_cb_regions);
#else
g_readyCallbackPC = ready_cb_regions;
#endif // PSX
}
else if (bVar1 == 1)
{
@ -170,7 +310,11 @@ void test_changemode(void)
nTPchunks_writing = 0;
ntpages = tsetcounter;
sectors_this_chunk = (uint)bVar1;
#ifdef PSX
CdReadyCallback(ready_cb_textures);
#else
g_readyCallbackPC = ready_cb_textures;
#endif // PSX
}
else if (bVar1 == 2)
{
@ -181,18 +325,32 @@ void test_changemode(void)
nTPchunks_writing = 0;
target_address = target_address + (loadbank_read & 1U) * 0x1000;
sectors_this_chunk = (uint)bVar1;
#ifdef PSX
CdReadyCallback(ready_cb_soundbank);
#else
g_readyCallbackPC = ready_cb_soundbank;
#endif // PSX
}
else if (bVar1 == 3)
{
sectors_to_read = (spooldata[spoolpos_reading].nsectors);
#ifdef PSX
CdReadyCallback(ready_cb_misc);
#else
g_readyCallbackPC = ready_cb_misc;
#endif // PSX
}
}
else
{
switch_spooltype = 0;
#ifdef PSX
CdReadyCallback(0);
#else
g_readyCallbackPC = NULL;
#endif // PSX
}
}
@ -224,18 +382,35 @@ void changemode(SPOOLQ *current)
if(bVar1 == 0)
{
#ifdef PSX
CdDataCallback(data_cb_regions);
#else
UNIMPLEMENTED();
#endif // PSX
}
else if (bVar1 == 1) {
else if (bVar1 == 1)
{
#ifdef PSX
CdDataCallback(data_cb_textures);
#else
UNIMPLEMENTED();
#endif // PSX
}
else if (bVar1 == 2)
{
#ifdef PSX
CdDataCallback(data_cb_soundbank);
#else
UNIMPLEMENTED();
#endif // PSX
}
else if (bVar1 == 3)
{
#ifdef PSX
CdDataCallback(data_cb_misc);
#else
UNIMPLEMENTED();
#endif // PSX
}
}
@ -640,12 +815,10 @@ void CheckValidSpoolData(void)
void UpdateSpool(void)
{
char bVar1;
int iVar2;
int iVar3;
CdlLOC pos;
iVar3 = XAPrepared();
iVar2 = spoolpos_reading;
if (iVar3 != 1)
{
@ -662,7 +835,8 @@ void UpdateSpool(void)
CdDataCallback(data_cb_regions);
CdReadyCallback(ready_cb_regions);
#else
UNIMPLEMENTED();
g_dataCallbackPC = data_cb_regions;
g_readyCallbackPC = ready_cb_regions;
#endif // PSX
}
else if (bVar1 == 1) // SPOOLTYPE_TEXTURES
@ -671,13 +845,16 @@ void UpdateSpool(void)
nTPchunks_reading = 0;
nTPchunks_writing = 0;
sectors_to_read = 0x11;
sectors_to_read = 17;
ntpages = tsetcounter;
sectors_this_chunk = (uint)bVar1;
#ifdef PSX
CdDataCallback(data_cb_textures);
CdReadyCallback(ready_cb_textures);
#else
g_dataCallbackPC = data_cb_textures;
g_readyCallbackPC = ready_cb_textures;
#endif // PSX
target_address = target_address + 0x4000;
@ -697,7 +874,8 @@ void UpdateSpool(void)
CdDataCallback(data_cb_soundbank);
CdReadyCallback(ready_cb_soundbank);
#else
UNIMPLEMENTED();
g_dataCallbackPC = data_cb_soundbank;
g_readyCallbackPC = ready_cb_soundbank;
#endif // PSX
target_address = target_address + (loadbank_read & 1U) * 0x1000;
@ -711,19 +889,21 @@ void UpdateSpool(void)
CdDataCallback(data_cb_misc);
CdReadyCallback(ready_cb_misc);
#else
UNIMPLEMENTED();
g_dataCallbackPC = data_cb_misc;
g_readyCallbackPC = ready_cb_misc;
#endif // PSX
}
current_sector = spooldata[iVar2].sector;
current_sector = spooldata[spoolpos_reading].sector;
endchunk = 0;
switch_spooltype = 0;
// run sector reading
#ifdef PSX
CdIntToPos(current_sector, &pos);
CdControlF(CdlReadS, (u_char*)&pos);
#else
startReadLevSectorsPC(current_sector);
#endif // PSX
}
}
@ -1063,6 +1243,8 @@ void SpoolSYNC(void)
// [D]
void LoadInAreaTSets(int area)
{
UNIMPLEMENTED();
/*
bool bVar1;
unsigned char bVar2;
uint uVar3;
@ -1140,17 +1322,23 @@ void LoadInAreaTSets(int area)
while (true)
{
RequestSpool(1, 0, offset, 0x11, address, SendTPage);
offset = offset + 0x11;
iVar6 = iVar6 + 1;
iVar4 = tsetcounter * 2;
tsetcounter = tsetcounter + 1;
tsetinfo[iVar4] = (uint)*pbVar7;
pbVar7 = pbVar7 + 1;
if ((int)uVar9 <= iVar6) {
if ((int)uVar9 <= iVar6)
{
return;
}
uVar3 = (uint)*pbVar7;
if (tpageloaded[uVar3] == '\0') break;
if (tpageloaded[uVar3] == '\0')
break;
LAB_0007bc94:
*(int *)((int)tsetinfo + (tsetcounter << 3 | 4U)) = (uint)tpageloaded[uVar3] - 1;
}
@ -1161,7 +1349,7 @@ void LoadInAreaTSets(int area)
iVar4 = availableslots[iVar8];
}
}
}
}*/
}
@ -1982,8 +2170,12 @@ void FoundError(char *name, unsigned char intr, unsigned char *result)
#endif // _DEBUG
spoolerror = 0x3c;
#ifdef PSX
CdIntToPos(current_sector, &p);
CdControlF(CdlReadS, (u_char*)&p);
#else
UNIMPLEMENTED();
#endif
}
@ -2109,7 +2301,11 @@ void data_cb_textures(void)
{
if (switch_spooltype == 0)
{
#ifdef PSX
CdDataCallback(0);
#else
UNIMPLEMENTED();
#endif // PSX
if (spoolpos_writing == spoolcounter)
{
@ -2173,7 +2369,11 @@ void ready_cb_textures(unsigned char intr, unsigned char *result)
if (intr == '\x01')
{
#ifdef PSX
CdGetSector(target_address, 0x200);
#else
getLevSectorPC(target_address, 0x200);
#endif // PSX
target_address = target_address + 0x800;
sectors_this_chunk = sectors_this_chunk + -1;
@ -2202,7 +2402,7 @@ void ready_cb_textures(unsigned char intr, unsigned char *result)
else
{
nTPchunks_reading = 0;
sectors_to_read = 0x11;
sectors_to_read = 17;
target_address = spooldata[spoolpos_reading].addr + 0x4000;
spoolpos_reading = spoolpos_reading + 1;
sectors_this_chunk = uVar1;
@ -2260,13 +2460,20 @@ void ready_cb_regions(unsigned char intr, unsigned char *result)
uVar1 = (uint)intr;
if (intr == '\x01')
{
#ifdef PSX
CdGetSector(target_address, 0x200);
#else
getLevSectorPC(target_address, 0x200);
#endif // PSX
target_address = target_address + 0x800;
sectors_this_chunk = sectors_this_chunk + -1;
current_sector = current_sector + 1;
sectors_to_read = sectors_to_read + -1;
printf("ready_cb_regions: remaining %d\n", sectors_to_read);
if (sectors_this_chunk == 0)
{
spoolpos_reading = spoolpos_reading + 1;
@ -2330,8 +2537,11 @@ void data_cb_regions(void)
{
chunk_complete = 0;
printf("data_cb_regions: %d\n", spoolpos_writing);
if (spooldata[spoolpos_writing].func != NULL)
{
printf("data_cb_regions: FUNCTION\n", spoolpos_writing);
(spooldata[spoolpos_writing].func)();
}
@ -2341,7 +2551,11 @@ void data_cb_regions(void)
{
if (switch_spooltype == 0)
{
#ifdef PSX
CdDataCallback(0);
#else
g_dataCallbackPC = NULL;
#endif // PSX
if (spoolpos_writing == spoolcounter)
{
@ -2406,7 +2620,11 @@ void data_cb_soundbank(void)
if (endchunk != 0) {
spoolpos_writing = spoolpos_writing + 1;
if (switch_spooltype == 0) {
#ifdef PSX
CdDataCallback(0);
#else
UNIMPLEMENTED();
#endif // PSX
if (spoolpos_writing == spoolcounter) {
spoolcounter = 0;
spoolpos_writing = 0;
@ -2465,7 +2683,12 @@ void ready_cb_soundbank(unsigned char intr, unsigned char *result)
uVar1 = (uint)intr;
if (intr == '\x01') {
#ifdef PSX
CdGetSector(target_address, 0x200);
#else
getLevSectorPC(target_address, 0x200);
#endif // PSX
target_address = target_address + 0x800;
sectors_this_chunk = sectors_this_chunk + -1;
current_sector = current_sector + 1;
@ -2549,7 +2772,11 @@ void data_cb_misc(void)
if (switch_spooltype == 0)
{
#ifdef PSX
CdDataCallback(0);
#else
UNIMPLEMENTED();
#endif // PSX
if (spoolpos_writing == spoolcounter)
{
spoolcounter = 0;
@ -2590,7 +2817,11 @@ void ready_cb_misc(unsigned char intr, unsigned char *result)
{
if (intr == '\x01')
{
#ifdef PSX
CdGetSector(target_address, 0x200);
#else
getLevSectorPC(target_address, 0x200);
#endif // PSX
target_address = target_address + 0x800;
sectors_to_read = sectors_to_read + -1;

View File

@ -1,5 +1,9 @@
#include "THISDUST.H"
#ifndef PSX
#include <SDL.h>
#endif // !PSX
#include "LIBETC.H"
#include "SYSTEM.H"
@ -1173,8 +1177,6 @@ void DoCDRetry(void)
/* end block 2 */
// End Line: 1293
#include <SDL.h>
// loads whole file into buffer
int Loadfile(char *name, char *addr)
{