; Platform/2 ROM identity classifier, x0.26c gated-map candidate.
; No UART use. Temporarily DISABLE ROM2 card overlay via gate array 0C10.
; Card maps over onboard C-ROM while gate config=03; config=00 exposes C.
; Both outcomes restore app card config=03; do not call from other ROM maps.
; Running copy is in RAM bank 1 throughout; PC and stack remain bank 1.
; UA=45 for IX direct access to gate array 0C10, UA=15 for IZ C-ROM.
; Fail closed unless all 18 C-ROM bytes match; emulator-first candidate.
; $0: 1 full match, 0 deny. On deny $1=first failing byte 1..18,
; $2=actual byte, $3=expected byte; match returns $1=0.
; DIAGNOSTIC ONLY; non-UART read, IZ/flags and $1..$3 clobbered.
; Saves/restores caller UA, $20, $6, $7; clobbers IZ and flags.
;
PLAT_ROM_ID:
        PHS     $20
        GST     UA,$20
        PHS     $6
        PHS     $7
; Copy is executing in RAM bank 1. Gate register access uses bank 0.
; This follows the same 0C10 = 00 / 03 switching as the SYSCAL bridge.
        PST     UA,&H45
        LDW     $6,&H0C10
        LD      $0,0
        ST      $0,($6)
; With the ROM2 overlay disabled, bank 0 selects onboard OM52C C-ROM.
        PST     UA,&H15
; Onboard C-ROM identity at 0DB9..0DBA (never Apple card ROM2).
        PRE     IZ,&H0DB9
        LD      $1,1   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&HD4
        SBC     $2,&HD4
        JP      NZ,PRI_UNKNOWN
        LD      $1,2   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H12
        SBC     $2,&H12
        JP      NZ,PRI_UNKNOWN
; Independent OM52C transmit wrapper signature (8 bytes).
        PRE     IZ,&H3C8B
        LD      $1,3   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H77
        SBC     $2,&H77
        JP      NZ,PRI_UNKNOWN
        LD      $1,4   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H48
        SBC     $2,&H48
        JP      NZ,PRI_UNKNOWN
        LD      $1,5   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H3C
        SBC     $2,&H3C
        JP      NZ,PRI_UNKNOWN
        LD      $1,6   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H77
        SBC     $2,&H77
        JP      NZ,PRI_UNKNOWN
        LD      $1,7   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&HBE
        SBC     $2,&HBE
        JP      NZ,PRI_UNKNOWN
        LD      $1,8   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H3C
        SBC     $2,&H3C
        JP      NZ,PRI_UNKNOWN
        LD      $1,9   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&HB7
        SBC     $2,&HB7
        JP      NZ,PRI_UNKNOWN
        LD      $1,10   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&HD2
        SBC     $2,&HD2
        JP      NZ,PRI_UNKNOWN
; Independent OM52C open service fingerprint (8 bytes).
        PRE     IZ,&H3BCC
        LD      $1,11   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H02
        SBC     $2,&H02
        JP      NZ,PRI_UNKNOWN
        LD      $1,12   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H64
        SBC     $2,&H64
        JP      NZ,PRI_UNKNOWN
        LD      $1,13   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H0B
        SBC     $2,&H0B
        JP      NZ,PRI_UNKNOWN
        LD      $1,14   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H4C
        SBC     $2,&H4C
        JP      NZ,PRI_UNKNOWN
        LD      $1,15   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H04
        SBC     $2,&H04
        JP      NZ,PRI_UNKNOWN
        LD      $1,16   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&HE8
        SBC     $2,&HE8
        JP      NZ,PRI_UNKNOWN
        LD      $1,17   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H49
        SBC     $2,&H49
        JP      NZ,PRI_UNKNOWN
        LD      $1,18   ; 1-based identity probe byte
        LDI     $2,(IZ+$SX)
        LD      $3,&H04
        SBC     $2,&H04
        JP      NZ,PRI_UNKNOWN
; A match only identifies an experimental candidate backend.
PRI_MATCH:
; Restore card mapping before returning to viewer or serial facade.
        PST     UA,&H45
        LDW     $6,&H0C10
        LD      $0,3
        ST      $0,($6)
        PST     UA,$20
        PPS     $7
        PPS     $6
        PPS     $20
        LD      $1,0
        LD      $0,1
        RTN
PRI_UNKNOWN:
; Same restoration on the first mismatching signature byte.
        PST     UA,&H45
        LDW     $6,&H0C10
        LD      $0,3
        ST      $0,($6)
        PST     UA,$20
        PPS     $7
        PPS     $6
        PPS     $20
        LD      $0,0
        RTN
; end of include
