[gnome-games/wip/exalm/sharp-x68000: 347/347] Add Sharp X68000 platform



commit d3fa1ce625e82bb3d785b2b756d96224c60fb2b0
Author: Exalm <exalm7659 gmail com>
Date:   Tue Apr 3 02:42:37 2018 +0500

    Add Sharp X68000 platform

 data/options/meson.build                           |   1 +
 data/options/px68k.options                         |   2 +
 data/org.gnome.Games.desktop.in.in                 |   3 +-
 flatpak/libretro-cores/px68k.libretro              |   9 +-
 meson_options.txt                                  |   1 +
 plugins/meson.build                                |   1 +
 plugins/sharp-x68000/data/meson.build              |   1 +
 plugins/sharp-x68000/data/sharp-x68000.plugin      |   6 +
 plugins/sharp-x68000/meson.build                   |   2 +
 plugins/sharp-x68000/src/meson.build               |  17 ++
 .../src/sharp-x68000-game-factory.vala             | 179 +++++++++++++++++++++
 plugins/sharp-x68000/src/sharp-x68000-plugin.vala  |  52 ++++++
 src/retro/retro-core-source.vala                   |   3 +-
 13 files changed, 272 insertions(+), 5 deletions(-)
---
diff --git a/data/options/meson.build b/data/options/meson.build
index 32a33ac6..39143968 100644
--- a/data/options/meson.build
+++ b/data/options/meson.build
@@ -2,6 +2,7 @@ options_files = [
   'desmume.options',
   'desmume2015.options',
   'pcsx_rearmed.options',
+  'px68k.options',
 ]
 
 install_data (options_files, install_dir: options_dir)
diff --git a/data/options/px68k.options b/data/options/px68k.options
new file mode 100644
index 00000000..9ad7b9c7
--- /dev/null
+++ b/data/options/px68k.options
@@ -0,0 +1,2 @@
+[Options]
+px68k_disk_path=disabled
diff --git a/data/org.gnome.Games.desktop.in.in b/data/org.gnome.Games.desktop.in.in
index fddc61f5..cccefa9d 100644
--- a/data/org.gnome.Games.desktop.in.in
+++ b/data/org.gnome.Games.desktop.in.in
@@ -12,4 +12,5 @@ X-GNOME-SingleWindow=true
 Type=Application
 StartupNotify=true
 Categories=GNOME;GTK;Player;Game;
-MimeType=application/vnd.nintendo.snes.rom;application/x-amiga-disk-format;application/x-atari-2600-rom;application/x-atari-7800-rom;application/x-atari-lynx-rom;application/x-cue;application/x-dc-rom;application/x-doom-wad;application/x-fds-disk;application/x-gameboy-color-rom;application/x-gameboy-rom;application/x-gamecube-rom;application/x-gamegear-rom;application/x-gba-rom;application/x-genesis-32x-rom;application/x-genesis-rom;application/x-love-game;application/x-mame-rom;application/x-ms-dos-executable;application/x-n64-rom;application/x-neo-geo-pocket-color-rom;application/x-neo-geo-pocket-rom;application/x-nes-rom;application/x-nintendo-ds-rom;application/x-pc-engine-rom;application/x-playstation-rom;application/x-saturn-rom;application/x-sega-cd-rom;application/x-sega-pico-rom;application/x-sg1000-rom;application/x-sms-rom;application/x-virtual-boy-rom;application/x-wii-rom;application/x-wii-wad;application/x-wonderswan-color-rom;application/x-wonderswan-rom;application/z
 ip;
+MimeType=application/vnd.nintendo.snes.rom;application/x-amiga-disk-format;application/x-atari-2600-rom;application/x-atari-7800-rom;application/x-atari-lynx-rom;application/x-cue;application/x-dc-rom;application/x-doom-wad;application/x-fds-disk;application/x-gameboy-color-rom;application/x-gameboy-rom;application/x-gamecube-rom;application/x-gamegear-rom;application/x-gba-rom;application/x-genesis-32x-rom;application/x-genesis-rom;application/x-love-game;application/x-mame-rom;application/x-ms-dos-executable;application/x-n64-rom;application/x-neo-geo-pocket-color-rom;application/x-neo-geo-pocket-rom;application/x-nes-rom;application/x-nintendo-ds-rom;application/x-pc-engine-rom;application/x-playstation-rom;application/x-saturn-rom;application/x-sega-cd-rom;application/x-sega-pico-rom;application/x-sg1000-rom;application/x-sms-rom;application/x-virtual-boy-rom;application/x-wii-rom;application/x-wii-wad;application/x-wonderswan-color-rom;application/x-wonderswan-rom;application/z
 ip;application/x-x68k-rom;
+
diff --git a/flatpak/libretro-cores/px68k.libretro b/flatpak/libretro-cores/px68k.libretro
index ec356c5e..06bc3190 100644
--- a/flatpak/libretro-cores/px68k.libretro
+++ b/flatpak/libretro-cores/px68k.libretro
@@ -8,8 +8,8 @@ Authors=hissorii;
 License=???;
 
 [Platform:SharpX68000]
-MimeType=application/x-x68k-rom;
-Firmwares=CGROM;IPLROM;
+MimeType=application/x-x68k-rom;application/x-x68k-xdf-rom;application/x-x68k-hdf-rom;
+Firmwares=CGROM;IPLROM;IPL30ROM;
 
 [Firmware:CGROM]
 Path=keropi/cgrom.dat
@@ -20,3 +20,8 @@ Mandatory=true
 Path=keropi/iplrom.dat
 MD5=7fd4caabac1d9169e289f0f7bbf71d8e
 Mandatory=true
+
+[Firmware:IPL30ROM]
+Path=keropi/iplrom30.dat
+MD5=f373003710ab4322642f527f567e020a
+Mandatory=false
diff --git a/meson_options.txt b/meson_options.txt
index fa589741..bf80e151 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -22,6 +22,7 @@ option ('nintendo-ds-plugin',   description: 'Support for Nintendo DS games',
 option ('playstation-plugin',   description: 'Support for PlayStation games',   type: 'boolean')
 option ('sega-cd-plugin',       description: 'Support for Sega CD games',       type: 'boolean')
 option ('sega-saturn-plugin',   description: 'Support for Sega Saturn games',   type: 'boolean')
+option ('sharp-x68000-plugin',  description: 'Support for Sharp X68000 games',  type: 'boolean')
 option ('steam-plugin',         description: 'Support for Steam games',         type: 'boolean')
 option ('turbografx-cd-plugin', description: 'Support for TurboGrafx-CD games', type: 'boolean')
 option ('virtual-boy-plugin',   description: 'Support for Virtual Boy games',   type: 'boolean')
diff --git a/plugins/meson.build b/plugins/meson.build
index f15025bb..8f88918d 100644
--- a/plugins/meson.build
+++ b/plugins/meson.build
@@ -11,6 +11,7 @@ plugins = [
   'playstation',
   'sega-cd',
   'sega-saturn',
+  'sharp-x68000',
   'steam',
   'turbografx-cd',
   'virtual-boy',
diff --git a/plugins/sharp-x68000/data/meson.build b/plugins/sharp-x68000/data/meson.build
new file mode 100644
index 00000000..0d4b6c49
--- /dev/null
+++ b/plugins/sharp-x68000/data/meson.build
@@ -0,0 +1 @@
+install_data (plugin_name + '.plugin', install_dir: plugins_dir)
diff --git a/plugins/sharp-x68000/data/sharp-x68000.plugin b/plugins/sharp-x68000/data/sharp-x68000.plugin
new file mode 100644
index 00000000..8070e816
--- /dev/null
+++ b/plugins/sharp-x68000/data/sharp-x68000.plugin
@@ -0,0 +1,6 @@
+[Plugin]
+Module=libgames-sharp-x68000-plugin
+Name=Sharp X68000 Plugin
+Description=Provides support for Sharp X68000 games.
+Authors=Alexander Mikhaylenko <exalm7659 gmail com>
+Copyright=Copyright © 2018 Alexander Mikhaylenko
diff --git a/plugins/sharp-x68000/meson.build b/plugins/sharp-x68000/meson.build
new file mode 100644
index 00000000..d7e84900
--- /dev/null
+++ b/plugins/sharp-x68000/meson.build
@@ -0,0 +1,2 @@
+subdir ('data')
+subdir ('src')
diff --git a/plugins/sharp-x68000/src/meson.build b/plugins/sharp-x68000/src/meson.build
new file mode 100644
index 00000000..abcb1f83
--- /dev/null
+++ b/plugins/sharp-x68000/src/meson.build
@@ -0,0 +1,17 @@
+vala_sources = [
+  'sharp-x68000-game-factory.vala',
+  'sharp-x68000-plugin.vala',
+]
+
+c_args = [
+  '-DG_LOG_DOMAIN="GamesSharpX68000"'
+]
+
+shared_module (
+  'games-' + plugin_name + '-plugin',
+  vala_sources,
+  dependencies: gnome_games_dep,
+  c_args: c_args,
+  install: true,
+  install_dir: plugins_dir
+)
diff --git a/plugins/sharp-x68000/src/sharp-x68000-game-factory.vala 
b/plugins/sharp-x68000/src/sharp-x68000-game-factory.vala
new file mode 100644
index 00000000..ed01bfba
--- /dev/null
+++ b/plugins/sharp-x68000/src/sharp-x68000-game-factory.vala
@@ -0,0 +1,179 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public class Games.SharpX68000GameFactory : Object, UriGameFactory {
+       private const string FINGERPRINT_PREFIX = "sharp-x68000";
+       private const string MIME_TYPE_DIM = "application/x-x68k-rom";
+       private const string MIME_TYPE_XDF = "application/x-x68k-xdf-rom";
+       private const string MIME_TYPE_HDF = "application/x-x68k-hdf-rom";
+       private const string MIME_TYPE_TGDB = "application/x-sharp-x68000-rom";
+       private const string PLATFORM = "SharpX68000";
+       private const string ICON_NAME = "media-floppy-symbolic";
+
+       private HashTable<string, PartialGameData?> uris_for_game;
+       private HashTable<Uri, Game> game_for_uri;
+       private GenericSet<Game> games;
+       private RetroPlatform platform;
+       private unowned GameCallback game_added_callback;
+
+       private struct PartialGameData {
+               Uri?[] uris;
+               string?[] titles;
+       }
+
+       public SharpX68000GameFactory (RetroPlatform platform) {
+               uris_for_game = new HashTable<string, PartialGameData?> (str_hash, str_equal);
+               game_for_uri = new HashTable<Uri, Game> (Uri.hash, Uri.equal);
+               games = new GenericSet<Game> (direct_hash, direct_equal);
+               this.platform = platform;
+       }
+
+       public string[] get_mime_types () {
+               return { MIME_TYPE_DIM, MIME_TYPE_XDF, MIME_TYPE_HDF };
+       }
+
+       public Game? query_game_for_uri (Uri uri) {
+               if (game_for_uri.contains (uri))
+                       return game_for_uri[uri];
+
+               return null;
+       }
+
+       public void add_uri (Uri uri) {
+               try {
+                       add_uri_with_error (uri);
+               }
+               catch (Error e) {
+                       debug (e.message);
+               }
+       }
+
+       private void add_uri_with_error (Uri uri) throws Error {
+               if (game_for_uri.contains (uri))
+                       return;
+
+               var file = uri.to_file ();
+               var file_info = file.query_info (FileAttribute.STANDARD_CONTENT_TYPE, 
FileQueryInfoFlags.NONE);
+               var mime_type = file_info.get_content_type ();
+
+               if (mime_type != MIME_TYPE_DIM && mime_type != MIME_TYPE_XDF && mime_type != MIME_TYPE_HDF)
+                       return;
+
+               var path = file.get_path ();
+               print ("%s\n", path);
+
+               var regex = /\((Dis[ck] (\d+)) of (\d+)\)/i;
+               MatchInfo match_info;
+               if (regex.match (path, 0, out match_info)) {
+                       // The game has multiple disks
+                       var title = match_info.fetch (1);
+                       var index = int.parse (match_info.fetch (2));
+                       var total = int.parse (match_info.fetch (3));
+                       print ("%d %d\n", index, total);
+
+                       if (index > 0 && total > 0) {
+                               var game_id = regex.replace (path, path.length, 0, "");
+                               print ("%s\n", game_id);
+                               if (!uris_for_game.contains (game_id))
+                                       uris_for_game.insert(game_id, { new Uri?[total], new string?[total] 
});
+                               uris_for_game.lookup(game_id).uris[index - 1] = uri;
+                               uris_for_game.lookup(game_id).titles[index - 1] = title;
+
+                               var data = uris_for_game.lookup(game_id);
+                               bool complete = true;
+                               foreach (var u in data.uris)
+                                       if (u == null) {
+                                               complete = false;
+                                               print ("null\n");
+                                       } else
+                                               print ("%s\n", u.to_string());
+                               print ("%d\n", complete ? 1 : 0);
+
+                               if (complete) {
+                                       var media_set = new MediaSet ();
+                                       for (var i = 0; i < total; i++) {
+                                               var media = new Media (new GenericTitle (data.titles[i]));
+                                               media.add_uri (data.uris[i]);
+                                               media_set.add_media (media);
+                                       }
+                                       media_set.icon_name = ICON_NAME;
+
+                                       var game = create_game (media_set, data.uris[0], mime_type);
+
+                                       foreach (var u in data.uris)
+                                               game_for_uri[u] = game;
+
+                                       games.add (game);
+                                       if (game_added_callback != null)
+                                               game_added_callback (game);
+                               }
+
+                               return;
+                       }
+               }
+
+               print ("The game is single-disk\n");
+
+               var game = create_game (null, uri, mime_type);
+
+               game_for_uri[uri] = game;
+               games.add (game);
+
+               if (game_added_callback != null)
+                       game_added_callback (game);
+/*
+//             File bin_file;
+//             var disc_id = uri.to_string
+
+               // Check whether we already have a media and by extension a media set
+               // and a game for this disc ID. If such a case, simply add the new URI.
+               if (media_for_disc_id.contains (disc_id)) {
+                       var media = media_for_disc_id.lookup (disc_id);
+                       media.add_uri (uri);
+                       game_for_uri[uri] = game_for_disc_set_id[disc_set_id];
+
+                       return;
+               }
+/*
+               var media_set = new MediaSet ();
+               foreach (var game_media in new_medias_array)
+                       media_set.add_media (game_media);
+               media_set.icon = GLib.Icon.new_for_string (ICON_NAME);
+               var game = create_game (media_set, disc_set_id, uri);
+
+               // Creating the Medias, MediaSet and Game worked, we can save them.
+
+               foreach (var new_disc_id in new_medias.get_keys ())
+                       media_for_disc_id[new_disc_id] = new_medias[new_disc_id];
+*/
+
+//             var game = create_game (uri);
+
+//             game_for_uri[uri] = game;
+//             games.add (game);
+
+//             game_added (game);
+       }
+
+       public void foreach_game (GameCallback game_callback) {
+               games.foreach ((game) => game_callback (game));
+       }
+
+       private Game create_game (MediaSet? media_set, Uri uri, string mime_type) throws Error {
+               var uid = new Uid (Fingerprint.get_uid (uri, FINGERPRINT_PREFIX));
+               var title = new FilenameTitle (uri);
+               var media = new GriloMedia (title, MIME_TYPE_TGDB);
+               var cover = new CompositeCover ({
+                       new LocalCover (uri),
+                       new GriloCover (media, uid)});
+
+               var game = new Game (uid, uri, title, platform);
+               game.media_set = media_set;
+               game.set_cover (cover);
+
+               return game;
+       }
+
+       public void set_game_added_callback (GameCallback game_callback) {
+               game_added_callback = game_callback;
+       }
+}
diff --git a/plugins/sharp-x68000/src/sharp-x68000-plugin.vala 
b/plugins/sharp-x68000/src/sharp-x68000-plugin.vala
new file mode 100644
index 00000000..e155ca17
--- /dev/null
+++ b/plugins/sharp-x68000/src/sharp-x68000-plugin.vala
@@ -0,0 +1,52 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.SharpX68000Plugin : Object, Plugin {
+       private const string MIME_TYPE_DIM = "application/x-x68k-rom";
+       private const string MIME_TYPE_XDF = "application/x-x68k-xdf-rom";
+       private const string MIME_TYPE_HDF = "application/x-x68k-hdf-rom";
+       private const string PLATFORM_ID = "SharpX68000";
+       private const string PLATFORM_NAME = _("Sharp X68000");
+       private const string PLATFORM_UID_PREFIX = "sharp-x68000";
+
+       private static RetroPlatform platform;
+
+       static construct {
+               string[] mime_types = { MIME_TYPE_DIM, MIME_TYPE_XDF, MIME_TYPE_HDF };
+               platform = new RetroPlatform (PLATFORM_ID, PLATFORM_NAME, mime_types, PLATFORM_UID_PREFIX);
+       }
+
+       public Platform[] get_platforms () {
+               return { platform };
+       }
+
+       public string[] get_mime_types () {
+               return { MIME_TYPE_DIM, MIME_TYPE_XDF, MIME_TYPE_HDF };
+       }
+
+       public UriGameFactory[] get_uri_game_factories () {
+               var factory = new SharpX68000GameFactory (platform);
+
+               return { factory };
+       }
+
+       public RunnerFactory[] get_runner_factories () {
+               var factory = new GenericRunnerFactory (create_runner);
+               factory.add_platform (platform);
+
+               return { factory };
+       }
+
+       private static Runner? create_runner (Game game) throws Error {
+               var core_source = new RetroCoreSource (platform);
+               var runner = new RetroRunner.from_source (game, core_source);
+
+               runner.input_capabilities = new GenericInputCapabilities (true, true);
+
+               return runner;
+       }
+}
+
+[ModuleInit]
+public Type register_games_plugin (TypeModule module) {
+       return typeof(Games.SharpX68000Plugin);
+}
diff --git a/src/retro/retro-core-source.vala b/src/retro/retro-core-source.vala
index cc0ad491..0bf7743e 100644
--- a/src/retro/retro-core-source.vala
+++ b/src/retro/retro-core-source.vala
@@ -63,9 +63,8 @@ public class Games.RetroCoreSource : Object {
 
                var platforms_dir = Application.get_platforms_dir ();
                var platform_id = platform.get_id ();
-               var firmware_dir = File.new_for_path (@"$platforms_dir/$platform_id/system");
                var firmware_path = core_descriptor.get_firmware_path (firmware);
-               var firmware_file = firmware_dir.get_child (firmware_path);
+               var firmware_file = File.new_for_path(@"$platforms_dir/$platform_id/system/" + firmware_path);
                if (!firmware_file.query_exists ())
                        throw new RetroError.FIRMWARE_NOT_FOUND (_("This game requires the %s firmware file 
to run."), firmware_file.get_path ());
 


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