Customized Screen Update Code For Keen 4-6

Here is where to post about the latest Commander Keen fangame or modification you've finished, a new website you've made, or another Keen-related creation.
Post Reply
User avatar
K1n9_Duk3
Vorticon Elite
Posts: 566
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Customized Screen Update Code For Keen 4-6

Post by K1n9_Duk3 » Sun Dec 01, 2019 23:21

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.
Last edited by K1n9_Duk3 on Tue Dec 03, 2019 23:37, edited 1 time in total.
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net

User avatar
Nisaba
Vorticon Elite
Posts: 994
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Customized Screen Update Code For Keen 4-6

Post by Nisaba » Sun Dec 01, 2019 23:28

fantastic!
thanks a whole lot for sharing.
I think it's about time to add this patch to our beloved KeenWiki as well.
"We have come to conquer you all and bring you lots of candy!" | about me | my current project: play Keen mods on a GameBoy |

User avatar
K1n9_Duk3
Vorticon Elite
Posts: 566
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Customized Screen Update Code For Keen 4-6

Post by K1n9_Duk3 » Tue Dec 03, 2019 23:39

Oops. I forgot to put the download link in my original post. Sorry about that.
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net

User avatar
Tormentor667
Vortininja
Posts: 107
Joined: Sat Mar 29, 2008 14:08
Location: Germany
Contact:

Re: Customized Screen Update Code For Keen 4-6

Post by Tormentor667 » Wed Dec 04, 2019 6:35

What exactly is the difference of this code?

User avatar
Nisaba
Vorticon Elite
Posts: 994
Joined: Fri Jan 01, 2016 23:34
Location: The Outpost
Contact:

Re: Customized Screen Update Code For Keen 4-6

Post by Nisaba » Wed Dec 04, 2019 8:00

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.
#-------------------------------------------------------------------------------
"We have come to conquer you all and bring you lots of candy!" | about me | my current project: play Keen mods on a GameBoy |

User avatar
K1n9_Duk3
Vorticon Elite
Posts: 566
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Customized Screen Update Code For Keen 4-6

Post by K1n9_Duk3 » Wed Dec 04, 2019 22:42

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.
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net

User avatar
proYorp
Vortininja
Posts: 158
Joined: Fri Mar 03, 2017 1:56
Location: mspaint.exe

Re: Customized Screen Update Code For Keen 4-6

Post by proYorp » Fri Dec 06, 2019 3:27

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?
"Friendly. Very friendly. Too friendly." :yorp

User avatar
K1n9_Duk3
Vorticon Elite
Posts: 566
Joined: Mon Aug 25, 2008 9:30
Location: Germany
Contact:

Re: Customized Screen Update Code For Keen 4-6

Post by K1n9_Duk3 » Fri Dec 06, 2019 22:02

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).
Hail to the K1n9, baby!
http://k1n9duk3.shikadi.net

User avatar
keropi
Meep
Posts: 1
Joined: Sun Aug 09, 2015 20:40

Re: Customized Screen Update Code For Keen 4-6

Post by keropi » Mon Dec 09, 2019 17:52

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

Post Reply