PDA

View Full Version : C++ and MAME


Kong
07-23-2012, 01:40 PM
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.

Kong
08-02-2014, 04:13 PM
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 (http://curl.haxx.se/libcurl/c/curlgtk.html)

Which uses GTK for the progress bar.

I think I have everything set up correctly except I need to add this
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.

Kong
08-04-2014, 04:07 PM
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 ----------

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

:beat-up: 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.

Seahawk
08-04-2014, 09:21 PM
Cplusplus.com (http://www.cplusplus.com/) is a good reference to have open in a tab while coding.

Kong
08-08-2014, 08:47 PM
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 (http://curl.haxx.se/libcurl/c/fopen.html)


Thanks.

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

Nevermind. I think I got it.

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));

Seahawk
08-08-2014, 09:08 PM
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.

Kong
08-08-2014, 10:46 PM
Like this?
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;
}

Seahawk
08-08-2014, 11:58 PM
// 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...

Kong
08-09-2014, 10:14 AM
I just copied the original from here.
Trying to rewrite realloc function in c - Stack Overflow (http://stackoverflow.com/questions/18943181/trying-to-rewrite-realloc-function-in-c)


I used your version but changed the final if to this.
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.

Seahawk
08-09-2014, 12:30 PM
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.


// 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.

Kong
08-10-2014, 01:19 PM
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.