#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA637_A31E_A31M_A35E_X31J
typedef struct {
        char Index;
        unsigned char Red;
        unsigned char Green;
        unsigned char Blue;
} COLOR_DEF_AMI;

extern FTL_LIBRARY* F9008_OpenPRIM();
extern FTL_LIBRARY* F9006_OpenMEM1();
extern FTL_LIBRARY* F9000_OpenGRF1();
extern void F9020_();
extern void F9022_SetNormalColorPalette();
extern void F9026_SetColorPalette();
extern void F1127_TransitionFromPaletteToPalette();
extern VDEO_14_SetNormalColorPalette(char P4186_, char* P4187_);
extern VDEO_15_ApplyNormalColorPalette(int16_t P4193_, char* P4194_, int16_t P4195_);
extern GRF1_12_HatchBox(unsigned char* P4188_, int16_t* P4189_, int16_t P4190_, int16_t P4191_, int16_t P4192_);

extern VDEO_FTL_LIBRARY* G9018_VDEObase2;
extern unsigned char* G9031_apuc_Bitmap_Screens[M787_SCREEN_COUNT];
extern long* G3410_pl_VerticalBlankCount;
extern long* G3412_;
#ifdef MEDIA636_A31E_A31M_A35E
extern DRIA_Video* G9019_ps_MsgPort_FTL_DRIA_Video;
#endif
extern GRF1_FTL_LIBRARY* G3135_GRF1_Library;

short G9029_ai_Palette_Normal[32];
short G9026_ai_Palette_Black[32];
#ifdef MEDIA636_A31E_A31M_A35E
int16_t G9030_ai_Palette_Source[16];
int16_t G3848_aui_Palette_Intermediate[16];
#endif
#ifdef MEDIA692_X31J
unsigned char G3098_[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
BOOLEAN G3420_B_VerticalBlankInterruptHandlerInstalled;
INT1_HANDLER G3423_s_InterruptHandler;
void (*G3422_)();
int16_t G3427_i_AddInterruptHandlerResult;
#endif


#ifdef MEDIA692_X31J
void F9021_VDEO_16_PaletteControl(
int16_t P2873_)
{
        ASM_STUB_PREFIX
        F9020_(P2873_);
        ASM_STUB_SUFFIX
}
#endif

void F9020_(
int16_t P2872_)
{
        if (P2872_ == 0) {
                F9026_SetColorPalette(G9029_ai_Palette_Normal);
        } else {
                if (P2872_ == 1) {
                        F9026_SetColorPalette(G9026_ai_Palette_Black);
                }
        }
}

#ifdef MEDIA636_A31E_A31M_A35E
void F9021_VDEO_16_PaletteControl(
int16_t P2873_)
{
        ASM_STUB_PREFIX
        F9020_(P2873_);
        ASM_STUB_SUFFIX
}
#endif

#ifdef MEDIA692_X31J
void F9023_VDEO_14_SetNormalColorPalette(
char P2876_c_ColorCount,
int16_t* P2877_pc_ColorComponents)
{
        ASM_STUB_PREFIX
        F9022_SetNormalColorPalette(P2876_c_ColorCount, P2877_pc_ColorComponents);
        ASM_STUB_SUFFIX
}
#endif

void F9022_SetNormalColorPalette(
register char P2874_c_ColorCount,
register COLOR_DEF_AMI* P2875_pc_ColorComponents)
{
        while (P2874_c_ColorCount--) {
#ifdef MEDIA636_A31E_A31M_A35E
                if ((int16_t)P2875_pc_ColorComponents->Index < (unsigned int16_t)16) {
                        G9029_ai_Palette_Normal[P2875_pc_ColorComponents->Index] = ((P2875_pc_ColorComponents->Red & 0xF0) << 4) | (P2875_pc_ColorComponents->Green & 0xF0) | ((P2875_pc_ColorComponents->Blue & 0xF0) >> 4);
#endif
#ifdef MEDIA692_X31J
                if ((int16_t)P2875_pc_ColorComponents->Index < (unsigned int16_t)32) {
                        G9029_ai_Palette_Normal[P2875_pc_ColorComponents->Index] = ((P2875_pc_ColorComponents->Green & 0xF8) << 8) | ((P2875_pc_ColorComponents->Red & 0xF8) << 3) | ((P2875_pc_ColorComponents->Blue & 0xF8) >> 2) | 1;
#endif
                }
                P2875_pc_ColorComponents++;
        }
}

#ifdef MEDIA636_A31E_A31M_A35E
void F9023_VDEO_14_SetNormalColorPalette(
register char P2876_c_ColorCount,
register int16_t* P2877_pc_ColorComponents)
{
        ASM_STUB_PREFIX
        F9022_SetNormalColorPalette(P2876_c_ColorCount, P2877_pc_ColorComponents);
        ASM_STUB_SUFFIX
}
#endif

void F9024_VDEO_15_ApplyNormalColorPalette(
#ifdef MEDIA636_A31E_A31M_A35E
register char P2878_c_ColorCount,
register int16_t* P2879_pi_Palette)
#endif
#ifdef MEDIA692_X31J
char P2878_c_ColorCount,
int16_t* P2879_pi_Palette)
#endif
{
#ifdef MEDIA636_A31E_A31M_A35E
        register int16_t* L3656_pi_Color;
        register int16_t L3657_i_ColorIndex;


#endif
        ASM_STUB_PREFIX
        VDEO_14_SetNormalColorPalette(P2878_c_ColorCount, P2879_pi_Palette);
#ifdef MEDIA636_A31E_A31M_A35E
        L3656_pi_Color = G9019_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort.ColorMap->ColorTable;
        for (L3657_i_ColorIndex = 0; L3657_i_ColorIndex < 16; L3657_i_ColorIndex++) {
                G9030_ai_Palette_Source[L3657_i_ColorIndex] = *L3656_pi_Color++;
        }
        F1127_TransitionFromPaletteToPalette(G9029_ai_Palette_Normal, G9030_ai_Palette_Source);
#endif
        ASM_STUB_SUFFIX
}

void F9025_VDEO_17_GetColorPalette(
int16_t* P2880_pi_ColorPalette)
{
#ifdef MEDIA636_A31E_A31M_A35E
        register int16_t* L3658_pi_;
        register int16_t* L3659_pi_;
        register int16_t L3660_i_;
#endif
#ifdef MEDIA692_X31J
        long L5031_l_SupervisorStack;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA636_A31E_A31M_A35E
        L3658_pi_ = P2880_pi_ColorPalette;
        L3660_i_ = G9019_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort.ColorMap->Count;
        L3660_i_ = (L3660_i_ > 16) ? 16 : L3660_i_;
        L3659_pi_ = G9019_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort.ColorMap->ColorTable;
        while (L3660_i_--) {
                *L3658_pi_++ = *L3659_pi_++;
        }
#endif
#ifdef MEDIA692_X31J
        asm {
                clr.l   -(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                move.l  d0,L5031_l_SupervisorStack(a6)
                lea     (0xE82000).l,a0
                movea.l P2880_pi_ColorPalette(a6),a1
                movem.l d3-d7,-(sp)
                movem.l (a0)+,d0-d7
                movem.l d0-d7,(a1)
                movem.l (a0),d0-d7
                movem.l d0-d7,0x20(a1)
                movem.l (sp)+,d3-d7
                move.l  L5031_l_SupervisorStack(a6),-(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                addq.l  #4,sp
        }
#endif
        ASM_STUB_SUFFIX
}

#ifdef MEDIA636_A31E_A31M_A35E
void F9026_SetColorPalette(
int16_t* P2871_pi_ColorPalette)
{
        LoadRGB4(&G9019_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort, P2871_pi_ColorPalette, 16L);
}
#endif

void F9027_VDEO_18_SetColorPalette(
int16_t* P2881_)
{
        ASM_STUB_PREFIX
        F9026_SetColorPalette(P2881_);
        ASM_STUB_SUFFIX
}

#ifdef MEDIA692_X31J
void F9026_SetColorPalette(
int16_t* P2871_pi_ColorPalette)
{
        long L5032_l_SupervisorStack;


        asm {
                clr.l   -(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                move.l  d0,L5032_l_SupervisorStack(a6)
                movea.l P2871_pi_ColorPalette(a6),a0
                lea     (0xE82000).l,a1
                movem.l d3-d7,-(sp)
                movem.l (a0)+,d0-d7
                movem.l d0-d7,(a1)
                movem.l (a0),d0-d7
                movem.l d0-d7,0x20(a1)
                movem.l (sp)+,d3-d7
                move.l  L5032_l_SupervisorStack(a6),-(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                addq.l  #4,sp
        }
}
#endif

void F9028_(
)
{
#ifdef MEDIA692_X31J
        long L5033_l_SupervisorStack;


#endif
        F9022_SetNormalColorPalette(G9018_VDEObase2->_b_0x54_ColorCount, G9018_VDEObase2->_pc_0x56_ColorComponents);
#ifdef MEDIA692_X31J
        asm {
                clr.l   -(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                move.l  d0,L5033_l_SupervisorStack(a6)
                lea     (0xE823E0).l,a0
                move.w  #0,0x18(a0)
                move.w  #0xFFC1,8(a0)
                move.l  L5033_l_SupervisorStack(a6),-(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                addq.l  #4,sp
        }
#endif
        F9020_(0);
}

#ifdef MEDIA636_A31E_A31M_A35E
#if (defined(MEDIA636_A31E_A31M_A35E) && (EXETYPE == C18_VDEO))
void F1127_TransitionFromPaletteToPalette(
unsigned int16_t* P2814_pui_Palette_Destination,
unsigned int16_t* P2815_pui_Palette_Source)
{
        register int16_t L2632_i_Color;
        register int16_t L2633_i_Counter;
        register int16_t L2634_i_ColorIndex;
        int16_t L2635_i_SourceRedComponent;
        int16_t L2636_i_DestinationRedComponent;
        int16_t L2637_i_DeltaRed;
        int16_t L2638_i_IntermediateRedComponent;
        int16_t L2639_i_RedIncrement;
        int16_t L2640_i_SourceGreenComponent;
        int16_t L2641_i_DestinationGreenComponent;
        int16_t L2642_i_DeltaGreen;
        int16_t L2643_i_IntermediateGreenComponent;
        int16_t L2644_i_GreenIncrement;
        int16_t L2645_i_SourceBlueComponent;
        int16_t L2646_i_DestinationBlueComponent;
        int16_t L2647_i_DeltaBlue;
        int16_t L2648_i_IntermediateBlueComponent;
        int16_t L2649_i_BlueIncrement;


        for (L2633_i_Counter = 0; L2633_i_Counter < 16; L2633_i_Counter++) {
                G3848_aui_Palette_Intermediate[L2633_i_Counter] = P2815_pui_Palette_Source[L2633_i_Counter];
        }
        for (L2633_i_Counter = 0; L2633_i_Counter < 15; L2633_i_Counter++) {
                for (L2634_i_ColorIndex = 0; L2634_i_ColorIndex < 16; L2634_i_ColorIndex++) {
                        L2632_i_Color = P2815_pui_Palette_Source[L2634_i_ColorIndex];
                        L2635_i_SourceRedComponent = (L2632_i_Color >> 8) & 0x0F;
                        L2640_i_SourceGreenComponent = (L2632_i_Color >> 4) & 0x0F;
                        L2645_i_SourceBlueComponent = L2632_i_Color & 0x0F;
                        L2632_i_Color = P2814_pui_Palette_Destination[L2634_i_ColorIndex];
                        L2636_i_DestinationRedComponent = (L2632_i_Color >> 8) & 0x0F;
                        L2641_i_DestinationGreenComponent = (L2632_i_Color >> 4) & 0x0F;
                        L2646_i_DestinationBlueComponent = L2632_i_Color & 0x0F;
                        L2632_i_Color = G3848_aui_Palette_Intermediate[L2634_i_ColorIndex];
                        L2638_i_IntermediateRedComponent = (L2632_i_Color >> 8) & 0x0F;
                        L2643_i_IntermediateGreenComponent = (L2632_i_Color >> 4) & 0x0F;
                        L2648_i_IntermediateBlueComponent = L2632_i_Color & 0x0F;
                        L2637_i_DeltaRed = ((L2636_i_DestinationRedComponent - L2635_i_SourceRedComponent) < 0) ? (L2636_i_DestinationRedComponent - L2635_i_SourceRedComponent) * -1 : (L2636_i_DestinationRedComponent - L2635_i_SourceRedComponent);
                        L2642_i_DeltaGreen = ((L2641_i_DestinationGreenComponent - L2640_i_SourceGreenComponent) < 0) ? (L2641_i_DestinationGreenComponent - L2640_i_SourceGreenComponent) * -1 : (L2641_i_DestinationGreenComponent - L2640_i_SourceGreenComponent);
                        L2647_i_DeltaBlue = ((L2646_i_DestinationBlueComponent - L2645_i_SourceBlueComponent) < 0) ? (L2646_i_DestinationBlueComponent - L2645_i_SourceBlueComponent) * -1 : (L2646_i_DestinationBlueComponent - L2645_i_SourceBlueComponent);
                        L2639_i_RedIncrement = G9019_ps_MsgPort_FTL_DRIA_Video->ColorComponentIncrements[L2633_i_Counter][L2637_i_DeltaRed];
                        L2644_i_GreenIncrement = G9019_ps_MsgPort_FTL_DRIA_Video->ColorComponentIncrements[L2633_i_Counter][L2642_i_DeltaGreen];
                        L2649_i_BlueIncrement = G9019_ps_MsgPort_FTL_DRIA_Video->ColorComponentIncrements[L2633_i_Counter][L2647_i_DeltaBlue];
                        if ((L2636_i_DestinationRedComponent - L2635_i_SourceRedComponent) < 0) {
                                L2639_i_RedIncrement = L2639_i_RedIncrement * -1;
                        }
                        if ((L2641_i_DestinationGreenComponent - L2640_i_SourceGreenComponent) < 0) {
                                L2644_i_GreenIncrement = L2644_i_GreenIncrement * -1;
                        }
                        if ((L2646_i_DestinationBlueComponent - L2645_i_SourceBlueComponent) < 0) {
                                L2649_i_BlueIncrement = L2649_i_BlueIncrement * -1;
                        }
                        L2638_i_IntermediateRedComponent += L2639_i_RedIncrement;
                        L2643_i_IntermediateGreenComponent += L2644_i_GreenIncrement;
                        L2648_i_IntermediateBlueComponent += L2649_i_BlueIncrement;
                        L2632_i_Color = (L2638_i_IntermediateRedComponent << 8) | (L2643_i_IntermediateGreenComponent << 4) | L2648_i_IntermediateBlueComponent;
                        G3848_aui_Palette_Intermediate[L2634_i_ColorIndex] = L2632_i_Color;
                }
                LoadRGB4(&G9019_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort, G3848_aui_Palette_Intermediate, 16L);
                VDEO_13_WaitVerticalBlank();
        }
}
#endif
#endif

void F9030_VDEO_05_ExpandGraphicToBitmap(
#ifdef MEDIA636_A31E_A31M_A35E
unsigned char* P2884_puc_Graphic,
#endif
#ifdef MEDIA692_X31J
unsigned int16_t* P2884_puc_Graphicpui_Graphic,
#endif
unsigned int16_t P2885_ui_ScreenOrdinal)
{
#ifdef MEDIA636_A31E_A31M_A35E
        register unsigned char* L3661_puc_Bitmap_Screen;
#endif
#ifdef MEDIA692_X31J
        int16_t L5034_i_Width;
        int16_t L5035_i_Height;
        char L6603_ac_Unreferenced[8];
        long L5036_l_SupervisorStack;
        unsigned char** L3661_puc_Bitmap_Screen;
        unsigned char** L5037_;
        long L5038_;
        int16_t L5039_;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA636_A31E_A31M_A35E
        if (P2884_puc_Graphic && (P2885_ui_ScreenOrdinal <= M787_SCREEN_COUNT)) {
#endif
#ifdef MEDIA692_X31J
        if (P2885_ui_ScreenOrdinal <= 2) {
                L5039_ = 0;
#endif
                if (P2885_ui_ScreenOrdinal == 0) {
                        L3661_puc_Bitmap_Screen = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
                } else {
                        L3661_puc_Bitmap_Screen = G9031_apuc_Bitmap_Screens[(int16_t)P2885_ui_ScreenOrdinal - 1];
                }
#ifdef MEDIA636_A31E_A31M_A35E
                GRF1_05_F0466_EXPAND_GraphicToBitmap(P2884_puc_Graphic, L3661_puc_Bitmap_Screen);
#endif
#ifdef MEDIA692_X31J
                L5038_ = G9018_VDEObase2->_w_0x44;
                L5034_i_Width = *P2884_puc_Graphicpui_Graphic;
                L5035_i_Height = *(P2884_puc_Graphicpui_Graphic + 1);
                if (L5034_i_Width < 0) {
                        L5034_i_Width = L5035_i_Height;
                        L5035_i_Height = *(P2884_puc_Graphicpui_Graphic + 2);
                        P2884_puc_Graphicpui_Graphic++;
                        L5039_ = 1;
                } else {
                        L5035_i_Height = *(P2884_puc_Graphicpui_Graphic + 1);
                }
                L5037_ = (unsigned char*)L3661_puc_Bitmap_Screen + (L5038_ * L5035_i_Height);
                asm {
                                clr.l   -(sp)
                                dc.w    0xFF20  /* DOS CALL SUPER */
                                addq.l  #4,sp
                                move.l  d0,L5036_l_SupervisorStack(a6)
                                movem.l d0-d7/a0-a3,-(sp)
                                moveq   #0,d3
                                movea.l L3661_puc_Bitmap_Screen(a6),a0
                                movea.l P2884_puc_Graphicpui_Graphic(a6),a1
                                move.w  L5039_(a6),d7
                                move.w  (a1)+,d3
                                move.w  (a1)+,d4
                                move.w  d3,d5
                                lsl.w   #1,d5
                                movea.l L5037_(a6),a3
                                moveq   #0xF,d4
                                moveq   #0,d6
                                move.w  d3,d6
                        @Tloc_D60:
                                moveq   #0,d0
                                move.b  (a1)+,d0
                                bmi.s   @Tloc_DA0
                                move.w  d0,d1
                                lsr.b   #4,d1
                                addq.w  #1,d1
                                and.b   d4,d0
                        @Tloc_D6E:
                                cmp.l   d1,d6
                                bge.s   @Tloc_D86
                                sub.l   d6,d1
                                exg     d6,d1
                                bsr.w   @Tloc_F1E
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                exg     d6,d1
                                move.l  d3,d6
                                bra.s   @Tloc_D6E
                        @Tloc_D86:
                                sub.l   d1,d6
                                bsr.w   @Tloc_F1E
                                tst.l   d6
                                bne.s   @Tloc_D98
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                move.l  d3,d6
                        @Tloc_D98:
                                cmpa.l  a0,a3
                                bhi.s   @Tloc_D60
                                bra.w   @Tloc_F52
                        @Tloc_DA0:
                                tst.w   d7
                                beq.s   @Tloc_E0E
                                moveq   #0x30,d1 ; '0'
                                and.b   d0,d1
                                cmpi.b  #0x20,d1 ; ' '
                                bne.s   @Tloc_E10
                                btst    #6,d0
                                beq.s   @Tloc_DB8
                                ori.b   #0x10,d0
                        @Tloc_DB8:
                                moveq   #0x1F,d1
                                and.b   d0,d1
                                cmpi.b  #0x1D,d1
                                bmi.s   @Tloc_DD8
                                move.b  d1,d0
                                move.b  (a1)+,d1
                                cmpi.b  #0x1E,d0
                                bmi.s   @Tloc_DD8
                                beq.s   @Tloc_DD4
                                lsl.w   #8,d1
                                move.b  (a1)+,d1
                                bra.s   @Tloc_DD8
                        @Tloc_DD4:
                                addi.w  #0x100,d1
                        @Tloc_DD8:
                                addq.w  #1,d1
                        @Tloc_DDA:
                                cmp.l   d1,d6
                                bge.s   @Tloc_DF2
                                sub.l   d6,d1
                                exg     d6,d1
                                bsr.w   @Tloc_F18
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                exg     d6,d1
                                move.l  d3,d6
                                bra.s   @Tloc_DDA
                        @Tloc_DF2:
                                sub.l   d1,d6
                                bsr.w   @Tloc_F18
                                tst.l   d6
                                bne.s   @Tloc_E04
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                move.l  d3,d6
                        @Tloc_E04:
                                cmpa.l  a0,a3
                                bhi.w   @Tloc_D60
                                bra.w   @Tloc_F52
                        @Tloc_E0E:
                                moveq   #0,d1
                        @Tloc_E10:
                                move.b  (a1)+,d1
                                btst    #6,d0
                                beq.s   @Tloc_E1C
                                lsl.w   #8,d1
                                move.b  (a1)+,d1
                        @Tloc_E1C:
                                addq.w  #1,d1
                                btst    #4,d0
                                bne.s   @Tloc_E5A
                                and.b   d4,d0
                        @Tloc_E26:
                                cmp.l   d1,d6
                                bge.s   @Tloc_E3E
                                sub.l   d6,d1
                                exg     d6,d1
                                bsr.w   @Tloc_F1E
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                exg     d6,d1
                                move.l  d3,d6
                                bra.s   @Tloc_E26
                        @Tloc_E3E:
                                sub.l   d1,d6
                                bsr.w   @Tloc_F1E
                                tst.l   d6
                                bne.s   @Tloc_E50
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                move.l  d3,d6
                        @Tloc_E50:
                                cmpa.l  a0,a3
                                bhi.w   @Tloc_D60
                                bra.w   @Tloc_F52
                        @Tloc_E5A:
                                btst    #5,d0
                                beq.s   @Tloc_EAA
                        @Tloc_E60:
                                movea.l a0,a2
                                suba.l  L5038_(a6),a2
                                cmp.l   d1,d6
                                bge.s   @Tloc_E7E
                                sub.l   d6,d1
                                exg     d6,d1
                                bsr.w   @Tloc_F0E
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                exg     d6,d1
                                move.l  d3,d6
                                bra.s   @Tloc_E60
                        @Tloc_E7E:
                                sub.l   d1,d6
                                bsr.w   @Tloc_F0E
                                tst.l   d6
                                bne.s   @Tloc_E90
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                move.l  d3,d6
                        @Tloc_E90:
                                and.b   d4,d0
                                move.w  d0,(a0)+
                                subq.w  #1,d6
                                bne.s   @Tloc_EA0
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                move.l  d3,d6
                        @Tloc_EA0:
                                cmpa.l  a0,a3
                                bhi.w   @Tloc_D60
                                bra.w   @Tloc_F52
                        @Tloc_EAA:
                                btst    #0,d1
                                beq.s   @Tloc_EC2
                                subq.w  #1,d1
                                and.b   d4,d0
                                move.w  d0,(a0)+
                                subq.w  #1,d6
                                bne.s   @Tloc_EC2
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                move.l  d3,d6
                        @Tloc_EC2:
                                cmp.l   d1,d6
                                bge.s   @Tloc_EF2
                                sub.l   d6,d1
                                exg     d6,d1
                                bsr.w   @Tloc_F28
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                exg     d6,d1
                                move.l  d3,d6
                                tst.w   d2
                                beq.s   @Tloc_EC2
                                move.b  (a1)+,d0
                                and.w   d4,d0
                                move.w  d0,(a0)+
                                subq.w  #1,d1
                                subq.w  #1,d6
                                bne.s   @Tloc_EC2
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                move.l  d3,d6
                                bra.s   @Tloc_EC2
                        @Tloc_EF2:
                                sub.l   d1,d6
                                bsr.w   @Tloc_F28
                                tst.l   d6
                                bne.s   @Tloc_F04
                                adda.l  L5038_(a6),a0
                                suba.w  d5,a0
                                move.l  d3,d6
                        @Tloc_F04:
                                cmpa.l  a0,a3
                                bhi.w   @Tloc_D60
                                bra.w   @Tloc_F52
                        @Tloc_F0E:
                                subq.w  #1,d1
                        @Tloc_F10:
                                move.w  (a2)+,(a0)+
                                dbf     d1,@Tloc_F10
                                rts
                        @Tloc_F18:
                                adda.w  d1,a0
                                adda.w  d1,a0
                                rts
                        @Tloc_F1E:
                                subq.w  #1,d1
                        @Tloc_F20:
                                move.w  d0,(a0)+
                                dbf     d1,@Tloc_F20
                                rts
                        @Tloc_F28:
                                tst.w   d1
                                beq.s   @Tloc_F4E
                                movea.l G3412_(a5),a2
                        @Tloc_F30:
                                moveq   #0,d0
                                cmpi.w  #1,d1
                                beq.s   @Tloc_F48
                                move.b  (a1)+,d0
                                add.w   d0,d0
                                add.w   d0,d0
                                move.l  (a2,d0.w),(a0)+
                                subq.w  #2,d1
                                bgt.s   @Tloc_F30
                                bra.s   @Tloc_F4E
                        @Tloc_F48:
                                move.b  (a1),d0
                                lsr.b   #4,d0
                                move.w  d0,(a0)+
                        @Tloc_F4E:
                                move.w  d1,d2
                                rts
                        @Tloc_F52:
                                movem.l (sp)+,d0-d7/a0-a3
                                move.l  L5036_l_SupervisorStack(a6),-(sp)
                                dc.w    0xFF20  /* DOS CALL SUPER */
                                addq.l  #4,sp
                }
#endif
        }
        ASM_STUB_SUFFIX
}

#ifdef MEDIA661_A31M_A35E
void F9031_(
int16_t P2886_)
{
        asm {
                        moveq   #0,d2
                        move.w  P2886_(a6),d2
                        addi.w  #0x2C,d2
                        lsl.l   #8,d2
                        lea     (0xDFF004).l,a0
                        move.l  #0x1FF00,d1
                @Tloc_726:
                        move.l  (a0),d0
                        and.l   d1,d0
                        cmp.l   d2,d0
                        blt.s   @Tloc_726
        }
}
#endif

void F9032_VDEO_08_FillScreenBox(
unsigned int16_t P2887_ui_ScreenOrdinal,
int16_t* P2888_pi_Box,
char P2889_c_Color)
{
#ifdef MEDIA636_A31E_A31M_A35E
        register long* L3662_pl_;
#endif
#ifdef MEDIA692_X31J
        long* L3662_pl_;
        int16_t L5040_;
        long L5041_l_SupervisorStack;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA636_A31E_A31M_A35E
        if (P2888_pi_Box && (P2887_ui_ScreenOrdinal <= M787_SCREEN_COUNT)) {
#endif
#ifdef MEDIA692_X31J
        if (P2887_ui_ScreenOrdinal <= 2) {
#endif
                if (P2887_ui_ScreenOrdinal == 0) {
                        L3662_pl_ = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
                } else {
                        L3662_pl_ = G9031_apuc_Bitmap_Screens[(int16_t)P2887_ui_ScreenOrdinal - 1];
                }
#ifdef MEDIA661_A31M_A35E
                F9031_(P2888_pi_Box[1] + P2888_pi_Box[3] - 1); /* Height */
#endif
#ifdef MEDIA636_A31E_A31M_A35E
                GRF1_08_FillBox(L3662_pl_, P2888_pi_Box, P2889_c_Color, G9018_VDEObase2->_w_0x3C_ScreenWidth, G9018_VDEObase2->_w_0x3E_ScreenHeight);
#endif
#ifdef MEDIA692_X31J
                L5040_ = G9018_VDEObase2->_w_0x44;
                asm {
                                movem.l d3-d7,-(sp)
                                move.l  P2888_pi_Box(a6),d0
                                beq.s   @Tloc_1018
                                movea.l d0,a0
                                movem.w (a0)+,d3-d6
                                subq.w  #1,d5
                                bmi.s   @Tloc_1018
                                subq.w  #1,d6
                                bmi.s   @Tloc_1018
                                lea     G3098_(a5),a0
                                moveq   #0,d1
                                move.b  P2889_c_Color(a6),d1
                                adda.w  d1,a0
                                move.b  (a0),d2
                                movea.l L3662_pl_(a6),a1
                                move.w  L5040_(a6),d1
                                andi.w  #0xF,d2
                                mulu.w  d1,d4
                                adda.l  d4,a1
                                add.w   d3,d3
                                adda.w  d3,a1
                                addq.w  #1,d5
                                add.w   d5,d5
                                sub.w   d5,d1
                                clr.l   -(sp)
                                dc.w    0xFF20  /* DOS CALL SUPER */
                                move.l  d0,L5041_l_SupervisorStack(a6)
                        @Tloc_1002:
                                move.w  d5,d7
                        @Tloc_1004:
                                move.w  d2,(a1)+
                                subq.w  #2,d7
                                bgt.s   @Tloc_1004
                                adda.w  d1,a1
                                subq.w  #1,d6
                                bcc.s   @Tloc_1002
                                move.l  L5041_l_SupervisorStack(a6),-(sp)
                                dc.w    0xFF20  /* DOS CALL SUPER */
                                addq.l  #4,sp
                        @Tloc_1018:
                                movem.l (sp)+,d3-d7
                }
#endif
        }
        ASM_STUB_SUFFIX
}

void F9033_VDEO_09_HatchScreenBox(
unsigned int16_t P2890_,
int16_t* P2891_pi_XYZ,
char P2892_c_Color)
{
#ifdef MEDIA636_A31E_A31M_A35E
        register long* L3663_pl_;
#endif
#ifdef MEDIA692_X31J
        long* L3663_pl_;
        int16_t L5042_;
        long L5043_l_SupervisorStack;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA636_A31E_A31M_A35E
        if (P2891_pi_XYZ && (P2890_ <= M787_SCREEN_COUNT)) {
#endif
#ifdef MEDIA692_X31J
        if (P2890_ <= 2) {
#endif
                if (P2890_ == 0) {
                        L3663_pl_ = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
                } else {
                        L3663_pl_ = G9031_apuc_Bitmap_Screens[(int16_t)P2890_ - 1];
                }
#ifdef MEDIA661_A31M_A35E
                F9031_(P2891_pi_XYZ[1] + P2891_pi_XYZ[3] - 1); /* Height */
#endif
#ifdef MEDIA636_A31E_A31M_A35E
                GRF1_12_HatchBox(L3663_pl_, P2891_pi_XYZ, P2892_c_Color, G9018_VDEObase2->_w_0x3C_ScreenWidth, G9018_VDEObase2->_w_0x3E_ScreenHeight);
#endif
#ifdef MEDIA692_X31J
                L5042_ = G9018_VDEObase2->_w_0x44;
                asm {
                                movem.l d3-d7,-(sp)
                                move.l  P2891_pi_XYZ(a6),d7
                                beq.w   @Tloc_10E0
                                movea.l d7,a0
                                movem.w (a0)+,d3-d6
                                subq.w  #1,d5
                                bmi.w   @Tloc_10E0
                                subq.w  #1,d6
                                bmi.s   @Tloc_10E0
                                moveq   #0xF,d2
                                and.b   P2892_c_Color(a6),d2
                                movea.l L3663_pl_(a6),a1
                                move.w  L5042_(a6),d1
                                mulu.w  d1,d4
                                adda.l  d4,a1
                                eor.w   d3,d4
                                andi.w  #1,d4
                                seq     d4
                                add.w   d3,d3
                                adda.w  d3,a1
                                addq.w  #1,d5
                                add.w   d5,d5
                                sub.w   d5,d1
                                clr.l   -(sp)
                                dc.w    0xFF20  /* DOS CALL SUPER */
                                move.l  d0,L5043_l_SupervisorStack(a6)
                        @Tloc_10C0:
                                move.w  d5,d7
                                not.b   d4
                                beq.s   @Tloc_10CC
                        @Tloc_10C6:
                                addq.l  #2,a1
                                subq.w  #2,d7
                                ble.s   @Tloc_10D2
                        @Tloc_10CC:
                                move.w  d2,(a1)+
                                subq.w  #2,d7
                                bgt.s   @Tloc_10C6
                        @Tloc_10D2:
                                adda.w  d1,a1
                                subq.w  #1,d6
                                bcc.s   @Tloc_10C0
                                move.l  L5043_l_SupervisorStack(a6),-(sp)
                                dc.w    0xFF20  /* DOS CALL SUPER */
                                addq.l  #4,sp
                        @Tloc_10E0:
                                movem.l (sp)+,d3-d7
                }
#endif
        }
        ASM_STUB_SUFFIX
}

void F9034_VDEO_10_InvertScreenBox( /* Does nothing in X31J */
unsigned int16_t P2893_ui_ScreenOrdinal,
int16_t* P2894_pi_Box,
int16_t* P2895_pi_Unused)
{
#ifdef MEDIA636_A31E_A31M_A35E
        register long* L3664_pl_;
#endif
#ifdef MEDIA692_X31J
        long* L3664_pl_;
        int16_t L5044_;
        long L5045_l_Unreferenced;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA636_A31E_A31M_A35E
        if (P2894_pi_Box && (P2893_ui_ScreenOrdinal <= M787_SCREEN_COUNT)) {
#endif
                if (P2893_ui_ScreenOrdinal == 0) {
                        L3664_pl_ = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
                } else {
                        L3664_pl_ = G9031_apuc_Bitmap_Screens[(int16_t)P2893_ui_ScreenOrdinal - 1];
                }
#ifdef MEDIA692_X31J
                L5044_ = G9018_VDEObase2->_w_0x44;
#endif
#ifdef MEDIA661_A31M_A35E
                F9031_(P2894_pi_Box[1] + P2894_pi_Box[3] - 1); /* Height? */
#endif
#ifdef MEDIA636_A31E_A31M_A35E
                GRF1_13_InvertBox(L3664_pl_, P2894_pi_Box, G9018_VDEObase2->_w_0x3C_ScreenWidth, G9018_VDEObase2->_w_0x3E_ScreenHeight, P2895_pi_Unused); /* BUGX_XX wrong number of arguments, fifth parameter is ignored */
        }
#endif
        ASM_STUB_SUFFIX
}

#ifdef MEDIA636_A31E_A31M_A35E
void F9035_VDEO_11_BlitFromScreenNoTransparency(
unsigned int16_t P2896_ui_ScreenOrdinal,
int16_t* P2897_pi_Bitmap,
int16_t* P2898_pi_Box)
{
        register unsigned char* L3665_puc_Bitmap_Screen;
        int16_t L3666_ai_Box[4];


        ASM_STUB_PREFIX
        if (P2897_pi_Bitmap && (P2896_ui_ScreenOrdinal <= M787_SCREEN_COUNT)) {
                if (P2896_ui_ScreenOrdinal == 0) {
                        L3665_puc_Bitmap_Screen = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
                } else {
                        L3665_puc_Bitmap_Screen = G9031_apuc_Bitmap_Screens[(int16_t)P2896_ui_ScreenOrdinal - 1];
                }
                L3666_ai_Box[0] = 0;
                L3666_ai_Box[1] = 0;
                L3666_ai_Box[2] = P2898_pi_Box[2];
                L3666_ai_Box[3] = P2898_pi_Box[3];
                GRF1_06_Blit(L3665_puc_Bitmap_Screen, P2897_pi_Bitmap, L3666_ai_Box, P2898_pi_Box[0], P2898_pi_Box[1], G9018_VDEObase2->_w_0x3C_ScreenWidth, L3666_ai_Box[2], CM1_COLOR_NO_TRANSPARENCY, G9018_VDEObase2->_w_0x3E_ScreenHeight, L3666_ai_Box[3]);
        }
        ASM_STUB_SUFFIX
}

void F9036_VDEO_12_BlitToScreenNoTransparency(
unsigned int16_t P2899_ui_ScreenOrdinal,
unsigned char* P2900_puc_Bitmap,
int16_t* P2901_pi_Box)
{
#ifdef MEDIA618_A31E
        register unsigned char* L4796_Bitmap_Screen;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA618_A31E
        if (P2900_puc_Bitmap && (P2899_ui_ScreenOrdinal <= M787_SCREEN_COUNT)) {
                if (P2899_ui_ScreenOrdinal == 0) {
                        L4796_Bitmap_Screen = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
                } else {
                        L4796_Bitmap_Screen = G9031_apuc_Bitmap_Screens[(int16_t)P2899_ui_ScreenOrdinal - 1];
                }
                GRF1_06_Blit(P2900_puc_Bitmap, L4796_Bitmap_Screen, P2901_pi_Box, 0, 0, M708_ZONE_WIDTH(P2901_pi_Box), G9018_VDEObase2->_w_0x3C_ScreenWidth, CM1_COLOR_NO_TRANSPARENCY, M709_ZONE_HEIGHT(P2901_pi_Box), G9018_VDEObase2->_w_0x3E_ScreenHeight);
        }
#endif
#ifdef MEDIA661_A31M_A35E
        if (P2900_puc_Bitmap) {
                VDEO_06_BlitToScreen(P2900_puc_Bitmap, P2899_ui_ScreenOrdinal, P2901_pi_Box, 0, 0, M708_ZONE_WIDTH(P2901_pi_Box), CM1_COLOR_NO_TRANSPARENCY, M709_ZONE_HEIGHT(P2901_pi_Box));
        }
#endif
        ASM_STUB_SUFFIX
}

#include "BLITAMIG.C"
#include "CONVBOXC.C"
#include "BLIT.C"
#endif

void F9041_VDEO_06_BlitToScreen(
unsigned char* P2924_puc_Bitmap,
unsigned int16_t P2925_ui_ScreenOrdinal,
int16_t* P2926_pi_Box,
int16_t P2927_i_X,
int16_t P2928_i_Y,
int16_t P2929_i_Width,
char P2930_c_TransparentColor,
int16_t P2931_i_Height)
{
#ifdef MEDIA636_A31E_A31M_A35E
        register unsigned char* L3667_puc_Bitmap_Screen;
#endif
#ifdef MEDIA692_X31J
        unsigned char* L3667_puc_Bitmap_Screen;
        int16_t L5046_;
        long L5047_l_SupervisorStack;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA636_A31E_A31M_A35E
        if (P2924_puc_Bitmap && (P2925_ui_ScreenOrdinal <= M787_SCREEN_COUNT)) {
#endif
#ifdef MEDIA692_X31J
        if (P2924_puc_Bitmap && (P2925_ui_ScreenOrdinal <= 2)) {
#endif
                if (P2925_ui_ScreenOrdinal == 0) {
                        L3667_puc_Bitmap_Screen = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
                } else {
                        L3667_puc_Bitmap_Screen = G9031_apuc_Bitmap_Screens[(int16_t)P2925_ui_ScreenOrdinal - 1];
                }
#ifdef MEDIA636_A31E_A31M_A35E
                F0132_VIDEO_Blit(P2924_puc_Bitmap, L3667_puc_Bitmap_Screen, P2926_pi_Box, P2927_i_X, P2928_i_Y, P2929_i_Width, G9018_VDEObase2->_w_0x3C_ScreenWidth, P2930_c_TransparentColor, P2931_i_Height, G9018_VDEObase2->_w_0x3E_ScreenHeight);
#endif
#ifdef MEDIA692_X31J
                L5046_ = G9018_VDEObase2->_w_0x44;
                asm {
                                movem.l d3-d7/a2-a5,-(sp)
                                move.l  P2926_pi_Box(a6),d0
                                beq.w   @Tloc_12AC
                                movea.l d0,a2
                                movea.l P2924_puc_Bitmap(a6),a0
                                move.w  P2929_i_Width(a6),d1
                                addq.w  #1,d1
                                lsr.w   #1,d1
                                movea.w d1,a3
                                movea.l L3667_puc_Bitmap_Screen(a6),a1
                                move.w  L5046_(a6),d7
                                movea.w d7,a4
                                move.w  P2927_i_X(a6),d4
                                move.w  P2928_i_Y(a6),d3
                                moveq   #0,d5
                                moveq   #0,d6
                                mulu.w  d1,d3
                                adda.l  d3,a0
                                lsr.w   #1,d4
                                adda.w  d4,a0
                                addx.b  d5,d5
                                moveq   #0,d1
                                moveq   #0,d2
                                moveq   #0,d3
                                moveq   #0,d4
                                move.w  (a2)+,d4
                                move.w  (a2)+,d3
                                move.w  (a2)+,d2
                                add.w   d4,d2
                                subq.w  #1,d2
                                adda.w  d4,a1
                                adda.w  d4,a1
                                sub.w   d4,d2
                                addq.w  #1,d2
                                suba.w  d2,a4
                                suba.w  d2,a4
                                add.w   d5,d2
                                swap    d5
                                lsr.w   #1,d2
                                suba.w  d2,a3
                                bcc.s   @Tloc_1202
                                addq.w  #1,d5
                                subq.l  #1,a3
                        @Tloc_1202:
                                move.w  (a2)+,d1
                                subq.w  #1,d1
                                mulu.w  d7,d3
                                adda.l  d3,a1
                                clr.l   -(sp)
                                dc.w    0xFF20  /* DOS CALL SUPER */
                                move.l  d0,L5047_l_SupervisorStack(a6)
                                move.b  P2930_c_TransparentColor(a6),d4
                                bpl.s   @Tloc_1256
                                movea.l G3412_(a5),a5
                        @Tloc_121C:
                                move.w  d2,d3
                                swap    d5
                                tst.w   d5
                                beq.s   @Tloc_123A
                                moveq   #0xF,d0
                                and.b   (a0)+,d0
                                move.w  d0,(a1)+
                                subq.w  #2,d3
                                bmi.s   @Tloc_123E
                        @Tloc_122E:
                                moveq   #0,d0
                                move.b  (a0)+,d0
                                add.w   d0,d0
                                add.w   d0,d0
                                move.l  (a5,d0.w),(a1)+
                        @Tloc_123A:
                                subq.w  #1,d3
                                bpl.s   @Tloc_122E
                        @Tloc_123E:
                                swap    d5
                                tst.w   d5
                                beq.s   @Tloc_124A
                                move.b  (a0)+,d0
                                lsr.b   #4,d0
                                move.w  d0,(a1)+
                        @Tloc_124A:
                                adda.l  a3,a0
                                adda.l  a4,a1
                                subq.w  #1,d1
                                bpl.s   @Tloc_121C
                                bra.w   @Tloc_12A4
                        @Tloc_1256:
                                move.w  d2,d3
                                swap    d5
                                tst.w   d5
                                beq.s   @Tloc_1286
                                moveq   #0xF,d0
                                and.b   (a0)+,d0
                                cmp.b   d0,d4
                                beq.s   @Tloc_1268
                                move.w  d0,(a1)
                        @Tloc_1268:
                                addq.l  #2,a1
                                subq.w  #2,d3
                                bmi.s   @Tloc_128A
                        @Tloc_126E:
                                move.b  (a0)+,d0
                                moveq   #0xF,d6
                                and.b   d0,d6
                                lsr.b   #4,d0
                                cmp.b   d0,d4
                                beq.s   @Tloc_127C
                                move.w  d0,(a1)
                        @Tloc_127C:
                                addq.l  #2,a1
                                cmp.b   d6,d4
                                beq.s   @Tloc_1284
                                move.w  d6,(a1)
                        @Tloc_1284:
                                addq.l  #2,a1
                        @Tloc_1286:
                                subq.w  #1,d3
                                bpl.s   @Tloc_126E
                        @Tloc_128A:
                                swap    d5
                                tst.w   d5
                                beq.s   @Tloc_129C
                                move.b  (a0)+,d0
                                lsr.b   #4,d0
                                cmp.b   d0,d4
                                beq.s   @Tloc_129A
                                move.w  d0,(a1)
                        @Tloc_129A:
                                addq.l  #2,a1
                        @Tloc_129C:
                                adda.l  a3,a0
                                adda.l  a4,a1
                                subq.w  #1,d1
                                bpl.s   @Tloc_1256
                        @Tloc_12A4:
                                move.l  L5047_l_SupervisorStack(a6),-(sp)
                                dc.w    0xFF20  /* DOS CALL SUPER */
                                addq.l  #4,sp
                        @Tloc_12AC:
                                movem.l (sp)+,d3-d7/a2-a5
                }
#endif
        }
        ASM_STUB_SUFFIX
}

void F9042_VDEO_07_Empty(
int16_t P4185_)
{
        ASM_STUB_PREFIX
        ASM_STUB_SUFFIX
}

#ifdef MEDIA636_A31E_A31M_A35E
long F9043_VDEO_04_GetBitmapByteCount(
unsigned int16_t P2932_ui_Width,
int16_t P2933_i_Height)
{
#ifdef MEDIA661_A31M_A35E
        register unsigned int16_t L3668_ui_BaseLineStridePixelCount;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA661_A31M_A35E
        L3668_ui_BaseLineStridePixelCount = G3135_GRF1_Library->_w_0x36_BaseLineStridePixelCount - 1;
#endif
        ASM_STUB_SUFFIX
#ifdef MEDIA618_A31E
        return ((P2932_ui_Width + G3135_GRF1_Library->_w_0x36_BaseLineStridePixelCount - 1) >> 3) * P2933_i_Height; /* BUGX_XX: wrong formula and located after ASM_STUB_SUFFIX meaning access to global variable G3135_GRF1_Library would fail */
#endif
#ifdef MEDIA661_A31M_A35E
        return (((P2932_ui_Width + L3668_ui_BaseLineStridePixelCount) & ~L3668_ui_BaseLineStridePixelCount) >> 1) * P2933_i_Height;
#endif
}
#endif

#ifdef MEDIA692_X31J
void F9035_VDEO_11_BlitFromScreenNoTransparency(
unsigned int16_t P2896_ui_ScreenOrdinal,
int16_t* P2897_pi_Bitmap,
int16_t* P2898_pi_Box)
{
        register int16_t* L5049_;
        register int16_t* L5050_;
        register unsigned char* L3665_;
        register int16_t L5051_;
        register int16_t L5052_;
        register int16_t L5053_;
        register int16_t L5054_;
        register unsigned int16_t L5055_;
        long L5048_l_SupervisorStack;


        ASM_STUB_PREFIX
        L5049_ = P2897_pi_Bitmap;
        L5052_ = P2898_pi_Box[2];
        L5053_ = P2898_pi_Box[3];
        L5055_ = G9018_VDEObase2->_w_0x44;
        L5054_ = (L5055_ >> 1) - L5052_;
        if (P2896_ui_ScreenOrdinal == 0) {
                L3665_ = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
        } else {
                L3665_ = G9031_apuc_Bitmap_Screens[(int16_t)P2896_ui_ScreenOrdinal - 1];
        }
        L5050_ = L3665_ + ((long)P2898_pi_Box[1] * L5055_) + (P2898_pi_Box[0] * 2);
        asm {
                clr.l   -(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                addq.l  #4,sp
                move.l  d0,L5048_l_SupervisorStack(a6)
        }
        while (--L5053_ >= 0) {
                L5051_ = L5052_;
                while (--L5051_ >= 0) {
                        *L5049_++ = *L5050_++;
                }
                L5050_ += L5054_;
        }
        asm {
                move.l  L5048_l_SupervisorStack(a6),-(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                addq.l  #4,sp
        }
        ASM_STUB_SUFFIX
}

void F9036_VDEO_12_BlitToScreenNoTransparency(
unsigned int16_t P2899_ui_ScreenOrdinal,
unsigned char* P2900_puc_Bitmap,
int16_t* P2901_pi_Box)
{
        register int16_t* L5057_;
        register int16_t* L5058_;
        register unsigned char* L4796_Bitmap_Screen;
        register int16_t L5059_;
        register int16_t L5060_;
        register int16_t L5061_;
        register int16_t L5062_;
        register unsigned int16_t L5063_;
        long L5056_l_SupervisorStack;


        ASM_STUB_PREFIX
        L5057_ = P2900_puc_Bitmap;
        L5060_ = P2901_pi_Box[2];
        L5061_ = P2901_pi_Box[3];
        L5063_ = G9018_VDEObase2->_w_0x44;
        L5062_ = (L5063_ >> 1) - L5060_;
        if (P2899_ui_ScreenOrdinal == 0) {
                L4796_Bitmap_Screen = G9031_apuc_Bitmap_Screens[G9018_VDEObase2->_w_0x4E_PhysicalScreenOrdinal - 1];
        } else {
                L4796_Bitmap_Screen = G9031_apuc_Bitmap_Screens[(int16_t)P2899_ui_ScreenOrdinal - 1];
        }
        L5058_ = L4796_Bitmap_Screen + ((long)P2901_pi_Box[1] * L5063_) + (P2901_pi_Box[0] * 2);
        VDEO_13_WaitVerticalBlank();
        asm {
                clr.l   -(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                addq.l  #4,sp
                move.l  d0,L5056_l_SupervisorStack(a6)
        }
        while (--L5061_ >= 0) {
                L5059_ = L5060_;
                while (--L5059_ >= 0) {
                        *L5058_++ = *L5057_++;
                }
                L5058_ += L5062_;
        }
        asm {
                move.l  L5056_l_SupervisorStack(a6),-(sp)
                dc.w    0xFF20  /* DOS CALL SUPER */
                addq.l  #4,sp
        }
        ASM_STUB_SUFFIX
}

void F1662_InstallVerticalBlankInterruptHandler(
)
{
        if (G3420_B_VerticalBlankInterruptHandlerInstalled) {
                return;
        }
        G3420_B_VerticalBlankInterruptHandlerInstalled = C1_TRUE;
        asm {
                lea     @T1662001_A5Backup,a0
                move.l  a5,(a0)
                lea     @T1662000_VerticalBlankInterruptHandler,a1
                move.l  a1,G3422_(a5)
        }
        G3423_s_InterruptHandler.Code = G3422_;
        G3423_s_InterruptHandler.Priority = 127;
        G3423_s_InterruptHandler.Type = 0; /* Vertical Blank */
        G3423_s_InterruptHandler.CurrentInterruptCount = 1; /* Runs on every interrupt */
        G3427_i_AddInterruptHandlerResult = INT1_04_InstallInterruptHandler(&G3423_s_InterruptHandler);
        return;
        asm {
                @T1662000_VerticalBlankInterruptHandler:
                        move.l  a5,-(sp)
                        movea.l @T1662001_A5Backup,a5
                        movea.l G3410_pl_VerticalBlankCount(a5),a5
                        addq.l  #1,(a5)
                        movea.l (sp)+,a5
                        bra.s   @T1662002_Return
                @T1662001_A5Backup:
                        dc.l 0
                @T1662002_Return:
        }
}

void F1663_UninstallVerticalBlankInterruptHandler(
)
{
        if (G3420_B_VerticalBlankInterruptHandlerInstalled == C1_TRUE) {
                G3420_B_VerticalBlankInterruptHandlerInstalled = C0_FALSE;
                INT1_05_UninstallInterruptHandler(&G3423_s_InterruptHandler);
        }
}
#endif

void F9044_VDEO_13_WaitVerticalBlank(
)
{
#ifdef MEDIA692_X31J
        long L5064_;


#endif
        ASM_STUB_PREFIX
#ifdef MEDIA636_A31E_A31M_A35E
        WaitTOF();
#endif
#ifdef MEDIA692_X31J
        L5064_ = *G3410_pl_VerticalBlankCount;
        while (L5064_ == *G3410_pl_VerticalBlankCount);
#endif
        ASM_STUB_SUFFIX
}
#endif
