Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ jobs:
- name: Build
run: |
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC=ON -DBUILD_SDLGPU=On -DBUILD_WITH_ALL=ON ..
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_STATIC=ON -DBUILD_SDLGPU=On -DBUILD_WITH_ALL=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ..
cmake --build . --parallel

- name: Deploy
Expand Down
43 changes: 20 additions & 23 deletions src/system/libretro/tic80_libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct tic80_state
int mouseHideTimer;
int mouseHideTimerStart;
tic80* tic;
retro_usec_t frameTime;
retro_perf_get_time_usec_t get_time_usec; // Function pointer for the high-res timer
};
static struct tic80_state* state = NULL;

Expand All @@ -90,7 +90,9 @@ static u64 tic80_libretro_counter()
return 0;
}

return (u64)state->frameTime;
// return the elapsed microseconds since the game started
// adjusted by fast-forward or slow motion.
return state->get_time_usec();
}

/**
Expand Down Expand Up @@ -155,17 +157,6 @@ void tic80_libretro_fallback_log(enum retro_log_level level, const char *fmt, ..
va_end(va);
}

/**
* libretro callback; Called to indicate how much time has passed since last retro_run().
*/
void tic80_libretro_frame_time(retro_usec_t usec) {
if (state == NULL) {
return;
}

state->frameTime += usec;
}

/**
* libretro callback; Global initialization.
*/
Expand Down Expand Up @@ -1116,16 +1107,6 @@ RETRO_API bool retro_load_game(const struct retro_game_info *info)
return false;
}

// Set up the frame time callback.
struct retro_frame_time_callback frame_time = {
.callback = tic80_libretro_frame_time,
.reference = TIC80_FREQUENCY / TIC80_FRAMERATE,
};
if (!environ_cb(RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK, &frame_time)) {
log_cb(RETRO_LOG_ERROR, "[TIC-80] Failed to set frame time callback.\n");
return false;
}

// Set up the TIC-80 environment.
#if RETRO_IS_BIG_ENDIAN
state->tic = tic80_create(TIC80_SAMPLERATE, TIC80_PIXEL_COLOR_ARGB8888);
Expand Down Expand Up @@ -1156,6 +1137,22 @@ RETRO_API bool retro_load_game(const struct retro_game_info *info)
return false;
}

// --- TIMING INITIALIZATION --- Start

// Performance callback struct
struct retro_perf_callback perf_cb = {0};
state->get_time_usec = NULL;

// Request the performance interface from the frontend
if (!(environ_cb(RETRO_ENVIRONMENT_GET_PERF_INTERFACE, &perf_cb) && perf_cb.get_time_usec)) {
log_cb(RETRO_LOG_ERROR, "[TIC-80] Failed to get high-resolution timer.\n");
return false;
}

state->get_time_usec = perf_cb.get_time_usec;

// --- TIMING INITIALIZATION --- End

// Set up the input descriptors.
tic80_libretro_input_descriptors();

Expand Down
Loading