Converting from NESASM to ASM6, some questions

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

Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

Next issue, for the line:

Code: Select all

AND #~SPR_VFLIP
Asm6 is giving me the error "Value out of range".

My best guess is that the ~ operator returns a word instead of a byte, so I have to specifically state that I want the low byte?

Code: Select all

AND #<~SPR_VFLIP
It does assemble without complaint but I have no idea if this actually gives me the value I want lol.
Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

Alright, I'm getting somewhere now. The game boots up when assembled by asm6.

https://github.com/Drakim/smb3

Image

So, not everything is as it should be :wink: Unfortunately I'm a bit stuck, the project is huge and I have no idea where to start looking for these errors.

The sound and music is perfect, which at first lead me to believe that all that was messed up was the graphics. I double checked the CHR data, even going so far as to use NES Screen Tool to rip the CHR data from the actual binaries once they were assembled. But it turns out, the CHR data is just fine.

I also used FXEUX PPU viewer and made sure that everything was identical between the nesasm and asm6 version once the game was running and I was on the overworld, which it was.

So it's clear that the graphical glitches are not merely coming from the graphical data being misplaced or anything like that. It's a code issue.

Testing the game a bit more, I noticed some more things that are broken:

1. During the intro, Luigi walks up to Mario but doesn't jump on top of him.
2. During the World map any attempts to move fails with that DUUuuM! sound.
3. During the world map the hammer bros isn't doing his idle walk offset, but his animation is fine.

But surprisingly, a lot of things are not broken, like the intro background and sound. They work flawlessly.

So, my conclusion is that something related to fetching data (data for the sprites in the intro, data for the worldmap pathing, data for luigi's movement during the intro, etc) is broken. My initial guess was indirect access [] vs () being the cause, but looking around I could only find a single instance of () misuse in an LDA, which wasn't related to these glitches.

So, does anybody have any ideas, advice, tricks, tools or pointers that could help me figure this out?

I'm so close! :beer:
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Converting from NESASM to ASM6, some questions

Post by thefox »

Compare your ROM to the original SMB3 ROM. There are many ways to do this depending on your operating system. In Windows you can use fc /b on the command line. HxD hex editor can also do file comparisons (Analysis -> File-compare).

Once you find where the difference is, you just need to locate the same code in the assembly code and see what's going wrong. FCEUX debugger might come handy when doing this.
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

Thanks, that's finally a lead to follow. Gonna set up FCEUX's debugger with labels and see if I can figure out what's so different.
User avatar
nin-kuuku
Posts: 67
Joined: Tue Jan 24, 2017 1:23 am

Re: Converting from NESASM to ASM6, some questions

Post by nin-kuuku »

ADD and SUB macro is not working.
SUB Address,X
assembled as:
SEC
SBC Address
Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

Oh, you are right!

In NESASM macros behave a bit differently, so that ",X" part would have tagged along in the first parameter.

Thanks for the heads up, I'll fix this one right away and go over the other macros too. :beer:
Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

Actually, I'm struggling a bit. ASM6's macro system seems a lot weaker than NESASM's macro system.

I've been been going over the documentation, and it doesn't seem like there is any way of supporting an "optional" argument in ASM6, which means I'd either have to split it into two separate ADD and ADD2,X macros or just unroll all the macro calls entirely for ADD and SUB.

Unless somebody else knows any tricks that I'm not aware of?

Edit:

I used a regex to remove the macro from the project, and behold, the title screen is now correct!

Image

I also found a lead on the next issue for the glitchy overworld, NESASM and ASM6 treats negative numbers differently (NESASM makes a negative byte, while ASM6 makes a negative word)
Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

thefox wrote:Compare your ROM to the original SMB3 ROM. There are many ways to do this depending on your operating system. In Windows you can use fc /b on the command line. HxD hex editor can also do file comparisons (Analysis -> File-compare).

Once you find where the difference is, you just need to locate the same code in the assembly code and see what's going wrong. FCEUX debugger might come handy when doing this.

Ouch, I've run into a big problem with comparing the roms.

in ASM6, all zero page references automatically uses the zero page accessing mode, while in NESASM you have to manually specify if you want to use zero page or absolute access. This mean, a bunch of lines that used to be absolute access in NESASM have been made into zero page access in ASM6.

And, a zero page access LDA is 2 bytes in size, while an absolute access LDA is 3 bytes in size. This means ALL bytes afterwards is gonna be offset. This makes comparing byte for byte between the two roms is nearly impossible.
User avatar
nin-kuuku
Posts: 67
Joined: Tue Jan 24, 2017 1:23 am

Re: Converting from NESASM to ASM6, some questions

Post by nin-kuuku »

Lot of typos in levels dir.
Exsample:
\levels\Hills\1-2.asm
NESASM: .byte LEVEL4_BGBANK_INDEX(19) | LEVEL4_INITACT_NOTHING
assemble to $13
ASM6: .byte 9 & %00011111 | LEVEL4_INITACT_NOTHING
assemble to $09

Edit:
In many places "# & %00011111 | LEVEL4_INITACT_NOTHING" is missing the first digit. Fixing these will fix at least the level background.
User avatar
thefox
Posts: 3134
Joined: Mon Jan 03, 2005 10:36 am
Location: 🇫🇮
Contact:

Re: Converting from NESASM to ASM6, some questions

Post by thefox »

Drakim wrote:And, a zero page access LDA is 2 bytes in size, while an absolute access LDA is 3 bytes in size. This means ALL bytes afterwards is gonna be offset. This makes comparing byte for byte between the two roms is nearly impossible.
I think it would be a good idea to fix those places so you get a byte-per-byte equivalent output. Unfortunately IIRC ASM6 doesn't have a way to override zeropage addressing, so you might have to resort to creating some special macros (maybe something like LDA_ABS).
Download STREEMERZ for NES from fauxgame.com! — Some other stuff I've done: fo.aspekt.fi
Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

Thanks nin-kuuku, it was one of my regexp gone wrong

Also thanks thefox, I was thinking the same thing. As long as I get most of the binaries identical, finding any leftover errors should be a breeze.
Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

Alright, all the non-zero page opcodes are now restored!

The next (and hopefully last!) issue is that the orginal NESASM wrapped a lot of it's expressions in parenthesis for clarity, which unfortunately often triggers the indirect access mode in ASM6.

I'm writing a regexp to remove this from the entire project, however, I came across this case:

Code: Select all

LDA #((KingToad_Sprites_End - KingToad_Sprites - 1) & ~3)
Here the parenthesis is used for to ensure the correct precedence of operators. How can I do the same without triggering the indirect addressing mode in ASM6?

EDIT:
I figured it out by random testing. ASM6 detects it automatically, so that LDA ($50+1) is indirect and LDA ($50)+1 is not indirect.
Drakim
Posts: 97
Joined: Mon Apr 04, 2016 3:19 am

Re: Converting from NESASM to ASM6, some questions

Post by Drakim »

Image

Success!

The two rom outputs are now 100% identical.

The only downside is that I had to rely pretty heavily on some macros for the absolute addressing. If you don't care about having a 100% identical starting point (for binary patches or whatever) then you can remove them without any visible changes to the game.

https://github.com/Drakim/smb3

If you make something cool with this, give me a hoot! And major credits for Captain Southbird for actually doing all the hard work.
Post Reply