# Element type for DAT_ symbols where the decompiled C does not say.
#
# WHY THIS FILE EXISTS. gen_dat_perfile.py shapes every symbol from the text of
# the C, and recovers a pointer's element type when Ghidra declares a local of
# the right type and assigns the symbol to it. Some symbols are used directly,
# with no local to read, and then the element type is invisible in the text -
# while still deciding what pointer arithmetic means.
#
# Ghidra cannot be asked either: DumpDataTypes.java reports the stored type for
# these as plain undefined4, because the pointer type exists only inside the
# decompiler's per-function inference and is not written back to the listing.
#
# So each line here is backed by the INSTRUCTIONS, recorded in the comment above
# it. The general fix is to read the access width off the disassembly for every
# symbol; until that exists, this is the auditable short list.
#
# Format:  SYMBOL <space> ELEMENT-TYPE

# 0x020D1334 holds 0x04000184, IPCFIFOCNT. FUN_020D12B0 accesses it as a
# halfword and writes the FIFO one halfword-pair further on:
#
#   020D12B8  LDR  r3,[pc] -> 0x04000184
#   020D12C8  LDRH r0,[r3,#0x0]        ; the control register is 16-bit
#   020D12F8  STRH r1,[r3,#0x0]
#   020D1324  STR  r1,[r2,#0x4]        ; IPCFIFOSEND at 0x04000188
#
# so `DAT_020d1334 + 2` is +4 bytes. Shaped as undefined4 it was +8, and the
# ARM9's message to the ARM7 went to 0x0400018C - a register nothing reads. The
# ARM9 then waited forever for a reply that could not be sent.
DAT_020d1334 undefined2

# 0x020D6174 holds 0x027FFC10, in the DS system region. FUN_020D6118 is the
# card-removal check: it re-reads the cartridge chip ID and compares it against
# the copy the firmware left in RAM, choosing which copy by a halfword flag.
#
#   020D6120  E59F204C  LDR   r2,[pc] -> 0x027FFC10
#   020D6124  E1D210B0  LDRH  r1,[r2,#0x0]   ; HALFWORD - so the element is 2
#   020D6128  E3510000  CMP   r1,#0x0
#   020D612C  02421E41  SUBEQ r1,r2,#0x410   ; -0x410 BYTES -> 0x027FF800
#   020D6130  12421010  SUBNE r1,r2,#0x10    ; -0x10  BYTES -> 0x027FFC00
#   020D6134  E5911000  LDR   r1,[r1,#0x0]
#   020D6140  E1500001  CMP   r0,r1
#   020D6148  08BD8018  LDMEQIA r13!,{r3,r4,pc}   ; equal -> return
#
# Ghidra's C says `+ -0x208` and `+ -8`, which are correct AS ELEMENT COUNTS for
# a 2-byte element: -0x208 * 2 = -0x410 and -8 * 2 = -0x10. Shaped as undefined4
# they became -0x820 and -0x20, so the check read 0x027FF3F0 - unwritten memory,
# nowhere near a chip ID - found zero, disagreed with the cartridge, and shut
# the console down exactly as it would for a card swapped mid-play.
#
# Publishing the chip ID at both 0x027FF800 and 0x027FFC00 was necessary and on
# its own did nothing, because the address being read was neither of them.
DAT_020d6174 undefined2
