C08FF7 ====== C0/8FF7: C2 10 REP #$10 // X flag clear; index registers are 16 bits. C0/8FF9: EB XBA // Swap the low and high order portions of the accumulator. C0/8FFA: F0 26 BEQ $9022 // If the low order byte became 0x00 after the previous instruction (XBA), this jump occurs. That would occur if the accumulator value was less than 0x100. Documentation of this follows the C08FF7 section. C0/8FFC: E2 20 SEP #$20 // If greater than/equal to 0x100, A becomes eight-bit. C0/8FFE: EB XBA // Swap back. |-----------------------------------------------------------| | The overall result at this point is a modulus operation: | | A = A mod 0x100 | | With filtering to prevent 0 mod 0x100. The result of this | | modulus operation is placed on the stack. | |-----------------------------------------------------------| C0/8FFF: 48 PHA // Push the modulus result onto the stack. C0/9000: 98 TYA // Transfer Y to A. Y is usually set to a definite (#$) value before this routine is called; for example, in the stat modification CCs (1E 0A-0E), it's set to 0x5F. C0/9001: C2 20 REP #$20 // M flag clear; the accumulator becomes 16 bits. |-----------------------------------| | The overall result at this point: | | A = 1122 -> A = 1144 | | X = 33 -> X = 33 | | Y = 44 -> Y = 44 | | Stack = 55 -> Stack = 2255 | |-----------------------------------| C0/9003: 8F 02 42 00 STA $004202 // Store the accumulator at $004202 - the multiplication register. C0/9007: EA NOP C0/9008: EA NOP C0/9009: AF 16 42 00 LDA $004216 // Wait two cycles for the result and then read it. C0/900D: A8 TAY // Move result to Y. |----------------------------------------| | The overall result at this point: | | A = 1144 -> A = (44 * 11) | | X = 33 -> X = 33 | | Y = 44 -> Y = (44 * 11) | | Stack = 2255 -> Stack = 2255 | |----------------------------------------| C0/900E: E2 20 SEP #$20 // M flag set; A = 8 bits. C0/9010: 68 PLA // Pull the modulus remainder off the stack. C0/9011: 8F 03 42 00 STA $004203 // Multiplication. C0/9015: C2 20 REP #$20 // M flag clear; the accumulator becomes 16 bits. C0/9017: 98 TYA // Transfer Y to A. |---------------------------------------------| | The overall result at this point: | | A = (11 * 44) -> A = (44 * 11) | | X = 33 -> X = 33 | | Y = (11 * 44) -> Y = (44 * 11) | | Stack = 2255 -> Stack = 55 | | $4216 = (44 * 22) | |---------------------------------------------| C0/9018: EB XBA // Swap low/high order. C0/9019: 29 00 FF AND #$FF00 // And axe the new low order. Overall, the accumulator equals: (11 * 44)'s low order * 0x100 C0/901C: 18 CLC // Clear carry flag. C0/901D: 6F 16 42 00 ADC $004216 // Add the accumulator and the multiplication result. C0/9021: 6B RTL // Return. |---------------------------------------------------------------------------------| | The overall result at this point: | | A = (11 * 44) -> A = (44 * 11)'s low order times 0x100 + (44 * 22) | | X = 33 -> X = 33 | | Y = (11 * 44) -> Y = (44 * 11) | | Stack = 55 -> Stack = 55 | |---------------------------------------------------------------------------------| |----------------------------------------------------------------------------| | The overall result: | | A = 1122 -> A = 0x100 times (44 * 11)'s low order + (44 * 22) | | X = 33 -> X = 33 | | Y = 44 -> Y = (44 * 11) | | Stack = 55 -> Stack = 55 | |----------------------------------------------------------------------------| ACCUMULATOR RESULT 1. Multiply the Y register by the high order of the accumulator. 2. Get the low order of the result of Step 1 and multiply it by 0x100. 3. Add (Y register * the initial low order of the accumulator) to the result of Step 2. Y REGISTER RESULT Multiply the Y register by the initial high order of the accumulator. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// C09022 ====== C0/9022: E2 20 SEP #$20 // The accumulator becomes eight-bit. C0/9024: 98 TYA // Transfer Y to A. C0/9025: C2 20 REP #$20 // The accumulator resumes being sixteen-bit. C0/9027: 8F 02 42 00 STA $004202 // Multiplication. C0/902B: EA NOP C0/902C: EA NOP C0/902D: AF 16 42 00 LDA $004216 // Wait two cycles for the result and then read it. C0/9031: 6B RTL // Return. |----------------------------------------| | The overall result: | | A = 1122 -> A = (44 * 22) | | X = 33 -> X = 33 | | Y = 44 -> Y = 44 | | Stack = 55 -> Stack = 55 | |----------------------------------------| ACCUMULATOR RESULT 1. Multiply the low order of the accumulator by the Y register. /////////////////////////////////////////////////////////////////////////////////////////////////////////////// CONCLUSION C08FF7 multiplies the accumulator by the Y register, and stores the result in the accumulator.