Commit Graph

114 Commits

Author SHA1 Message Date
lif 6928b667ae fix most(?) rendering issues i have seen so far in swizzled mode. tiles at screen edges are still being drawn backwards 2024-01-03 03:04:44 -08:00
David Guillen Fandos 7127ec6408 Improve DMA and BIOS reads 2023-10-01 23:51:53 +02:00
David Guillen Fandos 9632dedf90 Implement EEPROM save override.
Disabled SRAM/FLASH when EEPROM saves have been attempted. Allows to
override games via gba_over too
2023-09-23 18:13:18 +02:00
David Guillen Fandos ae048beb9c Rework RTC and break it into GPIO, with RTC and Rumble (GPIO3)
This adds Rumble support for GPIO3-enabled games (Drill Dozer).
2023-09-20 22:46:06 +02:00
David Guillen Fandos f0bacff91a Remove gpsp savegame method in favour of libretro's one
This generates 128KB save files (instead of variable sized ones) to
prevent truncated savegames under some circumstances. Most other
emulators have no trouble loading them (and the unused data is simply
ignored).

Remove also config txt file that's now unused.
2023-09-19 20:36:56 +02:00
David Guillen Fandos bcd062ea1b Remove config.txt parsing and reading 2023-09-19 20:36:56 +02:00
David Guillen Fandos 0501be5d78 Simplify gba over a bit 2023-09-19 20:36:56 +02:00
David Guillen Fandos 6e59ca6795 Improve EEPROM reads/writes and ROM reads
Unmapped areas read a value closer to what hardware produces.
Ensure that 32MB games can do EEPROM reads.
2023-09-14 00:22:55 +02:00
David Guillen Fandos c0d8ffaa38 Adding DMA transfer "Sleep" mode
This accounts for DMA stealing cycles from the CPU whenever the CPU
triggers a DMA (does not affect H/V blank or sound DMAs).
Works by moving the CPU to a PAUSED state where the cycles are accounted
for, reusing a similar mechanism for HALT/STOP.

Fixes a couple of games, notably GTA that has a DMA/IRQ race condition
(likely a bug really) if cycles are grossly miscalculated.
2023-09-08 19:44:13 +02:00
David Guillen Fandos 2352adcc50 Improve savestate loading to avoid corrupting the current state
It should not happen since the magic value and version would normally
discard incompatible savestates, however it's preferrable to check
before loading the state (it's just some minor sanity check).
2023-09-07 20:26:44 +02:00
David Guillen Fandos 1d972ec7ff Improve GBC sound by fixing its deferred rendering
This fixes many games that use the PSG, particuarly the noise generator.
It is very noticeable in explosion/collision sounds with Sonic and Kirby
games, where the noise channel is rapidly tweaked.
2023-07-14 00:37:33 +02:00
David Guillen Fandos 7f07da9ade Make sound control deterministic by having proper reset 2023-06-12 20:24:18 +02:00
David Guillen Fandos 84c347edad [interp] Improve interpreter timings and honor WAITCNT
This fixes a few games and makes the interpreter faster (since it
doesn't run an overclocked CPU anymore).
2023-06-07 19:40:27 +02:00
David Guillen Fandos 64b19d1301 Improve and simplify 16 bit I/O writes too 2023-04-21 22:21:01 +02:00
David Guillen Fandos a53399af58 Simplify I/O byte writes
Can easily be mapped to 16 bit writes.
2023-04-21 21:44:34 +02:00
David Guillen Fandos 8c6ff8d358 Simplify I/O writes further
Improve FIFO writes, make them a bit faster
2023-04-20 00:52:30 +02:00
David Guillen Fandos 6bf53cf3db Minor I/O write improvements 2023-04-19 23:22:18 +02:00
David Guillen Fandos 413157dedd Fix timer bug regression, introduced at 0bc2a11
Thanks andy for finding the fix!
2023-04-19 20:00:28 +02:00
David Guillen Fandos 3f976c9557 Refine BIOS and unmapped memory accesses
Turns out there's a couple of inaccuracies that do affect a couple of
games. Most of them are buggy games but emulating these accesses
correctly helps jumping over some bugs.
2023-04-15 11:44:48 +02:00
David Guillen Fandos 08372aae64 Add missing DMA side effects on I/O writes 2023-04-15 11:44:02 +02:00
David Guillen Fandos 11d87b89df Rewrite I/O side effects write and IRQ triggers
This rewrites the way that CPU alerts work, making them a bitmap (since
multiple alerts can happen simultaneously, like SMC and IRQ). This
doesn't really fix many games but improves accuracy overall and improves
performance on some I/O writes (the ones without side effects).
The IRQ raising is now decoupled and explicitely called via a new
function (check_and_raise_interrupts) to avoid issues such as invalid
CPSR values (doesn't seem to bother most games!). There's more side
effects missing, so this just lays the ground for more fixes.
2023-04-14 01:41:55 +02:00
David Guillen Fandos 2bbd77054e Fix pending interrupts not raised on IME/IE writes
Whenever an interrupt is pending and interrupts are disabled (via
IME/IE), an IE/IME write that re-enables IRQs will fail to raise an IRQ.
This makes some games hang. Most games seem to use CPSR.IRQ to enable
and disable interruts, so they are not affected. However some others use
IME/IE (or all of them), causing these deadlocks and some race
conditions.

This fixes a bunch of games that did not crash but would "hang" in some
interesting ways.
2023-04-10 12:58:03 +02:00
David Guillen Fandos f9d7f51ef1 Minor cleanup and fix in DMA code. 2023-04-09 14:16:47 +02:00
David Guillen Fandos 541adc9e1c Fix ROM swapping capabilities
This fixes ROM swapping for x86/64, arm32 and arm64. On top of that it
improves speed by removing unnecessary slow paths on small ROMs for
arm32 and mips. If the ROM can fit in RAM, it will emit more efficient
code that assumes the ROM is fully loaded.

For low-memory Linux platforms it would be better to use some mmap'ed
ROM, that way the OS would transparently handle page swapping, which is
perhaps faster. Will investigate and follow up on this in a separate
commit.
2023-03-03 21:05:12 +01:00
David Guillen Fandos b552d5eb7e Improve open bus reads on ARM/MIPS 2023-01-05 21:29:20 +01:00
David Guillen Fandos 4eac8e30a8 Add WAITCNT but do nothing for now 2022-01-05 21:43:03 +01:00
David Guillen Fandos ef399b9315 [mips] Remove IWRAM stack optimization hack
Converted the hack into another... hopefully better hack.
Check for IW/EWRAM addr bit and handle accesses to EWRAM by correcting
the base addr and the mirroring range.
Assumes that iwram and ewram buffers are at a distance multiple of 64KB
for speed (so that lw/sw offsets can be shared).

This fixes a variety of games that should have been present in
game_config.txt such as Ninja Cop, Star Wars JPB, Medal of Honor,
Spongebob, etc. Some of them were just missing regional versions of the
cart. It also fixes newer games and homebrew such as GoodBoy Galaxy.
2021-12-30 23:39:09 +01:00
David Guillen Fandos bc8c07272b Add DMA cycle accounting for H/V blank and sound DMA
This is just responsible for a few cycles every frame (could be around 1
and 2% depending on the game usage) but makes emulation a bit more
accurate and potentially faster.
2021-12-21 12:02:48 +01:00
David Guillen Fandos 7b181cb6ff Fix PC calculation for open bus loads
It was pretty much broken in all platforms, just "ok" enough for it to
work on some games though.
2021-12-20 19:31:33 +01:00
David Guillen Fandos 44ccdb3d25 Minor mem handler fixes (pretty much a no-op) 2021-11-03 21:33:29 +00:00
David Guillen Fandos 6a59c71d55 Get rid of enums (to u32) for better compat
Serialization code needs u32 to ensure compatiblity. In platforms with
short enums this goes very wrong. Fixes issues on 3DS platform.
2021-10-15 21:28:40 +02:00
David Guillen Fandos 6c195cdcaa Add libretro-common and VFS functions for read/write
Remove small unused stuff while at it.
2021-09-30 18:31:11 +02:00
David Guillen Fandos ed89923fda Minor mem fixes around mirrors and u8/u16 accesses
Improve the open bus access a bit too.
2021-09-17 21:30:33 +02:00
David Guillen Fandos 1feab54699 Rewrite DMA handlers
Make it cleaner and clearer, also fix an out of bounds issue in high
memory regions.
2021-08-27 21:38:38 +02:00
David Guillen Fandos 8207775256 Fix out of bounds read bug on open bus read
This bug doesn't affect many games but makes sanitizers unhappy.
Also fix some minor FIFO clear bug
2021-08-24 19:55:37 +02:00
David Guillen Fandos 7068cbc95b New savestate implementation
This uses BSON as savestate format, to allow external tools to parse it
(so that we can add proper test of the states). The BSON is not 100%
correct according to spec (no ordered keys) but can be parsed by most
libraries.

This fixes also a bug in the savestate palette color recalculation that
was wrongly overwritting the original palette (which could cause some
problems on some games).

Also fixes some potential issues by serializing some more stuff and
cleans up unused stuff.

Testing shows that states look good and there's only minor differences
in audio ticks, related to buffer sizes (since buffer flushes are
de-synced from video frames due to different frequency).
2021-08-24 17:15:27 +02:00
David Guillen Fandos 1e976fb312 Remove unused stuff and fix const variables
Trying to figure out what needs to be part of a savestate :)
2021-08-24 10:57:30 +02:00
David Guillen Fandos b61bec202f Simplify EEPROM handling and remove some mem aliasing warnings.
This fixes issue #29
2021-08-22 00:23:53 +02:00
David Guillen Fandos fb830447ba Simplify DMA handling 2021-08-21 19:41:52 +02:00
David Guillen Fandos a3377c2ac1 Minor DMA cleanup 2021-08-21 18:10:12 +02:00
David Guillen Fandos 86b365f065 Remove unused variable 2021-08-21 16:59:07 +02:00
David Guillen Fandos 77803adcac Remove more unused stuff 2021-08-20 17:39:35 +02:00
David Guillen Fandos 7f7d066854 Remove video vars serialization
This is not needed at all, since the variables are not updated between
reload and end-of-frame (where we take our savestates). Added a reload
call during gba_load_state() to initialize it from the I/O regs.
2021-08-15 23:30:57 +02:00
David Guillen Fandos ce14e2585b Fix and reenable Android arm 32 bit builds
Removed the last bits of text relocations by moving all relevant RAMs to
the stub reachable area. This should be as fast or even faster than
previous code.
2021-07-31 17:45:46 +02:00
David Guillen Fandos da5ec48982 Rework I/O mappings
Mirrors exist at 64KB boundary (not 0x400) but works nevertheless
2021-07-30 00:18:02 +02:00
David Guillen Fandos ab7d9bb161 Move membuffers close to dynarec area to fix x86 relocs
This essentially makes it easier to get a relocation-free text area for
x86 so that Android loaders are happy.
2021-07-28 19:12:43 +02:00
David Guillen Fandos dec6f50d89 Fix DMA VRAM mirror overflow and small 1-off error
Seems that this could make VRAM overflow big time and overwrite IWRAM
most of the time (since it lives after that buffer). This causes a
variety of errors, some of them hidden if IWRAM not used.
Most games do not use VRAM mirror so it's not a big deal, but some do
have a off-by-one errors that trigger this.
2021-07-28 01:26:19 +02:00
David Guillen Fandos 5fe5121c81 Remove pointer from sound struct, use index instead
This makes serialization possible, previously it was broken.
2021-07-27 21:45:15 +02:00
David Guillen Fandos ba51aa6a1c Fix pointer serialization in the memory system
This makes savestates potentially unstable under certain conditions (and
definitely not portable)
2021-07-27 21:18:15 +02:00
David Guillen Fandos 84cd7b2934 Rewrite ROM buffer allocation
This improves the existing on-demand ROM paging and also breaks down ROM
buffers into 1MB blocks for platforms with memory fragmentation issues.

Fixed some potential RTC reg issue in said platforms too.
Fixed page pinning on interpreter (would crash due to LRU evictions).
2021-07-14 01:20:30 +02:00