RPGHacker / asar

(Now) official repository of the SNES assembler Asar, originally created by Alcaro
Other
203 stars 44 forks source link

Support for ASM 6502 (NES) #155

Closed ShadowOne333 closed 4 years ago

ShadowOne333 commented 4 years ago

Having support for 6502 would greatly help so that users can also utilize Asar for NES projects. I am currently unsure if Asar as-is supports 6502 or not, but if not, it would be great to have it, as xkas is starting to get obsolete as time goes on, and Asar seems like the most appropriate moving point from it.

randomdude999 commented 4 years ago

65816 assembly is a strict superset of 6502 assembly, so Asar already supports 6502. Though the unofficial opcodes do differ, but if you really need those you can make macros for them. But if you're looking for an xkas replacement, Asar should work fine.

ShadowOne333 commented 4 years ago

Are there any specifications as to what to write for the header of the .asm file? For example, in xkas I had this for a hack I am doing:

arch nes.cpu        // set processor architecture (NES)
banksize $4000      // set the size of each bank
header          // rom has a header

What would I need to make it so that Asar recognizes this as proper 6502 code?

randomdude999 commented 4 years ago

....oh right, I forgot xkas 0.06 isn't the only version of xkas. Setting the processor architecture shouldn't be needed, the default is to assemble for 65816 (which as I said is backwards compatible with 6502), though you'll just have to be careful to not use any instructions that weren't present on 6502. Banking can be handled using the norom mapper and a custom address converter macro. Asar natively handles headers of 512 bytes, I don't remember if NES headers were a different size or not, but if they were different then those too could be handled by an address converter macro.

I think one such macro could work like this:

norom
!headersize = 512 ; or however big NES headers were
macro org(address,bank)
    ; I think the way NES mappers worked was that $8000-$BFFF was hardcoded to bank 0, then $C000-$FFFF was switchable
    ; if your mapper is different, edit this function accordingly
    if <bank> == 0
        org <address>-$8000+!headersize ; org sets the position in the output file to write to (in norom, at least)
        base <address> ; base sets the position that all labels are relative to - this is necessary so labels will still start from $8000, instead of $0000 or somewhere
    else
        org <address>-$C000+$4000*<bank>+!headersize
        base <address>
    endif
endmacro

then use this macro where you would usually use the org statement (for homebrew, it should only be the start of each bank anyways)