News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Are there any tools like xkas for the nes?  (Read 3353 times)

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Are there any tools like xkas for the nes?
« on: November 28, 2012, 03:11:12 am »
I tried implementing the dte examples I've seen on this site through fceux but I keep getting syntax error with commands like BCC, BNE and BEQ. Xkas was suggested to me for this purpose but I see it is geared toward snes roms so I don't think it would work on an nes rom. Would you more experienced asm guys use when you are just trying change small sections of asm in an nes rom?
« Last Edit: November 28, 2012, 06:13:47 pm by Pikachumanson »

STARWIN

  • Sr. Member
  • ****
  • Posts: 454
    • View Profile
Re: Are there any tools like xkas for the nes?
« Reply #1 on: November 28, 2012, 12:42:09 pm »
I haven't used assemblers, so someone more experienced can answer the actual question.

However.

What do you exactly mean by "implementing through fceux"? I understand it is mostly for running the ROM while allowing us to view the content of RAM and ROM and the registers.

If you know the asm code you want to turn into assembly, you can do it manually. I assume people use tools when doing it a lot, but it might help understanding at this point (if there is not a great amount of it). You could post your asm code here if you want? It basically means mapping the asm to opcodes (machine language). 2 byte addresses go in reversed order (little-endian). A helpful reference for a beginner (or any 6502 asm coder) would be: http://www.obelisk.demon.co.uk/6502/reference.html (some of the other pages are definitely helpful as well http://www.obelisk.demon.co.uk/6502/ , NOT much to read)

If you want to change existing code, you want to replace some bytes in the ROM with your bytes (=opcode sequence). This can be done in a hex editor. You need to figure out what the location is in the ROM. This depends on whether banks are used or not (mapper) and the banking mechanism, if used. I guess the easiest way is to search for the existing bytes, they should identify it quite well. If the amount of new bytes is less than that of the existing bytes, there is no problem, just return earlier or add NOPs or jump over. Otherwise you need to find free space (from the same bank if possible) and do a jump to it, and possibly jump back, depending on if it is a called routine or something else.

Did I forget anything?

Oh, everything may be game specific, as far as the stuff you actually write is concerned. e.g. there is no "RLE", there are only various variations of it. Haven't checked what dte is, but it might apply there too. Also, even if you know what you are doing, it can be ridiculously easy to code bugs when using asm. Though that is kind of irrelevant until it happens.

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 593
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: Are there any tools like xkas for the nes?
« Reply #2 on: November 28, 2012, 05:21:50 pm »
If you're using the mini assembler in FCUEX, it believe only accepts absolute addresses for branching instructions, even though they actually get encoded as relative offsets.

If you're looking for a simple, straightforward assembler, ASM6 is worth a try.

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Are there any tools like xkas for the nes?
« Reply #3 on: November 28, 2012, 06:11:42 pm »
I have ASM6 I just need some help(explanation, tutorial in how actually to use it to change a few routines). I wish my C++ was up to par. I'd totally make a 6502 ide but, alas college taught me only how to make a simple cmd type compiler, nonetheless I will attempt this eventually... but enough of my rant.
So back to the original topic, I assume in this case that notepad will be my best friend when it comes to changing the code, I got that. What I don't understand about asm6 is how would I be able to patch my changes to the nes rom since a full on reassembly is out of the question. I have disassembled the portion of code I wanted from the rom now how do I go about sticking it back in?

@Starwin I thought the NES was BIG endian?

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 593
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: Are there any tools like xkas for the nes?
« Reply #4 on: November 28, 2012, 09:59:10 pm »
@Starwin I thought the NES was BIG endian?
Nope. $ABCD would be stored as CD AB. If you're looking at the debugger, just compare the hex on the left to the decoded operands for instructions that use absolute addressing.

As far as patching with an assembler, back when I used ASM6 I wrote a very simple console app to insert the patches. It would go something like this.
Code: [Select]
>asm6 myhack.asm
>patchrom thegame.nes myhack.bin $1C010

Even if you have a minimal understanding of C++ you should be able to whip up a simple utility to patch files.

These days I use an assembler I wrote for myself designed for patching, which produces .ips files. The downside is that nobody else on the planet uses the same assembler. Well... I actually made my own NES IDE, but again, nobody else on the planet uses it.

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Are there any tools like xkas for the nes?
« Reply #5 on: November 28, 2012, 10:42:01 pm »
I'd use both if they were available to me... that is unless you want to be the only one on the planet who uses those two programs. In which case I should probably get to coding my own...

snarfblam

  • Submission Reviewer
  • Hero Member
  • *****
  • Posts: 593
  • CANT HACK METROID
    • View Profile
    • snarfblam
Re: Are there any tools like xkas for the nes?
« Reply #6 on: December 02, 2012, 05:49:02 pm »
If you're still interested, here's the assembler, http://snarfblam.com/files/snarfblasm_1.1.zip. And documentation. Like I said, nobody really uses this but me, so it's probably not the most bestly debugged assembler out there.

The assembler assumes banks are $4000 bytes. Suppose you want to patch some code into bank 7 at $D00D (located at 0x1D01D in the ROM) to give the player 255 lives. You can do it one of two ways.

1 - Specify which file to patch and where to patch it on the command line.
Spoiler:
Example.asm
Code: [Select]
;Variable declarations
PlayerLives = $6069

.ORG $D00D

lda #$FF
sta PlayerLives
Command line
Code: [Select]
snarfblasm Example.asm TheGame.nes -asm6:on -offset:$1D01D

2 - Use the .PATCH directive. This allows you to include multiple patches in the same file and produces an IPS file. Note that .PATCH replaces .ORG in this case.

Spoiler:
Example.asm
Code: [Select]
;Variable declarations
PlayerLives = $6069

; bank 7, address $D00D
.PATCH 07:D00D

lda #$FF
sta PlayerLives
Command line (produces example.ips):
Code: [Select]
snarfblasm Example.asm -asm6:on

The -asm6:on switch just increases compatibility with asm6's loose syntax. Actually, I'd encourage you to avoid it unless it's needed. I included it in case you're copying code that uses asm6-specific syntax. Also, head's up: no macros! If macros are important to you, this is probably a deal breaker. If not, but you want to keep the possibility of using macros open down the road, code should port over to asm6 pretty painlessly.
« Last Edit: December 02, 2012, 05:55:10 pm by snarfblam »

Pikachumanson

  • Hero Member
  • *****
  • Posts: 607
    • View Profile
Re: Are there any tools like xkas for the nes?
« Reply #7 on: December 02, 2012, 06:06:58 pm »
Thank you! I apreciate it!