Author Topic: Event Flag log  (Read 3627 times)

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Event Flag log
« Reply #15 on: April 26, 2014, 11:35:01 AM »
I think those divisions in yousei's editor are monster encounter borders.

Like I said, new RAM is overwritten with every movement north or south. Wherever you may be located, there will be 20 (hex) rows above you and below you loaded. And the entire row, from x=0 through x=255.

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Event Flag log
« Reply #16 on: May 01, 2014, 10:01:19 AM »
Well, after all that, I discovered a more mathematical (and thus, to me at least, easier) way to figure all this out.

So...
0,0 on the Overworld Map is loaded into 7F:5C71 (the first byte of Map RAM), and the first row (0,0 through 255,0) is loaded when 7E:0693 is 00.
0,1 on the Overworld Map is loaded into 7F:5D71 (100 hex bytes, or one row's worth, later), and the second row (0,1 through 255,1) is loaded when 7E:0693 is 01.
0,3 on the Overworld Map is loaded into 7F:5E71, and the third row (0,2 through 255,2) is loaded when 7E:0693 is 02.
... And so on in this fashion for the first 64 rows (0,0 through 255,63), or 1/4 of the map.

Now then...
0,64 on the Overworld Map is loaded into 7F:5C71 (the first byte of Map RAM), and the 65th row (0,64 through 255,64) is loaded when 7E:0693 is 40 (hex, which equals 64 in base-10).
0,65 on the Overworld Map is loaded into (you guessed it) 7F:5D71, and the 66th row (0,65 through 255,65) is loaded when 7E:0693 is (you guessed it again) 41 (or 65 in base-10).
... And so on in this fashion for the rest of the second 64 rows.

From here, the pattern is pretty predictable.

So...
To figure out the coding to change a specific point on the map:
First, figure out the hex representation of your map position.
The change will be made when 7E:0693 equals the y value of the point you want to change.
Then, simply add your x value to 7F:5C71 to determine the indexed location in RAM that will be affected.

For example:
If you want a flag to change position 123,204 on the Overworld Map...
first, convert your base-10 position to hex. That's 7B,CC.
You'll be making the change when 7E:0693 equals your y value: CC.
Then add your x value (7B) to 7F:5C71. That's 7F:5CEC.

So the code would look like this (after the flag check comes back true):
Code: [Select]
A5 93 LDA $93
C9 CC CMP #$CC
D0 06 BNE $06
A9 13 LDA #$13
9F EC 5C 7F STA $7F5CEC,X
6B RTL

There it is!
A much quicker process than what I previously posted!
 :childish:

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Event Flag log
« Reply #17 on: May 10, 2014, 01:10:24 PM »
So here's a thing I'm working on: Overworld encounters that are determined by game progress instead of physical location.
This was inspired by ffviii and ix, in which this does happen at certain points, but it has special significance for my hack, where much time will be spent traversing the same terrain - it'll be nice to not have to fight imps at level 25.
I wrote some prototype code this morning and it works like a charm, but I think I still need to work in the bit that tells the game only to do this on the world map and not in locations. I'll post a universal patch when this is complete.

 :edit: typos - I said "is" instead of "ix"and "t8me" instead of "time"
« Last Edit: May 10, 2014, 04:50:13 PM by chillyfeez »

chillyfeez

  • FF4 Hacker
  • *
  • Posts: 1,285
  • Gender: Male
  • Go ahead, ask me about Angel Feathers!
    • View Profile
Re: Event Flag log
« Reply #18 on: May 11, 2014, 12:42:43 PM »
So, as if the programmers actually wanted me to do this, it turns out that the code that picks encounter sets in the Overworld is entirely separate from that which picks encounter sets everywhere else (presumably the same goes for the Underworld and the Moon, but my goal was to only make this happen in the Overworld anyway). So I didn't need to make any edits to the original prototype code! (... ok, I did clean it up a bit after testing it out)

So, the original code that picks enemy encounter sets in the Overworld looks like this:
Code: [Select]
$00/8994 5A          PHY                     
$00/8995 FA          PLX                     
$00/8996 BF 42 C5 0E LDA $0EC542,x     ;Load encounter set based on current section of Overworld Map

Simple enough - observe current location, then reference the appropriate encounter set.

My custom code uses a convenient big block of empty coding space at (LoROM) 00/FD31-FFBB
Basically, it looks at flags 240-245 (normally unused) and based on which, if any, is set it will reference a different encounter set. By using this code, the hacker can then (using FF4kster) simply set one of these flags at the point in the game when they want Overworld encounters to get more difficult!

Here's the code:
Code: [Select]
$00/8994 4C 31 FD    JMP $FD31  [$00:FD31]  ;Jump to custom code
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$00/FD31 5A          PHY                     
$00/FD32 FA          PLX                    ;Make sure registers X and Y are not affected by the custom code, in case they're important (They're not used here)
$00/FD33 AD 9E 12    LDA $129E  [$00:129E]   
$00/FD36 29 3F       AND #$3F               ;Observe (only) flags 240 through 245
$00/FD38 C9 20       CMP #$20               ;Is flag 245 set?
$00/FD3A 90 04       BCC $04    [$FD40]     ;If not, skip to next check
$00/FD3C A9 06       LDA #$06               ;If so, load encounter set 6 into A
$00/FD3E 80 1E       BRA $1E    [$FD5E]     ;Jump to end
$00/FD40 C9 10       CMP #$10               ;Is flag 244 set?
$00/FD42 90 04       BCC $04    [$FD48]     ;If not, skip to next check
$00/FD44 A9 05       LDA #$05               ;If so, load encounter set 5 into A
$00/FD46 80 16       BRA $16    [$FD5E]     ;Jump to end
$00/FD48 C9 08       CMP #$08               ;Is flag 243 set?
$00/FD4A 90 04       BCC $04    [$FD50]     ;If not, skip to next check
$00/FD4C A9 04       LDA #$04               ;If so, load encounter set 4 into A
$00/FD4E 80 0E       BRA $0E    [$FD5E]     ;Jump to end
$00/FD50 C9 04       CMP #$04               ;Is flag 242 set?
$00/FD52 90 04       BCC $04    [$FD58]     ;If not, skip to next check
$00/FD54 A9 03       LDA #$03               ;If so, load encounter set 3 into A
$00/FD56 80 06       BRA $06    [$FD5E]     ;Jump to end
$00/FD58 C9 02       CMP #$02               ;Is flag 241 Set?
$00/FD5A 90 02       BCC $02    [$FD5E]     ;If not, then the appropriate encounter set (0 or 1) is already loaded into A, so jump to end
$00/FD5C A9 02       LDA #$02               ;If so, load encounter set 2 into A
$00/FD5E 4C 9A 89    JMP $899A  [$00:899A]  ;Jump back to the rest of the normal routine

By the way, this only uses three of the almost 40 lines of code in FD31-FFBB, so the same could be done for the other world maps if you wanted.

Since the code is all here, I'm going to skip the patch (I have some housework to do today). But I can put up a patch later if anyone wants it - let me know.

Grimoire LD

  • FF4 Hacker
  • *
  • Posts: 1,684
    • View Profile
Re: Event Flag log
« Reply #19 on: May 11, 2014, 03:43:36 PM »
Oh my goodness! This is absolutely awesome! What a fantastic idea for a patch, Chillyfeez and what a way to show an ever changing world instead of... as you mentioned.. Imps in at least 60% of the world map. Keep up the excellent work!