core::arch::global_asm!(include_str!("trampoline.s"));
extern "C" {
pub fn psx_file_open(filename: *const i8, accessmode: u32) -> i8;
pub fn psx_file_seek(fd: i8, offset: u32, seektype: u8) -> i32;
pub fn psx_file_read(fd: i8, dst: *mut u32, length: usize) -> i32;
pub fn psx_file_write(fd: i8, src: *const u32, length: usize) -> i32;
pub fn psx_file_close(fd: i8) -> i8;
pub fn psx_exit(exitcode: i32) -> !;
pub fn psx_save_state(buf: *mut u8);
pub fn psx_restore_state(buf: *const u8, ret_val: u32);
pub fn psx_rand() -> u16;
pub fn psx_srand(seed: u32);
pub fn psx_malloc(size: usize) -> *mut u8;
pub fn psx_free(buf: *mut u8);
pub fn psx_calloc(sizex: usize, sizey: usize) -> *const u8;
pub fn psx_realloc(old_buf: *const u8, new_size: usize);
pub fn psx_init_heap(addr: usize, size: usize);
pub fn psx_system_error_exit(exitcode: i32) -> !;
pub fn psx_std_out_putchar(char: u8);
pub fn psx_std_out_puts(msg: *const i8);
pub fn psx_printf(msg: *const i8, ...);
pub fn psx_load_exe_header(filename: *const i8, headerbuf: *mut u8);
pub fn psx_load_exe_file(filename: *const i8, headerbuf: *mut u8);
pub fn psx_do_execute(headerbuf: *mut u8, param1: u32, param2: u32);
pub fn psx_flush_cache();
pub fn psx_gpu_send_dma(xdst: u16, ydst: u16, xsiz: u16, ysize: u16, src: u32);
pub fn psx_gp1_command(cmd: u32);
pub fn psx_gp0_command(cmd: u32);
pub fn psx_gp0_command_params(src: *const u32, num: usize);
pub fn psx_gpu_get_status() -> u32;
pub fn psx_gpu_sync() -> i32;
pub fn psx_load_and_execute(filename: *const i8, stackbase: u32, stackoffset: u32);
pub fn psx_cd_init();
pub fn psx_cd_remove();
pub fn psx_cd_async_get_status(dst: *mut u32);
pub fn psx_add_cdrom_device();
pub fn psx_set_memsize(megabytes: u8);
pub fn psx_warm_boot() -> !;
pub fn psx_cd_get_lbn(filename: *const i8) -> i32;
pub fn psx_cd_get_status(dst: *mut u32);
pub fn psx_get_system_info(index: u8) -> u32;
pub fn psx_get_timer(t: u32);
pub fn psx_enable_timer_irq(t: u32);
pub fn psx_disable_timer_irq(t: u32);
pub fn psx_restart_timer(t: u32);
pub fn psx_deliver_event(class: u32, spec: u16);
pub fn psx_open_event(class: u32, spec: u16, mode: u16, func: *const u32) -> u32;
pub fn psx_close_event(event: u32);
pub fn psx_wait_event(event: u32) -> bool;
pub fn psx_test_event(event: u32) -> bool;
pub fn psx_enable_event(event: u32);
pub fn psx_disable_event(event: u32);
pub fn psx_open_thread(pc: usize, sp: usize, gp: usize) -> u32;
pub fn psx_close_thread(handle: u32);
pub fn psx_change_thread(handle: u32);
pub fn psx_init_pad(buf1: *mut u8, siz1: usize, buf2: *mut u8, siz2: usize);
pub fn psx_start_pad();
pub fn psx_stop_pad();
pub fn psx_set_default_exit_from_exception();
pub fn psx_undeliver_event(class: u32, spec: u16);
pub fn psx_first_file(filename: *const i8) -> *const [u8; 40];
pub fn psx_next_file() -> *const [u8; 40];
pub fn psx_file_rename(old_filename: *const i8, new_filename: *const i8) -> bool;
pub fn psx_file_delete(filename: *const i8) -> bool;
pub fn psx_file_undelete(filename: *const i8) -> bool;
pub fn psx_print_installed_devices();
pub fn psx_init_card(pad_enable: bool);
pub fn psx_start_card();
pub fn psx_stop_card();
pub fn psx_get_last_error() -> u32;
pub fn psx_get_last_file_error(fd: i8) -> u32;
pub fn psx_change_clear_pad(int: u32);
pub fn psx_change_clear_rcnt(t: u32, flag: bool) -> bool;
pub fn psx_flush_std_in_out_put();
pub fn psx_enter_critical_section() -> bool;
pub fn psx_exit_critical_section();
pub fn psx_change_thread_sub_fn(_: usize, addr: usize);
}
pub const FILE_OPEN_NUM: u8 = 0x00;
pub const FILE_OPEN_TY: u8 = 0xA0;
pub const FILE_SEEK_NUM: u8 = 0x01;
pub const FILE_SEEK_TY: u8 = 0xA0;
pub const FILE_READ_NUM: u8 = 0x02;
pub const FILE_READ_TY: u8 = 0xA0;
pub const FILE_WRITE_NUM: u8 = 0x03;
pub const FILE_WRITE_TY: u8 = 0xA0;
pub const FILE_CLOSE_NUM: u8 = 0x04;
pub const FILE_CLOSE_TY: u8 = 0xA0;
pub const EXIT_NUM: u8 = 0x06;
pub const EXIT_TY: u8 = 0xA0;
pub const SAVE_STATE_NUM: u8 = 0x13;
pub const SAVE_STATE_TY: u8 = 0xA0;
pub const RESTORE_STATE_NUM: u8 = 0x14;
pub const RESTORE_STATE_TY: u8 = 0xA0;
pub const RAND_NUM: u8 = 0x2F;
pub const RAND_TY: u8 = 0xA0;
pub const SRAND_NUM: u8 = 0x30;
pub const SRAND_TY: u8 = 0xA0;
pub const MALLOC_NUM: u8 = 0x33;
pub const MALLOC_TY: u8 = 0xA0;
pub const FREE_NUM: u8 = 0x34;
pub const FREE_TY: u8 = 0xA0;
pub const CALLOC_NUM: u8 = 0x37;
pub const CALLOC_TY: u8 = 0xA0;
pub const REALLOC_NUM: u8 = 0x38;
pub const REALLOC_TY: u8 = 0xA0;
pub const INIT_HEAP_NUM: u8 = 0x39;
pub const INIT_HEAP_TY: u8 = 0xA0;
pub const SYSTEM_ERROR_EXIT_NUM: u8 = 0x3A;
pub const SYSTEM_ERROR_EXIT_TY: u8 = 0xA0;
pub const STD_OUT_PUTCHAR_NUM: u8 = 0x3D;
pub const STD_OUT_PUTCHAR_TY: u8 = 0xB0;
pub const STD_OUT_PUTS_NUM: u8 = 0x3E;
pub const STD_OUT_PUTS_TY: u8 = 0xA0;
pub const PRINTF_NUM: u8 = 0x3F;
pub const PRINTF_TY: u8 = 0xA0;
pub const LOAD_EXE_HEADER_NUM: u8 = 0x41;
pub const LOAD_EXE_HEADER_TY: u8 = 0xA0;
pub const LOAD_EXE_FILE_NUM: u8 = 0x42;
pub const LOAD_EXE_FILE_TY: u8 = 0xA0;
pub const DO_EXECUTE_NUM: u8 = 0x43;
pub const DO_EXECUTE_TY: u8 = 0xA0;
pub const FLUSH_CACHE_NUM: u8 = 0x44;
pub const FLUSH_CACHE_TY: u8 = 0xA0;
pub const GPU_SEND_DMA_NUM: u8 = 0x47;
pub const GPU_SEND_DMA_TY: u8 = 0xA0;
pub const GP1_COMMAND_NUM: u8 = 0x48;
pub const GP1_COMMAND_TY: u8 = 0xA0;
pub const GP0_COMMAND_NUM: u8 = 0x49;
pub const GP0_COMMAND_TY: u8 = 0xA0;
pub const GP0_COMMAND_PARAMS_NUM: u8 = 0x4A;
pub const GP0_COMMAND_PARAMS_TY: u8 = 0xA0;
pub const GPU_GET_STATUS_NUM: u8 = 0x4D;
pub const GPU_GET_STATUS_TY: u8 = 0xA0;
pub const GPU_SYNC_NUM: u8 = 0x4E;
pub const GPU_SYNC_TY: u8 = 0xA0;
pub const LOAD_AND_EXECUTE_NUM: u8 = 0x51;
pub const LOAD_AND_EXECUTE_TY: u8 = 0xA0;
pub const CD_INIT_NUM: u8 = 0x54;
pub const CD_INIT_TY: u8 = 0xA0;
pub const CD_REMOVE_NUM: u8 = 0x56;
pub const CD_REMOVE_TY: u8 = 0xA0;
pub const CD_ASYNC_GET_STATUS_NUM: u8 = 0x7C;
pub const CD_ASYNC_GET_STATUS_TY: u8 = 0xA0;
pub const ADD_CDROM_DEVICE_NUM: u8 = 0x96;
pub const ADD_CDROM_DEVICE_TY: u8 = 0xA0;
pub const SET_MEMSIZE_NUM: u8 = 0x9F;
pub const SET_MEMSIZE_TY: u8 = 0xA0;
pub const WARM_BOOT_NUM: u8 = 0xA0;
pub const WARM_BOOT_TY: u8 = 0xA0;
pub const CD_GET_LBN_NUM: u8 = 0xA4;
pub const CD_GET_LBN_TY: u8 = 0xA0;
pub const CD_GET_STATUS_NUM: u8 = 0xA6;
pub const CD_GET_STATUS_TY: u8 = 0xA0;
pub const GET_SYSTEM_INFO_NUM: u8 = 0xB4;
pub const GET_SYSTEM_INFO_TY: u8 = 0xA0;
pub const GET_TIMER_NUM: u8 = 0x03;
pub const GET_TIMER_TY: u8 = 0xB0;
pub const ENABLE_TIMER_IRQ_NUM: u8 = 0x04;
pub const ENABLE_TIMER_IRQ_TY: u8 = 0xB0;
pub const DISABLE_TIMER_IRQ_NUM: u8 = 0x05;
pub const DISABLE_TIMER_IRQ_TY: u8 = 0xB0;
pub const RESTART_TIMER_NUM: u8 = 0x06;
pub const RESTART_TIMER_TY: u8 = 0xB0;
pub const DELIVER_EVENT_NUM: u8 = 0x07;
pub const DELIVER_EVENT_TY: u8 = 0xB0;
pub const OPEN_EVENT_NUM: u8 = 0x08;
pub const OPEN_EVENT_TY: u8 = 0xB0;
pub const CLOSE_EVENT_NUM: u8 = 0x09;
pub const CLOSE_EVENT_TY: u8 = 0xB0;
pub const WAIT_EVENT_NUM: u8 = 0x0A;
pub const WAIT_EVENT_TY: u8 = 0xB0;
pub const TEST_EVENT_NUM: u8 = 0x0B;
pub const TEST_EVENT_TY: u8 = 0xB0;
pub const ENABLE_EVENT_NUM: u8 = 0x0C;
pub const ENABLE_EVENT_TY: u8 = 0xB0;
pub const DISABLE_EVENT_NUM: u8 = 0x0D;
pub const DISABLE_EVENT_TY: u8 = 0xB0;
pub const OPEN_THREAD_NUM: u8 = 0x0E;
pub const OPEN_THREAD_TY: u8 = 0xB0;
pub const CLOSE_THREAD_NUM: u8 = 0x0F;
pub const CLOSE_THREAD_TY: u8 = 0xB0;
pub const CHANGE_THREAD_NUM: u8 = 0x10;
pub const CHANGE_THREAD_TY: u8 = 0xB0;
pub const INIT_PAD_NUM: u8 = 0x12;
pub const INIT_PAD_TY: u8 = 0xB0;
pub const START_PAD_NUM: u8 = 0x13;
pub const START_PAD_TY: u8 = 0xB0;
pub const STOP_PAD_NUM: u8 = 0x14;
pub const STOP_PAD_TY: u8 = 0xB0;
pub const SET_DEFAULT_EXIT_FROM_EXCEPTION_NUM: u8 = 0x18;
pub const SET_DEFAULT_EXIT_FROM_EXCEPTION_TY: u8 = 0xB0;
pub const UNDELIVER_EVENT_NUM: u8 = 0x20;
pub const UNDELIVER_EVENT_TY: u8 = 0xB0;
pub const FIRST_FILE_NUM: u8 = 0x42;
pub const FIRST_FILE_TY: u8 = 0xB0;
pub const NEXT_FILE_NUM: u8 = 0x43;
pub const NEXT_FILE_TY: u8 = 0xB0;
pub const FILE_RENAME_NUM: u8 = 0x44;
pub const FILE_RENAME_TY: u8 = 0xB0;
pub const FILE_DELETE_NUM: u8 = 0x45;
pub const FILE_DELETE_TY: u8 = 0xB0;
pub const FILE_UNDELETE_NUM: u8 = 0x46;
pub const FILE_UNDELETE_TY: u8 = 0xB0;
pub const PRINT_INSTALLED_DEVICES_NUM: u8 = 0x49;
pub const PRINT_INSTALLED_DEVICES_TY: u8 = 0xB0;
pub const INIT_CARD_NUM: u8 = 0x4A;
pub const INIT_CARD_TY: u8 = 0xB0;
pub const START_CARD_NUM: u8 = 0x4B;
pub const START_CARD_TY: u8 = 0xB0;
pub const STOP_CARD_NUM: u8 = 0x4C;
pub const STOP_CARD_TY: u8 = 0xB0;
pub const GET_LAST_ERROR_NUM: u8 = 0x54;
pub const GET_LAST_ERROR_TY: u8 = 0xB0;
pub const GET_LAST_FILE_ERROR_NUM: u8 = 0x55;
pub const GET_LAST_FILE_ERROR_TY: u8 = 0xB0;
pub const CHANGE_CLEAR_PAD_NUM: u8 = 0x5B;
pub const CHANGE_CLEAR_PAD_TY: u8 = 0xB0;
pub const CHANGE_CLEAR_RCNT_NUM: u8 = 0x0A;
pub const CHANGE_CLEAR_RCNT_TY: u8 = 0xC0;
pub const FLUSH_STD_IN_OUT_PUT_NUM: u8 = 0x13;
pub const FLUSH_STD_IN_OUT_PUT_TY: u8 = 0xC0;
pub const ENTER_CRITICAL_SECTION_NUM: u8 = 0x01;
pub const EXIT_CRITICAL_SECTION_NUM: u8 = 0x02;
pub const CHANGE_THREAD_SUB_FN_NUM: u8 = 0x03;