From 48c9e01be8ad93a7902e22f9ad07aba4527e6572 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 6 Jan 2018 21:29:59 +0200 Subject: [PATCH] improve 64bit portability for win64 mostly --- cpu/cz80/cz80.h | 8 +++++++- cpu/cz80/cz80macro.h | 2 +- cpu/fame/fame.h | 10 ++++++++-- cpu/fame/famec.c | 2 +- cpu/musashi/m68kcpu.h | 1 + pico/32x/draw.c | 2 +- pico/32x/memory.c | 4 ++-- pico/cd/memory.c | 12 ++++++------ pico/memory.c | 4 ++-- pico/memory.h | 4 +++- pico/pico_int.h | 1 - pico/pico_port.h | 6 ++++++ pico/sound/sound.c | 2 +- platform/libretro/libretro.c | 10 +++------- 14 files changed, 42 insertions(+), 26 deletions(-) diff --git a/cpu/cz80/cz80.h b/cpu/cz80/cz80.h index 9b97d3b4..f3f79b39 100644 --- a/cpu/cz80/cz80.h +++ b/cpu/cz80/cz80.h @@ -11,6 +11,12 @@ #ifndef CZ80_H #define CZ80_H +// uintptr_t +#include +#ifndef _MSC_VER +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -44,7 +50,7 @@ extern "C" { #endif #ifndef FPTR -#define FPTR unsigned long +#define FPTR uintptr_t #endif /*************************************/ diff --git a/cpu/cz80/cz80macro.h b/cpu/cz80/cz80macro.h index 5adca13a..2e21d409 100644 --- a/cpu/cz80/cz80macro.h +++ b/cpu/cz80/cz80macro.h @@ -73,7 +73,7 @@ #define WRITE_MEM8(A, D) { \ unsigned short a = A; \ unsigned char d = D; \ - unsigned long v = z80_write_map[a >> Z80_MEM_SHIFT]; \ + uptr v = z80_write_map[a >> Z80_MEM_SHIFT]; \ if (map_flag_set(v)) \ ((z80_write_f *)(v << 1))(a, d); \ else \ diff --git a/cpu/fame/fame.h b/cpu/fame/fame.h index 0baabf26..aba9316e 100644 --- a/cpu/fame/fame.h +++ b/cpu/fame/fame.h @@ -9,6 +9,12 @@ #ifndef __FAME_H__ #define __FAME_H__ +// uintptr_t +#include +#ifndef _MSC_VER +#include +#endif + #ifdef __cplusplus extern "C" { #endif @@ -127,7 +133,7 @@ typedef struct signed int cycles_needed; unsigned short *PC; - unsigned long BasePC; + uintptr_t BasePC; unsigned int flag_C; unsigned int flag_V; unsigned int flag_NotZ; @@ -140,7 +146,7 @@ typedef struct unsigned char not_polling; unsigned char pad[3]; - unsigned long Fetch[M68K_FETCHBANK1]; + uintptr_t Fetch[M68K_FETCHBANK1]; } M68K_CONTEXT; typedef enum diff --git a/cpu/fame/famec.c b/cpu/fame/famec.c index 41620944..60a9e550 100644 --- a/cpu/fame/famec.c +++ b/cpu/fame/famec.c @@ -94,7 +94,7 @@ #define s16 signed short #define u32 unsigned int #define s32 signed int -#define uptr unsigned long +#define uptr uintptr_t /* typedef unsigned char u8; diff --git a/cpu/musashi/m68kcpu.h b/cpu/musashi/m68kcpu.h index 63055cbe..a1dff7de 100644 --- a/cpu/musashi/m68kcpu.h +++ b/cpu/musashi/m68kcpu.h @@ -142,6 +142,7 @@ /* Exception Vectors handled by emulation */ #define EXCEPTION_BUS_ERROR 2 /* This one is not emulated! */ #define EXCEPTION_ADDRESS_ERROR 3 /* This one is partially emulated (doesn't stack a proper frame yet) */ +#undef EXCEPTION_ILLEGAL_INSTRUCTION #define EXCEPTION_ILLEGAL_INSTRUCTION 4 #define EXCEPTION_ZERO_DIVIDE 5 #define EXCEPTION_CHK 6 diff --git a/pico/32x/draw.c b/pico/32x/draw.c index ee541bd9..2287e246 100644 --- a/pico/32x/draw.c +++ b/pico/32x/draw.c @@ -58,7 +58,7 @@ static void convert_pal555(int invert_prio) unsigned short t; \ int i; \ for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \ - t = pal[*(unsigned char *)((long)p32x ^ 1)]; \ + t = pal[*(unsigned char *)((uintptr_t)p32x ^ 1)]; \ if ((t & 0x20) || (*pmd & 0x3f) == mdbg) \ *pd = t; \ else \ diff --git a/pico/32x/memory.c b/pico/32x/memory.c index 706d820e..d9f18db5 100644 --- a/pico/32x/memory.c +++ b/pico/32x/memory.c @@ -1786,9 +1786,9 @@ void PicoMemSetup32x(void) cpu68k_map_set(m68k_write16_map, 0x880000, 0x880000 + rs - 1, PicoWrite16_cart, 1); #ifdef EMU_F68K // setup FAME fetchmap - PicoCpuFM68k.Fetch[0] = (unsigned long)Pico32xMem->m68k_rom; + PicoCpuFM68k.Fetch[0] = (uptr)Pico32xMem->m68k_rom; for (rs = 0x88; rs < 0x90; rs++) - PicoCpuFM68k.Fetch[rs] = (unsigned long)Pico.rom - 0x880000; + PicoCpuFM68k.Fetch[rs] = (uptr)Pico.rom - 0x880000; #endif // 32X ROM (banked) diff --git a/pico/cd/memory.c b/pico/cd/memory.c index 22694389..1c5dcf94 100644 --- a/pico/cd/memory.c +++ b/pico/cd/memory.c @@ -1168,29 +1168,29 @@ PICO_INTERNAL void PicoMemSetupCD(void) #ifdef __clang__ volatile // prevent strange relocs from clang #endif - unsigned long ptr_ram = (unsigned long)PicoMem.ram; + unsigned long ptr_ram = (uptr)PicoMem.ram; int i; // M68k // by default, point everything to fitst 64k of ROM (BIOS) for (i = 0; i < M68K_FETCHBANK1; i++) - PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom - (i<<(24-FAMEC_FETCHBITS)); + PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom - (i<<(24-FAMEC_FETCHBITS)); // now real ROM (BIOS) for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++) - PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom; + PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom; // .. and RAM for (i = M68K_FETCHBANK1*14/16; i < M68K_FETCHBANK1; i++) PicoCpuFM68k.Fetch[i] = ptr_ram - (i<<(24-FAMEC_FETCHBITS)); // S68k // PRG RAM is default for (i = 0; i < M68K_FETCHBANK1; i++) - PicoCpuFS68k.Fetch[i] = (unsigned long)Pico_mcd->prg_ram - (i<<(24-FAMEC_FETCHBITS)); + PicoCpuFS68k.Fetch[i] = (uptr)Pico_mcd->prg_ram - (i<<(24-FAMEC_FETCHBITS)); // real PRG RAM for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < 0x80000; i++) - PicoCpuFS68k.Fetch[i] = (unsigned long)Pico_mcd->prg_ram; + PicoCpuFS68k.Fetch[i] = (uptr)Pico_mcd->prg_ram; // WORD RAM 2M area for (i = M68K_FETCHBANK1*0x08/0x100; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < 0xc0000; i++) - PicoCpuFS68k.Fetch[i] = (unsigned long)Pico_mcd->word_ram2M - 0x80000; + PicoCpuFS68k.Fetch[i] = (uptr)Pico_mcd->word_ram2M - 0x80000; // remap_word_ram() will setup word ram for both } #endif diff --git a/pico/memory.c b/pico/memory.c index c633c89b..a31a08e9 100644 --- a/pico/memory.c +++ b/pico/memory.c @@ -832,10 +832,10 @@ PICO_INTERNAL void PicoMemSetup(void) int i; // by default, point everything to first 64k of ROM for (i = 0; i < M68K_FETCHBANK1 * 0xe0 / 0x100; i++) - PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom - (i<<(24-FAMEC_FETCHBITS)); + PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom - (i<<(24-FAMEC_FETCHBITS)); // now real ROM for (i = 0; i < M68K_FETCHBANK1 && (i<<(24-FAMEC_FETCHBITS)) < Pico.romsize; i++) - PicoCpuFM68k.Fetch[i] = (unsigned long)Pico.rom; + PicoCpuFM68k.Fetch[i] = (uptr)Pico.rom; // RAM already set } #endif diff --git a/pico/memory.h b/pico/memory.h index ae7ae50d..eb440dd4 100644 --- a/pico/memory.h +++ b/pico/memory.h @@ -1,9 +1,11 @@ // memory map related stuff +#include "pico_port.h" + typedef unsigned char u8; typedef unsigned short u16; typedef unsigned int u32; -typedef unsigned long uptr; // unsigned pointer-sized int +typedef uintptr_t uptr; // unsigned pointer-sized int #define M68K_MEM_SHIFT 16 // minimum size we can map diff --git a/pico/pico_int.h b/pico/pico_int.h index 0b50e4b9..da0fbb90 100644 --- a/pico/pico_int.h +++ b/pico/pico_int.h @@ -11,7 +11,6 @@ #define PICO_INTERNAL_INCLUDED #include -#include #include #include "pico_port.h" #include "pico.h" diff --git a/pico/pico_port.h b/pico/pico_port.h index 70802202..e26e6ca2 100644 --- a/pico/pico_port.h +++ b/pico/pico_port.h @@ -1,6 +1,12 @@ #ifndef PICO_PORT_INCLUDED #define PICO_PORT_INCLUDED +// provide size_t, uintptr_t +#include +#if !(defined(_MSC_VER) && _MSC_VER < 1800) +#include +#endif + #if defined(__GNUC__) && defined(__i386__) #define REGPARM(x) __attribute__((regparm(x))) #else diff --git a/pico/sound/sound.c b/pico/sound/sound.c index fc71b741..95aac128 100644 --- a/pico/sound/sound.c +++ b/pico/sound/sound.c @@ -265,7 +265,7 @@ PICO_INTERNAL void PsndClear(void) memset32((int *) PicoIn.sndOut, 0, len); // assume PicoIn.sndOut to be aligned else { short *out = PicoIn.sndOut; - if ((long)out & 2) { *out++ = 0; len--; } + if ((uintptr_t)out & 2) { *out++ = 0; len--; } memset32((int *) out, 0, len/2); if (len & 1) out[len-1] = 0; } diff --git a/platform/libretro/libretro.c b/platform/libretro/libretro.c index 42d30c2d..9111048f 100644 --- a/platform/libretro/libretro.c +++ b/platform/libretro/libretro.c @@ -79,11 +79,7 @@ static void *vout_buf; static int vout_width, vout_height, vout_offset; static float user_vout_width = 0.0; -#ifdef _MSC_VER -static short sndBuffer[2*44100/50]; -#else -static short __attribute__((aligned(4))) sndBuffer[2*44100/50]; -#endif +static short ALIGNED(4) sndBuffer[2*44100/50]; static void snd_write(int len); @@ -375,7 +371,7 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed) int flags = MAP_PRIVATE | MAP_ANONYMOUS; void *req, *ret; - req = (void *)addr; + req = (void *)(uintptr_t)addr; ret = mmap(req, size, PROT_READ | PROT_WRITE, flags, -1, 0); if (ret == MAP_FAILED) { if (log_cb) @@ -383,7 +379,7 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed) return NULL; } - if (addr != 0 && ret != (void *)addr) { + if (addr != 0 && ret != (void *)(uintptr_t)addr) { if (log_cb) log_cb(RETRO_LOG_WARN, "warning: wanted to map @%08lx, got %p\n", addr, ret); -- 2.39.5