Skip to content

Commit

Permalink
Open RetroArch Menu Long Pressing Start button
Browse files Browse the repository at this point in the history
  • Loading branch information
fjtrujy committed Jan 7, 2019
1 parent 3bb0c7c commit f48ffb9
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 90 deletions.
74 changes: 36 additions & 38 deletions audio/drivers/ps2_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,41 +81,41 @@ static void audioCreateThread(ps2_audio_t *ps2)
thread.attr=thread.option=0;

/*Backup the PS2 content to be used in the thread */
backup_ps2 = ps2;
backup_ps2 = ps2;

ps2->running = true;
ps2->running = true;
ps2->worker_thread = CreateThread(&thread);

if (ps2->worker_thread >= 0)
{
if (ps2->worker_thread >= 0) {
ret = StartThread(ps2->worker_thread, NULL);
if (ret < 0)
if (ret < 0) {
printf("sound_init: StartThread returned %d\n", ret);
}
else
}
} else {
printf("CreateThread failed: %d\n", ps2->worker_thread);
}
}

static void audioStopNDeleteThread(ps2_audio_t *ps2)
{
ps2->running = false;
if (ps2->worker_thread)
if (ps2->worker_thread) {
ps2->worker_thread = 0;
}
}

static void audioConfigure(ps2_audio_t *ps2, unsigned rate)
{
int err;
struct audsrv_fmt_t format;

format.bits = AUDIO_BITS;
format.freq = rate;
format.bits = AUDIO_BITS;
format.freq = rate;
format.channels = AUDIO_CHANNELS;

err = audsrv_set_format(&format);
err = audsrv_set_format(&format);

if (err)
{
if (err){
printf("set format returned %d\n", err);
printf("audsrv returned error string: %s\n", audsrv_get_error_string());
}
Expand All @@ -128,16 +128,16 @@ static void audioCreateSemas(ps2_audio_t *ps2)
ee_sema_t lock_info;
ee_sema_t cond_lock_info;

lock_info.max_count = 1;
lock_info.init_count = 1;
lock_info.option = 0;
ps2->lock = CreateSema(&lock_info);
lock_info.max_count = 1;
lock_info.init_count = 1;
lock_info.option = 0;
ps2->lock = CreateSema(&lock_info);

cond_lock_info.init_count = 1;
cond_lock_info.max_count = 1;
cond_lock_info.option = 0;
cond_lock_info.option = 0;

ps2->cond_lock = CreateSema(&cond_lock_info);
ps2->cond_lock = CreateSema(&cond_lock_info);
}

static void *ps2_audio_init(const char *device,
Expand All @@ -164,18 +164,15 @@ static void ps2_audio_free(void *data)
if(!ps2)
return;

if(ps2->running)
{
if(ps2->running){
audioStopNDeleteThread(ps2);

if (ps2->lock)
{
if (ps2->lock){
iDeleteSema(ps2->lock);
ps2->lock = 0;
}

if (ps2->cond_lock)
{
if (ps2->cond_lock){
iDeleteSema(ps2->cond_lock);
ps2->cond_lock = 0;
}
Expand All @@ -192,14 +189,14 @@ static ssize_t ps2_audio_write(void *data, const void *buf, size_t size)
if (!ps2->running)
return -1;

if (ps2->nonblocking)
{
if (ps2->nonblocking){
if (fifo_write_avail(ps2->buffer) < size)
return 0;
}

while (fifo_write_avail(ps2->buffer) < size)
while (fifo_write_avail(ps2->buffer) < size) {
WaitSema(ps2->cond_lock);
}

WaitSema(ps2->lock);
fifo_write(ps2->buffer, buf, size);
Expand All @@ -213,8 +210,9 @@ static bool ps2_audio_alive(void *data)
bool alive = false;

ps2_audio_t* ps2 = (ps2_audio_t*)data;
if (ps2)
if (ps2) {
alive = ps2->running;
}

return alive;
}
Expand All @@ -224,8 +222,7 @@ static bool ps2_audio_stop(void *data)
bool stop = true;
ps2_audio_t* ps2 = (ps2_audio_t*)data;

if (ps2)
{
if (ps2) {
audioStopNDeleteThread(ps2);
audsrv_stop_audio();
}
Expand All @@ -235,13 +232,13 @@ static bool ps2_audio_stop(void *data)

static bool ps2_audio_start(void *data, bool is_shutdown)
{
bool start = true;
ps2_audio_t* ps2 = (ps2_audio_t*)data;
bool start = true;

if(ps2)
{
if (!ps2->running && !ps2->worker_thread)
if (ps2) {
if (!ps2->running && !ps2->worker_thread) {
audioCreateThread(ps2);
}
}

return start;
Expand All @@ -250,8 +247,10 @@ static bool ps2_audio_start(void *data, bool is_shutdown)
static void ps2_audio_set_nonblock_state(void *data, bool toggle)
{
ps2_audio_t* ps2 = (ps2_audio_t*)data;
if (ps2)

if (ps2) {
ps2->nonblocking = toggle;
}
}

static bool ps2_audio_use_float(void *data)
Expand All @@ -263,8 +262,7 @@ static size_t ps2_audio_write_avail(void *data)
{
ps2_audio_t* ps2 = (ps2_audio_t*)data;

if (ps2 && ps2->running)
{
if (ps2 && ps2->running) {
size_t size;
WaitSema(ps2->lock);
size = AUDIO_BUFFER - fifo_read_avail(ps2->buffer);
Expand Down
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ static bool default_screenshots_in_content_dir = false;

#if defined(__CELLOS_LV2__) || defined(_XBOX1) || defined(_XBOX360)
static unsigned menu_toggle_gamepad_combo = INPUT_TOGGLE_L3_R3;
#elif defined(PS2)
static unsigned menu_toggle_gamepad_combo = INPUT_TOGGLE_HOLD_START;
#elif defined(VITA)
static unsigned menu_toggle_gamepad_combo = INPUT_TOGGLE_L1_R1_START_SELECT;
#elif defined(SWITCH)
Expand Down
88 changes: 44 additions & 44 deletions gfx/drivers/ps2_gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct ps2_video

// PRIVATE METHODS
static GSGLOBAL *init_GSGlobal(void) {
GSGLOBAL *gsGlobal = gsKit_init_global();
GSGLOBAL *gsGlobal = gsKit_init_global();

gsGlobal->Mode = GS_MODE_NTSC;
gsGlobal->Interlace = GS_INTERLACED;
Expand All @@ -54,28 +54,26 @@ static GSGLOBAL *init_GSGlobal(void) {
gsGlobal->Height = NTSC_HEIGHT;

gsGlobal->PSM = GS_PSM_CT16;
gsGlobal->PSMZ = GS_PSMZ_16;
gsGlobal->DoubleBuffering = GS_SETTING_OFF;
gsGlobal->ZBuffering = GS_SETTING_OFF;
gsGlobal->PSMZ = GS_PSMZ_16;
gsGlobal->DoubleBuffering = GS_SETTING_OFF;
gsGlobal->ZBuffering = GS_SETTING_OFF;
gsGlobal->PrimAlphaEnable = GS_SETTING_OFF;

dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);
dmaKit_init(D_CTRL_RELE_OFF,D_CTRL_MFD_OFF, D_CTRL_STS_UNSPEC,
D_CTRL_STD_OFF, D_CTRL_RCYC_8, 1 << DMA_CHANNEL_GIF);

// Initialize the DMAC
dmaKit_chan_init(DMA_CHANNEL_GIF);
/* Initialize the DMAC */
dmaKit_chan_init(DMA_CHANNEL_GIF);

gsKit_init_screen(gsGlobal);
gsKit_mode_switch(gsGlobal, GS_ONESHOT);
gsKit_init_screen(gsGlobal);
gsKit_mode_switch(gsGlobal, GS_ONESHOT);

gsKit_clear(gsGlobal, GS_BLACK);

return gsGlobal;
return gsGlobal;
}

static GSTEXTURE * prepare_new_texture(void) {
GSTEXTURE *texture = calloc(1, sizeof(*texture));
return texture;
GSTEXTURE *texture = calloc(1, sizeof(*texture));
return texture;
}

static void init_ps2_video(ps2_video_t *ps2) {
Expand All @@ -93,22 +91,22 @@ static void deinitTexture(GSTEXTURE *texture) {

static void color_correction32(uint32_t *buffer, uint32_t dimensions)
{
uint32_t i;
uint32_t x32;
for (i = 0; i < dimensions; i++) {
uint32_t i;
uint32_t x32;
for (i = 0; i < dimensions; i++) {
x32 = buffer[i];
buffer[i] = ((x32 >> 16) & 0xFF) | ((x32 << 16) & 0xFF0000) | (x32 & 0xFF00FF00);
}
}
}

static void color_correction16(uint16_t *buffer, uint32_t dimensions)
{
uint32_t i;
uint16_t x16;
for (i = 0; i < dimensions; i++) {
uint32_t i;
uint16_t x16;
for (i = 0; i < dimensions; i++) {
x16 = buffer[i];
buffer[i] = (x16 & 0x8000) | ((x16 << 10) & 0x7C00) | ((x16 >> 1) & 0x3E0) | ((x16 >> 11) & 0x1F);
}
}
}

static void transfer_texture(GSTEXTURE *texture, const void *frame,
Expand Down Expand Up @@ -144,32 +142,32 @@ if (color_correction) {

static void vram_alloc(GSGLOBAL *gsGlobal, GSTEXTURE *texture) {
uint32_t size = gsKit_texture_size(texture->Width, texture->Height, texture->PSM);
texture->Vram=gsKit_vram_alloc(gsGlobal, size, GSKIT_ALLOC_USERBUFFER);
texture->Vram = gsKit_vram_alloc(gsGlobal, size, GSKIT_ALLOC_USERBUFFER);
if(texture->Vram == GSKIT_ALLOC_ERROR) {
printf("VRAM Allocation Failed. Will not upload texture.\n");
}
}

static void prim_texture(GSGLOBAL *gsGlobal, GSTEXTURE *texture, int zPosition, bool force_aspect) {
float x1, y1, x2, y2;
if (force_aspect) {
float width_proportion = (float)gsGlobal->Width / (float)texture->Width;
float height_proportion = (float)gsGlobal->Height / (float)texture->Height;
float delta = MIN(width_proportion, height_proportion);
float newWidth = texture->Width * delta;
float newHeight = texture->Height * delta;
x1 = (gsGlobal->Width - newWidth) / 2.0f;
y1 = (gsGlobal->Height - newHeight) / 2.0f;
x2 = newWidth + x1;
y2 = newHeight + y1;

} else {
x1 = 0.0f;
y1 = 0.0f;
x2 = gsGlobal->Width;
y2 = gsGlobal->Height;
}
if (force_aspect) {
float width_proportion = (float)gsGlobal->Width / (float)texture->Width;
float height_proportion = (float)gsGlobal->Height / (float)texture->Height;
float delta = MIN(width_proportion, height_proportion);
float newWidth = texture->Width * delta;
float newHeight = texture->Height * delta;

x1 = (gsGlobal->Width - newWidth) / 2.0f;
y1 = (gsGlobal->Height - newHeight) / 2.0f;
x2 = newWidth + x1;
y2 = newHeight + y1;

} else {
x1 = 0.0f;
y1 = 0.0f;
x2 = gsGlobal->Width;
y2 = gsGlobal->Height;
}

gsKit_prim_sprite_texture( gsGlobal, texture,
x1, //X1
Expand Down Expand Up @@ -225,13 +223,15 @@ static bool ps2_gfx_frame(void *data, const void *frame,
static float fps = 0.0;
#endif
ps2_video_t *ps2 = (ps2_video_t*)data;
bool texture_empty = true;

if (!width || !height)
return false;

if (frame_count%120==0) {
printf("ps2_gfx_frame %d\n", frame_count);
printf("ps2_gfx_frame %lu\n", frame_count);
}
gsKit_clear(ps2->gsGlobal, GS_BLACK);
gsKit_vram_clear(ps2->gsGlobal);

if (frame) {
Expand All @@ -241,7 +241,7 @@ static bool ps2_gfx_frame(void *data, const void *frame,
prim_texture(ps2->gsGlobal, ps2->coreTexture, 1, ps2->force_aspect);
}

bool texture_empty = !ps2->menuTexture->Width || !ps2->menuTexture->Height;
texture_empty = !ps2->menuTexture->Width || !ps2->menuTexture->Height;
if (ps2->menuVisible && !texture_empty) {
vram_alloc(ps2->gsGlobal, ps2->menuTexture);
gsKit_texture_upload(ps2->gsGlobal, ps2->menuTexture);
Expand Down
12 changes: 5 additions & 7 deletions input/drivers_joypad/ps2_joypad.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static char padBuf[256] __attribute__((aligned(64)));

static uint64_t pad_state[PS2_MAX_PADS];

extern uint64_t lifecycle_state;

static const char *ps2_joypad_name(unsigned pad)
{
Expand All @@ -45,6 +46,8 @@ static bool ps2_joypad_init(void *data)

for (i = 0; i < players_count; i++)
{
int ret, port, slot;

bool auto_configure = input_autoconfigure_connect( ps2_joypad_name(i),
NULL,
ps2_joypad.ident,
Expand All @@ -57,9 +60,6 @@ static bool ps2_joypad_init(void *data)

padInit(i);

int ret;
int port, slot;

port = 0; // 0 -> Connector 1, 1 -> Connector 2
slot = 0; // Always zero if not using multitap

Expand Down Expand Up @@ -101,15 +101,13 @@ static void ps2_joypad_poll(void)
unsigned players_count = PS2_MAX_PADS;
struct padButtonStatus buttons;

for (player = 0; player < players_count; player++)
{
for (player = 0; player < players_count; player++) {
unsigned j, k;
unsigned i = player;
unsigned p = player;

int ret = padRead(player, player, &buttons); // port, slot, buttons
if (ret != 0)
{
if (ret != 0) {
int32_t state_tmp = 0xffff ^ buttons.btns;

pad_state[i] = 0;
Expand Down
2 changes: 1 addition & 1 deletion retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3716,4 +3716,4 @@ struct retro_system_info *runloop_get_libretro_system_info(void)
char *get_retroarch_launch_arguments(void)
{
return launch_arguments;
}
}

0 comments on commit f48ffb9

Please sign in to comment.