Page 1 of 1

Help with Pagan 8 disassembled code...

Posted: Wed Oct 28, 2015 8:57 am
by lazar0
Hi guys,

a bunch of time has passed since my last visit... and, congrats for the prize for the Fan Project of Ultima Codex.

All right, here goes my question, let's see if someone of Pentagram team can help me.

I'm trying to do the spanish translation for Pagan, I had talked about it years ago, but no tolos... so, I decided to do my own, but I needed to disassemble EUSECODE.FLX CLASSES to check what they were doing.

Until now I interpreted all the major code, but there is something in one EUSECODE CLASS, that I don't know what is doing.

Let's see the disassembled code (a portion):

==============================
.
.
CODE
.
.
B976: 57 spawn 00 02 057C:1090 (METHOD::1090)
B97D: 5E push retval
B97E: 54 implies 01 01
B981: 12 pop temp
B982: 53 suspend
B983: 52 jmp 0006h (to B98C)
B986: 52 jmp 0000h (to B989)
--->> B989: 52 jmp 6711h (to 1209D)
B98C: 62 free string [BP-07h]
B98E: 62 free string [BP-09h]
B990: 62 free string [BP-0Bh]
B992: 62 free string [BP-0Dh]
B994: 63 free slist [BP-0Fh]
B996: 50 ret
B997: 7A end
Destroying FileSystem...
======================================

Ok, let's see in 0xB989 address for this 0x040A CLASS. The end of class it's at 0xB997 address. The selected line (0xB989) makes a JMP instruction OUTSIDE BOUNDARIES of the class. This is the unique class that it is doing this. There are also in the previous code for this class more JMP or JNE instructions that go OUTSIDE BOUNDARIES, AFTER or BEFORE the addresses of this class.

Here goes my question:

Where in the hell are going this JMP & JNE instructions, to another EUSECODE CLASS? How can I know where they go?

I hope you can help with this, is the only thing in all the disassembled code that I can not interpret, and for one file it will be a mess that I can not do a good translation for this game.

Thanks in advance.

Re: Help with Pagan 8 disassembled code...

Posted: Thu Oct 29, 2015 4:49 pm
by wjp
This is probably just an overflow in the disassembly printing code, in which case it would actually jump to 209D.

Re: Help with Pagan 8 disassembled code...

Posted: Thu Oct 29, 2015 9:09 pm
by lazar0
Well, I don't know, and I can not permit to assume this for what I pretend to do.

In any case, how do you have arrived to that conclusiĆ³n? If you can explain me how is calculated x209D (assuming that printing is wrong AND this ONLY happens in 1 of 516 files...) I could accept you're assumption.

Re: Help with Pagan 8 disassembled code...

Posted: Fri Oct 30, 2015 8:02 am
by wjp
Because U8 is a 16 bit engine, all its addresses are 16 bit, so 1209D is really interpreted as 209D.

Re: Help with Pagan 8 disassembled code...

Posted: Fri Oct 30, 2015 7:45 pm
by lazar0
This could be true if there were more situations like this. But I am not really sure about that.

Apart that U8 is 16bit, the shifting in JMPs and JNEs are signed. So, If the game need to do a jump to 209D, it is not represented as 1209D, it would be something like 0xC37B (calculation: 0xFFFF - shifting). The shifting from 0x7FFF will go up, and in your assumption, that is how it would have been calculated.

Maybe I'm wrong, but I've looked a looot of files and when the code needs to go to a previous address (in the own class, of course), it uses the unsigned shifting.

Re: Help with Pagan 8 disassembled code...

Posted: Sat Oct 31, 2015 9:18 am
by wjp
You're misunderstanding how integer arithmetic works.

Re: Help with Pagan 8 disassembled code...

Posted: Sat Oct 31, 2015 10:23 am
by lazar0
Let's see... maybe I had not explained very well because my english is not very good.

If we have this in a JMP/JNE instruction:

0020h: JMP 004Ch

This will go to 20h+4Ch, this would be address 006Ch.

BUT, if we have this:

006Ch: JMP FFB3h

This will go to 6Ch-(FFFFh-FFB3h), this would be addres 0020h.

So, I say that the JMP&JNE are signed because if the jump is over 7FFFh, the jumping goes up.

AND I can confirm that, I'm totally sure. Maybe I'm not explaining well, but I think that the essence is well described.

So, because of that, it is NOT possible (for the question I've proposed in first post), that the jumping goes INSIDE the class. I don't know where is going this jump or what is doing. Unless disasm.exe tool is wrong. But it only happens in one class file of 516 class files.

Re: Help with Pagan 8 disassembled code...

Posted: Sat Oct 31, 2015 1:59 pm
by wjp
There's no difference between signed and unsigned addition of 16 bit ints in a 16 bit world.

Re: Help with Pagan 8 disassembled code...

Posted: Sat Oct 31, 2015 4:27 pm
by lazar0
Well, signed goes from -32767 to 32768 and not signed goes from 0 to 65536. So I say it has some differences, right? At least having in mind which is your intention when using integers in a program.

If not, why can you specify 'unsigned' sentence when declaring vars in C?????

Re: Help with Pagan 8 disassembled code...

Posted: Sat Oct 31, 2015 7:02 pm
by wjp
Because C has more than just 16 bit addition :-)

Re: Help with Pagan 8 disassembled code...

Posted: Sat Oct 31, 2015 7:58 pm
by lazar0
Well, anyway.

If someone can help me with first post, let me know, please. I hope someone of the Pentagram Team knows what is doing that jump. ;)

Thanks!!

Re: Help with Pagan 8 disassembled code...

Posted: Sat Oct 31, 2015 8:34 pm
by Dominus
Well wjp is one of the pentagram team members who made pentagram happen.

Re: Help with Pagan 8 disassembled code...

Posted: Sun Nov 01, 2015 9:45 am
by lazar0
Oh, sorry, I don't know that.

But I don't find the sense to what we were talking about in previous posts.

I can assume disasm.exe is doing what wjp is saying, but it is an assumption or is really a problem with the code in disasm.exe?

I only need to know that. If disasm.exe is doing what wjd is saying, and that is a fact, I can work assuming it then.

Re: Help with Pagan 8 disassembled code...

Posted: Sun Nov 01, 2015 7:07 pm
by wjp
I checked, and what I said is correct.

Re: Help with Pagan 8 disassembled code...

Posted: Sun Nov 01, 2015 7:55 pm
by lazar0
Ok, thank you very much. Then I know what to do when recompiling. This will help a lot!!!

Regards,
David.