FF6 Hacking
Newbie Still Doesn't Understand Code - 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: Newbie Still Doesn't Understand Code (/thread-3335.html)

Pages: 1 2 3


Newbie Still Doesn't Understand Code - Turbotastic - 09-21-2016

I was looking at the C3 dissassembly and when looking at the code to draw spells for the magic menu, I noticed this.

Code:
C3/4FE4:    20A250      JSR $50A2      (get spells learned amount)
C3/4FE7:    C9FF        CMP #$FF
C3/4FE9:    D02F        BNE $501A      (branch if spell is already learned?)

I'm relying on the comments because I don't understand everything...but is the commentary wrong in this case? The part where it's branching (501A) to is the "blanking out" part. However, there's already a check for not knowing a spell at all prior to this, and this check is for if something is NOT equal to something (what BNE is, essentially). Is 4FE9 just redudnant code or am I terribly misunderstanding what that is checking for?


RE: Newbie Still Doesn't Understand Code - dn - 09-21-2016

That code is part of the code that shows spell+MP cost (enabled by pressing Y), which blanks out partially learned spells as well as unlearned ones. It likely is redundant but wouldn't save much space, as the blanking code is needed regardless. If you'll notice above it, there's a check for whether MP display is enabled or not, and it branches elsewhere if it isn't. That code actually displays learn %.

Code:
Draw text in spell slot of Magic menu
C3/4FC4: A5E6     LDA $E6        ; BG1 write row
C3/4FC6: 1A       INC A          ; Go 1 row down
C3/4FC7: 209F80   JSR $809F      ; Compute map ptr
C3/4FCA: C220     REP #$20       ; 16-bit A
C3/4FCC: 8A       TXA            ; ...
C3/4FCD: 8F899E7E STA $7E9E89    ; Set position
C3/4FD1: E220     SEP #$20       ; 8-bit A
C3/4FD3: A59E     LDA $9E        ; Show MP in list?
C3/4FD5: F067     BEQ $503E      ; Branch if not
C3/4FD7: 20EC50   JSR $50EC      ; Spell
C3/4FDA: 204D51   JSR $514D      ; Handle graying
C3/4FDD: 20EC50   JSR $50EC      ; Spell
C3/4FE0: C9FF     CMP #$FF       ; None?
C3/4FE2: F036     BEQ $501A      ; Blank if so
C3/4FE4: 20A250   JSR $50A2      ; Spell mastery
C3/4FE7: C9FF     CMP #$FF       ; Fully learned?
C3/4FE9: D02F     BNE $501A      ; Blank if not

Fork: Draw spell plus percentage
C3/503E: 20EC50   JSR $50EC      ; Spell
C3/5041: C9FF     CMP #$FF       ; None?
C3/5043: F0D5     BEQ $501A      ; Blank if so
C3/5045: 20A250   JSR $50A2      ; Spell mastery
C3/5048: C900     CMP #$00       ; Zero?
C3/504A: F0CE     BEQ $501A      ; Blank if so
C3/504C: 20EC50   JSR $50EC      ; Spell
C3/504F: 206784   JSR $8467      ; Load name
C3/5052: A2929E   LDX #$9E92     ; 7E/9E92
C3/5055: 8E8121   STX $2181      ; Set WRAM LBs
C3/5058: 20EC50   JSR $50EC      ; Spell
C3/505B: 20A250   JSR $50A2      ; Spell mastery
C3/505E: C9FF     CMP #$FF       ; Fully learned?
C3/5060: F026     BEQ $5088      ; Branch if so
C3/5062: 48       PHA            ; Save mastery
C3/5063: 20B951   JSR $51B9      ; Disable spell
C3/5066: A92C     LDA #$2C       ; Palette 3
C3/5068: 8529     STA $29        ; Color: Bluish
C3/506A: A9C7     LDA #$C7       ; Char: "…"
C3/506C: 8D8021   STA $2180      ; Add to string
C3/506F: 68       PLA            ; Spell mastery
C3/5070: 20E004   JSR $04E0      ; Turn into text
C3/5073: A5F8     LDA $F8        ; Tens digit
C3/5075: 8D8021   STA $2180      ; Add to string
C3/5078: A5F9     LDA $F9        ; Ones digit
C3/507A: 8D8021   STA $2180      ; Add to string
C3/507D: A9CD     LDA #$CD       ; Char: "%"
C3/507F: 8D8021   STA $2180      ; Add to string
C3/5082: 9C8021   STZ $2180      ; End string
C3/5085: 4CD97F   JMP $7FD9      ; Draw string



RE: Newbie Still Doesn't Understand Code - B-Run - 09-21-2016

You also might want to check out this. If you are working on understanding the code, this is a much more exhaustive commentary on C3.


RE: Newbie Still Doesn't Understand Code - Turbotastic - 09-21-2016

Thank you both for the help, resources, and handholding. One of these days I'll either get it or give up.


RE: Newbie Still Doesn't Understand Code - B-Run - 09-21-2016

I was in the same boat at one point. Really, the best way to get over the hump is to pick something small you'd like to do and start working on it. Ask for help when you're stuck and let experience show you how the logic works.


RE: Newbie Still Doesn't Understand Code - Gi Nattak - 09-21-2016

I've been lost at sea on that boat for years now.


RE: Newbie Still Doesn't Understand Code - Lockirby2 - 09-21-2016

(09-21-2016, 09:44 PM)Gi Nattak Wrote: I've been lost at sea on that boat for years now.

Oh, so that sea is made out of alcohol then?


RE: Newbie Still Doesn't Understand Code - Gi Nattak - 09-21-2016

Bwahaha!


RE: Newbie Still Doesn't Understand Code - Turbotastic - 10-06-2016

I'm a slow learner. I'm only now starting to figure out one reason why I was misunderstanding this and other sections of code.

I was assuming "FF" meant "255"  After consulting more documentation, I learned it probably means "-1" instead.

Now it's starting to come together a little.


RE: Newbie Still Doesn't Understand Code - Tenkarider - 10-06-2016

decimals: 0-255
hex: 00-FF
there's the zero, so FF is 256 - 1 = 255