void usf_shutdown(void * state) { r4300_end(USF_STATE); if (USF_STATE->enable_trimming_mode) { if (USF_STATE->barray_rom) bit_array_destroy(USF_STATE->barray_rom); if (USF_STATE->barray_ram_read) bit_array_destroy(USF_STATE->barray_ram_read); if (USF_STATE->barray_ram_written_first) bit_array_destroy(USF_STATE->barray_ram_written_first); USF_STATE->barray_rom = 0; USF_STATE->barray_ram_read = 0; USF_STATE->barray_ram_written_first = 0; } USF_STATE->MemoryState = 0; free(USF_STATE->save_state); USF_STATE->save_state = 0; close_rom(USF_STATE); #ifdef DEBUG_INFO fclose(USF_STATE->debug_log); #endif resampler_delete(USF_STATE->resampler); USF_STATE->resampler = 0; }
EXPORT m64p_error CALL CoreDoCommand(m64p_command Command, int ParamInt, void *ParamPtr) { m64p_error rval; int keysym, keymod; if (!l_CoreInit) return M64ERR_NOT_INIT; switch(Command) { case M64CMD_NOP: return M64ERR_SUCCESS; case M64CMD_ROM_OPEN: if (g_EmulatorRunning || l_ROMOpen) return M64ERR_INVALID_STATE; if (ParamPtr == NULL || ParamInt < 4096) return M64ERR_INPUT_ASSERT; rval = open_rom((const unsigned char *) ParamPtr, ParamInt); if (rval == M64ERR_SUCCESS) { l_ROMOpen = 1; } return rval; case M64CMD_ROM_CLOSE: if (g_EmulatorRunning || !l_ROMOpen) return M64ERR_INVALID_STATE; l_ROMOpen = 0; return close_rom(); case M64CMD_ROM_GET_HEADER: if (!l_ROMOpen) return M64ERR_INVALID_STATE; if (ParamPtr == NULL) return M64ERR_INPUT_ASSERT; if (sizeof(m64p_rom_header) < ParamInt) ParamInt = sizeof(m64p_rom_header); memcpy(ParamPtr, &ROM_HEADER, ParamInt); // Mupen64Plus used to keep a m64p_rom_header with a clean ROM name // Keep returning a clean ROM name for backwards compatibility if (ParamInt >= 0x20) { int size = (ParamInt >= 0x20 + 20) ? 20 : (ParamInt - 0x20); memcpy((char *)ParamPtr + 0x20, ROM_PARAMS.headername, size); } return M64ERR_SUCCESS; case M64CMD_ROM_GET_SETTINGS: if (!l_ROMOpen) return M64ERR_INVALID_STATE; if (ParamPtr == NULL) return M64ERR_INPUT_ASSERT; if (sizeof(m64p_rom_settings) < ParamInt) ParamInt = sizeof(m64p_rom_settings); memcpy(ParamPtr, &ROM_SETTINGS, ParamInt); return M64ERR_SUCCESS; case M64CMD_EXECUTE: if (g_EmulatorRunning || !l_ROMOpen) return M64ERR_INVALID_STATE; /* the main_run() function will not return until the player has quit the game */ rval = main_run(); return rval; case M64CMD_STOP: if (!g_EmulatorRunning) return M64ERR_INVALID_STATE; /* this stop function is asynchronous. The emulator may not terminate until later */ return main_core_state_set(M64CORE_EMU_STATE, M64EMU_STOPPED); case M64CMD_PAUSE: if (!g_EmulatorRunning) return M64ERR_INVALID_STATE; return main_core_state_set(M64CORE_EMU_STATE, M64EMU_PAUSED); case M64CMD_RESUME: if (!g_EmulatorRunning) return M64ERR_INVALID_STATE; return main_core_state_set(M64CORE_EMU_STATE, M64EMU_RUNNING); case M64CMD_CORE_STATE_QUERY: if (ParamPtr == NULL) return M64ERR_INPUT_ASSERT; return main_core_state_query((m64p_core_param) ParamInt, (int *) ParamPtr); case M64CMD_CORE_STATE_SET: if (ParamPtr == NULL) return M64ERR_INPUT_ASSERT; return main_core_state_set((m64p_core_param) ParamInt, *((int *)ParamPtr)); case M64CMD_SET_FRAME_CALLBACK: g_FrameCallback = (m64p_frame_callback) ParamPtr; return M64ERR_SUCCESS; case M64CMD_READ_SCREEN: if (!g_EmulatorRunning) return M64ERR_INVALID_STATE; if (ParamPtr == NULL) return M64ERR_INPUT_ASSERT; if (ParamInt < 0 || ParamInt > 1) return M64ERR_INPUT_INVALID; return main_read_screen(ParamPtr, ParamInt); case M64CMD_RESET: if (!g_EmulatorRunning) return M64ERR_INVALID_STATE; if (ParamInt < 0 || ParamInt > 1) return M64ERR_INPUT_INVALID; return main_reset(ParamInt); case M64CMD_ADVANCE_FRAME: if (!g_EmulatorRunning) return M64ERR_INVALID_STATE; main_advance_one(); return M64ERR_SUCCESS; default: return M64ERR_INPUT_INVALID; } return M64ERR_INTERNAL; }