Usefulness

Request patches for Keens 1-3.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

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.
User avatar
CommanderSpleen
Posts: 1017
Joined: Sun Aug 31, 2003 12:11 pm
Location: The Land of Sparkly Things
Contact:

Post by CommanderSpleen »

Andy wrote:Does that stand for If I Remember Keenly?
Indeedity.
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.
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).
Levellass wrote:there is a problem with Xky's method, my strings can be anywhere from 2 to 4 characters long
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
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Um, what?

Quick Basic converts my numbers into strings without adding a zero, same with the hex value, and I can't go if...elseing ever variable in there.

I found a way around variable length strings, I'm abandoning the LEFT$, RIGHT$ approach.
User avatar
adurdin
Site Founder
Posts: 549
Joined: Fri Aug 29, 2003 11:27 pm
Location: Edinburgh, Scotland
Contact:

Post by adurdin »

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
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Thanks, but this is not needed anymore, I must work more on my program, but it's essentially finished. The big problem now remains with the patches themselves; for some reason, random ones don't work.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Actually, this is now useful, I just found out I'll need to calculate negative numbers too.

Tell me, if a call is negative, is there any difference? (Say$14 $00 means 'go forward $14 spaces from the $14; does $F0 $FF mean 'move back $0F spaces from the $FF'?)
User avatar
adurdin
Site Founder
Posts: 549
Joined: Fri Aug 29, 2003 11:27 pm
Location: Edinburgh, Scotland
Contact:

Post by adurdin »

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:

Code: Select all

CS:1503  E9 30 05  ; JMP 1A35  (1A35 = 1505 + 0530)
CS:1505  ...
versus

Code: Select all

CS:1503  E9 30 F5  ; JMP 0A35  (0A35 = 1505 + F530)
CS:1505  ...
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.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

Hmmmn, my Quick Basic won't allow a STRING$ command to add a string to the generated string. (Type mismatch.)

What are jump far and call far instructions? What do they do?
User avatar
adurdin
Site Founder
Posts: 549
Joined: Fri Aug 29, 2003 11:27 pm
Location: Edinburgh, Scotland
Contact:

Post by adurdin »

levellass wrote:Hmmmn, my Quick Basic won't allow a STRING$ command to add a string to the generated string. (Type mismatch.)
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.

Can you IM me (see my profile) and ask me again, if you can't figure it out otherwise?
What are jump far and call far instructions? What do they do?
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...
User avatar
XkyRauh
Posts: 1114
Joined: Sun Aug 31, 2003 9:14 pm
Location: San Diego, California

Post by XkyRauh »

So if JMP is E9, would CALL FAR be 9A? *Stares at code, sweating*
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

I have noticed three types of JUMP in Keen; jump (so many places ahead); jump (so many places from some certain adress) and jump (to some absolute place in the file) They are very useful to look for.
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

On a patch related note, when does the Keen game stop considering a value negative? $FFEF is evidently negative, $00FC is positive, but is say $DDDC positive or negative?
User avatar
ckguy
Posts: 465
Joined: Tue Oct 14, 2003 11:20 am
Location: Wakefield, RI, US
Contact:

Post by ckguy »

Signed word values typically range from -32768 to 32767, so my guess is that $0000 to $7FFF are 0 to 32767 and $8000 to $FFFF are -32768 to -1.
User avatar
adurdin
Site Founder
Posts: 549
Joined: Fri Aug 29, 2003 11:27 pm
Location: Edinburgh, Scotland
Contact:

Post by adurdin »

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? :-)
levellass
Posts: 3001
Joined: Wed Oct 11, 2006 12:03 pm
Location: Ngaruawahia New Zealand

Post by levellass »

I didn't understand any of that, however, it may not matter now as a virus has disabled my computer utterly.
Post Reply