Neo TeAm Forum

The 9th. NEO Project for SNES => The 9th. NEO Project for SNES Dev kit. => SNES development section => Topic started by: Bottle on May 07, 2012, 11:22:15 PM

Title: ASM questions
Post by: Bottle on May 07, 2012, 11:22:15 PM
Hello! I have been going through some tutorials for programming the SNES in ASM, and I have a couple of questions. I have a basic understanding of how assembly language works, and I have been reading a book on 65816 assembly, but there are a few things in the tutorials that I can't find any information on.

For example, there are some symbols that I am not familiar with, in the following code:

Code: [Select]
.MACRO LoadPalette
    lda #\2
    sta $2121       ; Start at START color
    lda #:\1        ; Using : before the parameter gets its bank.
    ldx #\1         ; Not using : gets the offset address.
    ldy #(\3 * 2)   ; 2 bytes for every color
    jsr DMAPalette
.ENDM

What do the symbols \ and * represent? I have only dealt with #, $, and %.

Next question, all over example code I see things like this:

.BANK, .ORG, .MACRO, etc.

What are these called? I mean, they aren't instructions, right? They're not in my book anyway. I just want to know what they are so that I can look them up. Are they part of 65816 ASM, or do they have to do with the hardware and the compiler?

Thanks!
Title: Re: ASM questions
Post by: KungFuFurby on May 07, 2012, 11:51:35 PM
You're looking at code made to compile with WLA DX. The README file for WLA DX is your friend in this particular case...

That piece of code you're looking at is a macro, which is kinda like a piece of code you can reuse over and over again. That also means you need to terminate a macro with .ENDM if you start one with .MACRO. ^_^

\ is mostly reserved for macros to some extent... the way this code uses it, \ with a number next to it is an argument number inside a macro
\1 is effectively "argument 1", or the first argument.
\2 is the second argument...
\3 is the third argument...
...and so on.

* stands for multiplication. Basically it's multiplying 3 and 2.

.BANK has a ROM bank number. Although it has SLOT next to it, you can just use a zero, as it is not necessary.

.ORG is a starting address in the bank. Basically, it's like an offset.

 ~sm-71.gif~.gif  And that's your request satisfied.
Title: Re: ASM questions
Post by: Bottle on May 08, 2012, 01:18:21 AM
Ok, I get it! Thanks :)
Title: Re: ASM questions
Post by: mic_ on May 08, 2012, 01:54:15 AM
Quote
.BANK, .ORG, .MACRO, etc.

What are these called?

They're directives.


Quote
* stands for multiplication. Basically it's multiplying 3 and 2.

It's multiplying the third argument by 2 in this case. Note that this only works if the third argument is an immediate value. I.e. it doesn't work if you send register A as the third argument, because the value of A isn't known at compile time, and there' no such instruction as LDY #(A * 2)


Quote
.BANK has a ROM bank number. Although it has SLOT next to it, you can just use a zero, as it is not necessary.

Depending on the ROM layout and slot size you use there could potentially be situations where you'd want to put code or data in a specific slot. But initially you probably won't need anything other than slot 0.
Title: Re: ASM questions
Post by: Bottle on May 09, 2012, 05:32:43 AM
Directives! Thanks a lot for the additional details :)