installed Garteal's text-based configuration system

This commit is contained in:
unknown 2013-12-01 16:11:59 -05:00
parent 60550657b2
commit 896022318b
3 changed files with 63 additions and 56 deletions

View File

@ -23,25 +23,21 @@
#define VU_EMULATE_SCALAR_ACCUMULATOR_READ
#endif
const char DLL_name[100] = "Iconoclast's SP Interpreter";
const char DLL_name[100] = "Static Interpreter";
static unsigned char conf[32];
#define CFG_FILE "rsp_conf.bin"
#define CFG_FILE "rsp_conf.cfg"
/*
* The name of the config file is subject to change.
* On InitiateRSP, plug-in checks if a file named after the game code in the
* ROM header of the loaded ROM exists. If so, load the settings per-ROM.
* The config file used to be a 32-byte EEPROM with binary settings storage.
* It was found necessary for user and contributor convenience to replace.
*
* The current configuration system now uses Garteal's CFG text definitions.
*/
#define CFG_HLE (conf[0x00])
#define CFG_HLE_GFX ((CFG_HLE >> 0) & 1)
#define CFG_HLE_AUD ((CFG_HLE >> 1) & 1)
#define CFG_HLE_VID ((CFG_HLE >> 2) & 1) /* reserved/unused */
#define CFG_HLE_JPG ((CFG_HLE >> 3) & 1) /* reserved/unused */
#define CFG_HLE_005 (0) /* I have no idea what (OSTask.type == 5) is. */
#define CFG_HLE_HVQ ((CFG_HLE >> 5) & 1) /* reserved/unused */
#define CFG_HLE_HVQM ((CFG_HLE >> 6) & 1) /* reserved/unused */
#define CFG_HLE_UNK ((CFG_HLE >> 7) & 1) /* anything else, reserved */
#define CFG_HLE_GFX (conf[0x00])
#define CFG_HLE_AUD (conf[0x01])
#define CFG_HLE_VID (conf[0x02]) /* reserved/unused */
#define CFG_HLE_JPG (conf[0x03]) /* unused */
/*
* Most of the point behind this config system is to let users use HLE video
* or audio plug-ins. The other task types are used less than 1% of the time
@ -51,25 +47,22 @@ static unsigned char conf[32];
* HLE RSP plug-in, so consider using that instead for complete HLE.
*/
/*
* Anything between 0x01 and 0x03 of the config file, I have not yet found a
* use for. That section of bits is currently all reserved for new settings.
*/
/*
* Schedule binary dump exports to the DllConfig schedule delay queue.
*/
#define CFG_QUEUE_E_DRAM (*(int *)(conf + 0x04))
#define CFG_QUEUE_E_DMEM (*(int *)(conf + 0x08))
#define CFG_QUEUE_E_IMEM (*(int *)(conf + 0x0C))
/*
* Note: This never actually made it into the configuration system.
* Instead, DMEM and IMEM are always exported on every call to DllConfig().
*/
/*
* Special switches.
* (generally for correcting RSP clock behavior on Project64 2.x)
* Also includes RSP register states debugger.
* Also includes entirely useless, custom bit-wise checksum security.
*/
#define CFG_WAIT_FOR_CPU_HOST (*(int *)(conf + 0x10))
#define CFG_MEND_SEMAPHORE_LOCK (*(int *)(conf + 0x14))
#define CFG_TRACE_RSP_REGISTERS (*(int *)(conf + 0x18))
#define CFG_CHECKSUM (*(conf + 0x1F))

67
rsp.h
View File

@ -25,6 +25,8 @@ RSP_INFO RSP;
#include <emmintrin.h>
#endif
typedef unsigned char byte;
NOINLINE void message(const char* body, int priority)
{ /* Avoid SHELL32/ADVAPI32/USER32 dependencies by using standard C to print. */
char argv[4096] = "CMD /Q /D /C \"TITLE RSP Message&&ECHO ";
@ -37,7 +39,7 @@ NOINLINE void message(const char* body, int priority)
/*
* I'm just using system() to call the Windows command shell to print text.
* When the OS permits it, just use printf to trace messages, not this crap.
* When the subsystem permits, use printf to trace messages, not this crap.
* I don't use WIN32 MessageBox because that's just extra OS dependencies. :P
*/
while (body[i] != '\0')
@ -65,41 +67,54 @@ NOINLINE void message(const char* body, int priority)
/*
* Update RSP configuration memory from local file resource.
*/
void update_conf(const char* source)
#define CHARACTERS_PER_LINE (80)
/* typical standard DOS text file limit per line */
NOINLINE void update_conf(const char* source)
{
FILE* stream;
unsigned char checksum;
char line[CHARACTERS_PER_LINE] = "";
char key[CHARACTERS_PER_LINE], value[CHARACTERS_PER_LINE];
register int i, test;
stream = fopen(source, "rb");
stream = fopen(source, "r");
if (stream == NULL)
{ /* try GetModulePath or whatever to correct the path? */
message("Failed to read config.", 3);
return;
}
for (i = 0; i < 32; i++)
do
{
test = fgetc(stream);
conf[i] = (unsigned char)(test);
}
/* my own little checksum code, not really useful :P */
checksum = 0x00000000;
for (i = 0; i < 31; i++)
checksum = checksum
+ !!(conf[i] & 0x80)
+ !!(conf[i] & 0x40)
+ !!(conf[i] & 0x20)
+ !!(conf[i] & 0x10)
+ !!(conf[i] & 0x08)
+ !!(conf[i] & 0x04)
+ !!(conf[i] & 0x02)
+ !!(conf[i] & 0x01);
if (checksum != CFG_CHECKSUM)
{
message("Checksum mismatch.", 3);
memset(conf, 0x00, 32);
return;
}
int bvalue;
line[0] = '\0';
key[0] = '\0';
value[0] = '\0';
for (i = 0; i < CHARACTERS_PER_LINE; i++)
{
test = fgetc(stream);
if (test < 0) /* either EOF or invalid ASCII characters */
return;
line[i] = (char)(test);
if (line[i] == '\n')
break;
}
line[i] = '\0';
for (i = 0; i < CHARACTERS_PER_LINE && line[i] != '='; i++);
line[i] = '\0';
strcpy(key, line);
strcpy(value, line + i + 1);
bvalue = atoi(value);
if (strcmp(key, "DisplayListToGraphicsPlugin") == 0)
CFG_HLE_GFX = (byte)(bvalue);
else if (strcmp(key, "AudioListToAudioPlugin") == 0)
CFG_HLE_AUD = (byte)(bvalue);
else if (strcmp(key, "WaitForCPUHost") == 0)
CFG_WAIT_FOR_CPU_HOST = bvalue;
else if (strcmp(key, "SupportCPUSemaphoreLock") == 0)
CFG_MEND_SEMAPHORE_LOCK = bvalue;
} while (test != EOF);
return;
}

17
su.h
View File

@ -66,14 +66,14 @@ void set_PC(int address)
#else
#define ENDIAN ~0
#endif
#define BES(address) ((address) ^ ((ENDIAN) & 03))
#define HES(address) ((address) ^ ((ENDIAN) & 02))
#define MES(address) ((address) ^ ((ENDIAN) & 01))
#define WES(address) ((address) ^ ((ENDIAN) & 00))
#define SR_B(s, i) (*(unsigned char *)(((unsigned char *)(SR + s)) + BES(i)))
#define SR_S(s, i) (*(short *)(((unsigned char *)(SR + s)) + HES(i)))
#define SE(x, b) (-(x & (1 << b)) | (x & ~(~0 << b)))
#define ZE(x, b) (+(x & (1 << b)) | (x & ~(~0 << b)))
#define BES(address) ((address) ^ ((ENDIAN) & 03))
#define HES(address) ((address) ^ ((ENDIAN) & 02))
#define MES(address) ((address) ^ ((ENDIAN) & 01))
#define WES(address) ((address) ^ ((ENDIAN) & 00))
#define SR_B(s, i) (*(byte *)(((byte *)(SR + s)) + BES(i)))
#define SR_S(s, i) (*(short *)(((byte *)(SR + s)) + HES(i)))
#define SE(x, b) (-(x & (1 << b)) | (x & ~(~0 << b)))
#define ZE(x, b) (+(x & (1 << b)) | (x & ~(~0 << b)))
static union {
unsigned char B[4];
@ -302,7 +302,6 @@ void SP_DMA_WRITE(void)
extern ALIGNED short VR[32][8];
typedef unsigned char byte;
/*
* Since RSP vectors are stored 100% accurately as big-endian arrays for the
* proper vector operation math to be done, LWC2 and SWC2 emulation code will