000a5750: 3c03800f lui r3,0x800f 000a5754: 8c633a1c lw r3,0x3a1c(r3) // 800f3a1C = Counter of steal and morph. Add +1 // everytime you use steal or morph. next slot to // fill in a circular buffer? 000a5758: 3c02800f lui r2,0x800f 000a575c: 8c423a18 lw r2,0x3a18(r2) // 800f3a18 = next slot to process in Steal/Morph // circular buffer? 000a5760: 00000000 nop 000a5764: 10620087 beq r3,r2,0x000a5984 // exit if they already match, as we've already // processed them all 000a5768: 27bdfff8 addiu r29,r29,0xfff8 // subtract 8 from stack pointer, to reserve stack // space 000a576c: 3c0a8016 lui r10,0x8016 000a5770: 254a71b8 addiu r10,r10,0x71b8 // 801671b8: Start of item list in battle 000a5774: 340bffff ori r11,r0,0xffff // 65535 constant for use by this function 000a5778: 2409ffff addiu r9,r0,0xffff // -1 (268435455) constant for use by this function 000a577c: 3c02800f lui r2,0x800f 000a5780: 8c423a18 lw r2,0x3a18(r2) // next slot to process in Steal/Morph circular // buffer? 000a5784: 2406ffff addiu r6,r0,0xffff // start off as null (-1 or 268435455) 000a5788: 00021840 sll r3,r2,0x01 000a578c: 3c01800f lui r1,0x800f 000a5790: 00230821 addu r1,r1,r3 // bottom half r1 = (buffer slot * 2) 000a5794: 84233a20 lh r3,0x3a20(r1) // get Item ID from this circular buffer slot? 000a5798: 24420001 addiu r2,r2,0x0001 000a579c: 3c01800f lui r1,0x800f 000a57a0: ac223a18 sw r2,0x3a18(r1) // we're tending to current slot, so advance pointer // of next slot to process 000a57a4: 28620180 slti r2,r3,0x0180 // is Item ID in this slot high but without Bit 15 // set? so some non-null special number? 000a57a8: 1040006d beq r2,r0,0x000a5960 // branch if so 000a57ac: 00604021 addu r8,r3,r0 // r8 is copy of Item ID from circular buffer slot 000a57b0: 00003821 addu r7,r0,r0 // r7 will hold half of a count based on the item // list slot we stored the item to, IF that slot had // been empty 000a57b4: 00002821 addu r5,r0,r0 // r5 will be our item list counter 000a57b8: 01402021 addu r4,r10,r0 // r4 will be our memory offset to read item list // data. have it begin at start of item list. 000a57bc: 94820000 lhu r2,0x0000(r4) // get Item ID from current list slot 000a57c0: 00000000 nop 000a57c4: 14430008 bne r2,r3,0x000a57e8 // branch if it doesn't match that in current // Steal/Morph buffer slot 000a57c8: 00000000 nop 000a57cc: 90830002 lbu r3,0x0002(r4) // get quantity of item in this list slot 000a57d0: 00000000 nop 000a57d4: 2c620063 sltiu r2,r3,0x0063 // 99 quantity limit 000a57d8: 1040000c beq r2,r0,0x000a580c // branch if at or above it; will skip new item slot // initialization. why not go to 000a5938 directly? 000a57dc: 24620001 addiu r2,r3,0x0001 // increment quantity 000a57e0: 08029603 j 0x000a580c // will skip new item slot initialization. why not go // to 000a5938 directly? // DUE TO PIPELINING, below "sb" will happen. 000a57e4: a0820002 sb r2,0x0002(r4) // save new quantity in item list 000a57e8: 144b0004 bne r2,r11,0x000a57fc // branch if *Item ID* from list is not null (FFFFh) 000a57ec: 00000000 nop 000a57f0: 14c90002 bne r6,r9,0x000a57fc // if r6 is no longer null, we already found a null // slot to POSSIBLY save our item to, so don't // overwrite index 000a57f4: 00000000 nop 000a57f8: 00a03021 addu r6,r5,r0 // copy of existing item list counter. will hold // the first empty item slot, for use when we DON'T // find a matching one. 000a57fc: 24a50001 addiu r5,r5,0x0001 // advance counter 000a5800: 28a20140 slti r2,r5,0x0140 // have we passed end of 320-item list? 000a5804: 1440ffed bne r2,r0,0x000a57bc // loop if not. DUE TO PIPELINING, below "addiu" will // happen. 000a5808: 24840006 addiu r4,r4,0x0006 // advance memory offset in item list by 6, as each // slot takes 6 bytes. 000a580c: 34020140 ori r2,r0,0x0140 000a5810: 14a20049 bne r5,r2,0x000a5938 // did we just pass end of 320-item list? if not, we // arrived here due to a matched slot (with or // without maxed out quantity), as opposed to no // matching slots. // believe above code that found match could've just // branched straight to 000a5938 instead of 000a580c; // it's not like latter address has shared code that // needed executing. 000a5814: 00000000 nop 000a5818: 10c90047 beq r6,r9,0x000a5938 // r6 is position of our first null slot in item list // (i.e. that precedes any matched slot), OR // FFFFFFFFh if we never found such a null slot. // branch if latter. 000a581c: 00061040 sll r2,r6,0x01 000a5820: 00461021 addu r2,r2,r6 000a5824: 00021040 sll r2,r2,0x01 // chosen empty item slot * 6 000a5828: 004a2021 addu r4,r2,r10 // plus offset to start of item list 000a582c: 34020001 ori r2,r0,0x0001 000a5830: a0820002 sb r2,0x0002(r4) // Set item quantity to 1 (found via breakpoint in // item quantity) 000a5834: 34020003 ori r2,r0,0x0003 000a5838: a0820003 sb r2,0x0003(r4) // Save a default value for on whom the item can be // used. Examples: // (Hex value: Can be used on; First selection is) // 01: Ally or an enemy; an ally // 03: Enemy or an ally; an enemy // 05: All allies or all enemies; all allies // 07: All enemies or all allies; all enemies // 11: The item can be used only on one ally. 000a583c: 00081400 sll r2,r8,0x10 // ID of Morph/Steal buffer item * 65536 000a5840: 00021c03 sra r3,r2,0x10 // ID of buffer item, but with Bit 15 sign-extended // into top word. didn't "lh r3,0x3a20(r1)" already // do this? i'm confused. 000a5844: 28620080 slti r2,r3,0x0080 // r2 = 1 if (adjusted) Item ID < 128. // or if it had Bit 15 set for some reason? 000a5848: 1040000e beq r2,r0,0x000a5884 // branch if it was >= 128 (and with Bit 15 clear) // DUE TO PIPELINING, next "sh" will run. 000a584c: a4880000 sh r8,0x0000(r4) // Save Item ID (found via breakpoint in Item ID) 000a5850: 000310c0 sll r2,r3,0x03 000a5854: 00431023 subu r2,r2,r3 000a5858: 00021080 sll r2,r2,0x02 // (adjusted Item ID from Morph/Steal buffer) * 28. // will access normal Item data. 000a585c: 3c018007 lui r1,0x8007 000a5860: 00220821 addu r1,r1,r2 000a5864: 902322d8 lbu r3,0x22d8(r1) 000a5868: 00000000 nop 000a586c: a0830003 sb r3,0x0003(r4) // save on whom the item can be used. 000a5838 has // examples. 000a5870: 3c018007 lui r1,0x8007 000a5874: 00220821 addu r1,r1,r2 000a5878: 942222d6 lhu r2,0x22d6(r1) 000a587c: 08029647 j 0x000a591c // DUE TO PIPELINING, next "sb" will run. 000a5880: a0820004 sb r2,0x0004(r4) // Save the way in which this item can be used. // Examples: // 02 = Can be used in battle using Throw command. // 08 = Can be used in battle using Item or W-Item command. // 0A = Can not be used in battle. // 0B = Can not be used in battle and can not be stolen from you. 000a5884: 28620100 slti r2,r3,0x0100 // is adjusted Item ID from buffer < 256? 000a5888: 10400011 beq r2,r0,0x000a58d0 // branch if >= 128 and < 256 // DUE TO PIPELINING, next "slti" will run. 000a588c: 28620120 slti r2,r3,0x0120 000a5890: 2463ff80 addiu r3,r3,0xff80 // transform 80h to FFh ID range into 0h to 7Fh 000a5894: 00031040 sll r2,r3,0x01 000a5898: 00431021 addu r2,r2,r3 000a589c: 00021080 sll r2,r2,0x02 000a58a0: 00431023 subu r2,r2,r3 000a58a4: 00021080 sll r2,r2,0x02 // normalized Item ID * 44. will access Weapon data. 000a58a8: 3c018007 lui r1,0x8007 000a58ac: 00220821 addu r1,r1,r2 000a58b0: 902338a0 lbu r3,0x38a0(r1) 000a58b4: 00000000 nop 000a58b8: a0830003 sb r3,0x0003(r4) // save on whom the item can be used. 000a5838 has // examples. 000a58bc: 3c018007 lui r1,0x8007 000a58c0: 00220821 addu r1,r1,r2 000a58c4: 942238ca lhu r2,0x38ca(r1) 000a58c8: 08029647 j 0x000a591c // DUE TO PIPELINING, next "sb" will run. 000a58cc: a0820004 sb r2,0x0004(r4) // save the way in which this item can be used. // 000a5880 has examples. 000a58d0: 10400009 beq r2,r0,0x000a58f8 // branch if adjusted Item ID from buffer >= 288. // (pipelined test was done as "slti r2,r3,0x0120".) 000a58d4: 2462ff00 addiu r2,r3,0xff00 // transform 100h to 11Fh ID range into 0 to 1Fh 000a58d8: 000218c0 sll r3,r2,0x03 000a58dc: 00621821 addu r3,r3,r2 000a58e0: 00031880 sll r3,r3,0x02 // normalized Item ID * 36. will access Armor data. 000a58e4: 3c018007 lui r1,0x8007 000a58e8: 00230821 addu r1,r1,r3 000a58ec: 94221e64 lhu r2,0x1e64(r1) 000a58f0: 08029647 j 0x000a591c // DUE TO PIPELINING, next "sb" will run. 000a58f4: a0820004 sb r2,0x0004(r4) // save the way in which this item can be used. // 000a5880 has examples. 000a58f8: 28620140 slti r2,r3,0x0140 // is adjusted Item ID from buffer < 320? 000a58fc: 10400007 beq r2,r0,0x000a591c // branch if >= 320 000a5900: 2462fee0 addiu r2,r3,0xfee0 // transform 120h to 13Fh ID range into 0 to 1Fh 000a5904: 00021100 sll r2,r2,0x04 // normalized Item ID * 16. will access Accessory // data. 000a5908: 3c018007 lui r1,0x8007 000a590c: 00220821 addu r1,r1,r2 000a5910: 94221c32 lhu r2,0x1c32(r1) 000a5914: 00000000 nop 000a5918: a0820004 sb r2,0x0004(r4) // save the way in which this item can be used. // 000a5880 has examples. 000a591c: 24c20001 addiu r2,r6,0x0001 // r6 is position of our first null slot in item list // (i.e. that precedes any matched slot), OR // FFFFFFFFh if we never found such a null slot. // convert index to a quantity, floored at 0? 000a5920: 00021fc2 srl r3,r2,0x1f // think this will always be 0 with known values. // were they trying to get the old sign bit? // besides, i believe r6 will never be -1 (FFFFFFFFh) // here, thanks to 000a5810 and 000a5818 branches. 000a5924: 00431021 addu r2,r2,r3 000a5928: 90830004 lbu r3,0x0004(r4) // get the way in which this item can be used. // 000a5880 has examples. 000a592c: 00023843 sra r7,r2,0x01 // halve our quantity, as a count that can reach 320 // won't fit a 1-byte variable 000a5930: 3063000b andi r3,r3,0x000b // filter out irrelevant (or erroneous) bits from item // usability? 000a5934: a0830004 sb r3,0x0004(r4) // save the way in which this item can be used 000a5938: 3c038016 lui r3,0x8016 000a593c: 90636f74 lbu r3,0x6f74(r3) // 80166f74 = It is related to the number of items // that Item list shows (related to the pages?). It // seems that its value is equal to half the number // of slots shown. 000a5940: 340200ff ori r2,r0,0x00ff 000a5944: 3c018016 lui r1,0x8016 000a5948: a0226f75 sb r2,0x6f75(r1) // 80166f75 = Its value is equal to FF when you gain // a new type of item. 000a594c: 0067182a slt r3,r3,r7 // compare existing halved slot count variable to: // halved slot count based on empty slot we just // saved to, OR zero, if we didn't find or didn't use // such a slot (see 000a5810 and 000a5818 branches). 000a5950: 10600003 beq r3,r0,0x000a5960 // branch if existing variable already >= 000a5954: 00000000 nop 000a5958: 3c018016 lui r1,0x8016 000a595c: a0276f74 sb r7,0x6f74(r1) // count based on empty slot we just saved to is // higher, so record that grown list half-size 000a5960: 3c02800f lui r2,0x800f 000a5964: 8c423a18 lw r2,0x3a18(r2) // 800f3a18 = next slot to process in Steal/Morph // circular buffer? 000a5968: 3c03800f lui r3,0x800f 000a596c: 8c633a1c lw r3,0x3a1c(r3) // Counter of steal and morph. 1 is added every time // you use steal or morph. next slot to fill in a // circular buffer? 000a5970: 3042000f andi r2,r2,0x000f // wrap our processing slot back to 0 if it exceeded // 15 000a5974: 3c01800f lui r1,0x800f 000a5978: ac223a18 sw r2,0x3a18(r1) // save adjusted morph/steal next slot to process 000a597c: 1462ff7f bne r3,r2,0x000a577c // loop if it doesn't match next slot to fill, as we // still have more to handle 000a5980: 00000000 nop 000a5984: 27bd0008 addiu r29,r29,0x0008 // add 8 back to stack pointer, to free up stack // space 000a5988: 03e00008 jr r31