From: dankcushions Date: Fri, 22 Apr 2016 14:05:41 +0000 (+0100) Subject: Merge branch 'master' of https://github.com/notaz/pcsx_rearmed into notaz-master X-Git-Tag: r24l~857^2^2 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cb4d282af668df3bdbd428be5a5ad26996cd0f4f;hp=-c;p=pcsx_rearmed.git Merge branch 'master' of https://github.com/notaz/pcsx_rearmed into notaz-master --- cb4d282af668df3bdbd428be5a5ad26996cd0f4f diff --combined frontend/libretro.c index a9b6e433,37cccc4f..ec065270 --- a/frontend/libretro.c +++ b/frontend/libretro.c @@@ -25,13 -25,10 +25,14 @@@ #include "main.h" #include "plugin.h" #include "plugin_lib.h" + #include "arm_features.h" #include "revision.h" #include "libretro.h" +#ifdef _3DS +#include "3ds/3ds_utils.h" +#endif + static retro_video_refresh_t video_cb; static retro_input_poll_t input_poll_cb; static retro_input_state_t input_state_cb; @@@ -55,7 -52,6 +56,7 @@@ extern char McdDisable[2] /* PCSX ReARMed core calls and stuff */ int in_type1, in_type2; int in_a1[2] = { 127, 127 }, in_a2[2] = { 127, 127 }; +int in_a3[2] = { 127, 127 }, in_a4[2] = { 127, 127 }; int in_keystate; int in_enable_vibration = 1; @@@ -169,87 -165,8 +170,87 @@@ static void vout_close(void { } -static void *pl_mmap(unsigned int size) +#ifdef _3DS +typedef struct { + void* buffer; + uint32_t target_map; + size_t size; + enum psxMapTag tag; +}psx_map_t; + +psx_map_t custom_psx_maps[] = { + {NULL, 0x13000000, 0x210000, MAP_TAG_RAM}, // 0x80000000 + {NULL, 0x12800000, 0x010000, MAP_TAG_OTHER}, // 0x1f800000 + {NULL, 0x12c00000, 0x080000, MAP_TAG_OTHER}, // 0x1fc00000 + {NULL, 0x11000000, 0x800000, MAP_TAG_LUTS}, // 0x08000000 + {NULL, 0x12000000, 0x200000, MAP_TAG_VRAM}, // 0x00000000 +}; + +void* pl_3ds_mmap(unsigned long addr, size_t size, int is_fixed, + enum psxMapTag tag) +{ + (void)is_fixed; + (void)addr; + + if (__ctr_svchax) + { + psx_map_t* custom_map = custom_psx_maps; + + for (; custom_map->size; custom_map++) + { + if ((custom_map->size == size) && (custom_map->tag == tag)) + { + uint32_t ptr_aligned, tmp; + + custom_map->buffer = malloc(size + 0x1000); + ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; + + if(svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_MAP, 0x3) < 0) + { + SysPrintf("could not map memory @0x%08X\n", custom_map->target_map); + exit(1); + } + + return (void*)custom_map->target_map; + } + } + } + + return malloc(size); +} + +void pl_3ds_munmap(void *ptr, size_t size, enum psxMapTag tag) +{ + (void)tag; + + if (__ctr_svchax) + { + psx_map_t* custom_map = custom_psx_maps; + + for (; custom_map->size; custom_map++) + { + if ((custom_map->target_map == (uint32_t)ptr)) + { + uint32_t ptr_aligned, tmp; + + ptr_aligned = (((u32)custom_map->buffer) + 0xFFF) & ~0xFFF; + + svcControlMemory(&tmp, (void*)custom_map->target_map, (void*)ptr_aligned, size, MEMOP_UNMAP, 0x3); + + free(custom_map->buffer); + custom_map->buffer = NULL; + return; + } + } + } + + free(ptr); +} +#endif + +static void *pl_mmap(unsigned int size) +{ return psxMap(0, size, 0, MAP_TAG_VRAM); } @@@ -327,8 -244,8 +328,8 @@@ void retro_set_environment(retro_enviro static const struct retro_variable vars[] = { { "pcsx_rearmed_frameskip", "Frameskip; 0|1|2|3" }, { "pcsx_rearmed_region", "Region; Auto|NTSC|PAL" }, - { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog" }, - { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog" }, + { "pcsx_rearmed_pad1type", "Pad 1 Type; standard|analog|negcon" }, + { "pcsx_rearmed_pad2type", "Pad 2 Type; standard|analog|negcon" }, #ifndef DRC_DISABLE { "pcsx_rearmed_drc", "Dynamic recompiler; enabled|disabled" }, #endif @@@ -340,8 -257,6 +341,8 @@@ { "pcsx_rearmed_duping_enable", "Frame duping; on|off" }, { "pcsx_rearmed_spu_reverb", "Sound: Reverb; on|off" }, { "pcsx_rearmed_spu_interpolation", "Sound: Interpolation; simple|gaussian|cubic|off" }, + { "pcsx_rearmed_pe2_fix", "Parasite Eve 2/Vandal Hearts 1/2 Fix; disabled|enabled" }, + { "pcsx_rearmed_inuyasha_fix", "InuYasha Sengoku Battle Fix; disabled|enabled" }, { NULL, NULL }, }; @@@ -1065,8 -980,6 +1066,8 @@@ static void update_variables(bool in_fl in_type1 = PSE_PAD_TYPE_STANDARD; if (strcmp(var.value, "analog") == 0) in_type1 = PSE_PAD_TYPE_ANALOGPAD; + if (strcmp(var.value, "negcon") == 0) + in_type1 = PSE_PAD_TYPE_NEGCON; } var.value = NULL; @@@ -1077,9 -990,6 +1078,9 @@@ in_type2 = PSE_PAD_TYPE_STANDARD; if (strcmp(var.value, "analog") == 0) in_type2 = PSE_PAD_TYPE_ANALOGPAD; + if (strcmp(var.value, "negcon") == 0) + in_type2 = PSE_PAD_TYPE_NEGCON; + } #ifdef __ARM_NEON__ @@@ -1136,11 -1046,6 +1137,11 @@@ { R3000Acpu *prev_cpu = psxCpu; +#ifdef _3DS + if(!__ctr_svchax) + Config.Cpu = CPU_INTERPRETER; + else +#endif if (strcmp(var.value, "disabled") == 0) Config.Cpu = CPU_INTERPRETER; else if (strcmp(var.value, "enabled") == 0) @@@ -1181,28 -1086,6 +1182,28 @@@ spu_config.iUseInterpolation = 0; } + var.value = "NULL"; + var.key = "pcsx_rearmed_pe2_fix"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + if (strcmp(var.value, "disabled") == 0) + Config.RCntFix = 0; + else if (strcmp(var.value, "enabled") == 0) + Config.RCntFix = 1; + } + + var.value = "NULL"; + var.key = "pcsx_rearmed_inuyasha_fix"; + + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) || var.value) + { + if (strcmp(var.value, "disabled") == 0) + Config.VSyncWA = 0; + else if (strcmp(var.value, "enabled") == 0) + Config.VSyncWA = 1; + } + if (in_flight) { // inform core things about possible config changes plugin_call_rearmed_cbs(); @@@ -1218,7 -1101,7 +1219,7 @@@ void retro_run(void) { - int i; + int i, val; input_poll_cb(); @@@ -1235,7 -1118,6 +1236,7 @@@ if (input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, i)) in_keystate |= retro_psx_map[i]; + if (in_type1 == PSE_PAD_TYPE_ANALOGPAD) { in_a1[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; @@@ -1244,68 -1126,6 +1245,68 @@@ in_a2[1] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128; } + if (in_type2 == PSE_PAD_TYPE_ANALOGPAD) + { + in_a3[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; + in_a3[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128; + in_a4[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; + in_a4[1] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 256) + 128; + } + + + if (in_type1 == PSE_PAD_TYPE_NEGCON) + { + /* left brake */ + if(input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, 12)) + in_a1[1] = 255; + else + in_a1[1] = 0; + + /* steer */ + in_a2[0] = (input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; + + /* thrust and fire */ + val = ((input_state_cb(0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 127)); + if(val < -2) { + in_a1[0] = 256 - val; + } + if (val > 2) { + in_a2[1] = val; + } + if(val >= -2 && val <= 2) + { + in_a2[1] = 0; + in_a1[0] = 0; + } + } + + if (in_type2 == PSE_PAD_TYPE_NEGCON) + { + /* left brake */ + if(input_state_cb(1, RETRO_DEVICE_JOYPAD, 0, 12)) + in_a3[1] = 255; + else + in_a3[1] = 0; + + /* steer */ + in_a4[0] = (input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X) / 256) + 128; + + /* thrust and fire */ + val = ((input_state_cb(1, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y) / 127)); + if(val < -2) { + in_a3[0] = 256 - val; + } + if (val > 2) { + in_a4[1] = val; + } + if(val >= -2 && val <= 2) + { + in_a4[1] = 0; + in_a3[0] = 0; + } + } + + stop = 0; psxCpu->Execute(); @@@ -1338,7 -1158,7 +1339,7 @@@ static bool try_use_bios(const char *pa return true; } -#if 1 +#ifndef VITA #include #include @@@ -1382,25 -1202,14 +1383,25 @@@ void retro_init(void int i, ret; bool found_bios = false; +#ifdef _3DS + psxMapHook = pl_3ds_mmap; + psxUnmapHook = pl_3ds_munmap; +#endif ret = emu_core_preinit(); +#ifdef _3DS + /* emu_core_preinit sets the cpu to dynarec */ + if(!__ctr_svchax) + Config.Cpu = CPU_INTERPRETER; +#endif ret |= emu_core_init(); if (ret != 0) { SysPrintf("PCSX init failed.\n"); exit(1); } -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) +#ifdef _3DS + vout_buf = linearMemAlign(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2, 0x80); +#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) && !defined(VITA) posix_memalign(&vout_buf, 16, VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); #else vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); @@@ -1408,7 -1217,7 +1409,7 @@@ if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) { - snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s/", dir); + snprintf(Config.BiosDir, sizeof(Config.BiosDir), "%s", dir); for (i = 0; i < sizeof(bios) / sizeof(bios[0]); i++) { snprintf(path, sizeof(path), "%s/%s.bin", dir, bios[i]); @@@ -1441,9 -1250,8 +1442,8 @@@ /* Set how much slower PSX CPU runs * 100 (so that 200 is 2 times) * we have to do this because cache misses and some IO penalties * are not emulated. Warning: changing this may break compatibility. */ - #if !defined(__arm__) || defined(__ARM_ARCH_7A__) cycle_multiplier = 175; - #else + #ifdef HAVE_PRE_ARMV7 cycle_multiplier = 200; #endif pl_rearmed_cbs.gpu_peops.iUseDither = 1; @@@ -1466,18 -1274,6 +1466,18 @@@ void retro_deinit(void) { SysClose(); +#ifdef _3DS + linearFree(vout_buf); +#else free(vout_buf); +#endif vout_buf = NULL; } + +#ifdef VITA +#include +int usleep (unsigned long us) +{ + sceKernelDelayThread(us); +} +#endif diff --combined frontend/main.c index 2deff706,a824fdcc..f0485845 --- a/frontend/main.c +++ b/frontend/main.c @@@ -11,7 -11,7 +11,7 @@@ #include #include #include -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) #include #endif @@@ -26,6 -26,7 +26,7 @@@ #include "../libpcsxcore/new_dynarec/new_dynarec.h" #include "../plugins/cdrcimg/cdrcimg.h" #include "../plugins/dfsound/spu_config.h" + #include "arm_features.h" #include "revision.h" #ifndef NO_FRONTEND @@@ -142,7 -143,7 +143,7 @@@ void emu_set_default_config(void spu_config.iVolume = 768; spu_config.iTempo = 0; spu_config.iUseThread = 1; // no effect if only 1 core is detected - #if defined(__arm__) && !defined(__ARM_ARCH_7A__) /* XXX GPH hack */ + #ifdef HAVE_PRE_ARMV7 /* XXX GPH hack */ spu_config.iUseReverb = 0; spu_config.iUseInterpolation = 0; spu_config.iTempo = 1; @@@ -771,7 -772,7 +772,7 @@@ int emu_save_state(int slot return ret; ret = SaveState(fname); - #if defined(__arm__) && !defined(__ARM_ARCH_7A__) && !defined(_3DS) /* XXX GPH hack */ + #ifdef HAVE_PRE_ARMV7 /* XXX GPH hack */ sync(); #endif SysPrintf("* %s \"%s\" [%d]\n", @@@ -985,7 -986,7 +986,7 @@@ void *SysLoadLibrary(const char *lib) return (void *)(long)(PLUGIN_DL_BASE + builtin_plugin_ids[i]); } -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) ret = dlopen(lib, RTLD_NOW); if (ret == NULL) SysMessage("dlopen: %s", dlerror()); @@@ -1002,7 -1003,7 +1003,7 @@@ void *SysLoadSym(void *lib, const char if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins)) return plugin_link(plugid - PLUGIN_DL_BASE, sym); -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) return dlsym(lib, sym); #else return NULL; @@@ -1010,9 -1011,7 +1011,9 @@@ } const char *SysLibError() { -#ifndef _WIN32 +#if defined(NO_DYLIB) + return NULL; +#elif !defined(_WIN32) return dlerror(); #else return "not supported"; @@@ -1025,7 -1024,7 +1026,7 @@@ void SysCloseLibrary(void *lib) if (PLUGIN_DL_BASE <= plugid && plugid < PLUGIN_DL_BASE + ARRAY_SIZE(builtin_plugins)) return; -#ifndef _WIN32 +#if !defined(_WIN32) && !defined(NO_DYLIB) dlclose(lib); #endif } diff --combined frontend/menu.c index 4fd0b565,cf9382a8..7e1fdd1c --- a/frontend/menu.c +++ b/frontend/menu.c @@@ -39,6 -39,7 +39,7 @@@ #include "../plugins/dfinput/externals.h" #include "../plugins/dfsound/spu_config.h" #include "psemu_plugin_defs.h" + #include "arm_features.h" #include "revision.h" #define REARMED_BIRTHDAY_TIME 1293306830 /* 25 Dec 2010 */ @@@ -100,7 -101,7 +101,7 @@@ int scanlines, scanline_level = 20 int soft_scaling, analog_deadzone; // for Caanoo int soft_filter; - #ifdef __ARM_ARCH_7A__ + #ifndef HAVE_PRE_ARMV7 #define DEFAULT_PSX_CLOCK 57 #define DEFAULT_PSX_CLOCK_S "57" #else @@@ -308,12 -309,12 +309,12 @@@ static void menu_sync_config(void switch (in_type_sel1) { case 1: in_type1 = PSE_PAD_TYPE_ANALOGPAD; break; - case 2: in_type1 = PSE_PAD_TYPE_GUNCON; break; + case 2: in_type1 = PSE_PAD_TYPE_NEGCON; break; default: in_type1 = PSE_PAD_TYPE_STANDARD; } switch (in_type_sel2) { case 1: in_type2 = PSE_PAD_TYPE_ANALOGPAD; break; - case 2: in_type2 = PSE_PAD_TYPE_GUNCON; break; + case 2: in_type2 = PSE_PAD_TYPE_NEGCON; break; default: in_type2 = PSE_PAD_TYPE_STANDARD; } if (in_evdev_allow_abs_only != allow_abs_only_old) { @@@ -732,7 -733,7 +733,7 @@@ static unsigned short fname2color(cons static void draw_savestate_bg(int slot); #define MENU_ALIGN_LEFT - #ifdef __ARM_ARCH_7A__ // assume hires device + #ifndef HAVE_PRE_ARMV7 // assume hires device #define MENU_X2 1 #else #define MENU_X2 0 @@@ -852,7 -853,7 +853,7 @@@ me_bind_action emuctrl_actions[] { "Toggle Frameskip ", 1 << SACTION_TOGGLE_FSKIP }, { "Take Screenshot ", 1 << SACTION_SCREENSHOT }, { "Show/Hide FPS ", 1 << SACTION_TOGGLE_FPS }, - #ifdef __ARM_ARCH_7A__ + #ifndef HAVE_PRE_ARMV7 { "Switch Renderer ", 1 << SACTION_SWITCH_DISPMODE }, #endif { "Fast Forward ", 1 << SACTION_FAST_FORWARD }, @@@ -2521,7 -2522,7 +2522,7 @@@ void menu_init(void me_enable(e_menu_gfx_options, MA_OPT_GAMMA, plat_target.gamma_set != NULL); - #ifndef __ARM_ARCH_7A__ + #ifdef HAVE_PRE_ARMV7 me_enable(e_menu_gfx_options, MA_OPT_SWFILTER, 0); #endif me_enable(e_menu_gfx_options, MA_OPT_VARSCALER, MENU_SHOW_VARSCALER); diff --combined libpcsxcore/cdriso.c index 46ee0207,515370f7..d2c904c5 --- a/libpcsxcore/cdriso.c +++ b/libpcsxcore/cdriso.c @@@ -30,7 -30,7 +30,7 @@@ #include #include #define strcasecmp _stricmp -#define usleep(x) Sleep((x) / 1000) +#define usleep(x) (Sleep((x) / 1000)) #else #include #include @@@ -39,6 -39,8 +39,8 @@@ #include #include + #define OFF_T_MSB ((off_t)1 << (sizeof(off_t) * 8 - 1)) + unsigned int cdrIsoMultidiskCount; unsigned int cdrIsoMultidiskSelect; @@@ -83,7 -85,7 +85,7 @@@ static unsigned int pregapOffset static struct { unsigned char buff_raw[16][CD_FRAMESIZE_RAW]; unsigned char buff_compressed[CD_FRAMESIZE_RAW * 16 + 100]; - unsigned int *index_table; + off_t *index_table; unsigned int index_len; unsigned int block_shift; unsigned int current_block; @@@ -223,9 -225,7 +225,9 @@@ static void *playthread(void *param do { ret = SPU_playCDDAchannel((short *)sndbuffer, s); if (ret == 0x7761) + { usleep(6 * 1000); + } } while (ret == 0x7761 && playing); // rearmed_wait } @@@ -236,9 -236,7 +238,9 @@@ // HACK: stop feeding data while emu is paused extern int stop; while (stop && playing) + { usleep(10000); + } now = GetTickCount(); osleep = t - now; @@@ -791,8 -789,9 +793,9 @@@ static int handlepbp(const char *isofil unsigned int dontcare[6]; } index_entry; char psar_sig[11]; - unsigned int t, cd_length, cdimg_base; - unsigned int offsettab[8], psisoimg_offs; + off_t psisoimg_offs, cdimg_base; + unsigned int t, cd_length; + unsigned int offsettab[8]; const char *ext = NULL; int i, ret; @@@ -801,7 -800,7 +804,7 @@@ if (ext == NULL || (strcmp(ext, ".pbp") != 0 && strcmp(ext, ".PBP") != 0)) return -1; - fseek(cdHandle, 0, SEEK_SET); + fseeko(cdHandle, 0, SEEK_SET); numtracks = 0; @@@ -811,7 -810,7 +814,7 @@@ goto fail_io; } - ret = fseek(cdHandle, pbp_hdr.psar_offs, SEEK_SET); + ret = fseeko(cdHandle, pbp_hdr.psar_offs, SEEK_SET); if (ret != 0) { SysPrintf("failed to seek to %x\n", pbp_hdr.psar_offs); goto fail_io; @@@ -822,7 -821,7 +825,7 @@@ psar_sig[10] = 0; if (strcmp(psar_sig, "PSTITLEIMG") == 0) { // multidisk image? - ret = fseek(cdHandle, pbp_hdr.psar_offs + 0x200, SEEK_SET); + ret = fseeko(cdHandle, pbp_hdr.psar_offs + 0x200, SEEK_SET); if (ret != 0) { SysPrintf("failed to seek to %x\n", pbp_hdr.psar_offs + 0x200); goto fail_io; @@@ -848,9 -847,9 +851,9 @@@ psisoimg_offs += offsettab[cdrIsoMultidiskSelect]; - ret = fseek(cdHandle, psisoimg_offs, SEEK_SET); + ret = fseeko(cdHandle, psisoimg_offs, SEEK_SET); if (ret != 0) { - SysPrintf("failed to seek to %x\n", psisoimg_offs); + SysPrintf("failed to seek to %llx\n", (long long)psisoimg_offs); goto fail_io; } @@@ -864,9 -863,9 +867,9 @@@ } // seek to TOC - ret = fseek(cdHandle, psisoimg_offs + 0x800, SEEK_SET); + ret = fseeko(cdHandle, psisoimg_offs + 0x800, SEEK_SET); if (ret != 0) { - SysPrintf("failed to seek to %x\n", psisoimg_offs + 0x800); + SysPrintf("failed to seek to %llx\n", (long long)psisoimg_offs + 0x800); goto fail_io; } @@@ -900,7 -899,7 +903,7 @@@ sec2msf(t, ti[numtracks].length); // seek to ISO index - ret = fseek(cdHandle, psisoimg_offs + 0x4000, SEEK_SET); + ret = fseeko(cdHandle, psisoimg_offs + 0x4000, SEEK_SET); if (ret != 0) { SysPrintf("failed to seek to ISO index\n"); goto fail_io; @@@ -958,6 -957,7 +961,7 @@@ static int handlecbin(const char *isofi unsigned char rsv_06[2]; } ciso_hdr; const char *ext = NULL; + unsigned int *index_table = NULL; unsigned int index = 0, plain; int i, ret; @@@ -979,7 -979,7 +983,7 @@@ return -1; } if (ciso_hdr.header_size != 0 && ciso_hdr.header_size != sizeof(ciso_hdr)) { - ret = fseek(cdHandle, ciso_hdr.header_size, SEEK_SET); + ret = fseeko(cdHandle, ciso_hdr.header_size, SEEK_SET); if (ret != 0) { SysPrintf("failed to seek to %x\n", ciso_hdr.header_size); return -1; @@@ -994,30 -994,33 +998,33 @@@ compr_img->current_block = (unsigned int)-1; compr_img->index_len = ciso_hdr.total_bytes / ciso_hdr.block_size; - compr_img->index_table = malloc((compr_img->index_len + 1) * sizeof(compr_img->index_table[0])); - if (compr_img->index_table == NULL) + index_table = malloc((compr_img->index_len + 1) * sizeof(index_table[0])); + if (index_table == NULL) goto fail_io; - ret = fread(compr_img->index_table, sizeof(compr_img->index_table[0]), compr_img->index_len, cdHandle); + ret = fread(index_table, sizeof(index_table[0]), compr_img->index_len, cdHandle); if (ret != compr_img->index_len) { SysPrintf("failed to read index table\n"); goto fail_index; } + compr_img->index_table = malloc((compr_img->index_len + 1) * sizeof(compr_img->index_table[0])); + if (compr_img->index_table == NULL) + goto fail_index; + for (i = 0; i < compr_img->index_len + 1; i++) { - index = compr_img->index_table[i]; + index = index_table[i]; plain = index & 0x80000000; index &= 0x7fffffff; - compr_img->index_table[i] = (index << ciso_hdr.align) | plain; + compr_img->index_table[i] = (off_t)index << ciso_hdr.align; + if (plain) + compr_img->index_table[i] |= OFF_T_MSB; } - if ((long long)index << ciso_hdr.align >= 0x80000000ll) - SysPrintf("warning: ciso img too large, expect problems\n"); return 0; fail_index: - free(compr_img->index_table); - compr_img->index_table = NULL; + free(index_table); fail_io: if (compr_img != NULL) { free(compr_img); @@@ -1120,8 -1123,9 +1127,9 @@@ static int uncompress2(void *out, unsig static int cdread_compressed(FILE *f, unsigned int base, void *dest, int sector) { unsigned long cdbuffer_size, cdbuffer_size_expect; - unsigned int start_byte, size; + unsigned int size; int is_compressed; + off_t start_byte; int ret, block; if (base) @@@ -1140,16 -1144,16 +1148,16 @@@ return -1; } - start_byte = compr_img->index_table[block] & 0x7fffffff; - if (fseek(cdHandle, start_byte, SEEK_SET) != 0) { - SysPrintf("seek error for block %d at %x: ", - block, start_byte); + start_byte = compr_img->index_table[block] & ~OFF_T_MSB; + if (fseeko(cdHandle, start_byte, SEEK_SET) != 0) { + SysPrintf("seek error for block %d at %llx: ", + block, (long long)start_byte); perror(NULL); return -1; } - is_compressed = !(compr_img->index_table[block] & 0x80000000); - size = (compr_img->index_table[block + 1] & 0x7fffffff) - start_byte; + is_compressed = !(compr_img->index_table[block] & OFF_T_MSB); + size = (compr_img->index_table[block + 1] & ~OFF_T_MSB) - start_byte; if (size > sizeof(compr_img->buff_compressed)) { SysPrintf("block %d is too large: %u\n", block, size); return -1; @@@ -1280,11 -1284,11 +1288,11 @@@ static long CALLBACK ISOopen(void) SysPrintf("[+sbi]"); } - fseek(cdHandle, 0, SEEK_END); + fseeko(cdHandle, 0, SEEK_END); // maybe user selected metadata file instead of main .bin .. bin_filename = GetIsoFile(); - if (ftell(cdHandle) < 2352 * 0x10) { + if (ftello(cdHandle) < 2352 * 0x10) { static const char *exts[] = { ".bin", ".BIN", ".img", ".IMG" }; FILE *tmpf = NULL; size_t i; @@@ -1305,12 -1309,12 +1313,12 @@@ bin_filename = alt_bin_filename; fclose(cdHandle); cdHandle = tmpf; - fseek(cdHandle, 0, SEEK_END); + fseeko(cdHandle, 0, SEEK_END); } } // guess whether it is mode1/2048 - if (ftell(cdHandle) % 2048 == 0) { + if (ftello(cdHandle) % 2048 == 0) { unsigned int modeTest = 0; fseek(cdHandle, 0, SEEK_SET); fread(&modeTest, 4, 1, cdHandle);