L'Empereur/Jump Table Operations: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
No edit summary
No edit summary
Line 13: Line 13:
  3X - Push values from location X to stack
  3X - Push values from location X to stack


  For 00-3F, the significant of the second digit is as follows:
  For 00-3F, the significance of the second digit is as follows:


  0 - Storage values 17/18
  0 - Storage values 17/18

Revision as of 02:43, 4 January 2019

  • $0000/$0001 - M0 - Address pointer
  • $0002/$0003 - M2 - Stack (not the actual NES stack)
  • $0004/$0005 - M4 - Stack Offset (part of stack dedicated to current function)
  • $0006/$0007 - M6 - Command Queue (current spot in current function)
  • $0008/$0009 - M8 - Math Register 1
  • $000C/$000D - MC - Math Register 2
OPERATIONS:
0X - Store value from location X to M8
1X - Store value from location X to MC
2X - Store M8 to location X
3X - Push values from location X to stack
For 00-3F, the significance of the second digit is as follows:
0 - Storage values 17/18
1 - Storage values 15/16
2 - Storage values 13/14
3 - Storage values 11/12
4 - Storage values 0F/10
5 - Storage values 0D/0E
6 - Storage values 0B/0C
7 - Storage values 09/0A
8 - Storage values 07/08
9 - Storage values 05/06
A - Storage values 03/04
B - Storage values 01/02
C - Parameters 1/2\
D - Parameters 3/4 \
E - Parameters 5/6 / Pushed to stack by parent function
F - Parameters 7/8/  (located at 0B past bottom of stack)

Note that other operations refer to these locations relative to the stack offset. So to refer to storage values 1,2,3 you would say "FFFF, FFFE, FFFD"... etc. While for referring to the parameters values, you would refer to parameters 1,2,3 as "000B, 000C, 000D"... etc. This is necessary since many functions require more than 4 parameter slots or 12 storage slots.

4X - Store X to $0008 (1-byte value)
5X - Store X to $000C (1-byte value)
6X - Push X to stack (as 2-byte value)
7X - Add X to $0008

81 (XX) - Store 2-byte value from stack location XX (+1) to M8
85 (XX) - Store 2-byte value from M8 to stack location XX (+1)
87 (XX) - Push 2-byte value at stack address XX (+1) to stack
89 (XX) - Store XX to $0008 ($0009 = #$00)
8A (XX)(YY) - Store XX/YY to M8
8B (XX) - Store XX to $000C ($000D = #$00)
8C (XX)(YY) - Store XX/YY to MC 
8D (XX) - Push XX to stack (as 2-byte value)
8E (XX)(YY) - Push XX/YY to stack 
8F (XX) - Add XX to M8
90 (XX)(YY) - Add XX/YY to M8

A0 (XX)(YY) - Store 1-byte value from stack location XX/YY to $0008
A2 (XX)(YY) - Store $0008 to stack location XX/YY

A4 (XX/YY) - Store 2-byte contents of address to M8
A5 (XX/YY) - Store 1-byte contents of address to $0008 ($0009=#$00)
A6 (XX/YY) - Store 2-byte contents of address to MC
A7 (XX/YY) - Store 1-byte contents of address to $000C ($000D=#$00)
A8 (XX/YY) - Store 2-byte contents of M8 to address
A9 (XX/YY) - Store 1-byte contents of $0008 to address
AA (XX/YY) - Push 2-byte contents of address to stack

AC (XX/YY) - Run specified function 
AE (XX) - Empty XX values from the stack
B0 - Replace M8 with the 2-byte value at the address it contains
B1 - Pull 2 stack values and store M8 to that address (+1)
B3 - Push M8 to stack
B4 - Pull 2 values from stack to MC

NOTE: For all math functions, result is stored back into M8
B5 - Multiply M8 by MC (2-byte)
B8 - Divide M8 by MC (rounded down)
B9 - M8 modulo MC
BB - Add MC to M8
BC - Subtract MC from M8
BD - Perform a # of left shifts to M8 equal to the value in MC
BE - Perform a # of right shifts to M8 equal to the value in MC
COMPARISON FUNCTIONS: Stores 0 in M8 if false, or 1 if true
C0 - Checks if M8 = MC
C1 - Checks if M8 != MC
C2 - Checks if M8 < MC (signed)
C3 - Checks if M8 ≤ MC (signed)
C4 - Checks if M8 > MC (signed)
C5 - Checks if M8 ≥ MC (signed)
C6 - Checks if M8 < MC (unsigned)
C7 - Checks if M8 ≤ MC (unsigned)
C8 - Checks if M8 > MC (unsigned)
C9 - Checks if M8 ≥ MC (unsigned)
CA - Checks if M8 = MC = 0
CB - Takes the negative of M8 (signed)
CD - Swaps the contents of M8 and MC
CF - Ends function and returns to parent function
D0 - Increment M8
D1 - Decrement M8
D2 - Double M8 (single left shift)
D3 - Replace M8 with the 1-byte value at the address it contains
D4 - Pull 2 stack values, store $0008 to that address
D5 (##) (##) (##) ... - Adds the first 2 values to M8. Values 3 & 4 indicate the # of redirect addresses that follow.
The first address is the "else" address if M8 ≥ values 3 & 4.
The addresses after that correspond to the value of M8 beginning with #$00.
D6 (XX)(YY) - Jump to address
D7 (XX)(YY) - Jump to address if M8 is positive (e.g. if previous comparison was true)
D8 (XX)(YY) - Jump to address if M8 is negative (e.g. if previous comparison was false)
D9 (##) ... - Multiple if-then statement.
First two values are the number of conditions to check.
Checks if the next two values are equal to M8. If they aren't, skip ahead 4 bytes.
If the values match, jump to the specified address (next 2 bytes) in the function.
If the counter runs out, jump to the final address ("else")
DA - M8 AND MC
DB - M8 ORA MC
DC - M8 EOR MC
DD - Run the function located in M8
DE (XX)(YY) - Store the address of specified stack location to M8
E9 (XX)(YY)(##) - Run function (XX/YY), using (##) previously pushed stack values as parameters. (They are pulled permanently from the stack upon returning)