Skip to content
Clément Gallet edited this page Jun 28, 2014 · 5 revisions

How RNG is generated during fights

$BE: offset in the RNG table 0xC0fd00 - 0xC0fdff

Three random number generator functions:

  1. Random number [0..1]: C2/4B53
  2. Random number [0..255]: C2/4B5A
  3. Random number [0..A-1]: C2/4B65

Each function increments $BE by 1 and looks at the RNG table with offset $BE.

Content of the init battle function (C2/23ED) which involved RNG

Taken from a http://www14.brinkster.com/assassin17/guides/00BE-results.txt by Assassin.

  1. C2/23ED initializes $00BE to Variable $021E (the frame counter, ranged 1-60) * 4. Hence it's always a multiple of 4 between 4 and 240.

  2. C2/30E8 calls random number function (C2/4B5A) to further pick the formation, and $00BE is incremented by the random # function. (NOTE: this step only applies to the Floating Continent, where you can randomly get 4 formations for each entry in a 4-pack.)

  3. C2/23ED calls random number function (C2/4B5A) 10 times (once for each possible entity); each call increments $00BE by 1. This randomization serves to stagger when entities get periodic damage/healing from Seizure, Regen, Phantasm, Poison, or from being a Tentacle who's Seize draining.

  4. In function C2/2C30, the Vigor for every monster (active or not) is randomly calculated using C2/4B5A; each call increments $00BE by 1.

  5. C2/083F calls C2/09B4 for each target onscreen, though it apparently skips the call for dormant enemies. C2/09B4 determines an entity's starting Condemned counter (which will promptly be cleared after this if the entity wasn't actually getting the status), and it calls random number function C2/4B65, which increments $00BE.

  6. Now it's time to randomly pick an encounter type (front/back/side/pincer). C2/5247 is responsible for that, and it calls C2/4B65, which increments $00BE before giving us our random number.

  7. determine if preemptive (C2/2E93 - C2/2E99: fonction pointers). This step is skipped if the formation has "Hide start messages" set, or if any active monsters therein have "Attack First" set.

  • if front attack, preemptive if [0..255] < 0x20 (0x40 for Gale Hairpin)
  • if side attack, preemptive if [0..255] < 0x38 (0x70 for Gale Hairpin)
  1. load ATBs (C2/2575). For each entity, assign a specific incrementor (unique element in 0, 8, .., 72; see C2/522A).
  • If front attack, set top byte of ATB = [0 .. Speed($3B19,Y)-1] + Speed + specific_incrementor + (10 - number of valid entities) * 16. Top byte of ATB is set to 255 if overflowed.
  • If back or pincer, set top byte ATB of characters to specific_incrementor + 1
  • If preemptive or side attack, set top byte ATB of monsters to 2

Specific incrementor for ATB stratup, to be deciphered

Randomly picks a bit set in A

C2/522A: 5A           PHY
C2/522B: 08           PHP 
C2/522C: C2 20        REP #$20       (Set 16-bit Accumulator)
C2/522E: 85 EE        STA $EE
C2/5230: 20 0E 52     JSR $520E      (X = number of bits set in A)
C2/5233: 8A           TXA 
C2/5234: F0 0E        BEQ $5244      (Exit if no bits set)
C2/5236: 20 65 4B     JSR $4B65      (random: 0 to A - 1)
C2/5239: AA           TAX 
C2/523A: 38           SEC 
C2/523B: 7B           TDC 
C2/523C: 2A           ROL 
C2/523D: 24 EE        BIT $EE
C2/523F: F0 FB        BEQ $523C
C2/5241: CA           DEX 
C2/5242: 10 F8        BPL $523C
C2/5244: 28           PLP 
C2/5245: 7A           PLY 
C2/5246: 60           RTS 
Clone this wiki locally