Skip to content

132 worked example the debug screen behind the zoom toggle

Alex Diakovsky edited this page Oct 11, 2026 · 2 revisions

132. Worked example: the debug screen behind the zoom toggle

Question: issue #105. While closing #91 (document 129) we found a camera toggle in the vehicle's per-tick FUN_0040b980. It only works when DAT_00442afc == 1, and nothing obvious ever sets that. What turns it on, and should the port build the toggle? Scripts and field names are in the tracing cheat sheet.

Answer: DAT_00442afc is the "Display FPS" switch on the developers' debug screen. That screen opens on a three-button chord. The PC can't produce the third button: no key, CONFIG.BIN control or joystick button is bound to it. So in the retail PC game the toggle can't be reached. It is not built.

Step 1: the toggle

0x40bc0f (in FUN_0040b980, after the decoder has filled state+8 with the vehicle's input word):

if (DAT_00442afc == 1 && (state->input & 0x120) == 0x120) {        // A pressed and B pressed, this tick
    state->rest_height = (state->rest_height == rec->+0x130) ? rec->+0x2d0 : rec->+0x130;
    state->input &= 0xfffff81f;                                       // drop the A/B press, hold and release bits: nothing fires
}

The decoder (document 113, FUN_0042ce40) turns button A (0x8000000) into 0x20 / 0x40 / 0x80 (press / hold / release) and B (0x4000000) into 0x100 / 0x200 / 0x400. So the toggle is "press the first two action buttons on the same tick". It swaps the rest height between +0x130 (0; Heli 60) and +0x2d0 (-200; Heli -150).

Step 2: who writes DAT_00442afc

A capstone sweep for the displacement 0x442afc (scan_disp.py) finds eleven uses. Ten are in FUN_004065c0 and FUN_00406cb0; the eleventh is the toggle above. The only constants ever stored are 0 and 1. FUN_004065c0 reads the value on entry and compares it again on exit, but never writes a new value itself. So the new value comes through a pointer. The pointer is in the table FUN_004065c0 walks: four 0x24-byte records at 0x442b38.

Record Label (+8) Value names (+0xc) Variable (+0x1c) min / max (+2, +3)
0x442b38 AUDIO SCREEN — — (handler 0x405720 at +0x20)
0x442b5c Flag in first building: %s 0x442b30 = {"Off", "On "} 0x442b00 0 / 1
0x442b80 Display FPS: %s 0x442b30 0x442afc 0 / 1
0x442ba4 EXIT — —

The edit code is in FUN_004065c0. Up and down move between items (the links at +0x10..+0x13). On an item, pressing A or right steps the pointed-to variable up to its max, and pressing left steps it down to its min:

piVar2 = *(int **)(item + 0x1c);
if (A pressed || right pressed)    { *piVar2 += 1; if (item[3] < *piVar2) *piVar2 = item[3]; }
if (left pressed)                  { *piVar2 -= 1; if (*piVar2 < item[2]) *piVar2 = item[2]; }

So DAT_00442afc is the menu's "Display FPS" item, which is Off or On. The 3DO disc's symbol table (rfire.sym, #94) names a Debug_DisplayFPS, a Debug_FirstFlag, a displayDebugScreen, a Debug_ControlRoutine and an fps_CCB. The addendum below confirms the first two from the 3DO data layout and values, not just the names.

Step 3: what the debug screen is

FUN_004065c0 is a modal screen. It draws text in a debug font and loops until EXIT. Text it prints (format strings found by disassembling the pushes):

RFire Ver: G406.1.0.00 Win95 x86
Map: "%s"
GameNumber: %06d
      0x%02x                     <- only after a secret sequence, below
Objects: Free %3d, Active %3d, Inactive %3d, Use...
Total: %3d                       <- drawn in another colour unless it is 511
AUDIO SCREEN / Flag in first building / Display FPS / EXIT

The 0x200000 and 0x400000 buttons (Q and E by default) shift a 1 or a 0 into DAT_0048caf8. When the last eleven are 0x6c6, the screen shows the byte at 0x4466fb as an extra line. "Flag in first building" (0x442b00) is read once, in the flag-reveal function FUN_00432710 (document 129, #104). At 0x432751, when it is on, the countdown is skipped and the first flag building destroyed reveals the flag.

FUN_00406cb0 runs every frame from the terrain blitter FUN_00408d60. Two things happen there:

  • The FPS counter. While DAT_00442afc is on, it counts frames (DAT_00457238). Every 60 ticks it draws the count (capped at 60) as one 16 x 8 tile of cel 2140: column n & 7, row n >> 3 (0x406db6). The counter is drawn at x = 32, y = 170, or a little higher in some modes (DAT_0045722c, DAT_00457230).
  • Opening the screen. For each player's input word it checks:
if ((*word & 0x1600000) == 0x1600000) {      // 0x1000000 + 0x400000 + 0x200000 together
    *word &= ~0x1000000;
    FUN_004065c0(word, previous_word);       // the debug screen
}

Cel 2140 is a picture of the numbers 0-109. The registry had called it effect.static_noise.01, a visual guess; document 80 had already doubted that.

Step 4: can the PC press 0x1600000?

The input word is built by FUN_0041b890. The keyboard path is FUN_0041bce0, and each slot of the per-player key table (0x480db0 + player * 0x94) adds one bit:

Slot +0x2c +0x30 +0x34 +0x38 +0x3c +0x40 +0x44 +0x48 ... +0x54
Bit 0x8000000 A 0x4000000 B 0x2000000 C 0x200000 0x400000 0x1000000 0x800000 up, down, left, right
1-player default (FUN_0041c990) H J K Q E none none W, S, A, D

FUN_0041c630 copies eleven halfwords per player into the table. FUN_0041c990 fills the defaults, and FUN_0041c810 reads the saved bindings from the registry value under Software\Silent Software, Inc.\Return Fire\1.0. The defaults never set halfwords 5 and 6 (bits 0x1000000 and 0x800000) for either player, in either layout. CONFIG.BIN's keyboard pages (dialogs 129 and 130) have nine keys per player: Forward, Reverse, Right, Left, Bank Left, Bank Right, Fire Down, Fire Straight, Switch Guns. So there are eleven slots and nine controls. The joystick path reads the buttons at 0x480e08..0x480e18 and the directions at 0x480e24..0x480e30, and skips 0x480e1c and 0x480e20. So no joystick button makes 0x1000000 either. The only other source is the replay reader FUN_00401150, which plays back words that were recorded from the same input.

The bit layout looks like the 3DO control pad's: A, B, C, the two shoulder buttons, P (start) and X (stop), then the four directions. Read that way, the PC never mapped P or X, and on a 3DO the screen would be both shoulder buttons + P. That reading comes from the 3DO pad layout, not from tracing the 3DO code.

What CONFIG.BIN writes into halfwords 5 and 6 is traced in the addendum below: always 0.

Applied in the port

Nothing is built. The toggle depends on a developer screen the retail PC game can't open, so it isn't part of PC parity. The pack keeps camera.zoom_height (record +0x2d0) in case a debug feature ever wants it. The notes now say why (engine game/camera_rig.gd):

## Not modelled: the two-button zoom toggle (0x40bc24, `zoom_height`). It only works while DAT_00442afc, the "Display FPS" switch of the
## developers' debug screen (3DO symbol Debug_DisplayFPS), is on, and that screen needs a button the PC never binds to a key or a
## joystick button, so the retail game never reaches it (openfire issue #105, document 132).

and tools/extract_vehicle_types.py:

        "zoom_height": fixed(t, 0x2D0),            # record +0x2d0: what the debug-only two-button toggle (0x40bc24) swaps rest_height to; never reached in the PC game, not built (document 132)

The registry renames cel 2140 (AUDIT15 in tools/registry/classify_batch2.py, mirrored by hand in packs/registry/asset_ids.json):

AUDIT15 = [
    (2140, "ui.debug.number_sheet", "ui", "the numbers 0-109 on 16 x 8 tiles, eight to a row: the debug screen's frame counter draws tile n "
     "for the n frames drawn in the last 60 ticks, capped at 60 (FUN_00406cb0 at 0x406db6, CCB 0x23870 / 68; the 3DO symbols include an fps_CCB; document 132). "
     "Was mislabelled effect.static_noise.01", "code_verified"),
]

PORTING_PLAN 1.14 records the result. No game code reads cel 2140, so the rename changes only the pack's sprite name.

Addendum: the loose ends

Traced after the first version of this document.

What CONFIG.BIN saves for the unused slots

CONFIG.BIN keeps the whole 0x84-byte bindings block in a global at 0x425198, in .data and zero at load. A capstone sweep for every halfword address in the block, 0x425198 + 2n, finds reads and writes for 54 of the 66 halfwords. It never touches halfwords 5, 6, 16, 17, 27, 28, the keyboard slots for 0x1000000 and 0x800000 in each layout, or 38, 39, 49, 50, 60, 61, the joystick slots the game skips. Its defaults (0x401050, 0x4010d0) skip them too.

At start-up (0x405120) it calls 0x401000, which writes the defaults and then calls the loader 0x4011c0. The loader reads the Keyboard and Joystick value (string 39) under Configuration. If the key is new, or the value is missing (error 2), it first writes the block as it is (0x4012f4, 0x401341). OK saves it with 0x4013b0 (RegSetValueExA(..., 0x425198, 0x84) at 0x4014c5). So whenever CONFIG.BIN has run, those slots are 0 in the registry. VK code 0 is not a key: Windows never sets it in GetKeyboardState, so 0x1000000 never appears.

The leftover-memory case needs RFIRE.BIN to create the value itself, before CONFIG.BIN has ever run. The normal way in is the AutoRun front end, which is CONFIG.BIN (string 1 &Play, string 4 &Config), so it runs first.

The 3DO symbols: matched by layout, not just by name

tools/rf3do_sym.py decodes the variable records (code 4) of rfire.sym. A record's location is the offset in the 3DO rfire executable, whose load base is 0: the two font path strings sit exactly at their symbols' locations. The variables around debug.c's data:

000386a8  DebugFontName        "RFIREData/DebugFont.3DO"       PC 0x442ac8, the same string
000386c0  SmallDebugFontName   "RFIREData/SmDebugFont.3DO"     PC 0x442ae0
000386dc  DebugFont            0
000386e0  SmallDebugFont       0
000386e4  Debug_DisplayFPS     0                               PC 0x442afc
000386e8  Debug_FirstFlag      0                               PC 0x442b00
000386ec  Debug_ControlRoutine 0
000386f0  ComboLock            0
000386f4  MinDebugZ            0xff560000 (-170.0)             PC 0x442b04 = 0xff560000
000386f8  MaxDebugZ            0x00f00000 (240.0)              PC 0x442b08 = 0x00f00000
00038700  fps_NextFrame, fps_FrameCount, fps_BackgroundCopy, fps_x, fps_y (statics), 00038714 fps_CCB

On the PC, the two strings are followed directly by 0x442afc, 0x442b00, -170 and 240. The four zero-initialised words between them on the 3DO are missing on the PC, presumably moved to uninitialised data by the PC compiler. With the two unusual constants in the same order, 0x442afc is Debug_DisplayFPS and 0x442b00 is Debug_FirstFlag. MinDebugZ and MaxDebugZ have no reader on the PC (no displacement hit). ComboLock fits the secret-sequence register DAT_0048caf8, but only by name: it lives in PC uninitialised data, so the layout check can't reach it.

One more 3DO global: ZoomStorage at 0x3778c holds four 16.16 values, -170, -170, -170, -100. The PC's zoom heights (record +0x2d0) are -200, and -150 for the Heli. Which vehicle each 3DO value belongs to, and whether the 3DO toggle works the same way, is not traced (3DO code; #94).

The hidden line: the options byte

The extra line after the 0x6c6 sequence prints the byte at 0x4466fb. Its only users are the Music option:

  • the Options menu's Music item (0x3f0) at 0x420197 / 0x4201c4;
  • the configuration dialog's Music box (0x3ef) at 0x4229c9;
  • 0x41ada7 and 0x405590.

Bit 0 is set while music is off: 0x405660 stops it (0x48c548 = 1) and 0x405680 starts it again. It is cleared at start-up (0x41a634), and no code tests any other bit. So the line shows 0x00 or 0x01, music on or off.

AUDIO SCREEN

This is the sound test that document 117 found (FUN_00405720). It lists every cue in the table at 0x44b9a0, by name (-- UNKNOWN -- for an unnamed one). Its help text (0x442bd0):

Stop Sounds   Play/Pause:            (P, 0x1000000)
Play Sound    Left Shift,A,B,C:
SFX Info      Right Shift
Exit          X:                     (0x800000)

These are the 3DO pad's names, which supports the reading in Step 4. SFX Info is FUN_00405c10. It shows the cue's Pri, PriTime, Freq, Gain and BandWidth and edits them in memory: Left/Right adjust, A restores, C changes the step, Right Shift keeps the change, X cancels. Its only calls are drawing, input and sound playing (0x406220, 0x41e6e0, 0x4232d0, ...). Nothing writes a file, so the edits last until the game quits. On the PC, "Stop Sounds" (P) and "Exit" (X) can't be pressed either. The only way out of the sound test is to quit the game.

FUN_004070a0: the average frame time

This runs when Debug_DisplayFPS is above 1, which the menu's max of 1 never allows (the 3DO also has a DisplayAvgFPS). It times frames with timeGetTime and keeps three averages in milliseconds per frame, 16.16: since it was switched on, over the last 10 frames, and over the last 60. FUN_00406eb0 draws them at y = 168 plus one and two HUD-digit heights (cel 2146's height, +0x40 of CCB 2146). That is the caller of the cel 2141 shift entry in document 131. It is dead code in the retail game.

Building it as a tool

Nothing above changes the answer. The debug screen, the sound test and the frame counter are not PC behaviour, so they stay out of parity. A port version, as a developer overlay on a key of our own, is issue #110, labelled optional.

Next: back to the issues list.

Clone this wiki locally