Skip to content

Commit

Permalink
Create cpu_pause and implement (libretro#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
mahoneyt944 authored May 20, 2024
1 parent aed807f commit 5744d3e
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 12 deletions.
4 changes: 4 additions & 0 deletions src/cpuexec.c
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ static void watchdog_reset(void)
watchdog_counter = 3 * Machine->drv->frames_per_second;
}

WRITE_HANDLER( watchdog_disarm_w )
{
watchdog_counter = -1;
}

WRITE_HANDLER( watchdog_reset_w )
{
Expand Down
3 changes: 3 additions & 0 deletions src/cpuexec.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void mame_frame(void);
*
*************************************/

/* Used to disarm the watchdog while cpu is paused */
WRITE_HANDLER( watchdog_disarm_w );

/* 8-bit watchdog read/write handlers */
WRITE_HANDLER( watchdog_reset_w );
READ_HANDLER( watchdog_reset_r );
Expand Down
2 changes: 1 addition & 1 deletion src/drawgfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3521,7 +3521,7 @@ void draw_crosshair(struct mame_bitmap *bitmap,int x,int y,const struct rectangl
unsigned long black,white;
int i;

if (!options.crosshair_enable)
if (!options.crosshair_enable || cpu_pause_state)
return;

black = Machine->uifont->colortable[0];
Expand Down
48 changes: 38 additions & 10 deletions src/mame2003/mame2003.c
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,30 @@ int16_t get_pointer_delta(int16_t coord, int16_t *prev_coord)
return delta;
}

bool cpu_pause_state = false;

void cpu_pause(bool pause)
{
int cpunum;

for (cpunum = 0; cpunum < cpu_gettotalcpu(); cpunum++)
{
if (pause)
cpunum_suspend(cpunum, SUSPEND_REASON_DISABLE, 1);
else
cpunum_resume(cpunum, SUSPEND_ANY_REASON);
}

/* disarm watchdog to prevent reset */
if (pause) watchdog_disarm_w(0, 0);

/* update state */
if (pause)
cpu_pause_state = true;
else
cpu_pause_state = false;
}

void retro_run (void)
{
int i;
Expand Down Expand Up @@ -668,35 +692,39 @@ int osd_start_audio_stream(int stereo)
int osd_update_audio_stream(INT16 *buffer)
{
int i,j;
if ( Machine->sample_rate !=0 && buffer )
if ( Machine->sample_rate !=0 && buffer)
{
memcpy(samples_buffer, buffer, samples_per_frame * (usestereo ? 4 : 2));
if (cpu_pause_state)
memset(samples_buffer, 0, samples_per_frame * (usestereo ? 4 : 2));
else
memcpy(samples_buffer, buffer, samples_per_frame * (usestereo ? 4 : 2));
if (usestereo)
audio_batch_cb(samples_buffer, samples_per_frame);
else
{
for (i = 0, j = 0; i < samples_per_frame; i++)
{
{
conversion_buffer[j++] = samples_buffer[i];
conversion_buffer[j++] = samples_buffer[i];
}
audio_batch_cb(conversion_buffer,samples_per_frame);
}
audio_batch_cb(conversion_buffer,samples_per_frame);
}
if (cpu_pause_state)
return samples_per_frame;


//process next frame
/*process next frame */

if ( samples_per_frame != orig_samples_per_frame ) samples_per_frame = orig_samples_per_frame;

// dont drop any sample frames some games like mk will drift with time
/* dont drop any sample frames some games like mk will drift with time */

delta_samples += (Machine->sample_rate / Machine->drv->frames_per_second) - orig_samples_per_frame;
if ( delta_samples >= 1.0f )
{

int integer_delta = (int)delta_samples;
if (integer_delta <= 16 )
{
{
log_cb(RETRO_LOG_DEBUG,"sound: Delta added value %d added to frame\n",integer_delta);
samples_per_frame += integer_delta;
}
Expand All @@ -706,7 +734,7 @@ int osd_update_audio_stream(INT16 *buffer)

}
}
return samples_per_frame;
return samples_per_frame;
}


Expand Down
7 changes: 7 additions & 0 deletions src/mame2003/mame2003.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ int osd_skip_this_frame(void);
void osd_update_video_and_audio(struct mame_display *display);


/*
Pause or resume all active cpus, true->pause, false->resume.
*/
extern bool cpu_pause_state;
extern void cpu_pause(bool pause);


/******************************************************************************
Sound
Expand Down
9 changes: 8 additions & 1 deletion src/usrintrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ static void showcharset(struct mame_bitmap *bitmap)
pen_t *colortable = NULL;
static const struct rectangle fullrect = { 0, 10000, 0, 10000 };


/* mark the whole thing dirty */
ui_markdirty(&fullrect);

Expand Down Expand Up @@ -3274,6 +3274,8 @@ int handle_user_interface(struct mame_bitmap *bitmap)
setup_via_menu = 1;
setup_menu_init();
}

if (setup_active()) cpu_pause(true);
}

if (setup_selected && setup_via_menu && !options.display_setup)
Expand Down Expand Up @@ -3326,11 +3328,16 @@ int handle_user_interface(struct mame_bitmap *bitmap)
skip_tmap = 0;
tilemap_xpos = 0;
tilemap_ypos = 0;

cpu_pause(true);
}
}

if(toggle_gfx) showcharset(bitmap);

if (!setup_active() && !toggle_gfx && cpu_pause_state)
cpu_pause(false);

return 0;
}

Expand Down

0 comments on commit 5744d3e

Please sign in to comment.