• Lucid Dreaming - Dream Views




    Results 1 to 12 of 12

    Hybrid View

    1. #1
      Wololo Achievements:
      Created Dream Journal Tagger Second Class 1000 Hall Points Made lots of Friends on DV Populated Wall Referrer Bronze Veteran First Class
      Supernova's Avatar
      Join Date
      Jul 2009
      LD Count
      Gender
      Location
      Spiral out, keep going.
      Posts
      2,909
      Likes
      908
      DJ Entries
      10

      Any suggestions? (C++ reading from file)

      Partly for the learning experience and partly just for the awesomeness of the finished product, I'm starting work on a multi-system game emulator. I'm planning on including MAME, C64, NES, SNES, N64 (depending on hardware), and any other consoles I think to add. Eventually I'm going to be buying some low-spec hardware to run it on and coming up with some sort of case (may use a NES case if I go with a small-enough motherboard, that does induce limitations though).

      Anyway, the point of this thread. Step 1 for me right now is writing a GUI program that will allow the user to select an emulator, and from there select a ROM from a list generated from a file containing a list of all available ROMs. It then writes a single command to a batch file which launches the selected emulator with the selected ROM (I already have that part pretty much figured out).

      The next step is to figure out how to read the ROM names from the file (I'll worry about generating the file later) and use that to list the available options for the user. I'm thinking maybe a plain .txt file would be easiest - one ROM name per line, then the program reads each line and inserts them as strings into an array so that any one can be referenced by number later (and inserted into the batch file).

      Partly due to my inexperience, I've started out working on this program by getting the most basic element working and adding things from there. Here's what I've done today:

      Code:
      #include <iostream>
      #include <fstream>
      #include <stdlib.h>
      
      using namespace std;
      
      void launcher();
      
      string emuname;
      string gamename;
      
      int main()
      {
          int gameno = 0;
      
          cout << "Hello.\n" "Enter a number to select a game.\n";
          while (true)
          {
          cout << "\n 1. Donkey Kong Country" "\n 2. Super Mario World" "\n 3. The Legend of Zelda: A Link To The Past" "\n enter 0 to quit\n";
          cin >> gameno;
          if (gameno == 1)
          {
              emuname = "zsnesw.exe";
              gamename = "\"Donkey Kong Country.zip\"";
              launcher();
          }
          else if (gameno == 2)
          {
              emuname = "zsnesw.exe";
              gamename = "\"Super Mario World.zip\"";
              launcher();
          }
          else if (gameno == 3)
          {
              emuname = "zsnesw.exe";
              gamename = "\"Zelda - A Link to the Past.zip\"";
              launcher();
          }
          else if (gameno ==0)
          break;
      
          else
          cout << "Invalid selection.  Choices are:";
          }
          return 0;
          }
      
      void launcher ()
      {
              ofstream myfile;
              myfile.open ("temp.bat", ios::in | ios::trunc);
              myfile << emuname << " " << gamename;
              myfile.close();
              system("temp.bat");
      }
      Would an approach like what I've described above work, or is there a better approach? More importantly, would that approach be useful when I'm ready to start building a GUI? I've never really done much with reading/writing to/from files before, so any tips are appreciated.

    2. #2
      Achievements:
      Veteran First Class 5000 Hall Points
      reci's Avatar
      Join Date
      Feb 2008
      LD Count
      18
      Gender
      Location
      -
      Posts
      380
      Likes
      90
      To clear up, on what machine will this 'emulator' be running? (i.e. computer, game console)

      What will be the controller(s)? (i.e. keyboard + mouse, game console controller, etc)

      Will you be writing the emulator for these games/consoles, or will your program solely consist of a GUI to select one of many games (and call an external program to start the emulation)?
      (if the former, I think you're in over your head)



      Will respond more thoroughly after the above is clear.
      Tutorial: How to Fall Asleep Faster
      You are dreaming.Do a reality check.

    3. #3
      Wololo Achievements:
      Created Dream Journal Tagger Second Class 1000 Hall Points Made lots of Friends on DV Populated Wall Referrer Bronze Veteran First Class
      Supernova's Avatar
      Join Date
      Jul 2009
      LD Count
      Gender
      Location
      Spiral out, keep going.
      Posts
      2,909
      Likes
      908
      DJ Entries
      10
      Quote Originally Posted by reci View Post
      To clear up, on what machine will this 'emulator' be running? (i.e. computer, game console)

      What will be the controller(s)? (i.e. keyboard + mouse, game console controller, etc)

      Will you be writing the emulator for these games/consoles, or will your program solely consist of a GUI to select one of many games (and call an external program to start the emulation)?
      (if the former, I think you're in over your head)



      Will respond more thoroughly after the above is clear.
      The emulators will be running on a PC, hopefully under Windows XP. Ultimately I would like the GUI to be navigable using only a game controller (N64 controller is one candidate, with USB adapters). The program is only going to be a frontend which will launch one of several emulators with the proper command line arguments (specifically, the name of the ROM file to load into the emulator).

      If I were intending to actually write all these emulators I'd be in way, waaaay over my head

      A note if you want to compile that code: I've just been tossing the .exe into a folder with zsnesw.exe and the 3 roms I used, whose filenames are found in the code. However, I've also (due I believe to the use of stdlib.h) had to put libgcc_s_dw2-1.dll and libstdc++-6.dll in the folder to get it to run; something's up with my compiler settings but that's a separate issue and I have an easy workaround for now.
      Last edited by Supernova; 08-26-2012 at 02:51 AM.

    4. #4
      Achievements:
      Veteran First Class 5000 Hall Points
      reci's Avatar
      Join Date
      Feb 2008
      LD Count
      18
      Gender
      Location
      -
      Posts
      380
      Likes
      90
      Okay, that sounds reasonable

      The launcher() function should have emuname and gamename as parameters and not global variables...
      And rather than writing a .bat with those, calling system(emuname+" "+gamename);, or the like, would probably be simpler, no?

      On the organization of ROM files; you could have them manually typed in a text file, but that would take much time if adding to your collection of games. I suggest having your program scan a folder structure like the following and associate the games based on which console folder they belong:

      • Console 1
        • Game 1
        • Game 2
      • Console 2
        • Game 3
      • Console 3
        • Game 4
        • Game 5


      And when selecting a game, the console folder containing the game determines what emuname to use.



      Good luck on this. Having it all self-contained sounds like it would make for a better gaming experience!
      Last edited by reci; 08-26-2012 at 03:55 AM.
      Tutorial: How to Fall Asleep Faster
      You are dreaming.Do a reality check.

    5. #5
      Wololo Achievements:
      Created Dream Journal Tagger Second Class 1000 Hall Points Made lots of Friends on DV Populated Wall Referrer Bronze Veteran First Class
      Supernova's Avatar
      Join Date
      Jul 2009
      LD Count
      Gender
      Location
      Spiral out, keep going.
      Posts
      2,909
      Likes
      908
      DJ Entries
      10
      Quote Originally Posted by reci View Post
      Okay, that sounds reasonable

      The launcher() function should have emuname and gamename as parameters and not global variables...
      And rather than writing a .bat with those, calling system(emuname+" "+gamename);, or the like, would probably be simpler, no?

      On the organization of ROM files; you could have them manually typed in a text file, but that would take much time if adding to your collection of games. I suggest having your program scan a folder structure like the following and associate the games based on which console folder they belong:
      Yeah, I started out with emuname and gamename being passed to launcher() as parameters, and to be honest I don't remember exactly why I tried global variables
      Running the one command directly via system(emuname+" "+gamename); would indeed be simpler - apparently I didn't do enough research into the system() function.

      I think at one point I was imagining a separate .exe which could be run to generate a list whenever changes were made, but I guess just merging that into the main program would be a better idea. What would be the typical procedure for scanning a folder structure like the one you described?

    6. #6
      Rational Spiritualist DrunkenArse's Avatar
      Join Date
      May 2009
      Gender
      Location
      Da Aina
      Posts
      2,941
      Likes
      1092
      Quote Originally Posted by Supernova View Post
      Yeah, I started out with emuname and gamename being passed to launcher() as parameters, and to be honest I don't remember exactly why I tried global variables
      If I was caught doing something like that (not that I do things like that), I'd probably blame it on satan
      Previously PhilosopherStoned

    7. #7
      Achievements:
      Veteran First Class 5000 Hall Points
      reci's Avatar
      Join Date
      Feb 2008
      LD Count
      18
      Gender
      Location
      -
      Posts
      380
      Likes
      90
      Let me google that for you

      And yes, I would imagine having it all in one .exe would be best.

      Having the "folder scanner" run its scan every time the "game select" screen is accessed.
      And perhaps a refresh button on that screen to re-scan the folders.

      Do post a published version, as others may find it useful
      Tutorial: How to Fall Asleep Faster
      You are dreaming.Do a reality check.

    8. #8
      Wololo Achievements:
      Created Dream Journal Tagger Second Class 1000 Hall Points Made lots of Friends on DV Populated Wall Referrer Bronze Veteran First Class
      Supernova's Avatar
      Join Date
      Jul 2009
      LD Count
      Gender
      Location
      Spiral out, keep going.
      Posts
      2,909
      Likes
      908
      DJ Entries
      10
      Hmm. Looks like this particular problem is a little more complicated than I anticipated. I did turn up this: Filesystem V3 Reference , but I don't really know anything about the Boost libraries.

      It probably helps that of the classes I start tomorrow, one is a CS course taught from the book Problem Solving With C++

      Also this could drag on for some time, especially as I'm starting classes, but I definitely intend to publish all this when It's in a working state.

    9. #9
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      You should come into IRC more often.

    10. #10
      Wololo Achievements:
      Created Dream Journal Tagger Second Class 1000 Hall Points Made lots of Friends on DV Populated Wall Referrer Bronze Veteran First Class
      Supernova's Avatar
      Join Date
      Jul 2009
      LD Count
      Gender
      Location
      Spiral out, keep going.
      Posts
      2,909
      Likes
      908
      DJ Entries
      10
      Hey guys. Just a quick update. Haven't really been moving on this lately while I got settled into my college schedule. I sat down just a bit ago with the intent of removing the write to the .bat (and thus removing launcher() as well). I ran into some trouble with system() however, from what I gather it seems it will only take a single string constant as an argument, and I'm not sure how I'm going to incorporate the string variables into that. Google hasn't turned up much yet (I found some reference material here but nothing that I could work out a solution from. I have to be up for work tomorrow morning, so I'm gonna pick up on this some time tomorrow.

    11. #11
      Banned
      Join Date
      May 2007
      LD Count
      Loads
      Gender
      Location
      Digital Forest.
      Posts
      6,864
      Likes
      386
      String::c_str()

    Similar Threads

    1. file sharing
      By LucidFlanders in forum The Lounge
      Replies: 34
      Last Post: 12-10-2008, 10:03 PM
    2. Could someone shrink this file?
      By Reality_is_a_Dream in forum Tech Talk
      Replies: 7
      Last Post: 07-26-2008, 04:10 PM
    3. Suggestions for reading material:
      By cleef in forum Lucid Aids
      Replies: 5
      Last Post: 11-30-2007, 07:07 PM

    Bookmarks

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •