Help me with this code

So, I found this code from a website (linked at the bottom) that explains how the glitch beams work in Super Metroid. There are few things that I don't understand about this code.


$90/AD12 B7 00 LDA [$00],y
$90/AD14 9F C0 C1 7E STA $7EC1C0,x
$90/AD18 E8 INX
$90/AD19 E8 INX
$90/AD1A C8 INY
$90/AD1B C8 INY
$90/AD1C C0 20 00 CPY #$0020
$90/AD1F 30 F1 BMI $F1 [$AD12]
$90/AD21 60 RTS

1. What are the numbers between $90/AD12 and LDA [$00],y

2. Why are some of the "positions in the ROM" (not sure what they are actually called) missing? (like $90/AD13)

3. What are the BMI and RTS?

4. What are the numbers inside the [ and ] ?



Here is the site I found this code. There are few other similar codes, so I just took this one as an example. If you want to fond the code that I used here, search for Spacetime beam (0psi0)

http://tasvideos.org/GameResources/SNES/SuperMetroid.html




EDIT: I forgot one thing. Is there a list of the "machine codes" for each "instruction" (like LDA and STA) that the SNES actually reads them. (like JSR is 20 in Hex if I remember correctly).

Comments

  • 1. That is the hex for what is on the right. If you were to look in the ROM with a hex editor where that lda is, you would see those numbers. Same with every consecutive one.



    2. It's not missing. See the 00 on line 1? That is what you are missing. If you'll notice between line 2 and 3, there would be 3 bytes missing, but the missing bytes are actually c0 c1 7e.



    3. BMI is branch on minus and RTS is return from subroutine.



    4. The number inside the brackets after the BMI (I believe that is what you are referring to), is where the program branches to when the negative flag (tested by the BMI) is set. That is included by the disassembler for your own reference, because BMI is going to be an 8-bit branch, the $f1 is telling the program where to go. So that number on the right is just showing you so you don't have to bother counting to the place where the branch goes. And notice that the number they give is actually line 1? So when the negative flag is set, the program loops back to the beginning of this snippet you posted.



    As for the question you edited in, do a search for 65816 opcodes and you should find what you want. And I'll throw in that since you weren't familiar with BMI, do a search for 65816 instruction set. You might even find them together somewhere : )



    Hope this helps and is understandable!
  • So, $F1 after the BMI is telling what it checks (if it's "minus") and if it minus then it branches to $AD12. If not then it continues normally to $90/AD21?

  • That $f1 is telling it where to branch to. Let me try to illustrate with the code as if it were in the source file. THE_ROUTINE will be the name of this routine hehe


     


     


    THE_ROUTINE:


    LDA [$00],y


    STA $7EC1C0,x


    INX


    INX


    INY


    INY


    CPY #$0020


    BMI THE_ROUTINE


    RTS


     


     


    The BMI is actually checking the negative flag of the CPY right above (which means ComPare Y). 


     
  • Okay, now I get it

    I took a look at SNES's opcodes and the machine-codes and now I'm kind of confused because there are so many different Addressing Modes and I can't find much information about them. Only site I have found has very lacking information about them.
  • 65816 is an expanded 6502, so most of docs consider you already familiar with 6502, and focus on the differences. So you just need to get a 6502 book, tons of them around. Then read something like this to get more 65816 understanding.
Sign In or Register to comment.