Ghosty Ghost

Use this forum to share and discuss Uzebox games and demos.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Ghosty Ghost

Post by Artcfox »

It looks like this might actually be a bug in packrom or Uzem's handling of the RomHeader. It works fine when I run the GGHOST.HEX file, but when I run the GGHOST.UZE file, it finds a "true" in the mouse field of the RomHeader structure, and then Uzem is enabling mouse support.

Yep, I checked and the RomHeader structure is defined differently in packrom than it is in uzem! The alignment needs to be the same in both, otherwise things like this will happen, and since different compilers arrange things differently, doing an fread() directly into a C structure means that "packed" alignment should be used for both packrom and uzem.

If the previous behavior relied on a weird unspecified alignment, then "packed" should still be used in both cases, but it also means that dummy pad bytes may need to be inserted between some existing variables to maintain backwards compatibility with the implied unspecified alignment.

The other thing that probably needs to be fixed in packrom is the header should be initialized to all zeros before populating any of the fields.

I'll let Uze decide and apply the correct fix for this.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Ghosty Ghost

Post by uze6666 »

Nice catch again. :) I have added to uzem the same packing as gconvert. It's funny that for so many games it works fine and some had this issue.

Commited to uzem140 branch.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Ghosty Ghost

Post by Artcfox »

uze6666 wrote:Nice catch again. :) I have added to uzem the same packing as gconvert. It's funny that for so many games it works fine and some had this issue.

Commited to uzem140 branch.
Awesome! I verified that it behaves correctly for me with the native and web build. (I wasn't sure that Clang/LLVM was going to like your Microsoft-specific fix, but Clang/LLVM seems to handle it okay; it just makes me cringe.) ;)
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Ghosty Ghost

Post by uze6666 »

(I wasn't sure that Clang/LLVM was going to like your Microsoft-specific fix, but Clang/LLVM seems to handle it okay; it just makes me cringe.) ;)
What's the official way to define the packing in GCC then? I have no problem we change it to GCC statndard. GCC mention they included these pragmas , indeed to provide compatibility to VC++.https://gcc.gnu.org/onlinedocs/gcc/Stru ... agmas.html
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Ghosty Ghost

Post by Artcfox »

uze6666 wrote:
(I wasn't sure that Clang/LLVM was going to like your Microsoft-specific fix, but Clang/LLVM seems to handle it okay; it just makes me cringe.) ;)
What's the official way to define the packing in GCC then? I have no problem we change it to GCC statndard. GCC mention they included these pragmas , indeed to provide compatibility to VC++.https://gcc.gnu.org/onlinedocs/gcc/Stru ... agmas.html

Code: Select all

struct S { short f[3]; } __attribute__((packed));
Edit: aligned can only increase alignment, so you need packed to be able to shrink it.
User avatar
uze6666
Site Admin
Posts: 4801
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: Ghosty Ghost

Post by uze6666 »

http://digitalvampire.org/blog/index.ph ... e__packed/

Besides, the current way works so, if it's not broken let's leave it like that.
User avatar
Artcfox
Posts: 1382
Joined: Thu Jun 04, 2015 5:35 pm
Contact:

Re: Ghosty Ghost

Post by Artcfox »

uze6666 wrote:http://digitalvampire.org/blog/index.ph ... e__packed/

Besides, the current way works so, if it's not broken let's leave it like that.
#pragma pack and __attribute__ ((packed)) do the same "dangerous" thing (which doesn't affect us, because the structure actually needs to be packed, and we aren't dereferencing pointers that are unaligned). If you insist on using #pragma pack, then you should use it like this:

Code: Select all

#pragma pack(push, 1) // save current pack setting and set to 1

...

#pragma pack(pop)     // return to previous pack setting
The way you did it doesn't actually restore to the alignment settings that were in use in that file above your #pragma pack(1) statement, it restores them to the compiler default (or what was passed on the command line when the compiler was invoked). That means that changing the order that things are declared in these files may unintentionally change the alignment of everything that follows, which would be a nightmare to debug.

(Since this issue ended up not being an issue with Ghosty Ghost, could you please move this entire tangent starting from my "For some reason when I try running your game" post to a new thread in the "Tools, Documentation & Tutorials" section?)
Post Reply