FF6 Hacking
Trying to understand subroutines - 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: Trying to understand subroutines (/thread-3041.html)

Pages: 1 2 3


RE: Trying to understand subroutines - Tenkarider - 12-08-2015

One thing that comes in my mind is that it's an event who doesn't stop your character movement, and it makes the command which pause the event for a certain number of frames


RE: Trying to understand subroutines - Catone - 12-08-2015

Have to have an "FE" after your subroutine command to end the routine.

Code:
Routine
CA/0003: B2 33 5E 00           Call subroutine at CA/5E33
CA/0007: FE                Return

Subroutine
CA/5E33:  A9 ** ** **
** ** ** (bunch of event code)** ** **
CA/5EA7: FE           Return to routine.
A crappy random example from the event script.

There is a way to just Jump in stead of Jump to subroutine, but requires doing a bit check which takes up more space than calling a subroutine and ending it with an FE.

There is a bit for this that is always on or always off, but as I said, takes up more space.
Code:
C0 F0 01.     If $1F0 is clear,
79 50 01.         Branch to CB/5079
FE             Return if  set
Quick example from a file I had opened. In this case it checks to see if event bit $1F0 is clear (that bit resets ever time a map loads so should be clear unless you set it at that time) if it is clear, it makes a direct jump to the address following the check and doesn't return to that point on a return. However if there is a chance that check might fail,(if $1F0 was set) it will ignore the address and continue to the following FE.

Yeah, it can be done and is done in vanilla code, usually better to stick with sub routines though.


RE: Trying to understand subroutines - Kugawattan - 12-08-2015

You mean like this?

[Image: 1st_class_junk_by_kugawattan-d9jgj4t.png]

If I do that (Jump in stead of Jump to subroutine), do I still have to end the code (at 3F/F000) with FE? I have tried with both and no luck.

'cause if I do that, the event does jump to where the new code is, but still doesn't end as it's supposed to (placing me on the world of balance map, took exact copy from CB/BEA3 to CB/BEC3).

It occurs to me I could like do another jump? Like "start here, do whatever's on this subroutine, and jump to another place where the code ends". I'm not sure why it doesn't work either.


RE: Trying to understand subroutines - Catone - 12-08-2015

If anything, you would do a bit check for a direct jump if true, to your new code, then another check and jump back to the original code that opens the world map, the other option would be to jump like that to your code, then follow your code (still in 3F/) with the code that opens the world map, following that with an FE to end the code without ever returning to your start point.

What is the line that Cyan says when you talk to him? I'll look at it and see if I can provide a more clear answer.


RE: Trying to understand subroutines - Tenkarider - 12-08-2015

it should be something like: "..."


RE: Trying to understand subroutines - Kugawattan - 12-08-2015

CB/BE99: B5 Pause for 15 * 5 (75) units
CB/BE9B: 4B Display dialogue message $02DF, wait for button press
CYAN: ……
CB/BE9E: FE Return

CB/BE9F: 4B Display dialogue message $02DE, wait for button press
SHADOW: Leave 'em alone.
CB/BEA2: FE Return

And then the code that puts you in the world map:


CB/BEA3: 5A Fade screen at speed $04
CB/BEA5: 5C Pause execution until fade in or fade out is complete
CB/BEA6: 3B Position character in a "ready-to-go" stance
CB/BEA7: 3F Assign character $02 (Actor in stot 2) to party 1
CB/BEAA: C0 If ($1E80($18D) [$1EB1, bit 5] is set), branch to $CBBEE5
CB/BEB0: B2 Call subroutine $CB6A37
CB/BEB4: B2 Call subroutine $CACB95
CB/BEB8: 3B Position character in a "ready-to-go" stance
CB/BEB9: 31 Begin action queue for character $31 (Party Character 0), 2 bytes long (Wait until complete)
CB/BEBB: CE Turn vehicle/entity down
CB/BEBC: FF End queue
CB/BEBD: 6B Load map $0000 (World of Balance) instantly, (upper bits $2400), place party at (178, 93), facing down
CB/BEC3: FF End map script


RE: Trying to understand subroutines - Catone - 12-08-2015

Forgive the short answer, but don't have time to recap exactly what all your trying to accomplish, that being said:

CB/BE8D is where the timer is set. That line of code should run, start the timer, then continue through CB/BE93 down to CB/BE98 and return to the "source" (the code that keeps the game running). The timer is running this whole time even though that event has run through, when the timer finally runs out, it starts the code at CB/BEA3 which takes you to the world map.

Point is, in order to remove that code easily, I'd suggest leaving CB/BEA3 where it is and use talking to Cyan (the code at CB/BE9B as a trigger to activate the code at BEA3. Make a jump for custom code at CB/BE8D. If you use a bit check to JUMP, end it with a FE and end it, if you do a jump to subroutine then do your 4 byte subroutine, followed by FE (should have plenty of space) as well as having a FE at the end of your sub routine code.

Not sure if that's the goal or not, sorry if I'm mistaken on your goal. My best guess for the issue is you've removed a small piece of code that the game is trying to access in there so the game is getting lost and don't know where to continue or its just not making its way back to the "go to world map" code.

Could make your jump to free space somewhere sooner in the code, but I would still return to CB/BEA3 and run that part of code where it is however you direct a code to it.

Again, sorry if that isn't much help.


RE: Trying to understand subroutines - Kugawattan - 12-08-2015

After Cyan sees his family depart, the game fades out and in another map where Cyan and Shadow are npcs and all the good stuff. You can talk to both there but to exit the scene there's a countdown that, when reaches 0, fades out and in the world of balance, continuing the game.

What I'm trying to do:
1) remove the countdown.
2) Talking to Cyan triggers a scene where the team leaves, after which it stars running the events at CB/BEA3 which leads me to the world of balance, continuing the game. It's this last part what I can't do. It plays the event just fine, even does the fade screen part.

What I did specifically is 'FD' from CB/BE8D to CB/BE92. Doing so removes the countdown just fine. You can stay there forever and nothing happens.
Then, at CB/BE99 (talk to Cyan) I ran a subroutine (or, more recently, the Code:
C0 F0 01. If $1F0 is clear,
00 F0 35. Branch to 3F/F000
FE Return if set)
to 3F/F000. I wrote my code there, and then literally copy pasted from CB/BEA3 to CB/BEC3, the "set party group and go to world of balance" code, to be clear, ending it with FE.

EDIT: Fixed the code. Derp.


RE: Trying to understand subroutines - Gi Nattak - 12-08-2015

(12-08-2015, 06:11 PM)Kugawattan Wrote: Then, at CB/BE99 (talk to Cyan) I ran a subroutine (or, more recently, the Code:
C0 F0 01. If $1F0 is clear,
35 F0 00. Branch to 3F/F000
FE Return if set)

You must mean 00 F0 35? If you have it like you wrote it here, that would jump to CA/F035.


RE: Trying to understand subroutines - Kugawattan - 12-08-2015

Yes, I meant that. Sorry.