Advertisement
SethBling

Jeffw's Shell Y-Coordinate Explanation

Jan 26th, 2015
1,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.91 KB | None | 0 0
  1. Yes, the goal is to get no-op code in the Y-position table.
  2.  
  3. Here is a very helpful reference page for all SNES assembly instructions: http://wiki.superfamicom.org/snes/show/65816+Reference. Each hex value from 0 to FF corresponds to an instruction. You want to avoid executing any instruction that will transfer control to somewhere else away from the sprite Y-position table. So definitely avoid all JSR, JSL, JMP, and JML instructions since those jump to somewhere else. Also avoid the return instructions RTS, RTL and RTI. Also it's best to avoid all branch instructions which includes BCC, BCS, BEQ, BMI, BNE, BPL, BRA, BVC, BVS. Some of these instructions only branch if certain conditions are met and could potentially be no-op however, these conditions are nearly impossible to control so its best to just avoid all of these. Any instruction that modifies the stack is also bad, which includes all instructions that start with P. There are a few other miscellaneous instructions that are also bad such as BRK, SED, SEI, STP, TCD, TCS, TXS, XCE, maybe COP, REP and SEP could be bad but not necessarily, and I'm not totally sure about WAI and WDM but they might be ok. Everything else should be fine. Some instructions do modify memory but as long as the memory getting modified isn't critical (very unlikely that it is) it shouldn't be a problem.
  4.  
  5. Now, the possible Y-position values that a shell can end up with range from 40 (resting on the ground) to 39 (the apex of the bounce). Of these values, all are totally safe instructions except for 40 which is RTI. So that is why you don't stomp shells on the ground. The real problem is the p-switch in slot 7 which unfortunately will always have Y-position 70 which is instruction BVS. This instruction branches if the overflow flag is set, which it almost always will be unless some previous instructions in the Y-position table happened to have cleared it. So you want to avoid executing the 70 as an instruction, and instead let it get used as an instruction operand. Each instruction will have a number of operands, which get used along with the instruction. On the reference page the bytes column indicates the number of bytes used by this instruction. The first byte will be the instruction code and the rest will be operands. So one simple way to improve your chances is to aim for instructions that have lots of operands so that the 70 is more likely to be used as an operand as opposed to an instruction. Here are the number of bytes in all possible instructions you can end up with for the shell Y-positions:
  6. 3F - 4 bytes
  7. 3E - 3 bytes
  8. 3D - 3 bytes
  9. 3C - 3 bytes
  10. 3B - 1 byte
  11. 3A - 1 byte
  12. 39 - 3 bytes
  13.  
  14. So it's better to stomp the shell when it's very close to the ground aiming for 3F to 3C to get instructions with lots of operands, but if you want to optimize even more, you could aim for a 1 byte long instruction for the shell in slot 4 to avoid getting a 3 byte long instruction there potentially ending up executing slot 7 as an instruction. Similarly, you could aim for a 1 byte long instruction in slot 1 as well to avoid executing slot 4 as an instruction, which could lead to slot 7. Anyway, this kind of stuff can be helpful to know but isn't too important. The only thing I did was aim for early smashes to try to avoid the 1 byte instructions.
  15.  
  16. As an interesting note, the actual code for the credits warp begins at address $E5, but in the three address before that we have:
  17. $E4: 0A which is just a safe 1 byte long instruction which you program with the X-position of the shell in slot 0. This could instead be any safe 1 byte long instruction.
  18. $E3: 37 which is a safe 2 byte long instruction which comes from the Y-position of the mushroom
  19. $E2: 0D which is a safe 3 byte long instruction which comes from the Y-position of the vine
  20. So these guarantee that the value in $E5 will always be reached and executed as an instruction instead of an operand, guaranteeing the credits warp code gets executed as intended.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement