Usefulness
Well; this program makes patches that have no definite location (Don't ask why) so the same patch could start at $1947 or $2123 say, ergo I need to calculate patch locations, then write them to file.
Hmmmn, there is a problem with Xky's method, my strings can be anywhere from 2 to 4 characters long (I.e $12AB to $C7) this means the LEFT$ and RIGHT$ functions return the following:
12AB -> AB 12
2AB -> AB 2A
AB -> AB AB
I think I'll have to use Spleen's method of first manipulating the decimal number, then converting to two hex strings.
Hmmmn, there is a problem with Xky's method, my strings can be anywhere from 2 to 4 characters long (I.e $12AB to $C7) this means the LEFT$ and RIGHT$ functions return the following:
12AB -> AB 12
2AB -> AB 2A
AB -> AB AB
I think I'll have to use Spleen's method of first manipulating the decimal number, then converting to two hex strings.
- CommanderSpleen
- Posts: 1017
- Joined: Sun Aug 31, 2003 12:11 pm
- Location: The Land of Sparkly Things
- Contact:
Indeedity.Andy wrote:Does that stand for If I Remember Keenly?
Aye, that would work for the static code. It's the variables that would necessitate some extra processing (ie. setting the X and Y coordinates of the bitmaps in the status screen patch).Andy wrote:I would have thought you could just store the parts of the patch as strings and just wrote the right strings to the patch file to get the result selected.
You shouldn't have 3-character strings--put a zero in front if there are only three bytes to a value. You can check the length of a string with LEN(), so a simple IF...ELSE statement can filter that problem.Levellass wrote:there is a problem with Xky's method, my strings can be anywhere from 2 to 4 characters long
- adurdin
- Site Founder
- Posts: 549
- Joined: Fri Aug 29, 2003 11:27 pm
- Location: Edinburgh, Scotland
- Contact:
Code: Select all
FUNCTION ToHex4$(i As Integer)
h$ = HEX$(i)
IF LEN(h$) < 4 THEN h$ = STRING$("0", 4 - LEN(h$)) + h$
ToHex4$ = h$
END FUNCTION
PRINT ToHex4$(29) ' will print 001D
- adurdin
- Site Founder
- Posts: 549
- Joined: Fri Aug 29, 2003 11:27 pm
- Location: Edinburgh, Scotland
- Contact:
If you're talking about JMP or CALL instructions, then negative does indeed mean to go backwards (except for the JMP FAR and CALL FAR instructions).
For example:
versus
Note that in the second example, F530 is the 2's complement representation of -0AD0.
In both examples the address which the offset is added to is the address of the instruction immediately following the JMP or CALL.
For example:
Code: Select all
CS:1503 E9 30 05 ; JMP 1A35 (1A35 = 1505 + 0530)
CS:1505 ...
Code: Select all
CS:1503 E9 30 F5 ; JMP 0A35 (0A35 = 1505 + F530)
CS:1505 ...
In both examples the address which the offset is added to is the address of the instruction immediately following the JMP or CALL.
- adurdin
- Site Founder
- Posts: 549
- Joined: Fri Aug 29, 2003 11:27 pm
- Location: Edinburgh, Scotland
- Contact:
Hmm, probably my mistake -- I wrote that off the top of my head, and I might be misremembering the arguments to STRING$... However I don't at the moment have ready access to QBasic or QuickBasic to check it.levellass wrote:Hmmmn, my Quick Basic won't allow a STRING$ command to add a string to the generated string. (Type mismatch.)
Can you IM me (see my profile) and ask me again, if you can't figure it out otherwise?
The x86 instructions JMP FAR and CALL FAR jump to an absolute address (in Keen, it'll be a segment + offset); whereas the normal JMP and CALL instructions have an offset relative to the end of the instruction. You should never have to worry about these when patching Keen 1-3, but with Keen 4-6 it might be necessary to do the occasional CALL FAR...What are jump far and call far instructions? What do they do?
- adurdin
- Site Founder
- Posts: 549
- Joined: Fri Aug 29, 2003 11:27 pm
- Location: Edinburgh, Scotland
- Contact:
CK Guy is absolutely correct. A signed 16-bit two's complement integer is negative if the high bit is 1, and its bit pattern can be derived by inverting all bits of the absolute value and adding 1.
In other words, if the first hex digit is 8, 9, A, B, C, D, E, or F, it's negative. If it's 0, 1, 2, 3, 4, 5, 6, 7, it's positive. And 0x8000 is the smallest negative number (largest absolute value) at -32768, while 0xFFFF is the largest negative number at -1. The positive numbers range from 0x0000 = 0 to 0x7FFF = 32767.
The nicest thing about two's complement from a hardware implementer's view is that addition just works (modulo overflow): if I add 0x4000 to 0x8000, the answer is clearly 0xC000 (as 0x8 + 0x4 = 0xC), which is in decimal -16384, which is clearly -32768 (0x8000) + 16384 (0x4000).
Perfectly clear? :-)
In other words, if the first hex digit is 8, 9, A, B, C, D, E, or F, it's negative. If it's 0, 1, 2, 3, 4, 5, 6, 7, it's positive. And 0x8000 is the smallest negative number (largest absolute value) at -32768, while 0xFFFF is the largest negative number at -1. The positive numbers range from 0x0000 = 0 to 0x7FFF = 32767.
The nicest thing about two's complement from a hardware implementer's view is that addition just works (modulo overflow): if I add 0x4000 to 0x8000, the answer is clearly 0xC000 (as 0x8 + 0x4 = 0xC), which is in decimal -16384, which is clearly -32768 (0x8000) + 16384 (0x4000).
Perfectly clear? :-)