
;                                     LOADING CHAR FROM CUSTOM FONT

makeCharPixelsCustom:
    
    addiu sp,sp,-0x18
    move a1,a0
    lui        a0,0x1f80
    ori a0,a0,0x358

    sw ra,0x10(sp)

    li a2,1

    lbu        t2,0xa8(gp)      ;a8(gp) -- color
    move      t0,r4
    lui        v1,0x801f                            ; ;load font addr to r3 (801ef480)
    ori        v1,v1,0xaa00                         ; 
    sll        v0,a1,0x1                            ;  r2 = r5 << 1 (*2)
    addu       v0,v0,a1                             ; r2 += r5 (it. *3)
    sll        v0,v0,0x2                            ; r2 << 2 (*4) (r2 = r5 *12)
    addu       t1,v0,v1    ;t1 = char addr          ; r9 = r2(offs) + r3 (start)
    li         r6,0x6                               ;     r6 = byteslength = 6
    move       v0,r6                                ;    r2 = r6 (counter)
    beq        v0,zero,charLoaded                   ;    if counter=0 then branch
    addiu      r6,r6,-0x1                           ; dec r6
    lui        a3,0x1f80
    ori        a3,a3,0x2e0                    ;       set scratch convert addr r7 = 1f8002e0
CharLoop:
    lhu v1,0x0(t1)                                  ;load upperhalf of char to r3
    nop
    andi       r4,v1,0xf                            ; r4 = r3 & 0f - cutting left semibyte
    srl        v1,v1,0x4                       ;      r3 >> 4
    andi       v0,v1,0xf                       ;      r2 = r3 & 0f
    sll        v0,v0,0x1                     ;        r2 << 1
    addu       v0,v0,a3                     ;         r2 = r2 + to4bitConvertTableAddr (r7)
    lhu        v0,0x0(v0);>DAT_1f8002e0               r2 = *r2(half) pixel pattern
    nop
    mult       v0,t2                        ;         r2*r10. make Color
    sll        r4,r4,0x1                    ;         r4 << 1
    addu       r4,r4,a3                     ;         r4 += r6 counter
    mflo       a1                           ;   load lo to r5
    lhu        v0,0x0(r4);>DAT_1f8002e0               load table+r4
    nop
    mult       v0,t2                            ;    r2 * colorIndex r10
    srl        v1,v1,0x4                    ;         r3 >> 4, right 4 bits
    andi       r4,v1,0xf                    ;         r4 = r3 & f0 (cut right semibyte)
    srl        v1,v1,0x4                    ;         r3 >> 4
    sll        v1,v1,0x1                    ;         r3 << 1 = *2
    addu       v1,v1,a3                     ;         r3=r3+Table r7
    sll        v0,a1,0x10                   ;   r2 = r5 << 10 bits
    mflo       t4                           ;         load r12,low
    or         v0,t4,v0                     ;         r2 = r12 | r2
    sw         v0,0x0(t0)                   ;         load *r8(current Scratch) from r2(result)
    lhu        v0,0x0(v1);>DAT_1f8002e0     ;         load r2 from TablePattern Half from r3
    nop
    mult       v0,t2                        ;         r2*color r10
    sll        r4,r4,0x1                    ;         r4 << 1
    addu       r4,r4,a3                     ;         r4 = r4 + TableStart
    mflo       a1                           ;         ld r5,lo
    lhu        v0,0x0(r4);>DAT_1f8002e0     ;         ld half r2 from *r4
    nop
    mult       v0,t2                        ;         r2*col
    addiu      t1,t1,0x2                    ;         move charFont + +2
    move       v1,a2                        ;         r3 = byteCount (r6)
    addiu      a2,a2,-0x1                   ;         r6 -= 1
    addiu      t0,t0,0x4                    ;         scrathAddr r8 += 4
    sll        v0,a1,0x10                   ;         r2 = r5 << 10 bits (move to hi)
    mflo       t4                           ;         ld r12,lo (result)
    or         v0,t4,v0                     ;         combine r2 & r 12 (0001 x 1111)
    sw         v0,0x0(t0)                   ;         store result to scratch r2 to *r8
    bne        v1,zero,charLoop             ;        if r3 counter<>0 goto loop
    addiu     t0,t0,0x4                     ;        r8 scrath += 4
charLoaded:

    lbu         v1, 0xa9(gp)                 ;                a9(gp) -- shadow
    li          v0, 0x1
    bne         v1, v0, NotShadow                     ;Shadow character check 
    nop
    lui         a0,0x1f80
    jal         MakeShadowSmallChar                 ;Make shadow in Scratch DMA
    ori         a0,a0,0x358

NotShadow:
    lw          ra,0x10(sp)                          ;Restore stack and exit
    nop
    jr          ra
    addiu       sp, sp, 0x18