enable -Wall and fix warnings reported by it

This commit is contained in:
notaz 2011-09-05 19:31:58 +03:00
parent eb3668fc5d
commit bbba320911
23 changed files with 294 additions and 285 deletions

View file

@ -233,7 +233,6 @@ u32 arm_disect_imm_32bit(u32 imm, u32 *stores, u32 *rotations)
{ {
u32 store_count = 0; u32 store_count = 0;
u32 left_shift = 0; u32 left_shift = 0;
u32 i;
// Otherwise it'll return 0 things to store because it'll never // Otherwise it'll return 0 things to store because it'll never
// find anything. // find anything.
@ -276,7 +275,6 @@ u32 arm_disect_imm_32bit(u32 imm, u32 *stores, u32 *rotations)
{ {
// Then we can throw out the last bit and tack it on // Then we can throw out the last bit and tack it on
// to the first bit. // to the first bit.
u32 initial_bits = rotations[0];
stores[0] = stores[0] =
(stores[0] << ((top_bits + (32 - rotations[0])) & 0x1F)) | (stores[0] << ((top_bits + (32 - rotations[0])) & 0x1F)) |
((imm >> left_shift) & 0xFF); ((imm >> left_shift) & 0xFF);

View file

@ -25,7 +25,7 @@ u32 num_cheats;
void decrypt_gsa_code(u32 *address_ptr, u32 *value_ptr, cheat_variant_enum void decrypt_gsa_code(u32 *address_ptr, u32 *value_ptr, cheat_variant_enum
cheat_variant) cheat_variant)
{ {
u32 i, i2, code_position; u32 i;
u32 address = *address_ptr; u32 address = *address_ptr;
u32 value = *value_ptr; u32 value = *value_ptr;
u32 r = 0xc6ef3720; u32 r = 0xc6ef3720;
@ -58,11 +58,11 @@ void decrypt_gsa_code(u32 *address_ptr, u32 *value_ptr, cheat_variant_enum
*value_ptr = value; *value_ptr = value;
} }
void add_cheats(u8 *cheats_filename) void add_cheats(char *cheats_filename)
{ {
FILE *cheats_file; FILE *cheats_file;
u8 current_line[256]; char current_line[256];
u8 *name_ptr; char *name_ptr;
u32 *cheat_code_ptr; u32 *cheat_code_ptr;
u32 address, value; u32 address, value;
u32 num_cheat_lines; u32 num_cheat_lines;
@ -110,8 +110,8 @@ void add_cheats(u8 *cheats_filename)
cheats[num_cheats].cheat_name[CHEAT_NAME_LENGTH - 1] = 0; cheats[num_cheats].cheat_name[CHEAT_NAME_LENGTH - 1] = 0;
cheat_name_length = strlen(cheats[num_cheats].cheat_name); cheat_name_length = strlen(cheats[num_cheats].cheat_name);
if(cheat_name_length && if(cheat_name_length &&
(cheats[num_cheats].cheat_name[cheat_name_length - 1] == '\n') || ((cheats[num_cheats].cheat_name[cheat_name_length - 1] == '\n') ||
(cheats[num_cheats].cheat_name[cheat_name_length - 1] == '\r')) (cheats[num_cheats].cheat_name[cheat_name_length - 1] == '\r')))
{ {
cheats[num_cheats].cheat_name[cheat_name_length - 1] = 0; cheats[num_cheats].cheat_name[cheat_name_length - 1] = 0;
cheat_name_length--; cheat_name_length--;
@ -382,6 +382,9 @@ void process_cheats()
case CHEAT_TYPE_GAMESHARK_V3: case CHEAT_TYPE_GAMESHARK_V3:
process_cheat_gs3(cheats + i); process_cheat_gs3(cheats + i);
break; break;
default:
break;
} }
} }
} }

View file

@ -28,7 +28,7 @@ typedef enum
typedef struct typedef struct
{ {
u8 cheat_name[CHEAT_NAME_LENGTH]; char cheat_name[CHEAT_NAME_LENGTH];
u32 cheat_active; u32 cheat_active;
u32 cheat_codes[256]; u32 cheat_codes[256];
u32 num_cheat_lines; u32 num_cheat_lines;
@ -36,7 +36,7 @@ typedef struct
} cheat_type; } cheat_type;
void process_cheats(); void process_cheats();
void add_cheats(u8 *cheats_filename); void add_cheats(char *cheats_filename);
#define MAX_CHEATS 16 #define MAX_CHEATS 16

51
cpu.c
View file

@ -362,7 +362,7 @@ void print_register_usage()
#define calculate_reg_sh() \ #define calculate_reg_sh() \
u32 reg_sh; \ u32 reg_sh = 0; \
switch((opcode >> 4) & 0x07) \ switch((opcode >> 4) & 0x07) \
{ \ { \
/* LSL imm */ \ /* LSL imm */ \
@ -451,7 +451,7 @@ void print_register_usage()
} \ } \
#define calculate_reg_sh_flags() \ #define calculate_reg_sh_flags() \
u32 reg_sh; \ u32 reg_sh = 0; \
switch((opcode >> 4) & 0x07) \ switch((opcode >> 4) & 0x07) \
{ \ { \
/* LSL imm */ \ /* LSL imm */ \
@ -604,7 +604,7 @@ void print_register_usage()
} \ } \
#define calculate_reg_offset() \ #define calculate_reg_offset() \
u32 reg_offset; \ u32 reg_offset = 0; \
switch((opcode >> 5) & 0x03) \ switch((opcode >> 5) & 0x03) \
{ \ { \
/* LSL imm */ \ /* LSL imm */ \
@ -960,7 +960,7 @@ const u32 psr_masks[16] =
else \ else \
\ \
if(((_address & aligned_address_mask##size) == 0) && \ if(((_address & aligned_address_mask##size) == 0) && \
(map = memory_map_read[address >> 15])) \ (map = memory_map_read[_address >> 15])) \
{ \ { \
dest = *((type *)((u8 *)map + (_address & 0x7FFF))); \ dest = *((type *)((u8 *)map + (_address & 0x7FFF))); \
} \ } \
@ -1016,37 +1016,39 @@ const u32 psr_masks[16] =
#define load_aligned32(address, dest) \ #define load_aligned32(address, dest) \
{ \ { \
u8 *map = memory_map_read[address >> 15]; \ u32 _address = address; \
if(address < 0x10000000) \ u8 *map = memory_map_read[_address >> 15]; \
if(_address < 0x10000000) \
{ \ { \
memory_region_access_read_u32[address >> 24]++; \ memory_region_access_read_u32[_address >> 24]++; \
memory_reads_u32++; \ memory_reads_u32++; \
} \ } \
if(map) \ if(map) \
{ \ { \
dest = address32(map, address & 0x7FFF); \ dest = address32(map, _address & 0x7FFF); \
} \ } \
else \ else \
{ \ { \
dest = read_memory32(address); \ dest = read_memory32(_address); \
} \ } \
} \ } \
#define store_aligned32(address, value) \ #define store_aligned32(address, value) \
{ \ { \
u8 *map = memory_map_write[address >> 15]; \ u32 _address = address; \
if(address < 0x10000000) \ u8 *map = memory_map_write[_address >> 15]; \
if(_address < 0x10000000) \
{ \ { \
memory_region_access_write_u32[address >> 24]++; \ memory_region_access_write_u32[_address >> 24]++; \
memory_writes_u32++; \ memory_writes_u32++; \
} \ } \
if(map) \ if(map) \
{ \ { \
address32(map, address & 0x7FFF) = value; \ address32(map, _address & 0x7FFF) = value; \
} \ } \
else \ else \
{ \ { \
cpu_alert = write_memory32(address, value); \ cpu_alert = write_memory32(_address, value); \
if(cpu_alert) \ if(cpu_alert) \
goto alert; \ goto alert; \
} \ } \
@ -1233,7 +1235,7 @@ const u32 psr_masks[16] =
const u32 _sa = src_a; \ const u32 _sa = src_a; \
const u32 _sb = src_b; \ const u32 _sb = src_b; \
u32 dest = _sa + _sb; \ u32 dest = _sa + _sb; \
calculate_flags_add(dest, src_a, src_b); \ calculate_flags_add(dest, _sa, _sb); \
reg[dest_reg] = dest; \ reg[dest_reg] = dest; \
thumb_pc_offset(2); \ thumb_pc_offset(2); \
} \ } \
@ -1241,7 +1243,7 @@ const u32 psr_masks[16] =
#define thumb_add_noflags(type, dest_reg, src_a, src_b) \ #define thumb_add_noflags(type, dest_reg, src_a, src_b) \
{ \ { \
thumb_decode_##type(); \ thumb_decode_##type(); \
u32 dest = src_a + src_b; \ u32 dest = (src_a) + (src_b); \
reg[dest_reg] = dest; \ reg[dest_reg] = dest; \
thumb_pc_offset(2); \ thumb_pc_offset(2); \
} \ } \
@ -1252,7 +1254,7 @@ const u32 psr_masks[16] =
const u32 _sa = src_a; \ const u32 _sa = src_a; \
const u32 _sb = src_b; \ const u32 _sb = src_b; \
u32 dest = _sa - _sb; \ u32 dest = _sa - _sb; \
calculate_flags_sub(dest, src_a, src_b); \ calculate_flags_sub(dest, _sa, _sb); \
reg[dest_reg] = dest; \ reg[dest_reg] = dest; \
thumb_pc_offset(2); \ thumb_pc_offset(2); \
} \ } \
@ -4058,19 +4060,19 @@ u32 last_instruction = 0;
u32 in_interrupt = 0; u32 in_interrupt = 0;
u32 debug_on() void debug_on()
{ {
current_debug_state = STEP; current_debug_state = STEP;
debug_screen_start(); debug_screen_start();
} }
u32 debug_off(debug_state new_debug_state) void debug_off(debug_state new_debug_state)
{ {
current_debug_state = new_debug_state; current_debug_state = new_debug_state;
debug_screen_end(); debug_screen_end();
} }
u32 function_cc step_debug(u32 pc, u32 cycles) void function_cc step_debug(u32 pc, u32 cycles)
{ {
u32 thumb = 0; u32 thumb = 0;
@ -4134,6 +4136,9 @@ u32 function_cc step_debug(u32 pc, u32 cycles)
break; break;
} }
default:
break;
} }
if((current_debug_state == STEP) || if((current_debug_state == STEP) ||
@ -4263,7 +4268,7 @@ u32 function_cc step_debug(u32 pc, u32 cycles)
case 'a': case 'a':
{ {
u8 current_savestate_filename[512]; char current_savestate_filename[512];
u16 *current_screen = copy_screen(); u16 *current_screen = copy_screen();
get_savestate_filename_noshot(savestate_slot, get_savestate_filename_noshot(savestate_slot,
current_savestate_filename); current_savestate_filename);
@ -4286,8 +4291,6 @@ u32 function_cc step_debug(u32 pc, u32 cycles)
reg[REG_PC] = pc + 2; reg[REG_PC] = pc + 2;
else else
reg[REG_PC] = pc + 4; reg[REG_PC] = pc + 4;
return 0;
} }
void set_cpu_mode(cpu_mode_type new_mode) void set_cpu_mode(cpu_mode_type new_mode)
@ -4352,7 +4355,7 @@ void raise_interrupt(irq_type irq_raised)
} }
} }
u32 execute_arm(u32 cycles) void execute_arm(u32 cycles)
{ {
u32 pc = reg[REG_PC]; u32 pc = reg[REG_PC];
u32 opcode; u32 opcode;

6
cpu.h
View file

@ -109,11 +109,13 @@ extern debug_state current_debug_state;
extern u32 instruction_count; extern u32 instruction_count;
extern u32 last_instruction; extern u32 last_instruction;
u32 function_cc step_debug(u32 pc, u32 cycles); void execute_arm(u32 cycles);
u32 execute_arm(u32 cycles);
void raise_interrupt(irq_type irq_raised); void raise_interrupt(irq_type irq_raised);
void set_cpu_mode(cpu_mode_type new_mode); void set_cpu_mode(cpu_mode_type new_mode);
void debug_on();
void debug_off(debug_state new_debug_state);
u32 function_cc execute_load_u8(u32 address); u32 function_cc execute_load_u8(u32 address);
u32 function_cc execute_load_u16(u32 address); u32 function_cc execute_load_u16(u32 address);
u32 function_cc execute_load_u32(u32 address); u32 function_cc execute_load_u32(u32 address);

View file

@ -3177,7 +3177,7 @@ block_exit_type block_exits[MAX_EXITS];
s32 translate_block_##type(u32 pc, translation_region_type \ s32 translate_block_##type(u32 pc, translation_region_type \
translation_region, u32 smc_enable) \ translation_region, u32 smc_enable) \
{ \ { \
u32 opcode; \ u32 opcode = 0; \
u32 last_opcode; \ u32 last_opcode; \
u32 condition; \ u32 condition; \
u32 last_condition; \ u32 last_condition; \
@ -3192,9 +3192,9 @@ s32 translate_block_##type(u32 pc, translation_region_type \
u32 branch_target; \ u32 branch_target; \
u32 cycle_count = 0; \ u32 cycle_count = 0; \
u8 *translation_target; \ u8 *translation_target; \
u8 *backpatch_address; \ u8 *backpatch_address = NULL; \
u8 *translation_ptr; \ u8 *translation_ptr = NULL; \
u8 *translation_cache_limit; \ u8 *translation_cache_limit = NULL; \
s32 i; \ s32 i; \
u32 flag_status; \ u32 flag_status; \
block_exit_type external_block_exits[MAX_EXITS]; \ block_exit_type external_block_exits[MAX_EXITS]; \

4
font.h
View file

@ -23,6 +23,8 @@
#define FONT_WIDTH 6 #define FONT_WIDTH 6
#define FONT_HEIGHT 10 #define FONT_HEIGHT 10
#ifdef WANT_FONT_BITS
/* Font information: /* Font information:
name: 6x10 name: 6x10
facename: -Misc-Fixed-Medium-R-Normal--10-100-75-75-C-60-ISO8859-1 facename: -Misc-Fixed-Medium-R-Normal--10-100-75-75-C-60-ISO8859-1
@ -5876,3 +5878,5 @@ static unsigned long _font_offset[256] =
2210, /* (0xfe) */ 2210, /* (0xfe) */
2220 /* (0xff) */ 2220 /* (0xff) */
}; };
#endif /* WANT_FONT_BITS */

View file

@ -29,7 +29,7 @@ CFLAGS += -DWIZ_BUILD
endif endif
# NOTE: -funroll-loops will slow down compiling considerably # NOTE: -funroll-loops will slow down compiling considerably
CFLAGS += -O3 -std=c99 -msoft-float -funsigned-char -fno-common \ CFLAGS += -O3 -std=c99 -msoft-float -funsigned-char -fno-common \
-fno-builtin \ -fno-builtin -Wall \
INCLUDES = `$(PREFIX)/bin/sdl-config --cflags` -I$(PREFIX)/include INCLUDES = `$(PREFIX)/bin/sdl-config --cflags` -I$(PREFIX)/include
LIBS = `$(PREFIX)/bin/sdl-config --libs` \ LIBS = `$(PREFIX)/bin/sdl-config --libs` \
@ -42,6 +42,10 @@ endif
.SUFFIXES: .c .SUFFIXES: .c
all: $(BIN)
cpu.o cpu_threaded.z: CFLAGS += -Wno-unused-variable -Wno-unused-label
%.z: %.c %.z: %.c
$(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $< $(CC) $(CFLAGS) $(INCLUDES) -c -o $@ $<
@ -57,7 +61,7 @@ endif
%.o: %.s %.o: %.s
$(CC) $(ASFLAGS) $(INCLUDES) -c -o $@ $< $(CC) $(ASFLAGS) $(INCLUDES) -c -o $@ $<
all: $(OBJS) $(BIN): $(OBJS)
$(CC) $(OBJS) $(LIBS) -o $(BIN) $(CC) $(OBJS) $(LIBS) -o $(BIN)
$(STRIP) $(BIN) $(STRIP) $(BIN)

View file

@ -32,7 +32,9 @@
static u32 gpsp_gp2x_dev_audio; static u32 gpsp_gp2x_dev_audio;
static u32 gpsp_gp2x_dev; static u32 gpsp_gp2x_dev;
#ifdef WIZ_BUILD
static u32 gpsp_gp2x_gpiodev; static u32 gpsp_gp2x_gpiodev;
#endif
static u32 gp2x_audio_volume = 74/2; static u32 gp2x_audio_volume = 74/2;

178
gui.c
View file

@ -69,7 +69,7 @@
#define COLOR_HELP_TEXT color16(16, 40, 24) #define COLOR_HELP_TEXT color16(16, 40, 24)
#ifdef PSP_BUILD #ifdef PSP_BUILD
u8 *clock_speed_options[] = static const char *clock_speed_options[] =
{ {
"33MHz", "66MHz", "100MHz", "133MHz", "166MHz", "200MHz", "233MHz", "33MHz", "66MHz", "100MHz", "133MHz", "166MHz", "200MHz", "233MHz",
"266MHz", "300MHz", "333MHz" "266MHz", "300MHz", "333MHz"
@ -79,7 +79,7 @@
#define get_clock_speed_number() \ #define get_clock_speed_number() \
clock_speed_number = (clock_speed / 33) - 1 clock_speed_number = (clock_speed / 33) - 1
#elif defined(WIZ_BUILD) #elif defined(WIZ_BUILD)
u8 *clock_speed_options[] = static const char *clock_speed_options[] =
{ {
"300MHz", "333MHz", "366MHz", "400MHz", "433MHz", "300MHz", "333MHz", "366MHz", "400MHz", "433MHz",
"466MHz", "500MHz", "533MHz", "566MHz", "600MHz", "466MHz", "500MHz", "533MHz", "566MHz", "600MHz",
@ -91,7 +91,7 @@
#define get_clock_speed_number() \ #define get_clock_speed_number() \
clock_speed_number = (clock_speed - 300) / 33 clock_speed_number = (clock_speed - 300) / 33
#elif defined(GP2X_BUILD) #elif defined(GP2X_BUILD)
u8 *clock_speed_options[] = static const char *clock_speed_options[] =
{ {
"150MHz", "160MHz", "170MHz", "180MHz", "190MHz", "150MHz", "160MHz", "170MHz", "180MHz", "190MHz",
"200MHz", "210MHz", "220MHz", "230MHz", "240MHz", "200MHz", "210MHz", "220MHz", "230MHz", "240MHz",
@ -102,12 +102,12 @@
#define get_clock_speed_number() \ #define get_clock_speed_number() \
clock_speed_number = (clock_speed - 150) / 10 clock_speed_number = (clock_speed - 150) / 10
#else #else
u8 *clock_speed_options[] = static const char *clock_speed_options[] =
{ {
"0" "0"
}; };
#define menu_get_clock_speed() 0 #define menu_get_clock_speed()
#define get_clock_speed_number() 0 #define get_clock_speed_number()
#endif #endif
@ -125,25 +125,24 @@ int sort_function(const void *dest_str_ptr, const void *src_str_ptr)
return strcasecmp(dest_str, src_str); return strcasecmp(dest_str, src_str);
} }
s32 load_file(u8 **wildcards, u8 *result) s32 load_file(const char **wildcards, char *result)
{ {
DIR *current_dir; DIR *current_dir;
struct dirent *current_file; struct dirent *current_file;
struct stat file_info; struct stat file_info;
u8 current_dir_name[MAX_PATH]; char current_dir_name[MAX_PATH];
u8 current_dir_short[81]; char current_dir_short[81];
u32 current_dir_length; u32 current_dir_length;
u32 total_filenames_allocated; u32 total_filenames_allocated;
u32 total_dirnames_allocated; u32 total_dirnames_allocated;
u8 **file_list; char **file_list;
u8 **dir_list; char **dir_list;
u32 num_files; u32 num_files;
u32 num_dirs; u32 num_dirs;
u8 *file_name; char *file_name;
u32 file_name_length; u32 file_name_length;
u32 ext_pos = -1; u32 ext_pos = -1;
u32 chosen_file, chosen_dir; u32 chosen_file, chosen_dir;
u32 dialog_result = 1;
s32 return_value = 1; s32 return_value = 1;
s32 current_file_selection; s32 current_file_selection;
s32 current_file_scroll_value; s32 current_file_scroll_value;
@ -168,10 +167,10 @@ s32 load_file(u8 **wildcards, u8 *result)
total_filenames_allocated = 32; total_filenames_allocated = 32;
total_dirnames_allocated = 32; total_dirnames_allocated = 32;
file_list = (u8 **)malloc(sizeof(u8 *) * 32); file_list = (char **)malloc(sizeof(char *) * 32);
dir_list = (u8 **)malloc(sizeof(u8 *) * 32); dir_list = (char **)malloc(sizeof(char *) * 32);
memset(file_list, 0, sizeof(u8 *) * 32); memset(file_list, 0, sizeof(char *) * 32);
memset(dir_list, 0, sizeof(u8 *) * 32); memset(dir_list, 0, sizeof(char *) * 32);
num_files = 0; num_files = 0;
num_dirs = 0; num_dirs = 0;
@ -199,8 +198,7 @@ s32 load_file(u8 **wildcards, u8 *result)
{ {
if(S_ISDIR(file_info.st_mode)) if(S_ISDIR(file_info.st_mode))
{ {
dir_list[num_dirs] = dir_list[num_dirs] = malloc(file_name_length + 1);
(u8 *)malloc(file_name_length + 1);
sprintf(dir_list[num_dirs], "%s", file_name); sprintf(dir_list[num_dirs], "%s", file_name);
@ -227,7 +225,7 @@ s32 load_file(u8 **wildcards, u8 *result)
wildcards[i])) wildcards[i]))
{ {
file_list[num_files] = file_list[num_files] =
(u8 *)malloc(file_name_length + 1); malloc(file_name_length + 1);
sprintf(file_list[num_files], "%s", file_name); sprintf(file_list[num_files], "%s", file_name);
@ -241,26 +239,26 @@ s32 load_file(u8 **wildcards, u8 *result)
if(num_files == total_filenames_allocated) if(num_files == total_filenames_allocated)
{ {
file_list = (u8 **)realloc(file_list, sizeof(u8 *) * file_list = (char **)realloc(file_list, sizeof(char *) *
total_filenames_allocated * 2); total_filenames_allocated * 2);
memset(file_list + total_filenames_allocated, 0, memset(file_list + total_filenames_allocated, 0,
sizeof(u8 *) * total_filenames_allocated); sizeof(char *) * total_filenames_allocated);
total_filenames_allocated *= 2; total_filenames_allocated *= 2;
} }
if(num_dirs == total_dirnames_allocated) if(num_dirs == total_dirnames_allocated)
{ {
dir_list = (u8 **)realloc(dir_list, sizeof(u8 *) * dir_list = (char **)realloc(dir_list, sizeof(char *) *
total_dirnames_allocated * 2); total_dirnames_allocated * 2);
memset(dir_list + total_dirnames_allocated, 0, memset(dir_list + total_dirnames_allocated, 0,
sizeof(u8 *) * total_dirnames_allocated); sizeof(char *) * total_dirnames_allocated);
total_dirnames_allocated *= 2; total_dirnames_allocated *= 2;
} }
} }
} while(current_file); } while(current_file);
qsort((void *)file_list, num_files, sizeof(u8 *), sort_function); qsort((void *)file_list, num_files, sizeof(char *), sort_function);
qsort((void *)dir_list, num_dirs, sizeof(u8 *), sort_function); qsort((void *)dir_list, num_dirs, sizeof(char *), sort_function);
closedir(current_dir); closedir(current_dir);
@ -296,8 +294,6 @@ s32 load_file(u8 **wildcards, u8 *result)
clear_screen(COLOR_BG); clear_screen(COLOR_BG);
{ {
u8 print_buffer[81];
while(repeat) while(repeat)
{ {
flip_screen(); flip_screen();
@ -526,6 +522,9 @@ s32 load_file(u8 **wildcards, u8 *result)
return_value = -1; return_value = -1;
repeat = 0; repeat = 0;
break; break;
default:
break;
} }
} }
} }
@ -747,7 +746,7 @@ u32 gamepad_config_line_to_button[] =
#endif #endif
u8 *scale_options[] = static const char *scale_options[] =
{ {
#ifdef PSP_BUILD #ifdef PSP_BUILD
"unscaled 3:2", "scaled 3:2", "fullscreen 16:9" "unscaled 3:2", "scaled 3:2", "fullscreen 16:9"
@ -765,7 +764,7 @@ u8 *scale_options[] =
s32 load_game_config_file() s32 load_game_config_file()
{ {
u8 game_config_filename[512]; char game_config_filename[512];
u32 file_loaded = 0; u32 file_loaded = 0;
u32 i; u32 i;
change_ext(gamepak_filename, game_config_filename, ".cfg"); change_ext(gamepak_filename, game_config_filename, ".cfg");
@ -840,7 +839,7 @@ s32 load_game_config_file()
s32 load_config_file() s32 load_config_file()
{ {
u8 config_path[512]; char config_path[512];
#if defined(_WIN32) || defined(_WIN32_WCE) #if defined(_WIN32) || defined(_WIN32_WCE)
sprintf(config_path, "%s\\%s", main_path, GPSP_CONFIG_FILENAME); sprintf(config_path, "%s\\%s", main_path, GPSP_CONFIG_FILENAME);
@ -858,8 +857,6 @@ s32 load_config_file()
if(file_size == 92) if(file_size == 92)
{ {
u32 file_options[file_size / 4]; u32 file_options[file_size / 4];
u32 i;
s32 menu_button = -1;
file_read_array(config_file, file_options); file_read_array(config_file, file_options);
screen_scale = file_options[0] % screen_scale = file_options[0] %
@ -885,6 +882,8 @@ s32 load_config_file()
// key, if not assign to triangle // key, if not assign to triangle
#ifndef PC_BUILD #ifndef PC_BUILD
u32 i;
s32 menu_button = -1;
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
{ {
gamepad_config_map[i] = file_options[7 + i] % gamepad_config_map[i] = file_options[7 + i] %
@ -913,7 +912,7 @@ s32 load_config_file()
s32 save_game_config_file() s32 save_game_config_file()
{ {
u8 game_config_filename[512]; char game_config_filename[512];
u32 i; u32 i;
change_ext(gamepak_filename, game_config_filename, ".cfg"); change_ext(gamepak_filename, game_config_filename, ".cfg");
@ -946,7 +945,7 @@ s32 save_game_config_file()
s32 save_config_file() s32 save_config_file()
{ {
u8 config_path[512]; char config_path[512];
#if (defined(PSP_BUILD) || defined(ARM_ARCH)) && !defined(_WIN32_WCE) #if (defined(PSP_BUILD) || defined(ARM_ARCH)) && !defined(_WIN32_WCE)
sprintf(config_path, "%s/%s", main_path, GPSP_CONFIG_FILENAME); sprintf(config_path, "%s/%s", main_path, GPSP_CONFIG_FILENAME);
@ -961,7 +960,6 @@ s32 save_config_file()
if(file_check_valid(config_file)) if(file_check_valid(config_file))
{ {
u32 file_options[23]; u32 file_options[23];
u32 i;
file_options[0] = screen_scale; file_options[0] = screen_scale;
file_options[1] = screen_filter; file_options[1] = screen_filter;
@ -972,6 +970,7 @@ s32 save_config_file()
file_options[6] = analog_sensitivity_level; file_options[6] = analog_sensitivity_level;
#ifndef PC_BUILD #ifndef PC_BUILD
u32 i;
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
{ {
file_options[7 + i] = gamepad_config_map[i]; file_options[7 + i] = gamepad_config_map[i];
@ -999,16 +998,16 @@ typedef enum
u32 savestate_slot = 0; u32 savestate_slot = 0;
void get_savestate_snapshot(u8 *savestate_filename) void get_savestate_snapshot(char *savestate_filename)
{ {
u16 snapshot_buffer[240 * 160]; u16 snapshot_buffer[240 * 160];
u8 savestate_timestamp_string[80]; char savestate_timestamp_string[80];
file_open(savestate_file, savestate_filename, read); file_open(savestate_file, savestate_filename, read);
if(file_check_valid(savestate_file)) if(file_check_valid(savestate_file))
{ {
u8 weekday_strings[7][11] = const char weekday_strings[7][11] =
{ {
"Sunday", "Monday", "Tuesday", "Wednesday", "Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday" "Thursday", "Friday", "Saturday"
@ -1045,9 +1044,9 @@ void get_savestate_snapshot(u8 *savestate_filename)
#endif #endif
} }
void get_savestate_filename(u32 slot, u8 *name_buffer) void get_savestate_filename(u32 slot, char *name_buffer)
{ {
u8 savestate_ext[16]; char savestate_ext[16];
sprintf(savestate_ext, "%d.svs", slot); sprintf(savestate_ext, "%d.svs", slot);
change_ext(gamepak_filename, name_buffer, savestate_ext); change_ext(gamepak_filename, name_buffer, savestate_ext);
@ -1055,9 +1054,9 @@ void get_savestate_filename(u32 slot, u8 *name_buffer)
get_savestate_snapshot(name_buffer); get_savestate_snapshot(name_buffer);
} }
void get_savestate_filename_noshot(u32 slot, u8 *name_buffer) void get_savestate_filename_noshot(u32 slot, char *name_buffer)
{ {
u8 savestate_ext[16]; char savestate_ext[16];
sprintf(savestate_ext, "%d.svs", slot); sprintf(savestate_ext, "%d.svs", slot);
change_ext(gamepak_filename, name_buffer, savestate_ext); change_ext(gamepak_filename, name_buffer, savestate_ext);
@ -1072,19 +1071,16 @@ void get_savestate_filename_noshot(u32 slot, u8 *name_buffer)
u32 menu(u16 *original_screen) u32 menu(u16 *original_screen)
{ {
u8 print_buffer[81]; char print_buffer[81];
u32 clock_speed_number; u32 clock_speed_number;
u32 _current_option = 0;
gui_action_type gui_action; gui_action_type gui_action;
menu_enum _current_menu = MAIN_MENU;
u32 i; u32 i;
u32 repeat = 1; u32 repeat = 1;
u32 return_value = 0; u32 return_value = 0;
u32 first_load = 0; u32 first_load = 0;
u8 savestate_ext[16]; char current_savestate_filename[512];
u8 current_savestate_filename[512]; char line_buffer[80];
u8 line_buffer[80]; char cheat_format_str[10][41];
u8 cheat_format_str[10][41];
menu_type *current_menu; menu_type *current_menu;
menu_option_type *current_option; menu_option_type *current_option;
@ -1094,7 +1090,8 @@ u32 menu(u16 *original_screen)
auto void choose_menu(); auto void choose_menu();
auto void clear_help(); auto void clear_help();
static const u8 * const gamepad_help[] = #ifndef PC_BUILD
static const char * const gamepad_help[] =
{ {
"Up button on GBA d-pad.", "Up button on GBA d-pad.",
"Down button on GBA d-pad.", "Down button on GBA d-pad.",
@ -1120,6 +1117,33 @@ u32 menu(u16 *original_screen)
"Does nothing." "Does nothing."
}; };
static const char *gamepad_config_buttons[] =
{
"UP",
"DOWN",
"LEFT",
"RIGHT",
"A",
"B",
"L",
"R",
"START",
"SELECT",
"MENU",
"FASTFORWARD",
"LOAD STATE",
"SAVE STATE",
"RAPIDFIRE A",
"RAPIDFIRE B",
"RAPIDFIRE L",
"RAPIDFIRE R",
"VOLUME UP",
"VOLUME DOWN",
"DISPLAY FPS",
"NOTHING"
};
#endif
void menu_update_clock() void menu_update_clock()
{ {
get_clock_speed_number(); get_clock_speed_number();
@ -1146,8 +1170,8 @@ u32 menu(u16 *original_screen)
void menu_load() void menu_load()
{ {
u8 *file_ext[] = { ".gba", ".bin", ".zip", NULL }; const char *file_ext[] = { ".gba", ".bin", ".zip", NULL };
u8 load_filename[512]; char load_filename[512];
save_game_config_file(); save_game_config_file();
if(load_file(file_ext, load_filename) != -1) if(load_file(file_ext, load_filename) != -1)
{ {
@ -1206,8 +1230,8 @@ u32 menu(u16 *original_screen)
void menu_load_state_file() void menu_load_state_file()
{ {
u8 *file_ext[] = { ".svs", NULL }; const char *file_ext[] = { ".svs", NULL };
u8 load_filename[512]; char load_filename[512];
if(load_file(file_ext, load_filename) != -1) if(load_file(file_ext, load_filename) != -1)
{ {
load_state(load_filename); load_state(load_filename);
@ -1268,55 +1292,28 @@ u32 menu(u16 *original_screen)
current_savestate_filename); current_savestate_filename);
} }
u8 *yes_no_options[] = { "no", "yes" }; const char *yes_no_options[] = { "no", "yes" };
u8 *enable_disable_options[] = { "disabled", "enabled" }; const char *enable_disable_options[] = { "disabled", "enabled" };
u8 *frameskip_options[] = { "automatic", "manual", "off" }; const char *frameskip_options[] = { "automatic", "manual", "off" };
u8 *frameskip_variation_options[] = { "uniform", "random" }; const char *frameskip_variation_options[] = { "uniform", "random" };
#ifndef PSP_BUILD #ifndef PSP_BUILD
u8 *audio_buffer_options[] = static const char *audio_buffer_options[] =
{ {
"16 bytes", "32 bytes", "64 bytes", "16 bytes", "32 bytes", "64 bytes",
"128 bytes", "256 bytes", "512 bytes", "1024 bytes", "2048 bytes", "128 bytes", "256 bytes", "512 bytes", "1024 bytes", "2048 bytes",
"4096 bytes", "8192 bytes", "16284 bytes" "4096 bytes", "8192 bytes", "16284 bytes"
}; };
#else #else
u8 *audio_buffer_options[] = const char *audio_buffer_options[] =
{ {
"3072 bytes", "4096 bytes", "5120 bytes", "6144 bytes", "7168 bytes", "3072 bytes", "4096 bytes", "5120 bytes", "6144 bytes", "7168 bytes",
"8192 bytes", "9216 bytes", "10240 bytes", "11264 bytes", "12288 bytes" "8192 bytes", "9216 bytes", "10240 bytes", "11264 bytes", "12288 bytes"
}; };
#endif #endif
u8 *update_backup_options[] = { "Exit only", "Automatic" }; static const char *update_backup_options[] = { "Exit only", "Automatic" };
u8 *gamepad_config_buttons[] =
{
"UP",
"DOWN",
"LEFT",
"RIGHT",
"A",
"B",
"L",
"R",
"START",
"SELECT",
"MENU",
"FASTFORWARD",
"LOAD STATE",
"SAVE STATE",
"RAPIDFIRE A",
"RAPIDFIRE B",
"RAPIDFIRE L",
"RAPIDFIRE R",
"VOLUME UP",
"VOLUME DOWN",
"DISPLAY FPS",
"NOTHING"
};
// Marker for help information, don't go past this mark (except \n)------* // Marker for help information, don't go past this mark (except \n)------*
menu_option_type graphics_sound_options[] = menu_option_type graphics_sound_options[] =
@ -1772,6 +1769,9 @@ u32 menu(u16 *original_screen)
if(current_option->option_type & SUBMENU_OPTION) if(current_option->option_type & SUBMENU_OPTION)
choose_menu(current_option->sub_menu); choose_menu(current_option->sub_menu);
break; break;
default:
break;
} }
} }

8
gui.h
View file

@ -22,7 +22,7 @@
#define GPSP_CONFIG_FILENAME "gpsp.cfg" #define GPSP_CONFIG_FILENAME "gpsp.cfg"
s32 load_file(u8 **wildcards, u8 *result); s32 load_file(const char **wildcards, char *result);
u32 adjust_frameskip(u32 button_id); u32 adjust_frameskip(u32 button_id);
s32 load_game_config_file(); s32 load_game_config_file();
s32 load_config_file(); s32 load_config_file();
@ -32,9 +32,9 @@ u32 menu(u16 *original_screen);
extern u32 savestate_slot; extern u32 savestate_slot;
void get_savestate_filename_noshot(u32 slot, u8 *name_buffer); void get_savestate_filename_noshot(u32 slot, char *name_buffer);
void get_savestate_filename(u32 slot, u8 *name_buffer); void get_savestate_filename(u32 slot, char *name_buffer);
void get_savestate_snapshot(u8 *savestate_filename); void get_savestate_snapshot(char *savestate_filename);
#ifdef WIZ_BUILD #ifdef WIZ_BUILD
#define default_clock_speed 533 #define default_clock_speed 533

12
input.c
View file

@ -24,7 +24,6 @@
void trigger_key(u32 key) void trigger_key(u32 key)
{ {
u32 p1_cnt = io_registers[REG_P1CNT]; u32 p1_cnt = io_registers[REG_P1CNT];
u32 p1;
if((p1_cnt >> 14) & 0x01) if((p1_cnt >> 14) & 0x01)
{ {
@ -474,7 +473,7 @@ u32 update_input()
case BUTTON_ID_LOADSTATE: case BUTTON_ID_LOADSTATE:
{ {
u8 current_savestate_filename[512]; char current_savestate_filename[512];
get_savestate_filename_noshot(savestate_slot, get_savestate_filename_noshot(savestate_slot,
current_savestate_filename); current_savestate_filename);
load_state(current_savestate_filename); load_state(current_savestate_filename);
@ -483,7 +482,7 @@ u32 update_input()
case BUTTON_ID_SAVESTATE: case BUTTON_ID_SAVESTATE:
{ {
u8 current_savestate_filename[512]; char current_savestate_filename[512];
u16 *current_screen = copy_screen(); u16 *current_screen = copy_screen();
get_savestate_filename_noshot(savestate_slot, get_savestate_filename_noshot(savestate_slot,
current_savestate_filename); current_savestate_filename);
@ -670,6 +669,9 @@ gui_action_type get_gui_input()
case SDLK_BACKSPACE: case SDLK_BACKSPACE:
gui_action = CURSOR_BACK; gui_action = CURSOR_BACK;
break; break;
default:
break;
} }
break; break;
} }
@ -742,7 +744,7 @@ u32 update_input()
if(event.key.keysym.sym == SDLK_F5) if(event.key.keysym.sym == SDLK_F5)
{ {
u8 current_savestate_filename[512]; char current_savestate_filename[512];
u16 *current_screen = copy_screen(); u16 *current_screen = copy_screen();
get_savestate_filename_noshot(savestate_slot, get_savestate_filename_noshot(savestate_slot,
current_savestate_filename); current_savestate_filename);
@ -753,7 +755,7 @@ u32 update_input()
if(event.key.keysym.sym == SDLK_F7) if(event.key.keysym.sym == SDLK_F7)
{ {
u8 current_savestate_filename[512]; char current_savestate_filename[512];
get_savestate_filename_noshot(savestate_slot, get_savestate_filename_noshot(savestate_slot,
current_savestate_filename); current_savestate_filename);
load_state(current_savestate_filename); load_state(current_savestate_filename);

27
main.c
View file

@ -82,7 +82,7 @@ u32 clock_speed = 200;
#else #else
u32 clock_speed = 333; u32 clock_speed = 333;
#endif #endif
u8 main_path[512]; char main_path[512];
void trigger_ext_event(); void trigger_ext_event();
@ -131,7 +131,7 @@ void trigger_ext_event();
} \ } \
} \ } \
u8 *file_ext[] = { ".gba", ".bin", ".zip", NULL }; static const char *file_ext[] = { ".gba", ".bin", ".zip", NULL };
#ifdef ARM_ARCH #ifdef ARM_ARCH
void ChangeWorkingDirectory(char *exe) void ChangeWorkingDirectory(char *exe)
@ -178,21 +178,12 @@ void init_main()
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
u32 i;
u32 vcount = 0;
u32 ticks;
u32 dispstat;
u8 load_filename[512];
u8 bios_filename[512];
#ifdef PSP_BUILD #ifdef PSP_BUILD
sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0, sceKernelRegisterSubIntrHandler(PSP_VBLANK_INT, 0,
vblank_interrupt_handler, NULL); vblank_interrupt_handler, NULL);
sceKernelEnableSubIntr(PSP_VBLANK_INT, 0); sceKernelEnableSubIntr(PSP_VBLANK_INT, 0);
#endif #endif
extern char *cpu_mode_names[];
init_gamepak_buffer(); init_gamepak_buffer();
// Copy the directory path of the executable into main_path // Copy the directory path of the executable into main_path
@ -218,6 +209,7 @@ int main(int argc, char *argv[])
init_video(); init_video();
#ifdef GP2X_BUILD #ifdef GP2X_BUILD
char bios_filename[512];
sprintf(bios_filename, "%s/%s", main_path, "gba_bios.bin"); sprintf(bios_filename, "%s/%s", main_path, "gba_bios.bin");
if(load_bios(bios_filename) == -1) if(load_bios(bios_filename) == -1)
#else #else
@ -292,7 +284,7 @@ int main(int argc, char *argv[])
if(load_gamepak(argv[1]) == -1) if(load_gamepak(argv[1]) == -1)
{ {
#ifndef PSP_BUILD #ifndef PSP_BUILD
printf("Failed to load gamepak %s, exiting.\n", load_filename); printf("Failed to load gamepak %s, exiting.\n", argv[1]);
#endif #endif
exit(-1); exit(-1);
} }
@ -305,6 +297,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
char load_filename[512];
if(load_file(file_ext, load_filename) == -1) if(load_file(file_ext, load_filename) == -1)
{ {
menu(copy_screen()); menu(copy_screen());
@ -392,7 +385,7 @@ void trigger_ext_event()
static u32 event_number = 0; static u32 event_number = 0;
static u64 benchmark_ticks[16]; static u64 benchmark_ticks[16];
u64 new_ticks; u64 new_ticks;
u8 current_savestate_filename[512]; char current_savestate_filename[512];
return; return;
@ -874,7 +867,7 @@ void reset_gba()
#ifdef PSP_BUILD #ifdef PSP_BUILD
u32 file_length(u8 *filename, s32 dummy) u32 file_length(char *filename, s32 dummy)
{ {
SceIoStat stats; SceIoStat stats;
sceIoGetstat(filename, &stats); sceIoGetstat(filename, &stats);
@ -896,7 +889,7 @@ void get_ticks_us(u64 *tick_return)
#else #else
u32 file_length(u8 *dummy, FILE *fp) u32 file_length(char *dummy, FILE *fp)
{ {
u32 length; u32 length;
@ -940,9 +933,9 @@ void get_ticks_us(u64 *ticks_return)
#endif #endif
void change_ext(u8 *src, u8 *buffer, u8 *extension) void change_ext(const char *src, char *buffer, const char *extension)
{ {
u8 *dot_position; char *dot_position;
strcpy(buffer, src); strcpy(buffer, src);
dot_position = strrchr(buffer, '.'); dot_position = strrchr(buffer, '.');

20
main.h
View file

@ -71,9 +71,6 @@ extern u32 global_cycles_per_instruction;
extern u32 synchronize_flag; extern u32 synchronize_flag;
extern u32 skip_next_frame; extern u32 skip_next_frame;
extern timer_type timer[4];
static u32 prescale_table[] = { 0, 6, 8, 10 };
extern u32 cycle_memory_access; extern u32 cycle_memory_access;
extern u32 cycle_pc_relative_access; extern u32 cycle_pc_relative_access;
extern u32 cycle_sp_relative_access; extern u32 cycle_sp_relative_access;
@ -86,7 +83,7 @@ extern u32 flush_ram_count;
extern u64 base_timestamp; extern u64 base_timestamp;
extern u8 main_path[512]; extern char main_path[512];
extern u32 update_backup_flag; extern u32 update_backup_flag;
extern u32 clock_speed; extern u32 clock_speed;
@ -97,18 +94,18 @@ void synchronize();
void quit(); void quit();
void delay_us(u32 us_count); void delay_us(u32 us_count);
void get_ticks_us(u64 *tick_return); void get_ticks_us(u64 *tick_return);
void game_name_ext(u8 *src, u8 *buffer, u8 *extension); void game_name_ext(char *src, char *buffer, char *extension);
void main_write_mem_savestate(file_tag_type savestate_file); void main_write_mem_savestate(file_tag_type savestate_file);
void main_read_savestate(file_tag_type savestate_file); void main_read_savestate(file_tag_type savestate_file);
#ifdef PSP_BUILD #ifdef PSP_BUILD
u32 file_length(u8 *filename, s32 dummy); u32 file_length(char *filename, s32 dummy);
#else #else
u32 file_length(u8 *dummy, FILE *fp); u32 file_length(char *dummy, FILE *fp);
#endif #endif
@ -117,6 +114,11 @@ extern u32 virtual_frame_count;
extern u32 max_frameskip; extern u32 max_frameskip;
extern u32 num_skipped_frames; extern u32 num_skipped_frames;
#ifdef IN_MEMORY_C
extern timer_type timer[4];
static u32 prescale_table[] = { 0, 6, 8, 10 };
#define count_timer(timer_number) \ #define count_timer(timer_number) \
timer[timer_number].reload = 0x10000 - value; \ timer[timer_number].reload = 0x10000 - value; \
if(timer_number < 2) \ if(timer_number < 2) \
@ -181,7 +183,9 @@ extern u32 num_skipped_frames;
} \ } \
address16(io_registers, 0x102 + (timer_number * 4)) = value; \ address16(io_registers, 0x102 + (timer_number * 4)) = value; \
void change_ext(u8 *src, u8 *buffer, u8 *extension); #endif // IN_MEMORY_C
void change_ext(const char *src, char *buffer, const char *extension);
void set_clock_speed(); void set_clock_speed();

View file

@ -17,6 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#define IN_MEMORY_C
#include "common.h" #include "common.h"
// This table is configured for sequential access on system defaults // This table is configured for sequential access on system defaults
@ -170,7 +171,7 @@ flash_size_type flash_size = FLASH_SIZE_64KB;
u8 read_backup(u32 address) u8 read_backup(u32 address)
{ {
u8 value; u8 value = 0;
if(backup_type == BACKUP_NONE) if(backup_type == BACKUP_NONE)
backup_type = BACKUP_SRAM; backup_type = BACKUP_SRAM;
@ -328,6 +329,9 @@ void function_cc write_eeprom(u32 address, u32 value)
eeprom_mode = EEPROM_BASE_MODE; eeprom_mode = EEPROM_BASE_MODE;
} }
break; break;
default:
break;
} }
} }
@ -1636,6 +1640,9 @@ void function_cc write_rtc(u32 address, u32 value)
case RTC_WRITE_STATUS: case RTC_WRITE_STATUS:
rtc_status = rtc_data[0]; rtc_status = rtc_data[0];
break; break;
default:
break;
} }
} }
} }
@ -1671,6 +1678,9 @@ void function_cc write_rtc(u32 address, u32 value)
} }
} }
break; break;
default:
break;
} }
} }
} }
@ -1897,7 +1907,7 @@ u32 save_backup(char *name)
if(file_check_valid(backup_file)) if(file_check_valid(backup_file))
{ {
u32 backup_size; u32 backup_size = 0;
switch(backup_type) switch(backup_type)
{ {
@ -1921,6 +1931,9 @@ u32 save_backup(char *name)
else else
backup_size = 0x2000; backup_size = 0x2000;
break; break;
default:
break;
} }
file_write(backup_file, gamepak_backup, backup_size); file_write(backup_file, gamepak_backup, backup_size);
@ -1952,7 +1965,7 @@ void update_backup_force()
#define CONFIG_FILENAME "game_config.txt" #define CONFIG_FILENAME "game_config.txt"
u8 *skip_spaces(u8 *line_ptr) char *skip_spaces(char *line_ptr)
{ {
while(*line_ptr == ' ') while(*line_ptr == ' ')
line_ptr++; line_ptr++;
@ -1960,10 +1973,10 @@ u8 *skip_spaces(u8 *line_ptr)
return line_ptr; return line_ptr;
} }
s32 parse_config_line(u8 *current_line, u8 *current_variable, u8 *current_value) s32 parse_config_line(char *current_line, char *current_variable, char *current_value)
{ {
u8 *line_ptr = current_line; char *line_ptr = current_line;
u8 *line_ptr_new; char *line_ptr_new;
if((current_line[0] == 0) || (current_line[0] == '#')) if((current_line[0] == 0) || (current_line[0] == '#'))
return -1; return -1;
@ -1994,14 +2007,12 @@ s32 parse_config_line(u8 *current_line, u8 *current_variable, u8 *current_value)
return 0; return 0;
} }
s32 load_game_config(u8 *gamepak_title, u8 *gamepak_code, u8 *gamepak_maker) s32 load_game_config(char *gamepak_title, char *gamepak_code, char *gamepak_maker)
{ {
u8 current_line[256]; char current_line[256];
u8 current_variable[256]; char current_variable[256];
u8 current_value[256]; char current_value[256];
u8 config_path[512]; char config_path[512];
u8 *line_ptr;
u32 fgets_value;
FILE *config_file; FILE *config_file;
idle_loop_target_pc = 0xFFFFFFFF; idle_loop_target_pc = 0xFFFFFFFF;
@ -2069,7 +2080,7 @@ s32 load_game_config(u8 *gamepak_title, u8 *gamepak_code, u8 *gamepak_maker)
} }
if(!strcmp(current_variable, "iwram_stack_optimize") && if(!strcmp(current_variable, "iwram_stack_optimize") &&
!strcmp(current_value, "no")) !strcmp(current_value, "no\0")) /* \0 for broken toolchain workaround */
{ {
iwram_stack_optimize = 0; iwram_stack_optimize = 0;
} }
@ -2145,16 +2156,16 @@ s32 load_gamepak_raw(char *name)
return -1; return -1;
} }
u8 gamepak_title[13]; char gamepak_title[13];
u8 gamepak_code[5]; char gamepak_code[5];
u8 gamepak_maker[3]; char gamepak_maker[3];
u8 gamepak_filename[512]; char gamepak_filename[512];
u32 load_gamepak(char *name) u32 load_gamepak(char *name)
{ {
char *dot_position = strrchr(name, '.'); char *dot_position = strrchr(name, '.');
s32 file_size; s32 file_size;
u8 cheats_filename[256]; char cheats_filename[256];
#ifdef WIZ_BUILD #ifdef WIZ_BUILD
file_size = wiz_load_gamepak(name); file_size = wiz_load_gamepak(name);
@ -2994,7 +3005,6 @@ void init_gamepak_buffer()
void init_memory() void init_memory()
{ {
u32 i;
u32 map_offset = 0; u32 map_offset = 0;
memory_regions[0x00] = (u8 *)bios_rom; memory_regions[0x00] = (u8 *)bios_rom;
@ -3133,7 +3143,6 @@ void load_state(char *savestate_filename)
if(file_check_valid(savestate_file)) if(file_check_valid(savestate_file))
{ {
char current_gamepak_filename[512]; char current_gamepak_filename[512];
char savestate_gamepak_filename[512];
u32 i; u32 i;
u32 current_color; u32 current_color;

View file

@ -168,10 +168,10 @@ extern u32 memory_limits[16];
extern u32 waitstate_cycles_sequential[16][3]; extern u32 waitstate_cycles_sequential[16][3];
extern u32 gamepak_size; extern u32 gamepak_size;
extern u8 gamepak_title[13]; extern char gamepak_title[13];
extern u8 gamepak_code[5]; extern char gamepak_code[5];
extern u8 gamepak_maker[3]; extern char gamepak_maker[3];
extern u8 gamepak_filename[512]; extern char gamepak_filename[512];
cpu_alert_type dma_transfer(dma_transfer_type *dma); cpu_alert_type dma_transfer(dma_transfer_type *dma);
u8 *memory_region(u32 address, u32 *memory_limit); u8 *memory_region(u32 address, u32 *memory_limit);

View file

@ -14,10 +14,9 @@ BIN = gpsp
# Platform specific definitions # Platform specific definitions
VPATH += .. ../arm VPATH += .. ../arm
CFLAGS += -DARM_ARCH -DPND_BUILD CFLAGS += -DARM_ARCH -DPND_BUILD -Wall
CFLAGS += -funsigned-char
CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfloat-abi=softfp -ffast-math CFLAGS += -mcpu=cortex-a8 -mtune=cortex-a8 -mfloat-abi=softfp -ffast-math
CFLAGS += -fno-common -fno-builtin CFLAGS += -fno-common
CFLAGS += -ggdb CFLAGS += -ggdb
CFLAGS += -O2 CFLAGS += -O2
@ -28,10 +27,12 @@ LIBS += -ldl -lpthread -lz
# Compilation: # Compilation:
all: $(BIN)
%.o: %.S %.o: %.S
$(CC) $(CFLAGS) -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
all: $(BIN) cpu.o cpu_threaded.o: CFLAGS += -Wno-unused-variable -Wno-unused-label
$(BIN): $(OBJS) $(BIN): $(OBJS)
$(CC) $(OBJS) $(LIBS) -o $(BIN) $(CC) $(OBJS) $(LIBS) -o $(BIN)

19
sound.c
View file

@ -27,9 +27,8 @@ gbc_sound_struct gbc_sound_channel[4];
u32 sound_frequency = 44100; u32 sound_frequency = 44100;
SDL_AudioSpec sound_settings;
SDL_mutex *sound_mutex; SDL_mutex *sound_mutex;
SDL_cond *sound_cv; static SDL_cond *sound_cv;
#ifdef PSP_BUILD #ifdef PSP_BUILD
u32 audio_buffer_size_number = 1; u32 audio_buffer_size_number = 1;
@ -37,15 +36,15 @@ u32 audio_buffer_size_number = 1;
u32 audio_buffer_size_number = 8; u32 audio_buffer_size_number = 8;
#endif #endif
u32 audio_buffer_size; u32 sound_on;
u32 sound_on = 0; static u32 audio_buffer_size;
s16 sound_buffer[BUFFER_SIZE]; static s16 sound_buffer[BUFFER_SIZE];
u32 sound_buffer_base = 0; static u32 sound_buffer_base;
u32 sound_last_cpu_ticks = 0; static u32 sound_last_cpu_ticks;
fixed16_16 gbc_sound_tick_step; static fixed16_16 gbc_sound_tick_step;
u32 sound_exit_flag; static u32 sound_exit_flag;
// Queue 1, 2, or 4 samples to the top of the DS FIFO, wrap around circularly // Queue 1, 2, or 4 samples to the top of the DS FIFO, wrap around circularly
@ -751,6 +750,8 @@ void sound_exit()
void init_sound() void init_sound()
{ {
SDL_AudioSpec sound_settings;
#ifdef PSP_BUILD #ifdef PSP_BUILD
audio_buffer_size = (audio_buffer_size_number * 1024) + 3072; audio_buffer_size = (audio_buffer_size_number * 1024) + 3072;
#else #else

View file

@ -118,7 +118,6 @@ extern u32 enable_low_pass_filter;
extern u32 audio_buffer_size_number; extern u32 audio_buffer_size_number;
extern SDL_mutex *sound_mutex; extern SDL_mutex *sound_mutex;
extern SDL_cond *sound_cv;
void sound_timer_queue8(u32 channel, u8 value); void sound_timer_queue8(u32 channel, u8 value);
void sound_timer_queue16(u32 channel, u16 value); void sound_timer_queue16(u32 channel, u16 value);
@ -130,6 +129,8 @@ void init_sound();
void sound_write_mem_savestate(file_tag_type savestate_file); void sound_write_mem_savestate(file_tag_type savestate_file);
void sound_read_savestate(file_tag_type savestate_file); void sound_read_savestate(file_tag_type savestate_file);
#ifdef IN_MEMORY_C
#define gbc_sound_tone_control_low(channel, address) \ #define gbc_sound_tone_control_low(channel, address) \
{ \ { \
u32 initial_volume = (value >> 12) & 0x0F; \ u32 initial_volume = (value >> 12) & 0x0F; \
@ -321,6 +322,7 @@ static u32 gbc_sound_wave_volume[4] = { 0, 16384, 8192, 4096 };
timer[timer_number].frequency_step = \ timer[timer_number].frequency_step = \
float_to_fp16_16(16777216.0 / (timer_reload * sound_frequency)) \ float_to_fp16_16(16777216.0 / (timer_reload * sound_frequency)) \
#endif // IN_MEMORY_C
void reset_sound(); void reset_sound();
void sound_exit(); void sound_exit();

117
video.c
View file

@ -18,6 +18,7 @@
*/ */
#include "common.h" #include "common.h"
#define WANT_FONT_BITS
#include "font.h" #include "font.h"
#ifdef PSP_BUILD #ifdef PSP_BUILD
@ -129,11 +130,11 @@ const u32 video_scale = 1;
#endif #endif
void render_scanline_conditional_tile(u32 start, u32 end, u16 *scanline, static void render_scanline_conditional_tile(u32 start, u32 end, u16 *scanline,
u32 enable_flags, u32 dispcnt, u32 bldcnt, tile_layer_render_struct u32 enable_flags, u32 dispcnt, u32 bldcnt, const tile_layer_render_struct
*layer_renderers); *layer_renderers);
void render_scanline_conditional_bitmap(u32 start, u32 end, u16 *scanline, static void render_scanline_conditional_bitmap(u32 start, u32 end, u16 *scanline,
u32 enable_flags, u32 dispcnt, u32 bldcnt, bitmap_layer_render_struct u32 enable_flags, u32 dispcnt, u32 bldcnt, const bitmap_layer_render_struct
*layer_renderers); *layer_renderers);
#define no_op \ #define no_op \
@ -1011,23 +1012,18 @@ void render_scanline_conditional_bitmap(u32 start, u32 end, u16 *scanline,
static const u32 map_widths[] = { 256, 512, 256, 512 };
// Map widths and heights
u32 map_widths[] = { 256, 512, 256, 512 };
u32 map_heights[] = { 256, 256, 512, 512 };
// Build text scanline rendering functions. // Build text scanline rendering functions.
#define render_scanline_text_builder(combine_op, alpha_op) \ #define render_scanline_text_builder(combine_op, alpha_op) \
void render_scanline_text_##combine_op##_##alpha_op(u32 layer, \ static void render_scanline_text_##combine_op##_##alpha_op(u32 layer, \
u32 start, u32 end, void *scanline) \ u32 start, u32 end, void *scanline) \
{ \ { \
render_scanline_extra_variables_##combine_op##_##alpha_op(text); \ render_scanline_extra_variables_##combine_op##_##alpha_op(text); \
u32 bg_control = io_registers[REG_BG0CNT + layer]; \ u32 bg_control = io_registers[REG_BG0CNT + layer]; \
u32 map_size = (bg_control >> 14) & 0x03; \ u32 map_size = (bg_control >> 14) & 0x03; \
u32 map_width = map_widths[map_size]; \ u32 map_width = map_widths[map_size]; \
u32 map_height = map_heights[map_size]; \
u32 horizontal_offset = \ u32 horizontal_offset = \
(io_registers[REG_BG0HOFS + (layer * 2)] + start) % 512; \ (io_registers[REG_BG0HOFS + (layer * 2)] + start) % 512; \
u32 vertical_offset = (io_registers[REG_VCOUNT] + \ u32 vertical_offset = (io_registers[REG_VCOUNT] + \
@ -1278,7 +1274,6 @@ void render_scanline_affine_##combine_op##_##alpha_op(u32 layer, \
u32 bg_control = io_registers[REG_BG0CNT + layer]; \ u32 bg_control = io_registers[REG_BG0CNT + layer]; \
u32 current_pixel; \ u32 current_pixel; \
s32 source_x, source_y; \ s32 source_x, source_y; \
u32 vcount = io_registers[REG_VCOUNT]; \
u32 pixel_x, pixel_y; \ u32 pixel_x, pixel_y; \
u32 layer_offset = (layer - 2) * 8; \ u32 layer_offset = (layer - 2) * 8; \
s32 dx, dy; \ s32 dx, dy; \
@ -1287,7 +1282,7 @@ void render_scanline_affine_##combine_op##_##alpha_op(u32 layer, \
u32 map_pitch = map_size + 4; \ u32 map_pitch = map_size + 4; \
u8 *map_base = vram + (((bg_control >> 8) & 0x1F) * (1024 * 2)); \ u8 *map_base = vram + (((bg_control >> 8) & 0x1F) * (1024 * 2)); \
u8 *tile_base = vram + (((bg_control >> 2) & 0x03) * (1024 * 16)); \ u8 *tile_base = vram + (((bg_control >> 2) & 0x03) * (1024 * 16)); \
u8 *tile_ptr; \ u8 *tile_ptr = NULL; \
u32 map_offset, last_map_offset = (u32)-1; \ u32 map_offset, last_map_offset = (u32)-1; \
u32 i; \ u32 i; \
render_scanline_dest_##alpha_op *dest_ptr = \ render_scanline_dest_##alpha_op *dest_ptr = \
@ -1475,13 +1470,11 @@ render_scanline_affine_builder(transparent, alpha);
// Build bitmap scanline rendering functions. // Build bitmap scanline rendering functions.
#define render_scanline_bitmap_builder(type, alpha_op, width, height) \ #define render_scanline_bitmap_builder(type, alpha_op, width, height) \
void render_scanline_bitmap_##type##_##alpha_op(u32 start, u32 end, \ static void render_scanline_bitmap_##type##_##alpha_op(u32 start, u32 end, \
void *scanline) \ void *scanline) \
{ \ { \
u32 bg_control = io_registers[REG_BG2CNT]; \
u32 current_pixel; \ u32 current_pixel; \
s32 source_x, source_y; \ s32 source_x, source_y; \
u32 vcount = io_registers[REG_VCOUNT]; \
s32 pixel_x, pixel_y; \ s32 pixel_x, pixel_y; \
\ \
s32 dx = (s16)io_registers[REG_BG2PA]; \ s32 dx = (s16)io_registers[REG_BG2PA]; \
@ -1542,7 +1535,7 @@ render_scanline_bitmap_builder(mode5, normal, 160, 128);
// Structs containing functions to render the layers for each mode, for // Structs containing functions to render the layers for each mode, for
// each render type. // each render type.
tile_layer_render_struct tile_mode_renderers[3][4] = static const tile_layer_render_struct tile_mode_renderers[3][4] =
{ {
{ {
tile_layer_render_functions(text), tile_layer_render_functions(text), tile_layer_render_functions(text), tile_layer_render_functions(text),
@ -1558,7 +1551,7 @@ tile_layer_render_struct tile_mode_renderers[3][4] =
} }
}; };
bitmap_layer_render_struct bitmap_mode_renderers[3] = static const bitmap_layer_render_struct bitmap_mode_renderers[3] =
{ {
bitmap_layer_render_functions(mode3), bitmap_layer_render_functions(mode3),
bitmap_layer_render_functions(mode4), bitmap_layer_render_functions(mode4),
@ -1567,11 +1560,11 @@ bitmap_layer_render_struct bitmap_mode_renderers[3] =
#define render_scanline_layer_functions_tile() \ #define render_scanline_layer_functions_tile() \
tile_layer_render_struct *layer_renderers = \ const tile_layer_render_struct *layer_renderers = \
tile_mode_renderers[dispcnt & 0x07] \ tile_mode_renderers[dispcnt & 0x07] \
#define render_scanline_layer_functions_bitmap() \ #define render_scanline_layer_functions_bitmap() \
bitmap_layer_render_struct *layer_renderers = \ const bitmap_layer_render_struct *layer_renderers = \
bitmap_mode_renderers + ((dispcnt & 0x07) - 3) \ bitmap_mode_renderers + ((dispcnt & 0x07) - 3) \
@ -1583,8 +1576,8 @@ bitmap_layer_render_struct bitmap_mode_renderers[3] =
+ (tile_size_##color_depth * ((obj_width - 8) / 8)) \ + (tile_size_##color_depth * ((obj_width - 8) / 8)) \
// Adjust the obj's starting point if it goes too far off the left edge of \ // Adjust the obj's starting point if it goes too far off the left edge of
// the screen. \ // the screen.
#define obj_tile_right_offset_noflip(color_depth) \ #define obj_tile_right_offset_noflip(color_depth) \
tile_ptr += (partial_tile_offset / 8) * tile_size_##color_depth \ tile_ptr += (partial_tile_offset / 8) * tile_size_##color_depth \
@ -1844,14 +1837,13 @@ bitmap_layer_render_struct bitmap_mode_renderers[3] =
#define obj_render_affine(combine_op, color_depth, alpha_op, map_space) \ #define obj_render_affine(combine_op, color_depth, alpha_op, map_space) \
{ \ { \
s16 *params = oam_ram + (((obj_attribute_1 >> 9) & 0x1F) * 16); \ s16 *params = (s16 *)oam_ram + (((obj_attribute_1 >> 9) & 0x1F) * 16); \
s32 dx = params[3]; \ s32 dx = params[3]; \
s32 dmx = params[7]; \ s32 dmx = params[7]; \
s32 dy = params[11]; \ s32 dy = params[11]; \
s32 dmy = params[15]; \ s32 dmy = params[15]; \
s32 source_x, source_y; \ s32 source_x, source_y; \
s32 tile_x, tile_y; \ s32 tile_x, tile_y; \
u32 tile_offset; \
u32 tile_map_offset; \ u32 tile_map_offset; \
s32 middle_x; \ s32 middle_x; \
s32 middle_y; \ s32 middle_y; \
@ -1910,12 +1902,14 @@ bitmap_layer_render_struct bitmap_mode_renderers[3] =
} \ } \
} \ } \
u32 obj_width_table[] = { 8, 16, 32, 64, 16, 32, 32, 64, 8, 8, 16, 32 }; static const u32 obj_width_table[] =
u32 obj_height_table[] = { 8, 16, 32, 64, 8, 8, 16, 32, 16, 32, 32, 64 }; { 8, 16, 32, 64, 16, 32, 32, 64, 8, 8, 16, 32 };
static const u32 obj_height_table[] =
{ 8, 16, 32, 64, 8, 8, 16, 32, 16, 32, 32, 64 };
u8 obj_priority_list[5][160][128]; static u8 obj_priority_list[5][160][128];
u32 obj_priority_count[5][160]; static u32 obj_priority_count[5][160];
u32 obj_alpha_count[160]; static u32 obj_alpha_count[160];
// Build obj rendering functions // Build obj rendering functions
@ -1934,11 +1928,11 @@ u32 obj_alpha_count[160];
#define render_scanline_obj_extra_variables_color() \ #define render_scanline_obj_extra_variables_color() \
u32 dest; \
u32 pixel_combine = color_combine_mask(4) | (1 << 8) \ u32 pixel_combine = color_combine_mask(4) | (1 << 8) \
#define render_scanline_obj_extra_variables_alpha_obj(map_space) \ #define render_scanline_obj_extra_variables_alpha_obj(map_space) \
render_scanline_obj_extra_variables_color(); \ render_scanline_obj_extra_variables_color(); \
u32 dest; \
if((pixel_combine & 0x00000200) == 0) \ if((pixel_combine & 0x00000200) == 0) \
{ \ { \
render_scanline_obj_color32_##map_space(priority, start, end, scanline); \ render_scanline_obj_color32_##map_space(priority, start, end, scanline); \
@ -1953,7 +1947,8 @@ u32 obj_alpha_count[160];
#define render_scanline_obj_extra_variables_partial_alpha(map_space) \ #define render_scanline_obj_extra_variables_partial_alpha(map_space) \
render_scanline_obj_extra_variables_color(); \ render_scanline_obj_extra_variables_color(); \
u32 base_pixel_combine = pixel_combine \ u32 base_pixel_combine = pixel_combine; \
u32 dest \
#define render_scanline_obj_extra_variables_copy(type) \ #define render_scanline_obj_extra_variables_copy(type) \
u32 bldcnt = io_registers[REG_BLDCNT]; \ u32 bldcnt = io_registers[REG_BLDCNT]; \
@ -2063,7 +2058,7 @@ u32 obj_alpha_count[160];
#define render_scanline_obj_builder(combine_op, alpha_op, map_space, \ #define render_scanline_obj_builder(combine_op, alpha_op, map_space, \
partial_alpha_op) \ partial_alpha_op) \
void render_scanline_obj_##alpha_op##_##map_space(u32 priority, \ static void render_scanline_obj_##alpha_op##_##map_space(u32 priority, \
u32 start, u32 end, render_scanline_dest_##alpha_op *scanline) \ u32 start, u32 end, render_scanline_dest_##alpha_op *scanline) \
{ \ { \
render_scanline_obj_extra_variables_##alpha_op(map_space); \ render_scanline_obj_extra_variables_##alpha_op(map_space); \
@ -2127,7 +2122,7 @@ render_scanline_obj_builder(copy, copy_bitmap, 2D, no_partial_alpha);
void order_obj(u32 video_mode) static void order_obj(u32 video_mode)
{ {
s32 obj_num, priority, row; s32 obj_num, priority, row;
s32 obj_x, obj_y; s32 obj_x, obj_y;
@ -2135,14 +2130,8 @@ void order_obj(u32 video_mode)
s32 obj_width, obj_height; s32 obj_width, obj_height;
u32 obj_priority; u32 obj_priority;
u32 obj_attribute_0, obj_attribute_1, obj_attribute_2; u32 obj_attribute_0, obj_attribute_1, obj_attribute_2;
s32 vcount = io_registers[REG_VCOUNT];
u32 partial_tile_run, partial_tile_offset;
u32 pixel_run;
u32 current_count; u32 current_count;
u16 *oam_ptr = oam_ram + 508; u16 *oam_ptr = oam_ram + 508;
u16 *dest_ptr;
u8 *tile_base = vram + 0x10000;
u8 *tile_ptr;
for(priority = 0; priority < 5; priority++) for(priority = 0; priority < 5; priority++)
{ {
@ -2234,7 +2223,7 @@ void order_obj(u32 video_mode)
u32 layer_order[16]; u32 layer_order[16];
u32 layer_count; u32 layer_count;
u32 order_layers(u32 layer_flags) static void order_layers(u32 layer_flags)
{ {
s32 priority, layer_number; s32 priority, layer_number;
layer_count = 0; layer_count = 0;
@ -2279,7 +2268,7 @@ u32 order_layers(u32 layer_flags)
#define fill_line_color_color32() \ #define fill_line_color_color32() \
#define fill_line_builder(type) \ #define fill_line_builder(type) \
void fill_line_##type(u16 color, render_scanline_dest_##type *dest_ptr, \ static void fill_line_##type(u16 color, render_scanline_dest_##type *dest_ptr,\
u32 start, u32 end) \ u32 start, u32 end) \
{ \ { \
fill_line_color_##type(); \ fill_line_color_##type(); \
@ -2479,7 +2468,7 @@ void expand_blend(u32 *screen_src_ptr, u16 *screen_dest_ptr,
// Blend scanline with white. // Blend scanline with white.
void expand_darken(u16 *screen_src_ptr, u16 *screen_dest_ptr, static void expand_darken(u16 *screen_src_ptr, u16 *screen_dest_ptr,
u32 start, u32 end) u32 start, u32 end)
{ {
u32 pixel_top; u32 pixel_top;
@ -2495,7 +2484,7 @@ void expand_darken(u16 *screen_src_ptr, u16 *screen_dest_ptr,
// Blend scanline with black. // Blend scanline with black.
void expand_brighten(u16 *screen_src_ptr, u16 *screen_dest_ptr, static void expand_brighten(u16 *screen_src_ptr, u16 *screen_dest_ptr,
u32 start, u32 end) u32 start, u32 end)
{ {
u32 pixel_top; u32 pixel_top;
@ -2517,7 +2506,7 @@ void expand_brighten(u16 *screen_src_ptr, u16 *screen_dest_ptr,
// Expand scanline such that if both top and bottom pass it's alpha, // Expand scanline such that if both top and bottom pass it's alpha,
// if only top passes it's as specified, and if neither pass it's normal. // if only top passes it's as specified, and if neither pass it's normal.
void expand_darken_partial_alpha(u32 *screen_src_ptr, u16 *screen_dest_ptr, static void expand_darken_partial_alpha(u32 *screen_src_ptr, u16 *screen_dest_ptr,
u32 start, u32 end) u32 start, u32 end)
{ {
s32 blend = 16 - (io_registers[REG_BLDY] & 0x1F); s32 blend = 16 - (io_registers[REG_BLDY] & 0x1F);
@ -2541,7 +2530,7 @@ void expand_darken_partial_alpha(u32 *screen_src_ptr, u16 *screen_dest_ptr,
} }
void expand_brighten_partial_alpha(u32 *screen_src_ptr, u16 *screen_dest_ptr, static void expand_brighten_partial_alpha(u32 *screen_src_ptr, u16 *screen_dest_ptr,
u32 start, u32 end) u32 start, u32 end)
{ {
s32 blend = io_registers[REG_BLDY] & 0x1F; s32 blend = io_registers[REG_BLDY] & 0x1F;
@ -2776,7 +2765,7 @@ void expand_brighten_partial_alpha(u32 *screen_src_ptr, u16 *screen_dest_ptr,
// Renders an entire scanline from 0 to 240, based on current color mode. // Renders an entire scanline from 0 to 240, based on current color mode.
void render_scanline_tile(u16 *scanline, u32 dispcnt) static void render_scanline_tile(u16 *scanline, u32 dispcnt)
{ {
u32 current_layer; u32 current_layer;
u32 layer_order_pos; u32 layer_order_pos;
@ -2787,9 +2776,8 @@ void render_scanline_tile(u16 *scanline, u32 dispcnt)
render_condition_alpha, render_condition_fade, 0, 240); render_condition_alpha, render_condition_fade, 0, 240);
} }
void render_scanline_bitmap(u16 *scanline, u32 dispcnt) static void render_scanline_bitmap(u16 *scanline, u32 dispcnt)
{ {
u32 bldcnt = io_registers[REG_BLDCNT];
render_scanline_layer_functions_bitmap(); render_scanline_layer_functions_bitmap();
u32 current_layer; u32 current_layer;
u32 layer_order_pos; u32 layer_order_pos;
@ -2908,8 +2896,8 @@ void render_scanline_bitmap(u16 *scanline, u32 dispcnt)
// Render all of the BG and OBJ in a tiled scanline from start to end ONLY if // Render all of the BG and OBJ in a tiled scanline from start to end ONLY if
// enable_flag allows that layer/OBJ. Also conditionally render color effects. // enable_flag allows that layer/OBJ. Also conditionally render color effects.
void render_scanline_conditional_tile(u32 start, u32 end, u16 *scanline, static void render_scanline_conditional_tile(u32 start, u32 end, u16 *scanline,
u32 enable_flags, u32 dispcnt, u32 bldcnt, tile_layer_render_struct u32 enable_flags, u32 dispcnt, u32 bldcnt, const tile_layer_render_struct
*layer_renderers) *layer_renderers)
{ {
u32 current_layer; u32 current_layer;
@ -2925,8 +2913,8 @@ void render_scanline_conditional_tile(u32 start, u32 end, u16 *scanline,
// Render the BG and OBJ in a bitmap scanline from start to end ONLY if // Render the BG and OBJ in a bitmap scanline from start to end ONLY if
// enable_flag allows that layer/OBJ. Also conditionally render color effects. // enable_flag allows that layer/OBJ. Also conditionally render color effects.
void render_scanline_conditional_bitmap(u32 start, u32 end, u16 *scanline, static void render_scanline_conditional_bitmap(u32 start, u32 end, u16 *scanline,
u32 enable_flags, u32 dispcnt, u32 bldcnt, bitmap_layer_render_struct u32 enable_flags, u32 dispcnt, u32 bldcnt, const bitmap_layer_render_struct
*layer_renderers) *layer_renderers)
{ {
u32 current_layer; u32 current_layer;
@ -2970,7 +2958,7 @@ void render_scanline_conditional_bitmap(u32 start, u32 end, u16 *scanline,
#define window_coords(window_number) \ #define window_coords(window_number) \
u32 window_##window_number##_x1, window_##window_number##_x2; \ u32 window_##window_number##_x1, window_##window_number##_x2; \
u32 window_##window_number##_y1, window_##window_number##_y2; \ u32 window_##window_number##_y1, window_##window_number##_y2; \
u32 window_##window_number##_enable; \ u32 window_##window_number##_enable = 0; \
window_##window_number##_y1 = \ window_##window_number##_y1 = \
io_registers[REG_WIN##window_number##V] >> 8; \ io_registers[REG_WIN##window_number##V] >> 8; \
window_##window_number##_y2 = \ window_##window_number##_y2 = \
@ -3181,7 +3169,7 @@ void render_scanline_conditional_bitmap(u32 start, u32 end, u16 *scanline,
} \ } \
#define render_scanline_window_builder(type) \ #define render_scanline_window_builder(type) \
void render_scanline_window_##type(u16 *scanline, u32 dispcnt) \ static void render_scanline_window_##type(u16 *scanline, u32 dispcnt) \
{ \ { \
u32 vcount = io_registers[REG_VCOUNT]; \ u32 vcount = io_registers[REG_VCOUNT]; \
u32 winout = io_registers[REG_WINOUT]; \ u32 winout = io_registers[REG_WINOUT]; \
@ -3219,7 +3207,6 @@ void render_scanline_window_##type(u16 *scanline, u32 dispcnt) \
/* Just OBJ windows */ \ /* Just OBJ windows */ \
case 0x04: \ case 0x04: \
{ \ { \
u32 window_obj_enable = winout >> 8; \
render_window_clip_obj(type, 0, 240); \ render_window_clip_obj(type, 0, 240); \
break; \ break; \
} \ } \
@ -3227,7 +3214,6 @@ void render_scanline_window_##type(u16 *scanline, u32 dispcnt) \
/* Window 0 and OBJ window */ \ /* Window 0 and OBJ window */ \
case 0x05: \ case 0x05: \
{ \ { \
u32 window_obj_enable = winout >> 8; \
u32 winin = io_registers[REG_WININ]; \ u32 winin = io_registers[REG_WININ]; \
window_coords(0); \ window_coords(0); \
render_window_multi(type, 0, obj); \ render_window_multi(type, 0, obj); \
@ -3237,7 +3223,6 @@ void render_scanline_window_##type(u16 *scanline, u32 dispcnt) \
/* Window 1 and OBJ window */ \ /* Window 1 and OBJ window */ \
case 0x06: \ case 0x06: \
{ \ { \
u32 window_obj_enable = winout >> 8; \
u32 winin = io_registers[REG_WININ]; \ u32 winin = io_registers[REG_WININ]; \
window_coords(1); \ window_coords(1); \
render_window_multi(type, 1, obj); \ render_window_multi(type, 1, obj); \
@ -3247,7 +3232,6 @@ void render_scanline_window_##type(u16 *scanline, u32 dispcnt) \
/* Window 0, 1, and OBJ window */ \ /* Window 0, 1, and OBJ window */ \
case 0x07: \ case 0x07: \
{ \ { \
u32 window_obj_enable = winout >> 8; \
u32 winin = io_registers[REG_WININ]; \ u32 winin = io_registers[REG_WININ]; \
window_coords(0); \ window_coords(0); \
window_coords(1); \ window_coords(1); \
@ -3260,7 +3244,7 @@ void render_scanline_window_##type(u16 *scanline, u32 dispcnt) \
render_scanline_window_builder(tile); render_scanline_window_builder(tile);
render_scanline_window_builder(bitmap); render_scanline_window_builder(bitmap);
u32 active_layers[6] = { 0x1F, 0x17, 0x1C, 0x14, 0x14, 0x14 }; static const u32 active_layers[6] = { 0x1F, 0x17, 0x1C, 0x14, 0x14, 0x14 };
u32 small_resolution_width = 240; u32 small_resolution_width = 240;
u32 small_resolution_height = 160; u32 small_resolution_height = 160;
@ -3270,11 +3254,9 @@ void update_scanline()
{ {
u32 pitch = get_screen_pitch(); u32 pitch = get_screen_pitch();
u32 dispcnt = io_registers[REG_DISPCNT]; u32 dispcnt = io_registers[REG_DISPCNT];
u32 display_flags = (dispcnt >> 8) & 0x1F;
u32 vcount = io_registers[REG_VCOUNT]; u32 vcount = io_registers[REG_VCOUNT];
u16 *screen_offset = get_screen_pixels() + (vcount * pitch); u16 *screen_offset = get_screen_pixels() + (vcount * pitch);
u32 video_mode = dispcnt & 0x07; u32 video_mode = dispcnt & 0x07;
u32 current_layer;
// If OAM has been modified since the last scanline has been updated then // If OAM has been modified since the last scanline has been updated then
// reorder and reprofile the OBJ lists. // reorder and reprofile the OBJ lists.
@ -3383,6 +3365,8 @@ void flip_screen()
{ {
switch(screen_scale) switch(screen_scale)
{ {
case unscaled:
break;
case scaled_aspect: case scaled_aspect:
upscale_aspect(gpsp_gp2x_screen, screen_pixels); upscale_aspect(gpsp_gp2x_screen, screen_pixels);
break; break;
@ -3914,15 +3898,8 @@ void set_gba_resolution(video_scale_type scale)
if(screen_scale != scale) if(screen_scale != scale)
{ {
screen_scale = scale; screen_scale = scale;
switch(scale) small_resolution_width = 240 * video_scale;
{ small_resolution_height = 160 * video_scale;
case unscaled:
case scaled_aspect:
case fullscreen:
small_resolution_width = 240 * video_scale;
small_resolution_height = 160 * video_scale;
break;
}
} }
} }

View file

@ -15,7 +15,7 @@ BIN ?= gpsp.exe
# Platform specific definitions # Platform specific definitions
VPATH += .. VPATH += ..
CFLAGS += -DPC_BUILD -m32 CFLAGS += -DPC_BUILD -Wall -m32
INCLUDES = -I${PREFIX}/include `sdl-config --cflags` INCLUDES = -I${PREFIX}/include `sdl-config --cflags`
LIBS = -L${PREFIX}/lib `sdl-config --libs` -mconsole -lz -m32 LIBS = -L${PREFIX}/lib `sdl-config --libs` -mconsole -lz -m32
@ -23,15 +23,19 @@ LIBS = -L${PREFIX}/lib `sdl-config --libs` -mconsole -lz -m32
.SUFFIXES: .c .S .SUFFIXES: .c .S
all: ${BIN}
%.o: %.c %.o: %.c
${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $< ${CC} ${CFLAGS} ${INCLUDES} -c -o $@ $<
%.o: %.S %.o: %.S
${CC} ${CFLAGS} -c -o $@ $< ${CC} ${CFLAGS} -c -o $@ $<
all: ${OBJS} cpu.o cpu_threaded.o: CFLAGS += -Wno-unused-variable -Wno-unused-label
${BIN}: ${OBJS}
${CC} ${OBJS} ${LIBS} -o ${BIN} ${CC} ${OBJS} ${LIBS} -o ${BIN}
${STRIP} ${BIN} # ${STRIP} ${BIN}
clean: clean:
rm -f *.o ${BIN} rm -f *.o ${BIN}

View file

@ -887,7 +887,7 @@ u32 function_cc execute_rrx(u32 value)
#define collapse_flags() \ #define collapse_flags() \
reg[REG_CPSR] = (reg[REG_N_FLAG] << 31) | (reg[REG_Z_FLAG] << 30) | \ reg[REG_CPSR] = (reg[REG_N_FLAG] << 31) | (reg[REG_Z_FLAG] << 30) | \
(reg[REG_C_FLAG] << 29) | (reg[REG_V_FLAG] << 28) | \ (reg[REG_C_FLAG] << 29) | (reg[REG_V_FLAG] << 28) | \
reg[REG_CPSR] & 0xFF \ (reg[REG_CPSR] & 0xFF) \
// It should be okay to still generate result flags, spsr will overwrite them. // It should be okay to still generate result flags, spsr will overwrite them.
// This is pretty infrequent (returning from interrupt handlers, et al) so // This is pretty infrequent (returning from interrupt handlers, et al) so
@ -1200,7 +1200,7 @@ typedef enum
generate_store_reg_pc_no_flags(a0, rd); \ generate_store_reg_pc_no_flags(a0, rd); \
} \ } \
u32 function_cc execute_mul_flags(u32 dest) static void function_cc execute_mul_flags(u32 dest)
{ {
calculate_z_flag(dest); calculate_z_flag(dest);
calculate_n_flag(dest); calculate_n_flag(dest);
@ -1228,7 +1228,7 @@ u32 function_cc execute_mul_flags(u32 dest)
arm_multiply_flags_##flags(); \ arm_multiply_flags_##flags(); \
} \ } \
u32 function_cc execute_mul_long_flags(u32 dest_lo, u32 dest_hi) static void function_cc execute_mul_long_flags(u32 dest_lo, u32 dest_hi)
{ {
reg[REG_Z_FLAG] = (dest_lo == 0) & (dest_hi == 0); reg[REG_Z_FLAG] = (dest_lo == 0) & (dest_hi == 0);
calculate_n_flag(dest_hi); calculate_n_flag(dest_hi);
@ -2045,7 +2045,7 @@ u32 function_cc execute_ror_imm_op(u32 value, u32 shift)
#define thumb_conditional_branch(condition) \ #define thumb_conditional_branch(condition) \
{ \ { \
condition_check_type condition_check; \ condition_check_type condition_check = CONDITION_TRUE; \
generate_cycle_update(); \ generate_cycle_update(); \
generate_condition_##condition(a0, a1); \ generate_condition_##condition(a0, a1); \
generate_conditional_branch_type(a0, a1); \ generate_conditional_branch_type(a0, a1); \
@ -2171,7 +2171,7 @@ data_proc_generate_logic_test_function(teq, rn ^ rm);
data_proc_generate_sub_test_function(cmp, rn, rm); data_proc_generate_sub_test_function(cmp, rn, rm);
data_proc_generate_add_test_function(cmn, rn, rm); data_proc_generate_add_test_function(cmn, rn, rm);
u32 function_cc execute_swi(u32 pc) static void function_cc execute_swi(u32 pc)
{ {
reg_mode[MODE_SUPERVISOR][6] = pc; reg_mode[MODE_SUPERVISOR][6] = pc;
collapse_flags(); collapse_flags();
@ -2182,7 +2182,7 @@ u32 function_cc execute_swi(u32 pc)
#define arm_conditional_block_header() \ #define arm_conditional_block_header() \
{ \ { \
condition_check_type condition_check; \ condition_check_type condition_check = CONDITION_TRUE; \
generate_condition(a0, a1); \ generate_condition(a0, a1); \
generate_conditional_branch_type(a0, a1); \ generate_conditional_branch_type(a0, a1); \
} }

4
zip.c
View file

@ -46,11 +46,11 @@ struct SZIPFileHeader
u32 load_file_zip(char *filename) u32 load_file_zip(char *filename)
{ {
struct SZIPFileHeader data; struct SZIPFileHeader data;
u8 tmp[1024]; char tmp[1024];
s32 retval = -1; s32 retval = -1;
u8 *buffer = NULL; u8 *buffer = NULL;
u8 *cbuffer; u8 *cbuffer;
u8 *ext; char *ext;
file_open(fd, filename, read); file_open(fd, filename, read);