Change 'background' tiles

Completed patches for Keen1.
Post Reply
KeenRush
Patch Maker
Posts: 1988
Joined: Sun Aug 31, 2003 2:52 pm
Location: Sand Yego
Contact:

Change 'background' tiles

Post by KeenRush »

Originally posted by adurdin.

This is a complex patch, which changes the 'background' tiles in Keen 1 -- more specifically, it means that the first tile in each row of the tileset (there are 13 tiles in a row) becomes the background for any door or collectable item on the same row. Here is the patch file for Keen 1:

Code: Select all

%ext ck1
%version 1.31

%patch $4409      $26 $8B $07 $B6 $0D $F6 $FE
%patch $4410  $F6 $EE $26 $89 $07 $E9 $60 $01

%patch $4482  $E9 $74 $FF
%patch $44BA  $E9 $3C $FF
%patch $4513  $E9 $E3 $FE

%patch $28EC                  $26 $8B $07 $B6
%patch $28F0  $0D $F6 $FE $F6 $EE $26 $89 $07
%patch $28F8  $03 $1E $08 $6C $03 $1E $08 $6C
%patch $2900  $26 $89 $07 $90 $90 $90 $90 $90

%end

Note that if you use this patch, you should ignore the original assignment of doors and collectable items, and instead rearrange them to suit your choice of background tiles etc. If you don't, bad things will happen: for example, Keen will die when he tries to open a yellow door or gets a raygun or the pogo stick, and he'll never be able to get through any other door. But some results might be considered good: he could get as many joysticks as he wanted, and hence as many points. Bonus points if you can explain all this.

Now, before you start re-using tile 143 for a totally different purpose, I should mention that there are two other references to tile 143 that I could find in the code--but I'm not sure what they do. Anyone who can tell me the other occurrences that will cause one tile to be replaced with this background tile will get mega bonus points.

Finally, for those who are interested in how this patch works, here is the assembly code that makes up the Keen 1 version of the patch (it's the same for Keen 2 except with a few different offsets):

Code: Select all

; At location 4409:
; Change point item collection so the background tile used is the leftmost tile in the row
; Store the tile in ax
es:
mov ax, word ptr [bx]
; Divide by 13, multiply by 13 to get replacement tile in ax
mov dh, 0D
idiv dh
imul dh
; Put the new tile on the map
es:
mov word ptr [bx], ax
; And continue
jmp 4578
; Actually, this now leaves us with 40 unused bytes here...
; I wonder what we could do with those...

; At locations 4482 (joystick etc.), 44BA (raygun and pogo), 4513 (keycards)
; Change so that they use the same tile replacement as point item collecting
jmp 43F9


; At location 28EC (when door opens)
; Change so that they replace with the leftmost tile in the row
; Store the tile in ax
es:
mov ax, word ptr [bx]
; Divide by 13, multiply by 13 to get replacement tile in ax
mov dh, 0D
idiv dh
imul dh
; Put the new tile on the map
es:
mov word ptr [bx], ax
; Move to the next row
add bx, word ptr [6c08]
add bx, word ptr [6c08]
; Put the new tile on the map
es:
mov word ptr [bx], ax
User avatar
Fleexy
Site Admin
Posts: 490
Joined: Fri Dec 12, 2008 1:33 am
Location: Bloogton Tower

Post by Fleexy »

I know the other occurances of the background tile: 1) the raygun tile (it has different code, for some reason). 2) doors (they referance 143 in a different way).

May I claim my MEGA BONUS POINTS now, please?

Big thanks to anyone who can tell me why there are 2 blank gray tiles in the K1 tileset.

--Fleexy
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

No, I figured them out before you, I claim supremacy! (See my doors patch for example.)

The two gray tiles are because the original Keen 1 setup is not quite perfect; if you make an item tile at the very bottom of the tileset, when got it will leave behind a different tile. Like the above patch for 'rows', but here the rows are exceedingly long. Before background patches, I believe this was used to allow two backgrounds for items in some mods.
User avatar
adurdin
Site Founder
Posts: 549
Joined: Fri Aug 29, 2003 11:27 pm
Location: Edinburgh, Scotland
Contact:

Post by adurdin »

I hereby grant MEGA BONUS POINTS to Fleexy for resurrecting this thread :)
gerstrong
Posts: 63
Joined: Sun Jan 25, 2009 3:21 pm

Post by gerstrong »

Hello, I have been developing on CKP since december 2008 and I'm trying to improve the tile reading.

143 was the number which caught my attention. Can somebody tell me which numbers are used? I'm talking about tile that is changed, when Keen picks up an item or opens a door, etc.

Some mods use tile with different backgrounds. EP1 only uses items with gray background. EP2 is also interesting...

Does somebody know how the DOS program know which tile it has to take in order to get the right background tile?

Thanks in advance!
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

It's simple, they're told. In Keen 1 there are several references to tile 143, such as when doors are opened (Replace top and bottom of door) falling block (In this case use the black tile), etc, etc. Usually you just have to search the code for the tile number.

Andy's patch makes things a lot simpler, making everything use the same routine rather than relying on their own little bits of code, in a way Keen 3 is LESS complicated than Keen 1/2, though more flexible.

A breakdown of the patch, as figured out by me and Fleexy some time ago: (Which was removed when the topic was moved here, bad Keenrush!)

Code: Select all

#Change item tiles to use tiles at the end of each row,
#note the $0D, doubble this and stuff becomes the first tile in
#every 2 rows, triple it, 3, etc
%patch $4409      $26 $8B $07 $B6 $0D $F6 $FE
%patch $4410  $F6 $EE $26 $89 $07 $E9 $60 $01

#Change keys, items, etc to use point tiles instead
%patch $4482  $E9 $74 $FF #Affect ship parts
%patch $44BA  $E9 $3C $FF #Affect raygun, pogo
%patch $4513  $E9 $E3 $FE #Affect keycards

#Change doors so they do the same,
#here we overwrite TWO references to 143
%patch $28EC                  $26 $8B $07 $B6
%patch $28F0  $0D $F6 $FE $F6 $EE $26 $89 $07
%patch $28F8  $03 $1E $08 $6C $03 $1E $08 $6C
%patch $2900  $26 $89 $07 $90 $90 $90 $90 $90 
Keen uses tile (grey background) to replace most tiles. Same with Keen 2. However, note that Keen 2 makes use of a 'bug' in the code that means that collectable tiles more than about half way down the tileset will become a DIFFERENT tile when got (Not doors!) So even unpatched you have a choice of two backgrounds.

Deleting a section of this patch will simply revert various things back to 'normal'; thus you can make ALL doors use 143 by not using those last few lines. This leads even more flexibility to the patch.
gerstrong
Posts: 63
Joined: Sun Jan 25, 2009 3:21 pm

Post by gerstrong »

thanks a lot levellass, this patch is really nice. However I want to know what the original game does. Maybe I can use the addresses to figure it out.

Is this some sort of loop with every $0D repeating? There must be a value(reference) which is always changed. I only want to know which of them is. I'll check it out closely. As the values must be of word size, it shouldn't be that difficult to figure it out.

About Keen 2 and the bug. What you mean with halfway down the tileset also happens in episode 1. Be careful. You don't notice that, because Ep1 doesn't have item tiles halfdown the tileset. But mods like silcar 1 use item tiles half way down, and you see that they don't use 143, when you play them. And I'm sure, that they use more than 2 different tiles which can be changed (See Silcar 4). The question here is, what algorithm is used for that change, so to get number. If you say halfway down, maybe it is logarithmic. And I don't think, that it is a bug.

But I think the patch code you posted tells it.

EDIT: Sorry, I have overseen the first post. THank you again
gerstrong
Posts: 63
Joined: Sun Jan 25, 2009 3:21 pm

Post by gerstrong »

Looking at the assembler code, there is just one thing I would like to know. How does the original game proceed the to be changed tiles? I really would like to know.
Post Reply