Skip to content

Commit

Permalink
Merging some commits from other forks. Also, fixing some input issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
gameblabla committed Feb 2, 2019
1 parent 07866d8 commit 9fa5d2b
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 141 deletions.
4 changes: 2 additions & 2 deletions bittboy/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion cheats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,4 +279,7 @@ typedef u32 fixed8_24;
#include "raspberrypi/rpi.h"
#endif

#define FULLY_UNINITIALIZED(declarator) declarator __attribute__((section(".noinit")))


#endif
4 changes: 2 additions & 2 deletions cpu_threaded.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
6 changes: 3 additions & 3 deletions input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 0 additions & 24 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
186 changes: 84 additions & 102 deletions memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand Down
2 changes: 1 addition & 1 deletion video.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
Loading

0 comments on commit 9fa5d2b

Please sign in to comment.