📄 porting.txt
字号:
restoring the current game to exact same spot. Call this routine whileyou're processing any pending system events when S9xMainLoop has returnedcontrol to you in your main loop.-> bool8 S9xUnfreezeGame (const char *filename)Restore the SNES hardware back to the exactly the state it was in whenS9xFreezeGame was used to generate the file specified. You have to arrangethe correct ROM is already loaded using Memory.LoadROM, an easy way toarrange this is to base freeze-game filenames on the ROM image name. TheLinux, UNIX and DOS ports load freeze-game files when the user presses afunction key, with the names romfilename.000 for F1, romfilename.001 for F2,etc. Games are frozen in the first place when the user presses Shift-functionkey. You could choose some other scheme.-> void S9xNextController ()The real SNES allows several different types of devices to be plugged intothe game controller ports. The devices Snes9x emulates are a joy-pad,multi-player adaptor (allowing a further 4 joy-pads to be plugged in),a 2-button mouse and a light gun known as the SuperScope.Each call to S9xNextController will step the current emulated device on tothe next device in the sequence multi-player, joy-pad, mouse on port 1,mouse on port 2, light gun then back to multi-player again. Definesallocating a number of each device type are in snes9x.h. The currentlyselected device is stored in IPPU.Controller if you want to give somefeedback to the user. The initial value of IPPU.Controller (set whenS9xReset is called) is obtained from Settings.ControllerOption based oncurrently enabled options.Some ROMs object to certain non-joy-pad devices being plugged into the realSNES while they are running, all Super FX games should only allow joy-pads tobe plugged in because the Super FX chip and any other device would overloadthe SNES power supply. Tetris and Dr. Mario also objects for reasons bestknown to itself. For this reason there are switches in the Settingsstructure to enable and display the emulation of the various devices.const char *S9xGameGenieToRaw (const char *code, uint32 &address, uint8 &byte)const char *S9xProActionReplayToRaw (const char *code, uint32 &address, uint8 &byte)const char *S9xGoldFingerToRaw (const char *code, uint32 &address, bool8 &sram, uint8 &num_bytes, uint8 bytes[3])void S9xApplyCheats (bool8 apply)void S9xRemoveCheats ()void S9xAddCheat (uint32 address, bool8 cpu_address, bool8 sram, uint8 num_bytes, uint8 byte1, uint8 byte2, uint8 byte3)void S9xDeleteCheats ()void S9xDoDebug ()Interface Routines You Need to Implement----------------------------------------bool8 S9xOpenSnapshotFile (const char *base, bool8 read_only, STREAM *file)***************************************************************************void S9xCloseSnapshotFile (STREAM file)***************************************Routines to open and close freeze-game files. STREAM is defined as agzFile if ZLIB is defined else its defined as FILE *. The read_only parameteris set to TRUE when reading a freeze-game file and FALSE when writing afreeze-game file.void S9xExit ()***************Called when some fatal error situation arises or when the 'q' debuggercommand is used. The Mac port just beeps and drops back to the GUI whenS9xExit is called, the MS-DOS, Linux and Solaris ports all call exit () toterminate the emulator process.void S9xParseArg (char **argv, int &index, int argc)****************************************************void S9xExtraUsage ()*********************If you're going to be using the simple command line parser, when itencounters an unknown option it calls S9xUsage which is supposed to reportall options the generic parse knows about (I haven't been keeping it up todate of late). S9xUsage then, in turn calls S9xExtraUsage which youimplement to report any port-specific options available.void S9xGraphicsMode ()***********************void S9xTextMode ()*******************The SNES debugger calls these routines to switch from a graphics screenmode used to display the SNES game to a debugger screen used to displaydebugger output. If the SNES screen can be displayed at the same time asa text display, as would be the case when the host system implements agraphical window system, or you're not going to support the SNES debugger,then these routines should do nothing.On the X Window System UNIX/Linux port, these routines do nothing where ason the MS-DOS port they switch between a graphics screen mode and a text-onlyscreen mode.bool8 S9xInitUpdate ()**********************Called just before Snes9x starts to render a SNES screen. The Windows portuses this call to lock Direct X screen area to allow exclusive access; onother existing ports its implemented as an empty function.bool8 S9xDeinitDisplay (int width, int height, bool8 sixteen_bit)*****************************************************************Called once a complete SNES screen has been rendered into the GFX.Screenmemory buffer, now is your chance to copy the SNES rendered screen to thehost computer's screen memory. The problem is that you have to cope withdifferent sized SNES rendered screens. Width is always 256, unless you'resupporting SNES hi-res. screen modes (Settings.SupportHiRes is TRUE), inwhich case it can be 256 or 512. The height parameter can be either 224 or239 if you're only supporting SNES lo-res. screen modes, or 224, 239, 448 or478 if hi-res. SNES screen modes are being supported.All current ports support scaling the SNES screen to fill the host system'sscreen, the many ports even supports interpolation - blending the colours ofadjacent pixels to help hide the fact they've been scaled - and scan-linesimulation - slightly darkening every other horizontal line.Don't forget that if you're just placing the SNES image centerally in thescreen then you might need to clear areas of the screen if the SNES imagechanges size between calls to S9xDeinitDisplay. The MS-DOS and UNIX portscurrently don't do this which results in junk being left on the screen ifthe ROM changes SNES screen modes.The sixteen_bit is just a copy of the Settings.SixteenBit setting and ifTRUE indicates a 16-bit SNES screen image has been rendered, 8-bit otherwise.void S9xMessage (int type, int number, const char *message)***********************************************************I've started work on converting all the old printfs into calls to thisroutine. When Snes9x wants to display an error, information or warningmessage, it calls this routine. Check in messages.h for the types andindividual message numbers that Snes9x currently passes as parameters.The idea is display the message string so the user can see it, but youchoose not to display anything at all, or change the message based on themessage number or message type.Eventually all debug output will also go via this function, trace informationalready does.bool8 S9xOpenSoundDevice(int mode, bool8 stereo, int buffer_size)*****************************************************************S9xInitSound calls this function to actually open the host operating system'ssound device, or initialise the sound card in MS-DOS port. The mode parameter is the value passed in on the command line with the -rcommand line flag, assuming you're using the Snes9x parser. Its meant toindicate what playback the sound hardware should be set to, value 1 to 7.I think the real SNES sound chip playback rate is 30kHz, but such highplayback rates take a lot of native CPU power to emulate. The defaultplayback rate is 22kHz for the MS-DOS and UNIX ports.The stereo flag indicates if the user wants stereo sound. Again, stereosound takes more CPU to power to emulate compared to mono sound.The buffer_size value indicates what sample buffer size the user wants,usually zero, meaning you should pick the value best suited to the currentplayback rate. Sound data is normally passed to the sound hardware inblocks, the smaller the block the less latency between the SNES game playinga sound and it being heard by the user. But if you pick a too smaller value,and you're having to periodically poll the operating system to see if it canaccept more sound data, then the sound output will break up because otheractions such as rendering the SNES screen can prevent you from polling thehardware often enough and the operating system runs out of sound data toplay.The MS-DOS port uses a buffer size of 128 samples since the sound cardsends an interrupt when more data is required which is acted upon promptly,where as the Linux and Solaris ports use a buffer size of 512 samples ormore depending on the playback rate. Stereo and 16-bit sound both double theactual size of the buffer in bytes.uint32 S9xReadJoypad (int which1_0_to_4)****************************************This function is called to return a bit-wise mask of the state of one of thefive emulated SNES controllers. Return 0 if you're not supporting controllerspast a certain number or return the mask representing the current state ofthe controller number passed as a parameter or'ed with 0x80000000.Symbolic constants are defined in snes9x.h indicating the bit positions ofthe various SNES buttons and direction indicators; they're all in the formSNES_X_MASK where X is the SNES controller button name.The MS-DOS and X Window System ports record what keys are currently pressedand use that to build up a mask, the Windows port polls the operating systemwhen S9xReadJoypad is called to find out what keys are pressed. All portsalso implement host joysticks and joy-pads via this interface.bool8 S9xReadMousePosition (int which1_0_to_1, int &x, int &y, uint32 &buttons)*******************************************************************************Used by Snes9x to get the current position of the host pointing device,usually a mouse, used to emulated the SNES mouse. Snes9x converts the x andy values to delta values required by the SNES mouse, so the actual x and yvalues are unimportant, only the change in value since the last call tothis function is used. Graphical windowing systems normally restrict the movement of the pointer onthe screen, if you're porting to such an environment you might want to makea note of the change in position in the mouse since the last time you askedthe operating system the mouse position, add this change in value to somesaved x and y value, the reposition the pointer back to the centre of theSNES display window. The saved x and y values will be the values returnedby this function.The buttons return value is a bit-wise mask of the two SNES mouse buttons,bit 0 for button 1 (left) and bit 1 for button 2 (right).bool8 S9xReadSuperScopePosition (int &x, int &y, uint32 &buttons)*****************************************************************void S9xSetPalette ()*********************void S9xSyncSpeed ()S9xUnixProcessSoundvoid _makepath(char *, char const *, char const *, char const *, char const *)void _splitpath(char const *, char *, char *, char *, char *)Sound Generation----------------Settings--------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -