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