diff options
author | aliaspider | 2014-12-09 00:17:28 +0100 |
---|---|---|
committer | aliaspider | 2014-12-09 00:17:28 +0100 |
commit | 8f9b841f721bbfbc74590267e57e0bb4744ae63f (patch) | |
tree | 568cffe5287aeb3bb907de99681e7d881d5f0277 | |
parent | 365077772d3d8d5d479febd0388d7e74ef08d508 (diff) | |
download | picogpsp-8f9b841f721bbfbc74590267e57e0bb4744ae63f.tar.gz picogpsp-8f9b841f721bbfbc74590267e57e0bb4744ae63f.tar.bz2 picogpsp-8f9b841f721bbfbc74590267e57e0bb4744ae63f.zip |
can compile
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | common.h | 10 | ||||
-rw-r--r-- | cpu.c | 4 | ||||
-rw-r--r-- | input.c | 5 | ||||
-rw-r--r-- | libretro.c | 62 | ||||
-rw-r--r-- | main.c | 13 | ||||
-rw-r--r-- | main.h | 6 | ||||
-rw-r--r-- | memory.c | 24 | ||||
-rw-r--r-- | memory.h | 3 | ||||
-rw-r--r-- | sound.c | 51 | ||||
-rw-r--r-- | sound.h | 111 | ||||
-rw-r--r-- | video.c | 14 | ||||
-rw-r--r-- | video.h | 4 | ||||
-rw-r--r-- | zip.c | 2 | ||||
-rw-r--r-- | zip.h | 2 |
15 files changed, 228 insertions, 87 deletions
@@ -4,7 +4,7 @@ CC = gcc AR = psp-ar STATIC_LINKING = 0 -CFLAGS += -fPIC +CFLAGS += -fPIC -Werror-implicit-function-declaration CFLAGS += -DPC_BUILD -Wall -m32 CFLAGS += -D__LIBRETRO__ @@ -26,7 +26,7 @@ OBJS += input.o OBJS += sound.o OBJS += cpu_threaded.o -OBJS += x86_stub.o +OBJS += x86/x86_stub.o OBJS += cheats.o OBJS += zip.o @@ -104,7 +104,15 @@ #include <time.h> #include <stdio.h> #else +#ifdef __LIBRETRO__ + +#define GBA_SCREEN_WIDTH (240) +#define GBA_SCREEN_HEIGHT (160) +#define GBA_SCREEN_PITCH (240) + +#else #include "SDL.h" +#endif #ifdef ARM_ARCH #define function_cc @@ -210,7 +218,9 @@ typedef u32 fixed8_24; #include <stdlib.h> #include <string.h> #include <stdarg.h> +#ifndef __LIBRETRO__ #include "SDL.h" +#endif #include "cpu.h" #include "memory.h" #include "video.h" @@ -4146,8 +4146,10 @@ void function_cc step_debug(u32 pc, u32 cycles) { u32 key = 0; +#ifndef __LIBRETRO__ SDL_LockMutex(sound_mutex); SDL_PauseAudio(1); +#endif if(output_field >= num_output_fields) { @@ -4281,8 +4283,10 @@ void function_cc step_debug(u32 pc, u32 cycles) quit(); } +#ifndef __LIBRETRO__ SDL_PauseAudio(0); SDL_UnlockMutex(sound_mutex); +#endif } last_instruction = reg[REG_PC]; @@ -343,10 +343,11 @@ void init_input() sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG); } -#endif +#elif defined(__LIBRETRO__) +/* todo */ -#if defined(PC_BUILD) +#elif defined(PC_BUILD) u32 key_map(SDLKey key_sym) { @@ -5,6 +5,11 @@ #include <stdint.h> #include "common.h" #include "libco.h" +#include "libretro.h" + +#ifndef MAX_PATH +#define MAX_PATH (512) +#endif static retro_log_printf_t log_cb; static retro_video_refresh_t video_cb; @@ -28,7 +33,7 @@ static inline void switch_to_cpu_thread(void) static void cpu_thread_entry(void) { - execute_arm_translate(reg[EXECUTE_CYCLES]); + execute_arm_translate(execute_cycles); } static inline void init_context_switch(void) @@ -42,6 +47,26 @@ static inline void deinit_context_switch(void) co_delete(cpu_thread); } +#ifdef PERF_TEST + +extern struct retro_perf_callback perf_cb; + +#define RETRO_PERFORMANCE_INIT(X) \ + static struct retro_perf_counter X = {#X}; \ + do { \ + if (!(X).registered) \ + perf_cb.perf_register(&(X)); \ + } while(0) + +#define RETRO_PERFORMANCE_START(X) perf_cb.perf_start(&(X)) +#define RETRO_PERFORMANCE_STOP(X) perf_cb.perf_stop(&(X)) +#else +#define RETRO_PERFORMANCE_INIT(X) +#define RETRO_PERFORMANCE_START(X) +#define RETRO_PERFORMANCE_STOP(X) + +#endif + void retro_get_system_info(struct retro_system_info *info) { info->library_name = "TempGBA"; @@ -59,8 +84,8 @@ void retro_get_system_av_info(struct retro_system_av_info *info) info->geometry.max_width = GBA_SCREEN_WIDTH; info->geometry.max_height = GBA_SCREEN_HEIGHT; info->geometry.aspect_ratio = 0; - info->timing.fps = ((float) CPU_FREQUENCY) / (308 * 228 * 4); // 59.72750057 hz - info->timing.sample_rate = SOUND_FREQUENCY; + info->timing.fps = ((float) (16* 1024 * 1024)) / (308 * 228 * 4); // 59.72750057 hz + info->timing.sample_rate = 44100; // info->timing.sample_rate = 32 * 1024; } @@ -68,13 +93,13 @@ void retro_get_system_av_info(struct retro_system_av_info *info) void retro_init() { init_gamepak_buffer(); - init_sound(); + init_sound(1); } void retro_deinit() { perf_cb.perf_log(); - quit_gba(); + memory_term(); } void retro_set_environment(retro_environment_t cb) @@ -110,27 +135,28 @@ void retro_reset() size_t retro_serialize_size() { - return SAVESTATE_SIZE; +// return SAVESTATE_SIZE; + return 0; } bool retro_serialize(void *data, size_t size) { - if (size < SAVESTATE_SIZE) +// if (size < SAVESTATE_SIZE) return false; - gba_save_state(data); +// gba_save_state(data); - return true; +// return true; } bool retro_unserialize(const void *data, size_t size) { - if (size < SAVESTATE_SIZE) +// if (size < SAVESTATE_SIZE) return false; - gba_load_state(data); +// gba_load_state(data); - return true; +// return true; } void retro_cheat_reset() {} @@ -184,12 +210,12 @@ bool retro_load_game(const struct retro_game_info *info) strncat(filename_bios, "/gba_bios.bin",sizeof(filename_bios)); - if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) - strncpy(dir_save, dir, sizeof(dir_save)); - else - strncpy(dir_save, main_path, sizeof(dir_save)); +// if (environ_cb(RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY, &dir) && dir) +// strncpy(dir_save, dir, sizeof(dir_save)); +// else +// strncpy(dir_save, main_path, sizeof(dir_save)); - strncat(dir_save, "/",sizeof(dir_save)); +// strncat(dir_save, "/",sizeof(dir_save)); strncat(main_path, "/",sizeof(main_path)); @@ -281,7 +307,7 @@ void retro_run() render_audio(); - video_cb(GBA_FRAME_TEXTURE, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT, 512); + video_cb(gba_screen_pixels, GBA_SCREEN_WIDTH, GBA_SCREEN_HEIGHT, GBA_SCREEN_PITCH * 2); if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE, &updated) && updated) check_variables(); @@ -18,6 +18,7 @@ */ #include "common.h" +#include <ctype.h> #ifdef PSP_BUILD @@ -773,6 +774,8 @@ void synchronize() */ } +#elif defined(__LIBRETRO__) + #else u32 real_frame_count = 0; @@ -870,6 +873,8 @@ void quit() sound_exit(); +#ifndef __LIBRETRO__ + #ifdef REGISTER_USAGE_ANALYZE print_register_usage(); #endif @@ -885,6 +890,8 @@ void quit() exit(0); #endif + +#endif } void reset_gba() @@ -919,7 +926,7 @@ void get_ticks_us(u64 *tick_return) #else -u32 file_length(char *dummy, FILE *fp) +u32 file_length(const char *dummy, FILE *fp) { u32 length; @@ -930,7 +937,9 @@ u32 file_length(char *dummy, FILE *fp) return length; } -#ifdef PC_BUILD +#ifdef __LIBRETRO__ + +#elif defined(PC_BUILD) void delay_us(u32 us_count) { @@ -90,7 +90,11 @@ extern u32 clock_speed; u32 update_gba(); void reset_gba(); +#ifdef __LIBRETRO__ +#define synchronize() +#else void synchronize(); +#endif void quit(); void delay_us(u32 us_count); void get_ticks_us(u64 *tick_return); @@ -105,7 +109,7 @@ u32 file_length(char *filename, s32 dummy); #else -u32 file_length(char *dummy, FILE *fp); +u32 file_length(const char *dummy, FILE *fp); #endif @@ -2115,7 +2115,7 @@ s32 load_game_config(char *gamepak_title, char *gamepak_code, char *gamepak_make return -1; } -s32 load_gamepak_raw(char *name) +s32 load_gamepak_raw(const char *name) { file_open(gamepak_file, name, read); @@ -2160,7 +2160,7 @@ char gamepak_code[5]; char gamepak_maker[3]; char gamepak_filename[512]; -u32 load_gamepak(char *name) +u32 load_gamepak(const char *name) { char *dot_position = strrchr(name, '.'); s32 file_size; @@ -3119,6 +3119,26 @@ void init_memory() bios_read_protect = 0xe129f000; } +void memory_term(void) +{ + if (file_check_valid(gamepak_file_large)) + { + file_close(gamepak_file_large); + } + + if (gamepak_memory_map != NULL) + { + free(gamepak_memory_map); + gamepak_memory_map = NULL; + } + + if (gamepak_rom != NULL) + { + free(gamepak_rom); + gamepak_rom = NULL; + } +} + void bios_region_read_allow() { memory_map_read[0] = bios_rom; @@ -175,13 +175,14 @@ extern char gamepak_filename[512]; cpu_alert_type dma_transfer(dma_transfer_type *dma); u8 *memory_region(u32 address, u32 *memory_limit); -u32 load_gamepak(char *name); +u32 load_gamepak(const char *name); u32 load_backup(char *name); s32 load_bios(char *name); void update_backup(); void update_backup_force(); void init_memory(); void init_gamepak_buffer(); +void memory_term(void); void bios_region_read_allow(); void bios_region_read_protect(); u8 *load_gamepak_page(u32 physical_index); @@ -19,7 +19,9 @@ #include "common.h" +#ifndef __LIBRETRO__ #include <SDL.h> +#endif u32 global_enable_audio = 1; direct_sound_struct direct_sound_channel[2]; @@ -27,8 +29,10 @@ gbc_sound_struct gbc_sound_channel[4]; u32 sound_frequency = 44100; +#ifndef __LIBRETRO__ SDL_mutex *sound_mutex; static SDL_cond *sound_cv; +#endif #ifdef PSP_BUILD u32 audio_buffer_size_number = 1; @@ -44,7 +48,9 @@ static u32 sound_buffer_base; static u32 sound_last_cpu_ticks; static fixed16_16 gbc_sound_tick_step; +#ifndef __LIBRETRO__ static u32 sound_exit_flag; +#endif // Queue 1, 2, or 4 samples to the top of the DS FIFO, wrap around circularly @@ -447,6 +453,7 @@ void update_gbc_sound(u32 cpu_ticks) gbc_sound_partial_ticks &= 0xFFFF; } +#ifndef __LIBRETRO__ SDL_LockMutex(sound_mutex); if(synchronize_flag) { @@ -487,6 +494,7 @@ void update_gbc_sound(u32 cpu_ticks) } } +#endif if(sound_on == 1) { gs = gbc_sound_channel + 0; @@ -562,9 +570,11 @@ void update_gbc_sound(u32 cpu_ticks) gbc_sound_buffer_index = (gbc_sound_buffer_index + (buffer_ticks * 2)) % BUFFER_SIZE; +#ifndef __LIBRETRO__ SDL_UnlockMutex(sound_mutex); SDL_CondSignal(sound_cv); +#endif } #define sound_copy_normal() \ @@ -595,7 +605,7 @@ void update_gbc_sound(u32 cpu_ticks) } \ -void sound_callback(void *userdata, Uint8 *stream, int length) +void sound_callback(void *userdata, u8 *stream, int length) { u32 sample_length = length / 2; u32 _length; @@ -604,6 +614,7 @@ void sound_callback(void *userdata, Uint8 *stream, int length) s16 *source; s32 current_sample; +#ifndef __LIBRETRO__ SDL_LockMutex(sound_mutex); while(((gbc_sound_buffer_index - sound_buffer_base) % BUFFER_SIZE) < @@ -611,6 +622,7 @@ void sound_callback(void *userdata, Uint8 *stream, int length) { SDL_CondWait(sound_cv, sound_mutex); } +#endif if(global_enable_audio) { @@ -645,9 +657,11 @@ void sound_callback(void *userdata, Uint8 *stream, int length) } } +#ifndef __LIBRETRO__ SDL_CondSignal(sound_cv); SDL_UnlockMutex(sound_mutex); +#endif } // Special thanks to blarrg for the LSFR frequency used in Meridian, as posted @@ -689,7 +703,9 @@ void reset_sound() gbc_sound_struct *gs = gbc_sound_channel; u32 i; +#ifndef __LIBRETRO__ SDL_LockMutex(sound_mutex); +#endif sound_on = 0; sound_buffer_base = 0; @@ -723,13 +739,16 @@ void reset_sound() gs->active_flag = 0; } +#ifndef __LIBRETRO__ SDL_UnlockMutex(sound_mutex); +#endif } void sound_exit() { gbc_sound_buffer_index = (sound_buffer_base + audio_buffer_size) % BUFFER_SIZE; +#ifndef __LIBRETRO__ SDL_PauseAudio(1); sound_exit_flag = 1; SDL_CondSignal(sound_cv); @@ -739,10 +758,12 @@ void sound_exit() sound_mutex = NULL; SDL_DestroyCond(sound_cv); sound_cv = NULL; +#endif } void init_sound(int need_reset) { +#ifndef __LIBRETRO__ SDL_AudioSpec sound_settings; sound_exit_flag = 0; @@ -779,6 +800,8 @@ void init_sound(int need_reset) printf("audio: freq %d, size %d\n", sound_frequency, audio_buffer_size); #endif +#endif + gbc_sound_tick_step = float_to_fp16_16(256.0f / sound_frequency); @@ -788,7 +811,9 @@ void init_sound(int need_reset) if (need_reset) reset_sound(); +#ifndef __LIBRETRO__ SDL_PauseAudio(0); +#endif } #define sound_savestate_builder(type) \ @@ -811,3 +836,27 @@ void sound_##type##_savestate(file_tag_type savestate_file) \ sound_savestate_builder(read); sound_savestate_builder(write_mem); + +#ifdef __LIBRETRO__ +#include "libretro.h" + +static retro_audio_sample_batch_t audio_batch_cb; +void retro_set_audio_sample(retro_audio_sample_t cb) { } +void retro_set_audio_sample_batch(retro_audio_sample_batch_t cb) { audio_batch_cb = cb; } + +void render_audio(void) +{ + static s16 stream_base[1024]; + u32 _length; + s16 *source; + u32 i; + s32 current_sample; + + while (((gbc_sound_buffer_index - sound_buffer_base) % BUFFER_SIZE) > 512) { + sound_copy(sound_buffer_base, 512, normal); + audio_batch_cb(stream_base, 256); + sound_buffer_base += 512; + } +} +#endif + @@ -25,79 +25,79 @@ #define GBA_XTAL 16777216.0f #define GBA_60HZ_RATE 16853760.0f /* 228*(272+960)*60 */ -#if !defined(PSP_BUILD) - // run GBA at 60Hz (~0.5% faster) to better match host display - #define GBC_BASE_RATE GBA_60HZ_RATE +#if !defined(PSP_BUILD) && !defined(__LIBRETRO__) +// run GBA at 60Hz (~0.5% faster) to better match host display +#define GBC_BASE_RATE GBA_60HZ_RATE #else - #define GBC_BASE_RATE GBA_XTAL +#define GBC_BASE_RATE GBA_XTAL #endif typedef enum { - DIRECT_SOUND_INACTIVE, - DIRECT_SOUND_RIGHT, - DIRECT_SOUND_LEFT, - DIRECT_SOUND_LEFTRIGHT + DIRECT_SOUND_INACTIVE, + DIRECT_SOUND_RIGHT, + DIRECT_SOUND_LEFT, + DIRECT_SOUND_LEFTRIGHT } direct_sound_status_type; typedef enum { - DIRECT_SOUND_VOLUME_50, - DIRECT_SOUND_VOLUME_100 + DIRECT_SOUND_VOLUME_50, + DIRECT_SOUND_VOLUME_100 } direct_sound_volume_type; typedef struct { - s8 fifo[32]; - u32 fifo_base; - u32 fifo_top; - fixed8_24 fifo_fractional; - // The + 1 is to give some extra room for linear interpolation - // when wrapping around. - u32 buffer_index; - direct_sound_status_type status; - direct_sound_volume_type volume; - u32 last_cpu_ticks; + s8 fifo[32]; + u32 fifo_base; + u32 fifo_top; + fixed8_24 fifo_fractional; + // The + 1 is to give some extra room for linear interpolation + // when wrapping around. + u32 buffer_index; + direct_sound_status_type status; + direct_sound_volume_type volume; + u32 last_cpu_ticks; } direct_sound_struct; typedef enum { - GBC_SOUND_INACTIVE, - GBC_SOUND_RIGHT, - GBC_SOUND_LEFT, - GBC_SOUND_LEFTRIGHT + GBC_SOUND_INACTIVE, + GBC_SOUND_RIGHT, + GBC_SOUND_LEFT, + GBC_SOUND_LEFTRIGHT } gbc_sound_status_type; typedef struct { - u32 rate; - fixed16_16 frequency_step; - fixed16_16 sample_index; - fixed16_16 tick_counter; - u32 total_volume; - u32 envelope_initial_volume; - u32 envelope_volume; - u32 envelope_direction; - u32 envelope_status; - u32 envelope_step; - u32 envelope_ticks; - u32 envelope_initial_ticks; - u32 sweep_status; - u32 sweep_direction; - u32 sweep_ticks; - u32 sweep_initial_ticks; - u32 sweep_shift; - u32 length_status; - u32 length_ticks; - u32 noise_type; - u32 wave_type; - u32 wave_bank; - u32 wave_volume; - gbc_sound_status_type status; - u32 active_flag; - u32 master_enable; - s8 *sample_data; + u32 rate; + fixed16_16 frequency_step; + fixed16_16 sample_index; + fixed16_16 tick_counter; + u32 total_volume; + u32 envelope_initial_volume; + u32 envelope_volume; + u32 envelope_direction; + u32 envelope_status; + u32 envelope_step; + u32 envelope_ticks; + u32 envelope_initial_ticks; + u32 sweep_status; + u32 sweep_direction; + u32 sweep_ticks; + u32 sweep_initial_ticks; + u32 sweep_shift; + u32 length_status; + u32 length_ticks; + u32 noise_type; + u32 wave_type; + u32 wave_bank; + u32 wave_volume; + gbc_sound_status_type status; + u32 active_flag; + u32 master_enable; + s8* sample_data; } gbc_sound_struct; extern direct_sound_struct direct_sound_channel[2]; @@ -116,7 +116,9 @@ extern u32 global_enable_audio; extern u32 enable_low_pass_filter; extern u32 audio_buffer_size_number; -extern SDL_mutex *sound_mutex; +#ifndef __LIBRETRO__ +extern SDL_mutex* sound_mutex; +#endif void sound_timer_queue8(u32 channel, u8 value); void sound_timer_queue16(u32 channel, u16 value); @@ -128,6 +130,11 @@ void init_sound(int need_reset); void sound_write_mem_savestate(file_tag_type savestate_file); void sound_read_savestate(file_tag_type savestate_file); +#ifdef __LIBRETRO__ +void render_audio(void); +#endif + + #ifdef IN_MEMORY_C #define gbc_sound_tone_control_low(channel, address) \ @@ -86,8 +86,13 @@ static void Ge_Finish_Callback(int id, void *arg) #define get_screen_pitch() \ screen_pitch \ -#else +#elif defined(__LIBRETRO__) +u16 gba_screen_pixels[GBA_SCREEN_PITCH * GBA_SCREEN_HEIGHT]; + +#define get_screen_pixels() gba_screen_pixels +#define get_screen_pitch() GBA_SCREEN_PITCH +#else SDL_Surface *screen; const u32 video_scale = 1; @@ -96,6 +101,7 @@ const u32 video_scale = 1; #define get_screen_pitch() \ (screen->pitch / 2) \ +#endif #endif @@ -3303,7 +3309,7 @@ void flip_screen() } } -#else +#elif !defined(__LIBRETRO__) #define integer_scale_copy_2() \ current_scanline_ptr[x2] = current_pixel; \ @@ -3476,7 +3482,7 @@ void init_video() GE_CMD(NOP, 0); } -#else +#elif !defined(__LIBRETRO__) void init_video() { @@ -3593,7 +3599,7 @@ void clear_screen(u16 color) sceGuSync(0, 0); */ } -#else +#elif !defined(__LIBRETRO__) void video_resolution_large() { @@ -103,4 +103,8 @@ extern video_filter_type2 screen_filter2; void set_gba_resolution(video_scale_type scale); +#ifdef __LIBRETRO__ +extern u16 gba_screen_pixels[GBA_SCREEN_PITCH * GBA_SCREEN_HEIGHT]; +#endif + #endif @@ -43,7 +43,7 @@ struct SZIPFileHeader s16 ExtraFieldLength; } __attribute__((packed)); -u32 load_file_zip(char *filename) +u32 load_file_zip(const char *filename) { struct SZIPFileHeader data; char tmp[1024]; @@ -20,7 +20,7 @@ #ifndef ZIP_H #define ZIP_H -u32 load_file_zip(char *filename); +u32 load_file_zip(const char *filename); #endif |