#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA571_F20J_X30J_P20JA_P20JB_F31J_X31J_P31J
static BOOLEAN F0818_IsJapaneseText(
REGISTER unsigned char* P2189_pc_String
);
#endif

#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
unsigned char* F0643_BuildCustomColorsFont( /* ANOMALY_FMT Parameters declared as int required for call in F0644_ but actually parameters are int16_t */
int P2180_i_TextColor       SEPARATOR
int P2181_i_BackgroundColor
);
#endif

#ifdef MEDIA591_X30J_P20JA_P20JB_I34E_I34M_X31J_P31J
#include "FONT.C"
#endif

void F0644_PrintTextAlt(
unsigned char* P2182_puc_Bitmap         SEPARATOR
int16_t        P2183_i_DestinationWidth SEPARATOR
int16_t        P2184_i_X                SEPARATOR
int16_t        P2185_i_Y                SEPARATOR
int16_t        P2186_i_TextColor        SEPARATOR
int16_t        P2187_i_BackgroundColor  SEPARATOR
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
REGISTER char* P2188_pc_String          FINAL_SEPARATOR
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
char*          P2188_pc_String          SEPARATOR
int16_t        P2755_i_Height           FINAL_SEPARATOR
#endif
{
#ifdef MEDIA525_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_F31E_F31J_X31J_P31J
        int16_t L3487_i_FontX;
        unsigned char* L3488_puc_Bitmap;
#ifdef MEDIA608_X30J_I34E_I34M_F31E_F31J_X31J_P31J
        int16_t L3489_i_TransparentColor;
#endif
        int16_t L3490_ai_XYZ[4];
#ifdef MEDIA571_F20J_X30J_P20JA_P20JB_F31J_X31J_P31J
        REGISTER int16_t L3495_i_;
        REGISTER unsigned char* L3491_puc_;
#endif
#ifdef MEDIA572_F20J_X30J_P20JA_P20JB_X31J
        long L3492_l_ByteCount;
#endif
#ifdef MEDIA571_F20J_X30J_P20JA_P20JB_F31J_X31J_P31J
        int16_t L3493_i_Width;
        int16_t L3494_i_Height;
#endif
#ifdef MEDIA489_F20E_F20J_P20JA_P20JB
        int16_t L3489_i_TransparentColor;
#endif


        if (!*P2188_pc_String) {
                return;
        }
#ifdef MEDIA608_X30J_I34E_I34M_F31E_F31J_X31J_P31J
        if (M007_GET(P2187_i_BackgroundColor, MASK0x4000_TRANSPARENT)) {
                L3489_i_TransparentColor = M009_CLEAR(P2187_i_BackgroundColor, MASK0x4000_TRANSPARENT);
        } else {
                L3489_i_TransparentColor = CM1_COLOR_NO_TRANSPARENCY;
        }
#endif
        M704_ZONE_LEFT(L3490_ai_XYZ) = P2184_i_X;
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
        M707_ZONE_BOTTOM(L3490_ai_XYZ) = P2185_i_Y;
#endif
#ifdef MEDIA571_F20J_X30J_P20JA_P20JB_F31J_X31J_P31J
        if (F0818_IsJapaneseText(M774_CAST_PUC(P2188_pc_String))) {
#endif
#ifdef MEDIA569_F20J_X30J_P20JA_P20JB
                M706_ZONE_TOP(L3490_ai_XYZ) = M707_ZONE_BOTTOM(L3490_ai_XYZ) - (G2338_i_JapaneseCharacterMaximumHeight - G2341_);
                L3491_puc_ = F0468_MEMORY_Allocate(L3492_l_ByteCount = M103_BITMAP_BYTE_COUNT(G2337_i_JapaneseCharacterMaximumWidth, G2338_i_JapaneseCharacterMaximumHeight), MASK0x8000_ALLOCATE_BITMAP | C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
                M100_PIXEL_WIDTH(L3491_puc_) = G2337_i_JapaneseCharacterMaximumWidth;
                M101_PIXEL_HEIGHT(L3491_puc_) = G2338_i_JapaneseCharacterMaximumHeight;
                L3495_i_ = 0;
#ifdef MEDIA565_F20J_P20JA_P20JB
                if (M007_GET(P2187_i_BackgroundColor, MASK0x4000_TRANSPARENT)) {
                        P2187_i_BackgroundColor = L3489_i_TransparentColor = P2187_i_BackgroundColor & (~MASK0x4000_TRANSPARENT);
                } else {
                        L3489_i_TransparentColor = CM1_COLOR_NO_TRANSPARENCY;
                }
#endif
                while (P2188_pc_String[L3495_i_] != '\0') {
                        L3495_i_ = F0952_JAPANESE_Print(M774_CAST_PUC(P2188_pc_String), L3495_i_, M772_CAST_PC(L3491_puc_), &L3493_i_Width, &L3494_i_Height, P2186_i_TextColor, P2187_i_BackgroundColor);
                        if (L3493_i_Width) {
                                M705_ZONE_RIGHT(L3490_ai_XYZ) = M704_ZONE_LEFT(L3490_ai_XYZ) + L3493_i_Width - 1;
#ifdef MEDIA458_P20JA_P20JB
                                F0132_VIDEO_Blit(L3491_puc_, P2182_puc_Bitmap, L3490_ai_XYZ, 0, 0, G2337_i_JapaneseCharacterMaximumWidth, P2183_i_DestinationWidth, L3489_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA567_F20J_X30J
                                F0132_VIDEO_Blit(L3491_puc_, P2182_puc_Bitmap, L3490_ai_XYZ, 0, 0, G2337_i_JapaneseCharacterMaximumWidth, P2183_i_DestinationWidth, L3489_i_TransparentColor);
#endif
                                M704_ZONE_LEFT(L3490_ai_XYZ) += L3493_i_Width + G2339_;
                        }
                }
                F0469_MEMORY_FreeAtHeapTop(L3492_l_ByteCount + 4);
        } else {
#endif
#ifdef MEDIA689_F31J_X31J_P31J
                M709_ZONE_HEIGHT(L3490_ai_XYZ) = G2338_i_JapaneseCharacterMaximumHeight;
                M706_ZONE_TOP(L3490_ai_XYZ) = P2185_i_Y + G2341_ - (M709_ZONE_HEIGHT(L3490_ai_XYZ) - 1);
                L3491_puc_ = F0606_AllocateMemForGraphic(G2337_i_JapaneseCharacterMaximumWidth, G2338_i_JapaneseCharacterMaximumHeight, C0_ALLOCATION_TEMPORARY_ON_TOP_OF_HEAP);
                L3495_i_ = 0;
                while (P2188_pc_String[L3495_i_] != '\0') {
                        L3495_i_ = F0952_JAPANESE_Print(M774_CAST_PUC(P2188_pc_String), L3495_i_, M772_CAST_PC(L3491_puc_), &L3493_i_Width, &L3494_i_Height, P2186_i_TextColor, P2187_i_BackgroundColor);
                        if (L3493_i_Width) {
                                M708_ZONE_WIDTH(L3490_ai_XYZ) = L3493_i_Width;
#ifdef MEDIA667_P31J
                                F0132_VIDEO_Blit(L3491_puc_, P2182_puc_Bitmap, L3490_ai_XYZ, 0, 0, G2337_i_JapaneseCharacterMaximumWidth, P2183_i_DestinationWidth, L3489_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA688_F31J_X31J
                                F0132_VIDEO_Blit(L3491_puc_, P2182_puc_Bitmap, L3490_ai_XYZ, 0, 0, G2337_i_JapaneseCharacterMaximumWidth, P2183_i_DestinationWidth, L3489_i_TransparentColor);
#endif
                                M704_ZONE_LEFT(L3490_ai_XYZ) += L3493_i_Width + G2339_;
                        }
                }
                F0607_FreeMemForGraphic(L3491_puc_);
        } else {
#endif
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                M707_ZONE_BOTTOM(L3490_ai_XYZ) += G2086_C1_;
                M706_ZONE_TOP(L3490_ai_XYZ) = M707_ZONE_BOTTOM(L3490_ai_XYZ) - (G2083_C6_ - G2086_C1_);
#endif
#ifdef MEDIA713_I34E_I34M_F31E_F31J_X31J_P31J
                M709_ZONE_HEIGHT(L3490_ai_XYZ) = G2083_C6_;
                M706_ZONE_TOP(L3490_ai_XYZ) = P2185_i_Y + G2086_C1_ - (M709_ZONE_HEIGHT(L3490_ai_XYZ) - 1);
                M708_ZONE_WIDTH(L3490_ai_XYZ) = G2087_C6_TextCharacterWidth;
#endif
                L3488_puc_Bitmap = F0643_BuildCustomColorsFont(P2186_i_TextColor, P2187_i_BackgroundColor);
                do {
                        L3487_i_FontX = (*((unsigned char*)P2188_pc_String) * 8) + (8 - G2082_);
#ifdef MEDIA508_F20E_F20J_X30J_P20JA_P20JB
                        M705_ZONE_RIGHT(L3490_ai_XYZ) = M704_ZONE_LEFT(L3490_ai_XYZ) + G2082_;
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
                        F0132_VIDEO_Blit(L3488_puc_Bitmap, P2182_puc_Bitmap, L3490_ai_XYZ, L3487_i_FontX, 0, C1024_WIDTH, P2183_i_DestinationWidth, CM1_COLOR_NO_TRANSPARENCY, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA543_F20E_F20J_X30J_F31E_F31J_X31J
                        F0132_VIDEO_Blit(L3488_puc_Bitmap, P2182_puc_Bitmap, L3490_ai_XYZ, L3487_i_FontX, 0, C1024_WIDTH, P2183_i_DestinationWidth, CM1_COLOR_NO_TRANSPARENCY);
#endif
                        M704_ZONE_LEFT(L3490_ai_XYZ) += G2087_C6_TextCharacterWidth;
                        P2188_pc_String++;
                } while (*P2188_pc_String);
#ifdef MEDIA571_F20J_X30J_P20JA_P20JB_F31J_X31J_P31J
        }
#endif
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        if (*P2188_pc_String == '\0') {
                return;
        }
        asm {
                        movem.l d3-d7/a2-a6,-(sp)
                        movea.l P2182_puc_Bitmap(a6),a3
                        move.w  P2184_i_X(a6),d7
                        move.w  P2185_i_Y(a6),d6
                        move.w  P2186_i_TextColor(a6),d5
                        move.w  P2187_i_BackgroundColor(a6),d4
                        moveq   #0,d1
                        move.w  P2183_i_DestinationWidth(a6),d1
                        lsr.w   #3,d1
                        move.w  d1,P2183_i_DestinationWidth(a6)
                        move.w  d6,d0
                        subq.w  #4,d0
                        mulu.w  d1,d0
                        adda.w  d0,a3
                        move.w  d7,d0
                        andi.w  #0xFFF0,d0
                        lsr.w   #3,d0
                        adda.w  d0,a3
                        move.w  d7,d3
                        andi.w  #0xF,d3
                        mulu.w  P2755_i_Height(a6),d1
                        movea.w d1,a4
                        move.w  d5,d1
                        add.w   d5,d5
                        add.w   d1,d5
                        add.w   d5,d5
                        addq.w  #2,d5
                        jmp     (pc,d5.w)
                        lea     @Tloc_3F42,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3EF6,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3EFA,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3EFE,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F02,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F06,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F0C,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F12,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F18,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F1C,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F22,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F28,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F2E,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F32,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F38,a0
                        bra.s   @Tloc_3DC0
                        lea     @Tloc_3F3E,a0
                @Tloc_3DC0:
                        move.w  d4,d1
                        add.w   d4,d4
                        add.w   d1,d4
                        add.w   d4,d4
                        addq.w  #2,d4
                        jmp     (pc,d4.w)
                        lea     @Tloc_3F9A,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F4E,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F52,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F56,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F5A,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F5E,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F64,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F6A,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F70,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F74,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F7A,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F80,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F86,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F8A,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F90,a1
                        bra.s   @Tloc_3E2C
                        lea     @Tloc_3F96,a1
                @Tloc_3E2C:
                        moveq   #0,d2
                        movea.l P2188_pc_String(a6),a2
                        move.b  (a2),d2
                        beq.w   @Tloc_3FC6
                @Tloc_3E38:
                        addq.l  #1,P2188_pc_String(a6)
                        movea.l G0357_puc_InterfaceAndScrollsFont(a5),a2
                        lea     (a2,d2.w),a2
                        cmpi.w  #0xB,d3
                        bhi.s   @Tloc_3E6E
                        moveq   #6,d4
                        move.l  #0x7FF07FF,d2
                        ror.l   d3,d2
                        moveq   #0,d5
                        move.l  a3,-(sp)
                        bsr.w   @Tloc_3EB2
                        movea.l (sp)+,a3
                        addq.w  #6,d3
                        cmpi.w  #0x10,d3
                        bcs.s   @Tloc_3E2C
                        andi.w  #1,d3
                        addq.l  #2,a3
                        bra.s   @Tloc_3E2C
                @Tloc_3E6E:
                        moveq   #6,d4
                        move.l  a3,-(sp)
                        addq.l  #2,(sp)
                        move.l  a2,-(sp)
                        move.l  d3,-(sp)
                        subi.w  #0xC,d3
                        lsl.w   #2,d3
                        lea     G0064_al_Graphic562_PrintTextMasks2(a5),a2
                        move.l  (a2,d3.w),d2
                        lea     G0065_al_Graphic562_PrintTextMasks1(a5),a2
                        move.l  (a2,d3.w),d5
                        move.l  (sp)+,d3
                        movea.l (sp),a2
                        move.l  d5,-(sp)
                        moveq   #8,d5
                        bsr.w   @Tloc_3EB2
                        move.l  (sp)+,d2
                        movea.l (sp)+,a2
                        movea.l (sp),a3
                        moveq   #6,d4
                        moveq   #0x12,d5
                        bsr.w   @Tloc_3EB2
                        movea.l (sp)+,a3
                        subi.w  #0xA,d3
                        bra.w   @Tloc_3E2C
                @Tloc_3EB2:
                        move.l  a3,-(sp)
                        and.w   d2,(a3)
                        adda.l  a4,a3
                        and.w   d2,(a3)
                        adda.l  a4,a3
                        and.w   d2,(a3)
                        adda.l  a4,a3
                        and.w   d2,(a3)
                        movea.l (sp)+,a3
                        moveq   #0,d0
                        move.b  (a2),d0
                        addq.w  #2,d5
                        jmp     (pc,d5.w)
                        moveq   #0xB,d1
                        sub.w   d3,d1
                        lsl.w   d1,d0
                        bra.s   @Tloc_3EE6
                        move.w  d3,d1
                        subi.w  #0xB,d1
                        lsr.w   d1,d0
                        bra.s   @Tloc_3EE6
                        moveq   #0x1B,d1
                        sub.w   d3,d1
                        lsl.w   d1,d0
                @Tloc_3EE6:
                        subq.w  #2,d5
                        move.w  d0,d1
                        swap    d1
                        move.w  d0,d1
                        swap    d0
                        moveq   #0,d6
                        moveq   #0,d7
                        jmp     (a0)
                @Tloc_3EF6:
                        move.l  d0,d6
                        bra.s   @Tloc_3F42
                @Tloc_3EFA:
                        move.w  d1,d6
                        bra.s   @Tloc_3F42
                @Tloc_3EFE:
                        move.l  d1,d6
                        bra.s   @Tloc_3F42
                @Tloc_3F02:
                        move.l  d0,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F06:
                        move.l  d0,d6
                        move.l  d0,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F0C:
                        move.w  d1,d6
                        move.l  d0,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F12:
                        move.l  d1,d6
                        move.l  d0,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F18:
                        move.w  d1,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F1C:
                        move.l  d0,d6
                        move.w  d1,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F22:
                        move.w  d1,d6
                        move.w  d1,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F28:
                        move.l  d1,d6
                        move.w  d1,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F2E:
                        move.l  d1,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F32:
                        move.l  d0,d6
                        move.l  d1,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F38:
                        move.w  d1,d6
                        move.l  d1,d7
                        bra.s   @Tloc_3F42
                @Tloc_3F3E:
                        move.l  d1,d6
                        move.l  d1,d7
                @Tloc_3F42:
                        or.l    d2,d0
                        not.l   d0
                        clr.w   d0
                        or.l    d2,d1
                        not.l   d1
                        jmp     (a1)
                @Tloc_3F4E:
                        or.l    d0,d6
                        bra.s   @Tloc_3F9A
                @Tloc_3F52:
                        or.w    d1,d6
                        bra.s   @Tloc_3F9A
                @Tloc_3F56:
                        or.l    d1,d6
                        bra.s   @Tloc_3F9A
                @Tloc_3F5A:
                        or.l    d0,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F5E:
                        or.l    d0,d6
                        or.l    d0,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F64:
                        or.w    d1,d6
                        or.l    d0,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F6A:
                        or.l    d1,d6
                        or.l    d0,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F70:
                        or.w    d1,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F74:
                        or.l    d0,d6
                        or.w    d1,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F7A:
                        or.w    d1,d6
                        or.w    d1,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F80:
                        or.l    d1,d6
                        or.w    d1,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F86:
                        or.l    d1,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F8A:
                        or.l    d0,d6
                        or.l    d1,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F90:
                        or.w    d1,d6
                        or.l    d1,d7
                        bra.s   @Tloc_3F9A
                @Tloc_3F96:
                        or.l    d1,d6
                        or.l    d1,d7
                @Tloc_3F9A:
                        move.l  a3,-(sp)
                        swap    d6
                        or.w    d6,(a3)
                        swap    d6
                        adda.l  a4,a3
                        or.w    d6,(a3)
                        swap    d7
                        adda.l  a4,a3
                        or.w    d7,(a3)
                        swap    d7
                        adda.l  a4,a3
                        or.w    d7,(a3)
                        movea.l (sp)+,a3
                        subq.w  #1,d4
                        bne.s   @Tloc_3FBA
                        rts
                @Tloc_3FBA:
                        lea     0x80(a2),a2
                        adda.w  P2183_i_DestinationWidth(a6),a3
                        bra.w   @Tloc_3EB2
                @Tloc_3FC6:
                        movem.l (sp)+,d3-d7/a2-a6
        }
#endif
}
#endif
