byuu wrote:
You shouldn't need any polymorphism
I mean "polymorphism" in the sense that there is a format for a "core" that the front-end can call into. For example, a pure-C implementation would give each core a function pointer table that might look like this:
Code:
struct EmulatorInterface {
// Allocate memory for an emulated machine
struct Machine (*alloc)();
// Deallocate all memory owned by this machine and free it
void (*dealloc)(struct Machine *);
// Initialize a machine by loading in a program image
// and hard reset the machine
bool (*initWithROM)(struct Machine *st,
const unsigned char *data, size_t size);
// Load the state of a machine after initWithROM.
// To soft-reset the emulator, specify data = NULL or size = 0.
bool (*loadState)(struct Machine *st,
const unsigned char *data, size_t size);
// Get an upper bound on the size of a saved state
uint32_t (*getStateSize)(struct Machine *st);
// Save the state of the machine if it would fit in size bytes.
// Return the actual number of bytes, or 0 if not enough space.
size_t (*saveState)(struct Machine *st,
unsigned char *data, size_t size);
// Set the input for one player
void (*setInput)(struct Machine *st,
size_t player, uint32_t axes, uint32_t buttons);
// Clock the machine by one "frame"
void (*runFrame)(struct Machine *st);
// Return a reference to a bitmap of the latest video frame.
// This reference is valid until the next runFrame call.
// Also get the current pixel aspect ratio (e.g. 8:7 for NTSC
// NES/SNES or 10:11 for DVD).
BITMAP *(*getVideo)(struct Machine *st,
uint32_t *parNum, uint32_t *parDen);
// Get the frame rate (e.g. 39375000/655171 for NTSC NES/SNES)
void (*getFrameRate)(struct Machine *st,
uint32_t *num, uint32_t *den);
// Get the audio's sample rate in Hz
uint32_t (*getAudioRate)(struct Machine *st);
// Get the number of audio output channels (usually 1 or 2)
size_t (*getAudioChannels)(struct Machine *st);
// Get up to nSamples audio samples. For multichannel audio,
// nSamples must be a multiple of the number of channels.
size_t (*getAudioSamples)(struct Machine *st,
int16_t *samples, size_t nSamples);
};
Without polymorphism, you can't have more than one core in one executable. That would rule out things like REW, Mednafen, MESS, VisualBoyAdvance, and emulation of a Genesis with a Power Base Converter.
koitsu wrote:
2) Don't worry -- the "behind the scenes" guy will most definitely become known about. A new emulator called MyFirstEmulator ((tm) Fisher Price) is released by some kid who's still learning C, with the actual emulator core being done by said "specialist guy that no one knows about". Site is put up, with a forum (as always is the case).
And per the free software license of the emulator (e.g. BSD, MIT, GPL), the author of the emulator engine gets credit either in the program or in the manual. For example, there are a few web browsers based on the Gecko back-end (e.g. Firefox, SeaMonkey, Fennec, K-Meleon) and a few based on the WebKit back-end (e.g. Safari, Chrome). If you're more of an Opera fan, open Wii Internet Channel and see how many credits you can spot in its manual.
A front-end might not even be a general emulator as you know it. It could be a level editor for a game (where the preview is rendered in the emulator), a music tracker, or any program that has both native and emulated code.