Retro Uprising
  Home Game Menu Rules and FAQs Forum Community Chat Today's Posts Search Register  
Go Back   Retro Uprising > Other > Programmers Developers Designers

Reply
 
Thread Tools Search this Thread Display Modes
Old 07-23-2012, 12:40 PM   #1
Kong's Avatar
 
Kong

C++ and MAME

We use the emulators MAME (Coin Op games) and MESS (Console Score Mode).

We use version .135.
Our beta emulators are .141.
In version .143 MAME switched from C to C++.
MAME is currently up to version .146.

I barely know C or C++. Converting all of my code to the new version is extremely hard and slow for me and not fun.

If anyone is interested in finishing up version .141 or converting everything to version .143 or .146 let me know.
My SignatureDisplay Signature Reply With Quote
Old 08-02-2014, 03:13 PM   #2
Kong's Avatar
 
Kong

Re: C++ and MAME

Attached is my mame makefile.

I have added libcurl to it so I can communicate with server.

I want to add a progress bar when uploading and downloading files.

The progress bar needs to be on a separate thread so it updates. I think that means I need a new window.

I am using this
libcurl - curlgtk.c

Which uses GTK for the progress bar.

I think I have everything set up correctly except I need to add this
Code:
pkg-config --cflags gtk+-2.0
somewhere in the make file. Where? Thanks.


If you have an alternative option to add a progress bar that would work too.
Attached Files
File Type: txt makefile.txt (23.9 KB, 0 views)
My SignatureDisplay Signature Reply With Quote
Old 08-04-2014, 03:07 PM   #3
Kong's Avatar
 
Kong

Re: C++ and MAME

Uggh. Feel like that might have been a waste of time.
Got it working but i had to include 20 DLLs that doubled the file size from 7MB to 15mb after compression.

The progress bar for transferring movies, scores, saves etc is as big as the entire rest of mame. I feel like there has to be a better way.

---------- Post added 08-04-2014 at 04:07 PM ---------- Previous post was 08-03-2014 at 11:50 AM ----------

Works with native windows code. No added bloat. Total file size still about 7mb.

I should take a C class. That was way harder than it should have been. About 50 lines of code, took over 15 hours of trial and error work with nearly no breaks.
My SignatureDisplay Signature Reply With Quote
Old 08-04-2014, 08:21 PM   #4
Seahawk's Avatar
Regular Poster
4,154 posts
Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!
View Stats
 
Seahawk

Re: C++ and MAME

Cplusplus.com is a good reference to have open in a tab while coding.
Reply With Quote
Old 08-08-2014, 07:47 PM   #5
Kong's Avatar
 
Kong

Re: C++ and MAME

I'll check it out.

I can usually get the coding that I want quick and easy. The part that hangs me up is the basic stuff like libraries, includes, threads, types, compiling, all the stuff that isn't part of php. Plus php.net provides way better documantation than anything I've found for c. And I'm not very good with oop even in php.

The last day was hell, but I'm feeling pretty good about the rest of it. Most of the remaining I have done before.

I'm going to switch over to N64 for a few days though.

---------- Post added 08-08-2014 at 08:03 PM ---------- Previous post was 08-04-2014 at 09:56 PM ----------

MAME disables "realloc". Defines it as "__error_realloc_is_dangerous__"

How can I rewrite this line so it is not using realloc?
newbuff=realloc(url->buffer,url->buffer_len + (size - rembuff));

It comes from here
libcurl - fopen.c


Thanks.

---------- Post added at 08:47 PM ---------- Previous post was at 08:03 PM ----------

Nevermind. I think I got it.
Code:
void *updateSize(void* p, size_t OldLength, size_t NewLength) {
  void *p2 = malloc(NewLength);
  if (p && p2) {
    memcpy(p2, p, OldLength < NewLength ? OldLength : NewLength);
  }
  if (p2 || (NewLength == 0)) {
    if (p)
    free(p);  // Note A
  }
  return p2;
}
newbuff=updateSize(url->buffer,url->buffer_len, url->buffer_len + (size - rembuff));
My SignatureDisplay Signature Reply With Quote
Old 08-08-2014, 08:08 PM   #6
Seahawk's Avatar
Regular Poster
4,154 posts
Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!
View Stats
 
Seahawk

Re: C++ and MAME

You should check that p2 is not a null pointer after the call to malloc. If the call to malloc fails then p2 is assigned null and the function returns it, causing newbuff to be null as well. The pointer p is also lost.
Reply With Quote
Old 08-08-2014, 09:46 PM   #7
Kong's Avatar
 
Kong

Re: C++ and MAME

Like this?
Code:
void *updateSize(void* p, size_t OldLength, size_t NewLength) {
  void *p2 = malloc(NewLength);
  if(p2 == NULL) {
	return NULL;
  }
  if (p && p2) {
    memcpy(p2, p, OldLength < NewLength ? OldLength : NewLength);
  }
  if (p && (p2 || (NewLength == 0))) {
    free(p); 
  }
  return p2;
}
My SignatureDisplay Signature Reply With Quote
Old 08-08-2014, 10:58 PM   #8
Seahawk's Avatar
Regular Poster
4,154 posts
Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!
View Stats
 
Seahawk

Re: C++ and MAME

Code:

// Copy memory block to a new, larger location
void *updateSize(void* p, size_t OldLength, size_t NewLength)
{
     void *p2 = malloc(NewLength); // Allocate the new block with the new size
     if(p2 == NULL)                // Check if malloc failed
          return NULL;

     if(p)                         // Check p only, we already checked if p2 was not null
          memcpy(p2, p, OldLength < NewLength ? OldLength : NewLength);

     if(NewLength == 0)            // Again, already checked p2. Also already checked p.
          free(p);                 // Delete the old block
     return p2;                    // Return the pointer for the new block
}
I am not sure why you are checking for if the size is 0, especially AFTER you've tried the memory copy...
Reply With Quote
Old 08-09-2014, 09:14 AM   #9
Kong's Avatar
 
Kong

Re: C++ and MAME

I just copied the original from here.
Trying to rewrite realloc function in c - Stack Overflow


I used your version but changed the final if to this.
Quote:
if (p) {
free(p);
Is working great. Thanks.

All file reads and writes can optionally be done on server and memory now with a progress bar.

Will try using online nvram in trivia games to make them random and save the server nvram with the inp so the movie plays back.
My SignatureDisplay Signature Reply With Quote
Old 08-09-2014, 11:30 AM   #10
Seahawk's Avatar
Regular Poster
4,154 posts
Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!Seahawk has earned the ear of the admin. Watch yourself!
View Stats
 
Seahawk

Re: C++ and MAME

Quote:
Originally Posted by chux on stackoverflow
Note A: There is an interesting issue when NewLength == 0. Some malloc(0) implementations return NULL, others return a pointer to "no data". In the former, a NULL pointer does not always imply a failed malloc()
I hate how after so many years some bits of C/C++ are not guaranteed to act the same on every compiler or machine. This uncertainty is probably why MAMEdev disabled the function. This new version takes this uncertainty into account.

Code:
// Copy memory block to a new, different size location
void *updateSize(void* p, size_t OldLength, size_t NewLength)
{
     void *p2 = malloc(NewLength); // Allocate the new block with the new size
     if(p2 == NULL || NewLength == 0 || p == NULL) // Check that p and p2 are not null, and that NewLength is a valid value
          return NULL; 

     memcpy(p2, p, OldLength < NewLength ? OldLength : NewLength); // Copy to the new block
     free(p);   // Delete the old block
     return p2; // Return the pointer for the new block
}


You don't have to change it if yours is working.

Last edited by Seahawk; 08-09-2014 at 11:50 AM..
Reply With Quote
Old 08-10-2014, 12:19 PM   #11
Kong's Avatar
 
Kong

Re: C++ and MAME

MARP is supposed to have a program that let's them detect auto fire in INPs.

If a button is pressed at an exact frequency with no irregularities then it flags it as auto fire.

Anyone feel like duplicating the functionality? I am not.

I'm going to upload the game controller name with the inp so if it matches a brand name that has rapid fire then we will at least know that it is an available option for them.
My SignatureDisplay Signature Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the mouse in Mame lightgun games hackeynut Retro Uprising Support 11 12-14-2015 07:50 AM
im buildind a mame cabinet Slime Slayer Help 30 08-05-2012 11:24 PM
RU MAME fails to pick up my GlovePIE signals supernintendosp Retro Uprising Support 3 08-05-2012 09:44 AM
New Donkey Kong World Record [MAME] d3scride Scoop 2 04-21-2012 06:36 PM


All times are GMT -5. The time now is 02:56 PM.

» vBadvanced CMPS