1 #ifndef _GIT_H 2 #define _GIT_H 3 4 #include <string> 5 6 #include "video.h" 7 8 typedef struct 9 { 10 const char *extension; // Example ".nes" 11 const char *description; // Example "iNES Format ROM Image" 12 } FileExtensionSpecStruct; 13 14 #include "file.h" 15 16 enum 17 { 18 MDFN_ROTATE0 = 0, 19 MDFN_ROTATE90, 20 MDFN_ROTATE180, 21 MDFN_ROTATE270 22 }; 23 24 typedef enum 25 { 26 VIDSYS_NONE, // Can be used internally in system emulation code, but it is an error condition to let it continue to be 27 // after the Load() or LoadCD() function returns! 28 VIDSYS_PAL, 29 VIDSYS_PAL_M, // Same timing as NTSC, but uses PAL-style colour encoding 30 VIDSYS_NTSC, 31 VIDSYS_SECAM 32 } VideoSystems; 33 34 typedef enum 35 { 36 GMT_CART, // Self-explanatory! 37 GMT_ARCADE, // VS Unisystem, PC-10... 38 GMT_DISK, // Famicom Disk System, mostly 39 GMT_CDROM, // PC Engine CD, PC-FX 40 GMT_PLAYER // Music player(NSF, HES, GSF) 41 } GameMediumTypes; 42 43 #include "state.h" 44 #include "settings-common.h" 45 46 typedef enum 47 { 48 IDIT_BUTTON, // 1-bit 49 IDIT_BUTTON_CAN_RAPID, // 1-bit 50 IDIT_BUTTON_BYTE, // 8-bits, Button as a byte instead of a bit. 51 IDIT_X_AXIS, // (mouse) 32-bits, signed, fixed-point: 1.15.16 - in-screen/window range: [0.0, nominal_width) 52 IDIT_Y_AXIS, // (mouse) 32-bits, signed, fixed-point: 1.15.16 - in-screen/window range: [0.0, nominal_height) 53 IDIT_X_AXIS_REL, // (mouse) 32-bits, signed 54 IDIT_Y_AXIS_REL, // (mouse) 32-bits, signed 55 IDIT_BYTE_SPECIAL, 56 IDIT_BUTTON_ANALOG, // 32-bits, 0 - 32767 57 IDIT_RUMBLE, // 32-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... 58 // May extend to 16-bit each in the future. 59 // It's also rather a special case of game module->driver code communication. 60 } InputDeviceInputType; 61 62 typedef struct 63 { 64 const char *SettingName; // No spaces, shouldbe all a-z0-9 and _. Definitely no ~! 65 const char *Name; 66 /*const InputDeviceInputVB VirtButton;*/ 67 const int ConfigOrder; // Configuration order during in-game config process, -1 for no config. 68 const InputDeviceInputType Type; 69 const char *ExcludeName; // SettingName of a button that can't be pressed at the same time as this button 70 // due to physical limitations. 71 72 const char *RotateName[3]; // 90, 180, 270 73 //const char *Rotate180Name; 74 //const char *Rotate270Name; 75 } InputDeviceInputInfoStruct; 76 77 typedef struct 78 { 79 const char *ShortName; 80 const char *FullName; 81 const char *Description; 82 83 //struct InputPortInfoStruct *PortExpanderDeviceInfo; 84 const void *PortExpanderDeviceInfo; // DON'T USE, IT'S NOT IMPLEMENTED PROPERLY CURRENTLY. 85 int NumInputs; // Usually just the number of buttons....OR if PortExpanderDeviceInfo is non-NULL, it's the number of input 86 // ports this port expander device provides. 87 const InputDeviceInputInfoStruct *IDII; 88 } InputDeviceInfoStruct; 89 90 typedef struct 91 { 92 const char *ShortName; 93 const char *FullName; 94 int NumTypes; // Number of unique input devices available for this input port 95 InputDeviceInfoStruct *DeviceInfo; 96 const char *DefaultDevice; // Default device for this port. 97 } InputPortInfoStruct; 98 99 typedef struct 100 { 101 int InputPorts; 102 const InputPortInfoStruct *Types; 103 } InputInfoStruct; 104 105 struct MemoryPatch; 106 107 struct CheatFormatStruct 108 { 109 const char *FullName; //"Game Genie", "GameShark", "Pro Action Catplay", etc. 110 const char *Description; // Whatever? 111 112 bool (*DecodeCheat)(const std::string& cheat_string, MemoryPatch* patch); // *patch should be left as initialized by MemoryPatch::MemoryPatch(), unless this is the 113 // second(or third or whatever) part of a multipart cheat. 114 // 115 // Will throw an std::exception(or derivative) on format error. 116 // 117 // Will return true if this is part of a multipart cheat. 118 }; 119 120 struct CheatFormatInfoStruct 121 { 122 unsigned NumFormats; 123 124 CheatFormatStruct *Formats; 125 }; 126 127 // Miscellaneous system/simple commands(power, reset, dip switch toggles, coin insert, etc.) 128 // (for DoSimpleCommand() ) 129 enum 130 { 131 MDFN_MSC_RESET = 0x01, 132 MDFN_MSC_POWER = 0x02, 133 134 MDFN_MSC_INSERT_COIN = 0x07, 135 136 // If we ever support arcade systems, we'll abstract DIP switches differently...maybe. 137 MDFN_MSC_TOGGLE_DIP0 = 0x10, 138 MDFN_MSC_TOGGLE_DIP1, 139 MDFN_MSC_TOGGLE_DIP2, 140 MDFN_MSC_TOGGLE_DIP3, 141 MDFN_MSC_TOGGLE_DIP4, 142 MDFN_MSC_TOGGLE_DIP5, 143 MDFN_MSC_TOGGLE_DIP6, 144 MDFN_MSC_TOGGLE_DIP7, 145 MDFN_MSC_TOGGLE_DIP8, 146 MDFN_MSC_TOGGLE_DIP9, 147 MDFN_MSC_TOGGLE_DIP10, 148 MDFN_MSC_TOGGLE_DIP11, 149 MDFN_MSC_TOGGLE_DIP12, 150 MDFN_MSC_TOGGLE_DIP13, 151 MDFN_MSC_TOGGLE_DIP14, 152 MDFN_MSC_TOGGLE_DIP15, 153 154 155 // n of DISKn translates to is emulation module specific. 156 MDFN_MSC_INSERT_DISK0 = 0x20, 157 MDFN_MSC_INSERT_DISK1, 158 MDFN_MSC_INSERT_DISK2, 159 MDFN_MSC_INSERT_DISK3, 160 MDFN_MSC_INSERT_DISK4, 161 MDFN_MSC_INSERT_DISK5, 162 MDFN_MSC_INSERT_DISK6, 163 MDFN_MSC_INSERT_DISK7, 164 MDFN_MSC_INSERT_DISK8, 165 MDFN_MSC_INSERT_DISK9, 166 MDFN_MSC_INSERT_DISK10, 167 MDFN_MSC_INSERT_DISK11, 168 MDFN_MSC_INSERT_DISK12, 169 MDFN_MSC_INSERT_DISK13, 170 MDFN_MSC_INSERT_DISK14, 171 MDFN_MSC_INSERT_DISK15, 172 173 MDFN_MSC_INSERT_DISK = 0x30, 174 MDFN_MSC_EJECT_DISK = 0x31, 175 176 // This command should select the next disk or disk side in the set and use MDFN_DispMessage() to show which disk is selected. 177 // (If it's only allowed while a disk is ejected, or not, is emulation module specific. 178 MDFN_MSC_SELECT_DISK = 0x32, 179 180 MDFN_MSC__LAST = 0x3F // WARNING: Increasing(or having the enum'd value of a command greater than this :b) this will necessitate a change to the netplay protocol. 181 }; 182 183 typedef struct 184 { 185 // Pitch(32-bit) must be equal to width and >= the "fb_width" specified in the MDFNGI struct for the emulated system. 186 // Height must be >= to the "fb_height" specified in the MDFNGI struct for the emulated system. 187 // The framebuffer pointed to by surface->pixels is written to by the system emulation code. 188 MDFN_Surface *surface; 189 190 // Will be set to TRUE if the video pixel format has changed since the last call to Emulate(), FALSE otherwise. 191 // Will be set to TRUE on the first call to the Emulate() function/method 192 bool VideoFormatChanged; 193 194 // Set by the system emulation code every frame, to denote the horizontal and vertical offsets of the image, and the size 195 // of the image. If the emulated system sets the elements of LineWidths, then the horizontal offset(x) and width(w) of this structure 196 // are ignored while drawing the image. 197 MDFN_Rect DisplayRect; 198 199 // Pointer to an array of MDFN_Rect, number of elements = fb_height, set by the driver code. Individual MDFN_Rect structs written 200 // to by system emulation code. If the emulated system doesn't support multiple screen widths per frame, or if you handle 201 // such a situation by outputting at a constant width-per-frame that is the least-common-multiple of the screen widths, then 202 // you can ignore this. If you do wish to use this, you must set all elements every frame. 203 MDFN_Rect *LineWidths; 204 205 // TODO 206 bool *IsFMV; 207 208 // Set(optionally) by emulation code. If InterlaceOn is true, then assume field height is 1/2 DisplayRect.h, and 209 // only every other line in surface (with the start line defined by InterlacedField) has valid data 210 // (it's up to internal Mednafen code to deinterlace it). 211 bool InterlaceOn; 212 bool InterlaceField; 213 214 // Skip rendering this frame if true. Set by the driver code. 215 int skip; 216 217 // 218 // If sound is disabled, the driver code must set SoundRate to false, SoundBuf to NULL, SoundBufMaxSize to 0. 219 220 // 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. 221 // Will be set to TRUE on the first call to the Emulate() function/method 222 bool SoundFormatChanged; 223 224 // Sound rate. Set by driver side. 225 double SoundRate; 226 227 // Pointer to sound buffer, set by the driver code, that the emulation code should render sound to. 228 // Guaranteed to be at least 500ms in length, but emulation code really shouldn't exceed 40ms or so. Additionally, if emulation code 229 // generates >= 100ms, 230 // DEPRECATED: Emulation code may set this pointer to a sound buffer internal to the emulation module. 231 int16 *SoundBuf; 232 233 // Maximum size of the sound buffer, in frames. Set by the driver code. 234 int32 SoundBufMaxSize; 235 236 // Number of frames currently in internal sound buffer. Set by the system emulation code, to be read by the driver code. 237 int32 SoundBufSize; 238 int32 SoundBufSizeALMS; // SoundBufSize value at last MidSync(), 0 239 // if mid sync isn't implemented for the emulation module in use. 240 241 // Number of cycles that this frame consumed, using MDFNGI::MasterClock as a time base. 242 // Set by emulation code. 243 int64 MasterCycles; 244 int64 MasterCyclesALMS; // MasterCycles value at last MidSync(), 0 245 // if mid sync isn't implemented for the emulation module in use. 246 247 // Current sound volume(0.000...<=volume<=1.000...). If, after calling Emulate(), it is still != 1, Mednafen will handle it internally. 248 // Emulation modules can handle volume themselves if they like, for speed reasons. If they do, afterwards, they should set its value to 1. 249 double SoundVolume; 250 251 // Current sound speed multiplier. Set by the driver code. If, after calling Emulate(), it is still != 1, Mednafen will handle it internally 252 // 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 most 253 // performance possible. HOWEVER, emulation modules must make sure the value is in a range(with minimum and maximum) that their code can handle 254 // before they try to handle it. 255 double soundmultiplier; 256 257 // True if we want to rewind one frame. Set by the driver code. 258 bool NeedRewind; 259 260 // Sound reversal during state rewinding is normally done in mednafen.cpp, but 261 // individual system emulation code can also do it if this is set, and clear it after it's done. 262 // (Also, the driver code shouldn't touch this variable) 263 bool NeedSoundReverse; 264 265 } EmulateSpecStruct; 266 267 typedef enum 268 { 269 MODPRIO_INTERNAL_EXTRA_LOW = 0, // For "cdplay" module, mostly. 270 271 MODPRIO_INTERNAL_LOW = 10, 272 MODPRIO_EXTERNAL_LOW = 20, 273 MODPRIO_INTERNAL_HIGH = 30, 274 MODPRIO_EXTERNAL_HIGH = 40 275 } ModPrio; 276 277 class CDIF; 278 279 typedef struct 280 { 281 /* Private functions to Mednafen. Do not call directly 282 from the driver code, or else bad things shall happen. Maybe. Probably not, but don't 283 do it(yet)! 284 */ 285 // Short system name, lowercase a-z, 0-9, and _ are the only allowable characters! 286 const char *shortname; 287 288 // Full system name. Preferably English letters, but can be UTF8 289 const char *fullname; 290 291 // Pointer to an array of FileExtensionSpecStruct, with the last entry being { NULL, NULL } to terminate the list. 292 // This list is used to make best-guess choices, when calling the TestMagic*() functions would be unreasonable, such 293 // 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. 294 const FileExtensionSpecStruct *FileExtensions; 295 296 ModPrio ModulePriority; 297 298 void *Debugger; 299 InputInfoStruct *InputInfo; 300 301 // Returns 1 on successful load, 0 on fatal error(deprecated: -1 on unrecognized format) 302 int (*Load)(const char *name, MDFNFILE *fp); 303 304 // Return TRUE if the file is a recognized type, FALSE if not. 305 bool (*TestMagic)(const char *name, MDFNFILE *fp); 306 307 // 308 // (*CDInterfaces).size() is guaranteed to be >= 1. 309 int (*LoadCD)(std::vector<CDIF *> *CDInterfaces); 310 bool (*TestMagicCD)(std::vector<CDIF *> *CDInterfaces); 311 312 void (*CloseGame)(void); 313 314 void (*SetLayerEnableMask)(uint64 mask); // Video 315 const char *LayerNames; 316 317 void (*SetChanEnableMask)(uint64 mask); // Audio(TODO, placeholder) 318 const char *ChanNames; 319 320 void (*InstallReadPatch)(uint32 address); 321 void (*RemoveReadPatches)(void); 322 uint8 (*MemRead)(uint32 addr); 323 324 #ifdef WANT_NEW_API 325 CheatFormatInfoStruct *CheatFormatInfo; 326 #endif 327 328 bool SaveStateAltersState; // true for bsnes and some libco-style emulators, false otherwise. 329 // Main save state routine, called by the save state code in state.cpp. 330 // When saving, load is set to 0. When loading, load is set to the version field of the save state being loaded. 331 // data_only is true when the save state data is temporary, such as being saved into memory for state rewinding. 332 int (*StateAction)(StateMem *sm, int load, int data_only); 333 334 void (*Emulate)(EmulateSpecStruct *espec); 335 void (*SetInput)(int port, const char *type, void *ptr); 336 337 void (*DoSimpleCommand)(int cmd); 338 339 const MDFNSetting *Settings; 340 341 // Time base for EmulateSpecStruct::MasterCycles 342 #define MDFN_MASTERCLOCK_FIXED(n) ((int64)((double)(n) * (1LL << 32))) 343 int64 MasterClock; 344 345 uint32 fps; // frames per second * 65536 * 256, truncated 346 347 // multires is a hint that, if set, indicates that the system has fairly programmable video modes(particularly, the ability 348 // to display multiple horizontal resolutions, such as the PCE, PC-FX, or Genesis). In practice, it will cause the driver 349 // code to set the linear interpolation on by default. 350 // 351 // lcm_width and lcm_height are the least common multiples of all possible 352 // resolutions in the frame buffer as specified by DisplayRect/LineWidths(Ex for PCE: widths of 256, 341.333333, 512, 353 // lcm = 1024) 354 // 355 // nominal_width and nominal_height specify the resolution that Mednafen should display 356 // the framebuffer image in at 1x scaling, scaled from the dimensions of DisplayRect, and optionally the LineWidths array 357 // passed through espec to the Emulate() function. 358 // 359 bool multires; 360 361 int lcm_width; 362 int lcm_height; 363 364 void *dummy_separator; // 365 366 int nominal_width; 367 int nominal_height; 368 369 int fb_width; // Width of the framebuffer(not necessarily width of the image). MDFN_Surface width should be >= this. 370 int fb_height; // Height of the framebuffer passed to the Emulate() function(not necessarily height of the image) 371 372 int soundchan; // Number of output sound channels. 373 374 375 int rotated; 376 377 uint8 *name; /* Game name, UTF8 encoding */ 378 379 int soundrate; /* For Ogg Vorbis expansion sound wacky support. 0 for default. */ 380 381 VideoSystems VideoSystem; 382 GameMediumTypes GameType; 383 384 //int DiskLogicalCount; // A single double-sided disk would be 2 here. 385 //const char *DiskNames; // Null-terminated. 386 387 const char *cspecial; /* Special cart expansion: DIP switches, barcode reader, etc. */ 388 389 std::vector<const char *>DesiredInput; // Desired input device for the input ports, NULL for don't care 390 391 double mouse_sensitivity; 392 } MDFNGI; 393 #endif 394