Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teen Titans (USA) ; The Sims 2: Pets ; Monster House - graphical glitches #224

Open
Apaczer opened this issue Aug 27, 2023 · 19 comments
Open

Comments

@Apaczer
Copy link

Apaczer commented Aug 27, 2023

Issue: Blank screen during startup animation and many graphical glitches in gameplay.

INFO: I tested it with older revision of libretro and the newest one, also present in old standalone port. First noticed in TriForceX/MiyooCFW#482 (comment)

Commit: 188887e
Engine: Interpreter/Dynarec
Platform: Win x86_64, Miyoo ARM32

@andymcca
Copy link

I suspect this is a timing issue - similar graphical glitches to Sims 2: The Pets, possibly trying to load some graphics tiles before they exist in VRAM or something like that. Timing in gpsp is/has always been rather screwy. Good to have this issue tracked though, give another game that experiences the same/similar issue.

@Apaczer
Copy link
Author

Apaczer commented Aug 28, 2023 via email

@Apaczer
Copy link
Author

Apaczer commented Aug 28, 2023 via email

@Apaczer Apaczer changed the title Teen Titans (USA) - graphical glitches Teen Titans (USA) ; The Sims 2: Pets ; Monster House - graphical glitches Aug 28, 2023
@andymcca
Copy link

Thank you @Apaczer - I asked a user on GBATemp to check for the existence of this bug on TempGBA. He said -

_**TempGBA 20160527

-Sims 2:The Pets PAL
Intro was fine. Graphics looks fine to me. Fullspeed

-Tiny Toon Adventures - Buster's Bad Dream PAL
Intro was fine and I couldn't spot any graphical issues. Games had some slowdowns with many enemies at ones but emulator was still showing (60/60) so it's probably just how the game behaves**_

So this is interesting - TempGBA doesn't seem to have this bug. I have seen this situation before, so I will try and troubleshoot by comparing the code.

@andymcca
Copy link

andymcca commented Sep 2, 2023

OK, so speaking with David he tells me this is a timing issue.

gpsp is focused on speed rather than accuracy, so whilst there is some cycle counting going on to make sure things work well enough, it's a balancing act.

Doing some crude testing with the code (setting a penalty on ARM/Thumb default instruction cycles), sure enough, I can reduce the visual glitching on Sims 2 but at the expense of introducing glitches to the audio and slowing down video rendering. I haven't found a combination that yields acceptable performance with this method, nor would I really expect to - it requires more thought and coding to address properly. So I think these games are just particularly susceptible to some aspect of timing

TempGBA-Mod seems to take a different approach to timing and is targeted at the PS2/PSP CPU only. I'd be interested to know how Sims 2 works in something like ReGBA (derived from TempGBA) on an Opendingux device.

@Apaczer
Copy link
Author

Apaczer commented Sep 2, 2023 via email

@andymcca
Copy link

andymcca commented Sep 3, 2023

Thank you @Apaczer !

I actually made a bit of progress on this issue -

gpsp/main.c

Line 114 in 188887e

remaining_cycles = MAX(remaining_cycles, -64);

If we change the baseline value in this line from -64 to a positive value (say, 4), then this clears up all visual issues in Sims 2 and Teen Titans. The downside is it breaks all other games 😆

I have reported this to David but I'm not sure why this works and whether it is something that we can even utilise. Still, if you wish to build with that change then you can play these two games and maybe Monster House only 😆

Teen Titans seems to have a separate issue where you get to the 'this icon means the game is saving' screen on the intro, in that it stays on this screen for a few seconds and then either reboots to the Gameboy logo or freezes the emulator (this happens regardless of the change above)

@andymcca
Copy link

andymcca commented Sep 3, 2023

Monster House also hangs on the 'Create Game' screen.

Probably worth checking the other games from this developer / release year(s) to see if the same problems occur -
https://en.wikipedia.org/wiki/Behaviour_Interactive#Titles

@Apaczer
Copy link
Author

Apaczer commented Sep 3, 2023

I tried to bisect it and I got similar crash on "Monster House" and "The Sims". However these were very random and usually had happend after loadstate (no log), to be sure I would have to reproduce it on another platform.

@andymcca I was following David Richard dev work, where he was lead designer.

@andymcca
Copy link

andymcca commented Sep 8, 2023

Yes I've noticed that once changing the line mentioned above, you also need to have .srm or .sav files in place beforehand (depending if save type is set to libretro or gpsp respectively) in order for the games to work. Otherwise you'll be met with a blank screen on load. Even then, if you attempt to save in-game it will crash as described above! Probably causes a race condition or similar

Anyway, all shooting in the dark a bit - needs proper investigating and solving by someone more knowledgeable than me! 😆

@andymcca
Copy link

@Apaczer I'm looking at this again 😁 as of the current commit, for Sims 2 The Pets you need to change the MAX of remaining_cycles to either be -256 to see the 'Warning' splash screen at the start, or to 4096 or higher to remove in-game graphics glitches.

The issue seems to be connected to entering the loop in the update_gba function in main.c when the CPU is in an active state. It needs to go into the loop once to check Timers/IRQs/DMAs, but this seems to mess up the graphics so my gut feeling is that graphics transfer DMAs are being interrupted/aborted early somehow. When setting remaining_cycles to 4096, this greatly limits the number of times video_count goes below 0, which stops the above.

@davidgfnet - any thoughts? I'm still investigating/playing with it.

andymcca added a commit to andymcca/lr-gpsp-amcc that referenced this issue May 18, 2024
Commenting out this line appears to fix issue libretro#224 with no adverse effects elsewhere, as far as I can see through limited testing on these games and other games in my collection.

@davidgfnet you will know far better than me, but maybe this line is rendered unnecessary following after you implemented DMA sleep mode and taking into account those cycles?
@andymcca
Copy link

andymcca commented May 20, 2024

I did a PR for this based on commenting out the below line -

gpsp/main.c

Line 265 in 4caf7a1

execute_cycles = MAX(video_count, 0);

It makes the games work but stops the sync between execute_cycles and video_count, so execute_cycles never gets updated and it makes some other games run very slowly.

A better change which seems to work well for all games including those in this issue is -

execute_cycles = MIN(video_count, 96);

EDIT: having run some more tests I think the above works by allowing timers/irqs/dma transfers to be initiated in a more timely manner in relation to the scanlines being rendered. Unedited, the current code enters the update_gba function between 600-800 times a frame. With this change, it enters the function around 3000 times, whilst still maintaining 456 entries into the video_count if statement and approx 280896 cycles run per frame as normal.

The instances where update_gba is entered where video_count > 0 are greatly increased, meaning that timers are checked and irqs flagged earlier.

These games generate a huge number of interrupts per frame compared to other games, hence the timing appears to be far more sensitive. The change above seems to work well on all games I've tried so far, including these, with no speed or other penalty that I can see. If anyone else can build and test, it would be appreciated!

@Apaczer
Copy link
Author

Apaczer commented Aug 25, 2024

Big 🙇 @andymcca, I tried with this change:

diff --git a/main.c b/main.c
index 55401d7..df14d3b 100644
--- a/main.c
+++ b/main.c
@@ -265,7 +265,7 @@ u32 function_cc update_gba(int remaining_cycles)
     execute_cycles = MAX(video_count, 0);
     {
       u32 cc = serial_next_event();
-      execute_cycles = MIN(execute_cycles, cc);
+      execute_cycles = MIN(execute_cycles, 96);
     }
 
     // If we are paused due to a DMA, cap the number of cyles to that amount.

this change indeed fix the issue on "Teen Titans (USA)" and "The Sims 2: Pets" and as you said there is performance penalty (tried with unrelated game "Castelvania AoS" to be sure). Moreover it seems "Monster House" still suffers (not as much as before!), for e.g. you can see glitching on round sprites' shadows.

@andymcca
Copy link

andymcca commented Aug 25, 2024

@Apaczer good to hear!! Slight error in your change though, from your diff it looks like you changed the wrong line. In the most current commit the change should be changing line 265 in main.c from -

execute_cycles = MAX(video_count, 0);

to -

execute_cycles = MIN(video_count, 96);

You should find this works without a performance hit. Also, you can limit the character shadow problems in Monster House by turning on Interframe Blending

@Apaczer
Copy link
Author

Apaczer commented Aug 25, 2024

ah, yes sry for mistep! Tried now with:

diff --git a/main.c b/main.c
index 55401d7..71b3bcb 100644
--- a/main.c
+++ b/main.c
@@ -262,7 +262,7 @@ u32 function_cc update_gba(int remaining_cycles)

     // Figure out when we need to stop CPU execution. The next event is
     // a video event or a timer event, whatever happens first.
-    execute_cycles = MAX(video_count, 0);
+    execute_cycles = MIN(video_count, 96);
     {
       u32 cc = serial_next_event();
       execute_cycles = MIN(execute_cycles, cc);

much better now, I would say it is 5÷3fps drawback (propably could be overcome with platform specific optimization) - tested on armv5.

BTW: The Interframe Blending opt helps a lot! 👍

@andymcca
Copy link

andymcca commented Aug 25, 2024

@Apaczer Excellent! Yes you will definitely feel it more on armv5 platforms, as they usually seem to be single core/lower cache/software fpu.

Yeah Interframe Blending really helps when the games try and do that 'flicker' effect that the GBA has, other games that do it that I know about are Phantasy Star 1 and Steel Empire.

By the way - could you help test my Draft Pull Request which fixes the sprites in areas in Golden Sun 1/2 and Zelda Minish Cap? It's all described in issue #227 and the Pull Request is the only one open at the moment. I know it works as-is but I'm not sure of what the performance hit is. Testing on an Armv5 would be useful (my old Armv5-based console has bitten the dust unfortunately!)

@Apaczer
Copy link
Author

Apaczer commented Aug 25, 2024

sure, will try with those changes (saw the PR gratz!), glad to be of any help and see progress.

andymcca added a commit to andymcca/lr-gpsp-amcc that referenced this issue Aug 31, 2024
This resolves issue libretro#224.  All games in this issue (all from the same developer) generate a high number of DMA/IRQ requests per scanline relative to other games.  Theory is that the default frequency (about once or twice per scanline) isn't enough for these to be fired in a timely fashion for these games, resulting in the graphics corruption reported in the issue.

This PR significantly reduces the number of cycles that are run before update_gba is called to check for DMA/IRQ status, which resolves the corrupted graphics.  Casual testing with other games hasn't shown any side affects but full impact testing with other games will be needed.
@andymcca
Copy link

sure, will try with those changes (saw the PR gratz!), glad to be of any help and see progress.

Hey @Apaczer , I created my own fork of lr-gpsp just to incorporate all my PRs and experiments!!! I've put it here -

https://github.com/andymcca/lr-gpsp-amcc

Could you please build it when you have time and try it out? It should work a bit nicer on older/less powerful devices like ARMv5te, though I'm not too sure what the compatibility will be like!

@Apaczer
Copy link
Author

Apaczer commented Sep 16, 2024

@andymcca, sent a DM via mail, didnt want to go offtopic here 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants