Compare commits

...
939 Commits
Author SHA1 Message Date
Themaister d109c22b49 Update Windows makefile. 2012-01-16 22:10:31 +01:00
Themaister 98f2f1c23d Updates for 0.9.4. 2012-01-16 22:08:54 +01:00
TwinAphex51224 94bc6ff3a2 (PS3) Some more settings filled in 2012-01-16 17:15:16 +01:00
TwinAphex51224 62dc63542c (PS3) Clean up PS3 GL driver always assume HAVE_FBO and HAVE_CG 2012-01-16 16:46:35 +01:00
TwinAphex51224 dd8acd5872 (PS3) Added SN version number in 'print compiler' function 2012-01-16 16:38:27 +01:00
TwinAphex51224 d1113a5af0 (PS3) Added sysutil screenshot feature 2012-01-16 15:45:55 +01:00
TwinAphex51224 024e10b5a9 (PS3) Implemented some settings 2012-01-16 15:33:18 +01:00
TwinAphex51224 c4b2492872 (PS3) Some cleanups 2012-01-16 04:09:28 +01:00
TwinAphex51224 44bc9fe291 (PS3) Menu refactoring 2012-01-16 04:07:02 +01:00
Themaister ee7bacd2bc Fix critical performance regression. 2012-01-14 23:15:25 +01:00
Themaister 90a2070718 Return 0 from main().
On console targets, main() is overridden to ssnes_main().
2012-01-14 20:45:05 +01:00
Themaister abf34c06c1 Attempt to always return from ssnes_main_init() when errors occur. 2012-01-14 16:08:54 +01:00
Themaister 661836fd77 Deconstruct main() into three separate functions.
Split main() into init/iterate/deinit functions.
2012-01-14 14:08:43 +01:00
Themaister 260f3ac7ce Use a more general SSNES_CONSOLE define. 2012-01-14 13:43:15 +01:00
Themaister f57ab1ccd8 Handle zero sized writes. 2012-01-14 02:03:49 +01:00
Themaister ef206b3a27 Fix directory detection. 2012-01-14 01:42:51 +01:00
TwinAphex51224 2dce493240 (PS3) Sysutil exit callback works in menu too 2012-01-13 01:27:18 +01:00
TwinAphex51224 83c3d7be57 (PS3) Menu fixes 2012-01-13 01:01:08 +01:00
TwinAphex51224 7b0e1e8022 (PS3) Got rid of warnings in main.c 2012-01-13 00:22:43 +01:00
Themaister 86950b4d2a FBO scale are float. 2012-01-13 00:29:01 +01:00
Themaister fe02783fc7 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-13 00:09:27 +01:00
Themaister 072406e3c3 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-13 00:09:13 +01:00
Themaister 751761d99c Add config_get_float. 2012-01-13 00:08:55 +01:00
TwinAphex51224 fe993fafd5 (PS3) Fixed menu speed 2012-01-13 00:01:52 +01:00
TwinAphex51224 057785539b Merge branch 'master' of github.com:Themaister/SSNES 2012-01-12 23:46:10 +01:00
TwinAphex51224 048d2f65e0 (PS3) Fixed controller 2 2012-01-12 23:45:48 +01:00
Themaister c305f4347d Add g_console struct. 2012-01-12 22:53:14 +01:00
TwinAphex51224 3ca62fbbbc (PS3) Pushed PS3 video fix 2012-01-12 22:02:28 +01:00
Themaister 225699f545 No real need to memset(). 2012-01-12 20:41:52 +01:00
Themaister 35ae61fbc7 Use more correct UINT*_C() constants. 2012-01-12 20:16:47 +01:00
Themaister 86dac8c979 Make sure sockets are not closed twice on error. 2012-01-12 09:21:33 +01:00
TwinAphex51224 95431414ae (PS3) Initialize some settings 2012-01-12 00:24:17 +01:00
TwinAphex51224 b3f7224ea1 (PS3) menu works, ROM loads, but screen is black 2012-01-12 00:05:32 +01:00
Themaister e583546778 Add some more needed stuff. 2012-01-11 23:48:48 +01:00
Themaister a39c37e1ee Add some hooks to video init/deinit for PS3. 2012-01-11 23:44:29 +01:00
Themaister 67fb35b645 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-11 23:10:05 +01:00
Themaister 3c1e4c879a Integer scale is bad mmkay. 2012-01-11 23:09:22 +01:00
TwinAphex51224 83a11be669 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-11 22:55:37 +01:00
TwinAphex51224 08e35a62d4 (PS3) Can now compile with SNC as well 2012-01-11 22:55:07 +01:00
Themaister 5461c0d86e Merge branch 'master' of github.com:Themaister/SSNES 2012-01-11 22:52:57 +01:00
Themaister 4eab7c4387 Font scale option. 2012-01-11 22:52:25 +01:00
TwinAphex51224 59aeb77744 (PS3) Some more work on menu 2012-01-11 22:27:07 +01:00
Themaister c6fc8e45ff Log more clearly disconnects. 2012-01-11 21:08:44 +01:00
Themaister 4dde927c12 Add some logging and increase buffer sizes. 2012-01-11 20:50:21 +01:00
Themaister 6325b4cd2e Set larger buffer size to mitigate lags on client connect. 2012-01-11 20:14:59 +01:00
Themaister 4beec3870f Spectator mode. 2012-01-11 19:22:18 +01:00
Themaister 36a2c96cb7 ifdef console oriented binds. 2012-01-11 10:00:24 +01:00
TwinAphex51224 a4a68a2ad5 (PS3) Implemented menu code some more 2012-01-11 02:25:49 +01:00
TwinAphex51224 13a2010ed6 (PS3) Fix 2012-01-11 01:17:04 +01:00
TwinAphex51224 e37fd21424 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-11 01:04:47 +01:00
TwinAphex51224 a2698061a6 (PS3) Loads settings from config file 2012-01-11 01:04:17 +01:00
Themaister d00257382a Always dump 16-bit little endian values for movie record. 2012-01-11 00:55:50 +01:00
TwinAphex51224 51ab2f2509 (PS3) Added initial menu - not yet compiled in 2012-01-10 23:33:44 +01:00
TwinAphex51224 61f9ceccab PATH_MAX gets redefined for PS3/Libxenon 2012-01-10 22:08:24 +01:00
Themaister f836a291a0 Reinstate ssnes.cfg. 2012-01-09 16:05:02 +01:00
Themaister 97725e69eb Add missing license header. 2012-01-08 02:30:32 +01:00
Themaister d186e14eeb VSync one frame earlier. 2012-01-08 02:21:28 +01:00
Themaister 08aaa1021c More aestethically pleasing effect. 2012-01-08 01:32:45 +01:00
Themaister b4248038fb Update license headers. 2012-01-08 01:12:05 +01:00
Themaister ca587ab92e Actually runs. 2012-01-08 01:07:26 +01:00
Themaister 6f5c33848e Begin work on menu for Wii. 2012-01-08 00:57:44 +01:00
Themaister 17d380400e Update AUTHORS. 2012-01-07 17:07:22 +01:00
Themaister 2e456b2570 Rename gl-> to vid-> for consistency. 2012-01-07 15:30:52 +01:00
TwinAphex51224 fe17a42e62 (360) Fixed 2012-01-07 15:28:39 +01:00
Themaister c46866c6e5 Use correct geometries (I hope). 2012-01-07 15:21:23 +01:00
Themaister 3117633adf Actually use a viewport. 2012-01-07 15:11:57 +01:00
Themaister 8a49321648 Rename shader vars again. :D 2012-01-07 15:03:09 +01:00
Themaister 18f027ed41 Rename shader variable names. 2012-01-07 15:00:51 +01:00
TwinAphex51224 79b9c68cb5 (360) Compile fixes 2012-01-07 14:59:11 +01:00
Themaister 2b1344c3cf Clean up and add missing bits to 360 D3D9. 2012-01-07 14:54:55 +01:00
TwinAphex51224 da26925118 (360) Fleshed out video driver some more 2012-01-07 14:13:23 +01:00
Themaister f2a152f7c9 Minor cleanup. 2012-01-07 11:47:53 +01:00
Themaister 1953ea7312 Fix Xenon build. 2012-01-07 11:32:39 +01:00
TwinAphex51224 e55dbe944d (360) changed buf to uint8_t * 2012-01-06 22:55:07 +01:00
Themaister f5ad906e7b Don't need byteswapping on 360. 2012-01-06 22:49:30 +01:00
TwinAphex51224 7cad2bcd6e (360) Some sound fixes 2012-01-06 22:40:40 +01:00
Themaister cc921f25ed Use integer audio on 360. 2012-01-06 22:30:12 +01:00
Themaister 435109ceae Rework SRAM semantics for Sufami. 2012-01-06 20:32:30 +01:00
Themaister ca375f65d5 Call CreateEvent. 2012-01-06 19:45:27 +01:00
Themaister 76212f47bf Fix indentation. 2012-01-06 18:51:45 +01:00
TwinAphex51224 6efb904919 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-06 14:12:38 +01:00
TwinAphex51224 072342cdab (360) Gets to initing audio 2012-01-06 14:12:12 +01:00
Themaister 09761c0786 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-06 00:05:05 +01:00
Themaister c48fab00e8 Remove unneeded header. 2012-01-06 00:04:48 +01:00
TwinAphex51224 d1c562ce4e (360) Small correction to main.c file 2012-01-05 23:19:14 +01:00
Themaister 45cae81d51 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-05 23:10:28 +01:00
Themaister 30e28acfb3 Workaround GetFullPathName not existing on XDK. 2012-01-05 23:09:52 +01:00
TwinAphex51224 00459365c4 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-05 22:47:54 +01:00
TwinAphex51224 649884bc05 (360) Added main files 2012-01-05 22:47:34 +01:00
TwinAphex51224 e1af420b2d (360) More work on 360 2012-01-05 22:46:11 +01:00
Themaister 613f50dd14 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-05 21:45:32 +01:00
Themaister a18c0b2b14 Use const. 2012-01-05 21:43:55 +01:00
TwinAphex51224 d7f8500b3a Merge branch 'master' of github.com:Themaister/SSNES 2012-01-05 20:54:26 +01:00
TwinAphex51224 7ecf9681c5 (360) Updated vcxproj file 2012-01-05 20:54:04 +01:00
Themaister e9ca7acce9 Merge branch 'master' of github.com:Themaister/SSNES 2012-01-05 19:44:39 +01:00
Themaister ea68de8070 Don't use *A() version. 2012-01-05 19:44:11 +01:00
TwinAphex51224 0fa0bfeb74 (360) Compiles in dynamic.c 2012-01-05 19:42:29 +01:00
TwinAphex51224 4a5d0d8dfb (360) Updated solution 2012-01-05 19:35:56 +01:00
Themaister af35a18515 :v 2012-01-05 19:34:15 +01:00
Themaister 5560babc11 Some build fixups. 2012-01-05 19:33:38 +01:00
Themaister 3e76201d80 Rename to C++. 2012-01-05 19:28:19 +01:00
Themaister 5b15d8626c Restructure XAudio2 360 driver. 2012-01-05 19:27:58 +01:00
TwinAphex51224 f8a03a7d5d Merge branch 'master' of github.com:Themaister/SSNES 2012-01-05 18:38:49 +01:00
TwinAphex51224 b7b9acb336 (360) compiles now 2012-01-05 18:38:29 +01:00
Themaister 44e2d66cf5 Mainstub clean. 2012-01-05 17:53:30 +01:00
Themaister 9747767474 Use GetFileAttributes. 2012-01-05 17:41:04 +01:00
Themaister cee33327f8 Ugh 2012-01-05 17:28:11 +01:00
Themaister f70b52a0df Don't use unicode. 2012-01-05 17:27:48 +01:00
Themaister 0b62771b54 Don't use getenv on XBOX. 2012-01-05 17:27:18 +01:00
Themaister b168109672 Fix missing stuff. 2012-01-05 17:23:22 +01:00
Themaister d8b6aebe9a Use plain ASCII for directories. 2012-01-05 17:22:03 +01:00
TwinAphex51224 4812b632c3 (360) Fixed most compile errors for 360 2012-01-05 15:11:55 +01:00
TwinAphex51224 8320d0a0e9 (360) Xaudio2 driver compiles now 2012-01-05 14:48:54 +01:00
TwinAphex51224 a287ebe736 (360) New Xaudio2 driver 2012-01-05 14:17:35 +01:00
TwinAphex51224 ebea0220cd (360) Added 360 solution and added some defines 2012-01-05 13:30:13 +01:00
TwinAphex51224 2b01f36fc0 (360) Added preliminary xdk 360 drivers 2012-01-05 12:37:27 +01:00
Themaister 7e3092dc93 Build in freetype. Will be used later. 2012-01-03 13:04:23 +01:00
Themaister 114c723d59 Only init input once. 2012-01-03 12:22:07 +01:00
Themaister da39f8d3d6 Support classic controller. 2012-01-03 12:11:02 +01:00
Themaister 33b76628aa Far better vsync handling. 2012-01-03 11:32:07 +01:00
Themaister 94162f452d Use RGB5A3 for Wii. 2012-01-03 10:32:51 +01:00
Themaister 318d875981 Small cleanups. 2012-01-03 02:50:45 +01:00
Themaister 520878272c Checks if swapinterval succeeds. 2012-01-02 22:09:55 +01:00
Themaister fc87336c45 MSVC doesn't have PATH_MAX. 2012-01-02 16:03:39 +01:00
Themaister d66e039536 Fix 15->16 bit conversions. 2012-01-02 15:43:46 +01:00
Themaister eeebc2d06b Optimize a bit. 2012-01-02 14:50:03 +01:00
Themaister 7d1ebdf94a Pick linear/nearest filtering correctly. 2012-01-02 13:45:31 +01:00
Themaister 3d1b0ef35b Merge branch 'fix' 2012-01-02 13:33:27 +01:00
Themaister c2ba0d474c Use limits.h and PATH_MAX. 2012-01-02 13:33:03 +01:00
Themaister 793c00e614 Attempt on tiled textures for Wii. 2012-01-02 12:56:09 +01:00
Themaister d4093dc31c Fix build for gekko. 2012-01-02 12:12:30 +01:00
Themaister bc66841a29 More correct save state and rewind handling. 2011-12-27 18:30:14 +01:00
Themaister f4cc8a4bca Update filters. 2011-12-27 03:33:18 +01:00
Themaister 539563f0f4 Add filters to project. 2011-12-27 03:27:28 +01:00
Themaister 8c5d86a6eb Add logging to SDL_Init(). 2011-12-27 01:04:50 +01:00
Themaister 884c113645 Cleanup stupid code. 2011-12-27 00:54:31 +01:00
Themaister 70587bc0df More verbosely log SDL failure. 2011-12-27 00:37:29 +01:00
Themaister df4e0bb1e4 Don't use x64libs. 2011-12-27 00:15:58 +01:00
Themaister cdc92af959 Cleanups. 2011-12-26 16:43:47 +01:00
Themaister 763a5bf2c0 Style nit. 2011-12-26 16:22:34 +01:00
Themaister 8301cf8a2f Style nit. 2011-12-26 16:14:33 +01:00
Themaister 44da8a6749 :v 2011-12-26 01:32:19 +01:00
Themaister 06309ba1e0 Build some more stuff. 2011-12-26 00:06:41 +01:00
Themaister 004ca0fe89 Better formatting. 2011-12-25 21:43:00 +01:00
Themaister 40cce7c9d6 Also log compiler version normally. 2011-12-25 21:39:58 +01:00
Themaister 1c29d31859 Better formatting. 2011-12-25 21:20:07 +01:00
Themaister d3af29fa1f Compiler logging macros. 2011-12-25 21:16:48 +01:00
Themaister c5d1fd32d5 Deinit audio before video. 2011-12-25 19:31:05 +01:00
Themaister a4767d3d43 Add python build. Fix ssize_t define. 2011-12-25 18:25:37 +01:00
Themaister c26f527c20 Enable SSE for 64-bit builds. 2011-12-25 16:50:13 +01:00
Themaister 0c8d85d589 Minor fixes. 2011-12-25 16:47:03 +01:00
Themaister 0c16e1a134 x64 build. 2011-12-25 16:36:56 +01:00
Themaister 0a887395eb Remove useless global. 2011-12-25 16:11:48 +01:00
Themaister 9118976c49 Don't include general.h 2011-12-25 12:56:21 +01:00
Themaister 7f1e599186 Use modern FFmpeg defines. 2011-12-25 12:50:34 +01:00
Themaister 672102d377 Change asserts to ssnes_assert(). 2011-12-25 12:47:47 +01:00
Themaister fe7f05e717 Style nit. 2011-12-25 12:14:26 +01:00
Themaister 0724ab2ca1 Fix assertion bugs. 2011-12-25 12:13:19 +01:00
Themaister c272ba56ad Fix build for Release mode. 2011-12-25 11:45:27 +01:00
Themaister 381498e945 Print feature for DirectSound. 2011-12-25 01:59:30 +01:00
Themaister 70f07196ea gettimeofday() should return int. 2011-12-25 01:54:29 +01:00
Themaister c8dee57278 Set constant macros with define. 2011-12-25 01:45:09 +01:00
Themaister 0ab305156b Fixup header. 2011-12-25 01:41:12 +01:00
Themaister eac468ba19 MSVC compat. 2011-12-25 01:38:59 +01:00
Themaister 18f407110b Fixup compatibility. 2011-12-24 20:43:58 +01:00
Themaister ceee10b56c Fix types. 2011-12-24 15:57:43 +01:00
Themaister 9805bcc5f9 Merge branch 'master' of github.com:Themaister/SSNES 2011-12-24 15:47:47 +01:00
Themaister d5fca50a2f Can build for C++. 2011-12-24 15:26:01 +01:00
Themaister 4ca72bd7e6 Fix endian issues and strict aliasing. 2011-12-24 14:41:19 +01:00
Themaister 62ead00f0f Some additions, but still broken. 2011-12-24 14:41:19 +01:00
TwinAphex51224 5dc573ed38 (Libxenon) Changed texture size to 512x512 - stop libxenon development
for now - no double buffering/triple buffering available - return to
it when it's more mature
2011-12-24 14:41:19 +01:00
TwinAphex51224 fa053ffc2b (Libxenon) Fixed colors 2011-12-24 14:41:18 +01:00
TwinAphex51224 be6c7bad24 (Libxenon) Revert to Xenos driver that works - current issues - colors
are wrong (doing | XE_FMT_ARGB produces 'distorted' graphics but right colors) - no vsync (doing while Xe_IsVBlank(device) Xe_Sync(device) makes everything too
slow
2011-12-24 14:41:18 +01:00
Themaister 2680971bb3 Try some stuff. 2011-12-24 14:41:18 +01:00
Themaister 630f19f248 ... 2011-12-24 14:41:18 +01:00
Themaister ef4bee2e4e Minor fix. 2011-12-24 14:41:18 +01:00
Themaister f182a2ad24 Debork party. Untested. 2011-12-24 14:41:18 +01:00
Themaister 3eb98951f7 :v 2011-12-24 14:41:18 +01:00
Themaister f9d4bbf4d3 Fix endian issues and strict aliasing. 2011-12-19 01:27:04 +01:00
Themaister eff4fcecae Some additions, but still broken. 2011-12-18 13:27:06 +01:00
TwinAphex51224 cbfdc9cf97 (Libxenon) Changed texture size to 512x512 - stop libxenon development
for now - no double buffering/triple buffering available - return to
it when it's more mature
2011-12-16 18:54:12 +01:00
TwinAphex51224 034c7c70fb (Libxenon) Fixed colors 2011-12-16 17:22:37 +01:00
TwinAphex51224 44ad016b91 (Libxenon) Revert to Xenos driver that works - current issues - colors
are wrong (doing | XE_FMT_ARGB produces 'distorted' graphics but right colors) - no vsync (doing while Xe_IsVBlank(device) Xe_Sync(device) makes everything too
slow
2011-12-16 17:09:33 +01:00
Themaister 5ed0d00249 Try some stuff. 2011-12-16 16:38:25 +01:00
Themaister 6336fb4a1b ... 2011-12-16 16:26:44 +01:00
Themaister 99497e21cf Minor fix. 2011-12-16 16:21:58 +01:00
Themaister 0181d97cae Debork party. Untested. 2011-12-16 16:02:30 +01:00
TwinAphex51224 968c73a748 Merge branch 'master' of github.com:Themaister/SSNES 2011-12-16 15:22:56 +01:00
TwinAphex51224 13f9e94f61 (Libxenon 360) Shows video for one/two frames, then crashes 2011-12-16 15:22:25 +01:00
Themaister 8c1018d573 Merge branch 'master' of github.com:Themaister/SSNES 2011-12-16 15:09:46 +01:00
Themaister d4d00a35d7 :v 2011-12-16 15:09:15 +01:00
TwinAphex51224 e3177fd489 (Libxenon) Xenos gfx commit - still broken 2011-12-16 14:43:09 +01:00
Themaister dd1300f1cc Fix rewind granularity setting when not playing movies. 2011-12-16 10:19:45 +01:00
TwinAphex51224 7f03af2b2b (Libxenon) starts up now - borked graphics though :) 2011-12-15 15:32:47 +01:00
TwinAphex51224 f431f77834 (Libxenon) fix (still crashes during init) 2011-12-15 15:19:03 +01:00
TwinAphex51224 7c28a62b40 (Libxenon) No more SDL 2011-12-15 13:54:22 +01:00
TwinAphex51224 a360042f77 Merge branch 'master' of github.com:Themaister/SSNES 2011-12-15 13:38:55 +01:00
TwinAphex51224 82af27cf33 (Libxenon) Initial xenos graphics driver 2011-12-15 13:38:28 +01:00
Themaister 0b78abb31d hrr drr. 2011-12-15 00:28:47 +01:00
Themaister 2fd8ffbf22 Some progress at least. 2011-12-14 23:56:07 +01:00
Themaister 83f7be0cbb Some more stuff. 2011-12-14 22:29:12 +01:00
Themaister 7f5db4d70f Boots up, but broken graphics. 2011-12-14 21:44:03 +01:00
Themaister 4f04c1288b Use fatInit default. 2011-12-14 19:11:46 +01:00
Themaister 8a2c5bf9e1 Some cleanups. 2011-12-14 17:05:23 +01:00
Themaister 5c05e309c1 Xenon input takes prio. 2011-12-14 16:53:13 +01:00
Themaister bd147270eb Use built-in getopt. 2011-12-14 16:40:25 +01:00
Themaister 528cf8d472 Don't use SDL input on xenon. 2011-12-14 16:37:31 +01:00
Themaister 0fce2f409f Add a warning. :3 2011-12-14 16:29:38 +01:00
Themaister fd7b0b05b8 Hurr. 2011-12-14 16:01:16 +01:00
Themaister 9abc7c00c9 It links :o 2011-12-14 14:52:58 +01:00
Themaister ebc5f433cd It links :o 2011-12-14 14:36:23 +01:00
Themaister aa4f79f236 Start working on video. 2011-12-14 14:26:40 +01:00
Themaister 62f5c53b72 Start on Wii input. 2011-12-14 13:20:22 +01:00
Themaister 534163a57f Start adding stuff for Wii. 2011-12-14 12:49:13 +01:00
TwinAphex51224 325a9fb48e (Libxenon) D-pad works now in ROM browser menu 2011-12-14 08:36:04 +01:00
TwinAphex51224 ee43531a99 Merge branch 'master' of github.com:Themaister/SSNES 2011-12-14 01:35:46 +01:00
TwinAphex51224 757fa71469 (Libxenon) Added (non-working) input driver 2011-12-14 01:35:17 +01:00
Themaister bfee7986bd Fix missing break; 2011-12-14 00:58:17 +01:00
Themaister 9aaad17c1a Update Makefile. 2011-12-14 00:44:38 +01:00
Themaister 93874bba83 Fixup makefile. 2011-12-14 00:41:06 +01:00
Themaister 9c67452f10 <________________________< 2011-12-14 00:36:28 +01:00
Themaister 0416a2ae61 Don't use float <_< 2011-12-14 00:30:03 +01:00
Themaister 8bbde14019 Merge branch 'master' of github.com:Themaister/SSNES 2011-12-14 00:25:26 +01:00
Themaister 0e8f2339d8 Might work better ... 2011-12-14 00:25:04 +01:00
TwinAphex51224 9f37427d7a (Libxenon) Compile with -O3 2011-12-13 23:50:56 +01:00
Themaister 6ad4b1f15a Little endian DAC on 360 (lolwut?) 2011-12-13 23:44:55 +01:00
Themaister a39c0f01f9 Should fix up audio driver a bit. 2011-12-13 23:38:05 +01:00
TwinAphex51224 1136820124 (Libxenon) Terribly borked libxenon audio driver :) 2011-12-13 23:17:37 +01:00
TwinAphex51224 2a3f3bad23 (360 Libxenon) Initial xenon 360 audio driver 2011-12-13 22:57:49 +01:00
Themaister 74def91a53 Debork main a bit. 2011-12-13 21:48:17 +01:00
TwinAphex51224 bc62e1be08 (Libxenon) Added slimjim Libxenon filebrowser - from examples 2011-12-13 21:12:50 +01:00
Themaister 25aea134ef Add temporary hack for SDL cond in Xenon. 2011-12-13 19:34:45 +01:00
Themaister e488c3081d Small nit. 2011-12-11 13:14:44 +01:00
Themaister 331f46fb24 Missing stuff. 2011-12-11 12:51:32 +01:00
Themaister e88662cab0 Updates for 0.9.3. 2011-12-11 12:50:16 +01:00
Themaister 395f6d1d3c Build fixups. 2011-12-10 18:02:50 +01:00
Themaister 94bd78b3e1 Merge branch 'master' of github.com:Themaister/SSNES
Conflicts:
	Makefile.xenon
2011-12-10 17:42:07 +01:00
Themaister dc373fb7d0 Gets to link, but fails there. 2011-12-10 17:41:16 +01:00
Themaister 140812d64a Fixup xenon makefile a bit. 2011-12-10 16:26:26 +01:00
TwinAphex51224 a91c4e556f (360 Libxenon) change to makefile - use built-in getopt 2011-12-10 16:22:37 +01:00
Themaister 372c622166 Nits. 2011-12-10 15:23:20 +01:00
TwinAphex51224 d961d68e9c (360 / Libxenon) Added Libxenon Makefile 2011-12-07 03:19:12 +01:00
Themaister 33a325a730 Nit. 2011-12-07 01:13:06 +01:00
Themaister 909b25c7ac Remove XML stuff. 2011-12-04 18:44:50 +01:00
Themaister 77f110c23e Nits. 2011-12-04 18:26:17 +01:00
Themaister 9dc9416ef9 Merge branch 'ssnes-ps3' 2011-12-04 18:13:31 +01:00
Themaister 0b20f11617 Nits. 2011-12-04 18:06:50 +01:00
Themaister c9594776f8 Style nits. 2011-12-04 18:06:50 +01:00
Themaister 8f55b9904d Update license. 2011-12-04 18:06:50 +01:00
Themaister 093ba1c33d Dynamic fix. 2011-12-04 18:06:50 +01:00
Themaister 67a434d563 Clean. 2011-12-04 18:06:50 +01:00
Themaister ff0c3f047a Some cleanups. 2011-12-04 18:06:50 +01:00
Themaister 2934ba301b Nit. 2011-12-04 18:06:50 +01:00
Themaister f3627aaf59 Nits. 2011-12-04 18:03:08 +01:00
Themaister dc8a2dea72 Style nits. 2011-12-04 18:00:55 +01:00
Themaister 329969eb05 Update license. 2011-12-04 17:57:25 +01:00
Themaister 71923af675 Dynamic fix. 2011-12-04 17:54:00 +01:00
Themaister 18e58ca5f4 Clean. 2011-12-04 17:30:44 +01:00
Themaister 8c3aebbbc8 Some cleanups. 2011-12-04 17:29:59 +01:00
Themaister 7f40c11eb7 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-ps3 2011-12-04 17:24:28 +01:00
Themaister 0ed668d1b5 Minor cleanups. 2011-12-04 17:19:21 +01:00
Themaister 1c8632cac9 Nit. 2011-12-04 17:17:49 +01:00
TwinAphex51224 e7324989fc (PS3) Better extra button bindings 2011-12-04 04:11:02 +01:00
TwinAphex51224 a7fc3807b9 (PS3) Cleaned up indenting in ps3_input.c 2011-12-04 04:00:17 +01:00
TwinAphex51224 99ad7bcc51 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-04 03:43:52 +01:00
Themaister 5b88e338df Nits. 2011-12-04 01:42:00 +01:00
Themaister 425af71450 GET_CAN_REWIND. 2011-12-04 01:40:25 +01:00
Themaister 19c5eab07a Minor clean. 2011-12-04 01:30:16 +01:00
Themaister e5286cbe39 Update XAudio for pure C. 2011-12-04 01:10:16 +01:00
Themaister 02d40aa212 Drop shadows for fonts. 2011-12-03 19:48:13 +01:00
Themaister 8a5c537e15 Fix warning. 2011-12-03 04:09:40 +01:00
TwinAphex51224 c6c4f2f4d1 (PS3) Debug fonts hooked up 2011-12-03 03:52:53 +01:00
TwinAphex51224 5bc7ea4045 (PS3) Properly exits now with shader loaded 2011-12-03 03:10:23 +01:00
TwinAphex51224 077acf7894 (PS3) Savestates hooked up (R2 + R3 - save state - L2 + R3 - load state -
R2 + Right stick right - save state plus - R2 + Right stick left - save state minus)
2011-12-03 02:40:20 +01:00
TwinAphex51224 c5f86f12c0 Revert "(PS3) Would not cleanly exit on PS3 without this - perhaps something"
This reverts commit 243e941d81.
2011-12-03 01:56:41 +01:00
TwinAphex51224 243e941d81 (PS3) Would not cleanly exit on PS3 without this - perhaps something
Cg-related needs deiniting prior to exit(0)
2011-12-03 01:54:57 +01:00
TwinAphex51224 d67e6b7c15 (PS3) Cg shader support fixed 2011-12-03 01:26:56 +01:00
Themaister f76bf59fed Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-03 00:49:26 +01:00
Themaister 1c4d88eb04 Compiles ... properly. 2011-12-03 00:49:09 +01:00
Themaister ad04db8365 Fix includes. 2011-12-03 00:48:42 +01:00
TwinAphex51224 a63ccbbdab (PS3) Implemented rewind/fast forward hooks 2011-12-03 00:07:01 +01:00
Themaister 278f314c03 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 22:57:13 +01:00
Themaister a3abda7e7b Refactor. 2011-12-02 22:56:11 +01:00
Themaister c0a9db111d Fix bug with reordering. 2011-12-02 22:23:19 +01:00
TwinAphex51224 676ce10119 (PS3) Now reads from config file 2011-12-02 22:22:44 +01:00
Themaister c18dce4783 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 22:25:37 +01:00
Themaister 088b01b52e More logial ordering. 2011-12-02 21:37:35 +01:00
Themaister c0f436b8ab Minor nit. 2011-12-02 21:25:25 +01:00
Themaister 3377020242 Fixup build. 2011-12-02 21:24:33 +01:00
Themaister 6db58fe1dd Merge branch 'ssnes-consoles' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 21:22:36 +01:00
Themaister 67c7cd8de9 No default config path on ps3. 2011-12-02 21:22:14 +01:00
Themaister 457a3d458a Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles
Conflicts:
	general.h
2011-12-02 21:18:09 +01:00
Themaister 6538312d86 Fix some includes. 2011-12-02 21:16:51 +01:00
TwinAphex51224 7f1a5075b1 Updated Makefile 2011-12-02 21:14:25 +01:00
Themaister e412ecdefe Do not exit() prematurely. 2011-12-02 19:28:39 +01:00
Themaister 67b89d6f42 Kill off useless font rendering code. 2011-12-02 19:19:48 +01:00
Themaister c8d3278dbc Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 19:15:21 +01:00
Themaister 3556445660 Add new extension support. 2011-12-02 19:12:47 +01:00
Themaister f28fc0cabb Merge branch 'ssnes-consoles' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 16:22:05 +01:00
Themaister e0bc548400 sys_lw synchro. 2011-12-02 16:21:01 +01:00
TwinAphex51224 011a4c8a89 Merge branch 'ssnes-consoles' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 15:59:40 +01:00
TwinAphex51224 87bc5220eb (PS3) Takes care of audio pop 2011-12-02 15:59:07 +01:00
Themaister 673d0ed1a2 Minor fix. 2011-12-02 15:55:49 +01:00
Themaister a5079bdda1 Should improve the state of audio. 2011-12-02 15:50:51 +01:00
Themaister fc43e7155e Should fixup input. 2011-12-02 15:33:14 +01:00
TwinAphex51224 4935333b63 (PS3) Updated icon + PARAM.SFO title 2011-12-02 04:52:29 +01:00
TwinAphex51224 5a3232adff (PS3) SSNES PS3 lives :) - audio, video works - controls don't
seem to work
2011-12-02 03:46:31 +01:00
TwinAphex51224 d03f351f33 (PS3) Crashes in find_audio_driver (driver.c) 2011-12-02 03:32:04 +01:00
TwinAphex51224 8d5bf997a9 Made global g_quitting variable in PSGL driver 2011-12-02 02:51:21 +01:00
Themaister 0738480439 Make sure set_defaults is called. 2011-12-02 02:48:04 +01:00
TwinAphex51224 9a5e1a31ad Merge branch 'ssnes-consoles' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 02:47:28 +01:00
Themaister 5ab7664f49 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 02:48:26 +01:00
TwinAphex51224 1cb2c60ccc Calblack put in video_psgl.c - not sure how to use it there 2011-12-02 02:46:47 +01:00
Themaister 1356d0ab4c .___. 2011-12-02 02:41:32 +01:00
Themaister b4c4a65f2d Clear up input. 2011-12-02 02:34:06 +01:00
Themaister ab3cf8daca Merge branch 'ssnes-consoles' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 02:25:40 +01:00
Themaister 2b6c252747 Minor fixes. 2011-12-02 02:22:29 +01:00
TwinAphex51224 ec9a6ac90a Can make a PKG now 2011-12-02 02:07:46 +01:00
Themaister a207549f18 fixup stub. 2011-12-02 01:59:44 +01:00
Themaister efbf9354f9 It ... links! 2011-12-02 01:59:07 +01:00
Themaister 216ddc9fd6 Merge branch 'ssnes-consoles' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 01:38:24 +01:00
Themaister 3b668cccd3 Add audio/utils.o. 2011-12-02 01:38:04 +01:00
Themaister 30a86a2845 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-12-02 01:35:15 +01:00
Themaister a7870aa888 Altivec sample conversion. 2011-12-02 01:34:02 +01:00
TwinAphex51224 271b99981c Won't link right now 2011-12-02 01:28:47 +01:00
Themaister 08ef01bb13 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles
Conflicts:
	dynamic.c
2011-12-02 00:07:54 +01:00
Themaister e778af462a Stub main. 2011-12-02 00:01:48 +01:00
Themaister 9d124b2380 Do not use anything dylib related if not compiled in. 2011-12-01 22:36:26 +01:00
Themaister f24e7cd665 Texrefs (untested). 2011-12-01 22:21:15 +01:00
Themaister e7f1526942 Fix compilation errors. 2011-12-01 21:54:42 +01:00
TwinAphex51224 647b1ba53c (PS3) Comiles now, doesn't link 2011-12-01 21:23:49 +01:00
TwinAphex51224 eac8d9f191 Update to PSGL driver 2011-12-01 11:25:08 +01:00
TwinAphex51224 50babe8432 More commits to PSGL driver 2011-11-30 23:50:31 +01:00
TwinAphex51224 8171977ed7 Preliminary version of PSGL video driver 2011-11-30 21:54:25 +01:00
TwinAphex51224 f8aaf1df1e (PS3) Some more commits 2011-11-30 18:32:45 +01:00
Themaister 04d0d84d01 Fix up more paths. 2011-11-30 18:31:09 +01:00
TwinAphex51224 f4aa9fa865 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-11-30 18:27:11 +01:00
TwinAphex51224 40ef7d6f00 Improved Makefile a bit 2011-11-30 18:26:42 +01:00
TwinAphex51224 66b7b1691c (PS3) Removed thread.o from Makefile 2011-11-30 18:19:34 +01:00
Themaister 43972d4c35 Fix build. 2011-11-30 18:18:50 +01:00
TwinAphex51224 632545c409 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-11-30 18:13:27 +01:00
TwinAphex51224 3a47e2cd63 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-11-30 18:11:06 +01:00
Themaister a221e3e4cd Enable/disable threading support. 2011-11-30 17:46:58 +01:00
Themaister b87f50dc9d Fix include path. 2011-11-30 17:34:18 +01:00
Themaister a5b3f421d1 Fix include paths for libsnes header. 2011-11-30 17:32:30 +01:00
TwinAphex51224 182525afa9 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-11-30 17:28:11 +01:00
TwinAphex51224 419afbcb83 Progresses to thread.c now 2011-11-30 17:27:47 +01:00
Themaister 12ca70a308 Refactor binds. 2011-11-30 17:25:44 +01:00
TwinAphex51224 1fa7663d3b Put in old input driver too - progresses to dynamic.c now 2011-11-30 17:24:18 +01:00
TwinAphex51224 2e34c6fc5c Moved in old PS3 audio driver 2011-11-30 17:11:42 +01:00
Themaister cb7002559d Put defines in makefile. 2011-11-30 17:01:15 +01:00
TwinAphex51224 36ec92793f Put PACKAGE_VERSION define in Makefile 2011-11-30 16:58:20 +01:00
TwinAphex51224 4187d70b30 Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-11-30 16:56:38 +01:00
Themaister 5969655c3c Do not allow netplay args if not compiled in. 2011-11-30 16:43:09 +01:00
Themaister 09d2ec7d3a Do not build in anything netplay related if not included. 2011-11-30 16:41:00 +01:00
TwinAphex51224 27b975d0fc Add in PS3 define for ssnes_sleep 2011-11-30 16:40:52 +01:00
TwinAphex51224 6da64013fa Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-11-30 16:38:53 +01:00
Themaister d8eb5de380 Do not include netplay header needlessly. 2011-11-30 16:27:16 +01:00
Themaister 23aa8bbe7a Actually use sleep param. 2011-11-30 16:26:23 +01:00
TwinAphex51224 3b5472dbac Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-11-30 16:22:16 +01:00
TwinAphex51224 3b4e60aada Header guards for netplay.c not necessary 2011-11-30 16:21:21 +01:00
TwinAphex51224 8d8fb44c18 Use getopt replacement 2011-11-30 16:19:12 +01:00
TwinAphex51224 b46fb60a6e Merge branch 'master' of github.com:Themaister/SSNES into ssnes-consoles 2011-11-30 16:02:49 +01:00
Themaister f7399bbc8b Fix docs. 2011-11-30 12:09:22 +01:00
Themaister 7f7d47b120 Custom getopt for portability. 2011-11-30 11:48:53 +01:00
TwinAphex51224 e7aa3ed0cc Compile in OpenGL and Cg 2011-11-30 01:41:50 +01:00
TwinAphex51224 0ece8b1319 Added static Makefile for PS3 2011-11-30 01:33:14 +01:00
TwinAphex51224 557e05dd12 initial new branch 2011-11-30 01:07:38 +01:00
Themaister 08a1496501 Use big-endian BSV1 magic.
Keep compatibility with old implementation.
Documentation was suggesting little-endian, but this was not correct.
2011-11-28 02:11:33 +01:00
Themaister 5a24037c61 Update joyconfig. 2011-11-26 16:02:49 +01:00
Themaister 5dbd1ea35c Add mute toggle. 2011-11-26 15:54:58 +01:00
Themaister 2476e3dee3 Updates for 0.9.2. 2011-11-24 13:13:55 +01:00
Themaister c05a5c9fdd Only init Video if it isn't already. 2011-11-23 03:26:56 +01:00
Themaister 503c51d633 Check for additional fonts. 2011-11-22 18:52:20 +01:00
Themaister 46054de4f8 Fix possible segfault. 2011-11-22 17:32:38 +01:00
Themaister 604eb9b973 Can dupe extension. 2011-11-22 17:27:02 +01:00
Themaister 0e72120bdc Updates for 0.9.2-rc2. 2011-11-21 16:30:35 +01:00
Themaister b8064f5d42 New semantics for BSV movie recording. 2011-11-20 20:19:05 +01:00
Themaister 379b14a0f3 Flush more sanely. 2011-11-20 03:19:17 +01:00
Themaister 2a598c0b97 Do not quit SSNES on movie playback end. 2011-11-20 03:00:21 +01:00
Themaister aa124b4c40 Should fix occasional horrible noise on end of recordings. 2011-11-20 02:44:21 +01:00
Themaister bb5e31df0d Still record audio even if audio is not enabled. 2011-11-20 02:06:25 +01:00
Themaister e49d216884 Check for large skews in timing. 2011-11-19 14:16:55 +01:00
Themaister 598d06fcb5 More explicitly log paths. 2011-11-19 01:33:21 +01:00
Themaister 7f13ec88e6 Simplify things a bit. 2011-11-18 18:43:02 +01:00
Themaister c5c60c6f53 Add --bsvrecord. 2011-11-18 18:03:24 +01:00
Themaister 81b0e6d0a3 Use display refresh rates rather than input rate directly. 2011-11-18 15:14:56 +01:00
Themaister da97b29d0b Update FFmpeg to use new define in Win32. 2011-11-18 13:07:24 +01:00
Themaister 69b7f92285 Updates for 0.9.2-rc1. 2011-11-18 12:17:25 +01:00
Themaister 3a9dbbc8b7 Pause while inactive disabled by default. 2011-11-17 21:17:29 +01:00
Themaister bf5db10459 Change timeout message to be less misleading. 2011-11-16 22:30:57 +01:00
Themaister 4fa27a5f0f Binaries link in README. 2011-11-16 21:28:30 +01:00
Themaister 3e7c412738 Custom timing support for FFmpeg recording. 2011-11-16 18:56:42 +01:00
Themaister 88c870dcfa Allow -L/--libsnes from command line. 2011-11-15 21:15:12 +01:00
Themaister 66e1179503 Do not remove -s. 2011-11-15 16:44:40 +01:00
Themaister 4ecea5d0a4 Expose python to external drivers. 2011-11-15 15:41:49 +01:00
Themaister 57816edfd3 Fix some hardcoding. 2011-11-13 17:44:20 +01:00
Themaister 17cf0985c5 Typo. 2011-11-13 17:10:21 +01:00
Themaister 776b0a1e2d Add a helper define for input scale. 2011-11-13 17:09:49 +01:00
Themaister 4a6392aefa Fix wrong placement of line in print_help(). 2011-11-13 01:12:32 +01:00
Themaister 29dd4727b8 Disable used attribs in Cg as well. 2011-11-12 18:31:22 +01:00
Themaister face42a888 Disable used attributes on shader change. 2011-11-12 18:20:54 +01:00
Themaister 45fa6795c3 Fixups. 2011-11-12 16:43:59 +01:00
Themaister a9d339efb4 Use glColorPointer(). 2011-11-12 15:51:37 +01:00
Themaister 60841b01a5 Use custom "stock" program. 2011-11-12 15:26:24 +01:00
Themaister ad67511483 Cleanups. PREV{1-6} for GLSL as well. 2011-11-12 14:18:10 +01:00
Themaister 104fb4fb16 nits. 2011-11-12 13:00:37 +01:00
Themaister 816ef095ed Lots of PREV frames in Cg. 2011-11-12 12:55:03 +01:00
Themaister 48e8472f9c Ring buffer of 8 textures :o 2011-11-12 12:28:07 +01:00
Themaister 1755500b19 Source cleanup. 2011-11-12 01:42:37 +01:00
Themaister 4bfc827eb2 Some fixes to Python. 2011-11-11 19:20:56 +01:00
Themaister ddfeacbd83 Minor fixes and cleanups to BSV. 2011-11-11 00:55:35 +01:00
Themaister 79353f861c Do not report dupes. 2011-11-10 00:49:45 +01:00
Themaister f3f4efe304 Improve error reporting in Cg. 2011-11-10 00:46:39 +01:00
Themaister 51721b4cb6 video_font_enable. 2011-11-10 00:15:41 +01:00
Themaister 477091ce8f Do not force crop_overscan with ffmpeg. 2011-11-10 00:03:52 +01:00
Themaister 2707b87767 Should fix overscan overcrop. 2011-11-09 23:58:14 +01:00
Themaister b3d422b5cd rubyFrameDirection / IN.frame_direction. 2011-11-09 23:45:34 +01:00
Themaister d1dc65f202 Cleaner setup of bind-map. 2011-11-09 22:47:12 +01:00
Themaister 7815940a97 SNES_ENVIRONMENT_OVERSCAN. 2011-11-09 22:18:48 +01:00
Themaister 4f841c208d Use --qp 0 rather than --crf 0 for lossless. 2011-11-07 23:16:32 +01:00
Themaister b4f0d9b8f8 Restrict number of lag frames. 2011-11-06 20:38:42 +01:00
Themaister b96ab2982c Should fix minor issues with timeouts when lag frames > 8. 2011-11-06 20:28:02 +01:00
Themaister 825c1de7d1 Nits. 2011-11-05 15:24:29 +01:00
Themaister 6ada4d87d3 Style nit. 2011-11-05 13:34:41 +01:00
Themaister 53abc92322 Add some metadata. Should be a workaround. 2011-11-05 12:25:09 +01:00
Themaister a816082ac3 Style nit. 2011-11-05 11:44:17 +01:00
Themaister 47e63f1c6b Style nit. 2011-11-05 11:37:04 +01:00
Themaister cdf3d05c8e Should fix spurious timeouts for netplay. 2011-11-04 00:18:17 +01:00
Themaister 389e9ba0dc Style nit. 2011-11-04 00:07:53 +01:00
Themaister a6f7a2311f Minor cleanups for hermite. 2011-11-03 23:48:36 +01:00
Themaister f19d99d523 Log error when netplay init fails. 2011-11-03 21:05:12 +01:00
Themaister e7082fd6ea Warning nit. 2011-11-02 20:33:37 +01:00
Themaister 4806d2fe88 Clear up inconsistencies, and avoid breaking standard compliance. 2011-11-02 20:04:31 +01:00
Themaister f85ff7124b More nits. 2011-11-02 19:34:08 +01:00
Themaister 0f010cf3d2 Fix style nits. 2011-11-02 19:31:36 +01:00
Themaister 95636d4f04 Refactor XVideo driver. Also, attempts harder to find suitable formats. 2011-11-02 17:51:15 +01:00
Themaister 43905e410e Fix build ... *grummel* 2011-11-02 17:04:49 +01:00
Themaister d23a7e3ddf HAVE_OPENGL=1 in Windows. 2011-11-02 17:02:59 +01:00
Themaister 652f4c5856 More explicit checking for inconsistency. 2011-11-02 16:54:45 +01:00
Themaister 90febc4ecf Use dynamic by default.
FFmpeg and Python does not require explicit --enable.
2011-11-02 16:50:34 +01:00
Themaister 34b5994842 Fix minor issue. 2011-11-01 21:28:32 +01:00
Themaister 0c3f6ed66b Cleanup and optimize rewind a bit. Forced POT buffer size. 2011-11-01 21:00:41 +01:00
Themaister f3e487557e Fix some style nits. 2011-11-01 20:27:59 +01:00
Themaister ee12266a2b Fix build for OSX. 2011-11-01 18:45:50 +01:00
Themaister 1981b14de9 Allow OpenGL to be disabled. 2011-11-01 18:24:43 +01:00
Themaister 65665f36cc Fixup netplay. 2011-10-31 22:51:54 +01:00
Themaister a48dc55c41 Fix ugly possible segfault. 2011-10-30 16:58:45 +01:00
Themaister 202a458524 Updates for 0.9.1. 2011-10-30 11:24:16 +01:00
Themaister b4de704a09 Style nit. 2011-10-30 02:12:00 +02:00
Themaister fef5edfac8 Change default aspect handling. 2011-10-30 01:58:08 +02:00
Themaister a6e74775b1 Edge trigger reset. 2011-10-29 13:35:01 +02:00
Themaister ee66a28d05 Style nit. 2011-10-29 13:33:15 +02:00
Themaister 5e28d82af2 Fix compile with HAVE_CONFIGFILE=0. 2011-10-28 17:10:58 +02:00
Themaister c2a06bfa09 Replace some magic numbers. 2011-10-28 09:06:34 +02:00
Themaister 66510e21aa Fixup build for non dynamic builds. 2011-10-28 00:34:42 +02:00
Themaister ec5e3355b9 Add some logging. 2011-10-28 00:23:49 +02:00
Themaister 0522a2d6a0 Start implementing some minor extensions to libsnes. 2011-10-27 23:40:34 +02:00
Themaister fad89f9d2d More gracious error handling for state tracker. 2011-10-26 19:51:10 +02:00
Themaister 97f937ec6d Use floating point values for uniforms from Python. 2011-10-26 10:26:09 +02:00
Themaister 9647006a2b Merge branch 'master' of github.com:Themaister/SSNES 2011-10-25 23:03:20 +02:00
Themaister 418ba455f8 Allow the rest of the buttons in Python.
Fix issue where long type was enforced for return values of uniforms.
2011-10-25 23:02:17 +02:00
Themaister 197d62860b Default screenshot directory. 2011-10-24 21:34:30 +02:00
Themaister 402451626f More accurate colors for screenshot. 2011-10-24 19:23:58 +02:00
Themaister 3739cbfc70 Minor cleanup for rewind. 2011-10-23 17:13:16 +02:00
Themaister 235355ffc7 Check more explicitly for XVideo and Xext. 2011-10-23 12:48:44 +02:00
Themaister 4856d0cac3 Allow screenshots while paused. 2011-10-23 12:38:11 +02:00
Themaister 77a2723bb0 Neat optimizations for SSE. 2011-10-23 02:56:33 +02:00
Themaister 41cd6e21c3 Use _mm* intrinsics. 2011-10-22 23:36:02 +02:00
Themaister 1fc99c7123 Fix deprecation warning. 2011-10-22 22:54:36 +02:00
Themaister fddcc3447c Fix build for Clang. 2011-10-22 22:19:54 +02:00
Themaister 70e9f084b7 Merge branch 'master' of github.com:Themaister/SSNES 2011-10-22 20:20:03 +02:00
Themaister 824790a80d Updates for 0.9. 2011-10-22 20:19:40 +02:00
Themaister 23d23983bc Fix broken #define in header. 2011-10-21 22:12:03 +02:00
Themaister c42655ed91 Logging for paused. 2011-10-20 23:33:15 +02:00
Themaister f46ee78c76 Apply a hack and push the frame several times when changing fullscreen. 2011-10-20 23:28:46 +02:00
Themaister 5d1d188231 Hardcode hermite for 2 channels. 2011-10-20 22:26:41 +02:00
Themaister c55ce543c2 Revert "Use C99 stdio in mingw, yay" :\
This reverts commit de8bc62474.
2011-10-19 18:12:30 +02:00
Themaister de8bc62474 Use C99 stdio in mingw, yay 2011-10-19 18:10:05 +02:00
Themaister 397da887a7 Merge branch 'master' of github.com:Themaister/SSNES 2011-10-19 08:16:26 +02:00
Themaister f44733d7f6 Only show paused rewind for 1 frame. 2011-10-26 03:24:39 +02:00
Themaister 5faa28a1a2 Clarify x/yscale. 2011-10-19 08:16:01 +02:00
Themaister efaa85ff9b Cleaner. 2011-10-18 21:59:37 +02:00
Themaister 8f5580be10 Frame advance goes into pause. 2011-10-18 21:57:28 +02:00
Themaister c7acd99548 Same for SDL ... 2011-10-18 19:52:43 +02:00
Themaister 64ee13e6f4 Push window loop in .alive(). 2011-10-18 19:51:38 +02:00
Themaister e134f8afc7 And yet another ... :) 2011-10-18 19:22:20 +02:00
Themaister dd89e6fbe0 Fix build without FFmpeg. 2011-10-18 19:16:38 +02:00
Themaister a79a1b46f7 Updates for 0.9-rc4. 2011-10-18 19:12:28 +02:00
Themaister 6467f51ea8 Frame caching for more "proper" fullscreen switch. 2011-10-18 17:26:15 +02:00
Themaister 141eefb03b Fix fullscreen pause toggle for windows. 2011-10-18 14:39:54 +02:00
Themaister 068c224d83 Include windows.h properly. 2011-10-18 14:05:30 +02:00
Themaister 5bc8090ea7 Allow fullscreen toggle while paused. 2011-10-18 13:29:39 +02:00
Themaister 466ab1ef8d Frame advance. 2011-10-17 21:30:58 +02:00
Themaister a1c19ed1f5 Minor refactor. 2011-10-17 20:46:38 +02:00
Themaister cce4b7d20c Allow #include depth. 2011-10-17 20:09:57 +02:00
Themaister 80925ffc11 Some Windows fixes. 2011-10-17 19:30:52 +02:00
Themaister 9eb14e328d Add "#include" for config files. 2011-10-17 19:11:31 +02:00
Themaister 5ae0cb1821 Base size for windowed mode calculations. 2011-10-16 21:36:17 +02:00
Themaister fc594f7f0f Fix edge case on input poll. 2011-10-16 15:45:04 +02:00
Themaister 0c4e406ee7 Remove unused variable. 2011-10-16 12:51:14 +02:00
Themaister a082ec5251 Fix segfault. 2011-10-16 04:01:01 +02:00
Themaister 953b5daf0a Pause hooked up. 2011-10-16 02:00:55 +02:00
Themaister b4ff622f32 Title buf hints. Purge samplerate opts. 2011-10-15 20:05:34 +02:00
Themaister f26b54c998 Updates for RC3. 2011-10-15 18:51:58 +02:00
Themaister d7b3f39136 SSE2 optimized a bit :D 2011-10-15 18:09:44 +02:00
Themaister 5bcf601a40 Refactor out audio conversion. 2011-10-15 17:47:29 +02:00
Themaister e91ebdac97 Do not recalculate ratio all the time. 2011-10-15 16:16:13 +02:00
Themaister b2dd12d186 Rewind audio! :D 2011-10-15 14:33:41 +02:00
Themaister 9c79bf0ba2 Refactor audio flushing method. 2011-10-15 13:16:32 +02:00
Themaister f48247a18b Style nits ... 2011-10-15 12:56:48 +02:00
Themaister 48e015558e Style nits. 2011-10-15 12:54:47 +02:00
Themaister 0ff3cbc93b Nits. 2011-10-15 12:51:17 +02:00
Themaister 25f0e162a4 Purge support for libsamplerate. Obsolete. 2011-10-15 12:48:15 +02:00
Themaister 0810812cd9 Slight cleanups when pushing audio. 2011-10-15 12:42:39 +02:00
Themaister 15e0b721e6 Updates for RC2. 2011-10-14 14:07:03 +02:00
Themaister 9d12c3ac87 Use Makefile.win for Phoenix. 2011-10-14 13:34:27 +02:00
Themaister a7c3d8d17a Some slight recording tweaks. 2011-10-14 11:27:02 +02:00
Themaister 8fbfdee011 Do not always force 4.0 / 3 aspect ratio for output. 2011-10-14 11:00:31 +02:00
Themaister bc999e72fa Updates for v0.9-rc1. Use --features rather than spamming down --help. 2011-10-11 20:02:46 +02:00
Themaister c7f8110670 Use glorious x264 RGB. 2011-10-10 22:24:26 +02:00
Themaister b0dbc67281 Fix build when only Cg is being compiled. 2011-10-17 15:35:02 +02:00
Themaister 4916f7b08b Add placeholder define for when libx264 RGB support is built in. 2011-10-09 12:37:53 +02:00
Themaister 1058d94ec1 x264 RGB recording. 2011-10-09 12:27:02 +02:00
Themaister 340dca3c6d Download headers (lib/headers split). 2011-10-08 17:01:40 +02:00
Themaister 4ae0f3da22 Remove obsolete readme. 2011-10-08 01:27:21 +02:00
Themaister 7d2d1ce49e Change "hashing" value used for netplay. 2011-10-07 22:33:38 +02:00
Themaister fa26f6a10c Cache font rendering. Major overhead reduction. 2011-10-07 17:58:22 +02:00
Themaister db71a5cdba New font rendering code for OpenGL. 2011-10-07 17:43:39 +02:00
Themaister 5058fdcd1a Update docs. 2011-10-07 01:36:52 +02:00
Themaister ef04f199d5 Slight cleanups. 2011-10-07 01:21:54 +02:00
Themaister d26dd9d9e7 Slight cleanups. 2011-10-07 00:54:47 +02:00
Themaister d2bc4096de Some fixes to FFmpeg. Conserves RAM better. 2011-10-07 00:04:52 +02:00
Themaister 08ca1a54d3 Remove useless asserts. 2011-10-06 23:44:21 +02:00
Themaister 869eddfc1a Custom FFmpeg recording sizes. 2011-10-06 23:43:48 +02:00
Themaister fbced43f11 Update threading for Win32. 2011-10-06 22:40:47 +02:00
Themaister c996f816b8 Default font path OSX. 2011-10-06 21:12:11 +02:00
Themaister 33ecedb462 Fixup build for OSX. 2011-10-06 20:49:00 +02:00
Themaister a58676c9e1 Linux needs -lrt for clock_gettime. 2011-10-06 20:34:01 +02:00
Themaister 1ee9722e5f Start working on custom thread implementation.
Avoids SDL dependency for this to improve portability.
2011-10-06 20:31:39 +02:00
Themaister 81250657f0 Change default font color to yellow. 2011-10-06 19:10:01 +02:00
Themaister 7d33cccc8e Default fonts. 2011-10-06 19:06:38 +02:00
Themaister 3db79ab2f0 Nits. 2011-10-05 22:56:52 +02:00
Themaister ea0f6813d2 Avoid assertions. 2011-10-05 22:39:54 +02:00
Themaister f6d4d32c03 Dynamic loading by default, add OSD message for netplay DC. 2011-10-05 21:44:17 +02:00
Themaister 892e82141f Fix FTBFS. 2011-10-05 19:57:32 +02:00
Themaister 65ec7fae9c Is this it? 2011-10-05 02:09:54 +02:00
Themaister a0acb75a19 Might push lagframes better. 2011-10-05 01:05:34 +02:00
Themaister bcae973d82 Savestate auto indexing support. 2011-09-27 15:31:25 +02:00
Themaister d01a4fe61b Only load second pass shaders when render-to-texture is set. 2011-09-26 22:45:28 +02:00
Themaister 8d4620b680 FFmpeg API seems to be too fragmented. Give in and #ifdef shit. :v 2011-09-23 22:57:41 +02:00
Themaister c2cedb1b6f Resizing windows in 1.2 should not trigger some init code :) 2011-09-22 21:50:57 +02:00
Themaister 157dcad87b Fix newline typo. 2011-09-22 13:15:16 +03:00
Themaister 8ea5ba171a Updates for 0.8.2. 2011-09-21 21:17:46 +02:00
Themaister fa876b10a3 Style nit. 2011-09-20 12:22:30 +02:00
Themaister 3c58d10eae Small fix. 2011-09-20 12:05:21 +02:00
Themaister a3ee8c8849 Defensive nit. 2011-09-20 11:58:21 +02:00
Themaister 5e14b302bc Replace a VLA with char[MAXPATHLEN]. 2011-09-20 12:50:13 +03:00
Themaister efe3f943d5 Only autosave when the data actually changed. 2011-09-17 10:57:55 +02:00
Themaister 38e7fc6659 Add support for blocking SRAM writes :) 2011-09-16 15:32:21 +02:00
Themaister a1ceb534de nit. 2011-09-13 23:24:06 +02:00
Themaister 0d897dd65d Check some additional WM messages. 2011-09-13 22:38:32 +02:00
Themaister 721d73f451 Fix stupid crash. 2011-09-13 22:16:34 +02:00
Themaister e8bd64e898 Allow SDL driver to work as well in 1.3. 2011-09-13 20:01:22 +02:00
Themaister 7da7ab2ce7 lalala ... 2011-09-13 19:36:15 +02:00
Themaister 3f6183ff15 Updates, fixes ... 2011-09-13 19:30:22 +02:00
Themaister 642316a1e2 Somewhat haphazard. Can't find some needed API calls :\ 2011-09-13 18:50:40 +02:00
Themaister 21c6b75839 Use SwapInterval with SDL 1.3. 2011-09-13 15:00:26 +02:00
Themaister 87d34deb0c Can build with SDL 1.3 on Win32. 2011-09-13 14:57:42 +02:00
Themaister 1b3408919c Can use SDL 1.3 just fine now. 2011-09-13 14:41:45 +02:00
Themaister 23516572b7 Use SK_* keysyms (pretty much SDL 1.2). 2011-09-13 14:40:33 +02:00
Themaister 924848fdad Start working towards SDL 1.2/1.3 compat. 2011-09-13 14:06:49 +02:00
Themaister 4c40e56060 Properly disable it :D 2011-09-11 15:41:46 +02:00
Themaister cf34444505 Disable resizing on OSX. 2011-09-11 15:33:28 +02:00
Themaister 9ca5e4e470 Updates for 0.8.1. 2011-09-10 19:15:05 +02:00
Themaister 32f2689b6a Add LIBXML_TEST_VERSION to XML cheats. 2011-09-09 09:48:46 +02:00
Themaister 13ae61031f Add ttf_font_color to ext driver struct.
Does not need to bump ABI version.
2011-09-09 09:47:32 +02:00
Themaister 1ced96c5e9 Make it non-public. 2011-09-07 18:59:51 +02:00
Themaister 0d905eb3f6 Actually load cheats on startup ... :') 2011-09-07 18:59:01 +02:00
Themaister 32a5460ea7 Small cleanup. 2011-09-06 19:53:22 +02:00
Themaister be5acff69c Update font rendering for SDL. 2011-09-06 18:32:40 +02:00
Themaister 1b0ef5793e Font colors for XVideo. Some cleanups. 2011-09-06 17:56:42 +02:00
Themaister 2bd0caae2e Do not set RESIZABLE on fullscreen (really? :v) 2011-09-06 15:38:32 +02:00
Themaister 3045f2c478 Move cheat initializing as late as possible. 2011-09-06 12:55:21 +03:00
Themaister 1282a142d6 Fix load/save semantics for cheats ... 2011-09-06 12:51:52 +03:00
Themaister ac1a539d22 Fix stupid typo. 2011-09-05 21:21:18 +02:00
Themaister 6f47775239 Add cheat config. 2011-09-05 17:57:30 +02:00
Themaister 0823d72dee Add coloring to fonts. 2011-09-05 17:00:28 +02:00
Themaister 407ad94f58 Style nit. 2011-09-04 21:11:26 +02:00
Themaister b2b103362d Warn if glX VSync call isn't found. 2011-09-04 13:01:54 +02:00
Themaister 231680944f Remove #ifdef for FFmpeg. 2011-09-04 11:37:59 +02:00
Themaister ec7dab05e8 Small bloop fix :D 2011-09-02 20:50:51 +03:00
Themaister 9588f6061f Merge branch 'master' of github.com:Themaister/SSNES 2011-09-02 16:12:53 +02:00
Themaister 57c25dcb0b Should detect MacPorts. 2011-09-02 16:12:34 +02:00
Themaister 38763c4554 Merge branch 'master' of github.com:Themaister/SSNES 2011-09-01 10:07:24 +02:00
Themaister fac2ea00dd Update docs. 2011-09-01 10:07:07 +02:00
Themaister 74782a1bea Clarify. 2011-09-01 10:06:18 +02:00
Themaister c1265e7227 Update build script a bit. 2011-08-29 18:47:52 +02:00
Themaister f0841256e8 Fixup. 2011-08-29 17:23:49 +02:00
Themaister 600efab1bd Consistently use BGRA for possible performance gains. 2011-08-29 17:19:38 +02:00
Themaister dc9dd2e6bf Fix bug where shaders could crash using LUT textures. 2011-08-29 17:05:11 +02:00
Themaister de8fe0e88c Reword a bit. 2011-08-29 16:20:55 +02:00
Themaister 338432c35f Add build automated build script for MinGW. 2011-08-29 16:15:55 +02:00
Themaister 11aeb05a6e Do not drop netplay in SLIM build. 2011-08-28 22:43:50 +02:00
Themaister e28a32d922 Add in SDL.dll. 2011-08-28 22:31:11 +02:00
Themaister edac39cb2b Link explicitly to iconv. 2011-08-28 22:20:15 +02:00
Themaister c1954aa4a6 Fixups in Makefile. 2011-08-28 22:19:02 +02:00
Themaister ef048fcfd5 Remove cruft. 2011-08-28 21:57:24 +02:00
Themaister 48a1531d7c Start generalize the windows makefiles a bit. 2011-08-28 21:56:56 +02:00
Themaister 4b4686ae04 Merge ../SSNES-w64 2011-08-28 21:48:06 +02:00
Themaister cb4a54fefe Add SLIM targets. 2011-08-28 21:47:58 +02:00
Themaister 131b2386cd Merge ../SSNES-w64 2011-08-28 21:35:20 +02:00
Themaister 4d6d01228c Use static zlib. 2011-08-28 21:34:53 +02:00
Themaister a050955113 Merge ../SSNES-w64 2011-08-28 15:06:37 +02:00
Themaister b02789d280 Update build some more ... 2011-08-28 15:06:22 +02:00
Themaister 6f92d0588d Merge branch 'master' of github.com:Themaister/SSNES 2011-08-28 12:13:02 +02:00
Themaister 45df48ab67 Add to dist. 2011-08-28 12:12:15 +02:00
Themaister aba5c7722e Build with python and sdl_image as well. 2011-08-28 12:11:30 +02:00
Themaister 07a1a1ee2f Add python to build. 2011-08-28 11:16:38 +02:00
Themaister 3b952973de Start updating to 0.8. 2011-08-27 17:56:24 +02:00
Themaister ac4adebdf6 Small optimization. 2011-08-26 18:28:05 +02:00
Themaister 1bfd9716c5 Small refactor. 2011-08-26 17:32:04 +02:00
Themaister 702cf9c804 Optimize some more... 2011-08-25 16:29:17 +02:00
Themaister 5993fffb64 Add config_get_array() for simpler and faster config access. 2011-08-25 16:15:34 +02:00
Themaister 58758d2818 Check Cg with CXX. 2011-08-25 09:49:32 +02:00
Themaister 21f88fcf39 Obey library_dirs in makefile. 2011-08-24 16:24:58 +02:00
Themaister e3f029a446 Add /usr/lib64 to LIBRARY_DIRS. 2011-08-24 16:12:38 +02:00
Themaister 0694d8884f Allow configurable save files/states. 2011-08-24 15:47:39 +02:00
Themaister 0730a34a5b Reverting config path to system default if it doesn't find it. 2011-08-24 08:14:03 +02:00
Themaister f827bb4cbd Allow directory path for config files. 2011-08-24 07:54:52 +02:00
Themaister eafd8d91d7 Avoid spamming down stderr with autosave messages. 2011-08-23 21:04:00 +02:00
Themaister 56a4d1ddac Attempt to check for mysterious crashes :D 2011-08-23 17:10:02 +02:00
Themaister 8d3f15602c More robust recovery. 2011-08-22 18:45:38 +02:00
Themaister 7877c7939d Add backquote as alias to tilde ... 2011-08-22 18:26:39 +02:00
Themaister c55263b956 Clean up some file handling stuff ... 2011-08-22 18:13:30 +02:00
Themaister 96ce288120 Update docs to reflect new changes. 2011-08-22 17:44:37 +02:00
Themaister e5326467a1 Attempt to recover SRAM writes! 2011-08-22 17:39:29 +02:00
Themaister 596d8d9985 Attempt to recover SRAM write failures gracefully ... 2011-08-22 17:35:31 +02:00
Themaister b4b0be9118 Allow directories for -s/-S. Paths will be inferred. 2011-08-22 17:05:27 +02:00
Themaister 00e5f0fe97 Cleanup in cheat module. Do not use assert().
More rigid error checking for memory.
2011-08-21 20:48:27 +02:00
Themaister cb140c3691 Update XAudio driver to use floating point. Nits here and there. 2011-08-21 19:27:11 +02:00
Themaister ad85ccb42f Minor nit. 2011-08-20 03:28:24 +02:00
Themaister 97e50f15de Small cleanups. 2011-08-20 03:25:44 +02:00
Themaister 071c03e194 Do not link XAudio2 dynamically. Build with MinGW. 2011-08-20 03:22:19 +02:00
Themaister 6f47c21ce9 Fix capitalization. 2011-08-20 02:05:26 +02:00
Themaister 68bfda24ff Update dist. 2011-08-20 01:27:43 +02:00
Themaister 4f2fbcb9bc Update dist. 2011-08-20 00:30:43 +02:00
Themaister 90ab5dfc2f Add Cg as well. 2011-08-19 23:46:52 +02:00
Themaister 362cbe5deb Add RSound. 2011-08-19 19:22:52 +02:00
Themaister e133662346 FFmpeg as well. Small fixup. 2011-08-19 19:16:53 +02:00
Themaister 1fe83ab25a Use more proper .dll.a. 2011-08-19 18:50:05 +02:00
Themaister 1d95b5ee22 Update Makefile for 64-bit. 2011-08-19 18:39:05 +02:00
Themaister 9dc603d405 Update Makefile for freetype. 2011-08-19 14:35:09 +02:00
Themaister 5cb2863e6e Fix up Win64 warnings/errors. 2011-08-19 13:33:10 +02:00
Themaister 98cf4223ab Do not try to remove dead hqflt :D 2011-08-19 12:58:47 +02:00
Themaister ff7843cbe9 Update API usage of FFmpeg. Use 2 threads for encoding :) 2011-08-19 02:06:13 +02:00
Themaister c4d6b0b7c1 Update makefiles for BPS. 2011-08-18 00:45:10 +02:00
Themaister fb739621ac BPS seems to work ... :) 2011-08-18 00:37:43 +02:00
Themaister 24e8ca6856 Some more needed stuff ... 2011-08-18 00:24:57 +02:00
Themaister 1ff9b6a375 Start adding support for BPS patches. 2011-08-18 00:05:56 +02:00
Themaister cb6086635c Nit. 2011-08-16 12:11:44 +02:00
Themaister bce679df78 Only use hack on X when in windowed mode. 2011-08-16 10:26:36 +02:00
Themaister 22e8c3d895 Should fix breakage of OGL on OSX. 2011-08-15 22:21:50 +02:00
Themaister d2b06a92c5 0.7 baby! 2011-08-14 23:17:02 +02:00
Themaister 3901934d97 Add an ugly hack to try and remedy things ... 2011-08-14 23:03:48 +02:00
Themaister a76b25aff9 Fix ugly Jack crash with race condition. 2011-08-14 16:29:31 +02:00
Themaister 343852af26 Allocate before activation. 2011-08-14 16:24:42 +02:00
Themaister 4395f124ca Slight fixups. 2011-08-14 04:50:16 +02:00
Themaister b16ff3024c Add new DSP plugin API, events. 2011-08-13 04:09:08 +02:00
Themaister bc23b421e1 New resize checking code. 2011-08-12 19:02:12 +02:00
Themaister d9cb85a8d5 Add new possible workaround for tiling WMs ... 2011-08-11 15:19:30 +02:00
Themaister 7d1cc23d16 Fix build. 2011-08-11 06:02:05 +02:00
Themaister 4496ed3c13 Should make sizes right after startup ... 2011-08-11 05:59:32 +02:00
Themaister 3f5b6a450e Should fix behavior for tiled WMs. 2011-08-11 05:32:03 +02:00
Themaister 9e24474047 Can record hi-res and filtered output. 2011-08-11 05:25:31 +02:00
Themaister 7c17ede1ef Updates for 0.7beta1. 2011-08-09 23:04:13 +02:00
Themaister 5d9805c3e5 Small fix. 2011-08-09 22:07:11 +02:00
Themaister b17617bed5 Updated copyrights. 2011-08-09 12:58:13 +02:00
Themaister a405708f1c Huzzah, ordering matters. 2011-08-09 00:11:09 +02:00
Themaister 594e66704d Allow disabling composition in SDL as well. 2011-08-08 23:38:11 +02:00
Themaister 50579aaeea Floating point. 2011-08-08 17:45:49 +02:00
Themaister 38eb855b48 Works! :D 2011-08-08 17:41:55 +02:00
Themaister 12cc85c8a5 CoreAudio builds. 2011-08-08 17:31:03 +02:00
Themaister 5b12595c85 Merge branch 'master' of git://github.com/Themaister/SSNES 2011-08-08 17:29:06 +02:00
Themaister 3753f0bfca Merge branch 'master' of github.com:Themaister/SSNES 2011-08-08 17:28:32 +02:00
Themaister 14ae5e397a Add CoreAudio driver. Untested. 2011-08-08 17:27:52 +02:00
Themaister 657b4ce8c7 Merge branch 'master' of git://github.com/Themaister/SSNES 2011-08-08 14:47:47 +02:00
Themaister 777e6a5334 Better shader path semantics. 2011-08-07 23:35:54 +02:00
Themaister a2ec78320b Improve behavior a bit. 2011-08-07 22:31:59 +02:00
Themaister 1fb53627ac Make sure to free lib. 2011-08-07 21:18:51 +02:00
Themaister fc2a39cd58 More appropriate renaming. 2011-08-07 21:15:50 +02:00
Themaister 7425e1f879 Allow disabling composition in Win Vista/7Allow disabling composition in Win Vista/7. 2011-08-07 15:00:34 +02:00
Themaister 6a260a57dd Reset frame counter properly. 2011-08-06 03:28:07 +02:00
Themaister dadd794ece Remove useless define. 2011-08-05 19:18:43 +02:00
Themaister 706a3738b5 Abandon POT buffer sizes only for dsound.
Allows more fine tuned latencies.
2011-08-05 19:17:33 +02:00
Themaister 9aef33aabd More fixups in DSound. 2011-08-05 14:01:58 +02:00
Themaister ac4219bcde Small clarification. 2011-08-05 13:39:27 +02:00
Themaister b337856f80 More extensive error checking in dsound. 2011-08-05 13:35:02 +02:00
Themaister 079a0100c0 Remove unneeded call. 2011-08-05 03:06:48 +02:00
Themaister 014c3c90e0 Fix possible race condition. 2011-08-05 02:57:30 +02:00
Themaister 4759e3411f Fix DSound up some more in Windows ... :D 2011-08-05 02:05:32 +02:00
Themaister 4a05e50636 Minor progress. But no audio, hrm. 2011-08-04 19:11:14 +02:00
Themaister 72c070f338 Alter default ordering of audio drivers. 2011-08-04 18:52:00 +02:00
Themaister 776291a137 Start working on DirectSound driver. Untested so far. 2011-08-04 18:45:40 +02:00
Themaister f3cdb95b04 Fix endian issues in OSS driver. 2011-07-26 00:53:24 +02:00
Themaister 033860ceb9 Add -f/--fullscreen command line option. 2011-07-09 08:37:08 +02:00
Themaister ab601ee3dc v0.6.2 2011-07-06 16:54:54 +02:00
Themaister 783ab7acd5 Improve error handling. 2011-07-04 13:33:09 +02:00
Themaister 19a46b1f8b Seems to work in Cg as well. 2011-07-03 15:53:56 +02:00
Themaister 508cfdbda7 Start implementing access to previous texture. 2011-07-03 15:39:35 +02:00
Themaister d81b9ee0a7 Print full compile error in Cg. 2011-07-03 13:41:24 +02:00
Themaister 36c6c21194 Use RSOUND_CFLAGS, etc. 2011-06-29 04:54:30 +02:00
Themaister 1631e940f6 Fix up VSync calls for OSX. 2011-06-29 03:45:52 +02:00
Themaister 2eeb1fa6d1 Fix up VSync calls for OSX. 2011-06-29 03:45:17 +02:00
Themaister 26ac00ad76 Fix incompatible type. 2011-06-29 03:26:21 +02:00
Themaister bafc4f596f Add nonused VSync code for OSX. 2011-06-28 03:20:36 +02:00
Themaister eee89dddb1 Check for SDL 1.3 API and report it as an error. 2011-06-28 02:31:41 +02:00
Themaister 089b4fbba0 Updates for 0.6.1. 2011-06-27 02:28:35 +02:00
Themaister 80727cef5a Nitpick. 2011-06-26 18:47:54 +02:00
Themaister 346a9f2b4e Remove debug messages. 2011-06-26 17:06:05 +02:00
Themaister 363d8ca5b4 More proper string reading function. 2011-06-26 17:05:29 +02:00
Themaister 06a574225d Merge branch 'master' of github.com:Themaister/SSNES 2011-06-26 16:04:13 +02:00
Themaister fa777b8356 Should fix netplay for bSNES as well.
Do not rely on when polling takes place in the emu core.
We earlier assumed that this occured always at the start of the main
loop. We now do not care about when the poll callback is called, and we
manually poll the network ourselves in pre_frame.
2011-06-26 16:02:18 +02:00
Themaister 7cf01318cb Should fix netplay for bSNES as well. 2011-06-26 15:32:24 +02:00
Themaister 7c538274b4 Do not check twice for OS. 2011-06-25 17:22:47 +02:00
Themaister 72fb694e97 Use pkg-config more where appropriate. 2011-06-25 17:15:58 +02:00
Themaister 59c92dddc3 Slight QB cleanup. 2011-06-25 17:11:18 +02:00
Themaister 3f60fdd106 Fix build for XVideo. 2011-06-25 18:11:04 +02:00
Themaister d221c480e6 Fix aliasing issue. 2011-06-25 16:49:34 +02:00
Themaister 59d9ff0d29 Add check_code_c/cxx. 2011-06-25 14:44:45 +02:00
Themaister d279ea79e8 Fix some standard compliance. 2011-06-25 14:17:31 +02:00
Themaister 77cf9423cc Abolish use of echo -n as it isn't perfectly standard. 2011-06-25 14:10:40 +02:00
Themaister 60b94bbe43 Add some additional checks in qb. 2011-06-25 13:57:46 +02:00
Themaister b6272f9653 Small bug. 2011-06-24 13:31:21 +02:00
Themaister 25fce1a6c6 Allow XML mapping. 2011-06-24 13:29:30 +02:00
Themaister 59229f99c5 Swap client by default. 2011-06-22 21:56:04 +02:00
Themaister db3e1ae053 Updates for 0.6. 2011-06-21 22:37:48 +02:00
Themaister ec1401e657 Fix build error on Win32. 2011-06-21 02:33:59 +02:00
Themaister f85fd50fa1 Add --nodevice. 2011-06-19 11:11:04 +02:00
Themaister c39b0ab09b Merge branch 'master' of github.com:Themaister/SSNES
Conflicts:
	Makefile
	qb/config.libs.sh
2011-06-16 23:54:40 +02:00
Themaister 4b5ed0fa41 Do not force -lossaudio. 2011-06-16 23:50:33 +02:00
Themaister 75d1155a23 Fix OSS build for BSD. 2011-06-16 23:20:12 +02:00
Themaister 753d2057bb Fix BSD build. Convert strcpy()/strcat() to strl* variants. 2011-06-16 22:47:37 +02:00
Themaister b06d814d9c Fix OSS build for BSD. 2011-06-16 21:20:59 +02:00
Themaister eb085a8068 Fix BSD build. Convert strcpy()/strcat() to strl* variants. 2011-06-16 20:59:48 +02:00
Themaister 45904ccd73 Fix issue when input_slot is 2. 2011-06-16 15:00:04 +02:00
Themaister 3b0606bbd6 Ifdef for AVIO. 2011-06-15 12:20:51 +02:00
Themaister 0f1a76f932 POSIX stuff for Quickbuild. 2011-06-15 04:34:28 +02:00
Themaister d3e0140f01 Holy crap, now that was painful. 2011-06-15 04:16:53 +02:00
Themaister ea7dded915 Fix up alignment issues. 2011-06-15 03:04:20 +02:00
Themaister f187f3db29 Small regex change. 2011-06-15 00:42:09 +02:00
Themaister 3099a79bac Should fix grep error. 2011-06-15 00:26:44 +02:00
Themaister 7cdea39c95 Can build with FFmpeg if desired :) 2011-06-14 23:59:00 +02:00
Themaister 95f6a5116a Just to be sure ... ;) 2011-06-14 22:59:47 +02:00
Themaister da94877155 Less magic numbers ... ;) 2011-06-14 22:44:54 +02:00
Themaister b1feed9d2b Allocate from heap. 2011-06-14 22:20:09 +02:00
Themaister a3816bffa1 Force rewind granularity to 1 when we're using movies. 2011-06-14 22:09:16 +02:00
Themaister 612270ec9b Aww yeah :3 2011-06-14 21:52:31 +02:00
Themaister 54bc0a8d96 Heyhey :D 2011-06-14 21:35:31 +02:00
Themaister f761811189 Move buffer to top-level as it's not audio only. 2011-06-14 19:58:12 +02:00
Themaister 0e964c5cc2 More generic naming for FIFO buffer. 2011-06-14 19:55:08 +02:00
Themaister c34a944fcf Fix deprecation, yay. :) 2011-06-14 18:52:02 +02:00
Themaister 3feade6b6e Update FFemu a bit. Convert to lossless HuffYUV/FLAC. 2011-06-14 18:45:30 +02:00
Themaister f79eafe449 Should perhaps continue if one joypad failed. 2011-06-12 10:42:42 +02:00
Themaister 111b159373 Should fix dinput. 2011-06-12 10:37:04 +02:00
Themaister d744167865 Small cleanup. 2011-06-11 22:46:51 +02:00
Themaister a2fea86c92 Fixes 2-5 player. (Damn o.O) 2011-06-11 22:25:55 +02:00
Themaister 5385806e74 Hrm ... 2011-06-11 22:02:05 +02:00
Themaister 99e85684db Input capturing semantic. 2011-06-11 20:02:17 +02:00
Themaister 45727bf9f5 Fix mask value. (32-bit). 2011-06-11 19:01:34 +02:00
Themaister 2a0abb0618 Unsigned mask. 2011-06-11 18:57:16 +02:00
Themaister 192e3303a1 Update dist and version. 2011-06-11 18:19:00 +02:00
Themaister b6051add6a SDL_image for Win32 2011-06-11 18:13:12 +02:00
Themaister 24d0cda5fd SDL_image seems to work :) 2011-06-11 18:05:52 +02:00
Themaister d0ba59f8b5 Start moving over to SDL_image rather than imlib2.
Imlib2 takes more space, and was a pure bitch to compile for Win32,
so I gave up ... ;)
2011-06-11 16:55:53 +02:00
Themaister 99a1784aaf Move window logic away from SDL input.
We weren't using the event loop anyways ...
2011-06-11 12:54:14 +02:00
Themaister b6ff98cf18 Should fix DInput crash. 2011-06-10 18:01:44 +02:00
Themaister 2dcccc7cda Fix some includes and stuff. 2011-06-10 17:55:40 +02:00
Themaister d03855c655 Add some sanity logging. 2011-06-10 17:47:16 +02:00
Themaister 69227bc1ca Alter design. Use DInput as piggyback only. 2011-06-10 17:34:04 +02:00
Themaister 851debf1e4 Start working on DInput. 2011-06-10 16:55:05 +02:00
Themaister 8c1db1c407 Fix shenanigans. 2011-06-09 23:17:10 +02:00
Themaister 576894e0e8 Build Python in Windows. 2011-06-09 13:56:29 +02:00
Themaister 631c3ca393 Fix link for Clang. 2011-06-08 19:52:03 +02:00
Themaister fd70a1c875 Make sure we only call semantics once per frame. 2011-06-08 17:59:29 +02:00
Themaister 30cb2e4c07 Slight cleanup. 2011-06-08 17:55:32 +02:00
Themaister 7d87cc2d24 Add input hook API to python. 2011-06-08 17:53:15 +02:00
Themaister 0342dcb169 Fix transition_prev. 2011-06-07 21:07:00 +02:00
Themaister f339560550 Put all scripts in <script> 2011-06-07 16:28:58 +02:00
Themaister 11b58d8c69 Clean up error handling a bit. 2011-06-07 15:58:30 +02:00
Themaister 3717f7442c Inline XML python. 2011-06-07 15:33:29 +02:00
Themaister e02d9f41e8 Transition count semantic. 2011-06-06 21:32:10 +02:00
Themaister f62120861a Show if python is compiled in or not. 2011-06-06 20:21:26 +02:00
Themaister 884e2881a0 Add script support to Cg. 2011-06-06 20:18:31 +02:00
Themaister a605628dff :v 2011-06-06 18:50:59 +02:00
Themaister 4d96fbba6a Python works :P 2011-06-06 18:50:36 +02:00
Themaister 9bfeb88e24 Start implementing Python support for game-aware shaders. 2011-06-06 17:44:05 +02:00
Themaister 712f463022 Disable audio sync properly in external driver. 2011-06-06 02:01:21 +02:00
Themaister 713e8624a0 Fixed typo. 2011-06-05 22:23:50 +02:00
Themaister 5c8a549125 Cleanups. 2011-06-05 02:21:35 +02:00
Themaister c3e7a35b62 Fixes case where backdrops are used in second or later pass. 2011-06-05 02:01:44 +02:00
Themaister 5bc9ca216e Clean up shader compilation slightly. 2011-06-02 13:49:22 +02:00
Themaister 838a85a719 Could make coordinate flipping consistent ... Finally. 2011-06-01 12:19:48 +02:00
Themaister b880039541 Clarify more ... 2011-05-31 23:08:02 +02:00
Themaister c646166fe1 Make an "empty" buffer for performance. Also attempt to fall back if
vsync fails on start.
2011-05-31 23:03:01 +02:00
Themaister 44c52ca4f8 Add -pedantic for shits 'n giggles.
Fix portability issues with void* -> void (*)(void) casts.
Use a more ... bizarre technique ;)
2011-05-31 15:03:59 +02:00
Themaister 9c9eee5d01 Should fix zip loading of [!] files... 2011-05-31 14:29:32 +02:00
Themaister 7bbaa6ee31 Add pixel size uniform. 2011-05-30 14:32:31 +02:00
Themaister f24aed9358 (addr) is redundant... 2011-05-30 00:04:26 +02:00
Themaister 02344f9048 Bitmasking. 2011-05-29 23:58:04 +02:00
Themaister 200d2b598b Slight cleanup. 2011-05-28 15:06:46 +02:00
Themaister 3213bb13ea Fix color conversion for XVideo. 2011-05-28 14:37:16 +02:00
Themaister 53fd0b3751 Fix up color conversion for SDL. 2011-05-28 14:33:23 +02:00
Themaister 9b6e6a1215 Goddamnit, it was ARGB after all o.O weird. 2011-05-28 14:11:37 +02:00
Themaister e5a9d78b70 Fixed typo. 2011-05-28 11:29:40 +02:00
Themaister f22e964cc0 Err ... 32-bit color was RGBA, not ARGB. 2011-05-27 20:38:42 +02:00
Themaister 9fb827d238 Stuff seems to work. 2011-05-27 03:48:59 +02:00
Themaister 24f802023a Start adding tracker stuff to Cg as well. 2011-05-27 02:25:26 +02:00
Themaister ef2b755e17 Merge branch 'master' of github.com:Themaister/SSNES 2011-05-26 23:56:28 +02:00
Themaister 7cc8c01a1e Fix slight bug. Also add missing scale_type_x/y. 2011-05-26 23:55:46 +02:00
Themaister ca509c5b9f Fix slight bug. 2011-05-26 23:55:27 +02:00
Themaister 12a39e160b Should fix weird viewport bug with some FBO shaders. 2011-05-26 22:25:30 +02:00
Themaister 7c5f36be61 Fix build when config file support isn't compiled in. 2011-05-26 20:44:12 +02:00
Themaister aec44b093e Add new transition_previous. 2011-05-26 16:23:11 +02:00
Themaister ee83c31183 Reorder set-param and texture upload. 2011-05-26 12:53:24 +02:00
Themaister f2ad94f1c3 Finally figure it all out ... Damn. 2011-05-26 12:34:14 +02:00
Themaister 3aed471d57 This bug is driving me nuts. It cannot possibly be my bug ... 2011-05-26 02:03:38 +02:00
Themaister 3ee19ec75f Found something ... unsettling. 2011-05-26 00:23:36 +02:00
Themaister b0d1a98cd1 Fix when too many variables are used. 2011-05-25 20:55:38 +02:00
Themaister 94ff67ee15 Stuff seems to work :) 2011-05-25 17:31:07 +02:00
Themaister 8d2a7e4593 More work on state monitor ... compiles. 2011-05-25 15:58:12 +02:00
Themaister 4e7a003497 Start adding snes state tracker uniforms. 2011-05-25 15:15:20 +02:00
Themaister 380384654c Add hold bind to joyconfig. 2011-05-24 11:56:55 +02:00
Themaister 2144ef84fd Add fast-forward (hold) mode.
Also purge default player 2-5 binds ...
2011-05-24 02:31:21 +02:00
Themaister 83d913b6d2 Add possibility to build Imlib on win32/64. 2011-05-24 01:28:00 +02:00
Themaister 2782c9da91 Ifdef CG debugging. 2011-05-23 21:43:08 +02:00
Themaister 2f539cd326 Seems to work in Cg as well ... :) 2011-05-23 21:04:25 +02:00
Themaister f4af518fb4 Yay ... <_< 2011-05-23 20:08:16 +02:00
Themaister eebe0ae5d0 Getting there ... But passN textures aren't set properly ;x 2011-05-23 19:57:52 +02:00
Themaister f9c5c7c8a5 Path to check initial texture with GLSL. 2011-05-23 17:43:29 +02:00
Themaister 8bc3d3ac5c Add possibility for audio driver to override sample rate. 2011-05-23 14:04:31 +02:00
Themaister 6a3386ad1a Should fix stupid SDL message rendering bug when no font is set. 2011-05-23 11:45:44 +02:00
Themaister 5dced40c98 LUT textures work :) 2011-05-22 18:48:43 +02:00
Themaister 3f58932c2b Seems to work :) Yay! 2011-05-22 17:36:18 +02:00
Themaister 373b9dcc37 Some fixups. 2011-05-22 17:07:47 +02:00
Themaister 993bdfb75f Start working on Cg preset spec. 2011-05-22 17:02:09 +02:00
Themaister 70000607a2 Some EQ-ish stuff for lulz. 2011-05-21 20:09:43 +02:00
Themaister 1b64e4b902 Fix macro for input plugin. 2011-05-20 19:58:11 +02:00
Themaister 2166db91e2 Fix awkward compiler warning. 2011-05-19 22:51:23 +02:00
Themaister 4f50b6a749 Clarify default path in $HOME. 2011-05-19 15:51:30 +02:00
Themaister 676f659306 Fix Makefile to work when mkdir -p is being stupid. 2011-05-19 15:40:39 +02:00
Themaister 2f858b7948 Clean up ugly inline stuff. :\ 2011-05-18 22:40:42 +02:00
Themaister 36d9adbc0f *Shrug* windows. Works at least ... :D 2011-05-18 22:11:34 +02:00
Themaister 9473b392df TGA loader (nolib). 2011-05-18 21:49:23 +02:00
Themaister 3bf050d5aa Use MultiTexCoord1 for image coords. 2011-05-18 20:38:04 +02:00
Themaister 8a0ccc99df Make sure we don't load too many pictures. 2011-05-18 20:27:27 +02:00
Themaister c938f3d8de Add lookup texture support. :D yay. 2011-05-18 20:22:27 +02:00
Themaister d1c7b774f0 Remove default buttons. 2011-05-18 14:07:31 +02:00
Themaister 6b6877afc1 DSP config option to ssnes-joyconfig. 2011-05-17 19:41:57 +02:00
Themaister c370cba5b5 Update config. 2011-05-17 19:37:05 +02:00
Themaister 05d62a93c9 Update gitignore. 2011-05-17 19:34:57 +02:00
Themaister 24cb2e6844 Update filter a bit. Add a Makefile. 2011-05-17 19:34:24 +02:00
Themaister 7f1cd62c8a Update DSP API for config callback.
Clean up API a bit to have separate
SSNES_*_API_VERSION defines.
2011-05-17 19:20:41 +02:00
Themaister 5f5013871a Should fix tilde/grave key. 2011-05-17 18:52:00 +02:00
Themaister aebe6bcd23 Add example SSE3-optimized IIR filter. 2011-05-17 02:45:10 +02:00
Themaister ac21fb81e2 Prepare for 0.5 release. 2011-05-15 22:18:36 +02:00
Themaister 74afe7f95b Win32 doesn't like %g in strftime ... 2011-05-15 22:01:24 +02:00
Themaister c8161a31d6 Everything implemented. 2011-05-15 21:57:16 +02:00
Themaister 628217c6ae Fix up screenshot formatting. 2011-05-15 17:30:00 +02:00
Themaister efed98d5b6 Yay, works :) 2011-05-15 17:16:29 +02:00
Themaister 29addd605e Start adding screenshot support. 2011-05-15 16:54:43 +02:00
Themaister 0c121571b3 Update TODO. 2011-05-15 16:17:57 +02:00
Themaister 6244671b04 Small API cleanup. 2011-05-15 15:57:47 +02:00
Themaister 21b046cdd1 Add more binds to X11 input. 2011-05-15 15:54:46 +02:00
Themaister b32224d406 Check for API mismatch. 2011-05-15 01:49:37 +02:00
Themaister 5d5865cfd8 Add external API for audio driver. 2011-05-15 01:46:11 +02:00
Themaister 4a78f2fef1 Add a clarifying comment. 2011-05-14 20:53:38 +02:00
Themaister b521becd3c Fix up external video lib a bit. 2011-05-14 20:52:35 +02:00
Themaister f10ed12b74 Fix doc bug. 2011-05-13 22:05:16 +02:00
Themaister 8d051ab413 Fix up case where plugin resamples. 2011-05-13 21:43:32 +02:00
Themaister 4cc17a74f7 Clean up error handling a bit. 2011-05-13 21:22:37 +02:00
Themaister 5ae4235545 Some fixes. 2011-05-13 21:19:05 +02:00
Themaister 8ceb8225ad DSP plugin interface, weeee :D 2011-05-13 21:05:28 +02:00
Themaister 20a3087d1c Make input_scale more clear. 2011-05-13 19:42:37 +02:00
Themaister 1f45dc512b 80-cols comments. 2011-05-12 01:30:30 +02:00
Themaister 13dee59fc8 Fix some more ... :v 2011-05-12 00:35:29 +02:00
Themaister 5f78063449 Fix up call conventions, etc. 2011-05-12 00:34:08 +02:00
Themaister ea6bd8c5c5 Fix up Win32 build a bit, and a crash. :D 2011-05-11 22:53:54 +02:00
Themaister bdc85f2def Fix up Win32 build. 2011-05-11 21:37:50 +02:00
Themaister efa731fc6d Fix inconsistency with ext input. 2011-05-11 21:12:14 +02:00
Themaister 80d50b046d Fix crash. 2011-05-11 18:47:36 +02:00
Themaister 1855a7ea0d Add driver stuff. 2011-05-11 18:40:03 +02:00
Themaister f5c11071be Start hooking up input driver. 2011-05-11 18:26:00 +02:00
Themaister 4b9e46ff06 Update config. 2011-05-11 17:57:31 +02:00
Themaister 75d618140b Some more work on external API. 2011-05-11 17:52:16 +02:00
Themaister 59c6de69b0 Frame counter for shaders. Not in spec currently. 2011-05-11 13:24:59 +02:00
Themaister dc20c58189 Update path. 2011-05-11 12:19:33 +02:00
Themaister c6eecf706a Add Win64 Makefile. 2011-05-11 12:13:55 +02:00
Themaister f2ee22d259 Start working on video interface. 2011-05-05 20:23:08 +02:00
Themaister b48322222a Add overscan cropping. 2011-05-05 14:13:12 +02:00
Themaister bbf5a1ee72 Should fix aspect ratio calculation. 2011-05-05 11:38:57 +02:00
Themaister c0851877bf Update TODO. 2011-05-05 00:13:51 +02:00
Themaister 51d96676af Update TODO list. 2011-05-04 22:26:37 +02:00
Themaister 9f3b86e893 Update joyconfig. 2011-05-04 22:25:27 +02:00
Themaister ac85037fc1 And some more ... 2011-05-04 22:16:25 +02:00
Themaister fa8e948e3e Some additional keybinds. 2011-05-04 22:10:17 +02:00
Themaister 252cce07a6 Update TODO again. 2011-05-01 23:41:39 +02:00
Themaister 17581106ba Update TODO. 2011-05-01 17:10:26 +02:00
Themaister 1bd8424fb4 A TODO list to keep track of things. 2011-05-01 17:05:49 +02:00
Themaister 23db525296 Fix nasty cheat handling bug. 2011-04-29 12:36:28 +02:00
Themaister d679f8b24f v0.4.1 updates. 2011-04-26 19:00:50 +02:00
Themaister d2f2ab6a9d Windowed width with xscale depends on aspect ratio. 2011-04-24 02:44:02 +02:00
Themaister 3e1e08ca9a Variadic shifts. Optimizes the path when format matches. 2011-04-23 19:15:15 +02:00
Themaister bb93f20be9 Hopefully make conversions more portable ... 2011-04-23 18:33:56 +02:00
Themaister 54dc289cde SDL fixes. 2011-04-23 18:06:48 +02:00
Themaister fcebad2589 FreeConsole() to avoid ugly console. 2011-04-23 14:47:50 +02:00
Themaister 4b60f98603 Might fix some odd warnings. 2011-04-22 04:27:53 +02:00
Themaister d304960c21 0.4.1-beta I suppose. 2011-04-22 03:17:31 +02:00
Themaister 8da13b716a Simple font rendering with SDL. 2011-04-22 03:13:09 +02:00
Themaister a6c08a24d7 Fix 32-bit 2011-04-21 14:30:54 +02:00
Themaister 6713272809 Hrm... Seems to work, except for 32-bit -> 32-bit <_< 2011-04-21 13:12:45 +02:00
Themaister 8d7cf23b40 Meh, SDL performs like shit :p 2011-04-21 03:39:03 +02:00
Themaister d317a9773f Start on SDL video driver. 2011-04-21 03:23:44 +02:00
Themaister e8806c48c9 Default keybinds and stuff. 2011-04-17 16:55:31 +02:00
Themaister abd7bab43a Cheat support... Somewhat. 2011-04-17 16:53:19 +02:00
Themaister 66464c2cce Parsing seems to work at least. 2011-04-17 15:58:18 +02:00
Themaister 092fa9d531 Get initial cheat support down. 2011-04-17 13:30:59 +02:00
Themaister 1005d7fa9b SHA256 support. Now onto cheats ... 2011-04-17 12:29:58 +02:00
Themaister 079549cbd2 Fix an edge case with strlcat(). 2011-04-11 21:28:03 +02:00
Themaister 0f0a4d0a5e Fix fullscreen state flickering with XVideo. 2011-04-09 13:15:14 +02:00
Themaister f0bbeb901d Fix some error handling for XVideo. 2011-04-08 20:53:11 +02:00
Themaister 8027a25016 Fix include issue in windows. 2011-04-07 21:31:58 +02:00
Themaister a1426c96f8 Update for Win32. 2011-04-07 21:26:02 +02:00
Themaister a4c901df57 Bit more logging when saving SRAM to be sure. 0.4! :D 2011-04-07 21:20:11 +02:00
Themaister f2cc19d1a7 Some fixups for SGB etc. 2011-04-07 21:06:31 +02:00
Themaister ad55829890 Convert to strlcpy/strlcat. More sane. 2011-04-03 22:29:36 +02:00
Themaister 6b8eea6363 Start with strlcpy/strlcat ... 2011-04-03 22:16:59 +02:00
Themaister b2d214ee79 Should fix path issues with UPS patching.
When filename had two dots ('.') in it,
using fill_pathname on g_extern.basename was wrong.
Added fill_pathname_noext to countermeasure this.
2011-04-03 21:43:25 +02:00
Themaister f5fb113563 Should fix case where we have 1 pass and scale attributes. 2011-03-30 23:09:29 +02:00
174 changed files with 25402 additions and 3558 deletions

No files matched your search

View File
Whitespace-only changes.
+11 -1
View File
@@ -1,5 +1,15 @@
*.o
ssnes
*.bmpobj
*.so
*.dll
/ssnes
/config.h
/config.mk
/tools/ssnes-joyconfig
*.sdf
*.opensdf
*.suo
Debug
Release
ipch
*.user
+42
View File
@@ -0,0 +1,42 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* Copyright (C) 2011-2012 - Daniel De Matteis
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <xtl.h>
#include <stddef.h>
#include <xbdm.h>
int ssnes_main(int argc, char *argv[]);
#undef main
// Temporary, a more sane implementation should go here.
int main(int argc, char *argv[])
{
//for devits only, we will need to mount all partitions for retail
//in a different way
DmMapDevkitDrive();
char arg1[] = "ssnes";
char arg2[] = "e:\\roms\\mario.sfc";
char arg3[] = "-v";
char arg4[] = "-c";
char arg5[] = "e:\\roms\\ssnes.cfg";
char *argv_[] = { arg1, arg2, arg3, arg4, arg5, NULL };
return ssnes_main(sizeof(argv_) / sizeof(argv_[0]) - 1, argv_);
}
+49
View File
@@ -0,0 +1,49 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_MSVC_COMPAT_H
#define __SSNES_MSVC_COMPAT_H
#ifdef _MSC_VER
#undef UNICODE // Do not bother with UNICODE at this time.
#include <stddef.h>
#include <math.h>
// Python headers defines ssize_t and sets HAVE_SSIZE_T. Cannot duplicate these efforts.
#ifndef HAVE_SSIZE_T
typedef int ssize_t;
#endif
#define snprintf _snprintf
#define strcasecmp _stricmp
// Disable some of the annoying warnings.
#pragma warning(disable : 4800)
#pragma warning(disable : 4244)
#pragma warning(disable : 4305)
#pragma warning(disable : 4146)
#pragma warning(disable : 4267)
static inline float roundf(float in)
{
return in >= 0.0f ? floorf(in + 0.5f) : ceilf(in - 0.5f);
}
#endif
#endif
+222
View File
@@ -0,0 +1,222 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../driver.h"
#include <stdlib.h>
#include <xtl.h>
#include <xaudio2.h>
#include "../general.h"
#define MAX_BUFFERS 16
#define MAX_BUFFERS_MASK 15
struct XAudio : public IXAudio2VoiceCallback
{
XAudio() :
buf(0), pXAudio2(0), pMasteringVoice(0),
pSourceVoice(0), nonblock(false), bufsize(0),
bufptr(0), write_buffer(0), buffers(0), hEvent(0)
{}
~XAudio()
{
if (pSourceVoice)
{
pSourceVoice->Stop(0, XAUDIO2_COMMIT_NOW);
pSourceVoice->DestroyVoice();
}
if (pMasteringVoice)
pMasteringVoice->DestroyVoice();
if (pXAudio2)
pXAudio2->Release();
if (hEvent)
CloseHandle(hEvent);
delete[] buf;
}
bool init(unsigned rate, unsigned latency)
{
size_t bufsize_ = latency * rate / 1000;
size_t size = bufsize_ * 2 * sizeof(int16_t);
SSNES_LOG("XAudio2: Requesting %d ms latency, using %d ms latency.\n", latency, (int)bufsize_ * 1000 / rate);
if (FAILED(XAudio2Create(&pXAudio2, 0)))
return false;
if (FAILED(pXAudio2->CreateMasteringVoice(&pMasteringVoice, 2, rate, 0, 0, NULL)))
return false;
WAVEFORMATEX wfx = {0};
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = 2;
wfx.nSamplesPerSec = rate;
wfx.nBlockAlign = 2 * sizeof(int16_t);
wfx.wBitsPerSample = sizeof(int16_t) * 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.cbSize = 0;
if (FAILED(pXAudio2->CreateSourceVoice(&pSourceVoice, &wfx,
XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO, this, 0, 0)))
return false;
hEvent = CreateEvent(0, FALSE, FALSE, 0);
bufsize = size / MAX_BUFFERS;
buf = new uint8_t[bufsize * MAX_BUFFERS];
memset(buf, 0, bufsize * MAX_BUFFERS);
if (FAILED(pSourceVoice->Start(0)))
return false;
return true;
}
// It's really 16-bit, but we have to byteswap.
size_t write(const uint8_t *buffer, size_t size)
{
if (nonblock)
{
size_t avail = bufsize * (MAX_BUFFERS - buffers - 1);
if (avail == 0)
return 0;
if (avail < size)
size = avail;
}
unsigned bytes = size;
while (bytes)
{
unsigned need = min(bytes, bufsize - bufptr);
uint8_t *base_write = buf + write_buffer * bufsize + bufptr;
memcpy(base_write, buffer, need);
bufptr += need;
buffer += need;
bytes -= need;
if (bufptr == bufsize)
{
while (buffers == MAX_BUFFERS - 1)
WaitForSingleObject(hEvent, INFINITE);
XAUDIO2_BUFFER xa2buffer = {0};
xa2buffer.AudioBytes = bufsize;
xa2buffer.pAudioData = buf + write_buffer * bufsize;
if (FAILED(pSourceVoice->SubmitSourceBuffer(&xa2buffer)))
return 0;
InterlockedIncrement(&buffers);
bufptr = 0;
write_buffer = (write_buffer + 1) & MAX_BUFFERS_MASK;
}
}
return size;
}
STDMETHOD_(void, OnBufferStart) (void *) {}
STDMETHOD_(void, OnBufferEnd) (void *)
{
InterlockedDecrement(&buffers);
SetEvent(hEvent);
}
STDMETHOD_(void, OnLoopEnd) (void *) {}
STDMETHOD_(void, OnStreamEnd) () {}
STDMETHOD_(void, OnVoiceError) (void *, HRESULT) {}
STDMETHOD_(void, OnVoiceProcessingPassEnd) () {}
STDMETHOD_(void, OnVoiceProcessingPassStart) (UINT32) {}
uint8_t *buf;
IXAudio2 *pXAudio2;
IXAudio2MasteringVoice *pMasteringVoice;
IXAudio2SourceVoice *pSourceVoice;
bool nonblock;
unsigned bufsize;
unsigned bufptr;
unsigned write_buffer;
volatile long buffers;
HANDLE hEvent;
};
static void *xa_init(const char *device, unsigned rate, unsigned latency)
{
if (latency < 8)
latency = 8; // Do not allow shenanigans.
XAudio *xa = new XAudio;
if (!xa->init(rate, latency))
goto error;
return xa;
error:
SSNES_ERR("Failed to init XAudio2.\n");
delete xa;
return NULL;
}
static ssize_t xa_write(void *data, const void *buf, size_t size)
{
XAudio *xa = (XAudio*)data;
size_t ret = xa->write((const uint8_t*)buf, size);
if (ret == 0)
return -1;
return ret;
}
static bool xa_stop(void *data)
{
(void)data;
return true;
}
static void xa_set_nonblock_state(void *data, bool state)
{
XAudio *xa = (XAudio*)data;
xa->nonblock = state;
}
static bool xa_start(void *data)
{
(void)data;
return true;
}
static void xa_free(void *data)
{
XAudio *xa = (XAudio*)data;
if (xa)
delete xa;
}
const audio_driver_t audio_xdk360 = {
xa_init,
xa_write,
xa_stop,
xa_start,
xa_set_nonblock_state,
xa_free,
NULL,
"xdk360"
};
+124
View File
@@ -0,0 +1,124 @@
/* SSNES - A Super Ninteno Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* Copyright (C) 2011-2012 - Daniel De Matteis
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdlib.h>
#include <xtl.h>
#include "../driver.h"
#include "../libsnes.hpp"
static XINPUT_STATE state[5];
static void xdk360_input_poll(void *data)
{
(void)data;
ZeroMemory(&state, sizeof(XINPUT_STATE));
for (unsigned i = 0; i < 5; i++)
XInputGetState(i, &state[i]);
}
static int16_t xdk360_input_state(void *data, const struct snes_keybind **binds,
bool port, unsigned device,
unsigned index, unsigned id)
{
(void)data;
(void)binds;
(void)index;
if (device != SNES_DEVICE_JOYPAD)
return 0;
unsigned player = 0;
if (port == SNES_PORT_2 && device == SNES_DEVICE_MULTITAP)
player = index + 1;
else if (port == SNES_PORT_2)
player = 1;
// Hardcoded binds.
uint64_t button;
switch (id)
{
case SNES_DEVICE_ID_JOYPAD_A:
button = XINPUT_GAMEPAD_B;
break;
case SNES_DEVICE_ID_JOYPAD_B:
button = XINPUT_GAMEPAD_A;
break;
case SNES_DEVICE_ID_JOYPAD_X:
button = XINPUT_GAMEPAD_Y;
break;
case SNES_DEVICE_ID_JOYPAD_Y:
button = XINPUT_GAMEPAD_X;
break;
case SNES_DEVICE_ID_JOYPAD_LEFT:
button = XINPUT_GAMEPAD_DPAD_LEFT;
break;
case SNES_DEVICE_ID_JOYPAD_RIGHT:
button = XINPUT_GAMEPAD_DPAD_RIGHT;
break;
case SNES_DEVICE_ID_JOYPAD_UP:
button = XINPUT_GAMEPAD_DPAD_UP;
break;
case SNES_DEVICE_ID_JOYPAD_DOWN:
button = XINPUT_GAMEPAD_DPAD_DOWN;
break;
case SNES_DEVICE_ID_JOYPAD_START:
button = XINPUT_GAMEPAD_START;
break;
case SNES_DEVICE_ID_JOYPAD_SELECT:
button = XINPUT_GAMEPAD_BACK;
break;
case SNES_DEVICE_ID_JOYPAD_L:
button = XINPUT_GAMEPAD_LEFT_SHOULDER;
break;
case SNES_DEVICE_ID_JOYPAD_R:
button = XINPUT_GAMEPAD_RIGHT_SHOULDER;
break;
default:
button = 0;
}
return (state[player].Gamepad.wButtons & button) ? 1 : 0;
}
static void xdk360_free_input(void *data)
{
(void)data;
}
static void* xdk360_input_init(void)
{
return (void*)-1;
}
static bool xdk360_key_pressed(void *data, int key)
{
(void)data;
(void)key;
return false;
}
const input_driver_t input_xdk360 = {
xdk360_input_init,
xdk360_input_poll,
xdk360_input_state,
xdk360_key_pressed,
xdk360_free_input,
"xdk360"};
+304
View File
@@ -0,0 +1,304 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <xtl.h>
#include "../driver.h"
#include "../general.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
static const char* g_strPixelShaderProgram =
" sampler2D tex : register(s0); "
" struct PS_IN "
" { "
" float2 coord : TEXCOORD0; "
" }; "
" "
" float4 main(PS_IN input) : COLOR "
" { "
" return tex2D(tex, input.coord); "
" } ";
static const char* g_strVertexShaderProgram =
" struct VS_IN "
" "
" { "
" float2 pos : POSITION; "
" float2 coord : TEXCOORD0; "
" }; "
" "
" struct VS_OUT "
" { "
" float4 pos : POSITION; "
" float2 coord : TEXCOORD0; "
" }; "
" "
" VS_OUT main(VS_IN input) "
" { "
" VS_OUT output; "
" output.pos = float4(input.pos, 0.0, 1.0); "
" output.coord = input.coord; "
" return output; "
" } ";
typedef struct DrawVerticeFormats
{
float x, y;
float u, v;
} DrawVerticeFormats;
static bool g_quitting;
typedef struct xdk360_video
{
IDirect3D9* xdk360_device;
IDirect3DDevice9* xdk360_render_device;
IDirect3DVertexShader9 *pVertexShader;
IDirect3DPixelShader9* pPixelShader;
IDirect3DVertexDeclaration9* pVertexDecl;
IDirect3DVertexBuffer9* vertex_buf;
IDirect3DTexture9* lpTexture;
unsigned frame_count;
unsigned last_width, last_height;
} xdk360_video_t;
static void xdk360_gfx_free(void *data)
{
xdk360_video_t *vid = (xdk360_video_t*)data;
if (!vid)
return;
vid->lpTexture->Release();
vid->vertex_buf->Release();
vid->pVertexDecl->Release();
vid->pPixelShader->Release();
vid->pVertexShader->Release();
vid->xdk360_render_device->Release();
vid->xdk360_device->Release();
free(vid);
}
static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
xdk360_video_t *vid = (xdk360_video_t*)calloc(1, sizeof(xdk360_video_t));
if (!vid)
return NULL;
vid->xdk360_device = Direct3DCreate9(D3D_SDK_VERSION);
if (!vid->xdk360_device)
{
free(vid);
return NULL;
}
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.BackBufferWidth = 1280;
d3dpp.BackBufferHeight = 720;
d3dpp.BackBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_A8R8G8B8);
d3dpp.FrontBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_LE_X8R8G8B8);
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
d3dpp.MultiSampleQuality = 0;
d3dpp.BackBufferCount = 2;
d3dpp.EnableAutoDepthStencil = TRUE;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
vid->xdk360_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp,
&vid->xdk360_render_device);
ID3DXBuffer* pShaderCodeV = NULL;
ID3DXBuffer* pShaderCodeP = NULL;
ID3DXBuffer* pErrorMsg = NULL;
HRESULT hr = D3DXCompileShader(g_strVertexShaderProgram, (UINT)strlen(g_strVertexShaderProgram),
NULL, NULL, "main", "vs_2_0", 0, &pShaderCodeV, &pErrorMsg, NULL);
if (SUCCEEDED(hr))
{
hr = D3DXCompileShader(g_strPixelShaderProgram, (UINT)strlen(g_strPixelShaderProgram),
NULL, NULL, "main", "ps_2_0", 0, &pShaderCodeP, &pErrorMsg, NULL);
}
if (FAILED(hr))
{
OutputDebugString(pErrorMsg ? (char*)pErrorMsg->GetBufferPointer() : "");
vid->xdk360_render_device->Release();
vid->xdk360_device->Release();
free(vid);
return NULL;
}
vid->xdk360_render_device->CreateVertexShader((const DWORD*)pShaderCodeV->GetBufferPointer(), &vid->pVertexShader);
vid->xdk360_render_device->CreatePixelShader((const DWORD*)pShaderCodeP->GetBufferPointer(), &vid->pPixelShader);
pShaderCodeV->Release();
pShaderCodeP->Release();
vid->xdk360_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5,
0, &vid->lpTexture, NULL);
D3DLOCKED_RECT d3dlr;
if (SUCCEEDED(vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK)))
{
memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
vid->lpTexture->UnlockRect(0);
}
vid->last_width = 512;
vid->last_height = 512;
vid->xdk360_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), 0,
0, 0, &vid->vertex_buf, NULL);
static const DrawVerticeFormats init_verts[] = {
{ -1.0f, -1.0f, 0.0f, 1.0f },
{ 1.0f, -1.0f, 1.0f, 1.0f },
{ -1.0f, 1.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, 1.0f, 0.0f },
};
void *verts_ptr;
vid->vertex_buf->Lock(0, 0, &verts_ptr, 0);
memcpy(verts_ptr, init_verts, sizeof(init_verts));
vid->vertex_buf->Unlock();
static const D3DVERTEXELEMENT9 VertexElements[] =
{
{ 0, 0 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 2 * sizeof(float), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};
vid->xdk360_render_device->CreateVertexDeclaration(VertexElements, &vid->pVertexDecl);
vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
0xff000000, 1.0f, 0);
vid->xdk360_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
vid->xdk360_render_device->SetRenderState(D3DRS_ZENABLE, FALSE);
D3DVIEWPORT9 vp = {0};
vp.Width = 1280;
vp.Height = 720;
vp.MinZ = 0.0f;
vp.MaxZ = 1.0f;
vid->xdk360_render_device->SetViewport(&vp);
return vid;
}
static bool xdk360_gfx_frame(void *data, const void *frame,
unsigned width, unsigned height, unsigned pitch, const char *msg)
{
xdk360_video_t *vid = (xdk360_video_t*)data;
vid->frame_count++;
vid->xdk360_render_device->Clear(0, NULL, D3DCLEAR_TARGET,
0xff000000, 1.0f, 0);
if (vid->last_width != width || vid->last_height != height)
{
D3DLOCKED_RECT d3dlr;
if (SUCCEEDED(vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK)))
{
memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch);
vid->lpTexture->UnlockRect(0);
}
float tex_w = width / 512.0f;
float tex_h = height / 512.0f;
const DrawVerticeFormats verts[] = {
{ -1.0f, -1.0f, 0.0f, tex_h },
{ 1.0f, -1.0f, tex_w, tex_h },
{ -1.0f, 1.0f, 0.0f, 0.0f },
{ 1.0f, 1.0f, tex_w, 0.0f },
};
void *verts_ptr;
vid->vertex_buf->Lock(0, 0, &verts_ptr, 0);
memcpy(verts_ptr, verts, sizeof(verts));
vid->vertex_buf->Unlock();
vid->last_width = width;
vid->last_height = height;
}
D3DLOCKED_RECT d3dlr;
if (SUCCEEDED(vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK)))
{
for (unsigned y = 0; y < height; y++)
{
const uint8_t *in = (const uint8_t*)frame + y * pitch;
uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch;
memcpy(out, in, width * sizeof(uint16_t));
}
vid->lpTexture->UnlockRect(0);
}
vid->xdk360_render_device->SetTexture(0, vid->lpTexture);
vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
vid->xdk360_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
vid->xdk360_render_device->SetVertexShader(vid->pVertexShader);
vid->xdk360_render_device->SetPixelShader(vid->pPixelShader);
vid->xdk360_render_device->SetVertexDeclaration(vid->pVertexDecl);
vid->xdk360_render_device->SetStreamSource(0, vid->vertex_buf, 0, sizeof(DrawVerticeFormats));
vid->xdk360_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
vid->xdk360_render_device->Present(NULL, NULL, NULL, NULL);
return true;
}
static void xdk360_gfx_set_nonblock_state(void *data, bool state)
{
(void)data;
(void)state;
}
static bool xdk360_gfx_alive(void *data)
{
(void)data;
return !g_quitting;
}
static bool xdk360_gfx_focus(void *data)
{
(void)data;
return true;
}
const video_driver_t video_xdk360 = {
xdk360_gfx_init,
xdk360_gfx_frame,
xdk360_gfx_set_nonblock_state,
xdk360_gfx_alive,
xdk360_gfx_focus,
NULL,
xdk360_gfx_free,
"xdk360"
};
+8
View File
@@ -3,3 +3,11 @@ Hans-Kristian Arntzen - <[email protected]>
Devin J. Pohly - <[email protected]>
- Joypad axis support
Chris Moeller - <[email protected]>
- CoreAudio audio driver
Daniel De Matteis - <[email protected]>
- PlayStation 3 port
- XBox 360 XDK port
+102 -40
View File
@@ -2,25 +2,34 @@ include config.mk
TARGET = ssnes tools/ssnes-joyconfig
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o
OBJ = ssnes.o file.o driver.o settings.o dynamic.o message.o rewind.o movie.o gfx/gfx_common.o ups.o bps.o strl.o getopt.o screenshot.o audio/hermite.o audio/utils.o
JOYCONFIG_OBJ = tools/ssnes-joyconfig.o conf/config_file.o strl.o
HEADERS = $(wildcard */*.h) $(wildcard *.h)
LIBS = -lm
DEFINES = -DHAVE_CONFIG_H
ifneq ($(findstring Darwin,$(shell uname -a)),)
ifneq ($(findstring Darwin,$(OS)),)
OSX := 1
LIBS += -framework AppKit
else
OSX := 0
endif
ifeq ($(HAVE_SRC), 1)
LIBS += $(SRC_LIBS)
DEFINES += $(SRC_CFLAGS)
else
OBJ += audio/hermite.o
BSD_LOCAL_INC =
DYLIB_LIB = -ldl
ifneq ($(findstring BSD,$(OS)),)
BSD_LOCAL_INC = -I/usr/local/include
DYLIB_LIB = -lc
endif
ifneq ($(findstring Linux,$(OS)),)
LIBS += -lrt
endif
ifeq ($(HAVE_THREADS), 1)
OBJ += autosave.o thread.o
LIBS += -lpthread
endif
ifeq ($(HAVE_CONFIGFILE), 1)
@@ -33,19 +42,29 @@ endif
ifeq ($(HAVE_RSOUND), 1)
OBJ += audio/rsound.o
LIBS += -lrsound
LIBS += $(RSOUND_LIBS)
DEFINES += $(RSOUND_CFLAGS)
endif
ifeq ($(HAVE_OSS), 1)
OBJ += audio/oss.o
endif
ifeq ($(HAVE_OSS_BSD), 1)
OBJ += audio/oss.o
endif
ifeq ($(HAVE_OSS_LIB), 1)
LIBS += -lossaudio
endif
ifeq ($(HAVE_ALSA), 1)
OBJ += audio/alsa.o
LIBS += -lasound
LIBS += $(ALSA_LIBS)
DEFINES += $(ALSA_CFLAGS)
endif
ifeq ($(HAVE_ROAR), 1)
OBJ += audio/roar.o
LIBS += -lroar
LIBS += $(ROAR_LIBS)
DEFINES += $(ROAR_CFLAGS)
endif
ifeq ($(HAVE_AL), 1)
OBJ += audio/openal.o
@@ -66,24 +85,30 @@ ifeq ($(HAVE_PULSE), 1)
DEFINES += $(PULSE_CFLAGS)
endif
ifeq ($(HAVE_SDL), 1)
OBJ += gfx/gl.o input/sdl.o audio/sdl.o audio/buffer.o
DEFINES += $(SDL_CFLAGS)
LIBS += $(SDL_LIBS)
ifeq ($(OSX),1)
LIBS += -framework OpenGL
else
LIBS += -lGL
endif
ifeq ($(HAVE_COREAUDIO), 1)
OBJ += audio/coreaudio.o
LIBS += -framework CoreServices -framework CoreAudio -framework AudioUnit
endif
ifeq ($(HAVE_FBO), 1)
DEFINES += -DHAVE_FBO
ifeq ($(HAVE_SDL), 1)
OBJ += gfx/sdl_gfx.o gfx/sdlwrap.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o
DEFINES += $(SDL_CFLAGS) $(BSD_LOCAL_INC)
LIBS += $(SDL_LIBS)
ifeq ($(HAVE_OPENGL), 1)
OBJ += gfx/gl.o
ifeq ($(OSX),1)
LIBS += -framework OpenGL
else
LIBS += -lGL
endif
endif
endif
ifeq ($(HAVE_XVIDEO), 1)
OBJ += gfx/xvideo.o input/x11_input.o
LIBS += -lXv -lX11
LIBS += $(XVIDEO_LIBS) $(X11_LIBS) $(XEXT_LIBS)
DEFINES += $(XVIDEO_CFLAGS) $(X11_CFLAGS) $(XEXT_CFLAGS)
endif
ifeq ($(HAVE_CG), 1)
@@ -92,13 +117,24 @@ ifeq ($(HAVE_CG), 1)
endif
ifeq ($(HAVE_XML), 1)
OBJ += gfx/shader_glsl.o
OBJ += sha256.o cheats.o
LIBS += $(XML_LIBS)
DEFINES += $(XML_CFLAGS)
ifeq ($(HAVE_OPENGL), 1)
OBJ += gfx/shader_glsl.o
endif
endif
ifeq ($(HAVE_FILTER), 1)
LIBS += -ldl
ifeq ($(HAVE_XML), 1)
OBJ += gfx/snes_state.o gfx/image.o
else ifeq ($(HAVE_CG), 1)
OBJ += gfx/snes_state.o gfx/image.o
endif
ifeq ($(HAVE_DYLIB), 1)
OBJ += gfx/ext_gfx.o audio/ext_audio.o
LIBS += $(DYLIB_LIB)
endif
ifeq ($(HAVE_FREETYPE), 1)
@@ -107,28 +143,48 @@ ifeq ($(HAVE_FREETYPE), 1)
DEFINES += $(FREETYPE_CFLAGS)
endif
ifeq ($(HAVE_SDL_IMAGE), 1)
LIBS += $(SDL_IMAGE_LIBS)
DEFINES += $(SDL_IMAGE_CFLAGS)
endif
ifeq ($(HAVE_FFMPEG), 1)
OBJ += record/ffemu.o
LIBS += $(AVCODEC_LIBS) $(AVCORE_LIBS) $(AVFORMAT_LIBS) $(AVUTIL_LIBS) $(SWSCALE_LIBS)
DEFINES += $(AVCODEC_CFLAGS) $(AVCORE_CFLAGS) $(AVFORMAT_CFLAGS) $(AVUTIL_CFLAGS) $(SWSCALE_CFLAGS)
LIBS += $(AVCODEC_LIBS) $(AVFORMAT_LIBS) $(AVUTIL_LIBS) $(SWSCALE_LIBS)
DEFINES += $(AVCODEC_CFLAGS) $(AVFORMAT_CFLAGS) $(AVUTIL_CFLAGS) $(SWSCALE_CFLAGS)
endif
ifeq ($(HAVE_DYNAMIC), 1)
LIBS += -ldl
LIBS += $(DYLIB_LIB)
else
LIBS += $(libsnes)
endif
ifeq ($(HAVE_PYTHON), 1)
DEFINES += $(PYTHON_CFLAGS) -Wno-unused-parameter
LIBS += $(PYTHON_LIBS)
OBJ += gfx/py_state/py_state.o
endif
ifneq ($(V),1)
Q := @
endif
CFLAGS += -Wall -O3 -g -I.
OPTIMIZE_FLAG = -O3
ifeq ($(DEBUG), 1)
OPTIMIZE_FLAG = -O0
endif
CFLAGS += -Wall $(OPTIMIZE_FLAG) -g -I. -pedantic
ifeq ($(CXX_BUILD), 1)
CFLAGS += -std=c++0x -xc++ -D__STDC_CONSTANT_MACROS
else
ifneq ($(findstring icc,$(CC)),)
CFLAGS += -std=c99
CFLAGS += -std=c99 -D_GNU_SOURCE
else
CFLAGS += -std=gnu99
endif
endif
all: $(TARGET) config.mk
@@ -137,11 +193,15 @@ config.mk: configure qb/*
@exit 1
ssnes: $(OBJ)
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS) $(LIBRARY_DIRS)
@$(if $(Q), $(shell echo echo LD $@),)
tools/ssnes-joyconfig: $(JOYCONFIG_OBJ)
$(Q)$(CC) -o $@ $(JOYCONFIG_OBJ) $(SDL_LIBS) $(LDFLAGS)
ifeq ($(CXX_BUILD), 1)
$(Q)$(CXX) -o $@ $(JOYCONFIG_OBJ) $(SDL_LIBS) $(LDFLAGS) $(LIBRARY_DIRS)
else
$(Q)$(CC) -o $@ $(JOYCONFIG_OBJ) $(SDL_LIBS) $(LDFLAGS) $(LIBRARY_DIRS)
endif
@$(if $(Q), $(shell echo echo LD $@),)
%.o: %.c config.h config.mk $(HEADERS)
@@ -149,9 +209,9 @@ tools/ssnes-joyconfig: $(JOYCONFIG_OBJ)
@$(if $(Q), $(shell echo echo CC $<),)
install: $(TARGET)
mkdir -p $(DESTDIR)$(PREFIX)/bin
mkdir -p $(DESTDIR)/etc
mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1
mkdir -p $(DESTDIR)$(PREFIX)/bin 2>/dev/null || /bin/true
mkdir -p $(DESTDIR)/etc 2>/dev/null || /bin/true
mkdir -p $(DESTDIR)$(PREFIX)/share/man/man1 2>/dev/null || /bin/true
install -m755 $(TARGET) $(DESTDIR)$(PREFIX)/bin
install -m644 ssnes.cfg $(DESTDIR)/etc/ssnes.cfg
install -m644 docs/ssnes.1 $(DESTDIR)$(PREFIX)/share/man/man1
@@ -159,18 +219,20 @@ install: $(TARGET)
install -m755 ssnes-zip $(DESTDIR)$(PREFIX)/bin
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/{ssnes,ssnes-joyconfig,ssnes-zip}
rm -f $(DESTDIR)$(PREFIX)/bin/ssnes
rm -f $(DESTDIR)$(PREFIX)/bin/ssnes-joyconfig
rm -f $(DESTDIR)$(PREFIX)/bin/ssnes-zip
rm -f $(DESTDIR)/etc/ssnes.cfg
rm -f $(DESTDIR)$(PREFIX)/share/man/man1/{ssnes,ssnes-joyconfig}.1
rm -f $(DESTDIR)$(PREFIX)/share/man/man1/ssnes.1
rm -f $(DESTDIR)$(PREFIX)/share/man/man1/ssnes-joyconfig.1
clean:
rm -f *.o
rm -f audio/*.o
rm -f conf/*.o
rm -f gfx/*.o
rm -f gfx/py_state/*.o
rm -f record/*.o
rm -f hqflt/*.o
rm -f hqflt/snes_ntsc/*.o
rm -f input/*.o
rm -f tools/*.o
rm -f $(TARGET)
+85
View File
@@ -0,0 +1,85 @@
###
##
# Makefile for SSNES PS3. Somewhat generic and avoids using the odd SDK examples.
##
###
##
DEBUG = 0
CELL_BUILD_TOOLS = GCC
## Platform detection from nall/Makefile. Only two applicable hosts for PS3 SDK.
ifeq ($(platform),)
uname := $(shell uname -a)
ifeq ($(uname),)
platform := win
else
platform := linux
endif
endif
CELL_SDK := /usr/local/cell
ifeq ($(platform),win)
HOST_DIR := host-win32
else
HOST_DIR := host-linux
endif
ifeq ($(CELL_BUILD_TOOLS),SNC)
CC = $(CELL_SDK)/$(HOST_DIR)/sn/bin/ps3ppusnc
CXX = $(CC)
LD = $(CELL_SDK)/$(HOST_DIR)/sn/bin/ps3ppuld
else
CC = $(CELL_SDK)/$(HOST_DIR)/ppu/bin/ppu-lv2-gcc
CXX = $(CELL_SDK)/$(HOST_DIR)/ppu/bin/ppu-lv2-g++
LD = $(CELL_SDK)/$(HOST_DIR)/ppu/bin/ppu-lv2-g++
endif
STRIP = $(CELL_SDK)/$(HOST_DIR)/ppu/bin/ppu-lv2-strip
PPU_TARGET := ssnes.elf
LDDIRS = -L. -L$(CELL_SDK)/target/ppu/lib/PSGL/RSX/ultra-opt
INCDIRS = -I. -Icommon
MAKE_FSELF_NPDRM = $(CELL_SDK)/$(HOST_DIR)/bin/make_fself_npdrm
MAKE_PACKAGE_NPDRM = $(CELL_SDK)/$(HOST_DIR)/bin/make_package_npdrm
OBJ = fifo_buffer.o ps3/cellframework2/fileio/file_browser.o ps3/ps3_audio.o ps3/menu.o ps3/ps3_input.o ps3/cellframework2/input/pad_input.o getopt.o ssnes.o driver.o file.o settings.o message.o rewind.o movie.o gfx/gfx_common.o ps3/ps3_video_psgl.o gfx/shader_cg.o gfx/snes_state.o ups.o bps.o strl.o screenshot.o audio/hermite.o dynamic.o ps3/main.o audio/utils.o conf/config_file.o gfx/image.o
LIBS = -ldbgfont -lPSGL -lPSGLcgc -lcgc -lgcm_cmd -lgcm_sys_stub -lsnes -lresc_stub -lm -lio_stub -lfs_stub -lsysutil_stub -lsysutil_game_stub -lsysutil_screenshot_stub -lsysmodule_stub -laudio_stub -lnet_stub -lpthread
DEFINES = -DSSNES_CONSOLE -DHAVE_OPENGL=1 -DHAVE_CG=1 -DHAVE_FBO=1 -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DPACKAGE_VERSION=\"0.9.4\" -Dmain=ssnes_main
ifeq ($(DEBUG), 1)
PPU_OPTIMIZE_LV := -O0 -g
else
PPU_OPTIMIZE_LV := -O3 -g
endif
## Use this for new SDK!
CFLAGS = $(PPU_OPTIMIZE_LV) $(DEFINES)
CXXFLAGS = $(PPU_OPTIMIZE_LV) $(DEFINES)
all: pkg
$(PPU_TARGET): $(OBJ)
$(LD) -o $@ $(OBJ) $(LDFLAGS) $(LDDIRS) $(LIBS)
$(STRIP) $(PPU_TARGET)
%.o: %.c config.h
$(CC) $(INCDIRS) $(CFLAGS) -c -o $@ $<
%.o: %.cpp config.h
$(CXX) $(INCDIRS) $(CXXFLAGS) -c -o $@ $<
pkg: $(PPU_TARGET)
cp ssnes.cfg ps3/pkg/USRDIR/
$(MAKE_FSELF_NPDRM) $(PPU_TARGET) ps3/pkg/USRDIR/EBOOT.BIN
$(MAKE_PACKAGE_NPDRM) ps3/pkg/package.conf ps3/pkg
clean:
rm -f $(PPU_TARGET)
rm -f $(OBJ)
rm -f *.pkg
.PHONY: all clean pkg
+58
View File
@@ -0,0 +1,58 @@
###
##
# Makefile for SSNES Wii.
## Doesn't really work yet, beware :V
###
##
DEBUG = 0
CC = powerpc-eabi-gcc
CXX = powerpc-eabi-g++
LD = powerpc-eabi-ld
DOL_TARGET := ssnes.dol
ELF_TARGET := ssnes.elf
INCLUDE := -I. -I$(DEVKITPRO)/libogc/include
LIBDIRS := -L$(DEVKITPRO)/libogc/lib/wii -L.
MACHDEP := -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float
CFLAGS += -Wall -std=gnu99 $(MACHDEP) $(INCLUDE)
CXXFLAGS += -Wall -std=gnu99 $(MACHDEP) $(INCLUDE)
LDFLAGS := $(MACHDEP)
LIBS := -lfat -lsnes -lwiiuse -logc -lbte -lfreetype
OBJ = wii/main.o fifo_buffer.o ssnes.o driver.o gfx/fonts.o file.o settings.o message.o rewind.o movie.o ups.o bps.o strl.o screenshot.o audio/hermite.o dynamic.o audio/utils.o conf/config_file.o wii/audio.o wii/input.o wii/video.o console/sgui.o console/list.o console/font.bmpobj
CFLAGS += -std=gnu99 -DSSNES_CONSOLE -DHAVE_CONFIGFILE=1 -DHAVE_GETOPT_LONG -DHAVE_FREETYPE -DPACKAGE_VERSION=\"0.9.4\" -Dmain=ssnes_main -Wno-char-subscripts
ifeq ($(DEBUG), 1)
CFLAGS += -O0 -g
CXXFLAGS += -O0 -g
else
CLFAGS += -O3
CXXFLAGS += -O3
endif
all: $(DOL_TARGET)
%.dol: %.elf
elf2dol $< $@
$(ELF_TARGET): $(OBJ)
$(CXX) -o $@ $(LDFLAGS) $(LIBDIRS) $(OBJ) $(LIBS)
%.o: %.c
$(CC) $(CFLAGS) -c -o $@ $<
%.bmpobj: %.bmp
$(LD) -r -b binary -o $@ $<
clean:
rm -f $(DOL_TARGET)
rm -f $(ELF_TARGET)
rm -f $(OBJ)
.PHONY: clean
+202
View File
@@ -0,0 +1,202 @@
TARGET = ssnes.exe
JTARGET = ssnes-joyconfig.exe
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o gfx/gfx_common.o bps.o ups.o strl.o screenshot.o audio/hermite.o getopt.o audio/utils.o posix_string.o
JOBJ = conf/config_file.o tools/ssnes-joyconfig.o strl.o posix_string.o
CC = gcc
CXX = g++
HAVE_DINPUT = 1
HAVE_XAUDIO = 1
HAVE_DSOUND = 1
HAVE_SDL = 1
HAVE_OPENGL = 1
HAVE_DYLIB = 1
HAVE_NETPLAY = 1
HAVE_THREADS = 1
DYNAMIC = 1
ifeq ($(SLIM),)
HAVE_SDL_IMAGE = 1
HAVE_XML = 1
HAVE_FREETYPE = 1
HAVE_RSOUND = 1
HAVE_FBO = 1
HAVE_CG = 1
HAVE_PYTHON = 1
HAVE_FFMPEG = 1
endif
libsnes ?= -lsnes
LIBS = -lm
DEFINES = -I. -DHAVE_CONFIGFILE -DPACKAGE_VERSION=\"0.9.4\"
LDFLAGS = -L. -static-libgcc
LDCXXFLAGS = -static-libstdc++ -s
ifeq ($(HAVE_SDL), 1)
OBJ += gfx/sdl_gfx.o gfx/gl.o gfx/sdlwrap.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o
LIBS += -lSDL
DEFINES += -ISDL -DHAVE_SDL
endif
ifeq ($(HAVE_THREADS), 1)
OBJ += autosave.o thread.o
DEFINES += -DHAVE_THREADS
endif
ifeq ($(HAVE_OPENGL), 1)
DEFINES += -DHAVE_OPENGL
LIBS += -lopengl32
endif
ifeq ($(HAVE_SDL_IMAGE), 1)
LIBS += -lSDL_image
DEFINES += -DHAVE_SDL_IMAGE
endif
ifeq ($(HAVE_CG), 1)
OBJ += gfx/shader_cg.o
LIBS += -lcg -lcgGL
DEFINES += -DHAVE_CG
endif
ifeq ($(HAVE_XAUDIO), 1)
OBJ += audio/xaudio.o audio/xaudio-c/xaudio-c.o
DEFINES += -DHAVE_XAUDIO
LIBS += -lole32
endif
ifeq ($(HAVE_DSOUND), 1)
OBJ += audio/dsound.o
DEFINES += -DHAVE_DSOUND
LIBS += -ldxguid -ldsound
endif
ifeq ($(HAVE_RSOUND), 1)
OBJ += audio/rsound.o
DEFINES += -DHAVE_RSOUND
LIBS += -lrsound
endif
ifeq ($(HAVE_XML), 1)
OBJ += gfx/shader_glsl.o gfx/image.o gfx/snes_state.o sha256.o cheats.o
DEFINES += -Ilibxml2 -DHAVE_XML
LIBS += -lxml2 -liconv
endif
ifeq ($(HAVE_DYLIB), 1)
DEFINES += -DHAVE_DYLIB
endif
ifeq ($(HAVE_NETPLAY), 1)
DEFINES += -DHAVE_NETPLAY
OBJ += netplay.o
LIBS += -lws2_32
endif
ifeq ($(HAVE_FREETYPE), 1)
OBJ += gfx/fonts.o
DEFINES += -DHAVE_FREETYPE -Ifreetype2
LIBS += -lfreetype -lz
endif
ifeq ($(DYNAMIC), 1)
DEFINES += -DHAVE_DYNAMIC
else
LIBS += $(libsnes)
endif
ifeq ($(HAVE_FBO), 1)
DEFINES += -DHAVE_FBO
endif
ifeq ($(HAVE_DYLIB), 1)
OBJ += gfx/ext_gfx.o audio/ext_audio.o
endif
ifeq ($(HAVE_PYTHON), 1)
LIBS += -lpython32
DEFINES += -DHAVE_PYTHON -Ipython
OBJ += gfx/py_state/py_state.o
endif
ifeq ($(HAVE_DINPUT), 1)
LIBS += -ldinput8 -ldxguid -lole32
DEFINES += -DHAVE_DINPUT
OBJ += input/dinput.o
endif
ifeq ($(HAVE_FFMPEG), 1)
LIBS += -lavformat -lavcodec -lavutil -lswscale -lws2_32 -lz
DEFINES += -DHAVE_FFMPEG -Iffmpeg
DEFINES += -DHAVE_FFMPEG_ALLOC_CONTEXT3
DEFINES += -DHAVE_FFMPEG_AVCODEC_OPEN2
DEFINES += -DHAVE_FFMPEG_AVIO_OPEN
DEFINES += -DHAVE_FFMPEG_AVFORMAT_WRITE_HEADER
DEFINES += -DHAVE_FFMPEG_AVFORMAT_NEW_STREAM
DEFINES += -DHAVE_X264RGB
OBJ += record/ffemu.o
endif
ifneq ($(V), 1)
Q := @
endif
CFLAGS += -Wall -O3 -I.
ifeq ($(CXX_BUILD), 1)
CFLAGS += -std=c++0x -xc++ -D__STDC_CONSTANT_MACROS
else
CFLAGS += -std=gnu99
endif
all: $(TARGET) $(JTARGET)
$(TARGET): $(OBJ)
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS) $(LDCXXFLAGS)
@$(if $(Q), $(shell echo echo LD $@),)
%.o: %.c
$(Q)$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
@$(if $(Q), $(shell echo echo CC $<),)
$(JTARGET): $(JOBJ)
ifeq ($(CXX_BUILD), 1)
$(Q)$(CXX) -o $@ $(JOBJ) -lSDL $(LDFLAGS)
else
$(Q)$(CC) -o $@ $(JOBJ) -lSDL $(LDFLAGS)
endif
@$(if $(Q), $(shell echo echo LD $@),)
clean:
rm -f *.o
rm -f audio/*.o
rm -f audio/xaudio-c/*.o
rm -f conf/*.o
rm -f gfx/*.o
rm -f gfx/py_state/*.o
rm -f record/*.o
rm -f input/*.o
rm -f $(TARGET)
rm -f ssnes-joyconfig.exe
rm -f tools/*.o
dist_x86: all
zip -r ssnes-win32-0.9.4.zip $(TARGET) $(JTARGET) ssnes.cfg snes.dll SDL.dll
dist_x86_64: all
zip -r ssnes-win64-0.9.4.zip $(TARGET) $(JTARGET) ssnes.cfg snes.dll SDL.dll
libs_x86:
wget https://github.com/downloads/Themaister/SSNES/SSNES-win32-libs.zip --no-check-certificate
unzip SSNES-win32-libs.zip
wget https://github.com/downloads/Themaister/SSNES/SSNES-win32-headers.zip --no-check-certificate
unzip SSNES-win32-headers.zip
libs_x86_64:
wget https://github.com/downloads/Themaister/SSNES/SSNES-win64-libs.zip --no-check-certificate
unzip SSNES-win64-libs.zip
wget https://github.com/downloads/Themaister/SSNES/SSNES-win64-headers.zip --no-check-certificate
unzip SSNES-win64-headers.zip
.PHONY: all install uninstall clean dist_x86 dist_x86_64 libs_x86 libs_x86_64
-125
View File
@@ -1,125 +0,0 @@
TARGET = ssnes.exe
JTARGET = ssnes-joyconfig.exe
OBJ = ssnes.o file.o driver.o conf/config_file.o settings.o dynamic.o message.o rewind.o movie.o autosave.o gfx/gfx_common.o ups.o
JOBJ = conf/config_file.o tools/main-stub.o tools/ssnes-joyconfig.o
CC = gcc
CXX = g++
HAVE_SRC = 0
HAVE_SDL = 1
HAVE_XML = 1
HAVE_FREETYPE = 1
HAVE_XAUDIO = 1
HAVE_RSOUND = 1
HAVE_FILTER = 1
HAVE_NETPLAY = 1
HAVE_FBO = 1
libsnes ?= -lsnes
LIBS = -lm
DEFINES = -I. -DHAVE_CONFIGFILE
LDFLAGS = -L. -static-libgcc -s
SRC_LIBS = -lsamplerate-0
SDL_LIBS = -lSDL
SDL_CFLAGS = -ISDL
ifeq ($(HAVE_SRC), 1)
LIBS += $(SRC_LIBS)
DEFINES += $(SRC_CFLAGS) -DHAVE_SRC
else
OBJ += audio/hermite.o
endif
ifeq ($(HAVE_SDL), 1)
OBJ += gfx/gl.o input/sdl.o audio/sdl.o audio/buffer.o
LIBS += $(SDL_LIBS) -lopengl32
DEFINES += $(SDL_CFLAGS) -DHAVE_SDL
endif
ifeq ($(HAVE_XAUDIO), 1)
OBJ += audio/xaudio.o
DEFINES += -DHAVE_XAUDIO
endif
ifeq ($(HAVE_RSOUND), 1)
OBJ += audio/rsound.o
DEFINES += -DHAVE_RSOUND
LIBS += -lrsound
endif
ifeq ($(HAVE_XML), 1)
OBJ += gfx/shader_glsl.o
DEFINES += $(XML_CFLAGS) -DHAVE_XML
LIBS += -lxml2
endif
ifeq ($(HAVE_FILTER), 1)
DEFINES += -DHAVE_FILTER
endif
ifeq ($(HAVE_NETPLAY), 1)
DEFINES += -DHAVE_NETPLAY
OBJ += netplay.o
LIBS += -lws2_32
endif
ifeq ($(HAVE_FREETYPE), 1)
OBJ += gfx/fonts.o
DEFINES += -DHAVE_FREETYPE -Ifreetype2
LIBS += -lz -lfreetype6
endif
ifeq ($(DYNAMIC), 1)
DEFINES += -DHAVE_DYNAMIC
else
LIBS += $(libsnes)
endif
ifeq ($(HAVE_FBO), 1)
DEFINES += -DHAVE_FBO
endif
ifneq ($(V),1)
Q := @
endif
CFLAGS = -Wall -O3 -std=gnu99 -I.
all: $(TARGET) $(JTARGET)
$(TARGET): $(OBJ)
$(Q)$(CXX) -o $@ $(OBJ) $(LIBS) $(LDFLAGS)
@$(if $(Q), $(shell echo echo LD $@),)
%.o: %.c
$(Q)$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
@$(if $(Q), $(shell echo echo CC $<),)
$(JTARGET): $(JOBJ)
$(Q)$(CC) -o $@ $(JOBJ) $(SDL_LIBS) $(LDFLAGS)
@$(if $(Q), $(shell echo echo LD $@),)
clean:
rm -f *.o
rm -f audio/*.o
rm -f conf/*.o
rm -f gfx/*.o
rm -f record/*.o
rm -f hqflt/*.o
rm -f input/*.o
rm -f hqflt/snes_ntsc/*.o
rm -f $(TARGET)
rm -f ssnes-joyconfig.exe
rm -f tools/*.o
dist: all
zip -r ssnes-win32-0.4-beta.zip $(TARGET) ssnes.cfg snes.dll libxml2.dll iconv.dll zlib1.dll SDL.dll freetype6.dll xaudio-c.dll rsound.dll pthreadGC2.dll README.win32.txt $(JTARGET)
libs:
wget https://github.com/downloads/Themaister/SSNES/SSNES-win32-libs.zip --no-check-certificate
unzip SSNES-win32-libs.zip
.PHONY: all install uninstall clean dist libs
+55
View File
@@ -0,0 +1,55 @@
###
##
# Makefile for SSNES libxenon.
##
###
##
DEBUG = 0
CC = xenon-gcc
CXX = xenon-g++
OBJCOPY = xenon-objcopy
STRIP = xenon-strip
PPU_TARGET := ssnes-libxenon.elf
PPU_TARGET_ADJUSTED := ssnes-libxenon.elf32
LDDIRS = -L. -L$(DEVKITXENON)/usr/lib -L$(DEVKITXENON)/xenon/lib/32
INCDIRS = -I. -I$(DEVKITXENON)/usr/include
OBJ = fifo_buffer.o ssnes.o driver.o file.o settings.o message.o rewind.o movie.o gfx/gfx_common.o ups.o bps.o strl.o screenshot.o audio/hermite.o dynamic.o audio/utils.o conf/config_file.o xenon/main.o xenon/xenon360_audio.o xenon/xenon360_input.o xenon/xenon360_video.o
LIBS = -lsnes -lxenon -lm -lc
DEFINES = -std=gnu99 -DHAVE_CONFIGFILE=1 -DPACKAGE_VERSION=\"0.9.4\" -DSSNES_CONSOLE -DHAVE_GETOPT_LONG=1 -Dmain=ssnes_main
DEFINES += -maltivec -mhard-float -m32 -mpowerpc64 -mcpu=cell -mtune=cell -fno-pic -g -Wall -DXENON $(INCDIRS)
DEFINES += -u read -u _start -u exc_base
ifeq ($(DEBUG), 1)
OPTIMIZE_LV := -O0 -g
else
OPTIMIZE_LV := -O3
endif
all: $(PPU_TARGET_ADJUSTED)
CFLAGS := $(OPTIMIZE_LV) $(DEFINES)
LDFLAGS := -m32 -n -T $(DEVKITXENON)/app.lds
$(PPU_TARGET_ADJUSTED): $(PPU_TARGET)
$(OBJCOPY) -O elf32-powerpc --adjust-vma 0x80000000 $< $@
$(STRIP) $@
$(PPU_TARGET): $(OBJ)
$(CXX) -o $@ $(OBJ) $(LDFLAGS) $(LDDIRS) $(LIBS)
%.o: %.c config.h
$(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f $(PPU_TARGET)
rm -f $(OBJ)
.PHONY: clean
+4
View File
@@ -7,6 +7,10 @@ SSNES is a simple frontend for the libsnes library.
libsnes is the emulator core of [bSNES](http://www.byuu.org), the most accurate SNES emulator to date, in library form. The libsnes API has been implemented by SNES9x as well, allowing multiple different cores to be used for an emulator that supports libsnes.
This enables the possibility of custom front-ends for the emulator.
# Binaries
Latest Windows binaries are currently hosted on my [homepage](http://themaister.net/ssnes.html).
# Philosophy
SSNES attempts to be very small and lean, while still having all the useful core features expected from an emulator.
-39
View File
@@ -1,39 +0,0 @@
===================================================
SSNES - Simple Super Nintendo Emulator System
===================================================
SSNES is a simplistic emulator frontend designed for use without any GUI.
It is used from command line, but is designed to play well with eventual GUI frontends,
as the configuration file format is very simple.
This allows for great portability and focus on what matters in a frontend, such as video and audio performance.
Its core libraries for video and input are OpenGL and SDL, with many different audio library supported.
On first use you should get accustomed to how SSNES works.
- SSNES emphasizes simplicity. It has no graphical user interface, and is primarily used through the command line.
It is recommended for experienced users.
It is possible though to create a GUI which can use SSNES.
- SSNES isn't dependant on any emulator core, such as bSNES, SNES9x or ZSNES.
SSNES only talks to the libsnes interface,
which was created initially by bSNES but it has an implementation available for SNES9x as well.
- SSNES is configured through a config file. In the Win32 distribution, there should be a ssnes.cfg included.
This config file serves as a base for your custom configuration file.
It is recommended that you go through the config file and alter any configurations you might use.
This is a good way to learn about the features SSNES have.
It is possible to pick which configuration file you want with the '-c' flag.
E.g.: ssnes.exe -c myconfig.cfg rom.sfc.
- When unsure which command line flags to use, use the command: ssnes.exe --help.
- When something is not working as expected, try using verbose logging first to see what is happening:
E.g.: ssnes.exe -v romfile.sfc
If something is not working, and you want to file a bug report,
please include console output with the -v flag turned on.
- SSNES does not support zipped roms directly. It only supports roms with extentions .sfc and .smc.
However, SSNES can read roms from stdin,
which makes it possible to create wrapper programs that can support every zip format under the sun.
This can also be performed by a GUI frontend.
+41 -45
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -16,12 +16,12 @@
*/
#include "driver.h"
#include "../driver.h"
#include <stdlib.h>
#include <alsa/asoundlib.h>
#include "general.h"
#include <asoundlib.h>
#include "../general.h"
#define TRY_ALSA(x) if ( x < 0 ) { \
#define TRY_ALSA(x) if (x < 0) { \
goto error; \
}
@@ -32,9 +32,9 @@ typedef struct alsa
bool has_float;
} alsa_t;
static bool __alsa_use_float(void *data)
static bool alsa_use_float(void *data)
{
alsa_t *alsa = data;
alsa_t *alsa = (alsa_t*)data;
return alsa->has_float;
}
@@ -49,27 +49,30 @@ static bool find_float_format(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
return false;
}
static void* __alsa_init(const char* device, int rate, int latency)
static void *alsa_init(const char *device, unsigned rate, unsigned latency)
{
alsa_t *alsa = calloc(1, sizeof(alsa_t));
if ( alsa == NULL )
alsa_t *alsa = (alsa_t*)calloc(1, sizeof(alsa_t));
if (!alsa)
return NULL;
snd_pcm_hw_params_t *params = NULL;
snd_pcm_sw_params_t *sw_params = NULL;
const char *alsa_dev = "default";
if ( device != NULL )
if (device)
alsa_dev = device;
unsigned int latency_usec = latency * 1000;
unsigned int channels = 2;
unsigned periods = 4;
snd_pcm_uframes_t buffer_size;
snd_pcm_format_t format;
TRY_ALSA(snd_pcm_open(&alsa->pcm, alsa_dev, SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK));
unsigned int latency_usec = latency * 1000;
TRY_ALSA(snd_pcm_hw_params_malloc(&params));
alsa->has_float = find_float_format(alsa->pcm, params);
snd_pcm_format_t format = alsa->has_float ? SND_PCM_FORMAT_FLOAT : SND_PCM_FORMAT_S16;
unsigned int channels = 2;
format = alsa->has_float ? SND_PCM_FORMAT_FLOAT : SND_PCM_FORMAT_S16;
TRY_ALSA(snd_pcm_hw_params_any(alsa->pcm, params));
TRY_ALSA(snd_pcm_hw_params_set_access(alsa->pcm, params, SND_PCM_ACCESS_RW_INTERLEAVED));
@@ -78,12 +81,10 @@ static void* __alsa_init(const char* device, int rate, int latency)
TRY_ALSA(snd_pcm_hw_params_set_rate(alsa->pcm, params, rate, 0));
TRY_ALSA(snd_pcm_hw_params_set_buffer_time_near(alsa->pcm, params, &latency_usec, NULL));
unsigned periods = 4;
TRY_ALSA(snd_pcm_hw_params_set_periods_near(alsa->pcm, params, &periods, NULL));
TRY_ALSA(snd_pcm_hw_params(alsa->pcm, params));
snd_pcm_uframes_t buffer_size;
snd_pcm_hw_params_get_period_size(params, &buffer_size, NULL);
SSNES_LOG("ALSA: Period size: %d frames\n", (int)buffer_size);
snd_pcm_hw_params_get_buffer_size(params, &buffer_size);
@@ -117,16 +118,16 @@ error:
return NULL;
}
static ssize_t __alsa_write(void* data, const void* buf, size_t size)
static ssize_t alsa_write(void *data, const void *buf, size_t size)
{
alsa_t *alsa = data;
alsa_t *alsa = (alsa_t*)data;
snd_pcm_sframes_t frames;
snd_pcm_sframes_t written = 0;
int rc;
size = snd_pcm_bytes_to_frames(alsa->pcm, size); // Frames to write
while (written < size)
while (written < (snd_pcm_sframes_t)size)
{
if (!alsa->nonblock)
{
@@ -141,16 +142,16 @@ static ssize_t __alsa_write(void* data, const void* buf, size_t size)
frames = snd_pcm_writei(alsa->pcm, (const char*)buf + written * 2 * (alsa->has_float ? sizeof(float) : sizeof(int16_t)), size - written);
if ( frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE )
if (frames == -EPIPE || frames == -EINTR || frames == -ESTRPIPE)
{
if ( snd_pcm_recover(alsa->pcm, frames, 1) < 0 )
if (snd_pcm_recover(alsa->pcm, frames, 1) < 0)
return -1;
return 0;
}
else if ( frames == -EAGAIN && alsa->nonblock )
else if (frames == -EAGAIN && alsa->nonblock)
return 0;
else if ( frames < 0 )
else if (frames < 0)
return -1;
written += frames;
@@ -159,28 +160,28 @@ static ssize_t __alsa_write(void* data, const void* buf, size_t size)
return snd_pcm_frames_to_bytes(alsa->pcm, size);
}
static bool __alsa_stop(void *data)
static bool alsa_stop(void *data)
{
return true;
}
static void __alsa_set_nonblock_state(void *data, bool state)
static void alsa_set_nonblock_state(void *data, bool state)
{
alsa_t *alsa = data;
alsa_t *alsa = (alsa_t*)data;
alsa->nonblock = state;
}
static bool __alsa_start(void *data)
static bool alsa_start(void *data)
{
return true;
}
static void __alsa_free(void *data)
static void alsa_free(void *data)
{
alsa_t *alsa = data;
if ( alsa )
alsa_t *alsa = (alsa_t*)data;
if (alsa)
{
if ( alsa->pcm )
if (alsa->pcm)
{
snd_pcm_drop(alsa->pcm);
snd_pcm_close(alsa->pcm);
@@ -190,18 +191,13 @@ static void __alsa_free(void *data)
}
const audio_driver_t audio_alsa = {
.init = __alsa_init,
.write = __alsa_write,
.stop = __alsa_stop,
.start = __alsa_start,
.use_float = __alsa_use_float,
.set_nonblock_state = __alsa_set_nonblock_state,
.free = __alsa_free,
.ident = "alsa"
alsa_init,
alsa_write,
alsa_stop,
alsa_start,
alsa_set_nonblock_state,
alsa_free,
alsa_use_float,
"alsa"
};
+283
View File
@@ -0,0 +1,283 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
* Copyright (C) 2011-2012 - Chris Moeller
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "driver.h"
#include "general.h"
#include "fifo_buffer.h"
#include <stdlib.h>
#include "../boolean.h"
#include <pthread.h>
#include <CoreAudio/CoreAudio.h>
#include <CoreServices/CoreServices.h>
#include <AudioUnit/AudioUnit.h>
#include <AudioUnit/AUComponent.h>
typedef struct coreaudio
{
pthread_mutex_t lock;
pthread_cond_t cond;
ComponentInstance dev;
bool dev_alive;
fifo_buffer_t *buffer;
bool nonblock;
} coreaudio_t;
static void coreaudio_free(void *data)
{
coreaudio_t *dev = (coreaudio_t*)data;
if (!dev)
return;
if (dev->dev_alive)
{
AudioOutputUnitStop(dev->dev);
CloseComponent(dev->dev);
}
if (dev->buffer)
fifo_free(dev->buffer);
pthread_mutex_destroy(&dev->lock);
pthread_cond_destroy(&dev->cond);
free(dev);
}
static OSStatus audio_cb(void *userdata, AudioUnitRenderActionFlags *action_flags,
const AudioTimeStamp *time_stamp, UInt32 bus_number,
UInt32 number_frames, AudioBufferList *io_data)
{
coreaudio_t *dev = (coreaudio_t*)userdata;
(void)time_stamp;
(void)bus_number;
(void)number_frames;
if (!io_data)
return noErr;
if (io_data->mNumberBuffers != 1)
return noErr;
unsigned write_avail = io_data->mBuffers[0].mDataByteSize;
void *outbuf = io_data->mBuffers[0].mData;
pthread_mutex_lock(&dev->lock);
if (fifo_read_avail(dev->buffer) < write_avail)
{
*action_flags = kAudioUnitRenderAction_OutputIsSilence;
memset(outbuf, 0, write_avail); // Seems to be needed.
pthread_mutex_unlock(&dev->lock);
pthread_cond_signal(&dev->cond); // Technically possible to deadlock without.
return noErr;
}
fifo_read(dev->buffer, outbuf, write_avail);
pthread_mutex_unlock(&dev->lock);
pthread_cond_signal(&dev->cond);
return noErr;
}
static void *coreaudio_init(const char *device, unsigned rate, unsigned latency)
{
(void)device;
coreaudio_t *dev = (coreaudio_t*)calloc(1, sizeof(*dev));
if (!dev)
return NULL;
CFRunLoopRef run_loop = NULL;
AudioObjectPropertyAddress addr = {
kAudioHardwarePropertyRunLoop,
kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster
};
pthread_mutex_init(&dev->lock, NULL);
pthread_cond_init(&dev->cond, NULL);
AudioObjectSetPropertyData(kAudioObjectSystemObject, &addr, 0, NULL,
sizeof(CFRunLoopRef), &run_loop);
ComponentDescription desc = {0};
desc.componentType = kAudioUnitType_Output;
desc.componentSubType = kAudioUnitSubType_HALOutput;
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
AudioStreamBasicDescription stream_desc = {0};
AudioStreamBasicDescription real_desc;
AudioChannelLayout layout = {0};
AURenderCallbackStruct cb = {0};
Component comp = NULL;
OSStatus res = noErr;
UInt32 i_size = 0;
size_t fifo_size;
comp = FindNextComponent(NULL, &desc);
if (comp == NULL)
goto error;
res = OpenAComponent(comp, &dev->dev);
if (res != noErr)
goto error;
dev->dev_alive = true;
stream_desc.mSampleRate = rate;
stream_desc.mBitsPerChannel = sizeof(float) * CHAR_BIT;
stream_desc.mChannelsPerFrame = 2;
stream_desc.mBytesPerPacket = 2 * sizeof(float);
stream_desc.mBytesPerFrame = 2 * sizeof(float);
stream_desc.mFramesPerPacket = 1;
stream_desc.mFormatID = kAudioFormatLinearPCM;
stream_desc.mFormatFlags = kAudioFormatFlagIsFloat | kAudioFormatFlagIsPacked | (is_little_endian() ? 0 : kAudioFormatFlagIsBigEndian);
res = AudioUnitSetProperty(dev->dev, kAudioUnitProperty_StreamFormat,
kAudioUnitScope_Input, 0, &stream_desc, sizeof(stream_desc));
if (res != noErr)
goto error;
i_size = sizeof(real_desc);
res = AudioUnitGetProperty(dev->dev, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &real_desc, &i_size);
if (res != noErr)
goto error;
SSNES_LOG("[CoreAudio]: Using output sample rate of %.1f Hz\n", (float)real_desc.mSampleRate);
g_settings.audio.out_rate = real_desc.mSampleRate;
if (real_desc.mChannelsPerFrame != stream_desc.mChannelsPerFrame)
goto error;
if (real_desc.mBitsPerChannel != stream_desc.mBitsPerChannel)
goto error;
if (real_desc.mFormatFlags != stream_desc.mFormatFlags)
goto error;
if (real_desc.mFormatID != stream_desc.mFormatID)
goto error;
layout.mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelBitmap;
layout.mChannelBitmap = 0x03;
res = AudioUnitSetProperty(dev->dev, kAudioUnitProperty_AudioChannelLayout,
kAudioUnitScope_Input, 0, &layout, sizeof(layout));
if (res != noErr)
goto error;
cb.inputProc = audio_cb;
cb.inputProcRefCon = dev;
res = AudioUnitSetProperty(dev->dev, kAudioUnitProperty_SetRenderCallback,
kAudioUnitScope_Input, 0, &cb, sizeof(cb));
if (res != noErr)
goto error;
res = AudioUnitInitialize(dev->dev);
if (res != noErr)
goto error;
fifo_size = (latency * g_settings.audio.out_rate) / 1000;
fifo_size *= 2 * sizeof(float);
dev->buffer = fifo_new(fifo_size);
if (!dev->buffer)
goto error;
SSNES_LOG("[CoreAudio]: Using buffer size of %u bytes: (latency = %u ms)\n", (unsigned)fifo_size, latency);
res = AudioOutputUnitStart(dev->dev);
if (res != noErr)
goto error;
return dev;
error:
SSNES_ERR("[CoreAudio]: Failed to initialize driver ...\n");
coreaudio_free(dev);
return NULL;
}
static ssize_t coreaudio_write(void *data, const void *buf_, size_t size)
{
coreaudio_t *dev = (coreaudio_t*)data;
const uint8_t *buf = (const uint8_t*)buf_;
size_t written = 0;
while (size > 0)
{
pthread_mutex_lock(&dev->lock);
size_t write_avail = fifo_write_avail(dev->buffer);
if (write_avail > size)
write_avail = size;
fifo_write(dev->buffer, buf, write_avail);
buf += write_avail;
written += write_avail;
size -= write_avail;
if (dev->nonblock)
{
pthread_mutex_unlock(&dev->lock);
break;
}
if (write_avail == 0)
pthread_cond_wait(&dev->cond, &dev->lock);
pthread_mutex_unlock(&dev->lock);
}
return written;
}
static bool coreaudio_stop(void *data)
{
coreaudio_t *dev = (coreaudio_t*)data;
return AudioOutputUnitStop(dev->dev) == noErr;
}
static void coreaudio_set_nonblock_state(void *data, bool state)
{
coreaudio_t *dev = (coreaudio_t*)data;
dev->nonblock = state;
}
static bool coreaudio_start(void *data)
{
coreaudio_t *dev = (coreaudio_t*)data;
return AudioOutputUnitStart(dev->dev) == noErr;
}
static bool coreaudio_use_float(void *data)
{
(void)data;
return true;
}
const audio_driver_t audio_coreaudio = {
coreaudio_init,
coreaudio_write,
coreaudio_stop,
coreaudio_start,
coreaudio_set_nonblock_state,
coreaudio_free,
coreaudio_use_float,
"coreaudio"
};
+386
View File
@@ -0,0 +1,386 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "../driver.h"
#include <stdlib.h>
#include "../boolean.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <dsound.h>
#include "../fifo_buffer.h"
#include "../general.h"
typedef struct dsound
{
LPDIRECTSOUND ds;
LPDIRECTSOUNDBUFFER dsb;
HANDLE event;
bool nonblock;
fifo_buffer_t *buffer;
CRITICAL_SECTION crit;
volatile bool thread_alive;
HANDLE thread;
unsigned buffer_size;
} dsound_t;
static inline unsigned write_avail(unsigned read_ptr, unsigned write_ptr, unsigned buffer_size)
{
return (read_ptr + buffer_size - write_ptr) % buffer_size;
}
static inline void get_positions(dsound_t *ds, DWORD *read_ptr, DWORD *write_ptr)
{
IDirectSoundBuffer_GetCurrentPosition(ds->dsb, read_ptr, write_ptr);
}
#define CHUNK_SIZE 256
struct audio_lock
{
void *chunk1;
DWORD size1;
void *chunk2;
DWORD size2;
};
static inline bool grab_region(dsound_t *ds, DWORD write_ptr, struct audio_lock *region)
{
HRESULT res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, &region->chunk1, &region->size1, &region->chunk2, &region->size2, 0);
if (res == DSERR_BUFFERLOST)
{
res = IDirectSoundBuffer_Restore(ds->dsb);
if (res != DS_OK)
return false;
res = IDirectSoundBuffer_Lock(ds->dsb, write_ptr, CHUNK_SIZE, &region->chunk1, &region->size1, &region->chunk2, &region->size2, 0);
if (res != DS_OK)
return false;
}
const char *err;
switch (res)
{
case DSERR_BUFFERLOST:
err = "DSERR_BUFFERLOST";
break;
case DSERR_INVALIDCALL:
err = "DSERR_INVALIDCALL";
break;
case DSERR_INVALIDPARAM:
err = "DSERR_INVALIDPARAM";
break;
case DSERR_PRIOLEVELNEEDED:
err = "DSERR_PRIOLEVELNEEDED";
break;
default:
err = NULL;
}
if (err)
{
SSNES_WARN("[DirectSound error]: %s\n", err);
return false;
}
return true;
}
static inline void release_region(dsound_t *ds, const struct audio_lock *region)
{
IDirectSoundBuffer_Unlock(ds->dsb, region->chunk1, region->size1, region->chunk2, region->size2);
}
static DWORD CALLBACK dsound_thread(PVOID data)
{
dsound_t *ds = (dsound_t*)data;
SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
DWORD write_ptr;
get_positions(ds, NULL, &write_ptr);
write_ptr = (write_ptr + ds->buffer_size / 2) % ds->buffer_size;
while (ds->thread_alive)
{
DWORD read_ptr;
get_positions(ds, &read_ptr, NULL);
DWORD avail = write_avail(read_ptr, write_ptr, ds->buffer_size);
EnterCriticalSection(&ds->crit);
DWORD fifo_avail = fifo_read_avail(ds->buffer);
LeaveCriticalSection(&ds->crit);
// No space to write, or we don't have data in our fifo, but we can wait some time before it underruns ...
if (avail < CHUNK_SIZE || ((fifo_avail < CHUNK_SIZE) && (avail < ds->buffer_size / 2)))
{
Sleep(1);
// We could opt for using the notification interface,
// but it is not guaranteed to work, so use high priority sleeping patterns. :(
}
else if (fifo_avail < CHUNK_SIZE) // Got space to write, but nothing in FIFO (underrun), fill block with silence.
{
struct audio_lock region;
if (!grab_region(ds, write_ptr, &region))
{
ds->thread_alive = false;
SetEvent(ds->event);
break;
}
memset(region.chunk1, 0, region.size1);
memset(region.chunk2, 0, region.size2);
release_region(ds, &region);
write_ptr = (write_ptr + region.size1 + region.size2) % ds->buffer_size;
}
else // All is good. Pull from it and notify FIFO :D
{
struct audio_lock region;
if (!grab_region(ds, write_ptr, &region))
{
ds->thread_alive = false;
SetEvent(ds->event);
break;
}
EnterCriticalSection(&ds->crit);
if (region.chunk1)
fifo_read(ds->buffer, region.chunk1, region.size1);
if (region.chunk2)
fifo_read(ds->buffer, region.chunk2, region.size2);
LeaveCriticalSection(&ds->crit);
release_region(ds, &region);
write_ptr = (write_ptr + region.size1 + region.size2) % ds->buffer_size;
SetEvent(ds->event);
}
}
ExitThread(0);
}
static void dsound_stop_thread(dsound_t *ds)
{
if (ds->thread)
{
ds->thread_alive = false;
WaitForSingleObject(ds->thread, INFINITE);
CloseHandle(ds->thread);
ds->thread = NULL;
}
}
static bool dsound_start_thread(dsound_t *ds)
{
if (!ds->thread)
{
ds->thread_alive = true;
ds->thread = CreateThread(NULL, 0, dsound_thread, ds, 0, NULL);
if (ds->thread == NULL)
return false;
}
return true;
}
static void dsound_clear_buffer(dsound_t *ds)
{
IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0);
void *ptr;
DWORD size;
if (IDirectSoundBuffer_Lock(ds->dsb, 0, 0, &ptr, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER) == DS_OK)
{
memset(ptr, 0, size);
IDirectSoundBuffer_Unlock(ds->dsb, ptr, size, NULL, 0);
}
}
static void dsound_free(void *data)
{
dsound_t *ds = (dsound_t*)data;
if (ds)
{
if (ds->thread)
{
ds->thread_alive = false;
WaitForSingleObject(ds->thread, INFINITE);
CloseHandle(ds->thread);
}
DeleteCriticalSection(&ds->crit);
if (ds->dsb)
{
IDirectSoundBuffer_Stop(ds->dsb);
IDirectSoundBuffer_Release(ds->dsb);
}
if (ds)
IDirectSound_Release(ds->ds);
if (ds->event)
CloseHandle(ds->event);
if (ds->buffer)
fifo_free(ds->buffer);
free(ds);
}
}
static void *dsound_init(const char *device, unsigned rate, unsigned latency)
{
WAVEFORMATEX wfx = {0};
DSBUFFERDESC bufdesc = {0};
dsound_t *ds = (dsound_t*)calloc(1, sizeof(*ds));
if (!ds)
goto error;
InitializeCriticalSection(&ds->crit);
if (DirectSoundCreate(NULL, &ds->ds, NULL) != DS_OK)
goto error;
if (IDirectSound_SetCooperativeLevel(ds->ds, GetDesktopWindow(), DSSCL_PRIORITY) != DS_OK)
goto error;
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = 2;
wfx.nSamplesPerSec = rate;
wfx.wBitsPerSample = 16;
wfx.nBlockAlign = 2 * sizeof(int16_t);
wfx.nAvgBytesPerSec = rate * 2 * sizeof(int16_t);
ds->buffer_size = (latency * wfx.nAvgBytesPerSec) / 1000;
ds->buffer_size /= CHUNK_SIZE;
ds->buffer_size *= CHUNK_SIZE;
if (ds->buffer_size < 4 * CHUNK_SIZE)
ds->buffer_size = 4 * CHUNK_SIZE;
SSNES_LOG("[DirectSound]: Setting buffer size of %u bytes\n", ds->buffer_size);
SSNES_LOG("[DirectSound]: Latency = %u ms\n", (unsigned)((1000 * ds->buffer_size) / wfx.nAvgBytesPerSec));
bufdesc.dwSize = sizeof(DSBUFFERDESC);
bufdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2 | DSBCAPS_GLOBALFOCUS;
bufdesc.dwBufferBytes = ds->buffer_size;
bufdesc.lpwfxFormat = &wfx;
ds->event = CreateEvent(NULL, false, false, NULL);
if (!ds->event)
goto error;
ds->buffer = fifo_new(4 * 1024);
if (!ds->buffer)
goto error;
if (IDirectSound_CreateSoundBuffer(ds->ds, &bufdesc, &ds->dsb, 0) != DS_OK)
goto error;
IDirectSoundBuffer_SetCurrentPosition(ds->dsb, 0);
dsound_clear_buffer(ds);
if (IDirectSoundBuffer_Play(ds->dsb, 0, 0, DSBPLAY_LOOPING) != DS_OK)
goto error;
if (!dsound_start_thread(ds))
goto error;
return ds;
error:
SSNES_ERR("[DirectSound] Error occured in init!\n");
dsound_free(ds);
return NULL;
}
static bool dsound_stop(void *data)
{
dsound_t *ds = (dsound_t*)data;
dsound_stop_thread(ds);
return IDirectSoundBuffer_Stop(ds->dsb) == DS_OK;
}
static bool dsound_start(void *data)
{
dsound_t *ds = (dsound_t*)data;
dsound_clear_buffer(ds);
if (!dsound_start_thread(ds))
return false;
return IDirectSoundBuffer_Play(ds->dsb, 0, 0, DSBPLAY_LOOPING) == DS_OK;
}
static void dsound_set_nonblock_state(void *data, bool state)
{
dsound_t *ds = (dsound_t*)data;
ds->nonblock = state;
}
static ssize_t dsound_write(void *data, const void *buf_, size_t size)
{
dsound_t *ds = (dsound_t*)data;
const uint8_t *buf = (const uint8_t*)buf_;
if (!ds->thread_alive)
return -1;
size_t written = 0;
while (size > 0)
{
EnterCriticalSection(&ds->crit);
size_t avail = fifo_write_avail(ds->buffer);
if (avail > size)
avail = size;
fifo_write(ds->buffer, buf, avail);
LeaveCriticalSection(&ds->crit);
buf += avail;
size -= avail;
written += avail;
if (ds->nonblock || !ds->thread_alive)
break;
if (avail == 0)
WaitForSingleObject(ds->event, INFINITE);
}
return written;
}
const audio_driver_t audio_dsound = {
dsound_init,
dsound_write,
dsound_stop,
dsound_start,
dsound_set_nonblock_state,
dsound_free,
NULL,
"dsound"
};
+16
View File
@@ -0,0 +1,16 @@
TARGET = ssnes_iir_filter.so
OBJ = ssnes_iir_filter.o
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) -o $@ -shared $(OBJ) -lm
%.o: %.c
$(CC) -c -o $@ $< -g -std=c99 -fPIC -O3 -march=native $(CFLAGS)
clean:
rm -f $(TARGET)
rm -f $(OBJ)
.PHONY: clean
+16
View File
@@ -0,0 +1,16 @@
TARGET = iir_filter
OBJ = ssnes_iir_filter.o
all: $(TARGET)
$(TARGET): $(OBJ)
$(CC) -o $@ $(OBJ) -lm
%.o: %.c
$(CC) -c -o $@ $< -g -std=c99 -O3 -march=native $(CFLAGS) -DTEST -DLOG
clean:
rm -f $(TARGET)
rm -f $(OBJ)
.PHONY: clean
+128
View File
@@ -0,0 +1,128 @@
/////
// API header for external SSNES audio driver plugins.
//
//
#ifndef __SSNES_AUDIO_DRIVER_PLUGIN_H
#define __SSNES_AUDIO_DRIVER_PLUGIN_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#ifdef SSNES_DLL_IMPORT
#define SSNES_API_EXPORT __declspec(dllimport)
#else
#define SSNES_API_EXPORT __declspec(dllexport)
#endif
#define SSNES_API_CALLTYPE __cdecl
#else
#define SSNES_API_EXPORT
#define SSNES_API_CALLTYPE
#endif
#ifndef SSNES_TRUE
#define SSNES_TRUE 1
#endif
#ifndef SSNES_FALSE
#define SSNES_FALSE 0
#endif
#ifndef SSNES_OK
#define SSNES_OK 1
#endif
#ifndef SSNES_ERROR
#define SSNES_ERROR 0
#endif
#define SSNES_AUDIO_API_VERSION 2
typedef struct ssnes_audio_driver_info
{
// A hint for a subdevice of the audio driver.
// This is driver independent, and not relevant for all
// audio drivers. I.e. ALSA driver might use "hw:0",
// OSS "/dev/audio", etc.
const char *device;
// Audio sample rate.
unsigned sample_rate;
// Maximum audio latency requested for output,
// measured in milliseconds.
// If driver is not able to provide this latency, it can
// be disregarded.
unsigned latency;
} ssnes_audio_driver_info_t;
typedef struct ssnes_audio_driver
{
// Initializes the device.
void *(*init)(const ssnes_audio_driver_info_t *info);
// Write data in buffer to audio driver.
// A frame here is defined as one combined sample of left and right
// channels. (I.e. 44.1kHz, 16-bit stereo has 88.2k samples/s, and
// 44.1k frames/s.)
//
// Samples are interleaved in format LRLRLRLRLR ...
// If the driver returns true in use_float(), a floating point
// format will be used, with range [-1.0, 1.0].
// If not, signed 16-bit samples in native byte ordering will be used.
//
// This function returns the number of frames successfully written.
// If an error occurs, -1 should be returned.
// Note that non-blocking behavior that cannot write at this time
// should return 0 as returning -1 will terminate the driver.
//
// Unless said otherwise with set_nonblock_state(), all writes
// are blocking, and it should block till it has written all frames.
int (*write)(void *data, const void *buffer, unsigned frames);
// Temporarily pauses the audio driver.
int (*stop)(void *data);
// Resumes audio driver from the paused state.
int (*start)(void *data);
// If state is true, nonblocking operation is assumed.
// This is typically used for fast-forwarding. If driver cannot
// implement nonblocking writes, this can be disregarded, but should
// log a message to stderr.
void (*set_nonblock_state)(void *data, int state);
// Stops and frees the audio driver.
void (*free)(void *data);
// If true is returned, the audio driver is capable of using
// floating point data. This will likely increase performance as the
// resampler unit uses floating point. The sample range is
// [-1.0, 1.0].
int (*use_float)(void *data);
// The driver might be forced to use a certain output frequency
// (i.e. Jack), and thus to avoid double resampling, the driver
// can request SSNES to resample to a different sample rate.
// This function can be set to NULL if the driver does not
// desire to override the sample rate.
unsigned (*sample_rate)(void *data);
// Human readable identification string for the driver.
const char *ident;
// Must be set to SSNES_AUDIO_API_VERSION.
// Used for detecting API mismatch.
int api_version;
} ssnes_audio_driver_t;
SSNES_API_EXPORT const ssnes_audio_driver_t* SSNES_API_CALLTYPE
ssnes_audio_driver_init(void);
#ifdef __cplusplus
}
#endif
#endif
+129
View File
@@ -0,0 +1,129 @@
/////
// API header for external SSNES DSP plugins.
//
//
#ifndef __SSNES_DSP_PLUGIN_H
#define __SSNES_DSP_PLUGIN_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#ifdef SSNES_DLL_IMPORT
#define SSNES_API_EXPORT __declspec(dllimport)
#else
#define SSNES_API_EXPORT __declspec(dllexport)
#endif
#define SSNES_API_CALLTYPE __cdecl
#else
#define SSNES_API_EXPORT
#define SSNES_API_CALLTYPE
#endif
#ifndef SSNES_FALSE
#define SSNES_FALSE 0
#endif
#ifndef SSNES_TRUE
#define SSNES_TRUE 1
#endif
#define SSNES_DSP_API_VERSION 3
typedef struct ssnes_dsp_info
{
// Input sample rate that the DSP plugin receives. This is generally ~32kHz.
// Some small variance is allowed due to syncing behavior.
float input_rate;
// SSNES requests that the DSP plugin resamples the
// input to a certain frequency.
//
// However, the plugin might ignore this
// using the resample field in ssnes_dsp_output_t (see below).
float output_rate;
} ssnes_dsp_info_t;
typedef struct ssnes_dsp_output
{
// The DSP plugin has to provide the buffering for the output samples.
// This is for performance reasons to avoid redundant copying of data.
// The samples are laid out in interleaving order: LRLRLRLR
// The range of the samples are [-1.0, 1.0].
// This range cannot be exceeded without horrible audio glitches.
const float *samples;
// Frames which the DSP plugin outputted for the current process.
// One frame is here defined as a combined sample of
// left and right channels.
// (I.e. 44.1kHz, 16bit stereo will have
// 88.2k samples/sec and 44.1k frames/sec.)
unsigned frames;
// If true, the DSP plugin did not resample the input audio,
// and requests resampling to the proper frequency to be
// performed outside the plugin.
// If false,
// it is assumed that the output has the same sample rate as given
// in output_rate.
int should_resample;
} ssnes_dsp_output_t;
typedef struct ssnes_dsp_input
{
// Input data for the DSP. The samples are interleaved in order: LRLRLRLR
const float *samples;
// Number of frames for input data.
// One frame is here defined as a combined sample of
// left and right channels.
// (I.e. 44.1kHz, 16bit stereo will have
// 88.2k samples/sec and 44.1k frames/sec.)
unsigned frames;
} ssnes_dsp_input_t;
typedef struct ssnes_dsp_plugin
{
// Creates a handle of the plugin. Returns NULL if failed.
void *(*init)(const ssnes_dsp_info_t *info);
// Processes input data.
// The plugin is allowed to return variable sizes for output data.
void (*process)(void *data, ssnes_dsp_output_t *output,
const ssnes_dsp_input_t *input);
// Frees the handle.
void (*free)(void *data);
// API version used to compile the plugin.
// Used to detect mismatches in API.
// Must be set to SSNES_DSP_API_VERSION on compile.
int api_version;
// Signal plugin that it may open a configuring window or
// something similiar. The behavior of this function
// is thus plugin dependent. Implementing this is optional,
// and can be set to NULL.
void (*config)(void *data);
// Human readable identification string.
const char *ident;
// Called every frame, allows creating a GUI main loop in the main thread.
// GUI events can be processed here in a non-blocking fashion.
// Can be set to NULL to ignore it.
void (*events)(void *data);
} ssnes_dsp_plugin_t;
// Called by SSNES at startup to get the callback struct.
// This is NOT dynamically allocated!
SSNES_API_EXPORT const ssnes_dsp_plugin_t* SSNES_API_CALLTYPE
ssnes_dsp_plugin_init(void);
#ifdef __cplusplus
}
#endif
#endif
+418
View File
@@ -0,0 +1,418 @@
#include "ssnes_dsp.h"
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <stdio.h>
#include <math.h>
#include <complex.h>
// Simple IIR/EQ filter implementation, optimized for SSE3.
#ifdef __SSE3__ // Build with -march=native or -msse3 to let this be detected! D:
#define USE_SSE3
#endif
#ifdef USE_SSE3
#include <pmmintrin.h>
#endif
// Make a test build with standalone main()
//#define TEST
#ifdef TEST
#include <stdio.h>
#include <assert.h>
#endif
// Log filter coeffs for debugging
//#define LOG
#define min(x, y) ((x) < (y) ? (x) : (y))
#ifndef M_PI
#define M_PI 3.14159265
#endif
// Taps needs to be power-of-two.
#define TAPS (2048)
static const float lp_freq = 5000.0;
static const float hp_freq = 500.0;
static const float bp_freq = 300.0;
static const unsigned bp_q = 500;
#ifdef USE_SSE3
typedef union
{
__m128 vec[TAPS / 4 + 1]; // Wraparound for unaligned reads.
float f[TAPS + 4];
} vec_filt;
#else
typedef float vec_filt[TAPS + 4];
#endif
typedef struct
{
vec_filt buffer[2];
vec_filt iir_buffer[2];
vec_filt fir_coeff;
vec_filt iir_coeff;
float out_buffer[4096];
unsigned buf_ptr;
} dsp_state;
// Convolve polynoms.
static void conv(float * restrict a, const float * restrict b, unsigned a_size, unsigned b_size)
{
float output[a_size + b_size - 1];
// Lead-in
for (int i = 0; i < b_size - 1; i++)
{
output[i] = 0.0;
for (int j = 0; j < b_size; j++)
{
if ((i - j) >= 0)
output[i] += a[i - j] * b[j];
}
}
// Mid-section
for (unsigned i = b_size - 1; i < a_size; i++)
{
output[i] = 0.0;
for (unsigned j = 0; j < b_size; j++)
output[i] += a[i - j] * b[j];
}
// Lead-out
for (unsigned i = a_size; i < a_size + b_size - 1; i++)
{
output[i] = 0.0;
for (unsigned j = 0; j < b_size; j++)
{
if ((i - j) < a_size)
output[i] += a[i - j] * b[j];
}
}
memcpy(a, output, sizeof(output));
}
#ifdef LOG
static void print_coeff(const char *key, const float *coeff, unsigned elem)
{
for (unsigned i = 0; i < elem; i++)
fprintf(stderr, "%4s [%3u] = %9.5f\n", key, i, coeff[i]);
}
static void print_filter_coeffs(const float *fir, const float *iir, unsigned elem)
{
print_coeff("FIR", fir, elem);
print_coeff("IIR", iir, elem);
}
#endif
// Simulate plain 1-pole RC circuit.
// dVc/dt = (Vin - Vc) / RC =>
// y[n] = y[n - 1] * (1 - Ts/RC) + x[n] * Ts/RC
// RCw = 1 => RC = 1/(2*pi*fc)
static void generate_low_pass(float fir_out[1], float iir_out[2], float freq, float input_rate)
{
float ts = 1.0 / input_rate;
float t = 1.0 / (2 * M_PI * freq);
fir_out[0] = ts / t;
iir_out[0] = 1.0;
iir_out[1] = -(1.0 - ts / t);
#ifdef LOG
print_coeff("FLOW", fir_out, 1);
print_coeff("ILOW", iir_out, 2);
#endif
}
// 1-pole RC circuit (Vo taken over R).
static void generate_high_pass(float fir_out[2], float iir_out[2], float freq, float input_rate)
{
float ts = 1.0 / input_rate;
float t = 1.0 / (2 * M_PI * freq);
fir_out[0] = 1.0;
fir_out[1] = -1.0;
iir_out[0] = 1.0;
iir_out[1] = -(1.0 - ts / t);
#ifdef LOG
print_coeff("FHI", fir_out, 2);
print_coeff("IHI", iir_out, 2);
#endif
}
static void generate_band_pass(float *fir_out, unsigned num_fir, float freq, float input_rate)
{
float w_norm = 2.0 * M_PI * freq / input_rate;
for (unsigned i = 0; i < num_fir; i++)
fir_out[i] = cosf(i * w_norm);
complex float amp = 0.0;
for (unsigned i = 0; i < num_fir; i++)
amp += cosf(i * w_norm) * cexp(-I * w_norm * i);
float abs = cabs(amp);
for (unsigned i = 0; i < num_fir; i++)
fir_out[i] /= abs;
}
// Generic low-pass. Differential equation.
static void generate_filter_coeffs(float * restrict fir_out, float * restrict iir_out, float input_rate)
{
fir_out[0] = 1.0;
iir_out[0] = 1.0;
unsigned fir_length = 1;
unsigned iir_length = 1;
/*
// Low pass
float lp_fir[1];
float lp_iir[2];
generate_low_pass(lp_fir, lp_iir, lp_freq, input_rate);
conv(fir_out, lp_fir, fir_length, 1);
conv(iir_out, lp_iir, iir_length, 2);
fir_length += 0;
iir_length += 1;
// High pass
float hp_fir[2];
float hp_iir[2];
generate_high_pass(hp_fir, hp_iir, hp_freq, input_rate);
conv(fir_out, hp_fir, fir_length, 2);
conv(iir_out, hp_iir, iir_length, 2);
fir_length += 1;
iir_length += 1;
*/
// Band pass
float bp_fir[bp_q];
generate_band_pass(bp_fir, bp_q, bp_freq, input_rate);
conv(fir_out, bp_fir, fir_length, bp_q);
fir_length += bp_q - 1;
iir_length += 0;
// Adjust from Z rational polynomial model to discrete domain.
// We don't care about first param as it's implicitly 1.
for (unsigned i = 0; i < TAPS; i++)
iir_out[i] = -1.0 * iir_out[i + 1];
}
static void *dsp_init(const ssnes_dsp_info_t *info)
{
(void)info;
dsp_state *state = calloc(1, sizeof(*state));
if (!state)
return NULL;
fprintf(stderr, "Input rate = %.2f\n", (float)info->input_rate);
#ifdef USE_SSE3
generate_filter_coeffs(state->fir_coeff.f, state->iir_coeff.f, info->input_rate);
#ifdef LOG
print_filter_coeffs(state->fir_coeff.f, state->iir_coeff.f, 3);
#endif
#else
generate_filter_coeffs(state->fir_coeff, state->iir_coeff, info->input_rate);
#ifdef LOG
print_filter_coeffs(state->fir_coeff, state->iir_coeff, 3);
#endif
#endif
#ifdef USE_SSE3
memcpy(state->fir_coeff.f + TAPS, state->fir_coeff.f, 4 * sizeof(float));
memcpy(state->iir_coeff.f + TAPS, state->iir_coeff.f, 4 * sizeof(float));
#endif
return state;
}
#ifdef USE_SSE3
static void calculate_iir(float *out, dsp_state *dsp)
{
unsigned buf_ptr = (dsp->buf_ptr - 1) & (TAPS - 1);
unsigned iir_ptr = (TAPS - dsp->buf_ptr) & (TAPS - 1);
const float * restrict samples_left = dsp->buffer[0].f;
const float * restrict samples_right = dsp->buffer[1].f;
const float * restrict iir_left = dsp->iir_buffer[0].f;
const float * restrict iir_right = dsp->iir_buffer[1].f;
__m128 sum_left = _mm_setzero_ps();
__m128 sum_right = _mm_setzero_ps();
for (unsigned i = 0; i < TAPS; i += 4)
{
__m128 left = _mm_load_ps(samples_left + i);
__m128 right = _mm_load_ps(samples_right + i);
const __m128 ileft = _mm_load_ps(iir_left + i);
const __m128 iright = _mm_load_ps(iir_right + i);
// Need unaligned reads here.
const __m128 fir = _mm_loadu_ps(dsp->fir_coeff.f + iir_ptr);
const __m128 iir = _mm_loadu_ps(dsp->iir_coeff.f + iir_ptr);
const __m128 fir_res_left = _mm_mul_ps(fir, left);
const __m128 fir_res_right = _mm_mul_ps(fir, right);
const __m128 iir_res_left = _mm_mul_ps(iir, ileft);
const __m128 iir_res_right = _mm_mul_ps(iir, iright);
left = _mm_add_ps(fir_res_left, iir_res_left);
right = _mm_add_ps(fir_res_right, iir_res_right);
sum_left = _mm_add_ps(sum_left, left);
sum_right = _mm_add_ps(sum_right, right);
iir_ptr = (iir_ptr + 4) & (TAPS - 1);
}
__m128 res = _mm_hadd_ps(sum_left, sum_right);
res = _mm_hadd_ps(res, res);
union
{
__m128 vec;
float f[4];
} u;
u.vec = res;
out[0] = u.f[0];
out[1] = u.f[1];
dsp->iir_buffer[0].f[buf_ptr] = u.f[0];
dsp->iir_buffer[1].f[buf_ptr] = u.f[1];
}
#else
static void calculate_iir(float *out, dsp_state *dsp)
{
const float * restrict samples_left = dsp->buffer[0];
const float * restrict samples_right = dsp->buffer[1];
const float * restrict iir_left = dsp->iir_buffer[0];
const float * restrict iir_right = dsp->iir_buffer[1];
const float * restrict fir = dsp->fir_coeff;
const float * restrict iir = dsp->iir_coeff;
unsigned iir_ptr = 0;
unsigned sample_ptr = dsp->buf_ptr;
float sum[2] = { 0.0f, 0.0f };
for (unsigned i = 0; i < TAPS; i++)
{
sum[0] += fir[iir_ptr] * samples_left[sample_ptr] + iir[iir_ptr] * iir_left[sample_ptr];
sum[1] += fir[iir_ptr] * samples_right[sample_ptr] + iir[iir_ptr] * iir_right[sample_ptr];
iir_ptr++;
sample_ptr = (sample_ptr + 1) & (TAPS - 1);
}
// Stick our output value in the IIR buffer.
for (unsigned i = 0; i < 2; i++)
{
out[i] = sum[i];
dsp->iir_buffer[i][(dsp->buf_ptr - 1) & (TAPS - 1)] = sum[i];
}
}
#endif
static void dsp_process(void *data, ssnes_dsp_output_t *output, const ssnes_dsp_input_t *input)
{
dsp_state *dsp = data;
output->should_resample = SSNES_TRUE;
output->frames = input->frames;
output->samples = dsp->out_buffer;
for (unsigned i = 0; i < input->frames; i++)
{
#ifdef USE_SSE3
dsp->buffer[0].f[dsp->buf_ptr] = input->samples[(i << 1) + 0];
dsp->buffer[1].f[dsp->buf_ptr] = input->samples[(i << 1) + 1];
#else
dsp->buffer[0][dsp->buf_ptr] = input->samples[(i << 1) + 0];
dsp->buffer[1][dsp->buf_ptr] = input->samples[(i << 1) + 1];
#endif
calculate_iir(&dsp->out_buffer[i << 1], dsp);
dsp->buf_ptr = (dsp->buf_ptr - 1) & (TAPS - 1);
}
}
static void dsp_config(void *data)
{
(void)data;
// Normally we unhide a GUI window or something,
// but we're just going to print to the log instead.
fprintf(stderr, "DSP_CONFIG\n");
}
static void dsp_free(void *data)
{
free(data);
}
const ssnes_dsp_plugin_t dsp_plug = {
.init = dsp_init,
.process = dsp_process,
.free = dsp_free,
.config = dsp_config,
.api_version = SSNES_DSP_API_VERSION,
.ident = "IIR filter"
};
SSNES_API_EXPORT const ssnes_dsp_plugin_t*
SSNES_API_CALLTYPE ssnes_dsp_plugin_init(void)
{
return &dsp_plug;
}
#ifdef TEST
int main(void)
{
const ssnes_dsp_plugin_t *plug = ssnes_dsp_plugin_init();
assert(plug);
ssnes_dsp_info_t info = {
.input_rate = 44100,
.output_rate = 44100
};
void *handle = plug->init(&info); // Info isn't used.
assert(handle);
int16_t buf[64];
float fbuf[64];
for (;;)
{
size_t rd = fread(buf, sizeof(int16_t), 64, stdin);
for (unsigned i = 0; i < rd; i++)
fbuf[i] = (float)buf[i];
ssnes_dsp_input_t input = {
.samples = fbuf,
.frames = rd >> 1
};
ssnes_dsp_output_t output;
plug->process(handle, &output, &input);
for (unsigned i = 0; i < output.frames << 1; i++)
{
int32_t sample = (int32_t)output.samples[i];
buf[i] = (sample > 0x7fff) ? 0x7fff : ((sample < -0x8000) ? -0x8000 : (int16_t)sample);
}
fwrite(buf, sizeof(int16_t), output.frames << 1, stdout);
if (rd < 64)
break;
}
plug->free(handle);
}
#endif
+164
View File
@@ -0,0 +1,164 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "ext/ssnes_audio.h"
#include "../boolean.h"
#include <stdlib.h>
#include <stdint.h>
#include "../driver.h"
#include "../dynamic.h"
#include "../general.h"
#include <sys/types.h>
typedef struct audio_ext
{
dylib_t lib;
const ssnes_audio_driver_t *driver;
void *handle;
bool is_float;
} audio_ext_t;
static void audio_ext_free(void *data)
{
audio_ext_t *ext = (audio_ext_t*)data;
if (ext)
{
if (ext->driver && ext->handle)
ext->driver->free(ext->handle);
if (ext->lib)
dylib_close(ext->lib);
free(ext);
}
}
static void *audio_ext_init(const char *device, unsigned rate, unsigned latency)
{
if (!(*g_settings.audio.external_driver))
{
SSNES_ERR("Please define an external audio driver.\n");
return NULL;
}
audio_ext_t *ext = (audio_ext_t*)calloc(1, sizeof(*ext));
if (!ext)
return NULL;
ssnes_audio_driver_info_t info = {0};
const ssnes_audio_driver_t *(*plugin_load)(void) = NULL;
ext->lib = dylib_load(g_settings.audio.external_driver);
if (!ext->lib)
{
SSNES_ERR("Failed to load external library \"%s\"\n", g_settings.audio.external_driver);
goto error;
}
plugin_load = (const ssnes_audio_driver_t *(*)(void))dylib_proc(ext->lib, "ssnes_audio_driver_init");
if (!plugin_load)
{
SSNES_ERR("Failed to find symbol \"ssnes_audio_driver_init\" in plugin.\n");
goto error;
}
ext->driver = plugin_load();
if (!ext->driver)
{
SSNES_ERR("Received invalid driver from plugin.\n");
goto error;
}
SSNES_LOG("Loaded external audio driver: \"%s\"\n", ext->driver->ident ? ext->driver->ident : "Unknown");
if (ext->driver->api_version != SSNES_AUDIO_API_VERSION)
{
SSNES_ERR("API mismatch in external audio plugin. SSNES: %d, Plugin: %d ...\n", SSNES_AUDIO_API_VERSION, ext->driver->api_version);
goto error;
}
info.device = device;
info.sample_rate = rate;
info.latency = latency;
ext->handle = ext->driver->init(&info);
if (!ext->handle)
{
SSNES_ERR("Failed to init audio driver.\n");
goto error;
}
if (ext->driver->sample_rate)
g_settings.audio.out_rate = ext->driver->sample_rate(ext->handle);
if (!g_settings.audio.sync)
ext->driver->set_nonblock_state(ext->handle, SSNES_TRUE);
return ext;
error:
audio_ext_free(ext);
return NULL;
}
static ssize_t audio_ext_write(void *data, const void *buf, size_t size)
{
audio_ext_t *ext = (audio_ext_t*)data;
unsigned frame_size = ext->is_float ? (2 * sizeof(float)) : (2 * sizeof(int16_t));
size /= frame_size;
int ret = ext->driver->write(ext->handle, buf, size);
if (ret < 0)
return -1;
return ret * frame_size;
}
static bool audio_ext_start(void *data)
{
audio_ext_t *ext = (audio_ext_t*)data;
return ext->driver->start(ext->handle);
}
static bool audio_ext_stop(void *data)
{
audio_ext_t *ext = (audio_ext_t*)data;
return ext->driver->stop(ext->handle);
}
static void audio_ext_set_nonblock_state(void *data, bool toggle)
{
audio_ext_t *ext = (audio_ext_t*)data;
ext->driver->set_nonblock_state(ext->handle, toggle);
}
static bool audio_ext_use_float(void *data)
{
audio_ext_t *ext = (audio_ext_t*)data;
ext->is_float = ext->driver->use_float(ext->handle);
return ext->is_float;
}
const audio_driver_t audio_ext = {
audio_ext_init,
audio_ext_write,
audio_ext_stop,
audio_ext_start,
audio_ext_set_nonblock_state,
audio_ext_free,
audio_ext_use_float,
"ext"
};
+20 -35
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -20,13 +20,12 @@
#include "hermite.h"
#include <stdlib.h>
#define MAX_CHANS 8
#define CHANNELS 2
struct hermite_resampler
{
float chan_data[MAX_CHANS][4];
float chan_data[CHANNELS][4];
double r_frac;
unsigned chans;
};
static inline float hermite_kernel(float mu1, float a, float b, float c, float d)
@@ -36,8 +35,8 @@ static inline float hermite_kernel(float mu1, float a, float b, float c, float d
mu2 = mu1 * mu1;
mu3 = mu2 * mu1;
m0 = (c - a) * 0.5;
m1 = (d - b) * 0.5;
m0 = (c - a) * 0.5f;
m1 = (d - b) * 0.5f;
a0 = +2 * mu3 - 3 * mu2 + 1;
a1 = mu3 - 2 * mu2 + mu1;
@@ -47,60 +46,46 @@ static inline float hermite_kernel(float mu1, float a, float b, float c, float d
return (a0 * b) + (a1 * m0) + (a2 * m1) + (a3 * c);
}
hermite_resampler_t *hermite_new(unsigned channels)
hermite_resampler_t *hermite_new(void)
{
if (channels > MAX_CHANS)
return NULL;
hermite_resampler_t *re = calloc(1, sizeof(*re));
if (!re)
return NULL;
re->chans = channels;
return re;
return (hermite_resampler_t*)calloc(1, sizeof(hermite_resampler_t));
}
// We make sure to allocate enough output data beforehand ... ;)
void hermite_process(hermite_resampler_t *re, struct hermite_data *data)
{
double r_step = 1.0 / data->src_ratio;
double r_step = 1.0 / data->ratio;
size_t processed_out = 0;
size_t processed_in = 0;
size_t in_frames = data->input_frames;
size_t out_frames = data->output_frames;
const float *in_data = data->data_in;
float *out_data = data->data_out;
while (processed_in < in_frames && processed_out < out_frames)
for (size_t i = 0; i < in_frames; i++)
{
while (re->r_frac <= 1.0 && processed_out < out_frames)
while (re->r_frac <= 1.0)
{
re->r_frac += r_step;
for (unsigned i = 0; i < re->chans; i++)
for (unsigned i = 0; i < CHANNELS; i++)
{
float res = hermite_kernel(re->r_frac,
float res = hermite_kernel((float)re->r_frac,
re->chan_data[i][0], re->chan_data[i][1], re->chan_data[i][2], re->chan_data[i][3]);
*out_data++ = res;
}
processed_out++;
}
if (re->r_frac >= 1.0)
re->r_frac -= 1.0;
for (unsigned i = 0; i < CHANNELS; i++)
{
re->r_frac -= 1.0;
for (unsigned i = 0; i < re->chans; i++)
{
re->chan_data[i][0] = re->chan_data[i][1];
re->chan_data[i][1] = re->chan_data[i][2];
re->chan_data[i][2] = re->chan_data[i][3];
re->chan_data[i][3] = *in_data++;
}
processed_in++;
re->chan_data[i][0] = re->chan_data[i][1];
re->chan_data[i][1] = re->chan_data[i][2];
re->chan_data[i][2] = re->chan_data[i][3];
re->chan_data[i][3] = *in_data++;
}
}
data->input_frames_used = processed_in;
data->output_frames_gen = processed_out;
data->output_frames = processed_out;
}
void hermite_free(hermite_resampler_t *re)
+4 -8
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -22,11 +22,11 @@
#define __SSNES_HERMITE_H
#include <stddef.h>
#include <stdbool.h>
#include "../boolean.h"
typedef struct hermite_resampler hermite_resampler_t;
hermite_resampler_t *hermite_new(unsigned channels);
hermite_resampler_t *hermite_new(void);
struct hermite_data
{
@@ -36,11 +36,7 @@ struct hermite_data
size_t input_frames;
size_t output_frames;
size_t input_frames_used;
size_t output_frames_gen;
bool end_of_input; // Just used to clone the SRC API.
double src_ratio;
double ratio;
};
void hermite_process(hermite_resampler_t *re, struct hermite_data *data);
+59 -59
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -16,16 +16,16 @@
*/
#include "driver.h"
#include "../driver.h"
#include <stdlib.h>
#include "general.h"
#include "../general.h"
#include <jack/jack.h>
#include <jack/types.h>
#include <jack/ringbuffer.h>
#include <pthread.h>
#include <stdint.h>
#include <stdbool.h>
#include "../boolean.h"
#include <string.h>
#include <assert.h>
@@ -45,7 +45,7 @@ typedef struct jack
static int process_cb(jack_nframes_t nframes, void *data)
{
jack_t *jd = data;
jack_t *jd = (jack_t*)data;
if (nframes <= 0)
{
pthread_cond_signal(&jd->cond);
@@ -62,7 +62,7 @@ static int process_cb(jack_nframes_t nframes, void *data)
for (int i = 0; i < 2; i++)
{
jack_default_audio_sample_t *out = jack_port_get_buffer(jd->ports[i], nframes);
jack_default_audio_sample_t *out = (jack_default_audio_sample_t*)jack_port_get_buffer(jd->ports[i], nframes);
assert(out);
jack_ringbuffer_read(jd->buffer[i], (char*)out, min_avail * sizeof(jack_default_audio_sample_t));
@@ -77,7 +77,7 @@ static int process_cb(jack_nframes_t nframes, void *data)
static void shutdown_cb(void *data)
{
jack_t *jd = data;
jack_t *jd = (jack_t*)data;
jd->shutdown = true;
pthread_cond_signal(&jd->cond);
}
@@ -108,7 +108,7 @@ static size_t find_buffersize(jack_t *jd, int latency)
for (int i = 0; i < 2; i++)
{
jack_port_get_latency_range(jd->ports[i], JackPlaybackLatency, &range);
if (range.max > jack_latency)
if ((int)range.max > jack_latency)
jack_latency = range.max;
}
@@ -124,13 +124,19 @@ static size_t find_buffersize(jack_t *jd, int latency)
return buffer_frames * sizeof(jack_default_audio_sample_t);
}
static void* __jack_init(const char* device, int rate, int latency)
static void *ja_init(const char *device, unsigned rate, unsigned latency)
{
jack_t *jd = calloc(1, sizeof(jack_t));
if ( jd == NULL )
jack_t *jd = (jack_t*)calloc(1, sizeof(jack_t));
if (!jd)
return NULL;
pthread_cond_init(&jd->cond, NULL);
pthread_mutex_init(&jd->cond_lock, NULL);
const char **jports = NULL;
char *dest_ports[2];
size_t bufsize = 0;
int parsed = 0;
jd->client = jack_client_open("SSNES", JackNullOption, NULL);
if (jd->client == NULL)
@@ -148,9 +154,7 @@ static void* __jack_init(const char* device, int rate, int latency)
SSNES_ERR("Failed to register ports.\n");
goto error;
}
char *dest_ports[2];
jports = jack_get_ports(jd->client, NULL, NULL, JackPortIsPhysical | JackPortIsInput);
if (jports == NULL)
{
@@ -158,7 +162,19 @@ static void* __jack_init(const char* device, int rate, int latency)
goto error;
}
int parsed = parse_ports(dest_ports, jports);
bufsize = find_buffersize(jd, latency);
SSNES_LOG("JACK: Internal buffer size: %d frames.\n", (int)(bufsize / sizeof(jack_default_audio_sample_t)));
for (int i = 0; i < 2; i++)
{
jd->buffer[i] = jack_ringbuffer_create(bufsize);
if (jd->buffer[i] == NULL)
{
SSNES_ERR("Failed to create buffers.\n");
goto error;
}
}
parsed = parse_ports(dest_ports, jports);
if (jack_activate(jd->client) < 0)
{
@@ -177,23 +193,7 @@ static void* __jack_init(const char* device, int rate, int latency)
for (int i = 0; i < parsed; i++)
free(dest_ports[i]);
size_t bufsize = find_buffersize(jd, latency);
SSNES_LOG("JACK: Internal buffer size: %d frames.\n", (int)(bufsize / sizeof(jack_default_audio_sample_t)));
for (int i = 0; i < 2; i++)
{
jd->buffer[i] = jack_ringbuffer_create(bufsize);
if (jd->buffer[i] == NULL)
{
SSNES_ERR("Failed to create buffers.\n");
goto error;
}
}
pthread_cond_init(&jd->cond, NULL);
pthread_mutex_init(&jd->cond_lock, NULL);
jack_free(jports);
return jd;
@@ -205,7 +205,7 @@ error:
static size_t write_buffer(jack_t *jd, const float *buf, size_t size)
{
jack_default_audio_sample_t out_deinterleaved_buffer[2][FRAMES(size)];
jack_default_audio_sample_t out_deinterleaved_buffer[2][AUDIO_CHUNK_SIZE_NONBLOCKING];
for (int i = 0; i < 2; i++)
for (size_t j = 0; j < FRAMES(size); j++)
@@ -219,9 +219,11 @@ static size_t write_buffer(jack_t *jd, const float *buf, size_t size)
if (jd->shutdown)
return 0;
size_t avail[2];
avail[0] = jack_ringbuffer_write_space(jd->buffer[0]);
avail[1] = jack_ringbuffer_write_space(jd->buffer[1]);
size_t avail[2] = {
jack_ringbuffer_write_space(jd->buffer[0]),
jack_ringbuffer_write_space(jd->buffer[1]),
};
size_t min_avail = avail[0] < avail[1] ? avail[0] : avail[1];
min_avail /= sizeof(float);
@@ -230,7 +232,10 @@ static size_t write_buffer(jack_t *jd, const float *buf, size_t size)
if (write_frames > 0)
{
for (int i = 0; i < 2; i++)
jack_ringbuffer_write(jd->buffer[i], (const char*)&out_deinterleaved_buffer[i][written], write_frames * sizeof(jack_default_audio_sample_t));
{
jack_ringbuffer_write(jd->buffer[i], (const char*)&out_deinterleaved_buffer[i][written],
write_frames * sizeof(jack_default_audio_sample_t));
}
written += write_frames;
}
else
@@ -247,34 +252,34 @@ static size_t write_buffer(jack_t *jd, const float *buf, size_t size)
return written * sizeof(float) * 2;
}
static ssize_t __jack_write(void* data, const void* buf, size_t size)
static ssize_t ja_write(void *data, const void *buf, size_t size)
{
jack_t *jd = data;
jack_t *jd = (jack_t*)data;
return write_buffer(jd, buf, size);
return write_buffer(jd, (const float*)buf, size);
}
static bool __jack_stop(void *data)
static bool ja_stop(void *data)
{
(void)data;
return true;
}
static void __jack_set_nonblock_state(void *data, bool state)
static void ja_set_nonblock_state(void *data, bool state)
{
jack_t *jd = data;
jack_t *jd = (jack_t*)data;
jd->nonblock = state;
}
static bool __jack_start(void *data)
static bool ja_start(void *data)
{
(void)data;
return true;
}
static void __jack_free(void *data)
static void ja_free(void *data)
{
jack_t *jd = data;
jack_t *jd = (jack_t*)data;
jd->shutdown = true;
@@ -293,25 +298,20 @@ static void __jack_free(void *data)
free(jd);
}
static bool __jack_use_float(void *data)
static bool ja_use_float(void *data)
{
(void)data;
return true;
}
const audio_driver_t audio_jack = {
.init = __jack_init,
.write = __jack_write,
.stop = __jack_stop,
.start = __jack_start,
.set_nonblock_state = __jack_set_nonblock_state,
.free = __jack_free,
.use_float = __jack_use_float,
.ident = "jack"
ja_init,
ja_write,
ja_stop,
ja_start,
ja_set_nonblock_state,
ja_free,
ja_use_float,
"jack"
};
+30 -32
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -15,8 +15,7 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "driver.h"
#include "../driver.h"
#ifdef __APPLE__
#include <OpenAL/al.h>
@@ -56,11 +55,11 @@ typedef struct al
} al_t;
static void* __al_init(const char* device, int rate, int latency)
static void *al_init(const char *device, unsigned rate, unsigned latency)
{
(void)device;
al_t *al = calloc(1, sizeof(al_t));
if ( al == NULL )
al_t *al = (al_t*)calloc(1, sizeof(al_t));
if (!al)
return NULL;
al->handle = alcOpenDevice(NULL);
@@ -76,8 +75,8 @@ static void* __al_init(const char* device, int rate, int latency)
al->rate = rate;
al->num_buffers = (latency * rate * 2 * 2) / (1000 * BUFSIZE);
al->buffers = calloc(al->num_buffers, sizeof(ALuint));
al->res_buf = calloc(al->num_buffers, sizeof(ALuint));
al->buffers = (ALuint*)calloc(al->num_buffers, sizeof(ALuint));
al->res_buf = (ALuint*)calloc(al->num_buffers, sizeof(ALuint));
if (al->buffers == NULL || al->res_buf == NULL)
goto error;
@@ -127,13 +126,12 @@ static bool al_get_buffer(al_t *al, ALuint *buffer)
if (al->res_ptr == 0)
{
#ifndef _WIN32
struct timespec tv = {
.tv_sec = 0,
.tv_nsec = 1000000
};
struct timespec tv = {0};
tv.tv_sec = 0;
tv.tv_nsec = 1000000;
#endif
for(;;)
for (;;)
{
if (al_unqueue_buffers(al))
break;
@@ -153,17 +151,17 @@ static bool al_get_buffer(al_t *al, ALuint *buffer)
return true;
}
static size_t al_fill_internal_buf(al_t *al, const void* buf, size_t size)
static size_t al_fill_internal_buf(al_t *al, const void *buf, size_t size)
{
size_t read_size = (BUFSIZE - al->tmpbuf_ptr > size) ? size : (BUFSIZE - al->tmpbuf_ptr);
size_t read_size = (BUFSIZE - al->tmpbuf_ptr > (ssize_t)size) ? size : (BUFSIZE - al->tmpbuf_ptr);
memcpy(al->tmpbuf + al->tmpbuf_ptr, buf, read_size);
al->tmpbuf_ptr += read_size;
return read_size;
}
static ssize_t __al_write(void* data, const void* buf, size_t size)
static ssize_t al_write(void *data, const void *buf, size_t size)
{
al_t *al = data;
al_t *al = (al_t*)data;
size_t written = 0;
while (written < size)
@@ -196,32 +194,32 @@ static ssize_t __al_write(void* data, const void* buf, size_t size)
return size;
}
static bool __al_stop(void *data)
static bool al_stop(void *data)
{
(void)data;
return true;
}
static void __al_set_nonblock_state(void *data, bool state)
static void al_set_nonblock_state(void *data, bool state)
{
al_t *al = data;
al_t *al = (al_t*)data;
al->nonblock = state;
}
static bool __al_start(void *data)
static bool al_start(void *data)
{
(void)data;
return true;
}
static void __al_free(void *data)
static void al_free(void *data)
{
al_t *al= data;
al_t *al = (al_t*)data;
if (al)
{
alSourceStop(al->source);
alDeleteSources(1, &al->source);
if ( al->buffers )
if (al->buffers)
{
alDeleteBuffers(al->num_buffers, al->buffers);
free(al->buffers);
@@ -235,13 +233,13 @@ static void __al_free(void *data)
}
const audio_driver_t audio_openal = {
.init = __al_init,
.write = __al_write,
.stop = __al_stop,
.start = __al_start,
.set_nonblock_state = __al_set_nonblock_state,
.free = __al_free,
.ident = "openal"
al_init,
al_write,
al_stop,
al_start,
al_set_nonblock_state,
al_free,
NULL,
"openal"
};
+49 -36
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -15,28 +15,44 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "driver.h"
#include "general.h"
#include <stdlib.h>
#ifdef HAVE_OSS_BSD
#include <soundcard.h>
#else
#include <sys/soundcard.h>
#endif
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
static void* __oss_init(const char* device, int rate, int latency)
#ifdef HAVE_OSS_BSD
#define DEFAULT_OSS_DEV "/dev/audio"
#else
#define DEFAULT_OSS_DEV "/dev/dsp"
#endif
static void *oss_init(const char *device, unsigned rate, unsigned latency)
{
int *fd = calloc(1, sizeof(int));
if ( fd == NULL )
int *fd = (int*)calloc(1, sizeof(int));
if (fd == NULL)
return NULL;
const char *oss_device = "/dev/dsp";
const char *oss_device = DEFAULT_OSS_DEV;
if ( device != NULL )
if (device != NULL)
oss_device = device;
if ( (*fd = open(oss_device, O_WRONLY)) < 0 )
if ((*fd = open(oss_device, O_WRONLY)) < 0)
{
free(fd);
return NULL;
@@ -45,7 +61,7 @@ static void* __oss_init(const char* device, int rate, int latency)
int frags = (latency * rate * 4)/(1000 * (1 << 9));
int frag = (frags << 16) | 9;
if ( ioctl(*fd, SNDCTL_DSP_SETFRAGMENT, &frag) < 0 )
if (ioctl(*fd, SNDCTL_DSP_SETFRAGMENT, &frag) < 0)
{
close(*fd);
free(fd);
@@ -53,23 +69,24 @@ static void* __oss_init(const char* device, int rate, int latency)
}
int channels = 2;
int format = AFMT_S16_LE;
int format = is_little_endian() ?
AFMT_S16_LE : AFMT_S16_BE;
if ( ioctl(*fd, SNDCTL_DSP_CHANNELS, &channels) < 0 )
if (ioctl(*fd, SNDCTL_DSP_CHANNELS, &channels) < 0)
{
close(*fd);
free(fd);
return NULL;
}
if ( ioctl(*fd, SNDCTL_DSP_SETFMT, &format) < 0 )
if (ioctl(*fd, SNDCTL_DSP_SETFMT, &format) < 0)
{
close(*fd);
free(fd);
return NULL;
}
if ( ioctl(*fd, SNDCTL_DSP_SPEED, &rate) < 0 )
if (ioctl(*fd, SNDCTL_DSP_SPEED, &rate) < 0)
{
close(*fd);
free(fd);
@@ -79,17 +96,17 @@ static void* __oss_init(const char* device, int rate, int latency)
return fd;
}
static ssize_t __oss_write(void* data, const void* buf, size_t size)
static ssize_t oss_write(void *data, const void *buf, size_t size)
{
int *fd = data;
int *fd = (int*)data;
if ( size == 0 )
if (size == 0)
return 0;
ssize_t ret;
if ( (ret = write(*fd, buf, size)) <= 0 )
if ((ret = write(*fd, buf, size)) <= 0)
{
if ( (fcntl(*fd, F_GETFL) & O_NONBLOCK) && errno == EAGAIN )
if ((fcntl(*fd, F_GETFL) & O_NONBLOCK) && errno == EAGAIN)
return 0;
return -1;
}
@@ -97,21 +114,21 @@ static ssize_t __oss_write(void* data, const void* buf, size_t size)
return ret;
}
static bool __oss_stop(void *data)
static bool oss_stop(void *data)
{
int *fd = data;
int *fd = (int*)data;
ioctl(*fd, SNDCTL_DSP_RESET, 0);
return true;
}
static bool __oss_start(void *data)
static bool oss_start(void *data)
{
return true;
}
static void __oss_set_nonblock_state(void *data, bool state)
static void oss_set_nonblock_state(void *data, bool state)
{
int *fd = data;
int *fd = (int*)data;
int rc;
if (state)
rc = fcntl(*fd, F_SETFL, fcntl(*fd, F_GETFL) | O_NONBLOCK);
@@ -121,9 +138,9 @@ static void __oss_set_nonblock_state(void *data, bool state)
fprintf(stderr, "SSNES [ERROR]: Could not set nonblocking on OSS file descriptor. Will not be able to fast-forward.\n");
}
static void __oss_free(void *data)
static void oss_free(void *data)
{
int *fd = data;
int *fd = (int*)data;
ioctl(*fd, SNDCTL_DSP_RESET, 0);
close(*fd);
@@ -131,17 +148,13 @@ static void __oss_free(void *data)
}
const audio_driver_t audio_oss = {
.init = __oss_init,
.write = __oss_write,
.stop = __oss_stop,
.start = __oss_start,
.set_nonblock_state = __oss_set_nonblock_state,
.free = __oss_free,
.ident = "oss"
oss_init,
oss_write,
oss_stop,
oss_start,
oss_set_nonblock_state,
oss_free,
NULL,
"oss"
};
+38 -55
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -19,7 +19,7 @@
#include "driver.h"
#include "general.h"
#include <pulse/pulseaudio.h>
#include <stdbool.h>
#include "../boolean.h"
#include <string.h>
#include <stdio.h>
@@ -32,9 +32,9 @@ typedef struct
bool nonblock;
} pa_t;
static void __pulse_free(void *data)
static void pulse_free(void *data)
{
pa_t *pa = data;
pa_t *pa = (pa_t*)data;
if (pa)
{
if (pa->mainloop)
@@ -59,21 +59,9 @@ static void __pulse_free(void *data)
}
}
static inline uint8_t is_little_endian(void)
{
union
{
uint16_t x;
uint8_t y[2];
} u;
u.x = 1;
return u.y[0];
}
static void context_state_cb(pa_context *c, void *data)
{
pa_t *pa = data;
pa_t *pa = (pa_t*)data;
switch (pa_context_get_state(c))
{
case PA_CONTEXT_READY:
@@ -88,7 +76,7 @@ static void context_state_cb(pa_context *c, void *data)
static void stream_state_cb(pa_stream *s, void *data)
{
pa_t *pa = data;
pa_t *pa = (pa_t*)data;
switch (pa_stream_get_state(s)) {
case PA_STREAM_READY:
case PA_STREAM_FAILED:
@@ -104,20 +92,24 @@ static void stream_request_cb(pa_stream *s, size_t length, void *data)
{
(void)length;
(void)s;
pa_t *pa = data;
pa_t *pa = (pa_t*)data;
pa_threaded_mainloop_signal(pa->mainloop, 0);
}
static void stream_latency_update_cb(pa_stream *s, void *data)
{
(void)s;
pa_t *pa = data;
pa_t *pa = (pa_t*)data;
pa_threaded_mainloop_signal(pa->mainloop, 0);
}
static void* __pulse_init(const char* device, int rate, int latency)
static void *pulse_init(const char *device, unsigned rate, unsigned latency)
{
pa_t *pa = calloc(1, sizeof(*pa));
pa_sample_spec spec;
memset(&spec, 0, sizeof(spec));
pa_buffer_attr buffer_attr = {0};
pa_t *pa = (pa_t*)calloc(1, sizeof(*pa));
if (!pa)
goto error;
@@ -143,11 +135,9 @@ static void* __pulse_init(const char* device, int rate, int latency)
if (pa_context_get_state(pa->context) != PA_CONTEXT_READY)
goto unlock_error;
pa_sample_spec spec = {
.format = is_little_endian() ? PA_SAMPLE_FLOAT32LE : PA_SAMPLE_FLOAT32BE,
.channels = 2,
.rate = rate
};
spec.format = is_little_endian() ? PA_SAMPLE_FLOAT32LE : PA_SAMPLE_FLOAT32BE;
spec.channels = 2;
spec.rate = rate;
pa->stream = pa_stream_new(pa->context, "audio", &spec, NULL);
if (!pa->stream)
@@ -157,13 +147,11 @@ static void* __pulse_init(const char* device, int rate, int latency)
pa_stream_set_write_callback(pa->stream, stream_request_cb, pa);
pa_stream_set_latency_update_callback(pa->stream, stream_latency_update_cb, pa);
pa_buffer_attr buffer_attr = {
.maxlength = -1,
.tlength = pa_usec_to_bytes(latency * PA_USEC_PER_MSEC, &spec),
.prebuf = -1,
.minreq = -1,
.fragsize = -1
};
buffer_attr.maxlength = -1;
buffer_attr.tlength = pa_usec_to_bytes(latency * PA_USEC_PER_MSEC, &spec);
buffer_attr.prebuf = -1;
buffer_attr.minreq = -1;
buffer_attr.fragsize = -1;
if (pa_stream_connect_playback(pa->stream, NULL, &buffer_attr, PA_STREAM_ADJUST_LATENCY, NULL, NULL) < 0)
goto error;
@@ -180,13 +168,13 @@ static void* __pulse_init(const char* device, int rate, int latency)
unlock_error:
pa_threaded_mainloop_unlock(pa->mainloop);
error:
__pulse_free(pa);
pulse_free(pa);
return NULL;
}
static ssize_t __pulse_write(void* data, const void* buf, size_t size)
static ssize_t pulse_write(void *data, const void *buf, size_t size)
{
pa_t *pa = data;
pa_t *pa = (pa_t*)data;
pa_threaded_mainloop_lock(pa->mainloop);
unsigned length = pa_stream_writable_size(pa->stream);
@@ -210,43 +198,38 @@ static ssize_t __pulse_write(void* data, const void* buf, size_t size)
return write_size;
}
static bool __pulse_stop(void *data)
static bool pulse_stop(void *data)
{
(void)data;
return true;
}
static bool __pulse_start(void *data)
static bool pulse_start(void *data)
{
(void)data;
return true;
}
static void __pulse_set_nonblock_state(void *data, bool state)
static void pulse_set_nonblock_state(void *data, bool state)
{
pa_t *pa = data;
pa_t *pa = (pa_t*)data;
pa->nonblock = state;
}
static bool __pulse_use_float(void *data)
static bool pulse_use_float(void *data)
{
(void)data;
return true;
}
const audio_driver_t audio_pulse = {
.init = __pulse_init,
.write = __pulse_write,
.stop = __pulse_stop,
.start = __pulse_start,
.set_nonblock_state = __pulse_set_nonblock_state,
.use_float = __pulse_use_float,
.free = __pulse_free,
.ident = "pulse"
pulse_init,
pulse_write,
pulse_stop,
pulse_start,
pulse_set_nonblock_state,
pulse_free,
pulse_use_float,
"pulse"
};
+21 -24
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -21,7 +21,7 @@
#include <roaraudio.h>
#include <errno.h>
#include <stdio.h>
#include <stdbool.h>
#include "../boolean.h"
#include "general.h"
typedef struct
@@ -30,10 +30,11 @@ typedef struct
bool nonblocking;
} roar_t;
static void* __roar_init(const char* device, int rate, int latency)
static void *ra_init(const char *device, unsigned rate, unsigned latency)
{
(void)latency;
int err;
roar_t *roar = calloc(1, sizeof(roar_t));
roar_t *roar = (roar_t*)calloc(1, sizeof(roar_t));
if (roar == NULL)
return NULL;
@@ -51,9 +52,9 @@ static void* __roar_init(const char* device, int rate, int latency)
return roar;
}
static ssize_t __roar_write(void* data, const void* buf, size_t size)
static ssize_t ra_write(void *data, const void *buf, size_t size)
{
roar_t *roar = data;
roar_t *roar = (roar_t*)data;
ssize_t rc;
if (size == 0)
@@ -77,45 +78,41 @@ static ssize_t __roar_write(void* data, const void* buf, size_t size)
return size;
}
static bool __roar_stop(void *data)
static bool ra_stop(void *data)
{
(void)data;
return true;
}
static void __roar_set_nonblock_state(void *data, bool state)
static void ra_set_nonblock_state(void *data, bool state)
{
roar_t *roar = data;
roar_t *roar = (roar_t*)data;
if (roar_vs_blocking(roar->vss, (state) ? ROAR_VS_FALSE : ROAR_VS_TRUE, NULL) < 0)
fprintf(stderr, "SSNES [ERROR]: Can't set nonblocking. Will not be able to fast-forward.\n");
roar->nonblocking = state;
}
static bool __roar_start(void *data)
static bool ra_start(void *data)
{
(void)data;
return true;
}
static void __roar_free(void *data)
static void ra_free(void *data)
{
roar_t *roar = data;
roar_t *roar = (roar_t*)data;
roar_vs_close(roar->vss, ROAR_VS_TRUE, NULL);
free(data);
}
const audio_driver_t audio_roar = {
.init = __roar_init,
.write = __roar_write,
.stop = __roar_stop,
.start = __roar_start,
.set_nonblock_state = __roar_set_nonblock_state,
.free = __roar_free,
.ident = "roar"
ra_init,
ra_write,
ra_stop,
ra_start,
ra_set_nonblock_state,
ra_free,
NULL,
"roar"
};
+39 -38
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -19,8 +19,8 @@
#include "driver.h"
#include <stdlib.h>
#include <rsound.h>
#include "buffer.h"
#include <stdbool.h>
#include "fifo_buffer.h"
#include "../boolean.h"
#include "SDL.h"
typedef struct rsd
@@ -29,7 +29,7 @@ typedef struct rsd
bool nonblock;
volatile bool has_error;
rsound_fifo_buffer_t *buffer;
fifo_buffer_t *buffer;
SDL_mutex *cond_lock;
SDL_cond *cond;
@@ -37,11 +37,11 @@ typedef struct rsd
static ssize_t audio_cb(void *data, size_t bytes, void *userdata)
{
rsd_t *rsd = userdata;
rsd_t *rsd = (rsd_t*)userdata;
size_t avail = rsnd_fifo_read_avail(rsd->buffer);
size_t avail = fifo_read_avail(rsd->buffer);
size_t write_size = bytes > avail ? avail : bytes;
rsnd_fifo_read(rsd->buffer, data, write_size);
fifo_read(rsd->buffer, data, write_size);
SDL_CondSignal(rsd->cond);
return write_size;
@@ -49,20 +49,20 @@ static ssize_t audio_cb(void *data, size_t bytes, void *userdata)
static void err_cb(void *userdata)
{
rsd_t *rsd = userdata;
rsd_t *rsd = (rsd_t*)userdata;
rsd->has_error = true;
SDL_CondSignal(rsd->cond);
}
static void* __rsd_init(const char* device, int rate, int latency)
static void *rs_init(const char *device, unsigned rate, unsigned latency)
{
rsd_t *rsd = calloc(1, sizeof(rsd_t));
if ( rsd == NULL )
rsd_t *rsd = (rsd_t*)calloc(1, sizeof(rsd_t));
if (!rsd)
return NULL;
rsound_t *rd;
if ( rsd_init(&rd) < 0 )
if (rsd_init(&rd) < 0)
{
free(rsd);
return NULL;
@@ -71,7 +71,7 @@ static void* __rsd_init(const char* device, int rate, int latency)
rsd->cond_lock = SDL_CreateMutex();
rsd->cond = SDL_CreateCond();
rsd->buffer = rsnd_fifo_new(1024 * 4);
rsd->buffer = fifo_new(1024 * 4);
int channels = 2;
int format = RSD_S16_NE;
@@ -80,14 +80,14 @@ static void* __rsd_init(const char* device, int rate, int latency)
rsd_set_param(rd, RSD_SAMPLERATE, &rate);
rsd_set_param(rd, RSD_LATENCY, &latency);
if ( device != NULL )
if (device)
rsd_set_param(rd, RSD_HOST, (void*)device);
rsd_set_param(rd, RSD_FORMAT, &format);
rsd_set_callback(rd, audio_cb, err_cb, 256, rsd);
if ( rsd_start(rd) < 0 )
if (rsd_start(rd) < 0)
{
free(rsd);
rsd_free(rd);
@@ -98,9 +98,9 @@ static void* __rsd_init(const char* device, int rate, int latency)
return rsd;
}
static ssize_t __rsd_write(void* data, const void* buf, size_t size)
static ssize_t rs_write(void *data, const void *buf, size_t size)
{
rsd_t *rsd = data;
rsd_t *rsd = (rsd_t*)data;
if (rsd->has_error)
return -1;
@@ -108,9 +108,9 @@ static ssize_t __rsd_write(void* data, const void* buf, size_t size)
if (rsd->nonblock)
{
rsd_callback_lock(rsd->rd);
size_t avail = rsnd_fifo_write_avail(rsd->buffer);
size_t avail = fifo_write_avail(rsd->buffer);
size_t write_amt = avail > size ? size : avail;
rsnd_fifo_write(rsd->buffer, buf, write_amt);
fifo_write(rsd->buffer, buf, write_amt);
rsd_callback_unlock(rsd->rd);
return write_amt;
}
@@ -120,7 +120,7 @@ static ssize_t __rsd_write(void* data, const void* buf, size_t size)
while (written < size && !rsd->has_error)
{
rsd_callback_lock(rsd->rd);
size_t avail = rsnd_fifo_write_avail(rsd->buffer);
size_t avail = fifo_write_avail(rsd->buffer);
if (avail == 0)
{
@@ -135,7 +135,7 @@ static ssize_t __rsd_write(void* data, const void* buf, size_t size)
else
{
size_t write_amt = size - written > avail ? avail : size - written;
rsnd_fifo_write(rsd->buffer, (const char*)buf + written, write_amt);
fifo_write(rsd->buffer, (const char*)buf + written, write_amt);
rsd_callback_unlock(rsd->rd);
written += write_amt;
}
@@ -144,37 +144,37 @@ static ssize_t __rsd_write(void* data, const void* buf, size_t size)
}
}
static bool __rsd_stop(void *data)
static bool rs_stop(void *data)
{
rsd_t *rsd = data;
rsd_t *rsd = (rsd_t*)data;
rsd_stop(rsd->rd);
return true;
}
static void __rsd_set_nonblock_state(void *data, bool state)
static void rs_set_nonblock_state(void *data, bool state)
{
rsd_t *rsd = data;
rsd_t *rsd = (rsd_t*)data;
rsd->nonblock = state;
}
static bool __rsd_start(void *data)
static bool rs_start(void *data)
{
rsd_t *rsd = data;
if ( rsd_start(rsd->rd) < 0)
rsd_t *rsd = (rsd_t*)data;
if (rsd_start(rsd->rd) < 0)
return false;
return true;
}
static void __rsd_free(void *data)
static void rs_free(void *data)
{
rsd_t *rsd = data;
rsd_t *rsd = (rsd_t*)data;
rsd_stop(rsd->rd);
rsd_free(rsd->rd);
rsnd_fifo_free(rsd->buffer);
fifo_free(rsd->buffer);
SDL_DestroyMutex(rsd->cond_lock);
SDL_DestroyCond(rsd->cond);
@@ -182,12 +182,13 @@ static void __rsd_free(void *data)
}
const audio_driver_t audio_rsound = {
.init = __rsd_init,
.write = __rsd_write,
.stop = __rsd_stop,
.start = __rsd_start,
.set_nonblock_state = __rsd_set_nonblock_state,
.free = __rsd_free,
.ident = "rsound"
rs_init,
rs_write,
rs_stop,
rs_start,
rs_set_nonblock_state,
rs_free,
NULL,
"rsound"
};
+50 -54
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -16,36 +16,37 @@
*/
#include "driver.h"
#include "../driver.h"
#include <stdlib.h>
#include <stdbool.h>
#include "../boolean.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include "SDL.h"
#include "SDL_audio.h"
#include "SDL_thread.h"
#include "general.h"
#include "buffer.h"
#include "../thread.h"
#include "../general.h"
#include "../fifo_buffer.h"
typedef struct sdl_audio
{
bool nonblock;
SDL_mutex *lock;
SDL_cond *cond;
rsound_fifo_buffer_t *buffer;
slock_t *lock;
scond_t *cond;
fifo_buffer_t *buffer;
} sdl_audio_t;
static void sdl_audio_cb(void *data, Uint8 *stream, int len)
{
sdl_audio_t *sdl = data;
sdl_audio_t *sdl = (sdl_audio_t*)data;
size_t avail = rsnd_fifo_read_avail(sdl->buffer);
size_t write_size = len > avail ? avail : len;
rsnd_fifo_read(sdl->buffer, stream, write_size);
SDL_CondSignal(sdl->cond);
size_t avail = fifo_read_avail(sdl->buffer);
size_t write_size = len > (int)avail ? avail : len;
fifo_read(sdl->buffer, stream, write_size);
scond_signal(sdl->cond);
// If underrun, fill rest with silence.
memset(stream + write_size, 0, len - write_size);
@@ -58,27 +59,26 @@ static inline int find_num_frames(int rate, int latency)
return next_pow2(frames);
}
static void* sdl_audio_init(const char* device, int rate, int latency)
static void *sdl_audio_init(const char *device, unsigned rate, unsigned latency)
{
(void)device;
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0)
return NULL;
sdl_audio_t *sdl = calloc(1, sizeof(*sdl));
sdl_audio_t *sdl = (sdl_audio_t*)calloc(1, sizeof(*sdl));
if (!sdl)
return NULL;
// We have to buffer up some data ourselves, so we let SDL carry approx half of the latency. SDL double buffers audio and we do as well.
int frames = find_num_frames(rate, latency / 4);
SDL_AudioSpec spec = {
.freq = rate,
.format = AUDIO_S16SYS,
.channels = 2,
.samples = frames, // This is in audio frames, not samples ... :(
.callback = sdl_audio_cb,
.userdata = sdl
};
SDL_AudioSpec spec = {0};
spec.freq = rate;
spec.format = AUDIO_S16SYS;
spec.channels = 2;
spec.samples = frames; // This is in audio frames, not samples ... :(
spec.callback = sdl_audio_cb;
spec.userdata = sdl;
SDL_AudioSpec out;
@@ -90,18 +90,18 @@ static void* sdl_audio_init(const char* device, int rate, int latency)
}
g_settings.audio.out_rate = out.freq;
sdl->lock = SDL_CreateMutex();
sdl->cond = SDL_CreateCond();
sdl->lock = slock_new();
sdl->cond = scond_new();
SSNES_LOG("SDL audio: Requested %d ms latency, got %d ms\n", latency, (int)(out.samples * 4 * 1000 / g_settings.audio.out_rate));
// Create a buffer twice as big as needed and prefill the buffer.
size_t bufsize = out.samples * 4 * sizeof(int16_t);
void *tmp = calloc(1, bufsize);
sdl->buffer = rsnd_fifo_new(bufsize);
sdl->buffer = fifo_new(bufsize);
if (tmp)
{
rsnd_fifo_write(sdl->buffer, tmp, bufsize);
fifo_write(sdl->buffer, tmp, bufsize);
free(tmp);
}
@@ -109,17 +109,17 @@ static void* sdl_audio_init(const char* device, int rate, int latency)
return sdl;
}
static ssize_t sdl_audio_write(void* data, const void* buf, size_t size)
static ssize_t sdl_audio_write(void *data, const void *buf, size_t size)
{
sdl_audio_t *sdl = data;
sdl_audio_t *sdl = (sdl_audio_t*)data;
ssize_t ret = 0;
if (sdl->nonblock)
{
SDL_LockAudio();
size_t avail = rsnd_fifo_write_avail(sdl->buffer);
size_t avail = fifo_write_avail(sdl->buffer);
size_t write_amt = avail > size ? size : avail;
rsnd_fifo_write(sdl->buffer, buf, write_amt);
fifo_write(sdl->buffer, buf, write_amt);
SDL_UnlockAudio();
ret = write_amt;
}
@@ -129,19 +129,19 @@ static ssize_t sdl_audio_write(void* data, const void* buf, size_t size)
while (written < size)
{
SDL_LockAudio();
size_t avail = rsnd_fifo_write_avail(sdl->buffer);
size_t avail = fifo_write_avail(sdl->buffer);
if (avail == 0)
{
SDL_UnlockAudio();
SDL_mutexP(sdl->lock);
SDL_CondWait(sdl->cond, sdl->lock);
SDL_mutexV(sdl->lock);
slock_lock(sdl->lock);
scond_wait(sdl->cond, sdl->lock);
slock_unlock(sdl->lock);
}
else
{
size_t write_amt = size - written > avail ? avail : size - written;
rsnd_fifo_write(sdl->buffer, (const char*)buf + written, write_amt);
fifo_write(sdl->buffer, (const char*)buf + written, write_amt);
SDL_UnlockAudio();
written += write_amt;
}
@@ -168,7 +168,7 @@ static bool sdl_audio_start(void *data)
static void sdl_audio_set_nonblock_state(void *data, bool state)
{
sdl_audio_t *sdl = data;
sdl_audio_t *sdl = (sdl_audio_t*)data;
sdl->nonblock = state;
}
@@ -177,28 +177,24 @@ static void sdl_audio_free(void *data)
SDL_CloseAudio();
SDL_QuitSubSystem(SDL_INIT_AUDIO);
sdl_audio_t *sdl = data;
sdl_audio_t *sdl = (sdl_audio_t*)data;
if (sdl)
{
rsnd_fifo_free(sdl->buffer);
SDL_DestroyMutex(sdl->lock);
SDL_DestroyCond(sdl->cond);
fifo_free(sdl->buffer);
slock_free(sdl->lock);
scond_free(sdl->cond);
}
free(sdl);
}
const audio_driver_t audio_sdl = {
.init = sdl_audio_init,
.write = sdl_audio_write,
.stop = sdl_audio_stop,
.start = sdl_audio_start,
.set_nonblock_state = sdl_audio_set_nonblock_state,
.free = sdl_audio_free,
.ident = "sdl"
sdl_audio_init,
sdl_audio_write,
sdl_audio_stop,
sdl_audio_start,
sdl_audio_set_nonblock_state,
sdl_audio_free,
NULL,
"sdl"
};
+119
View File
@@ -0,0 +1,119 @@
#include "utils.h"
#if __SSE2__
#include <emmintrin.h>
#elif __ALTIVEC__
#include <altivec.h>
#endif
void audio_convert_s16_to_float_C(float *out,
const int16_t *in, size_t samples)
{
for (size_t i = 0; i < samples; i++)
out[i] = (float)in[i] / 0x8000;
}
void audio_convert_float_to_s16_C(int16_t *out,
const float *in, size_t samples)
{
for (size_t i = 0; i < samples; i++)
{
int32_t val = (int32_t)(in[i] * 0x8000);
out[i] = (val > 0x7FFF) ? 0x7FFF : (val < -0x8000 ? -0x8000 : (int16_t)val);
}
}
#if __SSE2__
void audio_convert_s16_to_float_SSE2(float *out,
const int16_t *in, size_t samples)
{
__m128 factor = _mm_set1_ps(1.0f / (0x7fff * 0x10000));
size_t i;
for (i = 0; i + 8 <= samples; i += 8, in += 8, out += 8)
{
__m128i input = _mm_loadu_si128((const __m128i *)in);
__m128i regs[2] = {
_mm_unpacklo_epi16(_mm_setzero_si128(), input),
_mm_unpackhi_epi16(_mm_setzero_si128(), input),
};
__m128 output[2] = {
_mm_mul_ps(_mm_cvtepi32_ps(regs[0]), factor),
_mm_mul_ps(_mm_cvtepi32_ps(regs[1]), factor),
};
_mm_storeu_ps(out + 0, output[0]);
_mm_storeu_ps(out + 4, output[1]);
}
audio_convert_s16_to_float_C(out, in, samples - i);
}
void audio_convert_float_to_s16_SSE2(int16_t *out,
const float *in, size_t samples)
{
__m128 factor = _mm_set1_ps((float)0x7fff);
size_t i;
for (i = 0; i + 8 <= samples; i += 8, in += 8, out += 8)
{
__m128 input[2] = { _mm_loadu_ps(in + 0), _mm_loadu_ps(in + 4) };
__m128 res[2] = { _mm_mul_ps(input[0], factor), _mm_mul_ps(input[1], factor) };
__m128i ints[2] = { _mm_cvtps_epi32(res[0]), _mm_cvtps_epi32(res[1]) };
__m128i packed = _mm_packs_epi32(ints[0], ints[1]);
_mm_storeu_si128((__m128i *)out, packed);
}
audio_convert_float_to_s16_C(out, in, samples - i);
}
#elif __ALTIVEC__
void audio_convert_s16_to_float_altivec(float *out,
const int16_t *in, size_t samples)
{
// Unaligned loads/store is a bit expensive, so we optimize for the good path (very likely).
if (((uintptr_t)out & 15) + ((uintptr_t)in & 15) == 0)
{
size_t i;
for (i = 0; i + 8 <= samples; i += 8, in += 8, out += 8)
{
vector signed short input = vec_ld(0, in);
vector signed int hi = vec_unpackh(input);
vector signed int lo = vec_unpackl(input);
vector float out_hi = vec_ctf(hi, 15);
vector float out_lo = vec_ctf(lo, 15);
vec_st(out_hi, 0, out);
vec_st(out_lo, 16, out);
}
audio_convert_s16_to_float_C(out, in, samples - i);
}
else
audio_convert_s16_to_float_C(out, in, samples);
}
void audio_convert_float_to_s16_altivec(int16_t *out,
const float *in, size_t samples)
{
// Unaligned loads/store is a bit expensive, so we optimize for the good path (very likely).
if (((uintptr_t)out & 15) + ((uintptr_t)in & 15) == 0)
{
size_t i;
for (i = 0; i + 8 <= samples; i += 8, in += 8, out += 8)
{
vector float input0 = vec_ld( 0, in);
vector float input1 = vec_ld(16, in);
vector signed int result0 = vec_cts(input0, 15);
vector signed int result1 = vec_cts(input1, 15);
vec_st(vec_packs(result0, result1), 0, out);
}
audio_convert_float_to_s16_C(out, in, samples - i);
}
else
audio_convert_float_to_s16_C(out, in, samples);
}
#endif
+38
View File
@@ -0,0 +1,38 @@
#ifndef AUDIO_UTILS_H
#define AUDIO_UTILS_H
#include <stdint.h>
#include <stddef.h>
#if __SSE2__
#define audio_convert_s16_to_float audio_convert_s16_to_float_SSE2
#define audio_convert_float_to_s16 audio_convert_float_to_s16_SSE2
void audio_convert_s16_to_float_SSE2(float *out,
const int16_t *in, size_t samples);
void audio_convert_float_to_s16_SSE2(int16_t *out,
const float *in, size_t samples);
#elif __ALTIVEC__
#define audio_convert_s16_to_float audio_convert_s16_to_float_altivec
#define audio_convert_float_to_s16 audio_convert_float_to_s16_altivec
void audio_convert_s16_to_float_altivec(float *out,
const int16_t *in, size_t samples);
void audio_convert_float_to_s16_altivec(int16_t *out,
const float *in, size_t samples);
#else
#define audio_convert_s16_to_float audio_convert_s16_to_float_C
#define audio_convert_float_to_s16 audio_convert_float_to_s16_C
#endif
void audio_convert_s16_to_float_C(float *out,
const int16_t *in, size_t samples);
void audio_convert_float_to_s16_C(int16_t *out,
const float *in, size_t samples);
#endif
-160
View File
@@ -1,160 +0,0 @@
/*
Simple C interface for XAudio2
Author: Hans-Kristian Arntzen
License: Public Domain
*/
// This will currently only compile with MSVC2k10.
// Should be compilable with some MinGW trickery as well.
#include "xaudio-c.h"
struct xaudio2 : public IXAudio2VoiceCallback
{
xaudio2(unsigned samplerate, unsigned channels, unsigned bits, unsigned size) :
buf(nullptr), pXAudio2(nullptr), pMasterVoice(nullptr), pSourceVoice(nullptr),
buffers(0), bufptr(0)
{
CoInitializeEx(nullptr, COINIT_MULTITHREADED);
HRESULT hr;
if (FAILED(hr = XAudio2Create(&pXAudio2, 0)))
throw -1;
if (FAILED(hr = pXAudio2->CreateMasteringVoice(
&pMasterVoice, channels, samplerate, 0, 0, nullptr)))
throw -1;
WAVEFORMATEX wfx;
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nChannels = channels;
wfx.nSamplesPerSec = samplerate;
wfx.nBlockAlign = channels * bits / 8;
wfx.wBitsPerSample = bits;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.cbSize = 0;
if (FAILED(hr = pXAudio2->CreateSourceVoice(
&pSourceVoice, &wfx, XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO, this, nullptr, nullptr)))
throw -1;
pSourceVoice->Start();
hEvent = CreateEvent(nullptr, FALSE, FALSE, nullptr);
if (!hEvent)
throw -1;
max_buffers = 8;
bufsize = size / max_buffers;
buf = new uint8_t[bufsize * max_buffers];
write_buffer = 0;
}
~xaudio2()
{
if (pSourceVoice)
{
pSourceVoice->Stop();
pSourceVoice->DestroyVoice();
}
if (pMasterVoice)
pMasterVoice->DestroyVoice();
if (pXAudio2)
pXAudio2->Release();
if (hEvent)
CloseHandle(hEvent);
if (buf)
delete[] buf;
}
size_t write_avail() const
{
return bufsize * (max_buffers - buffers - 1);
}
size_t write(const void *buffer, size_t bytes)
{
size_t written = 0;
while (written < bytes)
{
size_t need = min(bytes - written, bufsize - bufptr);
memcpy((uint8_t*)buf + write_buffer * bufsize + bufptr, (const uint8_t*)buffer + written, need);
written += need;
bufptr += need;
if (bufptr == bufsize)
{
while (buffers == max_buffers - 1)
WaitForSingleObject(hEvent, INFINITE);
XAUDIO2_BUFFER xa2buffer = {0};
xa2buffer.AudioBytes = bufsize;
xa2buffer.pAudioData = buf + write_buffer * bufsize;
xa2buffer.pContext = nullptr;
InterlockedIncrement(&buffers);
pSourceVoice->SubmitSourceBuffer(&xa2buffer);
bufptr = 0;
write_buffer = (write_buffer + 1) % max_buffers;
}
}
return bytes;
}
STDMETHOD_(void, OnBufferStart) (void *) {}
STDMETHOD_(void, OnBufferEnd) (void *)
{
InterlockedDecrement(&buffers);
SetEvent(hEvent);
}
STDMETHOD_(void, OnLoopEnd) (void *) {}
STDMETHOD_(void, OnStreamEnd) () {}
STDMETHOD_(void, OnVoiceError) (void *, HRESULT) {}
STDMETHOD_(void, OnVoiceProcessingPassEnd) ()
{
SetEvent(hEvent);
}
STDMETHOD_(void, OnVoiceProcessingPassStart) (UINT32) {}
uint8_t *buf;
IXAudio2 *pXAudio2;
IXAudio2MasteringVoice *pMasterVoice;
IXAudio2SourceVoice *pSourceVoice;
HANDLE hEvent;
volatile long buffers;
unsigned max_buffers;
unsigned bufsize;
unsigned bufptr;
unsigned write_buffer;
};
XAUDIOC_API xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels, unsigned bits, size_t size)
{
xaudio2 *handle = nullptr;
try {
handle = new xaudio2(samplerate, channels, bits, size);
} catch(...) { delete handle; return nullptr; }
return handle;
}
XAUDIOC_API size_t xaudio2_write_avail(xaudio2_t *handle)
{
try {
return handle->write_avail();
} catch(...) { return 0; }
}
XAUDIOC_API size_t xaudio2_write(xaudio2_t *handle, const void *buf, size_t bytes)
{
try {
return handle->write(buf, bytes);
} catch(...) { return 0; }
}
XAUDIOC_API void xaudio2_free(xaudio2_t *handle)
{
delete handle;
}
-38
View File
@@ -1,38 +0,0 @@
/*
Simple C interface for XAudio2
Author: Hans-Kristian Arntzen
License: Public Domain
*/
#ifndef XAUDIO_C_H
#define XAUDIO_C_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef XAUDIOC_EXPORTS
#define XAUDIOC_API __declspec(dllexport)
#else
#define XAUDIOC_API __declspec(dllimport)
#endif
typedef struct xaudio2 xaudio2_t;
XAUDIOC_API xaudio2_t* xaudio2_new(unsigned samplerate, unsigned channels, unsigned bits, size_t bufsize);
XAUDIOC_API size_t xaudio2_write_avail(xaudio2_t *handle);
XAUDIOC_API size_t xaudio2_write(xaudio2_t *handle, const void *data, size_t bytes);
XAUDIOC_API void xaudio2_free(xaudio2_t *handle);
typedef xaudio2_t* (*xaudio2_new_t)(unsigned, unsigned, unsigned, size_t);
typedef size_t (*xaudio2_write_avail_t)(xaudio2_t*);
typedef size_t (*xaudio2_write_t)(xaudio2_t*, const void*, size_t);
typedef void (*xaudio2_free_t)(xaudio2_t*);
#ifdef __cplusplus
}
#endif
#endif
+172
View File
@@ -0,0 +1,172 @@
/*
Simple C interface for XAudio2
Author: Hans-Kristian Arntzen
License: Public Domain
*/
#include "xaudio.h"
#include "xaudio-c.h"
#include <stdint.h>
#include "../../msvc/msvc_compat.h"
#define MAX_BUFFERS 16
#define MAX_BUFFERS_MASK (MAX_BUFFERS - 1)
#undef min
#undef max
#define min(a, b) ((a) < (b) ? (a) : (b))
#define max(a, b) ((a) > (b) ? (a) : (b))
struct xaudio2
{
const IXAudio2VoiceCallbackVtbl *lpVtbl;
uint8_t *buf;
IXAudio2 *pXAudio2;
IXAudio2MasteringVoice *pMasterVoice;
IXAudio2SourceVoice *pSourceVoice;
HANDLE hEvent;
volatile long buffers;
unsigned bufsize;
unsigned bufptr;
unsigned write_buffer;
};
static void WINAPI voice_on_buffer_end(void *handle_, void *data)
{
(void)data;
xaudio2_t *handle = (xaudio2_t*)handle_;
InterlockedDecrement(&handle->buffers);
SetEvent(handle->hEvent);
}
static void WINAPI dummy_voidp(void *handle, void *data) { (void)handle; (void)data; }
static void WINAPI dummy_nil(void *handle) { (void)handle; }
static void WINAPI dummy_uint32(void *handle, UINT32 dummy) { (void)handle; (void)dummy; }
static void WINAPI dummy_voidp_hresult(void *handle, void *data, HRESULT dummy) { (void)handle; (void)data; (void)dummy; }
const struct IXAudio2VoiceCallbackVtbl voice_vtable = {
dummy_uint32,
dummy_nil,
dummy_nil,
dummy_voidp,
voice_on_buffer_end,
dummy_voidp,
dummy_voidp_hresult,
};
xaudio2_t *xaudio2_new(unsigned samplerate, unsigned channels, size_t size)
{
xaudio2_t *handle = (xaudio2_t*)calloc(1, sizeof(*handle));
if (!handle)
return NULL;
handle->lpVtbl = &voice_vtable;
CoInitializeEx(0, COINIT_MULTITHREADED);
WAVEFORMATEX wfx = {0};
if (FAILED(XAudio2Create(&handle->pXAudio2)))
goto error;
if (FAILED(IXAudio2_CreateMasteringVoice(handle->pXAudio2,
&handle->pMasterVoice, channels, samplerate, 0, 0, 0)))
goto error;
wfx.wFormatTag = WAVE_FORMAT_IEEE_FLOAT;
wfx.nChannels = channels;
wfx.nSamplesPerSec = samplerate;
wfx.nBlockAlign = channels * sizeof(float);
wfx.wBitsPerSample = sizeof(float) * 8;
wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign;
wfx.cbSize = 0;
if (FAILED(IXAudio2_CreateSourceVoice(handle->pXAudio2,
&handle->pSourceVoice, &wfx,
XAUDIO2_VOICE_NOSRC, XAUDIO2_DEFAULT_FREQ_RATIO,
(IXAudio2VoiceCallback*)handle, 0, 0)))
goto error;
handle->hEvent = CreateEvent(0, FALSE, FALSE, 0);
if (!handle->hEvent)
goto error;
handle->bufsize = size / MAX_BUFFERS;
handle->buf = (uint8_t*)calloc(1, handle->bufsize * MAX_BUFFERS);
if (!handle->buf)
goto error;
if (FAILED(IXAudio2SourceVoice_Start(handle->pSourceVoice, 0, XAUDIO2_COMMIT_NOW)))
goto error;
return handle;
error:
xaudio2_free(handle);
return NULL;
}
size_t xaudio2_write_avail(xaudio2_t *handle)
{
return handle->bufsize * (MAX_BUFFERS - handle->buffers - 1);
}
size_t xaudio2_write(xaudio2_t *handle, const void *buf, size_t bytes_)
{
unsigned bytes = bytes_;
const uint8_t *buffer = (const uint8_t*)buf;
while (bytes)
{
unsigned need = min(bytes, handle->bufsize - handle->bufptr);
memcpy(handle->buf + handle->write_buffer * handle->bufsize + handle->bufptr,
buffer, need);
handle->bufptr += need;
buffer += need;
bytes -= need;
if (handle->bufptr == handle->bufsize)
{
while (handle->buffers == MAX_BUFFERS - 1)
WaitForSingleObject(handle->hEvent, INFINITE);
XAUDIO2_BUFFER xa2buffer = {0};
xa2buffer.AudioBytes = handle->bufsize;
xa2buffer.pAudioData = handle->buf + handle->write_buffer * handle->bufsize;
if (FAILED(IXAudio2SourceVoice_SubmitSourceBuffer(handle->pSourceVoice, &xa2buffer, NULL)))
return 0;
InterlockedIncrement(&handle->buffers);
handle->bufptr = 0;
handle->write_buffer = (handle->write_buffer + 1) & MAX_BUFFERS_MASK;
}
}
return bytes_;
}
void xaudio2_free(xaudio2_t *handle)
{
if (handle)
{
if (handle->pSourceVoice)
{
IXAudio2SourceVoice_Stop(handle->pSourceVoice, 0, XAUDIO2_COMMIT_NOW);
IXAudio2SourceVoice_DestroyVoice(handle->pSourceVoice);
}
if (handle->pMasterVoice)
IXAudio2MasteringVoice_DestroyVoice(handle->pMasterVoice);
if (handle->pXAudio2)
IXAudio2_Release(handle->pXAudio2);
if (handle->hEvent)
CloseHandle(handle->hEvent);
free(handle->buf);
free(handle);
}
}
+27
View File
@@ -0,0 +1,27 @@
/*
Simple C interface for XAudio2
Author: Hans-Kristian Arntzen
License: Public Domain
*/
#ifndef XAUDIO_C_H
#define XAUDIO_C_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct xaudio2 xaudio2_t;
xaudio2_t* xaudio2_new(unsigned samplerate, unsigned channels, size_t bufsize);
size_t xaudio2_write_avail(xaudio2_t *handle);
size_t xaudio2_write(xaudio2_t *handle, const void *data, size_t bytes);
void xaudio2_free(xaudio2_t *handle);
#ifdef __cplusplus
}
#endif
#endif
+231
View File
@@ -0,0 +1,231 @@
/*
xaudio.h (2010-08-14) / (2012-12-04)
authors: OV2, Themaister
*/
// Kinda stripped down. Only contains the bare essentials used in SSNES.
#ifndef XAUDIO2_MINGW_H
#define XAUDIO2_MINGW_H
#ifdef __cplusplus
#define CINTERFACE
#endif
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <basetyps.h>
#include <objbase.h>
#include <mmreg.h>
#define DEFINE_GUID_X(n, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
static const GUID n = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
#define DEFINE_CLSID_X(className, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
DEFINE_GUID_X(CLSID_##className, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
#define DEFINE_IID_X(interfaceName, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
DEFINE_GUID_X(IID_##interfaceName, 0x##l, 0x##w1, 0x##w2, 0x##b1, 0x##b2, 0x##b3, 0x##b4, 0x##b5, 0x##b6, 0x##b7, 0x##b8)
#define X2DEFAULT(x)
DEFINE_CLSID_X(XAudio2, e21a7345, eb21, 468e, be, 50, 80, 4d, b9, 7c, f7, 08);
DEFINE_IID_X(IXAudio2, 8bcf1f58, 9fe7, 4583, 8a, c6, e2, ad, c4, 65, c8, bb);
#ifndef INTERFACE
#define INTERFACE void
#endif
#define XAUDIO2_COMMIT_NOW 0
#define XAUDIO2_DEFAULT_CHANNELS 0
#define XAUDIO2_DEFAULT_SAMPLERATE 0
#define XAUDIO2_DEFAULT_FREQ_RATIO 4.0f
#define XAUDIO2_DEBUG_ENGINE 0x0001
#define XAUDIO2_VOICE_NOSRC 0x0004
typedef enum XAUDIO2_DEVICE_ROLE
{
NotDefaultDevice = 0x0,
DefaultConsoleDevice = 0x1,
DefaultMultimediaDevice = 0x2,
DefaultCommunicationsDevice = 0x4,
DefaultGameDevice = 0x8,
GlobalDefaultDevice = 0xf,
InvalidDeviceRole = ~GlobalDefaultDevice
} XAUDIO2_DEVICE_ROLE;
typedef enum XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER
{
XAUDIO2_ANY_PROCESSOR = 0xffffffff,
XAUDIO2_DEFAULT_PROCESSOR = XAUDIO2_ANY_PROCESSOR
} XAUDIO2_WINDOWS_PROCESSOR_SPECIFIER, XAUDIO2_PROCESSOR;
typedef enum XAUDIO2_FILTER_TYPE {
LowPassFilter,
BandPassFilter,
HighPassFilter
} XAUDIO2_FILTER_TYPE;
typedef struct XAUDIO2_DEVICE_DETAILS XAUDIO2_DEVICE_DETAILS;
typedef struct XAUDIO2_VOICE_DETAILS XAUDIO2_VOICE_DETAILS;
typedef struct XAUDIO2_VOICE_SENDS XAUDIO2_VOICE_SENDS;
typedef struct XAUDIO2_EFFECT_DESCRIPTOR XAUDIO2_EFFECT_DESCRIPTOR;
typedef struct XAUDIO2_EFFECT_CHAIN XAUDIO2_EFFECT_CHAIN;
typedef struct XAUDIO2_FILTER_PARAMETERS XAUDIO2_FILTER_PARAMETERS;
typedef struct XAUDIO2_BUFFER_WMA XAUDIO2_BUFFER_WMA;
typedef struct XAUDIO2_VOICE_STATE XAUDIO2_VOICE_STATE;
typedef struct XAUDIO2_PERFORMANCE_DATA XAUDIO2_PERFORMANCE_DATA;
typedef struct XAUDIO2_DEBUG_CONFIGURATION XAUDIO2_DEBUG_CONFIGURATION;
typedef struct IXAudio2EngineCallback IXAudio2EngineCallback;
typedef struct IXAudio2SubmixVoice IXAudio2SubmixVoice;
typedef struct XAUDIO2_BUFFER
{
UINT32 Flags;
UINT32 AudioBytes;
const BYTE* pAudioData;
UINT32 PlayBegin;
UINT32 PlayLength;
UINT32 LoopBegin;
UINT32 LoopLength;
UINT32 LoopCount;
void *pContext;
} XAUDIO2_BUFFER;
DECLARE_INTERFACE(IXAudio2VoiceCallback)
{
STDMETHOD_(void, OnVoiceProcessingPassStart) (THIS_ UINT32 BytesRequired) PURE;
STDMETHOD_(void, OnVoiceProcessingPassEnd) (THIS) PURE;
STDMETHOD_(void, OnStreamEnd) (THIS) PURE;
STDMETHOD_(void, OnBufferStart) (THIS_ void *pBufferContext) PURE;
STDMETHOD_(void, OnBufferEnd) (THIS_ void *pBufferContext) PURE;
STDMETHOD_(void, OnLoopEnd) (THIS_ void *pBufferContext) PURE;
STDMETHOD_(void, OnVoiceError) (THIS_ void *pBufferContext, HRESULT Error) PURE;
};
DECLARE_INTERFACE(IXAudio2Voice)
{
#define Declare_IXAudio2Voice_Methods() \
STDMETHOD_(void, GetVoiceDetails) (THIS_ XAUDIO2_VOICE_DETAILS* pVoiceDetails) PURE; \
STDMETHOD(SetOutputVoices) (THIS_ const XAUDIO2_VOICE_SENDS* pSendList) PURE; \
STDMETHOD(SetEffectChain) (THIS_ const XAUDIO2_EFFECT_CHAIN* pEffectChain) PURE; \
STDMETHOD(EnableEffect) (THIS_ UINT32 EffectIndex, \
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
STDMETHOD(DisableEffect) (THIS_ UINT32 EffectIndex, \
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
STDMETHOD_(void, GetEffectState) (THIS_ UINT32 EffectIndex, BOOL* pEnabled) PURE; \
STDMETHOD(SetEffectParameters) (THIS_ UINT32 EffectIndex, \
const void *pParameters, \
UINT32 ParametersByteSize, \
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
STDMETHOD(GetEffectParameters) (THIS_ UINT32 EffectIndex, void *pParameters, \
UINT32 ParametersByteSize) PURE; \
STDMETHOD(SetFilterParameters) (THIS_ const XAUDIO2_FILTER_PARAMETERS* pParameters, \
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
STDMETHOD_(void, GetFilterParameters) (THIS_ XAUDIO2_FILTER_PARAMETERS* pParameters) PURE; \
STDMETHOD(SetVolume) (THIS_ float Volume, \
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
STDMETHOD_(void, GetVolume) (THIS_ float* pVolume) PURE; \
STDMETHOD(SetChannelVolumes) (THIS_ UINT32 Channels, const float* pVolumes, \
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
STDMETHOD_(void, GetChannelVolumes) (THIS_ UINT32 Channels, float* pVolumes) PURE; \
STDMETHOD(SetOutputMatrix) (THIS_ IXAudio2Voice* pDestinationVoice, \
UINT32 SourceChannels, UINT32 DestinationChannels, \
const float* pLevelMatrix, \
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE; \
STDMETHOD_(void, GetOutputMatrix) (THIS_ IXAudio2Voice* pDestinationVoice, \
UINT32 SourceChannels, UINT32 DestinationChannels, \
float* pLevelMatrix) PURE; \
STDMETHOD_(void, DestroyVoice) (THIS) PURE
Declare_IXAudio2Voice_Methods();
};
DECLARE_INTERFACE_(IXAudio2MasteringVoice, IXAudio2Voice)
{
Declare_IXAudio2Voice_Methods();
};
DECLARE_INTERFACE_(IXAudio2SourceVoice, IXAudio2Voice)
{
Declare_IXAudio2Voice_Methods();
STDMETHOD(Start) (THIS_ UINT32 Flags, UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
STDMETHOD(Stop) (THIS_ UINT32 Flags, UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
STDMETHOD(SubmitSourceBuffer) (THIS_ const XAUDIO2_BUFFER* pBuffer, const XAUDIO2_BUFFER_WMA* pBufferWMA X2DEFAULT(NULL)) PURE;
STDMETHOD(FlushSourceBuffers) (THIS) PURE;
STDMETHOD(Discontinuity) (THIS) PURE;
STDMETHOD(ExitLoop) (THIS_ UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
STDMETHOD_(void, GetState) (THIS_ XAUDIO2_VOICE_STATE* pVoiceState) PURE;
STDMETHOD(SetFrequencyRatio) (THIS_ float Ratio,
UINT32 OperationSet X2DEFAULT(XAUDIO2_COMMIT_NOW)) PURE;
STDMETHOD_(void, GetFrequencyRatio) (THIS_ float* pRatio) PURE;
};
DECLARE_INTERFACE_(IXAudio2, IUnknown)
{
STDMETHOD(QueryInterface) (THIS_ REFIID riid, void** ppvInterface) PURE;
STDMETHOD_(ULONG, AddRef) (THIS) PURE;
STDMETHOD_(ULONG, Release) (THIS) PURE;
STDMETHOD(GetDeviceCount) (THIS_ UINT32* pCount) PURE;
STDMETHOD(GetDeviceDetails) (THIS_ UINT32 Index, XAUDIO2_DEVICE_DETAILS* pDeviceDetails) PURE;
STDMETHOD(Initialize) (THIS_ UINT32 Flags X2DEFAULT(0),
XAUDIO2_PROCESSOR XAudio2Processor X2DEFAULT(XAUDIO2_DEFAULT_PROCESSOR)) PURE;
STDMETHOD(RegisterForCallbacks) (IXAudio2EngineCallback* pCallback) PURE;
STDMETHOD_(void, UnregisterForCallbacks) (IXAudio2EngineCallback* pCallback) PURE;
STDMETHOD(CreateSourceVoice) (THIS_ IXAudio2SourceVoice** ppSourceVoice,
const WAVEFORMATEX* pSourceFormat,
UINT32 Flags X2DEFAULT(0),
float MaxFrequencyRatio X2DEFAULT(XAUDIO2_DEFAULT_FREQ_RATIO),
IXAudio2VoiceCallback* pCallback X2DEFAULT(NULL),
const XAUDIO2_VOICE_SENDS* pSendList X2DEFAULT(NULL),
const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
STDMETHOD(CreateSubmixVoice) (THIS_ IXAudio2SubmixVoice** ppSubmixVoice,
UINT32 InputChannels, UINT32 InputSampleRate,
UINT32 Flags X2DEFAULT(0), UINT32 ProcessingStage X2DEFAULT(0),
const XAUDIO2_VOICE_SENDS* pSendList X2DEFAULT(NULL),
const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
STDMETHOD(CreateMasteringVoice) (THIS_ IXAudio2MasteringVoice** ppMasteringVoice,
UINT32 InputChannels X2DEFAULT(XAUDIO2_DEFAULT_CHANNELS),
UINT32 InputSampleRate X2DEFAULT(XAUDIO2_DEFAULT_SAMPLERATE),
UINT32 Flags X2DEFAULT(0), UINT32 DeviceIndex X2DEFAULT(0),
const XAUDIO2_EFFECT_CHAIN* pEffectChain X2DEFAULT(NULL)) PURE;
STDMETHOD(StartEngine) (THIS) PURE;
STDMETHOD_(void, StopEngine) (THIS) PURE;
STDMETHOD(CommitChanges) (THIS_ UINT32 OperationSet) PURE;
STDMETHOD_(void, GetPerformanceData) (THIS_ XAUDIO2_PERFORMANCE_DATA* pPerfData) PURE;
STDMETHOD_(void, SetDebugConfiguration) (THIS_ const XAUDIO2_DEBUG_CONFIGURATION* pDebugConfiguration,
void *pReserved X2DEFAULT(NULL)) PURE;
};
// C hooks.
#define IXAudio2_Initialize(THIS, a, b) (THIS)->lpVtbl->Initialize(THIS, a, b)
#define IXAudio2_Release(THIS) (THIS)->lpVtbl->Release(THIS)
#define IXAudio2_CreateSourceVoice(THIS, a, b, c, d, e, f, g) (THIS)->lpVtbl->CreateSourceVoice(THIS, a, b, c, d, e, f, g)
#define IXAudio2_CreateMasteringVoice(THIS, a, b, c, d, e, f) (THIS)->lpVtbl->CreateMasteringVoice(THIS, a, b, c, d, e, f)
#define IXAudio2SourceVoice_Start(THIS, a, b) (THIS)->lpVtbl->Start(THIS, a, b)
#define IXAudio2SourceVoice_Stop(THIS, a, b) (THIS)->lpVtbl->Stop(THIS, a, b)
#define IXAudio2SourceVoice_SubmitSourceBuffer(THIS, a, b) (THIS)->lpVtbl->SubmitSourceBuffer(THIS, a, b)
#define IXAudio2SourceVoice_DestroyVoice(THIS) (THIS)->lpVtbl->DestroyVoice(THIS)
#define IXAudio2MasteringVoice_DestroyVoice(THIS) (THIS)->lpVtbl->DestroyVoice(THIS)
static inline HRESULT XAudio2Create(IXAudio2 **ppXAudio2)
{
IXAudio2 *pXAudio2;
#ifdef __cplusplus
HRESULT hr = CoCreateInstance(CLSID_XAudio2, NULL, CLSCTX_INPROC_SERVER, IID_IXAudio2, (void**)&pXAudio2);
#else
HRESULT hr = CoCreateInstance(&CLSID_XAudio2, NULL, CLSCTX_INPROC_SERVER, &IID_IXAudio2, (void**)&pXAudio2);
#endif
if (SUCCEEDED(hr))
{
hr = IXAudio2_Initialize(pXAudio2, 0, XAUDIO2_DEFAULT_PROCESSOR);
if (SUCCEEDED(hr))
*ppXAudio2 = pXAudio2;
else
IXAudio2_Release(pXAudio2);
}
return hr;
}
#endif
+44 -79
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -15,14 +15,10 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "driver.h"
#include "../driver.h"
#include <stdlib.h>
#include "xaudio-c.h"
#include "general.h"
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "xaudio-c/xaudio-c.h"
#include "../general.h"
typedef struct
{
@@ -30,121 +26,90 @@ typedef struct
bool nonblock;
} xa_t;
static xaudio2_new_t pxanew = NULL;
static xaudio2_write_t pxawrite = NULL;
static xaudio2_write_avail_t pxawrite_avail = NULL;
static xaudio2_free_t pxafree = NULL;
static HMODULE lib = NULL;
#define LIB_NAME "xaudio-c.dll"
#define SYM(X) ((void*)GetProcAddress(lib, "xaudio2_" #X))
static void deinit_lib(void)
static void *xa_init(const char *device, unsigned rate, unsigned latency)
{
FreeModule(lib);
lib = NULL;
}
if (latency < 8)
latency = 8; // Do not allow shenanigans.
static bool init_lib(void)
{
if (lib)
return true;
lib = LoadLibrary(LIB_NAME);
if (!lib)
return false;
pxanew = SYM(new);
pxawrite = SYM(write);
pxawrite_avail = SYM(write_avail);
pxafree = SYM(free);
if (!pxanew || !pxawrite || !pxawrite_avail || !pxafree)
{
deinit_lib();
return false;
}
return true;
}
static void* __xa_init(const char* device, int rate, int latency)
{
if (!init_lib())
return NULL;
xa_t *xa = calloc(1, sizeof(xa_t));
if (xa == NULL)
xa_t *xa = (xa_t*)calloc(1, sizeof(*xa));
if (!xa)
return NULL;
size_t bufsize = latency * rate / 1000;
bufsize = next_pow2(bufsize);
SSNES_LOG("XAudio2: Requesting %d ms latency, using %d ms latency.\n", latency, (int)bufsize * 1000 / rate);
xa->xa = pxanew(rate, 2, 16, bufsize << 2);
xa->xa = xaudio2_new(rate, 2, bufsize * 2 * sizeof(float));
if (!xa->xa)
{
SSNES_ERR("Failed to init XAudio2.\n");
free(xa);
return NULL;
}
return xa;
}
static ssize_t __xa_write(void* data, const void* buf, size_t size)
static ssize_t xa_write(void *data, const void *buf, size_t size)
{
xa_t *xa = data;
xa_t *xa = (xa_t*)data;
if (xa->nonblock)
{
size_t avail = pxawrite_avail(xa->xa);
size_t avail = xaudio2_write_avail(xa->xa);
if (avail == 0)
return 0;
if (avail < size)
size = avail;
}
return pxawrite(xa->xa, buf, size);
size_t ret = xaudio2_write(xa->xa, buf, size);
if (ret == 0 && size > 0)
return -1;
return ret;
}
static bool __xa_stop(void *data)
static bool xa_stop(void *data)
{
(void)data;
return true;
}
static void __xa_set_nonblock_state(void *data, bool state)
static void xa_set_nonblock_state(void *data, bool state)
{
xa_t *xa = data;
xa_t *xa = (xa_t*)data;
xa->nonblock = state;
}
static bool __xa_start(void *data)
static bool xa_start(void *data)
{
(void)data;
return true;
}
static void __xa_free(void *data)
static bool xa_use_float(void *data)
{
xa_t *xa = data;
if (xa && xa->xa)
(void)data;
return true;
}
static void xa_free(void *data)
{
xa_t *xa = (xa_t*)data;
if (xa)
{
if (pxafree)
pxafree(xa->xa);
if (xa->xa)
xaudio2_free(xa->xa);
free(xa);
}
deinit_lib();
}
const audio_driver_t audio_xa = {
.init = __xa_init,
.write = __xa_write,
.stop = __xa_stop,
.start = __xa_start,
.set_nonblock_state = __xa_set_nonblock_state,
.free = __xa_free,
.ident = "xaudio"
xa_init,
xa_write,
xa_stop,
xa_start,
xa_set_nonblock_state,
xa_free,
xa_use_float,
"xaudio"
};
+54 -39
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -16,9 +16,9 @@
*/
#include "autosave.h"
#include "SDL.h"
#include "thread.h"
#include <stdlib.h>
#include <stdbool.h>
#include "boolean.h"
#include <string.h>
#include <stdio.h>
#include "general.h"
@@ -26,11 +26,11 @@
struct autosave
{
volatile bool quit;
SDL_mutex *lock;
slock_t *lock;
SDL_mutex *cond_lock;
SDL_cond *cond;
SDL_Thread *thread;
slock_t *cond_lock;
scond_t *cond;
sthread_t *thread;
void *buffer;
const void *snes_buffer;
@@ -39,40 +39,54 @@ struct autosave
unsigned interval;
};
static int autosave_thread(void *data)
static void autosave_thread(void *data)
{
autosave_t *save = data;
autosave_t *save = (autosave_t*)data;
bool first_log = true;
while (!save->quit)
{
autosave_lock(save);
memcpy(save->buffer, save->snes_buffer, save->bufsize);
bool differ = memcmp(save->buffer, save->snes_buffer, save->bufsize) != 0;
if (differ)
memcpy(save->buffer, save->snes_buffer, save->bufsize);
autosave_unlock(save);
// Should probably deal with this more elegantly.
FILE *file = fopen(save->path, "wb");
if (file)
if (differ)
{
SSNES_LOG("Autosaving SRAM to \"%s\"\n", save->path);
bool failed = false;
failed |= fwrite(save->buffer, 1, save->bufsize, file) != save->bufsize;
failed |= fflush(file) != 0;
failed |= fclose(file) != 0;
if (failed)
SSNES_WARN("Failed to autosave SRAM! Disk might be full.\n");
// Should probably deal with this more elegantly.
FILE *file = fopen(save->path, "wb");
if (file)
{
// Avoid spamming down stderr ... :)
if (first_log)
{
SSNES_LOG("Autosaving SRAM to \"%s\", will continue to check every %u seconds ...\n", save->path, save->interval);
first_log = false;
}
else
SSNES_LOG("SRAM changed ... autosaving ...\n");
bool failed = false;
failed |= fwrite(save->buffer, 1, save->bufsize, file) != save->bufsize;
failed |= fflush(file) != 0;
failed |= fclose(file) != 0;
if (failed)
SSNES_WARN("Failed to autosave SRAM! Disk might be full.\n");
}
}
SDL_mutexP(save->cond_lock);
slock_lock(save->cond_lock);
if (!save->quit)
SDL_CondWaitTimeout(save->cond, save->cond_lock, save->interval * 1000);
SDL_mutexV(save->cond_lock);
scond_wait_timeout(save->cond, save->cond_lock, save->interval * 1000);
slock_unlock(save->cond_lock);
}
return 0;
}
autosave_t *autosave_new(const char *path, const void *data, size_t size, unsigned interval)
{
autosave_t *handle = calloc(1, sizeof(*handle));
autosave_t *handle = (autosave_t*)calloc(1, sizeof(*handle));
if (!handle)
return NULL;
@@ -87,37 +101,38 @@ autosave_t *autosave_new(const char *path, const void *data, size_t size, unsign
free(handle);
return NULL;
}
memcpy(handle->buffer, handle->snes_buffer, handle->bufsize);
handle->lock = SDL_CreateMutex();
handle->cond_lock = SDL_CreateMutex();
handle->cond = SDL_CreateCond();
handle->lock = slock_new();
handle->cond_lock = slock_new();
handle->cond = scond_new();
handle->thread = SDL_CreateThread(autosave_thread, handle);
handle->thread = sthread_create(autosave_thread, handle);
return handle;
}
void autosave_lock(autosave_t *handle)
{
SDL_mutexP(handle->lock);
slock_lock(handle->lock);
}
void autosave_unlock(autosave_t *handle)
{
SDL_mutexV(handle->lock);
slock_unlock(handle->lock);
}
void autosave_free(autosave_t *handle)
{
SDL_mutexP(handle->cond_lock);
slock_lock(handle->cond_lock);
handle->quit = true;
SDL_mutexV(handle->cond_lock);
SDL_CondSignal(handle->cond);
SDL_WaitThread(handle->thread, NULL);
slock_unlock(handle->cond_lock);
scond_signal(handle->cond);
sthread_join(handle->thread);
SDL_DestroyMutex(handle->lock);
SDL_DestroyMutex(handle->cond_lock);
SDL_DestroyCond(handle->cond);
slock_free(handle->lock);
slock_free(handle->cond_lock);
scond_free(handle->cond);
free(handle->buffer);
free(handle);
+1 -1
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
+26
View File
@@ -0,0 +1,26 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_BOOLEAN_H
#define __SSNES_BOOLEAN_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#endif
+174
View File
@@ -0,0 +1,174 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "bps.h"
#include "movie.h"
#include <stdint.h>
#include "boolean.h"
#include "msvc/msvc_compat.h"
enum bps_mode
{
SOURCE_READ = 0,
TARGET_READ,
SOURCE_COPY,
TARGET_COPY
};
struct bps_data
{
const uint8_t *modify_data, *source_data;
uint8_t *target_data;
size_t modify_length, source_length, target_length;
size_t modify_offset, source_offset, target_offset;
uint32_t modify_checksum, source_checksum, target_checksum;
size_t source_relative_offset, target_relative_offset, output_offset;
};
static uint8_t bps_read(struct bps_data *bps)
{
uint8_t data = bps->modify_data[bps->modify_offset++];
bps->modify_checksum = crc32_adjust(bps->modify_checksum, data);
return data;
}
static uint64_t bps_decode(struct bps_data *bps)
{
uint64_t data = 0, shift = 1;
for (;;)
{
uint8_t x = bps_read(bps);
data += (x & 0x7f) * shift;
if (x & 0x80)
break;
shift <<= 7;
data += shift;
}
return data;
}
static void bps_write(struct bps_data *bps, uint8_t data)
{
bps->target_data[bps->output_offset++] = data;
bps->target_checksum = crc32_adjust(bps->target_checksum, data);
}
bps_error_t bps_apply_patch(
const uint8_t *modify_data, size_t modify_length,
const uint8_t *source_data, size_t source_length,
uint8_t *target_data, size_t *target_length)
{
if (modify_length < 19)
return BPS_PATCH_TOO_SMALL;
struct bps_data bps = {0};
bps.modify_data = modify_data;
bps.modify_length = modify_length;
bps.target_data = target_data;
bps.target_length = *target_length;
bps.source_data = source_data;
bps.source_length = source_length;
bps.modify_checksum = ~0;
bps.target_checksum = ~0;
if ((bps_read(&bps) != 'B') || (bps_read(&bps) != 'P') || (bps_read(&bps) != 'S') || (bps_read(&bps) != '1'))
return BPS_PATCH_INVALID_HEADER;
size_t modify_source_size = bps_decode(&bps);
size_t modify_target_size = bps_decode(&bps);
size_t modify_markup_size = bps_decode(&bps);
for (size_t i = 0; i < modify_markup_size; i++)
bps_read(&bps);
if (modify_source_size > bps.source_length)
return BPS_SOURCE_TOO_SMALL;
if (modify_target_size > bps.target_length)
return BPS_TARGET_TOO_SMALL;
while (bps.modify_offset < bps.modify_length - 12)
{
size_t length = bps_decode(&bps);
unsigned mode = length & 3;
length = (length >> 2) + 1;
switch (mode)
{
case SOURCE_READ:
while (length--)
bps_write(&bps, bps.source_data[bps.output_offset]);
break;
case TARGET_READ:
while (length--)
bps_write(&bps, bps_read(&bps));
break;
case SOURCE_COPY:
case TARGET_COPY:
{
int offset = bps_decode(&bps);
bool negative = offset & 1;
offset >>= 1;
if (negative)
offset = -offset;
if (mode == SOURCE_COPY)
{
bps.source_offset += offset;
while (length--)
bps_write(&bps, bps.source_data[bps.source_offset++]);
}
else
{
bps.target_offset += offset;
while (length--)
bps_write(&bps, bps.target_data[bps.target_offset++]);
break;
}
break;
}
}
}
uint32_t modify_source_checksum = 0, modify_target_checksum = 0, modify_modify_checksum = 0;
for (unsigned i = 0; i < 32; i += 8)
modify_source_checksum |= bps_read(&bps) << i;
for (unsigned i = 0; i < 32; i += 8)
modify_target_checksum |= bps_read(&bps) << i;
uint32_t checksum = ~bps.modify_checksum;
for (unsigned i = 0; i < 32; i += 8)
modify_modify_checksum |= bps_read(&bps) << i;
bps.source_checksum = crc32_calculate(bps.source_data, bps.source_length);
bps.target_checksum = ~bps.target_checksum;
if (bps.source_checksum != modify_source_checksum)
return BPS_SOURCE_CHECKSUM_INVALID;
if (bps.target_checksum != modify_target_checksum)
return BPS_TARGET_CHECKSUM_INVALID;
if (checksum != modify_modify_checksum)
return BPS_PATCH_CHECKSUM_INVALID;
*target_length = modify_target_size;
return BPS_SUCCESS;
}
+45
View File
@@ -0,0 +1,45 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BPS_H
#define __BPS_H
#include <stdint.h>
#include <stddef.h>
// BPS implementation from bSNES (nall::).
typedef enum bps_error
{
BPS_UNKNOWN,
BPS_SUCCESS,
BPS_PATCH_TOO_SMALL,
BPS_PATCH_INVALID_HEADER,
BPS_SOURCE_TOO_SMALL,
BPS_TARGET_TOO_SMALL,
BPS_SOURCE_CHECKSUM_INVALID,
BPS_TARGET_CHECKSUM_INVALID,
BPS_PATCH_CHECKSUM_INVALID
} bps_error_t;
bps_error_t bps_apply_patch(
const uint8_t *patch_data, size_t patch_length,
const uint8_t *source_data, size_t source_length,
uint8_t *target_data, size_t *target_length);
#endif
+390
View File
@@ -0,0 +1,390 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "cheats.h"
#include "sha256.h"
#include "dynamic.h"
#include "general.h"
#include "strl.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_CONFIGFILE
#include "conf/config_file.h"
#endif
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
struct cheat
{
char *desc;
bool state;
char *code;
};
struct cheat_manager
{
struct cheat *cheats;
unsigned ptr;
unsigned size;
unsigned buf_size;
};
static char *strcat_alloc(char *dest, const char *input)
{
size_t dest_len = dest ? strlen(dest) : 0;
size_t input_len = strlen(input);
size_t required_len = dest_len + input_len + 1;
char *output = (char*)realloc(dest, required_len);
if (!output)
return NULL;
if (dest)
strlcat(output, input, required_len);
else
strlcpy(output, input, required_len);
return output;
}
static bool xml_grab_cheat(struct cheat *cht, xmlNodePtr ptr)
{
if (!ptr)
return false;
memset(cht, 0, sizeof(struct cheat));
bool first = true;
for (; ptr; ptr = ptr->next)
{
if (strcmp((const char*)ptr->name, "description") == 0)
{
cht->desc = (char*)xmlNodeGetContent(ptr);
}
else if (strcmp((const char*)ptr->name, "code") == 0)
{
if (!first)
{
cht->code = strcat_alloc(cht->code, "+");
if (!cht->code)
return false;
}
xmlChar *code = xmlNodeGetContent(ptr);
if (!code)
return false;
cht->code = strcat_alloc(cht->code, (const char*)code);
xmlFree(code);
if (!cht->code)
return false;
first = false;
}
}
return true;
}
static bool xml_grab_cheats(cheat_manager_t *handle, xmlNodePtr ptr)
{
for (; ptr; ptr = ptr->next)
{
if (strcmp((const char*)ptr->name, "name") == 0)
{
xmlChar *name = xmlNodeGetContent(ptr);
if (name)
{
SSNES_LOG("Found cheat for game: \"%s\"\n", name);
xmlFree(name);
}
}
else if (strcmp((const char*)ptr->name, "cheat") == 0)
{
if (handle->size == handle->buf_size)
{
handle->buf_size *= 2;
handle->cheats = (struct cheat*)realloc(handle->cheats, handle->buf_size * sizeof(struct cheat));
if (!handle->cheats)
return false;
}
if (xml_grab_cheat(&handle->cheats[handle->size], ptr->children))
handle->size++;
}
}
return true;
}
static void cheat_manager_apply_cheats(cheat_manager_t *handle)
{
unsigned index = 0;
psnes_cheat_reset();
for (unsigned i = 0; i < handle->size; i++)
{
if (handle->cheats[i].state)
psnes_cheat_set(index++, true, handle->cheats[i].code);
}
}
static void cheat_manager_load_config(cheat_manager_t *handle, const char *path, const char *sha256)
{
#ifdef HAVE_CONFIGFILE
if (!(*path))
return;
config_file_t *conf = config_file_new(path);
if (!conf)
return;
char *str;
if (!config_get_string(conf, sha256, &str))
{
config_file_free(conf);
return;
}
const char *num = strtok(str, ";");
while (num)
{
unsigned index = strtoul(num, NULL, 0);
if (index < handle->size)
handle->cheats[index].state = true;
num = strtok(NULL, ";");
}
free(str);
config_file_free(conf);
cheat_manager_apply_cheats(handle);
#else
(void)handle;
(void)path;
(void)sha256;
#endif
}
static void cheat_manager_save_config(cheat_manager_t *handle, const char *path, const char *sha256)
{
#ifdef HAVE_CONFIGFILE
if (!(*path))
return;
config_file_t *conf = config_file_new(path);
if (!conf)
conf = config_file_new(NULL);
if (!conf)
{
SSNES_ERR("Cannot save XML cheat settings!\n");
return;
}
char conf_str[512] = {0};
char tmp[32] = {0};
for (unsigned i = 0; i < handle->size; i++)
{
if (handle->cheats[i].state)
{
snprintf(tmp, sizeof(tmp), "%u;", i);
strlcat(conf_str, tmp, sizeof(conf_str));
}
}
if (*conf_str)
conf_str[strlen(conf_str) - 1] = '\0'; // Remove the trailing ';'
config_set_string(conf, sha256, conf_str);
if (!config_file_write(conf, path))
SSNES_ERR("Failed to write XML cheat settings to \"%s\"! Check permissions!\n", path);
config_file_free(conf);
#else
(void)handle;
(void)path;
(void)sha256;
#endif
}
cheat_manager_t* cheat_manager_new(const char *path)
{
LIBXML_TEST_VERSION;
psnes_cheat_reset();
xmlParserCtxtPtr ctx = NULL;
xmlDocPtr doc = NULL;
cheat_manager_t *handle = (cheat_manager_t*)calloc(1, sizeof(struct cheat_manager));
if (!handle)
return NULL;
xmlNodePtr head = NULL;
xmlNodePtr cur = NULL;
handle->buf_size = 1;
handle->cheats = (struct cheat*)calloc(handle->buf_size, sizeof(struct cheat));
if (!handle->cheats)
{
handle->buf_size = 0;
goto error;
}
ctx = xmlNewParserCtxt();
if (!ctx)
goto error;
doc = xmlCtxtReadFile(ctx, path, NULL, 0);
if (!doc)
{
SSNES_ERR("Failed to parse XML file: %s\n", path);
goto error;
}
if (ctx->valid == 0)
{
SSNES_ERR("Cannot validate XML file: %s\n", path);
goto error;
}
head = xmlDocGetRootElement(doc);
for (cur = head; cur; cur = cur->next)
{
if (cur->type == XML_ELEMENT_NODE && strcmp((const char*)cur->name, "database") == 0)
break;
}
if (!cur)
goto error;
for (cur = cur->children; cur; cur = cur->next)
{
if (cur->type != XML_ELEMENT_NODE)
continue;
if (strcmp((const char*)cur->name, "cartridge") == 0)
{
xmlChar *sha256 = xmlGetProp(cur, (const xmlChar*)"sha256");
if (!sha256)
continue;
if (strcmp((const char*)sha256, g_extern.sha256) == 0)
{
xmlFree(sha256);
break;
}
xmlFree(sha256);
}
}
if (!cur)
goto error;
if (!xml_grab_cheats(handle, cur->children))
{
SSNES_ERR("Failed to grab cheats. This should not happen.\n");
goto error;
}
if (handle->size == 0)
{
SSNES_ERR("Did not find any cheats in XML file: %s\n", path);
goto error;
}
cheat_manager_load_config(handle, g_settings.cheat_settings_path, g_extern.sha256);
xmlFreeDoc(doc);
xmlFreeParserCtxt(ctx);
return handle;
error:
cheat_manager_free(handle);
if (doc)
xmlFreeDoc(doc);
if (ctx)
xmlFreeParserCtxt(ctx);
return NULL;
}
void cheat_manager_free(cheat_manager_t *handle)
{
if (!handle)
return;
if (handle->cheats)
{
cheat_manager_save_config(handle, g_settings.cheat_settings_path, g_extern.sha256);
for (unsigned i = 0; i < handle->size; i++)
{
xmlFree(handle->cheats[i].desc);
free(handle->cheats[i].code);
}
free(handle->cheats);
}
free(handle);
}
static void cheat_manager_update(cheat_manager_t *handle)
{
msg_queue_clear(g_extern.msg_queue);
char msg[256];
snprintf(msg, sizeof(msg), "Cheat: #%u [%s]: %s", handle->ptr, handle->cheats[handle->ptr].state ? "ON" : "OFF", handle->cheats[handle->ptr].desc);
msg_queue_push(g_extern.msg_queue, msg, 1, 180);
SSNES_LOG("%s\n", msg);
}
void cheat_manager_toggle(cheat_manager_t *handle)
{
handle->cheats[handle->ptr].state ^= true;
cheat_manager_apply_cheats(handle);
cheat_manager_update(handle);
}
void cheat_manager_index_next(cheat_manager_t *handle)
{
handle->ptr = (handle->ptr + 1) % handle->size;
cheat_manager_update(handle);
}
void cheat_manager_index_prev(cheat_manager_t *handle)
{
if (handle->ptr == 0)
handle->ptr = handle->size - 1;
else
handle->ptr--;
cheat_manager_update(handle);
}
+30
View File
@@ -0,0 +1,30 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_CHEATS_H
#define __SSNES_CHEATS_H
typedef struct cheat_manager cheat_manager_t;
cheat_manager_t* cheat_manager_new(const char *path);
void cheat_manager_free(cheat_manager_t *handle);
void cheat_manager_index_next(cheat_manager_t *handle);
void cheat_manager_index_prev(cheat_manager_t *handle);
void cheat_manager_toggle(cheat_manager_t *handle);
#endif
+416 -81
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -21,22 +21,59 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include "../strl.h"
#include "../posix_string.h"
#include "../msvc/msvc_compat.h"
#if !defined(_WIN32) && !defined(__CELLOS_LV2__) && !defined(_XBOX)
#include <sys/param.h> // PATH_MAX
#elif defined(_WIN32) && !defined(_XBOX)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(_XBOX)
#include <xtl.h>
#endif
#ifndef PATH_MAX
#ifdef PATH_MAX
#define PATH_MAX PATH_MAX
#else
#define PATH_MAX 512
#endif
#endif
#define MAX_INCLUDE_DEPTH 16
struct entry_list
{
bool readonly; // If we got this from an #include, do not allow write.
char *key;
char *value;
struct entry_list *next;
};
struct include_list
{
char *path;
struct include_list *next;
};
struct config_file
{
char *path;
struct entry_list *entries;
struct entry_list *tail;
unsigned include_depth;
struct include_list *includes;
};
static config_file_t *config_file_new_internal(const char *path, unsigned depth);
static char *getaline(FILE *file)
{
char *newline = malloc(9);
char *newline = (char*)malloc(9);
size_t cur_size = 8;
size_t index = 0;
@@ -46,7 +83,7 @@ static char *getaline(FILE *file)
if (index == cur_size)
{
cur_size *= 2;
newline = realloc(newline, cur_size + 1);
newline = (char*)realloc(newline, cur_size + 1);
}
newline[index++] = in;
@@ -56,18 +93,198 @@ static char *getaline(FILE *file)
return newline;
}
static bool parse_line(struct entry_list *list, char *line)
static char *extract_value(char *line, bool is_value)
{
if (is_value)
{
while (isspace(*line))
line++;
// If we don't have an equal sign here, we've got an invalid string...
if (*line != '=')
return NULL;
line++;
}
while (isspace(*line))
line++;
// We have a full string. Read until next ".
if (*line == '"')
{
line++;
char *tok = strtok(line, "\"");
if (!tok)
return NULL;
return strdup(tok);
}
else if (*line == '\0') // Nothing :(
return NULL;
else // We don't have that... Read till next space.
{
char *tok = strtok(line, " \n\t\f\r\v");
if (tok)
return strdup(tok);
else
return NULL;
}
}
static void set_list_readonly(struct entry_list *list)
{
while (list)
{
list->readonly = true;
list = list->next;
}
}
// Move semantics? :)
static void add_child_list(config_file_t *parent, config_file_t *child)
{
if (parent->entries)
{
struct entry_list *head = parent->entries;
while (head->next)
head = head->next;
set_list_readonly(child->entries);
head->next = child->entries;
}
else
{
set_list_readonly(child->entries);
parent->entries = child->entries;
}
child->entries = NULL;
// Rebase tail.
if (parent->entries)
{
struct entry_list *head = parent->entries;
while (head->next)
head = head->next;
parent->tail = head;
}
else
parent->tail = NULL;
}
static void add_include_list(config_file_t *conf, const char *path)
{
struct include_list *head = conf->includes;
struct include_list *node = (struct include_list*)calloc(1, sizeof(*node));
node->path = strdup(path);
if (head)
{
while (head->next)
head = head->next;
head->next = node;
}
else
conf->includes = node;
}
static void add_sub_conf(config_file_t *conf, char *line)
{
char *path = extract_value(line, false);
if (!path)
return;
add_include_list(conf, path);
char real_path[PATH_MAX];
#ifdef _WIN32
// Accomodate POSIX systems on Win32.
bool is_full_path = *path == '/';
if (is_full_path)
strlcpy(real_path, path, sizeof(real_path));
else
{
// Workaround GetFullPathName not existing on XDK.
// : is not a valid element in a path name. (NTFS streams?)
if (strchr(path, ':') == NULL)
{
strlcpy(real_path, conf->path, sizeof(real_path));
char *split = strrchr(real_path, '/');
if (!split)
split = strrchr(real_path, '\\');
split[1] = '\0';
strlcat(real_path, path, sizeof(real_path));
}
else
strlcpy(real_path, path, sizeof(real_path));
}
#else
if (*path == '/')
strlcpy(real_path, path, sizeof(real_path));
#ifndef __CELLOS_LV2__
else if (*path == '~')
{
const char *home = getenv("HOME");
strlcpy(real_path, home ? home : "/", sizeof(real_path));
strlcat(real_path, path + 1, sizeof(real_path));
}
#endif
else
{
strlcpy(real_path, conf->path, sizeof(real_path));
char *split = strrchr(real_path, '/');
if (split)
{
split[1] = '\0';
strlcat(real_path, path, sizeof(real_path));
}
else
strlcpy(real_path, path, sizeof(real_path));
}
#endif
config_file_t *sub_conf = config_file_new_internal(real_path, conf->include_depth + 1);
if (!sub_conf)
{
free(path);
return;
}
// Pilfer internal list! :D
add_child_list(conf, sub_conf);
config_file_free(sub_conf);
free(path);
}
static bool parse_line(config_file_t *conf, struct entry_list *list, char *line)
{
// Remove everything after comment.
char *comment = strchr(line, '#');
if (comment)
*comment = '\0';
// Starting line with # and include includes config files. :)
if ((comment == line) && (conf->include_depth < MAX_INCLUDE_DEPTH))
{
comment++;
if (strstr(comment, "include ") == comment)
{
add_sub_conf(conf, comment + strlen("include "));
return false;
}
}
else if (conf->include_depth >= MAX_INCLUDE_DEPTH)
fprintf(stderr, "!!! #include depth exceeded for config! Might be a cycle.\n");
// Skips to first character.
while (isspace(*line))
line++;
char *key = malloc(9);
char *key = (char*)malloc(9);
size_t cur_size = 8;
size_t index = 0;
@@ -76,7 +293,7 @@ static bool parse_line(struct entry_list *list, char *line)
if (index == cur_size)
{
cur_size *= 2;
key = realloc(key, cur_size + 1);
key = (char*)realloc(key, cur_size + 1);
}
key[index++] = *line++;
@@ -84,118 +301,113 @@ static bool parse_line(struct entry_list *list, char *line)
key[index] = '\0';
list->key = key;
while (isspace(*line))
line++;
// If we don't have an equal sign here, we've got an invalid string...
if (*line != '=')
list->value = extract_value(line, true);
if (!list->value)
{
list->key = NULL;
free(key);
return false;
}
line++;
while (isspace(*line))
line++;
// We have a full string. Read until next ".
if (*line == '"')
{
char *tok = strtok(line + 1, "\"");
if (tok == NULL)
{
list->key = NULL;
free(key);
return false;
}
list->value = strdup(tok);
}
else // We don't have that... Read till next space.
{
char *tok = strtok(line, " \t\f");
if (tok == NULL)
{
list->key = NULL;
free(key);
return false;
}
list->value = strdup(tok);
}
return true;
}
config_file_t *config_file_new(const char *path)
static config_file_t *config_file_new_internal(const char *path, unsigned depth)
{
struct config_file *conf = calloc(1, sizeof(*conf));
if (conf == NULL)
struct config_file *conf = (struct config_file*)calloc(1, sizeof(*conf));
if (!conf)
return NULL;
if (path == NULL)
if (!path)
return conf;
FILE *file = fopen(path, "r");
if (!file)
conf->path = strdup(path);
if (!conf->path)
{
free(conf);
return NULL;
}
struct entry_list *tail = conf->entries;
conf->include_depth = depth;
FILE *file = fopen(path, "r");
if (!file)
{
free(conf->path);
free(conf);
return NULL;
}
while (!feof(file))
{
struct entry_list *list = calloc(1, sizeof(*list));
struct entry_list *list = (struct entry_list*)calloc(1, sizeof(*list));
char *line = getaline(file);
if (line)
{
if (parse_line(list, line))
if (parse_line(conf, list, line))
{
if (conf->entries == NULL)
if (conf->entries)
{
conf->entries = list;
tail = list;
conf->tail->next = list;
conf->tail = list;
}
else
{
tail->next = list;
tail = list;
conf->entries = list;
conf->tail = list;
}
}
free(line);
}
if (list != conf->tail)
free(list);
}
fclose(file);
return conf;
}
config_file_t *config_file_new(const char *path)
{
return config_file_new_internal(path, 0);
}
void config_file_free(config_file_t *conf)
{
if (conf != NULL)
if (!conf)
return;
struct entry_list *tmp = conf->entries;
while (tmp)
{
struct entry_list *tmp = conf->entries;
struct entry_list *old = tmp;
while (tmp != NULL)
{
free(tmp->key);
free(tmp->value);
old = tmp;
tmp = tmp->next;
free(old);
}
free(conf);
free(tmp->key);
free(tmp->value);
struct entry_list *hold = tmp;
tmp = tmp->next;
free(hold);
}
struct include_list *inc_tmp = conf->includes;
while (inc_tmp)
{
free(inc_tmp->path);
struct include_list *hold = inc_tmp;
inc_tmp = inc_tmp->next;
free(hold);
}
free(conf->path);
free(conf);
}
bool config_get_double(config_file_t *conf, const char *key, double *in)
{
struct entry_list *list = conf->entries;
while (list != NULL)
while (list)
{
if (strcmp(key, list->key) == 0)
{
@@ -207,16 +419,79 @@ bool config_get_double(config_file_t *conf, const char *key, double *in)
return false;
}
bool config_get_float(config_file_t *conf, const char *key, float *in)
{
struct entry_list *list = conf->entries;
while (list)
{
if (strcmp(key, list->key) == 0)
{
*in = (float)strtod(list->value, NULL);
return true;
}
list = list->next;
}
return false;
}
bool config_get_int(config_file_t *conf, const char *key, int *in)
{
struct entry_list *list = conf->entries;
while (list != NULL)
while (list)
{
if (strcmp(key, list->key) == 0)
{
*in = strtol(list->value, NULL, 0);
return true;
errno = 0;
int val = strtol(list->value, NULL, 0);
if (errno == 0)
{
*in = val;
return true;
}
return
false;
}
list = list->next;
}
return false;
}
bool config_get_uint(config_file_t *conf, const char *key, unsigned *in)
{
struct entry_list *list = conf->entries;
while (list != NULL)
{
if (strcmp(key, list->key) == 0)
{
*in = strtol(list->value, NULL, 0);
return true;
}
list = list->next;
}
return false;
}
bool config_get_hex(config_file_t *conf, const char *key, unsigned *in)
{
struct entry_list *list = conf->entries;
while (list)
{
if (strcmp(key, list->key) == 0)
{
errno = 0;
unsigned val = strtoul(list->value, NULL, 16);
if (errno == 0)
{
*in = val;
return true;
}
else
return false;
}
list = list->next;
}
@@ -227,11 +502,11 @@ bool config_get_char(config_file_t *conf, const char *key, char *in)
{
struct entry_list *list = conf->entries;
while (list != NULL)
while (list)
{
if (strcmp(key, list->key) == 0)
{
if (strlen(list->value) > 1)
if (list->value[0] && list->value[1])
return false;
*in = *list->value;
return true;
@@ -245,7 +520,7 @@ bool config_get_string(config_file_t *conf, const char *key, char **str)
{
struct entry_list *list = conf->entries;
while (list != NULL)
while (list)
{
if (strcmp(key, list->key) == 0)
{
@@ -257,11 +532,27 @@ bool config_get_string(config_file_t *conf, const char *key, char **str)
return false;
}
bool config_get_array(config_file_t *conf, const char *key, char *buf, size_t size)
{
struct entry_list *list = conf->entries;
while (list)
{
if (strcmp(key, list->key) == 0)
{
strlcpy(buf, list->value, size);
return true;
}
list = list->next;
}
return false;
}
bool config_get_bool(config_file_t *conf, const char *key, bool *in)
{
struct entry_list *list = conf->entries;
while (list != NULL)
while (list)
{
if (strcmp(key, list->key) == 0)
{
@@ -287,19 +578,20 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
{
struct entry_list *list = conf->entries;
struct entry_list *last = list;
while (list != NULL)
while (list)
{
if (strcmp(key, list->key) == 0)
if (!list->readonly && (strcmp(key, list->key) == 0))
{
free(list->value);
list->value = strdup(val);
return;
}
last = list;
list = list->next;
}
struct entry_list *elem = calloc(1, sizeof(*elem));
struct entry_list *elem = (struct entry_list*)calloc(1, sizeof(*elem));
elem->key = strdup(key);
elem->value = strdup(val);
@@ -312,7 +604,11 @@ void config_set_string(config_file_t *conf, const char *key, const char *val)
void config_set_double(config_file_t *conf, const char *key, double val)
{
char buf[128];
#ifdef __cplusplus
snprintf(buf, sizeof(buf), "%f", (float)val);
#else
snprintf(buf, sizeof(buf), "%lf", val);
#endif
config_set_string(conf, key, buf);
}
@@ -358,11 +654,50 @@ bool config_file_write(config_file_t *conf, const char *path)
void config_file_dump(config_file_t *conf, FILE *file)
{
struct entry_list *list = conf->entries;
while (list != NULL)
struct include_list *includes = conf->includes;
while (includes)
{
fprintf(file, "%s = \"%s\"\n", list->key, list->value);
fprintf(file, "#include \"%s\"\n", includes->path);
includes = includes->next;
}
struct entry_list *list = conf->entries;
while (list)
{
if (!list->readonly)
fprintf(file, "%s = \"%s\"\n", list->key, list->value);
list = list->next;
}
}
void config_file_dump_all(config_file_t *conf, FILE *file)
{
struct include_list *includes = conf->includes;
while (includes)
{
fprintf(file, "#include \"%s\"\n", includes->path);
includes = includes->next;
}
struct entry_list *list = conf->entries;
while (list)
{
fprintf(file, "%s = \"%s\" %s\n", list->key, list->value, list->readonly ? "(included)" : "");
list = list->next;
}
}
bool config_entry_exists(config_file_t *conf, const char *entry)
{
struct entry_list *list = conf->entries;
while (list)
{
if (strcmp(entry, list->key) == 0)
return true;
list = list->next;
}
return false;
}
+26 -7
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -20,8 +20,9 @@
#define __CONFIG_FILE_H
#include <stdint.h>
#include <stdbool.h>
#include "../boolean.h"
#include <stdio.h>
#include <stddef.h>
typedef struct config_file config_file_t;
@@ -30,26 +31,43 @@ typedef struct config_file config_file_t;
// - # are treated as comments. Rest of the line is ignored.
// - Format is: key = value. There can be as many spaces as you like in-between.
// - Value can be wrapped inside "" for multiword strings. (foo = "hai u")
//
// - #include includes a config file in-place.
// Path is relative to where config file was loaded unless an absolute path is chosen.
// Key/value pairs from an #include are read-only, and cannot be modified.
// Loads a config file. Returns NULL if file doesn't exist. NULL path will create an empty config file.
// Loads a config file. Returns NULL if file doesn't exist.
// NULL path will create an empty config file.
config_file_t *config_file_new(const char *path);
// Frees config file.
void config_file_free(config_file_t *conf);
// All extract functions return true when value is valid and exists. Returns false otherwise.
// All extract functions return true when value is valid and exists.
// Returns false otherwise.
bool config_entry_exists(config_file_t *conf, const char *entry);
// Extracts a double from config file.
bool config_get_double(config_file_t *conf, const char *entry, double *in);
// Extracts a float from config file.
bool config_get_float(config_file_t *conf, const char *entry, float *in);
// Extracts an int from config file.
bool config_get_int(config_file_t *conf, const char *entry, int *in);
// Extracts an uint from config file.
bool config_get_uint(config_file_t *conf, const char *entry, unsigned *in);
// Extracts an int from config file. (Hexadecimal)
bool config_get_hex(config_file_t *conf, const char *entry, unsigned *in);
// Extracts a single char. If value consists of several chars, this is an error.
bool config_get_char(config_file_t *conf, const char *entry, char *in);
// Extracts an allocated string in *in. This must be free()-d if this function succeeds.
bool config_get_string(config_file_t *conf, const char *entry, char **in);
// Extracts a string to a preallocated buffer. Avoid memory allocation.
bool config_get_array(config_file_t *conf, const char *entry, char *in, size_t size);
// Extracts a boolean from config. Valid boolean true are "true" and "1". Valid false are "false" and "0". Other values will be treated as an error.
bool config_get_bool(config_file_t *conf, const char *entry, bool *in);
// Setters. Similiar to the getters.
// Setters. Similar to the getters. Will not write to entry if the entry
// was obtained from an #include.
void config_set_double(config_file_t *conf, const char *entry, double value);
void config_set_int(config_file_t *conf, const char *entry, int val);
void config_set_char(config_file_t *conf, const char *entry, char val);
@@ -61,7 +79,8 @@ bool config_file_write(config_file_t *conf, const char *path);
// Dump the current config to an already opened file. Does not close the file.
void config_file_dump(config_file_t *conf, FILE *file);
// Also dumps inherited values, useful for logging.
void config_file_dump_all(config_file_t *conf, FILE *file);
#endif
+159 -129
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -22,7 +22,7 @@
#ifndef __CONFIG_DEF_H
#define __CONFIG_DEF_H
#include <stdbool.h>
#include "boolean.h"
#include "libsnes.hpp"
#include "driver.h"
@@ -30,20 +30,16 @@
#include "config.h"
#endif
#ifdef HAVE_SDL
#include "SDL.h"
#else
#error HAVE_SDL is not defined!
#endif
#ifdef HAVE_SRC
#include <samplerate.h>
#endif
#include "input/keysym.h"
///////////////// Drivers
#define VIDEO_GL 0
#define VIDEO_XVIDEO 11
#define VIDEO_SDL 13
#define VIDEO_EXT 14
#define VIDEO_WII 24
#define VIDEO_XENON360 25
#define VIDEO_XDK360 28
////////////////////////
#define AUDIO_RSOUND 1
#define AUDIO_OSS 2
@@ -54,18 +50,49 @@
#define AUDIO_SDL 8
#define AUDIO_XAUDIO 9
#define AUDIO_PULSE 10
#define AUDIO_EXT 15
#define AUDIO_DSOUND 16
#define AUDIO_COREAUDIO 17
#define AUDIO_PS3 18
#define AUDIO_XENON360 20
#define AUDIO_WII 22
#define AUDIO_XDK360 27
////////////////////////
#define INPUT_SDL 7
#define INPUT_X 12
#define INPUT_PS3 19
#define INPUT_XENON360 21
#define INPUT_WII 23
#define INPUT_XDK360 26
////////////////////////
#if defined(HAVE_SDL)
#if defined(HAVE_OPENGL) || defined(__CELLOS_LV2__)
#define VIDEO_DEFAULT_DRIVER VIDEO_GL
#elif defined(GEKKO)
#define VIDEO_DEFAULT_DRIVER VIDEO_WII
#elif defined(XENON)
#define VIDEO_DEFAULT_DRIVER VIDEO_XENON360
#elif defined(_XBOX)
#define VIDEO_DEFAULT_DRIVER VIDEO_XDK360
#elif defined(HAVE_XVIDEO)
#define VIDEO_DEFAULT_DRIVER VIDEO_XVIDEO
#elif defined(HAVE_SDL)
#define VIDEO_DEFAULT_DRIVER VIDEO_SDL
#elif defined(HAVE_DYLIB)
#define VIDEO_DEFAULT_DRIVER VIDEO_EXT
#else
#error "Need at least one video driver!"
#endif
#if defined(HAVE_ALSA)
#if defined(__CELLOS_LV2__)
#define AUDIO_DEFAULT_DRIVER AUDIO_PS3
#elif defined(XENON)
#define AUDIO_DEFAULT_DRIVER AUDIO_XENON360
#elif defined(_XBOX)
#define AUDIO_DEFAULT_DRIVER AUDIO_XDK360
#elif defined(GEKKO)
#define AUDIO_DEFAULT_DRIVER AUDIO_WII
#elif defined(HAVE_ALSA)
#define AUDIO_DEFAULT_DRIVER AUDIO_ALSA
#elif defined(HAVE_PULSE)
#define AUDIO_DEFAULT_DRIVER AUDIO_PULSE
@@ -73,8 +100,12 @@
#define AUDIO_DEFAULT_DRIVER AUDIO_OSS
#elif defined(HAVE_JACK)
#define AUDIO_DEFAULT_DRIVER AUDIO_JACK
#elif defined(HAVE_COREAUDIO)
#define AUDIO_DEFAULT_DRIVER AUDIO_COREAUDIO
#elif defined(HAVE_AL)
#define AUDIO_DEFAULT_DRIVER AUDIO_AL
#elif defined(HAVE_DSOUND)
#define AUDIO_DEFAULT_DRIVER AUDIO_DSOUND
#elif defined(HAVE_SDL)
#define AUDIO_DEFAULT_DRIVER AUDIO_SDL
#elif defined(HAVE_XAUDIO)
@@ -83,14 +114,26 @@
#define AUDIO_DEFAULT_DRIVER AUDIO_RSOUND
#elif defined(HAVE_ROAR)
#define AUDIO_DEFAULT_DRIVER AUDIO_ROAR
#elif defined(HAVE_DYLIB)
#define AUDIO_DEFAULT_DRIVER AUDIO_EXT
#else
#error Need at least one audio driver!
#error "Need at least one audio driver!"
#endif
#if defined(HAVE_SDL)
#if defined(XENON)
#define INPUT_DEFAULT_DRIVER INPUT_XENON360
#elif defined(_XBOX)
#define INPUT_DEFAULT_DRIVER INPUT_XDK360
#elif defined(HAVE_SDL)
#define INPUT_DEFAULT_DRIVER INPUT_SDL
#elif defined(__CELLOS_LV2__)
#define INPUT_DEFAULT_DRIVER INPUT_PS3
#elif defined(GEKKO)
#define INPUT_DEFAULT_DRIVER INPUT_WII
#elif defined(HAVE_XVIDEO)
#define INPUT_DEFAULT_DRIVER INPUT_X
#else
#error "Need at least one input driver!"
#endif
@@ -99,14 +142,20 @@
////////////////
// Windowed
static const float xscale = 3.0; // Real x res = 296 * xscale
static const float yscale = 3.0; // Real y res = 224 * yscale
static const float xscale = 3.0; // Real x res = aspect * base_size * xscale
static const float yscale = 3.0; // Real y res = base_size * yscale
// Fullscreen
static const bool fullscreen = false; // To start in Fullscreen or not
static const unsigned fullscreen_x = 0; // Fullscreen resolution. A value of 0 uses the desktop resolution.
static const unsigned fullscreen_y = 0;
// Force 16-bit colors.
static const bool force_16bit = false;
// Forcibly disable composition. Only valid on Windows Vista/7 for now.
static const bool disable_composition = false;
// Video VSYNC (recommended)
static const bool vsync = true;
@@ -116,12 +165,20 @@ static const bool video_smooth = true;
// On resize and fullscreen, rendering area will stay 4:3
static const bool force_aspect = true;
// Crop overscanned frames (7/8 or 15/15 for interlaced frames).
static const bool crop_overscan = true;
// Font size for on-screen messages.
static const unsigned font_size = 48;
// Attempt to scale the font size.
// The scale factor will be window_size / desktop_size.
static const bool font_scale = true;
// Offset for where messages will be placed on-screen. Values are in range [0.0, 1.0].
static const float message_pos_offset_x = 0.05;
static const float message_pos_offset_y = 0.05;
// Color of the message.
static const uint32_t message_color = 0xffff00; // RGB hex value.
// Render-to-texture before rendering to screen (multi-pass shaders)
static const bool render_to_texture = false;
@@ -129,7 +186,28 @@ static const float fbo_scale_x = 2.0;
static const float fbo_scale_y = 2.0;
static const bool second_pass_smooth = true;
#define SNES_ASPECT_RATIO (4.0/3)
// Record video assuming game runs hi-res.
static const bool hires_record = false;
// Record post-filtered (CPU filter) video rather than raw SNES output.
static const bool post_filter_record = false;
// OSD-messages
static const bool font_enable = true;
// The accurate refresh rate of your monitor (Hz).
// This is used to calculate audio input rate with the formula:
// audio_input_rate = game_input_rate * display_refresh_rate / game_refresh_rate.
// If the implementation does not report any values,
// SNES NTSC defaults will be assumed for compatibility.
// This value should stay close to 60Hz to avoid large pitch changes.
// If your monitor does not run at 60Hz, or something close to it, disable VSync,
// and leave this at its default.
#if defined(__CELLOS_LV2__) || defined(XENON) || defined(GEKKO)
static const float refresh_rate = 59.92;
#else
static const float refresh_rate = 59.95;
#endif
////////////////
// Audio
@@ -141,15 +219,11 @@ static const bool audio_enable = true;
// Output samplerate
static const unsigned out_rate = 48000;
// Input samplerate from libSNES.
// Lower this (slightly) if you are experiencing frequent audio dropouts while vsync is enabled.
static const float in_rate = 31980.0;
// When changing input rate on-the-fly
static const float audio_rate_step = 0.25;
// Audio device (e.g. hw:0,0 or /dev/audio). If NULL, will use defaults.
static const char* audio_device = NULL;
static const char *audio_device = NULL;
// Desired audio latency in milliseconds. Might not be honored if driver can't provide given latency.
static const int out_latency = 64;
@@ -157,11 +231,6 @@ static const int out_latency = 64;
// Will sync audio. (recommended)
static const bool audio_sync = true;
// Defines the quality (and cpu reqirements) of samplerate conversion.
#ifdef HAVE_SRC
#define SAMPLERATE_QUALITY SRC_LINEAR
#endif
// Enables use of rewind. This will incur some memory footprint depending on the save state buffer.
// This rewind only works when using bSNES core atm.
static const bool rewind_enable = false;
@@ -173,13 +242,21 @@ static const unsigned rewind_buffer_size = 20 << 20; // 20MiB
static const unsigned rewind_granularity = 1;
// Pause gameplay when gameplay loses focus.
static const bool pause_nonactive = true;
static const bool pause_nonactive = false;
// Saves non-volatile SRAM at a regular interval. It is measured in seconds. A value of 0 disables autosave.
static const unsigned autosave_interval = 0;
// When being client over netplay, use keybinds for player 1 rather than player 2.
static const bool netplay_client_swap_input = false;
static const bool netplay_client_swap_input = true;
// On save state load, block SRAM from being overwritten.
// This could potentially lead to buggy games.
static const bool block_sram_overwrite = false;
// When saving savestates, state index is automatically incremented before saving.
// When the ROM is loaded, state index will be set to the highest existing value.
static const bool savestate_auto_index = false;
////////////////////
@@ -188,113 +265,66 @@ static const bool netplay_client_swap_input = false;
// Axis threshold (between 0.0 and 1.0)
// How far an axis must be tilted to result in a button press
#define AXIS_THRESHOLD 0.5
static const float axis_threshold = 0.5;
// To figure out which joypad buttons to use, check jstest or similar.
// SDL sometimes reverses the axes for some odd reason, but hey. :D
// Player 1
static const struct snes_keybind snes_keybinds_1[] = {
// SNES button | keyboard key | js btn | js axis |
{ SNES_DEVICE_ID_JOYPAD_A, SDLK_x, 1, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_B, SDLK_z, 0, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_X, SDLK_s, 3, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_Y, SDLK_a, 2, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_L, SDLK_q, 4, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_R, SDLK_w, 5, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_LEFT, SDLK_LEFT, 11, AXIS_NEG(0) },
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SDLK_RIGHT, 12, AXIS_POS(0) },
{ SNES_DEVICE_ID_JOYPAD_UP, SDLK_UP, 13, AXIS_NEG(1) },
{ SNES_DEVICE_ID_JOYPAD_DOWN, SDLK_DOWN, 14, AXIS_POS(1) },
{ SNES_DEVICE_ID_JOYPAD_START, SDLK_RETURN, 7, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_SELECT, SDLK_RSHIFT, 6, AXIS_NONE },
{ SSNES_FAST_FORWARD_KEY, SDLK_SPACE, 10, AXIS_NONE },
{ SSNES_SAVE_STATE_KEY, SDLK_F2, NO_BTN, AXIS_NONE },
{ SSNES_LOAD_STATE_KEY, SDLK_F4, NO_BTN, AXIS_NONE },
{ SSNES_FULLSCREEN_TOGGLE_KEY, SDLK_f, NO_BTN, AXIS_NONE },
{ SSNES_QUIT_KEY, SDLK_ESCAPE, NO_BTN, AXIS_NONE },
{ SSNES_STATE_SLOT_MINUS, SDLK_F6, NO_BTN, AXIS_NONE },
{ SSNES_STATE_SLOT_PLUS, SDLK_F7, NO_BTN, AXIS_NONE },
{ SSNES_AUDIO_INPUT_RATE_PLUS, SDLK_KP_PLUS, NO_BTN, AXIS_NONE },
{ SSNES_AUDIO_INPUT_RATE_MINUS, SDLK_KP_MINUS, NO_BTN, AXIS_NONE },
{ SSNES_REWIND, SDLK_r, NO_BTN, AXIS_NONE },
{ SSNES_MOVIE_RECORD_TOGGLE, SDLK_o, NO_BTN, AXIS_NONE },
{ SSNES_PAUSE_TOGGLE, SDLK_p, NO_BTN, AXIS_NONE },
{ SSNES_RESET, SDLK_h, NO_BTN, AXIS_NONE },
{ SSNES_SHADER_NEXT, SDLK_m, NO_BTN, AXIS_NONE },
{ SSNES_SHADER_PREV, SDLK_n, NO_BTN, AXIS_NONE },
// SNES button | keyboard key | js btn | js axis |
{ SNES_DEVICE_ID_JOYPAD_A, SK_x, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_B, SK_z, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_X, SK_s, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_Y, SK_a, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_L, SK_q, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_R, SK_w, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_LEFT, SK_LEFT, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SK_RIGHT, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_UP, SK_UP, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_DOWN, SK_DOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_START, SK_RETURN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_SELECT, SK_RSHIFT, NO_BTN, AXIS_NONE },
{ SSNES_FAST_FORWARD_KEY, SK_SPACE, NO_BTN, AXIS_NONE },
{ SSNES_FAST_FORWARD_HOLD_KEY, SK_l, NO_BTN, AXIS_NONE },
{ SSNES_SAVE_STATE_KEY, SK_F2, NO_BTN, AXIS_NONE },
{ SSNES_LOAD_STATE_KEY, SK_F4, NO_BTN, AXIS_NONE },
{ SSNES_FULLSCREEN_TOGGLE_KEY, SK_f, NO_BTN, AXIS_NONE },
{ SSNES_QUIT_KEY, SK_ESCAPE, NO_BTN, AXIS_NONE },
{ SSNES_STATE_SLOT_MINUS, SK_F6, NO_BTN, AXIS_NONE },
{ SSNES_STATE_SLOT_PLUS, SK_F7, NO_BTN, AXIS_NONE },
{ SSNES_AUDIO_INPUT_RATE_PLUS, SK_KP_PLUS, NO_BTN, AXIS_NONE },
{ SSNES_AUDIO_INPUT_RATE_MINUS, SK_KP_MINUS, NO_BTN, AXIS_NONE },
{ SSNES_REWIND, SK_r, NO_BTN, AXIS_NONE },
{ SSNES_MOVIE_RECORD_TOGGLE, SK_o, NO_BTN, AXIS_NONE },
{ SSNES_PAUSE_TOGGLE, SK_p, NO_BTN, AXIS_NONE },
{ SSNES_FRAMEADVANCE, SK_k, NO_BTN, AXIS_NONE },
{ SSNES_RESET, SK_h, NO_BTN, AXIS_NONE },
{ SSNES_SHADER_NEXT, SK_m, NO_BTN, AXIS_NONE },
{ SSNES_SHADER_PREV, SK_n, NO_BTN, AXIS_NONE },
{ SSNES_CHEAT_INDEX_PLUS, SK_y, NO_BTN, AXIS_NONE },
{ SSNES_CHEAT_INDEX_MINUS, SK_t, NO_BTN, AXIS_NONE },
{ SSNES_CHEAT_TOGGLE, SK_u, NO_BTN, AXIS_NONE },
{ SSNES_SCREENSHOT, SK_PRINT, NO_BTN, AXIS_NONE },
{ SSNES_DSP_CONFIG, SK_c, NO_BTN, AXIS_NONE },
{ SSNES_MUTE, SK_F9, NO_BTN, AXIS_NONE },
{ -1 }
};
// Player 2
static const struct snes_keybind snes_keybinds_2[] = {
// SNES button | keyboard key | js btn | js axis |
{ SNES_DEVICE_ID_JOYPAD_A, SDLK_b, 1, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_B, SDLK_v, 0, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_X, SDLK_g, 3, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_Y, SDLK_f, 2, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_L, SDLK_r, 4, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_R, SDLK_t, 5, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_LEFT, SDLK_j, 11, AXIS_NEG(0) },
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SDLK_l, 12, AXIS_POS(0) },
{ SNES_DEVICE_ID_JOYPAD_UP, SDLK_i, 13, AXIS_NEG(1) },
{ SNES_DEVICE_ID_JOYPAD_DOWN, SDLK_k, 14, AXIS_POS(1) },
{ SNES_DEVICE_ID_JOYPAD_START, SDLK_p, 6, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_SELECT, SDLK_o, 7, AXIS_NONE },
{ -1 }
};
// Player 3
static const struct snes_keybind snes_keybinds_3[] = {
// SNES button | keyboard key | js btn | js axis |
{ SNES_DEVICE_ID_JOYPAD_A, SDLK_b, 1, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_B, SDLK_v, 0, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_X, SDLK_g, 3, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_Y, SDLK_f, 2, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_L, SDLK_r, 4, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_R, SDLK_t, 5, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_LEFT, SDLK_j, 11, AXIS_NEG(0) },
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SDLK_l, 12, AXIS_POS(0) },
{ SNES_DEVICE_ID_JOYPAD_UP, SDLK_i, 13, AXIS_NEG(1) },
{ SNES_DEVICE_ID_JOYPAD_DOWN, SDLK_k, 14, AXIS_POS(1) },
{ SNES_DEVICE_ID_JOYPAD_START, SDLK_p, 6, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_SELECT, SDLK_o, 7, AXIS_NONE },
{ -1 }
};
// Player 4
static const struct snes_keybind snes_keybinds_4[] = {
// SNES button | keyboard key | js btn | js axis |
{ SNES_DEVICE_ID_JOYPAD_A, SDLK_b, 1, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_B, SDLK_v, 0, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_X, SDLK_g, 3, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_Y, SDLK_f, 2, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_L, SDLK_r, 4, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_R, SDLK_t, 5, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_LEFT, SDLK_j, 11, AXIS_NEG(0) },
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SDLK_l, 12, AXIS_POS(0) },
{ SNES_DEVICE_ID_JOYPAD_UP, SDLK_i, 13, AXIS_NEG(1) },
{ SNES_DEVICE_ID_JOYPAD_DOWN, SDLK_k, 14, AXIS_POS(1) },
{ SNES_DEVICE_ID_JOYPAD_START, SDLK_p, 6, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_SELECT, SDLK_o, 7, AXIS_NONE },
{ -1 }
};
// Player 5
static const struct snes_keybind snes_keybinds_5[] = {
// SNES button | keyboard key | js btn | js axis |
{ SNES_DEVICE_ID_JOYPAD_A, SDLK_b, 1, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_B, SDLK_v, 0, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_X, SDLK_g, 3, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_Y, SDLK_f, 2, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_L, SDLK_r, 4, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_R, SDLK_t, 5, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_LEFT, SDLK_j, 11, AXIS_NEG(0) },
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SDLK_l, 12, AXIS_POS(0) },
{ SNES_DEVICE_ID_JOYPAD_UP, SDLK_i, 13, AXIS_NEG(1) },
{ SNES_DEVICE_ID_JOYPAD_DOWN, SDLK_k, 14, AXIS_POS(1) },
{ SNES_DEVICE_ID_JOYPAD_START, SDLK_p, 6, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_SELECT, SDLK_o, 7, AXIS_NONE },
// Player 2-5
static const struct snes_keybind snes_keybinds_rest[] = {
{ SNES_DEVICE_ID_JOYPAD_A, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_B, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_X, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_Y, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_L, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_R, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_LEFT, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_RIGHT, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_UP, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_DOWN, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_START, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ SNES_DEVICE_ID_JOYPAD_SELECT, SK_UNKNOWN, NO_BTN, AXIS_NONE },
{ -1 }
};
+44 -8
View File
@@ -2,7 +2,7 @@
#define __SSNES_FEATURES_H
#include <stddef.h>
#include <stdbool.h>
#include "boolean.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -14,13 +14,31 @@ static const bool _sdl_supp = true;
static const bool _sdl_supp = false;
#endif
#ifdef HAVE_THREADS
static const bool _thread_supp = true;
#else
static const bool _thread_supp = false;
#endif
#ifdef HAVE_OPENGL
static const bool _opengl_supp = true;
#else
static const bool _opengl_supp = false;
#endif
#ifdef HAVE_XVIDEO
static const bool _xvideo_supp = true;
#else
static const bool _xvideo_supp = false;
#endif
#ifdef HAVE_ALSA
static const bool _alsa_supp = true;
#else
static const bool _alsa_supp = false;
#endif
#ifdef HAVE_OSS
#if defined(HAVE_OSS) || defined(HAVE_OSS_BSD)
static const bool _oss_supp = true;
#else
static const bool _oss_supp = false;
@@ -56,16 +74,22 @@ static const bool _pulse_supp = true;
static const bool _pulse_supp = false;
#endif
#ifdef HAVE_DSOUND
static const bool _dsound_supp = true;
#else
static const bool _dsound_supp = false;
#endif
#ifdef HAVE_XAUDIO
static const bool _xaudio_supp = true;
#else
static const bool _xaudio_supp = false;
#endif
#ifdef HAVE_FILTER
static const bool _filter_supp = true;
#ifdef HAVE_DYLIB
static const bool _dylib_supp = true;
#else
static const bool _filter_supp = false;
static const bool _dylib_supp = false;
#endif
#ifdef HAVE_CG
@@ -80,6 +104,12 @@ static const bool _xml_supp = true;
static const bool _xml_supp = false;
#endif
#ifdef HAVE_SDL_IMAGE
static const bool _sdl_image_supp = true;
#else
static const bool _sdl_image_supp = false;
#endif
#ifdef HAVE_FBO
static const bool _fbo_supp = true;
#else
@@ -98,10 +128,10 @@ static const bool _ffmpeg_supp = true;
static const bool _ffmpeg_supp = false;
#endif
#ifdef HAVE_SRC
static const bool _src_supp = true;
#ifdef HAVE_X264RGB
static const bool _x264rgb_supp = true;
#else
static const bool _src_supp = false;
static const bool _x264rgb_supp = false;
#endif
#ifdef HAVE_CONFIGFILE
@@ -122,4 +152,10 @@ static const bool _netplay_supp = true;
static const bool _netplay_supp = false;
#endif
#ifdef HAVE_PYTHON
static const bool _python_supp = true;
#else
static const bool _python_supp = false;
#endif
#endif
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 192 KiB

+118
View File
@@ -0,0 +1,118 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "list.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
struct sgui_file
{
char *path;
sgui_file_type_t type;
};
struct sgui_list
{
struct sgui_file *list;
size_t capacity;
size_t ptr;
};
sgui_list_t *sgui_list_new(void)
{
return (sgui_list_t*)calloc(1, sizeof(sgui_list_t));
}
bool sgui_list_empty(const sgui_list_t *list)
{
return list->ptr == 0;
}
void sgui_list_push(sgui_list_t *list, const char *path, sgui_file_type_t type)
{
if (list->ptr >= list->capacity)
{
list->capacity++;
list->capacity *= 2;
list->list = (struct sgui_file*)realloc(list->list, list->capacity * sizeof(struct sgui_file));
}
list->list[list->ptr].path = strdup(path);
list->list[list->ptr].type = type;
list->ptr++;
}
void sgui_list_pop(sgui_list_t *list)
{
if (!sgui_list_empty(list))
free(list->list[--list->ptr].path);
}
void sgui_list_free(sgui_list_t *list)
{
for (size_t i = 0; i < list->ptr; i++)
free(list->list[i].path);
free(list->list);
free(list);
}
void sgui_list_clear(sgui_list_t *list)
{
for (size_t i = 0; i < list->ptr; i++)
free(list->list[i].path);
list->ptr = 0;
}
void sgui_list_back(const sgui_list_t *list,
const char **path, sgui_file_type_t *file_type)
{
if (sgui_list_size(list) > 0)
sgui_list_at(list, sgui_list_size(list) - 1, path, file_type);
}
size_t sgui_list_size(const sgui_list_t *list)
{
return list->ptr;
}
void sgui_list_at(const sgui_list_t *list, size_t index,
const char **path, sgui_file_type_t *file_type)
{
if (path)
*path = list->list[index].path;
if (file_type)
*file_type = list->list[index].type;
}
static int list_comp(const void *a_, const void *b_)
{
const struct sgui_file *a = (const struct sgui_file*)a_;
const struct sgui_file *b = (const struct sgui_file*)b_;
if (a->type != b->type)
return a->type == SGUI_FILE_DIRECTORY ? -1 : 1;
return strcmp(a->path, b->path);
}
void sgui_list_sort(sgui_list_t *list)
{
qsort(list->list, list->ptr, sizeof(struct sgui_file), list_comp);
}
+51
View File
@@ -0,0 +1,51 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SGUI_LIST_H__
#define SGUI_LIST_H__
#include "sgui.h"
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct sgui_list sgui_list_t;
sgui_list_t *sgui_list_new(void);
void sgui_list_free(sgui_list_t *list);
void sgui_list_push(sgui_list_t *list, const char *path, sgui_file_type_t type);
void sgui_list_pop(sgui_list_t *list);
void sgui_list_clear(sgui_list_t *list);
bool sgui_list_empty(const sgui_list_t *list);
void sgui_list_back(const sgui_list_t *list,
const char **path, sgui_file_type_t *type);
size_t sgui_list_size(const sgui_list_t *list);
void sgui_list_at(const sgui_list_t *list, size_t index,
const char **path, sgui_file_type_t *type);
void sgui_list_sort(sgui_list_t *list);
#ifdef __cplusplus
}
#endif
#endif
+314
View File
@@ -0,0 +1,314 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "sgui.h"
#include "list.h"
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#define FONT_WIDTH 5
#define FONT_HEIGHT 10
#define FONT_WIDTH_STRIDE (FONT_WIDTH + 1)
#define FONT_HEIGHT_STRIDE (FONT_HEIGHT + 1)
#define TERM_WIDTH (((SGUI_WIDTH - 30) / (FONT_WIDTH_STRIDE)))
#define TERM_HEIGHT (((SGUI_HEIGHT - 30) / (FONT_HEIGHT_STRIDE)))
#define TERM_START_X 15
#define TERM_START_Y 15
struct sgui_handle
{
uint16_t *frame_buf;
size_t frame_buf_pitch;
const uint8_t *font_buf;
sgui_folder_enum_cb_t folder_cb;
void *userdata;
sgui_list_t *path_stack;
sgui_list_t *folder_buf;
size_t directory_ptr;
bool need_refresh;
char path_buf[PATH_MAX];
uint16_t font_white[256][FONT_HEIGHT][FONT_WIDTH];
uint16_t font_green[256][FONT_HEIGHT][FONT_WIDTH];
};
static void copy_glyph(uint16_t glyph_white[FONT_HEIGHT][FONT_WIDTH],
uint16_t glyph_green[FONT_HEIGHT][FONT_WIDTH],
const uint8_t *buf)
{
for (int y = 0; y < FONT_HEIGHT; y++)
{
for (int x = 0; x < FONT_WIDTH; x++)
{
uint32_t col =
((uint32_t)buf[3 * (-y * 256 + x) + 0] << 0) |
((uint32_t)buf[3 * (-y * 256 + x) + 1] << 8) |
((uint32_t)buf[3 * (-y * 256 + x) + 2] << 16);
glyph_white[y][x] = col == 0xff ? 0 : 0x7fff;
glyph_green[y][x] = col == 0xff ? 0 : (5 << 10) | (20 << 5) | (5 << 0);
}
}
}
static void init_font(sgui_handle_t *sgui, const char *path)
{
for (unsigned i = 0; i < 256; i++)
{
unsigned y = i / 16;
unsigned x = i % 16;
copy_glyph(sgui->font_white[i],
sgui->font_green[i],
sgui->font_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x));
}
}
sgui_handle_t *sgui_init(const char *base_path,
uint16_t *buf, size_t buf_pitch,
const uint8_t *font_buf,
sgui_folder_enum_cb_t folder_cb, void *userdata)
{
sgui_handle_t *sgui = (sgui_handle_t*)calloc(1, sizeof(*sgui));
sgui->frame_buf = buf;
sgui->frame_buf_pitch = buf_pitch;
sgui->font_buf = font_buf;
sgui->folder_cb = folder_cb;
sgui->userdata = userdata;
sgui->path_stack = sgui_list_new();
sgui->folder_buf = sgui_list_new();
sgui_list_push(sgui->path_stack, base_path, SGUI_FILE_DIRECTORY);
init_font(sgui, "font.bmp");
return sgui;
}
void sgui_free(sgui_handle_t *sgui)
{
sgui_list_free(sgui->path_stack);
sgui_list_free(sgui->folder_buf);
free(sgui);
}
static uint16_t gray_filler(unsigned x, unsigned y)
{
x >>= 1;
y >>= 1;
uint16_t col = ((x + y) & 1) + 1;
col <<= 1;
return (col << 0) | (col << 5) | (col << 10);
}
static uint16_t green_filler(unsigned x, unsigned y)
{
x >>= 1;
y >>= 1;
uint16_t col = ((x + y) & 1) + 1;
col <<= 1;
return (col << 0) | (col << 6) | (col << 10);
}
static void fill_rect(uint16_t *buf, unsigned pitch,
unsigned x, unsigned y,
unsigned width, unsigned height,
uint16_t (*col)(unsigned x, unsigned y))
{
for (unsigned j = y; j < y + height; j++)
for (unsigned i = x; i < x + width; i++)
buf[j * (pitch >> 1) + i] = col(i, j);
}
static void blit_line(sgui_handle_t *sgui,
unsigned x, unsigned y, const char *message, bool green)
{
while (*message)
{
for (unsigned j = 0; j < FONT_HEIGHT; j++)
{
for (unsigned i = 0; i < FONT_WIDTH; i++)
{
uint16_t col = green ?
sgui->font_green[(unsigned char)*message][j][i] :
sgui->font_white[(unsigned char)*message][j][i];
if (col)
sgui->frame_buf[(y + j) * (sgui->frame_buf_pitch >> 1) + (x + i)] = col;
}
}
x += FONT_WIDTH_STRIDE;
message++;
}
}
static void render_text(sgui_handle_t *sgui, size_t begin, size_t end)
{
fill_rect(sgui->frame_buf, sgui->frame_buf_pitch,
0, 0, SGUI_WIDTH, SGUI_HEIGHT, gray_filler);
fill_rect(sgui->frame_buf, sgui->frame_buf_pitch,
5, 5, SGUI_WIDTH - 10, 5, green_filler);
fill_rect(sgui->frame_buf, sgui->frame_buf_pitch,
5, SGUI_HEIGHT - 10, SGUI_WIDTH - 10, 5, green_filler);
fill_rect(sgui->frame_buf, sgui->frame_buf_pitch,
5, 5, 5, SGUI_HEIGHT - 10, green_filler);
fill_rect(sgui->frame_buf, sgui->frame_buf_pitch,
SGUI_WIDTH - 10, 5, 5, SGUI_HEIGHT - 10, green_filler);
unsigned x = TERM_START_X;
unsigned y = TERM_START_Y;
for (size_t i = begin; i < end; i++, y += FONT_HEIGHT_STRIDE)
{
const char *path;
sgui_file_type_t type;
sgui_list_at(sgui->folder_buf, i, &path, &type);
char message[TERM_WIDTH + 1];
snprintf(message, sizeof(message), "%c %-*s %6s\n",
i == sgui->directory_ptr ? '>' : ' ',
TERM_WIDTH - (6 + 1 + 2),
path,
type == SGUI_FILE_PLAIN ? "(FILE)" : "(DIR)");
blit_line(sgui, x, y, message, i == sgui->directory_ptr);
}
}
const char *sgui_iterate(sgui_handle_t *sgui, sgui_action_t action)
{
switch (action)
{
case SGUI_ACTION_UP:
if (sgui->directory_ptr > 0)
sgui->directory_ptr--;
break;
case SGUI_ACTION_DOWN:
if (sgui->directory_ptr + 1 < sgui_list_size(sgui->folder_buf))
sgui->directory_ptr++;
break;
case SGUI_ACTION_LEFT:
case SGUI_ACTION_CANCEL:
if (sgui_list_size(sgui->path_stack) > 1)
{
sgui_list_pop(sgui->path_stack);
sgui->need_refresh = true;
}
break;
case SGUI_ACTION_RIGHT:
case SGUI_ACTION_OK:
{
if (sgui_list_size(sgui->folder_buf) == 0)
return NULL;
const char *path = NULL;
sgui_file_type_t type = SGUI_FILE_PLAIN;
sgui_list_at(sgui->folder_buf, sgui->directory_ptr,
&path, &type);
const char *dir;
sgui_list_back(sgui->path_stack, &dir, NULL);
if (type == SGUI_FILE_DIRECTORY)
{
char cat_path[PATH_MAX];
snprintf(cat_path, sizeof(cat_path), "%s/%s",
strcmp(dir, "/") == 0 ? "" : dir, path);
sgui_list_push(sgui->path_stack, cat_path, SGUI_FILE_DIRECTORY);
sgui->need_refresh = true;
}
else
{
snprintf(sgui->path_buf, sizeof(sgui->path_buf), "%s/%s",
strcmp(dir, "/") == 0 ? "" : dir, path);
return sgui->path_buf;
}
break;
}
case SGUI_ACTION_REFRESH:
sgui->need_refresh = true;
break;
default:
return NULL;
}
if (sgui->need_refresh)
{
sgui->directory_ptr = 0;
sgui_list_clear(sgui->folder_buf);
const char *path = NULL;
sgui_list_back(sgui->path_stack, &path, NULL);
if (!sgui->folder_cb(path,
(sgui_file_enum_cb_t)sgui_list_push,
sgui->userdata, sgui->folder_buf))
return NULL;
sgui_list_sort(sgui->folder_buf);
sgui->need_refresh = false;
}
size_t begin = sgui->directory_ptr >= TERM_HEIGHT / 2 ?
sgui->directory_ptr - TERM_HEIGHT / 2 : 0;
size_t end = sgui->directory_ptr + TERM_HEIGHT <= sgui_list_size(sgui->folder_buf) ?
sgui->directory_ptr + TERM_HEIGHT : sgui_list_size(sgui->folder_buf);
if (end - begin > TERM_HEIGHT)
end = begin + TERM_HEIGHT;
#if 0
printf("========================================\n");
for (size_t i = begin; i < end; i++)
{
const char *path;
sgui_file_type_t type;
sgui_list_at(sgui->folder_buf, i, &path, &type);
printf("%c %-50s %s\n",
i == sgui->directory_ptr ? '>' : ' ',
path,
type == SGUI_FILE_PLAIN ? "(FILE)" : "(DIR)");
}
printf("========================================\n");
#endif
render_text(sgui, begin, end);
return NULL;
}
+71
View File
@@ -0,0 +1,71 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SGUI_H__
#define SGUI_H__
#include <stdint.h>
#include <stddef.h>
#ifndef __cplusplus
#include <stdbool.h>
#else
extern "C" {
#endif
typedef enum
{
SGUI_FILE_PLAIN,
SGUI_FILE_DIRECTORY
} sgui_file_type_t;
typedef enum
{
SGUI_ACTION_UP,
SGUI_ACTION_DOWN,
SGUI_ACTION_LEFT,
SGUI_ACTION_RIGHT,
SGUI_ACTION_OK,
SGUI_ACTION_CANCEL,
SGUI_ACTION_REFRESH,
SGUI_ACTION_NOOP
} sgui_action_t;
typedef struct sgui_handle sgui_handle_t;
typedef void (*sgui_file_enum_cb_t)(void *ctx, const char *path,
sgui_file_type_t file_type);
typedef bool (*sgui_folder_enum_cb_t)(const char *directory,
sgui_file_enum_cb_t file_cb, void *userdata, void *ctx);
#define SGUI_WIDTH 320
#define SGUI_HEIGHT 240
sgui_handle_t *sgui_init(const char *base_path,
uint16_t *framebuf, size_t framebuf_pitch,
const uint8_t *font_buf,
sgui_folder_enum_cb_t folder_cb, void *userdata);
const char *sgui_iterate(sgui_handle_t *sgui, sgui_action_t action);
void sgui_free(sgui_handle_t *sgui);
#ifdef __cplusplus
}
#endif
#endif
+1 -1
View File
@@ -1,6 +1,6 @@
.\" ssnes-joyconfig.1:
.TH "SSNES-JOYCONFIG" "1" "January 2011" "SSNES-JOYCONFIG" "System Manager's Manual: ssnes-joyconfig"
.TH "SSNES-JOYCONFIG" "1" "October 2011" "SSNES-JOYCONFIG" "System Manager's Manual: ssnes-joyconfig"
.SH NAME
+68 -3
View File
@@ -1,6 +1,6 @@
.\" ssnes.1:
.TH "SSNES" "1" "January 2011" "SSNES" "System Manager's Manual: ssnes"
.TH "SSNES" "1" "November 2011" "SSNES" "System Manager's Manual: ssnes"
.SH NAME
@@ -27,24 +27,45 @@ If no rom file path is defined on the command line, \fBssnes\fR will try to load
\fB--help, -h\fR
Prints help text.
.TP
\fB--features\fR
Prints available features compiled into SSNES, then exits.
.TP
\fB-L PATH, --libsnes PATH\fR
Path to a libsnes implementation which is to be used.
This option will override any setting in a config file.
This option is only available if SSNES is compiled with dynamic libsnes loading.
.TP
\fB--save PATH, -s PATH\fR
Overrides the path used for save ram (*.srm).
Without this flag, the save ram path will be inferred from the rom path name, and put in the same directory as the rom file with the extention replaced with '.srm'.
When rom is loaded from \fBstdin\fR, this flag is mandatory to define as no path can be inferred.
If PATH is a directory, SSNES will treat this as the save file directory, where the save file name will be inferred from the rom name.
When loading a rom from stdin, the path must be a full path, however.
.TP
\fB--savestate PATH, -S path\fR
\fB--savestate PATH, -S PATH\fR
Overrides the path used for save states.
Without this flag, the save state path will be inferred from the rom path name, and put in the same directory as the rom file with the extention replace with '.state'.
When rom is loaded from \fBstdin\fR, this flag is mandatory to define as no path can be inferred.
If PATH is a directory, SSNES will treat this as the save state directory, where the state file name will be inferred from the rom name.
When loading a rom from stdin, the path must be a full path, however.
Do note that save states are bound to the libsnes implementation being used. Using a different libsnes could invalidate the save state file.
.TP
\fB--fullscreen, -f\fR
Always starts SSNES in fullscreen. Disregards settings in configuration file.
.TP
\fB--config PATH, -c PATH\fR
Sets the configuration file path. \fBssnes\fR will use this path to load the configuration file.
Should this not be defined, \fBssnes\fR will look in platform specific paths to attempt finding the config file.
/etc/ssnes.cfg (when installed), or ssnes.cfg in the source tarball serves as a skeleton configuration file.
If PATH is a directory, SSNES will treat this as the config file directory, where the state file name will be inferred from the rom name (*.cfg).
When loading a rom from stdin, the path must be a full path, however.
If a config cannot be found when using directory path, the default config path will be used instead.
.IP
Unix-like systems will look in $XDG_CONFIG_HOME/ssnes/ssnes.cfg first. Then it will try $HOME/.ssnes.cfg. Last, it will try /etc/ssnes.cfg. If no configuration is found, default settings will be assumed. A configuration file does not need to define every possible option, only those that should be overridden.
@@ -80,6 +101,10 @@ When using Sufami, save ram paths will be inferred from the Sufami BIOS path, no
\fB--mouse PORT, -m PORT\fR
Connects a Super Nintendo Mouse into port number PORT of the emulated SNES. Possible values for PORT are 1 and 2.
.TP
\fB--nodevice PORT, -N PORT\fR
Disconnects an input device from port number PORT of the emulated SNES. Possible values for PORT are 1 and 2. This may be needed for some odd games to run properly.
.TP
\fB--scope, -p\fR
Connects a Super Scope into port 2 of the SNES. It is controlled with your mouse.
@@ -98,13 +123,30 @@ Connects a four-way multitap into port 2 of the SNES. This allows for up to 5 pl
.TP
\fB--record PATH, -r PATH\fR
Activates video recording of gameplay into PATH. Video recording options can be configured in config file.
Activates video recording of gameplay into PATH. Using .mkv extension is recommended.
Codecs used are (FFV1 or H264 RGB lossless (x264))/FLAC, suitable for processing the material further.
.TP
\fB--size WIDTHxHEIGHT\fR
Allows specifying the exact output width and height of FFmpeg recording. This option will override any configuration settings.
The video input is scaled with point filtering before being encoded at the correct size.
.TP
\fB--bsvplay PATH, -P PATH\fR
Play back a movie recorded in the .bsv format (bSNES). Cart ROM and movie file need to correspond.
It also requires to play back with the same libsnes backend that was used for recording.
.TP
\fB--bsvrecord PATH, -R PATH\fR
Start recording a .bsv video to PATH immediately after startup.
.TP
\fB--sram-mode MODE, -M MODE\fR
MODE designates how to handle SRAM.
The format of the second parameter is {no,}load-{no,}save.
These two boolean values tell if SRAM loading and SRAM saving should take place.
Note that noload-save implies that the SRAM will be overwritten with new data.
.TP
\fB--verbose, -v\fR
Activates verbose logging.
@@ -126,10 +168,33 @@ Set FRAMES to 0 to have perfect sync. 0 frames is only suitable for LAN. Default
\fB--port PORT\fR
Network port used for netplay. This defaults to 55435. This option affects both TCP and UDP.
.TP
\fB--spectate\fR
If netplay is used, it will go into a spectator mode.
Spectator mode allows one host to live stream game playback to multiple clients.
Essentially, clients receive a live streamed BSV movie file.
Clients can connect and disconnect at any time.
Clients thus cannot interact as player 2.
For spectating mode to work, both host and clients will need to use this flag.
.TP
\fB--ups PATCH, -U PATCH\fR
Attempts to apply an UPS patch to the current ROM image. No files are altered.
If this flag is not specified, SSNES will look for a .ups file with same basename as ROM specified.
.TP
\fB--bps PATCH\fR
Attempts to apply a BPS patch to the current ROM image. No files are altered.
If this flag is not specified, SSNES will look for a .bps file with same basename as ROM specified.
.TP
\fB--xml MAP, -X MAP\fR
Specifies path to XML memory map for the given ROM.
If this flag is not specified, SSNES will look for a .xml file with same basename as ROM specified.
.TP
\fB-D, --detach\fR
Detach from the current console. This is currently only relevant for Microsoft Windows.
.SH "SEE ALSO"
\fBssnes-joyconfig\fR(1)
+291 -92
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -21,8 +21,8 @@
#include "file.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include "posix_string.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -32,12 +32,15 @@ static const audio_driver_t *audio_drivers[] = {
#ifdef HAVE_ALSA
&audio_alsa,
#endif
#ifdef HAVE_OSS
#if defined(HAVE_OSS) || defined(HAVE_OSS_BSD)
&audio_oss,
#endif
#ifdef HAVE_RSOUND
&audio_rsound,
#endif
#ifdef HAVE_COREAUDIO
&audio_coreaudio,
#endif
#ifdef HAVE_AL
&audio_openal,
#endif
@@ -53,32 +56,77 @@ static const audio_driver_t *audio_drivers[] = {
#ifdef HAVE_XAUDIO
&audio_xa,
#endif
#ifdef HAVE_DSOUND
&audio_dsound,
#endif
#ifdef HAVE_PULSE
&audio_pulse,
#endif
#ifdef HAVE_DYLIB
&audio_ext,
#endif
#ifdef __CELLOS_LV2__
&audio_ps3,
#endif
#ifdef XENON
&audio_xenon360,
#endif
#ifdef _XBOX
&audio_xdk360,
#endif
#ifdef GEKKO
&audio_wii,
#endif
};
static const video_driver_t *video_drivers[] = {
#ifdef HAVE_SDL
#ifdef HAVE_OPENGL
&video_gl,
#endif
#ifdef XENON
&video_xenon360,
#endif
#ifdef _XBOX
&video_xdk360,
#endif
#ifdef HAVE_SDL
&video_sdl,
#endif
#ifdef HAVE_XVIDEO
&video_xvideo,
#endif
#ifdef HAVE_DYLIB
&video_ext,
#endif
#ifdef GEKKO
&video_wii,
#endif
};
static const input_driver_t *input_drivers[] = {
#ifdef __CELLOS_LV2__
&input_ps3,
#endif
#ifdef HAVE_SDL
&input_sdl,
#endif
//#ifdef HAVE_XVIDEO
// &input_x,
//#endif
#ifdef HAVE_XVIDEO
&input_x,
#endif
#ifdef XENON
&input_xenon360,
#endif
#ifdef _XBOX
&input_xdk360,
#endif
#ifdef GEKKO
&input_wii,
#endif
};
static void find_audio_driver(void)
{
for (int i = 0; i < sizeof(audio_drivers) / sizeof(audio_driver_t*); i++)
for (unsigned i = 0; i < sizeof(audio_drivers) / sizeof(audio_driver_t*); i++)
{
if (strcasecmp(g_settings.audio.driver, audio_drivers[i]->ident) == 0)
{
@@ -88,15 +136,15 @@ static void find_audio_driver(void)
}
SSNES_ERR("Couldn't find any audio driver named \"%s\"\n", g_settings.audio.driver);
fprintf(stderr, "Available audio drivers are:\n");
for (int i = 0; i < sizeof(audio_drivers) / sizeof(audio_driver_t*); i++)
for (size_t i = 0; i < sizeof(audio_drivers) / sizeof(audio_driver_t*); i++)
fprintf(stderr, "\t%s\n", audio_drivers[i]->ident);
exit(1);
ssnes_fail(1, "find_audio_driver()");
}
static void find_video_driver(void)
{
for (int i = 0; i < sizeof(video_drivers) / sizeof(video_driver_t*); i++)
for (unsigned i = 0; i < sizeof(video_drivers) / sizeof(video_driver_t*); i++)
{
if (strcasecmp(g_settings.video.driver, video_drivers[i]->ident) == 0)
{
@@ -106,15 +154,15 @@ static void find_video_driver(void)
}
SSNES_ERR("Couldn't find any video driver named \"%s\"\n", g_settings.video.driver);
fprintf(stderr, "Available video drivers are:\n");
for (int i = 0; i < sizeof(video_drivers) / sizeof(video_driver_t*); i++)
for (size_t i = 0; i < sizeof(video_drivers) / sizeof(video_driver_t*); i++)
fprintf(stderr, "\t%s\n", video_drivers[i]->ident);
exit(1);
ssnes_fail(1, "find_video_driver()");
}
static void find_input_driver(void)
{
for (int i = 0; i < sizeof(input_drivers) / sizeof(input_driver_t*); i++)
for (unsigned i = 0; i < sizeof(input_drivers) / sizeof(input_driver_t*); i++)
{
if (strcasecmp(g_settings.input.driver, input_drivers[i]->ident) == 0)
{
@@ -124,10 +172,10 @@ static void find_input_driver(void)
}
SSNES_ERR("Couldn't find any input driver named \"%s\"\n", g_settings.input.driver);
fprintf(stderr, "Available input drivers are:\n");
for (int i = 0; i < sizeof(input_drivers) / sizeof(input_driver_t*); i++)
fprintf(stderr, "\t%s\n", video_drivers[i]->ident);
for (size_t i = 0; i < sizeof(input_drivers) / sizeof(input_driver_t*); i++)
fprintf(stderr, "\t%s\n", input_drivers[i]->ident);
exit(1);
ssnes_fail(1, "find_input_driver()");
}
void init_drivers(void)
@@ -138,28 +186,139 @@ void init_drivers(void)
void uninit_drivers(void)
{
uninit_video_input();
uninit_audio();
uninit_video_input();
}
#ifdef HAVE_DYLIB
static void init_dsp_plugin(void)
{
if (!(*g_settings.audio.dsp_plugin))
return;
ssnes_dsp_info_t info = {0};
g_extern.audio_data.dsp_lib = dylib_load(g_settings.audio.dsp_plugin);
if (!g_extern.audio_data.dsp_lib)
{
SSNES_ERR("Failed to open DSP plugin: \"%s\" ...\n", g_settings.audio.dsp_plugin);
return;
}
const ssnes_dsp_plugin_t* (SSNES_API_CALLTYPE *plugin_init)(void) =
(const ssnes_dsp_plugin_t *(SSNES_API_CALLTYPE*)(void))dylib_proc(g_extern.audio_data.dsp_lib, "ssnes_dsp_plugin_init");
if (!plugin_init)
{
SSNES_ERR("Failed to find symbol \"ssnes_dsp_plugin_init\" in DSP plugin.\n");
goto error;
}
g_extern.audio_data.dsp_plugin = plugin_init();
if (!g_extern.audio_data.dsp_plugin)
{
SSNES_ERR("Failed to get a valid DSP plugin.\n");
goto error;
}
if (g_extern.audio_data.dsp_plugin->api_version != SSNES_DSP_API_VERSION)
{
SSNES_ERR("DSP plugin API mismatch! SSNES: %d, Plugin: %d\n", SSNES_DSP_API_VERSION, g_extern.audio_data.dsp_plugin->api_version);
goto error;
}
SSNES_LOG("Loaded DSP plugin: \"%s\"\n", g_extern.audio_data.dsp_plugin->ident ? g_extern.audio_data.dsp_plugin->ident : "Unknown");
info.input_rate = g_settings.audio.in_rate;
info.output_rate = g_settings.audio.out_rate;
g_extern.audio_data.dsp_handle = g_extern.audio_data.dsp_plugin->init(&info);
if (!g_extern.audio_data.dsp_handle)
{
SSNES_ERR("Failed to init DSP plugin.\n");
goto error;
}
return;
error:
if (g_extern.audio_data.dsp_lib)
dylib_close(g_extern.audio_data.dsp_lib);
g_extern.audio_data.dsp_plugin = NULL;
g_extern.audio_data.dsp_lib = NULL;
}
static void deinit_dsp_plugin(void)
{
if (g_extern.audio_data.dsp_lib && g_extern.audio_data.dsp_plugin)
{
g_extern.audio_data.dsp_plugin->free(g_extern.audio_data.dsp_handle);
dylib_close(g_extern.audio_data.dsp_lib);
}
}
#endif
static void adjust_audio_input_rate(void)
{
static bool first = true;
if (!first)
return;
if (g_extern.system.timing_set)
{
float timing_skew = fabs(1.0f - g_extern.system.timing.fps / g_settings.video.refresh_rate);
if (timing_skew > 0.05f) // We don't want to adjust pitch too much. If we have extreme cases, just don't readjust at all.
{
SSNES_LOG("Timings deviate too much. Will not adjust. (Display = %.2f Hz, Game = %.2f Hz)\n",
g_settings.video.refresh_rate,
(float)g_extern.system.timing.fps);
g_settings.video.refresh_rate = g_extern.system.timing.fps;
}
}
if (g_extern.system.timing_set)
{
g_settings.audio.in_rate = g_extern.system.timing.sample_rate *
(g_settings.video.refresh_rate / g_extern.system.timing.fps);
}
else
{
g_settings.audio.in_rate = 32040.5 *
(g_settings.video.refresh_rate / (21477272.0 / 357366.0)); // SNES metrics.
}
SSNES_LOG("Set audio input rate to: %.2f Hz.\n", g_settings.audio.in_rate);
first = false;
}
#define AUDIO_CHUNK_SIZE_BLOCKING 64
#define AUDIO_CHUNK_SIZE_NONBLOCKING 2048 // So we don't get complete line-noise when fast-forwarding audio.
#define AUDIO_MAX_RATIO 16
void init_audio(void)
{
// Accomodate rewind since at some point we might have two full buffers.
size_t max_bufsamples = AUDIO_CHUNK_SIZE_NONBLOCKING * 2;
// Used for recording even if audio isn't enabled.
ssnes_assert(g_extern.audio_data.conv_outsamples = (int16_t*)malloc(max_bufsamples * sizeof(int16_t) * AUDIO_MAX_RATIO));
g_extern.audio_data.block_chunk_size = AUDIO_CHUNK_SIZE_BLOCKING;
g_extern.audio_data.nonblock_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING;
g_extern.audio_data.chunk_size = g_extern.audio_data.block_chunk_size;
// Needs to be able to hold full content of a full max_bufsamples in addition to its own.
ssnes_assert(g_extern.audio_data.rewind_buf = (int16_t*)malloc(max_bufsamples * sizeof(int16_t)));
g_extern.audio_data.rewind_size = max_bufsamples;
if (!g_settings.audio.enable)
{
g_extern.audio_active = false;
return;
}
adjust_audio_input_rate();
find_audio_driver();
g_extern.audio_data.block_chunk_size = AUDIO_CHUNK_SIZE_BLOCKING;
g_extern.audio_data.nonblock_chunk_size = AUDIO_CHUNK_SIZE_NONBLOCKING;
driver.audio_data = driver.audio->init(*g_settings.audio.device ? g_settings.audio.device : NULL,
g_settings.audio.out_rate, g_settings.audio.latency);
driver.audio_data = driver.audio->init(strlen(g_settings.audio.device) ? g_settings.audio.device : NULL, g_settings.audio.out_rate, g_settings.audio.latency);
if ( driver.audio_data == NULL )
if (!driver.audio_data)
g_extern.audio_active = false;
if (g_extern.audio_active && driver.audio->use_float && driver.audio->use_float(driver.audio_data))
@@ -170,56 +329,58 @@ void init_audio(void)
driver.audio->set_nonblock_state(driver.audio_data, true);
g_extern.audio_data.chunk_size = g_extern.audio_data.nonblock_chunk_size;
}
else
g_extern.audio_data.chunk_size = g_extern.audio_data.block_chunk_size;
#ifdef HAVE_SRC
int err;
g_extern.audio_data.source = src_new(g_settings.audio.src_quality, 2, &err);
g_extern.audio_data.source = hermite_new();
if (!g_extern.audio_data.source)
g_extern.audio_active = false;
#else
g_extern.audio_data.source = hermite_new(2);
if (!g_extern.audio_data.source)
g_extern.audio_active = false;
#endif
size_t max_bufsamples = g_extern.audio_data.block_chunk_size > g_extern.audio_data.nonblock_chunk_size ?
g_extern.audio_data.block_chunk_size : g_extern.audio_data.nonblock_chunk_size;
assert(g_settings.audio.out_rate < g_settings.audio.in_rate * AUDIO_MAX_RATIO);
assert((g_extern.audio_data.data = malloc(max_bufsamples * sizeof(float))));
ssnes_assert(g_extern.audio_data.data = (float*)malloc(max_bufsamples * sizeof(float)));
g_extern.audio_data.data_ptr = 0;
assert((g_extern.audio_data.outsamples = malloc(max_bufsamples * sizeof(float) * AUDIO_MAX_RATIO)));
assert((g_extern.audio_data.conv_outsamples = malloc(max_bufsamples * sizeof(int16_t) * AUDIO_MAX_RATIO)));
ssnes_assert(g_settings.audio.out_rate < g_settings.audio.in_rate * AUDIO_MAX_RATIO);
ssnes_assert(g_extern.audio_data.outsamples = (float*)malloc(max_bufsamples * sizeof(float) * AUDIO_MAX_RATIO));
g_extern.audio_data.src_ratio =
(double)g_settings.audio.out_rate / g_settings.audio.in_rate;
#ifdef HAVE_DYLIB
init_dsp_plugin();
#endif
}
void uninit_audio(void)
{
free(g_extern.audio_data.conv_outsamples);
g_extern.audio_data.conv_outsamples = NULL;
g_extern.audio_data.data_ptr = 0;
free(g_extern.audio_data.rewind_buf);
g_extern.audio_data.rewind_buf = NULL;
if (!g_settings.audio.enable)
{
g_extern.audio_active = false;
return;
}
if ( driver.audio_data && driver.audio )
if (driver.audio_data && driver.audio)
driver.audio->free(driver.audio_data);
if ( g_extern.audio_data.source )
{
#ifdef HAVE_SRC
src_delete(g_extern.audio_data.source);
#else
if (g_extern.audio_data.source)
hermite_free(g_extern.audio_data.source);
#endif
}
free(g_extern.audio_data.data); g_extern.audio_data.data = NULL;
free(g_extern.audio_data.outsamples); g_extern.audio_data.outsamples = NULL;
free(g_extern.audio_data.conv_outsamples); g_extern.audio_data.conv_outsamples = NULL;
free(g_extern.audio_data.data);
g_extern.audio_data.data = NULL;
free(g_extern.audio_data.outsamples);
g_extern.audio_data.outsamples = NULL;
#ifdef HAVE_DYLIB
deinit_dsp_plugin();
#endif
}
#ifdef HAVE_FILTER
#ifdef HAVE_DYLIB
static void init_filter(void)
{
if (g_extern.filter.active)
@@ -235,8 +396,12 @@ static void init_filter(void)
return;
}
g_extern.filter.psize = dylib_proc(g_extern.filter.lib, "filter_size");
g_extern.filter.prender = dylib_proc(g_extern.filter.lib, "filter_render");
g_extern.filter.psize =
(void (*)(unsigned*, unsigned*))dylib_proc(g_extern.filter.lib, "filter_size");
g_extern.filter.prender =
(void (*)(uint32_t*, uint32_t*,
unsigned, const uint16_t*,
unsigned, unsigned, unsigned))dylib_proc(g_extern.filter.lib, "filter_render");
if (!g_extern.filter.psize || !g_extern.filter.prender)
{
SSNES_ERR("Failed to find functions in filter...\n");
@@ -247,23 +412,23 @@ static void init_filter(void)
g_extern.filter.active = true;
unsigned width = 512;
unsigned height = 512;
unsigned width = g_extern.system.geom.max_width;
unsigned height = g_extern.system.geom.max_height;
g_extern.filter.psize(&width, &height);
unsigned pow2_x = next_pow2(ceil(width));
unsigned pow2_y = next_pow2(ceil(height));
unsigned pow2_x = next_pow2(width);
unsigned pow2_y = next_pow2(height);
unsigned maxsize = pow2_x > pow2_y ? pow2_x : pow2_y;
g_extern.filter.scale = maxsize / 256;
g_extern.filter.scale = maxsize / SSNES_SCALE_BASE;
g_extern.filter.buffer = malloc(256 * 256 * g_extern.filter.scale * g_extern.filter.scale * sizeof(uint32_t));
g_extern.filter.pitch = 256 * g_extern.filter.scale * sizeof(uint32_t);
assert(g_extern.filter.buffer);
g_extern.filter.buffer = (uint32_t*)malloc(SSNES_SCALE_BASE * SSNES_SCALE_BASE * g_extern.filter.scale * g_extern.filter.scale * sizeof(uint32_t));
g_extern.filter.pitch = SSNES_SCALE_BASE * g_extern.filter.scale * sizeof(uint32_t);
ssnes_assert(g_extern.filter.buffer);
g_extern.filter.colormap = malloc(32768 * sizeof(uint32_t));
assert(g_extern.filter.colormap);
g_extern.filter.colormap = (uint32_t*)malloc(32768 * sizeof(uint32_t));
ssnes_assert(g_extern.filter.colormap);
// Set up conversion map from 16-bit XBGR1555 to 32-bit RGBA.
// Set up conversion map from 16-bit XRGB1555 to 32-bit ARGB.
for (int i = 0; i < 32768; i++)
{
unsigned r = (i >> 10) & 31;
@@ -273,10 +438,9 @@ static void init_filter(void)
r = (r << 3) | (r >> 2);
g = (g << 3) | (g >> 2);
b = (b << 3) | (b >> 2);
g_extern.filter.colormap[i] = (r << 24) | (g << 16) | (b << 8);
g_extern.filter.colormap[i] = (r << 16) | (g << 8) | (b << 0);
}
}
#endif
static void deinit_filter(void)
{
@@ -289,6 +453,7 @@ static void deinit_filter(void)
free(g_extern.filter.colormap);
}
}
#endif
#ifdef HAVE_XML
static void init_shader_dir(void)
@@ -313,12 +478,15 @@ static void deinit_shader_dir(void)
{
// It handles NULL, no worries :D
dir_list_free(g_extern.shader_dir.elems);
g_extern.shader_dir.elems = NULL;
g_extern.shader_dir.size = 0;
g_extern.shader_dir.ptr = 0;
}
#endif
void init_video_input(void)
{
#ifdef HAVE_FILTER
#ifdef HAVE_DYLIB
init_filter();
#endif
@@ -326,8 +494,9 @@ void init_video_input(void)
init_shader_dir();
#endif
// We use at least 512x512 textures to accomodate for hi-res games.
unsigned scale = 2;
unsigned max_dim = max(g_extern.system.geom.max_width, g_extern.system.geom.max_height);
unsigned scale = max_dim / SSNES_SCALE_BASE;
scale = max(scale, 1);
find_video_driver();
find_input_driver();
@@ -335,24 +504,52 @@ void init_video_input(void)
if (g_extern.filter.active)
scale = g_extern.filter.scale;
video_info_t video = {
.width = (g_settings.video.fullscreen) ? g_settings.video.fullscreen_x : (296 * g_settings.video.xscale),
.height = (g_settings.video.fullscreen) ? g_settings.video.fullscreen_y : (224 * g_settings.video.yscale),
.fullscreen = g_settings.video.fullscreen,
.vsync = g_settings.video.vsync,
.force_aspect = g_settings.video.force_aspect,
.smooth = g_settings.video.smooth,
.input_scale = scale,
.rgb32 = g_extern.filter.active
};
unsigned width;
unsigned height;
if (g_settings.video.fullscreen)
{
width = g_settings.video.fullscreen_x;
height = g_settings.video.fullscreen_y;
}
else
{
if (g_settings.video.force_aspect && (g_settings.video.aspect_ratio > 0.0f))
{
width = roundf(g_extern.system.geom.base_height * g_settings.video.xscale * g_settings.video.aspect_ratio);
height = roundf(g_extern.system.geom.base_height * g_settings.video.yscale);
}
else
{
width = roundf(g_extern.system.geom.base_width * g_settings.video.xscale);
height = roundf(g_extern.system.geom.base_height * g_settings.video.yscale);
}
}
if (g_settings.video.aspect_ratio < 0.0f)
{
g_settings.video.aspect_ratio = (float)g_extern.system.geom.base_width / g_extern.system.geom.base_height;
SSNES_LOG("Adjusting aspect ratio to %.2f\n", g_settings.video.aspect_ratio);
}
SSNES_LOG("Video @ %ux%u\n", width, height);
video_info_t video = {0};
video.width = width;
video.height = height;
video.fullscreen = g_settings.video.fullscreen;
video.vsync = g_settings.video.vsync;
video.force_aspect = g_settings.video.force_aspect;
video.smooth = g_settings.video.smooth;
video.input_scale = scale;
video.rgb32 = g_extern.filter.active;
const input_driver_t *tmp = driver.input;
driver.video_data = driver.video->init(&video, &driver.input, &driver.input_data);
if ( driver.video_data == NULL )
if (driver.video_data == NULL)
{
SSNES_ERR("Cannot open video driver... Exiting ...\n");
exit(1);
SSNES_ERR("Cannot open video driver ... Exiting ...\n");
ssnes_fail(1, "init_video_input()");
}
// Video driver didn't provide an input driver so we use configured one.
@@ -362,29 +559,31 @@ void init_video_input(void)
if (driver.input != NULL)
{
driver.input_data = driver.input->init();
if ( driver.input_data == NULL )
if (driver.input_data == NULL)
{
SSNES_ERR("Cannot init input driver. Exiting ...\n");
exit(1);
ssnes_fail(1, "init_video_input()");
}
}
else
{
SSNES_ERR("Cannot find input driver. Exiting ...\n");
exit(1);
ssnes_fail(1, "init_video_input()");
}
}
}
void uninit_video_input(void)
{
if ( driver.video_data && driver.video )
driver.video->free(driver.video_data);
if ( driver.input_data != driver.video_data && driver.input )
if (driver.input_data != driver.video_data && driver.input)
driver.input->free(driver.input_data);
if (driver.video_data && driver.video)
driver.video->free(driver.video_data);
#ifdef HAVE_DYLIB
deinit_filter();
#endif
#ifdef HAVE_XML
deinit_shader_dir();
+68 -30
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -20,14 +20,22 @@
#define __DRIVER__H
#include <sys/types.h>
#include <stdbool.h>
#include "boolean.h"
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include "msvc/msvc_compat.h"
#include "input/keysym.h"
#define AUDIO_CHUNK_SIZE_BLOCKING 64
#define AUDIO_CHUNK_SIZE_NONBLOCKING 2048 // So we don't get complete line-noise when fast-forwarding audio.
#define AUDIO_MAX_RATIO 16
// SNES has 12 buttons from 0-11 (libsnes.hpp)
#define SSNES_FIRST_META_KEY 12
enum
{
SSNES_FAST_FORWARD_KEY = 0x666, // Hurr, durr
SSNES_FAST_FORWARD_KEY = SSNES_FIRST_META_KEY,
SSNES_FAST_FORWARD_HOLD_KEY,
SSNES_LOAD_STATE_KEY,
SSNES_SAVE_STATE_KEY,
SSNES_FULLSCREEN_TOGGLE_KEY,
@@ -39,24 +47,39 @@ enum
SSNES_REWIND,
SSNES_MOVIE_RECORD_TOGGLE,
SSNES_PAUSE_TOGGLE,
SSNES_FRAMEADVANCE,
SSNES_RESET,
SSNES_SHADER_NEXT,
SSNES_SHADER_PREV,
};
SSNES_CHEAT_INDEX_PLUS,
SSNES_CHEAT_INDEX_MINUS,
SSNES_CHEAT_TOGGLE,
SSNES_SCREENSHOT,
SSNES_DSP_CONFIG,
SSNES_MUTE,
#if defined(__CELLOS_LV2__) || defined(XENON) || defined(_XBOX)
SSNES_CHEAT_INPUT,
SSNES_INGAME_MENU,
SSNES_EXIT_TO_MENU,
SSNES_SRAM_WRITE_PROTECT,
#endif
SSNES_BIND_LIST_END
};
struct snes_keybind
{
int id;
uint16_t key;
enum ssnes_key key;
uint16_t joykey;
uint32_t joyaxis;
};
typedef struct video_info
{
int width;
int height;
unsigned width;
unsigned height;
bool fullscreen;
bool vsync;
bool force_aspect;
@@ -67,24 +90,24 @@ typedef struct video_info
typedef struct audio_driver
{
void* (*init)(const char* device, int rate, int latency);
ssize_t (*write)(void* data, const void* buf, size_t size);
bool (*stop)(void* data);
bool (*start)(void* data);
void (*set_nonblock_state)(void* data, bool toggle); // Should we care about blocking in audio thread? Fast forwarding.
void (*free)(void* data);
void *(*init)(const char *device, unsigned rate, unsigned latency);
ssize_t (*write)(void *data, const void *buf, size_t size);
bool (*stop)(void *data);
bool (*start)(void *data);
void (*set_nonblock_state)(void *data, bool toggle); // Should we care about blocking in audio thread? Fast forwarding.
void (*free)(void *data);
bool (*use_float)(void *data); // Defines if driver will take standard floating point samples, or int16_t samples.
const char *ident;
} audio_driver_t;
#define AXIS_NEG(x) (((uint32_t)(x) << 16) | 0xFFFFU)
#define AXIS_POS(x) ((uint32_t)(x) | 0xFFFF0000U)
#define AXIS_NONE (0xFFFFFFFFU)
#define AXIS_NEG(x) (((uint32_t)(x) << 16) | UINT16_C(0xFFFF))
#define AXIS_POS(x) ((uint32_t)(x) | UINT32_C(0xFFFF0000))
#define AXIS_NONE UINT32_C(0xFFFFFFFF)
#define AXIS_NEG_GET(x) (((uint32_t)(x) >> 16) & 0xFFFFU)
#define AXIS_POS_GET(x) ((uint32_t)(x) & 0xFFFFU)
#define AXIS_NEG_GET(x) (((uint32_t)(x) >> 16) & UINT16_C(0xFFFF))
#define AXIS_POS_GET(x) ((uint32_t)(x) & UINT16_C(0xFFFF))
#define NO_BTN ((uint16_t)0xFFFFU) // I hope no joypad will ever have this many buttons ... ;)
#define NO_BTN UINT16_C(0xFFFF) // I hope no joypad will ever have this many buttons ... ;)
#define HAT_UP_MASK (1 << 15)
#define HAT_DOWN_MASK (1 << 14)
@@ -98,29 +121,28 @@ typedef struct audio_driver
typedef struct input_driver
{
void* (*init)(void);
void (*poll)(void* data);
int16_t (*input_state)(void* data, const struct snes_keybind **snes_keybinds, bool port, unsigned device, unsigned index, unsigned id);
bool (*key_pressed)(void* data, int key);
void (*free)(void* data);
void *(*init)(void);
void (*poll)(void *data);
int16_t (*input_state)(void *data, const struct snes_keybind **snes_keybinds, bool port, unsigned device, unsigned index, unsigned id);
bool (*key_pressed)(void *data, int key);
void (*free)(void *data);
const char *ident;
} input_driver_t;
typedef struct video_driver
{
void* (*init)(video_info_t *video, const input_driver_t **input, void **input_data);
void *(*init)(const video_info_t *video, const input_driver_t **input, void **input_data);
// Should the video driver act as an input driver as well? :) The video init might preinitialize an input driver to override the settings in case the video driver relies on input driver for event handling, e.g.
bool (*frame)(void* data, const void* frame, unsigned width, unsigned height, unsigned pitch, const char *msg); // msg is for showing a message on the screen along with the video frame.
void (*set_nonblock_state)(void* data, bool toggle); // Should we care about syncing to vblank? Fast forwarding.
bool (*frame)(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg); // msg is for showing a message on the screen along with the video frame.
void (*set_nonblock_state)(void *data, bool toggle); // Should we care about syncing to vblank? Fast forwarding.
// Is the window still active?
bool (*alive)(void *data);
bool (*focus)(void *data); // Does the window have focus?
bool (*xml_shader)(void *data, const char *path); // Sets XML-shader. Might not be implemented.
void (*free)(void* data);
void (*free)(void *data);
const char *ident;
} video_driver_t;
typedef struct driver
{
const audio_driver_t *audio;
@@ -151,10 +173,26 @@ extern const audio_driver_t audio_jack;
extern const audio_driver_t audio_sdl;
extern const audio_driver_t audio_xa;
extern const audio_driver_t audio_pulse;
extern const audio_driver_t audio_ext;
extern const audio_driver_t audio_dsound;
extern const audio_driver_t audio_coreaudio;
extern const audio_driver_t audio_xenon360;
extern const audio_driver_t audio_xdk360;
extern const audio_driver_t audio_ps3;
extern const audio_driver_t audio_wii;
extern const video_driver_t video_gl;
extern const video_driver_t video_wii;
extern const video_driver_t video_xenon360;
extern const video_driver_t video_xvideo;
extern const video_driver_t video_xdk360;
extern const video_driver_t video_sdl;
extern const video_driver_t video_ext;
extern const input_driver_t input_sdl;
extern const input_driver_t input_x;
extern const input_driver_t input_ps3;
extern const input_driver_t input_xenon360;
extern const input_driver_t input_wii;
extern const input_driver_t input_xdk360;
////////////////////////////////////////////////
#endif
+219 -60
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -17,35 +17,41 @@
#include "dynamic.h"
#include "general.h"
#include "strl.h"
#include <string.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <libsnes.hpp>
#include "boolean.h"
#include "libsnes.hpp"
#ifdef NEED_DYNAMIC
#ifdef _WIN32
#include <windows.h>
#else
#include <dlfcn.h>
#endif
#ifdef HAVE_DYNAMIC
#define DLSYM(lib, x) dylib_proc(lib, #x)
#define SYM(x) do { \
p##x = DLSYM(lib_handle, x); \
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); exit(1); } \
} while(0)
#define OPT_SYM(x) do { \
p##x = DLSYM(lib_handle, x); \
} while(0)
static dylib_t lib_handle = NULL;
#endif
#ifdef NEED_DYNAMIC
#define DLSYM(lib, x) dylib_proc(lib, #x)
#define SYM(type, x) do { \
p##x = (type)DLSYM(lib_handle, x); \
if (p##x == NULL) { SSNES_ERR("Failed to load symbol: \"%s\"\n", #x); ssnes_fail(1, "init_libsnes_sym()"); } \
} while (0)
#define OPT_SYM(type, x) do { \
p##x = (type)DLSYM(lib_handle, x); \
} while (0)
#endif
#ifdef HAVE_DYNAMIC
static dylib_t lib_handle = NULL;
#endif
void (*psnes_init)(void);
@@ -57,6 +63,9 @@ void (*psnes_set_input_state)(snes_input_state_t);
void (*psnes_reset)(void);
void (*psnes_run)(void);
void (*psnes_cheat_reset)(void);
void (*psnes_cheat_set)(unsigned, bool, const char*);
const char *(*psnes_library_id)(void) = NULL;
unsigned (*psnes_library_revision_minor)(void);
unsigned (*psnes_library_revision_major)(void);
@@ -92,6 +101,11 @@ unsigned (*psnes_get_memory_size)(unsigned);
void (*psnes_unload_cartridge)(void);
void (*psnes_term)(void);
#if defined(NEED_DYNAMIC) || defined(GEKKO) || defined(__CELLOS_LV2__) || defined(XENON)
static void set_environment(void);
#endif
static void set_environment_defaults(void);
#ifdef HAVE_DYNAMIC
static void load_dynamic(void)
{
@@ -100,42 +114,47 @@ static void load_dynamic(void)
if (!lib_handle)
{
SSNES_ERR("Failed to open dynamic library: \"%s\"\n", g_settings.libsnes);
exit(1);
ssnes_fail(1, "load_dynamic()");
}
SYM(snes_init);
SYM(snes_set_video_refresh);
SYM(snes_set_audio_sample);
SYM(snes_set_input_poll);
SYM(snes_set_input_state);
OPT_SYM(snes_library_id);
SYM(snes_library_revision_minor);
SYM(snes_library_revision_major);
SYM(snes_reset);
SYM(snes_run);
SYM(snes_get_region);
SYM(snes_load_cartridge_normal);
SYM(snes_load_cartridge_super_game_boy);
SYM(snes_load_cartridge_bsx);
SYM(snes_load_cartridge_bsx_slotted);
SYM(snes_load_cartridge_sufami_turbo);
SYM(snes_set_controller_port_device);
SYM(snes_serialize_size);
SYM(snes_serialize);
SYM(snes_unserialize);
SYM(snes_set_cartridge_basename);
SYM(snes_get_memory_data);
SYM(snes_get_memory_size);
SYM(snes_unload_cartridge);
SYM(snes_term);
SYM(void (*)(void), snes_init);
SYM(void (*)(snes_video_refresh_t), snes_set_video_refresh);
SYM(void (*)(snes_audio_sample_t), snes_set_audio_sample);
SYM(void (*)(snes_input_poll_t), snes_set_input_poll);
SYM(void (*)(snes_input_state_t), snes_set_input_state);
SYM(const char *(*)(void), snes_library_id);
SYM(unsigned (*)(void), snes_library_revision_minor);
SYM(unsigned (*)(void), snes_library_revision_major);
SYM(void (*)(void), snes_cheat_reset);
SYM(void (*)(unsigned, bool, const char*), snes_cheat_set);
SYM(void (*)(void), snes_reset);
SYM(void (*)(void), snes_run);
SYM(bool (*)(void), snes_get_region);
SYM(bool (*)(const char*, const uint8_t*, unsigned), snes_load_cartridge_normal);
SYM(bool (*)(const char*, const uint8_t*, unsigned,
const char*, const uint8_t*, unsigned), snes_load_cartridge_super_game_boy);
SYM(bool (*)(const char*, const uint8_t*, unsigned,
const char*, const uint8_t*, unsigned), snes_load_cartridge_bsx);
SYM(bool (*)(const char*, const uint8_t*, unsigned,
const char*, const uint8_t*, unsigned), snes_load_cartridge_bsx_slotted);
SYM(bool (*)(const char*, const uint8_t*, unsigned,
const char*, const uint8_t*, unsigned,
const char*, const uint8_t*, unsigned), snes_load_cartridge_sufami_turbo);
SYM(void (*)(bool, unsigned), snes_set_controller_port_device);
SYM(unsigned (*)(void), snes_serialize_size);
SYM(bool (*)(uint8_t*, unsigned), snes_serialize);
SYM(bool (*)(const uint8_t*, unsigned), snes_unserialize);
SYM(void (*)(const char*), snes_set_cartridge_basename);
SYM(uint8_t *(*)(unsigned), snes_get_memory_data);
SYM(unsigned (*)(unsigned), snes_get_memory_size);
SYM(void (*)(void), snes_unload_cartridge);
SYM(void (*)(void), snes_term);
}
#endif
#else
#define SSYM(x) do { \
p##x = x; \
} while(0)
} while (0)
#ifndef HAVE_DYNAMIC
static void set_statics(void)
{
SSYM(snes_init);
@@ -145,6 +164,9 @@ static void set_statics(void)
SSYM(snes_set_input_state);
SSYM(snes_library_revision_minor);
SSYM(snes_library_revision_major);
SSYM(snes_library_id);
SSYM(snes_cheat_reset);
SSYM(snes_cheat_set);
SSYM(snes_reset);
SSYM(snes_run);
SSYM(snes_get_region);
@@ -165,22 +187,47 @@ static void set_statics(void)
}
#endif
void init_dlsym(void)
void init_libsnes_sym(void)
{
// Guarantee that we can do "dirty" casting.
// Every OS that this program supports should pass this ...
ssnes_assert(sizeof(void*) == sizeof(void (*)(void)));
#ifdef HAVE_DYNAMIC
if (strlen(g_settings.libsnes) > 0)
load_dynamic();
else
// Try to verify that -lsnes was not linked in from other modules
// since loading it dynamically and with -l will fail hard.
function_t sym = dylib_proc(NULL, "snes_init");
if (sym)
{
SSNES_ERR("This binary is built to use runtime dynamic binding of libsnes. Set libsnes_path in config to load a libsnes library dynamically.\n");
exit(1);
SSNES_ERR("Serious problem! SSNES wants to load libsnes dyamically, but it is already linked!\n");
SSNES_ERR("This could happen if other modules SSNES depends on link against libsnes directly.\n");
SSNES_ERR("Proceeding could cause a crash! Aborting ...\n");
ssnes_fail(1, "init_libsnes_sym()");
}
if (!*g_settings.libsnes)
{
#if defined(_WIN32)
strlcpy(g_settings.libsnes, "snes.dll", sizeof(g_settings.libsnes));
#elif defined(__APPLE__)
strlcpy(g_settings.libsnes, "libsnes.dylib", sizeof(g_settings.libsnes));
#else
set_statics();
strlcpy(g_settings.libsnes, "libsnes.so", sizeof(g_settings.libsnes));
#endif
}
load_dynamic();
#else
set_statics();
#endif
set_environment_defaults();
#if defined(NEED_DYNAMIC) || defined(GEKKO) || defined(__CELLOS_LV2__) || defined(XENON)
set_environment();
#endif
}
void uninit_dlsym(void)
void uninit_libsnes_sym(void)
{
#ifdef HAVE_DYNAMIC
if (lib_handle)
@@ -188,6 +235,7 @@ void uninit_dlsym(void)
#endif
}
#ifdef NEED_DYNAMIC
// Platform independent dylib loading.
dylib_t dylib_load(const char *path)
{
@@ -198,25 +246,136 @@ dylib_t dylib_load(const char *path)
#endif
}
void* dylib_proc(dylib_t lib, const char *proc)
function_t dylib_proc(dylib_t lib, const char *proc)
{
#ifdef _WIN32
void *sym = (void*)GetProcAddress(lib, proc);
function_t sym = (function_t)GetProcAddress(lib ? (HMODULE)lib : GetModuleHandle(NULL), proc);
#else
void *sym = dlsym(lib, proc);
void *ptr_sym = NULL;
if (lib)
ptr_sym = dlsym(lib, proc);
else
{
void *handle = dlopen(NULL, RTLD_LAZY);
if (handle)
{
ptr_sym = dlsym(handle, proc);
dlclose(handle);
}
}
// Dirty hack to workaround the non-legality of (void*) -> fn-pointer casts.
function_t sym;
memcpy(&sym, &ptr_sym, sizeof(void*));
#endif
if (!sym)
SSNES_WARN("Failed to load symbol \"%s\"\n", proc);
return sym;
}
void dylib_close(dylib_t lib)
{
#ifdef _WIN32
FreeLibrary(lib);
FreeLibrary((HMODULE)lib);
#else
dlclose(lib);
#endif
}
#endif
#if defined(NEED_DYNAMIC) || defined(GEKKO) || defined(__CELLOS_LV2__) || defined(XENON)
static bool environment_cb(unsigned cmd, void *data)
{
switch (cmd)
{
case SNES_ENVIRONMENT_GET_FULLPATH:
*(const char**)data = g_extern.system.fullpath;
SSNES_LOG("Environ FULLPATH: \"%s\"\n", g_extern.system.fullpath);
break;
case SNES_ENVIRONMENT_SET_GEOMETRY:
g_extern.system.geom = *(const struct snes_geometry*)data;
g_extern.system.geom.max_width = next_pow2(g_extern.system.geom.max_width);
g_extern.system.geom.max_height = next_pow2(g_extern.system.geom.max_height);
SSNES_LOG("Environ SET_GEOMETRY: (%ux%u) / (%ux%u)\n",
g_extern.system.geom.base_width,
g_extern.system.geom.base_height,
g_extern.system.geom.max_width,
g_extern.system.geom.max_height);
break;
case SNES_ENVIRONMENT_SET_PITCH:
g_extern.system.pitch = *(const unsigned*)data;
SSNES_LOG("Environ SET_PITCH: %u\n", g_extern.system.pitch);
break;
case SNES_ENVIRONMENT_GET_OVERSCAN:
*(bool*)data = !g_settings.video.crop_overscan;
SSNES_LOG("Environ GET_OVERSCAN: %u\n", (unsigned)!g_settings.video.crop_overscan);
break;
case SNES_ENVIRONMENT_SET_TIMING:
g_extern.system.timing = *(const struct snes_system_timing*)data;
g_extern.system.timing_set = true;
SSNES_LOG("Environ SET_TIMING: %.3f Hz/ %.3f Hz\n",
(float)g_extern.system.timing.fps, (float)g_extern.system.timing.sample_rate);
break;
case SNES_ENVIRONMENT_GET_CAN_DUPE:
*(bool*)data = true;
SSNES_LOG("Environ GET_CAN_DUPE: true\n");
break;
case SNES_ENVIRONMENT_SET_NEED_FULLPATH:
g_extern.system.need_fullpath = *(const bool*)data;
SSNES_LOG("Environ SET_NEED_FULLPATH: %s\n", g_extern.system.need_fullpath ? "true" : "false");
break;
case SNES_ENVIRONMENT_GET_CAN_REWIND:
*(bool*)data = g_settings.rewind_enable;
SSNES_LOG("Environ GET_CAN_REWIND: %s\n", g_settings.rewind_enable ? "true" : "false");
break;
default:
SSNES_LOG("Environ UNSUPPORTED (#%u)!\n", cmd);
return false;
}
return true;
}
#endif
#ifdef NEED_DYNAMIC
// SSNES extension hooks. Totally optional 'n shizz :)
static void set_environment(void)
{
#ifdef HAVE_DYNAMIC
dylib_t lib = lib_handle;
#else
dylib_t lib = NULL;
#endif
void (*psnes_set_environment)(snes_environment_t) =
(void (*)(snes_environment_t))dylib_proc(lib, "snes_set_environment");
if (psnes_set_environment)
psnes_set_environment(environment_cb);
}
#elif defined(GEKKO) || defined(__CELLOS_LV2__) || defined(XENON)
// Not very optional when we're running on a console without dynamic loading support.
static void set_environment(void)
{
snes_set_environment(environment_cb);
}
#endif
// Assume SNES as defaults.
static void set_environment_defaults(void)
{
SSNES_LOG("Setting environment defaults (SNES)\n");
g_extern.system.pitch = 0; // 0 is classic libsnes semantics.
g_extern.system.geom.base_width = 256;
g_extern.system.geom.base_height = 224;
g_extern.system.geom.max_width = 512;
g_extern.system.geom.max_height = 512;
}
+23 -7
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -18,17 +18,30 @@
#ifndef __DYNAMIC_H
#define __DYNAMIC_H
#include <stdbool.h>
#include <libsnes.hpp>
#include "boolean.h"
#include "libsnes.hpp"
void init_dlsym(void);
void uninit_dlsym(void);
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_DYNAMIC) || defined(HAVE_DYLIB)
#define NEED_DYNAMIC
#else
#undef NEED_DYNAMIC
#endif
void init_libsnes_sym(void);
void uninit_libsnes_sym(void);
typedef void *dylib_t;
#ifdef NEED_DYNAMIC
typedef void (*function_t)(void);
dylib_t dylib_load(const char *path);
void dylib_close(dylib_t lib);
void* dylib_proc(dylib_t lib, const char *proc);
function_t dylib_proc(dylib_t lib, const char *proc);
#endif
extern void (*psnes_init)(void);
@@ -37,7 +50,10 @@ extern void (*psnes_set_audio_sample)(snes_audio_sample_t);
extern void (*psnes_set_input_poll)(snes_input_poll_t);
extern void (*psnes_set_input_state)(snes_input_state_t);
extern const char* (*psnes_library_id)(void);
extern void (*psnes_cheat_reset)(void);
extern void (*psnes_cheat_set)(unsigned, bool, const char*);
extern const char *(*psnes_library_id)(void);
extern unsigned (*psnes_library_revision_minor)(void);
extern unsigned (*psnes_library_revision_major)(void);
+16 -34
View File
@@ -1,5 +1,5 @@
/* RSound - A PCM audio client/server
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* RSound is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
@@ -13,23 +13,24 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "buffer.h"
#include "fifo_buffer.h"
#include <stdint.h>
struct rsound_fifo_buffer
struct fifo_buffer
{
char *buffer;
uint8_t *buffer;
size_t bufsize;
size_t first;
size_t end;
};
rsound_fifo_buffer_t* rsnd_fifo_new(size_t size)
fifo_buffer_t *fifo_new(size_t size)
{
rsound_fifo_buffer_t *buf = calloc(1, sizeof(*buf));
fifo_buffer_t *buf = (fifo_buffer_t*)calloc(1, sizeof(*buf));
if (buf == NULL)
return NULL;
buf->buffer = calloc(1, size + 1);
buf->buffer = (uint8_t*)calloc(1, size + 1);
if (buf->buffer == NULL)
{
free(buf);
@@ -40,20 +41,14 @@ rsound_fifo_buffer_t* rsnd_fifo_new(size_t size)
return buf;
}
void rsnd_fifo_free(rsound_fifo_buffer_t* buffer)
void fifo_free(fifo_buffer_t *buffer)
{
assert(buffer);
assert(buffer->buffer);
free(buffer->buffer);
free(buffer);
}
size_t rsnd_fifo_read_avail(rsound_fifo_buffer_t* buffer)
size_t fifo_read_avail(fifo_buffer_t *buffer)
{
assert(buffer);
assert(buffer->buffer);
size_t first = buffer->first;
size_t end = buffer->end;
if (end < first)
@@ -61,11 +56,8 @@ size_t rsnd_fifo_read_avail(rsound_fifo_buffer_t* buffer)
return end - first;
}
size_t rsnd_fifo_write_avail(rsound_fifo_buffer_t* buffer)
size_t fifo_write_avail(fifo_buffer_t *buffer)
{
assert(buffer);
assert(buffer->buffer);
size_t first = buffer->first;
size_t end = buffer->end;
if (end < first)
@@ -74,13 +66,8 @@ size_t rsnd_fifo_write_avail(rsound_fifo_buffer_t* buffer)
return (buffer->bufsize - 1) - (end - first);
}
void rsnd_fifo_write(rsound_fifo_buffer_t* buffer, const void* in_buf, size_t size)
void fifo_write(fifo_buffer_t *buffer, const void *in_buf, size_t size)
{
assert(buffer);
assert(buffer->buffer);
assert(in_buf);
assert(rsnd_fifo_write_avail(buffer) >= size);
size_t first_write = size;
size_t rest_write = 0;
if (buffer->end + size > buffer->bufsize)
@@ -91,19 +78,14 @@ void rsnd_fifo_write(rsound_fifo_buffer_t* buffer, const void* in_buf, size_t si
memcpy(buffer->buffer + buffer->end, in_buf, first_write);
if (rest_write > 0)
memcpy(buffer->buffer, (const char*)in_buf + first_write, rest_write);
memcpy(buffer->buffer, (const uint8_t*)in_buf + first_write, rest_write);
buffer->end = (buffer->end + size) % buffer->bufsize;
}
void rsnd_fifo_read(rsound_fifo_buffer_t* buffer, void* in_buf, size_t size)
void fifo_read(fifo_buffer_t *buffer, void *in_buf, size_t size)
{
assert(buffer);
assert(buffer->buffer);
assert(in_buf);
assert(rsnd_fifo_read_avail(buffer) >= size);
size_t first_read = size;
size_t rest_read = 0;
if (buffer->first + size > buffer->bufsize)
@@ -112,9 +94,9 @@ void rsnd_fifo_read(rsound_fifo_buffer_t* buffer, void* in_buf, size_t size)
rest_read = size - first_read;
}
memcpy(in_buf, (const char*)buffer->buffer + buffer->first, first_read);
memcpy(in_buf, (const uint8_t*)buffer->buffer + buffer->first, first_read);
if (rest_read > 0)
memcpy((char*)in_buf + first_read, buffer->buffer, rest_read);
memcpy((uint8_t*)in_buf + first_read, buffer->buffer, rest_read);
buffer->first = (buffer->first + size) % buffer->bufsize;
}
+10 -11
View File
@@ -1,5 +1,5 @@
/* RSound - A PCM audio client/server
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* RSound is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
@@ -17,20 +17,19 @@
#define __BUFFER_H
#include <stdlib.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#ifndef RSD_FIFO_BUF_TYPEDEF
#define RSD_FIFO_BUF_TYPEDEF
typedef struct rsound_fifo_buffer rsound_fifo_buffer_t;
#ifndef FIFO_BUF_TYPEDEF
#define FIFO_BUF_TYPEDEF
typedef struct fifo_buffer fifo_buffer_t;
#endif
rsound_fifo_buffer_t* rsnd_fifo_new(size_t size);
void rsnd_fifo_write(rsound_fifo_buffer_t* buffer, const void* in_buf, size_t size);
void rsnd_fifo_read(rsound_fifo_buffer_t* buffer, void* in_buf, size_t size);
void rsnd_fifo_free(rsound_fifo_buffer_t* buffer);
size_t rsnd_fifo_read_avail(rsound_fifo_buffer_t* buffer);
size_t rsnd_fifo_write_avail(rsound_fifo_buffer_t* buffer);
fifo_buffer_t *fifo_new(size_t size);
void fifo_write(fifo_buffer_t *buffer, const void *in_buf, size_t size);
void fifo_read(fifo_buffer_t *buffer, void *in_buf, size_t size);
void fifo_free(fifo_buffer_t *buffer);
size_t fifo_read_avail(fifo_buffer_t *buffer);
size_t fifo_write_avail(fifo_buffer_t *buffer);
#endif
+537 -182
View File
File diff suppressed because it is too large. Load diff
+24 -7
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -19,23 +19,40 @@
#ifndef __SSNES_FILE_H
#define __SSNES_FILE_H
#include <stdbool.h>
#include "boolean.h"
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <sys/types.h>
#include "general.h"
bool load_state(const char* path);
bool save_state(const char* path);
// Generic file, path and directory handling.
void load_ram_file(const char* path, int type);
void save_ram_file(const char* path, int type);
ssize_t read_file(const char *path, void **buf);
bool load_state(const char *path);
bool save_state(const char *path);
void load_ram_file(const char *path, int type);
void save_ram_file(const char *path, int type);
bool init_rom_file(enum ssnes_game_type type);
// Returns a NULL-terminated list of files in a directory with full paths.
char** dir_list_new(const char *dir, const char *ext);
// If ext is NULL, any file will be picked.
// If non-NULL, only files with extension ext are added.
char **dir_list_new(const char *dir, const char *ext);
void dir_list_free(char **dir_list);
bool path_is_directory(const char *path);
bool path_file_exists(const char *path);
// Path-name operations.
// Replaces filename extension with replace.
void fill_pathname(char *out_path, const char *in_path, const char *replace, size_t size);
// Sets filename extension. Assumes in_path has no extension.
void fill_pathname_noext(char *out_path, const char *in_path, const char *replace, size_t size);
// Concatenates in_basename and replace to in_dir.
void fill_pathname_dir(char *in_dir, const char *in_basename, const char *replace, size_t size);
#endif
+242 -55
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -19,30 +19,56 @@
#ifndef __SSNES_GENERAL_H
#define __SSNES_GENERAL_H
#include <stdbool.h>
#include "driver.h"
#include "boolean.h"
#include <stdio.h>
#include <time.h>
#include <limits.h>
#include <setjmp.h>
#include "driver.h"
#include "record/ffemu.h"
#include "message.h"
#include "rewind.h"
#include "movie.h"
#include "autosave.h"
#include "netplay.h"
#include "dynamic.h"
#include "cheats.h"
#include "audio/ext/ssnes_dsp.h"
#include "strl.h"
#ifdef __CELLOS_LV2__
#include <sys/timer.h>
#endif
#ifdef XENON
#include <time/time.h>
#endif
#if defined(XENON) || defined(__CELLOS_LV2__)
#undef PATH_MAX
#define PATH_MAX 4096
#endif
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_SRC
#include <samplerate.h>
#else
#include "audio/hermite.h"
#ifdef HAVE_NETPLAY
#include "netplay.h"
#endif
#include "audio/hermite.h"
#if defined(_WIN32) && !defined(_XBOX)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include "msvc/msvc_compat.h"
#elif defined(_XBOX)
#include <xtl.h>
#include "360/msvc_compat.h"
#endif
#define MAX_PLAYERS 5
#define MAX_BINDS 28 // Needs to be increased every time there are new binds added.
#define MAX_BINDS (SSNES_BIND_LIST_END + 1)
#define SSNES_NO_JOYPAD 0xFFFF
enum ssnes_shader_type
@@ -67,24 +93,38 @@ struct settings
bool vsync;
bool smooth;
bool force_aspect;
bool crop_overscan;
float aspect_ratio;
char cg_shader_path[256];
char bsnes_shader_path[256];
char filter_path[256];
char cg_shader_path[PATH_MAX];
char bsnes_shader_path[PATH_MAX];
char filter_path[PATH_MAX];
enum ssnes_shader_type shader_type;
float refresh_rate;
bool render_to_texture;
double fbo_scale_x;
double fbo_scale_y;
char second_pass_shader[256];
float fbo_scale_x;
float fbo_scale_y;
char second_pass_shader[PATH_MAX];
bool second_pass_smooth;
char shader_dir[256];
char shader_dir[PATH_MAX];
char font_path[256];
char font_path[PATH_MAX];
unsigned font_size;
bool font_enable;
bool font_scale;
float msg_pos_x;
float msg_pos_y;
float msg_color_r;
float msg_color_g;
float msg_color_b;
bool force_16bit;
bool disable_composition;
bool hires_record;
bool post_filter_record;
char external_driver[PATH_MAX];
} video;
struct
@@ -94,10 +134,12 @@ struct settings
unsigned out_rate;
float in_rate;
float rate_step;
char device[256];
char device[PATH_MAX];
unsigned latency;
bool sync;
int src_quality;
char dsp_plugin[PATH_MAX];
char external_driver[PATH_MAX];
} audio;
struct
@@ -109,23 +151,42 @@ struct settings
bool netplay_client_swap_input;
} input;
char libsnes[256];
char libsnes[PATH_MAX];
char cheat_database[PATH_MAX];
char cheat_settings_path[PATH_MAX];
char screenshot_directory[PATH_MAX];
bool rewind_enable;
unsigned rewind_buffer_size;
size_t rewind_buffer_size;
unsigned rewind_granularity;
bool pause_nonactive;
unsigned autosave_interval;
bool block_sram_overwrite;
bool savestate_auto_index;
};
// Settings and/or global state that is specific to a console-style implementation.
#ifdef SSNES_CONSOLE
struct console_settings
{
bool block_config_read;
#ifdef __CELLOS_LV2__
bool return_to_multiman_enable;
#endif
bool screenshots_enable;
};
#endif
enum ssnes_game_type
{
SSNES_CART_NORMAL = 0,
SSNES_CART_SGB,
SSNES_CART_BSX,
SSNES_CART_BSX_SLOTTED,
SSNES_CART_SUFAMI,
SSNES_CART_SUFAMI
};
@@ -135,45 +196,58 @@ struct global
bool verbose;
bool audio_active;
bool video_active;
bool force_fullscreen;
bool has_mouse[2];
bool has_scope[2];
bool has_justifier;
bool has_justifiers;
bool has_multitap;
bool disconnect_device[2];
FILE *rom_file;
enum ssnes_game_type game_type;
uint32_t cart_crc;
char gb_rom_path[256];
char bsx_rom_path[256];
char sufami_rom_path[2][256];
char gb_rom_path[PATH_MAX];
char bsx_rom_path[PATH_MAX];
char sufami_rom_path[2][PATH_MAX];
bool has_set_save_path;
bool has_set_state_path;
#ifdef HAVE_CONFIGFILE
char config_path[256];
char config_path[PATH_MAX];
#endif
char basename[256];
char savefile_name_srm[256];
char savefile_name_rtc[512]; // Make sure that fill_pathname has space.
char savefile_name_psrm[512];
char savefile_name_asrm[512];
char savefile_name_bsrm[512];
char savestate_name[256];
char ups_name[512];
char basename[PATH_MAX];
char savefile_name_srm[PATH_MAX];
char savefile_name_rtc[PATH_MAX]; // Make sure that fill_pathname has space.
char savefile_name_psrm[PATH_MAX];
char savefile_name_asrm[PATH_MAX];
char savefile_name_bsrm[PATH_MAX];
char savestate_name[PATH_MAX];
char xml_name[PATH_MAX];
bool ups_pref;
bool bps_pref;
char ups_name[PATH_MAX];
char bps_name[PATH_MAX];
unsigned state_slot;
struct
{
#ifdef HAVE_SRC
SRC_STATE *source;
#else
struct snes_geometry geom;
unsigned pitch; // If 0, has classic libsnes semantics.
char fullpath[PATH_MAX];
struct snes_system_timing timing;
bool timing_set;
bool need_fullpath;
} system;
struct
{
hermite_resampler_t *source;
#endif
float *data;
size_t data_ptr;
@@ -181,10 +255,21 @@ struct global
size_t nonblock_chunk_size;
size_t block_chunk_size;
double src_ratio;
bool use_float;
bool mute;
float *outsamples;
int16_t *conv_outsamples;
int16_t *rewind_buf;
size_t rewind_ptr;
size_t rewind_size;
dylib_t dsp_lib;
const ssnes_dsp_plugin_t *dsp_plugin;
void *dsp_handle;
} audio_data;
struct
@@ -206,65 +291,120 @@ struct global
// Rewind support.
state_manager_t *state_manager;
void *state_buf;
size_t state_size;
bool frame_is_reverse;
// Movie record support
bsv_movie_t *bsv_movie;
char bsv_movie_path[256];
bool bsv_movie_end;
bool bsv_movie_playback;
// Movie playback/recording support.
struct
{
bsv_movie_t *movie;
char movie_path[PATH_MAX];
bool movie_playback;
// Immediate playback/recording.
char movie_start_path[PATH_MAX];
bool movie_start_recording;
bool movie_start_playback;
bool movie_end;
} bsv;
bool sram_load_disable;
bool sram_save_disable;
bool use_sram;
// Pausing support
bool is_paused;
bool is_oneshot;
// Autosave support.
autosave_t *autosave[2];
// Netplay.
#ifdef HAVE_NETPLAY
netplay_t *netplay;
char netplay_server[256];
char netplay_server[PATH_MAX];
bool netplay_enable;
bool netplay_is_client;
bool netplay_is_spectate;
unsigned netplay_sync_frames;
uint16_t netplay_port;
#endif
// FFmpeg record.
#ifdef HAVE_FFMPEG
ffemu_t *rec;
char record_path[256];
char record_path[PATH_MAX];
bool recording;
unsigned record_width;
unsigned record_height;
#endif
struct
{
const uint16_t *data;
unsigned width;
unsigned height;
} frame_cache;
char title_buf[64];
struct
{
char** elems;
char **elems;
size_t size;
size_t ptr;
} shader_dir;
char sha256[64 + 1];
#ifdef HAVE_XML
cheat_manager_t *cheat;
#endif
bool error_in_init;
char error_string[1024];
jmp_buf error_sjlj_context;
};
void parse_config(void);
void config_set_defaults(void);
void ssnes_main_clear_state(void);
int ssnes_main_init(int argc, char *argv[]);
bool ssnes_main_iterate(void);
void ssnes_main_deinit(void);
extern struct settings g_settings;
extern struct global g_extern;
#ifdef SSNES_CONSOLE
extern struct console_settings g_console;
#endif
#define SSNES_LOG(msg, args...) do { \
#define SSNES_LOG(...) do { \
if (g_extern.verbose) \
fprintf(stderr, "SSNES: " msg, ##args); \
fprintf(stderr, "SSNES: " __VA_ARGS__); \
fflush(stderr); \
} while(0)
} while (0)
#define SSNES_ERR(msg, args...) do { \
fprintf(stderr, "SSNES [ERROR] :: " msg, ##args); \
#define SSNES_ERR(...) do { \
fprintf(stderr, "SSNES [ERROR] :: " __VA_ARGS__); \
fflush(stderr); \
} while(0)
} while (0)
#define SSNES_WARN(msg, args...) do { \
fprintf(stderr, "SSNES [WARN] :: " msg, ##args); \
#define SSNES_WARN(...) do { \
fprintf(stderr, "SSNES [WARN] :: " __VA_ARGS__); \
fflush(stderr); \
} while(0)
} while (0)
#ifndef max
#define max(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef min
#define min(a, b) ((a) < (b) ? (a) : (b))
#endif
#define SSNES_SCALE_BASE 256
static inline uint32_t next_pow2(uint32_t v)
{
@@ -278,6 +418,53 @@ static inline uint32_t next_pow2(uint32_t v)
return v;
}
static inline uint8_t is_little_endian(void)
{
union
{
uint16_t x;
uint8_t y[2];
} u;
u.x = 1;
return u.y[0];
}
#ifdef GEKKO
#include <unistd.h>
#endif
static inline void ssnes_sleep(unsigned msec)
{
#ifdef __CELLOS_LV2__
sys_timer_usleep(1000 * msec);
#elif defined(_WIN32)
Sleep(msec);
#elif defined(XENON)
udelay(1000 * msec);
#elif defined(GEKKO)
usleep(1000 * msec);
#else
struct timespec tv = {0};
tv.tv_sec = msec / 1000;
tv.tv_nsec = (msec % 1000) * 1000000;
nanosleep(&tv, NULL);
#endif
}
#define ssnes_assert(cond) \
if (!(cond)) { SSNES_ERR("Assertion failed at %s:%d!\n", __FILE__, __LINE__); exit(2); }
static inline void ssnes_fail(int error_code, const char *error)
{
// We cannot longjmp unless we're in ssnes_main_init().
// If not, something went very wrong, and we should just exit right away.
ssnes_assert(g_extern.error_in_init);
strlcpy(g_extern.error_string, error, sizeof(g_extern.error_string));
longjmp(g_extern.error_sjlj_context, error_code);
}
#endif
+187
View File
@@ -0,0 +1,187 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "getopt_ssnes.h"
#ifndef HAVE_GETOPT_LONG
#include <string.h>
#include "boolean.h"
#include <stddef.h>
#include <stdlib.h>
#include "msvc/msvc_compat.h"
#include "general.h"
char *optarg;
int optind, opterr, optopt;
static bool is_short_option(const char *str)
{
return str[0] == '-' && str[1] != '-';
}
static bool is_long_option(const char *str)
{
return str[0] == '-' && str[1] == '-';
}
static int find_short_index(char * const *argv)
{
for (int index = 0; argv[index]; index++)
{
if (is_short_option(argv[index]))
return index;
}
return -1;
}
static int find_long_index(char * const *argv)
{
for (int index = 0; argv[index]; index++)
{
if (is_long_option(argv[index]))
return index;
}
return -1;
}
static int parse_short(const char *optstring, char * const *argv)
{
char arg = argv[0][1];
if (arg == ':')
return '?';
const char *opt = strchr(optstring, arg);
if (!opt)
return '?';
bool multiple_opt = argv[0][2];
bool takes_arg = opt[1] == ':';
if (multiple_opt && takes_arg) // Makes little sense to allow.
return '?';
if (takes_arg)
{
optarg = argv[1];
optind += 2;
return optarg ? opt[0] : '?';
}
else if (multiple_opt)
{
memmove(&argv[0][1], &argv[0][2], strlen(&argv[0][2]) + 1);
return opt[0];
}
else
{
optind++;
return opt[0];
}
}
static int parse_long(const struct option *longopts, char * const *argv)
{
const struct option *opt = NULL;
for (size_t indice = 0; longopts[indice].name; indice++)
{
if (strcmp(longopts[indice].name, &argv[0][2]) == 0)
{
opt = &longopts[indice];
break;
}
}
if (!opt)
return '?';
// getopt_long has an "optional" arg, but we don't bother with that.
if (opt->has_arg && !argv[1])
return '?';
if (opt->has_arg)
{
optarg = argv[1];
optind += 2;
}
else
optind++;
if (opt->flag)
{
*opt->flag = opt->val;
return 0;
}
else
return opt->val;
}
static void shuffle_block(char **begin, char **last, char **end)
{
ptrdiff_t len = last - begin;
const char **tmp = (const char**)calloc(len, sizeof(const char*));
ssnes_assert(tmp);
memcpy(tmp, begin, sizeof(tmp));
memmove(begin, last, (end - last) * sizeof(char*));
memcpy(end - len, tmp, sizeof(tmp));
free(tmp);
}
int getopt_long(int argc, char *argv[],
const char *optstring, const struct option *longopts, int *longindex)
{
(void)longindex;
if (argc == 1)
return -1;
if (optind == 0)
optind = 1;
int short_index = find_short_index(&argv[optind]);
int long_index = find_long_index(&argv[optind]);
// We're done here.
if (short_index == -1 && long_index == -1)
return -1;
// Reorder argv so that non-options come last.
// Non-POSIXy, but that's what getopt does by default.
if ((short_index > 0) && ((short_index < long_index) || (long_index == -1)))
{
shuffle_block(&argv[optind], &argv[optind + short_index], &argv[argc]);
short_index = 0;
}
else if ((long_index > 0) && ((long_index < short_index) || (short_index == -1)))
{
shuffle_block(&argv[optind], &argv[optind + long_index], &argv[argc]);
long_index = 0;
}
ssnes_assert(short_index == 0 || long_index == 0);
if (short_index == 0)
return parse_short(optstring, &argv[optind]);
else if (long_index == 0)
return parse_long(longopts, &argv[optind]);
else
return '?';
}
#endif
+52
View File
@@ -0,0 +1,52 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_GETOPT_H
#define __SSNES_GETOPT_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
// Custom implementation of the GNU getopt_long for portability.
// Not designed to be fully compatible,
// but compatible with the features SSNES uses.
#ifdef HAVE_GETOPT_LONG
#include <getopt.h>
#else
// Avoid possible naming collitions during link since we prefer to use the actual name.
#define getopt_long(argc, argv, optstring, longopts, longindex) __getopt_long_ssnes(argc, argv, optstring, longopts, longindex)
struct option
{
const char *name;
int has_arg;
int *flag;
int val;
};
// argv[] is declared with char * const argv[] in GNU,
// but this makes no sense, as non-POSIX getopt_long mutates argv (non-opts are moved to the end).
int getopt_long(int argc, char *argv[],
const char *optstring, const struct option *longopts, int *longindex);
extern char *optarg;
extern int optind, opterr, optopt;
#endif
#endif
+278
View File
@@ -0,0 +1,278 @@
/////
// API header for external SSNES video and input plugins.
//
//
#ifndef __SSNES_VIDEO_DRIVER_H
#define __SSNES_VIDEO_DRIVER_H
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#ifdef SSNES_DLL_IMPORT
#define SSNES_API_EXPORT __declspec(dllimport)
#else
#define SSNES_API_EXPORT __declspec(dllexport)
#endif
#define SSNES_API_CALLTYPE __cdecl
#else
#define SSNES_API_EXPORT
#define SSNES_API_CALLTYPE
#endif
#define SSNES_GRAPHICS_API_VERSION 2
// Since we don't want to rely on C++ or C99 for a proper boolean type,
// make sure return semantics are perfectly clear ... ;)
#ifndef SSNES_OK
#define SSNES_OK 1
#endif
#ifndef SSNES_ERROR
#define SSNES_ERROR 0
#endif
#ifndef SSNES_TRUE
#define SSNES_TRUE 1
#endif
#ifndef SSNES_FALSE
#define SSNES_FALSE 0
#endif
#define SSNES_COLOR_FORMAT_XRGB1555 0
#define SSNES_COLOR_FORMAT_ARGB8888 1
#define SSNES_INPUT_SCALE_BASE 256
typedef struct py_state py_state_t;
// Create a new runtime for Python.
// py_script: The python script to be loaded. If is_file is true, this will be the full path to a file.
// If false, it will be an UTF-8 encoded string of the script.
// is_file: Tells if py_script is the path to a script, or a script itself.
// py_class: name of the class being instantiated.
typedef py_state_t *(*python_state_new_cb)(const char *py_script, unsigned is_file, const char *py_class);
// Grabs a value from the Python runtime.
// id: The uniform (class method) to be called.
// frame_count: Passes frame_count as an argument to the script.
typedef float (*python_state_get_cb)(py_state_t *handle, const char *id, unsigned frame_count);
// Frees the runtime.
typedef void (*python_state_free_cb)(py_state_t *handle);
typedef struct ssnes_video_info
{
// Width of window.
// If fullscreen mode is requested,
// a width of 0 means the resolution of the desktop should be used.
unsigned width;
// Height of window.
// If fullscreen mode is requested,
// a height of 0 means the resolutiof the desktop should be used.
unsigned height;
// If true, start the window in fullscreen mode.
int fullscreen;
// If true, VSync should be enabled.
int vsync;
// If true, the output image should have the aspect ratio
// as set in aspect_ratio.
int force_aspect;
// Aspect ratio. Only takes effect if force_aspect is enabled.
float aspect_ratio;
// Requests that the image is smoothed,
// using bilinear filtering or otherwise.
// If this cannot be implemented efficiently, this can be disregarded.
// If smooth is false, nearest-neighbor scaling is requested.
int smooth;
// input_scale defines the maximum size of the picture that will
// ever be used with the frame callback.
// The maximum resolution is a multiple of 256x256 size (SSNES_INPUT_SCALE_BASE),
// so an input scale of 2
// means you should allocate a texture or of 512x512.
unsigned input_scale;
// Defines the coloring format used of the input frame.
// XRGB1555 format is 16-bit and has byte ordering: 0RRRRRGGGGGBBBBB,
// in native endian.
// ARGB8888 is AAAAAAAARRRRRRRRGGGGGGGGBBBBBBBB, native endian.
// Alpha channel should be disregarded.
int color_format;
// If non-NULL, requests the use of an XML shader.
// Can be disregarded.
const char *xml_shader;
// If non-NULL, requests the use of a Cg shader.
// Can be disregarded.
// If both are non-NULL,
// Cg or XML could be used at the discretion of the plugin.
const char *cg_shader;
// Requestes that a certain
// TTF font is used for rendering messages to the screen.
// Can be disregarded.
const char *ttf_font;
unsigned ttf_font_size;
unsigned ttf_font_color; // Font color, in format ARGB8888. Alpha should be disregarded.
// A title that should be displayed in the title bar of the window.
const char *title_hint;
// Functions to peek into the python runtime for shaders.
// Check typedefs above for explanation.
// These may be NULL if SSNES is not built with Python support.
python_state_new_cb python_state_new;
python_state_get_cb python_state_get;
python_state_free_cb python_state_free;
} ssnes_video_info_t;
// Some convenience macros.
// Extract which axes to test for in negative or positive direction.
// May be equal to SSNES_NO_AXIS, which means testing should not occur.
#define SSNES_AXIS_NEG_GET(x) (((unsigned)(x) >> 16) & 0xFFFFU)
#define SSNES_AXIS_POS_GET(x) ((unsigned)(x) & 0xFFFFU)
// I hope no joypad will ever have this many buttons or axes ... ;)
// If joykey is this value, do not check that button.
#define SSNES_NO_AXIS (0xFFFFFFFFU)
#define SSNES_NO_BTN ((unsigned short)0xFFFFU)
// Masks to test on joykey which hat direction is to be tested for.
#define SSNES_HAT_UP_MASK (1 << 15)
#define SSNES_HAT_DOWN_MASK (1 << 14)
#define SSNES_HAT_LEFT_MASK (1 << 13)
#define SSNES_HAT_RIGHT_MASK (1 << 12)
#define SSNES_HAT_MAP(x, hat) ((x & ((1 << 12) - 1)) | hat)
#define SSNES_HAT_MASK (SSNES_HAT_UP_MASK | SSNES_HAT_DOWN_MASK | \
SSNES_HAT_LEFT_MASK | SSNES_HAT_RIGHT_MASK)
// Test this on the joykey. If true, we want to test for a joypad hat
// rather than a button.
#define SSNES_GET_HAT_DIR(x) (x & SSNES_HAT_MASK)
// Gets the joypad hat to be tested for.
// Only valid when SSNES_GET_HAT_DIR() returns true.
#define SSNES_GET_HAT(x) (x & (~SSNES_HAT_MASK))
// key, joykey and joyaxis are all checked at the same time.
// If any one of these are pressed, return 1 in state callback.
struct ssnes_keybind
{
// If analog_x is true, we request an analog device to be polled
// rather than normal keys.
// The returned value should be the delta of
// last frame and current frame in the X-axis.
int analog_x;
// If analog_y is true, we request an analog device to be polled
// rather than normal keys.
// The returned value should be the delta of
// last frame and current frame in the Y-axis.
int analog_y;
// Keyboard key. The key values use the SDL 1.2 keysyms,
// which probably need to be transformed to the native format.
// The actual keysyms SSNES uses are found in input/keysym.h.
unsigned short key;
// Joypad key. Joypad POV (hats) are embedded into this key as well.
unsigned short joykey;
// Joypad axis. Negative and positive axes are embedded into this variable.
unsigned joyaxis;
};
typedef struct ssnes_input_driver
{
// Inits input driver.
// Joypad index denotes which joypads are desired for the various players.
// Should an entry be negative,
// do not open joypad for that player.
// Threshold states the minimum offset that a joypad axis
// has to be held for it to be registered.
// The range of this is [0, 1],
// where 0 means any displacement will register,
// and 1 means the axis has to be pressed all the way to register.
void *(*init)(const int joypad_index[5], float axis_threshold);
// Polls input. Called once every frame.
void (*poll)(void *data);
// Queries input state for a certain key on a certain player.
// Players are 1 - 5.
// For digital inputs, pressed key is 1, not pressed key is 0.
// Analog values have same range as a signed 16-bit integer.
int (*input_state)(void *data, const struct ssnes_keybind *bind,
unsigned player);
// Frees the input struct.
void (*free)(void *data);
// Human readable indentification string.
const char *ident;
} ssnes_input_driver_t;
typedef struct ssnes_video_driver
{
// Inits the video driver. Returns an opaque handle pointer to the driver.
// Returns NULL on error.
//
// Should the video driver request that a certain input driver is used,
// it is possible to set the driver to *input.
// If no certain driver is desired, set *input to NULL.
void *(*init)(const ssnes_video_info_t *video,
const ssnes_input_driver_t **input);
// Updates frame on the screen.
// Frame can be either XRGB1555 or ARGB32 format
// depending on rgb32 setting in ssnes_video_info_t.
// Pitch is the distance in bytes between two scanlines in memory.
//
// When msg is non-NULL,
// it's a message that should be displayed to the user.
int (*frame)(void *data, const void *frame,
unsigned width, unsigned height, unsigned pitch, const char *msg);
// Requests nonblocking operation.
// True = VSync is turned off.
// False = VSync is turned on.
void (*set_nonblock_state)(void *data, int toggle);
// This must return false when the user exits the emulator.
int (*alive)(void *data);
// Does the window have focus?
int (*focus)(void *data);
// Frees the video driver.
void (*free)(void *data);
// A human-readable identification of the video driver.
const char *ident;
// Needs to be defined to SSNES_GRAPHICS_API_VERSION.
// This is used to detect API/ABI mismatches.
int api_version;
} ssnes_video_driver_t;
// Called by SSNES on startup to get a driver handle.
// This is NOT dynamically allocated.
SSNES_API_EXPORT const ssnes_video_driver_t* SSNES_API_CALLTYPE
ssnes_video_init(void);
#ifdef __cplusplus
}
#endif
#endif
+364
View File
@@ -0,0 +1,364 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
// Loader for external API plugins.
#define SSNES_DLL_IMPORT
#include "ext/ssnes_video.h"
#include "../boolean.h"
#include <stdlib.h>
#include <stdint.h>
#include "../dynamic.h"
#include "../general.h"
#include "sdlwrap.h"
#include "gfx_common.h"
#ifdef HAVE_FREETYPE
#include "fonts.h"
#endif
#ifdef HAVE_PYTHON
#define PY_STATE_OMIT_DECLARATION
#include "py_state/py_state.h"
#endif
static bool g_input_dead = true;
static bool g_video_dead = true;
static dylib_t g_lib = NULL;
/////////// Input hook
typedef struct
{
const ssnes_input_driver_t *driver;
void *handle;
} input_ext_t;
static void *input_ext_init(void)
{
g_input_dead = false;
return calloc(1, sizeof(input_ext_t));
}
static void input_ext_poll(void *data)
{
input_ext_t *ext = (input_ext_t*)data;
ext->driver->poll(ext->handle);
}
static int16_t input_ext_input_state(void *data, const struct snes_keybind **snes_keybinds, bool port, unsigned device, unsigned index, unsigned id)
{
input_ext_t *ext = (input_ext_t*)data;
unsigned player = 0;
if (device == SNES_DEVICE_MULTITAP)
player = (port == SNES_PORT_1) ? 1 : index + 2;
else
player = (port == SNES_PORT_1) ? 1 : 2;
const struct snes_keybind *ssnes_bind = NULL;
for (unsigned i = 0; g_settings.input.binds[player - 1][i].id != -1; i++)
{
if (g_settings.input.binds[player - 1][i].id == (int)id)
{
ssnes_bind = &g_settings.input.binds[player - 1][i];
break;
}
}
if (ssnes_bind)
{
struct ssnes_keybind bind = {0};
bind.key = ssnes_bind->key;
bind.joykey = ssnes_bind->joykey;
bind.joyaxis = ssnes_bind->joyaxis;
return ext->driver->input_state(ext->handle, &bind, player);
}
else
return 0;
}
static bool input_ext_key_pressed(void *data, int key)
{
input_ext_t *ext = (input_ext_t*)data;
const struct snes_keybind *ssnes_bind = NULL;
for (unsigned i = 0; g_settings.input.binds[0][i].id != -1; i++)
{
if (g_settings.input.binds[0][i].id == key)
{
ssnes_bind = &g_settings.input.binds[0][i];
break;
}
}
if (ssnes_bind)
{
struct ssnes_keybind bind = {0};
bind.key = ssnes_bind->key;
bind.joykey = ssnes_bind->joykey;
bind.joyaxis = ssnes_bind->joyaxis;
return ext->driver->input_state(ext->handle, &bind, 1);
}
else
return false;
}
static void input_ext_free(void *data)
{
input_ext_t *ext = (input_ext_t*)data;
if (ext)
{
if (ext->driver && ext->handle)
ext->driver->free(ext->handle);
if (g_video_dead)
{
dylib_close(g_lib);
g_lib = NULL;
}
g_input_dead = true;
free(ext);
}
}
static const input_driver_t input_ext = {
input_ext_init,
input_ext_poll,
input_ext_input_state,
input_ext_key_pressed,
input_ext_free,
"ext"
};
//////////// Video hook
typedef struct
{
const ssnes_video_driver_t *driver;
void *handle;
} ext_t;
static void video_ext_free(void *data)
{
ext_t *ext = (ext_t*)data;
if (ext)
{
if (ext->driver && ext->handle)
ext->driver->free(ext->handle);
if (g_input_dead)
{
dylib_close(g_lib);
g_lib = NULL;
}
g_video_dead = true;
free(ext);
}
}
static bool video_ext_focus(void *data)
{
ext_t *ext = (ext_t*)data;
return ext->driver->focus(ext->handle);
}
static bool video_ext_alive(void *data)
{
ext_t *ext = (ext_t*)data;
return ext->driver->alive(ext->handle);
}
static void video_ext_set_nonblock_state(void *data, bool state)
{
ext_t *ext = (ext_t*)data;
ext->driver->set_nonblock_state(ext->handle, state);
}
static bool video_ext_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
{
ext_t *ext = (ext_t*)data;
return ext->driver->frame(ext->handle, frame, width, height, pitch, msg);
}
static void *setup_input(ext_t *ext, const ssnes_input_driver_t *driver)
{
int joypad_index[5];
for (unsigned i = 0; i < 5; i++)
joypad_index[i] = g_settings.input.joypad_map[i] == SSNES_NO_JOYPAD ? -1 : g_settings.input.joypad_map[i];
void *handle = driver->init(joypad_index, g_settings.input.axis_threshold);
if (!handle)
return NULL;
input_ext_t *wrap_handle = (input_ext_t*)input_ext.init();
if (!wrap_handle)
return NULL;
wrap_handle->handle = handle;
wrap_handle->driver = driver;
return wrap_handle;
}
static bool setup_video(ext_t *ext, const video_info_t *video, const input_driver_t **input, void **input_data)
{
SSNES_LOG("Loaded driver: \"%s\"\n", ext->driver->ident ? ext->driver->ident : "Unknown");
if (SSNES_GRAPHICS_API_VERSION != ext->driver->api_version)
{
SSNES_ERR("API version mismatch detected!\n");
SSNES_ERR("Required API version: %d, Library version: %d\n", SSNES_GRAPHICS_API_VERSION, ext->driver->api_version);
return false;
}
const char *cg_shader = NULL;
const char *xml_shader = NULL;
enum ssnes_shader_type type = g_settings.video.shader_type;
if ((type == SSNES_SHADER_CG || type == SSNES_SHADER_AUTO) && *g_settings.video.cg_shader_path)
cg_shader = g_settings.video.cg_shader_path;
else if ((type == SSNES_SHADER_BSNES || type == SSNES_SHADER_AUTO) && *g_settings.video.bsnes_shader_path)
xml_shader = g_settings.video.bsnes_shader_path;
int font_color_r = g_settings.video.msg_color_r * 255;
int font_color_g = g_settings.video.msg_color_g * 255;
int font_color_b = g_settings.video.msg_color_b * 255;
font_color_r = font_color_r > 255 ? 255 : (font_color_r < 0 ? 0 : font_color_r);
font_color_g = font_color_g > 255 ? 255 : (font_color_g < 0 ? 0 : font_color_g);
font_color_b = font_color_b > 255 ? 255 : (font_color_b < 0 ? 0 : font_color_b);
const char *font = NULL;
if (g_settings.video.font_enable)
{
#ifdef HAVE_FREETYPE
if (*g_settings.video.font_path)
font = g_settings.video.font_path;
else
font = font_renderer_get_default_font();
#else
font = *g_settings.video.font_path ?
g_settings.video.font_path : NULL;
#endif
}
char title_buf[128];
gfx_window_title_reset();
gfx_window_title(title_buf, sizeof(title_buf));
ssnes_video_info_t info = {0};
info.width = video->width;
info.height = video->height;
info.fullscreen = video->fullscreen;
info.vsync = video->vsync;
info.force_aspect = video->force_aspect;
info.aspect_ratio = g_settings.video.aspect_ratio;
info.smooth = video->smooth;
info.input_scale = video->input_scale;
info.color_format = video->rgb32 ? SSNES_COLOR_FORMAT_ARGB8888 : SSNES_COLOR_FORMAT_XRGB1555;
info.xml_shader = xml_shader;
info.cg_shader = cg_shader;
info.ttf_font = font;
info.ttf_font_size = g_settings.video.font_size;
info.ttf_font_color = (font_color_r << 16) | (font_color_g << 8) | (font_color_b << 0);
info.title_hint = title_buf;
#ifdef HAVE_PYTHON
info.python_state_new = py_state_new;
info.python_state_get = py_state_get;
info.python_state_free = py_state_free;
#endif
const ssnes_input_driver_t *input_driver = NULL;
ext->handle = ext->driver->init(&info, &input_driver);
if (!ext->handle)
return false;
*input = input_driver ? &input_ext : NULL;
if (input_driver)
*input_data = setup_input(ext, input_driver);
else
*input_data = NULL;
return true;
}
static void *video_ext_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
ext_t *ext = (ext_t*)calloc(1, sizeof(*ext));
if (!ext)
return NULL;
const ssnes_video_driver_t *(*video_init)(void) = NULL;
if (!(*g_settings.video.external_driver))
{
SSNES_ERR("External driver needs video_external_driver path to be set!\n");
goto error;
}
g_lib = dylib_load(g_settings.video.external_driver);
if (!g_lib)
{
SSNES_ERR("Failed to open library: \"%s\"\n", g_settings.video.external_driver);
goto error;
}
video_init = (const ssnes_video_driver_t *(*)(void))dylib_proc(g_lib, "ssnes_video_init");
if (!video_init)
{
SSNES_ERR("Couldn't find function ssnes_video_init in library ...\n");
goto error;
}
ext->driver = video_init();
if (!ext->driver)
{
SSNES_ERR("External driver returned invalid driver handle.\n");
goto error;
}
if (!setup_video(ext, video, input, input_data))
{
SSNES_ERR("Failed to start driver.\n");
goto error;
}
g_video_dead = false;
return ext;
error:
video_ext_free(ext);
return NULL;
}
const video_driver_t video_ext = {
video_ext_init,
video_ext_frame,
video_ext_set_nonblock_state,
video_ext_alive,
video_ext_focus,
NULL,
video_ext_free,
"ext"
};
+46 -9
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -16,10 +16,10 @@
*/
#include "fonts.h"
#include "../file.h"
#include <string.h>
#include <stddef.h>
#include <stdlib.h>
#include <assert.h>
#include <ft2build.h>
#include FT_FREETYPE_H
@@ -33,11 +33,12 @@ struct font_renderer
font_renderer_t *font_renderer_new(const char *font_path, unsigned font_size)
{
(void)font_size;
font_renderer_t *handle = calloc(1, sizeof(*handle));
FT_Error err;
font_renderer_t *handle = (font_renderer_t*)calloc(1, sizeof(*handle));
if (!handle)
goto error;
FT_Error err = FT_Init_FreeType(&handle->lib);
err = FT_Init_FreeType(&handle->lib);
if (err)
goto error;
@@ -78,13 +79,17 @@ void font_renderer_msg(font_renderer_t *handle, const char *msg, struct font_out
if (!err)
{
struct font_output *tmp = calloc(1, sizeof(*tmp));
assert(tmp);
struct font_output *tmp = (struct font_output*)calloc(1, sizeof(*tmp));
if (!tmp)
break;
//fprintf(stderr, "Char: %c, off_x: %d, off_y: %d, bmp_left: %d, bmp_top: %d\n", msg[i], off_x, off_y, slot->bitmap_left, slot->bitmap_top);
tmp->output = (uint8_t*)malloc(slot->bitmap.pitch * slot->bitmap.rows);
if (!tmp->output)
{
free(tmp);
break;
}
tmp->output = malloc(slot->bitmap.pitch * slot->bitmap.rows);
assert(tmp->output);
memcpy(tmp->output, slot->bitmap.buffer, slot->bitmap.pitch * slot->bitmap.rows);
tmp->width = slot->bitmap.width;
@@ -128,3 +133,35 @@ void font_renderer_free(font_renderer_t *handle)
if (handle->lib)
FT_Done_FreeType(handle->lib);
}
// Not the cleanest way to do things for sure, but should hopefully work ... :)
#if defined(_WIN32)
static const char *font_paths[] = {
"C:\\Windows\\Fonts\\consola.ttf",
"C:\\Windows\\Fonts\\verdana.ttf",
#elif defined(__APPLE__)
static const char *font_paths[] = {
"/Library/Fonts/Microsoft/Candara.ttf",
"/Library/Fonts/Verdana.ttf",
"/Library/Fonts/Tahoma.ttf",
#else
static const char *font_paths[] = {
"/usr/share/fonts/TTF/DejaVuSansMono.ttf",
"/usr/share/fonts/TTF/DejaVuSans.ttf",
#endif
"osd-font.ttf", // Magic font to search for, useful for distribution.
};
// Highly OS/platform dependent.
const char *font_renderer_get_default_font(void)
{
for (size_t i = 0; i < sizeof(font_paths) / sizeof(font_paths[0]); i++)
{
if (path_file_exists(font_paths[i]))
return font_paths[i];
}
return NULL;
}
+8 -4
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -25,10 +25,10 @@ typedef struct font_renderer font_renderer_t;
struct font_output
{
uint8_t *output;
uint8_t *output; // 8-bit intensity.
unsigned width, height, pitch;
int off_x, off_y;
struct font_output *next;
struct font_output *next; // linked list.
};
struct font_output_list
@@ -37,8 +37,12 @@ struct font_output_list
};
font_renderer_t *font_renderer_new(const char *font_path, unsigned font_size);
void font_renderer_msg(font_renderer_t *handle, const char *msg, struct font_output_list *output);
void font_renderer_msg(font_renderer_t *handle, const char *msg,
struct font_output_list *output);
void font_renderer_free_output(struct font_output_list *list);
void font_renderer_free(font_renderer_t *handle);
const char *font_renderer_get_default_font(void);
#endif
+92 -9
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -16,8 +16,35 @@
*/
#include "gfx_common.h"
#include "general.h"
#include "../general.h"
#ifndef _MSC_VER
#include <sys/time.h>
#else
#include <winsock2.h>
#include <mmsystem.h>
static int gettimeofday(struct timeval *val, void *dummy)
{
(void)dummy;
DWORD msec = timeGetTime();
uint64_t usec = msec * 1000;
val->tv_sec = usec / 1000000;
val->tv_usec = usec % 1000000;
return 0;
}
#endif
#ifdef __CELLOS_LV2__
#include <sys/sys_time.h>
static int gettimeofday(struct timeval *val, void *dummy)
{
(void)dummy;
uint64_t usec = sys_time_get_system_time();
val->tv_sec = usec / 1000000;
val->tv_usec = usec % 1000000;
return 0;
}
#endif
static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, int frames)
{
@@ -25,21 +52,26 @@ static float tv_to_fps(const struct timeval *tv, const struct timeval *new_tv, i
return frames/time;
}
static unsigned gl_frames = 0;
void gfx_window_title_reset(void)
{
gl_frames = 0;
}
bool gfx_window_title(char *buf, size_t size)
{
static int frames = 0;
static struct timeval tv;
struct timeval new_tv;
bool ret = false;
if (frames == 0)
if (gl_frames == 0)
{
gettimeofday(&tv, NULL);
snprintf(buf, size, g_extern.title_buf);
snprintf(buf, size, "%s", g_extern.title_buf);
ret = true;
}
if ((frames % 180) == 0 && frames > 0)
else if ((gl_frames % 180) == 0)
{
gettimeofday(&new_tv, NULL);
struct timeval tmp_tv = tv;
@@ -47,12 +79,63 @@ bool gfx_window_title(char *buf, size_t size)
float fps = tv_to_fps(&tmp_tv, &new_tv, 180);
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, frames);
snprintf(buf, size, "%s || FPS: %6.1f || Frames: %d", g_extern.title_buf, fps, gl_frames);
ret = true;
}
frames++;
gl_frames++;
return ret;
}
#ifdef _WIN32
#include <windows.h>
#include "../dynamic.h"
// We only load this library once, so we let it be unloaded at application shutdown,
// since unloading it early seems to cause issues on some systems.
static dylib_t dwmlib = NULL;
static void gfx_dwm_shutdown(void)
{
if (dwmlib)
dylib_close(dwmlib);
}
void gfx_set_dwm(void)
{
static bool inited = false;
if (inited)
return;
inited = true;
dwmlib = dylib_load("dwmapi.dll");
if (!dwmlib)
{
SSNES_LOG("Did not find dwmapi.dll.\n");
return;
}
atexit(gfx_dwm_shutdown);
HRESULT (WINAPI *mmcss)(BOOL) = (HRESULT (WINAPI*)(BOOL))dylib_proc(dwmlib, "DwmEnableMMCSS");
if (mmcss)
{
SSNES_LOG("Setting multimedia scheduling for DWM.\n");
mmcss(TRUE);
}
if (!g_settings.video.disable_composition)
return;
HRESULT (WINAPI *composition_enable)(UINT) = (HRESULT (WINAPI*)(UINT))dylib_proc(dwmlib, "DwmEnableComposition");
if (!composition_enable)
{
SSNES_ERR("Did not find DwmEnableComposition ...\n");
return;
}
HRESULT ret = composition_enable(0);
if (FAILED(ret))
SSNES_ERR("Failed to set composition state ...\n");
}
#endif
+7 -2
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -19,8 +19,13 @@
#define __GFX_COMMON_H
#include <stddef.h>
#include <stdbool.h>
#include "../boolean.h"
bool gfx_window_title(char *buf, size_t size);
void gfx_window_title_reset(void);
#ifdef _WIN32
void gfx_set_dwm(void);
#endif
#endif
+550 -198
View File
File diff suppressed because it is too large. Load diff
+28 -6
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -18,11 +18,19 @@
#ifndef __GL_COMMON_H
#define __GL_COMMON_H
#include "general.h"
#include "../general.h"
#ifdef __APPLE__
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#if defined(__APPLE__)
#include <OpenGL/gl.h>
#include <OpenGL/glext.h>
#elif defined(__CELLOS_LV2__)
#include <PSGL/psgl.h>
#include <PSGL/psglu.h>
#include <GLES/glext.h>
#else
#define GL_GLEXT_PROTOTYPES
#include <GL/gl.h>
@@ -52,9 +60,6 @@ static inline bool gl_check_error(void)
case GL_OUT_OF_MEMORY:
SSNES_ERR("GL: Out of memory. Harhar.\n");
break;
case GL_TABLE_TOO_LARGE:
SSNES_ERR("GL: Table too large. Big tables scare you! :(\n");
break;
case GL_NO_ERROR:
return true;
break;
@@ -93,4 +98,21 @@ struct gl_fbo_scale
bool valid;
};
struct gl_tex_info
{
GLuint tex;
GLfloat input_size[2];
GLfloat tex_size[2];
GLfloat coord[8];
};
// Windows ... <_<
#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32)
extern PFNGLCLIENTACTIVETEXTUREPROC pglClientActiveTexture;
extern PFNGLACTIVETEXTUREPROC pglActiveTexture;
#else
#define pglClientActiveTexture glClientActiveTexture
#define pglActiveTexture glActiveTexture
#endif
#endif
+183
View File
@@ -0,0 +1,183 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif
#include "image.h"
#include "../file.h"
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include "../general.h"
#ifdef HAVE_SDL_IMAGE
#include "SDL_image.h"
bool texture_image_load(const char *path, struct texture_image *out_img)
{
SDL_Surface *img = IMG_Load(path);
if (!img)
return false;
out_img->width = img->w;
out_img->height = img->h;
size_t size = out_img->width * out_img->height * sizeof(uint32_t);
out_img->pixels = (uint32_t*)malloc(size);
if (!out_img->pixels)
{
SDL_FreeSurface(img);
return false;
}
const SDL_PixelFormat *fmt = img->format;
SSNES_LOG("SDL_image: %dx%d @ %d bpp\n", img->w, img->h, img->format->BitsPerPixel);
if (img->format->BitsPerPixel == 32)
{
for (int y = 0; y < img->h; y++)
{
uint32_t *dst = out_img->pixels + y * img->w;
const uint32_t *src = (const uint32_t*)img->pixels + y * img->pitch / sizeof(uint32_t);
for (int x = 0; x < img->w; x++)
{
uint32_t r = (src[x] & fmt->Rmask) >> fmt->Rshift;
uint32_t g = (src[x] & fmt->Gmask) >> fmt->Gshift;
uint32_t b = (src[x] & fmt->Bmask) >> fmt->Bshift;
uint32_t a = (src[x] & fmt->Amask) >> fmt->Ashift;
dst[x] = (b << 24) | (g << 16) | (r << 8) | a;
}
}
}
else if (img->format->BitsPerPixel == 24)
{
for (int y = 0; y < img->h; y++)
{
uint32_t *dst = out_img->pixels + y * img->w;
const uint8_t *src = (const uint8_t*)img->pixels + y * img->pitch;
for (int x = 0; x < img->w; x++)
{
// Correct?
uint32_t color = 0;
color |= src[3 * x + 0] << 0;
color |= src[3 * x + 1] << 8;
color |= src[3 * x + 2] << 16;
uint32_t r = (color & fmt->Rmask) >> fmt->Rshift;
uint32_t g = (color & fmt->Gmask) >> fmt->Gshift;
uint32_t b = (color & fmt->Bmask) >> fmt->Bshift;
dst[x] = (b << 24) | (g << 16) | (r << 8) | 0xff;
}
}
}
else
{
SSNES_ERR("8-bit and 16-bit image support are not implemented.\n");
SDL_FreeSurface(img);
return false;
}
SDL_FreeSurface(img);
return true;
}
#else
bool texture_image_load(const char *path, struct texture_image *out_img)
{
// TODO: Check more gracefully.
if (!strstr(path, ".tga"))
return false;
void *raw_buf = NULL;
ssize_t len = read_file(path, &raw_buf);
if (len < 0)
return false;
uint8_t *buf = (uint8_t*)raw_buf;
if (buf[2] != 2) // Uncompressed RGB
{
free(buf);
return false;
}
unsigned width = 0;
unsigned height = 0;
uint8_t info[6];
memcpy(info, buf + 12, 6);
width = info[0] + ((unsigned)info[1] * 256);
height = info[2] + ((unsigned)info[3] * 256);
unsigned bits = info[4];
SSNES_LOG("Loaded TGA: (%ux%u @ %u bpp)\n", width, height, bits);
unsigned size = width * height * sizeof(uint32_t);
out_img->pixels = (uint32_t*)malloc(size);
out_img->width = width;
out_img->height = height;
if (!out_img->pixels)
{
free(buf);
return false;
}
const uint8_t *tmp = buf + 18;
if (bits == 32)
{
for (unsigned i = 0; i < width * height; i++)
{
uint32_t b = tmp[i * 4 + 0];
uint32_t g = tmp[i * 4 + 1];
uint32_t r = tmp[i * 4 + 2];
uint32_t a = tmp[i * 4 + 3];
out_img->pixels[i] = (b << 24) | (g << 16) | (r << 8) | a;
}
}
else if (bits == 24)
{
for (unsigned i = 0; i < width * height; i++)
{
uint32_t b = tmp[i * 3 + 0];
uint32_t g = tmp[i * 3 + 1];
uint32_t r = tmp[i * 3 + 2];
uint32_t a = 0xff;
out_img->pixels[i] = (b << 24) | (g << 16) | (r << 8) | a;
}
}
else
{
free(buf);
free(out_img->pixels);
out_img->pixels = NULL;
return false;
}
free(buf);
return true;
}
#endif
+34
View File
@@ -0,0 +1,34 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_IMAGE_H
#define __SSNES_IMAGE_H
#include <stdint.h>
#include "../boolean.h"
struct texture_image
{
unsigned width;
unsigned height;
uint32_t *pixels;
};
bool texture_image_load(const char *path, struct texture_image* img);
#endif
+353
View File
@@ -0,0 +1,353 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <Python.h>
#include "../../boolean.h"
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "../../dynamic.h"
#include "../../libsnes.hpp"
#include "py_state.h"
#include "../../general.h"
#include "../../strl.h"
#include "../../posix_string.h"
#include "../../file.h"
#define PY_READ_FUNC_DECL(RAMTYPE) py_read_##RAMTYPE
#define PY_READ_FUNC(RAMTYPE) \
static PyObject* PY_READ_FUNC_DECL(RAMTYPE) (PyObject *self, PyObject *args) \
{ \
(void)self; \
\
const uint8_t *data = psnes_get_memory_data(SNES_MEMORY_##RAMTYPE); \
if (!data) \
{ \
Py_INCREF(Py_None); \
return Py_None; \
} \
unsigned max = psnes_get_memory_size(SNES_MEMORY_##RAMTYPE); \
\
unsigned addr; \
if (!PyArg_ParseTuple(args, "I", &addr)) \
return NULL; \
\
if (addr >= max || addr < 0) \
{ \
Py_INCREF(Py_None); \
return Py_None; \
} \
\
return PyLong_FromLong((long)data[addr]); \
}
PY_READ_FUNC(WRAM)
PY_READ_FUNC(VRAM)
PY_READ_FUNC(APURAM)
PY_READ_FUNC(CGRAM)
PY_READ_FUNC(OAM)
static PyObject *py_read_input(PyObject *self, PyObject *args)
{
(void)self;
if (!driver.input_data)
return PyBool_FromLong(0);
unsigned player;
unsigned key;
if (!PyArg_ParseTuple(args, "II", &player, &key))
return NULL;
if (player > MAX_PLAYERS || player < 1 || key >= SSNES_FIRST_META_KEY)
return NULL;
static const struct snes_keybind *binds[MAX_PLAYERS] = {
g_settings.input.binds[0],
g_settings.input.binds[1],
g_settings.input.binds[2],
g_settings.input.binds[3],
g_settings.input.binds[4],
};
int16_t res = driver.input->input_state(driver.input_data,
binds, player > 1,
player > 2 ? SNES_DEVICE_MULTITAP : SNES_DEVICE_JOYPAD,
player > 2 ? player - 2 : 0,
key);
return PyBool_FromLong(res);
}
static PyObject *py_read_input_meta(PyObject *self, PyObject *args)
{
(void)self;
if (!driver.input_data)
return PyBool_FromLong(0);
unsigned key;
if (!PyArg_ParseTuple(args, "I", &key))
return NULL;
if (key < SSNES_FIRST_META_KEY)
return NULL;
bool ret = driver.input->key_pressed(driver.input_data, key);
return PyBool_FromLong(ret);
}
static PyMethodDef SNESMethods[] = {
{ "read_wram", PY_READ_FUNC_DECL(WRAM), METH_VARARGS, "Read WRAM from SNES." },
{ "read_vram", PY_READ_FUNC_DECL(VRAM), METH_VARARGS, "Read VRAM from SNES." },
{ "read_apuram", PY_READ_FUNC_DECL(APURAM), METH_VARARGS, "Read APURAM from SNES." },
{ "read_cgram", PY_READ_FUNC_DECL(CGRAM), METH_VARARGS, "Read CGRAM from SNES." },
{ "read_oam", PY_READ_FUNC_DECL(OAM), METH_VARARGS, "Read OAM from SNES." },
{ "input", py_read_input, METH_VARARGS, "Read input state from SNES." },
{ "input_meta", py_read_input_meta, METH_VARARGS, "Read SSNES specific input." },
{ NULL, NULL, 0, NULL }
};
#define DECL_ATTR_SNES(attr) PyObject_SetAttrString(mod, #attr, PyLong_FromLong(SNES_DEVICE_ID_JOYPAD_##attr))
#define DECL_ATTR_SSNES(attr) PyObject_SetAttrString(mod, #attr, PyLong_FromLong(SSNES_##attr))
static void py_set_attrs(PyObject *mod)
{
DECL_ATTR_SNES(B);
DECL_ATTR_SNES(Y);
DECL_ATTR_SNES(SELECT);
DECL_ATTR_SNES(START);
DECL_ATTR_SNES(UP);
DECL_ATTR_SNES(DOWN);
DECL_ATTR_SNES(LEFT);
DECL_ATTR_SNES(RIGHT);
DECL_ATTR_SNES(A);
DECL_ATTR_SNES(X);
DECL_ATTR_SNES(L);
DECL_ATTR_SNES(R);
DECL_ATTR_SSNES(FAST_FORWARD_KEY);
DECL_ATTR_SSNES(FAST_FORWARD_HOLD_KEY);
DECL_ATTR_SSNES(LOAD_STATE_KEY);
DECL_ATTR_SSNES(SAVE_STATE_KEY);
DECL_ATTR_SSNES(FULLSCREEN_TOGGLE_KEY);
DECL_ATTR_SSNES(QUIT_KEY);
DECL_ATTR_SSNES(STATE_SLOT_PLUS);
DECL_ATTR_SSNES(STATE_SLOT_MINUS);
DECL_ATTR_SSNES(AUDIO_INPUT_RATE_PLUS);
DECL_ATTR_SSNES(AUDIO_INPUT_RATE_MINUS);
DECL_ATTR_SSNES(REWIND);
DECL_ATTR_SSNES(MOVIE_RECORD_TOGGLE);
DECL_ATTR_SSNES(PAUSE_TOGGLE);
DECL_ATTR_SSNES(FRAMEADVANCE);
DECL_ATTR_SSNES(RESET);
DECL_ATTR_SSNES(SHADER_NEXT);
DECL_ATTR_SSNES(SHADER_PREV);
DECL_ATTR_SSNES(CHEAT_INDEX_PLUS);
DECL_ATTR_SSNES(CHEAT_INDEX_MINUS);
DECL_ATTR_SSNES(CHEAT_TOGGLE);
DECL_ATTR_SSNES(SCREENSHOT);
DECL_ATTR_SSNES(DSP_CONFIG);
DECL_ATTR_SSNES(MUTE);
}
static PyModuleDef SNESModule = {
PyModuleDef_HEAD_INIT, "snes", NULL, -1, SNESMethods,
NULL, NULL, NULL, NULL
};
static PyObject* PyInit_SNES(void)
{
PyObject *mod = PyModule_Create(&SNESModule);
if (!mod)
return NULL;
py_set_attrs(mod);
return mod;
}
struct py_state
{
PyObject *main;
PyObject *dict;
PyObject *inst;
bool warned_ret;
bool warned_type;
};
static char *dupe_newline(const char *str)
{
if (!str)
return NULL;
unsigned size = strlen(str) + 2;
char *ret = (char*)malloc(size);
if (!ret)
return NULL;
strlcpy(ret, str, size);
ret[size - 2] = '\n';
ret[size - 1] = '\0';
return ret;
}
// Need to make sure that first-line indentation is 0. :(
static char *align_program(const char *program)
{
char *prog = strdup(program);
if (!prog)
return NULL;
size_t prog_size = strlen(program) + 1;
char *new_prog = (char*)calloc(1, prog_size);
if (!new_prog)
return NULL;
char *line = dupe_newline(strtok(prog, "\n"));
if (!line)
{
free(prog);
return NULL;
}
unsigned skip_chars = 0;
while (isblank(line[skip_chars]) && line[skip_chars])
skip_chars++;
while (line)
{
unsigned length = strlen(line);
unsigned skip_len = skip_chars > length ? length : skip_chars;
strlcat(new_prog, line + skip_len, prog_size);
free(line);
line = dupe_newline(strtok(NULL, "\n"));
}
free(prog);
return new_prog;
}
py_state_t *py_state_new(const char *script, unsigned is_file, const char *pyclass)
{
SSNES_LOG("Initializing Python runtime ...\n");
PyImport_AppendInittab("snes", &PyInit_SNES);
Py_Initialize();
SSNES_LOG("Initialized Python runtime!\n");
py_state_t *handle = (py_state_t*)calloc(1, sizeof(*handle));
PyObject *hook = NULL;
handle->main = PyImport_AddModule("__main__");
if (!handle->main)
goto error;
Py_INCREF(handle->main);
if (is_file)
{
// Have to hack around the fact that the
// FILE struct isn't standardized across environments.
// PyRun_SimpleFile() breaks on Windows.
char *script_ = NULL;
if (read_file(script, (void**)&script_) < 0)
{
SSNES_ERR("Python: Failed to read script\n");
goto error;
}
PyRun_SimpleString(script_);
free(script_);
}
else
{
char *script_ = align_program(script);
if (script_)
{
PyRun_SimpleString(script_);
free(script_);
}
}
SSNES_LOG("Python: Script loaded.\n");
handle->dict = PyModule_GetDict(handle->main);
if (!handle->dict)
{
SSNES_ERR("Python: PyModule_GetDict() failed.\n");
goto error;
}
Py_INCREF(handle->dict);
hook = PyDict_GetItemString(handle->dict, pyclass);
if (!hook)
{
SSNES_ERR("Python: PyDict_GetItemString() failed.\n");
goto error;
}
handle->inst = PyObject_CallFunction(hook, NULL);
if (!handle->inst)
{
SSNES_ERR("Python: PyObject_CallFunction() failed.\n");
goto error;
}
Py_INCREF(handle->inst);
return handle;
error:
PyErr_Print();
PyErr_Clear();
py_state_free(handle);
return NULL;
}
void py_state_free(py_state_t *handle)
{
if (handle)
{
PyErr_Print();
PyErr_Clear();
Py_CLEAR(handle->inst);
Py_CLEAR(handle->dict);
Py_CLEAR(handle->main);
free(handle);
Py_Finalize();
}
}
float py_state_get(py_state_t *handle, const char *id,
unsigned frame_count)
{
PyObject *ret = PyObject_CallMethod(handle->inst, (char*)id, (char*)"I", frame_count);
if (!ret)
{
if (!handle->warned_ret)
SSNES_WARN("Didn't get return value from script! Bug?\n");
handle->warned_ret = true;
return 0.0f;
}
float retval = (float)PyFloat_AsDouble(ret);
Py_DECREF(ret);
return retval;
}
+34
View File
@@ -0,0 +1,34 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_PY_STATE_H
#define __SSNES_PY_STATE_H
#include <stdint.h>
#include "../../boolean.h"
#ifndef PY_STATE_OMIT_DECLARATION
typedef struct py_state py_state_t;
#endif
py_state_t *py_state_new(const char *program, unsigned is_file, const char *pyclass);
void py_state_free(py_state_t *handle);
float py_state_get(py_state_t *handle,
const char *id, unsigned frame_count);
#endif
+557
View File
@@ -0,0 +1,557 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "SDL.h"
#include "../driver.h"
#include <stdlib.h>
#include <string.h>
#include "../general.h"
#include "../input/ssnes_sdl_input.h"
#include "gfx_common.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_FREETYPE
#include "fonts.h"
#endif
static void convert_15bit_15bit_direct(uint16_t *out, unsigned outpitch, const uint16_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt);
static void convert_32bit_32bit_direct(uint32_t *out, unsigned outpitch, const uint32_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt);
static void convert_15bit_15bit_shift(uint16_t *out, unsigned outpitch, const uint16_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt);
static void convert_32bit_32bit_shift(uint32_t *out, unsigned outpitch, const uint32_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt);
typedef struct sdl_video
{
SDL_Surface *screen, *buffer;
bool quitting;
bool rgb32;
bool upsample;
bool render32;
void (*convert_15_func)(uint16_t*, unsigned, const uint16_t*, unsigned, unsigned, unsigned, const SDL_PixelFormat*);
void (*convert_32_func)(uint32_t*, unsigned, const uint32_t*, unsigned, unsigned, unsigned, const SDL_PixelFormat*);
#ifdef HAVE_FREETYPE
font_renderer_t *font;
uint8_t font_r;
uint8_t font_g;
uint8_t font_b;
#endif
} sdl_video_t;
static void sdl_gfx_free(void *data)
{
sdl_video_t *vid = (sdl_video_t*)data;
if (!vid)
return;
if (vid->buffer)
SDL_FreeSurface(vid->buffer);
SDL_QuitSubSystem(SDL_INIT_VIDEO);
#ifdef HAVE_FREETYPE
if (vid->font)
font_renderer_free(vid->font);
#endif
free(vid);
}
static void sdl_init_font(sdl_video_t *vid, const char *font_path, unsigned font_size)
{
#ifdef HAVE_FREETYPE
if (!g_settings.video.font_enable)
return;
const char *path = font_path;
if (!*path)
path = font_renderer_get_default_font();
if (path)
{
vid->font = font_renderer_new(path, font_size);
if (vid->font)
{
int r = g_settings.video.msg_color_r * 255;
int g = g_settings.video.msg_color_g * 255;
int b = g_settings.video.msg_color_b * 255;
r = r < 0 ? 0 : (r > 255 ? 255 : r);
g = g < 0 ? 0 : (g > 255 ? 255 : g);
b = b < 0 ? 0 : (b > 255 ? 255 : b);
// RGB888 -> RGB555
if (!vid->render32)
{
r >>= 3;
g >>= 3;
b >>= 3;
}
vid->font_r = r;
vid->font_g = g;
vid->font_b = b;
}
else
SSNES_WARN("Failed to init font.\n");
}
else
SSNES_LOG("Did not find default font.\n");
#else
(void)vid;
(void)font_path;
(void)font_size;
#endif
}
// Not very optimized, but hey :D
static void sdl_render_msg_15(sdl_video_t *vid, SDL_Surface *buffer, const char *msg, unsigned width, unsigned height, const SDL_PixelFormat *fmt)
{
#ifdef HAVE_FREETYPE
if (!vid->font)
return;
struct font_output_list out;
font_renderer_msg(vid->font, msg, &out);
struct font_output *head = out.head;
int base_x = g_settings.video.msg_pos_x * width;
int base_y = (1.0 - g_settings.video.msg_pos_y) * height;
unsigned rshift = fmt->Rshift;
unsigned gshift = fmt->Gshift;
unsigned bshift = fmt->Bshift;
while (head)
{
int rbase_x = base_x + head->off_x;
int rbase_y = base_y - head->off_y;
if (rbase_y >= 0)
{
for (int y = 0; y < (int)head->height && (y + rbase_y) < (int)height; y++)
{
if (rbase_x < 0)
continue;
const uint8_t *a = head->output + head->pitch * y;
uint16_t *out = (uint16_t*)buffer->pixels + (rbase_y - head->height + y) * (buffer->pitch >> 1) + rbase_x;
for (int x = 0; x < (int)head->width && (x + rbase_x) < (int)width; x++)
{
unsigned blend = a[x];
unsigned out_pix = out[x];
unsigned r = (out_pix >> rshift) & 0x1f;
unsigned g = (out_pix >> gshift) & 0x1f;
unsigned b = (out_pix >> bshift) & 0x1f;
unsigned out_r = (r * (256 - blend) + vid->font_r * blend) >> 8;
unsigned out_g = (g * (256 - blend) + vid->font_g * blend) >> 8;
unsigned out_b = (b * (256 - blend) + vid->font_b * blend) >> 8;
out[x] = (out_r << rshift) | (out_g << gshift) | (out_b << bshift);
}
}
}
head = head->next;
}
font_renderer_free_output(&out);
#else
(void)vid;
(void)buffer;
(void)msg;
(void)width;
(void)height;
#endif
}
static void sdl_render_msg_32(sdl_video_t *vid, SDL_Surface *buffer, const char *msg, unsigned width, unsigned height, const SDL_PixelFormat *fmt)
{
#ifdef HAVE_FREETYPE
if (!vid->font)
return;
struct font_output_list out;
font_renderer_msg(vid->font, msg, &out);
struct font_output *head = out.head;
int base_x = g_settings.video.msg_pos_x * width;
int base_y = (1.0 - g_settings.video.msg_pos_y) * height;
unsigned rshift = fmt->Rshift;
unsigned gshift = fmt->Gshift;
unsigned bshift = fmt->Bshift;
while (head)
{
int rbase_x = base_x + head->off_x;
int rbase_y = base_y - head->off_y;
if (rbase_y >= 0)
{
for (int y = 0; y < (int)head->height && (y + rbase_y) < (int)height; y++)
{
if (rbase_x < 0)
continue;
const uint8_t *a = head->output + head->pitch * y;
uint32_t *out = (uint32_t*)buffer->pixels + (rbase_y - head->height + y) * (buffer->pitch >> 2) + rbase_x;
for (int x = 0; x < (int)head->width && (x + rbase_x) < (int)width; x++)
{
unsigned blend = a[x];
unsigned out_pix = out[x];
unsigned r = (out_pix >> rshift) & 0xff;
unsigned g = (out_pix >> gshift) & 0xff;
unsigned b = (out_pix >> bshift) & 0xff;
unsigned out_r = (r * (256 - blend) + vid->font_r * blend) >> 8;
unsigned out_g = (g * (256 - blend) + vid->font_g * blend) >> 8;
unsigned out_b = (b * (256 - blend) + vid->font_b * blend) >> 8;
out[x] = (out_r << rshift) | (out_g << gshift) | (out_b << bshift);
}
}
}
head = head->next;
}
font_renderer_free_output(&out);
#else
(void)vid;
(void)buffer;
(void)msg;
(void)width;
(void)height;
#endif
}
static void *sdl_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
#ifdef _WIN32
gfx_set_dwm();
#endif
SDL_InitSubSystem(SDL_INIT_VIDEO);
sdl_video_t *vid = (sdl_video_t*)calloc(1, sizeof(*vid));
if (!vid)
return NULL;
const SDL_VideoInfo *video_info = SDL_GetVideoInfo();
ssnes_assert(video_info);
unsigned full_x = video_info->current_w;
unsigned full_y = video_info->current_h;
SSNES_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y);
sdl_input_t *sdl_input = NULL;
const SDL_PixelFormat *fmt = NULL;
if (!video->fullscreen)
SSNES_LOG("Creating window @ %ux%u\n", video->width, video->height);
vid->render32 = video->rgb32 && !g_settings.video.force_16bit;
vid->screen = SDL_SetVideoMode(video->width, video->height, vid->render32 ? 32 : 15, SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | (video->fullscreen ? SDL_FULLSCREEN : 0));
if (!vid->screen && !g_settings.video.force_16bit && !video->rgb32)
{
vid->upsample = true;
vid->screen = SDL_SetVideoMode(video->width, video->height, 32, SDL_HWSURFACE | SDL_HWACCEL | SDL_DOUBLEBUF | (video->fullscreen ? SDL_FULLSCREEN : 0));
SSNES_WARN("SDL: 15-bit colors failed, attempting 32-bit colors.\n");
vid->render32 = true;
}
if (!vid->screen)
{
SSNES_ERR("Failed to init SDL surface: %s\n", SDL_GetError());
goto error;
}
SDL_ShowCursor(SDL_DISABLE);
fmt = vid->screen->format;
if (vid->render32)
{
SSNES_LOG("SDL: Creating 32-bit buffer.\n");
vid->buffer = SDL_CreateRGBSurface(SDL_SWSURFACE, SSNES_SCALE_BASE * video->input_scale,
SSNES_SCALE_BASE * video->input_scale, 32,
fmt->Rmask, fmt->Bmask, fmt->Gmask, fmt->Amask);
}
else
{
SSNES_LOG("SDL: Creating 15-bit buffer.\n");
vid->buffer = SDL_CreateRGBSurface(SDL_SWSURFACE, SSNES_SCALE_BASE * video->input_scale,
SSNES_SCALE_BASE * video->input_scale, 15,
fmt->Rmask, fmt->Gmask, fmt->Bmask, fmt->Amask);
}
SSNES_LOG("[Debug]: SDL Pixel format: Rshift = %u, Gshift = %u, Bshift = %u\n",
(unsigned)fmt->Rshift, (unsigned)fmt->Gshift, (unsigned)fmt->Bshift);
if (!vid->buffer)
{
SSNES_ERR("SDL_CreateRGBSurface failed: %s\n", SDL_GetError());
goto error;
}
sdl_input = (sdl_input_t*)input_sdl.init();
if (sdl_input)
{
*input = &input_sdl;
*input_data = sdl_input;
}
else
{
*input = NULL;
*input_data = NULL;
}
vid->rgb32 = video->rgb32;
sdl_init_font(vid, g_settings.video.font_path, g_settings.video.font_size);
if (fmt->Rshift == 10 && fmt->Gshift == 5 && fmt->Bshift == 0) // XRGB1555
{
SSNES_LOG("SDL: 15-bit format matches. Fast blit.\n");
vid->convert_15_func = convert_15bit_15bit_direct;
}
else
{
SSNES_LOG("SDL: 15-bit format does not match. Needs conversion.\n");
vid->convert_15_func = convert_15bit_15bit_shift;
}
if (fmt->Rshift == 16 && fmt->Gshift == 8 && fmt->Bshift == 0) // ARGB8888
{
SSNES_LOG("SDL: 32-bit format matches. Fast blit.\n");
vid->convert_32_func = convert_32bit_32bit_direct;
}
else
{
SSNES_LOG("SDL: 32-bit format does not match. Needs conversion.\n");
vid->convert_32_func = convert_32bit_32bit_shift;
}
return vid;
error:
sdl_gfx_free(vid);
return NULL;
}
static inline uint16_t conv_pixel_32_15(uint32_t pix, const SDL_PixelFormat *fmt)
{
uint16_t r = ((pix & 0x00f80000) >> 19) << fmt->Rshift;
uint16_t g = ((pix & 0x0000f800) >> 11) << fmt->Gshift;
uint16_t b = ((pix & 0x000000f8) >> 3) << fmt->Bshift;
return r | g | b;
}
static inline uint32_t conv_pixel_15_32(uint16_t pix, const SDL_PixelFormat *fmt)
{
uint32_t r = ((pix >> 10) & 0x1f) << (fmt->Rshift + 3);
uint32_t g = ((pix >> 5) & 0x1f) << (fmt->Gshift + 3);
uint32_t b = ((pix >> 0) & 0x1f) << (fmt->Bshift + 3);
return r | g | b;
}
static void convert_32bit_15bit(uint16_t *out, unsigned outpitch, const uint32_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt)
{
for (unsigned y = 0; y < height; y++)
{
for (unsigned x = 0; x < width; x++)
out[x] = conv_pixel_32_15(input[x], fmt);
out += outpitch >> 1;
input += pitch >> 2;
}
}
static void convert_15bit_32bit(uint32_t *out, unsigned outpitch, const uint16_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt)
{
for (unsigned y = 0; y < height; y++)
{
for (unsigned x = 0; x < width; x++)
out[x] = conv_pixel_15_32(input[x], fmt);
out += outpitch >> 2;
input += pitch >> 1;
}
}
static void convert_15bit_15bit_direct(uint16_t *out, unsigned outpitch, const uint16_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt)
{
for (unsigned y = 0; y < height; y++)
{
uint16_t *dest = out + ((y * outpitch) >> 1);
const uint16_t *src = input + ((y * pitch) >> 1);
memcpy(dest, src, width * sizeof(uint16_t));
}
(void)fmt;
}
static void convert_32bit_32bit_direct(uint32_t *out, unsigned outpitch, const uint32_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt)
{
for (unsigned y = 0; y < height; y++)
{
uint32_t *dest = out + ((y * outpitch) >> 2);
const uint32_t *src = input + ((y * pitch) >> 2);
memcpy(dest, src, width * sizeof(uint32_t));
}
(void)fmt;
}
static void convert_15bit_15bit_shift(uint16_t *out, unsigned outpitch, const uint16_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt)
{
for (unsigned y = 0; y < height; y++)
{
uint16_t *dest = out + ((y * outpitch) >> 1);
const uint16_t *src = input + ((y * pitch) >> 1);
for (unsigned x = 0; x < width; x++)
{
uint16_t color = src[x];
uint16_t r = ((color >> 10) & 0x1f) << fmt->Rshift;
uint16_t g = ((color >> 5) & 0x1f) << fmt->Gshift;
uint16_t b = ((color >> 0) & 0x1f) << fmt->Bshift;
dest[x] = r | g | b;
}
}
}
static void convert_32bit_32bit_shift(uint32_t *out, unsigned outpitch, const uint32_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt)
{
for (unsigned y = 0; y < height; y++)
{
uint32_t *dest = out + ((y * outpitch) >> 2);
const uint32_t *src = input + ((y * pitch) >> 2);
for (unsigned x = 0; x < width; x++)
{
uint32_t color = src[x];
uint32_t r = ((color >> 16) & 0xff) << fmt->Rshift;
uint32_t g = ((color >> 8) & 0xff) << fmt->Gshift;
uint32_t b = ((color >> 0) & 0xff) << fmt->Bshift;
dest[x] = r | g | b;
}
}
}
static void check_window(sdl_video_t *vid)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
vid->quitting = true;
break;
default:
break;
}
}
}
static bool sdl_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
{
sdl_video_t *vid = (sdl_video_t*)data;
if (SDL_MUSTLOCK(vid->buffer))
SDL_LockSurface(vid->buffer);
// :(
// 15-bit -> 32-bit (Sometimes 15-bit won't work on "modern" OSes :\)
if (vid->upsample)
convert_15bit_32bit((uint32_t*)vid->buffer->pixels, vid->buffer->pitch, (const uint16_t*)frame, width, height, pitch, vid->screen->format);
// 15-bit -> 15-bit
else if (!vid->rgb32)
vid->convert_15_func((uint16_t*)vid->buffer->pixels, vid->buffer->pitch, (const uint16_t*)frame, width, height, pitch, vid->screen->format);
// 32-bit -> 15-bit
else if (vid->rgb32 && g_settings.video.force_16bit)
convert_32bit_15bit((uint16_t*)vid->buffer->pixels, vid->buffer->pitch, (const uint32_t*)frame, width, height, pitch, vid->screen->format);
// 32-bit -> 32-bit
else
vid->convert_32_func((uint32_t*)vid->buffer->pixels, vid->buffer->pitch, (const uint32_t*)frame, width, height, pitch, vid->screen->format);
if (SDL_MUSTLOCK(vid->buffer))
SDL_UnlockSurface(vid->buffer);
SDL_Rect src = {0};
src.x = 0;
src.y = 0;
src.w = width;
src.h = height;
SDL_Rect dest = {0};
dest.x = 0;
dest.y = 0;
dest.w = vid->screen->w;
dest.h = vid->screen->h;
SDL_SoftStretch(vid->buffer, &src, vid->screen, &dest);
if (msg)
{
if ((!vid->rgb32 || g_settings.video.force_16bit) && !vid->upsample)
sdl_render_msg_15(vid, vid->screen, msg, vid->screen->w, vid->screen->h, vid->screen->format);
else
sdl_render_msg_32(vid, vid->screen, msg, vid->screen->w, vid->screen->h, vid->screen->format);
}
char buf[128];
if (gfx_window_title(buf, sizeof(buf)))
SDL_WM_SetCaption(buf, NULL);
SDL_Flip(vid->screen);
return true;
}
static void sdl_gfx_set_nonblock_state(void *data, bool state)
{
(void)data; // Can SDL even do this?
(void)state;
}
static bool sdl_gfx_alive(void *data)
{
sdl_video_t *vid = (sdl_video_t*)data;
check_window(vid);
return !vid->quitting;
}
static bool sdl_gfx_focus(void *data)
{
(void)data;
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
}
const video_driver_t video_sdl = {
sdl_gfx_init,
sdl_gfx_frame,
sdl_gfx_set_nonblock_state,
sdl_gfx_alive,
sdl_gfx_focus,
NULL,
sdl_gfx_free,
"sdl"
};
+363
View File
@@ -0,0 +1,363 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "sdlwrap.h"
#include "SDL_syswm.h"
#include "../general.h"
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl.h>
#endif
// SDL 1.2 is portable, sure, but you still need some platform specific workarounds ;)
// Hopefully SDL 1.3 will solve this more cleanly :D
// Welcome to #ifdef HELL! :D
//
#if SDL_MODERN
static SDL_Window* g_window;
static SDL_GLContext g_ctx;
#endif
static bool g_fullscreen;
static unsigned g_interval;
void sdlwrap_set_swap_interval(unsigned interval, bool inited)
{
g_interval = interval;
bool success = true;
#if SDL_MODERN
if (g_window)
success = SDL_GL_SetSwapInterval(g_interval) == 0;
#else
if (inited)
{
#if defined(_WIN32)
static BOOL (APIENTRY *wgl_swap_interval)(int) = NULL;
if (!wgl_swap_interval)
SDL_SYM_WRAP(wgl_swap_interval, "wglSwapIntervalEXT");
if (wgl_swap_interval)
success = wgl_swap_interval(g_interval);
#elif defined(__APPLE__) && defined(HAVE_OPENGL)
GLint val = g_interval;
success = CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &val) == 0;
#else
static int (*glx_swap_interval)(int) = NULL;
if (!glx_swap_interval)
SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalSGI");
if (!glx_swap_interval)
SDL_SYM_WRAP(glx_swap_interval, "glXSwapIntervalMESA");
if (glx_swap_interval)
success = glx_swap_interval(g_interval) == 0;
else
SSNES_WARN("Could not find GLX VSync call.\n");
#endif
}
#endif
if (!success)
SSNES_WARN("Failed to set swap interval!\n");
}
bool sdlwrap_init(void)
{
#if SDL_MODERN
bool ret = SDL_VideoInit(NULL) == 0;
#else
if (SDL_WasInit(SDL_INIT_VIDEO))
return true;
bool ret = SDL_Init(SDL_INIT_VIDEO) == 0;
#endif
if (!ret)
SSNES_ERR("Failed to init SDL video!\n");
return ret;
}
#if SDL_MODERN
void sdlwrap_destroy(void)
{
if (g_ctx)
SDL_GL_DeleteContext(g_ctx);
if (g_window)
SDL_DestroyWindow(g_window);
g_ctx = NULL;
g_window = NULL;
SDL_VideoQuit();
}
#else
void sdlwrap_destroy(void)
{
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
#endif
bool sdlwrap_set_video_mode(
unsigned width, unsigned height,
unsigned bits, bool fullscreen)
{
#if SDL_MODERN
if (g_window)
return true;
#endif
#if SDL_MODERN
static const int resizable = SDL_WINDOW_RESIZABLE;
#else
#ifndef __APPLE__ // Resizing on OSX is broken in 1.2 it seems :)
static const int resizable = SDL_RESIZABLE;
#else
static const int resizable = 0;
#endif
#endif
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
#if !SDL_MODERN
SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, g_interval);
#endif
#if SDL_MODERN
if (bits == 15)
{
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
}
g_window = SDL_CreateWindow("SSNES", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
width, height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | (fullscreen ? SDL_WINDOW_FULLSCREEN : resizable));
if (!g_window)
{
SSNES_ERR("Failed to create SDL window!\n");
return false;
}
g_ctx = SDL_GL_CreateContext(g_window);
#else
if (!SDL_SetVideoMode(width, height, bits,
SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : resizable)))
{
SSNES_ERR("Failed to create SDL window!\n");
return false;
}
#endif
int attr = 0;
#if SDL_MODERN
SDL_GL_SetSwapInterval(g_interval);
#else
SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &attr);
if (attr <= 0 && g_interval)
{
SSNES_WARN("SDL failed to setup VSync, attempting to recover using native calls!\n");
sdlwrap_set_swap_interval(g_interval, true);
}
#endif
g_fullscreen = fullscreen;
attr = 0;
SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &attr);
if (attr <= 0)
SSNES_WARN("GL double buffer has not been enabled!\n");
return true;
}
// SDL 1.2 has an awkward model where you need to "confirm" window resizing.
// SDL 1.3 luckily removes this quirk.
void sdlwrap_set_resize(unsigned width, unsigned height)
{
#if SDL_MODERN
(void)width;
(void)height;
#else
#ifndef __APPLE__ // Resizing on OSX is broken in 1.2 it seems :)
static const int resizable = SDL_RESIZABLE;
#else
static const int resizable = 0;
#endif
SDL_SetVideoMode(width, height, 0, SDL_OPENGL | (g_fullscreen ? SDL_FULLSCREEN : resizable));
#endif
}
void sdlwrap_wm_set_caption(const char *str)
{
#if SDL_MODERN
SDL_SetWindowTitle(g_window, str);
#else
SDL_WM_SetCaption(str, NULL);
#endif
}
void sdlwrap_swap_buffers(void)
{
#if SDL_MODERN
SDL_GL_SwapWindow(g_window);
#else
SDL_GL_SwapBuffers();
#endif
}
bool sdlwrap_key_pressed(int key)
{
int num_keys;
#if SDL_MODERN
Uint8 *keymap = SDL_GetKeyboardState(&num_keys);
key = SDL_GetScancodeFromKey(key);
if (key >= num_keys)
return false;
return keymap[key];
#else
Uint8 *keymap = SDL_GetKeyState(&num_keys);
if (key >= num_keys)
return false;
return keymap[key];
#endif
}
// 1.2 specific workaround for tiling WMs. In 1.3 we call GetSize directly, so we don't need to rely on
// proper event handling (I hope).
#if !defined(__APPLE__) && !defined(_WIN32) && !SDL_MODERN && !defined(XENON)
static void sdlwrap_get_window_size(unsigned *width, unsigned *height)
{
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
SDL_GetWMInfo(&info);
XWindowAttributes target;
info.info.x11.lock_func();
XGetWindowAttributes(info.info.x11.display, info.info.x11.window,
&target);
info.info.x11.unlock_func();
*width = target.width;
*height = target.height;
}
#endif
void sdlwrap_check_window(bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count)
{
*quit = false;
*resize = false;
SDL_Event event;
#if SDL_MODERN
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
*quit = true;
return;
case SDL_WINDOWEVENT:
switch (event.window.event)
{
case SDL_WINDOWEVENT_CLOSE:
*quit = true;
return;
case SDL_WINDOWEVENT_RESIZED:
*resize = true;
*width = event.window.data1;
*height = event.window.data2;
break;
}
break;
}
}
if (!*resize)
{
int w, h;
SDL_GetWindowSize(g_window, &w, &h);
if (*width != (unsigned)w || *height != (unsigned)h)
{
*resize = true;
*width = w;
*height = h;
}
}
#else
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
*quit = true;
break;
case SDL_VIDEORESIZE:
*resize = true;
*width = event.resize.w;
*height = event.resize.h;
break;
}
}
#if !defined(__APPLE__) && !defined(_WIN32) && !defined(XENON)
// Hack to workaround limitations in tiling WMs ...
if (!*resize && !g_fullscreen)
{
unsigned new_width, new_height;
sdlwrap_get_window_size(&new_width, &new_height);
if ((new_width != *width || new_height != *height) || (frame_count == 10)) // Ugly hack :D
{
*resize = true;
*width = new_width;
*height = new_height;
SSNES_LOG("GL: Verified window size: %u x %u\n", *width, *height);
}
}
#endif
#endif
}
bool sdlwrap_get_wm_info(SDL_SysWMinfo *info)
{
#ifdef XENON
(void)info;
return false;
#elif SDL_MODERN
if (g_window)
return SDL_GetWindowWMInfo(g_window, info);
else
return SDL_GetWMInfo(info) == 1;
#else
return SDL_GetWMInfo(info) == 1;
#endif
}
bool sdlwrap_window_has_focus(void)
{
#if SDL_MODERN
Uint32 flags = SDL_GetWindowFlags(g_window);
flags &= SDL_WINDOW_INPUT_FOCUS;
return flags == SDL_WINDOW_INPUT_FOCUS;
#else
return (SDL_GetAppState() & (SDL_APPINPUTFOCUS | SDL_APPACTIVE)) == (SDL_APPINPUTFOCUS | SDL_APPACTIVE);
#endif
}
+68
View File
@@ -0,0 +1,68 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
// Compatibility wrapper between SDL 1.2/1.3 for OpenGL.
// Wraps functions which differ in 1.2 and 1.3.
#ifndef __SDLWRAP_H
#define __SDLWRAP_H
#include "../boolean.h"
#include "SDL.h"
#include "SDL_version.h"
#include "SDL_syswm.h"
#if SDL_VERSION_ATLEAST(1, 3, 0)
#define SDL_MODERN 1
#else
#define SDL_MODERN 0
#endif
// Not legal to cast (void*) to fn-pointer. Need workaround to be compliant.
#define SDL_SYM_WRAP(sym, symbol) { \
ssnes_assert(sizeof(void*) == sizeof(void (*)(void))); \
void *sym__ = SDL_GL_GetProcAddress(symbol); \
memcpy(&(sym), &sym__, sizeof(void*)); \
}
void sdlwrap_set_swap_interval(unsigned interval, bool inited);
bool sdlwrap_set_video_mode(
unsigned width, unsigned height,
unsigned bits, bool fullscreen);
bool sdlwrap_init(void);
void sdlwrap_destroy(void);
void sdlwrap_wm_set_caption(const char *str);
void sdlwrap_swap_buffers(void);
bool sdlwrap_key_pressed(int key);
void sdlwrap_check_window(bool *quit,
bool *resize, unsigned *width, unsigned *height, unsigned frame_count);
void sdlwrap_set_resize(unsigned width, unsigned height);
bool sdlwrap_get_wm_info(SDL_SysWMinfo *info);
bool sdlwrap_window_has_focus(void);
#endif
+979 -79
View File
File diff suppressed because it is too large. Load diff
+7 -3
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -19,7 +19,7 @@
#ifndef __SSNES_CG_H
#define __SSNES_CG_H
#include <stdbool.h>
#include "../boolean.h"
#include "gl_common.h"
bool gl_cg_init(const char *path);
@@ -30,7 +30,11 @@ void gl_cg_set_proj_matrix(void);
void gl_cg_set_params(unsigned width, unsigned height,
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height);
unsigned out_width, unsigned out_height,
unsigned frame_count,
const struct gl_tex_info *info,
const struct gl_tex_info *prev_info,
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt);
void gl_cg_use(unsigned index);
+698 -62
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -15,10 +15,14 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include "../boolean.h"
#include <string.h>
#include "general.h"
#include "../general.h"
#include "shader_glsl.h"
#include "../strl.h"
#include "../posix_string.h"
#include "snes_state.h"
#include "../dynamic.h"
#ifdef __APPLE__
#include <OpenGL/gl.h>
@@ -30,13 +34,16 @@
#define NO_SDL_GLEXT
#include "SDL.h"
#include "sdlwrap.h"
#include "SDL_opengl.h"
#include <stdlib.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "gl_common.h"
#include "image.h"
#ifdef __APPLE__
#define pglCreateProgram glCreateProgram
@@ -50,6 +57,7 @@
#define pglLinkProgram glLinkProgram
#define pglGetUniformLocation glGetUniformLocation
#define pglUniform1i glUniform1i
#define pglUniform1f glUniform1f
#define pglUniform2fv glUniform2fv
#define pglUniform4fv glUniform4fv
#define pglGetShaderiv glGetShaderiv
@@ -58,6 +66,10 @@
#define pglGetProgramInfoLog glGetProgramInfoLog
#define pglDeleteProgram glDeleteProgram
#define pglGetAttachedShaders glGetAttachedShaders
#define pglGetAttribLocation glGetAttribLocation
#define pglEnableVertexAttribArray glEnableVertexAttribArray
#define pglDisableVertexAttribArray glDisableVertexAttribArray
#define pglVertexAttribPointer glVertexAttribPointer
#else
static PFNGLCREATEPROGRAMPROC pglCreateProgram = NULL;
static PFNGLUSEPROGRAMPROC pglUseProgram = NULL;
@@ -70,6 +82,7 @@ static PFNGLDETACHSHADERPROC pglDetachShader = NULL;
static PFNGLLINKPROGRAMPROC pglLinkProgram = NULL;
static PFNGLGETUNIFORMLOCATIONPROC pglGetUniformLocation = NULL;
static PFNGLUNIFORM1IPROC pglUniform1i = NULL;
static PFNGLUNIFORM1FPROC pglUniform1f = NULL;
static PFNGLUNIFORM2FVPROC pglUniform2fv = NULL;
static PFNGLUNIFORM4FVPROC pglUniform4fv = NULL;
static PFNGLGETSHADERIVPROC pglGetShaderiv = NULL;
@@ -78,9 +91,16 @@ static PFNGLGETPROGRAMIVPROC pglGetProgramiv = NULL;
static PFNGLGETPROGRAMINFOLOGPROC pglGetProgramInfoLog = NULL;
static PFNGLDELETEPROGRAMPROC pglDeleteProgram = NULL;
static PFNGLGETATTACHEDSHADERSPROC pglGetAttachedShaders = NULL;
static PFNGLGETATTRIBLOCATIONPROC pglGetAttribLocation = NULL;
static PFNGLENABLEVERTEXATTRIBARRAYPROC pglEnableVertexAttribArray = NULL;
static PFNGLDISABLEVERTEXATTRIBARRAYPROC pglDisableVertexAttribArray = NULL;
static PFNGLVERTEXATTRIBPOINTERPROC pglVertexAttribPointer = NULL;
#endif
#define MAX_PROGRAMS 16
#define MAX_TEXTURES 8
#define MAX_VARIABLES 256
#define PREV_TEXTURES 7
enum filter_type
{
@@ -96,6 +116,21 @@ static struct gl_fbo_scale gl_scale[MAX_PROGRAMS];
static unsigned gl_num_programs = 0;
static unsigned active_index = 0;
static GLuint gl_teximage[MAX_TEXTURES];
static unsigned gl_teximage_cnt = 0;
static char gl_teximage_uniforms[MAX_TEXTURES][64];
static snes_tracker_t *gl_snes_tracker = NULL;
static struct snes_tracker_uniform_info gl_tracker_info[MAX_VARIABLES];
static unsigned gl_tracker_info_cnt = 0;
static char gl_tracker_script[PATH_MAX];
static char gl_tracker_script_class[64];
static xmlChar *gl_script_program = NULL;
static GLint gl_attribs[PREV_TEXTURES + 1 + MAX_PROGRAMS];
static unsigned gl_attrib_index = 0;
struct shader_program
{
char *vertex;
@@ -112,6 +147,21 @@ struct shader_program
bool valid_scale;
};
static const char *stock_vertex =
"varying vec4 color;\n"
"void main() {\n"
" gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
" gl_TexCoord[0] = gl_MultiTexCoord0;\n"
" color = gl_Color;\n"
"}";
static const char *stock_fragment =
"uniform sampler2D rubyTexture;\n"
"varying vec4 color;\n"
"void main() {\n"
" gl_FragColor = color * texture2D(rubyTexture, gl_TexCoord[0].xy);\n"
"}";
static bool get_xml_attrs(struct shader_program *prog, xmlNodePtr ptr)
{
prog->scale_x = 1.0;
@@ -273,6 +323,291 @@ static bool get_xml_attrs(struct shader_program *prog, xmlNodePtr ptr)
return true;
}
static bool get_texture_image(const char *shader_path, xmlNodePtr ptr)
{
if (gl_teximage_cnt >= MAX_TEXTURES)
{
SSNES_WARN("Too many texture images! Ignoring ...\n");
return true;
}
bool linear = true;
xmlChar *filename = xmlGetProp(ptr, (const xmlChar*)"file");
xmlChar *filter = xmlGetProp(ptr, (const xmlChar*)"filter");
xmlChar *id = xmlGetProp(ptr, (const xmlChar*)"id");
char *last = NULL;
struct texture_image img;
if (!id)
{
SSNES_ERR("Could not find ID in texture.\n");
goto error;
}
if (!filename)
{
SSNES_ERR("Could not find filename in texture.\n");
goto error;
}
if (filter && strcmp((const char*)filter, "nearest") == 0)
linear = false;
char tex_path[PATH_MAX];
strlcpy(tex_path, shader_path, sizeof(tex_path));
last = strrchr(tex_path, '/');
if (!last) last = strrchr(tex_path, '\\');
if (last) last[1] = '\0';
strlcat(tex_path, (const char*)filename, sizeof(tex_path));
SSNES_LOG("Loading texture image from: \"%s\" ...\n", tex_path);
if (!texture_image_load(tex_path, &img))
{
SSNES_ERR("Failed to load texture image from: \"%s\"\n", tex_path);
goto error;
}
strlcpy(gl_teximage_uniforms[gl_teximage_cnt], (const char*)id, sizeof(gl_teximage_uniforms[0]));
glGenTextures(1, &gl_teximage[gl_teximage_cnt]);
pglActiveTexture(GL_TEXTURE0 + gl_teximage_cnt + 1);
glBindTexture(GL_TEXTURE_2D, gl_teximage[gl_teximage_cnt]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, linear ? GL_LINEAR : GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glPixelStorei(GL_UNPACK_ROW_LENGTH, img.width);
glTexImage2D(GL_TEXTURE_2D,
0, GL_RGBA, img.width, img.height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, img.pixels);
pglActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
free(img.pixels);
xmlFree(filename);
xmlFree(id);
if (filter)
xmlFree(filter);
gl_teximage_cnt++;
return true;
error:
if (filename)
xmlFree(filename);
if (filter)
xmlFree(filter);
if (filter)
xmlFree(id);
return false;
}
#ifdef HAVE_PYTHON
static bool get_script(const char *path, xmlNodePtr ptr)
{
if (*gl_tracker_script || gl_script_program)
{
SSNES_ERR("Script already imported.\n");
return false;
}
xmlChar *script_class = xmlGetProp(ptr, (const xmlChar*)"class");
if (script_class)
{
strlcpy(gl_tracker_script_class, (const char*)script_class, sizeof(gl_tracker_script_class));
xmlFree(script_class);
}
xmlChar *language = xmlGetProp(ptr, (const xmlChar*)"language");
if (!language || strcmp((const char*)language, "python") != 0)
{
SSNES_ERR("Script language is not Python!\n");
if (language)
xmlFree(language);
return false;
}
if (language)
xmlFree(language);
xmlChar *src = xmlGetProp(ptr, (const xmlChar*)"src");
if (src)
{
strlcpy(gl_tracker_script, path, sizeof(gl_tracker_script));
char *dir_ptr = strrchr(gl_tracker_script, '/');
if (!dir_ptr) dir_ptr = strrchr(gl_tracker_script, '\\');
if (dir_ptr) dir_ptr[1] = '\0';
strlcat(gl_tracker_script, (const char*)src, sizeof(gl_tracker_script));
xmlFree(src);
}
else
{
xmlChar *script = xmlNodeGetContent(ptr);
if (!script)
{
SSNES_ERR("No content in script!\n");
return false;
}
gl_script_program = script;
}
return true;
}
#endif
static bool get_import_value(xmlNodePtr ptr)
{
if (gl_tracker_info_cnt >= MAX_VARIABLES)
{
SSNES_ERR("Too many import variables ...\n");
return false;
}
xmlChar *id = xmlGetProp(ptr, (const xmlChar*)"id");
xmlChar *semantic = xmlGetProp(ptr, (const xmlChar*)"semantic");
xmlChar *wram = xmlGetProp(ptr, (const xmlChar*)"wram");
xmlChar *input = xmlGetProp(ptr, (const xmlChar*)"input_slot");
xmlChar *apuram = xmlGetProp(ptr, (const xmlChar*)"apuram");
xmlChar *vram = xmlGetProp(ptr, (const xmlChar*)"vram");
xmlChar *oam = xmlGetProp(ptr, (const xmlChar*)"oam");
xmlChar *cgram = xmlGetProp(ptr, (const xmlChar*)"cgram");
xmlChar *bitmask = xmlGetProp(ptr, (const xmlChar*)"mask");
unsigned memtype;
enum snes_tracker_type tracker_type;
enum snes_ram_type ram_type = SSNES_STATE_NONE;
uint32_t addr = 0;
unsigned mask_value = 0;
if (!semantic || !id)
{
SSNES_ERR("No semantic or ID for import value!\n");
goto error;
}
if (strcmp((const char*)semantic, "capture") == 0)
tracker_type = SSNES_STATE_CAPTURE;
else if (strcmp((const char*)semantic, "capture_previous") == 0)
tracker_type = SSNES_STATE_CAPTURE_PREV;
else if (strcmp((const char*)semantic, "transition") == 0)
tracker_type = SSNES_STATE_TRANSITION;
else if (strcmp((const char*)semantic, "transition_count") == 0)
tracker_type = SSNES_STATE_TRANSITION_COUNT;
else if (strcmp((const char*)semantic, "transition_previous") == 0)
tracker_type = SSNES_STATE_TRANSITION_PREV;
#ifdef HAVE_PYTHON
else if (strcmp((const char*)semantic, "python") == 0)
tracker_type = SSNES_STATE_PYTHON;
#endif
else
{
SSNES_ERR("Invalid semantic for import value.\n");
goto error;
}
#ifdef HAVE_PYTHON
if (tracker_type != SSNES_STATE_PYTHON)
#endif
{
if (input)
{
unsigned slot = strtoul((const char*)input, NULL, 0);
switch (slot)
{
case 1:
ram_type = SSNES_STATE_INPUT_SLOT1;
break;
case 2:
ram_type = SSNES_STATE_INPUT_SLOT2;
break;
default:
SSNES_ERR("Invalid input slot for import!\n");
goto error;
}
}
else if (wram) { addr = strtoul((const char*)wram, NULL, 16); ram_type = SSNES_STATE_WRAM; }
else if (apuram) { addr = strtoul((const char*)apuram, NULL, 16); ram_type = SSNES_STATE_APURAM; }
else if (vram) { addr = strtoul((const char*)vram, NULL, 16); ram_type = SSNES_STATE_VRAM; }
else if (oam) { addr = strtoul((const char*)oam, NULL, 16); ram_type = SSNES_STATE_OAM; }
else if (cgram) { addr = strtoul((const char*)cgram, NULL, 16); ram_type = SSNES_STATE_CGRAM; }
else
{
SSNES_ERR("No RAM address specificed for import value.\n");
goto error;
}
}
switch (ram_type)
{
case SSNES_STATE_WRAM:
memtype = SNES_MEMORY_WRAM;
break;
case SSNES_STATE_APURAM:
memtype = SNES_MEMORY_APURAM;
break;
case SSNES_STATE_VRAM:
memtype = SNES_MEMORY_VRAM;
break;
case SSNES_STATE_OAM:
memtype = SNES_MEMORY_OAM;
break;
case SSNES_STATE_CGRAM:
memtype = SNES_MEMORY_CGRAM;
break;
default:
memtype = -1u;
}
if ((memtype != -1u) && (addr >= psnes_get_memory_size(memtype)))
{
SSNES_ERR("Address out of bounds.\n");
goto error;
}
if (bitmask)
mask_value = strtoul((const char*)bitmask, NULL, 16);
strlcpy(gl_tracker_info[gl_tracker_info_cnt].id, (const char*)id, sizeof(gl_tracker_info[0].id));
gl_tracker_info[gl_tracker_info_cnt].addr = addr;
gl_tracker_info[gl_tracker_info_cnt].type = tracker_type;
gl_tracker_info[gl_tracker_info_cnt].ram_type = ram_type;
gl_tracker_info[gl_tracker_info_cnt].mask = mask_value;
gl_tracker_info_cnt++;
if (id) xmlFree(id);
if (semantic) xmlFree(semantic);
if (wram) xmlFree(wram);
if (input) xmlFree(input);
if (apuram) xmlFree(apuram);
if (vram) xmlFree(vram);
if (oam) xmlFree(oam);
if (cgram) xmlFree(cgram);
if (bitmask) xmlFree(bitmask);
return true;
error:
if (id) xmlFree(id);
if (semantic) xmlFree(semantic);
if (wram) xmlFree(wram);
if (input) xmlFree(input);
if (apuram) xmlFree(apuram);
if (vram) xmlFree(vram);
if (oam) xmlFree(oam);
if (cgram) xmlFree(cgram);
if (bitmask) xmlFree(bitmask);
return false;
}
static unsigned get_xml_shaders(const char *path, struct shader_program *prog, size_t size)
{
LIBXML_TEST_VERSION;
@@ -286,6 +621,10 @@ static unsigned get_xml_shaders(const char *path, struct shader_program *prog, s
SSNES_LOG("Loading XML shader: %s\n", path);
xmlDocPtr doc = xmlCtxtReadFile(ctx, path, NULL, 0);
xmlNodePtr head = NULL;
xmlNodePtr cur = NULL;
unsigned num = 0;
if (!doc)
{
SSNES_ERR("Failed to parse XML file: %s\n", path);
@@ -298,8 +637,8 @@ static unsigned get_xml_shaders(const char *path, struct shader_program *prog, s
goto error;
}
xmlNodePtr head = xmlDocGetRootElement(doc);
xmlNodePtr cur = NULL;
head = xmlDocGetRootElement(doc);
for (cur = head; cur; cur = cur->next)
{
if (cur->type == XML_ELEMENT_NODE && strcmp((const char*)cur->name, "shader") == 0)
@@ -320,7 +659,6 @@ static unsigned get_xml_shaders(const char *path, struct shader_program *prog, s
if (!cur) // We couldn't find any GLSL shader :(
goto error;
unsigned num = 0;
memset(prog, 0, sizeof(struct shader_program) * size);
// Iterate to check if we find fragment and/or vertex shaders.
@@ -354,6 +692,32 @@ static unsigned get_xml_shaders(const char *path, struct shader_program *prog, s
}
num++;
}
else if (strcmp((const char*)cur->name, "texture") == 0)
{
if (!get_texture_image(path, cur))
{
SSNES_ERR("Texture image failed to load.\n");
goto error;
}
}
else if (strcmp((const char*)cur->name, "import") == 0)
{
if (!get_import_value(cur))
{
SSNES_ERR("Import value is invalid.\n");
goto error;
}
}
#ifdef HAVE_PYTHON
else if (strcmp((const char*)cur->name, "script") == 0)
{
if (!get_script(path, cur))
{
SSNES_ERR("Script is invalid.\n");
goto error;
}
}
#endif
}
if (num == 0)
@@ -376,30 +740,75 @@ error:
static void print_shader_log(GLuint obj)
{
int info_len = 0;
int max_len;
GLint info_len = 0;
GLint max_len;
pglGetShaderiv(obj, GL_INFO_LOG_LENGTH, &max_len);
char info_log[max_len];
if (max_len == 0)
return;
char *info_log = (char*)malloc(max_len);
if (!info_log)
return;
pglGetShaderInfoLog(obj, max_len, &info_len, info_log);
if (info_len > 0)
SSNES_LOG("Shader log: %s\n", info_log);
free(info_log);
}
static void print_linker_log(GLuint obj)
{
int info_len = 0;
int max_len;
GLint info_len = 0;
GLint max_len;
pglGetProgramiv(obj, GL_INFO_LOG_LENGTH, &max_len);
char info_log[max_len];
if (max_len == 0)
return;
char *info_log = (char*)malloc(max_len);
if (!info_log)
return;
pglGetProgramInfoLog(obj, max_len, &info_len, info_log);
if (info_len > 0)
SSNES_LOG("Linker log: %s\n", info_log);
free(info_log);
}
static bool compile_shader(GLuint shader, const char *program)
{
pglShaderSource(shader, 1, &program, 0);
pglCompileShader(shader);
GLint status;
pglGetShaderiv(shader, GL_COMPILE_STATUS, &status);
print_shader_log(shader);
return status == GL_TRUE;
}
static bool link_program(GLuint prog)
{
pglLinkProgram(prog);
GLint status;
pglGetProgramiv(prog, GL_LINK_STATUS, &status);
print_linker_log(prog);
if (status == GL_TRUE)
{
pglUseProgram(prog);
return true;
}
else
return false;
}
static bool compile_programs(GLuint *gl_prog, struct shader_program *progs, size_t num)
@@ -408,7 +817,7 @@ static bool compile_programs(GLuint *gl_prog, struct shader_program *progs, size
{
gl_prog[i] = pglCreateProgram();
if (!gl_check_error() || gl_prog[i] == 0)
if (gl_prog[i] == 0)
{
SSNES_ERR("Failed to create GL program #%u.\n", i);
return false;
@@ -418,61 +827,56 @@ static bool compile_programs(GLuint *gl_prog, struct shader_program *progs, size
{
SSNES_LOG("Found GLSL vertex shader.\n");
GLuint shader = pglCreateShader(GL_VERTEX_SHADER);
pglShaderSource(shader, 1, (const char**)&progs[i].vertex, 0);
pglCompileShader(shader);
print_shader_log(shader);
if (!compile_shader(shader, progs[i].vertex))
{
SSNES_ERR("Failed to compile vertex shader #%u\n", i);
return false;
}
pglAttachShader(gl_prog[i], shader);
free(progs[i].vertex);
}
if (!gl_check_error())
{
SSNES_ERR("Failed to compile vertex shader #%u\n", i);
return false;
}
if (progs[i].fragment)
{
SSNES_LOG("Found GLSL fragment shader.\n");
GLuint shader = pglCreateShader(GL_FRAGMENT_SHADER);
pglShaderSource(shader, 1, (const char**)&progs[i].fragment, 0);
pglCompileShader(shader);
print_shader_log(shader);
if (!compile_shader(shader, progs[i].fragment))
{
SSNES_ERR("Failed to compile fragment shader #%u\n", i);
return false;
}
pglAttachShader(gl_prog[i], shader);
free(progs[i].fragment);
}
if (!gl_check_error())
{
SSNES_ERR("Failed to compile fragment shader #%u\n", i);
return false;
}
if (progs[i].vertex || progs[i].fragment)
{
SSNES_LOG("Linking GLSL program.\n");
pglLinkProgram(gl_prog[i]);
pglUseProgram(gl_prog[i]);
print_linker_log(gl_prog[i]);
if (!link_program(gl_prog[i]))
{
SSNES_ERR("Failed to link program #%u\n", i);
return false;
}
GLint location = pglGetUniformLocation(gl_prog[i], "rubyTexture");
pglUniform1i(location, 0);
pglUseProgram(0);
}
if (!gl_check_error())
{
SSNES_ERR("Failed to link program #%u\n", i);
return false;
}
}
return true;
}
#define LOAD_GL_SYM(SYM) if (!(pgl##SYM)) pgl##SYM = SDL_GL_GetProcAddress("gl" #SYM)
static void gl_glsl_reset_attrib(void)
{
for (unsigned i = 0; i < gl_attrib_index; i++)
pglDisableVertexAttribArray(gl_attribs[i]);
gl_attrib_index = 0;
}
#define LOAD_GL_SYM(SYM) if (!pgl##SYM) { SDL_SYM_WRAP(pgl##SYM, "gl" #SYM) }
bool gl_glsl_init(const char *path)
{
@@ -489,6 +893,7 @@ bool gl_glsl_init(const char *path)
LOAD_GL_SYM(LinkProgram);
LOAD_GL_SYM(GetUniformLocation);
LOAD_GL_SYM(Uniform1i);
LOAD_GL_SYM(Uniform1f);
LOAD_GL_SYM(Uniform2fv);
LOAD_GL_SYM(Uniform4fv);
LOAD_GL_SYM(GetShaderiv);
@@ -497,6 +902,10 @@ bool gl_glsl_init(const char *path)
LOAD_GL_SYM(GetProgramInfoLog);
LOAD_GL_SYM(DeleteProgram);
LOAD_GL_SYM(GetAttachedShaders);
LOAD_GL_SYM(GetAttribLocation);
LOAD_GL_SYM(EnableVertexAttribArray);
LOAD_GL_SYM(DisableVertexAttribArray);
LOAD_GL_SYM(VertexAttribPointer);
#endif
SSNES_LOG("Checking GLSL shader support ...\n");
@@ -506,17 +915,26 @@ bool gl_glsl_init(const char *path)
bool shader_support = pglCreateProgram && pglUseProgram && pglCreateShader
&& pglDeleteShader && pglShaderSource && pglCompileShader && pglAttachShader
&& pglDetachShader && pglLinkProgram && pglGetUniformLocation
&& pglUniform1i && pglUniform2fv && pglUniform4fv
&& pglUniform1i && pglUniform1f && pglUniform2fv && pglUniform4fv
&& pglGetShaderiv && pglGetShaderInfoLog && pglGetProgramiv && pglGetProgramInfoLog
&& pglDeleteProgram && pglGetAttachedShaders;
&& pglDeleteProgram && pglGetAttachedShaders
&& pglGetAttribLocation && pglEnableVertexAttribArray && pglDisableVertexAttribArray
&& pglVertexAttribPointer;
#endif
if (!shader_support)
{
SSNES_ERR("GLSL shaders aren't supported by your GL driver.\n");
SSNES_ERR("GLSL shaders aren't supported by your OpenGL driver.\n");
return false;
}
struct shader_program stock_prog = {0};
stock_prog.vertex = strdup(stock_vertex);
stock_prog.fragment = strdup(stock_fragment);
if (!compile_programs(&gl_program[0], &stock_prog, 1))
return false;
struct shader_program progs[MAX_PROGRAMS];
unsigned num_progs = get_xml_shaders(path, progs, MAX_PROGRAMS - 1);
@@ -542,7 +960,7 @@ bool gl_glsl_init(const char *path)
return false;
// SSNES custom two-pass with two different files.
if (num_progs == 1 && *g_settings.video.second_pass_shader)
if (num_progs == 1 && *g_settings.video.second_pass_shader && g_settings.video.render_to_texture)
{
unsigned secondary_progs = get_xml_shaders(g_settings.video.second_pass_shader, progs, 1);
if (secondary_progs == 1)
@@ -557,11 +975,43 @@ bool gl_glsl_init(const char *path)
}
}
if (!gl_check_error())
return false;
//if (!gl_check_error())
// SSNES_WARN("Detected GL error!\n");
if (gl_tracker_info_cnt > 0)
{
struct snes_tracker_info info = {0};
info.wram = psnes_get_memory_data(SNES_MEMORY_WRAM);
info.vram = psnes_get_memory_data(SNES_MEMORY_VRAM);
info.cgram = psnes_get_memory_data(SNES_MEMORY_CGRAM);
info.apuram = psnes_get_memory_data(SNES_MEMORY_APURAM);
info.oam = psnes_get_memory_data(SNES_MEMORY_OAM);
info.info = gl_tracker_info;
info.info_elem = gl_tracker_info_cnt;
#ifdef HAVE_PYTHON
if (*gl_tracker_script)
info.script = gl_tracker_script;
else if (gl_script_program)
info.script = (const char*)gl_script_program;
else
info.script = NULL;
info.script_class = *gl_tracker_script_class ? gl_tracker_script_class : NULL;
info.script_is_file = *gl_tracker_script;
#endif
gl_snes_tracker = snes_tracker_init(&info);
if (!gl_snes_tracker)
SSNES_WARN("Failed to init SNES tracker!\n");
}
glsl_enable = true;
gl_num_programs = num_progs;
gl_program[gl_num_programs + 1] = gl_program[0];
gl_glsl_reset_attrib();
return true;
}
@@ -570,10 +1020,10 @@ void gl_glsl_deinit(void)
if (glsl_enable)
{
pglUseProgram(0);
for (int i = 1; i < MAX_PROGRAMS; i++)
for (unsigned i = 0; i <= gl_num_programs; i++)
{
if (gl_program[i] == 0)
break;
continue;
GLsizei count;
GLuint shaders[2];
@@ -587,32 +1037,216 @@ void gl_glsl_deinit(void)
pglDeleteProgram(gl_program[i]);
}
glDeleteTextures(gl_teximage_cnt, gl_teximage);
gl_teximage_cnt = 0;
memset(gl_teximage_uniforms, 0, sizeof(gl_teximage_uniforms));
}
memset(gl_program, 0, sizeof(gl_program));
glsl_enable = false;
active_index = 0;
gl_tracker_info_cnt = 0;
memset(gl_tracker_info, 0, sizeof(gl_tracker_info));
memset(gl_tracker_script, 0, sizeof(gl_tracker_script));
memset(gl_tracker_script_class, 0, sizeof(gl_tracker_script_class));
if (gl_script_program)
{
xmlFree(gl_script_program);
gl_script_program = NULL;
}
if (gl_snes_tracker)
{
snes_tracker_free(gl_snes_tracker);
gl_snes_tracker = NULL;
}
gl_glsl_reset_attrib();
}
void gl_glsl_set_params(unsigned width, unsigned height,
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height)
unsigned out_width, unsigned out_height,
unsigned frame_count,
const struct gl_tex_info *info,
const struct gl_tex_info *prev_info,
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt)
{
if (glsl_enable && gl_program[active_index] > 0)
// We enforce a certain layout for our various texture types in the texunits.
// - Regular SNES frame (rubyTexture) (always bound).
// - LUT textures (always bound).
// - Original texture (always bound if meaningful).
// - FBO textures (always bound if available).
// - Previous textures.
if (!glsl_enable || (gl_program[active_index] == 0))
return;
GLint location;
float inputSize[2] = {(float)width, (float)height};
location = pglGetUniformLocation(gl_program[active_index], "rubyInputSize");
pglUniform2fv(location, 1, inputSize);
float outputSize[2] = {(float)out_width, (float)out_height};
location = pglGetUniformLocation(gl_program[active_index], "rubyOutputSize");
pglUniform2fv(location, 1, outputSize);
float textureSize[2] = {(float)tex_width, (float)tex_height};
location = pglGetUniformLocation(gl_program[active_index], "rubyTextureSize");
pglUniform2fv(location, 1, textureSize);
location = pglGetUniformLocation(gl_program[active_index], "rubyFrameCount");
pglUniform1i(location, frame_count);
location = pglGetUniformLocation(gl_program[active_index], "rubyFrameDirection");
pglUniform1i(location, g_extern.frame_is_reverse ? -1 : 1);
for (unsigned i = 0; i < gl_teximage_cnt; i++)
{
GLint location;
location = pglGetUniformLocation(gl_program[active_index], gl_teximage_uniforms[i]);
pglUniform1i(location, i + 1);
}
float inputSize[2] = {width, height};
location = pglGetUniformLocation(gl_program[active_index], "rubyInputSize");
pglUniform2fv(location, 1, inputSize);
unsigned texunit = gl_teximage_cnt + 1;
float outputSize[2] = {out_width, out_height};
location = pglGetUniformLocation(gl_program[active_index], "rubyOutputSize");
pglUniform2fv(location, 1, outputSize);
// Set original texture unless we're in first pass (pointless).
if (active_index > 1)
{
// Bind original texture.
pglActiveTexture(GL_TEXTURE0 + texunit);
float textureSize[2] = {tex_width, tex_height};
location = pglGetUniformLocation(gl_program[active_index], "rubyTextureSize");
pglUniform2fv(location, 1, textureSize);
location = pglGetUniformLocation(gl_program[active_index], "rubyOrigTexture");
pglUniform1i(location, texunit++);
glBindTexture(GL_TEXTURE_2D, info->tex);
location = pglGetUniformLocation(gl_program[active_index], "rubyOrigTextureSize");
pglUniform2fv(location, 1, info->tex_size);
location = pglGetUniformLocation(gl_program[active_index], "rubyOrigInputSize");
pglUniform2fv(location, 1, info->input_size);
// Pass texture coordinates.
location = pglGetAttribLocation(gl_program[active_index], "rubyOrigTexCoord");
if (location >= 0)
{
pglEnableVertexAttribArray(location);
pglVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, info->coord);
gl_attribs[gl_attrib_index++] = location;
}
// Bind new texture in the chain.
if (fbo_info_cnt > 0)
{
pglActiveTexture(GL_TEXTURE0 + texunit + fbo_info_cnt - 1);
glBindTexture(GL_TEXTURE_2D, fbo_info[fbo_info_cnt - 1].tex);
}
// Bind FBO textures.
for (unsigned i = 0; i < fbo_info_cnt; i++)
{
char attrib_buf[64];
snprintf(attrib_buf, sizeof(attrib_buf), "rubyPass%uTexture", i + 1);
location = pglGetUniformLocation(gl_program[active_index], attrib_buf);
pglUniform1i(location, texunit++);
snprintf(attrib_buf, sizeof(attrib_buf), "rubyPass%uTextureSize", i + 1);
location = pglGetUniformLocation(gl_program[active_index], attrib_buf);
pglUniform2fv(location, 1, fbo_info[i].tex_size);
snprintf(attrib_buf, sizeof(attrib_buf), "rubyPass%uInputSize", i + 1);
location = pglGetUniformLocation(gl_program[active_index], attrib_buf);
pglUniform2fv(location, 1, fbo_info[i].input_size);
snprintf(attrib_buf, sizeof(attrib_buf), "rubyPass%uTexCoord", i + 1);
location = pglGetAttribLocation(gl_program[active_index], attrib_buf);
if (location >= 0)
{
pglEnableVertexAttribArray(location);
pglVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, fbo_info[i].coord);
gl_attribs[gl_attrib_index++] = location;
}
}
}
else
{
// First pass, so unbind everything to avoid collitions.
// Unbind ORIG.
pglActiveTexture(GL_TEXTURE0 + texunit);
glBindTexture(GL_TEXTURE_2D, 0);
GLuint base_tex = texunit + 1;
// Unbind any lurking FBO passes.
// Rendering to a texture that is bound to a texture unit
// sounds very shaky ... ;)
for (unsigned i = 0; i < gl_num_programs; i++)
{
pglActiveTexture(GL_TEXTURE0 + base_tex + i);
glBindTexture(GL_TEXTURE_2D, 0);
}
}
// Set previous textures. Only bind if they're actually used.
for (unsigned i = 0; i < PREV_TEXTURES; i++)
{
char attr_buf_tex[64];
char attr_buf_tex_size[64];
char attr_buf_input_size[64];
char attr_buf_coord[64];
static const char *prev_names[PREV_TEXTURES] = {
"Prev",
"Prev1",
"Prev2",
"Prev3",
"Prev4",
"Prev5",
"Prev6",
};
snprintf(attr_buf_tex, sizeof(attr_buf_tex), "ruby%sTexture", prev_names[i]);
snprintf(attr_buf_tex_size, sizeof(attr_buf_tex_size), "ruby%sTextureSize", prev_names[i]);
snprintf(attr_buf_input_size, sizeof(attr_buf_input_size), "ruby%sInputSize", prev_names[i]);
snprintf(attr_buf_coord, sizeof(attr_buf_coord), "ruby%sTexCoord", prev_names[i]);
location = pglGetUniformLocation(gl_program[active_index], attr_buf_tex);
if (location >= 0)
{
pglActiveTexture(GL_TEXTURE0 + texunit);
glBindTexture(GL_TEXTURE_2D, prev_info[i].tex);
pglUniform1i(location, texunit++);
}
location = pglGetUniformLocation(gl_program[active_index], attr_buf_tex_size);
pglUniform2fv(location, 1, prev_info[i].tex_size);
location = pglGetUniformLocation(gl_program[active_index], attr_buf_input_size);
pglUniform2fv(location, 1, prev_info[i].input_size);
// Pass texture coordinates.
location = pglGetAttribLocation(gl_program[active_index], attr_buf_coord);
if (location >= 0)
{
pglEnableVertexAttribArray(location);
pglVertexAttribPointer(location, 2, GL_FLOAT, GL_FALSE, 0, prev_info[i].coord);
gl_attribs[gl_attrib_index++] = location;
}
}
pglActiveTexture(GL_TEXTURE0);
if (gl_snes_tracker)
{
static struct snes_tracker_uniform info[MAX_VARIABLES];
static unsigned cnt = 0;
if (active_index == 1)
cnt = snes_get_uniform(gl_snes_tracker, info, MAX_VARIABLES, frame_count);
for (unsigned i = 0; i < cnt; i++)
{
location = pglGetUniformLocation(gl_program[active_index], info[i].id);
pglUniform1f(location, info[i].value);
}
}
}
@@ -623,6 +1257,8 @@ void gl_glsl_use(unsigned index)
{
if (glsl_enable)
{
gl_glsl_reset_attrib();
active_index = index;
pglUseProgram(gl_program[index]);
}
+7 -3
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -19,7 +19,7 @@
#ifndef __SSNES_GLSL_H
#define __SSNES_GLSL_H
#include <stdbool.h>
#include "../boolean.h"
#include "gl_common.h"
bool gl_glsl_init(const char *path);
@@ -30,7 +30,11 @@ void gl_glsl_set_proj_matrix(void);
void gl_glsl_set_params(unsigned width, unsigned height,
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height);
unsigned out_width, unsigned out_height,
unsigned frame_counter,
const struct gl_tex_info *info,
const struct gl_tex_info *prev_info,
const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt);
void gl_glsl_use(unsigned index);
+259
View File
@@ -0,0 +1,259 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "snes_state.h"
#include <stdlib.h>
#include "../strl.h"
#include "../general.h"
#include "../libsnes.hpp"
#ifdef HAVE_PYTHON
#include "py_state/py_state.h"
#endif
struct snes_tracker_internal
{
char id[64];
bool is_input;
const uint16_t *input_ptr;
const uint8_t *ptr;
#ifdef HAVE_PYTHON
py_state_t *py;
#endif
uint32_t addr;
unsigned mask;
enum snes_tracker_type type;
uint32_t prev[2];
int frame_count;
int frame_count_prev;
uint32_t old_value;
int transition_count;
};
struct snes_tracker
{
struct snes_tracker_internal *info;
unsigned info_elem;
uint16_t input_state[2];
#ifdef HAVE_PYTHON
py_state_t *py;
#endif
};
snes_tracker_t* snes_tracker_init(const struct snes_tracker_info *info)
{
snes_tracker_t *tracker = (snes_tracker_t*)calloc(1, sizeof(*tracker));
if (!tracker)
return NULL;
#ifdef HAVE_PYTHON
if (info->script)
{
tracker->py = py_state_new(info->script, info->script_is_file, info->script_class ? info->script_class : "GameAware");
if (!tracker->py)
{
free(tracker);
SSNES_ERR("Failed to init Python script.\n");
return NULL;
}
}
#endif
tracker->info = (struct snes_tracker_internal*)calloc(info->info_elem, sizeof(struct snes_tracker_internal));
tracker->info_elem = info->info_elem;
for (unsigned i = 0; i < info->info_elem; i++)
{
strlcpy(tracker->info[i].id, info->info[i].id, sizeof(tracker->info[i].id));
tracker->info[i].addr = info->info[i].addr;
tracker->info[i].type = info->info[i].type;
tracker->info[i].mask = (info->info[i].mask == 0) ? -1u : info->info[i].mask;
#ifdef HAVE_PYTHON
if (info->info[i].type == SSNES_STATE_PYTHON)
tracker->info[i].py = tracker->py;
#endif
// If we don't have a valid pointer.
static const uint8_t empty = 0;
switch (info->info[i].ram_type)
{
case SSNES_STATE_WRAM:
tracker->info[i].ptr = info->wram ? info->wram : &empty;
break;
case SSNES_STATE_APURAM:
tracker->info[i].ptr = info->apuram ? info->apuram : &empty;
break;
case SSNES_STATE_OAM:
tracker->info[i].ptr = info->oam ? info->oam : &empty;
break;
case SSNES_STATE_CGRAM:
tracker->info[i].ptr = info->cgram ? info->cgram : &empty;
break;
case SSNES_STATE_VRAM:
tracker->info[i].ptr = info->vram ? info->vram : &empty;
break;
case SSNES_STATE_INPUT_SLOT1:
tracker->info[i].input_ptr = &tracker->input_state[0];
tracker->info[i].is_input = true;
break;
case SSNES_STATE_INPUT_SLOT2:
tracker->info[i].input_ptr = &tracker->input_state[1];
tracker->info[i].is_input = true;
break;
default:
tracker->info[i].ptr = &empty;
}
}
return tracker;
}
void snes_tracker_free(snes_tracker_t *tracker)
{
free(tracker->info);
#ifdef HAVE_PYTHON
py_state_free(tracker->py);
#endif
free(tracker);
}
#define fetch() ((info->is_input ? *info->input_ptr : info->ptr[info->addr]) & info->mask)
static void update_element(
struct snes_tracker_uniform *uniform,
struct snes_tracker_internal *info,
unsigned frame_count)
{
uniform->id = info->id;
switch (info->type)
{
case SSNES_STATE_CAPTURE:
uniform->value = fetch();
break;
case SSNES_STATE_CAPTURE_PREV:
if (info->prev[0] != fetch())
{
info->prev[1] = info->prev[0];
info->prev[0] = fetch();
}
uniform->value = info->prev[1];
break;
case SSNES_STATE_TRANSITION:
if (info->old_value != fetch())
{
info->old_value = fetch();
info->frame_count = frame_count;
}
uniform->value = info->frame_count;
break;
case SSNES_STATE_TRANSITION_COUNT:
if (info->old_value != fetch())
{
info->old_value = fetch();
info->transition_count++;
}
uniform->value = info->transition_count;
break;
case SSNES_STATE_TRANSITION_PREV:
if (info->old_value != fetch())
{
info->old_value = fetch();
info->frame_count_prev = info->frame_count;
info->frame_count = frame_count;
}
uniform->value = info->frame_count_prev;
break;
#ifdef HAVE_PYTHON
case SSNES_STATE_PYTHON:
uniform->value = py_state_get(info->py, info->id, frame_count);
break;
#endif
default:
break;
}
}
#undef fetch
// Updates 16-bit input in same format as SNES itself.
static void update_input(snes_tracker_t *tracker)
{
if (!driver.input_data)
return;
static const unsigned buttons[] = {
SNES_DEVICE_ID_JOYPAD_R,
SNES_DEVICE_ID_JOYPAD_L,
SNES_DEVICE_ID_JOYPAD_X,
SNES_DEVICE_ID_JOYPAD_A,
SNES_DEVICE_ID_JOYPAD_RIGHT,
SNES_DEVICE_ID_JOYPAD_LEFT,
SNES_DEVICE_ID_JOYPAD_DOWN,
SNES_DEVICE_ID_JOYPAD_UP,
SNES_DEVICE_ID_JOYPAD_START,
SNES_DEVICE_ID_JOYPAD_SELECT,
SNES_DEVICE_ID_JOYPAD_Y,
SNES_DEVICE_ID_JOYPAD_B
};
static const struct snes_keybind *binds[MAX_PLAYERS] = {
g_settings.input.binds[0],
g_settings.input.binds[1],
g_settings.input.binds[2],
g_settings.input.binds[3],
g_settings.input.binds[4]
};
uint16_t state[2] = {0};
for (unsigned i = 4; i < 16; i++)
{
state[0] |= (driver.input->input_state(driver.input_data, binds, SNES_PORT_1, SNES_DEVICE_JOYPAD, 0, buttons[i - 4]) ? 1 : 0) << i;
state[1] |= (driver.input->input_state(driver.input_data, binds, SNES_PORT_2, SNES_DEVICE_JOYPAD, 0, buttons[i - 4]) ? 1 : 0) << i;
}
for (unsigned i = 0; i < 2; i++)
tracker->input_state[i] = state[i];
}
unsigned snes_get_uniform(snes_tracker_t *tracker, struct snes_tracker_uniform *uniforms, unsigned elem, unsigned frame_count)
{
unsigned elems = tracker->info_elem < elem ? tracker->info_elem : elem;
update_input(tracker);
for (unsigned i = 0; i < elems; i++)
update_element(&uniforms[i], &tracker->info[i], frame_count);
return elems;
}
+92
View File
@@ -0,0 +1,92 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_SNES_STATE_H
#define __SSNES_SNES_STATE_H
#include <stdint.h>
#include "../boolean.h"
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
enum snes_tracker_type
{
SSNES_STATE_CAPTURE,
SSNES_STATE_CAPTURE_PREV,
SSNES_STATE_TRANSITION,
SSNES_STATE_TRANSITION_COUNT,
SSNES_STATE_TRANSITION_PREV,
#ifdef HAVE_PYTHON
SSNES_STATE_PYTHON
#endif
};
enum snes_ram_type
{
SSNES_STATE_NONE,
SSNES_STATE_WRAM,
SSNES_STATE_APURAM,
SSNES_STATE_OAM,
SSNES_STATE_CGRAM,
SSNES_STATE_VRAM,
SSNES_STATE_INPUT_SLOT1,
SSNES_STATE_INPUT_SLOT2
};
struct snes_tracker_uniform_info
{
char id[64];
uint32_t addr;
enum snes_tracker_type type;
enum snes_ram_type ram_type;
unsigned mask;
};
struct snes_tracker_info
{
const uint8_t *wram;
const uint8_t *vram;
const uint8_t *cgram;
const uint8_t *oam;
const uint8_t *apuram;
const struct snes_tracker_uniform_info *info;
unsigned info_elem;
#ifdef HAVE_PYTHON
const char *script;
const char *script_class;
bool script_is_file;
#endif
};
struct snes_tracker_uniform
{
const char *id;
float value;
};
typedef struct snes_tracker snes_tracker_t;
snes_tracker_t* snes_tracker_init(const struct snes_tracker_info *info);
void snes_tracker_free(snes_tracker_t *tracker);
unsigned snes_get_uniform(snes_tracker_t *tracker, struct snes_tracker_uniform *uniforms, unsigned elem, unsigned frame_count);
#endif
+216 -134
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -37,8 +37,7 @@
// Adapted from bSNES and MPlayer source.
typedef struct xv xv_t;
struct xv
typedef struct xv
{
Display *display;
GC gc;
@@ -63,21 +62,27 @@ struct xv
uint8_t *ytable;
uint8_t *utable;
uint8_t *vtable;
unsigned luma_i;
unsigned chroma_i;
#ifdef HAVE_FREETYPE
font_renderer_t *font;
unsigned luma_index[2];
unsigned chroma_u_index;
unsigned chroma_v_index;
uint8_t font_y;
uint8_t font_u;
uint8_t font_v;
#endif
void (*render_func)(xv_t*, const void *frame, unsigned width, unsigned height, unsigned pitch);
};
void (*render_func)(struct xv*, const void *frame, unsigned width, unsigned height, unsigned pitch);
} xv_t;
static void xv_set_nonblock_state(void *data, bool state)
{
xv_t *xv = data;
xv_t *xv = (xv_t*)data;
Atom atom = XInternAtom(xv->display, "XV_SYNC_TO_VBLANK", true);
if (atom != None && xv->port >= 0)
if (atom != None && xv->port)
XvSetPortAttribute(xv->display, xv->port, atom, !state);
else
SSNES_WARN("Failed to set SYNC_TO_VBLANK attribute.\n");
@@ -89,27 +94,32 @@ static void sighandler(int sig)
g_quit = 1;
}
static inline void calculate_yuv(uint8_t *y, uint8_t *u, uint8_t *v, unsigned r, unsigned g, unsigned b)
{
int y_ = (int)(+((double)r * 0.257) + ((double)g * 0.504) + ((double)b * 0.098) + 16.0);
int u_ = (int)(-((double)r * 0.148) - ((double)g * 0.291) + ((double)b * 0.439) + 128.0);
int v_ = (int)(+((double)r * 0.439) - ((double)g * 0.368) - ((double)b * 0.071) + 128.0);
*y = y_ < 0 ? 0 : (y_ > 255 ? 255 : y_);
*u = y_ < 0 ? 0 : (u_ > 255 ? 255 : u_);
*v = v_ < 0 ? 0 : (v_ > 255 ? 255 : v_);
}
static void init_yuv_tables(xv_t *xv)
{
xv->ytable = malloc(0x8000);
xv->utable = malloc(0x8000);
xv->vtable = malloc(0x8000);
xv->ytable = (uint8_t*)malloc(0x8000);
xv->utable = (uint8_t*)malloc(0x8000);
xv->vtable = (uint8_t*)malloc(0x8000);
for (unsigned i = 0; i < 0x8000; i++)
{
// Extract RGB555 color data from i
uint8_t r = (i >> 10) & 0x1F, g = (i >> 5) & 0x1F, b = (i) & 0x1F;
r = (r << 3) | (r >> 2); //R5->R8
g = (g << 3) | (g >> 2); //G5->G8
b = (b << 3) | (b >> 2); //B5->B8
unsigned r = (i >> 10) & 0x1F, g = (i >> 5) & 0x1F, b = (i) & 0x1F;
r = (r << 3) | (r >> 2); // R5->R8
g = (g << 3) | (g >> 2); // G5->G8
b = (b << 3) | (b >> 2); // B5->B8
int y = (int)(+((double)r * 0.257) + ((double)g * 0.504) + ((double)b * 0.098) + 16.0);
int u = (int)(-((double)r * 0.148) - ((double)g * 0.291) + ((double)b * 0.439) + 128.0);
int v = (int)(+((double)r * 0.439) - ((double)g * 0.368) - ((double)b * 0.071) + 128.0);
xv->ytable[i] = y < 0 ? 0 : y > 255 ? 255 : y;
xv->utable[i] = u < 0 ? 0 : u > 255 ? 255 : u;
xv->vtable[i] = v < 0 ? 0 : v > 255 ? 255 : v;
calculate_yuv(&xv->ytable[i], &xv->utable[i], &xv->vtable[i], r, g, b);
}
}
@@ -173,19 +183,40 @@ static void set_fullscreen(xv_t *xv)
static void xv_init_font(xv_t *xv, const char *font_path, unsigned font_size)
{
#ifdef HAVE_FREETYPE
if (*font_path)
if (!g_settings.video.font_enable)
return;
const char *path = font_path;
if (!*path)
path = font_renderer_get_default_font();
if (path)
{
xv->font = font_renderer_new(font_path, font_size);
if (!xv->font)
SSNES_WARN("Failed to init font\n");
xv->font = font_renderer_new(path, font_size);
if (xv->font)
{
int r = g_settings.video.msg_color_r * 255;
r = (r < 0 ? 0 : (r > 255 ? 255 : r));
int g = g_settings.video.msg_color_g * 255;
g = (g < 0 ? 0 : (g > 255 ? 255 : g));
int b = g_settings.video.msg_color_b * 255;
b = (b < 0 ? 0 : (b > 255 ? 255 : b));
calculate_yuv(&xv->font_y, &xv->font_u, &xv->font_v,
r, g, b);
}
else
SSNES_WARN("Failed to init font.\n");
}
else
SSNES_LOG("Did not find default font.\n");
#endif
}
// We render @ 2x scale to combat chroma downsampling. Also makes fonts more bearable :)
static void render16_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch)
{
const uint16_t *input = input_;
const uint16_t *input = (const uint16_t*)input_;
uint8_t *output = (uint8_t*)xv->image->data;
for (unsigned y = 0; y < height; y++)
@@ -213,7 +244,7 @@ static void render16_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned
static void render16_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch)
{
const uint16_t *input = input_;
const uint16_t *input = (const uint16_t*)input_;
uint8_t *output = (uint8_t*)xv->image->data;
for (unsigned y = 0; y < height; y++)
@@ -241,7 +272,7 @@ static void render16_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned
static void render32_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch)
{
const uint32_t *input = input_;
const uint32_t *input = (const uint32_t*)input_;
uint8_t *output = (uint8_t*)xv->image->data;
for (unsigned y = 0; y < height; y++)
@@ -249,7 +280,7 @@ static void render32_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned
for (unsigned x = 0; x < width; x++)
{
uint32_t p = *input++;
p = ((p >> 17) & 0x7c00) | ((p >> 14) & 0x03e0) | ((p >> 11) & 0x1f); // RGBA -> RGB15
p = ((p >> 9) & 0x7c00) | ((p >> 6) & 0x03e0) | ((p >> 3) & 0x1f); // ARGB -> RGB15
uint8_t y0 = xv->ytable[p];
uint8_t u = xv->utable[p];
@@ -270,7 +301,7 @@ static void render32_yuy2(xv_t *xv, const void *input_, unsigned width, unsigned
static void render32_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned height, unsigned pitch)
{
const uint32_t *input = input_;
const uint32_t *input = (const uint32_t*)input_;
uint16_t *output = (uint16_t*)xv->image->data;
for (unsigned y = 0; y < height; y++)
@@ -278,7 +309,7 @@ static void render32_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned
for (unsigned x = 0; x < width; x++)
{
uint32_t p = *input++;
p = ((p >> 17) & 0x7c00) | ((p >> 14) & 0x03e0) | ((p >> 11) & 0x1f); // RGBA -> RGB15
p = ((p >> 9) & 0x7c00) | ((p >> 6) & 0x03e0) | ((p >> 3) & 0x1f); // ARGB -> RGB15
uint8_t y0 = xv->ytable[p];
uint8_t u = xv->utable[p];
@@ -297,14 +328,92 @@ static void render32_uyvy(xv_t *xv, const void *input_, unsigned width, unsigned
}
}
static void* xv_init(video_info_t *video, const input_driver_t **input, void **input_data)
struct format_desc
{
xv_t *xv = calloc(1, sizeof(*xv));
void (*render_16)(xv_t *xv, const void *input,
unsigned width, unsigned height, unsigned pitch);
void (*render_32)(xv_t *xv, const void *input,
unsigned width, unsigned height, unsigned pitch);
char components[4];
unsigned luma_index[2];
unsigned u_index;
unsigned v_index;
};
static const struct format_desc formats[] = {
{
render16_yuy2,
render32_yuy2,
{ 'Y', 'U', 'Y', 'V' },
{ 0, 2 },
1,
3,
},
{
render16_uyvy,
render32_uyvy,
{ 'U', 'Y', 'V', 'Y' },
{ 1, 3 },
0,
2,
},
};
static bool adaptor_set_format(xv_t *xv, Display *dpy, XvPortID port, const video_info_t *video)
{
int format_count;
XvImageFormatValues *format = XvListImageFormats(xv->display, port, &format_count);
if (!format)
return false;
for (int i = 0; i < format_count; i++)
{
for (unsigned j = 0; j < sizeof(formats) / sizeof(formats[0]); j++)
{
if (format[i].type == XvYUV && format[i].bits_per_pixel == 16 && format[i].format == XvPacked)
{
if (format[i].component_order[0] == formats[j].components[0] &&
format[i].component_order[1] == formats[j].components[1] &&
format[i].component_order[2] == formats[j].components[2] &&
format[i].component_order[3] == formats[j].components[3])
{
xv->fourcc = format[i].id;
xv->render_func = video->rgb32 ? formats[j].render_32 : formats[j].render_16;
#ifdef HAVE_FREETYPE
xv->luma_index[0] = formats[j].luma_index[0];
xv->luma_index[1] = formats[j].luma_index[1];
xv->chroma_u_index = formats[j].u_index;
xv->chroma_v_index = formats[j].v_index;
#endif
XFree(format);
return true;
}
}
}
}
XFree(format);
return false;
}
static void *xv_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{
xv_t *xv = (xv_t*)calloc(1, sizeof(*xv));
if (!xv)
return NULL;
xv->display = XOpenDisplay(NULL);
struct sigaction sa;
unsigned adaptor_count = 0;
int visualmatches = 0;
XSetWindowAttributes attributes = {0};
unsigned width = 0, height = 0;
char buf[128];
Atom atom = 0;
void *xinput = NULL;
XVisualInfo *visualinfo = NULL;
XVisualInfo visualtemplate = {0};
if (!XShmQueryExtension(xv->display))
{
@@ -315,9 +424,8 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
xv->keep_aspect = video->force_aspect;
// Find an appropriate Xv port.
xv->port = -1;
xv->port = 0;
XvAdaptorInfo *adaptor_info;
unsigned adaptor_count = 0;
XvQueryAdaptors(xv->display, DefaultRootWindow(xv->display), &adaptor_count, &adaptor_info);
for (unsigned i = 0; i < adaptor_count; i++)
{
@@ -325,27 +433,28 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
if (adaptor_info[i].num_formats < 1) continue;
if (!(adaptor_info[i].type & XvInputMask)) continue;
if (!(adaptor_info[i].type & XvImageMask)) continue;
if (!adaptor_set_format(xv, xv->display, adaptor_info[i].base_id, video)) continue;
xv->port = adaptor_info[i].base_id;
xv->depth = adaptor_info[i].formats->depth;
xv->visualid = adaptor_info[i].formats->visual_id;
SSNES_LOG("XVideo: Found suitable XvPort #%u\n", (unsigned)xv->port);
break;
}
XvFreeAdaptorInfo(adaptor_info);
if (xv->port < 0)
if (xv->port == 0)
{
SSNES_ERR("XVideo: Failed to find valid XvPort.\n");
SSNES_ERR("XVideo: Failed to find valid XvPort or format.\n");
goto error;
}
XVisualInfo visualtemplate;
visualtemplate.visualid = xv->visualid;
visualtemplate.screen = DefaultScreen(xv->display);
visualtemplate.depth = xv->depth;
visualtemplate.visual = 0;
int visualmatches = 0;
XVisualInfo *visualinfo = XGetVisualInfo(xv->display, VisualIDMask | VisualScreenMask | VisualDepthMask, &visualtemplate, &visualmatches);
visualinfo = XGetVisualInfo(xv->display, VisualIDMask | VisualScreenMask | VisualDepthMask, &visualtemplate, &visualmatches);
if (visualmatches < 1 || !visualinfo->visual)
{
if (visualinfo) XFree(visualinfo);
@@ -354,13 +463,12 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
}
xv->colormap = XCreateColormap(xv->display, DefaultRootWindow(xv->display), visualinfo->visual, AllocNone);
XSetWindowAttributes attributes;
attributes.colormap = xv->colormap;
attributes.border_pixel = 0;
attributes.event_mask = StructureNotifyMask | DestroyNotify | ClientMessage;
unsigned width = video->fullscreen ? ((video->width == 0) ? 256 : video->width) : video->width;
unsigned height = video->fullscreen ? ((video->height == 0) ? 224 : video->height) : video->height;
width = video->fullscreen ? ((video->width == 0) ? g_extern.system.geom.base_width : video->width) : video->width;
height = video->fullscreen ? ((video->height == 0) ? g_extern.system.geom.base_height : video->height) : video->height;
xv->window = XCreateWindow(xv->display, DefaultRootWindow(xv->display),
0, 0, width, height,
0, xv->depth, InputOutput, visualinfo->visual,
@@ -371,7 +479,6 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
XMapWindow(xv->display, xv->window);
char buf[128];
if (gfx_window_title(buf, sizeof(buf)))
XStoreName(xv->display, xv->window, buf);
@@ -382,55 +489,11 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
xv->gc = XCreateGC(xv->display, xv->window, 0, 0);
// Set colorkey to auto paint, so that Xv video output is always visible
Atom atom = XInternAtom(xv->display, "XV_AUTOPAINT_COLORKEY", true);
if(atom != None) XvSetPortAttribute(xv->display, xv->port, atom, 1);
atom = XInternAtom(xv->display, "XV_AUTOPAINT_COLORKEY", true);
if (atom != None) XvSetPortAttribute(xv->display, xv->port, atom, 1);
int format_count;
XvImageFormatValues *format = XvListImageFormats(xv->display, xv->port, &format_count);
bool has_format = false;
for (int i = 0; i < format_count; i++)
{
if (format[i].type == XvYUV && format[i].bits_per_pixel == 16 && format[i].format == XvPacked)
{
if (format[i].component_order[0] == 'Y' && format[i].component_order[1] == 'U'
&& format[i].component_order[2] == 'Y' && format[i].component_order[3] == 'V')
{
has_format = true;
xv->fourcc = format[i].id;
xv->render_func = video->rgb32 ? render32_yuy2 : render16_yuy2;
xv->luma_i = 0; xv->chroma_i = 1;
break;
}
}
}
if (!has_format) for (int i = 0; i < format_count; i++)
{
if (format[i].type == XvYUV && format[i].bits_per_pixel == 16 && format[i].format == XvPacked)
{
if (format[i].component_order[0] == 'U' && format[i].component_order[1] == 'Y'
&& format[i].component_order[2] == 'V' && format[i].component_order[3] == 'Y')
{
has_format = true;
xv->fourcc = format[i].id;
xv->render_func = video->rgb32 ? render32_uyvy : render16_uyvy;
xv->chroma_i = 0; xv->luma_i = 1;
break;
}
}
}
free(format);
if (!has_format)
{
SSNES_ERR("XVideo: unable to find a supported image format.\n");
goto error;
}
xv->width = 512;
xv->height = 512;
xv->width = g_extern.system.geom.max_width;
xv->height = g_extern.system.geom.max_height;
xv->image = XvShmCreateImage(xv->display, xv->port, xv->fourcc, NULL, xv->width, xv->height, &xv->shminfo);
if (!xv->image)
@@ -442,7 +505,7 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
xv->height = xv->image->height;
xv->shminfo.shmid = shmget(IPC_PRIVATE, xv->image->data_size, IPC_CREAT | 0777);
xv->shminfo.shmaddr = xv->image->data = shmat(xv->shminfo.shmid, NULL, 0);
xv->shminfo.shmaddr = xv->image->data = (char*)shmat(xv->shminfo.shmid, NULL, 0);
xv->shminfo.readOnly = false;
if (!XShmAttach(xv->display, &xv->shminfo))
{
@@ -456,7 +519,6 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
if (xv->quit_atom)
XSetWMProtocols(xv->display, xv->window, &xv->quit_atom, 1);
struct sigaction sa;
sa.sa_handler = sighandler;
sa.sa_flags = SA_RESTART;
sigemptyset(&sa.sa_mask);
@@ -466,9 +528,7 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
xv_set_nonblock_state(xv, !video->vsync);
xv->focus = true;
xv_init_font(xv, g_settings.video.font_path, g_settings.video.font_size);
void *xinput = input_x.init();
xinput = input_x.init();
if (xinput)
{
*input = &input_x;
@@ -478,6 +538,8 @@ static void* xv_init(video_info_t *video, const input_driver_t **input, void **i
*input = NULL;
init_yuv_tables(xv);
xv_init_font(xv, g_settings.video.font_path, g_settings.video.font_size);
return xv;
error:
@@ -516,7 +578,7 @@ static bool check_resize(xv_t *xv, unsigned width, unsigned height)
return false;
}
xv->shminfo.shmaddr = xv->image->data = shmat(xv->shminfo.shmid, NULL, 0);
xv->shminfo.shmaddr = xv->image->data = (char*)shmat(xv->shminfo.shmid, NULL, 0);
xv->shminfo.readOnly = false;
if (!XShmAttach(xv->display, &xv->shminfo))
@@ -561,6 +623,7 @@ static void calc_out_rect(bool keep_aspect, unsigned *x, unsigned *y, unsigned *
}
// TODO: Is there some way to render directly like GL? :(
// Hacky C code is hacky :D Yay.
static void xv_render_msg(xv_t *xv, const char *msg, unsigned width, unsigned height)
{
#ifdef HAVE_FREETYPE
@@ -574,35 +637,52 @@ static void xv_render_msg(xv_t *xv, const char *msg, unsigned width, unsigned he
int _base_x = g_settings.video.msg_pos_x * width;
int _base_y = height - g_settings.video.msg_pos_y * height;
unsigned luma_i = xv->luma_i;
unsigned chroma_i = xv->chroma_i;
unsigned luma_index[2] = { xv->luma_index[0], xv->luma_index[1] };
unsigned chroma_u_index = xv->chroma_u_index;
unsigned chroma_v_index = xv->chroma_v_index;
unsigned pitch = width << 1; // YUV formats used are 16 bpp.
while (head)
{
int base_x = _base_x + head->off_x;
int base_x = (_base_x + head->off_x) << 1;
base_x &= ~3; // Make sure we always start on the correct boundary so the indices are correct.
int base_y = _base_y - head->off_y;
if (base_y >= 0)
{
for (int y = 0; y < head->height && (base_y + y) < height; y++)
for (int y = 0; y < (int)head->height && (base_y + y) < height; y++)
{
if (base_x < 0)
continue;
const uint8_t *a = head->output + head->pitch * y;
uint8_t *out = (uint8_t*)xv->image->data + (base_y - head->height + y) * (width << 1) + (base_x << 1);
uint8_t *out = (uint8_t*)xv->image->data + (base_y - head->height + y) * pitch + base_x;
for (int x = 0; x < (head->width << 1) && (base_x + x) < width; x += 2)
for (int x = 0; x < (head->width << 1) && (base_x + x) < pitch; x += 4)
{
// Blend luma
uint8_t blend = a[x >> 1];
unsigned blended = blend + (((256 - blend) * (unsigned)out[x + luma_i]) >> 8);
blended = blended > 255 ? 255 : blended;
out[x + luma_i] = blended;
unsigned alpha[2];
alpha[0] = a[(x >> 1) + 0];
// Blend chroma
blended = (128 * blend + ((256 - blend) * (unsigned)out[x + chroma_i])) >> 8;
blended = blended > 255 ? 255 : blended;
out[x + chroma_i] = blended;
if (((x >> 1) + 1) == head->width) // We reached the end, uhoh! Branching like a BOSS! :D
alpha[1] = 0;
else
alpha[1] = a[(x >> 1) + 1];
unsigned alpha_sub = (alpha[0] + alpha[1]) >> 1; // Blended alpha for the sub-samples U/V channels.
for (unsigned i = 0; i < 2; i++)
{
unsigned blended = (xv->font_y * alpha[i] + ((256 - alpha[i]) * out[x + luma_index[i]])) >> 8;
out[x + luma_index[i]] = blended;
}
// Blend chroma channels
unsigned blended = (xv->font_u * alpha_sub + ((256 - alpha_sub) * out[x + chroma_u_index])) >> 8;
out[x + chroma_u_index] = blended;
blended = (xv->font_v * alpha_sub + ((256 - alpha_sub) * out[x + chroma_v_index])) >> 8;
out[x + chroma_v_index] = blended;
}
}
}
@@ -619,9 +699,9 @@ static void xv_render_msg(xv_t *xv, const char *msg, unsigned width, unsigned he
#endif
}
static bool xv_frame(void *data, const void* frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
static bool xv_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg)
{
xv_t *xv = data;
xv_t *xv = (xv_t*)data;
if (!check_resize(xv, width, height))
return false;
@@ -630,11 +710,12 @@ static bool xv_frame(void *data, const void* frame, unsigned width, unsigned hei
XGetWindowAttributes(xv->display, xv->window, &target);
xv->render_func(xv, frame, width, height, pitch);
if (msg)
xv_render_msg(xv, msg, xv->width, xv->height);
unsigned x, y, owidth, oheight;
calc_out_rect(xv->keep_aspect, &x, &y, &owidth, &oheight, target.width, target.height);
if (msg)
xv_render_msg(xv, msg, width << 1, height << 1);
XvShmPutImage(xv->display, xv->port, xv->window, xv->gc, xv->image,
0, 0, width << 1, height << 1,
x, y, owidth, oheight,
@@ -650,7 +731,7 @@ static bool xv_frame(void *data, const void* frame, unsigned width, unsigned hei
static bool xv_alive(void *data)
{
xv_t *xv = data;
xv_t *xv = (xv_t*)data;
XEvent event;
while (XPending(xv->display))
@@ -659,7 +740,7 @@ static bool xv_alive(void *data)
switch (event.type)
{
case ClientMessage:
if (event.xclient.data.l[0] == xv->quit_atom)
if ((Atom)event.xclient.data.l[0] == xv->quit_atom)
return false;
break;
case DestroyNotify:
@@ -680,22 +761,22 @@ static bool xv_alive(void *data)
static bool xv_focus(void *data)
{
xv_t *xv = data;
xv_t *xv = (xv_t*)data;
return xv->focus;
}
static void xv_free(void *data)
{
xv_t *xv = data;
xv_t *xv = (xv_t*)data;
XShmDetach(xv->display, &xv->shminfo);
shmdt(xv->shminfo.shmaddr);
shmctl(xv->shminfo.shmid, IPC_RMID, NULL);
XFree(xv->image);
if(xv->window)
if (xv->window)
XUnmapWindow(xv->display, xv->window);
if(xv->colormap)
if (xv->colormap)
XFreeColormap(xv->display, xv->colormap);
XCloseDisplay(xv->display);
@@ -713,12 +794,13 @@ static void xv_free(void *data)
}
const video_driver_t video_xvideo = {
.init = xv_init,
.frame = xv_frame,
.alive = xv_alive,
.set_nonblock_state = xv_set_nonblock_state,
.focus = xv_focus,
.free = xv_free,
.ident = "xvideo"
xv_init,
xv_frame,
xv_set_nonblock_state,
xv_alive,
xv_focus,
NULL,
xv_free,
"xvideo"
};
+267
View File
@@ -0,0 +1,267 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "ssnes_dinput.h"
#include "SDL.h"
#include "SDL_syswm.h"
#include "../boolean.h"
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include "../gfx/sdlwrap.h"
void sdl_dinput_free(sdl_dinput_t *di)
{
if (di)
{
for (unsigned i = 0; i < MAX_PLAYERS; i++)
{
if (di->joypad[i])
{
IDirectInputDevice8_Unacquire(di->joypad[i]);
IDirectInputDevice8_Release(di->joypad[i]);
}
}
if (di->ctx)
IDirectInput8_Release(di->ctx);
free(di);
}
}
static BOOL CALLBACK enum_axes_cb(const DIDEVICEOBJECTINSTANCE *inst, void *p)
{
LPDIRECTINPUTDEVICE8 joypad = (LPDIRECTINPUTDEVICE8)p;
DIPROPRANGE range;
memset(&range, 0, sizeof(range));
range.diph.dwSize = sizeof(DIPROPRANGE);
range.diph.dwHeaderSize = sizeof(DIPROPHEADER);
range.diph.dwHow = DIPH_BYID;
range.diph.dwObj = inst->dwType;
range.lMin = -32768;
range.lMax = 32767;
IDirectInputDevice8_SetProperty(joypad, DIPROP_RANGE, &range.diph);
return DIENUM_CONTINUE;
}
static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
{
sdl_dinput_t *di = (sdl_dinput_t*)p;
unsigned active = 0;
unsigned n;
for (n = 0; n < MAX_PLAYERS; n++)
{
if (!di->joypad[n] && g_settings.input.joypad_map[n] == di->joypad_cnt)
break;
if (di->joypad[n])
active++;
}
if (active == MAX_PLAYERS) return DIENUM_STOP;
di->joypad_cnt++;
if (n == MAX_PLAYERS)
return DIENUM_CONTINUE;
#ifdef __cplusplus
if (FAILED(IDirectInput8_CreateDevice(di->ctx, inst->guidInstance, &di->joypad[n], NULL)))
#else
if (FAILED(IDirectInput8_CreateDevice(di->ctx, &inst->guidInstance, &di->joypad[n], NULL)))
#endif
return DIENUM_CONTINUE;
IDirectInputDevice8_SetDataFormat(di->joypad[n], &c_dfDIJoystick2);
IDirectInputDevice8_SetCooperativeLevel(di->joypad[n], di->hWnd,
DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
IDirectInputDevice8_EnumObjects(di->joypad[n], enum_axes_cb,
di->joypad[n], DIDFT_ABSAXIS);
return DIENUM_CONTINUE;
}
sdl_dinput_t* sdl_dinput_init(void)
{
sdl_dinput_t *di = (sdl_dinput_t*)calloc(1, sizeof(*di));
if (!di)
return NULL;
CoInitialize(NULL);
SDL_SysWMinfo info;
SDL_VERSION(&info.version);
if (!sdlwrap_get_wm_info(&info))
{
SSNES_ERR("Failed to get SysWM info.\n");
goto error;
}
#if SDL_MODERN
di->hWnd = info.info.win.window;
#else
di->hWnd = info.window;
#endif
#ifdef __cplusplus
if (FAILED(DirectInput8Create(
GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8,
(void**)&di->ctx, NULL)))
#else
if (FAILED(DirectInput8Create(
GetModuleHandle(NULL), DIRECTINPUT_VERSION, &IID_IDirectInput8,
(void**)&di->ctx, NULL)))
#endif
{
SSNES_ERR("Failed to init DirectInput.\n");
goto error;
}
SSNES_LOG("Enumerating DInput devices ...\n");
IDirectInput8_EnumDevices(di->ctx, DI8DEVCLASS_GAMECTRL, enum_joypad_cb, di, DIEDFL_ATTACHEDONLY);
SSNES_LOG("Done enumerating DInput devices ...\n");
return di;
error:
sdl_dinput_free(di);
return NULL;
}
static bool dinput_joykey_pressed(sdl_dinput_t *di, unsigned port_num, uint16_t joykey)
{
if (joykey == NO_BTN)
return false;
// Check hat.
if (GET_HAT_DIR(joykey))
{
unsigned hat = GET_HAT(joykey);
unsigned elems = sizeof(di->joy_state[0].rgdwPOV) / sizeof(di->joy_state[0].rgdwPOV[0]);
if (hat >= elems)
return false;
unsigned pov = di->joy_state[port_num].rgdwPOV[hat];
// Magic numbers I'm not sure where originate from.
if (pov < 36000)
{
switch (GET_HAT_DIR(joykey))
{
case HAT_UP_MASK:
return (pov >= 31500) || (pov <= 4500);
case HAT_RIGHT_MASK:
return (pov >= 4500) && (pov <= 13500);
case HAT_DOWN_MASK:
return (pov >= 13500) && (pov <= 22500);
case HAT_LEFT_MASK:
return (pov >= 22500) && (pov <= 31500);
}
}
return false;
}
else
{
unsigned elems = sizeof(di->joy_state[0].rgbButtons) / sizeof(di->joy_state[0].rgbButtons[0]);
if (joykey < elems)
return di->joy_state[port_num].rgbButtons[joykey];
}
return false;
}
static bool dinput_joyaxis_pressed(sdl_dinput_t *di, unsigned port_num, uint32_t joyaxis)
{
if (joyaxis == AXIS_NONE)
return false;
int min = -32678 * g_settings.input.axis_threshold;
int max = 32677 * g_settings.input.axis_threshold;
switch (AXIS_NEG_GET(joyaxis))
{
case 0:
return di->joy_state[port_num].lX <= min;
case 1:
return di->joy_state[port_num].lY <= min;
case 2:
return di->joy_state[port_num].lZ <= min;
case 3:
return di->joy_state[port_num].lRx <= min;
case 4:
return di->joy_state[port_num].lRy <= min;
case 5:
return di->joy_state[port_num].lRz <= min;
}
switch (AXIS_POS_GET(joyaxis))
{
case 0:
return di->joy_state[port_num].lX >= max;
case 1:
return di->joy_state[port_num].lY >= max;
case 2:
return di->joy_state[port_num].lZ >= max;
case 3:
return di->joy_state[port_num].lRx >= max;
case 4:
return di->joy_state[port_num].lRy >= max;
case 5:
return di->joy_state[port_num].lRz >= max;
}
return false;
}
bool sdl_dinput_pressed(sdl_dinput_t *di, unsigned port_num, const struct snes_keybind *key)
{
if (di->joypad[port_num] == NULL)
return false;
if (dinput_joykey_pressed(di, port_num, key->joykey))
return true;
if (dinput_joyaxis_pressed(di, port_num, key->joyaxis))
return true;
return false;
}
void sdl_dinput_poll(sdl_dinput_t *di)
{
memset(di->joy_state, 0, sizeof(di->joy_state));
for (unsigned i = 0; i < MAX_PLAYERS; i++)
{
if (di->joypad[i])
{
if (FAILED(IDirectInputDevice8_Poll(di->joypad[i])))
{
IDirectInputDevice8_Acquire(di->joypad[i]);
continue;
}
IDirectInputDevice8_GetDeviceState(di->joypad[i], sizeof(DIJOYSTATE2), &di->joy_state[i]);
}
}
}
+173
View File
@@ -0,0 +1,173 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_KEYSYM_H
#define __SSNES_KEYSYM_H
// Global keysym table for SSNES.
// As you may have noticed, it's the same as SDL 1.2 since I'm lazy.
enum ssnes_key
{
SK_UNKNOWN = 0,
SK_FIRST = 0,
SK_BACKSPACE = 8,
SK_TAB = 9,
SK_CLEAR = 12,
SK_RETURN = 13,
SK_PAUSE = 19,
SK_ESCAPE = 27,
SK_SPACE = 32,
SK_EXCLAIM = 33,
SK_QUOTEDBL = 34,
SK_HASH = 35,
SK_DOLLAR = 36,
SK_AMPERSAND = 38,
SK_QUOTE = 39,
SK_LEFTPAREN = 40,
SK_RIGHTPAREN = 41,
SK_ASTERISK = 42,
SK_PLUS = 43,
SK_COMMA = 44,
SK_MINUS = 45,
SK_PERIOD = 46,
SK_SLASH = 47,
SK_0 = 48,
SK_1 = 49,
SK_2 = 50,
SK_3 = 51,
SK_4 = 52,
SK_5 = 53,
SK_6 = 54,
SK_7 = 55,
SK_8 = 56,
SK_9 = 57,
SK_COLON = 58,
SK_SEMICOLON = 59,
SK_LESS = 60,
SK_EQUALS = 61,
SK_GREATER = 62,
SK_QUESTION = 63,
SK_AT = 64,
SK_LEFTBRACKET = 91,
SK_BACKSLASH = 92,
SK_RIGHTBRACKET = 93,
SK_CARET = 94,
SK_UNDERSCORE = 95,
SK_BACKQUOTE = 96,
SK_a = 97,
SK_b = 98,
SK_c = 99,
SK_d = 100,
SK_e = 101,
SK_f = 102,
SK_g = 103,
SK_h = 104,
SK_i = 105,
SK_j = 106,
SK_k = 107,
SK_l = 108,
SK_m = 109,
SK_n = 110,
SK_o = 111,
SK_p = 112,
SK_q = 113,
SK_r = 114,
SK_s = 115,
SK_t = 116,
SK_u = 117,
SK_v = 118,
SK_w = 119,
SK_x = 120,
SK_y = 121,
SK_z = 122,
SK_DELETE = 127,
SK_KP0 = 256,
SK_KP1 = 257,
SK_KP2 = 258,
SK_KP3 = 259,
SK_KP4 = 260,
SK_KP5 = 261,
SK_KP6 = 262,
SK_KP7 = 263,
SK_KP8 = 264,
SK_KP9 = 265,
SK_KP_PERIOD = 266,
SK_KP_DIVIDE = 267,
SK_KP_MULTIPLY = 268,
SK_KP_MINUS = 269,
SK_KP_PLUS = 270,
SK_KP_ENTER = 271,
SK_KP_EQUALS = 272,
SK_UP = 273,
SK_DOWN = 274,
SK_RIGHT = 275,
SK_LEFT = 276,
SK_INSERT = 277,
SK_HOME = 278,
SK_END = 279,
SK_PAGEUP = 280,
SK_PAGEDOWN = 281,
SK_F1 = 282,
SK_F2 = 283,
SK_F3 = 284,
SK_F4 = 285,
SK_F5 = 286,
SK_F6 = 287,
SK_F7 = 288,
SK_F8 = 289,
SK_F9 = 290,
SK_F10 = 291,
SK_F11 = 292,
SK_F12 = 293,
SK_F13 = 294,
SK_F14 = 295,
SK_F15 = 296,
SK_NUMLOCK = 300,
SK_CAPSLOCK = 301,
SK_SCROLLOCK = 302,
SK_RSHIFT = 303,
SK_LSHIFT = 304,
SK_RCTRL = 305,
SK_LCTRL = 306,
SK_RALT = 307,
SK_LALT = 308,
SK_RMETA = 309,
SK_LMETA = 310,
SK_LSUPER = 311,
SK_RSUPER = 312,
SK_MODE = 313,
SK_COMPOSE = 314,
SK_HELP = 315,
SK_PRINT = 316,
SK_SYSREQ = 317,
SK_BREAK = 318,
SK_MENU = 319,
SK_POWER = 320,
SK_EURO = 321,
SK_UNDO = 322,
SK_LAST
};
#endif
+178 -85
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -15,22 +15,130 @@
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "driver.h"
#include "../driver.h"
#include "SDL.h"
#include <stdbool.h>
#include "general.h"
#include "../gfx/sdlwrap.h"
#include "../boolean.h"
#include "../general.h"
#include <stdint.h>
#include <stdlib.h>
#include <libsnes.hpp>
#include "../libsnes.hpp"
#include "ssnes_sdl_input.h"
#include "keysym.h"
static void* sdl_input_init(void)
struct key_bind
{
sdl_input_t *sdl = calloc(1, sizeof(*sdl));
unsigned sdl;
enum ssnes_key sk;
};
static unsigned keysym_lut[SK_LAST];
static const struct key_bind lut_binds[] = {
{ SDLK_LEFT, SK_LEFT },
{ SDLK_RIGHT, SK_RIGHT },
{ SDLK_UP, SK_UP },
{ SDLK_DOWN, SK_DOWN },
{ SDLK_RETURN, SK_RETURN },
{ SDLK_TAB, SK_TAB },
{ SDLK_INSERT, SK_INSERT },
{ SDLK_DELETE, SK_DELETE },
{ SDLK_RSHIFT, SK_RSHIFT },
{ SDLK_LSHIFT, SK_LSHIFT },
{ SDLK_LCTRL, SK_LCTRL },
{ SDLK_LALT, SK_LALT },
{ SDLK_SPACE, SK_SPACE },
{ SDLK_ESCAPE, SK_ESCAPE },
{ SDLK_BACKSPACE, SK_BACKSPACE },
{ SDLK_KP_ENTER, SK_KP_ENTER },
{ SDLK_KP_PLUS, SK_KP_PLUS },
{ SDLK_KP_MINUS, SK_KP_MINUS },
{ SDLK_KP_MULTIPLY, SK_KP_MULTIPLY },
{ SDLK_KP_DIVIDE, SK_KP_DIVIDE },
{ SDLK_BACKQUOTE, SK_BACKQUOTE },
{ SDLK_PAUSE, SK_PAUSE },
{ SDLK_KP0, SK_KP0 },
{ SDLK_KP1, SK_KP1 },
{ SDLK_KP2, SK_KP2 },
{ SDLK_KP3, SK_KP3 },
{ SDLK_KP4, SK_KP4 },
{ SDLK_KP5, SK_KP5 },
{ SDLK_KP6, SK_KP6 },
{ SDLK_KP7, SK_KP7 },
{ SDLK_KP8, SK_KP8 },
{ SDLK_KP9, SK_KP9 },
{ SDLK_0, SK_0 },
{ SDLK_1, SK_1 },
{ SDLK_2, SK_2 },
{ SDLK_3, SK_3 },
{ SDLK_4, SK_4 },
{ SDLK_5, SK_5 },
{ SDLK_6, SK_6 },
{ SDLK_7, SK_7 },
{ SDLK_8, SK_8 },
{ SDLK_9, SK_9 },
{ SDLK_F1, SK_F1 },
{ SDLK_F2, SK_F2 },
{ SDLK_F3, SK_F3 },
{ SDLK_F4, SK_F4 },
{ SDLK_F5, SK_F5 },
{ SDLK_F6, SK_F6 },
{ SDLK_F7, SK_F7 },
{ SDLK_F8, SK_F8 },
{ SDLK_F9, SK_F9 },
{ SDLK_F10, SK_F10 },
{ SDLK_F11, SK_F11 },
{ SDLK_F12, SK_F12 },
{ SDLK_a, SK_a },
{ SDLK_b, SK_b },
{ SDLK_c, SK_c },
{ SDLK_d, SK_d },
{ SDLK_e, SK_e },
{ SDLK_f, SK_f },
{ SDLK_g, SK_g },
{ SDLK_h, SK_h },
{ SDLK_i, SK_i },
{ SDLK_j, SK_j },
{ SDLK_k, SK_k },
{ SDLK_l, SK_l },
{ SDLK_m, SK_m },
{ SDLK_n, SK_n },
{ SDLK_o, SK_o },
{ SDLK_p, SK_p },
{ SDLK_q, SK_q },
{ SDLK_r, SK_r },
{ SDLK_s, SK_s },
{ SDLK_t, SK_t },
{ SDLK_u, SK_u },
{ SDLK_v, SK_v },
{ SDLK_w, SK_w },
{ SDLK_x, SK_x },
{ SDLK_y, SK_y },
{ SDLK_z, SK_z },
};
static void init_lut(void)
{
memset(keysym_lut, 0, sizeof(keysym_lut));
for (unsigned i = 0; i < sizeof(lut_binds) / sizeof(lut_binds[0]); i++)
keysym_lut[lut_binds[i].sk] = lut_binds[i].sdl;
}
static void *sdl_input_init(void)
{
init_lut();
sdl_input_t *sdl = (sdl_input_t*)calloc(1, sizeof(*sdl));
if (!sdl)
return NULL;
#ifdef HAVE_DINPUT
sdl->di = sdl_dinput_init();
if (!sdl->di)
{
free(sdl);
SSNES_ERR("Failed to init SDL/DInput.\n");
return NULL;
}
#else
if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
return NULL;
@@ -60,31 +168,28 @@ static void* sdl_input_init(void)
sdl->num_hats[i] = SDL_JoystickNumHats(sdl->joysticks[i]);
}
}
#endif
sdl->use_keyboard = true;
return sdl;
}
static bool sdl_key_pressed(int key)
{
int num_keys;
Uint8 *keymap = SDL_GetKeyState(&num_keys);
if (key >= num_keys)
return false;
return keymap[key];
return sdlwrap_key_pressed(keysym_lut[key]);
}
#ifndef HAVE_DINPUT
static bool sdl_joykey_pressed(sdl_input_t *sdl, int port_num, uint16_t joykey)
{
if (joykey == NO_BTN)
return false;
// Check hat.
if (GET_HAT_DIR(joykey))
{
int hat = GET_HAT(joykey);
if (hat < sdl->num_hats[port_num])
if (hat < (int)sdl->num_hats[port_num])
{
Uint8 dir = SDL_JoystickGetHat(sdl->joysticks[port_num], hat);
switch (GET_HAT_DIR(joykey))
@@ -120,37 +225,43 @@ static bool sdl_joykey_pressed(sdl_input_t *sdl, int port_num, uint16_t joykey)
static bool sdl_axis_pressed(sdl_input_t *sdl, int port_num, uint32_t joyaxis)
{
if (joyaxis != AXIS_NONE)
if (joyaxis == AXIS_NONE)
return false;
if (AXIS_NEG_GET(joyaxis) < sdl->num_axes[port_num])
{
if (AXIS_NEG_GET(joyaxis) < sdl->num_axes[port_num])
{
Sint16 val = SDL_JoystickGetAxis(sdl->joysticks[port_num], AXIS_NEG_GET(joyaxis));
float scaled = (float)val / 0x8000;
if (scaled < -g_settings.input.axis_threshold)
return true;
}
if (AXIS_POS_GET(joyaxis) < sdl->num_axes[port_num])
{
Sint16 val = SDL_JoystickGetAxis(sdl->joysticks[port_num], AXIS_POS_GET(joyaxis));
float scaled = (float)val / 0x8000;
if (scaled > g_settings.input.axis_threshold)
return true;
}
Sint16 val = SDL_JoystickGetAxis(sdl->joysticks[port_num], AXIS_NEG_GET(joyaxis));
float scaled = (float)val / 0x8000;
if (scaled < -g_settings.input.axis_threshold)
return true;
}
if (AXIS_POS_GET(joyaxis) < sdl->num_axes[port_num])
{
Sint16 val = SDL_JoystickGetAxis(sdl->joysticks[port_num], AXIS_POS_GET(joyaxis));
float scaled = (float)val / 0x8000;
if (scaled > g_settings.input.axis_threshold)
return true;
}
return false;
}
#endif
static bool sdl_is_pressed(sdl_input_t *sdl, int port_num, const struct snes_keybind *key)
static bool sdl_is_pressed(sdl_input_t *sdl, unsigned port_num, const struct snes_keybind *key)
{
if (sdl->use_keyboard && sdl_key_pressed(key->key))
return true;
#ifdef HAVE_DINPUT
return sdl_dinput_pressed(sdl->di, port_num, key);
#else
if (sdl->joysticks[port_num] == NULL)
return false;
if (sdl_joykey_pressed(sdl, port_num, key->joykey))
return true;
if (sdl_axis_pressed(sdl, port_num, key->joyaxis))
return true;
#endif
return false;
}
@@ -159,32 +270,30 @@ static bool sdl_bind_button_pressed(void *data, int key)
{
// Only let player 1 use special binds called from main loop.
const struct snes_keybind *binds = g_settings.input.binds[0];
for (int i = 0; binds[i].id != -1; i++)
for (unsigned i = 0; binds[i].id != -1; i++)
{
if (binds[i].id == key)
return sdl_is_pressed(data, 0, &binds[i]);
return sdl_is_pressed((sdl_input_t*)data, 0, &binds[i]);
}
return false;
}
static int16_t sdl_joypad_device_state(sdl_input_t *sdl, const struct snes_keybind **binds,
int port_num, unsigned device, unsigned index, unsigned id)
unsigned port_num, int id)
{
const struct snes_keybind *snes_keybinds = binds[port_num];
for (int i = 0; snes_keybinds[i].id != -1; i++)
for (unsigned i = 0; snes_keybinds[i].id != -1; i++)
{
if (snes_keybinds[i].id == (int)id)
return sdl_is_pressed(sdl, port_num, &snes_keybinds[i]);
if (snes_keybinds[i].id == id)
return sdl_is_pressed(sdl, port_num, &snes_keybinds[i]) ? 1 : 0;
}
return false;
return 0;
}
static int16_t sdl_mouse_device_state(sdl_input_t *sdl, bool port, unsigned id)
static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id)
{
// Might implement support for joypad mapping later.
(void)port;
switch (id)
{
case SNES_DEVICE_ID_MOUSE_LEFT:
@@ -243,16 +352,17 @@ static int16_t sdl_justifier_device_state(sdl_input_t *sdl, unsigned index, unsi
return 0;
}
static int16_t sdl_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id)
static int16_t sdl_input_state(void *data_, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id)
{
sdl_input_t *data = (sdl_input_t*)data_;
switch (device)
{
case SNES_DEVICE_JOYPAD:
return sdl_joypad_device_state(data, binds, (port == SNES_PORT_1) ? 0 : 1, device, index, id);
return sdl_joypad_device_state(data, binds, (port == SNES_PORT_1) ? 0 : 1, id);
case SNES_DEVICE_MULTITAP:
return sdl_joypad_device_state(data, binds, (port == SNES_PORT_2) ? 1 + index : 0, device, index, id);
return sdl_joypad_device_state(data, binds, (port == SNES_PORT_2) ? 1 + index : 0, id);
case SNES_DEVICE_MOUSE:
return sdl_mouse_device_state(data, port, id);
return sdl_mouse_device_state(data, id);
case SNES_DEVICE_SUPER_SCOPE:
return sdl_scope_device_state(data, id);
case SNES_DEVICE_JUSTIFIER:
@@ -272,15 +382,20 @@ static void sdl_input_free(void *data)
SDL_Event event;
while (SDL_PollEvent(&event));
sdl_input_t *sdl = data;
sdl_input_t *sdl = (sdl_input_t*)data;
#ifdef HAVE_DINPUT
sdl_dinput_free(sdl->di);
#else
for (int i = 0; i < MAX_PLAYERS; i++)
{
if (sdl->joysticks[i])
SDL_JoystickClose(sdl->joysticks[i]);
}
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
#endif
free(data);
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
}
}
@@ -298,45 +413,23 @@ static void sdl_poll_mouse(sdl_input_t *sdl)
static void sdl_input_poll(void *data)
{
SDL_PumpEvents();
SDL_Event event;
sdl_input_t *sdl = (sdl_input_t*)data;
#ifdef HAVE_DINPUT
sdl_dinput_poll(sdl->di);
#else
SDL_JoystickUpdate();
sdl_poll_mouse(data);
#endif
sdl_input_t *sdl = data;
// Search for events...
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
if (sdl->quitting)
{
*sdl->quitting = true;
return;
}
break;
case SDL_VIDEORESIZE:
if (sdl->should_resize)
{
*sdl->new_width = event.resize.w;
*sdl->new_height = event.resize.h;
*sdl->should_resize = true;
}
break;
default:
break;
}
}
sdl_poll_mouse(sdl);
}
const input_driver_t input_sdl = {
.init = sdl_input_init,
.poll = sdl_input_poll,
.input_state = sdl_input_state,
.key_pressed = sdl_bind_button_pressed,
.free = sdl_input_free,
.ident = "sdl"
sdl_input_init,
sdl_input_poll,
sdl_input_state,
sdl_bind_button_pressed,
sdl_input_free,
"sdl"
};
+48
View File
@@ -0,0 +1,48 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
* SSNES is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* SSNES is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with SSNES.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __SSNES_DINPUT_H
#define __SSNES_DINPUT_H
#undef DIRECTINPUT_VERSION
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include "../boolean.h"
#include "../general.h"
// Piggyback joypad driver for SDL.
typedef struct sdl_dinput
{
HWND hWnd;
LPDIRECTINPUT8 ctx;
LPDIRECTINPUTDEVICE8 joypad[MAX_PLAYERS];
unsigned joypad_cnt;
DIJOYSTATE2 joy_state[MAX_PLAYERS];
} sdl_dinput_t;
sdl_dinput_t *sdl_dinput_init(void);
void sdl_dinput_free(sdl_dinput_t *di);
bool sdl_dinput_pressed(sdl_dinput_t *di, unsigned port_num,
const struct snes_keybind *key);
void sdl_dinput_poll(sdl_dinput_t *di);
#endif
+12 -7
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -19,21 +19,26 @@
#define __SSNES_SDL_INPUT_H
#include "SDL.h"
#include "general.h"
#include "../general.h"
#ifdef HAVE_DINPUT
#include "ssnes_dinput.h"
#endif
typedef struct sdl_input
{
#ifdef HAVE_DINPUT
sdl_dinput_t *di;
#else
SDL_Joystick *joysticks[MAX_PLAYERS];
unsigned num_axes[MAX_PLAYERS];
unsigned num_buttons[MAX_PLAYERS];
unsigned num_hats[MAX_PLAYERS];
unsigned num_joysticks;
#endif
bool use_keyboard;
// A video driver could pre-init with the SDL driver and have it handle resizing events...
bool *quitting;
bool *should_resize;
unsigned *new_width;
unsigned *new_height;
int16_t mouse_x, mouse_y;
int16_t mouse_l, mouse_r, mouse_m;
} sdl_input_t;
+101 -74
View File
@@ -1,5 +1,5 @@
/* SSNES - A Super Nintendo Entertainment System (SNES) Emulator frontend for libsnes.
* Copyright (C) 2010-2011 - Hans-Kristian Arntzen
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* Some code herein may be based on code found in BSNES.
*
@@ -18,11 +18,12 @@
#include "driver.h"
#include "SDL.h"
#include <stdbool.h>
#include "../boolean.h"
#include "general.h"
#include <stdint.h>
#include <stdlib.h>
#include "ssnes_sdl_input.h"
#include "keysym.h"
#include <X11/Xlib.h>
#include <X11/Xutil.h>
@@ -37,78 +38,104 @@ typedef struct x11_input
struct key_bind
{
int x;
int sdl;
unsigned x;
enum ssnes_key sk;
};
static int keysym_lut[SDLK_LAST];
static unsigned keysym_lut[SK_LAST];
static const struct key_bind lut_binds[] = {
{ XK_Left, SDLK_LEFT },
{ XK_Right, SDLK_RIGHT },
{ XK_Up, SDLK_UP },
{ XK_Down, SDLK_DOWN },
{ XK_Return, SDLK_RETURN },
{ XK_Tab, SDLK_TAB },
{ XK_Insert, SDLK_INSERT },
{ XK_Delete, SDLK_DELETE },
{ XK_Shift_R, SDLK_RSHIFT },
{ XK_Shift_L, SDLK_LSHIFT },
{ XK_Control_L, SDLK_LCTRL },
{ XK_Alt_L, SDLK_LALT },
{ XK_space, SDLK_SPACE },
{ XK_Escape, SDLK_ESCAPE },
{ XK_KP_Add, SDLK_KP_PLUS },
{ XK_KP_Subtract, SDLK_KP_MINUS },
{ XK_F1, SDLK_F1 },
{ XK_F2, SDLK_F2 },
{ XK_F3, SDLK_F3 },
{ XK_F4, SDLK_F4 },
{ XK_F5, SDLK_F5 },
{ XK_F6, SDLK_F6 },
{ XK_F7, SDLK_F7 },
{ XK_F8, SDLK_F8 },
{ XK_F9, SDLK_F9 },
{ XK_F10, SDLK_F10 },
{ XK_F11, SDLK_F11 },
{ XK_F12, SDLK_F12 },
{ XK_a, SDLK_a },
{ XK_b, SDLK_b },
{ XK_c, SDLK_c },
{ XK_d, SDLK_d },
{ XK_e, SDLK_e },
{ XK_f, SDLK_f },
{ XK_g, SDLK_g },
{ XK_h, SDLK_h },
{ XK_i, SDLK_i },
{ XK_j, SDLK_j },
{ XK_k, SDLK_k },
{ XK_l, SDLK_l },
{ XK_m, SDLK_m },
{ XK_n, SDLK_n },
{ XK_o, SDLK_o },
{ XK_p, SDLK_p },
{ XK_q, SDLK_q },
{ XK_r, SDLK_r },
{ XK_s, SDLK_s },
{ XK_t, SDLK_t },
{ XK_u, SDLK_u },
{ XK_v, SDLK_v },
{ XK_w, SDLK_w },
{ XK_x, SDLK_x },
{ XK_y, SDLK_y },
{ XK_z, SDLK_z },
{ XK_Left, SK_LEFT },
{ XK_Right, SK_RIGHT },
{ XK_Up, SK_UP },
{ XK_Down, SK_DOWN },
{ XK_Return, SK_RETURN },
{ XK_Tab, SK_TAB },
{ XK_Insert, SK_INSERT },
{ XK_Delete, SK_DELETE },
{ XK_Shift_R, SK_RSHIFT },
{ XK_Shift_L, SK_LSHIFT },
{ XK_Control_L, SK_LCTRL },
{ XK_Alt_L, SK_LALT },
{ XK_space, SK_SPACE },
{ XK_Escape, SK_ESCAPE },
{ XK_BackSpace, SK_BACKSPACE },
{ XK_KP_Enter, SK_KP_ENTER },
{ XK_KP_Add, SK_KP_PLUS },
{ XK_KP_Subtract, SK_KP_MINUS },
{ XK_KP_Multiply, SK_KP_MULTIPLY },
{ XK_KP_Divide, SK_KP_DIVIDE },
{ XK_grave, SK_BACKQUOTE },
{ XK_Pause, SK_PAUSE },
{ XK_KP_0, SK_KP0 },
{ XK_KP_1, SK_KP1 },
{ XK_KP_2, SK_KP2 },
{ XK_KP_3, SK_KP3 },
{ XK_KP_4, SK_KP4 },
{ XK_KP_5, SK_KP5 },
{ XK_KP_6, SK_KP6 },
{ XK_KP_7, SK_KP7 },
{ XK_KP_8, SK_KP8 },
{ XK_KP_9, SK_KP9 },
{ XK_0, SK_0 },
{ XK_1, SK_1 },
{ XK_2, SK_2 },
{ XK_3, SK_3 },
{ XK_4, SK_4 },
{ XK_5, SK_5 },
{ XK_6, SK_6 },
{ XK_7, SK_7 },
{ XK_8, SK_8 },
{ XK_9, SK_9 },
{ XK_F1, SK_F1 },
{ XK_F2, SK_F2 },
{ XK_F3, SK_F3 },
{ XK_F4, SK_F4 },
{ XK_F5, SK_F5 },
{ XK_F6, SK_F6 },
{ XK_F7, SK_F7 },
{ XK_F8, SK_F8 },
{ XK_F9, SK_F9 },
{ XK_F10, SK_F10 },
{ XK_F11, SK_F11 },
{ XK_F12, SK_F12 },
{ XK_a, SK_a },
{ XK_b, SK_b },
{ XK_c, SK_c },
{ XK_d, SK_d },
{ XK_e, SK_e },
{ XK_f, SK_f },
{ XK_g, SK_g },
{ XK_h, SK_h },
{ XK_i, SK_i },
{ XK_j, SK_j },
{ XK_k, SK_k },
{ XK_l, SK_l },
{ XK_m, SK_m },
{ XK_n, SK_n },
{ XK_o, SK_o },
{ XK_p, SK_p },
{ XK_q, SK_q },
{ XK_r, SK_r },
{ XK_s, SK_s },
{ XK_t, SK_t },
{ XK_u, SK_u },
{ XK_v, SK_v },
{ XK_w, SK_w },
{ XK_x, SK_x },
{ XK_y, SK_y },
{ XK_z, SK_z },
};
static void init_lut(void)
{
memset(keysym_lut, 0, sizeof(keysym_lut));
for (unsigned i = 0; i < sizeof(lut_binds) / sizeof(lut_binds[0]); i++)
keysym_lut[lut_binds[i].sdl] = lut_binds[i].x;
keysym_lut[lut_binds[i].sk] = lut_binds[i].x;
}
static void* x_input_init(void)
static void *x_input_init(void)
{
x11_input_t *x11 = calloc(1, sizeof(*x11));
x11_input_t *x11 = (x11_input_t*)calloc(1, sizeof(*x11));
if (!x11)
return NULL;
@@ -119,7 +146,7 @@ static void* x_input_init(void)
return NULL;
}
x11->sdl = input_sdl.init();
x11->sdl = (sdl_input_t*)input_sdl.init();
if (!x11->sdl)
{
free(x11);
@@ -144,7 +171,7 @@ static bool x_is_pressed(x11_input_t *x11, const struct snes_keybind *binds, uns
{
for (int i = 0; binds[i].id != -1; i++)
{
if (binds[i].id == id)
if (binds[i].id == (int)id)
return x_key_pressed(x11, binds[i].key);
}
@@ -153,7 +180,7 @@ static bool x_is_pressed(x11_input_t *x11, const struct snes_keybind *binds, uns
static bool x_bind_button_pressed(void *data, int key)
{
x11_input_t *x11 = data;
x11_input_t *x11 = (x11_input_t*)data;
bool pressed = x_is_pressed(x11, g_settings.input.binds[0], key);
if (!pressed)
return input_sdl.key_pressed(x11->sdl, key);
@@ -162,7 +189,7 @@ static bool x_bind_button_pressed(void *data, int key)
static int16_t x_input_state(void *data, const struct snes_keybind **binds, bool port, unsigned device, unsigned index, unsigned id)
{
x11_input_t *x11 = data;
x11_input_t *x11 = (x11_input_t*)data;
bool pressed = false;
switch (device)
@@ -186,7 +213,7 @@ static int16_t x_input_state(void *data, const struct snes_keybind **binds, bool
static void x_input_free(void *data)
{
x11_input_t *x11 = data;
x11_input_t *x11 = (x11_input_t*)data;
input_sdl.free(x11->sdl);
XCloseDisplay(x11->display);
free(data);
@@ -194,17 +221,17 @@ static void x_input_free(void *data)
static void x_input_poll(void *data)
{
x11_input_t *x11 = data;
x11_input_t *x11 = (x11_input_t*)data;
XQueryKeymap(x11->display, x11->state);
input_sdl.poll(x11->sdl);
}
const input_driver_t input_x = {
.init = x_input_init,
.poll = x_input_poll,
.input_state = x_input_state,
.key_pressed = x_bind_button_pressed,
.free = x_input_free,
.ident = "x"
x_input_init,
x_input_poll,
x_input_state,
x_bind_button_pressed,
x_input_free,
"x"
};
+56
View File
@@ -66,6 +66,60 @@ extern "C" {
#define SNES_MEMORY_OAM 103
#define SNES_MEMORY_CGRAM 104
// SSNES extension. Not required to be implemented for a working implementation.
#define SNES_ENVIRONMENT_GET_FULLPATH 0 // const char ** --
// Full path of game loaded.
//
#define SNES_ENVIRONMENT_SET_GEOMETRY 1 // const struct snes_geometry * --
// Window geometry information for the system/game.
//
#define SNES_ENVIRONMENT_SET_PITCH 2 // const unsigned * --
// Pitch of game image.
//
#define SNES_ENVIRONMENT_GET_OVERSCAN 3 // bool * --
// Boolean value whether or not the implementation should use overscan.
//
#define SNES_ENVIRONMENT_SET_TIMING 4 // const struct snes_system_timing * --
// Set exact timings of the system. Used primarily for video recording.
//
#define SNES_ENVIRONMENT_GET_CAN_DUPE 5 // bool * --
// Boolean value whether or not SSNES supports frame duping,
// passing NULL to video frame callback.
//
//
#define SNES_ENVIRONMENT_SET_NEED_FULLPATH 6 // const bool * --
// Boolean value telling if implementation needs a valid fullpath to be able to run.
// If this is the case, SSNES will not open the rom directly,
// and pass NULL to rom data.
// Implementation must then use SNES_ENVIRONMENT_GET_FULLPATH.
// This is useful for implementations with very large roms,
// which are impractical to load fully into RAM.
//
#define SNES_ENVIRONMENT_GET_CAN_REWIND 7 // bool * --
// Boolean value telling if SSNES is able to rewind.
// Some implementations might need to take extra precautions
// to allow this as smoothly as possible.
struct snes_geometry
{
unsigned base_width; // Nominal video width of system.
unsigned base_height; // Nominal video height of system.
unsigned max_width; // Maximum possible width of system.
unsigned max_height; // Maximum possible height of system.
};
struct snes_system_timing
{
double fps;
double sample_rate;
};
typedef bool (*snes_environment_t)(unsigned cmd, void *data);
// Must be called before calling snes_init().
void snes_set_environment(snes_environment_t);
////
typedef void (*snes_video_refresh_t)(const uint16_t *data, unsigned width, unsigned height);
typedef void (*snes_audio_sample_t)(uint16_t left, uint16_t right);
typedef void (*snes_input_poll_t)(void);
@@ -74,6 +128,8 @@ typedef int16_t (*snes_input_state_t)(bool port, unsigned device, unsigned index
unsigned snes_library_revision_major(void);
unsigned snes_library_revision_minor(void);
const char *snes_library_id(void);
void snes_set_video_refresh(snes_video_refresh_t);
void snes_set_audio_sample(snes_audio_sample_t);
void snes_set_input_poll(snes_input_poll_t);
Loaded 100 of 174 files, more files were not shown because too many files have changed in this diff. Show more