User:Kmeisthax/Findings/2011/6/10/ROM 34 7F40 Disassembly

From Wikifang, a definitive guide to Telefang, Dino Device and Bugsite
Jump to: navigation, search

Notes for the Text Center Fix

ROM 34:7F69 (from a trace) appears to be called from 00DA. The routine's entrypoint is thus ROM 34:7F40 (from disasm). This copies the Denjuu name into RAM. Here's a disassembly:

   ROM:000D3F40 ; ---------------------------------------------------------------------------
   ROM:000D3F40                 push    hl
   ROM:000D3F41                 push    de
   ROM:000D3F42                 ld      c, $10
   ROM:000D3F44                 ld      a, 0
   ROM:000D3F46                 ld      [de], a
   ROM:000D3F47                 inc     de
   ROM:000D3F48                 dec     c
   ROM:000D3F49                 jr      nz, D3F46       ; Clear the whole area
   ROM:000D3F4B                 pop     de
   ROM:000D3F4C                 ld      c, $11
   ROM:000D3F4E                 dec     c
   ROM:000D3F4F                 jr      z, D3F63
   ROM:000D3F51                 ldi     a, [hl]
   ROM:000D3F52                 cp      $E0 ; 'a'
   ROM:000D3F54                 jr      nz, D3F4E       ; Count how many bytes are unused in the string.
   ROM:000D3F56                 srl     c
   ROM:000D3F58                 srl     c
   ROM:000D3F5A                 ld      a, c
   ROM:000D3F5B                 or      a
   ROM:000D3F5C                 jr      z, D3F65        ; floor(C/4).
   ROM:000D3F5E                 ld      a, 0
   ROM:000D3F60                 ld      [de], a
   ROM:000D3F61                 inc     de
   ROM:000D3F62                 dec     c
   ROM:000D3F63                 jr      nz, D3F60       ; This inserts blank spaces in the string,
   ROM:000D3F63                                         ; one for every four characters between the string
   ROM:000D3F63                                         ; and the end of the temporary area.
   ROM:000D3F65                 pop     hl
   ROM:000D3F66                 ld      c, $10
   ROM:000D3F68                 ldi     a, [hl]
   ROM:000D3F69                 ld      [de], a
   ROM:000D3F6A                 dec     c
   ROM:000D3F6B                 ret     z
   ROM:000D3F6C                 inc     de
   ROM:000D3F6D                 cp      $E0 ; 'a'
   ROM:000D3F6F                 jr      nz, D3F68       ; copy the text bytes
   ROM:000D3F71                 ld      a, 0
   ROM:000D3F73                 ld      [de], a         ; null terminate the rest of the string
   ROM:000D3F74                 inc     de
   ROM:000D3F75                 dec     c
   ROM:000D3F76                 jr      nz, D3F73
   ROM:000D3F78                 ret
   ROM:000D3F78 ; ---------------------------------------------------------------------------

Some interesting things to note:

The routine is actually written to center 8 tile wide lines. It counts how many letters are unused in the temporary line storage area [de] and divides it by four to get how many spaces should be added. Normally two would suffice, but it's four, specifically because the line storage is twice as wide as the status line items loaded this way.