diff options
author | 2010-06-26 12:49:46 +0200 | |
---|---|---|
committer | 2010-06-26 12:49:46 +0200 | |
commit | 5888e168c4185d5cd62305acf558cb6a752a17f0 (patch) | |
tree | 6f1278505129be628d9543353345b703cf4463c9 /plugins/ao | |
parent | c4c49d34513458a2cb73bff87c6fe73b10a2c350 (diff) |
adding reentrant API to ao plugin WIP
Diffstat (limited to 'plugins/ao')
-rw-r--r-- | plugins/ao/Makefile.am | 2 | ||||
-rwxr-xr-x | plugins/ao/ao.h | 8 | ||||
-rw-r--r-- | plugins/ao/eng_dsf/eng_dsf.c | 89 | ||||
-rw-r--r-- | plugins/ao/eng_protos.h | 68 | ||||
-rw-r--r-- | plugins/ao/eng_psf/eng_psf.c | 110 | ||||
-rw-r--r-- | plugins/ao/eng_psf/eng_psf2.c | 120 | ||||
-rw-r--r-- | plugins/ao/eng_psf/eng_spu.c | 172 | ||||
-rw-r--r-- | plugins/ao/eng_psf/peops/registers.c | 7 | ||||
-rw-r--r-- | plugins/ao/eng_psf/peops/regs.h | 7 | ||||
-rw-r--r-- | plugins/ao/eng_psf/peops/spu.c | 1 | ||||
-rw-r--r-- | plugins/ao/eng_qsf/eng_qsf.c | 159 | ||||
-rw-r--r-- | plugins/ao/eng_ssf/eng_ssf.c | 87 | ||||
-rw-r--r-- | plugins/ao/main.c | 30 | ||||
-rw-r--r-- | plugins/ao/plugin.c | 27 |
14 files changed, 486 insertions, 401 deletions
diff --git a/plugins/ao/Makefile.am b/plugins/ao/Makefile.am index 005537f0..82209227 100644 --- a/plugins/ao/Makefile.am +++ b/plugins/ao/Makefile.am @@ -20,6 +20,6 @@ eng_psf/peops2/adsr.h eng_psf/peops2/dma.h eng_psf/peops2/externals.h eng_psf/pe ao_la_LDFLAGS = -module -fPIC ao_la_LIBADD = $(LDADD) -AM_CFLAGS = $(CFLAGS) -DPATH_MAX=1024 -DHAS_PSXCPU=1 -I.. -Ieng_ssf -Ieng_qsf -Ieng_dsf -DLSB_FIRST=1 -lm $(ZLIB_LIBS) +AM_CFLAGS = $(CFLAGS) -Wall -DPATH_MAX=1024 -DHAS_PSXCPU=1 -I.. -Ieng_ssf -Ieng_qsf -Ieng_dsf -DLSB_FIRST=1 -lm $(ZLIB_LIBS) endif diff --git a/plugins/ao/ao.h b/plugins/ao/ao.h index b3d59382..010317be 100755 --- a/plugins/ao/ao.h +++ b/plugins/ao/ao.h @@ -182,12 +182,12 @@ int ao_get_lib(char *filename, uint8 **buffer, uint64 *length); int ao_identify (char *buffer); -int ao_start (uint32 type, char *buffer, uint32 size); +void *ao_start (uint32 type, uint8 *buffer, uint32 size); -int ao_stop (uint32 type); +int ao_stop (uint32 type, void *handle); -int ao_get_info (uint32 type, ao_display_info *info); +int ao_get_info (uint32 type, void *handle, ao_display_info *info); -int ao_decode (uint32 type, int16 *buffer, uint32 size); +int ao_decode (uint32 type, void *handle, int16 *buffer, uint32 size); #endif // AO_H diff --git a/plugins/ao/eng_dsf/eng_dsf.c b/plugins/ao/eng_dsf/eng_dsf.c index f6ac91ed..aa636def 100644 --- a/plugins/ao/eng_dsf/eng_dsf.c +++ b/plugins/ao/eng_dsf/eng_dsf.c @@ -28,15 +28,20 @@ #include "arm7core.h" #endif -static corlett_t *c = NULL; -static char psfby[256]; -static uint32 decaybegin, decayend, total_samples; +typedef struct { + corlett_t *c; + char psfby[256]; + uint32 decaybegin, decayend, total_samples; +} dsf_synth_t; void *aica_start(const void *config); void AICA_Update(void *param, INT16 **inputs, INT16 **buf, int samples); -int32 dsf_start(uint8 *buffer, uint32 length) +void *dsf_start(uint8 *buffer, uint32 length) { + dsf_synth_t *s = malloc (sizeof (dsf_synth_t)); + memset (s, 0, sizeof (dsf_synth_t)); + uint8 *file, *lib_decoded, *lib_raw_file; uint32 offset, plength, lengthMS, fadeMS; uint64 file_len, lib_len, lib_raw_length; @@ -48,9 +53,10 @@ int32 dsf_start(uint8 *buffer, uint32 length) memset(dc_ram, 0, 8*1024*1024); // Decode the current SSF - if (corlett_decode(buffer, length, &file, &file_len, &c) != AO_SUCCESS) + if (corlett_decode(buffer, length, &file, &file_len, &s->c) != AO_SUCCESS) { - return AO_FAIL; + dsf_stop (s); + return NULL; } #if DEBUG_LOADER @@ -59,7 +65,7 @@ int32 dsf_start(uint8 *buffer, uint32 length) // Get the library file, if any for (i=0; i<9; i++) { - libfile = i ? c->libaux[i-1] : c->lib; + libfile = i ? s->c->libaux[i-1] : s->c->lib; if (libfile[0] != 0) { uint64 tmp_length; @@ -69,14 +75,16 @@ int32 dsf_start(uint8 *buffer, uint32 length) #endif if (ao_get_lib(libfile, &lib_raw_file, &tmp_length) != AO_SUCCESS) { - return AO_FAIL; + dsf_stop (s); + return NULL; } lib_raw_length = tmp_length; if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) { free(lib_raw_file); - return AO_FAIL; + dsf_stop (s); + return NULL; } // Free up raw file @@ -98,13 +106,13 @@ int32 dsf_start(uint8 *buffer, uint32 length) free(file); // Finally, set psfby/ssfby tag - strcpy(psfby, "n/a"); - if (c) + strcpy(s->psfby, "n/a"); + if (s->c) { for (i = 0; i < MAX_UNKNOWN_TAGS; i++) { - if ((!strcasecmp(c->tag_name[i], "psfby")) || (!strcasecmp(c->tag_name[i], "ssfby"))) - strcpy(psfby, c->tag_data[i]); + if ((!strcasecmp(s->c->tag_name[i], "psfby")) || (!strcasecmp(s->c->tag_name[i], "ssfby"))) + strcpy(s->psfby, s->c->tag_data[i]); } } @@ -127,9 +135,9 @@ int32 dsf_start(uint8 *buffer, uint32 length) dc_hw_init(); // now figure out the time in samples for the length/fade - lengthMS = psfTimeToMS(c->inf_length); - fadeMS = psfTimeToMS(c->inf_fade); - total_samples = 0; + lengthMS = psfTimeToMS(s->c->inf_length); + fadeMS = psfTimeToMS(s->c->inf_fade); + s->total_samples = 0; if (lengthMS == 0) { @@ -138,22 +146,24 @@ int32 dsf_start(uint8 *buffer, uint32 length) if (lengthMS == ~0) { - decaybegin = lengthMS; + s->decaybegin = lengthMS; } else { lengthMS = (lengthMS * 441) / 10; fadeMS = (fadeMS * 441) / 10; - decaybegin = lengthMS; - decayend = lengthMS + fadeMS; + s->decaybegin = lengthMS; + s->decayend = lengthMS + fadeMS; } - return AO_SUCCESS; + return s; } -int32 dsf_gen(int16 *buffer, uint32 samples) -{ +int32 dsf_gen(void *handle, int16 *buffer, uint32 samples) +{ + dsf_synth_t *s = handle; + int i; int16 output[44100/30], output2[44100/30]; int16 *stereo[2]; @@ -177,9 +187,9 @@ int32 dsf_gen(int16 *buffer, uint32 samples) for (i = 0; i < samples; i++) { // process the fade tags - if (total_samples >= decaybegin) + if (s->total_samples >= s->decaybegin) { - if (total_samples >= decayend) + if (s->total_samples >= s->decayend) { // song is done here, signal your player appropriately! // ao_song_done = 1; @@ -188,16 +198,16 @@ int32 dsf_gen(int16 *buffer, uint32 samples) } else { - int32 fader = 256 - (256*(total_samples - decaybegin)/(decayend-decaybegin)); + int32 fader = 256 - (256*(s->total_samples - s->decaybegin)/(s->decayend-s->decaybegin)); output[i] = (output[i] * fader)>>8; output2[i] = (output2[i] * fader)>>8; - total_samples++; + s->total_samples++; } } else { - total_samples++; + s->total_samples++; } *outp++ = output[i]; @@ -207,12 +217,12 @@ int32 dsf_gen(int16 *buffer, uint32 samples) return AO_SUCCESS; } -int32 dsf_stop(void) +int32 dsf_stop(void *handle) { return AO_SUCCESS; } -int32 dsf_command(int32 command, int32 parameter) +int32 dsf_command(void *handle, int32 command, int32 parameter) { switch (command) { @@ -223,34 +233,35 @@ int32 dsf_command(int32 command, int32 parameter) return AO_FAIL; } -int32 dsf_fill_info(ao_display_info *info) +int32 dsf_fill_info(void *handle, ao_display_info *info) { - if (c == NULL) + dsf_synth_t *s = handle; + if (s->c == NULL) return AO_FAIL; strcpy(info->title[1], "Name: "); - sprintf(info->info[1], "%s", c->inf_title); + sprintf(info->info[1], "%s", s->c->inf_title); strcpy(info->title[2], "Game: "); - sprintf(info->info[2], "%s", c->inf_game); + sprintf(info->info[2], "%s", s->c->inf_game); strcpy(info->title[3], "Artist: "); - sprintf(info->info[3], "%s", c->inf_artist); + sprintf(info->info[3], "%s", s->c->inf_artist); strcpy(info->title[4], "Copyright: "); - sprintf(info->info[4], "%s", c->inf_copy); + sprintf(info->info[4], "%s", s->c->inf_copy); strcpy(info->title[5], "Year: "); - sprintf(info->info[5], "%s", c->inf_year); + sprintf(info->info[5], "%s", s->c->inf_year); strcpy(info->title[6], "Length: "); - sprintf(info->info[6], "%s", c->inf_length); + sprintf(info->info[6], "%s", s->c->inf_length); strcpy(info->title[7], "Fade: "); - sprintf(info->info[7], "%s", c->inf_fade); + sprintf(info->info[7], "%s", s->c->inf_fade); strcpy(info->title[8], "Ripper: "); - sprintf(info->info[8], "%s", psfby); + sprintf(info->info[8], "%s", s->psfby); return AO_SUCCESS; } diff --git a/plugins/ao/eng_protos.h b/plugins/ao/eng_protos.h index 335d13c0..4d01d4b2 100644 --- a/plugins/ao/eng_protos.h +++ b/plugins/ao/eng_protos.h @@ -9,35 +9,35 @@ // eng_protos.h // -int32 psf_start(uint8 *, uint32 length); -int32 psf_gen(int16 *, uint32); -int32 psf_stop(void); -int32 psf_command(int32, int32); -int32 psf_fill_info(ao_display_info *); - -int32 psf2_start(uint8 *, uint32 length); -int32 psf2_gen(int16 *, uint32); -int32 psf2_stop(void); -int32 psf2_command(int32, int32); -int32 psf2_fill_info(ao_display_info *); - -int32 qsf_start(uint8 *, uint32 length); -int32 qsf_gen(int16 *, uint32); -int32 qsf_stop(void); -int32 qsf_command(int32, int32); -int32 qsf_fill_info(ao_display_info *); - -int32 ssf_start(uint8 *, uint32 length); -int32 ssf_gen(int16 *, uint32); -int32 ssf_stop(void); -int32 ssf_command(int32, int32); -int32 ssf_fill_info(ao_display_info *); - -int32 spu_start(uint8 *, uint32 length); -int32 spu_gen(int16 *, uint32); -int32 spu_stop(void); -int32 spu_command(int32, int32); -int32 spu_fill_info(ao_display_info *); +void *psf_start(uint8 *, uint32 length); +int32 psf_gen(void *, int16 *, uint32); +int32 psf_stop(void *); +int32 psf_command(void *, int32, int32); +int32 psf_fill_info(void *, ao_display_info *); + +void *psf2_start(uint8 *, uint32 length); +int32 psf2_gen(void *, int16 *, uint32); +int32 psf2_stop(void *); +int32 psf2_command(void *, int32, int32); +int32 psf2_fill_info(void *, ao_display_info *); + +void *qsf_start(uint8 *, uint32 length); +int32 qsf_gen(void *, int16 *, uint32); +int32 qsf_stop(void *); +int32 qsf_command(void *, int32, int32); +int32 qsf_fill_info(void*, ao_display_info *); + +void *ssf_start(uint8 *, uint32 length); +int32 ssf_gen(void *, int16 *, uint32); +int32 ssf_stop(void *); +int32 ssf_command(void *, int32, int32); +int32 ssf_fill_info(void *, ao_display_info *); + +void *spu_start(uint8 *, uint32 length); +int32 spu_gen(void *, int16 *, uint32); +int32 spu_stop(void *); +int32 spu_command(void *, int32, int32); +int32 spu_fill_info(void *, ao_display_info *); uint8 qsf_memory_read(uint16 addr); uint8 qsf_memory_readop(uint16 addr); @@ -45,9 +45,9 @@ uint8 qsf_memory_readport(uint16 addr); void qsf_memory_write(uint16 addr, uint8 byte); void qsf_memory_writeport(uint16 addr, uint8 byte); -int32 dsf_start(uint8 *, uint32 length); -int32 dsf_gen(int16 *, uint32); -int32 dsf_stop(void); -int32 dsf_command(int32, int32); -int32 dsf_fill_info(ao_display_info *); +void *dsf_start(uint8 *, uint32 length); +int32 dsf_gen(void *, int16 *, uint32); +int32 dsf_stop(void *); +int32 dsf_command(void *, int32, int32); +int32 dsf_fill_info(void *, ao_display_info *); diff --git a/plugins/ao/eng_psf/eng_psf.c b/plugins/ao/eng_psf/eng_psf.c index 604c424b..61e77610 100644 --- a/plugins/ao/eng_psf/eng_psf.c +++ b/plugins/ao/eng_psf/eng_psf.c @@ -44,11 +44,13 @@ #define DEBUG_LOADER (0) -static corlett_t *c = NULL; -static char psfby[256]; -char *spu_pOutput; -int psf_refresh = -1; +char *spu_pOutput; // hack! +int psf_refresh = -1; // hack +typedef struct { + corlett_t *c; + char psfby[256]; +} psf_synth_t; // main RAM extern uint32 psx_ram[((2*1024*1024)/4)+4]; @@ -66,8 +68,11 @@ extern void psx_hw_slice(void); extern void psx_hw_frame(void); extern void setlength(int32 stop, int32 fade); -int32 psf_start(uint8 *buffer, uint32 length) +void *psf_start(uint8 *buffer, uint32 length) { + psf_synth_t *s = malloc (sizeof (psf_synth_t)); + psf_refresh = -1; + uint8 *file, *lib_decoded, *lib_raw_file, *alib_decoded; uint32 offset, plength, PC, SP, GP, lengthMS, fadeMS; uint64 file_len, lib_len, lib_raw_length, alib_len; @@ -81,9 +86,10 @@ int32 psf_start(uint8 *buffer, uint32 length) // printf("Length = %d\n", length); // Decode the current GSF - if (corlett_decode(buffer, length, &file, &file_len, &c) != AO_SUCCESS) + if (corlett_decode(buffer, length, &file, &file_len, &s->c) != AO_SUCCESS) { - return AO_FAIL; + psf_stop (s); + return NULL; } // printf("file_len %d reserve %d\n", file_len, c->res_size); @@ -91,7 +97,8 @@ int32 psf_start(uint8 *buffer, uint32 length) // check for PSX EXE signature if (strncmp((char *)file, "PS-X EXE", 8)) { - return AO_FAIL; + psf_stop (s); + return NULL; } #if DEBUG_LOADER @@ -103,11 +110,11 @@ int32 psf_start(uint8 *buffer, uint32 length) printf("refresh: [%s]\n", c->inf_refresh); #endif - if (c->inf_refresh[0] == '5') + if (s->c->inf_refresh[0] == '5') { psf_refresh = 50; } - if (c->inf_refresh[0] == '6') + if (s->c->inf_refresh[0] == '6') { psf_refresh = 60; } @@ -121,23 +128,25 @@ int32 psf_start(uint8 *buffer, uint32 length) #endif // Get the library file, if any - if (c->lib[0] != 0) + if (s->c->lib[0] != 0) { uint64 tmp_length; #if DEBUG_LOADER printf("Loading library: %s\n", c->lib); #endif - if (ao_get_lib(c->lib, &lib_raw_file, &tmp_length) != AO_SUCCESS) + if (ao_get_lib(s->c->lib, &lib_raw_file, &tmp_length) != AO_SUCCESS) { - return AO_FAIL; + psf_stop (s); + return NULL; } lib_raw_length = tmp_length; if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) { free(lib_raw_file); - return AO_FAIL; + psf_stop (s); + return NULL; } // Free up raw file @@ -147,7 +156,8 @@ int32 psf_start(uint8 *buffer, uint32 length) { printf("Major error! PSF was OK, but referenced library is not!\n"); free(lib); - return AO_FAIL; + psf_stop (s); + return NULL; } #if DEBUG_LOADER @@ -208,7 +218,7 @@ int32 psf_start(uint8 *buffer, uint32 length) // load any auxiliary libraries now for (i = 0; i < 8; i++) { - if (c->libaux[i][0] != 0) + if (s->c->libaux[i][0] != 0) { uint64 tmp_length; @@ -216,16 +226,18 @@ int32 psf_start(uint8 *buffer, uint32 length) printf("Loading aux library: %s\n", c->libaux[i]); #endif - if (ao_get_lib(c->libaux[i], &lib_raw_file, &tmp_length) != AO_SUCCESS) + if (ao_get_lib(s->c->libaux[i], &lib_raw_file, &tmp_length) != AO_SUCCESS) { - return AO_FAIL; + psf_stop (s); + return NULL; } lib_raw_length = tmp_length; if (corlett_decode(lib_raw_file, lib_raw_length, &alib_decoded, &alib_len, &lib) != AO_SUCCESS) { free(lib_raw_file); - return AO_FAIL; + psf_stop (s); + return NULL; } // Free up raw file @@ -235,7 +247,8 @@ int32 psf_start(uint8 *buffer, uint32 length) { printf("Major error! PSF was OK, but referenced library is not!\n"); free(lib); - return AO_FAIL; + psf_stop (s); + return NULL; } #if DEBUG_LOADER @@ -261,14 +274,14 @@ int32 psf_start(uint8 *buffer, uint32 length) // free(lib_decoded); // Finally, set psfby tag - strcpy(psfby, "n/a"); - if (c) + strcpy(s->psfby, "n/a"); + if (s->c) { int i; for (i = 0; i < MAX_UNKNOWN_TAGS; i++) { - if (!strcasecmp(c->tag_name[i], "psfby")) - strcpy(psfby, c->tag_data[i]); + if (!strcasecmp(s->c->tag_name[i], "psfby")) + strcpy(s->psfby, s->c->tag_data[i]); } } @@ -310,8 +323,8 @@ int32 psf_start(uint8 *buffer, uint32 length) SPUinit(); SPUopen(); - lengthMS = psfTimeToMS(c->inf_length); - fadeMS = psfTimeToMS(c->inf_fade); + lengthMS = psfTimeToMS(s->c->inf_length); + fadeMS = psfTimeToMS(s->c->inf_fade); #if DEBUG_LOADER printf("length %d fade %d\n", lengthMS, fadeMS); @@ -327,9 +340,9 @@ int32 psf_start(uint8 *buffer, uint32 length) // patch illegal Chocobo Dungeon 2 code - CaitSith2 put a jump in the delay slot from a BNE // and rely on Highly Experimental's buggy-ass CPU to rescue them. Verified on real hardware // that the initial code is wrong. - if (c->inf_game) + if (s->c->inf_game) { - if (!strcmp(c->inf_game, "Chocobo Dungeon 2")) + if (!strcmp(s->c->inf_game, "Chocobo Dungeon 2")) { if (psx_ram[0xbc090/4] == LE32(0x0802f040)) { @@ -351,16 +364,17 @@ int32 psf_start(uint8 *buffer, uint32 length) mips_execute(5000); - return AO_SUCCESS; + return s; } -void spu_update(unsigned char* pSound,long lBytes) +void spu_update (unsigned char* pSound,long lBytes) { memcpy(spu_pOutput, pSound, lBytes); } -int32 psf_gen(int16 *buffer, uint32 samples) +int32 psf_gen(void *handle, int16 *buffer, uint32 samples) { + psf_synth_t *s = handle; int i; for (i = 0; i < samples; i++) @@ -377,16 +391,19 @@ int32 psf_gen(int16 *buffer, uint32 samples) return AO_SUCCESS; } -int32 psf_stop(void) +int32 psf_stop(void *handle) { + psf_synth_t *s = handle; SPUclose(); - free(c); + free(s->c); + free (s); return AO_SUCCESS; } -int32 psf_command(int32 command, int32 parameter) +int32 psf_command(void *handle, int32 command, int32 parameter) { + psf_synth_t *s = handle; union cpuinfo mipsinfo; uint32 lengthMS, fadeMS; @@ -404,8 +421,8 @@ int32 psf_command(int32 command, int32 parameter) SPUinit(); SPUopen(); - lengthMS = psfTimeToMS(c->inf_length); - fadeMS = psfTimeToMS(c->inf_fade); + lengthMS = psfTimeToMS(s->c->inf_length); + fadeMS = psfTimeToMS(s->c->inf_fade); if (lengthMS == 0) { @@ -429,34 +446,35 @@ int32 psf_command(int32 command, int32 parameter) return AO_FAIL; } -int32 psf_fill_info(ao_display_info *info) +int32 psf_fill_info(void *handle, ao_display_info *info) { - if (c == NULL) + psf_synth_t *s = handle; + if (s->c == NULL) return AO_FAIL; strcpy(info->title[1], "Name: "); - sprintf(info->info[1], "%s", c->inf_title); + sprintf(info->info[1], "%s", s->c->inf_title); strcpy(info->title[2], "Game: "); - sprintf(info->info[2], "%s", c->inf_game); + sprintf(info->info[2], "%s", s->c->inf_game); strcpy(info->title[3], "Artist: "); - sprintf(info->info[3], "%s", c->inf_artist); + sprintf(info->info[3], "%s", s->c->inf_artist); strcpy(info->title[4], "Copyright: "); - sprintf(info->info[4], "%s", c->inf_copy); + sprintf(info->info[4], "%s", s->c->inf_copy); strcpy(info->title[5], "Year: "); - sprintf(info->info[5], "%s", c->inf_year); + sprintf(info->info[5], "%s", s->c->inf_year); strcpy(info->title[6], "Length: "); - sprintf(info->info[6], "%s", c->inf_length); + sprintf(info->info[6], "%s", s->c->inf_length); strcpy(info->title[7], "Fade: "); - sprintf(info->info[7], "%s", c->inf_fade); + sprintf(info->info[7], "%s", s->c->inf_fade); strcpy(info->title[8], "Ripper: "); - sprintf(info->info[8], "%s", psfby); + sprintf(info->info[8], "%s", s->psfby); return AO_SUCCESS; } diff --git a/plugins/ao/eng_psf/eng_psf2.c b/plugins/ao/eng_psf/eng_psf2.c index 3919aa75..a3e37b82 100644 --- a/plugins/ao/eng_psf/eng_psf2.c +++ b/plugins/ao/eng_psf/eng_psf2.c @@ -35,7 +35,7 @@ // eng_psf2.c // // References: -// psf_format.txt v1.6 by Neill Corlett (filesystem and decompression info) +// psf_format.txt v1.6 by Neill Corlett (s->filesystem and decompression info) // Intel ELF format specs ELF.PS (general ELF parsing info) // http://ps2dev.org/kb.x?T=457 (IRX relocation and inter-module call info) // http://ps2dev.org/ (the whole site - lots of IOP info) @@ -61,27 +61,29 @@ #include "corlett.h" #define DEBUG_LOADER (0) -#define MAX_FS (32) // maximum # of filesystems (libs and subdirectories) +#define MAX_FS (32) // maximum # of s->filesystems (libs and subdirectories) // ELF relocation helpers #define ELF32_R_SYM(val) ((val) >> 8) #define ELF32_R_TYPE(val) ((val) & 0xff) -static corlett_t *c = NULL; -static char psfby[256]; -static char *spu_pOutput; - // main RAM extern uint32 psx_ram[(2*1024*1024)/4]; extern uint32 initial_ram[(2*1024*1024)/4]; -static uint32 initialPC, initialSP; static uint32 loadAddr, lengthMS, fadeMS; - +static char *spu_pOutput; static uint8 *filesys[MAX_FS]; -static uint8 *lib_raw_file; static uint32 fssize[MAX_FS]; static int num_fs; +typedef struct { + corlett_t *c; + char psfby[256]; + uint32 initialPC, initialSP; + + uint8 *lib_raw_file; +} psf2_synth_t; + extern void mips_init( void ); extern void mips_reset( void *param ); extern int mips_execute( int cycles ); @@ -381,8 +383,8 @@ static dump_files(int fs, uint8 *buf, uint32 buflen) printf("Dumping FS %d\n", fs); - start = filesys[fs]; - len = fssize[fs]; + start = s->filesys[fs]; + len = s->fssize[fs]; cptr = start + 4; @@ -456,8 +458,10 @@ uint32 psf2_load_file(char *file, uint8 *buf, uint32 buflen) return 0xffffffff; } -int32 psf2_start(uint8 *buffer, uint32 length) +void *psf2_start(uint8 *buffer, uint32 length) { + psf2_synth_t *s = malloc (sizeof (psf2_synth_t)); + uint8 *file, *lib_decoded; uint32 irx_len; uint64 file_len, lib_raw_length, lib_len; @@ -472,39 +476,42 @@ int32 psf2_start(uint8 *buffer, uint32 length) memset(psx_ram, 0, 2*1024*1024); // Decode the current PSF2 - if (corlett_decode(buffer, length, &file, &file_len, &c) != AO_SUCCESS) + if (corlett_decode(buffer, length, &file, &file_len, &s->c) != AO_SUCCESS) { - return AO_FAIL; + free (s); + return NULL; } if (file_len > 0) printf("ERROR: PSF2 can't have a program section! ps %08x\n", file_len); #if DEBUG_LOADER - printf("FS section: size %x\n", c->res_size); + printf("FS section: size %x\n", s->c->res_size); #endif num_fs = 1; - filesys[0] = (uint8 *)c->res_section; - fssize[0] = c->res_size; + filesys[0] = (uint8 *)s->c->res_section; + fssize[0] = s->c->res_size; // Get the library file, if any - if (c->lib[0] != 0) + if (s->c->lib[0] != 0) { uint64 tmp_length; #if DEBUG_LOADER - printf("Loading library: %s\n", c->lib); + printf("Loading library: %s\n", s->c->lib); #endif - if (ao_get_lib(c->lib, &lib_raw_file, &tmp_length) != AO_SUCCESS) + if (ao_get_lib(s->c->lib, &s->lib_raw_file, &tmp_length) != AO_SUCCESS) { - return AO_FAIL; + free (s); + return NULL; } lib_raw_length = tmp_length; - if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) + if (corlett_decode(s->lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) { - free(lib_raw_file); - return AO_FAIL; + free(s->lib_raw_file); + free (s); + return NULL; } #if DEBUG_LOADER @@ -520,7 +527,7 @@ int32 psf2_start(uint8 *buffer, uint32 length) #if 0 buf = (uint8 *)malloc(16*1024*1024); dump_files(0, buf, 16*1024*1024); - if (c->lib[0] != 0) + if (s->c->lib[0] != 0) dump_files(1, buf, 16*1024*1024); free(buf); #endif @@ -531,18 +538,19 @@ int32 psf2_start(uint8 *buffer, uint32 length) if (irx_len != 0xffffffff) { - initialPC = psf2_load_elf(buf, irx_len); - initialSP = 0x801ffff0; + s->initialPC = psf2_load_elf(buf, irx_len); + s->initialSP = 0x801ffff0; } free(buf); - if (initialPC == 0xffffffff) + if (s->initialPC == 0xffffffff) { - return AO_FAIL; + free (s); + return NULL; } - lengthMS = psfTimeToMS(c->inf_length); - fadeMS = psfTimeToMS(c->inf_fade); + lengthMS = psfTimeToMS(s->c->inf_length); + fadeMS = psfTimeToMS(s->c->inf_fade); if (lengthMS == 0) { lengthMS = ~0; @@ -552,10 +560,10 @@ int32 psf2_start(uint8 *buffer, uint32 length) mips_init(); mips_reset(NULL); - mipsinfo.i = initialPC; + mipsinfo.i = s->initialPC; mips_set_info(CPUINFO_INT_PC, &mipsinfo); - mipsinfo.i = initialSP; + mipsinfo.i = s->initialSP; mips_set_info(CPUINFO_INT_REGISTER + MIPS_R29, &mipsinfo); mips_set_info(CPUINFO_INT_REGISTER + MIPS_R30, &mipsinfo); @@ -583,7 +591,7 @@ int32 psf2_start(uint8 *buffer, uint32 length) SPU2init(); SPU2open(NULL); - return AO_SUCCESS; + return s; } void ps2_update(unsigned char *pSound, long lBytes) @@ -591,7 +599,7 @@ void ps2_update(unsigned char *pSound, long lBytes) memcpy(spu_pOutput, pSound, lBytes); // (for direct 44.1kHz output) } -int32 psf2_gen(int16 *buffer, uint32 samples) +int32 psf2_gen(void *handle, int16 *buffer, uint32 samples) { int i; @@ -611,20 +619,23 @@ int32 psf2_gen(int16 *buffer, uint32 samples) return AO_SUCCESS; } -int32 psf2_stop(void) +int32 psf2_stop(void *handle) { + psf2_synth_t *s = handle; SPU2close(); - if (c->lib[0] != 0) + if (s->c->lib[0] != 0) { - free(lib_raw_file); + free(s->lib_raw_file); } - free(c); + free(s->c); + free (s); return AO_SUCCESS; } -int32 psf2_command(int32 command, int32 parameter) +int32 psf2_command(void *handle, int32 command, int32 parameter) { + psf2_synth_t *s = handle; union cpuinfo mipsinfo; uint32 lengthMS, fadeMS; @@ -641,10 +652,10 @@ int32 psf2_command(int32 command, int32 parameter) SPU2init(); SPU2open(NULL); - mipsinfo.i = initialPC; + mipsinfo.i = s->initialPC; mips_set_info(CPUINFO_INT_PC, &mipsinfo); - mipsinfo.i = initialSP; + mipsinfo.i = s->initialSP; mips_set_info(CPUINFO_INT_REGISTER + MIPS_R29, &mipsinfo); mips_set_info(CPUINFO_INT_REGISTER + MIPS_R30, &mipsinfo); @@ -661,8 +672,8 @@ int32 psf2_command(int32 command, int32 parameter) psx_hw_init(); - lengthMS = psfTimeToMS(c->inf_length); - fadeMS = psfTimeToMS(c->inf_fade); + lengthMS = psfTimeToMS(s->c->inf_length); + fadeMS = psfTimeToMS(s->c->inf_fade); if (lengthMS == 0) { lengthMS = ~0; @@ -675,34 +686,35 @@ int32 psf2_command(int32 command, int32 parameter) return AO_FAIL; } -int32 psf2_fill_info(ao_display_info *info) +int32 psf2_fill_info(void *handle, ao_display_info *info) { - if (c == NULL) + psf2_synth_t *s = handle; + if (s->c == NULL) return AO_FAIL; strcpy(info->title[1], "Name: "); - sprintf(info->info[1], "%s", c->inf_title); + sprintf(info->info[1], "%s", s->c->inf_title); strcpy(info->title[2], "Game: "); - sprintf(info->info[2], "%s", c->inf_game); + sprintf(info->info[2], "%s", s->c->inf_game); strcpy(info->title[3], "Artist: "); - sprintf(info->info[3], "%s", c->inf_artist); + sprintf(info->info[3], "%s", s->c->inf_artist); strcpy(info->title[4], "Copyright: "); - sprintf(info->info[4], "%s", c->inf_copy); + sprintf(info->info[4], "%s", s->c->inf_copy); strcpy(info->title[5], "Year: "); - sprintf(info->info[5], "%s", c->inf_year); + sprintf(info->info[5], "%s", s->c->inf_year); strcpy(info->title[6], "Length: "); - sprintf(info->info[6], "%s", c->inf_length); + sprintf(info->info[6], "%s", s->c->inf_length); strcpy(info->title[7], "Fade: "); - sprintf(info->info[7], "%s", c->inf_fade); + sprintf(info->info[7], "%s", s->c->inf_fade); strcpy(info->title[8], "Ripper: "); - sprintf(info->info[8], "%s", psfby); + sprintf(info->info[8], "%s", s->psfby); return AO_SUCCESS; } diff --git a/plugins/ao/eng_psf/eng_spu.c b/plugins/ao/eng_psf/eng_spu.c index 8bbda879..b3752f32 100644 --- a/plugins/ao/eng_psf/eng_spu.c +++ b/plugins/ao/eng_psf/eng_spu.c @@ -39,28 +39,40 @@ #include "eng_protos.h" #include "cpuintrf.h" #include "psx.h" +#include "peops/externals.h" extern int SPUinit(void); extern int SPUopen(void); extern int SPUclose(void); extern void SPUinjectRAMImage(unsigned short *source); +extern void setlength(int32 stop, int32 fade); +extern void SPUwriteRegister(u32 reg, u16 val); +extern u16 SPUreadRegister(u32 reg); -static uint8 *start_of_file, *song_ptr; -static uint32 cur_tick, cur_event, num_events, next_tick, end_tick; -static int old_fmt; -static char name[128], song[128], company[128]; +typedef struct { + uint8 *start_of_file, *song_ptr; + uint32 cur_tick, cur_event, num_events, next_tick, end_tick; + int old_fmt; + char name[128], song[128], company[128]; +} spu_synth_t; -int32 spu_start(uint8 *buffer, uint32 length) +extern char *spu_pOutput; // hack! + +void *spu_start(uint8 *buffer, uint32 length) { + spu_synth_t *s = malloc (sizeof (spu_synth_t)); + memset (s, 0, sizeof (spu_synth_t)); + int i; uint16 reg; if (strncmp((char *)buffer, "SPU", 3)) { - return AO_FAIL; + spu_stop (s); + return NULL; } - start_of_file = buffer; + s->start_of_file = buffer; SPUinit(); SPUopen(); @@ -77,123 +89,121 @@ int32 spu_start(uint8 *buffer, uint32 length) SPUwriteRegister((i/2)+0x1f801c00, reg); } - old_fmt = 1; + s->old_fmt = 1; if ((buffer[0x80200] != 0x44) || (buffer[0x80201] != 0xac) || (buffer[0x80202] != 0x00) || (buffer[0x80203] != 0x00)) { - old_fmt = 0; + s->old_fmt = 0; } - if (old_fmt) + if (s->old_fmt) { - num_events = buffer[0x80204] | buffer[0x80205]<<8 | buffer[0x80206]<<16 | buffer[0x80207]<<24; + s->num_events = buffer[0x80204] | buffer[0x80205]<<8 | buffer[0x80206]<<16 | buffer[0x80207]<<24; - if (((num_events * 12) + 0x80208) > length) + if (((s->num_events * 12) + 0x80208) > length) { - old_fmt = 0; + s->old_fmt = 0; } else { - cur_tick = 0; + s->cur_tick = 0; } } - if (!old_fmt) + if (!s->old_fmt) { - end_tick = buffer[0x80200] | buffer[0x80201]<<8 | buffer[0x80202]<<16 | buffer[0x80203]<<24; - cur_tick = buffer[0x80204] | buffer[0x80205]<<8 | buffer[0x80206]<<16 | buffer[0x80207]<<24; - next_tick = cur_tick; + s->end_tick = buffer[0x80200] | buffer[0x80201]<<8 | buffer[0x80202]<<16 | buffer[0x80203]<<24; + s->cur_tick = buffer[0x80204] | buffer[0x80205]<<8 | buffer[0x80206]<<16 | buffer[0x80207]<<24; + s->next_tick = s->cur_tick; } - song_ptr = &buffer[0x80208]; - cur_event = 0; + s->song_ptr = &buffer[0x80208]; + s->cur_event = 0; - strncpy((char *)&buffer[4], name, 128); - strncpy((char *)&buffer[0x44], song, 128); - strncpy((char *)&buffer[0x84], company, 128); + strncpy((char *)&buffer[4], s->name, 128); + strncpy((char *)&buffer[0x44], s->song, 128); + strncpy((char *)&buffer[0x84], s->company, 128); - return AO_SUCCESS; + return s; } extern int SPUasync(uint32 cycles); extern void SPU_flushboot(void); -extern char *spu_pOutput; // this is a bit lame, but we'll deal - -static void spu_tick(void) +static void spu_tick(spu_synth_t *s) { uint32 time, reg, size; uint16 rdata; uint8 opcode; - if (old_fmt) + if (s->old_fmt) { - time = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; + time = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; - while ((time == cur_tick) && (cur_event < num_events)) + while ((time == s->cur_tick) && (s->cur_event < s->num_events)) { - reg = song_ptr[4] | song_ptr[5]<<8 | song_ptr[6]<<16 | song_ptr[7]<<24; - rdata = song_ptr[8] | song_ptr[9]<<8; + reg = s->song_ptr[4] | s->song_ptr[5]<<8 | s->song_ptr[6]<<16 | s->song_ptr[7]<<24; + rdata = s->song_ptr[8] | s->song_ptr[9]<<8; SPUwriteRegister(reg, rdata); - cur_event++; - song_ptr += 12; + s->cur_event++; + s->song_ptr += 12; - time = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; + time = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; } } else { - if (cur_tick < end_tick) + if (s->cur_tick < s->end_tick) { - while (cur_tick == next_tick) + while (s->cur_tick == s->next_tick) { - opcode = song_ptr[0]; - song_ptr++; + opcode = s->song_ptr[0]; + s->song_ptr++; switch (opcode) { case 0: // write register - reg = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; - rdata = song_ptr[4] | song_ptr[5]<<8; + reg = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; + rdata = s->song_ptr[4] | s->song_ptr[5]<<8; SPUwriteRegister(reg, rdata); - next_tick = song_ptr[6] | song_ptr[7]<<8 | song_ptr[8]<<16 | song_ptr[9]<<24; - song_ptr += 10; + s->next_tick = s->song_ptr[6] | s->song_ptr[7]<<8 | s->song_ptr[8]<<16 | s->song_ptr[9]<<24; + s->song_ptr += 10; break; case 1: // read register - reg = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; + reg = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; SPUreadRegister(reg); - next_tick = song_ptr[4] | song_ptr[5]<<8 | song_ptr[6]<<16 | song_ptr[7]<<24; - song_ptr += 8; + s->next_tick = s->song_ptr[4] | s->song_ptr[5]<<8 | s->song_ptr[6]<<16 | s->song_ptr[7]<<24; + s->song_ptr += 8; break; case 2: // dma write - size = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; - song_ptr += (4 + size); - next_tick = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; - song_ptr += 4; + size = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; + s->song_ptr += (4 + size); + s->next_tick = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; + s->song_ptr += 4; break; case 3: // dma read - next_tick = song_ptr[4] | song_ptr[5]<<8 | song_ptr[6]<<16 | song_ptr[7]<<24; - song_ptr += 8; + s->next_tick = s->song_ptr[4] | s->song_ptr[5]<<8 | s->song_ptr[6]<<16 | s->song_ptr[7]<<24; + s->song_ptr += 8; break; case 4: // xa play - song_ptr += (32 + 16384); - next_tick = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; - song_ptr += 4; + s->song_ptr += (32 + 16384); + s->next_tick = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; + s->song_ptr += 4; break; case 5: // cdda play - size = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; - song_ptr += (4 + size); - next_tick = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; - song_ptr += 4; + size = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; + s->song_ptr += (4 + size); + s->next_tick = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; + s->song_ptr += 4; break; default: @@ -205,27 +215,28 @@ static void spu_tick(void) } else { -// ao_song_done = 1; +// ao_s->song_done = 1; } } - cur_tick++; + s->cur_tick++; } -int32 spu_gen(int16 *buffer, uint32 samples) +int32 spu_gen(void *handle, int16 *buffer, uint32 samples) { + spu_synth_t *s = handle; int i, run = 1; - if (old_fmt) + if (s->old_fmt) { - if (cur_event >= num_events) + if (s->cur_event >= s->num_events) { run = 0; } } else { - if (cur_tick >= end_tick) + if (s->cur_tick >= s->end_tick) { run = 0; } @@ -235,7 +246,7 @@ int32 spu_gen(int16 *buffer, uint32 samples) { for (i = 0; i < samples; i++) { - spu_tick(); + spu_tick(s); SPUasync(384); } @@ -250,13 +261,15 @@ int32 spu_gen(int16 *buffer, uint32 samples) return AO_SUCCESS; } -int32 spu_stop(void) +int32 spu_stop(void *handle) { + free (handle); return AO_SUCCESS; } -int32 spu_command(int32 command, int32 parameter) +int32 spu_command(void *handle, int32 command, int32 parameter) { + spu_synth_t *s = handle; switch (command) { case COMMAND_GET_MIN: @@ -278,20 +291,20 @@ int32 spu_command(int32 command, int32 parameter) case COMMAND_RESTART: { - song_ptr = &start_of_file[0x80200]; + s->song_ptr = &s->start_of_file[0x80200]; - if (old_fmt) + if (s->old_fmt) { - num_events = song_ptr[4] | song_ptr[5]<<8 | song_ptr[6]<<16 | song_ptr[7]<<24; + s->num_events = s->song_ptr[4] | s->song_ptr[5]<<8 | s->song_ptr[6]<<16 | s->song_ptr[7]<<24; } else { - end_tick = song_ptr[0] | song_ptr[1]<<8 | song_ptr[2]<<16 | song_ptr[3]<<24; - cur_tick = song_ptr[4] | song_ptr[5]<<8 | song_ptr[6]<<16 | song_ptr[7]<<24; + s->end_tick = s->song_ptr[0] | s->song_ptr[1]<<8 | s->song_ptr[2]<<16 | s->song_ptr[3]<<24; + s->cur_tick = s->song_ptr[4] | s->song_ptr[5]<<8 | s->song_ptr[6]<<16 | s->song_ptr[7]<<24; } - song_ptr += 8; - cur_event = 0; + s->song_ptr += 8; + s->cur_event = 0; return AO_SUCCESS; } break; @@ -306,14 +319,15 @@ int32 spu_command(int32 command, int32 parameter) return AO_FAIL; } -int32 spu_fill_info(ao_display_info *info) +int32 spu_fill_info(void *handle, ao_display_info *info) { + spu_synth_t *s = handle; strcpy(info->title[1], "Game: "); - sprintf(info->info[1], "%.128s", name); + sprintf(info->info[1], "%.128s", s->name); strcpy(info->title[2], "Song: "); - sprintf(info->info[2], "%.128s", song); + sprintf(info->info[2], "%.128s", s->song); strcpy(info->title[3], "Company: "); - sprintf(info->info[3], "%.128s", company); + sprintf(info->info[3], "%.128s", s->company); return AO_SUCCESS; } diff --git a/plugins/ao/eng_psf/peops/registers.c b/plugins/ao/eng_psf/peops/registers.c index 0ad1540b..bcafc8c0 100644 --- a/plugins/ao/eng_psf/peops/registers.c +++ b/plugins/ao/eng_psf/peops/registers.c @@ -46,6 +46,13 @@ #include "../peops/registers.h" #include "../peops/regs.h" +static void SoundOn(int start,int end,u16 val); +static void SoundOff(int start,int end,u16 val); +static void FModOn(int start,int end,u16 val); +static void NoiseOn(int start,int end,u16 val); +static void SetVolumeLR(int right, u8 ch,s16 vol); +static void SetPitch(int ch,u16 val); + //////////////////////////////////////////////////////////////////////// // WRITE REGISTERS: called by main emu //////////////////////////////////////////////////////////////////////// diff --git a/plugins/ao/eng_psf/peops/regs.h b/plugins/ao/eng_psf/peops/regs.h index e4675547..8288830e 100644 --- a/plugins/ao/eng_psf/peops/regs.h +++ b/plugins/ao/eng_psf/peops/regs.h @@ -24,11 +24,4 @@ // //*************************************************************************// - -static void SoundOn(int start,int end,u16 val); -static void SoundOff(int start,int end,u16 val); -static void FModOn(int start,int end,u16 val); -static void NoiseOn(int start,int end,u16 val); -static void SetVolumeLR(int right, u8 ch,s16 vol); -static void SetPitch(int ch,u16 val); void SPUwriteRegister(u32 reg, u16 val); diff --git a/plugins/ao/eng_psf/peops/spu.c b/plugins/ao/eng_psf/peops/spu.c index dc2f5b27..b121cd11 100644 --- a/plugins/ao/eng_psf/peops/spu.c +++ b/plugins/ao/eng_psf/peops/spu.c @@ -490,6 +490,7 @@ int SPUasync(u32 cycles) return(1); } +extern void spu_update (unsigned char* pSound,long lBytes); // HACK! void SPU_flushboot(void) { if((u8*)pS>((u8*)pSpuBuffer+1024)) diff --git a/plugins/ao/eng_qsf/eng_qsf.c b/plugins/ao/eng_qsf/eng_qsf.c index e2d8f7fd..a00b955a 100644 --- a/plugins/ao/eng_qsf/eng_qsf.c +++ b/plugins/ao/eng_qsf/eng_qsf.c @@ -72,16 +72,17 @@ that no encryption is used. static int32 samples_per_tick = 44100/285; static int32 samples_to_next_tick = 44100/285; -static corlett_t *c = NULL; -static char qsfby[256]; -static uint32 skey1, skey2; -static uint16 akey; -static uint8 xkey; -static int32 uses_kabuki = 0; - -static char *Z80ROM, *QSamples; -static char RAM[0x1000], RAM2[0x1000]; -static int32 cur_bank; +typedef struct { + corlett_t *c; + char qsfby[256]; + uint32 skey1, skey2; + uint16 akey; + uint8 xkey; + int32 uses_kabuki; + char *Z80ROM, *QSamples; + char RAM[0x1000], RAM2[0x1000]; + int32 cur_bank; +} qsf_synth_t; static struct QSound_interface qsintf = { @@ -91,7 +92,7 @@ static struct QSound_interface qsintf = extern void cps1_decode(unsigned char *rom, int swap_key1,int swap_key2,int addr_key,int xor_key); -static void qsf_walktags(uint8 *buffer, uint8 *end) +static void qsf_walktags(qsf_synth_t *s, uint8 *buffer, uint8 *end) { uint8 *cbuf = buffer; uint32 offset, length; @@ -111,18 +112,18 @@ static void qsf_walktags(uint8 *buffer, uint8 *end) switch (cbuf[0]) { case 'Z': - memcpy(&Z80ROM[offset], &cbuf[11], length); + memcpy(&s->Z80ROM[offset], &cbuf[11], length); break; case 'S': - memcpy(&QSamples[offset], &cbuf[11], length); + memcpy(&s->QSamples[offset], &cbuf[11], length); break; case 'K': - skey1 = cbuf[11]<<24 | cbuf[12]<<16 | cbuf[13]<<8 | cbuf[14]; - skey2 = cbuf[15]<<24 | cbuf[16]<<16 | cbuf[17]<<8 | cbuf[18]; - akey = cbuf[19]<<8 | cbuf[20]; - xkey = cbuf[20]; + s->skey1 = cbuf[11]<<24 | cbuf[12]<<16 | cbuf[13]<<8 | cbuf[14]; + s->skey2 = cbuf[15]<<24 | cbuf[16]<<16 | cbuf[17]<<8 | cbuf[18]; + s->akey = cbuf[19]<<8 | cbuf[20]; + s->xkey = cbuf[20]; break; default: @@ -140,96 +141,101 @@ static int32 qsf_irq_cb(int param) return 0x000000ff; // RST_38 } -int32 qsf_start(uint8 *buffer, uint32 length) +void *qsf_start(uint8 *buffer, uint32 length) { + qsf_synth_t *s = malloc (sizeof (qsf_synth_t)); + memset (s, 0, sizeof (qsf_synth_t)); + uint8 *file, *lib_decoded, *lib_raw_file; uint64 file_len, lib_len, lib_raw_length; corlett_t *lib; z80_init(); - Z80ROM = malloc(512*1024); - QSamples = malloc(8*1024*1024); + s->Z80ROM = malloc(512*1024); + s->QSamples = malloc(8*1024*1024); - skey1 = skey2 = 0; - akey = 0; - xkey = 0; - cur_bank = 0; + s->skey1 = s->skey2 = 0; + s->akey = 0; + s->xkey = 0; + s->cur_bank = 0; - memset(RAM, 0, 0x1000); - memset(RAM2, 0, 0x1000); + memset(s->RAM, 0, 0x1000); + memset(s->RAM2, 0, 0x1000); // Decode the current QSF - if (corlett_decode(buffer, length, &file, &file_len, &c) != AO_SUCCESS) + if (corlett_decode(buffer, length, &file, &file_len, &s->c) != AO_SUCCESS) { return AO_FAIL; } // Get the library file - if (c->lib[0] != 0) + if (s->c->lib[0] != 0) { uint64 tmp_length; #if DEBUG_LOADER - printf("Loading library: %s\n", c->lib); + printf("Loading library: %s\n", s->c->lib); #endif - if (ao_get_lib(c->lib, &lib_raw_file, &tmp_length) != AO_SUCCESS) + if (ao_get_lib(s->c->lib, &lib_raw_file, &tmp_length) != AO_SUCCESS) { - return AO_FAIL; + qsf_stop (s); + return NULL; } lib_raw_length = tmp_length; if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) { free(lib_raw_file); - return AO_FAIL; + qsf_stop (s); + return NULL; } // Free up raw file free(lib_raw_file); // use the contents - qsf_walktags(lib_decoded, lib_decoded+lib_len); + qsf_walktags(s, lib_decoded, lib_decoded+lib_len); // Dispose the corlett structure for the lib - we don't use it free(lib); } // now patch the file into RAM OVER the libraries - qsf_walktags(file, file+file_len); + qsf_walktags(s, file, file+file_len); free(file); - if ((skey1 != 0) && (skey2 != 0)) + if ((s->skey1 != 0) && (s->skey2 != 0)) { #if DEBUG_LOADER printf("Decoding Kabuki: skey1 %08x skey2 %08x akey %04x xkey %02x\n", skey1, skey2, akey, xkey); #endif - uses_kabuki = 1; - cps1_decode((unsigned char *)Z80ROM, skey1, skey2, akey, xkey); + s->uses_kabuki = 1; + cps1_decode((unsigned char *)s->Z80ROM, s->skey1, s->skey2, s->akey, s->xkey); } // set qsfby tag - strcpy(qsfby, "n/a"); - if (c) + strcpy(s->qsfby, "n/a"); + if (s->c) { int i; for (i = 0; i < MAX_UNKNOWN_TAGS; i++) { - if (!strcasecmp(c->tag_name[i], "qsfby")) + if (!strcasecmp(s->c->tag_name[i], "qsfby")) { - strcpy(qsfby, c->tag_data[i]); + strcpy(s->qsfby, s->c->tag_data[i]); } } } z80_reset(NULL); z80_set_irq_callback(qsf_irq_cb); - qsintf.sample_rom = QSamples; + qsintf.sample_rom = s->QSamples; qsound_sh_start(&qsintf); - return AO_SUCCESS; + return s; } static void timer_tick(void) @@ -301,15 +307,17 @@ int32 qsf_gen(int16 *buffer, uint32 samples) return AO_SUCCESS; } -int32 qsf_stop(void) +int32 qsf_stop(void *handle) { - free(Z80ROM); - free(QSamples); + qsf_synth_t *s = (qsf_synth_t *)handle; + free(s->Z80ROM); + free(s->QSamples); + free(s); return AO_SUCCESS; } -int32 qsf_command(int32 command, int32 parameter) +int32 qsf_command(void *handle, int32 command, int32 parameter) { switch (command) { @@ -320,51 +328,52 @@ int32 qsf_command(int32 command, int32 parameter) return AO_FAIL; } -int32 qsf_fill_info(ao_display_info *info) +int32 qsf_fill_info(void *handle, ao_display_info *info) { - if (c == NULL) + qsf_synth_t *s = handle; + if (s->c == NULL) return AO_FAIL; strcpy(info->title[1], "Name: "); - sprintf(info->info[1], "%s", c->inf_title); + sprintf(info->info[1], "%s", s->c->inf_title); strcpy(info->title[2], "Game: "); - sprintf(info->info[2], "%s", c->inf_game); + sprintf(info->info[2], "%s", s->c->inf_game); strcpy(info->title[3], "Artist: "); - sprintf(info->info[3], "%s", c->inf_artist); + sprintf(info->info[3], "%s", s->c->inf_artist); strcpy(info->title[4], "Copyright: "); - sprintf(info->info[4], "%s", c->inf_copy); + sprintf(info->info[4], "%s", s->c->inf_copy); strcpy(info->title[5], "Year: "); - sprintf(info->info[5], "%s", c->inf_year); + sprintf(info->info[5], "%s", s->c->inf_year); strcpy(info->title[6], "Length: "); - sprintf(info->info[6], "%s", c->inf_length); + sprintf(info->info[6], "%s", s->c->inf_length); strcpy(info->title[7], "Fade: "); - sprintf(info->info[7], "%s", c->inf_fade); + sprintf(info->info[7], "%s", s->c->inf_fade); strcpy(info->title[8], "Ripper: "); - sprintf(info->info[8], "%s", qsfby); + sprintf(info->info[8], "%s", s->qsfby); return AO_SUCCESS; } -uint8 qsf_memory_read(uint16 addr) +uint8 qsf_memory_read(qsf_synth_t *s, uint16 addr) { if (addr < 0x8000) { - return Z80ROM[addr]; + return s->Z80ROM[addr]; } else if (addr < 0xc000) { - return Z80ROM[(addr - 0x8000) + cur_bank]; + return s->Z80ROM[(addr - 0x8000) + s->cur_bank]; } else if (addr <= 0xcfff) { - return RAM[addr - 0xc000]; + return s->RAM[addr - 0xc000]; } else if (addr == 0xd007) { @@ -372,36 +381,36 @@ uint8 qsf_memory_read(uint16 addr) } else if (addr >= 0xf000) { - return RAM2[addr-0xf000]; + return s->RAM2[addr-0xf000]; } } -uint8 qsf_memory_readop(uint16 addr) +uint8 qsf_memory_readop(qsf_synth_t *s, uint16 addr) { - if (!uses_kabuki) + if (!s->uses_kabuki) { - return qsf_memory_read(addr); + return qsf_memory_read(s, addr); } if (addr < 0x8000) { - return Z80ROM[addr + (256*1024)]; + return s->Z80ROM[addr + (256*1024)]; } - return qsf_memory_read(addr); + return qsf_memory_read(s, addr); } -uint8 qsf_memory_readport(uint16 addr) +uint8 qsf_memory_readport(qsf_synth_t *s, uint16 addr) { - return Z80ROM[0x11]; + return s->Z80ROM[0x11]; } -void qsf_memory_write(uint16 addr, uint8 byte) +void qsf_memory_write(qsf_synth_t *s, uint16 addr, uint8 byte) { if (addr >= 0xc000 && addr <= 0xcfff) { - RAM[addr-0xc000] = byte; + s->RAM[addr-0xc000] = byte; return; } else if (addr == 0xd000) @@ -421,17 +430,17 @@ void qsf_memory_write(uint16 addr, uint8 byte) } else if (addr == 0xd003) { - cur_bank = (0x8000 + (byte & 0xf) * 0x4000); - if (cur_bank > (256*1024)) + s->cur_bank = (0x8000 + (byte & 0xf) * 0x4000); + if (s->cur_bank > (256*1024)) { - cur_bank = 0; + s->cur_bank = 0; } // printf("Z80 bank to %x (%x)\n", cur_bank, byte); return; } else if (addr >= 0xf000) { - RAM2[addr-0xf000] = byte; + s->RAM2[addr-0xf000] = byte; return; } } diff --git a/plugins/ao/eng_ssf/eng_ssf.c b/plugins/ao/eng_ssf/eng_ssf.c index 59988209..02d538ff 100644 --- a/plugins/ao/eng_ssf/eng_ssf.c +++ b/plugins/ao/eng_ssf/eng_ssf.c @@ -75,17 +75,23 @@ Sega driver commands: #include "sat_hw.h" #include "scsp.h" +extern int m68k_execute(int num_cycles); + #define DEBUG_LOADER (0) -static corlett_t *c = NULL; -static char psfby[256]; -static uint32 decaybegin, decayend, total_samples; +typedef struct { + corlett_t *c; + char psfby[256]; + uint32 decaybegin, decayend, total_samples; +} ssf_synth_t; void *scsp_start(const void *config); void SCSP_Update(void *param, INT16 **inputs, INT16 **buf, int samples); -int32 ssf_start(uint8 *buffer, uint32 length) +void *ssf_start(uint8 *buffer, uint32 length) { + ssf_synth_t *s = malloc (sizeof (ssf_synth_t)); + memset (s, 0, sizeof (ssf_synth_t)); uint8 *file, *lib_decoded, *lib_raw_file; uint32 offset, plength, lengthMS, fadeMS; uint64 file_len, lib_len, lib_raw_length; @@ -97,9 +103,10 @@ int32 ssf_start(uint8 *buffer, uint32 length) memset(sat_ram, 0, 512*1024); // Decode the current SSF - if (corlett_decode(buffer, length, &file, &file_len, &c) != AO_SUCCESS) + if (corlett_decode(buffer, length, &file, &file_len, &s->c) != AO_SUCCESS) { - return AO_FAIL; + ssf_stop (s); + return NULL; } #if DEBUG_LOADER @@ -109,7 +116,7 @@ int32 ssf_start(uint8 *buffer, uint32 length) // Get the library file, if any for (i=0; i<9; i++) { - libfile = i ? c->libaux[i-1] : c->lib; + libfile = i ? s->c->libaux[i-1] : s->c->lib; if (libfile[0] != 0) { uint64 tmp_length; @@ -119,14 +126,16 @@ int32 ssf_start(uint8 *buffer, uint32 length) #endif if (ao_get_lib(libfile, &lib_raw_file, &tmp_length) != AO_SUCCESS) { - return AO_FAIL; + ssf_stop (s); + return NULL; } lib_raw_length = tmp_length; if (corlett_decode(lib_raw_file, lib_raw_length, &lib_decoded, &lib_len, &lib) != AO_SUCCESS) { free(lib_raw_file); - return AO_FAIL; + ssf_stop (s); + return NULL; } // Free up raw file @@ -161,13 +170,13 @@ int32 ssf_start(uint8 *buffer, uint32 length) free(file); // Finally, set psfby tag - strcpy(psfby, "n/a"); - if (c) + strcpy(s->psfby, "n/a"); + if (s->c) { for (i = 0; i < MAX_UNKNOWN_TAGS; i++) { - if (!strcasecmp(c->tag_name[i], "psfby")) - strcpy(psfby, c->tag_data[i]); + if (!strcasecmp(s->c->tag_name[i], "psfby")) + strcpy(s->psfby, s->c->tag_data[i]); } } @@ -194,9 +203,9 @@ int32 ssf_start(uint8 *buffer, uint32 length) sat_hw_init(); // now figure out the time in samples for the length/fade - lengthMS = psfTimeToMS(c->inf_length); - fadeMS = psfTimeToMS(c->inf_fade); - total_samples = 0; + lengthMS = psfTimeToMS(s->c->inf_length); + fadeMS = psfTimeToMS(s->c->inf_fade); + s->total_samples = 0; if (lengthMS == 0) { @@ -205,22 +214,23 @@ int32 ssf_start(uint8 *buffer, uint32 length) if (lengthMS == ~0) { - decaybegin = lengthMS; + s->decaybegin = lengthMS; } else { lengthMS = (lengthMS * 441) / 10; fadeMS = (fadeMS * 441) / 10; - decaybegin = lengthMS; - decayend = lengthMS + fadeMS; + s->decaybegin = lengthMS; + s->decayend = lengthMS + fadeMS; } - return AO_SUCCESS; + return s; } -int32 ssf_gen(int16 *buffer, uint32 samples) +int32 ssf_gen(void *handle, int16 *buffer, uint32 samples) { + ssf_synth_t *s = handle; int i; int16 output[samples], output2[samples]; int16 *stereo[2]; @@ -237,9 +247,9 @@ int32 ssf_gen(int16 *buffer, uint32 samples) for (i = 0; i < samples; i++) { // process the fade tags - if (total_samples >= decaybegin) + if (s->total_samples >= s->decaybegin) { - if (total_samples >= decayend) + if (s->total_samples >= s->decayend) { // song is done here, call out as necessary to make your player stop output[i] = 0; @@ -247,16 +257,16 @@ int32 ssf_gen(int16 *buffer, uint32 samples) } else { - int32 fader = 256 - (256*(total_samples - decaybegin)/(decayend-decaybegin)); + int32 fader = 256 - (256*(s->total_samples - s->decaybegin)/(s->decayend-s->decaybegin)); output[i] = (output[i] * fader)>>8; output2[i] = (output2[i] * fader)>>8; - total_samples++; + s->total_samples++; } } else { - total_samples++; + s->total_samples++; } *outp++ = output[i]; @@ -266,12 +276,12 @@ int32 ssf_gen(int16 *buffer, uint32 samples) return AO_SUCCESS; } -int32 ssf_stop(void) +int32 ssf_stop(void *handle) { return AO_SUCCESS; } -int32 ssf_command(int32 command, int32 parameter) +int32 ssf_command(void *handle, int32 command, int32 parameter) { switch (command) @@ -283,34 +293,35 @@ int32 ssf_command(int32 command, int32 parameter) return AO_FAIL; } -int32 ssf_fill_info(ao_display_info *info) +int32 ssf_fill_info(void *handle, ao_display_info *info) { - if (c == NULL) + ssf_synth_t *s = handle; + if (s->c == NULL) return AO_FAIL; strcpy(info->title[1], "Name: "); - sprintf(info->info[1], "%s", c->inf_title); + sprintf(info->info[1], "%s", s->c->inf_title); strcpy(info->title[2], "Game: "); - sprintf(info->info[2], "%s", c->inf_game); + sprintf(info->info[2], "%s", s->c->inf_game); strcpy(info->title[3], "Artist: "); - sprintf(info->info[3], "%s", c->inf_artist); + sprintf(info->info[3], "%s", s->c->inf_artist); strcpy(info->title[4], "Copyright: "); - sprintf(info->info[4], "%s", c->inf_copy); + sprintf(info->info[4], "%s", s->c->inf_copy); strcpy(info->title[5], "Year: "); - sprintf(info->info[5], "%s", c->inf_year); + sprintf(info->info[5], "%s", s->c->inf_year); strcpy(info->title[6], "Length: "); - sprintf(info->info[6], "%s", c->inf_length); + sprintf(info->info[6], "%s", s->c->inf_length); strcpy(info->title[7], "Fade: "); - sprintf(info->info[7], "%s", c->inf_fade); + sprintf(info->info[7], "%s", s->c->inf_fade); strcpy(info->title[8], "Ripper: "); - sprintf(info->info[8], "%s", psfby); + sprintf(info->info[8], "%s", s->psfby); return AO_SUCCESS; } diff --git a/plugins/ao/main.c b/plugins/ao/main.c index 6124c78d..7ddb814d 100644 --- a/plugins/ao/main.c +++ b/plugins/ao/main.c @@ -41,12 +41,12 @@ static struct { uint32 sig; char *name; - int32 (*start)(uint8 *, uint32); - int32 (*gen)(int16 *, uint32); - int32 (*stop)(void); - int32 (*command)(int32, int32); + void * (*start)(uint8 *, uint32); // returns handle + int32 (*gen)(void *handle, int16 *, uint32); + int32 (*stop)(void *handle); + int32 (*command)(void *handle, int32, int32); uint32 rate; - int32 (*fillinfo)(ao_display_info *); + int32 (*fillinfo)(void *handle, ao_display_info *); } types[] = { { 0x50534641, "Capcom QSound (.qsf)", qsf_start, qsf_gen, qsf_stop, qsf_command, 60, qsf_fill_info }, { 0x50534611, "Sega Saturn (.ssf)", ssf_start, ssf_gen, ssf_stop, ssf_command, 60, ssf_fill_info }, @@ -196,7 +196,9 @@ int main(int argv, char *argc[]) return -1; } - if ((*types[type].start)(buffer, size) != AO_SUCCESS) + void *handle = (*types[type].start)(buffer, size); + + if (!handle) { free(buffer); printf("ERROR: Engine rejected file!\n"); @@ -256,24 +258,24 @@ ao_identify (char *buffer) { return type; } -int -ao_start (uint32 type, char *buffer, uint32 size) { +void * +ao_start (uint32 type, uint8 *buffer, uint32 size) { printf ("ao_start %d %p %d\n", type, buffer, size); return (*types[type].start)(buffer, size); } int -ao_stop (uint32 type) { - return (*types[type].stop)(); +ao_stop (uint32 type, void *handle) { + return (*types[type].stop)(handle); } int -ao_get_info (uint32 type, ao_display_info *info) { - return (*types[type].fillinfo)(info); +ao_get_info (uint32 type, void *handle, ao_display_info *info) { + return (*types[type].fillinfo)(handle, info); } int -ao_decode (uint32 type, int16 *buffer, uint32 size) { - (*types[type].gen)(buffer, size); +ao_decode (uint32 type, void *handle, int16 *buffer, uint32 size) { + (*types[type].gen)(handle, buffer, size); return size; } diff --git a/plugins/ao/plugin.c b/plugins/ao/plugin.c index e4650815..6d648fad 100644 --- a/plugins/ao/plugin.c +++ b/plugins/ao/plugin.c @@ -38,6 +38,7 @@ typedef struct { DB_fileinfo_t info; int currentsample; uint32 type; + void *decoder; char *filebuffer; size_t filesize; char buffer[735*4]; // psf2 decoder only works with 735 samples buffer @@ -71,7 +72,7 @@ aoplug_init (DB_fileinfo_t *_info, DB_playItem_t *it) { info->filesize = deadbeef->fgetlength (file); info->filebuffer = malloc (info->filesize); if (!info->filebuffer) { - fprintf(stderr, "psf: could not allocate %d bytes of memory\n", info->filesize); + fprintf(stderr, "psf: could not allocate %d bytes of memory\n", (int)info->filesize); deadbeef->fclose (file); return -1; } @@ -89,7 +90,8 @@ aoplug_init (DB_fileinfo_t *_info, DB_playItem_t *it) { return -1; } - if (ao_start (info->type, info->filebuffer, info->filesize) != AO_SUCCESS) { + info->decoder = ao_start (info->type, (uint8 *)info->filebuffer, info->filesize); + if (!info->decoder) { fprintf (stderr, "psf: ao_start failed\n"); return -1; } @@ -102,7 +104,7 @@ aoplug_free (DB_fileinfo_t *_info) { aoplug_info_t *info = (aoplug_info_t *)_info; if (info) { if (info->filebuffer) { - ao_stop (info->type); + ao_stop (info->type, info->decoder); free (info->filebuffer); info->filebuffer = NULL; } @@ -130,7 +132,7 @@ aoplug_read_int16 (DB_fileinfo_t *_info, char *bytes, int size) { size -= n*4; } if (!info->remaining) { - ao_decode (info->type, (int16_t *)info->buffer, 735); + ao_decode (info->type, info->decoder, (int16_t *)info->buffer, 735); info->remaining = 735; } } @@ -164,7 +166,7 @@ aoplug_insert (DB_playItem_t *after, const char *fname) { char *buffer = malloc (size); if (!buffer) { deadbeef->fclose (fp); - fprintf(stderr, "psf: could not allocate %d bytes of memory\n", size); + fprintf(stderr, "psf: could not allocate %d bytes of memory\n", (int)size); return NULL; } @@ -182,17 +184,20 @@ aoplug_insert (DB_playItem_t *after, const char *fname) { return NULL; } - if (ao_start (type, buffer, size) != AO_SUCCESS) { + void *dec = ao_start (type, (uint8*)buffer, size); + if (!dec) { free (buffer); return NULL; } - ao_display_info info; int have_info = 0; - if (ao_get_info (type, &info) == AO_SUCCESS) { + if (ao_get_info (type, dec, &info) == AO_SUCCESS) { have_info = 1; } + ao_stop (type, dec); + dec = NULL; + free (buffer); DB_playItem_t *it = deadbeef->pl_item_alloc (); @@ -233,8 +238,8 @@ aoplug_insert (DB_playItem_t *after, const char *fname) { int i; for (i = 1; i < 9; i++) { if (!strncasecmp (info.title[i], "Length: ", 8)) { - int min, sec, unused; - if (sscanf (info.info[i], "%d:%d", &min, &sec, &unused) == 2) { + int min, sec; + if (sscanf (info.info[i], "%d:%d", &min, &sec) == 2) { duration = min * 60 + sec; } } @@ -289,6 +294,8 @@ static DB_decoder_t plugin = { .plugin.author = "Alexey Yakovenko", .plugin.email = "waker@users.sourceforge.net", .plugin.website = "http://deadbeef.sf.net", + .plugin.start = aoplug_start, + .plugin.stop = aoplug_stop, .open = aoplug_open, .init = aoplug_init, .free = aoplug_free, |