Advertisement
Guest User

Untitled

a guest
May 18th, 2011
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.06 KB | None | 0 0
  1. Saves x, y, and p. Modifies A and values at $03F0- (and $CC).
  2. Electrospecter thinks this is the RNG. If so, the result is
  3. a random byte in the low part of A (the high part is not
  4. used, seems to always be 0f, but we don't have all the branches
  5. here).
  6. $C0/38A0 DA PHX A:0007 X:0000 Y:0000 P:envMxdIzc
  7. $C0/38A1 5A PHY A:0007 X:0000 Y:0000 P:envMxdIzc
  8. $C0/38A2 08 PHP A:0007 X:0000 Y:0000 P:envMxdIzc
  9. $C0/38A3 E2 10 SEP #$10 A:0007 X:0000 Y:0000 P:envMxdIzc
  10. $C0/38A5 AE F0 03 LDX $03F0 [$7E:03F0] A:0007 X:0000 Y:0000 P:envMXdIzc
  11. $C0/38A8 BD F1 03 LDA $03F1,x[$7E:03F9] A:0007 X:0008 Y:0000 P:envMXdIzc
  12. $C0/38AB 85 CC STA $CC [$00:03CC] A:007D X:0008 Y:0000 P:envMXdIzc
  13. $C0/38AD CA DEX A:007D X:0008 Y:0000 P:envMXdIzc
  14. $C0/38AE 10 02 BPL $02 [$38B2] A:007D X:0007 Y:0000 P:envMXdIzc
  15. $C0/38B2 BD F1 03 LDA $03F1,x[$7E:03F8] A:007D X:0007 Y:0000 P:envMXdIzc
  16. $C0/38B5 18 CLC A:00AF X:0007 Y:0000 P:eNvMXdIzc
  17. $C0/38B6 65 CC ADC $CC [$00:03CC] A:00AF X:0007 Y:0000 P:eNvMXdIzc
  18. $C0/38B8 9D F1 03 STA $03F1,x[$7E:03F8] A:002C X:0007 Y:0000 P:envMXdIzC
  19. $C0/38BB EB XBA A:002C X:0007 Y:0000 P:envMXdIzC
  20. $C0/38BC EE F0 03 INC $03F0 [$7E:03F0] A:2C00 X:0007 Y:0000 P:envMXdIZC
  21. $C0/38BF A9 0F LDA #$0F A:2C00 X:0007 Y:0000 P:envMXdIzC
  22. $C0/38C1 CD F0 03 CMP $03F0 [$7E:03F0] A:2C0F X:0007 Y:0000 P:envMXdIzC
  23. $C0/38C4 D0 03 BNE $03 [$38C9] A:2C0F X:0007 Y:0000 P:envMXdIzC
  24. $C0/38C9 EB XBA A:2C0F X:0007 Y:0000 P:envMXdIzC
  25. $C0/38CA 28 PLP A:0F2C X:0007 Y:0000 P:envMXdIzC
  26. $C0/38CB 7A PLY A:0F2C X:0007 Y:0000 P:envMxdIzc
  27. $C0/38CC FA PLX A:0F2C X:0007 Y:0000 P:envMxdIZc
  28. $C0/38CD 60 RTS A:0F2C X:0000 Y:0000 P:envMxdIZc
  29.  
  30.  
  31. $C0/389F 6B RTL A:0F2C X:0000 Y:0000 P:envMxdIZc
  32.  
  33. Discard the top 2 bits of A
  34. $C8/E13D 29 3F AND #$3F A:0F2C X:0000 Y:0000 P:envMxdIZc
  35. Compare with $A4, and save result of comparison for later
  36. $C8/E13F C5 A4 CMP $A4 [$00:03A4] A:0F2C X:0000 Y:0000 P:envMxdIzc
  37. $C8/E141 08 PHP A:0F2C X:0000 Y:0000 P:envMxdIzC
  38. Take the two highest bits in $AC, and do different things
  39. depending on which of them are set. We lack the 00, 40 and 80 branches:
  40. only the C0 branch happens here.
  41. $C8/E142 A5 AC LDA $AC [$00:03AC] A:0F2C X:0000 Y:0000 P:envMxdIzC
  42. $C8/E144 29 C0 AND #$C0 A:0FF8 X:0000 Y:0000 P:eNvMxdIzC
  43. $C8/E146 D0 03 BNE $03 [$E14B] A:0FC0 X:0000 Y:0000 P:eNvMxdIzC
  44. $C8/E14B C9 40 CMP #$40 A:0FC0 X:0000 Y:0000 P:eNvMxdIzC
  45. $C8/E14D F0 13 BEQ $13 [$E162] A:0FC0 X:0000 Y:0000 P:eNvMxdIzC
  46. $C8/E14F C9 80 CMP #$80 A:0FC0 X:0000 Y:0000 P:eNvMxdIzC
  47. $C8/E151 F0 1E BEQ $1E [$E171] A:0FC0 X:0000 Y:0000 P:envMxdIzC
  48. Ok, we now use the result of the first comparison. Branch
  49. if the original A was >= than the value in $A4, which is the case here.
  50. $C8/E153 28 PLP A:0FC0 X:0000 Y:0000 P:envMxdIzC
  51. $C8/E154 90 06 BCC $06 [$E15C] A:0FC0 X:0000 Y:0000 P:envMxdIzC
  52. Look up D03A53[x]. x got its value earlier than this trace started.
  53. Probably useful to find out what this far-away table does
  54. $C8/E156 BF 53 3A D0 LDA $D03A53,x[$D0:3A53] A:0FC0 X:0000 Y:0000 P:envMxdIzC
  55. $C8/E15A 80 22 BRA $22 [$E17E] A:0F40 X:0000 Y:0000 P:envMxdIzC
  56. The table value (40) is stored in $A4 again
  57. $C8/E17E 85 A4 STA $A4 [$00:03A4] A:0F40 X:0000 Y:0000 P:envMxdIzC
  58. $C8/E180 C9 00 CMP #$00 A:0F40 X:0000 Y:0000 P:envMxdIzC
  59. Branch if the value is >= 80, which it isn't.
  60. $C8/E182 30 15 BMI $15 [$E199] A:0F40 X:0000 Y:0000 P:envMxdIzC
  61. $C8/E184 22 20 64 C0 JSL $C06420[$C0:6420] A:0F40 X:0000 Y:0000 P:envMxdIzC
  62.  
  63. This simple code just saves the processor flags, the high
  64. accumulator (B), and the direct page, makes sure A is 8 bit,
  65. and stores A in $1820 and 0 in $1821. It is basially a wrapper,
  66. preparing for the subroutine $C064A4. The subroutine at $C064A4
  67. just sets the direct page to be 0 instead of $300, as it was.
  68. $C0/6420 4C BD 64 JMP $64BD [$C0:64BD] A:0F40 X:0000 Y:0000 P:envMxdIzC
  69. $C0/64BD 08 PHP A:0F40 X:0000 Y:0000 P:envMxdIzC
  70. $C0/64BE 8B PHB A:0F40 X:0000 Y:0000 P:envMxdIzC
  71. $C0/64BF 0B PHD A:0F40 X:0000 Y:0000 P:envMxdIzC
  72. $C0/64C0 E2 20 SEP #$20 A:0F40 X:0000 Y:0000 P:envMxdIzC
  73. $C0/64C2 9C 21 18 STZ $1821 [$7E:1821] A:0F40 X:0000 Y:0000 P:envMxdIzC
  74. $C0/64C5 8D 20 18 STA $1820 [$7E:1820] A:0F40 X:0000 Y:0000 P:envMxdIzC
  75. $C0/64C8 22 A4 64 C0 JSL $C064A4[$C0:64A4] A:0F40 X:0000 Y:0000 P:envMxdIzC
  76.  
  77.  
  78. $C0/64A4 C2 30 REP #$30 A:0F40 X:0000 Y:0000 P:envMxdIzC
  79. $C0/64A6 48 PHA A:0F40 X:0000 Y:0000 P:envmxdIzC
  80. $C0/64A7 A9 00 00 LDA #$0000 A:0F40 X:0000 Y:0000 P:envmxdIzC
  81. $C0/64AA 5B TCD A:0000 X:0000 Y:0000 P:envmxdIZC
  82. $C0/64AB E2 20 SEP #$20 A:0000 X:0000 Y:0000 P:envmxdIZC
  83. $C0/64AD 48 PHA A:0000 X:0000 Y:0000 P:envMxdIZC
  84. $C0/64AE AB PLB A:0000 X:0000 Y:0000 P:envMxdIZC
  85. $C0/64AF C2 30 REP #$30 A:0000 X:0000 Y:0000 P:envMxdIZC
  86. $C0/64B1 68 PLA A:0000 X:0000 Y:0000 P:envmxdIZC
  87. $C0/64B2 6B RTL A:0F40 X:0000 Y:0000 P:envmxdIzC
  88.  
  89. And finally call the subroutine we prepared for.
  90. $C0/64CC 20 D1 64 JSR $64D1 [$C0:64D1] A:0F40 X:0000 Y:0000 P:envmxdIzC
  91.  
  92.  
  93. $C0/64D1 C2 10 REP #$10 A:0F40 X:0000 Y:0000 P:envmxdIzC
  94. $C0/64D3 E2 20 SEP #$20 A:0F40 X:0000 Y:0000 P:envmxdIzC
  95. We will loop over Y.
  96. $C0/64D5 A0 00 00 LDY #$0000 A:0F40 X:0000 Y:0000 P:envMxdIzC
  97. Handle various values of $1280 (ultimately based on what
  98. we looked up in table $D03A53. The index into the table was
  99. x, which was set before the trace started. But the fact that
  100. we used this table is probably due to the value of A we got
  101. from the supposed RNG.
  102. if($1280 is any of 0, 15 or 2A) goto $6514 (seems like this basically gives up)
  103. $C0/64D8 AD 20 18 LDA $1820 [$00:1820] A:0F40 X:0000 Y:0000 P:envMxdIZC
  104. $C0/64DB F0 37 BEQ $37 [$6514] A:0F40 X:0000 Y:0000 P:envMxdIzC
  105. $C0/64DD C9 15 CMP #$15 A:0F40 X:0000 Y:0000 P:envMxdIzC
  106. $C0/64DF F0 33 BEQ $33 [$6514] A:0F40 X:0000 Y:0000 P:envMxdIzC
  107. $C0/64E1 C9 2A CMP #$2A A:0F40 X:0000 Y:0000 P:envMxdIzC
  108. $C0/64E3 F0 2F BEQ $2F [$6514] A:0F40 X:0000 Y:0000 P:envMxdIzC
  109. Otherwise, find out which X we will use based on how high the A
  110. value is. If A < 40, goto $6516, which will try to place an item?
  111. $C0/64E5 A2 24 00 LDX #$0024 A:0F40 X:0000 Y:0000 P:envMxdIzC
  112. $C0/64E8 C9 15 CMP #$15 A:0F40 X:0024 Y:0000 P:envMxdIzC
  113. $C0/64EA 90 2A BCC $2A [$6516] A:0F40 X:0024 Y:0000 P:envMxdIzC
  114. $C0/64EC A2 30 00 LDX #$0030 A:0F40 X:0024 Y:0000 P:envMxdIzC
  115. $C0/64EF C9 2A CMP #$2A A:0F40 X:0030 Y:0000 P:envMxdIzC
  116. $C0/64F1 90 23 BCC $23 [$6516] A:0F40 X:0030 Y:0000 P:envMxdIzC
  117. $C0/64F3 A2 3C 00 LDX #$003C A:0F40 X:0030 Y:0000 P:envMxdIzC
  118. $C0/64F6 C9 3F CMP #$3F A:0F40 X:003C Y:0000 P:envMxdIzC
  119. $C0/64F8 90 1C BCC $1C [$6516] A:0F40 X:003C Y:0000 P:envMxdIzC
  120. Otherwise, subtract 40, and overwrite $1820, and use an even bigger x.
  121. If the result is <= C, goto $652E. Otherwise, subtract 40
  122. again (looks like this could underflow), overwrite $1820, and use
  123. an even bigger x. Otherwise go to either 655F or 658D depending on
  124. the value.
  125. $C0/64FA 38 SEC A:0F40 X:003C Y:0000 P:envMxdIzC
  126. $C0/64FB E9 40 SBC #$40 A:0F40 X:003C Y:0000 P:envMxdIzC
  127. $C0/64FD 8D 20 18 STA $1820 [$00:1820] A:0F00 X:003C Y:0000 P:envMxdIZC
  128. $C0/6500 A2 48 00 LDX #$0048 A:0F00 X:003C Y:0000 P:envMxdIZC
  129. $C0/6503 C9 0C CMP #$0C A:0F00 X:0048 Y:0000 P:envMxdIzC
  130. $C0/6505 90 27 BCC $27 [$652E] A:0F00 X:0048 Y:0000 P:eNvMxdIzc
  131. $C0/6507 38 SEC
  132. $C0/6508 E9 40 SBC #$40
  133. $C0/650A 8D 20 18 STA $1820 [$00:1820]
  134. $C0/650D A2 54 00 LDX #$0054
  135. $C0/6510 C9 48 CMP #$48
  136. $C0/6512 90 4B BCC $4B [$655F]
  137. $C0/6514 80 77 BRA $77 [$658D]
  138. Ok, the $6516 branch. Basicallly:
  139. for(;7ECC00[x] != FF && Y < 0B;++x,--y);
  140. This looks like it might be looking for a free spot
  141. in the inventory (which is pretty small, just B places).
  142. Branch to $6529 if we found a free spot.
  143. $C0/6516 BF 00 CC 7E LDA $7ECC00,x[$7E:CC05]
  144. $C0/651A C9 FF CMP #$FF
  145. $C0/651C F0 0B BEQ $0B [$6529]
  146. $C0/651E E8 INX
  147. $C0/651F C8 INY
  148. $C0/6520 C0 0B 00 CPY #$000B
  149. $C0/6523 90 F1 BCC $F1 [$6516]
  150. If we got here, we ran out of space. Set A to 1,
  151. and exit.
  152. $C0/6525 A9 01 LDA #$01
  153. $C0/6527 80 66 BRA $66 [$658F]
  154. Ok, we found a free spot. Get the 1820 value, and
  155. continue to 657A
  156. $C0/6529 AD 20 18 LDA $1820 [$00:1820]
  157. $C0/652C 80 4C BRA $4C [$657A]
  158. The $652E branch. Which is an alternative loop to the
  159. earlier one. Different kind of item?
  160. Loop until:
  161. 7ECC00[x] == FF (found free space) => 654B
  162. 7ECC00[x]&1F == 1820 (found existing item of same type?) => 6552
  163. Y > C (ran out of space) => 6547
  164. $C0/652E 9C 21 18 STZ $1821 [$00:1821] A:0F00 X:0048 Y:0000 P:eNvMxdIzc
  165. $C0/6531 BF 00 CC 7E LDA $7ECC00,x[$7E:CC48] A:0F00 X:0048 Y:0000 P:eNvMxdIzc
  166. $C0/6535 C9 FF CMP #$FF A:0FFF X:0048 Y:0000 P:eNvMxdIzc
  167. $C0/6537 F0 12 BEQ $12 [$654B] A:0FFF X:0048 Y:0000 P:envMxdIZC
  168. $C0/6539 29 1F AND #$1F
  169. $C0/653B CD 20 18 CMP $1820 [$00:1820]
  170. $C0/653E F0 12 BEQ $12 [$6552]
  171. $C0/6540 E8 INX
  172. $C0/6541 C8 INY
  173. $C0/6542 C0 0C 00 CPY #$000C
  174. $C0/6545 90 E7 BCC $E7 [$652E]
  175. No space. Set status to 2, and exit.
  176. $C0/6547 A9 02 LDA #$02
  177. $C0/6549 80 44 BRA $44 [$658F]
  178. Found free space. Get our value, set the 20 bit, and go to 657A, were
  179. the intersting stuff happens.
  180. $C0/654B AD 20 18 LDA $1820 [$00:1820] A:0FFF X:0048 Y:0000 P:envMxdIZC
  181. $C0/654E 09 20 ORA #$20 A:0F00 X:0048 Y:0000 P:envMxdIZC
  182. $C0/6550 80 28 BRA $28 [$657A] A:0F20 X:0048 Y:0000 P:envMxdIzC
  183. Found an item of existing type? Check the item we have.
  184. Is Item+20 >= 9F? If so, exit with status 2.
  185. Otherwise, proceed to 657A.
  186. $C0/6552 BF 00 CC 7E LDA $7ECC00,x[$7E:CC05]
  187. $C0/6556 18 CLC
  188. $C0/6557 69 20 ADC #$20
  189. $C0/6559 C9 9F CMP #$9F
  190. $C0/655B B0 EA BCS $EA [$6547]
  191. $C0/655D 80 1B BRA $1B [$657A]
  192. ...
  193. $C0/655F 38 SEC
  194. $C0/6560 E9 09 SBC #$09
  195. $C0/6562 30 03 BMI $03 [$6567]
  196. $C0/6564 E8 INX
  197. $C0/6565 80 F8 BRA $F8 [$655F]
  198. $C0/6567 18 CLC
  199. $C0/6568 69 09 ADC #$09
  200. $C0/656A 8D 20 18 STA $1820 [$00:1820]
  201. $C0/656D BF 00 CC 7E LDA $7ECC00,x[$7E:CC05]
  202. $C0/6571 C9 FF CMP #$FF
  203. $C0/6573 F0 B4 BEQ $B4 [$6529]
  204. $C0/6575 29 C0 AND #$C0
  205. $C0/6577 0D 20 18 ORA $1820 [$00:1820]
  206. Ok, this part seems to be the main point of the function.
  207. Set A |= $1821 << 6:
  208. $C0/657A 48 PHA A:0F20 X:0048 Y:0000 P:envMxdIzC
  209. $C0/657B AD 21 18 LDA $1821 [$00:1821] A:0F20 X:0048 Y:0000 P:envMxdIzC
  210. $C0/657E 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZC
  211. $C0/657F 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
  212. $C0/6580 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
  213. $C0/6581 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
  214. $C0/6582 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
  215. $C0/6583 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
  216. $C0/6584 03 01 ORA $01,s [$00:01E5] A:0F00 X:0048 Y:0000 P:envMxdIZc
  217. $C0/6586 83 01 STA $01,s [$00:01E5] A:0F20 X:0048 Y:0000 P:envMxdIzc
  218. $C0/6588 68 PLA A:0F20 X:0048 Y:0000 P:envMxdIzc
  219. And save the result to the current inventory space(?).
  220. $C0/6589 9F 00 CC 7E STA $7ECC00,x[$7E:CC48] A:0F20 X:0048 Y:0000 P:envMxdIzc
  221. Exiting with status 0.
  222. $C0/658D A9 00 LDA #$00 A:0F20 X:0048 Y:0000 P:envMxdIzc
  223. $C0/658F 8F 0F CF 7E STA $7ECF0F[$7E:CF0F] A:0F00 X:0048 Y:0000 P:envMxdIZc
  224. $C0/6593 60 RTS A:0F00 X:0048 Y:0000 P:envMxdIZc
  225.  
  226. This is based on a "place an item in the inventory" interpretation.
  227. If this is correct, there are several different sorts of inventories
  228. all stored in concatenated fashion from 7ECC00 and up. The
  229. earlier parts of the code (the ones with the large steps in x
  230. values) determine which of the subinventories to use. Then,
  231. that subinventory is scanned for free space to put the item in
  232. or an item with the same type (some items can be overwritten
  233. without error, or have an amount that can be increased (looks
  234. like the top 2 bits of an inventory byte hold this amount
  235. if that is the case).
  236.  
  237. The item ultimately placed is given by $1820, so look for things
  238. that change this address.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement