Assembly bug in WLA-DX or user error?

Discussion of hardware and software development for Super NES and Super Famicom. See the SNESdev wiki for more information.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
User avatar
jwdonal
Posts: 719
Joined: Sat Jun 27, 2009 11:05 pm
Location: New Mexico, USA
Contact:

Assembly bug in WLA-DX or user error?

Post by jwdonal »

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

Re: Assembly bug in WLA-DX or user error?

Post by koitsu »

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.
User avatar
jwdonal
Posts: 719
Joined: Sat Jun 27, 2009 11:05 pm
Location: New Mexico, USA
Contact:

Re: Assembly bug in WLA-DX or user error?

Post by jwdonal »

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

Re: Assembly bug in WLA-DX or user error?

Post by koitsu »

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.
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Re: Assembly bug in WLA-DX or user error?

Post by bazz »

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

.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.
SNES Tutorials (WLA DX)
SNES Memory Mapping Tutorial (Universal / LoROM) -- By Universal I introduce how memory mapping works, rather than just provide a LoROM map.
SNES Tracker (WIP) - Music/SFX composition tool / SPC Debugger
Post Reply