Users browsing this thread: 1 Guest(s)
Trying to understand subroutines

#1
Posts: 378
Threads: 94
Thanks Received: 17
Thanks Given: 26
Joined: Jul 2013
Reputation: 11
Status
Charmed
I was told I could expand the space in events by using subroutines; however, their mechanics looked difficult to learn so I decided to stay away from them.
Now that I'm better at scripting I gave it a go but I can't seem to get the hang of it. Here's what I'm doing.

When you talk to Cyan after the phantom train departs, you wait (B5 05) then displays the "Cyan: ..." message and ends. I decided to start a subroutine there (replacing the B5 with B2 and so on). I went to free space located at 010118 (CA/FF18?), so I went with B2 18 FF 01 FE.

On CA/FF18 I wrote my code, ended it with FE and returned. As I was afraid the game freezes (game stays still forever, doesn't shut down) whenever I speak to Cyan instead of supposedly doing whatever it is on CA/FF18. I'm posting a picture of my WindHex, hoping you can help me figure out why this isn't working for me.

[Image: untitled_1_by_kugawattan-d9jesk2.png]

Thanks in advance.


Step forward, spriters! We are also responsible to make hacks look new and fresh, we are no less important than code or ASM hackers! CHARGE!!
Quote  

#2
Posts: 2,549
Threads: 98
Thanks Received: 147
Thanks Given: 159
Joined: Aug 2009
Reputation: 52
Status
Nattak\'d
(12-07-2015, 11:50 PM)Kugawattan Wrote: I went to free space located at 010118 (CA/FF18?), so I went with B2 18 FF 01 FE.

This would jump to CB, not CA, since you have 01. 00 is for CA.

EDIT:
Hmm, I see in your pic the jump is correct in jumping to CA, so that must've been a typo.
BUT, you're pic to the right is showing the C0-C1 bank why?!? That's where you put your code? You can only use event space in the normal range of CA-CC, or the expanded banks. I...think... now I'm confusing myself. Anyway I think the issue is you put the code there in C0, and not at CA lol.


We are born, live, die and then do the same thing over again.
Quote  

#3
Posts: 3,970
Threads: 279
Thanks Received: 236
Thanks Given: 58
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
With command B2 you can call event code anywhere between banks $CA and $FF. Technically if event triggers and NPC data have the absolute bank value in the event offset (not sure if the case) you could have event code anywhere in the ROM.
  Find
Quote  

#4
Posts: 378
Threads: 94
Thanks Received: 17
Thanks Given: 26
Joined: Jul 2013
Reputation: 11
Status
Charmed
On List of free space I got this

Quote:OFFSETS WITH HEADER!

010118 0101AF [152 Bytes] Unused Space

Back then I was told 00 translated to CA, 01 to CB and 02 to CC. So I went with 010118 -> CB/0118, but this is with a header, so I have to substract it 200, giving me CA/FF18. I'm probably missing something but I hope this clears your doubts.


Step forward, spriters! We are also responsible to make hacks look new and fresh, we are no less important than code or ASM hackers! CHARGE!!
Quote  

#5
Posts: 676
Threads: 44
Thanks Received: 26
Thanks Given: 21
Joined: Jan 2015
Reputation: 11
Status
Zombie
Man I forgot how nasty windhex looks, HxD so much... cleaner.

Anyway, for the purpose of event code, CA/0000 is the begining of all. Every event is wrote reletive to CA/0000 being point 0. Sure you can put code anywhere in the ROM by making a jump, as long as it is above CA. You can't make it jump to C1/ using event code but you can make it go to 40/0000 (beyond FF0000) if your doing really weird stuff but it is all based off of CA being ground zero.

Don't think that is your problem though. The thing with sub-routines is they have to return to the routine, then the routine itself still has to end/return.

Such as: B2 18 FF 00 (subroutine runs, then returns to here on return command) FE

After returning from the subroutine, the code still needs to end.

Heh, now I see what Gi Nattak is saying though. In your screenshot on the right, your at address C1/0118 which event code will not jump to.

CA/0000 does = 00/0000 for the purpopes of event code. In other words you trying to jump to C1/0118 would require telling the event code to jump to negative 08FEE8 which it will not do.

In other words, CA/ > C1/ won't jump.


The only true wisdom is knowing you know nothing.
  Find
Quote  

#6
Posts: 378
Threads: 94
Thanks Received: 17
Thanks Given: 26
Joined: Jul 2013
Reputation: 11
Status
Charmed
Oh, damn. When I saw 010118 I didn't realize it was C1. So let me get this straight.
CA/00EA -> 00A00EA + header = 00A02EA Call Subroutine: B2 EA 00 00 (why is it that 0A becomes 00 when doing the subroutine thing?)
C0/FF18 -> 000FF18 + header = 0010118
Correct?

Hm, so apparently space from C1 wasn't for events. There's even a post later that explicitly says it. Ugh.

Anyway, where's the "free space for events" then? :O


Step forward, spriters! We are also responsible to make hacks look new and fresh, we are no less important than code or ASM hackers! CHARGE!!
Quote  

#7
Posts: 676
Threads: 44
Thanks Received: 26
Thanks Given: 21
Joined: Jan 2015
Reputation: 11
Status
Zombie
Absolutely anything after CA/0000

Actual hi-rom adress minus CA/0000 equals the address event commands can use. Can't be a negative value for event code.


The only true wisdom is knowing you know nothing.
  Find
Quote  

#8
Posts: 378
Threads: 94
Thanks Received: 17
Thanks Given: 26
Joined: Jul 2013
Reputation: 11
Status
Charmed
Okay thanks, but mind if you tell me where there's free space after CA/0000? Like I need around 150 bytes of space for this to work. Where could I find them?


Step forward, spriters! We are also responsible to make hacks look new and fresh, we are no less important than code or ASM hackers! CHARGE!!
Quote  

#9
Posts: 676
Threads: 44
Thanks Received: 26
Thanks Given: 21
Joined: Jan 2015
Reputation: 11
Status
Zombie
I personally enjoy using the end of the very end of normal expanded rom space (3F/0000) but my tendancy to do that also makes alot of my seperate stuff overlap because I always tend to go to the exact same address each time.

If your doing everything yourself, adding no other patches, then anything out in the great beyond should be free. I do not remember exactly where FF3usME relocates data but I think it only goes to 2F/ area or so. Also don't remember where Madsiur relocated map data off the top of my head if your using his LE+ patch for extra map space.

Not to be a shamelessly promote myself, but my Auction House rewrite frees up about ... 669 bytes I think? At the end of the auction script in the... hrm... I'm gonna have to check my stuff, something funny going on.
Either way, it frees up a bunch of space inside normal event accessing range without steping outside of the normal auction house code. Might look into it. Few minor documented edits and it will look mostly vanilla from in game.

Short answer, pick a spot out around 3F/F000 (should read as FF/F000 in hi-rom windhex mode)and set up camp for all your extended eventing needs.


The only true wisdom is knowing you know nothing.
  Find
Quote  

#10
Posts: 378
Threads: 94
Thanks Received: 17
Thanks Given: 26
Joined: Jul 2013
Reputation: 11
Status
Charmed
Okay, 3F/F000. Got it, I think. How would the B2 command go? B2 00 F0 ?? FE? I'm not sure how to translate 3F.

EDIT: Just rewatched Madsiur's tutorial, FF-CA=35, right? So B2 00 F0 35 FE?

EDIT2: OHMYGOD OHMYGOD OHMYGOD IT WOOOORKEDDDD

Double post oooo

Okay, finished polishing my event. Now, there's only one issue. At the phantom train departing scene, you wait for the timer to run out and then you go back to the world map. Instead of this, I want that to happen when you talk to Cyan after the event plays. What I did was call a subroutine, which worked (the event played after talking to Cyan), but after the event the screen freezes. I tried to move the code at CB/BEA3 at the end of the subroutine with the rest of the event code. But I guess that because it returns to the end of the event back at CB/BE9B it gets stuck or something. I assume there's no way of telling the game "Go here and stay there, don't return"? Or maybe that's not the solution. I'm not sure. Help pls?


Step forward, spriters! We are also responsible to make hacks look new and fresh, we are no less important than code or ASM hackers! CHARGE!!
Quote  



Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite