From 9fa5d2b29c3ab015605ea9f415680eb0b45a3c20 Mon Sep 17 00:00:00 2001 From: gameblabla Date: Sat, 2 Feb 2019 18:13:00 +0100 Subject: [PATCH] Merging some commits from other forks. Also, fixing some input issues. --- bittboy/Makefile | 4 +- cheats.c | 3 +- common.h | 3 + cpu_threaded.c | 4 +- input.c | 6 +- main.c | 24 ------ memory.c | 186 +++++++++++++++++++++-------------------------- memory.h | 6 +- sound.c | 4 +- video.c | 2 +- x86/Makefile | 2 +- 11 files changed, 103 insertions(+), 141 deletions(-) diff --git a/bittboy/Makefile b/bittboy/Makefile index 00f16cc7..46168256 100644 --- a/bittboy/Makefile +++ b/bittboy/Makefile @@ -16,12 +16,12 @@ BIN = gpsp VPATH += .. ../arm CFLAGS += -DARM_ARCH -DPC_BUILD -Wall -CFLAGS += -Ofast -fdata-sections -ffunction-sections -fno-PIC -fprofile-use +CFLAGS += -O2 -fdata-sections -ffunction-sections -fno-PIC -fprofile-use CFLAGS += `/opt/bittboy-toolchain/arm-miyoo-linux-musleabi/sysroot/usr/bin/sdl-config --cflags` # expecting to have PATH set up to get correct sdl-config first -LIBS += `sdl-config --libs` +LIBS += -lSDL LIBS += -ldl -lpthread -lz -lgcov -lasound -Wl,--as-needed -Wl,--gc-sections -flto -s # Compilation: diff --git a/cheats.c b/cheats.c index 8fa69aec..05a5ca92 100644 --- a/cheats.c +++ b/cheats.c @@ -266,7 +266,8 @@ void process_cheat_gs3(cheat_type *cheat) { case 0x0: { - u32 iterations = value >> 24; + /* Was 24 before. According to https://github.com/phoe-nix/TempGBA4PSP-mod/commit/e7885c30a117b9dde7ffdb9f199df44c5b1fbcb9, this fixes GS3 cheats */ + u32 iterations = value >> 8; u32 i2; value &= 0xFF; diff --git a/common.h b/common.h index 7282c7c9..46f8582c 100644 --- a/common.h +++ b/common.h @@ -279,4 +279,7 @@ typedef u32 fixed8_24; #include "raspberrypi/rpi.h" #endif +#define FULLY_UNINITIALIZED(declarator) declarator __attribute__((section(".noinit"))) + + #endif diff --git a/cpu_threaded.c b/cpu_threaded.c index db7155c2..4dbabed9 100644 --- a/cpu_threaded.c +++ b/cpu_threaded.c @@ -3069,8 +3069,8 @@ block_lookup_address_builder(dual); #define MAX_BLOCK_SIZE 8192 #define MAX_EXITS 256 -block_data_type block_data[MAX_BLOCK_SIZE]; -block_exit_type block_exits[MAX_EXITS]; +block_data_type FULLY_UNINITIALIZED(block_data[MAX_BLOCK_SIZE]); +block_exit_type FULLY_UNINITIALIZED(block_exits[MAX_EXITS]); #define smc_write_arm_yes() \ if(address32(pc_address_block, (block_end_pc & 0x7FFF) - 0x8000) == 0x0000) \ diff --git a/input.c b/input.c index 818d6d38..3d9ab12d 100644 --- a/input.c +++ b/input.c @@ -626,14 +626,14 @@ u32 key_map(SDLKey key_sym) case SDLK_RETURN: return BUTTON_START; - case SDLK_RCTRL: + case SDLK_ESCAPE: return BUTTON_SELECT; case SDLK_LCTRL: - return BUTTON_B; + return BUTTON_A; case SDLK_LALT: - return BUTTON_A; + return BUTTON_B; default: return BUTTON_NONE; diff --git a/main.c b/main.c index c0841819..8113ef97 100644 --- a/main.c +++ b/main.c @@ -296,30 +296,6 @@ int main(int argc, char *argv[]) quit(); } - if(bios_rom[0] != 0x18) - { - gui_action_type gui_action = CURSOR_NONE; - - debug_screen_start(); - debug_screen_printl("You have an incorrect BIOS image. "); - debug_screen_printl("While many games will work fine, some will not. It"); - debug_screen_printl("is strongly recommended that you obtain the "); - debug_screen_printl("correct BIOS file. Do NOT report any bugs if you "); - debug_screen_printl("are seeing this message. "); - debug_screen_printl(" "); - debug_screen_printl("Press any button to resume, at your own risk. "); - - debug_screen_update(); - - while(gui_action == CURSOR_NONE) - { - gui_action = get_gui_input(); - delay_us(15000); - } - - debug_screen_end(); - } - init_main(); init_sound(1); diff --git a/memory.c b/memory.c index 875b7229..53ef4ed5 100644 --- a/memory.c +++ b/memory.c @@ -58,37 +58,38 @@ u32 gamepak_waitstate_sequential[2][3][3] = } }; -u16 palette_ram[512]; -u16 oam_ram[512]; -u16 palette_ram_converted[512]; -u16 io_registers[1024 * 16]; -u8 ewram[1024 * 256 * 2]; -u8 iwram[1024 * 32 * 2]; -u8 vram[1024 * 96 * 2]; -u8 bios_rom[1024 * 32]; -u32 bios_read_protect; +FULLY_UNINITIALIZED(uint16_t palette_ram[0x200]); +FULLY_UNINITIALIZED(uint16_t oam_ram[0x200]); +FULLY_UNINITIALIZED(uint16_t palette_ram_converted[0x200]); +FULLY_UNINITIALIZED(uint16_t io_registers[1024 * 16]); +FULLY_UNINITIALIZED(uint8_t ewram[1024 * 256 * 2]); +FULLY_UNINITIALIZED(uint8_t iwram[1024 * 32 * 2]); +FULLY_UNINITIALIZED(uint8_t vram[1024 * 96 * 2]); + +FULLY_UNINITIALIZED(uint8_t bios_rom[1024 * 32]); +uint32_t bios_read_protect; // Up to 128kb, store SRAM, flash ROM, or EEPROM here. -u8 gamepak_backup[1024 * 128]; +uint8_t gamepak_backup[0x20000]; // Keeps us knowing how much we have left. -u8 *gamepak_rom; -u32 gamepak_size; +uint8_t *gamepak_rom; +uint32_t gamepak_size; dma_transfer_type dma[4]; -u8 *memory_regions[16]; -u32 memory_limits[16]; +uint8_t *memory_regions[16]; +uint32_t memory_limits[16]; typedef struct { - u32 page_timestamp; - u32 physical_index; + uint32_t page_timestamp; + uint32_t physical_index; } gamepak_swap_entry_type; -u32 gamepak_ram_buffer_size; -u32 gamepak_ram_pages; +uint32_t gamepak_ram_buffer_size; +uint32_t gamepak_ram_pages; // Enough to map the gamepak RAM space. gamepak_swap_entry_type *gamepak_memory_map; @@ -861,35 +862,26 @@ cpu_alert_type function_cc write_io_register8(u32 address, u32 value) break; // Sound FIFO A - case 0xA0: - sound_timer_queue8(0, value); + case 0xA0 ... 0xA3: + address8(io_registers, address) = value; + sound_timer_queue32(0, value); break; // Sound FIFO B - case 0xA4: - sound_timer_queue8(1, value); - break; - - // DMA control (trigger byte) - case 0xBB: - access_register8_low(0xBA); - trigger_dma(0); - break; - - case 0xC7: - access_register8_low(0xC6); - trigger_dma(1); + case 0xA4 ... 0xA7: + address8(io_registers, address) = value; + sound_timer_queue32(1, value); break; - case 0xD3: - access_register8_low(0xD2); - trigger_dma(2); - break; - case 0xDF: - access_register8_low(0xDE); - trigger_dma(3); - break; + // DMA control (trigger byte) + case 0xBB: // DMA channel 0 + case 0xC7: // DMA channel 1 + case 0xD3: // DMA channel 2 + case 0xDF: // DMA channel 3 + access_register8_high(address - 1); + trigger_dma((address - 0xBB) / 12); + break; // Timer counts case 0x100: @@ -933,25 +925,28 @@ cpu_alert_type function_cc write_io_register8(u32 address, u32 value) break; // Timer control (trigger byte) - case 0x103: - access_register8_low(0x102); - trigger_timer(0); - break; - - case 0x107: - access_register8_low(0x106); - trigger_timer(1); - break; - - case 0x10B: - access_register8_low(0x10A); - trigger_timer(2); + case 0x103: // Timer 0 + case 0x107: // Timer 1 + case 0x10B: // Timer 2 + case 0x10F: // Timer 3 + access_register8_high(address - 1); + trigger_timer((address - 0x103) / 4); + break; + + case 0x128: + case 0x129: + case 0x134: + case 0x135: + // P1 + case 0x130: + case 0x131: + /* Read only */ break; - case 0x10F: - access_register8_low(0x10E); - trigger_timer(3); - break; + // IE + case 0x200: + address8(io_registers, 0x200) = value; + break; // IF case 0x202: @@ -1130,69 +1125,55 @@ cpu_alert_type function_cc write_io_register16(u32 address, u32 value) // Sound FIFO A case 0xA0: - sound_timer_queue16(0, value); + case 0xA2: + address16(io_registers, address) = value; + sound_timer_queue32(0, value); break; // Sound FIFO B case 0xA4: - sound_timer_queue16(1, value); + case 0xA6: + address16(io_registers, address) = value; + sound_timer_queue32(1, value); break; // DMA control - case 0xBA: - trigger_dma(0); - break; - - case 0xC6: - trigger_dma(1); - break; - - case 0xD2: - trigger_dma(2); - break; - - case 0xDE: - trigger_dma(3); - break; + case 0xBA: // DMA channel 0 + case 0xC6: // DMA channel 1 + case 0xD2: // DMA channel 2 + case 0xDE: // DMA channel 3 + trigger_dma((address - 0xBA) / 12); + break; // Timer counts case 0x100: - count_timer(0); - break; - case 0x104: - count_timer(1); - break; - case 0x108: - count_timer(2); - break; - case 0x10C: - count_timer(3); - break; + count_timer((address - 0x100) / 4); + break; // Timer control - case 0x102: - trigger_timer(0); - break; + case 0x102: // Timer 0 + case 0x106: // Timer 1 + case 0x10A: // Timer 2 + case 0x10E: // Timer 3 + trigger_timer((address - 0x102) / 4); + break; - case 0x106: - trigger_timer(1); - break; - - case 0x10A: - trigger_timer(2); - break; - - case 0x10E: - trigger_timer(3); - break; + case 0x128: + address16(io_registers, 0x128) |= 0x0C; + break; // P1 case 0x130: break; + // IE + case 0x200: + address16(io_registers, 0x200) = value; + break; + // Interrupt flag case 0x202: address16(io_registers, 0x202) &= ~value; @@ -3173,7 +3154,7 @@ void load_state(char *savestate_filename) file_close(savestate_file); - flush_translation_cache_ram(); + flush_translation_cache_ram(); flush_translation_cache_rom(); flush_translation_cache_bios(); @@ -3222,7 +3203,8 @@ void load_state(char *savestate_filename) } } -u8 savestate_write_buffer[506947]; + +FULLY_UNINITIALIZED(u8 savestate_write_buffer[506947] __attribute__ ((aligned (4)))); u8 *write_mem_ptr; void save_state(char *savestate_filename, u16 *screen_capture) diff --git a/memory.h b/memory.h index 5e65821c..98b0b726 100644 --- a/memory.h +++ b/memory.h @@ -199,9 +199,9 @@ extern dma_transfer_type dma[4]; extern u8 *write_mem_ptr; -extern u16 palette_ram[512]; -extern u16 oam_ram[512]; -extern u16 palette_ram_converted[512]; +extern u16 palette_ram[0x200]; +extern u16 oam_ram[0x200]; +extern u16 palette_ram_converted[0x200]; extern u16 io_registers[1024 * 16]; extern u8 ewram[1024 * 256 * 2]; extern u8 iwram[1024 * 32 * 2]; diff --git a/sound.c b/sound.c index 36635f4f..ff21c15b 100644 --- a/sound.c +++ b/sound.c @@ -194,8 +194,8 @@ s8 square_pattern_duty[4][8] = s8 wave_samples[64]; -u32 noise_table15[1024]; -u32 noise_table7[4]; +FULLY_UNINITIALIZED(u32 noise_table15[1024]); +FULLY_UNINITIALIZED(u32 noise_table7[4]); u32 gbc_sound_master_volume_table[4] = { 1, 2, 4, 0 }; diff --git a/video.c b/video.c index 56c1c02b..972ae55f 100644 --- a/video.c +++ b/video.c @@ -1909,7 +1909,7 @@ static const u32 obj_width_table[] = static const u32 obj_height_table[] = { 8, 16, 32, 64, 8, 8, 16, 32, 16, 32, 32, 64 }; -static u8 obj_priority_list[5][160][128]; +static FULLY_UNINITIALIZED(u8 obj_priority_list[5][160][128]); static u32 obj_priority_count[5][160]; static u32 obj_alpha_count[160]; diff --git a/x86/Makefile b/x86/Makefile index 62045722..e2868b6a 100644 --- a/x86/Makefile +++ b/x86/Makefile @@ -9,7 +9,7 @@ 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 + cpu_threaded.o gui.o x86_stub.o cheats.o zip.o sha1.o BIN ?= gpsp # Platform specific definitions