#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA079_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J_SU1E
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "start"
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
segment "start"
#endif

#ifdef MEDIA772_SU1E
#if (EXETYPE == C04_SWITCH)
unsigned char* G0348_Bitmap_Screen;
BOOLEAN G0578_B_UseByteBoxCoordinates;
#endif
#endif


#ifdef MEDIA577_X30J
void F1014_Unreferenced(int16_t P2784_) {
}

void F1015_Unreferenced(int16_t P2785_) {
}
#endif

#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
#if (EXETYPE == C03_GAME)
BOOLEAN G3199_B_UpdatePaletteColor16To31InVerticalBlank = C0_FALSE;
BOOLEAN G3121_B_UpdateMiddleScreenPaletteInNextVerticalBlank = C0_FALSE;
BOOLEAN G3127_B_UpdateTopAndBottomScreenPaletteInNextVerticalBlank = C0_FALSE;
unsigned int16_t* G3198_pui_PaletteColor16To31;
unsigned int16_t* G3123_PaletteSourceForMiddleScreen;
unsigned int16_t* G3119_pui_ColorPalette_SourceForTopAndBottomScreen;
int16_t G3207_B_AllowPaletteAndMessageAreaUpdatesInVerticalBlank = C0_FALSE;
unsigned int16_t* G3206_;
unsigned int16_t G3088_aui_Palette_TopAndBottomScreen[16] = {
0x000, 0x666, 0x888, 0x620, 0x0CC, 0x840, 0x080, 0x0C0, 0xF00, 0xFA0, 0xC86, 0xFF0, 0x444, 0xAAA, 0x00F, 0xFFF };
unsigned int16_t G3197_pui_ColorPalette[16] = {
0x000, 0x666, 0x888, 0x620, 0x0CC, 0x840, 0x080, 0x0C0, 0xF00, 0xFA0, 0xC86, 0xFF0, 0x000, 0xAAA, 0x00F, 0xFFF };
BOOLEAN G3208_B_ = C1_TRUE;
char G3209_[4] = { 0xAA, 0xAA, 0x55, 0x55 };


void F1122_(P2812_pi_ColorPalette, P2813_i_ColorCount)
register int16_t* P2812_pi_ColorPalette;
register int16_t P2813_i_ColorCount;
{
        register int16_t* L2630_pi_;
        register unsigned int16_t L2631_ui_;


        L2631_ui_ = G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort.ColorMap->Count;
        P2813_i_ColorCount = (P2813_i_ColorCount > L2631_ui_) ? L2631_ui_ : P2813_i_ColorCount;
        L2630_pi_ = G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort.ColorMap->ColorTable;
        while (P2813_i_ColorCount--) {
                *L2630_pi_++ = *P2812_pi_ColorPalette++;
        }
}

void F1123_(
)
{
        if (!F1138_()) {
                F1050_AlertCSBSystemError(0x80FF0029);
        }
        G3206_ = G3191_ps_MsgPort_FTL_DRIA_Video->_0x44_ViewPort.ColorMap->ColorTable;
        G3198_pui_PaletteColor16To31 = G3197_pui_ColorPalette;
        G3123_PaletteSourceForMiddleScreen = G3119_pui_ColorPalette_SourceForTopAndBottomScreen = G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort.ColorMap->ColorTable;
        G3207_B_AllowPaletteAndMessageAreaUpdatesInVerticalBlank = G3199_B_UpdatePaletteColor16To31InVerticalBlank = G3121_B_UpdateMiddleScreenPaletteInNextVerticalBlank = G3127_B_UpdateTopAndBottomScreenPaletteInNextVerticalBlank = C1_TRUE;
        while (G3199_B_UpdatePaletteColor16To31InVerticalBlank || G3121_B_UpdateMiddleScreenPaletteInNextVerticalBlank || G3127_B_UpdateTopAndBottomScreenPaletteInNextVerticalBlank);
        LoadView(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x032_View);
        G3199_B_UpdatePaletteColor16To31InVerticalBlank = G3121_B_UpdateMiddleScreenPaletteInNextVerticalBlank = G3127_B_UpdateTopAndBottomScreenPaletteInNextVerticalBlank = C1_TRUE;
        while (G3199_B_UpdatePaletteColor16To31InVerticalBlank || G3121_B_UpdateMiddleScreenPaletteInNextVerticalBlank || G3127_B_UpdateTopAndBottomScreenPaletteInNextVerticalBlank);
        F1122_(G3088_aui_Palette_TopAndBottomScreen, 32);
}

void F1124_(
)
{
#ifdef MEDIA758_A36M_A35E_A35M
        if (G3207_B_AllowPaletteAndMessageAreaUpdatesInVerticalBlank) {
#endif
                G3207_B_AllowPaletteAndMessageAreaUpdatesInVerticalBlank = C0_FALSE;
                WaitBlit();
                WaitTOF();
#ifdef MEDIA758_A36M_A35E_A35M
                F1122_(G3206_, 16);
                SetRGB4(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort, 17L, 15L, 15L, 0L);
                SetRGB4(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort, 18L, 0L, 0L, 0L);
                SetRGB4(&G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen->ViewPort, 19L, 0L, 0L, 0L);
                MakeScreen(G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen);
                RethinkDisplay();
        }
#endif
}

void F1125_(
)
{
#ifdef MEDIA620_A31E_A31M_A33M
        WaitBlit();
#endif
        if (G3207_B_AllowPaletteAndMessageAreaUpdatesInVerticalBlank) {
#ifdef MEDIA758_A36M_A35E_A35M
                WaitBlit();
#endif
                F0436_STARTEND_FadeToPalette(G0021_aaui_Graphic562_Palette_DungeonView);
#ifdef MEDIA620_A31E_A31M_A33M
                F1122_(G0021_aaui_Graphic562_Palette_DungeonView, 16);
                MakeScreen(G3191_ps_MsgPort_FTL_DRIA_Video->_0x108_Screen);
                RethinkDisplay();
#endif
        }
}

void F1126_(
)
{
#ifdef MEDIA620_A31E_A31M_A33M
        WaitBlit();
#endif
        if (G3207_B_AllowPaletteAndMessageAreaUpdatesInVerticalBlank) {
#ifdef MEDIA758_A36M_A35E_A35M
                WaitBlit();
#endif
#ifdef MEDIA625_A31E_A31M_A33M_A35E
                F0436_STARTEND_FadeToPalette(&G3161_ac_Buffer724Bytes->_aui_Palette_0x188);
                F0436_STARTEND_FadeToPalette(&G3161_ac_Buffer724Bytes->_aui_Palette_0x188);
                F0509_AMIGA_FillScreen(C00_COLOR_BLACK);
#endif
        }
}

void F1127_TransitionFromPaletteToPalette(
register unsigned int16_t* P2814_pui_Palette_Destination,
register 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 < 32; L2633_i_Counter++) {
                G3161_ac_Buffer724Bytes->_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 < 32; 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 & 15];
                        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 = G3161_ac_Buffer724Bytes->_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 = G3191_ps_MsgPort_FTL_DRIA_Video->ColorComponentIncrements[L2633_i_Counter][L2637_i_DeltaRed];
                        L2644_i_GreenIncrement = G3191_ps_MsgPort_FTL_DRIA_Video->ColorComponentIncrements[L2633_i_Counter][L2642_i_DeltaGreen];
                        L2649_i_BlueIncrement = G3191_ps_MsgPort_FTL_DRIA_Video->ColorComponentIncrements[L2633_i_Counter][L2647_i_DeltaBlue];
                        if ((L2636_i_DestinationRedComponent - L2635_i_SourceRedComponent) < 0) {
                                L2639_i_RedIncrement *= -1;
                        }
                        if ((L2641_i_DestinationGreenComponent - L2640_i_SourceGreenComponent) < 0) {
                                L2644_i_GreenIncrement *= -1;
                        }
                        if ((L2646_i_DestinationBlueComponent - L2645_i_SourceBlueComponent) < 0) {
                                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;
                        G3161_ac_Buffer724Bytes->_aui_Palette_Intermediate[L2634_i_ColorIndex] = L2632_i_Color;
                }
                G3123_PaletteSourceForMiddleScreen = G3161_ac_Buffer724Bytes->_aui_Palette_Intermediate;
                G3119_pui_ColorPalette_SourceForTopAndBottomScreen = &G3161_ac_Buffer724Bytes->_aui_Palette_Intermediate[16];
                Disable();
                G3121_B_UpdateMiddleScreenPaletteInNextVerticalBlank = G3127_B_UpdateTopAndBottomScreenPaletteInNextVerticalBlank = C1_TRUE;
                Enable();
                while (G3121_B_UpdateMiddleScreenPaletteInNextVerticalBlank || G3127_B_UpdateTopAndBottomScreenPaletteInNextVerticalBlank);
        }
}
#endif
#endif

void F0436_STARTEND_FadeToPalette(
#ifdef MEDIA077_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_X31J
P0849_pui_TargetColorPalette)
unsigned int16_t* P0849_pui_TargetColorPalette;
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
unsigned int16_t* P0849_pui_TargetColorPalette)
#endif
#ifdef MEDIA772_SU1E
#if (EXETYPE == C02_LAUNCHER)
P0849_pui_TargetColorPalette, P1035_i_Delay)
unsigned int16_t* P0849_pui_TargetColorPalette;
int16_t P1035_i_Delay;
#else
#if ((EXETYPE == C06_CEDT) || (EXETYPE == C04_SWITCH))
unsigned int16_t* P0849_pui_TargetColorPalette)
#endif
#if (EXETYPE == C05_ANIM)
unsigned int16_t* P0849_pui_TargetColorPalette,
int16_t P1035_i_Delay)
#endif
#endif
#endif
{
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        register unsigned int16_t* L3394_pui_;
#endif
#ifdef MEDIA087_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_SU1E
        REGISTER unsigned int16_t L1374_ui_CurrentRGBColor;
        REGISTER unsigned int16_t L1375_ui_TargetRGBColor;
#endif
#ifdef MEDIA086_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A36M_A31E_A31M_A33M_A35E_A35M_SU1E
        REGISTER int16_t L1376_i_Color;
#endif
#ifdef MEDIA087_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_SU1E
        REGISTER int16_t L1377_i_Counter;
#endif
#ifdef MEDIA155_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_SU1E
        REGISTER unsigned int16_t* L1378_pui_PaletteRegister;
#endif
#ifdef MEDIA772_SU1E
#if (EXETYPE == C02_LAUNCHER)
        int16_t L1839_i_;
#endif
#if (EXETYPE == C05_ANIM)
        int16_t L1839_i_;
#endif
#endif
#ifdef MEDIA174_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_SU1E
        long L1379_l_SupervisorStack;
#endif


#ifdef MEDIA174_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_SU1E
        L1378_pui_PaletteRegister = (unsigned int16_t*)0xFFFF8240;
        L1379_l_SupervisorStack = Super(0L);
        for (L1377_i_Counter = 0; L1377_i_Counter < 8; L1377_i_Counter++) {
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        for (L1377_i_Counter = 0; L1377_i_Counter < 16; L1377_i_Counter++) {
#endif
#ifdef MEDIA772_SU1E
#if (EXETYPE == C02_LAUNCHER)
                for (L1839_i_ = 0; L1839_i_ <= P1035_i_Delay; L1839_i_++) {
#endif
#if (EXETYPE == C05_ANIM)
                for (L1839_i_ = 0; L1839_i_ <= P1035_i_Delay; L1839_i_++) {
#endif
#endif
#ifdef MEDIA108_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_SU1E
                        M526_WaitVerticalBlank();
#endif
#ifdef MEDIA772_SU1E
#if (EXETYPE == C02_LAUNCHER)
                }
#endif
#if (EXETYPE == C05_ANIM)
                }
#endif
#endif
#ifdef MEDIA108_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_SU1E
                for (L1376_i_Color = 0; L1376_i_Color < 16; L1376_i_Color++) {
#endif
#ifdef MEDIA174_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_SU1E
                        L1374_ui_CurrentRGBColor = L1378_pui_PaletteRegister[L1376_i_Color];
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
                        L1374_ui_CurrentRGBColor = G3949_pui_Palette_MiddleScreen[L1376_i_Color];
#endif
#ifdef MEDIA108_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_SU1E
                        L1375_ui_TargetRGBColor = P0849_pui_TargetColorPalette[L1376_i_Color];
                        if (M007_GET(L1374_ui_CurrentRGBColor, M512_MASK_BLUE_COMPONENT) > M007_GET(L1375_ui_TargetRGBColor, M512_MASK_BLUE_COMPONENT))
                                L1374_ui_CurrentRGBColor--;
                        if (M007_GET(L1374_ui_CurrentRGBColor, M512_MASK_BLUE_COMPONENT) < M007_GET(L1375_ui_TargetRGBColor, M512_MASK_BLUE_COMPONENT))
                                L1374_ui_CurrentRGBColor++;
                        if (M007_GET(L1374_ui_CurrentRGBColor, M511_MASK_GREEN_COMPONENT) > M007_GET(L1375_ui_TargetRGBColor, M511_MASK_GREEN_COMPONENT))
                                L1374_ui_CurrentRGBColor -= 16;
                        if (M007_GET(L1374_ui_CurrentRGBColor, M511_MASK_GREEN_COMPONENT) < M007_GET(L1375_ui_TargetRGBColor, M511_MASK_GREEN_COMPONENT))
                                L1374_ui_CurrentRGBColor += 16;
                        if (M007_GET(L1374_ui_CurrentRGBColor, M510_MASK_RED_COMPONENT) > M007_GET(L1375_ui_TargetRGBColor, M510_MASK_RED_COMPONENT))
                                L1374_ui_CurrentRGBColor -= 256;
                        if (M007_GET(L1374_ui_CurrentRGBColor, M510_MASK_RED_COMPONENT) < M007_GET(L1375_ui_TargetRGBColor, M510_MASK_RED_COMPONENT))
                                L1374_ui_CurrentRGBColor += 256;
#endif
#ifdef MEDIA174_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_SU1E
                        L1378_pui_PaletteRegister[L1376_i_Color] = L1374_ui_CurrentRGBColor;
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
                        G3949_pui_Palette_MiddleScreen[L1376_i_Color] = L1374_ui_CurrentRGBColor;
                        G4049_pui_Palette_[L1376_i_Color] = L1374_ui_CurrentRGBColor;
#endif
#ifdef MEDIA108_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_SU1E
                }
        }
#endif
#ifdef MEDIA174_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_SU1E
        Super(L1379_l_SupervisorStack);
#endif
#ifdef MEDIA772_SU1E
        Setpalette(P0849_pui_TargetColorPalette);
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        L1378_pui_PaletteRegister = G1016_aui_Palette_FadeTemporary;
        for (L1376_i_Color = 0; L1376_i_Color < 16; L1376_i_Color++) {
                L1378_pui_PaletteRegister[L1376_i_Color] = G0731_pui_Palette_FadeFrom[L1376_i_Color];
        }
        for (L1377_i_Counter = 0; L1377_i_Counter < 8; L1377_i_Counter++) {
                for (L1376_i_Color = 0, L1378_pui_PaletteRegister = G1016_aui_Palette_FadeTemporary; L1376_i_Color < 16; L1376_i_Color++, L1378_pui_PaletteRegister++) {
                        L1374_ui_CurrentRGBColor = M007_GET(*L1378_pui_PaletteRegister, M512_MASK_BLUE_COMPONENT);
                        L1375_ui_TargetRGBColor = M007_GET(P0849_pui_TargetColorPalette[L1376_i_Color], M512_MASK_BLUE_COMPONENT);
                        if (L1374_ui_CurrentRGBColor > L1375_ui_TargetRGBColor) {
                                if (L1374_ui_CurrentRGBColor > L1375_ui_TargetRGBColor + 1) {
                                        *L1378_pui_PaletteRegister -= 2;
                                } else {
                                        *L1378_pui_PaletteRegister -= 1;
                                }
                        } else {
                                if (L1374_ui_CurrentRGBColor < L1375_ui_TargetRGBColor) {
                                        if (L1374_ui_CurrentRGBColor < L1375_ui_TargetRGBColor - 1) {
                                                *L1378_pui_PaletteRegister += 2;
                                        } else {
                                                *L1378_pui_PaletteRegister += 1;
                                        }
                                }
                        }
                        L1374_ui_CurrentRGBColor = M007_GET(*L1378_pui_PaletteRegister, M511_MASK_GREEN_COMPONENT) >> 4;
                        L1375_ui_TargetRGBColor = M007_GET(P0849_pui_TargetColorPalette[L1376_i_Color], M511_MASK_GREEN_COMPONENT) >> 4;
                        if (L1374_ui_CurrentRGBColor > L1375_ui_TargetRGBColor) {
                                if (L1374_ui_CurrentRGBColor > L1375_ui_TargetRGBColor + 1) {
                                        *L1378_pui_PaletteRegister -= 32;
                                } else {
                                        *L1378_pui_PaletteRegister -= 16;
                                }
                        } else {
                                if (L1374_ui_CurrentRGBColor < L1375_ui_TargetRGBColor) {
                                        if (L1374_ui_CurrentRGBColor < L1375_ui_TargetRGBColor - 1) {
                                                *L1378_pui_PaletteRegister += 32;
                                        } else {
                                                *L1378_pui_PaletteRegister += 16;
                                        }
                                }
                        }
                        L1374_ui_CurrentRGBColor = M007_GET(*L1378_pui_PaletteRegister, M510_MASK_RED_COMPONENT) >> 8;
                        L1375_ui_TargetRGBColor = M007_GET(P0849_pui_TargetColorPalette[L1376_i_Color], M510_MASK_RED_COMPONENT) >> 8;
                        if (L1374_ui_CurrentRGBColor > L1375_ui_TargetRGBColor) {
                                if (L1374_ui_CurrentRGBColor > L1375_ui_TargetRGBColor + 1) {
                                        *L1378_pui_PaletteRegister -= 512;
                                } else {
                                        *L1378_pui_PaletteRegister -= 256;
                                }
                        } else {
                                if (L1374_ui_CurrentRGBColor < L1375_ui_TargetRGBColor) {
                                        if (L1374_ui_CurrentRGBColor < L1375_ui_TargetRGBColor - 1) {
                                                *L1378_pui_PaletteRegister += 512;
                                        } else {
                                                *L1378_pui_PaletteRegister += 256;
                                        }
                                }
                        }
                }
#ifdef MEDIA433_A20E_A20F_A20G_A21E_A22E_A22G
                M526_WaitVerticalBlank();
#endif
#ifdef MEDIA410_A20ED
                WaitBOVP(&G0734_ps_AmigaData->ViewPort);
#endif
                F0508_AMIGA_BuildPaletteChangeCopperList(G1016_aui_Palette_FadeTemporary, G1016_aui_Palette_FadeTemporary);
        }
#endif
#ifdef MEDIA607_X30J_X31J
        F1016_SetPalette(P0849_pui_TargetColorPalette);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        for (L1376_i_Color = 0, L3394_pui_ = G3206_; L1376_i_Color < 32; L1376_i_Color++) {
                G3161_ac_Buffer724Bytes->_aui_Palette_0x208[L1376_i_Color] = *L3394_pui_++;
        }
        F1127_TransitionFromPaletteToPalette(P0849_pui_TargetColorPalette, G3161_ac_Buffer724Bytes->_aui_Palette_0x208);
#endif
}

#ifdef MEDIA351_G14ED_G20E_G21E
void F2163_SetBorderColor(P6043_i_BorderColorIndex)
int16_t P6043_i_BorderColorIndex;
{
        F0693_WaitVerticalBlank();
        asm {
                SEP        #0x30
                LDA        0xc034   /* Border color register */
                AND        #0xf0
                ORA        P6043_i_BorderColorIndex
                STA        0xc034   /* Border color register */
                REP        #0x30
        }
}
#endif

#ifdef MEDIA772_SU1E
#if (EXETYPE != C02_LAUNCHER)
#if ((EXETYPE == C06_CEDT) || (EXETYPE == C05_ANIM))
void F1779_SwapPalette(
unsigned int16_t* P5517_pui_Palette)
{
        register unsigned int16_t* L5252_pui_PaletteRegister;
        register unsigned int16_t L5253_ui_ColorIndex;
        register long L5254_l_SupervisorStack;
        unsigned int16_t L5255_aui_Palette[16];


        L5252_pui_PaletteRegister = (unsigned int16_t*)0xFFFF8240;
        L5254_l_SupervisorStack = Super(0L);
        L5253_ui_ColorIndex = 0;
        while (L5253_ui_ColorIndex < 16) {
                L5255_aui_Palette[L5253_ui_ColorIndex++] = *L5252_pui_PaletteRegister++;
        }
        Super(L5254_l_SupervisorStack);
        Setpalette(P5517_pui_Palette);
        M526_WaitVerticalBlank();
        for (L5253_ui_ColorIndex = 0; L5253_ui_ColorIndex < 16; L5253_ui_ColorIndex++) {
                P5517_pui_Palette[L5253_ui_ColorIndex] = L5255_aui_Palette[L5253_ui_ColorIndex];
        }
}
#endif
#endif
#endif
#endif
