Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Saves x, y, and p. Modifies A and values at $03F0- (and $CC).
- Electrospecter thinks this is the RNG. If so, the result is
- a random byte in the low part of A (the high part is not
- used, seems to always be 0f, but we don't have all the branches
- here).
- $C0/38A0 DA PHX A:0007 X:0000 Y:0000 P:envMxdIzc
- $C0/38A1 5A PHY A:0007 X:0000 Y:0000 P:envMxdIzc
- $C0/38A2 08 PHP A:0007 X:0000 Y:0000 P:envMxdIzc
- $C0/38A3 E2 10 SEP #$10 A:0007 X:0000 Y:0000 P:envMxdIzc
- $C0/38A5 AE F0 03 LDX $03F0 [$7E:03F0] A:0007 X:0000 Y:0000 P:envMXdIzc
- $C0/38A8 BD F1 03 LDA $03F1,x[$7E:03F9] A:0007 X:0008 Y:0000 P:envMXdIzc
- $C0/38AB 85 CC STA $CC [$00:03CC] A:007D X:0008 Y:0000 P:envMXdIzc
- $C0/38AD CA DEX A:007D X:0008 Y:0000 P:envMXdIzc
- $C0/38AE 10 02 BPL $02 [$38B2] A:007D X:0007 Y:0000 P:envMXdIzc
- $C0/38B2 BD F1 03 LDA $03F1,x[$7E:03F8] A:007D X:0007 Y:0000 P:envMXdIzc
- $C0/38B5 18 CLC A:00AF X:0007 Y:0000 P:eNvMXdIzc
- $C0/38B6 65 CC ADC $CC [$00:03CC] A:00AF X:0007 Y:0000 P:eNvMXdIzc
- $C0/38B8 9D F1 03 STA $03F1,x[$7E:03F8] A:002C X:0007 Y:0000 P:envMXdIzC
- $C0/38BB EB XBA A:002C X:0007 Y:0000 P:envMXdIzC
- $C0/38BC EE F0 03 INC $03F0 [$7E:03F0] A:2C00 X:0007 Y:0000 P:envMXdIZC
- $C0/38BF A9 0F LDA #$0F A:2C00 X:0007 Y:0000 P:envMXdIzC
- $C0/38C1 CD F0 03 CMP $03F0 [$7E:03F0] A:2C0F X:0007 Y:0000 P:envMXdIzC
- $C0/38C4 D0 03 BNE $03 [$38C9] A:2C0F X:0007 Y:0000 P:envMXdIzC
- $C0/38C9 EB XBA A:2C0F X:0007 Y:0000 P:envMXdIzC
- $C0/38CA 28 PLP A:0F2C X:0007 Y:0000 P:envMXdIzC
- $C0/38CB 7A PLY A:0F2C X:0007 Y:0000 P:envMxdIzc
- $C0/38CC FA PLX A:0F2C X:0007 Y:0000 P:envMxdIZc
- $C0/38CD 60 RTS A:0F2C X:0000 Y:0000 P:envMxdIZc
- $C0/389F 6B RTL A:0F2C X:0000 Y:0000 P:envMxdIZc
- Discard the top 2 bits of A
- $C8/E13D 29 3F AND #$3F A:0F2C X:0000 Y:0000 P:envMxdIZc
- Compare with $A4, and save result of comparison for later
- $C8/E13F C5 A4 CMP $A4 [$00:03A4] A:0F2C X:0000 Y:0000 P:envMxdIzc
- $C8/E141 08 PHP A:0F2C X:0000 Y:0000 P:envMxdIzC
- Take the two highest bits in $AC, and do different things
- depending on which of them are set. We lack the 00, 40 and 80 branches:
- only the C0 branch happens here.
- $C8/E142 A5 AC LDA $AC [$00:03AC] A:0F2C X:0000 Y:0000 P:envMxdIzC
- $C8/E144 29 C0 AND #$C0 A:0FF8 X:0000 Y:0000 P:eNvMxdIzC
- $C8/E146 D0 03 BNE $03 [$E14B] A:0FC0 X:0000 Y:0000 P:eNvMxdIzC
- $C8/E14B C9 40 CMP #$40 A:0FC0 X:0000 Y:0000 P:eNvMxdIzC
- $C8/E14D F0 13 BEQ $13 [$E162] A:0FC0 X:0000 Y:0000 P:eNvMxdIzC
- $C8/E14F C9 80 CMP #$80 A:0FC0 X:0000 Y:0000 P:eNvMxdIzC
- $C8/E151 F0 1E BEQ $1E [$E171] A:0FC0 X:0000 Y:0000 P:envMxdIzC
- Ok, we now use the result of the first comparison. Branch
- if the original A was >= than the value in $A4, which is the case here.
- $C8/E153 28 PLP A:0FC0 X:0000 Y:0000 P:envMxdIzC
- $C8/E154 90 06 BCC $06 [$E15C] A:0FC0 X:0000 Y:0000 P:envMxdIzC
- Look up D03A53[x]. x got its value earlier than this trace started.
- Probably useful to find out what this far-away table does
- $C8/E156 BF 53 3A D0 LDA $D03A53,x[$D0:3A53] A:0FC0 X:0000 Y:0000 P:envMxdIzC
- $C8/E15A 80 22 BRA $22 [$E17E] A:0F40 X:0000 Y:0000 P:envMxdIzC
- The table value (40) is stored in $A4 again
- $C8/E17E 85 A4 STA $A4 [$00:03A4] A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C8/E180 C9 00 CMP #$00 A:0F40 X:0000 Y:0000 P:envMxdIzC
- Branch if the value is >= 80, which it isn't.
- $C8/E182 30 15 BMI $15 [$E199] A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C8/E184 22 20 64 C0 JSL $C06420[$C0:6420] A:0F40 X:0000 Y:0000 P:envMxdIzC
- This simple code just saves the processor flags, the high
- accumulator (B), and the direct page, makes sure A is 8 bit,
- and stores A in $1820 and 0 in $1821. It is basially a wrapper,
- preparing for the subroutine $C064A4. The subroutine at $C064A4
- just sets the direct page to be 0 instead of $300, as it was.
- $C0/6420 4C BD 64 JMP $64BD [$C0:64BD] A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64BD 08 PHP A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64BE 8B PHB A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64BF 0B PHD A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64C0 E2 20 SEP #$20 A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64C2 9C 21 18 STZ $1821 [$7E:1821] A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64C5 8D 20 18 STA $1820 [$7E:1820] A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64C8 22 A4 64 C0 JSL $C064A4[$C0:64A4] A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64A4 C2 30 REP #$30 A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64A6 48 PHA A:0F40 X:0000 Y:0000 P:envmxdIzC
- $C0/64A7 A9 00 00 LDA #$0000 A:0F40 X:0000 Y:0000 P:envmxdIzC
- $C0/64AA 5B TCD A:0000 X:0000 Y:0000 P:envmxdIZC
- $C0/64AB E2 20 SEP #$20 A:0000 X:0000 Y:0000 P:envmxdIZC
- $C0/64AD 48 PHA A:0000 X:0000 Y:0000 P:envMxdIZC
- $C0/64AE AB PLB A:0000 X:0000 Y:0000 P:envMxdIZC
- $C0/64AF C2 30 REP #$30 A:0000 X:0000 Y:0000 P:envMxdIZC
- $C0/64B1 68 PLA A:0000 X:0000 Y:0000 P:envmxdIZC
- $C0/64B2 6B RTL A:0F40 X:0000 Y:0000 P:envmxdIzC
- And finally call the subroutine we prepared for.
- $C0/64CC 20 D1 64 JSR $64D1 [$C0:64D1] A:0F40 X:0000 Y:0000 P:envmxdIzC
- $C0/64D1 C2 10 REP #$10 A:0F40 X:0000 Y:0000 P:envmxdIzC
- $C0/64D3 E2 20 SEP #$20 A:0F40 X:0000 Y:0000 P:envmxdIzC
- We will loop over Y.
- $C0/64D5 A0 00 00 LDY #$0000 A:0F40 X:0000 Y:0000 P:envMxdIzC
- Handle various values of $1280 (ultimately based on what
- we looked up in table $D03A53. The index into the table was
- x, which was set before the trace started. But the fact that
- we used this table is probably due to the value of A we got
- from the supposed RNG.
- if($1280 is any of 0, 15 or 2A) goto $6514 (seems like this basically gives up)
- $C0/64D8 AD 20 18 LDA $1820 [$00:1820] A:0F40 X:0000 Y:0000 P:envMxdIZC
- $C0/64DB F0 37 BEQ $37 [$6514] A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64DD C9 15 CMP #$15 A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64DF F0 33 BEQ $33 [$6514] A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64E1 C9 2A CMP #$2A A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64E3 F0 2F BEQ $2F [$6514] A:0F40 X:0000 Y:0000 P:envMxdIzC
- Otherwise, find out which X we will use based on how high the A
- value is. If A < 40, goto $6516, which will try to place an item?
- $C0/64E5 A2 24 00 LDX #$0024 A:0F40 X:0000 Y:0000 P:envMxdIzC
- $C0/64E8 C9 15 CMP #$15 A:0F40 X:0024 Y:0000 P:envMxdIzC
- $C0/64EA 90 2A BCC $2A [$6516] A:0F40 X:0024 Y:0000 P:envMxdIzC
- $C0/64EC A2 30 00 LDX #$0030 A:0F40 X:0024 Y:0000 P:envMxdIzC
- $C0/64EF C9 2A CMP #$2A A:0F40 X:0030 Y:0000 P:envMxdIzC
- $C0/64F1 90 23 BCC $23 [$6516] A:0F40 X:0030 Y:0000 P:envMxdIzC
- $C0/64F3 A2 3C 00 LDX #$003C A:0F40 X:0030 Y:0000 P:envMxdIzC
- $C0/64F6 C9 3F CMP #$3F A:0F40 X:003C Y:0000 P:envMxdIzC
- $C0/64F8 90 1C BCC $1C [$6516] A:0F40 X:003C Y:0000 P:envMxdIzC
- Otherwise, subtract 40, and overwrite $1820, and use an even bigger x.
- If the result is <= C, goto $652E. Otherwise, subtract 40
- again (looks like this could underflow), overwrite $1820, and use
- an even bigger x. Otherwise go to either 655F or 658D depending on
- the value.
- $C0/64FA 38 SEC A:0F40 X:003C Y:0000 P:envMxdIzC
- $C0/64FB E9 40 SBC #$40 A:0F40 X:003C Y:0000 P:envMxdIzC
- $C0/64FD 8D 20 18 STA $1820 [$00:1820] A:0F00 X:003C Y:0000 P:envMxdIZC
- $C0/6500 A2 48 00 LDX #$0048 A:0F00 X:003C Y:0000 P:envMxdIZC
- $C0/6503 C9 0C CMP #$0C A:0F00 X:0048 Y:0000 P:envMxdIzC
- $C0/6505 90 27 BCC $27 [$652E] A:0F00 X:0048 Y:0000 P:eNvMxdIzc
- $C0/6507 38 SEC
- $C0/6508 E9 40 SBC #$40
- $C0/650A 8D 20 18 STA $1820 [$00:1820]
- $C0/650D A2 54 00 LDX #$0054
- $C0/6510 C9 48 CMP #$48
- $C0/6512 90 4B BCC $4B [$655F]
- $C0/6514 80 77 BRA $77 [$658D]
- Ok, the $6516 branch. Basicallly:
- for(;7ECC00[x] != FF && Y < 0B;++x,--y);
- This looks like it might be looking for a free spot
- in the inventory (which is pretty small, just B places).
- Branch to $6529 if we found a free spot.
- $C0/6516 BF 00 CC 7E LDA $7ECC00,x[$7E:CC05]
- $C0/651A C9 FF CMP #$FF
- $C0/651C F0 0B BEQ $0B [$6529]
- $C0/651E E8 INX
- $C0/651F C8 INY
- $C0/6520 C0 0B 00 CPY #$000B
- $C0/6523 90 F1 BCC $F1 [$6516]
- If we got here, we ran out of space. Set A to 1,
- and exit.
- $C0/6525 A9 01 LDA #$01
- $C0/6527 80 66 BRA $66 [$658F]
- Ok, we found a free spot. Get the 1820 value, and
- continue to 657A
- $C0/6529 AD 20 18 LDA $1820 [$00:1820]
- $C0/652C 80 4C BRA $4C [$657A]
- The $652E branch. Which is an alternative loop to the
- earlier one. Different kind of item?
- Loop until:
- 7ECC00[x] == FF (found free space) => 654B
- 7ECC00[x]&1F == 1820 (found existing item of same type?) => 6552
- Y > C (ran out of space) => 6547
- $C0/652E 9C 21 18 STZ $1821 [$00:1821] A:0F00 X:0048 Y:0000 P:eNvMxdIzc
- $C0/6531 BF 00 CC 7E LDA $7ECC00,x[$7E:CC48] A:0F00 X:0048 Y:0000 P:eNvMxdIzc
- $C0/6535 C9 FF CMP #$FF A:0FFF X:0048 Y:0000 P:eNvMxdIzc
- $C0/6537 F0 12 BEQ $12 [$654B] A:0FFF X:0048 Y:0000 P:envMxdIZC
- $C0/6539 29 1F AND #$1F
- $C0/653B CD 20 18 CMP $1820 [$00:1820]
- $C0/653E F0 12 BEQ $12 [$6552]
- $C0/6540 E8 INX
- $C0/6541 C8 INY
- $C0/6542 C0 0C 00 CPY #$000C
- $C0/6545 90 E7 BCC $E7 [$652E]
- No space. Set status to 2, and exit.
- $C0/6547 A9 02 LDA #$02
- $C0/6549 80 44 BRA $44 [$658F]
- Found free space. Get our value, set the 20 bit, and go to 657A, were
- the intersting stuff happens.
- $C0/654B AD 20 18 LDA $1820 [$00:1820] A:0FFF X:0048 Y:0000 P:envMxdIZC
- $C0/654E 09 20 ORA #$20 A:0F00 X:0048 Y:0000 P:envMxdIZC
- $C0/6550 80 28 BRA $28 [$657A] A:0F20 X:0048 Y:0000 P:envMxdIzC
- Found an item of existing type? Check the item we have.
- Is Item+20 >= 9F? If so, exit with status 2.
- Otherwise, proceed to 657A.
- $C0/6552 BF 00 CC 7E LDA $7ECC00,x[$7E:CC05]
- $C0/6556 18 CLC
- $C0/6557 69 20 ADC #$20
- $C0/6559 C9 9F CMP #$9F
- $C0/655B B0 EA BCS $EA [$6547]
- $C0/655D 80 1B BRA $1B [$657A]
- ...
- $C0/655F 38 SEC
- $C0/6560 E9 09 SBC #$09
- $C0/6562 30 03 BMI $03 [$6567]
- $C0/6564 E8 INX
- $C0/6565 80 F8 BRA $F8 [$655F]
- $C0/6567 18 CLC
- $C0/6568 69 09 ADC #$09
- $C0/656A 8D 20 18 STA $1820 [$00:1820]
- $C0/656D BF 00 CC 7E LDA $7ECC00,x[$7E:CC05]
- $C0/6571 C9 FF CMP #$FF
- $C0/6573 F0 B4 BEQ $B4 [$6529]
- $C0/6575 29 C0 AND #$C0
- $C0/6577 0D 20 18 ORA $1820 [$00:1820]
- Ok, this part seems to be the main point of the function.
- Set A |= $1821 << 6:
- $C0/657A 48 PHA A:0F20 X:0048 Y:0000 P:envMxdIzC
- $C0/657B AD 21 18 LDA $1821 [$00:1821] A:0F20 X:0048 Y:0000 P:envMxdIzC
- $C0/657E 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZC
- $C0/657F 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
- $C0/6580 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
- $C0/6581 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
- $C0/6582 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
- $C0/6583 0A ASL A A:0F00 X:0048 Y:0000 P:envMxdIZc
- $C0/6584 03 01 ORA $01,s [$00:01E5] A:0F00 X:0048 Y:0000 P:envMxdIZc
- $C0/6586 83 01 STA $01,s [$00:01E5] A:0F20 X:0048 Y:0000 P:envMxdIzc
- $C0/6588 68 PLA A:0F20 X:0048 Y:0000 P:envMxdIzc
- And save the result to the current inventory space(?).
- $C0/6589 9F 00 CC 7E STA $7ECC00,x[$7E:CC48] A:0F20 X:0048 Y:0000 P:envMxdIzc
- Exiting with status 0.
- $C0/658D A9 00 LDA #$00 A:0F20 X:0048 Y:0000 P:envMxdIzc
- $C0/658F 8F 0F CF 7E STA $7ECF0F[$7E:CF0F] A:0F00 X:0048 Y:0000 P:envMxdIZc
- $C0/6593 60 RTS A:0F00 X:0048 Y:0000 P:envMxdIZc
- This is based on a "place an item in the inventory" interpretation.
- If this is correct, there are several different sorts of inventories
- all stored in concatenated fashion from 7ECC00 and up. The
- earlier parts of the code (the ones with the large steps in x
- values) determine which of the subinventories to use. Then,
- that subinventory is scanned for free space to put the item in
- or an item with the same type (some items can be overwritten
- without error, or have an amount that can be increased (looks
- like the top 2 bits of an inventory byte hold this amount
- if that is the case).
- The item ultimately placed is given by $1820, so look for things
- that change this address.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement