shmups.system11.org

Shmups Forum
 
* FAQ    * Search
 * Register  * Login 
It is currently Thu Jul 18, 2019 4:55 am View unanswered posts
View active topics



Post new topic Reply to topic  [ 20 posts ] 
Author Message
 Post subject: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 4:33 am 


User avatar

Joined: 31 Aug 2009
Posts: 7478
Location: San Jose, California, USA
The following information (and the ROM) are available at my website: http://daifukkat.su/hacks/grdforcel/

Success's hidden gem Guardian Force is a truly amazing game, but has one very unfortunate flaw: the program is extremely poorly optimized in terms of input latency. Even on the ST-V arcade hardware, the game has somewhere on the order of 6 to 7 frames of input lag. This is beyond the point of uncomfortable, and makes the game almost unbearably hard to control.

So, I had a feeling there would be some low-hanging fruit here. You don't get 6 to 7 frames of input lag if you're even remotely paying attention to how your inputs are handled. So, time to pop open IDA and MAME and get cracking. Turns out, yes there are at least 2 frames of easy-to-fix lag in software.

Here's a little tutorial on setting up the patch, since it's a little different from most things. But hopefully it should be obviously easier than most. :)

Installing

Burn the binary file (available on my website) to any 8-bit ROM with a similar pinout to the 27C010. The file size is very small, and this is the only ROM size required. So you could use a 27C020, 040, 080, etc. You don't need to even repeat the file for those ROMs, it's very forgiving. :)

Once your ROM is burned, open up the cart. You will see an empty EPROM socket on the cart's board, as shown below.

Image

Simply put the ROM you've burned in that socket, and close it back up. That's it! Sega was very clever when they designed their carts, weren't they? ;)

Image

Dev Log

So with this, I had to figure out how the patch EPROM worked on the ST-V. It turns out it's really simple, all I really had to do was take parts of the beginning of the regular ROM data (just the bootstrap, essentially) and work some patching code into it. From there, I needed to find the sources of input lag and devise how to remove them. So, it's watchpoint time.

In the end, I traced the input data coming from the hardware through 2 interstitial buffers which were implemented by Success. We'll name the points here as:
  • hw_inp, the input data exposed directly from the hardware
  • smpc_buffer, the input data which would normally come from Saturn pads
  • smpc_parsed, the input data which is derived from smpc_buffer

Now, the critical thing to know about these buffers is that they're not all updated in one place, or at one time. Normally the smpc_buffer needs to be updated by the Saturn's input reading microcontroller, but the ST-V doesn't use this for inputs. Success clearly wrote their code for Saturn first, as the code which would normally read the data back from the microcontroller actually patches in data from hw_inp into the smpc_buffer.

We can look at these buffers in two ways: who fills them, and what order are they filled? If the buffers are used optimally (in a way which does not increase latency), these should essentially flow the exact same way. In Guardian Force's case, they literally flow the opposite.
Code:
Who fills who?
Hardware -fills-> hw_inp -fills-> smpc_buffer -fills-> smpc_parsed -fills-> Player's Input Code

What order are they filled?
Frame Start -> hw_inp -> Player's Input Code -> smpc_parsed -> smpc_buffer -> Frame End

For those paying attention, each one of these fills is introducing another frame of lag. The player's input code reads from smpc_parsed which isn't updated until after, meaning the data it is using is from the previous frame. The smpc_parsed buffer reads from smpc_buffer, which also isn't updated until after, meaning that too is reading the previous frame's buffer. smpc_buffer is the only one that isn't itself lagged, since hw_inp is always the current frame's data.

The obvious fix here is to invert the order of fills. In this way, each buffer reads from the buffer that was just filled, meaning it's still along the same frame's data. Thus, we remove 2 frames of input lag.

I'm sure there are more dumb sources of lag (it's still somewhere around 4 frames on hardware!), but this is such a massive improvement already that I figured it was worth posting.
_________________
Image
@trap0xf | daifukkat.su/blog | scores | FIRE LANCER
<S.Yagawa> I like the challenge of "doing the impossible" with older hardware, and pushing it as far as it can go.


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 4:46 am 


User avatar

Joined: 18 Jun 2012
Posts: 3430
Location: Chicago, IL
Awesome, trap! I share your assessment of Guardian Force: it's amazing, and an epic adventure (one I'm not good enough to 1CC - more like 7CC lol). I wonder if the input lag extends to the Saturn port, given that it's "arcade accurate." I always wondered whether or not my eyes played tricks on me, or the tank controlled "slippery."
_________________
Image
DEMON'S TILT [bullet hell pinball] - Music Composer || EC2151 ~ My FM/YM2612 music & more! || 1CC List || PCE-CD: The Search for Quality


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 4:52 am 


User avatar

Joined: 31 Aug 2009
Posts: 7478
Location: San Jose, California, USA
I would be really surprised if the Saturn version was any different in terms of lag. If anything it's worse I imagine, since it was definitely developed "first". It certainly should have felt like it was a bit slippery, with 6-7 frames of lag ;)
_________________
Image
@trap0xf | daifukkat.su/blog | scores | FIRE LANCER
<S.Yagawa> I like the challenge of "doing the impossible" with older hardware, and pushing it as far as it can go.


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 5:03 am 


User avatar

Joined: 13 Dec 2014
Posts: 3357
Location: Ringing the bells of fortune
I always thought it was a MAME flaw that introduced all the input lag, didn't know it was like that on actual hardware too. Maybe I should give it another try (with this patch, of course)...
_________________
Image
NTSC-J: You know STGs are in trouble when you have threads on how to introduce them to a wider audience and get more people playing followed by threads on how to get its hardcore fan base to play them, too.
1CCs | Twitch | YouTube


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 8:40 am 


User avatar

Joined: 05 Nov 2013
Posts: 6612
Location: block
IIRC mame's lag mostly comes from its video layer plus the computer's gfx and driver and settings on api, that's what builds like groovy and also retroarch now intervene on to reduce lag. basically a 'normal' mame build running on direct3d or bgfx and syncing or buffering to eliminate tearing will add up to 3 frames at all times, while groovy and retroarch either with d3d9ex or opengl and built-in features like 'frame_delay' can reduce the queue to one frame and even allow you to trim some more ms on the remaining frame of the video layer.

Then it was my understanding that the lag in the game's mame hardware driver is a different matter.
while I think this is what shmupmame intervenes on, that build lacks what groovy and retroarch have, so in the end it's less efficient at reducing lag and even desyncs sprite layers in some games.

EDIT: well at least that's what I understand of it, now what the gurus of emulation tweaking really do is beyond me.
Anyway it's relatively easy to check while playing.
_________________
mycophobia wrote:
have tyou ever played dodponpatchi


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 12:09 pm 


User avatar

Joined: 28 Feb 2015
Posts: 614
Location: Rome
Groovymame had recently a breakthrough and demonstrated that next-frame response is possible.

It has already been implemented but doesn't work on all games due to how some game drivers were written.

Now it's been discussing that this would break a correct 100% emulation of the system since several boards have some inherent lag in them. With GroovyMAME you can now actually achieve lower lag than the original board.


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 1:08 pm 



Joined: 24 Mar 2005
Posts: 689
Amazing work trap! Thanks for sharing! :)


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 2:31 pm 


User avatar

Joined: 25 Jan 2005
Posts: 642
Location: Virginia, USA
I'm guessing both ST-V Cotton games also used this buffer-chain system? They also have hideous input lag in MAME, but I haven't played on real hardware.


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 5:15 pm 


User avatar

Joined: 05 Nov 2013
Posts: 6612
Location: block
donluca wrote:
Groovymame had recently a breakthrough and demonstrated that next-frame response is possible

Current frame even!

Didn't mention because this is still experimental, but this will certainly be a nice feature to have along frame_delay, useful for someone who would have a laggy display for instance, and need to squeeze lag to a minimum.
_________________
mycophobia wrote:
have tyou ever played dodponpatchi


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 7:12 pm 


User avatar

Joined: 28 Feb 2015
Posts: 614
Location: Rome
Xyga wrote:
Current frame even!

Didn't mention because this is still experimental, but this will certainly be a nice feature to have along frame_delay, useful for someone who would have a laggy display for instance, and need to squeeze lag to a minimum.


It's the evolution of frame_delay, which is going to be removed when they'll manage to work with the slices in a way which the MAME game drivers cooperate. They are not not be used together, unless you meant to use frame delay with games which doesn't support the new slice thing :)


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Mon Apr 09, 2018 7:36 pm 


User avatar

Joined: 05 Nov 2013
Posts: 6612
Location: block
yup the one or the other, surely both features can cohabitate in the same build. if frame slice cuts into the actual delay existing with the real hardware it indeed breaks accurate emulation so it shouldn't be the only choice for lag reduction.

anyway we'll see what happens in the future
_________________
mycophobia wrote:
have tyou ever played dodponpatchi


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Tue Apr 10, 2018 10:48 am 


User avatar

Joined: 28 Feb 2015
Posts: 614
Location: Rome
Yeah, besides, these are very exciting times.

Thanks to MAME (and GroovyMAME) development we might see one day a fantastic (and free!) solution to play all those arcade games with 100% accuracy.

Managing to having them running flawlessly on a CRT is huge step forward, I think that the solution for LCD panels will arrive when MAME will start supporting properly adaptive sync monitors so they'll be able to run at the correct speed without any trickery.

Oh, and we're going to need much, much higher resolutions. The reason is that in the CRT era, pixels were never meant to be square.

Take for example ESPGaluda: its native resolution is 448x224 which is obviously very, very far from 4:3. This means that when you play it on a LCD, in order to achieve the correct aspect ratio you're going to need fractional scaling on one axis and this will look good only if you have a very very high resolution panel on which you can stretch that 448 pixels.

Maybe retina displays could be enough.

Anyway, I got a little bit carried away, sorry for derailing the thread!


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Tue Apr 10, 2018 11:21 am 


User avatar

Joined: 02 Dec 2010
Posts: 3579
There are numerous times when pixel artists would assume square pixels. This happened less with arcade hardware than with consoles, but it still very much happened... NMK/Jaleco hardware comes to mind. All hardware considered, CPS1/2/3 and PGM were some really big exceptions.

NES, SNES, PC Engine, Master System, etc, they typically rely on internal resolution. The big exception is the Mega Drive's "4:3-like" mode that a lot of games used. Other than that, attempting to play most of the games made for these platforms on 4:3 screens results in a distorted picture and distorted object movement. It's exactly like attempting to play a 4:3 PC game stretched to 16:9. Unsurprisingly, many people do just that, and don't see the problem even when you point it out to them.
_________________
In 1989,The Great Wall was discoverd
In 1990,The Picket Fence was also discoverd


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Tue Apr 10, 2018 5:31 pm 


User avatar

Joined: 13 Dec 2014
Posts: 3357
Location: Ringing the bells of fortune
donluca wrote:
Take for example ESPGaluda: its native resolution is 448x224 which is obviously very, very far from 4:3. This means that when you play it on a LCD, in order to achieve the correct aspect ratio you're going to need fractional scaling on one axis and this will look good only if you have a very very high resolution panel on which you can stretch that 448 pixels.

Technically all you need is 672x896 (each of the 224x448 pixels scaled to 3x2) or some multiple thereof if all you require is that every pixel be scaled to the same size. It's easier for Espgaluda with its simple 2:1 pixel ratio than it is for something like, say, Progear with its 12:7 pixel ratio (to achieve the same with Progear you would need to scale every pixel to 7x9, or 384x224 to 2688x2016). At high enough resolution, though, a bit of uneven scaling is hardly noticeable, especially in motion.
_________________
Image
NTSC-J: You know STGs are in trouble when you have threads on how to introduce them to a wider audience and get more people playing followed by threads on how to get its hardcore fan base to play them, too.
1CCs | Twitch | YouTube


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Tue Apr 10, 2018 5:37 pm 


User avatar

Joined: 05 Nov 2013
Posts: 6612
Location: block
Oh that little tearing line in Ketsui Extra in the middle of the screen when you set the zoom to 93% which is the closest to integer...save for that fucking pixel. The rage.
And you have no choice but to use one of their crappy filters if you want it gone lol so your zoom level sien't uselful anymore anyway lol.

You know me when I have room for clean integer I don't care about anything else. :p

Hugh I'm polluting this fine thread again sorry.
_________________
mycophobia wrote:
have tyou ever played dodponpatchi


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Wed Apr 11, 2018 1:44 pm 


User avatar

Joined: 04 Jan 2006
Posts: 443
Location: Central Tokyo, Japan, Asia, Earth, Solar System, Milky Way
Too bad the true original version on SPI is lost.
_________________
become history


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Wed Apr 11, 2018 3:29 pm 


User avatar

Joined: 01 Oct 2008
Posts: 135
Location: Nice
Thank you Trap. :!:
Will test it this weekend.
_________________
My Arcade PCBs


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Wed Apr 11, 2018 6:02 pm 


User avatar

Joined: 09 Mar 2014
Posts: 1835
Location: Mars Colony, 2309
Xyga wrote:
Oh that little tearing line in Ketsui Extra in the middle of the screen when you set the zoom to 93% which is the closest to integer...save for that fucking pixel. The rage.
And you have no choice but to use one of their crappy filters if you want it gone lol so your zoom level sien't uselful anymore anyway lol.

You know me when I have room for clean integer I don't care about anything else. :p

Hugh I'm polluting this fine thread again sorry.

You must really hate playing CPS2 games then. Nothing dumber (from a 2018 perspective) than 384x224 resolution that's supposed to be adjusted to a 4:3 aspect ratio.
_________________
YouTube | Restart Syndrome | 1cclist | Go Play Mars Matrix
Solunas wrote:
How to Takumi your scoring system
1) Create Scoring System
2) Make it a multiplier for your actual score


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Thu Apr 12, 2018 4:11 am 


User avatar

Joined: 05 Nov 2013
Posts: 6612
Location: block
No problem either on a crt (doesn't apply) or lcd, on the latter I use integers for instance on a 1080p display cps game are set to 4x5, I lose a few lines top and bottom but those are ususally empty space so I don't lose anything and it looks perfect af. IIRC marqs offers that option for his cps2 interface.
Full-HD displays are a bit limited to opt for integer-everything but most of the issues go away as long as you use settings for both yoko and tate, 320x240, 384x224, 448x224, 320x232 etc, there are good settings for most common resolutions as long as you accept a bit of overscan or underscan.
For fractional emulators/gpus or display's built-in scalers usually suck ass unless you use a select few shaders that can completely hide artifacts for the former, or a Sony TV for the latter. Otherwise an external scaler will do a better job. Unlike a lot of people who trust only the numbers I'm not so enthusiastic to see the panel's resolutions ever-increase, because I know that alone doesn't fix bad scaling.
_________________
mycophobia wrote:
have tyou ever played dodponpatchi


Top
 Offline Profile  
 
 Post subject: Re: Guardian Force De-Lag Patch
PostPosted: Wed Jun 12, 2019 3:56 pm 



Joined: 23 Mar 2011
Posts: 602
WARNING! Carefully examine your cart pcb before installing this patch.
My cart had one pin that was never soldered, and possibly caused a short which made
my mobo explode.

See Here: https://shmups.system11.org/viewtopic.php?p=1368254#p1368254


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ] 

All times are UTC


Who is online

Users browsing this forum: Google [Bot], yosai and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Space Pilot 3K template by Jakob Persson
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group