øAslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&topic=1700.0e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexf97a.htmlslickproductions.org/forum/index.php?PHPSESSID=5f0fck550j2m4m2fpbtkj2vkm1&board=8.200e:/My Web Sites/Slick Productions - FFIV Message Board/slickproductions.org/forum/indexf97a.html.zx|&h^ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈà•¤YÉOKtext/htmlISO-8859-1gzip8:ÖYÉÿÿÿÿÿÿÿÿWed, 11 Mar 2020 00:01:25 GMT0ó°° ®0®P®€§²ð®|&h^ÿÿÿÿÿÿÿÿ"YÉ Unused RAM?

Author Topic: Unused RAM?  (Read 2257 times)

Madsiur

  • Tunnel Armor
  • *
  • Posts: 149
  • Gender: Male
  • FF6AE coder
    • View Profile
    • Madsiur's Lair
Unused RAM?
« on: January 28, 2012, 10:23:01 PM »
I got a question for you guys,

Is there any RAM that could be used to store temporary values in FF3us? I'm trying to write a event command that would check if all the characters of the current party are above level X (parameter). My problem is that I'm looping 16 times and make a check on the party of each character to see if they are in the active one. So X holds the character number or in other words the number of times I have looped so far and Y holds the value of the increment to make the check respectively at $0867,Y (current character party?). Later on in the function I want to load the value at $1608 + (character number multiply by #$25) which is the level of the current character in the active party but I don't want to put that value in a variable that could affect other things in the game.

So is there some safe and/or unused places in the RAM I could dump that temporary value or any other value?

Or would there be a way by clever assembly programming to do what I want to do and only use A, X and Y without storing one of the two increments (level and party) related to the character in a variable ? (Don't give me the answer I just want to know if it's possible...)

Thanks in advance

Madsiur

  • Tunnel Armor
  • *
  • Posts: 149
  • Gender: Male
  • FF6AE coder
    • View Profile
    • Madsiur's Lair
Re: Unused RAM?
« Reply #1 on: February 03, 2012, 09:03:34 PM »
well sorry for the double post...

Someone suggested me to use the japane bushido names space ($1CF8 to $1D27) which is not a bad thing but I would prefer using a place in the RAM that is not where the data are saved so anywhere previous to $1600 and after $2000 I guess but I don't what t touch a spot that would contain or could contain an important value that could be needed by the game after I overwrite it. I know there must be "unused RAM" floating around but how can I identify it? I only need a few bytes for temporary values, at most 3 x 2 bytes...

I know that most of the RAM between $2000 to $3000 hold the battle related RAM so could I use temporary a spot there (like the enemy names from $200D to $2018) assuming the values are reset after a fight or overwritten at the beginning of a battle?

Any suggestion?

assassin

  • Bane of Retards
  • *
  • Posts: 1,033
  • space bears are not gentle!
    • View Profile
    • My Barren Webpage
Re: Unused RAM?
« Reply #2 on: February 03, 2012, 10:08:53 PM »
Or would there be a way by clever assembly programming to do what I want to do and only use A, X and Y without storing one of the two increments (level and party) related to the character in a variable ? (Don't give me the answer I just want to know if it's possible...)

i really couldn't answer this without seeing your tentative code, or at least pseudocode.  there's always the stack to store temporary variables on, btw.  though it can get unwieldly if you have branches, because then you have to PLA in two separate places.

as for potentially free variables, Function C0/6CF3, which is called by a few event functions, uses the 1-byte $1B.

that doesn't necessarily mean it's safe elsewhere, and i generally know nothing about Bank C0.  still, it's something to look into.  what prompted me to mention it is finding C0/6CF3 in a search for "$0867,Y".

but i'm sure one of the people who mess around in C0 more often can give you more conclusive answers.

Madsiur

  • Tunnel Armor
  • *
  • Posts: 149
  • Gender: Male
  • FF6AE coder
    • View Profile
    • Madsiur's Lair
Re: Unused RAM?
« Reply #3 on: February 04, 2012, 01:46:27 AM »
Thanks for the answer!

i really couldn't answer this without seeing your tentative code, or at least pseudocode.  there's always the stack to store temporary variables on, btw.  though it can get unwieldly if you have branches, because then you have to PLA in two separate places.

Well the stack could be a good option. Sorry for my ignorance, but how much bytes can the stack hold? I tried to find the answer on net but I haven't found anything...

Let's say I PHA 4 bytes (twice 2 bytes) into the stack: The important thing if I understand right would be to PLA those 4 bytes by the end of my custom function in case what is already in the stack (if there is anything) would be require by another function later on ?

Quote from: assassin
as for potentially free variables, Function C0/6CF3, which is called by a few event functions, uses the 1-byte $1B.

You're right. $1B seems to used to store a character number, sometimes a data from a character (such as his level) or it's even used a a counter for looping I think.
Another solution would be like you did to try to identify (potentially safe) variables that are used to store multiple things...I should start taking notes...

As for my code I haven't really worked on my function since last week and I was really absorbed in SPC composition this week. I'll post it when I'm sure it's good so that way I won't look like an idiot. I'm still learning...  :blush:


Edit: Well I'm not done but here's what my code looks like. This one checks if one member of the active party has a level higher than the parameter. I would like to change the code so it would check if all members of the party have a level higher than parameter...Then I would need to store the number of people in the party somewhere (in the stack maybe?) and how many members of the party has a level higher than the parameter somewhere else ($1B?) and compare those two values when I would have looped 16 times. There might be some mistakes in my code but you should get the general idea:

Code: [Select]
TDC                     (zero A)
  LDX $00 (zero X)
            TXY             (zero Y)
REP #$20              (16 bit accum./memory)
(A)           LDA $0867,Y (current character's party)
            AND #$0007 (check which party)
  CMP $1A6D (compare A to the value of the active party stored in $1A6D)
    BNE  (branch  to (B) if not the current party)
SEP #$20 (8 bit accum./memory)
STX $4202 (store character number as multiplier A)
LDA #$25 (character data length)
STA $4203 (store character data length as multiplier B)
REP #$20              (16 bit accum./memory)
NOP (wait for the multiplication to be done)
NOP (wait for the multiplication to be done)
LDA $4216 (store the result of the multiplication in A)
TAY (transfer A to Y)
LDA $1608,Y (load current level of the character)
SEP #$20 (8 bit accum./memory)
(E) CMP $EB (compare to parameter)
BEQ (Branch to (D) if level was initially equal or higher than parameter)
CMP #$01 (check if it looped down to level 1)
BEQ (branch to (B) if level was never equal or higher than parameter)
DEC (decrement level by 1)
BRA (Branch to (E))
(B) INX (Increment X by 1)
TXA (Transfer X to A)
BIT #$10 (Have we checked all 16 characters?)
BNE (Branch  to (C) if we have checked all the characters)
STX $4202 (store next character number as multiplier A)
LDA #$29 (character data lenght)
STA $4203               (store character data length as multiplier B)
NOP (wait for the multiplication to be done)
NOP (wait for the multiplication to be done)
REP #$20              (16 bit accum./memory)
LDA $4216               (store the result of the multiplication in A)
TAY (Transfer A to Y)
BRA (Branch to (A))
(C) REP #$21
LDA $E5                   (Load low and middle byte of current offset)
ADC #$0005    (Command + parameters length)
                STA $E5         (Save in $E5)
                TDC             (Transfer D to C)
                SEP #$20        (8 bit accum./memory)
                ADC $E7         (Add to A $E7)
                STA $E7         (Store A in $E7)
JMP $C09A6D            (Make a 5 bytes jump from the command number in the event)
(D)           REP #$20        (16 bit accum./memory)
                LDX $EC         (Load parameter 2 and 3)
                STX $E5         (store the low and middle byte of the offset in $E5)
                SEP #$20        (8 bit accum./memory)
                LDA $EE         (Load parameter 4)
                CLC             (clear carry)
                ADC #$CA        (Add #$CA to the high byte of the offset)
                STA $E7         (Stre high byte of the offset in $E7)
JMP $C09A6D     (Make the event branching/jumping effective)

« Last Edit: February 04, 2012, 05:22:37 AM by Madsiur »

Lenophis

  • Forum Overlord
  • *
  • Posts: 1,688
  • Gender: Male
  • I sad
    • View Profile
    • Slick Productions
Re: Unused RAM?
« Reply #4 on: February 04, 2012, 09:31:39 AM »
$1A-$1D are generally used for scratchpad purposes. There's others, but this is the most common here in C0.

119 bugs fixed and counting.

Madsiur

  • Tunnel Armor
  • *
  • Posts: 149
  • Gender: Male
  • FF6AE coder
    • View Profile
    • Madsiur's Lair
Re: Unused RAM?
« Reply #5 on: February 04, 2012, 01:02:54 PM »
Thanks Lenophis. I made it work with the stack and $1B.  :happy:


And this time I did more tests with the command.