Page 1 of 1

Customized Screen Update Code For Keen 4-6

Posted: Sun Dec 01, 2019 23:21
by K1n9_Duk3
Since a couple of people have asked for it...
Roobar wrote: Fri Oct 11, 2019 13:15 That screen update code fix is neat... I think this is so significant change that now this screen update code must be applied to all major galaxy mods.
55Aavenue wrote: Tue Oct 29, 2019 3:12 Also that screen update code is amazing and now I can't live without it.
Here is a download link for the patch script previously seen in action in Buried in Oblivion v1.3, which in turn is based on some code I wrote for Atroxian Realm v1.1 and above.

This download contains patch scripts for
  • Keen 4 (v1.4)
  • Keen 5 (v1.4)
  • Keen 6 (v1.4)
  • Keen 6 (v1.5)
The updated code fixes some graphical glitches when playing in DOSBox, like
  • jerky scrolling
  • sprites becoming invisible for one frame
  • sprites hidden behind foreground tiles becoming visible
Changing the "Fix Jerky Motion" option in the options menu will change the behavior of the screen update code. This option should be turned OFF (which is the default setting) when playing in DOSBox.

I also tested this code on various old PCs, using an MS-DOS 6.22 boot disk and running the game directly from DOS, and only one my systems had problems with the default setting. That machine was a "Texas Instruments TravelMate 4000E 486 WinSX/25MHz Color" system. Enabling the "Fix Jerky Motion" option fixed the problems on that machine.

Note that this code has NOT been tested on an actual EGA card. The WaitVBL code was designed to stop waiting for a VBL when more than 1/70th of a second has passed since the code started to wait for a VBL. That's because the code can miss the VBL if the CPU was hadling an interrupt while the VBL signal was present and therefore the WaitVBL code didn't get to "see" the VBL signal. But EGA cards use a refresh rate of 60 Hz, not 70 Hz like the (S)VGA cards. That means it is possible for the WaitVBL code to exit a little too early on systems equipped with an EGA card, which means the issues listed above could still pop up.

Re: Customized Screen Update Code For Keen 4-6

Posted: Sun Dec 01, 2019 23:28
by Nisaba
fantastic!
thanks a whole lot for sharing.
I think it's about time to add this patch to our beloved KeenWiki as well.

Re: Customized Screen Update Code For Keen 4-6

Posted: Tue Dec 03, 2019 23:39
by K1n9_Duk3
Oops. I forgot to put the download link in my original post. Sorry about that.

Re: Customized Screen Update Code For Keen 4-6

Posted: Wed Dec 04, 2019 6:35
by Tormentor667
What exactly is the difference of this code?

Re: Customized Screen Update Code For Keen 4-6

Posted: Wed Dec 04, 2019 8:00
by Nisaba
Tormentor667 wrote: Wed Dec 04, 2019 6:35 What exactly is the difference of this code?

The code comes with a readme section.
I'm quoting:
K1n9_Duk3 wrote:#-------------------------------------------------------------------------------
# What does this patch script do? Well, it fixes a few minor glitches when
# playing COMMANDER KEEN 4-6 in DOSBox, such as:
#
# - jerky scrolling
# - sprites becoming invisible for one frame
# - sprites hidden behind foreground tiles becoming visible
#
# Changing the "Fix Jerky Motion" option in the options menu will change the
# behavior of the screen update code. This option should be turned OFF (which
# is the default setting) when playing in DOSBox.
#
# I also tested this code on various old PCs, using an MS-DOS 6.22 boot disk and
# running the game directly from DOS, and only one of them had problems with the
# default setting. That machine was a "Texas Instruments TravelMate 4000E 486
# WinSX/25MHz Color" system. Enabling the "Fix Jerky Motion" option fixed the
# problems on that machine.
#
# Note that this code has NOT been tested on an actual EGA card. The WaitVBL
# code was designed to stop waiting for a VBL when more than 1/70th of a second
# has passed since the code started to wait for a VBL. That's because the code
# can miss the VBL if the CPU was hadling an interrupt while the VBL signal was
# present and therefore the WaitVBL code didn't get to "see" the VBL signal.
# But EGA cards use a refresh rate of 60 Hz, not 70 Hz like the (S)VGA cards.
# That means it is possible for the WaitVBL code to exit a little too early on
# systems equipped with an EGA card, which means the issues listed above could
# still pop up.
#-------------------------------------------------------------------------------

Re: Customized Screen Update Code For Keen 4-6

Posted: Wed Dec 04, 2019 22:42
by K1n9_Duk3
Tormentor667 wrote: Wed Dec 04, 2019 6:35 What exactly is the difference of this code?
Let's take this hairmonster12's Let's Play video for Buried in Oblivion (v1.0) level 1 as an example:

The first glitch appears at around 0:34. Look at the sprites for Keen and the bounder.
The second glitch is at around 1:51. Sprite flickering again. And again at 3:07.
At around 3:10 you can see a jawbreaker that should be hidden in a secret.
More sprite flickering and hidden items becoming visible at 5:38.
Again at 6:54 ...

As you can see, the glitches pop up roughly every 80 seconds in this video. And it's farily consistent behavior when playing (mods of) Keen 4-6 with the original screen update code in DOSBox at the default setting of 3000 cycles. The glitches may be less frequent or less noticeable when you tweak the cycles count in DOSBox, but they're still there. The customized screen update code should fix these issues regardless of your cycles settings, so everybody wins.

Re: Customized Screen Update Code For Keen 4-6

Posted: Fri Dec 06, 2019 3:27
by proYorp
This seems helpful. I usually fix these issues by setting DOSBox to run as "ega" instead of "svga_s3", which works most of the time unless the mod has a changed palette.

Can this be manually added into mods for personal use (like how people patch in infinite lives if the mod doesn't have it by default)? Is it likely to conflict with highly patched mods, or do you think it only changes things that most mods usually don't mess with?

Re: Customized Screen Update Code For Keen 4-6

Posted: Fri Dec 06, 2019 22:02
by K1n9_Duk3
Yes, you should be able to add these patches to pretty much any Keen 4-6 mod ever made.

The patch only modifies the part of the code that is responsible for the screen update (i.e. the part that tells the graphics card which parts of the video memory should be displayed). The drawing and scrolling are handled elsewhere, so it's highly unlikely that my patch would conflict with other parts of the mod's patch file, even for highly patched mods. The only reason to modify this part of the code would be an attempt to fix the scrolling issues, and I'm not aware of any other attempts besides my own.

Just to be safe, it's best to add this patch at the very end of the patch script (before the %end command). This way the patch can't be overridden by other patches in the file, so at least the screen update code will work correctly.

Unfortunately, CKPATCH doesn't appear to show any warning messages when one part of the patch script overrides the changes of an earlier part. You can use my patching utility to check for such errors, but you will have to replace the %ext and %ver commands with the %exefile command that you can find in my patch scripts. You will also need to disable a few commands in the patch script (%gamemaps, %maphead etc.) since my patching utility doesn't support those commands. Be warned, though: you will most likely get a ton of warning messages for some mods, so use at least version 1.5 of my patcher (v1.5 combines multiple warnings into one message box instead of showing each warning message in its own message box).

Re: Customized Screen Update Code For Keen 4-6

Posted: Mon Dec 09, 2019 17:52
by keropi
Just popping by to say that thanks to K1n9_Duk3 's patches I was able to play Keen4 and 5 on real hardware (ega card and monitor) . You would think that this combo would be the less problematic of all but this is not the case...
I have tested the new patches and they seem to work as intended , it is amazing that we had to reach 2019 to fix these games for EGA hardware :christmas

Re: Customized Screen Update Code For Keen 4-6

Posted: Sun May 30, 2021 16:03
by spikey
Hey guys,

Sorry to necro an old thread, but I was trying to use this patch with the Keen 4 mod "Keen 7" by Ceilick, and I couldn't get it working.

Basically, I did what I thought was right, which was to copy the text from King Duke's txt file (the K4 one) to the bottom of the Keen 7 patch file, removing the duplicate %end. After that didn't work I copied only the text after the readme in the K4 file. Still not working.

I'm new to playing Keen mods, so if I did something stupid I apologise! :) Any help appreciated.

Re: Customized Screen Update Code For Keen 4-6

Posted: Sun May 30, 2021 20:34
by K1n9_Duk3
spikey wrote: Sun May 30, 2021 16:03Any help appreciated.
You're probably better off using my unofficial bugfix release of that mod (see this thread). That release has the screen update patch already applied to it.

Apart from that, I can't help you any further unless you specify what "not working" means in this case. Maybe you're just confused about what this patch actually does? In that case, re-read this thread and watch the sections of that let's play video I linked to.

Re: Customized Screen Update Code For Keen 4-6

Posted: Mon May 31, 2021 17:14
by spikey
Fully aware of what the patch does, hence why I'm looking to use it! The game won't load with the fix added to the bottom of the patch (before the %end). It gives an error in DOSBox. I can be more specific if that's helpful.

Thanks for the link, that seems like a useful thread. Great work, by the way. And thanks for your various Apogee-related work over the years.

Re: Customized Screen Update Code For Keen 4-6

Posted: Mon May 31, 2021 20:34
by K1n9_Duk3
The version of CK4PATCH that comes with the official download for "Keys of Krodacia" is ancient and hopelessly outdated (v0.9.0 beta from 2003). That old version doesn't support the number formats used in my patch script. If you replace that version with a more recent one (or use my patching utility), then the patch should work fine.

I did replace the old CK4PATCH.EXE with a more recent one in my unofficial update for "Keys of Krodacia".

Unfortunately, you can't replace the old patcher for all mods or level packs. Some very old patch files use quirks that simply won't work in the more recent versions of CK*PATCH (my patcher doesn't support those, either), so you would need to edit those patches manually to make them work correctly.