don't click here

Gens MDP Plugins

Discussion in 'Engineering & Reverse Engineering' started by Top-Hatt, Aug 27, 2015.

  1. Top-Hatt

    Top-Hatt

    Member
    23
    0
    1
    slowly increasing memes
    So I was looking all over Google for documentation on the Gens/GS MDP Plugin system, and found absolutely nothing.

    So, I was wondering if anyone could educate me (and other Googlers in need) on how it works.

    Thanks a bunch!

    ~Top-Hatt
     
  2. GerbilSoft

    GerbilSoft

    RickRotate'd. Administrator
    2,971
    76
    28
    USA
    rom-properties
    MDP is currently a bit of a mess. I designed it so I could split out post-processing renderers from the main Gens/GS code base, then expanded it a bit to include some other stuff.

    The headers are here: http://www.dusers.drexel.edu/gitweb/gitweb.cgi/~korth/gens.git/tree/HEAD:/src/mdp

    Basically, an MDP plugin is a DLL (or shared library on Unix systems) that exports a single symbol: "mdp". This symbol is of type mdp_t, defined in mdp.h, and contains the following information:

    Code (Text):
    1.  
    2. typedef struct PACKED _mdp_t
    3. {
    4.     // Plugin version information.
    5.     const uint32_t interfaceVersion;
    6.     const uint32_t pluginVersion;
    7.  
    8.     // CPU flags.
    9.     const uint32_t cpuFlagsSupported;
    10.     const uint32_t cpuFlagsRequired;
    11.  
    12.     // UUID - each plugin must have a unique ID.
    13.     const unsigned char uuid[16];
    14.  
    15.     // Description.
    16.     mdp_desc_t *desc;
    17.  
    18.     // Functions.
    19.     mdp_func_t *func;
    20. } mdp_t;
    21.  
    I'll probably rework this structure to make more sense in MDP v1.1 in an upcoming release of Gens/GS II (though retaining compatibility). Among other things, the uint32_t values shouldn't be marked const. Anyways, here's what each of these fields are:

    • interfaceVersion: MDP interface version. The current version is 1.0, which is defined as MDP_VERSION(1,0,0) [or 0x01000000; use the macro]. The interface is designed such that minor version bumps are usually backwards-compatible, while major version bumps indicate the API has fundamentally changed. Plugins with a major interface version that doesn't match the emulator's version will not be loaded.
    • pluginVersion: Plugin version. Indicates the version of your plugin. Use MDP_VERSION(major,minor,revision) here.
    • cpuFlagsSupported: CPU flags supported by this plugin, e.g. MMX or SSE2. Flags are bitwise OR'd together and are defined in mdp_cpuflags.h.
    • cpuFlagsRequired: CPU flags required by this plugin. Some renderers included with Gens/GS require MMX, so they have the MMX flag set here. The emulator will refuse to load a plugin if it has a required flag set that your CPU doesn't support.
    • uuid: UUID uniquely identifying the plugin. Each plugin must have its own UUID, and the UUID should stay the same across plugin version updates.
    • desc: Pointer to an mdp_desc_t struct.
    • func: Pointer to an mdp_func_t struct.
    mdp_desc_t is a struct describing the plugin:

    Code (Text):
    1.  
    2. typedef struct PACKED _mdp_desc_t
    3. {
    4.     const char* name;
    5.     const char* author_mdp;
    6.     const char* author_orig;
    7.     const char* description;
    8.     const char* website;
    9.     const char* license;
    10.  
    11.     /* Filler for alignment purposes. */
    12.     const void* reserved1;
    13.     const void* reserved2;
    14.  
    15.     /* Icon data. (PNG format) */
    16.     const unsigned char* icon;
    17.     const unsigned int iconLength;
    18. } mdp_desc_t;
    19.  
    Fields:

    • name: Name of the plugin.
    • author_mdp: Author of the plugin, I.e. you.
    • author_orig: Author of the original code provided by the plugin. This is typically used when packaging someone else's renderer in MDP format. May be NULL if the entire plugin was written by you.
    • description: Description of the plugin.
    • website: URL of the plugin's website.
    • license: License, e.g. "GPL-2".
    • icon: C array containing a PNG-format icon. (32x32)
    • iconLength: Size of the icon array.
    Finally, mdp_func_t:

    Code (Text):
    1.  
    2. typedef int (MDP_FNCALL *mdp_init_fn)(const mdp_host_t *host_srv);
    3. typedef int (MDP_FNCALL *mdp_end_fn)(void);
    4.  
    5. typedef struct PACKED _mdp_func_t
    6. {
    7.     // Init/Shutdown functions
    8.     mdp_init_fn     init;
    9.     mdp_end_fn      end;
    10. } mdp_func_t;
    11.  
    Fields:

    • init: Function to call when the plugin is loaded. A parameter containing an mdp_host_t struct is passed to this function. This struct, defined by mdp_host_t, contains function pointers that allow the plugin to register rendering plugins, read/write ROM data, and other things.
    • end: Function to call when the plugin is unloaded.
    Note that Gens/GS does not currently support dynamic loading of plugins, so init() is always called when the emulator is started, and end() is always called when the emulator is closed.

    When I reimplement MDP in Gens/GS II, I'll work on improving the headers to remove some cruft, and I'll include some "sample" plugins that can be used as a starting point.
     
  3. Top-Hatt

    Top-Hatt

    Member
    23
    0
    1
    slowly increasing memes
    Oh awesome! Thanks!

    However, I have another question: Say somebody wanted to pull a value from a game's SRAM, and store it in a variable. How would I do that?

    I really appreciate the help!

    ~Top-Hatt
     
  4. GerbilSoft

    GerbilSoft

    RickRotate'd. Administrator
    2,971
    76
    28
    USA
    rom-properties
    mdp_host_t has functions for reading and writing emulated memory blocks. Unfortunately, MDP 1.0 doesn't have SRAM defined, so you can't access it using an MDP plugin right now.

    Some other memory spaces that are currently missing:
    - VSRAM
    - Sprite Attribute Table cache (probably not needed...)
    - /TIME area (for SRAM control)
    - TMSS registers

    All of these will be added to MDP 1.1 sometime later.
     
  5. Top-Hatt

    Top-Hatt

    Member
    23
    0
    1
    slowly increasing memes
    Alrighty! I'll definitely look more into this whole plugin thing. Again, thank you so much for the help!
    ~Top-Hatt
     
  6. Top-Hatt

    Top-Hatt

    Member
    23
    0
    1
    slowly increasing memes
    Sorry about this, but I just realized I have no idea how to do a lot of this. ¯\_(?)_/¯

    So, here are a few questions, if you don't mind:
    • How do I compile this?
    • How can this interact with the types of RAM allowed?
    • Are there disassembled examples out there?
    • Can MDP plugins interact with the host's filesystem?
    Thanks!

    ~Top-Hatt
     
  7. GerbilSoft

    GerbilSoft

    RickRotate'd. Administrator
    2,971
    76
    28
    USA
    rom-properties
    The MDP interface is a bunch of headers. You basically need to add them to a project, then write some code that makes use of it.

    You can read and write to the exposed memory. There's no watch functionality right now.

    The Gens/GS r7+ code base does have plugin source included, but it's a bit of a mess right now.

    MDP plugins are standard DLLs (or shared libraries on Linux). They have the same access to the host that the main program has.
     
  8. Top-Hatt

    Top-Hatt

    Member
    23
    0
    1
    slowly increasing memes
    Project...?
    Could you post an example?
    [hr]

    I really have no idea what's going on, but this thread is helping a lot! Thanks!

    ~Top-Hatt
     
  9. GerbilSoft

    GerbilSoft

    RickRotate'd. Administrator
    2,971
    76
    28
    USA
    rom-properties
    I don't have any ready-to-use "example" projects for MDP right now. I'll consider making one when I reimplement MDP in Gens/GS II.

    Incidentally, since you don't seem to know what a "project" is: Have you done any programming before, and if so, in what languages?
     
  10. Top-Hatt

    Top-Hatt

    Member
    23
    0
    1
    slowly increasing memes
    Oh jeez, I just realized how dumb I just sounded.

    Let me clear this up: I was asking what program this "project" would be in. I was (and still am) confused; is it a SonLVL project? A .NET project? A VB project?

    Also, I have worked with a few languages; General webdev, x86, 68k, C, and, if it counts, bash scripting.
    I mostly work with 68k.

    However, I have absolutely no concept of Windows applications or DLL extensions.

    Thank you so much for the help!
    (I'm really sorry if I'm pissing you off; please tell me if I am.)

    ~Top-Hatt
     
  11. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,743
    338
    63
    SonLVL
    SonLVL is a tool for editing levels in Sonic games, not a programming environment; .NET is a runtime, not a language, so there is no such thing as a ".NET project"; a VB project would only work if you were programming in VB, which is highly inadvisable for MDP.

    You say you have worked with C, if it was anything involving more than one or two .c files, you should have used some kind of tool that allows grouping together multiple source files into one output file, which is called a project. For example, Visual Studio, Code::Blocks, makefiles.

    If you're working from Linux or another Unix based OS, you will be making shared libraries (.so), not DLL files, unless you want to cross-compile for Windows.

    + - Also, it's really unnecessary to sign your posts, we can see your name right there.  
     
  12. Top-Hatt

    Top-Hatt

    Member
    23
    0
    1
    slowly increasing memes
    Thank you for correcting me; doing things like that is really helping me learn the ropes of this stuff.

    Also, I have used C, but only with SGDK; I can only imagine how different from C (in the application sense) that is.

    Thanks for pointing out Code::Blocks, I'll be sure to look into how it works.

    Overall, I'm sure I can try to put the pieces together from here.

    Thanks a bunch!
    ~Top-Hatt
     
  13. Cinossu

    Cinossu

    Administrator
    2,832
    44
    28
    London, UK
    Sonic the Hedgehog Extended Edition
    'tis good to see interest in MDP plugins again; when I did SonMP3 and the Retro Channel one at the time I used an existing plugin's source as a template, stripped it right the way down, and used that as a base. It worked quite well, and will do until a template or other example comes along. :U
     
  14. Top-Hatt

    Top-Hatt

    Member
    23
    0
    1
    slowly increasing memes
    Just as a side note, Cinossu, do you think that you could send me the source for rchan (or any other plugin for that matter)?

    (Also what the heck everything is rainbow in this thread)
     
  15. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    It is not so much "everything", but "everything, as long as a post by Cinossu is visible". + - Unless you block rotatecolour.gif, in which case it stops.