#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA042_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_00_OPTIMIZATION */
#ifndef NOCOPYPROTECTION
char G0295_ac_FuzzySectorReadingBuffer_CPSE[512];
#endif
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
#ifndef NOCOPYPROTECTION
char G0295_ac_FuzzySectorReadingBuffer_CPSE[709];
#endif
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_00_OPTIMIZATION Increased sector 7 read buffer size to 1024 bytes instead of 512 bytes but only the first 512 bytes are used */
#ifndef NOCOPYPROTECTION
char G0295_ac_FuzzySectorReadingBuffer_CPSE[1024];
#endif
#endif
#ifdef MEDIA586_X30J_P20JA_P20JB_X31J
#ifndef NOCOPYPROTECTION
char G0295_ac_FuzzySectorReadingBuffer_CPSE[256];
#endif
#endif
#ifdef MEDIA423_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
char* G1001_pc_FuzzySectorReadingBuffer_CPSE; /* In Amiga versions, buffer is dynamically allocated in order to use chip memory (required for DMA transfer) */
#endif
#endif
unsigned char* G0296_puc_Bitmap_Viewport;
BOOLEAN G0297_B_DrawFloorAndCeilingRequested = C1_TRUE;
#ifdef MEDIA728_I34E_I34M_A36M_A35E_A35M
unsigned char G2040_auc_MemoryFlags[6]; /* Flags drawn when "mem" typed in game. First flag is G0661_B_LargeHeapMemory in Atari ST version */
#endif
#ifdef MEDIA047_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
BOOLEAN G0298_B_NewGame;
#endif
#ifdef MEDIA707_I34E_I34M
BOOLEAN G0298_B_NewGame = C001_MODE_LOAD_DUNGEON;
#endif
unsigned int16_t G0299_ui_CandidateChampionOrdinal;
BOOLEAN G0300_B_PartyIsResting;
BOOLEAN G0301_B_GameTimeTicking;
BOOLEAN G0302_B_GameWon;
BOOLEAN G0303_B_PartyDead;
int16_t G0304_i_DungeonViewPaletteIndex;
unsigned int16_t G0305_ui_PartyChampionCount;
int16_t G0306_i_PartyMapX;
int16_t G0307_i_PartyMapY;
int16_t G0308_i_PartyDirection;
int16_t G0309_i_PartyMapIndex;
int16_t G0310_i_DisabledMovementTicks;
int16_t G0311_i_ProjectileDisabledMovementTicks;
unsigned int16_t G0312_i_LastProjectileDisabledMovementDirection;
unsigned long G0313_ul_GameTime;
#ifdef MEDIA153_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
int16_t G0314_i_SectorsReadRequested_CPSDF;
int16_t G0315_i_SectorsReadFailure_CPSDF;
int16_t G0316_i_SectorsReadPreviousFailure_CPSDF;
#endif
#endif
int16_t G0317_i_WaitForInputVerticalBlankCount;
int16_t G0318_i_WaitForInputMaximumVerticalBlankCount;
#ifdef MEDIA115_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_P20JA_P20JB_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
unsigned long G0319_ul_LoadGameTime;
#endif
#endif
#ifdef MEDIA386_G14ED_F20E_F20J_X30J_I34E_I34M_A36M_F31E_F31J_X31J_P31J
unsigned long G0319_ul_LoadGameTime;
#endif
#ifdef MEDIA171_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A31E_A31M_A33M_A35E_A35M
int16_t G0320_i_Unreferenced; /* BUG0_00 Useless code */
#endif
#ifdef MEDIA503_F20E_F20J_P20JB_F31E_F31J
BOOLEAN G2024_B_PendingMusicOn = C1_TRUE;
#endif
#ifdef MEDIA709_I34E_I34M_P31J
BOOLEAN G2024_B_PendingMusicOn = C0_FALSE;
#endif
#ifdef MEDIA480_P20JB_I34E_I34M_P31J
int16_t G2106_B_ShowMusicState = C0_FALSE;
#endif
#ifdef MEDIA670_F31E_F31J
int16_t G2106_B_ShowMusicState = C1_TRUE;
#endif
BOOLEAN G0321_B_StopWaitingForPlayerInput = C1_TRUE;
#ifdef MEDIA103_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
BOOLEAN G0322_B_PaletteSwitchingEnabled; /* Named DO_PAL_CHANGE in FM-Towns */
BOOLEAN G0323_B_EnablePaletteSwitchingRequested; /* Named WIPE_DO_PAL in FM-Towns */
#endif
#ifdef MEDIA047_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
BOOLEAN G0324_B_DrawViewportRequested;
#endif
BOOLEAN G0325_B_SetMousePointerToObjectInMainLoop;
BOOLEAN G0326_B_RefreshMousePointerInMainLoop;
int16_t G0327_i_NewPartyMapIndex = CM1_MAP_INDEX_NONE;
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#ifndef NOCOPYPROTECTION
int16_t G0328_i_TimeBombToKillParty_CPSF;
#endif
#endif
#ifdef MEDIA150_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
int16_t G0329_i_Useless_CPSD; /* BUG0_00 Useless code */
#endif
#endif
#ifdef MEDIA067_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB_A31E_A31M_A33M_A35E_A35M_X31J
#ifndef NOCOPYPROTECTION
int16_t G0330_i_StopExpiringEvents_CPSE;
#endif
#endif
BOOLEAN G0331_B_PressingEye;
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
BOOLEAN G0332_B_StopPressingEye;
#endif
BOOLEAN G0333_B_PressingMouth;
#ifdef MEDIA022_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_A31E_A31M_A33M_F31E_F31J_X31J_P31J
BOOLEAN G0334_B_StopPressingMouth;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t G2152_B_PressingClosedImaginaryFakeWall;
#endif
#ifdef MEDIA622_A31E_A31M_A33M_F31E_F31J_X31J_P31J
BOOLEAN G2229_B_StopPressingClosedImaginaryFakeWall;
#endif
#ifdef MEDIA020_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB
unsigned int16_t G0335_ui_SelectedDialogChoice;
int16_t G0336_i_HighlightBoxX1;
int16_t G0337_i_HighlightBoxX2;
int16_t G0338_i_HighlightBoxY1;
int16_t G0339_i_HighlightBoxY2;
BOOLEAN G0340_B_HighlightBoxInversionRequested;
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t G2012_HighlightedZone[4];
BOOLEAN G2150_B_;
#endif
BOOLEAN G0341_B_HighlightBoxEnabled;
BOOLEAN G0342_B_RefreshDungeonViewPaletteRequested;
unsigned char* G0343_puc_Graphic_DialogBox;
#ifdef MEDIA153_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_A31E_A31M_A33M_A35E_A35M
#ifndef NOCOPYPROTECTION
int16_t G0344_ai_CodePatch1_CPSE[34];
#endif
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
#ifndef NOCOPYPROTECTION
char G0344_ai_CodePatch1_CPSE[289];
#endif
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
int16_t G4144_HPAL1[16];
int16_t G4145_HPAL2[16];
#endif
#ifdef MEDIA051_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_F31E_F31J_X31J
unsigned int16_t G0345_aui_BlankBuffer[32];
#endif
#ifdef MEDIA170_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
unsigned int16_t G0346_aui_Palette_MiddleScreen[16];
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
unsigned int16_t* G3949_pui_Palette_MiddleScreen = (unsigned int16_t*)0x00E19E00;
unsigned int16_t* G4049_pui_Palette_ = (unsigned int16_t*)0x00E19E20;
unsigned char* G0348_Bitmap_Screen = (unsigned char*)0x00E12000;
unsigned long G0349_ul_LastRandomNumber;
#endif
#ifdef MEDIA152_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
unsigned int16_t G0347_aui_Palette_TopAndBottomScreen[16];
#endif
#ifdef MEDIA607_X30J_X31J
unsigned char* G0348_Bitmap_Screen;
#endif
#ifdef MEDIA692_X31J
BOOLEAN G3076_B_ = C1_TRUE;
#endif
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
long* G0348_Bitmap_Screen = Logbase();
unsigned long G0349_ul_LastRandomNumber = Random();
BOOLEAN G0350_B_SwitchToTopBottomPalette;
#endif
#ifdef MEDIA577_X30J
unsigned char* G3090_X68000VideoMemoryAddress = (unsigned char*)0xC07090;
#endif
#ifdef MEDIA692_X31J
unsigned char* G3090_X68000VideoMemoryAddress = NULL;
unsigned char* G3118_;
#endif
#ifdef MEDIA607_X30J_X31J
unsigned int16_t G3089_ = 0x400;
#endif
#ifdef MEDIA551_F20E_F20J_F31E_F31J
unsigned long G0349_ul_LastRandomNumber = 31459;
#endif
#ifdef MEDIA591_X30J_P20JA_P20JB_I34E_I34M_X31J_P31J
unsigned long G0349_ul_LastRandomNumber = 0;
#endif
#ifdef MEDIA577_X30J
int16_t G3042_ai_XYZ_X68000Screen[4] = { 0, 455, 0, 255 };
#endif
#ifdef MEDIA692_X31J
int16_t G3042_ai_XYZ_X68000Screen[4] = { 0, 0, 456, 256 };
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_01_FIX */
int16_t G0351_i_ConcurrentVerticalBlankExceptionCount;
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
struct GfxBase* GfxBase = NULL;
long G1000_l_ScreenWordCount = 8000; /* Number of words for 320x200 pixels */
#ifdef MEDIA448_A21E_A22E
long G1141_l_Unreferenced;
#endif
#ifndef NOCOPYPROTECTION
struct Interrupt* G1110_ps_Interrupt_CPSX;
#endif
struct Interrupt* G1113_ps_Interrupt;
struct IntuitionBase* IntuitionBase;
char G1078_ac_AlertMsg[84];
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
int16_t G2199_Unreferenced;
char G2200_Unreferenced[64];
int16_t G2201_Unreferenced;
char G2202_Unreferenced[64];
#endif
#ifdef MEDIA462_P20JA_P20JB_I34E_I34M
int16_t G2203_Unreferenced;
#endif
#ifdef MEDIA707_I34E_I34M
BOOLEAN G2151_ExitGameImmediately;
#endif


#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
overlay "main"
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
segment "main"
#endif

#ifdef MEDIA613_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
#include "IMAGE.C"
#endif

#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
void F0006_MAIN_HighlightScreenBox(
P0001_i_X1, P0002_i_X2, P0003_i_Y1, P0004_i_Y2)
int16_t P0001_i_X1 SEPARATOR
int16_t P0002_i_X2 SEPARATOR
int16_t P0003_i_Y1 SEPARATOR
int16_t P0004_i_Y2 FINAL_SEPARATOR
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        asm {
                        movem.l D4-D7,-(A7)
                        movea.l G0348_Bitmap_Screen(A4),A0
                        move.w  P0003_i_Y1(A6),D5
                        move.w  P0004_i_Y2(A6),D0
                        sub.w   D5,D0
                        mulu.w  #C160_BYTE_WIDTH_SCREEN,D5
                        adda.w  D5,A0
                        move.w  P0001_i_X1(A6),D5
                        move.w  D5,D6
                        lsr.w   #1,D5
                        andi.w  #0x00F8,D5
                        move.w  D5,D7
                        adda.w  D5,A0
                        addq.l  #4,A0
                        andi.w  #0x000F,D6
                        move.w  #-0x0001,D3
                        move.w  D3,D4
                        lsr.w   D6,D3
                        move.w  P0002_i_X2(A6),D5
                        move.w  D5,D6
                        lsr.w   #1,D6
                        andi.w  #0x00F8,D6
                        andi.w  #0x000F,D5
                        neg.w   D5
                        addi.w  #0x000F,D5
                        lsl.w   D5,D4
                        cmp.w   D6,D7
                        beq.s   T0006004
                        move.w  D6,D1
                        sub.w   D7,D1
                        subq.w  #8,D1
                        lsr.w   #3,D1
                T0006001:
                        lea     C160_BYTE_WIDTH_SCREEN(A0),A1
                        move.w  (A0),D5
                        move.w  D5,D6
                        not.w   D5
                        and.w   D3,D5
                        move.w  D3,D7
                        not.w   D7
                        and.w   D7,D6
                        or.w    D5,D6
                        move.w  D6,(A0)
                        addq.l  #8,A0
                        move.w  D1,D2
                        bra.s   T0006003
                T0006002:
                        not.w   (A0)
                        addq.l  #8,A0
                T0006003:
                        dbf     D2,T0006002
                        move.w  (A0),D5
                        move.w  D5,D6
                        not.w   D5
                        and.w   D4,D5
                        move.w  D4,D7
                        not.w   D7
                        and.w   D7,D6
                        or.w    D5,D6
                        move.w  D6,(A0)
                        movea.l A1,A0
                        dbf     D0,T0006001
                        bra.s   T0006006_Return
                T0006004:
                        and.w   D4,D3
                T0006005:
                        move.w  (A0),D5
                        move.w  D5,D6
                        not.w   D5
                        and.w   D3,D5
                        move.w  D3,D7
                        not.w   D7
                        and.w   D7,D6
                        or.w    D5,D6
                        move.w  D6,(A0)
                        lea     C160_BYTE_WIDTH_SCREEN(A0),A0
                        dbf     D0,T0006005
                T0006006_Return:
                        movem.l (A7)+,D4-D7
        }
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        unsigned char* L6200_;
        char L6202_;
        char L6203_;
        int16_t L6201_;
        unsigned int16_t L6204_;


        L6200_ = G0348_Bitmap_Screen + (P0003_i_Y1 * C160_BYTE_WIDTH_SCREEN) + (P0001_i_X1 >> 1);
        L6201_ = (P0002_i_X2 >> 1) - (P0001_i_X1 >> 1);
        if (P0001_i_X1 % 2) {
                L6202_ = 0x04;
        } else {
                L6202_ = 0x44;
        }
        if (P0002_i_X2 % 2) {
                L6203_ = 0x44;
        } else {
                L6203_ = 0x40;
        }
        if (L6201_ == 0) {
                if (P0001_i_X1 == P0002_i_X2) {
                        if (P0002_i_X2 % 2) {
                                L6203_ = 0x04;
                        } else {
                                L6203_ = 0x40;
                        }
                } else {
                        L6203_ = 0x44;
                }
        }
        L6204_ = P0004_i_Y2 - P0003_i_Y1;
        asm {
                L0201F0:
                        SEP        #0x20
                        LDY        L6201_
                        BNE        L0201FE
                        LDA        [L6200_]
                        EOR        L6203_
                        STA        [L6200_]
                        BRA        L020216
                L0201FE:
                        LDA        [L6200_],Y
                        EOR        L6203_
                        STA        [L6200_],Y
                        DEY
                        BEQ        L020210
                L020207:
                        LDA        [L6200_],Y
                        EOR        #0x44
                        STA        [L6200_],Y
                        DEY
                        BNE        L020207
                L020210:
                        LDA        [L6200_],Y
                        EOR        L6202_
                        STA        [L6200_],Y
                L020216:
                        REP        #0x20
                        DEC        L6204_
                        BMI        L02022A
                        CLC
                        LDA        L6200_
                        ADC        #C160_BYTE_WIDTH_SCREEN
                        STA        L6200_
                        BCC        L0201F0
                        INC        L6200_+2
                        BRA        L0201F0
                L02022A:
        }
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        AztecCDirective_asm
                        movem.l D4-D7,-(A7)
                        movea.l _G0348_Bitmap_Screen,A0
                        move.l _G1000_l_ScreenWordCount,D5
                        lsl.l   #1,D5
                        adda.l  D5,A0
                        move.w  12(A5),D5               ; P0003_i_Y1
                        move.w  14(A5),D0               ; P0004_i_Y2
                        sub.w   D5,D0
                        mulu.w  #40,D5
                        adda.w  D5,A0
                        move.w  8(A5),D5                ; P0001_i_X1
                        move.w  D5,D6
                        lsr.w   #3,D5
                        andi.w  #$00FE,D5
                        move.w  D5,D7
                        adda.w  D5,A0
                        andi.w  #$000F,D6
                        move.w  #-$0001,D3
                        move.w  D3,D4
                        lsr.w   D6,D3
                        move.w  10(A5),D5               ; P0002_i_X2
                        move.w  D5,D6
                        lsr.w   #3,D6
                        andi.w  #$00FE,D6
                        andi.w  #$000F,D5
                        neg.w   D5
                        addi.w  #$000F,D5
                        lsl.w   D5,D4
                        cmp.w   D6,D7
                        beq.s   T0006004
                        move.w  D6,D1
                        sub.w   D7,D1
                        subq.w  #2,D1
                        lsr.w   #1,D1
                T0006001:
                        lea     40(A0),A1
                        move.w  (A0),D5
                        move.w  D5,D6
                        not.w   D5
                        and.w   D3,D5
                        move.w  D3,D7
                        not.w   D7
                        and.w   D7,D6
                        or.w    D5,D6
                        move.w  D6,(A0)
                        addq.l  #2,A0
                        move.w  D1,D2
                        bra.s   T0006003
                T0006002:
                        not.w   (A0)
                        addq.l  #2,A0
                T0006003:
                        dbf     D2,T0006002
                        move.w  (A0),D5
                        move.w  D5,D6
                        not.w   D5
                        and.w   D4,D5
                        move.w  D4,D7
                        not.w   D7
                        and.w   D7,D6
                        or.w    D5,D6
                        move.w  D6,(A0)
                        movea.l A1,A0
                        dbf     D0,T0006001
                        bra.s   T0006006_Return
                T0006004:
                        and.w   D4,D3
                T0006005:
                        move.w  (A0),D5
                        move.w  D5,D6
                        not.w   D5
                        and.w   D3,D5
                        move.w  D3,D7
                        not.w   D7
                        and.w   D7,D6
                        or.w    D5,D6
                        move.w  D6,(A0)
                        lea     40(A0),A0
                        dbf     D0,T0006005
                T0006006_Return:
                        movem.l (A7)+,D4-D7
        AztecCDirective_endasm
#endif
}
#endif

#ifdef MEDIA613_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
#include "INVRTZON.C"
#endif

#ifdef MEDIA139_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
#include "COPYBYTE.C"
#endif
#ifdef MEDIA016_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
#include "CLEARBYT.C"
#endif

void F0009_MAIN_WriteSpacedBytes(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0010_pc_Buffer, P0011_ui_ByteCount, P0012_c_ByteValue, P0013_i_Spacing)
#endif
#ifdef MEDIA034_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER char*            P0010_pc_Buffer    SEPARATOR
REGISTER unsigned int16_t P0011_ui_ByteCount SEPARATOR
REGISTER char             P0012_c_ByteValue  SEPARATOR
REGISTER int16_t          P0013_i_Spacing    FINAL_SEPARATOR
#endif
#ifdef MEDIA744_A36M
register char*            P0010_pc_Buffer    SEPARATOR
register unsigned int16_t P0011_ui_ByteCount SEPARATOR
register char             P0012_c_ByteValue  SEPARATOR
register int16_t          P0013_i_Spacing    FINAL_SEPARATOR
#endif
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E /* Probably fully written in assembly in original source code (machine code identical to Amiga/X68000 versions, except registers used) */
        if (P0013_i_Spacing != 1) {
                do {
                        *P0010_pc_Buffer = P0012_c_ByteValue;
                        asm {
                                adda.w P0013_i_Spacing,P0010_pc_Buffer
                        }
                } while (--P0011_ui_ByteCount);
        } else {
                do {
                        *P0010_pc_Buffer++ = P0012_c_ByteValue;
                } while (--P0011_ui_ByteCount);
        }
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        asm {
                        LDX        P0011_ui_ByteCount
                L020266:
                        SEP        #0x30
                        LDA        P0012_c_ByteValue
                        STA        [P0010_pc_Buffer]
                        REP        #0x30
                        CLC
                        LDA        P0010_pc_Buffer
                        ADC        P0013_i_Spacing
                        STA        P0010_pc_Buffer
                        BCC        L020279
                        INC        P0010_pc_Buffer+2
                L020279:
                        DEX
                        BNE        L020266
        }
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        AztecCDirective_asm
                        cmpi.w  #1,d6           ; P0013_i_Spacing
                        beq.s   T0009001
                T0009000:
                        move.b  d5,(a2)         ; P0012_c_ByteValue, P0010_pc_Buffer
                        adda.w  d6,a2           ; P0013_i_Spacing, P0010_pc_Buffer
                        subq.w  #1,d4           ; P0011_ui_ByteCount
                        bne.s   T0009000
                        bra.s   T0009002
                T0009001:
                        move.b  d5,(a2)+        ; P0012_c_ByteValue, P0010_pc_Buffer
                        subq.w  #1,d4           ; P0011_ui_ByteCount
                        bne.s   T0009001
                T0009002:
        AztecCDirective_endasm
#endif
#ifdef MEDIA613_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
        asm {
                        cmpi.w  #1,d5           ; P0013_i_Spacing
                        beq.s   @T0009001
                @T0009000:
                        move.b  d6,(a4)         ; P0012_c_ByteValue, P0010_pc_Buffer
                        adda.w  d5,a4           ; P0013_i_Spacing, P0010_pc_Buffer
                        subq.w  #1,d7           ; P0011_ui_ByteCount
                        bne.s   @T0009000
                        bra.s   @T0009002
                @T0009001:
                        move.b  d6,(a4)+        ; P0012_c_ByteValue, P0010_pc_Buffer
                        subq.w  #1,d7           ; P0011_ui_ByteCount
                        bne.s   @T0009001
                @T0009002:
        }
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        int16_t L2159_i_Counter;
        int16_t L2160_i_ByteIndex;


        for (L2160_i_ByteIndex = 0, L2159_i_Counter = 0; L2159_i_Counter < P0011_ui_ByteCount; L2160_i_ByteIndex += P0013_i_Spacing, L2159_i_Counter++) {
                P0010_pc_Buffer[L2160_i_ByteIndex] = P0012_c_ByteValue;
        }
#endif
}

void F0010_MAIN_WriteSpacedWords(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0014_pi_Buffer, P0015_ui_WordCount, P0016_i_WordValue, P0017_i_Spacing)
#endif
REGISTER int16_t*          P0014_pi_Buffer    SEPARATOR
REGISTER unsigned int16_t  P0015_ui_WordCount SEPARATOR
REGISTER int16_t           P0016_i_WordValue  SEPARATOR
REGISTER int16_t           P0017_i_Spacing    FINAL_SEPARATOR
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E /* Probably fully written in assembly in original source code (machine code identical to Amiga/X68000 versions, except registers used) */
        if (P0017_i_Spacing != 2) {
                do {
                        *P0014_pi_Buffer = P0016_i_WordValue;
                        asm {
                                adda.w P0017_i_Spacing,P0014_pi_Buffer
                        }
                } while (--P0015_ui_WordCount);
        } else {
                do {
                        *P0014_pi_Buffer++ = P0016_i_WordValue;
                } while (--P0015_ui_WordCount);
        }
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        asm {
                        LDX        P0015_ui_WordCount
                L020291:
                        LDA        P0016_i_WordValue
                        STA        [P0014_pi_Buffer]
                        CLC
                        LDA        P0014_pi_Buffer
                        ADC        P0017_i_Spacing
                        STA        P0014_pi_Buffer
                        BCC        L0202A0
                        INC        P0014_pi_Buffer+2
                L0202A0:
                        DEX
                        BNE        L020291
        }
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        AztecCDirective_asm
                        cmpi.w  #2,d6           ; P0017_i_Spacing
                        beq.s   T0010001
                T0010000:
                        move.w  d5,(a2)         ; P0016_i_WordValue, P0014_pi_Buffer
                        adda.w  d6,a2           ; P0017_i_Spacing, P0014_pi_Buffer
                        subq.w  #1,d4           ; P0015_ui_WordCount
                        bne.s   T0010000
                        bra.s   T0010002
                T0010001:
                        move.w  d5,(a2)+        ; P0016_i_WordValue, P0014_pi_Buffer
                        subq.w  #1,d4           ; P0015_ui_WordCount
                        bne.s   T0010001
                T0010002:
        AztecCDirective_endasm
#endif
#ifdef MEDIA613_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J
        asm {
                        cmpi.w  #2,d5           ; P0017_i_Spacing
                        beq.s   @T0010001
                @T0010000:
                        move.w  d6,(a4)         ; P0016_i_WordValue, P0014_pi_Buffer
                        adda.w  d5,a4           ; P0017_i_Spacing, P0014_pi_Buffer
                        subq.w  #1,d7           ; P0015_ui_WordCount
                        bne.s   @T0010000
                        bra.s   @T0010002
                @T0010001:
                        move.w  d6,(a4)+        ; P0016_i_WordValue, P0014_pi_Buffer
                        subq.w  #1,d7           ; P0015_ui_WordCount
                        bne.s   @T0010001
                @T0010002:
        }
#endif
#ifdef MEDIA496_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        int16_t L2161_i_Counter;
        int16_t L2162_i_WordIndex;


        for (L2162_i_WordIndex = 0, P0017_i_Spacing >>= 1, L2161_i_Counter = 0; L2161_i_Counter < P0015_ui_WordCount; L2162_i_WordIndex += P0017_i_Spacing, L2161_i_Counter++) {
                P0014_pi_Buffer[L2162_i_WordIndex] = P0016_i_WordValue;
        }
#endif
}

#ifdef MEDIA351_G14ED_G20E_G21E
#include "COPYBYTE.C"
#endif

#ifdef MEDIA388_G20E_G21E
/* New-Video register (location $C029)
Bit     Function
7       Enables Super Hi-Res graphics display
6       Enables linear mapping for Super Hi-Res graphics
5       Inhibits color in standard Apple II displays
1-4     (reserved)
0       Enables bank latch (used by system) */
asm(F2147_EnableSuperHiResGraphics) {
        SEP        #0x30
        LDA        0xc029       /* NEWVIDEO */
        AND        #0x1f        /* Keep bits 0-4 only */
        ORA        #0xc0        /* Set bits 6 and 7 */
        STA        0xc029       /* NEWVIDEO */
        REP        #0x30
        RTL
}

asm(F2148_DisableSuperHiResGraphics) {
        SEP        #0x30
        LDA        0xc029       /* NEWVIDEO */
        AND        #0x1f        /* Keep bits 0-4 only */
        ORA        #0x40        /* Set bit 6 */
        STA        0xc029       /* NEWVIDEO */
        REP        #0x30
        RTL
}
#endif

#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
asm {
        V0011000_A4RegisterBackup:
                dc.l 0L                                                         /* Backup copy of A4 register (pointing to DATA/BSS). This is used in exception handlers */
        V0012000_A5RegisterBackup:
                dc.l 0L                                                         /* Backup copy of A5 register (pointing to JUMPTABLE). This is used in exception handlers */
        E0013_MAIN_Exception69Handler_TimerC_DoNothing:
                rte                                                             /* Return from exception (Status Register is restored). This exception handler corresponds to processor interrupt #6 (ST-MFP interrupt #5). The processor sets the 'interrupt priority mask' in sr to 6 before executing this exception handler */
        E0014_MAIN_Exception70Handler_KeyboardMIDI:                             /* This exception handler corresponds to processor interrupt #6 (ST-MFP interrupt #6). The processor sets the 'interrupt priority mask' in sr to 6 before executing this exception handler */
                move.w  D0,-(A7)
                move    SR,D0                                                   /* Status Register */
                andi.w  #0xF8FF,D0
                ori.w   #0x0500,D0
                move    D0,SR                                                   /* Set interrupt priority mask = 5 in Status Register. All interrupts below or equal to 5 will now be ignored. This means Horizontal Blank interrupts (level 2) and Vertical Blank interrupts (level 4) are ignored and MFP interrupts (level 6) are processed. This reduces the interrupt level of IKBD and now allows other interrupts 6 to be processed */
                move.w  (A7)+,D0
                dc.w    0x4EF9                                                  /* jmp instruction. The target address will be replaced by the default Exception Vector 70 Handler */
        V0014000_JMPTargetAddress:
                dc.l    0x00000000
        E0015_MAIN_Exception72Handler_TimerB_PaletteSwitcher:                   /* This exception handler corresponds to processor interrupt #6 (ST-MFP interrupt #8). The processor sets the 'interrupt priority mask' in sr to 6 before executing this exception handler */
                movem.l A0/A4,-(A7)
                movea.l V0011000_A4RegisterBackup(PC),A4                        /* Restore A4 */
                movea.w #0xFA00,A0                                              /* Base address of the MFP is 0xFFFFFA00 (movea sign extends the word address to a long address) */
                tst.w   G0350_B_SwitchToTopBottomPalette(A4)
                bne.s   T0015001                                                /* If the palette for top and bottom should be configured */
                clr.b   27(A0)                                                  /* Clear LSB of Timer B control register on the MFP. This stops Timer B (it does not count anymore) */
                move.b  #139,33(A0)                                             /* Write 139 in LSB of Timer B data register. This is the initial counter value. The timer will decrement this value at each Horizontal Blank until it reaches 1, then it produces an interrupt. The middle screen area has 139 lines */
                move.b  #8,27(A0)                                               /* Write 8 in LSB of Timer B control register on the MFP. This sets Timer B in event count mode */
                movem.l D0-D7,-(A7)
                movem.l G0346_aui_Palette_MiddleScreen(A4),D0-D7                /* Load all data registers with the color palette for the middle of the screen. 8 registers * 4 bytes/register = 32 bytes */
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_06_OPTIMIZATION */
                movem.l D0-D7,0x00FF8240                                        /* Write all data registers (the full palette) to the video palette registers */
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_06_OPTIMIZATION The correct register address is 0xFFFF8240 instead of 0x00FF8240, even if both addresses always work fine. Earlier models of Atari ST computers used a 68000 processor that has a 24 bit address bus and thus they completely ignore the most significant byte of addresses. Later models like Atari TT and Falcon used a 68030 processor that has a 32 bit address bus. However this has no consequence either because on these models the built-in MMU (Memory Management Unit) is programmed to redirect register accesses that use 24 bit addresses to the appropriate 32 bit addresses */
                movem.l D0-D7,0xFFFF8240                                        /* Write all data registers (the full palette) to the video palette registers */
#endif
                addq.w  #C1_TRUE,G0350_B_SwitchToTopBottomPalette(A4)           /* Set flag so that during the next execution of this exception, the palette will be switched to the top/bottom palette */
                bra.s   T0015002
        T0015001:
                movem.l D0-D7,-(A7)
                movem.l G0347_aui_Palette_TopAndBottomScreen(A4),D0-D7          /* Load all data registers with the color palette for the top and bottom of the screen. 8 registers * 4 bytes/register = 32 bytes */
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_06_OPTIMIZATION */
                movem.l D0-D7,0x00FF8240                                        /* Write all data registers (the full palette) to the video palette registers */
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_06_OPTIMIZATION */
                movem.l D0-D7,0xFFFF8240                                        /* Write all data registers (the full palette) to the video palette registers */
#endif
                andi.b  #0xFE,19(A0)                                            /* Clear bit 0 of LSB of Interrupt Mask Register A on the MFP. This masks interrupts for Timer B */
                andi.b  #0xFE,7(A0)                                             /* Clear bit 0 of LSB of Interrupt Enable Register A on the MFP. This disables interrupts for Timer B */
        T0015002:
                bclr    #0,15(A0)                                               /* Clear bit 0 of word of Interrupt In-Service Register A on the MFP. This marks the end of the processing of interrupt */
                movem.l (A7)+,D0-D7/A0/A4
                rte
        S0016_MAIN_DrawMousePointerHiddenScreenAreaIfNecessary_CPSDF:
#ifndef NOCOPYPROTECTION
                tst.w   G0625_i_FloppyDriveDMATimeout_CPSDF(A4)
                bpl.s   T0016001                                                /* If DMA transfer is still ongoing (> 0) or if it succeeded (= 0) */
                move.w  G0314_i_SectorsReadRequested_CPSDF(A4),D1
                or.w    D1,G0315_i_SectorsReadFailure_CPSDF(A4)                 /* Copy bits for requested sectors */
                clr.w   G0314_i_SectorsReadRequested_CPSDF(A4)                  /* Clear flags */
                clr.w   G0625_i_FloppyDriveDMATimeout_CPSDF(A4)                 /* Clear DMA error (negative value) */
        T0016001:
#endif
                tst.w   G0595_B_MousePointerVisible(A4)
                bne.s   T0016002                                                /* If mouse pointer is currently displayed */
                rts
        T0016002:
                tst.w   D0
                bne.s   T0016008_DrawMousePointerHiddenScreenArea               /* Branch if D0 != 0. If removing the mouse pointer was requested (D0 is set by E0017_MAIN_Exception28Handler_VerticalBlank_CPSDF) */
                tst.w   G0354_i_MessageAreaScrollingLineCount(A4)
                blt.s   T0016003                                                /* If there is no ongoing scrolling of the message area */
                cmpi.w  #151,D5
                bcc.s   T0016008_DrawMousePointerHiddenScreenArea               /* If mouse pointer Y >= 151. If mouse pointer is over text area */
        T0016003:
                tst.w   G0324_B_DrawViewportRequested(A4)
                beq.s   T0016006                                                /* If the viewport was not updated */
                cmpi.w  #169,D5
                bge.s   T0016006                                                /* If mouse pointer Y >= 169. If mouse pointer is not over the viewport */
                cmpi.w  #224,D4
                bge.s   T0016005                                                /* If mouse pointer X >= 224. If mouse pointer is not over the viewport */
                tst.w   G0600_B_UseObjectAsMousePointerBitmap(A4)
                beq.s   T0016004                                                /* If the mouse pointer bitmap is not an object */
                tst.w   G0602_B_CurrentMousePointerIsObject(A4)
                beq.s   T0016004                                                /* If the mouse pointer is not an object */
                cmpi.w  #23,D5
                ble.s   T0016006                                                /* If mouse pointer Y <= 23. Hotspot of an object mouse pointer is at coordinates 8,8 */
                bra.s   T0016008_DrawMousePointerHiddenScreenArea
        T0016004:
                cmpi.w  #16,D5
                blt.s   T0016006                                                /* If mouse pointer Y < 16 */
                bra.s   T0016008_DrawMousePointerHiddenScreenArea
        T0016005:
                tst.w   G0600_B_UseObjectAsMousePointerBitmap(A4)
                beq.s   T0016006
                cmpi.w  #28,D5
                bgt.s   T0016006                                                /* If mouse pointer Y > 28 */
                cmpi.w  #23,D5
                ble.s   T0016006                                                /* If mouse pointer Y <= 23 */
                cmpi.w  #232,D4
                blt.s   T0016008_DrawMousePointerHiddenScreenArea               /* If mouse pointer X <= 232 */
        T0016006:
                tst.w   G0340_B_HighlightBoxInversionRequested(A4)
                beq.s   T0016007                                                /* If no box is inversed */
                cmpi.w  #192,D4
                bge.s   T0016008_DrawMousePointerHiddenScreenArea               /* If mouse pointer X > 192 */
        T0016007:
                rts
        T0016008_DrawMousePointerHiddenScreenArea:
                moveq   #C1_TRUE,D0                                             /* Mouse pointer is no more on screen and must be drawn later in E0017_MAIN_Exception28Handler_VerticalBlank_CPSDF */
                jsr     S0072_MOUSE_DrawPointerHiddenScreenArea(PC)
                rts
        E0017_MAIN_Exception28Handler_VerticalBlank_CPSDF:                      /* This exception handler corresponds to processor interrupt 4 (vertical blank). The processor sets the 'interrupt priority mask' in sr to 4 before executing this exception handler. This means Horizontal Blank interrupts (level 2) and other Vertical Blank interrupts (level 4) are ignored and MFP interrupts (level 6) are processed */
                movem.l D0-D5/A0/A4-A5,-(A7)
                movea.l V0011000_A4RegisterBackup(PC),A4                        /* Restore A4 */
                movea.l V0012000_A5RegisterBackup(PC),A5                        /* Restore A5 */
                tst.w   G0324_B_DrawViewportRequested(A4)
                beq.s   T0017001
                move.w  G0323_B_EnablePaletteSwitchingRequested(A4),G0322_B_PaletteSwitchingEnabled(A4)
        T0017001:                                                               /* BUG0_03 Graphical glitch. If a vertical blank interrupt occurs while processing of the previous vertical blank exception has not completed then the interrupt is ignored because of the interrupt mask automatically set by the processor when running the exception. Consequently, the palette switching code below is not executed and the dungeon view may be drawn on screen with the wrong color palette. This is only visible for a very short amount of time and disappears on the next vertical scan. The issue can occur when the processor is under heavy load because many other interrupts occur with a higher priority level than the vertical blank interrupt, such as sound processing (another interrupt that occurs thousands of times per second to play the sound) and mouse processing (another interrupt each time the mouse moves or button status changes). North American systems are more affected because the vertical blank interrupt occurs at 60 Hz rather than 50 Hz in European systems */
                tst.w   G0322_B_PaletteSwitchingEnabled(A4)
                beq.s   T0017002                                                /* If palette switching is disabled */
                clr.w   G0350_B_SwitchToTopBottomPalette(A4)
                movea.w #0xFA00,A0                                              /* This is the base address of the MFP */
                clr.b   27(A0)                                                  /* Clear LSB of Timer B control register on the MFP. This stops Timer B (it does not count anymore) */
                move.b  #31,33(A0)                                              /* Write 31 in LSB of Timer B data register. This is the initial counter value. The timer will decrement this value at each Horizontal Blank until it reaches 1, then it produces an interrupt. This is the line number where color palette will be switched (below champion status boxes and above the dungeon view) */
                move.b  #8,27(A0)                                               /* Write 8 in LSB of Timer B control register on the MFP. This sets Timer B in event count mode */
                ori.b   #1,19(A0)                                               /* Set bit 0 of LSB of Interrupt Mask Register A on the MFP. Interrupts for Timer B are not masked anymore */
                ori.b   #1,7(A0)                                                /* Set bit 0 of LSB of Interrupt Enable Register A on the MFP. This enables interrupts for Timer B */
        T0017002:
#ifdef MEDIA265_S20E_S21E /* CHANGE7_01_FIX The exception handler now changes the interrupt mask to 3 so that other vertical blank interrupts are not ignored anymore. When concurrent exceptions occur, the handler will only run the palette switching code and return after incrementing a counter for concurrent exceptions. At the end of the exception handler, if there are concurrent exceptions that were not fully processed, then they are processed in a loop. With this mechanism, vertical blank interrupts are never ignored so that the palette switching code always starts on time and the graphical glitches are avoided */
                tst.w   G0351_i_ConcurrentVerticalBlankExceptionCount(A4)
                beq.s   T0017003                                                /* If no vertical blank exception is being processed */
                addq.w  #1,G0351_i_ConcurrentVerticalBlankExceptionCount(A4)    /* If a vertical blank exception is already being processed then increment the counter and return */
                movem.l (A7)+,D0-D5/A0/A4-A5
                rte
        T0017003:
                addq.w  #1,G0351_i_ConcurrentVerticalBlankExceptionCount(A4)    /* If no vertical blank exception is being processed then increment the counter */
        T0017004_Loop:
                move    SR,D0
                andi.w  #0xF8FF,D0
                ori.w   #0x0300,D0
                move    D0,SR                                                   /* Set interrupt priority mask = 3 in Status Register. All interrupts below or equal to 3 will now be ignored. This means Horizontal Blank interrupts (level 2) are ignored, Vertical Blank interrupts (level 4) and MFP interrupts (level 6) are processed. Other Vertical Blank interrupts are not ignored anymore and G0351_i_ConcurrentVerticalBlankExceptionCount counts the number of such interrupts that occur concurrently */
#endif
                tst.w   G0596_B_NoDrawInVerticalBlankWhileHidingMousePointer(A4)
                bne     T0017019
                moveq   #0,D0
                move.l  G0590_i_MousePointerHotspotY(A4),D3                     /* The long contains both words for Y & X coordinates */
                move.l  D3,G0591_l_MousePointerYX(A4)
                move.l  D3,D2
                swap    D2
                move.w  G0603_i_MousePointerScreenAreaCurrentX(A4),D4
                move.w  G0604_i_MousePointerScreenAreaCurrentY(A4),D5
                tst.w   G0599_ui_UseChampionIconOrdinalAsMousePointerBitmap(A4)
                beq.s   T0017006                                                /* If no champion icon is being dragged */
                cmpi.w  #274,D3
                blt.s   T0017005                                                /* If mouse pointer X < 274. If the mouse pointer was dragged too far to the left */
                cmpi.w  #28,D2
                ble.s   T0017006                                                /* If mouse pointer Y <= 28. If the mouse pointer is still in the champion icons area */
        T0017005:
                movem.l D0-D3/A0-A1,-(A7)
                jsr     F0071_MOUSE_DropChampionIcon(PC)
                movem.l (A7)+,D0-D3/A0-A1
        T0017006:
                move.w  G0593_B_BuildMousePointerScreenAreaCompleted(A4),D0     /* D0 is a boolean used by S0016_MAIN_DrawMousePointerHiddenScreenAreaIfNecessary_CPSDF for 'Remove mouse pointer from screen, perform updates on screen then draw the mouse pointer back on screen' */
                clr.w   G0593_B_BuildMousePointerScreenAreaCompleted(A4)        /* Reset request to force mouse pointer removal */
                tst.w   G0592_B_BuildMousePointerScreenAreaRequested(A4)
                beq.s   T0017007
                tst.w   G0598_B_MousePointerBitmapUpdated(A4)
                bne.s   T0017007                                                /* If the mouse pointer has changed */
                cmp.w   D3,D4                                                   /* If mouse pointer has moved */
                bne.s   T0017007
                cmp.w   D2,D5                                                   /* If mouse pointer has moved */
                bne.s   T0017007
                moveq   #C1_TRUE,D0                                             /* Force mouse pointer removal and later mouse pointer draw */
                clr.w   G0592_B_BuildMousePointerScreenAreaRequested(A4)
        T0017007:
                jsr     S0016_MAIN_DrawMousePointerHiddenScreenAreaIfNecessary_CPSDF(PC)
#ifndef NOCOPYPROTECTION
                move.l  A0,-(A7)
                lea     G0078_B_FuzzyBitFound_CPSF+20(A4),A0
                tst.w   -20(A0)                                                 /* Refers to G0078_B_FuzzyBitFound_CPSF */
                bne.s   T0017008                                                /* If at least a fuzzy bit was found */
                tst.w   G0328_i_TimeBombToKillParty_CPSF(A4)
                bne.s   T0017008                                                /* If the time bomb to kill the party is already triggered */
                movem.l D0-D3/A0-A1,-(A7)
                jsr     F0106_DUNGEONVIEW_TestResetToStep1_CPSF(PC)
                movem.l (A7)+,D0-D3/A0-A1
                addq.w  #5,G0328_i_TimeBombToKillParty_CPSF(A4)                 /* Trigger the time bomb to kill the party */
        T0017008:
                movea.l (A7)+,A0
#endif
                tst.w   D0
                beq.s   T0017009                                                /* If the mouse pointer should not be drawn on screen */
                cmpi.w  #15,D2
                bhi.s   T0017009                                                /* If Mouse Y > 15 */
                jsr     S0074_MOUSE_DrawPointerScreenArea(PC)
                moveq   #C0_FALSE,D0
        T0017009:
                tst.w   G0354_i_MessageAreaScrollingLineCount(A4)
                blt.s   T0017010
                movem.l D0-D3/A0-A1,-(A7)
                move.w  #27,D1                                                  /* Number of pixel lines in the message area */
                sub.w   G0354_i_MessageAreaScrollingLineCount(A4),D1
                mulu.w  #C160_BYTE_WIDTH_SCREEN,D1                              /* Each line is 320 pixels = 160 bytes */
                move.w  D1,-(A7)
                move.l  G0348_Bitmap_Screen(A4),D1
                addi.l  #27520,D1                                               /* Start of line 172 of the screen */
                move.l  D1,-(A7)
                addi.l  #C160_BYTE_WIDTH_SCREEN,D1                              /* Scroll 1 line */
                move.l  D1,-(A7)
                jsr     F0007_MAIN_CopyBytes(PC)
                adda.w  #10,A7
                movem.l (A7)+,D0-D3/A0-A1
                bra.s   T0017011
        T0017010:
                tst.w   G0355_B_ScrollMessageArea(A4)
                beq.s   T0017013                                                /* If there is no new text line to inject at bottom of the screen */
                clr.w   G0355_B_ScrollMessageArea(A4)
        T0017011:
                moveq   #7,D1                                                   /* Height in pixels of the text line */
                tst.w   G0354_i_MessageAreaScrollingLineCount(A4)
                blt.s   T0017012                                                /* If there is no ongoing vertical scrolling of the message area */
                addq.w  #1,G0354_i_MessageAreaScrollingLineCount(A4)            /* Add one more line of scrolling until the whole new line will be displayed on screen */
                move.w  G0354_i_MessageAreaScrollingLineCount(A4),D1
                cmpi.w  #7,D1
                bne.s   T0017012
                move.w  #-1,G0354_i_MessageAreaScrollingLineCount(A4)
        T0017012:
                movem.l D0-D3/A0-A1,-(A7)
                move.w  D1,D2
                mulu.w  #C160_BYTE_WIDTH_SCREEN,D1                              /* Number of bytes to move */
                move.w  D1,-(A7)
                neg.w   D2
                addi.w  #200,D2
                mulu.w  #C160_BYTE_WIDTH_SCREEN,D2
                add.l   G0348_Bitmap_Screen(A4),D2
                move.l  D2,-(A7)
                move.l  G0356_puc_Bitmap_MessageAreaNewRow(A4),-(A7)
                jsr     F0007_MAIN_CopyBytes(PC)
                adda.w  #10,A7
                movem.l (A7)+,D0-D3/A0-A1
        T0017013:
                tst.w   G0324_B_DrawViewportRequested(A4)
                beq.s   T0017016                                                /* If viewport was not updated */
                clr.w   G0324_B_DrawViewportRequested(A4)
                movem.l D0-D7/A0-A4,-(A7)
                tst.w   G0342_B_RefreshDungeonViewPaletteRequested(A4)
                beq.s   T0017014                                                /* If the color palette for the dungeon view has not changed */
                clr.w   G0342_B_RefreshDungeonViewPaletteRequested(A4)
                lea     G0021_aaui_Graphic562_Palette_DungeonView(A4),A0        /* Address of an array of 6 color palettes for dungeon view, depending on light in the dungeon */
                move.w  G0304_i_DungeonViewPaletteIndex(A4),D0
                lsl.w   #5,D0                                                   /* Each palette in the table is 32 bytes large */
                adda.w  D0,A0                                                   /* Address of the selected palette in the array */
                movem.l (A0),D0-D7                                              /* The eight data registers are loaded with the palette data (8 registers of 4 bytes each = 32 bytes) */
                movem.l D0-D7,G0346_aui_Palette_MiddleScreen(A4)                /* The eight data registers are copied to G0346_aui_Palette_MiddleScreen, which updates the color palette used by the palette switching routine */
        T0017014:
                movea.l G0296_puc_Bitmap_Viewport(A4),A0
                movea.l G0348_Bitmap_Screen(A4),A1
                adda.w  #5280,A1                                                /* This is the starting address of the viewport area in the video memory */
                move.w  #135,D0                                                 /* The viewport has 136 lines (0 to 135) */
        T0017015:
                movem.l (A0)+,D1-D7/A2-A4                                       /* Copy 40 bytes of viewport data (80 pixels) in registers */
                movem.l D1-D7/A2-A4,(A1)                                        /* Copy 40 bytes from registers to the screen */
                movem.l (A0)+,D1-D7/A2-A4                                       /* Copy 40 bytes of viewport data (80 pixels) in registers */
                movem.l D1-D7/A2-A4,40(A1)                                      /* Copy 40 bytes from registers to the screen */
                movem.l (A0)+,D1-D7/A2                                          /* Copy 32 bytes of viewport data (64 pixels) in registers */
                movem.l D1-D7/A2,80(A1)                                         /* Copy 32 bytes from registers to the screen. 40 + 40 + 32 = 112 bytes = 224 pixels which is the viewport width */
                lea     C160_BYTE_WIDTH_SCREEN(A1),A1                           /* This is the offset where the next viewport line starts (160 bytes = 320 pixels = 1 line on screen) */
                dbf     D0,T0017015
                movem.l (A7)+,D0-D7/A0-A4
        T0017016:
                tst.w   G0340_B_HighlightBoxInversionRequested(A4)
                beq.s   T0017017                                                /* If there is no highlight box inversion request */
                clr.w   G0340_B_HighlightBoxInversionRequested(A4)              /* Disable the highlight box inversion request */
                not.w   G0341_B_HighlightBoxEnabled(A4)                         /* Value is inverted between $0000 (box is not inverted on screen) and $FFFF (box is inverted on screen) */
                movem.l D0-D3/A0-A1,-(A7)
                move.w  G0339_i_HighlightBoxY2(A4),-(A7)
                move.w  G0338_i_HighlightBoxY1(A4),-(A7)
                move.w  G0337_i_HighlightBoxX2(A4),-(A7)
                move.w  G0336_i_HighlightBoxX1(A4),-(A7)
                jsr     F0006_MAIN_HighlightScreenBox(PC)
                addq.l  #8,A7
                movem.l (A7)+,D0-D3/A0-A1
        T0017017:
                tst.w   D0
                beq.s   T0017018                                                /* If the mouse pointer should not be drawn on screen */
                jsr     S0074_MOUSE_DrawPointerScreenArea(PC)
        T0017018:
                tst.w   G0592_B_BuildMousePointerScreenAreaRequested(A4)
                beq.s   T0017019
                clr.w   G0592_B_BuildMousePointerScreenAreaRequested(A4)
                move.w  #C1_TRUE,G0593_B_BuildMousePointerScreenAreaCompleted(A4)
                clr.w   G0598_B_MousePointerBitmapUpdated(A4)
                movem.l D0-D3/A0-A1,-(A7)
                jsr     F0073_MOUSE_BuildPointerScreenArea(PC)
                movem.l (A7)+,D0-D3/A0-A1
        T0017019:
#ifndef NOCOPYPROTECTION
                tst.w   G0625_i_FloppyDriveDMATimeout_CPSDF(A4)
                ble.s   T0017020                                                /* If floppy disk transfer is complete (succeeded if = 0 or failed if < 0) */
                movea.l G0626_pfv_S0080_CPSDF_CheckDMATransferCompletion(A4),A0
                move.l  A1,-(A7)
                jsr     (A0)
                movea.l (A7)+,A1
                bra.s   T0017021
        T0017020:
                tst.w   G0624_B_FloppyDriveTurnedOn_CPSDF(A4)
                beq.s   T0017021                                                /* If the floppy drive is turned off */
                movea.l G0627_pfv_S0081_CPSDF_TurnOffFloppyDrive(A4),A0
                jsr     (A0)
        T0017021:
#endif
                addq.w  #1,G0317_i_WaitForInputVerticalBlankCount(A4)
                move.w  G0317_i_WaitForInputVerticalBlankCount(A4),D0
                cmp.w   G0318_i_WaitForInputMaximumVerticalBlankCount(A4),D0
                bls.s   T0017022                                                /* Branch if G0317_i_WaitForInputVerticalBlankCount <= G0318_i_WaitForInputMaximumVerticalBlankCount */
                move.w  #C1_TRUE,G0321_B_StopWaitingForPlayerInput(A4)          /* This flag instructs the main loop to to increment the game time. This occurs every 11 vertical blank cycles */
        T0017022:
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_01_FIX */
                movem.l (A7)+,D0-D5/A0/A4-A5
                dc.w    0x4EF9                                                  /* Call the original exception handler with a jmp instruction */
        V0017000_JMPTargetAddress:
                dc.l    0x00000000
}
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_01_FIX */
                trap    #4                                                      /* Call the original exception handler for vertical blank. A trap instruction is used instead of the jmp in previous versions so that execution continues with the next instruction when the original exception handler returns with an rte instruction */
                move    SR,D0
                andi.w  #0xF8FF,D0
                ori.w   #0x0400,D0
                move    D0,SR                                                   /* Set interrupt priority mask = 4 in Status register. All interrupts below or equal to 4 will now be ignored. This means Horizontal Blank interrupts (level 2) and Vertical Blank interrupts (level 4) are ignored and MFP interrupts (level 6) are processed. This resets the interrupt priority mask to its regular value (set by the processor before running the exception handler). The rte instruction will restore the previous value of the SR register where the interrupt priority mask is usually 3 during execution of normal code (while not in an exception handler), which will enable again Vertical Blank interrupts */
                subq.w  #1,G0351_i_ConcurrentVerticalBlankExceptionCount(A4)
                bne     T0017004_Loop
                movem.l (A7)+,D0-D5/A0/A4-A5
                rte
}
#endif

void F0018_MAIN_SetExceptionVectors(
)
{
        asm {
                lea     E0013_MAIN_Exception69Handler_TimerC_DoNothing(PC),A0
                move.l  A0,C0x0114_ADDRESS_INTERRUPT_VECTOR_5_MFP_TIMER_C                     /* Replace Exception Vector 69 (MFP timer C (200Hz) System Clock, ST-MFP interrupt #5. Points to the system clock interrupt). This effectively disables the default handler (the new one is a simple RTE) */
                lea     V0014000_JMPTargetAddress(PC),A0                                      /* Address of the target address of the JMP instruction at the end of the exception 70 Handler prefix */
                move.l  C0x0118_ADDRESS_INTERRUPT_VECTOR_6_KEYBOARD_MIDI,(A0)                 /* Copy the address of the current exception 70 handler at the end of the custom handler prefix */
                lea     E0014_MAIN_Exception70Handler_KeyboardMIDI(PC),A0
                move.l  A0,C0x0118_ADDRESS_INTERRUPT_VECTOR_6_KEYBOARD_MIDI                   /* Replace Exception Vector 70 (IKBD/MIDI, ST-MFP interrupt #6. Points to the handler for IKBD and MIDI interrupts) */
                lea     E0015_MAIN_Exception72Handler_TimerB_PaletteSwitcher(PC),A0
                move.l  A0,C0x0120_ADDRESS_INTERRUPT_VECTOR_8_TIMER_B_HORIZONTAL_BLANK        /* Replace Exception Vector 72 (MFP timer B (HBL counter), ST-MFP interrupt #8) */
#ifdef MEDIA006_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB /* CHANGE7_01_FIX */
                lea     V0017000_JMPTargetAddress(PC),A0
                move.l  C0x0070_ADDRESS_INTERRUPT_AUTOVECTOR_4_VERTICAL_BLANK,(A0)            /* Copy current Exception Vector 28 (vertical blank) in the jmp target address. The custom vertical blank handler calls the original handler via this jmp */
#endif
#ifdef MEDIA265_S20E_S21E /* CHANGE7_01_FIX The original vertical blank handler is now called via a TRAP #4 instruction instead of a jmp */
                move.l  C0x0070_ADDRESS_INTERRUPT_AUTOVECTOR_4_VERTICAL_BLANK,C0x0090_ADDRESS_INTERRUPT_VECTOR_TRAP_4 /* Copy current Exception Vector 28 (vertical blank) to Exception Vector 36 (TRAP #4). The custom vertical blank handler calls the original handler via TRAP #4 */
#endif
                lea     E0017_MAIN_Exception28Handler_VerticalBlank_CPSDF(PC),A0
                move.l  A0,C0x0070_ADDRESS_INTERRUPT_AUTOVECTOR_4_VERTICAL_BLANK              /* Replace Exception Vector 28 */
        }
}
#endif

#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
#include "BLITFILL.C"

void F0552_BASE_DisplayError(
P0976_i_ErrorNumber)
int16_t P0976_i_ErrorNumber FINAL_SEPARATOR
{
        REGISTER char* L1750_pc_String;
        REGISTER char* L1751_pc_StringBuildBuffer;


        IntuitionBase = (struct IntuitionBase*)OpenLibrary("intuition.library", 0L);
        if (IntuitionBase == NULL) {
                Alert(0x80444DFF, 0L);
        }
        strcpy(G0353_ac_StringBuildBuffer, "Dungeon Master System Error #XX");
        G0353_ac_StringBuildBuffer[29] = (P0976_i_ErrorNumber / 10) + '0';
        G0353_ac_StringBuildBuffer[30] = (P0976_i_ErrorNumber % 10) + '0';
        L1751_pc_StringBuildBuffer = G0353_ac_StringBuildBuffer;
        *((int16_t*)G1078_ac_AlertMsg) = 320 - (strlen(L1751_pc_StringBuildBuffer) * 4); /* X coordinate on two bytes */
        G1078_ac_AlertMsg[2] = 11; /* Y coordinate on 1 byte */
        for (L1750_pc_String = &G1078_ac_AlertMsg[3] /* Start of actual string */; *L1751_pc_StringBuildBuffer; L1751_pc_StringBuildBuffer++) {
                *L1750_pc_String = *L1751_pc_StringBuildBuffer;
                L1750_pc_String++;
        };
        *L1750_pc_String++ = 0; /* End of string */
        *L1750_pc_String++ = 0; /* Null continuation byte, no more substrings */
        DisplayAlert(AT_Recovery, G1078_ac_AlertMsg, 20L); /* Minimum 20 lines required */
}
#endif

#ifdef MEDIA607_X30J_X31J
#include "DRAWVIEW.C"
#endif

void F0019_MAIN_DisplayErrorAndStop(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0018_i_ErrorNumber)
#endif
int16_t P0018_i_ErrorNumber FINAL_SEPARATOR
{
#ifdef MEDIA007_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E
        Cconws("\33HSYSTEM ERROR "); /* \33H is the VT-52 command to move the mouse pointer to the top left corner. 33 (octal) = 1B (hexadecimal) = 27 (decimal) = ESC (Megamax C does not support hexadecimal character constants) */
        Cconout((P0018_i_ErrorNumber / 10) + '0');
        Cconout((P0018_i_ErrorNumber % 10) + '0');
#endif
#ifdef MEDIA349_G14ED
        F2165_PrintErrorMessage("Dungeon Master system error ->", P0018_i_ErrorNumber); /* BUGX_XX: Wrong parameters order */
#endif
#ifdef MEDIA388_G20E_G21E
        F2165_PrintErrorMessage(P0018_i_ErrorNumber, "Dungeon Master fatal error ->");
#endif
#ifdef MEDIA460_P20JA_P20JB_F31E_F31J_P31J
        F0047_TEXT_MESSAGEAREA_PrintMessage(C08_COLOR_RED, "\n\x1BSYSTEM ERROR ");
#endif
#ifdef MEDIA707_I34E_I34M
        F0047_TEXT_MESSAGEAREA_PrintMessage(C08_COLOR_RED, "\nSYSTEM ERROR ");
#endif
#ifdef MEDIA464_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J
        F0048_TEXT_MESSAGEAREA_PrintCharacter(C08_COLOR_RED, (char)((P0018_i_ErrorNumber / 10) + '0'));
        F0048_TEXT_MESSAGEAREA_PrintCharacter(C08_COLOR_RED, (char)((P0018_i_ErrorNumber % 10) + '0'));
#endif
#ifdef MEDIA607_X30J_X31J
        F1023_PrintString("SYSTEM ERROR ");
        F1022_PrintCharacter((P0018_i_ErrorNumber / 10) + '0');
        F1022_PrintCharacter((P0018_i_ErrorNumber % 10) + '0');
#endif
#ifdef MEDIA692_X31J
        F1023_PrintString("\n\r<RETURN>");
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        F0552_BASE_DisplayError(P0018_i_ErrorNumber);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        F1093_DisplayAlertCSBInternalError(P0018_i_ErrorNumber);
#endif
#ifdef MEDIA731_I34E_I34M_A36M_A35M_F31E_F31J_X31J_P31J
        F0540_INPUT_Crawcin();
#endif
#ifdef MEDIA145_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_X30J_P20JA_P20JB
        for (;;); /*_Infinite loop_*/
#endif
#ifdef MEDIA720_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        F0666_endgame();
#endif
}

#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
#ifdef MEDIA527_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_P31J
unsigned int16_t F0653_GetBitmapByteCount(
#endif
#ifdef MEDIA692_X31J
unsigned long F0653_GetBitmapByteCount(
#endif
REGISTER unsigned char* P2231_puc_Bitmap FINAL_SEPARATOR
{
        return M103_BITMAP_BYTE_COUNT(M100_PIXEL_WIDTH(P2231_puc_Bitmap), M101_PIXEL_HEIGHT(P2231_puc_Bitmap));
}

void F0654_Call_F0132_VIDEO_Blit(
REGISTER char* P2232_puc_Bitmap_Source      SEPARATOR
REGISTER char* P2233_puc_Bitmap_Destination SEPARATOR
int16_t*       P2234_pi_XYZ                 SEPARATOR
int16_t        P2235_i_X                    SEPARATOR
int16_t        P2236_i_Y                    SEPARATOR
int16_t        P2237_i_TransparentColor     FINAL_SEPARATOR
{
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        F0132_VIDEO_Blit(P2232_puc_Bitmap_Source, P2233_puc_Bitmap_Destination, P2234_pi_XYZ, P2235_i_X, P2236_i_Y, M100_PIXEL_WIDTH(P2232_puc_Bitmap_Source), M100_PIXEL_WIDTH(P2233_puc_Bitmap_Destination), P2237_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA543_F20E_F20J_X30J_F31E_F31J_X31J
        F0132_VIDEO_Blit(M774_CAST_PUC(P2232_puc_Bitmap_Source), M774_CAST_PUC(P2233_puc_Bitmap_Destination), P2234_pi_XYZ, P2235_i_X, P2236_i_Y, M100_PIXEL_WIDTH(P2232_puc_Bitmap_Source), M100_PIXEL_WIDTH(P2233_puc_Bitmap_Destination), P2237_i_TransparentColor);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        F0132_VIDEO_Blit(P2232_puc_Bitmap_Source, P2233_puc_Bitmap_Destination, P2234_pi_XYZ, P2235_i_X, P2236_i_Y, M100_PIXEL_WIDTH(P2232_puc_Bitmap_Source), M100_PIXEL_WIDTH(P2233_puc_Bitmap_Destination), P2237_i_TransparentColor, M101_PIXEL_HEIGHT(P2232_puc_Bitmap_Source), M101_PIXEL_HEIGHT(P2233_puc_Bitmap_Destination));
#endif
}
#endif

#ifdef MEDIA458_P20JA_P20JB
void F1002_Call_F0132_VIDEO_Blit(
char*    P2238_puc_Bitmap_Source      SEPARATOR
char*    P2239_puc_Bitmap_Destination SEPARATOR
int16_t* P2240_pi_XYZ                 SEPARATOR
int16_t  P2241_i_X                    SEPARATOR
int16_t  P2242_i_Y                    SEPARATOR
int16_t  P2243_i_TransparentColor     SEPARATOR
int16_t  P2244_i_Flip                 FINAL_SEPARATOR
{
        F0132_VIDEO_Blit(P2238_puc_Bitmap_Source, P2239_puc_Bitmap_Destination, P2240_pi_XYZ, P2241_i_X, P2242_i_Y, M100_PIXEL_WIDTH(P2238_puc_Bitmap_Source), M100_PIXEL_WIDTH(P2239_puc_Bitmap_Destination), P2243_i_TransparentColor, P2244_i_Flip);
}
#endif

#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
void F0655_CopyBitmapAndFlip(
unsigned char* P2245_puc_Bitmap_Source      SEPARATOR
unsigned char* P2246_puc_Bitmap_Destination SEPARATOR
int16_t        P2247_i_Flip                 FINAL_SEPARATOR
{
        int16_t L2163_i_Width;
        int16_t L2164_i_Height;
#ifdef MEDIA458_P20JA_P20JB
        int16_t L2165_ai_XYZ[4];


        M704_ZONE_LEFT(L2165_ai_XYZ) = 0;
        M706_ZONE_TOP(L2165_ai_XYZ) = 0;
        M705_ZONE_RIGHT(L2165_ai_XYZ) = (L2163_i_Width = M100_PIXEL_WIDTH(P2245_puc_Bitmap_Source)) - 1;
        M707_ZONE_BOTTOM(L2165_ai_XYZ) = (L2164_i_Height = M101_PIXEL_HEIGHT(P2245_puc_Bitmap_Source)) - 1;
#endif
#ifdef MEDIA709_I34E_I34M_P31J
        L2163_i_Width = M100_PIXEL_WIDTH(P2245_puc_Bitmap_Source);
        L2164_i_Height = M101_PIXEL_HEIGHT(P2245_puc_Bitmap_Source);
#endif
        F0615_CopyBitmapDimensions(P2245_puc_Bitmap_Source, P2246_puc_Bitmap_Destination);
#ifdef MEDIA458_P20JA_P20JB
        F0132_VIDEO_Blit(P2245_puc_Bitmap_Source, P2246_puc_Bitmap_Destination, L2165_ai_XYZ, 0, 0, L2163_i_Width, L2163_i_Width, CM1_COLOR_NO_TRANSPARENCY, P2247_i_Flip);
#endif
#ifdef MEDIA709_I34E_I34M_P31J
        F0132_VIDEO_Blit(P2245_puc_Bitmap_Source, P2246_puc_Bitmap_Destination, F0627_GetTemporaryZoneInitializedFromDimensions(L2163_i_Width, L2164_i_Height), 0, 0, L2163_i_Width, L2163_i_Width, CM1_COLOR_NO_TRANSPARENCY, P2247_i_Flip);
#endif
}
#endif

void F0020_MAIN_BlitToViewport(
#ifdef MEDIA008_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E
P0019_puc_Bitmap, P0020_pi_Box, P0021_i_BitmapByteWidth, P0022_i_TransparentColor)
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0019_puc_Bitmap, P0020_pi_Box, P0021_i_BitmapByteWidth, P0022_i_TransparentColor, P0917_i_Height)
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
unsigned char*          P0019_puc_Bitmap         SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
REGISTER unsigned char* P0019_puc_Bitmap         SEPARATOR
#endif
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t*                P0020_pi_Box             SEPARATOR
int16_t                 P0021_i_BitmapByteWidth  SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t*                P2248_pi_XYZ             SEPARATOR
#endif
#ifdef MEDIA099_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t                 P0022_i_TransparentColor FINAL_SEPARATOR
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t                 P0022_i_TransparentColor SEPARATOR
int16_t                 P0917_i_Height           FINAL_SEPARATOR
#endif
{
#ifdef MEDIA008_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E
        G0578_B_UseByteBoxCoordinates = C0_FALSE, F0132_VIDEO_Blit(P0019_puc_Bitmap, G0296_puc_Bitmap_Viewport, P0020_pi_Box, 0, 0, P0021_i_BitmapByteWidth, C112_BYTE_WIDTH_VIEWPORT, P0022_i_TransparentColor);
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        G0578_B_UseByteBoxCoordinates = C0_FALSE, F0132_VIDEO_Blit(P0019_puc_Bitmap, G0296_puc_Bitmap_Viewport, P0020_pi_Box, 0, 0, P0021_i_BitmapByteWidth, C112_BYTE_WIDTH_VIEWPORT, P0022_i_TransparentColor, P0917_i_Height, C136_HEIGHT_VIEWPORT);
#endif
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        F0132_VIDEO_Blit(P0019_puc_Bitmap, G0296_puc_Bitmap_Viewport, P2248_pi_XYZ, 0, 0, M100_PIXEL_WIDTH(P0019_puc_Bitmap), G2073_C224_ViewportPixelWidth, P0022_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA543_F20E_F20J_X30J_F31E_F31J_X31J
        F0132_VIDEO_Blit(P0019_puc_Bitmap, G0296_puc_Bitmap_Viewport, P2248_pi_XYZ, 0, 0, M100_PIXEL_WIDTH(P0019_puc_Bitmap), G2073_C224_ViewportPixelWidth, P0022_i_TransparentColor);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        F0132_VIDEO_Blit(P0019_puc_Bitmap, G0296_puc_Bitmap_Viewport, P2248_pi_XYZ, 0, 0, M100_PIXEL_WIDTH(P0019_puc_Bitmap), G2073_C224_ViewportPixelWidth, P0022_i_TransparentColor, M101_PIXEL_HEIGHT(P0019_puc_Bitmap), G2074_C136_ViewportHeight);
#endif
}

#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void F0656_BlitBitmapToViewportZoneIndexWithTransparency(
unsigned char* P2249_puc_Bitmap         SEPARATOR
int16_t        P2250_i_ZoneIndex        SEPARATOR
int16_t        P2251_i_TransparentColor FINAL_SEPARATOR
{
        int16_t L2166_i_X;
        int16_t L2167_i_Y;
        int16_t L2168_ai_XYZ[4];


        L2166_i_X = 0;
        L2167_i_Y = 0;
        if (F0635_(P2249_puc_Bitmap, L2168_ai_XYZ, P2250_i_ZoneIndex, &L2166_i_X, &L2167_i_Y)) {
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
                F0132_VIDEO_Blit(P2249_puc_Bitmap, G0296_puc_Bitmap_Viewport, L2168_ai_XYZ, L2166_i_X, L2167_i_Y, M100_PIXEL_WIDTH(P2249_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2251_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA488_F20E_F20J
                F0132_VIDEO_Blit(G0296_puc_Bitmap_Viewport, G0348_Bitmap_Screen, L2168_ai_XYZ, L2166_i_X, L2167_i_Y, M100_PIXEL_WIDTH(P2249_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2251_i_TransparentColor);
#endif
#ifdef MEDIA605_X30J_F31E_F31J_X31J
                F0132_VIDEO_Blit(P2249_puc_Bitmap, G0296_puc_Bitmap_Viewport, L2168_ai_XYZ, L2166_i_X, L2167_i_Y, M100_PIXEL_WIDTH(P2249_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2251_i_TransparentColor);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                F0132_VIDEO_Blit(P2249_puc_Bitmap, G0296_puc_Bitmap_Viewport, L2168_ai_XYZ, L2166_i_X, L2167_i_Y, M100_PIXEL_WIDTH(P2249_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2251_i_TransparentColor, M101_PIXEL_HEIGHT(P2249_puc_Bitmap), G2074_C136_ViewportHeight);
#endif
        }
}

void F0657_BlitBitmapIndexToViewportZoneWithTransparency(
int16_t  P2252_i_BitmapIndex      SEPARATOR
int16_t* P2253_pi_XYZ             SEPARATOR
int16_t  P2254_i_TransparentColor FINAL_SEPARATOR
{
        REGISTER unsigned char* L2169_puc_Bitmap;
        STRUCT2 L2170_s_Struct2;


        L2169_puc_Bitmap = F0630_InitBitmapStruct2(P2252_i_BitmapIndex, &L2170_s_Struct2);
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        F0132_VIDEO_Blit(L2169_puc_Bitmap, G0296_puc_Bitmap_Viewport, P2253_pi_XYZ, L2170_s_Struct2.X, L2170_s_Struct2.Y, M100_PIXEL_WIDTH(L2169_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2254_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA543_F20E_F20J_X30J_F31E_F31J_X31J
        F0132_VIDEO_Blit(L2169_puc_Bitmap, G0296_puc_Bitmap_Viewport, P2253_pi_XYZ, L2170_s_Struct2.X, L2170_s_Struct2.Y, M100_PIXEL_WIDTH(L2169_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2254_i_TransparentColor);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        F0132_VIDEO_Blit(L2169_puc_Bitmap, G0296_puc_Bitmap_Viewport, P2253_pi_XYZ, L2170_s_Struct2.X, L2170_s_Struct2.Y, M100_PIXEL_WIDTH(L2169_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2254_i_TransparentColor, M101_PIXEL_HEIGHT(L2169_puc_Bitmap), G2074_C136_ViewportHeight);
#endif
}

void F0658_BlitBitmapIndexToZoneIndexWithTransparency(
int16_t P2255_i_BitmapIndex      SEPARATOR
int16_t P2256_i_ZoneIndex        SEPARATOR
int16_t P2257_i_TransparentColor FINAL_SEPARATOR
{
        REGISTER unsigned char* L2171_puc_Bitmap;
        int16_t L2172_i_Width;
        int16_t L2173_i_Height;
        int16_t L2174_ai_XYZ[4];
        STRUCT2 L2175_s_Struct2;


        L2171_puc_Bitmap = F0630_InitBitmapStruct2(P2255_i_BitmapIndex, &L2175_s_Struct2);
        if (P2255_i_BitmapIndex < 0) {
                L2172_i_Width = L2175_s_Struct2.Width;
                L2173_i_Height = L2175_s_Struct2.Height;
        } else {
                L2172_i_Width = 0;
                L2173_i_Height = 0;
        }
        if (F0635_(L2171_puc_Bitmap, L2174_ai_XYZ, P2256_i_ZoneIndex, &L2172_i_Width, &L2173_i_Height)) {
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
                F0132_VIDEO_Blit(L2171_puc_Bitmap, G0296_puc_Bitmap_Viewport, L2174_ai_XYZ, L2175_s_Struct2.X + L2172_i_Width, L2175_s_Struct2.Y + L2173_i_Height, M100_PIXEL_WIDTH(L2171_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2257_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA543_F20E_F20J_X30J_F31E_F31J_X31J
                F0132_VIDEO_Blit(L2171_puc_Bitmap, G0296_puc_Bitmap_Viewport, L2174_ai_XYZ, L2175_s_Struct2.X + L2172_i_Width, L2175_s_Struct2.Y + L2173_i_Height, M100_PIXEL_WIDTH(L2171_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2257_i_TransparentColor);
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                F0132_VIDEO_Blit(L2171_puc_Bitmap, G0296_puc_Bitmap_Viewport, L2174_ai_XYZ, L2175_s_Struct2.X + L2172_i_Width, L2175_s_Struct2.Y + L2173_i_Height, M100_PIXEL_WIDTH(L2171_puc_Bitmap), G2073_C224_ViewportPixelWidth, P2257_i_TransparentColor, M101_PIXEL_HEIGHT(L2171_puc_Bitmap), G2074_C136_ViewportHeight);
#endif
        }
}

void F0766_BlitToScreen(
unsigned char* P2258_puc_Bitmap         SEPARATOR
int16_t*       P2259_pi_XYZ             SEPARATOR
int16_t        P2260_i_TransparentColor FINAL_SEPARATOR
{
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        F0132_VIDEO_Blit(P2258_puc_Bitmap, G0348_Bitmap_Screen, P2259_pi_XYZ, 0, 0, M100_PIXEL_WIDTH(P2258_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2260_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA542_F20E_F20J_X30J_F31E_F31J
        F0132_VIDEO_Blit(P2258_puc_Bitmap, G0348_Bitmap_Screen, P2259_pi_XYZ, 0, 0, M100_PIXEL_WIDTH(P2258_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2260_i_TransparentColor);
#endif
#ifdef MEDIA692_X31J
        VDEO_06_BlitToScreen(P2258_puc_Bitmap, 0, P2259_pi_XYZ, 0, 0, M100_PIXEL_WIDTH(P2258_puc_Bitmap), P2260_i_TransparentColor, M101_PIXEL_HEIGHT(P2258_puc_Bitmap));
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        F0132_VIDEO_Blit(P2258_puc_Bitmap, G0348_Bitmap_Screen, P2259_pi_XYZ, 0, 0, M100_PIXEL_WIDTH(P2258_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2260_i_TransparentColor, M101_PIXEL_HEIGHT(P2258_puc_Bitmap), G2072_C200_ScreenPixelHeight);
#endif
}
#endif

void F0021_MAIN_BlitToScreen(
#ifdef MEDIA008_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E
P0023_puc_Bitmap, P0024_pi_Box, P0025_i_BitmapByteWidth, P0026_i_TransparentColor)
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0023_puc_Bitmap, P0024_pi_Box, P0025_i_BitmapByteWidth, P0026_i_TransparentColor, P0918_i_Height)
#endif
unsigned char* P0023_puc_Bitmap         SEPARATOR
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t*       P0024_pi_Box             SEPARATOR
int16_t        P0025_i_BitmapByteWidth  SEPARATOR
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t        P2261_i_ZoneIndex        SEPARATOR
#endif
#ifdef MEDIA099_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
int16_t        P0026_i_TransparentColor FINAL_SEPARATOR
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
int16_t        P0026_i_TransparentColor SEPARATOR
int16_t        P0918_i_Height           FINAL_SEPARATOR
#endif
{
#ifdef MEDIA008_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E
        G0578_B_UseByteBoxCoordinates = C0_FALSE, F0132_VIDEO_Blit(P0023_puc_Bitmap, G0348_Bitmap_Screen, P0024_pi_Box, 0, 0, P0025_i_BitmapByteWidth, C160_BYTE_WIDTH_SCREEN, P0026_i_TransparentColor);
#endif
#ifdef MEDIA413_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
        G0578_B_UseByteBoxCoordinates = C0_FALSE, F0132_VIDEO_Blit(P0023_puc_Bitmap, G0348_Bitmap_Screen, P0024_pi_Box, 0, 0, P0025_i_BitmapByteWidth, C160_BYTE_WIDTH_SCREEN, P0026_i_TransparentColor, P0918_i_Height, C200_HEIGHT_SCREEN);
#endif
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
        int16_t L2176_i_Width;
        int16_t L2177_i_Height;
        int16_t L2178_ai_XYZ[4];


        L2176_i_Width = 0;
        L2177_i_Height = 0;
        if (F0635_(P0023_puc_Bitmap, L2178_ai_XYZ, P2261_i_ZoneIndex, &L2176_i_Width, &L2177_i_Height)) {
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
                F0132_VIDEO_Blit(P0023_puc_Bitmap, G0348_Bitmap_Screen, L2178_ai_XYZ, L2176_i_Width, L2177_i_Height, M100_PIXEL_WIDTH(P0023_puc_Bitmap), G2071_C320_ScreenPixelWidth, P0026_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA542_F20E_F20J_X30J_F31E_F31J
                F0132_VIDEO_Blit(P0023_puc_Bitmap, G0348_Bitmap_Screen, L2178_ai_XYZ, L2176_i_Width, L2177_i_Height, M100_PIXEL_WIDTH(P0023_puc_Bitmap), G2071_C320_ScreenPixelWidth, P0026_i_TransparentColor);
#endif
#ifdef MEDIA692_X31J
                VDEO_06_BlitToScreen(P0023_puc_Bitmap, 0, L2178_ai_XYZ, L2176_i_Width, L2177_i_Height, M100_PIXEL_WIDTH(P0023_puc_Bitmap), P0026_i_TransparentColor, M101_PIXEL_HEIGHT(P0023_puc_Bitmap));
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                F0132_VIDEO_Blit(P0023_puc_Bitmap, G0348_Bitmap_Screen, L2178_ai_XYZ, L2176_i_Width, L2177_i_Height, M100_PIXEL_WIDTH(P0023_puc_Bitmap), G2071_C320_ScreenPixelWidth, P0026_i_TransparentColor, M101_PIXEL_HEIGHT(P0023_puc_Bitmap), G2072_C200_ScreenPixelHeight);
#endif
        }
#endif
}

#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void F0659_(
int16_t  P2262_i_P1    SEPARATOR
int16_t* P2263_pi_XYZ  SEPARATOR
int16_t  P2264_i_Color FINAL_SEPARATOR
{
        REGISTER unsigned char* L2179_puc_Bitmap;
        STRUCT2 L2180_s_Struct2;


        L2179_puc_Bitmap = F0630_InitBitmapStruct2(P2262_i_P1, &L2180_s_Struct2);
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
        F0132_VIDEO_Blit(L2179_puc_Bitmap, G0348_Bitmap_Screen, P2263_pi_XYZ, L2180_s_Struct2.X, L2180_s_Struct2.Y, M100_PIXEL_WIDTH(L2179_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2264_i_Color, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA542_F20E_F20J_X30J_F31E_F31J
        F0132_VIDEO_Blit(L2179_puc_Bitmap, G0348_Bitmap_Screen, P2263_pi_XYZ, L2180_s_Struct2.X, L2180_s_Struct2.Y, M100_PIXEL_WIDTH(L2179_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2264_i_Color);
#endif
#ifdef MEDIA692_X31J
        VDEO_06_BlitToScreen(L2179_puc_Bitmap, 0, P2263_pi_XYZ, L2180_s_Struct2.X, L2180_s_Struct2.Y, M100_PIXEL_WIDTH(L2179_puc_Bitmap), P2264_i_Color, M101_PIXEL_HEIGHT(L2179_puc_Bitmap));
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
        F0132_VIDEO_Blit(L2179_puc_Bitmap, G0348_Bitmap_Screen, P2263_pi_XYZ, L2180_s_Struct2.X, L2180_s_Struct2.Y, M100_PIXEL_WIDTH(L2179_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2264_i_Color, M101_PIXEL_HEIGHT(L2179_puc_Bitmap), G2072_C200_ScreenPixelHeight);
#endif
}

void F0660_(
int16_t P2265_i_BitmapIndex      SEPARATOR
int16_t P2266_i_ZoneIndex        SEPARATOR
int16_t P2267_i_TransparentColor FINAL_SEPARATOR
{
        REGISTER unsigned char* L2181_puc_Bitmap;
        int16_t L2182_i_Width;
        int16_t L2183_i_Height;
        int16_t L2184_ai_XYZ[4];
        STRUCT2 L2185_s_Struct2;


        L2181_puc_Bitmap = F0630_InitBitmapStruct2(P2265_i_BitmapIndex, &L2185_s_Struct2);
        if (P2265_i_BitmapIndex < 0) {
                L2182_i_Width = L2185_s_Struct2.Width;
                L2183_i_Height = L2185_s_Struct2.Height;
        } else {
                L2182_i_Width = 0;
                L2183_i_Height = 0;
        }
        if (F0635_(L2181_puc_Bitmap, L2184_ai_XYZ, P2266_i_ZoneIndex, &L2182_i_Width, &L2183_i_Height)) {
#ifdef MEDIA463_P20JA_P20JB_I34E_I34M_P31J
                F0132_VIDEO_Blit(L2181_puc_Bitmap, G0348_Bitmap_Screen, L2184_ai_XYZ, L2185_s_Struct2.X + L2182_i_Width, L2185_s_Struct2.Y + L2183_i_Height, M100_PIXEL_WIDTH(L2181_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2267_i_TransparentColor, MASK0x0000_NO_FLIP);
#endif
#ifdef MEDIA542_F20E_F20J_X30J_F31E_F31J
                F0132_VIDEO_Blit(L2181_puc_Bitmap, G0348_Bitmap_Screen, L2184_ai_XYZ, L2185_s_Struct2.X + L2182_i_Width, L2185_s_Struct2.Y + L2183_i_Height, M100_PIXEL_WIDTH(L2181_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2267_i_TransparentColor);
#endif
#ifdef MEDIA692_X31J
                VDEO_06_BlitToScreen(L2181_puc_Bitmap, 0, L2184_ai_XYZ, L2185_s_Struct2.X + L2182_i_Width, L2185_s_Struct2.Y + L2183_i_Height, M100_PIXEL_WIDTH(L2181_puc_Bitmap), P2267_i_TransparentColor, M101_PIXEL_HEIGHT(L2181_puc_Bitmap));
#endif
#ifdef MEDIA746_A36M_A31E_A31M_A33M_A35E_A35M
                F0132_VIDEO_Blit(L2181_puc_Bitmap, G0348_Bitmap_Screen, L2184_ai_XYZ, L2185_s_Struct2.X + L2182_i_Width, L2185_s_Struct2.Y + L2183_i_Height, M100_PIXEL_WIDTH(L2181_puc_Bitmap), G2071_C320_ScreenPixelWidth, P2267_i_TransparentColor, M101_PIXEL_HEIGHT(L2181_puc_Bitmap), G2072_C200_ScreenPixelHeight);
#endif
        }
}

unsigned char* F0767_(
int16_t          P2268_i_NativeBitmapIndex  SEPARATOR
REGISTER int16_t P2269_i_DerivedBitmapIndex SEPARATOR
int16_t          P2270_i_Width              SEPARATOR
int16_t          P2271_i_Height             SEPARATOR
unsigned char*   P2272_puc_PaletteChanges   FINAL_SEPARATOR
{
        REGISTER unsigned char* L2186_puc_DerivedBitmap;
        REGISTER unsigned char* L2187_puc_NativeBitmap;


        L2187_puc_NativeBitmap = F0489_MEMORY_GetNativeBitmapOrGraphic(P2268_i_NativeBitmapIndex);
        L2186_puc_DerivedBitmap = F0492_CACHE_GetDerivedBitmap(P2269_i_DerivedBitmapIndex);
        F0129_VIDEO_BlitShrinkWithPaletteChanges(L2187_puc_NativeBitmap, L2186_puc_DerivedBitmap, M100_PIXEL_WIDTH(L2187_puc_NativeBitmap), M101_PIXEL_HEIGHT(L2187_puc_NativeBitmap), M100_PIXEL_WIDTH(L2186_puc_DerivedBitmap) = P2270_i_Width, M101_PIXEL_HEIGHT(L2186_puc_DerivedBitmap) = P2271_i_Height, P2272_puc_PaletteChanges);
        return L2186_puc_DerivedBitmap;
}

unsigned char* F0661_GetShrinkedBitmap(
int16_t          P2273_i_NativeBitmapIndex  SEPARATOR
REGISTER int16_t P2274_i_DerivedBitmapIndex SEPARATOR
int16_t          P2275_i_Width              SEPARATOR
int16_t          P2276_i_Height             SEPARATOR
unsigned char*   P2277_puc_PaletteChanges   FINAL_SEPARATOR
{
        REGISTER unsigned char* L2188_puc_DerivedBitmap;
        REGISTER unsigned char* L2189_puc_NativeBitmap;


        if (F0491_CACHE_IsDerivedBitmapInCache(P2274_i_DerivedBitmapIndex)) {
                L2188_puc_DerivedBitmap = F0492_CACHE_GetDerivedBitmap(P2274_i_DerivedBitmapIndex);
        } else {
                L2189_puc_NativeBitmap = F0489_MEMORY_GetNativeBitmapOrGraphic(P2273_i_NativeBitmapIndex);
                L2188_puc_DerivedBitmap = F0492_CACHE_GetDerivedBitmap(P2274_i_DerivedBitmapIndex);
                F0129_VIDEO_BlitShrinkWithPaletteChanges(L2189_puc_NativeBitmap, L2188_puc_DerivedBitmap, M100_PIXEL_WIDTH(L2189_puc_NativeBitmap), M101_PIXEL_HEIGHT(L2189_puc_NativeBitmap), M100_PIXEL_WIDTH(L2188_puc_DerivedBitmap) = P2275_i_Width, M101_PIXEL_HEIGHT(L2188_puc_DerivedBitmap) = P2276_i_Height, P2277_puc_PaletteChanges);
                F0493_CACHE_AddDerivedBitmap(P2274_i_DerivedBitmapIndex);
        }
        return L2188_puc_DerivedBitmap;
}

void F0662_ApplyPaletteChanges(
REGISTER char* P2278_pc_ChampionIconBitmap SEPARATOR
unsigned char* P2279_puc_PaletteChanges    FINAL_SEPARATOR
{
        F0129_VIDEO_BlitShrinkWithPaletteChanges(M774_CAST_PUC(P2278_pc_ChampionIconBitmap), M774_CAST_PUC(P2278_pc_ChampionIconBitmap), M100_PIXEL_WIDTH(P2278_pc_ChampionIconBitmap), M101_PIXEL_HEIGHT(P2278_pc_ChampionIconBitmap), M100_PIXEL_WIDTH(P2278_pc_ChampionIconBitmap), M101_PIXEL_HEIGHT(P2278_pc_ChampionIconBitmap), P2279_puc_PaletteChanges);
}

void F0663_CopyBitmapWithPaletteChanges(
REGISTER unsigned char* P2280_puc_Bitmap         SEPARATOR
REGISTER unsigned char* P2281_puc_Bitmap2        SEPARATOR
unsigned char*          P2282_puc_PaletteChanges FINAL_SEPARATOR
{
        REGISTER int16_t L2190_i_Width;
        REGISTER int16_t L2191_i_Height;


        L2190_i_Width = M100_PIXEL_WIDTH(P2280_puc_Bitmap);
        L2191_i_Height = M101_PIXEL_HEIGHT(P2280_puc_Bitmap);
        F0129_VIDEO_BlitShrinkWithPaletteChanges(P2280_puc_Bitmap, P2281_puc_Bitmap2, L2190_i_Width, L2191_i_Height, M100_PIXEL_WIDTH(P2281_puc_Bitmap2) = L2190_i_Width, M101_PIXEL_HEIGHT(P2281_puc_Bitmap2) = L2191_i_Height, P2282_puc_PaletteChanges);
}
#endif

#ifdef MEDIA548_F20E_F20J_X30J_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J
void F1006_(
REGISTER unsigned char* P2757_puc_Bitmap FINAL_SEPARATOR
{
        F0130_VIDEO_FlipHorizontal(P2757_puc_Bitmap, M100_PIXEL_WIDTH(P2757_puc_Bitmap), M101_PIXEL_HEIGHT(P2757_puc_Bitmap));
}

void F1030_(
REGISTER unsigned char* P2758_puc_Bitmap FINAL_SEPARATOR
{
        F0131_VIDEO_FlipVertical(P2758_puc_Bitmap, M100_PIXEL_WIDTH(P2758_puc_Bitmap), M101_PIXEL_HEIGHT(P2758_puc_Bitmap));
}
#endif

void F0022_MAIN_Delay(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0027_ui_VerticalBlankCount)
#endif
unsigned int16_t P0027_ui_VerticalBlankCount FINAL_SEPARATOR
{
        while (P0027_ui_VerticalBlankCount--) {
                M526_WaitVerticalBlank();
        }
}

int16_t F0023_MAIN_GetAbsoluteValue(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0028_i_Value)
#endif
#ifdef MEDIA201_S10EA_S10EB_S11E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
REGISTER int16_t P0028_i_Value FINAL_SEPARATOR
#endif
#ifdef MEDIA247_S12E_S12G_S13FA_S13FB_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
int16_t P0028_i_Value FINAL_SEPARATOR
#endif
{
#ifdef MEDIA201_S10EA_S10EB_S11E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        return (P0028_i_Value < 0) ? -P0028_i_Value : P0028_i_Value;
#endif
#ifdef MEDIA247_S12E_S12G_S13FA_S13FB_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                        move.w  P0028_i_Value(A6),D0
                        bpl.s   @T0023002_Return         /* Branch if D0 >= 0 */
                        neg.w   D0
                @T0023002_Return:
        }
#endif
}

int16_t F0024_MAIN_GetMinimumValue(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0029_i_Value1, P0030_i_Value2)
#endif
int16_t P0029_i_Value1 SEPARATOR
int16_t P0030_i_Value2 FINAL_SEPARATOR
{
#ifdef MEDIA201_S10EA_S10EB_S11E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        return (P0029_i_Value1 < P0030_i_Value2) ? P0029_i_Value1 : P0030_i_Value2;
#endif
#ifdef MEDIA247_S12E_S12G_S13FA_S13FB_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                        move.w  P0029_i_Value1(A6),D0
                        cmp.w   P0030_i_Value2(A6),D0
                        blt.s   @T0024002_Return         /* Branch if D0 < P0030_i_Value2 (signed comparison) */
                        move.w  P0030_i_Value2(A6),D0
                @T0024002_Return:
        }
#endif
}

int16_t F0025_MAIN_GetMaximumValue(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0031_i_Value1, P0032_i_Value2)
#endif
int16_t P0031_i_Value1 SEPARATOR
int16_t P0032_i_Value2 FINAL_SEPARATOR
{
#ifdef MEDIA201_S10EA_S10EB_S11E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        return (P0031_i_Value1 > P0032_i_Value2) ? P0031_i_Value1 : P0032_i_Value2;
#endif
#ifdef MEDIA247_S12E_S12G_S13FA_S13FB_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                        move.w  P0031_i_Value1(A6),D0
                        cmp.w   P0032_i_Value2(A6),D0
                        bgt.s   @T0025002_Return         /* Branch if D0 > P0032_i_Value2 (signed comparison) */
                        move.w  P0032_i_Value2(A6),D0
                @T0025002_Return:
        }
#endif
}

int16_t F0026_MAIN_GetBoundedValue(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0033_i_MinimumAllowedValue, P0034_i_Value, P0035_i_MaximumAllowedValue)
#endif
int16_t P0033_i_MinimumAllowedValue SEPARATOR
int16_t P0034_i_Value               SEPARATOR
int16_t P0035_i_MaximumAllowedValue FINAL_SEPARATOR
{
#ifdef MEDIA201_S10EA_S10EB_S11E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        return (P0034_i_Value < P0033_i_MinimumAllowedValue) ? P0033_i_MinimumAllowedValue : (P0034_i_Value > P0035_i_MaximumAllowedValue) ? P0035_i_MaximumAllowedValue : P0034_i_Value;
#endif
#ifdef MEDIA247_S12E_S12G_S13FA_S13FB_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                        move.w  P0034_i_Value(A6),D0
                        cmp.w   P0033_i_MinimumAllowedValue(A6),D0
                        bgt.s   @T002601                                /* Branch if D0 > P0033_i_MinimumAllowedValue (signed comparison) */
                        move.w  P0033_i_MinimumAllowedValue(A6),D0
                        bra.s   @T002603
                @T002601:
                        cmp.w   P0035_i_MaximumAllowedValue(A6),D0
                        ble.s   @T002603                                /* Branch if D0 <= P0035_i_MaximumAllowedValue (signed comparison) */
                        move.w  P0035_i_MaximumAllowedValue(A6),D0
                @T002603:
        }
#endif
}

unsigned int16_t F0027_MAIN_Get16bitRandomNumber(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA202_S10EA_S10EB_S11E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        return (unsigned int16_t)((G0349_ul_LastRandomNumber = G0349_ul_LastRandomNumber * 0xBB40E62D + 11) >> 8); /* Pseudorandom number generator. 0xBB40E62D = 3141592621 */
#endif
#ifdef MEDIA237_S12E_S12G_S13FA_S13FB_S20E_S21E /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                move.l  G0349_ul_LastRandomNumber(A4),-(A7)
                move.l  #3141592621,-(A7)                       /* A classic value for pseudo random number generators (looks like first decimals of Pi, except the last two digits which are replaced by 21) */
                jsr     _lmul(PC)                               /* Multiply long values */
                moveq   #11,D0
                add.l   (A7)+,D0                                /* D0 = 11 + result of multiplication (from stack), then clean up stack */
                move.l  D0,G0349_ul_LastRandomNumber(A4)
                lsr.l   #8,D0                                   /* Return value is between 0 and 65535 */
        }
#endif
}

unsigned int16_t F0028_MAIN_Get1BitRandomNumber(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA205_S10EA_S10EB_S11E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        return (unsigned int16_t)((G0349_ul_LastRandomNumber = G0349_ul_LastRandomNumber * 0xBB40E62D + 11) >> 8) & 0x0001; /* Pseudorandom number generator. 0xBB40E62D = 3141592621 */
#endif
#ifdef MEDIA237_S12E_S12G_S13FA_S13FB_S20E_S21E /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                move.l  G0349_ul_LastRandomNumber(A4),-(A7)
                move.l  #3141592621,-(A7)                       /* A classic value for pseudo random number generators (looks like first decimals of Pi, except the last two digits which are replaced by 21) */
                jsr     _lmul(PC)                               /* Multiply long values */
                moveq   #11,D0
                add.l   (A7)+,D0                                /* D0 = 11 + result of multiplication (from stack), then clean up stack */
                move.l  D0,G0349_ul_LastRandomNumber(A4)
                lsr.l   #8,D0
                and.w   #0x0001,D0                              /* Return value is 0 or 1 */
        }
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        int16_t L6198_;


        asm {
                SEP        #0x30
                LDA        0xc02f       /* HORIZCNT */
                STA        L6198_
                LSR        A
                EOR        L6198_
                LSR        A
                EOR        L6198_
                LSR        A
                EOR        L6198_
                LSR        A
                EOR        L6198_
                LSR        A
                EOR        L6198_
                AND        #0x01
                STA        L6198_
                STZ        L6198_+1
                REP        #0x30
        }
        return L6198_;
#endif
}

unsigned int16_t F0029_MAIN_Get2BitRandomNumber(
#ifdef MEDIA529_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J
void
#endif
)
{
#ifdef MEDIA205_S10EA_S10EB_S11E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_X30J_P20JA_P20JB_I34E_I34M_A36M_A31E_A31M_A33M_A35E_A35M_F31E_F31J_X31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        return (unsigned int16_t)((G0349_ul_LastRandomNumber = G0349_ul_LastRandomNumber * 0xBB40E62D + 11) >> 8) & 0x0003; /* Pseudorandom number generator. 0xBB40E62D = 3141592621 */
#endif
#ifdef MEDIA237_S12E_S12G_S13FA_S13FB_S20E_S21E /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                move.l  G0349_ul_LastRandomNumber(A4),-(A7)
                move.l  #3141592621,-(A7)                       /* A classic value for pseudo random number generators (looks like first decimals of Pi, except the last two digits which are replaced by 21) */
                jsr     _lmul(PC)                               /* Multiply long values */
                moveq   #11,D0
                add.l   (A7)+,D0                                /* D0 = 11 + result of multiplication (from stack), then clean up stack */
                move.l  D0,G0349_ul_LastRandomNumber(A4)
                lsr.l   #8,D0
                and.w   #0x0003,D0                              /* Return value is 0, 1, 2 or 3 */
        }
#endif
#ifdef MEDIA351_G14ED_G20E_G21E
        int16_t L6199_;


        asm {
                SEP        #0x30
                LDA        0xc02f       /* HORIZCNT */
                STA        L6199_
                LSR        A
                EOR        L6199_
                LSR        A
                EOR        L6199_
                LSR        A
                EOR        L6199_
                LSR        A
                EOR        L6199_
                LSR        A
                EOR        L6199_
                AND        #0x03
                STA        L6199_
                STZ        L6199_+1
                REP        #0x30
        }
        return L6199_;
#endif
}

unsigned int16_t F0030_MAIN_GetScaledProduct(
#ifdef MEDIA009_S10EA_S10EB_S11E_S12E_S12G_S13FA_S13FB_S20E_S21E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G
P0036_ui_Value1, P0037_ui_Scale, P0038_ui_Value2)
#endif
unsigned int16_t P0036_ui_Value1 SEPARATOR
unsigned int16_t P0037_ui_Scale  SEPARATOR
unsigned int16_t P0038_ui_Value2 FINAL_SEPARATOR
{
#ifdef MEDIA201_S10EA_S10EB_S11E_G14ED_G20E_G21E_A20ED_A20E_A20F_A20G_A21E_A22E_A22G_F20E_F20J_P20JA_P20JB_I34E_I34M_F31E_F31J_P31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        return ((long)P0036_ui_Value1 * P0038_ui_Value2) >> P0037_ui_Scale;
#endif
#ifdef MEDIA247_S12E_S12G_S13FA_S13FB_S20E_S21E_X30J_A36M_A31E_A31M_A33M_A35E_A35M_X31J /* CHANGE3_01_OPTIMIZATION Source code converted from C language to assembly language for better performance and smaller machine code size */
        asm {
                move.w  P0036_ui_Value1(A6),D0
                mulu.w  P0038_ui_Value2(A6),D0
                move.w  P0037_ui_Scale(A6),D1
                asr.l   D1,D0                   /* Arithmetic Shift Right bits in D0 by D1 cells. D0 = D0 / 2^D1 */
        }
#endif
}
#endif
