pcsx_rearmed.git
2 years agoMerge several fixes from PCSX Redux and adjust delay for SetLocPending. (#221)
gameblabla [Sat, 2 Oct 2021 17:51:48 +0000 (17:51 +0000)]
Merge several fixes from PCSX Redux and adjust delay for SetLocPending. (#221)

There's a game, PoPoLoCrois Monogatari II, that unfortunately locks up
during the intro screen.
I should have known that code was wrong as Mednafen did not have anything
like that in their code either, hence the confusion.

Their fix however still don't include the Driver fix so the game would still
crash if we don't have the "+ Seektime".
To be honest, i'm not sure why the PCSX Reloaded team did it this way...

I noticed that the fastforward and fastbackward code was pretty much unused.
Looked at Mednafen and all they do is just adjust the cursector
and make sure that fastword & backword trigger the AUTO_REPORT code
so i did the latter.

Co-authored-by: Nicolas Noble <nicolasnoble@users.noreply.github.com>
2 years agoProper CDDA fix for Fantastic Pinball Kyuutenkai (and remove CDDA playthread as it...
gameblabla [Sat, 2 Oct 2021 15:51:24 +0000 (15:51 +0000)]
Proper CDDA fix for Fantastic Pinball Kyuutenkai (and remove CDDA playthread as it causes issues) (#215)

Part of the CDROM related changes were taken from PCSX Reloaded.
https://github.com/gameblabla/pcsxr/blob/6484236cb0281e8040ff6c8078c87899a3407534/pcsxr/libpcsxcore/cdrom.c

2 years agoOne more on odd lines for PAL HSYNC (#224)
gameblabla [Sat, 2 Oct 2021 14:53:16 +0000 (14:53 +0000)]
One more on odd lines for PAL HSYNC (#224)

As done by Duckstation
https://github.com/stenzek/duckstation/blob/bbcf1c67d1aefd5de9cdc9c158f92bc7aaecaa63/src/core/gpu.h#L56

2 years agoFix for Armored Core misdetecting a Link cable being detected (#223)
gameblabla [Sat, 2 Oct 2021 14:39:44 +0000 (14:39 +0000)]
Fix for Armored Core misdetecting a Link cable being detected (#223)

For some reason, the game detects that a link cable is plugged in
and disables the local multiplayer as a result.

Thanks @sony for fixing the issue in their PS Classic branch, a
simplier fix is done here instead.

Co-authored-by: Sony
2 years agoIcache emulation from PCSX Redux + Senquack changes from PCSX4ALL (#198)
gameblabla [Sat, 2 Oct 2021 13:41:42 +0000 (13:41 +0000)]
Icache emulation from PCSX Redux + Senquack changes from PCSX4ALL (#198)

* Merge Icache emulation from PCSX Redux

See (Redux) :
https://github.com/grumpycoders/pcsx-redux/commit/1923ce54ef585beba3a948d50f8c30161102312c

See original icache implementation (mirror of PCSX Reloaded):
https://github.com/gameblabla/pcsxr

Without icache emulation, F1 2001 will greatly misbehave :
if you accelerate, the car will go around like crazy.
With icache emulation, it works as intended.

Our code is slightly different from theirs as i found out that
having the icache arrays in psxregs would cause crashes so instead
what i'm doing is to taking them out of there and only allocating them
on the heap (due to their great size).

Co-authored-by: Nicolas Noble <nicolasnoble@users.noreply.github.com>
* Fix issues with BREAK and some interpreter commands. Fixes F1 2000.

Note that the game is very sensible to timing issues when it comes to the CDROM
controller.
That will be for a separate commit however.

* Culling off cache bits from the hardware addresses.

Based on those PRs from PCSX-Redux :
https://github.com/grumpycoders/pcsx-redux/commit/0cd940100e96b95eea87dbb47381596f7f8dbe72#diff-009cbf66734b5de152bf170b80f8c7e03bebaa08a191f6ad7a06c7420f24b69c
https://github.com/grumpycoders/pcsx-redux/commit/03d2ba3f278868cdd7ee3a44edef7ee87e6a1589#diff-009cbf66734b5de152bf170b80f8c7e03bebaa08a191f6ad7a06c7420f24b69c

Co-authored-by: Nicolas Noble <nicolasnoble@users.noreply.github.com>
* Slightly better "open bus" behavior

OG commit is here from PCSX Redux :
https://github.com/grumpycoders/pcsx-redux/commit/128ba97f9680ab8dcd2f840f72ae998507325730#diff-8552772bc73559e3448880c9b8126252b49b95a89cfac254148d27127cbec719

Co-authored-by: Nicolas Noble <nicolasnoble@users.noreply.github.com>
* [Interpreter] Link even if branch is not taken in BGEZAL/BLTZAL

Source :
grumpycoders/pcsx-redux@c1a0569

Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com>
Co-authored-by: Nicolas Noble <nicolasnoble@users.noreply.github.com>
2 years agoFix detection of some CDs such as Wild Arms USA detected as a PAL game. (#222)
gameblabla [Sat, 2 Oct 2021 13:23:27 +0000 (13:23 +0000)]
Fix detection of some CDs such as Wild Arms USA detected as a PAL game. (#222)

I was able to confirm it fixed the issue for Wild Arms.

Co-authored-by: bardeci <37640967+bardeci@users.noreply.github.com>
2 years agopsxmem: Writes to PIO Expansion area have no effect. (#220)
gameblabla [Mon, 27 Sep 2021 19:09:52 +0000 (19:09 +0000)]
psxmem: Writes to PIO Expansion area have no effect. (#220)

This is related to the Tetris with Card Captor fix a while back.
However, i forgot to merge this one as well related to writes,
even though it was not really necessary to fix that particular game.

Co-authored-by: senquack <dansilsby@gmail.com>
2 years agoARM build fixes. (Should fix building on ARM/GCC10) (#210)
gameblabla [Thu, 9 Sep 2021 20:20:54 +0000 (20:20 +0000)]
ARM build fixes. (Should fix building on ARM/GCC10) (#210)

This fixes building on GCC10 and ARM.
Note that in my previous HLE patch, i forgot to export psxNULL
so it was failling to compile it... Oops.

Co-authored-by: negativeExponent <negativeExponent@users.noreply.github.com>
2 years agoImplement fix from Mednafen for Fantastic Pinball Kyuutenkai. (#206)
gameblabla [Mon, 30 Aug 2021 22:34:02 +0000 (22:34 +0000)]
Implement fix from Mednafen for Fantastic Pinball Kyuutenkai. (#206)

This is taken from the way Mednafen implemented it.
https://github.com/libretro-mirrors/mednafen-git/blob/563b72e377fa8284559df4df0271108d4935c9f1/src/psx/cdc.cpp#L941

This properly fixes the freeze issue in Fantastic Pinball Kyuutenkai.

2 years agoFix regression with CdlPause (#209)
gameblabla [Mon, 30 Aug 2021 21:08:08 +0000 (21:08 +0000)]
Fix regression with CdlPause (#209)

2 years agoImprove CdlPause command based on Mednafen's implementation (#207)
gameblabla [Fri, 27 Aug 2021 22:05:02 +0000 (22:05 +0000)]
Improve CdlPause command based on Mednafen's implementation (#207)

Reference :
https://github.com/libretro-mirrors/mednafen-git/blob/master/src/psx/cdc.cpp#L1969

This fixed an issue with Worms Pinball booting to the language screen.
Previously, it would sometimes boot to it but not reliably
and the screen would always not appear or be black.

Now, the emulator doesn't crash anymore and the language screen
can be seen (although it is a glitchy mess).

2 years agoCDROM: Rename Reset+Init commands approperly, fix "This is Football 2" lockup (#205)
gameblabla [Thu, 26 Aug 2021 18:05:23 +0000 (18:05 +0000)]
CDROM: Rename Reset+Init commands approperly, fix "This is Football 2" lockup (#205)

Upon the reset command being issued, we need to set the Mode to 0x20
(as it was confirmed in Mednafen) and also disable the muting.

We also change the seektime for the reset command appropriately.
Please see Mednafen's implementation as reference :
https://github.com/libretro-mirrors/mednafen-git/blob/1899500078169e787f86eb5302a3f35abdaa8764/src/psx/cdc.cpp#L2007

This fixes the black screen issue in "This is Football 2".
This also fixes the black screen issue in Pooh's Party.

2 years agoFix CdlGetTD according to Mednafen's implementation. (#204)
gameblabla [Thu, 26 Aug 2021 18:04:19 +0000 (18:04 +0000)]
Fix CdlGetTD according to Mednafen's implementation. (#204)

2 years agoCdlGetmode is GetParam, fix it according to Mednafen's implementation (#203)
gameblabla [Wed, 25 Aug 2021 21:56:52 +0000 (21:56 +0000)]
CdlGetmode is GetParam, fix it according to Mednafen's implementation (#203)

The result size for GetParam (previously Getmode) should be only 5 and done this way.

2 years agoWe shouldn't throw an error for GetQ. (#202)
gameblabla [Wed, 25 Aug 2021 21:53:08 +0000 (21:53 +0000)]
We shouldn't throw an error for GetQ. (#202)

I doubt this is used by any games but who knows.

See Mednafen for reference :
https://github.com/libretro-mirrors/mednafen-git/blob/1899500078169e787f86eb5302a3f35abdaa8764/src/psx/cdc.cpp#L2527

2 years agoImprove SetLoc CDROM command from Duckstation (#201)
gameblabla [Wed, 25 Aug 2021 21:37:51 +0000 (21:37 +0000)]
Improve SetLoc CDROM command from Duckstation (#201)

See Duckstation's CDROM for reference :
https://github.com/stenzek/duckstation/blob/18241978ea056a81ff9847f0ad89658f886153ea/src/core/cdrom.cpp#L1087

This probably shouldn't make a difference but who knows.

2 years agoCdlSync should be NULL and return an error. (#199)
gameblabla [Wed, 25 Aug 2021 21:22:44 +0000 (21:22 +0000)]
CdlSync should be NULL and return an error. (#199)

This has been confirmed by both Mednafen and nocash's documentation.

2 years agoAlways look up verify_dirty literals from offsets by neonloop (#194)
gameblabla [Wed, 25 Aug 2021 20:55:22 +0000 (20:55 +0000)]
Always look up verify_dirty literals from offsets by neonloop (#194)

Literals are deduplicated, so there's no guarantee they will be stored
next to each other, even if they're written sequentially. verify_dirty
and get_bounds must use the offsets on each instruction, instead of
assuming values are stored sequentially.

Co-authored-by: neonloop <neonloop@pm.me>
2 years agopsxinterpreter: Merge DIV interpreter fix from libretro's fork (#193)
gameblabla [Sun, 22 Aug 2021 22:31:18 +0000 (22:31 +0000)]
psxinterpreter: Merge DIV interpreter fix from libretro's fork (#193)

Fix comes from here :
https://github.com/libretro/pcsx_rearmed/pull/530

Co-authored-by: Ember Cold <embercold@outlook.com>
2 years agoCDROM: Ignore sectors with channel number 255 (#195)
gameblabla [Sun, 22 Aug 2021 22:29:02 +0000 (22:29 +0000)]
CDROM: Ignore sectors with channel number 255 (#195)

This was inspired by the fix in Duckstation :
https://github.com/stenzek/duckstation/commit/0710e3b6d384526ed939f742f8f657623bb354bb

Some games have junk audio sectors with a channel number of 255.
If these are not skipped, then they will play wrong file.

This was tested on "Blue's Clues : Blue's Big Musical" and
it fixed the missing audio there.

Taxi 2 is also said to be affected by this.

2 years agomdec.cpp: Dare to set MDEC_BIAS to 10 (#186)
gameblabla [Sun, 22 Aug 2021 22:18:42 +0000 (22:18 +0000)]
mdec.cpp: Dare to set MDEC_BIAS to 10 (#186)

This fixes graphic artifacts during cinematics in :
- Vandal Hearts
- R-Types
- Galerians

Dmitrysmagin had a similar fix in PCSX4ALL but he set it to 6.
It turns out MDEC_BIAS set to 6 was still not enough for Galerians
to look properly so it was set to 10.
It seems so far that other games are unaffected.

Co-authored-by: Dmitry Smagin <exmortis@yandex.ru>
2 years agoFixes Diablo 1 SPU bug properly and remove Diablo hack. (#191)
gameblabla [Sun, 22 Aug 2021 21:50:09 +0000 (21:50 +0000)]
Fixes Diablo 1 SPU bug properly and remove Diablo hack. (#191)

(Mostly) inspired by the fixes done in PCSX Redux :
https://github.com/grumpycoders/pcsx-redux/blob/93653ba5281487d3bed57371d7b64c32dfc669f0/src/spu/registers.cc#L504

It seems that there was an attempt to initially implement it
in PCSX Reloaded (hence the bIgnoreLoop in freeze.c) but it was never
implemented properly.

Co-authored-by: Nicolas Noble <nicolasnoble@users.noreply.github.com>
2 years agoProperly protect the HLE instructions against corrupted memory. (#189)
gameblabla [Sun, 22 Aug 2021 21:39:05 +0000 (21:39 +0000)]
Properly protect the HLE instructions against corrupted memory. (#189)

Fix is from PCSX-redux :
https://github.com/grumpycoders/pcsx-redux/commit/99c9508f2a9dc1444b88f37eb100cdfb17862b52

This should hopefully fix HDHOSHY's experimental patch properly.

Co-authored-by: Nicolas Noble <nicolasnoble@users.noreply.github.com>
2 years agoRewrite GPU bios functions according to OpenBIOS. (#192)
gameblabla [Wed, 18 Aug 2021 21:15:09 +0000 (21:15 +0000)]
Rewrite GPU bios functions according to OpenBIOS. (#192)

See PCSX-Redux :
https://github.com/grumpycoders/pcsx-redux/blob/93653ba5281487d3bed57371d7b64c32dfc669f0/src/mips/openbios/gpu/gpu.c

2 years ago[SPU] Emulate SPUSTAT[5:0] as a mirror of SPUCNT[5:0] (#190)
gameblabla [Wed, 18 Aug 2021 20:58:45 +0000 (20:58 +0000)]
[SPU] Emulate SPUSTAT[5:0] as a mirror of SPUCNT[5:0] (#190)

Fix is from PCSX-Redux :
https://github.com/grumpycoders/pcsx-redux/commit/4e905d7953a26bffd52f486dc5b03c2a19075d01

I have tested the fix against Loonies 8192 (a PSn00bSDK made homebrew game) and it no longer
locks up during loading.

Co-authored-by: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com>
2 years agoCDRom timings changes (#184)
gameblabla [Wed, 18 Aug 2021 20:24:33 +0000 (20:24 +0000)]
CDRom timings changes (#184)

Upstreamed changes from PCSX Redux as seen here :
https://github.com/grumpycoders/pcsx-redux/commit/5730e04f0183f37038bc1d133cf9f9092425b90a

This apparently fixes Deus Fight in Xenogears.

Co-authored-by: Nicolas Noble <nicolasnoble@users.noreply.github.com>
2 years agoAdd internal database for problematic games. (#182)
gameblabla [Wed, 18 Aug 2021 20:22:43 +0000 (20:22 +0000)]
Add internal database for problematic games. (#182)

2 years agodeal with some more annoying warnings
notaz [Mon, 16 Aug 2021 22:09:20 +0000 (01:09 +0300)]
deal with some more annoying warnings

Especially main.c as it's regenerated after each commit.

2 years agoCHD support from libretro's fork. (#188)
gameblabla [Mon, 16 Aug 2021 21:37:34 +0000 (21:37 +0000)]
CHD support from libretro's fork. (#188)

We are implementing it as a sub-module for maintenance reasons.

Co-authored-by: aliaspider <aliaspider@gmail.com>
2 years agogte_divider: should include it's own header
notaz [Mon, 16 Aug 2021 21:26:01 +0000 (00:26 +0300)]
gte_divider: should include it's own header

Would have noticed the wrong divider type with this.

2 years agogte: Fix gteH division and sign extension (from PCSX4ALL) (#185)
gameblabla [Mon, 16 Aug 2021 21:18:58 +0000 (21:18 +0000)]
gte: Fix gteH division and sign extension (from PCSX4ALL) (#185)

gteH register is u16, not s16. DIVIDE macro/func assumed it was
s16 for some reason. Behavior now matches Mednafen.

Co-authored-by: senquack <dansilsby@gmail.com>
2 years agoFixed Linked List DMA end marker. (#183)
gameblabla [Mon, 16 Aug 2021 21:03:52 +0000 (21:03 +0000)]
Fixed Linked List DMA end marker. (#183)

Taken from PCSX Redux project.
https://github.com/grumpycoders/pcsx-redux/pull/396/commits/a6401da3a4e7b4860b0f7a7f679cf9a93e739caa

3 years agoFix crash on retrying mission in driver (#165)
ifcaro [Sat, 4 Jul 2020 13:26:16 +0000 (15:26 +0200)]
Fix crash on retrying mission in driver (#165)

Fix crash on retrying mission in driver

3 years agoMerge pull request #160 from J-O-N/fix-neon-cspace-upstream
notaz [Mon, 27 Apr 2020 17:37:45 +0000 (20:37 +0300)]
Merge pull request #160 from J-O-N/fix-neon-cspace-upstream

Fixed bug where MSB of a 15-bit BGR color could corrupt green value.

3 years agoFixed bug where MSB of a 15-bit BGR color could corrupt green value. Also added docum...
J-O-N [Sun, 26 Apr 2020 04:35:54 +0000 (00:35 -0400)]
Fixed bug where MSB of a 15-bit BGR color could corrupt green value. Also added documentation.

4 years agoMerge pull request #156 from pcercuei/fix-gte-divide
notaz [Sun, 16 Feb 2020 18:03:39 +0000 (20:03 +0200)]
Merge pull request #156 from pcercuei/fix-gte-divide

Replace existing gte_divider with MAME's version

4 years agoReplace existing gte_divider with MAME's version
Paul Cercueil [Wed, 12 Feb 2020 18:38:16 +0000 (15:38 -0300)]
Replace existing gte_divider with MAME's version

The original code did not have a license header, and as a result was
licensed under the GPLv2 which means that it was impossible to link it
with LGPL code.

The new code originates from MAME and is under a BSD-3-Clause license,
which is GPL-compatible, and also much cleaner.

Signed-off-by: Paul Cercueil <paul@crapouillou.net>
4 years agoadd some missing license headers
notaz [Tue, 11 Feb 2020 23:46:45 +0000 (01:46 +0200)]
add some missing license headers

4 years agogte_neon: fix compile under clang's assembler
notaz [Tue, 11 Feb 2020 23:19:43 +0000 (01:19 +0200)]
gte_neon: fix compile under clang's assembler

4 years agoLicense these files as MIT
twinaphex [Sat, 8 Feb 2020 20:40:17 +0000 (21:40 +0100)]
License these files as MIT

4 years agomenu: fix a buffer overflow
notaz [Sat, 8 Feb 2020 19:29:08 +0000 (21:29 +0200)]
menu: fix a buffer overflow

Reported by @wwhheerree, closes #152.

4 years agoMerge pull request #147 from senquack/cdrom_sstate_fix
notaz [Tue, 19 Nov 2019 22:24:11 +0000 (00:24 +0200)]
Merge pull request #147 from senquack/cdrom_sstate_fix

cdrom: add missing BCD->int convert in cdrFreeze()

4 years agocdrom: add missing BCD->int convert in cdrFreeze()
Daniel Silsby [Tue, 12 Nov 2019 23:48:44 +0000 (18:48 -0500)]
cdrom: add missing BCD->int convert in cdrFreeze()

For some Eboot .PBP game images, when loading a savestate, a zlib error
like 'uncompress failed with -5 for block 5383, sector 86132' would be
output to stdout/stderr. The savestate would still be playable, though.

Traced it down to cdrFreeze() failing to convert cdr.Prev from BCD->int
when calling ReadTrack(). Note that the odd 'cdr.Prev[0]++;' line seems
to be someone's hacky way of forcing ReadTrack() to avoid skipping what
it thinks is a duplicate sector read.

4 years agoMerge pull request #146 from senquack/gpulib_fix
notaz [Mon, 11 Nov 2019 18:50:44 +0000 (20:50 +0200)]
Merge pull request #146 from senquack/gpulib_fix

gpulib: fix out-of-bounds reads in do_cmd_buffer()

4 years agogpulib: fix out-of-bounds reads in do_cmd_buffer()
Daniel Silsby [Sat, 9 Nov 2019 01:30:04 +0000 (20:30 -0500)]
gpulib: fix out-of-bounds reads in do_cmd_buffer()

When gpu.cmd_buffer[] is filling up, and the last 1 or 2 words
in it are the beginning of a new vram read/write cmd, do_cmd_buffer()
would access out-of-bounds, reading garbage pos/size data.

Fixes corrupted gfx in this PS1 .exe test utility:
https://github.com/PeterLemon/PSX/tree/master/CPUTest/CPU/LOADSTORE/LW
(This and all similar tests on Peter's site).
Note that gfx access in this utility is done entirely through cmds given
through GPUwriteData(), i.e. direct CPU->GP0 stores, not DMA.

4 years agoMerge pull request #139 from retro-wertz/patch-3
notaz [Sat, 3 Aug 2019 13:22:14 +0000 (16:22 +0300)]
Merge pull request #139 from retro-wertz/patch-3

Fix corrupted memory card saves when using HLE

4 years agoFix corrupted memory card saves when using HLE
retro-wertz [Sat, 3 Aug 2019 13:04:35 +0000 (21:04 +0800)]
Fix corrupted memory card saves when using HLE

- This is fixed by adding the missing SaveMcd() to buwrite().

Tested on Wild Arms and Breath of Fire III

4 years agoMerge pull request #137 from gameblabla/hle
notaz [Wed, 24 Jul 2019 20:39:11 +0000 (23:39 +0300)]
Merge pull request #137 from gameblabla/hle

HLE BIOS improvements (based on nocash doc, pcsx4all, upstream pcsxr etc...)

4 years agopsxbios: Don't accept 400h as a valid sector.
gameblabla [Mon, 22 Jul 2019 21:25:49 +0000 (23:25 +0200)]
psxbios: Don't accept 400h as a valid sector.

Notaz said this could corrupt the emulator (even though
the console allowed this and it was a bug) so limit it to 0x3FF.

4 years agopsxbios: Properly fix garbage area code.
gameblabla [Mon, 22 Jul 2019 02:39:41 +0000 (04:39 +0200)]
psxbios: Properly fix garbage area code.

This should work as intended now.

4 years agopsxbios: Fixup mistake in card_info function.
gameblabla [Sun, 21 Jul 2019 18:57:57 +0000 (20:57 +0200)]
psxbios: Fixup mistake in card_info function.

This fixes Looney Tunes Sheep Raiders.

4 years agopsxbios: Return value is always 1 for CloseTh and ChangeTh.
gameblabla [Sun, 21 Jul 2019 15:31:48 +0000 (17:31 +0200)]
psxbios: Return value is always 1 for CloseTh and ChangeTh.

According to nocash PSX doc, ChangeThread and CloseThread should
always return 1. Fix it accordingly.

4 years agopsxbios: Add checks for memchr.
gameblabla [Sun, 21 Jul 2019 05:43:56 +0000 (07:43 +0200)]
psxbios: Add checks for memchr.

4 years agopsxbios: Some games read from address 0, fix that.
gameblabla [Sun, 21 Jul 2019 03:39:55 +0000 (05:39 +0200)]
psxbios: Some games read from address 0, fix that.

See Garbage Area at Address 00000000h in Nocash PSX Specifications for more inf>

R-types will refuse to boot if psxM[0] is zero.
Fade to Black can crash upon memory card access if psxM[5] is set to the wrong >
Crash Team Racing will refuse to boot if psxM[2] and psxM[3] are not zero.
(Previously, that region of memory would be overwritten above. No explanation why.)

It's set as such according to nocash :
[00000000h]=3C1A0000h  ;<-- but overwritten by 00000003h after soon
[00000004h]=275A0C80h  ;<-- or 275A0C50h (in older BIOS)
[00000008h]=03400008h
[0000000Ch]=00000000h

Note that setting 00000000h to 00000003h doesn't work for R-types.

4 years agopsxbios: Implement get_cd_status stub according to nocash doc.
gameblabla [Sun, 21 Jul 2019 00:45:58 +0000 (02:45 +0200)]
psxbios: Implement get_cd_status stub according to nocash doc.

4 years agopsxbios: Make HLE bios start from block 1, not 2.
gameblabla [Sun, 21 Jul 2019 00:38:32 +0000 (02:38 +0200)]
psxbios: Make HLE bios start from block 1, not 2.

I already fixed this for bufile :
ptr = Mcd##mcd##Data + 128 * (nfile + 1); \
instead of
ptr = Mcd##mcd##Data + 128 * nfile; \

But i forgot to also fix psxBios_firstfile accordingly.
So nfile would still start from block 2 and it would
cause all kinds of issues.

This was the original comment on pcsxr codeplex
as my patch was based on it :
"The HLE-Bios start to read memory card blocks at block 2. You need to change
ptr = Mcd##mcd##Data + 128 * nfile; \ to
ptr = Mcd##mcd##Data + 128 * (nfile + 1); \
for #define bufile(mcd) { \ and changing nfile = 1; to nfile = 0; for psxBios_firstfile() { // 42 Starts numbering slots in the right position."

4 years agopsxbios: Fix card_status function as to use card_active_chan.
gameblabla [Sun, 21 Jul 2019 00:30:15 +0000 (02:30 +0200)]
psxbios: Fix card_status function as to use card_active_chan.

4 years agopsxbios: Merge interrupt_r26 fix from PCSX4ALL.
gameblabla [Sun, 21 Jul 2019 00:13:34 +0000 (02:13 +0200)]
psxbios: Merge interrupt_r26 fix from PCSX4ALL.

Thanks DmitrySmagin for the fix.

4 years agopsxbios: Do the same for heap_size.
gameblabla [Sun, 21 Jul 2019 00:10:27 +0000 (02:10 +0200)]
psxbios: Do the same for heap_size.

4 years agopsxbios : Use bfreezel for pad_stopped instead of setting it to 0.
gameblabla [Sat, 20 Jul 2019 23:31:24 +0000 (01:31 +0200)]
psxbios : Use bfreezel for pad_stopped instead of setting it to 0.

4 years agopsxbios : Implement stub for wait_card.
gameblabla [Sat, 20 Jul 2019 23:28:56 +0000 (01:28 +0200)]
psxbios : Implement stub for wait_card.

Pretty much identical to get_card_status except it's supposed
to wait until a non-busy state occurs.

4 years agopsxbios : Fix a few mistakes :
gameblabla [Sat, 20 Jul 2019 23:26:10 +0000 (01:26 +0200)]
psxbios : Fix a few mistakes :

- Remove extra ffile, pfile.. as it is declared elsewhere.
- Remove extra condition as it's already being handled by pad_stopped.
- Remove n variable from function (pcsx4all did this) as it's useless
and documentation doesn't seem to specify it's needed.

4 years agopsxbios: Add note and update copyright.
gameblabla [Thu, 18 Jul 2019 00:51:25 +0000 (02:51 +0200)]
psxbios: Add note and update copyright.

4 years agopsxbios: Merge heap fix from PCSX4ALL.
gameblabla [Thu, 18 Jul 2019 00:42:41 +0000 (02:42 +0200)]
psxbios: Merge heap fix from PCSX4ALL.

4 years agopsxbios: Init some vars just to be sure.
gameblabla [Thu, 18 Jul 2019 00:40:13 +0000 (02:40 +0200)]
psxbios: Init some vars just to be sure.

4 years agopsxbios: Merge PCSX4ALL pad_stopped fix.
gameblabla [Thu, 18 Jul 2019 00:38:32 +0000 (02:38 +0200)]
psxbios: Merge PCSX4ALL pad_stopped fix.

4 years agopsxbios.cpp: Add psxBios_card_status(); doesn't seem to affect anything
gameblabla [Thu, 18 Jul 2019 00:35:47 +0000 (02:35 +0200)]
psxbios.cpp: Add psxBios_card_status(); doesn't seem to affect anything

4 years agopsxbios: Fixes save issues on Parasite Eve II, Parasite Eve I and others
gameblabla [Thu, 18 Jul 2019 00:34:31 +0000 (02:34 +0200)]
psxbios: Fixes save issues on Parasite Eve II, Parasite Eve I and others

Merging never-merged fix by Solus for Parasite Eve. I also fixed some GCC warnings
about dir->name going out of bounds too.
We also make sure to only add '/0' if string is not full and right after the last character in the dir array.

This fixes saving/loading in Parasite Eve II, Parasite Eve.
It also fixed regressions for the LEGO Racers where other games would break,
meaning this should be the proper fix for saves.

We're also using our own strlen implementation to avoid any issues or
relying on the libc's own strlen.

4 years agopsxbios: Callback Events should not set event status to busy in TestEvent.
gameblabla [Thu, 18 Jul 2019 00:30:31 +0000 (02:30 +0200)]
psxbios: Callback Events should not set event status to busy in TestEvent.

We are already doing that in WaitEvent. According to nocash documentation,
this also applies to TestEvent as well so let's implement it.

4 years agopsxbios: Support other syscalls
gameblabla [Thu, 18 Jul 2019 00:29:49 +0000 (02:29 +0200)]
psxbios: Support other syscalls

Since they don't do anything however, let's just add a default and break;
instead. Interestingly, trying to implement SYS(04h+ can actually crash
the HLE bios. Nocash documentation said that it should crash it
but due to other reasons, it doesn't and returns to main program instead.

4 years agopsxbios: Add checks for strlen.
gameblabla [Thu, 18 Jul 2019 00:28:55 +0000 (02:28 +0200)]
psxbios: Add checks for strlen.

Per what Nocash documentation says.

4 years agopsxbios: Add checks for strcpy & strncpy.
gameblabla [Thu, 18 Jul 2019 00:28:22 +0000 (02:28 +0200)]
psxbios: Add checks for strcpy & strncpy.

This should be closer to documentation.

4 years agopsxbios: Fixup free.
gameblabla [Thu, 18 Jul 2019 00:27:11 +0000 (02:27 +0200)]
psxbios: Fixup free.

This is needed for Burning Road. Fix comes from PCSX4ALL by dmitryssmagin.

4 years agopsxbios: Add checks for strcmp & strncmp.
gameblabla [Thu, 18 Jul 2019 00:26:18 +0000 (02:26 +0200)]
psxbios: Add checks for strcmp & strncmp.

Yes, it's supposed to have a lot of checks like these.
Also merge some more fixes from PCSX4ALL. (upstream did not have
these as far as i know)

4 years agopsxbios: Stub for get_error
gameblabla [Thu, 18 Jul 2019 00:23:24 +0000 (02:23 +0200)]
psxbios: Stub for get_error

According to a user on PCSX-Reloaded codeplex (now dead), this fixed loading/saving
in Final Fantasy Tactics.

4 years agopsxbios : Several fixes to malloc.
gameblabla [Thu, 18 Jul 2019 00:21:53 +0000 (02:21 +0200)]
psxbios : Several fixes to malloc.

- Don't allow malloc to init memory if heap is invalid
According to nocash documentation, malloc will not allocate if heap size
is too small or invalid.

- Also merge some fixes from PCSX4ALL fork by senquack in order to allow
Burning Road to run.

4 years agopsxbios: Add checks for memmove.
gameblabla [Thu, 18 Jul 2019 00:19:07 +0000 (02:19 +0200)]
psxbios: Add checks for memmove.

Always returns dst per documentation.

4 years agopsxbios : Add checks to memset.
gameblabla [Thu, 18 Jul 2019 00:17:35 +0000 (02:17 +0200)]
psxbios : Add checks to memset.

This now can be a tricky pony and an improper memset implementation means that
you can't play Tomb Raider 4 properly.
(Trying to put in the eye of horus will just result in Lara sidestepping)

This should hopefully be fixed (and follows nocash doc).

4 years agopsxbios: Add checks to memcpy.
gameblabla [Thu, 18 Jul 2019 00:16:41 +0000 (02:16 +0200)]
psxbios: Add checks to memcpy.

Always returns dst

4 years agopsxbios: Add checks for bzero.
gameblabla [Thu, 18 Jul 2019 00:15:27 +0000 (02:15 +0200)]
psxbios: Add checks for bzero.

Only return 0 if size is invalid. (0 or 0x7FFFFFFF), return dst if not.

4 years agopsxbios: Add checks for bcopy
gameblabla [Thu, 18 Jul 2019 00:13:13 +0000 (02:13 +0200)]
psxbios: Add checks for bcopy

Nocash documentation say that function refuses to copy any data
if dst is NULL or len greater than 0x7FFFFFFF.
(In any cases, return value is always dst)

4 years agopsxbios : Add checks to index and rindex calls
gameblabla [Thu, 18 Jul 2019 00:12:23 +0000 (02:12 +0200)]
psxbios : Add checks to index and rindex calls

Return 0 for index/rindex if src is 0x00.

4 years agopsxbios: Merge upstream fix for Deliverevent in firstfile
gameblabla [Thu, 18 Jul 2019 00:11:40 +0000 (02:11 +0200)]
psxbios: Merge upstream fix for Deliverevent in firstfile

Looks like it is only executed for memory cards, that makes sense i guess.

4 years agopsxbios: Should fix input issues in some games.
gameblabla [Thu, 18 Jul 2019 00:10:43 +0000 (02:10 +0200)]
psxbios: Should fix input issues in some games.

Someone reported that this fixed Negcon controls in Ridge Racer Revolution
and Grand Tour Racing.
I doubt this will suffer from regressions ?

4 years agopsxbios: Fix out-of-bounds issue.
gameblabla [Thu, 18 Jul 2019 00:09:56 +0000 (02:09 +0200)]
psxbios: Fix out-of-bounds issue.

Make sure to return 0xff is no TCBs are available.
Thanks senquack for the proper fix.

4 years agoOnly PCSX4ALL uses ResetIoCycle. Remove it for now.
gameblabla [Thu, 18 Jul 2019 00:08:32 +0000 (02:08 +0200)]
Only PCSX4ALL uses ResetIoCycle. Remove it for now.

4 years agoFixup buread & buwrite being undefined.
gameblabla [Thu, 18 Jul 2019 00:07:56 +0000 (02:07 +0200)]
Fixup buread & buwrite being undefined.

4 years agopsxbios: Improve WaitEvent behaviour according to documentation
gameblabla [Thu, 18 Jul 2019 00:02:48 +0000 (02:02 +0200)]
psxbios: Improve WaitEvent behaviour according to documentation

Nocash says it should return 0 if Event is unused, which it already does so it might be safe to remove the warning about it.
(see why below)

Then, it says that it should return 1 if event is ready (EvStALREADY). When that happens, it should also set it to ready (EvStACTIVE),
unless event mode is EvMdINTR. (aka Callback Events)
If it is a callback event, then documentation says it should be stuck in a loop forever.

It also says that it can sometime return 0 (a BUG according to nocash),
especially if it switched from EvStALREADY to EvStACTIVE.

Said return value was previously set to 1, for some reasons. Now that we are covering all the corner cases,
we should be returning 0 instead by default to cover the BUG.

This should cover how most games expects it to behave now and should make it more robust.

4 years agopsxbios: Better realloc implementation
gameblabla [Thu, 18 Jul 2019 00:01:34 +0000 (02:01 +0200)]
psxbios: Better realloc implementation

This should be closer to the real behaviour as described by nocash.
It doesn't do any bcopy though but it shouldn't be too much different
other than that.

4 years agopsxbios : Add checks for strncat
gameblabla [Thu, 18 Jul 2019 00:00:11 +0000 (02:00 +0200)]
psxbios : Add checks for strncat

Returns 0 if src or dst is 0x00.

4 years agopsxbios: Add todigit implementation
gameblabla [Wed, 17 Jul 2019 23:59:35 +0000 (01:59 +0200)]
psxbios: Add todigit implementation

Based on CTRX's code : https://github.com/machinamentum/CTRX/blob/master/bios/source/libc.c#L152

I'm not aware of any games using it but it doesn't hurt to have it
and it should work fine.

4 years agopsxbios: Adds putc and getc implementation
gameblabla [Wed, 17 Jul 2019 23:58:44 +0000 (01:58 +0200)]
psxbios: Adds putc and getc implementation

getc will need to be fixed later but this should do as it is.
No issues with putc. Both are similar to psxBios_read and psxBios_write,
except size is 1.

4 years agopsxbios: Return 0x1f801814 for gpu_abort_dma
gameblabla [Wed, 17 Jul 2019 23:57:53 +0000 (01:57 +0200)]
psxbios: Return 0x1f801814 for gpu_abort_dma

Nocash documentation says that it returns the I/O address.
I doubt any games use it so but it doesn't hurt to have it.

4 years agopsxbios: Better EnterCiritcal implementation
gameblabla [Wed, 17 Jul 2019 23:57:08 +0000 (01:57 +0200)]
psxbios: Better EnterCiritcal implementation

Nocash documentation says it should return 0 if one or
none of the bits were changed and return 1 of both bits were set.

This fixes Medievil 2, which would freeze upon starting up a game
and this properly fixes Digimon World crashing (with fixed strcat implementation).
It also possibly fix other games.

4 years agopsxbios: Add checks for card_write, card_read
gameblabla [Wed, 17 Jul 2019 23:55:57 +0000 (01:55 +0200)]
psxbios: Add checks for card_write, card_read

This also implements a bug which allows writes to 0x400
(Is supposed to only accept sector number between 0..3FFh).
Function should return 0 if sector is invalid.

4 years agopsxbios: Merging improved card_info function from upstream
gameblabla [Wed, 17 Jul 2019 23:54:58 +0000 (01:54 +0200)]
psxbios: Merging improved card_info function from upstream

It should be closer to the real thing, and this commit and the previous one
definitely fixes the save issues in Digimon World.

4 years agopsxbios: Merging fixes from upstream.
gameblabla [Wed, 17 Jul 2019 23:44:03 +0000 (01:44 +0200)]
psxbios: Merging fixes from upstream.

DeliverEvent functions are executed right after writing/reading instead of after setting v0.
This fixes saving in games like LEGO Racers.

4 years agopsxbios: Add checks to PAD_init
gameblabla [Wed, 17 Jul 2019 23:10:33 +0000 (01:10 +0200)]
psxbios: Add checks to PAD_init

Nocash documentation says that function fails if type is not 0x20000000
or 0x20000001. In case of failure, it should return 0.
If not, then it should return 2.

This fixes input in Digimon World.

4 years agopsxbios: Add checks to strcat
gameblabla [Wed, 17 Jul 2019 23:09:21 +0000 (01:09 +0200)]
psxbios: Add checks to strcat

Nocash documentation says that function fails if src or dst is 0.
If so, then it must return 0.

This fix is required for fixing crash on bootup in Digimon World.

5 years agoMerge pull request #127 from retro-wertz/fix_rtps_rtpt
notaz [Mon, 25 Mar 2019 21:48:57 +0000 (23:48 +0200)]
Merge pull request #127 from retro-wertz/fix_rtps_rtpt

gte: backport fix for RTPS/RTPT