This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

asm6n

asm6n
by on (#232474)
This is a modified version of asm6 that I use.

Code:
1.7.1
   * Changed BIN directive to work like HEX, but for binary
   * Added ! operator to force ABS/X/Y instead of ZP/X/Y
   * Added RAM,ENDRAM, WRAM,ENDWRAM, SRAM,ENDSRAM directives
   * Added RS alias for DSB directive
   * Added WORDB, DWB, DCWB, DC.WB directives (define word, big-endian)
   * Added BANK directive and ? operator to retrieve a label's bank number
   * Added PRINT directive
   * Added support for exporting Mesen (.mlb) label files [based on freem/Sour asm6f code]
   * Added support for exporting all RAM lables to a lua file
   * Added support for stable illegal opcodes [based on freem asm6f code]
Re: asm6n
by on (#232479)
Thanks for that.

Could you do an error message with PRINT?

like if Program Counter > $C000, print "error, bank full"
Re: asm6n
by on (#232490)
Isn't that what the ERROR directive is for?

Good job! You added the forced absolute addressing and bank management that everyone was missing. :) Would be nice if these were included in Freem's fork.
Not sure if the "?"-character is the right one for this operator though.


BTW what exactly does the RAM, WRAM etc directives do?
Re: asm6n
by on (#232493)
Thanks for this work.

Thought: Is there any chance this work could be merged with asm6f, given that at least part of your work was based on asm6f? Having several forks of a popular common-use assembler (we now have: asm6, asm6f, and asm6n -- and maybe more) becomes very annoying very quickly for folks. Collaboration is the key to getting said things implemented universally and benefits everyone. Edit: it seems the asm6f maintainer asked this exact question which may have prompted this thread here.

Feedback:

1. None of these changes are documented in the readme, or an additional readme, in the zip file. This is not good. Assemblers need reliable/proper documentation, with short/simple examples if possible.

2. Does the BIN/INCBIN modification you did not break backwards-compatibility with the existing syntax? I'm staring at the original asm6 documentation and comparing it to what you said. Documentation reference:

Code:
INCBIN foo.bin, $200, $2000   ;read $2000 bytes, starting from $200
HEX 456789ABCDEF              ;equivalent to DB $45,$67,$89,$AB,$CD,$EF

3. I question the use of ? for this purpose. Historically, many assemblers have used the ! operator to force absolute addressing. Not to sound rude, but I'm pretty sure I've talked about this before in other threads. Was question-mark chosen due to concerns over what the parser would do, or what?

4. I do not understand the purpose of the RAM,ENDRAM, WRAM,ENDWRAM, SRAM,ENDSRAM directives. Please explain/demonstrate.

5. I question the use of \ as the way to retrieve the current bank per the new BANK directive. This absolutely will cause confusion given that the parser itself already uses \ for escaping. Quoting the documentation, under "Numbers and expressions": The characters (' " \) within quotes must be preceded by a backslash (\).

6. What does the PRINT directive do? Is it simply a printf() / classic echo? If so, does it emit to stdout or stderr (yes I can go look at the C code, but I haven't).

Thanks.
Re: asm6n
by on (#232497)
Thanks for posting this!

koitsu wrote:
Thought: Is there any chance this work could be merged with asm6f, given that at least part of your work was based on asm6f? Edit: it seems the asm6f maintainer asked this exact question which may have prompted this thread here.


Indeed, that's why I've asked. No promises on when this stuff will be merged, but hopefully I can get to it this weekend.

koitsu wrote:
6. What does the PRINT directive do? Is it simply a printf() / classic echo? If so, does it emit to stdout or stderr (yes I can go look at the C code, but I haven't).


Specifically, it seems to only output text when verbose mode is enabled:
Code:
// Prints printf-style message if verbose mode is enabled.
static void message( const char fmt [], ... )
{
    if ( verbose ) {
        va_list args;
        va_start( args, fmt );
        vprintf( fmt, args );
        va_end( args );
    }
}


Messages go to standard output/stdout.

Other short comments:
- '!' makes more sense to me than '?' for absolute addressing as well.
- I share the same concern with relation to the '\' character for bank stuff, but can't think of a better solution at the moment.
Re: asm6n
by on (#232502)
Regarding the bank expression/character being \: I haven't looked at the C code, which is going to dictate the solution (I do not propose a revamp!), but:

If the code can use a string comparison (ex. strncasecmp()) instead of literal character comparison (ex. *buf == '\\'), then I'd suggest using something like {banknum} or some other variant. The reason I recommend using {foo} (curly brackets with a word between them) is because curly brackets aren't used in the expression parser, which allows for clear differentiation between the two (think: foo = ({banknum}/2)+128 or lda #{banknum}/2). I don't suggest some "magic word" like bank that works everywhere because that's probably going to conflict with someone's existing project variable/macro name etc...

Anyway, if a single character comparison is all that's available, then that does limit the choices substantially. Nothing really seems like a good choice given that almost all special characters are used. ` (backtick) might suffice; still ugly but it'd be less conflicting than \.

Also, sorry if this subject/sub-topic is on the verge of bikeshedding. Not my intention.
Re: asm6n
by on (#232504)
Not only ugly, the "`" is typed using a dead key so therefore is very annoying to type on many keyboards as it requires two presses (plus SHIFT on Swedish keyboards).

I heard "^" is a common operator for taking out bank numbers. As long as it doesn't conflict with the XOR operator...
Re: asm6n
by on (#232505)
koitsu wrote:
...

1. I started writing one up that details the changes, I will repost with it. But for now:

2. Only BIN was changed, INCBIN remains the same and it would/does break compatibility. I could change it to something else, if there are any suggestions.

3. I wasn't sure how the parser would handle the ! operator having two functions, so I chose a character that was unused. I dove a little deeper into the code and I believe I have it working with ! having 2 uses.

4. They function just like ENUM / ENDE, but will be included in the output with the -r switch. Mesen seems to (???) differentiate between different types of ram, or at least the *.mlb files make it appear that way. The main use was to differentiate between constants (defined with ENUM) and labels (defined with RAM/SRAM/WRAM).

5. With ! now being used to force ABS/X/Y, would ? be a good alternative?

6. It just prints a message to console, without stopping assembly like ERROR does.

freem wrote:
No promises on when this stuff will be merged, but hopefully I can get to it this weekend.

I'll post an updated version with the changes discussed in this thread, if you want to hold off a little bit.
Re: asm6n
by on (#232514)
never-obsolete wrote:
Mesen seems to (???) differentiate between different types of ram, or at least the *.mlb files make it appear that way.
Yes, Mesen's labels are defined as an offset in either the NES's built-in ram, work ram, save ram, or PRG ROM. That way there is no possible ambiguity.
Re: asm6n
by on (#232515)
What is the G section used for?
Re: asm6n
by on (#232518)
G is for "registers" (G for global because R was already used).
E.g if you want to define $8000 as being a register & give it a tooltip and appear in expressions like "STA MyRegister", but don't want
Code:
MyRegister:
   LDA #$00
   ...
to appear in the code window at $8000, this is what you use. It's used to define the PPU/APU registers by default.
Re: asm6n
by on (#232519)
Pokun wrote:
Not only ugly, the "`" is typed using a dead key so therefore is very annoying to type on many keyboards as it requires two presses (plus SHIFT on Swedish keyboards).

I wonder how any of these people write shell scripts. In my line of work, it's an incredibly commonly-used character, especially with workplace and personal chat mediums like Slack and Discord using it to denote monospaced text with a single backtick (ex. `hello`) or monospaced paragraphs of text or scripts/code using triple backticks (ex. ```lda #$12```). Just goes to show there's nothing that works "smoothly" universally for everyone.

Quote:
I heard "^" is a common operator for taking out bank numbers. As long as it doesn't conflict with the XOR operator...

That's the thing: it sounds like \ as a bank number identifier is a kind of "global character/variable" that can be used in expressions to represent a literal number. If it was changed to ^ then that would conflict with XOR, best I can tell. (But yes, ^ tends to be used to refer to "bank" in a couple contexts in 65xxx; on 6502/65c02 I think it could be used for this purpose, while on 65816 it actually refers to the literal PC bank, since the system has 24-bit addressing (bank = upper 8 bits of the 24-bit address)).

It's also why I was suggesting something like {banknum} since curly brackets could be used to denote a kind of "internal variable" or "internal function" of sorts (interal to the assembler). Sounds like we're limited to a single character though.

If contextually ^ would not conflict with XOR depending on expression, then yes, I think this would be a legitimate choice.
Re: asm6n
by on (#232520)
The ^ operator is already used by Managed C++ extensions to indicate a garbage collected object, but that's for C-like languages.
Re: asm6n
by on (#232530)
Most euro keyboards either have a dedicated section sign (§) key or keep it available on the numeral strip with a shift press, or in the case of italy, on shift+ù. Either way it's quickly accessed.

` fits american english keyboards
§ fits euro keyboards + mac keyboards.

you can have it accept both.

^ has the same input problem on at least this euro keyboard as `, unfortunately. You need to press shift+¨ and then space bar. i didn't find a comprehensive list on other euro keyboards regarding this.
Re: asm6n
by on (#232532)
I find it strange "`" not being a dead key. Isn't it supposed to be a grave accent diacritic that's normally combined with a vowel (or a consonant in some languages)?

As for software that uses funny characters in excess, I'd just avoid such software if I can't find a workaround.

Oh yeah "^" is also a dead key now when I think about it (like for û). So is "~" (like in ñ) which requires AltGr as a modifier instead of SHIFT.
Re: asm6n
by on (#232535)
In the US, ` is just ... well, originally was just ... open quote. And ' was close quote, and you were expected to manually balance the quotation marks. (LATEX still works this way). You can look at the original DOS CP437 fonts.

` was pretty quickly adjusted outside of this market.

Now backtick is in this weird limbo, where the lack of accented characters in the US – especially accented characters that take a grave accent – mean that it's more or less unused for regular typography in the US. And so it gets used by unix shell programming, or markdown, because every other key on a US keyboard already has a meaning.
Re: asm6n
by on (#232547)
This is great, But there still is one gripe with all current ASM6 forks:

There is still no support for non-ASCII string encoding support (i.e. support for fonts as seen in Super Mario, Zelda, Etc...)

Otherwise, it's fine!
Re: asm6n
by on (#232548)
Hamtaro126 wrote:
There is still no support for non-ASCII string encoding support

Well, you can "shift" character codes in a string by adding a number to it (e.g. .db "ABCD"+2 will output the bytes $43, $44, $45, $46), which helps with remapping ranges of characters, but I agree that a more complete mapping solution would work much better.
Re: asm6n
by on (#232550)
tokumaru wrote:
Hamtaro126 wrote:
There is still no support for non-ASCII string encoding support

Well, you can "shift" character codes in a string by adding a number to it (e.g. .db "ABCD"+2 will output the bytes $43, $44, $45, $46), which helps with remapping ranges of characters, but I agree that a more complete mapping solution would work much better.


That is what I want, Remapping Characters similar to CA65 without having to use CA65... This would be a gamechanger if it's done! Even adding support for table files (.TAB files) would suffice.
Re: asm6n
by on (#232551)
That doesn't sound hard to add at all... but what do I know? :lol:
Re: asm6n
by on (#232552)
tokumaru wrote:
That doesn't sound hard to add at all... but what do I know? :lol:


Heh, You have a point there, Tokumaru! :wink:
Re: asm6n
by on (#232553)
Because character set support is literally one of the most complicated and *horrible* things to implement into anything. I cannot stress with words how horrible it is to implement. You didn't specify what character set either, so for all I know you want a combination of UTF-8, SJIS and/or EUC, ISO-8859-1, and ASCII. Yikes.

Also, are you aware of any assembler that properly works with such things? I've never encountered one.

You may, however, be interested in Atlas, which is not an assembler but rather a script/table inserter of sorts. It's mainly intended for romhacking but I'm certain it could be used for actually generating your own stuff. It *does* have support for UTF-8. The idea would be that you'd make your ROM image with the necessary blank space for whatever you would insert via Atlas, and it'd be up to you to ensure the 6502 code would work properly with it. I've attached the PDF manual if you're curious. The examples are often for SNES, but it's general-purpose.
Re: asm6n
by on (#232558)
Surely you don't need real character set support in an 8-bit console with access to 256 tiles at a time... A simple "this character is encoded as this byte" solution should suffice.
Re: asm6n
by on (#232563)
Agreeing. I tend to put hud/text tiles on top of my chr table when doing things by myself. A value of 128 or over (N flag) will escape from normal text output to some formatting task (and naturally, don't take that value as a tile to lay down). Exactly what letters/symbols and in what order/offset may differ.

Best'd (imo) be to have a separate string to ID association table the user can text edit since the needs may differ from project to project, but maybe that goes against asm6:s one-file portability philosophy. On the other hand, a readme is also always included.
Re: asm6n
by on (#232565)
tokumaru wrote:
Surely you don't need real character set support in an 8-bit console with access to 256 tiles at a time

But not necessarily the same 256 tiles at the same time. Some games are known to use CHR RAM for variable-width or ideographic fonts.

tokumaru wrote:
... A simple "this character is encoded as this byte" solution should suffice.

True, but "this character" may be above U+007F, or even above U+FFFF. My NES port of 240p Test Suite has a couple BIRD (U+1F426) emoji to represent a contributor's handle on Twitter. (I can't exhibit it here because the tables haven't been upgraded to utf8mb4.)
Re: asm6n
by on (#232571)
Hence the suggestion - Keep a list of associations between symbol ID:s and tile ID:s in a separate xml file or something like that. If a user prefer something other than UTF-8, they can "simply" replace ID:s on the input side of the table. A little iffy, but the effort is decentralized and on a when-there's-need basis rather than a just-in-case one. The user is more importantly free to associate any symbol with any tileID; even mapping several symbols to the tile.
Re: asm6n
by on (#232601)
Posted an update that has ! forcing ABS/X/Y and ? retrieving a bank number from a label.