Commit e2541850 authored by Adrien Plazas's avatar Adrien Plazas
Browse files

playstation: Add DiscImageTime

This will be used in a subsequent commit to parse PlayStation disc
images.

https://bugzilla.gnome.org/show_bug.cgi?id=775255
parent 0524c14f
......@@ -36,6 +36,7 @@ libgames_playstation_plugin_la_DEPENDENCIES = \
libgames_playstation_plugin_la_SOURCES = \
$(BUILT_SOURCES) \
disc-image-time.c \
playstation-error.vala \
playstation-game-factory.vala \
playstation-header.vala \
......
// This file is part of GNOME Games. License: GPL-3.0+.
#include "disc-image-time.h"
/* Private */
#define GAMES_DISC_IMAGE_FRAMES_PER_SECOND 75
static void
games_disc_image_time_get_minute_second_frame (const GamesDiscImageTime *time,
guint8 *minute,
guint8 *second,
guint8 *frame)
{
*minute = time->minute;
*second = time->second;
*frame = time->frame;
}
/* Public */
void
games_disc_image_time_set_minute_second_frame (GamesDiscImageTime *time,
guint8 minute,
guint8 second,
guint8 frame)
{
time->minute = minute;
time->second = second;
time->frame = frame;
}
void
games_disc_image_time_set_from_time_reference (GamesDiscImageTime *time,
guint8 *time_reference)
{
gint32 block; // The value of the clock containing the target time
int minute, second, frame;
block = GINT32_FROM_LE (*((gint32 *) time_reference));
block += 2 * GAMES_DISC_IMAGE_FRAMES_PER_SECOND;
minute = block / (60 * GAMES_DISC_IMAGE_FRAMES_PER_SECOND);
block = block - minute * (60 * GAMES_DISC_IMAGE_FRAMES_PER_SECOND);
second = block / GAMES_DISC_IMAGE_FRAMES_PER_SECOND;
frame = block - second * GAMES_DISC_IMAGE_FRAMES_PER_SECOND;
games_disc_image_time_set_minute_second_frame (time, minute, second, frame);
}
gint
games_disc_image_time_get_sector (const GamesDiscImageTime *time)
{
guint8 minute, second, frame;
games_disc_image_time_get_minute_second_frame (time, &minute, &second, &frame);
return (minute * 60 + second - 2) * GAMES_DISC_IMAGE_FRAMES_PER_SECOND + frame;
}
void
games_disc_image_time_increment (GamesDiscImageTime *time)
{
guint8 minute, second, frame;
games_disc_image_time_get_minute_second_frame (time, &minute, &second, &frame);
frame++;
if (frame == GAMES_DISC_IMAGE_FRAMES_PER_SECOND) {
frame = 0;
second++;
if (second == 60) {
second = 0;
minute++;
}
}
games_disc_image_time_set_minute_second_frame (time, minute, second, frame);
}
// This file is part of GNOME Games. License: GPL-3.0+.
#ifndef DISC_IMAGE_TIME_H
#define DISC_IMAGE_TIME_H
#include <glib.h>
G_BEGIN_DECLS
typedef struct _GamesDiscImageTime GamesDiscImageTime;
struct _GamesDiscImageTime {
guint8 minute;
guint8 second;
guint8 frame;
};
void games_disc_image_time_set_minute_second_frame (GamesDiscImageTime *time,
guint8 minute,
guint8 second,
guint8 frame);
void
games_disc_image_time_set_from_time_reference (GamesDiscImageTime *time,
guint8 *time_reference);
gint games_disc_image_time_get_sector (const GamesDiscImageTime *time);
void games_disc_image_time_increment (GamesDiscImageTime *time);
G_END_DECLS
#endif /* DISC_IMAGE_TIME_H */
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment