ARTICLE: Patching large numbers

CKPatch is a set of patching tools for all Keen episodes.
Post Reply
User avatar
adurdin
Site Founder
Posts: 549
Joined: Fri Aug 29, 2003 11:27 pm
Location: Edinburgh, Scotland
Contact:

ARTICLE: Patching large numbers

Post by adurdin »

If you look at some of the sample patch files, you might notice that, whereas for patching a small (1 byte, 2-hex-digit) value like $32 you'd use the following:

Code: Select all

%patch $4192  $32
When it comes to larger (1 word, 2 byte, 4-hex-digit) values, such as $1F9A, the number must be split up into two sections, which are then reversed, like this:

Code: Select all

%patch $4192  $9A $1F
It gets more confusing when you want to patch even larger (1 dword, 2 word, 4 byte, 8-hex-digit) values, like $01B3902C, which would be done like this:

Code: Select all

%patch $4192  $2C $90 $B3 $01
All this is due to the way that Intel (and compatible) microprocessors store multi-byte numbers. They are stored in so-called 'little-endian' format, with the least-significant byte first. The upshot of this, is that when you are patching a value, you must patch each byte individually, in the reverse of the order which they come in the value.
KeenRush
Patch Maker
Posts: 1988
Joined: Sun Aug 31, 2003 2:52 pm
Location: Sand Yego
Contact:

Post by KeenRush »

I wondered that already. :) Thanks for the explaining.

By the way, what if it would be for example $21E?
Would the correct way be for example:
%patch $4192 $21 $E?
User avatar
adurdin
Site Founder
Posts: 549
Joined: Fri Aug 29, 2003 11:27 pm
Location: Edinburgh, Scotland
Contact:

Post by adurdin »

No; there are only three different integer sizes used by Keen -- byte, word (2 bytes), and dword (4 bytes).
$21E is a word, so you'd patch it as $1E $02.

It's probably best if you always write your values with 2, 4, or 8 hex digits to avoid confusion.
KeenRush
Patch Maker
Posts: 1988
Joined: Sun Aug 31, 2003 2:52 pm
Location: Sand Yego
Contact:

Post by KeenRush »

Ok then. :)
Post Reply