I'm sorry is this isn't the right place, but I'm trying desperately to understand what's happening in this Assembly script (I'm assuming that's what it is, based on the hours of googling I've done.) It's a rom for Pokemon Yellow version, and I understand some but not all. I figure if I can get some help understanding what this one paragraph is doing, I can figure the rest out. The code looks like this:
PalletTownScript:
CheckEvent EVENT_GOT_POKEBALLS_FROM_OAK
jr z, .next
SetEvent EVENT_PALLET_AFTER_GETTING_POKEBALLS
.next
call EnableAutoTextBoxDrawing
ld hl, PalletTownScriptPointers
ld a, [wPalletTownCurScript]
jp JumpTable
My understanding is that the first line just puts the rest of it into a label called "PalletTownScript", just a name that's referenced later. The second line checks that a certain event has happened, detailed in another file. All that's fine so far. The third line is where it gets complicated for me. I determined that "jr" jumps to another section of the script, and then returns back here? I think? But, from what I've seen, every single example only has one argument, and this line has two. Is it jumping to z? What is z? I've searched the rest of this file, and there's no section called z. Is z another function? The other argument is .next, which is, from what I can tell, a subsection of the PalletTownScript section. So it makes sense that it's jumping there (but why bother jumping? If it's right there, wouldn't it just do it anyway?) But I still don't know what "z" is doing there. In .next, it's calling some stuff and loading some other stuff, that's all fine, but at the end, it jumps to JumpTable, which is in another file (I'm assuming that doesn't matter after it's all compiled, so I'm not concerned about that), but is it still Jumped to the .next, and then again to JumpTable? When does it go back to do that SetEvent? Where does it go after that?
I have never dealt with Assembly before, and it's all very confusing for me, so if someone could give me some help with this, I would really appreciate it. Thanks!
jr z, .nextis a conditional relative jump. The jump will only be taken if the Zero flag is set (in the F register).If the event
EVENT_GOT_POKEBALLS_FROM_OAKhas already happened, the eventEVENT_PALLET_AFTER_GETTING_POKEBALLSbecomes set.If it didn't, the
SetEvent EVENT_PALLET_AFTER_GETTING_POKEBALLSis skipped.The
CheckEventandSetEventmacros are defined here: https://github.com/pret/pokered/blob/master/macros/scripts/events.asm