-
-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ds
content is documented as undefined in ROM sections
#350
Comments
Note that any attempt at making this truly undefined will break backwards compatibility. Case 1: Case 2: many tools assume that the padding byte is used for unused space (free space calculators, for instance). Many build setups rely on these tools. Changing the value output by TL;DR: this behavior is well-known by RGBDS users, and they take advantage of it; avoid another #136 and document it instead of making it truly undefined. |
Warning: rant incoming! Daily reminder that undefined doesn't mean random. It just means that you're not allowed to rely on the value, even if it always happens to be initialized to a certain value in a given implementation. And likewise, it means that when you define memory using My claim, then, would be that it is strictly speaking a user error to use
This makes sense because traditionally in assemblers, However, the documentation doesn't lie, or at least it didn't when it was written. Here's a blast form the past. The original versions of RGBDS, as released by Carsten himself, didn't clear the memory buffers before writing data to them. This was mostly not a problem since in practice they would mostly be zeroed. With the exception of the first 8 or so byte of the ROM, which would contain some junk data, probably because that buffer was Allowing I would strongly oppose any suggestions to randomize the fill value for I would instead propose the following:
Also, as the final part of the rant, I want to ask @aaaaaa123456789 exactly how that free space calculator would work. How could a tool rely on any continuous area of a certain value that's not at the end of a file/bank being empty? How would the tool know that this data was truly empty and not part of a data structure that just happens to be filled with a bunch of zeroes? It seems like such a tool would give wildly inaccurate results for many files. Furthermore, why use a binary analysis tool for output from RGBDS, when the linker can output a perfectly usable map file using the flag |
@nitro2k01 If you want to calculate free space in a ROM, generate two ROMs with two different values of |
@aaaaaa123456789 Ok, that's one way to do it. Either way, the |
Occasionally I use |
@aaaaaa123456789 So then if you are asking the linker explicitly to not use that space for anything useful, why would you want to include it in your free space calculation? Why not just let the linker use it if you consider it to be free? Even without marking it, that space would show up in your tool, since those bytes (if they are actually unused) are filled by the linker and would differ. It's a very niche use case, and even so you could do without
This is more academic than anything since I do support keeping |
Let me propose a compromise: ca65, an assembler targeting the 6502 architecture (and any other architecture for which someone has written a macro pack), has the
The latter form is equivalent to the following but does not occupy three source lines of code:
I propose adding a 2-argument alternate form of My own free space calculator (unused.py) avoids most false positives by requiring a run to be at least 32 bytes long. If a program triggers that, then the program needs a code review anyway in order to improve its data compression so that more can be packed into a 32K flash cart. As for @nitro2k01's suggestion to "output a perfectly usable map file using the flag |
Two-argument The convenience of EDIT: I'm not arguing against two-argument |
@aaaaaa123456789 Just to be clear, what I mentioned in the previous comment was a suggestion on how to reimplement your use case using existing features. It was not a new feature suggestion. The My opposition to using Another "philosophically consistent" way of implementing it would be to let the assembler leave bytes defined by @pinobatch I do like the idea, but I'd implement it rather differently because of my aforementioned philosophical opposition to this use of the
...would output the same data as...
So it would be a shorthand for a |
I agree with @nitro2k01, this looks like a way to abuse the However, I have no strong feelings on what to do about it. |
Imo, just document its current behavior properly. It's not exactly surprising or unintended behavior like #190 was, and people kind of expect it to work this way. Heck, if anything, I'm just going to point to existing behavior of binutils, with its |
Then yeah, a documentation update would probably be the best thing to do. |
I'm currently overhauling RGBDS' man pages, and here is the first draft of the section related to this issue:
|
The word "undefined" should probably be gone from that document. That content has never been undefined. |
It is undefined—in RAM sections. |
In the C standard, "undefined" means "don't effing do this because it can summon time-traveling nasal demons." In the case of |
RAM sections have no content — they are comparable to ELF |
A section like |
That's only reasonable when there is a program loader of some sort — typically the moral equivalent of what the C standard calls a hosted environment. |
But then, what's wrong with notifying the user that there is no such loader in the hardware? (The boot ROM could clear a portion of WRAM, for example.) |
Users expect tools to document their own behavior above everything else. That wording makes it seem like RGBDS may make users believe that RGBDS is making that area undefined. Documenting the GB itself is nice, but it shouldn't get in the way of documenting the tool itself, and listing an environmental constraint amongst tool-specific behavior leads to confusion. |
Anything related to headers is also "an environmental constraint," yet the competing toolchain WLA DX has syntactic sugar for declaring headers on many platforms it supports. Even the 16 KiB size of banks is "an environmental constraint" in a way. |
Which is why you don't say "the |
It actually is a property, in order to avoid creating too large a section. |
Again, I believe this was true in the very early days of RGBDS as I explained in the previous post. RGBDS sometimes wouldn't clear memory before using it as buffers and could leak internal RGBDS state as a result. And while what I observed back in the day was for the first few bytes of the ROM, and I'd have to go back and try to reproduce it for
@aaaaaa123456789 's previous comment reminded me of something:
That's actually incorrect. It supports arguments between 1 and 32768, because the tiny ROM mode exists, which allocates a flat 32 kiB area from $0-$7FFF. Now imagine if someone considered it a property of the |
Well, we do have some sanity checking, which in effect does limit the argument to I really insist on leaving "undefined" in this text because as mentioned above, using |
But the sanity check isn't actually part of the behavior of
And here we come to the true issue, the one that has plagued this toolchain for years: the maintainers actively fighting forms of programming they don't like.
This here is complete nonsense. The fill value of Describing it as undefined when it isn't is the complete opposite of good documentation. Documentation for a tool should primarily describe what the tool does, and using the word "undefined" is confusing because it might mislead users to believe the complete opposite of what actually happens. Except that it gets worse. You say that the fill value is undefined because RAM is undefined, which might lead to people mistakenly believing it is undefined in ROM — which makes the word 'undefined' confusing. But then you go ahead and use that argument yourself as a justification for not relying on the fill value in ROM — meaning that the confusion is completely deliberate! Writing confusing documentation in order to prevent usage of a feature isn't just a mistake; it's downright malicious. Documentation should strive to be truthful and accurate, not confusing and misleading. Doing the latter intentionally is nothing but a disservice to all users of the tool. It's actively harmful. Please stop this nonsense. |
It's not a problem that it's something I like or not, it's that it was never meant for that and it shows. It can only be used for a single value per program (the fill: MACRO
REPT \1
db \2
ENDR
ENDM |
The macro/directive you mention isn't a substitute for And the current behavior is not undefined by any means. It uses a specific value and it uses that value consistently. Once again, documentation should describe actual behavior, and the behavior isn't undefined. Considerations about how someone believes you should use this feature are immaterial — first and foremost, the document should describe how it works, and the word 'undefined' doesn't. |
Well, that's exactly what the proposed snippet above says.
|
Then you have contradictory documentation. It begins by saying it's undefined, but then makes a small note about ROM values. Contradictory and confusing — deliberately so, as you proved a few comments above. If you insist in noting that RAM values are undefined (which they always are due to hardware constraints, making that bit of documentation redundant), then that should be the sidenote, not the part of it that describes actual behavior (i.e., the ROM fill value). Nobody who understands the platform expects RAM to be initialized; it's well understood that a fill value can only apply to ROM. (And those who don't will come across your sidenote — which should clearly mention that the values are uninitialized, which is not quite the same as undefined.) The true tool-specific and directive-specific documentation is that |
The fill value is meaningless when using overlays, though, so The point is that the contents should not be relied on, for example if a new feature is added that changes how empty space is handled. |
Then mention that overlaid ROMs are filled with the underlying ROM's data, and regular ROMs with the fill value. All of this is worth being mentioned. It is the true behavior of the |
Also, if you change how |
Changing the way |
Because overlays are an opt-in feature by definition. If you make non-breaking changes to |
Here is a second draft:
|
Fixed by #455. |
As suggested by #350 (comment) The order `count` then `byte` was decided after some discussion: - First argument consistent with single-arg syntax - Intuitive at least to some people other than myself - Consistent with other assemblers, at least ca65
The content fillled by the
ds
directive in ROM sections is documented as undefined yet is is very well defined.Can a programmer rely on the
ds
areas being filled with the value to-p
or not?Also, it isn't very clear from the command-line usage that this value is used for the
ds
directive. (padding an image is only really relevant to rgblink and rgbfix)The text was updated successfully, but these errors were encountered: