Mednafen Members Members   Search Search   Help Help   Register Register   Login Login   Home Home
Home » Mednafen » Development » Fullscreen Frontend for NES ITX PC's (Windows)
Show: Today's Messages  :: Show Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Fullscreen Frontend for NES ITX PC's (Windows) [message #1239] Sat, 17 May 2008 01:42 Go to next message
patchwerk  [PM]
Greetings... I'm writing a public release version of the fullscreen frontend for Mednafen I wrote for my Mini-ITX in a NES shell whic is attached to my TV.

Obligatory screencap:

http://www.thepatchwerks.com/images/external/nesitx_screen01.jpg

It is written to be completely joystick driven (the reset button on the NES box is used to drop back from the emulator.. I'm trying to figure out a way to do so w/ the joystick, as I doubt many other people have a NES ITX rigged with a keyboard controller so the reset switch sends an Escape keypress), and I am adding a configuration tool so that people besides myself can customize their joystick mapping.

Here's my problem: in order to write the settings to the mednafen config file, I need to know how it derives the joystick's unique identifier. I'm using C# with managed Direct X, and can only pull a 16-byte GUID from the device listing, which does not match the 16-character hex string in the config file, no matter how I parse it out.

Does anyone know how I can pull the same identifier?

Oh, and if you're curious, yes, those are completely interactive graphics... god bless layered imaging in GDI+ =)

[Updated on: Sat, 17 May 2008 02:05]

Re: Fullscreen Frontend for NES ITX PC's (Windows) [message #1240 is a reply to message #1239 ] Sat, 17 May 2008 08:22 Go to previous messageGo to next message
Administrator  [PM]
uint64 GetJoystickUniqueID(SDL_Joystick *joystick)
{
 uint8 digest[16];
 int tohash[4];
 md5_context hashie;
 uint64 ret = 0;
 int x;

 tohash[0] = SDL_JoystickNumAxes(joystick);
 tohash[1] = SDL_JoystickNumBalls(joystick);
 tohash[2] = SDL_JoystickNumHats(joystick);
 tohash[3] = SDL_JoystickNumButtons(joystick);

 hashie.starts();
 hashie.update((uint8 *)tohash, sizeof(tohash));
 hashie.finish(digest);

 for(x=0;x<16;x++)
 {
  ret ^= (uint64)digest[x] << ((x & 7) * 8);
 }

 return(ret);
}


and

         Joysticks[n] = SDL_JoystickOpen(n);
         if(Joysticks[n])
         {
          UniqueID[n] = GetJoystickUniqueID(Joysticks[n]);

          int plusplus = 0;
          for(int x = 0; x < n; x++)
          {
           if(UniqueID[x] == UniqueID[n])
            plusplus++;
          }
          UniqueID[n] += plusplus;      // Work around hash collisions
          MDFN_printf(_("Joystick %d - %s - Unique ID: %016llx\n"), n, SDL_JoystickName(n), UniqueID[n]);
         }


The hashing code is obviously going to have a lot of collisions compared to a Windows GUID...

I think SDL uses WinMM joystick functions, so it may not always match up exactly with what DirectX reports, unfortunately.
Re: Fullscreen Frontend for NES ITX PC's (Windows) [message #1241 is a reply to message #1240 ] Sat, 17 May 2008 11:56 Go to previous messageGo to next message
patchwerk  [PM]
Ah, thank you! Actually, I've got SDL.NET, which returns precisely the values that this function is looking for, so that should work.

I just hate to have that SDL lib loaded right next to my nice, sleek little DX input wrapper. I may need to go back and rewrite all of it to work straight from SDL.NET altogether, and leave DX out of the mix.

Thanks for the code, I don't know how long it would have taken me to sift through the source on this... I've not touched C++ in a few years, and can't speed read it as well as I once could. =)


Re: Fullscreen Frontend for NES ITX PC's (Windows) [message #1242 is a reply to message #1239 ] Sat, 17 May 2008 15:38 Go to previous messageGo to next message
patchwerk  [PM]
Wow... I'm having no luck recreating that MD5 generator in C#. I think I may try to compile just that portion of the program (md5_context) as a standalone executable which takes four arguments, and returns the hash to stdout. My frontend can call it and capture the results.
Re: Fullscreen Frontend for NES ITX PC's (Windows) [message #1255 is a reply to message #1242 ] Fri, 30 May 2008 01:10 Go to previous messageGo to next message
MonkeeSage  [PM]
For calculating a MD5 sum for a file from c#:

using System;
using System.IO;
using System.Text;
using System.Security.Cryptography;

class test
{
    static int Main ()
    {
        StringBuilder sb = new StringBuilder();
        FileStream fs = new FileStream("some_blah_file.txt", FileMode.Open);
        MD5 md5 = new MD5CryptoServiceProvider();
        byte[] hash = md5.ComputeHash(fs);
        fs.Close();
        foreach (byte hex in hash)
            sb.Append(hex.ToString("x2"));
        Console.WriteLine(sb.ToString());
        return 0;
    }
}

[Updated on: Fri, 30 May 2008 03:30]

Re: Fullscreen Frontend for NES ITX PC's (Windows) [message #1257 is a reply to message #1255 ] Fri, 30 May 2008 20:07 Go to previous message
MonkeeSage  [PM]
Oh, sorry...you were trying to get an md5 from the joystick hash string from SDL I think? I didn't read the thread before I answered...for that you use the same method, you just use the byte version:

        . . .
        string jshash = "ce96ea6b9d7ca56a";
        StringBuilder sb = new StringBuilder();
        MD5 md5 = new MD5CryptoServiceProvider();
        ASCIIEncoding encoding = new ASCIIEncoding();
        byte[] hash = md5.ComputeHash(encoding.GetBytes(jshash));
        foreach (byte hex in hash)
            sb.Append(hex.ToString("x2"));
        . . .
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic:GTK+ frontend / launcher
Next Topic:7zip support
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ ]

Current Time: Sat May 18 04:08:55 CDT 2024
.:: Contact :: Home ::.

Powered by FUDforum.
Copyright © FUDforum Bulletin Board Software