Commit Graph

126 Commits

Author SHA1 Message Date
Rafael Kitover c169420fbc Turbo/throttle config and DirectSound fixes.
Make `speedup_frame_skip` and `speedup_throttle` independent settings,
with `speedup_frame_skip == 0` when `speedup_throttle` is not in effect,
and `speedup_throttle == 100` when `speedup_frame_skip` is in effect.

This fixes a previously introduced bug where `speedup == true &&
speedup_frame_skip = X` was never enabled.

This also allows `speedup_throttle == 0` for no throttle and no frame
skip during speedup.

Also set the upper bound on `throttle` and `speedup_throttle` to `450`
instead of `600`, as the DirectSound driver does not support values
higher than that.

In the DirectSound implementation of `setThrottle`, for `throttle == 0`
use a `throttle == 450` frequency multiplier, because a zero frequency
does nothing.

- Fix #719.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2020-08-22 20:25:05 +00:00
Edênis Freindorfer Azevedo baa0341bd5
Input refactor.
- Allow key shortcuts to run with loaded game.

For example, when we set `CTRL+A` for `load most recent save state` and
use `A` for some input command, holding `CTRL` and then pressing `A`
will not execute the shortcut. Instead, the key press `A` will be used
only as the input and nothing else.

With this, we use both the input and shortcut key.

- Isolate function to get keyboard key codes.

As explained on [1]:

"Using `GetUnicodeKey()` is in general the right thing to do if you are
interested in the characters typed by the user, `GetKeyCode()` should
be only used for special keys (for which `GetUnicodeKey()` returns
`WXK_NONE`)."

We also allow special keys to be mapped, hence the requirement of using
both functions.

[1] https://docs.wxwidgets.org/3.1/classwx_key_event.html

- Allow use of unicode keys for input and shortcut.

Use format `KeyCode:Modifier` for saving/loading unicode keys.

`WxWidgets=3.{0,1}` does not create an accelerator from strings with
unicode keys such as `ç` (`FromString` function). It fails with an
assertion error and stops execution. At the same time, we use the keys'
strings that are known for WxWidgets, such as `A`, `CTRL+O`,
`PAGEUP` etc.

Use both `EVT_KEY_DOWN` and `EVT_CHAR`.

`EVT_CHAR` is better than `EVT_KEY_DOWN` here because it is where the
raw key events will have been cooked using whatever recipes are in
effect from the os, locale, international keyboard settings, etc.

- Enable SDL joysticks input as key shortcuts.

Start/Stop polling joysticks on Unload/load game.

Our main loop already polls the joystick, we don't need the timer
while a game is running.

- Create function `str_split_with_sep` and use it.

For when we parse strings that may include the sep string, such as
game input and key shortcuts.
2020-06-18 20:47:47 -03:00
Edênis Freindorfer Azevedo 6b257d52f2
Avoid override of variable `throttle` for turbo.
It is not needed to set `throttle` on neither case. There is actually a
bug when using turbo/speedup and closing the emulator. The test case
is the following:

https://github.com/visualboyadvance-m/visualboyadvance-m/issues/627

On Windows:

1. use opengl;
2. load GBA game;
3. set throttle to `100%`;
4. set turbo throttle to `200%`;
5. enable turbo on menu;
6. save game;
7. close emulator && open emulator;
8. load GBA game;

==>

throttle is `200%`.

This is definitely not expected.
2020-06-17 13:23:14 -03:00
Rafael Kitover 1347026d40 Turbo config refactor followup.
In the Turbo config dialog, remove the selection list for entering the
value and leave only the spin control. Allow values above 600%, up to
4000%.

Reintroduce the speedup_frame_skip config variable, defaulting to 9, use
it for turbo selection values > 600%, with speedup_throttle == 0.

The rationale for this is that on average modern hardware, throttle
values above 500% or 600% will not be effective.

The default is now shown as 1000%, which is:

frame_skip == 9 && speedup == 1,

where:

speedup == 1 is equivalent to throttle == 0,

as was the case before the turbo config changes.

Values above 600% are automatically rounded up or down to the nearest
100%, on entry and on click of the up/down arrows of the spin control.

The frame skip checkbox is cleared and disabled for the "Unlimited"
setting (throttle == 0), and set and disabled for values > 600%, to
reflect the mechanism to the user.

When the value again enters the modifiable range in the spin control,
the previous value of the checkbox is restored.

Misc:

- Turn off translation of percentage values in the xrc.

- Remove the size element for the throttle selection list in the general
  config dialog xrc, it breaks the layout on GTK3.

- Add a note about passing wxWidgets_CONFIG_EXECUTABLE to cmake to
  select wxWidgets version to README.md.

Hopefully this will reduce confusion and present a nicer UI.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2020-05-15 02:01:57 +00:00
Rafael Kitover 045e95ab4e GB: Support 4MiB MBC30 ROM bank select.
MBC30 is a variant of MBC3 with a 4MiB ROM size and a larger RAM size.

https://gekkio.fi/files/gb-docs/gbctr.pdf

Allow addressing 4MiB of the ROM in MBC3 ROM bank select if the ROM size
is 4MiB.

Fix provided by roytam1.

- Fix #652.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2020-04-27 18:32:12 +00:00
Edênis Freindorfer Azevedo 0b14e9f885
[WINDOWS] Add function to open unicode files. (#644)
We have some issues when trying to open files on Windows that contains
characters not included in the current codepage. Using `fopen` fails
when that happens.

One example is using the `pt_BR` codepage and then using a name with
japanese chars for the battery file.

The games and BIOS work since they use `blargg_open`. It converts a
`const char *` to `const wchat_t *` and uses `_wfopen` for windows.
(doing a multibyte to widechar conversion)

Since we want to avoid doing many code changes on our cores, we need
some `util*` functions for the matter.

Replace `mb_fn_str` by UTF-8 strings.

Replace all occurrences of `fopen` for `utilOpenFile` on GBA core.

Replace all occurrences of `fopen` for `utilOpenFile` on GBA e-reader.

Adjust e-readers calls on wx frontend.

Replace all occurrences of `fopen` for `utilOpenFile` on Patcher files.

Always apply UTF-8 when dealing with path strings.

On our wx frontend we should always send UTF-8 `char *` to our cores
functions. This way we can have consistency when dealing with them for
each platform.

On Windows, we will convert all multibyte to wide chars and use proper
functions for I/O operation.

Create function to deal with unicode calls of `gzopen`.

We use `gzopen_w` (`zlib>=1.27`).

Replace all occurrences of `fopen` for `utilOpenFile` on Config Manager.

Replace all occurrences of `fopen` for `utilOpenFile` on Cheat files.

Use proper functions for unicode on GB core.

Use function instead of macro for `UTF8()`.

Use `nullptr` instead of `NULL`.

Print wide char strings on status bar.
2020-04-21 10:24:28 -03:00
Rafael Kitover 8e3978b314 Speedup/Turbo/Throttle fixes.
Fix throttle=0 (unlimited speed) settings for both the Speedup/Turbo
config panel and the general throttle setting and make 100 the default.

Replace the speedup frame skip option with a "Frame skip" checkbox,
which enables skipping the appropriate number of frames if vsync or very
low system performance is in effect. The systemFrameSkip (under video
config) is added to this value.

With speedup_throttle=100, the old speedup behavior is used with 9
frames skipped.

With speedup_throttle == 0 && speedup_throttle_frame_skip, skip 9
frames at full speed, which is exactly the same as the old behavior,
since throttle == 0 is equivalent to speedup == true.

Hopefully these changes will make the turbo config dialog more useful
for users, by default frame skipping to work around vsync will be
enabled, and users can uncheck the "Frame skip" checkbox for a smoother
experience.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2020-04-10 10:19:03 +00:00
Edênis Freindorfer Azevedo cd029ae696 Fix video recording with frame skip enabled.
When we skip frames, we just don't draw them on our frontend. The
function `systemDrawScreen` also send the video frames to be recorded,
but only when called from the core.

Our solution creates a auxiliary `systemSendScreen` that only adds the
frame to the recording. It is called when the core decides to skip a
frame. This way we can get the video frame for recording, just like
audio ones are always sent.
2020-03-18 00:48:43 +00:00
negativeExponent fd319d2184
GB: Check header for a valid ROM file.
Check some magic numbers in the ROM header to detect Game Genie and Game
Shark ROMs, and check for the Nintendo logo in the header in normal
ROMs.
2020-03-07 11:43:00 +00:00
Rafael Kitover 51a4f74b94
Merge remote-tracking branch 'vbam-libretro/master' 2019-08-15 18:42:08 +00:00
Edênis Freindorfer Azevedo f5b19475c9 [IDEA] Fix recording when using `speedup/turbo`.
We do not allow to skip frames while recording. The resulting length
will be extended compared to using turbo/speedup modes, because the
recording will be normal time (as in running without turbo/speedup).
2019-08-14 08:27:51 -01:00
retro-wertz 82e723a528 MBC3: Update mapper to check if RTC is present before running RTC functions 2019-08-10 19:01:10 +08:00
retro-wertz 03184dd513 libretro: Use GB RTC data when available
- Save GB RTC data using retro_get_memory/size and only init using localtime when its unavailable (check is done in retro_run)
2019-08-10 18:24:32 +08:00
retro-wertz d9f8396c67 Cleanup 2019-08-06 08:58:04 +08:00
retro-wertz a727e22265 GB: Rename this variable to isolate from a global variable of the same name
- this is a temporary variable and should only affect on this section, and not the global one.
2019-07-27 19:35:58 +08:00
retro-wertz 1532f555fe GB: Reduce input lag by 1 frame, video and audio timing updates...
Similar update to GBA which does the following:
- reduces input lag by 1 frame by reading user input at beginning of cpu loop
- audio and video timing update, which sends audio and video at every frame possible
- add missing sound state variable, soundTicks for gb and gba
2019-07-23 00:40:28 +08:00
retro-wertz bd5ba43122 Cleanup: Remove previous core option struct and unused variables etc 2019-07-18 19:34:20 +08:00
retro-wertz 6dcf016d20 GB: Allow support for colorizer patched games
- a new core option is provided since enabling this support
means allowing invalid access to vram and palette
- works in GBC/GBA hardware mode only
2019-07-18 10:41:59 +08:00
retro-wertz 85bd86cf5f GB: Send LCD interrupt only if there is no INT 48h signal
- Fixes Speedy Gonzales status bar in GB emulated hardware type.
2019-07-18 08:31:33 +08:00
Edênis Freindorfer Azevedo 331d9d331c Fix compilation warnings for MacOS build. 2019-04-04 18:01:05 -01:00
Edênis Freindorfer Azevedo 5540790ff1
fix some compilation warnings
Signed-off-by: Rafael Kitover <rkitover@gmail.com>
Merged #396
2019-04-03 17:32:25 +00:00
Rafael Kitover 98cb298efc
GB: fix 32/64 bit save/state incompatibility
The MBC3 and TAMA5 battery formats save the RTC data including a
`time_t` field which is the last field.

Since `time_t` is 32 bits for 32 bit builds and 64 bits for 64 bit
builds, pad it in the two battery structs with a `uint64_t` and detect
the 4 byte shorter saves made by older 32 bit builds.

Also remove some pointless code in save state reading that also uses
`sizeof(time_t)`.

Add two new constants for RTC data size in gbMemory.h and use them.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-02-23 13:40:25 -08:00
Rafael Kitover eb6dfb4bfa
fix libretro build broken in 16dd5d40 #339
Conditionally compile out the code for the feature implemented in
16dd5d40 (which is the throttle and frame skip configuration for the
speedup button) for libretro, and use the old behavior of skipping 9
frames.

Affects GBA.cpp and GB.cpp .

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-02-03 15:28:26 -08:00
Rafael Kitover 16dd5d4068
make speedup/turbo configurable + misc #339
Add Speedup / Turbo configuration panel which allows setting the
throttle or number of frames to skip for when the speed key is pressed
or turbo is enabled (which just presses the speed key.)

Throttle and frame-skip are mutually exclusive, throttle must be 0 (no
throttle) when number of frames to skip is non-zero. The dialog controls
handle this.

This is implemented in the core in GBA.cpp, GB.cpp and ConfigManager.

Two new options are added both in ConfigManager and in the wx options,
speedup_throttle and speedup_frame_skip, the defaults are:

```
speedup_throttle   = 0 (no throttle)
speedup_frame_skip = 9
```

this was the original behavior.

Add support for unsigned ints to wx/opts.cpp for these and for throttle,
this requires a new validator wxUIntValidator to use them in spin
controls.

Clean up appearance of the throttle spin control in the General dialog.

Maximum throttle and speedup_throttle is 600, values much over 500 will
not behave differently from 0 on modern hardware.

Maximum frame skip is 30 at the moment.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
2019-02-02 18:43:55 -08:00
retro-wertz ba678f4f2e GB: Make gbTimerOn an INT type instead of BOOL 2019-01-31 16:35:36 -08:00
retro-wertz 43647d3234 GB: Prevent gbSpritesTicks from going out-of-bounds 2019-01-31 16:35:36 -08:00
retro-wertz f2b3496298 GB: Add missing battery save for MMM01 cart 2019-01-29 08:28:17 -08:00
retro-wertz 3b87576e41 GB: Fix rumble support (MBC5)
- Fix missing call to rumble function on MBC5
- fix rumble flag gets disabled causing rumble not to work at all.
2019-01-21 05:28:27 -08:00
retro-wertz 59f76d05b8 libretro: Use gbWram[] for $C000 in CGB mode
This uses full size of gbWram[] so we have a continouos memory block
for RAM addresses $C000 and $D000 in CGB mode. This helps with
retroachievements.
2019-01-14 09:42:53 -08:00
retro-wertz ddea50d3c8 GB: Cleanup sound registers
Seems to be left-overs from switching to blargg
2018-07-26 14:39:06 +08:00
retro-wertz faf01db2cf GB: Backport STAT register behavior
http://www.devrs.com/gb/files/faqs.html#GBBugs
2018-07-26 13:45:06 +08:00
retrowertz d9e0d0f88d GB: Remove references to gbReadOpcode
Merged with gbReadMemory since this basically is just a duplicate
2018-07-26 00:24:06 +08:00
retro-wertz 76ad84fd28 Opps, accidentally broke borders in standalone 2018-07-17 02:29:03 +08:00
retro-wertz bf447bf89a Libretro: Add GB/GBC core
Gb,gbc and sgb enhanced version of roms and savestates working. Bios loading for gb/gbc works too. No save ram / battery handling yet.

Fix offset and pitch issues with vba rendering and when borders are enabled.
2018-07-17 01:55:19 +08:00
retro-wertz fc42f88bd7 GB: Fix SIO related issue 2018-07-06 04:23:58 -07:00
retro-wertz 27aeb6dc67 Re-add Types.h, remove some more #ifdef 2018-06-08 20:14:45 +08:00
Mystro256 e9e2100f6d Error case in gbCheatReadGSCodeFile
Silence GCC warning
2017-02-12 04:26:21 -08:00
Mystro256 0bcf4a5223 Clean up various used variables 2016-12-30 11:16:00 -05:00
Rafael Kitover 01200fadbd Mac OS X 10.7 (Lion) build and runtime support
Make a custom cstdint.h header file that includes <tr1/cstdint> if
<cstdint> is not available, because the clang 3.x used on Lion does not
have it. Change all references to <cstdint> to use it instead.

Add missing OpenGL header for older OS X in sdl/SDL.cpp .

When calling HiDPI methods, use respondsToSelector: to check if the
methods are available first.

Fix the bundling/linking script to support multiple copies of the same
dylib with different versions. Necessary to include both the Lion system
libpng and the brew libpng. Including the system libpng is necessary
because it is removed in later versions of OS X.
2016-11-03 10:49:13 -07:00
Christopher Snowhill 36d84cfa2b Update gbCheats.cpp
Bounds checking is important.
2016-11-02 21:28:58 -07:00
Dorian Wouters 31391e090c
Kill common/Types.h, replace its old typedefs w/ standard types
Fix includes in files using standard int types
Fix wxWidgets UI includes
Silence some unused variable warnings in GBA-arm.cpp macros
2016-07-29 11:07:11 +02:00
Dorian Wouters 37f0e75c45
Fix standard int types, prefix gb {C,H,N,Z}_FLAG with GB_ 2016-07-29 09:45:38 +02:00
Zach Bacon 1944613131
gb folder is done, next up gba, once this is all up I'm going to look at enhancing the cores 2016-07-09 11:41:31 -04:00
Zach Bacon 1f37311a4a
more and more formating issues, I keep doing it in parts for my own reasons 2016-07-09 10:13:54 -04:00
Zach Bacon 48086ba62f
some more formating things etc 2016-07-09 09:53:13 -04:00
Zach Bacon a49edee427
More changes being made, you'll know when it's over. 2016-07-09 09:24:19 -04:00
Zach Bacon 5bf44d19be
updated standards to webkit standard 2016-07-08 19:59:29 -04:00
skidau 4a5ae01e19 Removed the padding from the cheat file when it is saved in CLT format. 2015-05-22 07:05:06 +00:00
skidau 2d5ecd88db Fixed another cheat limit check in the GB code. 2015-05-22 05:52:50 +00:00
skidau fec1c7b770 Fixed the cheat list size check for GB games. 2015-05-22 05:34:05 +00:00