04-05-2015, 04:49 PM
I think what you're asking about is creating pointer tables or data tables and using a lookup index? If so your index or parameter would be loaded to X or Y with LDX or LDY and then you get the value from the table to A with LDA $table_start, X
If you don't want to create a data table you can use a series of compares and branches.
So you load the index or parameter to A and do a series of CMP for each value available.
This works like a switch statement or series of else-if statements in higher level languages.
-----
Regarding memory each slot in the memory is one byte so $E5 can only hold one byte, to make 16-bit, word pointers we need 2 bytes so that would be stored at two memory locations $E5 and $E6 for instance. And so for 24-bit, long pointers we need 3 bytes, hence, $E5, $E6, $E7 - However! It may be confusing that the registers in the CPU can actually hold 16-bit, word, 2 bytes at once. If they have been set to do so with REP, SEP commands.
In the code you pasted $E5 and $E6 are loaded at the same time with LDA $E5 (where the A register is set to 16-bit with REP #$21).
ADC then adds 5 to the current value and sets the carry flag if the value goes above FFFF (important to note)
Then we store the word $E5 and $E6 together with STA $E5
TDC basically just sets A to 0
SEP #$20 now a is 8-bit again holds only 1 byte.
ADC $E7 adds $E7 to zero, so it's like loading $E7 but, because we are adding we check the carry flag and if it is set $E7 gets incremented by one. This is how the carry flag is used to perform addition over multiple bytes.
from F1/A05D it's basically the same thing but setting the values directly from the event parameters.
If you don't need to branch with your event command I recommend this exit:
The routine at $9B5C does the same as you posted above but adds A to the $E5-$E7 pointer:
This routine also jumps to $9A6D that routine basically runs the event command at $E5-$E7 and in this way parses the event script.
If you don't want to create a data table you can use a series of compares and branches.
So you load the index or parameter to A and do a series of CMP for each value available.
Code:
LDA $parameter
CMP #$00
BEQ $where_to_go_when_zero
CMP #$01
BEQ $where_to_go_when_one
CMP #$02
BEQ $where_to_go_when_two
This works like a switch statement or series of else-if statements in higher level languages.
-----
Regarding memory each slot in the memory is one byte so $E5 can only hold one byte, to make 16-bit, word pointers we need 2 bytes so that would be stored at two memory locations $E5 and $E6 for instance. And so for 24-bit, long pointers we need 3 bytes, hence, $E5, $E6, $E7 - However! It may be confusing that the registers in the CPU can actually hold 16-bit, word, 2 bytes at once. If they have been set to do so with REP, SEP commands.
In the code you pasted $E5 and $E6 are loaded at the same time with LDA $E5 (where the A register is set to 16-bit with REP #$21).
ADC then adds 5 to the current value and sets the carry flag if the value goes above FFFF (important to note)
Then we store the word $E5 and $E6 together with STA $E5
TDC basically just sets A to 0
SEP #$20 now a is 8-bit again holds only 1 byte.
ADC $E7 adds $E7 to zero, so it's like loading $E7 but, because we are adding we check the carry flag and if it is set $E7 gets incremented by one. This is how the carry flag is used to perform addition over multiple bytes.
from F1/A05D it's basically the same thing but setting the values directly from the event parameters.
If you don't need to branch with your event command I recommend this exit:
Code:
A9 01 LDA #$01 (advance the script 1 place)
4C 5C 9B JMP $9B5C (standard exit)
The routine at $9B5C does the same as you posted above but adds A to the $E5-$E7 pointer:
Code:
C0/9B5C: 18 CLC (Called from various, below)
C0/9B5D: 65E5 ADC $E5 (Add event command size in bytes to current pointer)
C0/9B5F: 85E5 STA $E5 (Write new pointer)
C0/9B61: A5E6 LDA $E6
C0/9B63: 6900 ADC #$00 (carry overflow to high byte)
C0/9B65: 85E6 STA $E6
C0/9B67: A5E7 LDA $E7
C0/9B69: 6900 ADC #$00 (carry overflow to bank byte)
C0/9B6B: 85E7 STA $E7
C0/9B6D: 4C6D9A JMP $9A6D (General Actions: Branch Exit)
This routine also jumps to $9A6D that routine basically runs the event command at $E5-$E7 and in this way parses the event script.