Users browsing this thread: 1 Guest(s)
Newbie Still Doesn't Understand Code

#11
Posts: 826
Threads: 11
Thanks Received: 22
Thanks Given: 13
Joined: Nov 2011
Reputation: 16
Status
Double
Well, the thing is that the hex can have different meanings depending on whether it is representing a signed number or an unsigned number. If it is representing an unsigned number, $00 is zero, $7F is 127, $80 is 128, and $FF is 255. If it is representing a signed number, then $00 is zero, $7F is 127, $80 is -128, and $FF is -1 (although I think there are more systems for signed numbers, this is the one that I'm most familiar with).


Confused Moogles FTW
Quote  

#12
Posts: 3,970
Threads: 279
Thanks Received: 236
Thanks Given: 58
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
For any operation affection the Zero flag, number having the highest bit set (bit 7) can be considered negative.

It depends what you do with the number. Doing 255 + 1 will equal doing -1 + 1. It's $FF in both cases and the result is 0. The carry flag is set here. Doing 1 minus 2 will equal 1 but the carry will be cleared. It depends what you do with the carry (BSC, BCC).

Short story, $FF can equal minus 1.
  Find
Quote  

#13
Posts: 89
Threads: 11
Thanks Received: 3
Thanks Given: 1
Joined: Dec 2015
Reputation: 3
Status
Debrave
All right, I was playing around with NOP-ing pieces of the code with various degrees of success*, and I became curious about something.

Despite the fact that the "default" view is the normal pool of available spells, both the code and my tests seem to indicate that the Spell + Cost view when pressing Y mode is actually the primary mode (and thus any changes must be made there first), while the view the player sees by default is actually the secondary view. Is this actually the case, or am I making a distinction where there is none?

*My short-term goal was to allow spells to be available even if they aren't in the actor's spell list. I had limited success on that front. I NOPed C3/4FE0-C3/4FE3 andC3/4FE7-C3/4FEA and all the spells became usable when I pressed Y.  When I NOP-ed C3/4FD5, though, removing the branch granted access to the spells...but removed the ability to see the spells without the MP cost next to them.
  Find
Quote  

#14
Posts: 32
Threads: 5
Thanks Received: 4
Thanks Given: 1
Joined: Feb 2012
Reputation: 4
Status
Sleep
Can you provide info on what changes you made and a summary of the results?  That would help a bit when trying to diagnose what is happening.

In order to get a spell to display it needs to be marked as learned.  You shouldn't really need to change the display code, you would have to change the code that decides when a spell is learned.  In almost all cases spells are learned after battle, this code is in C2.  In this case spells include Magic, SwdTechs, Blitzes, and Lores as well.

If you are trying to allow spells to be available even if they aren't in the actor's spell list, we would need to first think of a way that you would trigger making that spell available otherwise. This would likely involve some coding that would interfere with the current system in place. Unfortunately I don't think it would be easy as It would be difficult to have spells marked both as not learned and learned at the same time.

A good point of study would be Hatzen08's Imbued Magic patch.  It replaces the current system with only allowing spells to be learned when an esper or item is equipped.  Once the item or esper is unequipped the spell is removed.  This also has the side effect of removing natural magic entirely.  I believe this was for space reasons but there are also some logistical issues to consider with it that make having both difficult at the same time.

EDIT: By logistical issues I mean overriding spell lists.
Quote  
[-] The following 1 user says Thank You to Xontract for this post:
  • Turbotastic (12-10-2017)

#15
Posts: 89
Threads: 11
Thanks Received: 3
Thanks Given: 1
Joined: Dec 2015
Reputation: 3
Status
Debrave
Sorry, I edited the post above after you posted.

Given that the code was allegedly blanking out the spells that aren't learned I was playing around to see if it was just blanking out the display, or if it were blanking out the use of those spells themselves. At least when you press the Y button, the code was doing the latter, essentially. It is possible for a spell to be used when it isn't learned by an actor. I was trying to see how this could be done without being stuck on that specific display. If it's obviously not at all practical, I can procreed with a non-standard menu.

I know I'd have to miles more work and custom ASM work, but I was trying to figure out if there is an equivalent for the standard display.

I realize I wasn't being clear.  In C3, I first changed the existing HEX

Code:
C3/4FE0:    C9FF        
C3/4FE2:    F036        
C3/4FE4:    20A250      
C3/4FE7:    C9FF    
C3/4FE9:    D02F    

to

Code:
C3/4FE0:    EAEA       
C3/4FE2:    EAEA       
C3/4FE4:    20A250      
C3/4FE7:    EAEA    
C3/4FE9:    EAEA    



This led to every spell being listed in the menu as fully learned (and behaving as such) when Y was pressed. Note that partially learned spells are still considered partially learned according to the Espers and presumanly wherever this information is stored. However, the spells themselves were usable from the menu.

I then changed the Hex here...


Code:
C3/4FD5: F067


...to...


Code:
C3/4FD5: EAEA


I removed the branch, and Magic screen behaved as if Y was being pressed.

Obviously this does not carry over into battle (although I played around there a little and can confirm it is possible for a spell to be added to an actor's menu for use AND for them to learn the unlearned spell normally), but I just wanted to be more straightforward.
  Find
Quote  

#16
Posts: 32
Threads: 5
Thanks Received: 4
Thanks Given: 1
Joined: Feb 2012
Reputation: 4
Status
Sleep
When you say usable were you actually able to cast spells like Cure? Its possible to get the spells to display without them being usable...I assumed by display you meant actually able to cast which I don't believe is possible.

It makes sense that all spells would display if you removed the code checking if they were usable before allowing them to display, I just didn't think you would actually be able to cast them.

I would doubt that all spells would be available in battle even if you could get them to be when pressing Y but i'm interested in hearing your results.
Quote  

#17
Posts: 89
Threads: 11
Thanks Received: 3
Thanks Given: 1
Joined: Dec 2015
Reputation: 3
Status
Debrave
I'm just working with C3 for this example, so I'm just looking at the "outside of battle menu." But I was able to cast the eligible spells from the menu and they worked as they normally would.

I'll try on another emulator to just confirm it wasn't just the one I was using, but it DID work.

Edit: I did try with both a different emulator and a fresh local copy where I made the changes. I can confirm the spells are usable from the menu.

[Image: 3yfPKIr.png]

Magic list displays as normal, but when you press Y...

[Image: qSZediN.png]
SUCCESS!!  Let's repeat.

[Image: 6zSRKBb.png]

Again with no Y...no spell...but press Y...

[Image: A0Bf1aq.png]

...and the spell is added to the list! (Note, the 0 in MP cost is displayed if the cursor does not move, but if you move the cursor, the correct cost is displayed. This part IS buggy, though.)

Yes, the spells work...

[Image: 0vmXA8f.png]
[Image: J0LZP7h.png]

What I was trying to do was figure out how to get the list of spells to appear without pressing Y, and while I can do that by removing the branch...that forces the MP cost to be displayed all the time. I can live with it, though, and I might figure it out myself. I'm taking baby steps here.

And speaking of baby steps, just blanking C3/4FE0 and C3/4FE2 has no effect while blanking C3/4FE7 and C3/4FE9 seems to have the same effect as described, which indicates the latter code is responsible.
  Find
Quote  

#18
Posts: 89
Threads: 11
Thanks Received: 3
Thanks Given: 1
Joined: Dec 2015
Reputation: 3
Status
Debrave
I hate to double post, but the content of this post is completely different from that of the previous ones.

I gave up on C3 for now and moseyed over to C2.  I'm finally starting to understand how the code works here instead of just reading commentary. However, there is still something that nags at me.

As many of you know already, the magic menu in  battle is literally built twice.  At first, the spells in the Magic menu are populated to those known by ALL the characters, and then the spells are restricted to individual character menus.  In both cases, there are are branches to deal with unknown spells, but in each loop these branches are handled differently.

For instance in the first pass, we get....


Code:
C2/55A3: C9 FF        CMP #$FF       (does this character know the current spell?)
C2/55A5: D0 04        BNE $55AB      (branch if not)

BNE (D0) is "branch if not equal" or if the zero flag is not set, and most often, this is the branch used to compare if something is not equal.

The second pass is different.


Code:
C2/56EC: C9 FF        CMP #$FF
C2/56EE: F0 1E        BEQ $570E


This uses BEQ (F0) operator, the branch if equal or zero. In this case, though, it does branch if not equal. Apparently because the zero flag has been set, it works that way.

I have two questions.

1. Where is the zero flag set prior to this?
2. If the zero flag is not set prior to this, why is BEQ behaving identically to BNE?
  Find
Quote  

#19
Posts: 1,633
Threads: 56
Thanks Received: 13
Thanks Given: 84
Joined: Apr 2014
Reputation: 12
Status
Atma
if i got your question, then the answer is... zero flag is affected from CMP, which compares the #$value with the accumulator(it should be that, the register)


THE GREATEST CHALLENGE OF ALL TIMES AWAITS:
http://www.ff6hacking.com/forums/showthr...p?tid=2593
DO YOU HAVE WHAT IT TAKES TO SLAY A GOD?
------------------------------------------------------------------------
Tenkarider's project #2 is started: FF6 Curse of the Madsiur Joke (CotMJ)
http://www.ff6hacking.com/forums/showthr...p?tid=2755
What happens when Madsiur tweaks your account? This full game hack will show that!
  Find
Quote  
[-] The following 1 user says Thank You to Tenkarider for this post:
  • Turbotastic (10-18-2016)

#20
Posts: 3,970
Threads: 279
Thanks Received: 236
Thanks Given: 58
Joined: Oct 2011
Reputation: 65
Status
Tissue-aware
(10-18-2016, 09:37 AM)Turbotastic Wrote: 2. If the zero flag is not set prior to this, why is BEQ behaving identically to BNE?

You have to look in the code previous to this to see where the zero flag is changed but it's a bit irrelevant to your example since CMP affect the zero flag. If the zero flag was already set and your CMP set the zero flag, it changes nothing, otherwise it will be clear. What the zero flag was prior to a CMP don't matter.

Your second example should branch if what is in A equals #$FF. Executing the branch with a debugger should prove you that. If A not equal #$FF, the code under the BEQ will be executed.
  Find
Quote  
[-] The following 1 user says Thank You to madsiur for this post:
  • Turbotastic (10-18-2016)



Forum Jump:

Users browsing this thread: 1 Guest(s)


Theme by Madsiur2017Custom Graphics by JamesWhite