User:Kmeisthax/Findings/2011/6/6/ROM B 79C1 Disassembly: Difference between revisions

From Wikifang, a definitive guide to Telefang, Dino Device and Bugsite
Jump to navigation Jump to search
(Created page with "This routine seems to render all the "status screen VWF" text, as opposed to the "main script" text or the "intro scene" text, the latter of which is still not spaced properly. ...")
 
No edit summary
Line 1: Line 1:
This routine seems to render all the "status screen VWF" text, as opposed to the "main script" text or the "intro scene" text, the latter of which is still not spaced properly.
This routine seems to render all the "status screen VWF" text, as opposed to the "main script" text or the "intro scene" text, the latter of which is still not spaced properly.
WARNING: This disassembly is inaccurate as of v63, which changes the core VWF routine.


     ;A big note: First off, there are a bunch of STATUS BYTES
     ;A big note: First off, there are a bunch of STATUS BYTES

Revision as of 16:27, 8 June 2011

This routine seems to render all the "status screen VWF" text, as opposed to the "main script" text or the "intro scene" text, the latter of which is still not spaced properly.

WARNING: This disassembly is inaccurate as of v63, which changes the core VWF routine.

   ;A big note: First off, there are a bunch of STATUS BYTES
   ;that live in Work RAM that control what the VWF does.
   ;They live at WRAM C7C1 to C7C6, as follows:
   ; WRAM_Text_CurrentLetter
   ; WRAM_VWFLetterShift
   ; WRAM_SPILL_GlyphDrawPtr0
   ; WRAM_SPILL_GlyphDrawPtr1
   ; WRAM_Text_OldTileMode
   ; WRAM_MyMisteryBite
   
   ; Theres also a byte at C9CB which I think is also VWF related,
   ; I named it WRAM_VWFGlyphsToNewline in this disassembly.
   
   ROM:0002F9C1 PhoneNumGetSCR_DrawDenjuuName:          ; Routine which draws denjuu name tiles to vram
   ROM:0002F9C1                 ld      a, [WRAM_MyMisteryBite] ; in the "you got a phone number" screen
   ROM:0002F9C1                                         ;
   ROM:0002F9C1                                         ; PARAMS:
   ROM:0002F9C1                                         ; HL - the address of the target VRAM glyph
   ROM:0002F9C1                                         ; DE - the address of the source 1bpp letter
   ROM:0002F9C4                 cp      1
   ROM:0002F9C6                 jr      nz, loc_2f9d3   ; if the mystery byte is 1, don't move HL back
   ROM:0002F9C8                 ld      a, [WRAM_VWFGlyphsToNewline]
   ROM:0002F9CB                 dec     a
   ROM:0002F9CC                 ld      [WRAM_VWFGlyphsToNewline], a
   ROM:0002F9CF                 ld      bc, $FFF0       ; -F
   ROM:0002F9D2                 add     hl, bc
   ROM:0002F9D3
   ROM:0002F9D3 loc_2F9D3:                              ; DATA XREF: ROM:0002F9C6�t
   ROM:0002F9D3                 ld      b, 8
   ROM:0002F9D5                 ld      a, $CF ; '-'
   ROM:0002F9D7                 ld      [WRAM_SPILL_GlyphDrawPtr0], a
   ROM:0002F9DA                 ld      a, $D0 ; '-'
   ROM:0002F9DC                 ld      [WRAM_SPILL_GlyphDrawPtr1], a ; CFD0 - Appears to be a temporary space for
   ROM:0002F9DC                                         ; glyph composing
   ROM:0002F9DF
   ROM:0002F9DF GlyphDrawLoop:                          ; DATA XREF: ROM:0002FA40�t
   ROM:0002F9DF                 push    bc
   ROM:0002F9E0                 push    de
   ROM:0002F9E1                 push    hl
   ROM:0002F9E2                 di
   ROM:0002F9E3                 ld      a, [WRAM_SPILL_GlyphDrawPtr0]
   ROM:0002F9E6                 ld      h, a
   ROM:0002F9E7                 ld      a, [WRAM_SPILL_GlyphDrawPtr1] ; HL = 0xCFD0
   ROM:0002F9EA                 ld      l, a
   ROM:0002F9EB                 ld      b, [hl]
   ROM:0002F9EC                 inc     hl
   ROM:0002F9ED                 ld      c, [hl]         ; BC is the old tile's line that we are
   ROM:0002F9ED                                         ; going to superimpose/clear/etc.
   ROM:0002F9EE                 dec     hl
   ROM:0002F9EF                 ld      a, [de]         ; DE is the 1BPP glyph we plan to draw.
   ROM:0002F9EF                                         ; It's an input parameter.
   ROM:0002F9F0                 ld      d, a
   ROM:0002F9F1                 ld      e, 0            ; Expand our 1BPP glyph into a 2BPP one
   ROM:0002F9F3                 ld      a, [WRAM_Text_OldTileMode] ; Selects an operation to be performed
   ROM:0002F9F3                                         ; on the existing line before mixing.
   ROM:0002F9F6                 cp      2
   ROM:0002F9F8                 jr      z, loc_2fa00    ; Mode 2
   ROM:0002F9F8                                         ; This clears the tile.
   ROM:0002F9FA                 cp      1
   ROM:0002F9FC                 jr      z, loc_2fa02    ; Mode 1
   ROM:0002F9FC                                         ;
   ROM:0002F9FC                                         ; This makes the tile black and white
   ROM:0002F9FC                                         ; and then superimposes the glyph onto the tile.
   ROM:0002F9FC                                         ;
   ROM:0002F9FC                                         ; This also is only usually set when we need to move
   ROM:0002F9FC                                         ; the glyph frame up.
   ROM:0002F9FE                 jr      loc_2fa03       ; Mode 0 (or other modes)
   ROM:0002F9FE                                         ; Superimpose the glyph onto the current tile.
   ROM:0002F9FE                                         ;
   ROM:0002F9FE                                         ; This is set during normal VWF operation, when
   ROM:0002F9FE                                         ; we don't need to move to the next tile yet.
   ROM:0002FA00 ; ---------------------------------------------------------------------------
   ROM:0002FA00
   ROM:0002FA00 loc_2FA00:                              ; DATA XREF: ROM:0002F9F8�t
   ROM:0002FA00                 ld      c, 0
   ROM:0002FA02
   ROM:0002FA02 loc_2FA02:                              ; DATA XREF: ROM:0002F9FC�t
   ROM:0002FA02                 ld      b, c
   ROM:0002FA03
   ROM:0002FA03 loc_2FA03:                              ; DATA XREF: ROM:0002F9FE�t
   ROM:0002FA03                 ld      a, [WRAM_VWFLetterShift] ; VWF shift value
   ROM:0002FA03                                         ; (verified by tracing the main script)
   ROM:0002FA06                 or      a
   ROM:0002FA07                 jr      z, loc_2fa10
   ROM:0002FA09
   ROM:0002FA09 loc_2FA09:                              ; DATA XREF: ROM:0002FA0E�t
   ROM:0002FA09                 srl     d
   ROM:0002FA0B                 rr      e
   ROM:0002FA0D                 dec     a
   ROM:0002FA0E                 jr      nz, loc_2fa09   ; Shift the incoming glyph by the current
   ROM:0002FA0E                                         ; letter shift value, if needed.
   ROM:0002FA0E                                         ;
   ROM:0002FA0E                                         ; It's a right shift for positive values
   ROM:0002FA10
   ROM:0002FA10 loc_2FA10:                              ; DATA XREF: ROM:0002FA07�t
   ROM:0002FA10                 ld      a, d
   ROM:0002FA11                 or      b
   ROM:0002FA12                 ld      b, a
   ROM:0002FA13                 ld      c, e            ; BC = (B|D) << 8 + E
   ROM:0002FA13                                         ;
   ROM:0002FA13                                         ; Mix the lower bits of the tile,
   ROM:0002FA13                                         ; but overwrite the upper bits.
   ROM:0002FA13                                         ;
   ROM:0002FA13                                         ; E is 0, so this forcibly clears
   ROM:0002FA13                                         ; all upper pallete bits.
   ROM:0002FA13                                         ;
   ROM:0002FA13                                         ; BUG: If we shift a letter, it will
   ROM:0002FA13                                         ; get shifted onto E and that's a problem
   ROM:0002FA14                 ld      [hl], b
   ROM:0002FA15                 inc     hl
   ROM:0002FA16                 ld      [hl], c
   ROM:0002FA17                 inc     hl              ; Write into our temporary glyph area.
   ROM:0002FA18                 ld      a, h
   ROM:0002FA19                 ld      [WRAM_SPILL_GlyphDrawPtr0], a
   ROM:0002FA1C                 ld      a, l
   ROM:0002FA1D                 ld      [WRAM_SPILL_GlyphDrawPtr1], a
   ROM:0002FA20                 pop     hl              ; Restore the glyph target address
   ROM:0002FA21                 ld      d, h
   ROM:0002FA22                 ld      e, l
   ROM:0002FA23                 ld      a, [byte_FF41]  ; LCD STAT
   ROM:0002FA25                 and     2
   ROM:0002FA27                 jr      nz, 2fa23       ; loop until it's safe to write
   ROM:0002FA29                 ld      a, b
   ROM:0002FA2A                 ldi     [hl], a
   ROM:0002FA2B                 ldi     [hl], a         ; Now, write into VRAM...
   ROM:0002FA2C                 push    hl
   ROM:0002FA2D                 ld      hl, $10
   ROM:0002FA30                 add     hl, de
   ROM:0002FA31                 ld      a, [byte_FF41]
   ROM:0002FA33                 and     2
   ROM:0002FA35                 jr      nz, 2fa31       ; loop until it's safe to write
   ROM:0002FA37                 ld      a, c
   ROM:0002FA38                 ldi     [hl], a
   ROM:0002FA39                 ldi     [hl], a         ; Write C into 16 bytes forward on VRAM for some reason
   ROM:0002FA39                                         ; (i.e. the next glyph)
   ROM:0002FA3A                 ei
   ROM:0002FA3B                 pop     hl
   ROM:0002FA3C                 pop     de
   ROM:0002FA3D                 pop     bc
   ROM:0002FA3E                 inc     de              ; go to the next line
   ROM:0002FA3F                 dec     b
   ROM:0002FA40                 jr      nz, GlyphDrawLoop
   ROM:0002FA42                 ld      a, 0
   ROM:0002FA44                 ld      [WRAM_Text_OldTileMode], a
   ROM:0002FA47                 ld      b, $7B ; '{'
   ROM:0002FA49                 ld      a, [WRAM_Text_CurrentLetter]
   ROM:0002FA4C                 ld      c, a
   ROM:0002FA4D                 ld      a, [bc]         ; Letter glyph width table?
   ROM:0002FA4D                                         ;
   ROM:0002FA4D                                         ; Seems to index 0x2FB00 with the current glyph ID?
   ROM:0002FA4E                 inc     a
   ROM:0002FA4F                 ld      b, a
   ROM:0002FA50                 ld      a, [WRAM_VWFLetterShift]
   ROM:0002FA53                 add     a, b
   ROM:0002FA54                 bit     3, a
   ROM:0002FA56                 jr      z, 2FA71        ; following code only execs
   ROM:0002FA56                                         ; on text frame overflow
   ROM:0002FA58                 sub     8
   ROM:0002FA5A                 push    af
   ROM:0002FA5B                 ld      a, 1
   ROM:0002FA5D                 ld      [WRAM_Text_OldTileMode], a
   ROM:0002FA60                 ld      a, [WRAM_MyMisteryBite]
   ROM:0002FA63                 cp      1
   ROM:0002FA65                 jr      nz, 2FA6C
   ROM:0002FA67                 ld      a, 0
   ROM:0002FA69                 ld      [WRAM_MyMisteryBite], a ; if the mystery byte is 1, make it 0
   ROM:0002FA69                                         ; some kinda sentinel?
   ROM:0002FA6C
   ROM:0002FA6C GlyphFinished:
   ROM:0002FA6C                 pop     af
   ROM:0002FA6D                 ld      [WRAM_VWFLetterShift], a
   ROM:0002FA70                 ret
   ROM:0002FA71 ; ---------------------------------------------------------------------------
   ROM:0002FA71                 push    af
   ROM:0002FA72                 ld      a, [WRAM_VWFGlyphsToNewline]
   ROM:0002FA75                 cp      $10
   ROM:0002FA77                 jr      z, 2FA7F
   ROM:0002FA79                 dec     a
   ROM:0002FA7A                 ld      [WRAM_VWFGlyphsToNewline], a
   ROM:0002FA7D                 jr      2FA6C
   ROM:0002FA7F ; ---------------------------------------------------------------------------
   ROM:0002FA7F                 ld      a, 1
   ROM:0002FA81                 ld      [WRAM_MyMisteryBite], a
   ROM:0002FA84                 jr      2FA6C