#ifndef _GIT_H1#define _GIT_H23#include <string>45#include "octoshock.h"67#include "video.h"8#include "file.h"910class CDIF;1112typedef struct13{14const char *extension; // Example ".nes"15const char *description; // Example "iNES Format ROM Image"16} FileExtensionSpecStruct;1718#include "file.h"1920enum21{22MDFN_ROTATE0 = 0,23MDFN_ROTATE90,24MDFN_ROTATE180,25MDFN_ROTATE27026};2728typedef enum29{30VIDSYS_NONE, // Can be used internally in system emulation code, but it is an error condition to let it continue to be31// after the Load() or LoadCD() function returns!32VIDSYS_PAL,33VIDSYS_PAL_M, // Same timing as NTSC, but uses PAL-style colour encoding34VIDSYS_NTSC,35VIDSYS_SECAM36} VideoSystems;3738typedef enum39{40GMT_CART, // Self-explanatory!41GMT_ARCADE, // VS Unisystem, PC-10...42GMT_DISK, // Famicom Disk System, mostly43GMT_CDROM, // PC Engine CD, PC-FX44GMT_PLAYER // Music player(NSF, HES, GSF)45} GameMediumTypes;4647#ifdef WANT_DEBUGGER48// #ifdef WANT_DEBUGGER49// typedef struct DebuggerInfoStruct;50// #else51#include "debug.h"5253#endif5455typedef enum56{57IDIT_BUTTON, // 1-bit58IDIT_BUTTON_CAN_RAPID, // 1-bit5960IDIT_X_AXIS, // (mouse) 16-bits, signed - in-screen/window range: [0.0, nominal_width)61IDIT_Y_AXIS, // (mouse) 16-bits, signed - in-screen/window range: [0.0, nominal_height)6263IDIT_X_AXIS_REL, // (mouse) 32-bits, signed64IDIT_Y_AXIS_REL, // (mouse) 32-bits, signed6566IDIT_BYTE_SPECIAL,6768IDIT_BUTTON_ANALOG, // 16-bits, 0 - 327676970IDIT_RUMBLE, // 16-bits, lower 8 bits are weak rumble(0-255), next 8 bits are strong rumble(0-255), 0=no rumble, 255=max rumble. Somewhat subjective, too...71// It's a rather special case of game module->driver code communication.72} InputDeviceInputType;737475#define IDIT_BUTTON_ANALOG_FLAG_SQLR 0x00000001 // Denotes analog data that may need to be scaled to ensure a more squareish logical range(for emulated76// analog sticks).7778typedef struct79{80const char *SettingName; // No spaces, shouldbe all a-z0-9 and _. Definitely no ~!81const char *Name;82const int ConfigOrder; // Configuration order during in-game config process, -1 for no config.83const InputDeviceInputType Type;84const char *ExcludeName; // SettingName of a button that can't be pressed at the same time as this button85// due to physical limitations.8687const char *RotateName[3]; // 90, 180, 27088unsigned Flags;89} InputDeviceInputInfoStruct;9091typedef struct92{93const char *ShortName;94const char *FullName;95const char *Description;9697//struct InputPortInfoStruct *PortExpanderDeviceInfo;98const void *PortExpanderDeviceInfo; // DON'T USE, IT'S NOT IMPLEMENTED PROPERLY CURRENTLY.99int NumInputs; // Usually just the number of buttons....OR if PortExpanderDeviceInfo is non-NULL, it's the number of input100// ports this port expander device provides.101const InputDeviceInputInfoStruct *IDII;102} InputDeviceInfoStruct;103104typedef struct105{106const char *ShortName;107const char *FullName;108int NumTypes; // Number of unique input devices available for this input port109InputDeviceInfoStruct *DeviceInfo;110const char *DefaultDevice; // Default device for this port.111} InputPortInfoStruct;112113typedef struct114{115int InputPorts;116const InputPortInfoStruct *Types;117} InputInfoStruct;118119struct MemoryPatch;120121typedef struct122{123// Pitch(32-bit) must be equal to width and >= the "fb_width" specified in the MDFNGI struct for the emulated system.124// Height must be >= to the "fb_height" specified in the MDFNGI struct for the emulated system.125// The framebuffer pointed to by surface->pixels is written to by the system emulation code.126MDFN_Surface *surface;127128// Will be set to TRUE if the video pixel format has changed since the last call to Emulate(), FALSE otherwise.129// Will be set to TRUE on the first call to the Emulate() function/method130bool VideoFormatChanged;131132// Set by the system emulation code every frame, to denote the horizontal and vertical offsets of the image, and the size133// of the image. If the emulated system sets the elements of LineWidths, then the width(w) of this structure134// is ignored while drawing the image.135MDFN_Rect DisplayRect;136137// Pointer to an array of int32, number of elements = fb_height, set by the driver code. Individual elements written138// to by system emulation code. If the emulated system doesn't support multiple screen widths per frame, or if you handle139// such a situation by outputting at a constant width-per-frame that is the least-common-multiple of the screen widths, then140// you can ignore this. If you do wish to use this, you must set all elements every frame.141int32 *LineWidths;142143// TODO144bool *IsFMV;145146// Set(optionally) by emulation code. If InterlaceOn is true, then assume field height is 1/2 DisplayRect.h, and147// only every other line in surface (with the start line defined by InterlacedField) has valid data148// (it's up to internal Mednafen code to deinterlace it).149bool InterlaceOn;150bool InterlaceField;151152// Skip rendering this frame if true. Set by the driver code.153int skip;154155//156// If sound is disabled, the driver code must set SoundRate to false, SoundBuf to NULL, SoundBufMaxSize to 0.157158// Will be set to TRUE if the sound format(only rate for now, at least) has changed since the last call to Emulate(), FALSE otherwise.159// Will be set to TRUE on the first call to the Emulate() function/method160bool SoundFormatChanged;161162// Sound rate. Set by driver side.163double SoundRate;164165// Pointer to sound buffer, set by the driver code, that the emulation code should render sound to.166// Guaranteed to be at least 500ms in length, but emulation code really shouldn't exceed 40ms or so. Additionally, if emulation code167// generates >= 100ms,168// DEPRECATED: Emulation code may set this pointer to a sound buffer internal to the emulation module.169int16 *SoundBuf;170171// Maximum size of the sound buffer, in frames. Set by the driver code.172int32 SoundBufMaxSize;173174// Number of frames currently in internal sound buffer. Set by the system emulation code, to be read by the driver code.175int32 SoundBufSize;176int32 SoundBufSizeALMS; // SoundBufSize value at last MidSync(), 0177// if mid sync isn't implemented for the emulation module in use.178179// Number of cycles that this frame consumed, using MDFNGI::MasterClock as a time base.180// Set by emulation code.181int64 MasterCycles;182int64 MasterCyclesALMS; // MasterCycles value at last MidSync(), 0183// if mid sync isn't implemented for the emulation module in use.184185// Current sound volume(0.000...<=volume<=1.000...). If, after calling Emulate(), it is still != 1, Mednafen will handle it internally.186// Emulation modules can handle volume themselves if they like, for speed reasons. If they do, afterwards, they should set its value to 1.187double SoundVolume;188189// Current sound speed multiplier. Set by the driver code. If, after calling Emulate(), it is still != 1, Mednafen will handle it internally190// by resampling the audio. This means that emulation modules can handle(and set the value to 1 after handling it) it if they want to get the most191// performance possible. HOWEVER, emulation modules must make sure the value is in a range(with minimum and maximum) that their code can handle192// before they try to handle it.193double soundmultiplier;194195// True if we want to rewind one frame. Set by the driver code.196bool NeedRewind;197198// Sound reversal during state rewinding is normally done in mednafen.cpp, but199// individual system emulation code can also do it if this is set, and clear it after it's done.200// (Also, the driver code shouldn't touch this variable)201bool NeedSoundReverse;202203} EmulateSpecStruct;204205206207typedef struct208{209/* Private functions to Mednafen. Do not call directly210from the driver code, or else bad things shall happen. Maybe. Probably not, but don't211do it(yet)!212*/213// Short system name, lowercase a-z, 0-9, and _ are the only allowable characters!214const char *shortname;215216// Full system name. Preferably English letters, but can be UTF8217const char *fullname;218219// Pointer to an array of FileExtensionSpecStruct, with the last entry being { NULL, NULL } to terminate the list.220// This list is used to make best-guess choices, when calling the TestMagic*() functions would be unreasonable, such221// as when scanning a ZIP archive for a file to load. The list may also be used in the future for GUI file open windows.222const FileExtensionSpecStruct *FileExtensions;223224#ifdef WANT_DEBUGGER225DebuggerInfoStruct *Debugger;226#else227void *Debugger;228#endif229InputInfoStruct *InputInfo;230231//232// Returns 1 on successful load.233// throws exception on fatal error.234//235// DEPRECATED: Return 0 on fatal error.236// DEPRECATED: Return -1 on unrecognized format.237//238// fp's stream position is guaranteed to be 0 when this function is called.239//240int (*Load)(MDFNFILE *fp);241242//243// Return true if the file is a recognized type, false if not.244//245// fp's stream position is guaranteed to be 0 when this function is called.246//247bool (*TestMagic)(MDFNFILE *fp);248249//250// (*CDInterfaces).size() is guaranteed to be >= 1.251void (*LoadCD)(std::vector<CDIF *> *CDInterfaces);252bool (*TestMagicCD)(std::vector<CDIF *> *CDInterfaces);253254void (*CloseGame)(void);255256void (*SetLayerEnableMask)(uint64 mask); // Video257const char *LayerNames;258259void (*SetChanEnableMask)(uint64 mask); // Audio(TODO, placeholder)260const char *ChanNames;261262//263// InstallReadPatch and RemoveReadPatches should be non-NULL(even if only pointing to dummy functions) if the emulator module supports264// read-substitution and read-substitution-with-compare style(IE Game Genie-style) cheats.265//266// See also "SubCheats" global stuff in mempatcher.h.267//268void (*InstallReadPatch)(uint32 address, uint8 value, int compare); // Compare is >= 0 when utilized.269void (*RemoveReadPatches)(void);270uint8 (*MemRead)(uint32 addr);271272bool SaveStateAltersState; // true for bsnes and some libco-style emulators, false otherwise.273// Main save state routine, called by the save state code in state.cpp.274// When saving, load is set to 0. When loading, load is set to the version field of the save state being loaded.275// data_only is true when the save state data is temporary, such as being saved into memory for state rewinding.276277void (*Emulate)(EmulateSpecStruct *espec);278void (*SetInput)(int port, const char *type, void *ptr);279280void (*DoSimpleCommand)(int cmd);281282// Time base for EmulateSpecStruct::MasterCycles283// MasterClock must be >= MDFN_MASTERCLOCK_FIXED(1.0)284// All or part of the fractional component may be ignored in some timekeeping operations in the emulator to prevent integer overflow,285// so it is unwise to have a fractional component when the integral component is very small(less than say, 10000).286#define MDFN_MASTERCLOCK_FIXED(n) ((int64)((double)(n) * (1LL << 32)))287int64 MasterClock;288289// Nominal frames per second * 65536 * 256, truncated.290// May be deprecated in the future due to many systems having slight frame rate programmability.291uint32 fps;292293// multires is a hint that, if set, indicates that the system has fairly programmable video modes(particularly, the ability294// to display multiple horizontal resolutions, such as the PCE, PC-FX, or Genesis). In practice, it will cause the driver295// code to set the linear interpolation on by default.296//297// lcm_width and lcm_height are the least common multiples of all possible298// resolutions in the frame buffer as specified by DisplayRect/LineWidths(Ex for PCE: widths of 256, 341.333333, 512,299// lcm = 1024)300//301// nominal_width and nominal_height specify the resolution that Mednafen should display302// the framebuffer image in at 1x scaling, scaled from the dimensions of DisplayRect, and optionally the LineWidths array303// passed through espec to the Emulate() function.304//305bool multires;306307int lcm_width;308int lcm_height;309310void *dummy_separator; //311312int nominal_width;313int nominal_height;314315int fb_width; // Width of the framebuffer(not necessarily width of the image). MDFN_Surface width should be >= this.316int fb_height; // Height of the framebuffer passed to the Emulate() function(not necessarily height of the image)317318int soundchan; // Number of output sound channels. Only values of 1 and 2 are currently supported.319320321int rotated;322323uint8 *name; /* Game name, UTF8 encoding */324uint8 MD5[16];325uint8 GameSetMD5[16]; /* A unique ID for the game set this CD belongs to, only used in PC-FX emulation. */326bool GameSetMD5Valid; /* True if GameSetMD5 is valid. */327328uint8 StateMD5[16]; // ID to use in save state naming and netplay session IDs, if329bool StateMD5Valid; // StateMD5Valid is true(useful for systems with multiple BIOS revisions, e.g. PS1).330331int soundrate; /* For Ogg Vorbis expansion sound wacky support. 0 for default. */332333VideoSystems VideoSystem;334GameMediumTypes GameType;335336//int DiskLogicalCount; // A single double-sided disk would be 2 here.337//const char *DiskNames; // Null-terminated.338339const char *cspecial; /* Special cart expansion: DIP switches, barcode reader, etc. */340341std::vector<const char *>DesiredInput; // Desired input device for the input ports, NULL for don't care342343// For mouse relative motion.344double mouse_sensitivity;345346347//348// For absolute coordinates(IDIT_X_AXIS and IDIT_Y_AXIS), usually mapped to a mouse(hence the naming).349//350float mouse_scale_x, mouse_scale_y;351float mouse_offs_x, mouse_offs_y;352} MDFNGI;353#endif354355356