From eac0e638190211e579f169357dfaff28c0aa801a Mon Sep 17 00:00:00 2001 From: aliaspider Date: Thu, 1 Oct 2015 00:30:14 +0100 Subject: [PATCH] clean indentation --- platform/libretro/libretro.c | 904 +++++++++++++++++------------------ 1 file changed, 452 insertions(+), 452 deletions(-) diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index 8bd6363f..62b168e3 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -75,11 +75,11 @@ void cache_flush_d_inval_i(void *start, void *end) { #ifdef __arm__ #if defined(__BLACKBERRY_QNX__) - msync(start, end - start, MS_SYNC | MS_CACHE_ONLY | MS_INVALIDATE_ICACHE); + msync(start, end - start, MS_SYNC | MS_CACHE_ONLY | MS_INVALIDATE_ICACHE); #elif defined(__MACH__) - size_t len = (char *)end - (char *)start; - sys_dcache_flush(start, len); - sys_icache_invalidate(start, len); + size_t len = (char *)end - (char *)start; + sys_dcache_flush(start, len); + sys_icache_invalidate(start, len); #elif defined(_3DS) ctr_flush_invalidate_cache(); #else @@ -128,62 +128,62 @@ void cache_flush_d_inval_i(void *start, void *end) static void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset) { - uint32_t flProtect, dwDesiredAccess; - off_t end; - HANDLE mmap_fd, h; - void *ret; - - if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) - return MAP_FAILED; - if (fd == -1) { - if (!(flags & MAP_ANON) || offset) - return MAP_FAILED; - } else if (flags & MAP_ANON) - return MAP_FAILED; - - if (prot & PROT_WRITE) { - if (prot & PROT_EXEC) - flProtect = PAGE_EXECUTE_READWRITE; - else - flProtect = PAGE_READWRITE; - } else if (prot & PROT_EXEC) { - if (prot & PROT_READ) - flProtect = PAGE_EXECUTE_READ; - else if (prot & PROT_EXEC) - flProtect = PAGE_EXECUTE; - } else - flProtect = PAGE_READONLY; - - end = length + offset; - - if (fd == -1) - mmap_fd = INVALID_HANDLE_VALUE; - else - mmap_fd = (HANDLE)_get_osfhandle(fd); - h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL); - if (h == NULL) - return MAP_FAILED; - - if (prot & PROT_WRITE) - dwDesiredAccess = FILE_MAP_WRITE; - else - dwDesiredAccess = FILE_MAP_READ; - if (prot & PROT_EXEC) - dwDesiredAccess |= FILE_MAP_EXECUTE; - if (flags & MAP_PRIVATE) - dwDesiredAccess |= FILE_MAP_COPY; - ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length); - if (ret == NULL) { - CloseHandle(h); - ret = MAP_FAILED; - } - return ret; + uint32_t flProtect, dwDesiredAccess; + off_t end; + HANDLE mmap_fd, h; + void *ret; + + if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) + return MAP_FAILED; + if (fd == -1) { + if (!(flags & MAP_ANON) || offset) + return MAP_FAILED; + } else if (flags & MAP_ANON) + return MAP_FAILED; + + if (prot & PROT_WRITE) { + if (prot & PROT_EXEC) + flProtect = PAGE_EXECUTE_READWRITE; + else + flProtect = PAGE_READWRITE; + } else if (prot & PROT_EXEC) { + if (prot & PROT_READ) + flProtect = PAGE_EXECUTE_READ; + else if (prot & PROT_EXEC) + flProtect = PAGE_EXECUTE; + } else + flProtect = PAGE_READONLY; + + end = length + offset; + + if (fd == -1) + mmap_fd = INVALID_HANDLE_VALUE; + else + mmap_fd = (HANDLE)_get_osfhandle(fd); + h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL); + if (h == NULL) + return MAP_FAILED; + + if (prot & PROT_WRITE) + dwDesiredAccess = FILE_MAP_WRITE; + else + dwDesiredAccess = FILE_MAP_READ; + if (prot & PROT_EXEC) + dwDesiredAccess |= FILE_MAP_EXECUTE; + if (flags & MAP_PRIVATE) + dwDesiredAccess |= FILE_MAP_COPY; + ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length); + if (ret == NULL) { + CloseHandle(h); + ret = MAP_FAILED; + } + return ret; } static void munmap(void *addr, size_t length) { - UnmapViewOfFile(addr); - /* ruh-ro, we leaked handle from CreateFileMapping() ... */ + UnmapViewOfFile(addr); + /* ruh-ro, we leaked handle from CreateFileMapping() ... */ } #elif defined(NO_MMAP) #define PROT_EXEC 0x04 @@ -205,7 +205,7 @@ void munmap(void *base_addr, size_t len) int mprotect(void *addr, size_t len, int prot) { - /* stub - not really needed at this point since this codepath has no dynarecs */ + /* stub - not really needed at this point since this codepath has no dynarecs */ return 0; } @@ -367,46 +367,46 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed) } } - return ret; + return ret; } void *plat_mremap(void *ptr, size_t oldsize, size_t newsize) { #ifdef __linux__ - void *ret = mremap(ptr, oldsize, newsize, 0); - if (ret == MAP_FAILED) - return NULL; + void *ret = mremap(ptr, oldsize, newsize, 0); + if (ret == MAP_FAILED) + return NULL; - return ret; + return ret; #else - void *tmp, *ret; - size_t preserve_size; - - preserve_size = oldsize; - if (preserve_size > newsize) - preserve_size = newsize; - tmp = malloc(preserve_size); - if (tmp == NULL) - return NULL; - memcpy(tmp, ptr, preserve_size); - - munmap(ptr, oldsize); - ret = mmap(ptr, newsize, PROT_READ | PROT_WRITE, - MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (ret == MAP_FAILED) { - free(tmp); - return NULL; - } - memcpy(ret, tmp, preserve_size); - free(tmp); - return ret; + void *tmp, *ret; + size_t preserve_size; + + preserve_size = oldsize; + if (preserve_size > newsize) + preserve_size = newsize; + tmp = malloc(preserve_size); + if (tmp == NULL) + return NULL; + memcpy(tmp, ptr, preserve_size); + + munmap(ptr, oldsize); + ret = mmap(ptr, newsize, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + if (ret == MAP_FAILED) { + free(tmp); + return NULL; + } + memcpy(ret, tmp, preserve_size); + free(tmp); + return ret; #endif } void plat_munmap(void *ptr, size_t size) { - if (ptr != NULL) - munmap(ptr, size); + if (ptr != NULL) + munmap(ptr, size); } #endif @@ -441,17 +441,17 @@ int plat_mem_set_exec(void *ptr, size_t size) if (ret != 0 && log_cb) log_cb(RETRO_LOG_ERROR, "mprotect(%p, %zd) failed: %d\n", ptr, size, errno); #endif - return ret; + return ret; } void emu_video_mode_change(int start_line, int line_count, int is_32cols) { - memset(vout_buf, 0, 320 * 240 * 2); - vout_width = is_32cols ? 256 : 320; - PicoDrawSetOutBuf(vout_buf, vout_width * 2); + memset(vout_buf, 0, 320 * 240 * 2); + vout_width = is_32cols ? 256 : 320; + PicoDrawSetOutBuf(vout_buf, vout_width * 2); - vout_height = line_count; - vout_offset = vout_width * start_line; + vout_height = line_count; + vout_offset = vout_width * start_line; } void emu_32x_startup(void) @@ -473,22 +473,22 @@ void lprintf(const char *fmt, ...) /* libretro */ void retro_set_environment(retro_environment_t cb) { - static const struct retro_variable vars[] = { - //{ "region", "Region; Auto|NTSC|PAL" }, - { "picodrive_input1", "Input device 1; 3 button pad|6 button pad|None" }, - { "picodrive_input2", "Input device 2; 3 button pad|6 button pad|None" }, - { "picodrive_sprlim", "No sprite limit; disabled|enabled" }, - { "picodrive_ramcart", "MegaCD RAM cart; disabled|enabled" }, - { "picodrive_region", "Region; Auto|Japan NTSC|Japan PAL|US|Europe" }, + static const struct retro_variable vars[] = { + //{ "region", "Region; Auto|NTSC|PAL" }, + { "picodrive_input1", "Input device 1; 3 button pad|6 button pad|None" }, + { "picodrive_input2", "Input device 2; 3 button pad|6 button pad|None" }, + { "picodrive_sprlim", "No sprite limit; disabled|enabled" }, + { "picodrive_ramcart", "MegaCD RAM cart; disabled|enabled" }, + { "picodrive_region", "Region; Auto|Japan NTSC|Japan PAL|US|Europe" }, #ifdef DRC_SH2 - { "picodrive_drc", "Dynamic recompilers; enabled|disabled" }, + { "picodrive_drc", "Dynamic recompilers; enabled|disabled" }, #endif - { NULL, NULL }, - }; + { NULL, NULL }, + }; - environ_cb = cb; + environ_cb = cb; - cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void *)vars); + cb(RETRO_ENVIRONMENT_SET_VARIABLES, (void *)vars); } void retro_set_video_refresh(retro_video_refresh_t cb) { video_cb = cb; } @@ -499,7 +499,7 @@ void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; } unsigned retro_api_version(void) { - return RETRO_API_VERSION; + return RETRO_API_VERSION; } void retro_set_controller_port_device(unsigned port, unsigned device) @@ -508,145 +508,145 @@ void retro_set_controller_port_device(unsigned port, unsigned device) void retro_get_system_info(struct retro_system_info *info) { - memset(info, 0, sizeof(*info)); - info->library_name = "PicoDrive"; - info->library_version = VERSION; - info->valid_extensions = "bin|gen|smd|md|32x|cue|iso|sms"; - info->need_fullpath = true; + memset(info, 0, sizeof(*info)); + info->library_name = "PicoDrive"; + info->library_version = VERSION; + info->valid_extensions = "bin|gen|smd|md|32x|cue|iso|sms"; + info->need_fullpath = true; } void retro_get_system_av_info(struct retro_system_av_info *info) { - memset(info, 0, sizeof(*info)); - info->timing.fps = Pico.m.pal ? 50 : 60; - info->timing.sample_rate = 44100; - info->geometry.base_width = 320; - info->geometry.base_height = vout_height; - info->geometry.max_width = VOUT_MAX_WIDTH; - info->geometry.max_height = VOUT_MAX_HEIGHT; - info->geometry.aspect_ratio = 4.0f / 3.0f; + memset(info, 0, sizeof(*info)); + info->timing.fps = Pico.m.pal ? 50 : 60; + info->timing.sample_rate = 44100; + info->geometry.base_width = 320; + info->geometry.base_height = vout_height; + info->geometry.max_width = VOUT_MAX_WIDTH; + info->geometry.max_height = VOUT_MAX_HEIGHT; + info->geometry.aspect_ratio = 4.0f / 3.0f; } /* savestates */ struct savestate_state { - const char *load_buf; - char *save_buf; - size_t size; - size_t pos; + const char *load_buf; + char *save_buf; + size_t size; + size_t pos; }; size_t state_read(void *p, size_t size, size_t nmemb, void *file) { - struct savestate_state *state = file; - size_t bsize = size * nmemb; + struct savestate_state *state = file; + size_t bsize = size * nmemb; - if (state->pos + bsize > state->size) { + if (state->pos + bsize > state->size) { if (log_cb) log_cb(RETRO_LOG_ERROR, "savestate error: %u/%u\n", state->pos + bsize, state->size); - bsize = state->size - state->pos; - if ((int)bsize <= 0) - return 0; - } - - memcpy(p, state->load_buf + state->pos, bsize); - state->pos += bsize; - return bsize; + bsize = state->size - state->pos; + if ((int)bsize <= 0) + return 0; + } + + memcpy(p, state->load_buf + state->pos, bsize); + state->pos += bsize; + return bsize; } size_t state_write(void *p, size_t size, size_t nmemb, void *file) { - struct savestate_state *state = file; - size_t bsize = size * nmemb; + struct savestate_state *state = file; + size_t bsize = size * nmemb; - if (state->pos + bsize > state->size) { + if (state->pos + bsize > state->size) { if (log_cb) log_cb(RETRO_LOG_ERROR, "savestate error: %u/%u\n", state->pos + bsize, state->size); - bsize = state->size - state->pos; - if ((int)bsize <= 0) - return 0; - } - - memcpy(state->save_buf + state->pos, p, bsize); - state->pos += bsize; - return bsize; + bsize = state->size - state->pos; + if ((int)bsize <= 0) + return 0; + } + + memcpy(state->save_buf + state->pos, p, bsize); + state->pos += bsize; + return bsize; } size_t state_skip(void *p, size_t size, size_t nmemb, void *file) { - struct savestate_state *state = file; - size_t bsize = size * nmemb; + struct savestate_state *state = file; + size_t bsize = size * nmemb; - state->pos += bsize; - return bsize; + state->pos += bsize; + return bsize; } size_t state_eof(void *file) { - struct savestate_state *state = file; + struct savestate_state *state = file; - return state->pos >= state->size; + return state->pos >= state->size; } int state_fseek(void *file, long offset, int whence) { - struct savestate_state *state = file; - - switch (whence) { - case SEEK_SET: - state->pos = offset; - break; - case SEEK_CUR: - state->pos += offset; - break; - case SEEK_END: - state->pos = state->size + offset; - break; - } - return (int)state->pos; + struct savestate_state *state = file; + + switch (whence) { + case SEEK_SET: + state->pos = offset; + break; + case SEEK_CUR: + state->pos += offset; + break; + case SEEK_END: + state->pos = state->size + offset; + break; + } + return (int)state->pos; } /* savestate sizes vary wildly depending if cd/32x or * carthw is active, so run the whole thing to get size */ -size_t retro_serialize_size(void) -{ - struct savestate_state state = { 0, }; - int ret; +size_t retro_serialize_size(void) +{ + struct savestate_state state = { 0, }; + int ret; - ret = PicoStateFP(&state, 1, NULL, state_skip, NULL, state_fseek); - if (ret != 0) - return 0; + ret = PicoStateFP(&state, 1, NULL, state_skip, NULL, state_fseek); + if (ret != 0) + return 0; - return state.pos; + return state.pos; } bool retro_serialize(void *data, size_t size) -{ - struct savestate_state state = { 0, }; - int ret; +{ + struct savestate_state state = { 0, }; + int ret; - state.save_buf = data; - state.size = size; - state.pos = 0; + state.save_buf = data; + state.size = size; + state.pos = 0; - ret = PicoStateFP(&state, 1, NULL, state_write, - NULL, state_fseek); - return ret == 0; + ret = PicoStateFP(&state, 1, NULL, state_write, + NULL, state_fseek); + return ret == 0; } bool retro_unserialize(const void *data, size_t size) { - struct savestate_state state = { 0, }; - int ret; + struct savestate_state state = { 0, }; + int ret; - state.load_buf = data; - state.size = size; - state.pos = 0; + state.load_buf = data; + state.size = size; + state.pos = 0; - ret = PicoStateFP(&state, 0, state_read, NULL, - state_eof, state_fseek); - return ret == 0; + ret = PicoStateFP(&state, 0, state_read, NULL, + state_eof, state_fseek); + return ret == 0; } /* cheats - TODO */ @@ -663,193 +663,193 @@ static bool disk_ejected; static unsigned int disk_current_index; static unsigned int disk_count; static struct disks_state { - char *fname; + char *fname; } disks[8]; static bool disk_set_eject_state(bool ejected) { - // TODO? - disk_ejected = ejected; - return true; + // TODO? + disk_ejected = ejected; + return true; } static bool disk_get_eject_state(void) { - return disk_ejected; + return disk_ejected; } static unsigned int disk_get_image_index(void) { - return disk_current_index; + return disk_current_index; } static bool disk_set_image_index(unsigned int index) { - enum cd_img_type cd_type; - int ret; + enum cd_img_type cd_type; + int ret; - if (index >= sizeof(disks) / sizeof(disks[0])) - return false; + if (index >= sizeof(disks) / sizeof(disks[0])) + return false; - if (disks[index].fname == NULL) { + if (disks[index].fname == NULL) { if (log_cb) log_cb(RETRO_LOG_ERROR, "missing disk #%u\n", index); - // RetroArch specifies "no disk" with index == count, - // so don't fail here.. - disk_current_index = index; - return true; - } + // RetroArch specifies "no disk" with index == count, + // so don't fail here.. + disk_current_index = index; + return true; + } if (log_cb) log_cb(RETRO_LOG_INFO, "switching to disk %u: \"%s\"\n", index, disks[index].fname); - ret = -1; - cd_type = PicoCdCheck(disks[index].fname, NULL); - if (cd_type != CIT_NOT_CD) - ret = cdd_load(disks[index].fname, cd_type); - if (ret != 0) { + ret = -1; + cd_type = PicoCdCheck(disks[index].fname, NULL); + if (cd_type != CIT_NOT_CD) + ret = cdd_load(disks[index].fname, cd_type); + if (ret != 0) { if (log_cb) log_cb(RETRO_LOG_ERROR, "Load failed, invalid CD image?\n"); - return 0; - } + return 0; + } - disk_current_index = index; - return true; + disk_current_index = index; + return true; } static unsigned int disk_get_num_images(void) { - return disk_count; + return disk_count; } static bool disk_replace_image_index(unsigned index, - const struct retro_game_info *info) + const struct retro_game_info *info) { - bool ret = true; + bool ret = true; - if (index >= sizeof(disks) / sizeof(disks[0])) - return false; + if (index >= sizeof(disks) / sizeof(disks[0])) + return false; - if (disks[index].fname != NULL) - free(disks[index].fname); - disks[index].fname = NULL; + if (disks[index].fname != NULL) + free(disks[index].fname); + disks[index].fname = NULL; - if (info != NULL) { - disks[index].fname = strdup(info->path); - if (index == disk_current_index) - ret = disk_set_image_index(index); - } + if (info != NULL) { + disks[index].fname = strdup(info->path); + if (index == disk_current_index) + ret = disk_set_image_index(index); + } - return ret; + return ret; } static bool disk_add_image_index(void) { - if (disk_count >= sizeof(disks) / sizeof(disks[0])) - return false; + if (disk_count >= sizeof(disks) / sizeof(disks[0])) + return false; - disk_count++; - return true; + disk_count++; + return true; } static struct retro_disk_control_callback disk_control = { - disk_set_eject_state, - disk_get_eject_state, - disk_get_image_index, - disk_set_image_index, - disk_get_num_images, - disk_replace_image_index, - disk_add_image_index, + disk_set_eject_state, + disk_get_eject_state, + disk_get_image_index, + disk_set_image_index, + disk_get_num_images, + disk_replace_image_index, + disk_add_image_index, }; static void disk_tray_open(void) { if (log_cb) log_cb(RETRO_LOG_INFO, "cd tray open\n"); - disk_ejected = 1; + disk_ejected = 1; } static void disk_tray_close(void) { if (log_cb) log_cb(RETRO_LOG_INFO, "cd tray close\n"); - disk_ejected = 0; + disk_ejected = 0; } static const char * const biosfiles_us[] = { - "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210", "bios_CD_U" + "us_scd2_9306", "SegaCDBIOS9303", "us_scd1_9210", "bios_CD_U" }; static const char * const biosfiles_eu[] = { - "eu_mcd2_9306", "eu_mcd2_9303", "eu_mcd1_9210", "bios_CD_E" + "eu_mcd2_9306", "eu_mcd2_9303", "eu_mcd1_9210", "bios_CD_E" }; static const char * const biosfiles_jp[] = { - "jp_mcd2_921222", "jp_mcd1_9112", "jp_mcd1_9111", "bios_CD_J" + "jp_mcd2_921222", "jp_mcd1_9112", "jp_mcd1_9111", "bios_CD_J" }; static void make_system_path(char *buf, size_t buf_size, - const char *name, const char *ext) + const char *name, const char *ext) { - const char *dir = NULL; - - if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) { - snprintf(buf, buf_size, "%s%c%s%s", dir, SLASH, name, ext); - } - else { - snprintf(buf, buf_size, "%s%s", name, ext); - } + const char *dir = NULL; + + if (environ_cb(RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY, &dir) && dir) { + snprintf(buf, buf_size, "%s%c%s%s", dir, SLASH, name, ext); + } + else { + snprintf(buf, buf_size, "%s%s", name, ext); + } } static const char *find_bios(int *region, const char *cd_fname) { - const char * const *files; - static char path[256]; - int i, count; - FILE *f = NULL; - - if (*region == 4) { // US - files = biosfiles_us; - count = sizeof(biosfiles_us) / sizeof(char *); - } else if (*region == 8) { // EU - files = biosfiles_eu; - count = sizeof(biosfiles_eu) / sizeof(char *); - } else if (*region == 1 || *region == 2) { - files = biosfiles_jp; - count = sizeof(biosfiles_jp) / sizeof(char *); - } else { - return NULL; - } - - for (i = 0; i < count; i++) - { - make_system_path(path, sizeof(path), files[i], ".bin"); - f = fopen(path, "rb"); - if (f != NULL) - break; - - make_system_path(path, sizeof(path), files[i], ".zip"); - f = fopen(path, "rb"); - if (f != NULL) - break; - } - - if (f != NULL) { + const char * const *files; + static char path[256]; + int i, count; + FILE *f = NULL; + + if (*region == 4) { // US + files = biosfiles_us; + count = sizeof(biosfiles_us) / sizeof(char *); + } else if (*region == 8) { // EU + files = biosfiles_eu; + count = sizeof(biosfiles_eu) / sizeof(char *); + } else if (*region == 1 || *region == 2) { + files = biosfiles_jp; + count = sizeof(biosfiles_jp) / sizeof(char *); + } else { + return NULL; + } + + for (i = 0; i < count; i++) + { + make_system_path(path, sizeof(path), files[i], ".bin"); + f = fopen(path, "rb"); + if (f != NULL) + break; + + make_system_path(path, sizeof(path), files[i], ".zip"); + f = fopen(path, "rb"); + if (f != NULL) + break; + } + + if (f != NULL) { if (log_cb) log_cb(RETRO_LOG_INFO, "using bios: %s\n", path); - fclose(f); - return path; - } + fclose(f); + return path; + } - return NULL; + return NULL; } bool retro_load_game(const struct retro_game_info *info) { - enum media_type_e media_type; - static char carthw_path[256]; - size_t i; + enum media_type_e media_type; + static char carthw_path[256]; + size_t i; struct retro_input_descriptor desc[] = { { 0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "D-Pad Left" }, @@ -961,210 +961,210 @@ bool retro_load_game(const struct retro_game_info *info) environ_cb(RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS, desc); - enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; - if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { + enum retro_pixel_format fmt = RETRO_PIXEL_FORMAT_RGB565; + if (!environ_cb(RETRO_ENVIRONMENT_SET_PIXEL_FORMAT, &fmt)) { if (log_cb) log_cb(RETRO_LOG_ERROR, "RGB565 support required, sorry\n"); - return false; - } + return false; + } - if (info == NULL || info->path == NULL) { + if (info == NULL || info->path == NULL) { if (log_cb) log_cb(RETRO_LOG_ERROR, "info->path required\n"); - return false; - } + return false; + } - for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) { - if (disks[i].fname != NULL) { - free(disks[i].fname); - disks[i].fname = NULL; - } - } + for (i = 0; i < sizeof(disks) / sizeof(disks[0]); i++) { + if (disks[i].fname != NULL) { + free(disks[i].fname); + disks[i].fname = NULL; + } + } - disk_current_index = 0; - disk_count = 1; - disks[0].fname = strdup(info->path); + disk_current_index = 0; + disk_count = 1; + disks[0].fname = strdup(info->path); - make_system_path(carthw_path, sizeof(carthw_path), "carthw", ".cfg"); + make_system_path(carthw_path, sizeof(carthw_path), "carthw", ".cfg"); - media_type = PicoLoadMedia(info->path, carthw_path, - find_bios, NULL); + media_type = PicoLoadMedia(info->path, carthw_path, + find_bios, NULL); - switch (media_type) { - case PM_BAD_DETECT: + switch (media_type) { + case PM_BAD_DETECT: if (log_cb) log_cb(RETRO_LOG_ERROR, "Failed to detect ROM/CD image type.\n"); - return false; - case PM_BAD_CD: + return false; + case PM_BAD_CD: if (log_cb) log_cb(RETRO_LOG_ERROR, "Invalid CD image\n"); - return false; - case PM_BAD_CD_NO_BIOS: + return false; + case PM_BAD_CD_NO_BIOS: if (log_cb) log_cb(RETRO_LOG_ERROR, "Missing BIOS\n"); - return false; - case PM_ERROR: + return false; + case PM_ERROR: if (log_cb) log_cb(RETRO_LOG_ERROR, "Load error\n"); - return false; - default: - break; - } + return false; + default: + break; + } - PicoLoopPrepare(); + PicoLoopPrepare(); - PicoWriteSound = snd_write; - memset(sndBuffer, 0, sizeof(sndBuffer)); - PsndOut = sndBuffer; - PsndRerate(0); + PicoWriteSound = snd_write; + memset(sndBuffer, 0, sizeof(sndBuffer)); + PsndOut = sndBuffer; + PsndRerate(0); - return true; + return true; } bool retro_load_game_special(unsigned game_type, const struct retro_game_info *info, size_t num_info) { - return false; + return false; } -void retro_unload_game(void) +void retro_unload_game(void) { } unsigned retro_get_region(void) { - return Pico.m.pal ? RETRO_REGION_PAL : RETRO_REGION_NTSC; + return Pico.m.pal ? RETRO_REGION_PAL : RETRO_REGION_NTSC; } void *retro_get_memory_data(unsigned id) { - if (id != RETRO_MEMORY_SAVE_RAM) - return NULL; + if (id != RETRO_MEMORY_SAVE_RAM) + return NULL; - if (PicoAHW & PAHW_MCD) - return Pico_mcd->bram; - else - return SRam.data; + if (PicoAHW & PAHW_MCD) + return Pico_mcd->bram; + else + return SRam.data; } size_t retro_get_memory_size(unsigned id) { - unsigned int i; - int sum; + unsigned int i; + int sum; - if (id != RETRO_MEMORY_SAVE_RAM) - return 0; + if (id != RETRO_MEMORY_SAVE_RAM) + return 0; - if (PicoAHW & PAHW_MCD) - // bram - return 0x2000; + if (PicoAHW & PAHW_MCD) + // bram + return 0x2000; - if (Pico.m.frame_count == 0) - return SRam.size; + if (Pico.m.frame_count == 0) + return SRam.size; - // if game doesn't write to sram, don't report it to - // libretro so that RA doesn't write out zeroed .srm - for (i = 0, sum = 0; i < SRam.size; i++) - sum |= SRam.data[i]; + // if game doesn't write to sram, don't report it to + // libretro so that RA doesn't write out zeroed .srm + for (i = 0, sum = 0; i < SRam.size; i++) + sum |= SRam.data[i]; - return (sum != 0) ? SRam.size : 0; + return (sum != 0) ? SRam.size : 0; } void retro_reset(void) { - PicoReset(); + PicoReset(); } static const unsigned short retro_pico_map[] = { - 1 << GBTN_B, - 1 << GBTN_A, - 1 << GBTN_MODE, - 1 << GBTN_START, - 1 << GBTN_UP, - 1 << GBTN_DOWN, - 1 << GBTN_LEFT, - 1 << GBTN_RIGHT, - 1 << GBTN_C, - 1 << GBTN_Y, - 1 << GBTN_X, - 1 << GBTN_Z, + 1 << GBTN_B, + 1 << GBTN_A, + 1 << GBTN_MODE, + 1 << GBTN_START, + 1 << GBTN_UP, + 1 << GBTN_DOWN, + 1 << GBTN_LEFT, + 1 << GBTN_RIGHT, + 1 << GBTN_C, + 1 << GBTN_Y, + 1 << GBTN_X, + 1 << GBTN_Z, }; #define RETRO_PICO_MAP_LEN (sizeof(retro_pico_map) / sizeof(retro_pico_map[0])) static void snd_write(int len) { - audio_batch_cb(PsndOut, len / 4); + audio_batch_cb(PsndOut, len / 4); } static enum input_device input_name_to_val(const char *name) { - if (strcmp(name, "3 button pad") == 0) - return PICO_INPUT_PAD_3BTN; - if (strcmp(name, "6 button pad") == 0) - return PICO_INPUT_PAD_6BTN; - if (strcmp(name, "None") == 0) - return PICO_INPUT_NOTHING; + if (strcmp(name, "3 button pad") == 0) + return PICO_INPUT_PAD_3BTN; + if (strcmp(name, "6 button pad") == 0) + return PICO_INPUT_PAD_6BTN; + if (strcmp(name, "None") == 0) + return PICO_INPUT_NOTHING; if (log_cb) log_cb(RETRO_LOG_WARN, "invalid picodrive_input: '%s'\n", name); - return PICO_INPUT_PAD_3BTN; + return PICO_INPUT_PAD_3BTN; } static void update_variables(void) { - struct retro_variable var; - - var.value = NULL; - var.key = "picodrive_input1"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - PicoSetInputDevice(0, input_name_to_val(var.value)); - - var.value = NULL; - var.key = "picodrive_input2"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) - PicoSetInputDevice(1, input_name_to_val(var.value)); - - var.value = NULL; - var.key = "picodrive_sprlim"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "enabled") == 0) - PicoOpt |= POPT_DIS_SPRITE_LIM; - else - PicoOpt &= ~POPT_DIS_SPRITE_LIM; - } - - var.value = NULL; - var.key = "picodrive_ramcart"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "enabled") == 0) - PicoOpt |= POPT_EN_MCD_RAMCART; - else - PicoOpt &= ~POPT_EN_MCD_RAMCART; - } - - var.value = NULL; - var.key = "picodrive_region"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "Auto") == 0) - PicoRegionOverride = 0; - else if (strcmp(var.value, "Japan NTSC") == 0) - PicoRegionOverride = 1; - else if (strcmp(var.value, "Japan PAL") == 0) - PicoRegionOverride = 2; - else if (strcmp(var.value, "US") == 0) - PicoRegionOverride = 4; - else if (strcmp(var.value, "Europe") == 0) - PicoRegionOverride = 8; - } + struct retro_variable var; + + var.value = NULL; + var.key = "picodrive_input1"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + PicoSetInputDevice(0, input_name_to_val(var.value)); + + var.value = NULL; + var.key = "picodrive_input2"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) + PicoSetInputDevice(1, input_name_to_val(var.value)); + + var.value = NULL; + var.key = "picodrive_sprlim"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { + if (strcmp(var.value, "enabled") == 0) + PicoOpt |= POPT_DIS_SPRITE_LIM; + else + PicoOpt &= ~POPT_DIS_SPRITE_LIM; + } + + var.value = NULL; + var.key = "picodrive_ramcart"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { + if (strcmp(var.value, "enabled") == 0) + PicoOpt |= POPT_EN_MCD_RAMCART; + else + PicoOpt &= ~POPT_EN_MCD_RAMCART; + } + + var.value = NULL; + var.key = "picodrive_region"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { + if (strcmp(var.value, "Auto") == 0) + PicoRegionOverride = 0; + else if (strcmp(var.value, "Japan NTSC") == 0) + PicoRegionOverride = 1; + else if (strcmp(var.value, "Japan PAL") == 0) + PicoRegionOverride = 2; + else if (strcmp(var.value, "US") == 0) + PicoRegionOverride = 4; + else if (strcmp(var.value, "Europe") == 0) + PicoRegionOverride = 8; + } #ifdef DRC_SH2 - var.value = NULL; - var.key = "picodrive_drc"; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { - if (strcmp(var.value, "enabled") == 0) - PicoOpt |= POPT_EN_DRC; - else - PicoOpt &= ~POPT_EN_DRC; - } + var.value = NULL; + var.key = "picodrive_drc"; + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value) { + if (strcmp(var.value, "enabled") == 0) + PicoOpt |= POPT_EN_DRC; + else + PicoOpt &= ~POPT_EN_DRC; + } #endif #ifdef _3DS if(!ctr_svchack_successful) @@ -1172,26 +1172,26 @@ static void update_variables(void) #endif } -void retro_run(void) +void retro_run(void) { - bool updated = false; - int pad, i; + bool updated = false; + int pad, i; - if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) - update_variables(); + if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) + update_variables(); input_poll_cb(); - PicoPad[0] = PicoPad[1] = 0; - for (pad = 0; pad < 2; pad++) - for (i = 0; i < RETRO_PICO_MAP_LEN; i++) - if (input_state_cb(pad, RETRO_DEVICE_JOYPAD, 0, i)) - PicoPad[pad] |= retro_pico_map[i]; + PicoPad[0] = PicoPad[1] = 0; + for (pad = 0; pad < 2; pad++) + for (i = 0; i < RETRO_PICO_MAP_LEN; i++) + if (input_state_cb(pad, RETRO_DEVICE_JOYPAD, 0, i)) + PicoPad[pad] |= retro_pico_map[i]; - PicoFrame(); + PicoFrame(); - video_cb((short *)vout_buf + vout_offset, - vout_width, vout_height, vout_width * 2); + video_cb((short *)vout_buf + vout_offset, + vout_width, vout_height, vout_width * 2); } static void check_system_specs(void) @@ -1204,36 +1204,36 @@ static void check_system_specs(void) void retro_init(void) { struct retro_log_callback log; - int level; + int level; - level = 0; - environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level); + level = 0; + environ_cb(RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL, &level); if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log)) log_cb = log.log; else log_cb = NULL; - environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control); + environ_cb(RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE, &disk_control); #ifdef _3DS ctr_svchack_successful = ctr_svchack_init(); #endif - PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 - | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX - | POPT_EN_32X|POPT_EN_PWM - | POPT_ACC_SPRITES|POPT_DIS_32C_BORDER; + PicoOpt = POPT_EN_STEREO|POPT_EN_FM|POPT_EN_PSG|POPT_EN_Z80 + | POPT_EN_MCD_PCM|POPT_EN_MCD_CDDA|POPT_EN_MCD_GFX + | POPT_EN_32X|POPT_EN_PWM + | POPT_ACC_SPRITES|POPT_DIS_32C_BORDER; #ifdef __arm__ #ifdef _3DS if (ctr_svchack_successful) #endif PicoOpt |= POPT_EN_DRC; #endif - PsndRate = 44100; - PicoAutoRgnOrder = 0x184; // US, EU, JP + PsndRate = 44100; + PicoAutoRgnOrder = 0x184; // US, EU, JP - vout_width = 320; + vout_width = 320; vout_height = 240; vout_buf = malloc(VOUT_MAX_WIDTH * VOUT_MAX_HEIGHT * 2); @@ -1241,14 +1241,14 @@ void retro_init(void) PicoDrawSetOutFormat(PDF_RGB555, 0); PicoDrawSetOutBuf(vout_buf, vout_width * 2); - //PicoMessage = plat_status_msg_busy_next; - PicoMCDopenTray = disk_tray_open; - PicoMCDcloseTray = disk_tray_close; + //PicoMessage = plat_status_msg_busy_next; + PicoMCDopenTray = disk_tray_open; + PicoMCDcloseTray = disk_tray_close; update_variables(); } void retro_deinit(void) { - PicoExit(); + PicoExit(); } -- 2.39.5