Announcement

Collapse
No announcement yet.

Help deciphering 65816 (SNES) opcodes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help deciphering 65816 (SNES) opcodes

    I've been studying ASM for different systems and trying to get a grasp on how it works on different systems. I'm looking at everything from Atari 2600 programming tutorials and ASM lists to... well, anything that uses a single ROM format. I think that came to an end in the 16 bit era, but the N64 may have used it. Haven't gotten that far yet.

    That actually brings me to my question. I followed this tutorial for building a simple SNES program that does nothing but display a simple color on screen and then enter an eternal loop. Once I had the program assembled, I opened it up in a hex editor to try and learn how the file was assembled. With an opcode list, everything was pretty straightforward. For instance, it wasn't hard to figure out that these lines...

    lda #%11100000 ; Load the low byte of the green color.
    sta $2122
    ...were compiled to "A9 00 8D 22 21" when you compare the data and remember that all numbers on the 6502 (NES, Atari 2600) and its descendant, the 65816, are Little Endian. All straightforward. No problems. 8D = STA. A9 = LDA. This page shows that to be true. So now we come to the very last line in the example program, which looks like this:

    ; Loop forever.
    Forever:
    jmp Forever

    .ends
    The data at the location in the compiled ROM reads as: 4C 1C 81. I tried to approach this from every angle I possibly can, but I can't decipher what it means. I checked the ASM reference, and 4C (JMP) is an operation that is 3 bytes long and uses Absolute Addressing. Absolute Addressing is not complicated. It takes the two byte address, Little Endian, at face value. So 4C 1C 81 means JUMP TO $811C. I'm not sure what this means. Chalk this up to inexperience, because that's exactly what's happening here, but I am having real trouble deciphering this. If it's referring to address $811C in the ROM, it shouldn't be. Couldn't be. If it's referring to $811C in memory, well, I checked this page and that didn't make things any clearer.

    Anyone who is experienced in these matters who could lend a hand, I would greatly appreciate some clarification.

    Thank you.

    -Turtle.

  • #2
    I know nothing about this, but here are some links:

    https://hackaday.com/2015/07/29/revi...816-computers/

    https://wdc65xx.com/Single-Board-Computers/w65c816sxb/
    Last edited by dlevere; 03-10-2021, 01:55:26 AM.
    The Hackmaster

    Comment


    • #3
      Thank you for your helpful links. I will definitely keep those bookmarked. However, I managed to puzzle it out with a little help from a Stack Overflow question that was very similar. I'll explain it here for anyone who might need some clarity on this in the future.

      First, the comment that made the light come on for me reads as follows:

      Address $230001 would access WRAM (this is also shown on the page I linked to). For a HiROM game you'd use the mirror starting at $C00000, i.e. address $E30001 in your case. For a LoROM game you don't have ROM in the lower halves of each bank; only the upper half ($8000-$FFFF) of the relevant banks contains ROM.
      Since this tutorial ROM is considered LoRom, the ROM data gets mapped to $8000-$FFFF only. That explains the first part of the $811C address. That only leaves 11C to figure out. Each row of data is laid out in the hex editor tables in sixteen characters, which are numbered using Zero Indexing. So each one is 0-F. Basic hex. There are 17 rows above the last row with the instruction in question. So we multiply 16 x 17 and get 272. The JMP instruction is at address C (12) on the last line. So we add 12 (C) to 272 and get 284. 284 in hex is 11C. $8000 (The ROM memory address) + $11C (the instruction address). So "JMP 1C 81" means "Jump to this instruction in memory and do that forever". Which is what the source code said it did. I just needed to understand more about how ROM was mapped in the SNES memory before I understood what I was looking at.
      Last edited by SawmillTurtle; 03-10-2021, 04:42:16 PM.

      Comment

      Working...
      X