asm6 small patch (forcing ZP address as absolute)

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

Post Reply
User avatar
morskoyzmey
Posts: 13
Joined: Sat Sep 15, 2018 2:59 pm

asm6 small patch (forcing ZP address as absolute)

Post by morskoyzmey » Thu Oct 11, 2018 1:41 pm

Hey

Just wanted to share my asm6 patch

DIFF: on github

Love this assembler. But I met inconvenient behaviour. For disassembled code, such as:

Code: Select all

sta $0092   ; $E88C:  8D 92 00
asm6 generates this:

Code: Select all

85 92
I read few topics with ideas of new syntax to deal with ZP and absolute addressing, but I'm working with disassembled code and there are many such rows everywhere so...
I thought that it might be useful to someone.
Last edited by morskoyzmey on Sun Oct 14, 2018 4:19 am, edited 4 times in total.

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

Re: asm6 small patch (four-digits ZP address as absolute)

Post by tepples » Thu Oct 11, 2018 1:52 pm

If an assembler already supports an address size prefix, as described for ca65 in the topic you linked, you could patch the disassembler to emit that. I guess the real problem is that ASM6 appears to lack an address size prefix at all, and you're proposing using the number of digits to fill that role. I'll let others weigh in on whether that's a good idea.

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

Re: asm6 small patch (four-digit ZP address as absolute)

Post by tokumaru » Thu Oct 11, 2018 5:23 pm

Too bad this solution doesn't solve the problem for those who use labels, which's probably the vast majority of coders.

User avatar
morskoyzmey
Posts: 13
Joined: Sat Sep 15, 2018 2:59 pm

Re: asm6 small patch (four-digit ZP address as absolute)

Post by morskoyzmey » Fri Oct 12, 2018 6:13 am

tokumaru wrote:Too bad this solution doesn't solve the problem for those who use labels, which's probably the vast majority of coders.
If it's yours code, then why you need to use absolute addressing for ZP?

User avatar
gauauu
Posts: 700
Joined: Sat Jan 09, 2016 9:21 pm
Location: Central Illinois, USA
Contact:

Re: asm6 small patch (four-digit ZP address as absolute)

Post by gauauu » Fri Oct 12, 2018 7:11 am

morskoyzmey wrote:
tokumaru wrote:Too bad this solution doesn't solve the problem for those who use labels, which's probably the vast majority of coders.
If it's yours code, then why you need to use absolute addressing for ZP?
Usually you wouldn't, but occasionally you want to force it to use the longer or slower addressing modes for timing or spacing tricks.

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

Re: asm6 small patch (four-digit ZP address as absolute)

Post by tepples » Fri Oct 12, 2018 8:48 am

Or if you want to be really weird, use the end of zero page contiguously with the start of the stack page, such as $0080-$017F or the like. I seem to remember seeing one demo that did this. Or did it use the end of RAM contiguously with the first mirror of zero page, such as $07C0-$08BF?

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

Re: asm6 small patch (four-digit ZP address as absolute)

Post by tokumaru » Fri Oct 12, 2018 9:37 am

tepples wrote:Or did it use the end of RAM contiguously with the first mirror of zero page, such as $07C0-$08BF?
That wouldn't have been a problem. I've used mirrors to get around this problem a few times. On the NES, add $800 to access a mirror of ZP, on the Atari 2600, add $100.

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

Re: asm6 small patch (four-digit ZP address as absolute)

Post by koitsu » Fri Oct 12, 2018 10:37 am

So important to remember is the fact that the OP did this because the disassembler output a particular syntax that the assembler didn't interpret identically. I will say that I'm disappointed he/she didn't state what disassembler was used -- it matters.

However, I do not believe this is something that should be backported or imported into either official asm6 or forks (ex. asm6f). I'll explain my stance:

I'm making an assumption that this was accomplished based on length (number of characters/bytes representing the address, ex. 4 for $0092). I have to assume this because only the full source code was posted, not a diff, and I can't be arsed to download it and diff it myself.

How this was accomplished on other assemblers was through some form of operator prefix or suffix.

If someone wants to solve this long-term, I urge you -- almost to the point of forcing you -- to read my post in the linked thread. Take the time to look at the manuals of existing commercial assemblers and products. You will find there is generally a "common implementation model" (despite different letters/characters used), and *where* that's implemented also matters (hint: it's not based on operand value/length/size). Tepples in the same thread proposed a different syntax (re: a: prefix). I don't care what is chosen, but it needs to be implemented properly.

As for disassemblers and their output: hopefully everyone is now starting to see why this matters so much. The state of 6502 disassemblers is pretty messy: I've tried several in the past few months and I roll my eyes at pretty much all of them in one way or another -- to the point where I don't even bother reassembling anything (like I usually do) because it's going to be a PITA due to the ridiculous variance of behaviours of each assembler. It wasn't like this in the early and late 90s, for whatever reason. The one I found to be most helpful but also kinda not helpful was disasm6, since it was designed to output code that worked with asm6, but there's annoyances with disasm6 too.

User avatar
morskoyzmey
Posts: 13
Joined: Sat Sep 15, 2018 2:59 pm

Re: asm6 small patch (four-digit ZP address as absolute)

Post by morskoyzmey » Fri Oct 12, 2018 1:34 pm

koitsu wrote:So important to remember is the fact that the OP did this because the disassembler output a particular syntax that the assembler didn't interpret identically. I will say that I'm disappointed he/she didn't state what disassembler was used -- it matters.
He :beer: . I used clever-disasm from nescom-1.2.0.
koitsu wrote:I'm making an assumption that this was accomplished based on length (number of characters/bytes representing the address, ex. 4 for $0092). I have to assume this because only the full source code was posted, not a diff, and I can't be arsed to download it and diff it myself.
First link in my first post is a link to the diff on github. :)
koitsu wrote:How this was accomplished on other assemblers was through some form of operator prefix or suffix.
The problem is that disassembler is using such syntax, not another. And for me it looks logic to modify asm6, because I don't see alternatives.

There is a code in ROM 8D 92 00, disassembler produces from it some readable text, and assembler should produce the same code from it. But asm6 can't do it in any way.

lidnariq
Posts: 9500
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: asm6 small patch (four-digit ZP address as absolute)

Post by lidnariq » Fri Oct 12, 2018 1:50 pm

Clever-disasm is meant to be used with xa65 and/or nescom ... of course, it doesn't generate the correct marker for that either ( " lda !$f0 would use 16-bit address instead of direct page. " )

It'd be better to modify clever.cc to have it emit the correct markup instead. Lines 1710-1719:

Code: Select all

    void PrintRAMaddress(unsigned addr, unsigned bytes) const
    {
        auto i = RAMaddressNames.find(addr);
 /* ----> here print extra marker if addr <= 0x100 and bytes == 2 <---- */
        if(i != RAMaddressNames.end())
        {
            printf("%s", i->second.c_str());
            return;
        }
        printf("$%0*X", bytes*2, addr);
    }

[/size]

User avatar
morskoyzmey
Posts: 13
Joined: Sat Sep 15, 2018 2:59 pm

Re: asm6 small patch (four-digit ZP address as absolute)

Post by morskoyzmey » Fri Oct 12, 2018 2:18 pm

lidnariq wrote:Clever-disasm is meant to be used with xa65 and/or nescom ... of course, it doesn't generate the correct marker for that either ( " lda !$f0 would use 16-bit address instead of direct page. " )

It'd be better to modify clever.cc to have it emit the correct markup instead. Lines 1710-1719:

Code: Select all

    void PrintRAMaddress(unsigned addr, unsigned bytes) const
    {
        auto i = RAMaddressNames.find(addr);
 /* ----> here print extra marker if addr <= 0x100 and bytes == 2 <---- */
        if(i != RAMaddressNames.end())
        {
            printf("%s", i->second.c_str());
            return;
        }
        printf("$%0*X", bytes*2, addr);
    }

[/size]
But what I supposed to do with that extra marker? To modify asm6 to support it? :D

BTW I've modified clever-disasm to make its output valid for asm6, except that asm6 understands it in its own way.

User avatar
morskoyzmey
Posts: 13
Joined: Sat Sep 15, 2018 2:59 pm

Re: asm6 small patch (forcing ZP address as absolute)

Post by morskoyzmey » Sun Oct 14, 2018 4:27 am

UPDATE.

Added support for " * " prefix as suggested for "!" mark. I didn't come up with another suitable symbol.
As you know "!" is an unary operator in expressions and I have not found a good workaround.
Also @ would be good, but it's for local labels.

Link to latest DIFF

Any suggestions?

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

Re: asm6 small patch (forcing ZP address as absolute)

Post by koitsu » Tue Feb 05, 2019 7:42 pm

I just posted a reply on GitHub discussing this subject in detail, covering the syntax variances and similarities of 21 different assemblers WRT this specific ordeal: https://github.com/freem/asm6f/issues/2 ... -460882018

This is why I disagree with use of asterisk as the character. Let us not make a bigger mess.

Post Reply