Attempting to create a new event command
#7
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.
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.
Reply


Messages In This Thread
RE: Attempting to create a new event command - by m06 - 04-05-2015, 04:49 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Command Change Custom Event GrayShadows 8 8,574 05-22-2022, 11:07 PM
Last Post: fedorajoe
  Invoke Game Saving Screen Event Command Morendo 1 1,777 09-05-2020, 10:29 PM
Last Post: C-Dude
  Attempting something... justincreedon 4 4,529 05-21-2015, 07:44 AM
Last Post: justincreedon
  How to create a new version of The Soul Shrine ShinMrKarate 23 21,990 11-01-2014, 06:42 AM
Last Post: Tenkarider
  Need help to create a custom event Astaroth_ 12 14,982 09-01-2013, 05:22 PM
Last Post: madsiur

Forum Jump:


Users browsing this thread: 1 Guest(s)