diff --git a/Makefile b/Makefile index ca5f90b..bdf1797 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ ifeq ($(platform), unix) ifneq ($(findstring Haiku,$(shell uname -a)),) LIBM := endif - CFLAGS += $(FORCE_32BIT) + CFLAGS += $(FORCE_32BIT) -DHAVE_MMAP # OS X else ifeq ($(platform), osx) TARGET := $(TARGET_NAME)_libretro.dylib @@ -66,6 +66,7 @@ else ifeq ($(platform), osx) fpic += -mmacosx-version-min=10.5 endif SHARED := -dynamiclib + CFLAGS += -DHAVE_MMAP # iOS else ifeq ($(platform), ios) @@ -79,7 +80,7 @@ else ifeq ($(platform), ios) endif CC = clang -arch armv7 -isysroot $(IOSSDK) - CFLAGS += -DIOS + CFLAGS += -DIOS -DHAVE_MMAP OSXVER = `sw_vers -productVersion | cut -d. -f 2` OSX_LT_MAVERICKS = `(( $(OSXVER) <= 9)) && echo "YES"` ifeq ($(OSX_LT_MAVERICKS),"YES") @@ -92,6 +93,7 @@ else ifeq ($(platform), qnx) TARGET := $(TARGET_NAME)_libretro_qnx.so fpic := -fPIC SHARED := -shared -Wl,--version-script=link.T + CFLAGS += -DHAVE_MMAP CC = qcc -Vgcc_ntoarmv7le AR = qcc -Vgcc_ntoarmv7le @@ -180,6 +182,7 @@ else ifneq (,$(findstring armv,$(platform))) ASFLAGS += -mfloat-abi=hard endif CFLAGS += -DARM + CFLAGS += -DHAVE_MMAP # emscripten else ifeq ($(platform), emscripten) @@ -191,7 +194,7 @@ else CC = gcc SHARED := -shared -static-libgcc -static-libstdc++ -s -Wl,--version-script=link.T CFLAGS += -D__WIN32__ -D__WIN32_LIBRETRO__ - +# CFLAGS += -DHAVE_MMAP endif # Forcibly disable PIC diff --git a/common.h b/common.h index 9656554..9b5f146 100644 --- a/common.h +++ b/common.h @@ -91,14 +91,12 @@ #include #include #else -#ifdef __LIBRETRO__ #define GBA_SCREEN_WIDTH (240) #define GBA_SCREEN_HEIGHT (160) #define GBA_SCREEN_PITCH (240) void switch_to_main_thread(void); -#endif #ifdef ARM_ARCH #define function_cc diff --git a/cpu.h b/cpu.h index 405fa3f..1dc5fb7 100644 --- a/cpu.h +++ b/cpu.h @@ -152,7 +152,7 @@ s32 translate_block_thumb(u32 pc, translation_region_type translation_region, #endif -#ifdef __LIBRETRO__ +#ifdef HAVE_MMAP extern u8* rom_translation_cache; extern u8* ram_translation_cache; extern u8* bios_translation_cache; diff --git a/cpu_threaded.c b/cpu_threaded.c index 30abec3..c0e27aa 100644 --- a/cpu_threaded.c +++ b/cpu_threaded.c @@ -23,7 +23,7 @@ #include "common.h" -#ifdef __LIBRETRO__ +#ifdef HAVE_MMAP u8* rom_translation_cache; u8* ram_translation_cache; u8* bios_translation_cache; diff --git a/disasm.c b/disasm.c deleted file mode 100644 index 97325b1..0000000 --- a/disasm.c +++ /dev/null @@ -1,184 +0,0 @@ -/* gameplaySP - * - * Copyright (C) 2006 Exophase - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - - -#define arm_decode_data_proc_reg(opcode) \ - u32 rn = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 rm = opcode & 0x0F \ - -#define arm_decode_data_proc_imm(opcode) \ - u32 rn = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 imm; \ - ror(imm, opcode & 0xFF, ((opcode >> 8) & 0x0F) * 2) \ - -#define arm_decode_psr_reg(opcode) \ - u32 psr_field = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 rm = opcode & 0x0F \ - -#define arm_decode_psr_imm(opcode) \ - u32 psr_field = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 imm; \ - ror(imm, opcode & 0xFF, ((opcode >> 8) & 0x0F) * 2) \ - -#define arm_decode_branchx(opcode) \ - u32 rn = opcode & 0x0F \ - -#define arm_decode_multiply() \ - u32 rd = (opcode >> 16) & 0x0F; \ - u32 rn = (opcode >> 12) & 0x0F; \ - u32 rs = (opcode >> 8) & 0x0F; \ - u32 rm = opcode & 0x0F \ - -#define arm_decode_multiply_long() \ - u32 rdhi = (opcode >> 16) & 0x0F; \ - u32 rdlo = (opcode >> 12) & 0x0F; \ - u32 rn = (opcode >> 8) & 0x0F; \ - u32 rm = opcode & 0x0F \ - -#define arm_decode_swap() \ - u32 rn = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 rm = opcode & 0x0F \ - -#define arm_decode_half_trans_r() \ - u32 rn = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 rm = opcode & 0x0F \ - -#define arm_decode_half_trans_of() \ - u32 rn = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 offset = ((opcode >> 4) & 0xF0) | (opcode & 0x0F) \ - -#define arm_decode_data_trans_imm() \ - u32 rn = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 offset = opcode & 0x0FFF \ - -#define arm_decode_data_trans_reg() \ - u32 rn = (opcode >> 16) & 0x0F; \ - u32 rd = (opcode >> 12) & 0x0F; \ - u32 rm = opcode & 0x0F \ - -#define arm_decode_block_trans() \ - u32 rn = (opcode >> 16) & 0x0F; \ - u32 reg_list = opcode & 0xFFFF \ - -#define arm_decode_branch() \ - s32 offset = ((s32)(opcode & 0xFFFFFF) << 8) >> 6 \ - -#define thumb_decode_shift() \ - u32 imm = (opcode >> 6) & 0x1F; \ - u32 rs = (opcode >> 3) & 0x07; \ - u32 rd = opcode & 0x07 \ - -#define thumb_decode_add_sub() \ - u32 rn = (opcode >> 6) & 0x07; \ - u32 rs = (opcode >> 3) & 0x07; \ - u32 rd = opcode & 0x07 \ - -#define thumb_decode_add_sub_imm() \ - u32 imm = (opcode >> 6) & 0x07; \ - u32 rs = (opcode >> 3) & 0x07; \ - u32 rd = opcode & 0x07 \ - -#define thumb_decode_imm() \ - u32 imm = opcode & 0xFF \ - -#define thumb_decode_alu_op() \ - u32 rs = (opcode >> 3) & 0x07; \ - u32 rd = opcode & 0x07 \ - -#define thumb_decode_hireg_op() \ - u32 rs = (opcode >> 3) & 0x0F; \ - u32 rd = ((opcode >> 4) & 0x08) | (opcode & 0x07) \ - -#define thumb_decode_mem_reg() \ - u32 ro = (opcode >> 6) & 0x07; \ - u32 rb = (opcode >> 3) & 0x07; \ - u32 rd = opcode & 0x07 \ - -#define thumb_decode_mem_imm() \ - u32 imm = (opcode >> 6) & 0x1F; \ - u32 rb = (opcode >> 3) & 0x07; \ - u32 rd = opcode & 0x07 \ - -#define thumb_decode_add_sp() \ - u32 imm = opcode & 0x7F \ - -#define thumb_decode_rlist() \ - u32 reg_list = opcode & 0xFF \ - -#define thumb_decode_branch_cond() \ - s32 offset = (s8)(opcode & 0xFF) \ - -#define thumb_decode_swi() \ - u32 comment = opcode & 0xFF \ - -#define thumb_decode_branch() \ - u32 offset = opcode & 0x07FF \ - -const char *condition_table[] = -{ - "eq", "ne", "cs", "cc", "mi", "pl", "vs", "vc", - "hi", "ls", "ge", "lt", "gt", "le", "al", "nv" -}; - -const char *data_proc_opcode_table[] = -{ - "and", "eor", "sub", "rsb", "add", "adc", "sbc", "rsc", - "tst", "teq", "cmp", "cmn", "orr", "mov", "bic", "mvn" -}; - - -u32 print_disasm_arm_instruction(u32 opcode) -{ - u32 condition = opcode >> 28; - - switch((opcode >> 25) & 0x07) - { - // Data processing reg, multiply, bx, memory transfer half/byte, swap, - // PSR reg - case 0x0: - - // Data processing imm, PSR imm - case 0x1: - - // Memory transfer imm - case 0x2: - - // Memory transfer reg, undefined - case 0x3: - - // Block memory transfer - case 0x4: - - // Branch - case 0x5: - - // Coprocessor - case 0x6: - - // Coprocessor, SWI - case 0x7: - } diff --git a/input.c b/input.c index 20336b8..0fe859f 100644 --- a/input.c +++ b/input.c @@ -19,7 +19,10 @@ #include "common.h" -// Special thanks to psp298 for the analog->dpad code! +static u32 old_key = 0; +static retro_input_state_t input_state_cb; + +void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; } void trigger_key(u32 key) { @@ -42,34 +45,8 @@ void trigger_key(u32 key) } } -u32 key = 0; - -u32 global_enable_analog = 1; -u32 analog_sensitivity_level = 4; - -typedef enum -{ - BUTTON_NOT_HELD, - BUTTON_HELD_INITIAL, - BUTTON_HELD_REPEAT -} button_repeat_state_type; - - -// These define autorepeat values (in microseconds), tweak as necessary. - -#define BUTTON_REPEAT_START 200000 -#define BUTTON_REPEAT_CONTINUE 50000 - -button_repeat_state_type button_repeat_state = BUTTON_NOT_HELD; -u32 button_repeat = 0; -gui_action_type cursor_repeat = CURSOR_NONE; - -static retro_input_state_t input_state_cb; -void retro_set_input_state(retro_input_state_t cb) { input_state_cb = cb; } - u32 update_input(void) { -// return; unsigned i; uint32_t new_key = 0; @@ -79,19 +56,19 @@ u32 update_input(void) for (i = 0; i < sizeof(btn_map) / sizeof(map); i++) new_key |= input_state_cb(0, RETRO_DEVICE_JOYPAD, 0, btn_map[i].retropad) ? btn_map[i].gba : 0; - if ((new_key | key) != key) + if ((new_key | old_key) != old_key) trigger_key(new_key); - key = new_key; - io_registers[REG_P1] = (~key) & 0x3FF; + old_key = new_key; + io_registers[REG_P1] = (~old_key) & 0x3FF; return 0; } -#define input_savestate_builder(type) \ -void input_##type##_savestate(void) \ -{ \ - state_mem_##type##_variable(key); \ +#define input_savestate_builder(type) \ +void input_##type##_savestate(void) \ +{ \ + state_mem_##type##_variable(old_key); \ } input_savestate_builder(read) diff --git a/input.h b/input.h index 809d4bf..4c9acaa 100644 --- a/input.h +++ b/input.h @@ -20,6 +20,8 @@ #ifndef INPUT_H #define INPUT_H +#include "libretro.h" + typedef enum { BUTTON_L = 0x200, @@ -35,58 +37,12 @@ typedef enum BUTTON_NONE = 0x00 } input_buttons_type; -typedef enum -{ - BUTTON_ID_UP, - BUTTON_ID_DOWN, - BUTTON_ID_LEFT, - BUTTON_ID_RIGHT, - BUTTON_ID_A, - BUTTON_ID_B, - BUTTON_ID_L, - BUTTON_ID_R, - BUTTON_ID_START, - BUTTON_ID_SELECT, - BUTTON_ID_MENU, - BUTTON_ID_FASTFORWARD, - BUTTON_ID_LOADSTATE, - BUTTON_ID_SAVESTATE, - BUTTON_ID_RAPIDFIRE_A, - BUTTON_ID_RAPIDFIRE_B, - BUTTON_ID_RAPIDFIRE_L, - BUTTON_ID_RAPIDFIRE_R, - BUTTON_ID_VOLUP, - BUTTON_ID_VOLDOWN, - BUTTON_ID_FPS, - BUTTON_ID_NONE -} input_buttons_id_type; - -typedef enum -{ - CURSOR_UP, - CURSOR_DOWN, - CURSOR_LEFT, - CURSOR_RIGHT, - CURSOR_SELECT, - CURSOR_BACK, - CURSOR_EXIT, - CURSOR_L, - CURSOR_R, - CURSOR_NONE -} gui_action_type; - -void init_input(); -u32 update_input(); -void input_write_savestate(void); -void input_read_savestate(void); - -#include "libretro.h" - typedef struct { unsigned retropad ; input_buttons_type gba; } map; + static const map btn_map[] = { { RETRO_DEVICE_ID_JOYPAD_L, BUTTON_L }, { RETRO_DEVICE_ID_JOYPAD_R, BUTTON_R }, @@ -100,8 +56,9 @@ static const map btn_map[] = { { RETRO_DEVICE_ID_JOYPAD_A, BUTTON_A } }; -extern u32 gamepad_config_map[]; -extern u32 global_enable_analog; -extern u32 analog_sensitivity_level; +void init_input(); +u32 update_input(); +void input_write_savestate(void); +void input_read_savestate(void); #endif diff --git a/jni/Android.mk b/jni/Android.mk index e25956b..4755db9 100644 --- a/jni/Android.mk +++ b/jni/Android.mk @@ -27,6 +27,6 @@ CPU_ARCH := arm include $(CORE_DIR)/Makefile.common LOCAL_SRC_FILES := $(SOURCES_C) $(SOURCES_ASM) -LOCAL_CFLAGS += -O2 -DARM_ARCH -DNDEBUG -DINLINE=inline -D__LIBRETRO__ -DFRONTEND_SUPPORTS_RGB565 $(INCFLAGS) +LOCAL_CFLAGS += -O2 -DHAVE_MMAP -DARM_ARCH -DNDEBUG -DINLINE=inline -D__LIBRETRO__ -DFRONTEND_SUPPORTS_RGB565 $(INCFLAGS) include $(BUILD_SHARED_LIBRARY) diff --git a/libretro.c b/libretro.c index c469bf1..d834ede 100644 --- a/libretro.c +++ b/libretro.c @@ -97,6 +97,7 @@ void retro_init() init_gamepak_buffer(); init_sound(1); +#ifdef HAVE_MMAP rom_translation_cache = mmap(NULL, ROM_TRANSLATION_CACHE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0); ram_translation_cache = mmap(NULL, RAM_TRANSLATION_CACHE_SIZE, @@ -107,6 +108,7 @@ void retro_init() rom_translation_ptr = rom_translation_cache; ram_translation_ptr = ram_translation_cache; bios_translation_ptr = bios_translation_cache; +#endif } void retro_deinit() @@ -114,9 +116,11 @@ void retro_deinit() perf_cb.perf_log(); memory_term(); +#ifdef HAVE_MMAP munmap(rom_translation_cache, ROM_TRANSLATION_CACHE_SIZE); munmap(ram_translation_cache, RAM_TRANSLATION_CACHE_SIZE); munmap(bios_translation_cache, BIOS_TRANSLATION_CACHE_SIZE); +#endif } void retro_set_environment(retro_environment_t cb) diff --git a/psp/Makefile b/psp/Makefile deleted file mode 100644 index 9906e6f..0000000 --- a/psp/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -# -x assembler-with-cpp -# gpSP makefile -# Gilead Kutnick - Exophase - -# Global definitions - -PSPSDK = ${shell psp-config --pspsdk-path} -PREFIX = ${shell psp-config --psp-prefix} - -OBJS = main.o cpu.o video.o memory.o sound.o input.o \ - cpu_threaded.o gui.o zip.o cheats.o mips_stub.o - -TARGET = gpSP - -VPATH += .. -CFLAGS += -O3 -DPSP_BUILD -G0 -funsigned-char -CFLAGS += ${shell ${PREFIX}/bin/sdl-config --cflags} -ASFLAGS = ${CFLAGS} -PSP_EBOOT_TITLE = gpSP -EXTRA_TARGETS = EBOOT.PBP - -LIBS += ${shell ${PREFIX}/bin/sdl-config --libs} -lpsppower \ - -lz - -include ${PSPSDK}/lib/build.mak - diff --git a/x86/Makefile b/x86/Makefile deleted file mode 100644 index 53d2dd8..0000000 --- a/x86/Makefile +++ /dev/null @@ -1,60 +0,0 @@ -# gpSP makefile -# Gilead Kutnick - Exophase - -# Global definitions - -CC = gcc -STRIP = strip -AS = as - -PREFIX = /usr -OBJS = ../main.o ../cpu.o ../memory.o ../video.o ../input.o ../sound.o \ - ../cpu_threaded.o ../gui.o x86_stub.o ../cheats.o ../zip.o - -# Platform specific definitions - -ifeq ($(shell uname -a),) -EXE_EXT = .exe -else ifneq ($(findstring MINGW,$(shell uname -a)),) -EXE_EXT = .exe -else -EXE_EXT = -endif - -BIN ?= gpsp$(EXE_EXT) - -CFLAGS += -DPC_BUILD -Wall -m32 -INCLUDES = -I$(PREFIX)/include `sdl-config --cflags` -LIBS = -L$(PREFIX)/lib32 `sdl-config --libs` -lz -m32 - -# Compilation: - -ifeq ($(DEBUG), 1) -OPTIMIZE := -O0 -g -OPTIMIZE_SAFE := -O0 -g -else -OPTIMIZE := -O3 -OPTIMIZE_SAFE := -O2 -endif - -all: $(BIN) - -%.o: %.c - $(CC) $(CFLAGS) $(OPTIMIZE) $(INCLUDES) -c -o $@ $< - -%.o: %.S - $(CC) $(CFLAGS) $(OPTIMIZE) -c -o $@ $< - -../cpu.o: ../cpu.c - $(CC) -c -o $@ $< $(CFLAGS) -Wno-unused-variable -Wno-unused-label $(OPTIMIZE_SAFE) $(INCLUDES) - -../cpu_threaded.o: ../cpu_threaded.c - $(CC) -c -o $@ $< $(CFLAGS) -Wno-unused-variable -Wno-unused-label $(OPTIMIZE_SAFE) $(INCLUDES) - - -$(BIN): $(OBJS) - $(CC) $(OBJS) $(LIBS) -o $(BIN) - -clean: - rm -f $(OBJS) $(BIN) -