I am lost, living inside myself...

This is a discussion / support forum for the Hugo programming language by Kent Tessman. Hugo is a powerful programming language for making text games / interactive fiction with multimedia support.

Hugo download links: https://www.generalcoffee.com/hugo
Roody Yogurt's Hugo Blog: https://notdeadhugo.blogspot.com
The Hugor interpreter by RealNC: http://ifwiki.org/index.php/Hugor

Moderators: Ice Cream Jonsey, joltcountry

User avatar
Tdarcos
Posts: 9333
Joined: Fri May 16, 2008 9:25 am
Location: Arlington, Virginia
Contact:

I am lost, living inside myself...

Post by Tdarcos »

If you follow what goes on here and over at Caltrops, you may be aware that Jonsey hired me to write a web-based interpreter for Hugo. And so, I have to figure out how to interpret the .hex files it generates.

Now I've got a problem. I've read the manual, I've read the original Tessman code, and I still can't figure it out. (The Hugor interpreter is simply a remake of the interface, the interpreter it uses is Tessman's unmodified code.)

To make things simple I picked one Hugo file, Guilty Bastards, I downloaded a hex editor so I am also viewing the file in hex locally as well as reading it in the PHP program off my server.

The format of a hugo .hex file has a 64-byte header that tells where everything is. The first 11 bytes aren't important. It's the next 14 bytes, 7 words.
Codestart
Property Table
Event Table
Array Table
Dictionary Table
Special Words Table

At first I was having some trouble until I realized that the items that are tables are segments, so each address is multiplied by 16 (and implicitly is on a 16-byte boundary). This allows each table to be up to 64K and allows a 16-bit address to cover up to 1 megabyte. The book mentions the addresses were divided by 16, so this sounds correct

Each table is a pointer, and the first two bytes it points to is the size of the table. Well, anyway, it seems to be right, but I have doubts, until I get to the dictionary table.

To thwart casual browsing of a compiled game, all text strings have 20 added to each character. Well, what lead me to have questions is that reading the dictionary table, it says it has about 1300 entries. Which sounds high but if every possible word is an entry that could be the case. Now, each entry is essentially a Pascal string, a single byte length followed by the string. Well, when I get to the third byte of the dictionary table, I'm getting 0 bytes. This makes no sense, who would be storing null strings in the dictionary table?

There's something here I'm not getting and I'm not sure what I'm doing wrong. I'm pulling integers as 16-bit little-endian integers, in which there are two characters, you take the second byte, multiply it by 256 and add the first byte, e.g. $0002 is 512.

The way the code is written seems to imply this is the correct interpretation. So the thing that I'm not sure about is the segmentation orientation, I'm thinking either I'm interpreting this wrong or there's some offset being used that I'm not getting.

So I know I'm doing something wrong, but I'm not exactly sure what. I think I'll go back and read the compiler this time and see how it writes the file.

I learned a long time ago - unfortunately, I don't always follow it as well as I should - that when you get in trouble to start looking for help early, don't keep digging a bigger hole.

This should be simple but there's something I am not getting. If anyone has any suggestions or ideas I'd love to hear them.

In the mean time I'll keep slogging and hopefully I'll find a solution. It could be that segments are actually treated differently than integers, that segments are big-endian rather than little-endian. Or something else strange.

Or maybe I have to read the file into an array and handle it as memory as opposed to reading it as a file. Shouldn't make any difference, but I can't be certain.

UPDATE Since I wrote this, I think I'm worrying too much. I had made a slight error in reading the table and had an off-by 1 error. Once I changed this, the dictionary table looked exactly right, a bunch of strings.

I had not presumed someone would create a 0-length string, but that's exactly what the first entry in the table is. When I had the system simply treat a null string as a null string and don't read any characters, it works and I see a bunch of strings.

So I think I was just overworrying. I feel a lot better.



----
Title quote from Gino Vanelli. At this point, as his other song "I Just Wanna Stop," says, on the whole I'd rather be in Montreal.
Alan Francis wrote a book containing everything men understand about women. It consisted of 100 blank pages.