asm6n

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

User avatar
never-obsolete
Posts: 411
Joined: Wed Sep 07, 2005 9:55 am
Location: Phoenix, AZ
Contact:

asm6n

Post by never-obsolete »

This is a modified version of asm6 that I use.

Code: Select all

1.7.3
	* Added support for label sizes (RAM,SRAM,WRAM blocks only)

1.7.2
	* Added REG directive
	* Added DH2 and DH3 directives
	* Added support for patching over an ines rom
	* Bugfix for macro parameters having a scope/name clash

1.7.1
	* Changed BIN directive
	* 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
	* 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]
edit: attached version 1.7.3
Attachments
asm6n.zip
v1.7.3
(85.52 KiB) Downloaded 155 times
asm6n.zip
v1.7.1
(82.47 KiB) Downloaded 339 times
Last edited by never-obsolete on Fri Oct 09, 2020 8:12 pm, edited 5 times in total.
. That's just like, your opinion, man .
User avatar
dougeff
Posts: 3079
Joined: Fri May 08, 2015 7:17 pm

Re: asm6n

Post by dougeff »

Thanks for that.

Could you do an error message with PRINT?

like if Program Counter > $C000, print "error, bank full"
nesdoug.com -- blog/tutorial on programming for the NES
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: asm6n

Post by Pokun »

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?
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: asm6n

Post by koitsu »

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: Select all

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.
User avatar
freem
Posts: 176
Joined: Mon Oct 01, 2012 3:47 pm
Location: freemland (NTSC-U)
Contact:

Re: asm6n

Post by freem »

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: Select all

// 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.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: asm6n

Post by koitsu »

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.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: asm6n

Post by Pokun »

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...
User avatar
never-obsolete
Posts: 411
Joined: Wed Sep 07, 2005 9:55 am
Location: Phoenix, AZ
Contact:

Re: asm6n

Post by never-obsolete »

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.
. That's just like, your opinion, man .
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: asm6n

Post by Sour »

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.
User avatar
never-obsolete
Posts: 411
Joined: Wed Sep 07, 2005 9:55 am
Location: Phoenix, AZ
Contact:

Re: asm6n

Post by never-obsolete »

What is the G section used for?
. That's just like, your opinion, man .
Sour
Posts: 891
Joined: Sun Feb 07, 2016 6:16 pm

Re: asm6n

Post by Sour »

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: Select all

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.
User avatar
koitsu
Posts: 4201
Joined: Sun Sep 19, 2004 9:28 pm
Location: A world gone mad

Re: asm6n

Post by koitsu »

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.
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.
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: asm6n

Post by Dwedit »

The ^ operator is already used by Managed C++ extensions to indicate a garbage collected object, but that's for C-like languages.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
FrankenGraphics
Formerly WheelInventor
Posts: 2064
Joined: Thu Apr 14, 2016 2:55 am
Location: Gothenburg, Sweden
Contact:

Re: asm6n

Post by FrankenGraphics »

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.
Pokun
Posts: 2681
Joined: Tue May 28, 2013 5:49 am
Location: Hokkaido, Japan

Re: asm6n

Post by Pokun »

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.
Post Reply