From b8a1c09ad1ef0b807c2eb1632d34e6bfae14b633 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 6 Dec 2009 17:03:58 +0000 Subject: [PATCH] port to 64bit. Some gcc 4.4 warning fixes git-svn-id: file:///home/notaz/opt/svn/PicoDrive@835 be3aeb3a-fb24-0410-a615-afba39da0efa --- cpu/cz80/cz80.c | 21 ++++++++++----------- cpu/cz80/cz80.h | 17 +++++++++++------ cpu/cz80/cz80_op.c | 2 +- cpu/cz80/cz80macro.h | 2 +- pico/32x/memory.c | 8 ++++---- pico/carthw/svp/compiler.c | 5 ++++- pico/carthw/svp/ssp16.c | 2 +- pico/memory.c | 6 +++--- pico/memory.h | 31 ++++++++++++++++++++----------- pico/misc.c | 2 +- pico/pico.c | 2 +- pico/pico_int.h | 6 ------ pico/sms.c | 12 ++++++------ pico/sound/sound.c | 2 +- pico/z80if.c | 15 +++++++-------- platform/common/emu.c | 17 ++++++++++------- platform/common/menu.c | 22 ++++++++++++++-------- platform/gp2x/in_gp2x.c | 4 ++-- platform/linux/sndout_oss.c | 6 +++++- 19 files changed, 102 insertions(+), 80 deletions(-) diff --git a/cpu/cz80/cz80.c b/cpu/cz80/cz80.c index 091e2a5..1f3cae2 100644 --- a/cpu/cz80/cz80.c +++ b/cpu/cz80/cz80.c @@ -14,8 +14,7 @@ #include "cz80.h" #if PICODRIVE_HACKS -#undef EMU_M68K -#include +#include #endif #ifndef ALIGN_DATA @@ -107,7 +106,7 @@ void Cz80_Init(cz80_struc *CPU) for (i = 0; i < CZ80_FETCH_BANK; i++) { - CPU->Fetch[i] = (UINT32)cz80_bad_address; + CPU->Fetch[i] = (FPTR)cz80_bad_address; #if CZ80_ENCRYPTED_ROM CPU->OPFetch[i] = 0; #endif @@ -211,7 +210,7 @@ void Cz80_Init(cz80_struc *CPU) void Cz80_Reset(cz80_struc *CPU) { - memset(CPU, 0, (INT32)&CPU->BasePC - (INT32)CPU); + memset(CPU, 0, (FPTR)&CPU->BasePC - (FPTR)CPU); Cz80_Set_Reg(CPU, CZ80_PC, 0); } @@ -219,8 +218,8 @@ void Cz80_Reset(cz80_struc *CPU) #if PICODRIVE_HACKS static inline unsigned char picodrive_read(unsigned short a) { - unsigned long v = z80_read_map[a >> Z80_MEM_SHIFT]; - if (v & 0x80000000) + uptr v = z80_read_map[a >> Z80_MEM_SHIFT]; + if (map_flag_set(v)) return ((z80_read_f *)(v << 1))(a); return *(unsigned char *)((v << 1) + a); } @@ -236,9 +235,9 @@ INT32 Cz80_Exec(cz80_struc *CPU, INT32 cycles) #include "cz80jmp.c" #endif - UINT32 PC; + FPTR PC; #if CZ80_ENCRYPTED_ROM - INT32 OPBase; + FPTR OPBase; #endif UINT32 Opcode; UINT32 adr = 0; @@ -317,9 +316,9 @@ void Cz80_Set_IRQ(cz80_struc *CPU, INT32 line, INT32 state) if (state != CLEAR_LINE) { - UINT32 PC = CPU->PC; + FPTR PC = CPU->PC; #if CZ80_ENCRYPTED_ROM - INT32 OPBase = CPU->OPBase; + FPTR OPBase = CPU->OPBase; #endif CPU->IRQLine = line; @@ -408,7 +407,7 @@ void Cz80_Set_Reg(cz80_struc *CPU, INT32 regnum, UINT32 val) ƒtƒFƒbƒ`ƒAƒhƒŒƒXÝ’è --------------------------------------------------------*/ -void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 fetch_adr) +void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, FPTR fetch_adr) { int i, j; diff --git a/cpu/cz80/cz80.h b/cpu/cz80/cz80.h index 4e84642..9b97d3b 100644 --- a/cpu/cz80/cz80.h +++ b/cpu/cz80/cz80.h @@ -43,6 +43,10 @@ extern "C" { #define INT32 signed int #endif +#ifndef FPTR +#define FPTR unsigned long +#endif + /*************************************/ /* Z80 core Structures & definitions */ /*************************************/ @@ -222,7 +226,7 @@ typedef struct cz80_t union16 IX; union16 IY; union16 SP; - UINT32 PC; + UINT32 unusedPC; /* left for binary compat */ union16 BC2; union16 DE2; @@ -242,11 +246,12 @@ typedef struct cz80_t INT32 ICount; INT32 ExtraCycles; - UINT32 BasePC; - UINT32 Fetch[CZ80_FETCH_BANK]; + FPTR BasePC; + FPTR PC; + FPTR Fetch[CZ80_FETCH_BANK]; #if CZ80_ENCRYPTED_ROM - INT32 OPBase; - INT32 OPFetch[CZ80_FETCH_BANK]; + FPTR OPBase; + FPTR OPFetch[CZ80_FETCH_BANK]; #endif UINT8 *pzR8[8]; @@ -284,7 +289,7 @@ void Cz80_Set_IRQ(cz80_struc *CPU, INT32 line, INT32 state); UINT32 Cz80_Get_Reg(cz80_struc *CPU, INT32 regnum); void Cz80_Set_Reg(cz80_struc *CPU, INT32 regnum, UINT32 value); -void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 fetch_adr); +void Cz80_Set_Fetch(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, FPTR fetch_adr); #if CZ80_ENCRYPTED_ROM void Cz80_Set_Encrypt_Range(cz80_struc *CPU, UINT32 low_adr, UINT32 high_adr, UINT32 decrypted_rom); #endif diff --git a/cpu/cz80/cz80_op.c b/cpu/cz80/cz80_op.c index 8691452..f84f8e7 100644 --- a/cpu/cz80/cz80_op.c +++ b/cpu/cz80/cz80_op.c @@ -917,7 +917,7 @@ OP_DJNZ: OP(0x18): // JR n OP_JR: adr = (INT8)READ_ARG(); - PC += adr; + PC += (INT8)adr; RET(12) OP(0x20): // JR NZ,n diff --git a/cpu/cz80/cz80macro.h b/cpu/cz80/cz80macro.h index 16f3a70..5adca13 100644 --- a/cpu/cz80/cz80macro.h +++ b/cpu/cz80/cz80macro.h @@ -74,7 +74,7 @@ unsigned short a = A; \ unsigned char d = D; \ unsigned long v = z80_write_map[a >> Z80_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ ((z80_write_f *)(v << 1))(a, d); \ else \ *(unsigned char *)((v << 1) + a) = d; \ diff --git a/pico/32x/memory.c b/pico/32x/memory.c index ea4051b..eaf1e3a 100644 --- a/pico/32x/memory.c +++ b/pico/32x/memory.c @@ -1178,7 +1178,7 @@ u32 REGPARM(2) p32x_sh2_read8(u32 a, SH2 *sh2) sh2_map += SH2MAP_ADDR2OFFS(a); p = sh2_map->addr; - if (p & (1 << 31)) + if (map_flag_set(p)) return ((sh2_read_handler *)(p << 1))(a, sh2->is_slave); else return *(u8 *)((p << 1) + ((a & sh2_map->mask) ^ 1)); @@ -1191,7 +1191,7 @@ u32 REGPARM(2) p32x_sh2_read16(u32 a, SH2 *sh2) sh2_map += SH2MAP_ADDR2OFFS(a); p = sh2_map->addr; - if (p & (1 << 31)) + if (map_flag_set(p)) return ((sh2_read_handler *)(p << 1))(a, sh2->is_slave); else return *(u16 *)((p << 1) + ((a & sh2_map->mask) & ~1)); @@ -1207,7 +1207,7 @@ u32 REGPARM(2) p32x_sh2_read32(u32 a, SH2 *sh2) offs = SH2MAP_ADDR2OFFS(a); sh2_map += offs; p = sh2_map->addr; - if (!(p & (1 << 31))) { + if (!map_flag_set(p)) { // XXX: maybe 32bit access instead with ror? u16 *pd = (u16 *)((p << 1) + ((a & sh2_map->mask) & ~1)); return (pd[0] << 16) | pd[1]; @@ -1376,7 +1376,7 @@ static void get_bios(void) } #define MAP_MEMORY(m) ((uptr)(m) >> 1) -#define MAP_HANDLER(h) (((uptr)(h) >> 1) | (1 << 31)) +#define MAP_HANDLER(h) ( ((uptr)(h) >> 1) | ((uptr)1 << (sizeof(uptr) * 8 - 1)) ) static sh2_memmap sh2_read8_map[0x20], sh2_read16_map[0x20]; // for writes we are using handlers only diff --git a/pico/carthw/svp/compiler.c b/pico/carthw/svp/compiler.c index 60834a2..3632b91 100644 --- a/pico/carthw/svp/compiler.c +++ b/pico/carthw/svp/compiler.c @@ -1197,7 +1197,10 @@ static int tr_detect_set_pm(unsigned int op, int *pc, int imm) int reg = is_write ? ((tmpv>>4)&0x7) : (tmpv&0x7); if (reg > 4) tr_unhandled(); if ((tmpv & 0x0f) != 0 && (tmpv & 0xf0) != 0) tr_unhandled(); - known_regs.pmac_read[is_write ? reg + 5 : reg] = pmcv; + if (is_write) + known_regs.pmac_write[reg] = pmcv; + else + known_regs.pmac_read[reg] = pmcv; known_regb |= is_write ? (1 << (reg+25)) : (1 << (reg+20)); dirty_regb |= is_write ? (1 << (reg+25)) : (1 << (reg+20)); known_regs.emu_status &= ~SSP_PMC_SET; diff --git a/pico/carthw/svp/ssp16.c b/pico/carthw/svp/ssp16.c index 4fe7c03..07831b0 100644 --- a/pico/carthw/svp/ssp16.c +++ b/pico/carthw/svp/ssp16.c @@ -213,7 +213,7 @@ #define IJind (((op>>6)&4)|(op&3)) #define GET_PC() (PC - (unsigned short *)svp->iram_rom) -#define GET_PPC_OFFS() ((unsigned int)PC - (unsigned int)svp->iram_rom - 2) +#define GET_PPC_OFFS() ((unsigned char *)PC - svp->iram_rom - 2) #define SET_PC(d) PC = (unsigned short *)svp->iram_rom + d #define REG_READ(r) (((r) <= 4) ? ssp->gr[r].h : read_handlers[r]()) diff --git a/pico/memory.c b/pico/memory.c index 9967f5c..f6c0eeb 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -44,7 +44,7 @@ static void xmap_set(uptr *map, int shift, int start_addr, int end_addr, for (i = start_addr >> shift; i <= end_addr >> shift; i++) { map[i] = addr >> 1; if (is_func) - map[i] |= 1 << (sizeof(addr) * 8 - 1); + map[i] |= (uptr)1 << (sizeof(addr) * 8 - 1); } } @@ -1146,8 +1146,8 @@ static void z80_mem_setup(void) drZ80.z80_out = z80_md_out; #endif #ifdef _USE_CZ80 - Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (UINT32)Pico.zram); // main RAM - Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (UINT32)Pico.zram); // mirror + Cz80_Set_Fetch(&CZ80, 0x0000, 0x1fff, (FPTR)Pico.zram); // main RAM + Cz80_Set_Fetch(&CZ80, 0x2000, 0x3fff, (FPTR)Pico.zram); // mirror Cz80_Set_INPort(&CZ80, z80_md_in); Cz80_Set_OUTPort(&CZ80, z80_md_out); #endif diff --git a/pico/memory.h b/pico/memory.h index d43fe23..9a5da86 100644 --- a/pico/memory.h +++ b/pico/memory.h @@ -20,6 +20,19 @@ extern uptr s68k_read16_map [0x1000000 >> M68K_MEM_SHIFT]; extern uptr s68k_write8_map [0x1000000 >> M68K_MEM_SHIFT]; extern uptr s68k_write16_map[0x1000000 >> M68K_MEM_SHIFT]; +// top-level handlers that cores can use +// (or alternatively build them into themselves) +// XXX: unhandled: *16 and *32 might cross the bank boundaries +typedef u32 (cpu68k_read_f)(u32 a); +typedef void (cpu68k_write_f)(u32 a, u32 d); + +// z80 +#define Z80_MEM_SHIFT 13 +extern uptr z80_read_map [0x10000 >> Z80_MEM_SHIFT]; +extern uptr z80_write_map[0x10000 >> Z80_MEM_SHIFT]; +typedef unsigned char (z80_read_f)(unsigned short a); +typedef void (z80_write_f)(unsigned int a, unsigned char data); + void z80_map_set(uptr *map, int start_addr, int end_addr, const void *func_or_mh, int is_func); void cpu68k_map_set(uptr *map, int start_addr, int end_addr, @@ -27,11 +40,7 @@ void cpu68k_map_set(uptr *map, int start_addr, int end_addr, void cpu68k_map_all_ram(int start_addr, int end_addr, void *ptr, int is_sub); void m68k_map_unmap(int start_addr, int end_addr); -// top-level handlers that cores can use -// (or alternatively build them into themselves) -// XXX: unhandled: *16 and *32 might cross the bank boundaries -typedef u32 (cpu68k_read_f)(u32 a); -typedef void (cpu68k_write_f)(u32 a, u32 d); +#define map_flag_set(x) ((x) & ((uptr)1 << (sizeof(uptr) * 8 - 1))) #define MAKE_68K_READ8(name, map) \ u32 name(u32 a) \ @@ -39,7 +48,7 @@ u32 name(u32 a) \ uptr v; \ a &= 0x00ffffff; \ v = map[a >> M68K_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ return ((cpu68k_read_f *)(v << 1))(a); \ else \ return *(u8 *)((v << 1) + (a ^ 1)); \ @@ -51,7 +60,7 @@ u32 name(u32 a) \ uptr v; \ a &= 0x00fffffe; \ v = map[a >> M68K_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ return ((cpu68k_read_f *)(v << 1))(a); \ else \ return *(u16 *)((v << 1) + a); \ @@ -65,7 +74,7 @@ u32 name(u32 a) \ a &= 0x00fffffe; \ v = map[a >> M68K_MEM_SHIFT]; \ vs = v << 1; \ - if (v & 0x80000000) { \ + if (map_flag_set(v)) { \ d = ((cpu68k_read_f *)vs)(a) << 16; \ d |= ((cpu68k_read_f *)vs)(a + 2); \ } \ @@ -82,7 +91,7 @@ void name(u32 a, u8 d) \ uptr v; \ a &= 0x00ffffff; \ v = map[a >> M68K_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ ((cpu68k_write_f *)(v << 1))(a, d); \ else \ *(u8 *)((v << 1) + (a ^ 1)) = d; \ @@ -94,7 +103,7 @@ void name(u32 a, u16 d) \ uptr v; \ a &= 0x00fffffe; \ v = map[a >> M68K_MEM_SHIFT]; \ - if (v & 0x80000000) \ + if (map_flag_set(v)) \ ((cpu68k_write_f *)(v << 1))(a, d); \ else \ *(u16 *)((v << 1) + a) = d; \ @@ -107,7 +116,7 @@ void name(u32 a, u32 d) \ a &= 0x00fffffe; \ v = map[a >> M68K_MEM_SHIFT]; \ vs = v << 1; \ - if (v & 0x80000000) { \ + if (map_flag_set(v)) { \ ((cpu68k_write_f *)vs)(a, d >> 16); \ ((cpu68k_write_f *)vs)(a + 2, d); \ } \ diff --git a/pico/misc.c b/pico/misc.c index 4e344fc..539416d 100644 --- a/pico/misc.c +++ b/pico/misc.c @@ -101,7 +101,7 @@ typedef struct PICO_INTERNAL_ASM void memcpy16(unsigned short *dest, unsigned short *src, int count) { - if ((((int)dest | (int)src) & 3) == 0) + if ((((long)dest | (long)src) & 3) == 0) { if (count >= 32) { memcpy32((int *)dest, (int *)src, count/2); diff --git a/pico/pico.c b/pico/pico.c index 96025ff..d312386 100644 --- a/pico/pico.c +++ b/pico/pico.c @@ -61,7 +61,7 @@ void PicoPower(void) Pico.m.frame_count = 0; // clear all memory of the emulated machine - memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram); + memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram); memset(&Pico.video,0,sizeof(Pico.video)); memset(&Pico.m,0,sizeof(Pico.m)); diff --git a/pico/pico_int.h b/pico/pico_int.h index 838af54..68a77c0 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -229,12 +229,6 @@ extern int z80_scanline_cycles; /* cycles done until z80_scanline */ #define cycles_68k_to_z80(x) ((x)*957 >> 11) -#define Z80_MEM_SHIFT 13 -extern unsigned long z80_read_map [0x10000 >> Z80_MEM_SHIFT]; -extern unsigned long z80_write_map[0x10000 >> Z80_MEM_SHIFT]; -typedef unsigned char (z80_read_f)(unsigned short a); -typedef void (z80_write_f)(unsigned int a, unsigned char data); - // ----------------------- SH2 CPU ----------------------- #include "cpu/sh2/sh2.h" diff --git a/pico/sms.c b/pico/sms.c index 5e32832..e94e731 100644 --- a/pico/sms.c +++ b/pico/sms.c @@ -156,14 +156,14 @@ static void write_bank(unsigned short a, unsigned char d) d &= bank_mask; z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0); #ifdef _USE_CZ80 - Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (UINT32)Pico.rom + (d << 14)); + Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (FPTR)Pico.rom + (d << 14)); #endif break; case 0x0f: d &= bank_mask; z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0); #ifdef _USE_CZ80 - Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (UINT32)Pico.rom + (d << 14)); + Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (FPTR)Pico.rom + (d << 14)); #endif break; } @@ -188,7 +188,7 @@ void PicoPowerMS(void) { int s, tmp; - memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram); + memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram); memset(&Pico.video,0,sizeof(Pico.video)); memset(&Pico.m,0,sizeof(Pico.m)); Pico.m.pal = 0; @@ -221,9 +221,9 @@ void PicoMemSetupMS(void) drZ80.z80_out = z80_sms_out; #endif #ifdef _USE_CZ80 - Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (UINT32)Pico.rom); - Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (UINT32)Pico.zram); - Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (UINT32)Pico.zram); + Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom); + Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)Pico.zram); + Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)Pico.zram); Cz80_Set_INPort(&CZ80, z80_sms_in); Cz80_Set_OUTPort(&CZ80, z80_sms_out); #endif diff --git a/pico/sound/sound.c b/pico/sound/sound.c index 5a9b8b3..dfa1d65 100644 --- a/pico/sound/sound.c +++ b/pico/sound/sound.c @@ -291,7 +291,7 @@ PICO_INTERNAL void PsndClear(void) memset32((int *) PsndOut, 0, len); // assume PsndOut to be aligned else { short *out = PsndOut; - if ((int)out & 2) { *out++ = 0; len--; } + if ((long)out & 2) { *out++ = 0; len--; } memset32((int *) out, 0, len/2); if (len & 1) out[len-1] = 0; } diff --git a/pico/z80if.c b/pico/z80if.c index f48da99..454938b 100644 --- a/pico/z80if.c +++ b/pico/z80if.c @@ -1,10 +1,9 @@ +#include #include "pico_int.h" -#include "sound/sn76496.h" +#include "memory.h" -#define Z80_MEM_SHIFT 13 - -unsigned long z80_read_map [0x10000 >> Z80_MEM_SHIFT]; -unsigned long z80_write_map[0x10000 >> Z80_MEM_SHIFT]; +uptr z80_read_map [0x10000 >> Z80_MEM_SHIFT]; +uptr z80_write_map[0x10000 >> Z80_MEM_SHIFT]; #ifdef _USE_MZ80 @@ -124,7 +123,7 @@ PICO_INTERNAL void z80_pack(unsigned char *data) #elif defined(_USE_CZ80) *(int *)data = 0x00007a43; // "Cz" *(int *)(data+4) = Cz80_Get_Reg(&CZ80, CZ80_PC); - memcpy(data+8, &CZ80, (INT32)&CZ80.BasePC - (INT32)&CZ80); + memcpy(data+8, &CZ80, offsetof(cz80_struc, BasePC)); #endif } @@ -171,7 +170,7 @@ PICO_INTERNAL void z80_unpack(unsigned char *data) } #elif defined(_USE_CZ80) if (*(int *)data == 0x00007a43) { // "Cz" save? - memcpy(&CZ80, data+8, (INT32)&CZ80.BasePC - (INT32)&CZ80); + memcpy(&CZ80, data+8, offsetof(cz80_struc, BasePC)); Cz80_Set_Reg(&CZ80, CZ80_PC, *(int *)(data+4)); } else { z80_reset(); @@ -192,6 +191,6 @@ PICO_INTERNAL void z80_debug(char *dstr) #if defined(_USE_DRZ80) sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", drZ80.Z80PC-drZ80.Z80PC_BASE, drZ80.Z80SP-drZ80.Z80SP_BASE); #elif defined(_USE_CZ80) - sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", CZ80.PC - CZ80.BasePC, CZ80.SP.W); + sprintf(dstr, "Z80 state: PC: %04x SP: %04x\n", (unsigned int)(CZ80.PC - CZ80.BasePC), CZ80.SP.W); #endif } diff --git a/platform/common/emu.c b/platform/common/emu.c index 370242d..e916b3f 100644 --- a/platform/common/emu.c +++ b/platform/common/emu.c @@ -464,25 +464,25 @@ int emu_reload_rom(char *rom_fname) // check for both gmv and rom int dummy; FILE *movie_file = fopen(rom_fname, "rb"); - if(!movie_file) { + if (!movie_file) { me_update_msg("Failed to open movie."); return 0; } fseek(movie_file, 0, SEEK_END); movie_size = ftell(movie_file); fseek(movie_file, 0, SEEK_SET); - if(movie_size < 64+3) { + if (movie_size < 64+3) { me_update_msg("Invalid GMV file."); fclose(movie_file); return 0; } movie_data = malloc(movie_size); - if(movie_data == NULL) { + if (movie_data == NULL) { me_update_msg("low memory."); fclose(movie_file); return 0; } - fread(movie_data, 1, movie_size, movie_file); + dummy = fread(movie_data, 1, movie_size, movie_file); fclose(movie_file); if (strncmp((char *)movie_data, "Gens Movie TEST", 15) != 0) { me_update_msg("Invalid GMV file."); @@ -1008,13 +1008,16 @@ int emu_save_load_game(int load, int sram) sram_size = SRam.size; sram_data = SRam.data; } - if (!sram_data) return 0; // SRam forcefully disabled for this game + if (sram_data == NULL) + return 0; // SRam forcefully disabled for this game if (load) { sramFile = fopen(saveFname, "rb"); - if(!sramFile) return -1; - fread(sram_data, 1, sram_size, sramFile); + if (!sramFile) + return -1; + ret = fread(sram_data, 1, sram_size, sramFile); + ret = ret > 0 ? 0 : -1; fclose(sramFile); if ((PicoAHW & PAHW_MCD) && (PicoOpt&POPT_EN_MCD_RAMCART)) memcpy32((int *)Pico_mcd->bram, (int *)sram_data, 0x2000/4); diff --git a/platform/common/menu.c b/platform/common/menu.c index 887e0cd..8e3b9dd 100644 --- a/platform/common/menu.c +++ b/platform/common/menu.c @@ -276,7 +276,8 @@ void menu_init(void) lprintf("found skin.txt\n"); while (!feof(f)) { - fgets(buff, sizeof(buff), f); + if (fgets(buff, sizeof(buff), f) == NULL) + break; if (buff[0] == '#' || buff[0] == '/') continue; // comment if (buff[0] == '\r' || buff[0] == '\n') continue; // empty line if (strncmp(buff, "text_color=", 11) == 0) @@ -744,10 +745,15 @@ static void draw_dirlist(char *curdir, struct dirent **namelist, int n, int sel) static int scandir_cmp(const void *p1, const void *p2) { - struct dirent **d1 = (struct dirent **)p1, **d2 = (struct dirent **)p2; - if ((*d1)->d_type == (*d2)->d_type) return alphasort(d1, d2); - if ((*d1)->d_type == DT_DIR) return -1; // put before - if ((*d2)->d_type == DT_DIR) return 1; + const struct dirent **d1 = (const struct dirent **)p1; + const struct dirent **d2 = (const struct dirent **)p2; + if ((*d1)->d_type == (*d2)->d_type) + return alphasort(d1, d2); + if ((*d1)->d_type == DT_DIR) + return -1; // put before + if ((*d2)->d_type == DT_DIR) + return 1; + return alphasort(d1, d2); } @@ -789,13 +795,13 @@ rescan: fname = p+1; } - n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp); + n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp); if (n < 0) { lprintf("menu_loop_romsel failed, dir: %s\n", curr_path); // try root - getcwd(curr_path, len); - n = scandir(curr_path, &namelist, scandir_filter, scandir_cmp); + plat_get_root_dir(curr_path, len); + n = scandir(curr_path, &namelist, scandir_filter, (void *)scandir_cmp); if (n < 0) { // oops, we failed lprintf("menu_loop_romsel failed, dir: %s\n", curr_path); diff --git a/platform/gp2x/in_gp2x.c b/platform/gp2x/in_gp2x.c index 818aead..37abeaf 100644 --- a/platform/gp2x/in_gp2x.c +++ b/platform/gp2x/in_gp2x.c @@ -55,8 +55,8 @@ static int in_gp2x_get_mmsp2_bits(void) static int in_gp2x_get_wiz_bits(void) { - int value = 0; - read(gpiodev, &value, 4); + int r, value = 0; + r = read(gpiodev, &value, 4); if (value & 0x02) value |= 0x05; if (value & 0x08) diff --git a/platform/linux/sndout_oss.c b/platform/linux/sndout_oss.c index ccadbba..f74e706 100644 --- a/platform/linux/sndout_oss.c +++ b/platform/linux/sndout_oss.c @@ -44,7 +44,11 @@ int sndout_oss_start(int rate, int frame_samples, int stereo) if (sounddev == -1) { perror("open(\"/dev/dsp\")"); - return -1; + sounddev = open("/dev/dsp1", O_WRONLY|O_ASYNC); + if (sounddev == -1) { + perror("open(\"/dev/dsp1\")"); + return -1; + } } // calculate buffer size. We one to fit 1 frame worth of sound data. -- 2.39.2