What is wrong with my metatile routine? (ASM6 quirk)

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
koitsu
Posts: 4214
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: What is wrong with my metatile routine? (ASM6 bug found)

Post by koitsu » Wed Feb 06, 2019 4:01 pm

Note: I did not change the Subject of the thread to include "(ASM6 bug found)". Someone else did that, and thus decided it's a bug -- and that's completely subjective.

It's a non-user-friendly quirk/bug that can potentially cause very unexpected problems (thread is proof).

***I*** do not care if it gets "fixed" or doesn't. What matters more, IMO, is that if it isn't "fixed" that the documentation be updated to reflect this fact (model/design). Remember: I am strong advocate of assembly programmers needing to read their assembler's documentation (and assemblers without documentation should be ignored). If a design/quirk/whatever is not documented, it's not the user's fault. So, a small paragraph describing this nuance in readme.txt would be enough, IMO.

But I will say existing/established assemblers over the past 40 years behaved more... shall I say... "intuitively" in this regard (parsing). Many enforced strict syntactical compliance for this exact reason -- and that adherence is important.

What I will say, however, is that there *are* established assemblers with good/excellent documentation of syntax, (and, well, everything!). Merlin and ORCA/M are two such examples, but this is far from limited to just those two:

Merlin 8/16:
Capture.PNG
ORCA/M:

Code: Select all

Each line may begin with a label, which is required for a few directives. The label must begin
in column 1, and cannot contain embedded blanks. Each label starts with an alphabetic character,
the tilde (~), or the underscore (_), and is followed by zero or more alphanumeric characters, tildes
(~) or underscores (_). Both tildes and underscores are significant. Labels may be as long as 255
characters. All characters are significant.
Note that labels starting with the tilde character are reserved for use in macros and libraries
supplied by the Byte Works. To avoid conflicts with the standard libraries, you should avoid use
of the tilde.
It is best not to use the single character A as a label, since it can cause confusion between
absolute addressing using the label A and accumulator addressing.
"Column 1", by the way, means literally "the first byte/character at the start of a line" (think: an 80-column text terminal). People who indent their labels and code would throw an absolute hissy fit over this, I assure you. (Remember what I said earlier about spacing?)

Other assemblers require a colon (:) after a label. Others don't allow labels on a single line by themselves (i.e. require an opcode after a label). Others have other nuances, or a combination of these. It all varies. There is literally no standard or norm, thus it becomes very hard to compare assemblers to one another (and further proves why switching from one to another is often painful). Many don't even document these nuances -- instead the programmer finds out the hard way (and accepts it; whinging over syntax is more of a post-90s thing.)

Off-topic-yet-sort-of-not: I spent 2 hours of my time yesterday writing up how 21 different assemblers allow forcing of absolute addressing, and I really don't want to spend several more hours writing up how many different assemblers handle different syntaxes; the term "time vampire" comes to mind. (I will note that in that post, I link to my Assembler Manuals Dropbox directory that has many different manuals. Web-based manuals I do not care to archive/copy. I urge anyone pondering assembler variances or comparisons to take the time to read through what I put there.)

samwise970
Posts: 20
Joined: Tue Oct 17, 2017 12:13 am

Re: What is wrong with my metatile routine? (ASM6 bug found)

Post by samwise970 » Wed Feb 06, 2019 4:17 pm

I changed the title, because I thought it was interesting and people may want to read. I'll change it again to reflect that it's a subjective opinion.

User avatar
tokumaru
Posts: 11443
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: What is wrong with my metatile routine? (ASM6 bug found)

Post by tokumaru » Wed Feb 06, 2019 4:24 pm

koitsu wrote:But I will say existing/established assemblers over the past 40 years behaved more... shall I say... "intuitively" in this regard (parsing).
And from what I can tell they also offered much less in terms of features, which made the parsing phase much more straightforward. From what I've seen, people used to hardcode the addresses of variables, they didn't use macros or repetition to automate some of the code generation... It's like assemblers hardly did anything more than manage labels.

Once you start adding more functionality and allowing more versatility, quirks are bound to appear. ca65 for example is extremely feature-packed, and the result is that its macro and scope functionalities have tons of quirks. ASM6 is a much simpler program, but the fact it's multi-pass makes it very versatile. I guess it is indeed somewhat lenient with the syntax because it tries to accommodate aspects from many other assemblers, and that may be a problem after all.

I definitely agree about documenting these kinds of quirks in the official manuals.

Rahsennor
Posts: 473
Joined: Thu Aug 20, 2015 3:09 am

Re: What is wrong with my metatile routine?

Post by Rahsennor » Wed Feb 06, 2019 4:41 pm

xa65 does the same thing, and I get bitten by it on a regular basis. Pre-defining labels named after all the 65C02/65816 opcodes can help (assuming the assembler throws errors on duplicate labels), but it doesn't fix the more serious problem of typos silently producing broken code, which is one of the worst possible language design flaws, IMO.

If I were designing an assembler and wanted it to use this syntax, I'd add [an option for] warnings on unused labels. I don't know if asm6 has such an option, but xa65 doesn't appear to.

User avatar
tokumaru
Posts: 11443
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: What is wrong with my metatile routine? (ASM6 quirk)

Post by tokumaru » Wed Feb 06, 2019 4:52 pm

Warnings on unreferenced labels is a good idea!

Preemptively defining problematic labels so you don't do it by accident later also an interesting idea.

tepples
Posts: 21720
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: What is wrong with my metatile routine? (ASM6 bug found)

Post by tepples » Wed Feb 06, 2019 8:20 pm

koitsu wrote:"Column 1", by the way, means literally "the first byte/character at the start of a line" (think: an 80-column text terminal). People who indent their labels and code would throw an absolute hissy fit over this, I assure you. (Remember what I said earlier about spacing?)
I myself had such a hissy fit over use of "column 1 means label" convention in RGBASM, an assembler targeting the Game Boy CPU, that I ended up writing a preprocessor to dedent labels so that I could use a folding editor. Input is code with "colon means label" convention; output is code with "column 1 means label" convention. I'll probably end up having to do the same thing to convert ca65 code to ASM6 code in order to make my audio driver usable by ASM6 users.

User avatar
slembcke
Posts: 170
Joined: Fri Nov 24, 2017 2:40 pm

Re: What is wrong with my metatile routine? (ASM6 quirk)

Post by slembcke » Wed Feb 06, 2019 9:11 pm

Hmm. I
tepples wrote:I myself had such a hissy fit over use of "column 1 means label" convention in RGBASM, an assembler targeting the Game Boy CPU, that I ended up writing a preprocessor to dedent labels so that I could use a folding editor.
I flirted with using macros to define labels so that I could indent them. It worked, but I feel like I was purposefully using RGBDS wrong, lol.

User avatar
Kasumi
Posts: 1289
Joined: Wed Apr 02, 2008 2:09 pm

Re: What is wrong with my metatile routine? (ASM6 quirk)

Post by Kasumi » Thu Feb 07, 2019 10:34 pm

Interesting! I also don't see it as a bug, just the price to pay for the convenience of not needing to add : to labels/making whitespace before the line starts not matter.

User avatar
tokumaru
Posts: 11443
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: What is wrong with my metatile routine? (ASM6 quirk)

Post by tokumaru » Thu Feb 07, 2019 10:55 pm

Speaking of macros, another way to avoid this quirk is to create macros named after all the unsupported instructions you want to avoid, and have them stop assembly.

Post Reply