void* Init(const char* strFile, unsigned int filecache, int* channels, int* samplerate, int* bitspersample, int64_t* totaltime, int* bitrate, AEDataFormat* format, const AEChannel** channelinfo) { upse_module_init(); upse_module_t* upse = upse_module_open(strFile, &upse_io); if (!upse) return NULL; UPSEContext* result = new UPSEContext; result->mod = upse; result->size = 0; result->head = result->buf; upse_spu_state_t * p_spu = reinterpret_cast<upse_spu_state_t *> ( upse->instance.spu ); upse_ps1_spu_setvolume( p_spu, 32 ); *totaltime = upse->metadata->length; static enum AEChannel map[3] = { AE_CH_FL, AE_CH_FR, AE_CH_NULL }; *format = AE_FMT_S16NE; *channelinfo = map; *channels = 2; *bitspersample = 16; *bitrate = 0.0; *samplerate = 44100; return result; }
void * emulator_singleton_thread(void *arg) { upse_module_t *mod; mod = upse_module_open(arg, &iofuncs); if (mod == NULL) { printf("opening %s failed?\n", arg); return NULL; } printf("thread %p is playing mod: %s\n", pthread_self(), mod->metadata->title); upse_eventloop_run(mod); printf("thread %p has played mod: %s\n", pthread_self(), mod->metadata->title); upse_module_close(mod); fflush(stdout); return NULL; }
int main(int argc, const char *argv[]) { upse_module_t *mod; FILE *f; u8 *exebuf, *writer; u32 exesize, readaddr; upse_exe_header_t *head; upse_module_instance_t *ins; if (argc < 3) { printf("%s: usage: in.minipsf out.psf\n", argv[0]); return -1; } upse_module_init(); mod = upse_module_open(argv[1], &psf2exe_iofuncs); if (mod == NULL) return -1; ins = &mod->instance; printf("Reassembling %s into %s:\n\n", argv[1], argv[2]); exesize = (ins->highest_addr - ins->lowest_addr) + ins->highest_addr_size; printf("Lowest load address : 0x%.8X\n", ins->lowest_addr); printf("Highest load address: 0x%.8X\n", ins->highest_addr); printf("Total image size : 0x%.8X\n", exesize); printf("Entry point : 0x%.8X\n", ins->cpustate.pc); printf("GP base : 0x%.8X\n", ins->cpustate.GPR.n.gp); printf("Stack base : 0x%.8X\n", ins->cpustate.GPR.n.sp); exebuf = malloc(sizeof(upse_exe_header_t) + 0x800 + exesize); head = (upse_exe_header_t *) exebuf; printf("\nBuilding PS-X EXE header.\n"); head->id[0] = 'P'; head->id[1] = 'S'; head->id[2] = '-'; head->id[3] = 'X'; head->id[4] = ' '; head->id[5] = 'E'; head->id[6] = 'X'; head->id[7] = 'E'; head->text = 0; head->data = 0; head->pc0 = ins->cpustate.pc; head->gp0 = ins->cpustate.GPR.n.gp; head->t_addr = ins->lowest_addr; head->t_size = exesize + 0x4C; head->d_addr = 0; head->d_size = 0; head->b_addr = 0; head->b_size = 0; head->s_addr = ins->cpustate.GPR.n.sp; head->s_size = 0; head->SavedSP = 0; head->SavedFP = 0; head->SavedGP = 0; head->SavedRA = 0; head->SavedS0 = 0; printf("Assembling binary image.\n"); for (readaddr = ins->lowest_addr, writer = exebuf + 0x800; (writer - exebuf) < exesize; readaddr++, writer++) { *writer = PSXMu8(ins, readaddr); } printf("PS-X EXE image assembled.\n"); upse_module_close(mod); ins = NULL; f = fopen(argv[2], "wb"); if (f == NULL) { perror(argv[2]); return -1; } printf("\nOpened %s for writing.\n", argv[2]); fwrite(exebuf, 1, sizeof(upse_exe_header_t) + 0x800 + exesize, f); fclose(f); printf("Wrote %s successfully.\n", argv[2]); return 0; }