Attempting to create a new event command - Printable Version +- FF6 Hacking (https://www.ff6hacking.com/forums) +-- Forum: Discussion Forums (https://www.ff6hacking.com/forums/forum-5.html) +--- Forum: Magitek Research Facility (https://www.ff6hacking.com/forums/forum-9.html) +--- Thread: Attempting to create a new event command (/thread-2848.html) Pages:
1
2
|
Attempting to create a new event command - Tenkarider - 04-05-2015 Hi! I was trying to write some asm code: command A3: AA BB CC CC CC That should allow me to read any battle var value AA(the ones that keep the value even after battle) and so compare it with CMP BB. After CMP, if the result is greater or equal, it branches to CC CC CC Else it returns. While i believe i have already created the right code, i didn't understand how to use CC CC CC input value to jump when the check is true I tried to check the code of other event command checks but it's messy... This would be the perfect moment to receive an hint. RE: Attempting to create a new event command - m06 - 04-05-2015 if the check results in a branch. The routine will jump to the specified address CC CC CC and continue running from that location. Otherwise it continues to the next line (byte/operator). CC CC CC will be little endian value, this means the least significant value is first. So consider CC CC CC as C1 C2 C3 then the address will be reversed: $C3C2C1. Addresses in ASM refer to the snes bank addresses not the ROM address so make sure to add the header (+$200) if you have one and subtract $C00000 to get the ROM location of a pointer. So for example: Pointer to Character Portraits: $ED1D00 (would show up as 00 1D ED) Location in a headered ROM: $ED1D00 - $C00000 + $000200 = $2D1F00 (in the ROM) RE: Attempting to create a new event command - Tenkarider - 04-05-2015 Yeah, i know that... What i'm not sure about is right the jump command to CC CC CC: i usually write a constant value as input for the jump... how do you insert as parameter CC CC CC in the jump command input? RE: Attempting to create a new event command - Catone - 04-05-2015 If your custom command mimics gen action C0 (at C0/B2C8) Then after the command, and the val to check you enter the destination, in reverse, as m06 said. The command should be set up to check var then read the following code as an address. In other words, why would you need a jump command during usage of the custom command. That should already be set up in the custom code. Or am I on the entirly wrong planet? RE: Attempting to create a new event command - Tenkarider - 04-05-2015 My custom event is based mainly on B7 B8 and/or B9 event commands, which deals with battle variables... but instead of their bits. i want to get the value of the chosen battle var. I already done the checks: i reached the following point: CMP BB; The next step should be BMI(branch if minus)... if i do the branch(few bytes), then i return and do nothing; If i don't branch, then it's greater or equal: now it's the time of doing a long JMP to anywhere i want, that's the problem... i cannot write a static value of CC CC CC for the JMP, if i do that, then i'd jump always in the same place I need of a dynamic value, that depends on the input value... you can't just load up $ED $EE and $EF (used to store the value of 3rd, 4th and 5th arguments) inside the JMP command... you must make them become a single value... how? that's the thread question. Meanwhile i tried to search the answer in Madsiur's custom event 83 readme... and there i'm pretty sure there's the answer, and it should be inside this piece of code: Code: F1/A049 C2 21 REP #$21 Unfortunately i don't understand some step of this code... for example i noticed his 3 input bytes for the JMP: he stores them in $E5, $E6 and $E7 and makes somehow their sum into a single value... still not figured out how it comes out a 6 byte value... Finally the JMP to $C09A6D... where is the code jumping, and what's in that place of the code? (obviously this last question is aimed to Madsiur) I'd like to have a detailed explaination on how this piece of code works... Another question: is this code easily portable and reusable for other event commands? RE: Attempting to create a new event command - Catone - 04-05-2015 I think I know the answer to one of those, maybe two, but I need a computer first. Gimmie an hour RE: Attempting to create a new event command - m06 - 04-05-2015 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 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) 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) This routine also jumps to $9A6D that routine basically runs the event command at $E5-$E7 and in this way parses the event script. RE: Attempting to create a new event command - Catone - 04-05-2015 Ha! I did know part of it! SEP and REP, 8-bit/16-bit how many values it loads at once... I just drive to slow and could have never explained it as pretty as m06 does. That being said, that code at $9A6D, it kinda makes sense how it works, but I'd be guessing the whole way. By the way, where is this "Madsiur's custom event 83 readme"? I need to save that one. As far as portable and reusable: Yeah, long as you treat it as an event command. Code: F1/A049 C2 21 REP #$21 Least that's what I see it doing. Still don't fully get the "exit" though. Please correct me if I'm wrong, it has been known to happen. (The added comments to that block of code is what I'm talking about btw) RE: Attempting to create a new event command - Tenkarider - 04-05-2015 Quite enlightening... Maaaaaaaaybe $E5 $E6 and $E7 are used as passive parameters of the dynamic value to use for the jump(or for continue in the case the check is false) Now i'd like to understand why/how a JMP to itself allows the command to do something so much elaborate. The other question is... if $E5-7 values have a so much important role, then why in the RAM map document they're not even mentioned?!? I'm gonna try to do something with those new info... we'll see what happens. PS. Madsiur's custom event 83 is inside this site, among hack patches, i believe... ____________________________________ Ok, i finished... the good new is that the game won't crash when i use the command, the problem is that it always returns false... Here's the code i wrote: Code: C0/D613: A6 EB LDX $EB (First byte for FC) This is the code i tested for see if that works: Code: 003F0200: A3 04 32 0B 00 35 // if battle var 04 >= 50 then jump to 3F020B I start a battle, var 04 chances its value and then battle ends: after the battle this code above is triggered... and always returns false. Could you try to figure out if i missed something? RE: Attempting to create a new event command - Catone - 04-06-2015 I don't have a debugger at work (not sure why, I should have) but that'd be the best suggestion I've got. Set a break at C0/D613 then step through it line by line to make sure the checked values are being loaded properly. If it is acting like an always false check with no crash, its either running the wrong thing with no visual result, or its being bypassed entirely, somehow. |