diff --git a/Makefile b/Makefile index a2b3e5b..290f858 100644 --- a/Makefile +++ b/Makefile @@ -201,9 +201,8 @@ else ifeq ($(platform), ctr) CFLAGS += -Wall -mword-relocations CFLAGS += -fomit-frame-pointer -ffast-math CPU_ARCH := arm - #no dynarec support for now - #HAVE_DYNAREC := 1 - #CFLAGS += -DARM_MEMORY_DYNAREC + # dynarec currently requires ninjahax to work + HAVE_DYNAREC = 1 STATIC_LINKING = 1 # Xbox 360 diff --git a/cpu_threaded.c b/cpu_threaded.c index 41ea483..5f52cb7 100644 --- a/cpu_threaded.c +++ b/cpu_threaded.c @@ -34,6 +34,13 @@ u8* bios_translation_cache; u8 *rom_translation_ptr; u8 *ram_translation_ptr; u8 *bios_translation_ptr; +#elif defined(_3DS) +u8 __attribute__((aligned(0x1000))) rom_translation_cache[ROM_TRANSLATION_CACHE_SIZE]; +u8 __attribute__((aligned(0x1000))) ram_translation_cache[RAM_TRANSLATION_CACHE_SIZE]; +u8 __attribute__((aligned(0x1000))) bios_translation_cache[BIOS_TRANSLATION_CACHE_SIZE]; +u8 *rom_translation_ptr = rom_translation_cache; +u8 *ram_translation_ptr = ram_translation_cache; +u8 *bios_translation_ptr = bios_translation_cache; #elif defined(ARM_MEMORY_DYNAREC) __asm__(".section .jit,\"awx\",%progbits"); @@ -226,7 +233,10 @@ extern u8 bit_count[256]; #if defined(PSP_BUILD) #define translate_invalidate_dcache() sceKernelDcacheWritebackAll() - +#elif defined(_3DS) +int32_t HB_FlushInvalidateCache(); +#define translate_invalidate_dcache() HB_FlushInvalidateCache() +#define invalidate_icache_region(addr, size) (void)0 #elif defined(ARM_ARCH) static int sys_cacheflush(void *addr, unsigned long size) { diff --git a/libretro.c b/libretro.c index c7f2cd7..c2820da 100644 --- a/libretro.c +++ b/libretro.c @@ -8,6 +8,14 @@ #include "libretro.h" #include "memmap.h" +#if defined(_3DS) && defined(HAVE_DYNAREC) +int32_t hbInit(void); +void hbExit(void); +int32_t HB_FlushInvalidateCache(void); +int32_t HB_ReprotectMemory(void* addr, uint32_t pages, uint32_t mode, uint32_t* reprotectedPages); +int hb_service_available; +#endif + #ifndef MAX_PATH #define MAX_PATH (512) #endif @@ -104,6 +112,19 @@ void retro_init(void) { init_gamepak_buffer(); init_sound(1); +#if defined(_3DS) && defined(HAVE_DYNAREC) + hb_service_available = !hbInit(); + if (hb_service_available) + { + HB_ReprotectMemory(rom_translation_cache, + ROM_TRANSLATION_CACHE_SIZE / 0x1000, 0b111, NULL); + HB_ReprotectMemory(ram_translation_cache, + RAM_TRANSLATION_CACHE_SIZE / 0x1000, 0b111, NULL); + HB_ReprotectMemory(bios_translation_cache, + BIOS_TRANSLATION_CACHE_SIZE / 0x1000, 0b111, NULL); + HB_FlushInvalidateCache(); + } +#endif } @@ -117,6 +138,9 @@ void retro_deinit(void) munmap(ram_translation_cache, RAM_TRANSLATION_CACHE_SIZE); munmap(bios_translation_cache, BIOS_TRANSLATION_CACHE_SIZE); #endif +#if defined(_3DS) && defined(HAVE_DYNAREC) + hbExit(); +#endif } static retro_time_t retro_perf_dummy_get_time_usec() { return 0; } @@ -275,6 +299,9 @@ bool retro_load_game(const struct retro_game_info* info) rom_translation_ptr = rom_translation_cache; ram_translation_ptr = ram_translation_cache; bios_translation_ptr = bios_translation_cache; +#elif defined(_3DS) + if(!hb_service_available) + dynarec_enable = 0; #endif } else