The NEW Palette Patch: smooth fading and custom darkness pal

Completed patches for Keen1.
Dr. Kylstein
Posts: 120
Joined: Wed Dec 16, 2009 5:20 pm

The NEW Palette Patch: smooth fading and custom darkness pal

Post by Dr. Kylstein »

So far the palette patch has only been used for minor modifications of the standard EGA palette. One reason for this is that the fade-in and fade-out routines are designed for for that palette, and cannot be easily adapted to custom palettes. I can now announce that this is no longer the case! You can change the palette as much as you want and have it smoothly fade to and from black!Even the otherwise unmodified game can benefit, as the new fade routines are much smoother than the originals, using full VGA color! This is demonstrated by the example patch.

This replaces the previous palette patch due to some necessary changes to the palette setting routine. Just copy your custom colors over the ones in the included patch, and it should work as before.

Addendum:
The patch now supports VGA palettes for the light-switch effect! You can completely control the colors used when the lights go out!

Code: Select all

%ext ck1
%version 1.31

# This is the color palette: 16 entries of r, g, b (each 0-63)
%patch $21850
       00 00 00 # black
       00 00 42 # blue
       00 42 00 # green
       00 42 42 # cyan
       42 00 00 # red
       42 00 42 # magenta
       42 21 00 # brown
       42 42 42 # bright gray
       21 21 21 # gray
       21 21 63 # bright blue
       21 63 21 # bright green
       21 63 63 # bright cyan
       63 21 21 # bright red
       63 21 63 # pink
       63 63 21 # yellow
       63 63 63 # white 
# lights out palette
       00 00 00 # black
       00 00 42 # blue
       00 21 00 # green
       00 21 42 # cyan
       21 00 00 # red
       21 00 42 # magenta
       21 10 00 # brown
       21 21 42 # bright gray
       10 10 21 # gray
       10 10 63 # bright blue
       10 42 21 # bright green
       10 42 63 # bright cyan
       42 10 21 # bright red
       42 10 63 # pink
       42 42 21 # yellow
       63 63 63 # white 

#----------------------------------------------------------------------------

# set EGA color register values for VGA pass-thru
%patch $1558B	$00 $01 $02 $03 $04 $05 $06 $07 
                $08 $09 $0A $0B $0C $0D $0E $0F $03

# Set the palette when we go into graphics mode
%patch $6E46 $E8 $60 $FE $90 $90

# Code to set graphics mode and set the palette
%patch $6CA9 $B8 $0D $00 $CD $10 $B8 $13 $10 $BB $00 $01 $CD $10 $B8 $02 $10 
             $1E $07 $BA $3B $25 $CD $10 $B8 $12 $10 $B9 $20 $00 $31 $DB $BA
             $00 $E8 $CD $10 $C3

#support functions
%patch $5B3D $BA $DA $03 $EC $A8 $08 $75 $FB $EC $A8 $08 $74 $FB $C3 $55 $89
             $E5 $E8 $EC $FF $BA $DA $03 $EC $BA $C0 $03 $EC $50 $B0 $14 $EE
             $8B $46 $04 $EE $58 $EE $89 $EC $5D $C3 $55 $89 $E5 $83 $EC $08
             $31 $C0 $31 $DB $89 $46 $F8 $8A $87 $00 $E8 $2A $46 $04 $73 $02
             $31 $C0 $89 $46 $FA $43 $8A $87 $00 $E8 $2A $46 $04 $73 $02 $31
             $C0 $89 $46 $FC $43 $8A $87 $00 $E8 $2A $46 $04 $73 $02 $31 $C0
             $89 $46 $FE $43 $E8 $B7 $10 $FF $46 $F8 $83 $FB $60 $75 $C8 $89
             $EC $5D $C3
%patch $6C5B $55 $89 $E5 $BA $C8 $03 $8B $46 $04 $EE $BA $C9 $03 $8B $46 $06
             $EE $8B $46 $08 $EE $8B $46 $0A $EE $89 $EC $5D $C3

#VGA palette fading
#fade in
%patch $6C49 $B9 $40 $00 $E8 $EE $EE $89 $C8 $48 $50 $E8 $11 $EF $44 $44 $E2
             $F2 $C3 
#fade out     
%patch $6C8D $B9 $40 $00 $E8 $AA $EE $B8 $40 $00 $29 $C8 $50 $E8 $CB $EE
             $44 $44 $E2 $F0 $31 $C0 $50 $E8 $A5 $EE $44 $44 $C3

#VGA lights
# delay value-----------------------------v
%patch $3592 $C7 $06 $1E $82 $01 $00 $B8 $01 $00 $50 $E8 $43 $8B $44 $44 $31
             $C0 $50 $E8 $A4 $25 $44 $44 $C3 # on
# delay value-----------------------------v
%patch $35B2 $C7 $06 $1E $82 $00 $00 $B8 $01 $00 $50 $E8 $23 $8B $44 $44 $B8
             $01 $00 $50 $E8 $83 $25 $44 $44 $C3 # off

%end
Last edited by Dr. Kylstein on Thu Jul 08, 2010 9:59 pm, edited 4 times in total.
lemm
Posts: 554
Joined: Sun Jul 05, 2009 12:32 pm

Post by lemm »

Very Cool!
User avatar
XkyRauh
Posts: 1114
Joined: Sun Aug 31, 2003 9:14 pm
Location: San Diego, California

Post by XkyRauh »

I copied all these files into a core copy of Keen1, and then did a "ck1patch keen1.pat" and didn't notice much of a difference. Can you give an old bean some advice on how to view this wizardry? :)
Dr. Kylstein
Posts: 120
Joined: Wed Dec 16, 2009 5:20 pm

Post by Dr. Kylstein »

XkyRauh wrote:I copied all these files into a core copy of Keen1, and then did a "ck1patch keen1.pat" and didn't notice much of a difference. Can you give an old bean some advice on how to view this wizardry? :)
The effect is subtle, but look at the way the unpatched game does fade-ins and fade-outs and then compare it to the patched version. You can also put a light switch in one of the levels and see how the darkness effect has changed.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Very nice! Some other patches may have to be reworked a bit to make sure they're compatible (And I'm curious as to why everyone prefers their patches in binary files, they could have easily been made into one, not that long patch.)

EDIT: There are two copies of the 'main' palette; couldn't you use just one, and get the game to read those values both when modifying and when retoring the graphics? Or are you hoping to use the two palettes for extra patch flexibility?
User avatar
XkyRauh
Posts: 1114
Joined: Sun Aug 31, 2003 9:14 pm
Location: San Diego, California

Post by XkyRauh »

Dr. Kylstein wrote: The effect is subtle, but look at the way the unpatched game does fade-ins and fade-outs and then compare it to the patched version. You can also put a light switch in one of the levels and see how the darkness effect has changed.
Ah, cool. :) Thank you!
Dr. Kylstein
Posts: 120
Joined: Wed Dec 16, 2009 5:20 pm

Post by Dr. Kylstein »

levellass wrote:Very nice! Some other patches may have to be reworked a bit to make sure they're compatible (And I'm curious as to why everyone prefers their patches in binary files, they could have easily been made into one, not that long patch.)
I think the only significant difference in the memory map from the old palette patch is the second palette. If there's a better place to put it, I'd like to know. As for the binaries, I don't have any tools that output CKPATCH compatible hex.
levellass wrote: EDIT: There are two copies of the 'main' palette; couldn't you use just one, and get the game to read those values both when modifying and when retoring the graphics? Or are you hoping to use the two palettes for extra patch flexibility?
The patch works by modifying the palette in memory and then passing it to the int $10 service to load into the DAC. Therefore I need a copy of the palette to to refer to when fading in. I don't think there's any avoiding having two copies (edit: unless I modify the registers one at a time), but I may be able to make the game do the duplication on it's own if I can find some code space.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Thanks to Lemm we have plenty of code space. At a pinch I could free some up easily enough.

I think the only significant difference in the memory map from the old palette patch is the second palette. If there's a better place to put it, I'd like to know. As for the binaries, I don't have any tools that output CKPATCH compatible hex.
There are some patches I know of that were made compatible with the old palette patch, since they used the 'empty' space at the start of the data segment. Notice, for example, that the custom status box patch places the name of the status box file 'Status.ck1' $00 right smack bang where your palette is.

I don't have any tools that output CKPATCH compatible hex.
I coded one up ages ago, drag-and-drop of binary file, it outputs the patch. I've written up the palette patches, including yours, here: http://www.shikadi.net/keenwiki/Patch:Palette (I'm using hex on the wiki for now to avoid linking to easily moved\deleted binary files.)
Dr. Kylstein
Posts: 120
Joined: Wed Dec 16, 2009 5:20 pm

Post by Dr. Kylstein »

Levellass, could you send me that converter program? I've made a better version of the patch that I would like to release.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Dr. Kylstein
Posts: 120
Joined: Wed Dec 16, 2009 5:20 pm

Post by Dr. Kylstein »

I've edited the first post with the new version of the patch. Changes:
-no more duplication
-the palette is out of the way of any existing patches
-the fade-in is nicer
-fades are faster in DOSBox and should be more compatible with real hardware
-light changes come with a delay as in the original. I've marked the spot where the delay value is since the offset changed from what existing patches use.
-binary converted to hex and included in the patch file.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

My game keeps crashing when I try to pick up the whiskey ship part, is this normal?
Draik
Posts: 117
Joined: Sat Jul 26, 2008 8:52 am
Contact:

Post by Draik »

Crashed when I grabbed the battery. Fix it, this is pretty neat other than that!
Dr. Kylstein
Posts: 120
Joined: Wed Dec 16, 2009 5:20 pm

Post by Dr. Kylstein »

levellass wrote:My game keeps crashing when I try to pick up the whiskey ship part, is this normal?
Draik wrote:Crashed when I grabbed the battery. Fix it, this is pretty neat other than that!
The video setup function was too long and corrupted the function for picking up parts. I moved it, and it works now.
thehackercat
Posts: 69
Joined: Sat Sep 26, 2009 10:49 pm
Location: Mississippi, USA

Post by thehackercat »

I'm seeing endless possibilities! There could be submarine levels, where the red combat lights are turned on, bathing everything in an infrared glow! Or there could be crazy puzzle rooms that inverted colors at the flip of a switch!
Post Reply