; =====================================================================
; MathROM-EVAL r001g - MATH_CORDIC_GET archived table accessor.
; Reads original table bytes copied with explicit owner approval into
; lib/math/math_cordic_table.inc (154 bytes / 22 historical records).
; NOT a ROM-bank probe, live-card read, or CORDIC algorithm.
; Input: $10 = RAM pointer to little-endian unsigned index (0..21)
;        $12 = RAM pointer to seven-byte output buffer (UA=&H14).
; Output: $0=0 success, 1 out-of-range index. Bad index writes nothing.
; Clobber: $0, $4..$9, $16, $20..$22, IX, IZ, flags; UA=14.
; Precondition: SX=0, SY=1; valid ROM mapping for own app and RAM.
; Source table is read-only and explicitly labelled archived data.
; =====================================================================
MATH_CORDIC_GET:
        PST     UA,&H14
        PRE     IX,$10
        LDW     $20,(IX+$SX)
        AN      $21,$21
        JP      NZ,MCG_BAD_INDEX
        LD      $22,$20
        SBC     $22,22
        JP      NC,MCG_BAD_INDEX
; Derive address from this ROM's own table label, not historic bank offset.
        LDW     $8,MCT_DATA
MCG_ADVANCE:
        AN      $20,$20
        JR      Z,MCG_COPY
        LDW     $4,7
        ADW     $8,$4
        SB      $20,$SY
        JR      MCG_ADVANCE
MCG_COPY:
        PRE     IZ,$8
        PRE     IX,$12
        LD      $22,0
MCG_CLOOP:
        LD      $16,(IZ+$22)
        ST      $16,(IX+$22)
        AD      $22,$SY
        SBC     $22,7
        JR      C,MCG_CLOOP
        LD      $0,0
        RTN
MCG_BAD_INDEX:
        LD      $0,1
        RTN
