Assembly bug in WLA-DX or user error?

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
Assembly bug in WLA-DX or user error?
by on (#178722)
Hello all,

I've been looking at Bazz' tutorials (http://wiki.superfamicom.org/snes/show/ ... ES+Program) and had a question.

I ran the first.smc (which is included in the link at the bottom of the tutorial: http://wiki.superfamicom.org/snes/files ... program.7z) through the MESS emulator debugger and WLA is assembling the code incorrectly. I don't know if it's a coding error (likely) or if it's an actual bug in WLA (unlikely).

In the InitializeSNES method (which is in the InitSNES.asm source file) it is assembling the following two lines:

LDA #$0000 ;set Direct Page = $0000
TCD ;Transfer Accumulator to Direct Register

...into the following 3 bytes:
A9 00 5B

...when it should really be 4 bytes since the accumulator is in 16-bit mode:
A9 00 00 5B

The $5B value is actually the TCD opcode but it's being treated as the upper byte of the LDA instruction! :-o I have included a screenshot for you.

I have also recompiled first.smc from scratch using the latest WLA binaries available here (viewtopic.php?f=12&t=12334) but the recompiled SMC has the exact same problem.

Does the source code need an extra assembler directive or something in order to tell WLA that the accumulator is in 16-bit mode?

Thanks!
Re: Assembly bug in WLA-DX or user error?
by on (#178724)
This subject has been discussed at ridiculous length on the forum already (no offense) -- "ridiculous length" means several pages. The problem is exacerbated by crummy documentation. See the section talking about .8BIT, .16BIT, .24BIT, .ACCU 8, .INDEX 8, and Section 3.6 (Mneumonics).

If you want to force 16-bit addressing, you need to use the .w "extension" on your opcode, e.g. lda.w #$0000. Likewise there is .b (byte) and .l (24-bit). You can alternately use this on the operand itself, e.g. lda #$0000.w; your choice.

It's still your responsibility to ensure the runtime accumulator or X/Y indexes are the correct size via rep/sep.
Re: Assembly bug in WLA-DX or user error?
by on (#178725)
Aha, thanks a lot! And I see all the pages you are talking about now. The problem is I didn't know what I was looking for. I've never programmed for the 65816 (or any other 16-bit CPU for that matter). Thanks again.
Re: Assembly bug in WLA-DX or user error?
by on (#178727)
No prob. The WLA DX documentation is very badly organised and not well-written (I believe written by someone whose native tongue is not English). IMO, the "pinnacle" of PC 65816 cross-assemblers was x816 by Norman Yen, but it's for MS-DOS.
Re: Assembly bug in WLA-DX or user error?
by on (#178730)
Yo, thanks for the report. This can be fixed by finding the "InitializeSNES:" label in InitSNES.asm and adding the following 2 lines before it:
Code:
.ACCU 16
.INDEX 16
InitializeSNES:


Unfortunately, all of the separate projects in the tutorial series each have this file so it needs to be replaced across the board. This makes me lean towards creating a Github repo which has all sub-projects source the same one library file, for easy maintenance.