what is the point of these other things? Do they help my code run better?
Organization and speed. Your code will be faster if it only has to initialize one external variable.
Also since I'm gonna have SO many variables that I'm gonna have to do this for, wouldn't eat be easier to read and take less effort just to use my above idea with longs? Or am I missing something here?
It isn’t easier to make twice as many external variables for each one than to make a single structure that is easy to edit for each.
It is correct to make a structure to make this type of data structure in the game.
When I try this I get an error: Array too large. So I guess that idea is going out the window, unless you have some kind of suggestion? And that is the CLOSEST static address I could find to the area I will be editing.
And when I try my technique (which probably sucks, lol):
…
I get this error IF I use rooms as a global....
ERROR: Pos: 93 Code emition failed! File: (null)
ERROR: Pos: 93 Unable to set the initialization data for “extern” global “rooms” (error evaluating second initializer). File: (null)
....but if I declare rooms it under lock it works fine. Of course then it's not global and I have to declare it in each function it is used in. Which means of course that I am screwing up AGAIN somehow.
There is no such thing as a structure that large (0x10299B4 bytes).
You are taking a pointer to the ROM base and using that as if it was a huge structure.
The preimise is technically workable, except that such large number, when used this way, cause other problems (as you noticed).
To keep stack sizes sane, I force a maximum limit on the length of pre-defined arrays.
This is standard in C as well.
But you aren’t actually using a pointer to the rooms.
Your pointer points to the start of the ROM image (hopefully, since that is what you
should be using on emulated games), and all the ROM-static data in the game is an offset from there, though usually a very huge offset, not actyally part of a structure.
In this situation, you need to use your second example.
Create a single global at address 0xAD2DCC as type DWORD.
Then for each static location inside the ROM based off this pointer, make a new local external variable using that value + the offset.
And yes, the second external has to be local. It can’t possibly work if both are global. Global = precalculated when compiled. And obviously the address of an external value can't be precalculated if it depends on another value that could change at any time.
When externals are declared as local, the address is recalculated each time the function is called, and only then, so it is not precalculated.
The same behavior would appear in C/C++ if C/C++ had external variables.
L. Spiro