[gnome-games] playstation: Add DiscImageTime



commit e2541850ead8a1e384aa964037ee0404ec95bf7a
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sat Jul 15 11:32:10 2017 +0200

    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

 plugins/playstation/src/Makefile.am       |    1 +
 plugins/playstation/src/disc-image-time.c |   77 +++++++++++++++++++++++++++++
 plugins/playstation/src/disc-image-time.h |   30 +++++++++++
 3 files changed, 108 insertions(+), 0 deletions(-)
---
diff --git a/plugins/playstation/src/Makefile.am b/plugins/playstation/src/Makefile.am
index 1b0067e..8e96934 100644
--- a/plugins/playstation/src/Makefile.am
+++ b/plugins/playstation/src/Makefile.am
@@ -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 \
diff --git a/plugins/playstation/src/disc-image-time.c b/plugins/playstation/src/disc-image-time.c
new file mode 100644
index 0000000..1973a75
--- /dev/null
+++ b/plugins/playstation/src/disc-image-time.c
@@ -0,0 +1,77 @@
+// 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);
+}
diff --git a/plugins/playstation/src/disc-image-time.h b/plugins/playstation/src/disc-image-time.h
new file mode 100644
index 0000000..79ea8ed
--- /dev/null
+++ b/plugins/playstation/src/disc-image-time.h
@@ -0,0 +1,30 @@
+// 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 */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]