Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,486,573
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 04-26-24 09:40 AM
Guest: Register | Login

0 users currently in ROM Hacking | 3 guests

Main - ROM Hacking - Assembler Trouble New thread | New reply


RetroRain
Posted on 03-12-08 11:54 PM Link | Quote | ID: 80257


Fuzz Ball
Level: 66

Posts: 59/994
EXP: 2438178
Next: 23673

Since: 09-30-07

Last post: 1935 days
Last view: 957 days
1. What is the best low-level NES Assembler to use? NESASM or FSNASM? Or is it something else?

2. Reason I'm asking, is because these two assemblers are being anal about compiling my code.

They keep saying that my .db or .dws are invalid codes, and they're not. It's pissing me off.

Let me show you some simple code I'm trying to compile:

.inesprg 1
.ineschr 1
.inesmir 1
.inesmap 4

.org $8000
.bank 0

Start:

LDA #$08
STA $2000
LDA #$1E
STA $2001

LDA #$3F
STA $2006
LDA #$00
STA $2006

LDX #$00
Load_Palette:
LDA Palette, X
STA $2007
INX
CPX #$21
BNE Load_Palette

.db $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03

.bank 2
.org $0000
.incbin "font.chr"

.bank 1
.org $FFFA
.dw 0 ;(NMI_Routine)
.dw Start ;(Reset_Routine)
.dw 0 ;(IRQ_Routine)

If I compile this with NESASM



Now, if I leave this out:

LDX #$00
Load_Palette:
LDA Palette, X
STA $2007
INX
CPX #$21
BNE Load_Palette

.db $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03

It will compile, because of the .db. But what I don't get, is that the .db is a prefectly valid code.

Now, lets move onto FSNASM.

FSNASM doesn't recognize a lot of the same code that I used here:



Consulting the FSNASM Readme......



The following directives can be used (the period is optional):

.data - Create a section.
.code - Create a section that will be placed within one bank.
.ram - Allocate an area in the RAM
.zram - Allocate a RAM area, that will end up between $0000 and $2000
.org pression> - Create a section at the specified address.
.end - Ends a section.
.dc - Put specified data, separated with commas.
Use double quotes for character strings.
.incbin - Include a binary file
.equ/= pression> - Define a symbol that will be set equal to the expression.
.align [,] - Align with nn bytes, perhaps fill with xx
.block [,] - Jump over some bytes and perhaps fill with xx
.global - Declare a global symbol
.base pression> - Set the current address
.endb - Restore the address
.defchars < name > [ s ]< range >=< value > [,...] - Define a character set. Place an
"S" to specify a sequence of characters.
.charset - Use a character set.



FSNASM doesn't support .db, .dw, .inesprg, .inesprg, etc.?

So how the hell do I compile my code?

I can compile it easily with NESASM if I take out the .db, and just manually have it read each line by line by line. That's impractical though.




Consulting the NESASM Readme:




Directives
----------


LIST, tell the assembler that you want a complete listing
file. You can later stop temporarily the output with
the NOLIST directive and restart it with LIST.

NOLIST, stop the listing output.

MLIST, include the macros in the listing file.

NOMLIST, stop expanding macros in the listing file.

EQU, assign a value to a symbol. The character '=' has
the same function too.

BANK, select a ROM bank (0-127) and reset the location
counter to the latest known position in this bank.

ORG, set the location of the program counter. The thirteen
lower bits of the address inform the assembler about
the offset in the ROM bank and the third upper bits
represent the page index.

DB, data byte(s).

DW, data word(s).

RSSET, set the internal counter of the RS directive to
a specified value.

RS, assign a value to a symbol; a bit like EQU but here
the value assigned is taken from an internal counter
and after the assignation this counter is increased
by the value specified in the RS directive.
It's a very handy way of defining variables, here's
a small example:

.rsset $2000 ; set the initial value of
; the RS internal counter
my_byte .rs 1 ; define a var of 1 byte
my_word .rs 2 ; " 2 bytes

MACRO, start a macro definition.

ENDM, end a macro definition.

INCBIN, include a binary file at the current location. If
the file is bigger than a ROM bank, as many successive
banks as necessary will be filled and the bank and
the location counter will be updated.

INCLUDE, include a source file at the current location.
Up to 7 levels are possible.

INESPRG, specifies the number of 16k prg banks.

INESCHR, specifies the number of 8k chr banks.

INESMAP, specifies the mapper used.

INESMIR, specifies VRAM mirroring of the banks. refer to INES
header documents (neshdr20.txt). This file should be part of
the compiler archive.




As you can see, NESASM supports these commands, so how come it gives me an invalid message then?



Am I doing something wrong?

____________________
My YouTube Channel

Sukasa
Posted on 03-13-08 12:47 AM Link | Quote | ID: 80260


Red Birdo
Level: 92

Posts: 704/2112
EXP: 7689334
Next: 67603

Since: 02-19-07

Last post: 4448 days
Last view: 3219 days
try "db" instead of ".db"

RetroRain
Posted on 03-13-08 12:56 AM (rev. 2 of 03-13-08 12:58 AM) Link | Quote | ID: 80261


Fuzz Ball
Level: 66

Posts: 60/994
EXP: 2438178
Next: 23673

Since: 09-30-07

Last post: 1935 days
Last view: 957 days
I already figured out what the problem was. I sent a PM to Ailure to have this closed. I appreciate the response though.

For those that are curious, here is what the problem was:

My Code

LDX #$00
Load_Palette:
LDA Palette, X
STA $2007
INX
CPX #$21
BNE Load_Palette

.db $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03

Correct Code

LDX #$00
Load_Palette:
LDA Palette, X
STA $2007
INX
CPX #$20
BNE Load_Palette

Palette .db $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03, $0F, $01, $02, $03

I had to add the label name to the beginning of the data table.

____________________
My YouTube Channel

Main - ROM Hacking - Assembler Trouble New thread | New reply

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 0.019 seconds. (347KB of memory used)
MySQL - queries: 47, rows: 69/70, time: 0.015 seconds.