#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA678_F31E_F31J_X31J_P31J_SU1E_AU1E_AU2E_AU3E
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
extern BACKUP_PORTRAIT G2328_s_TempPortrait;
extern BACKUP_PORTRAIT G2329_s_UndoPortrait;
extern unsigned char* G2243_OnScreenPortraitBitmaps[4];
#endif
#ifdef MEDIA772_SU1E
unsigned char* G0348_Bitmap_Screen; /* CANNOT BE IN PALETTE.C */
BOOLEAN G0578_B_UseByteBoxCoordinates;
#endif

#ifdef MEDIA773_SU1E_AU1E
#undef Floprd
#define Floprd(a, b, c, d, e, f, g) (long)R0056_TOS_CallXBIOS(0x08, a, b, c, d, e, f, g)
#undef Fopen
#define Fopen(a, b)                        (int16_t)R0057_TOS_CallGEMDOS(0x3D, a, b)


unsigned char G2267_auc_Graphic_Mirror[984] = {
        0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0x00, 0xBF, 0xFF, 0x3F, 0xFF, 0x80, 0x00, 0x00, 0x00,
        0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0xDF, 0xFF, 0x5F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,
        0xFF, 0xF0, 0xFF, 0xD0, 0x00, 0x20, 0x00, 0x00, 0xEF, 0xFF, 0x6F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0xFF, 0x90, 0x00, 0x60, 0x00, 0x00,
        0xF7, 0xFF, 0x77, 0xFF, 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0xFF, 0x10, 0x00, 0xE0, 0x00, 0x00, 0xFB, 0xFF, 0x7B, 0xFF, 0x80, 0x00, 0x00, 0x00,
        0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0xFE, 0x10, 0x01, 0xE0, 0x00, 0x00, 0xFC, 0x30, 0x7C, 0x30, 0x83, 0xFF, 0x00, 0x30, 0x00, 0xE4, 0x00, 0xE4, 0xFF, 0xFF, 0x00, 0xE4,
        0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x60, 0x7C, 0x60, 0x83, 0xFF, 0x00, 0x60, 0x01, 0xC8, 0x01, 0xC8, 0xFF, 0xFF, 0x01, 0xC8, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00,
        0xFC, 0x80, 0x7C, 0x80, 0x83, 0xFF, 0x00, 0x80, 0x03, 0x80, 0x03, 0x80, 0xFF, 0xFF, 0x03, 0x80, 0x07, 0xF0, 0x04, 0x10, 0xFF, 0xE0, 0x04, 0x00, 0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00,
        0x07, 0x00, 0x07, 0x00, 0xFF, 0xFF, 0x07, 0x00, 0x0F, 0xF0, 0x0C, 0x10, 0xFF, 0xE0, 0x0C, 0x00, 0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0x1E, 0x00, 0x1E, 0x00, 0xFF, 0xFF, 0x1E, 0x00,
        0x0B, 0xF0, 0x08, 0x10, 0xFF, 0xE0, 0x08, 0x00, 0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0x7C, 0x00, 0x7C, 0x00, 0xFF, 0xFF, 0x7C, 0x00, 0x13, 0xF0, 0x10, 0x10, 0xFF, 0xE0, 0x10, 0x00,
        0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0xF8, 0x00, 0xF8, 0x00, 0xFF, 0xFF, 0xF8, 0x00, 0x23, 0xF0, 0x20, 0x10, 0xFF, 0xE0, 0x20, 0x00, 0xFC, 0x01, 0x7C, 0x01, 0x83, 0xFF, 0x00, 0x01,
        0xF0, 0x00, 0xF0, 0x00, 0xFF, 0xFF, 0xF0, 0x00, 0x43, 0xF0, 0x40, 0x10, 0xFF, 0xE0, 0x40, 0x00, 0xFC, 0x03, 0x7C, 0x03, 0x83, 0xFF, 0x00, 0x03, 0xE0, 0x00, 0xE0, 0x00, 0xFF, 0xFF, 0xE0, 0x00,
        0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x07, 0x7C, 0x07, 0x83, 0xFF, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00,
        0xFC, 0x0C, 0x7C, 0x0C, 0x83, 0xFF, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x18, 0x7C, 0x18, 0x83, 0xFF, 0x00, 0x18,
        0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x20, 0x7C, 0x20, 0x83, 0xFF, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
        0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x40, 0x7C, 0x40, 0x83, 0xFF, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00,
        0xFC, 0x80, 0x7C, 0x80, 0x83, 0xFF, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x23, 0xF0, 0x20, 0x10, 0xFF, 0xE0, 0x20, 0x00, 0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
        0x43, 0xF0, 0x40, 0x10, 0xFF, 0xE0, 0x40, 0x00, 0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0xFF, 0xFF, 0x00, 0x01, 0x83, 0xF0, 0x80, 0x10, 0xFF, 0xE0, 0x80, 0x00,
        0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0x00, 0x03, 0x00, 0x03, 0xFF, 0xFF, 0x00, 0x03, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00,
        0x00, 0x0E, 0x00, 0x0E, 0xFF, 0xFF, 0x00, 0x0E, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x1C, 0xFF, 0xFF, 0x00, 0x1C,
        0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFC, 0x20, 0x7C, 0x20, 0x83, 0xFF, 0x00, 0x20, 0x00, 0x38, 0x00, 0x38, 0xFF, 0xFF, 0x00, 0x38, 0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00,
        0xFC, 0x40, 0x7C, 0x40, 0x83, 0xFF, 0x00, 0x40, 0x00, 0x78, 0x00, 0x78, 0xFF, 0xFF, 0x00, 0x78, 0x07, 0xF0, 0x04, 0x10, 0xFF, 0xE0, 0x04, 0x00, 0xFD, 0x80, 0x7D, 0x80, 0x83, 0xFF, 0x01, 0x80,
        0x00, 0x70, 0x00, 0x70, 0xFF, 0xFF, 0x00, 0x70, 0x0F, 0xF0, 0x0C, 0x10, 0xFF, 0xE0, 0x0C, 0x00, 0xFF, 0x00, 0x7F, 0x00, 0x83, 0xFF, 0x03, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0xFF, 0xFF, 0x00, 0xE0,
        0x3B, 0xF0, 0x38, 0x10, 0xFF, 0xE0, 0x38, 0x00, 0xFE, 0x00, 0x7E, 0x00, 0x83, 0xFF, 0x02, 0x00, 0x00, 0xE0, 0x00, 0xE0, 0xFF, 0xFF, 0x00, 0xE0, 0x73, 0xF0, 0x70, 0x10, 0xFF, 0xE0, 0x70, 0x00,
        0xFC, 0x00, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0x81, 0xC0, 0x81, 0xC0, 0xFF, 0xFF, 0x81, 0xC0, 0x43, 0xF0, 0x40, 0x10, 0xFF, 0xE0, 0x40, 0x00, 0xFC, 0x03, 0x7C, 0x03, 0x83, 0xFF, 0x00, 0x03,
        0x07, 0x80, 0x07, 0x80, 0xFF, 0xFF, 0x07, 0x80, 0x83, 0xF0, 0x80, 0x10, 0xFF, 0xE0, 0x80, 0x00, 0xFC, 0x0E, 0x7C, 0x0E, 0x83, 0xFF, 0x00, 0x0E, 0x0F, 0x00, 0x0F, 0x00, 0xFF, 0xFF, 0x0F, 0x00,
        0x03, 0xF0, 0x00, 0x10, 0xFF, 0xE0, 0x00, 0x00, 0xFF, 0xFF, 0x7C, 0x00, 0x83, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xF0, 0x02, 0x10, 0xFD, 0xE0, 0x00, 0x00,
        0xFF, 0xFF, 0x78, 0x00, 0x87, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xF0, 0x01, 0x10, 0xFE, 0xE0, 0x00, 0x00, 0xFF, 0xFF, 0x70, 0x00, 0x8F, 0xFF, 0x00, 0x00,
        0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0x90, 0xFF, 0x60, 0x00, 0x00, 0xFF, 0xFF, 0x60, 0x00, 0x9F, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00,
        0xFF, 0xF0, 0x00, 0x50, 0xFF, 0xA0, 0x00, 0x00, 0xFF, 0xFF, 0x40, 0x00, 0xBF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0xFF, 0xF0, 0x00, 0x30, 0xFF, 0xC0, 0x00, 0x00,
        0xFF, 0xFF, 0x7F, 0xFF, 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xF0, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00
};
#endif
#ifdef MEDIA670_F31E_F31J
int16_t G7108_BlinkingCursorTimer;
#endif
#ifdef MEDIA682_F31E_F31J_X31J_SU1E_AU1E_AU2E_AU3E
int16_t G7107_SelectedColorIndex;
int16_t G7109_SelectedChampionIndex;
#endif
#ifdef MEDIA772_SU1E
unsigned char G2243_OnScreenPortraitBitmaps[4][464];
#endif
#ifdef MEDIA762_AU1E
unsigned char (*G2243_OnScreenPortraitBitmaps)[464];
unsigned char* G3933_;
unsigned char* G7117_Bitmap_Mirror;
#endif
#ifdef MEDIA682_F31E_F31J_X31J_SU1E_AU1E_AU2E_AU3E
ON_DISK_PORTRAIT G2248_as_OnDiskPortraits[4];
#endif
#ifdef MEDIA773_SU1E_AU1E
int16_t G7108_BlinkingCursorTimer;
#endif
#ifdef MEDIA699_X31J_AU2E_AU3E
long G7108_BlinkingCursorTimer;
#endif
#ifdef MEDIA682_F31E_F31J_X31J_SU1E_AU1E_AU2E_AU3E
int16_t G2271_ai_Box_EditText[4];
BOOLEAN G7104_TextCursorVisible;
int16_t G7106_EditChampionNameOrTitle;
int16_t G7105_EditChampionNameOrTitleCharacterIndex;
#endif
#ifdef MEDIA670_F31E_F31J
int16_t G7102_;
int16_t G7103_;
#endif
#ifdef MEDIA773_SU1E_AU1E
int16_t G2277_ai_Box_SelectedPortraitZoomed[4] = { 157, 252, 60, 146 };
int16_t G7024_SelectedColorBoxX1 = 286; /* Convert to a int16_t[4] */
int16_t G7025_SelectedColorBoxX2 = 303;
int16_t G7026_SelectedColorBoxY1Base = 43;
int16_t G2304_Unreferenced = 169;
int16_t G2278_ai_Box_ColorPalette[4] = { 284, 305, 41, 171 };
int16_t G2273_aai_Box_ChampionNames[4][4] = {
        {   4,  48, 3, 11 },
        {  71, 115, 3, 11 },
        { 138, 182, 3, 11 },
        { 205, 249, 3, 11 } };
int16_t G2275_aai_Box_Portraits[4][4] = {
        {  11, 42,  14, 42 },
        {  78, 109, 14, 42 },
        { 145, 176, 14, 42 },
        { 211, 242, 14, 42 } };
int16_t G2276_ai_Box_Mirror[4] = { 77, 120, 56, 96 };
int16_t G2279_ai_Box_SelectedPortraitSmall[4] = { 83, 114, 62, 90 };
int16_t G2269_aai_Box_StatisticsArea[4] = { 0, 152, 114, 175 };
MOUSE2_INPUT G2272_MouseInputs[18] = {
        {   1, 0,   4,  48,   3,  42, 1 },
        {   2, 0,  71, 115,   3,  42, 1 },
        {   3, 0, 138, 182,   3,  42, 1 },
        {   4, 0, 205, 249,   3,  42, 1 },
        {   5, 0, 157, 252,  60, 146, 1 },
        {   6, 0, 157, 252,  60, 146, 2 },
        {   7, 0, 286, 303,  43, 169, 1 },
        {   8, 0, 156, 196, 159, 167, 1 },
        {   9, 0, 225, 253, 159, 167, 1 },
        { 100, 0, 350, 349, 250, 249, 0 },
        {  11, 0,   2,  92, 186, 194, 1 },
        {  12, 0, 102, 192, 186, 194, 1 },
        {  13, 0, 202, 316, 186, 194, 1 },
        {  14, 0,  15,  59,  87,  95, 1 },
        {  15, 0,  15, 131, 100, 108, 1 },
        { 102, 0, 350, 349, 250, 249, 0 },
        {  17, 0, 288, 316,   5,  13, 1 },
        {   0, 0,   0,   0,   0,   0, 0 } };
KEY2BOARD_INPUT G2305_KeyboardInputs[8] = {
        {  9, 0, 0x6100 },
        {  1, 0, 0x3B00 },
        {  2, 0, 0x3C00 },
        {  3, 0, 0x3D00 },
        {  4, 0, 0x3E00 },
        { 17, 0, 0x4400 },
        { 16, 0, 0xFFFF },
        {  0, 0, 0      } };
INPUT_INFO G2280_ = { 1, 0, G2272_MouseInputs, G2305_KeyboardInputs, 0 };
char* G0417_apc_BaseSkillNames[4] = { "FIGHTER", "NINJA", "PRIEST", "WIZARD" };
char* G0428_apc_SkillLevelNames[15] = {
        "NEOPHYTE   ",
        "NOVICE     ",
        "APPRENTICE ",
        "JOURNEYMAN ",
        "CRAFTSMAN  ",
        "ARTISAN    ",
        "ADEPT      ",
        "EXPERT     ",
        "` MASTER   ",
        "a MASTER   ",
        "b MASTER   ",
        "c MASTER   ",
        "d MASTER   ",
        "e MASTER   ",
        "ARCHMASTER " };
#endif
#ifdef MEDIA773_SU1E_AU1E
unsigned char G2274_ColorPalette[16] = {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
int16_t G2274_ColorPalette[16] = {
#endif
        C00_COLOR_BLACK,
        C12_COLOR_DARKEST_GRAY,
        C01_COLOR_DARK_GRAY,
        C02_COLOR_LIGHT_GRAY,
        C13_COLOR_LIGHTEST_GRAY,
        C15_COLOR_WHITE,
        C03_COLOR_DARK_BROWN,
        C05_COLOR_LIGHT_BROWN,
        C10_COLOR_FLESH,
        C08_COLOR_RED,
        C09_COLOR_GOLD,
        C11_COLOR_YELLOW,
        C07_COLOR_LIGHT_GREEN,
        C06_COLOR_DARK_GREEN,
        C04_COLOR_CYAN,
        C14_COLOR_BLUE };
#ifdef MEDIA773_SU1E_AU1E
BACKUP2_PORTRAIT G2329_s_UndoPortrait;
BACKUP2_PORTRAIT G2328_s_TempPortrait;
#endif
#ifdef MEDIA772_SU1E
char G3822_[2000];
#endif
char* G7003_ = "___________________";
#ifdef MEDIA700_X31J_SU1E_AU1E_AU2E_AU3E
int16_t G7102_;
int16_t G7103_;
#endif


void F7027_DrawTextCursor(int16_t P3668_i_, int16_t P3669_i_)
{
        REGISTER int16_t* L3868_pi_Box;


        L3868_pi_Box = G2272_MouseInputs[P3668_i_ + 13].Box;
        G7106_EditChampionNameOrTitle = P3668_i_;
        G7105_EditChampionNameOrTitleCharacterIndex = P3669_i_;
        F0077_MOUSE_EnableScreenUpdate_CPSE();
        if (G7104_TextCursorVisible) {
                F7260_FillScreenBox(G2271_ai_Box_EditText, C01_COLOR_DARK_GRAY);
        }
#ifdef MEDIA773_SU1E_AU1E
        M768_BOX_LEFT(G2271_ai_Box_EditText) = M769_BOX_RIGHT(G2271_ai_Box_EditText) = (P3669_i_ * 6) + M768_BOX_LEFT(L3868_pi_Box) + 1;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        M768_BOX_LEFT(G2271_ai_Box_EditText) = M769_BOX_RIGHT(G2271_ai_Box_EditText) = (G7053_TextCharacterWidth * P3669_i_) + M768_BOX_LEFT(L3868_pi_Box) + 1;
#endif
        M770_BOX_TOP(G2271_ai_Box_EditText) = M770_BOX_TOP(L3868_pi_Box);
        M771_BOX_BOTTOM(G2271_ai_Box_EditText) = M771_BOX_BOTTOM(L3868_pi_Box);
        F7260_FillScreenBox(G2271_ai_Box_EditText, C15_COLOR_WHITE);
        F0078_MOUSE_DisableScreenUpdate();
        G7104_TextCursorVisible = C1_TRUE;
#ifdef MEDIA672_F31E_F31J_P31J_SU1E_AU1E
        G7108_BlinkingCursorTimer = 30;
#endif
#ifdef MEDIA699_X31J_AU2E_AU3E
        G7108_BlinkingCursorTimer = F2093_GetVerticalBlankCount() + 30;
#endif
}

void F7028_EditChampionNameOrTitle(
#ifdef MEDIA773_SU1E_AU1E
int16_t P3670_i_, int16_t P3671_i_, char* P3672_pc_)
{
        F7027_DrawTextCursor(P3671_i_, F0026_MAIN_GetBoundedValue(0, (P3670_i_ - (M768_BOX_LEFT(G2272_MouseInputs[P3671_i_ + 13].Box) + 1)) / 6, F0090_strlen(P3672_pc_)));
}
#endif
#ifdef MEDIA695_X31J_P31J_AU2E_AU3E
unsigned int16_t P3670_ui_, int16_t P3671_i_, char* P3672_pc_)
#endif
#ifdef MEDIA670_F31E_F31J
int16_t P3670_ui_, int16_t P3671_i_, char* P3672_pc_)
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
{
        F7027_DrawTextCursor(P3671_i_, F0026_MAIN_GetBoundedValue(0, (P3670_ui_ - (M768_BOX_LEFT(G2272_MouseInputs[P3671_i_ + 13].Box) + 1)) / G7053_TextCharacterWidth, F0090_strlen(P3672_pc_)));
}
#endif

void F7029_(
#ifdef MEDIA773_SU1E_AU1E
register int16_t* P3673_pi_Box, register int16_t* P3674_pi_Box, register int16_t P3675_i_, register int16_t P3676_i_)
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
REGISTER int16_t* P3673_pi_Box, REGISTER int16_t* P3674_pi_Box, REGISTER short P3675_i_, REGISTER short P3676_i_)
#endif
{
        *P3674_pi_Box++ = *P3673_pi_Box++ - P3676_i_;
        *P3674_pi_Box++ = *P3673_pi_Box++ + P3676_i_;
        *P3674_pi_Box++ = *P3673_pi_Box++ - P3675_i_;
        *P3674_pi_Box = *P3673_pi_Box + P3675_i_;
}

#ifdef MEDIA773_SU1E_AU1E
#include "CEDTINCN.C"
#endif

void F7030_DrawFilledBox(REGISTER int16_t* P3677_pi_, REGISTER int16_t P3678_i_, int16_t P3679_i_FillColor, int16_t P3680_i_LineColor)
{
        int16_t L3869_ai_[4];
        int16_t L3870_ai_Box[4];
        int16_t L3871_ai_Box[4];
        REGISTER int16_t L3872_i_;


        if (P3678_i_ < 0) {
                F7029_((int16_t*)P3677_pi_, (int16_t*)L3869_ai_, P3678_i_, P3678_i_);
                P3678_i_ = -P3678_i_;
        } else {
                F7317_MAIN_CopyBytes_Alt((char*)P3677_pi_, (char*)L3869_ai_, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(L3869_ai_));
        }
        F7260_FillScreenBox(L3869_ai_, P3680_i_LineColor);
        if (P3678_i_) {
                F7029_((int16_t*)L3869_ai_, (int16_t*)L3870_ai_Box, P3678_i_, P3678_i_);
                P3678_i_--;
                for (L3872_i_ = 0; L3872_i_ < 4; L3872_i_++) {
                        F7317_MAIN_CopyBytes_Alt((char*)L3870_ai_Box, (char*)L3871_ai_Box, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(L3871_ai_Box));
                        switch (L3872_i_) {
                                case 0:
                                        M769_BOX_RIGHT(L3871_ai_Box) = M768_BOX_LEFT(L3871_ai_Box) + P3678_i_;
                                        break;
                                case 1:
                                        M768_BOX_LEFT(L3871_ai_Box) = M769_BOX_RIGHT(L3871_ai_Box) - P3678_i_;
                                        break;
                                case 2:
                                        M771_BOX_BOTTOM(L3871_ai_Box) = M770_BOX_TOP(L3871_ai_Box) + P3678_i_;
                                        break;
                                case 3:
                                        M770_BOX_TOP(L3871_ai_Box) = M771_BOX_BOTTOM(L3871_ai_Box) - P3678_i_;
                        }
                        F7260_FillScreenBox(L3871_ai_Box, P3679_i_FillColor);
                }
        }
}

void F7031_DrawZoomedPortrait(
)
{
        REGISTER unsigned char* L3873_puc_Bitmap;
        int16_t L3874_ai_Box_ZoomedPortraitPixel[4];
#ifdef MEDIA773_SU1E_AU1E
        register int16_t L3876_i_X;
        register int16_t L3875_i_Y;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        REGISTER int16_t L3876_i_X;
        REGISTER int16_t L3875_i_Y;
#endif


        L3873_puc_Bitmap = G2243_OnScreenPortraitBitmaps[G7109_SelectedChampionIndex];
        M768_BOX_LEFT(L3874_ai_Box_ZoomedPortraitPixel) = M768_BOX_LEFT(G2277_ai_Box_SelectedPortraitZoomed);
        F0077_MOUSE_EnableScreenUpdate_CPSE();
#ifdef MEDIA773_SU1E_AU1E
        for (L3876_i_X = 0; L3876_i_X < 32; L3876_i_X++) {
                M769_BOX_RIGHT(L3874_ai_Box_ZoomedPortraitPixel) = M768_BOX_LEFT(L3874_ai_Box_ZoomedPortraitPixel) + 3 - 1;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        for (L3876_i_X = 0; L3876_i_X < G7035_PortraitWidth; L3876_i_X++) {
                M769_BOX_RIGHT(L3874_ai_Box_ZoomedPortraitPixel) = M768_BOX_LEFT(L3874_ai_Box_ZoomedPortraitPixel) + G7042_PortraitWidthZoomFactor - 1;
#endif
                M770_BOX_TOP(L3874_ai_Box_ZoomedPortraitPixel) = M770_BOX_TOP(G2277_ai_Box_SelectedPortraitZoomed);
#ifdef MEDIA773_SU1E_AU1E
                for (L3875_i_Y = 0; L3875_i_Y < 29; L3875_i_Y++) {
                        M771_BOX_BOTTOM(L3874_ai_Box_ZoomedPortraitPixel) = M770_BOX_TOP(L3874_ai_Box_ZoomedPortraitPixel) + 3 - 1;
#ifdef MEDIA772_SU1E
                        F7260_FillScreenBox(L3874_ai_Box_ZoomedPortraitPixel, F7276_GetPixelColor(L3873_puc_Bitmap, L3876_i_X, L3875_i_Y, 16));
#endif
#ifdef MEDIA762_AU1E
                        F7260_FillScreenBox(L3874_ai_Box_ZoomedPortraitPixel, F7276_GetPixelColor(L3873_puc_Bitmap, L3876_i_X, L3875_i_Y, 16, 29));
#endif
                        M770_BOX_TOP(L3874_ai_Box_ZoomedPortraitPixel) += 3;
                }
                M768_BOX_LEFT(L3874_ai_Box_ZoomedPortraitPixel) += 3;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                for (L3875_i_Y = 0; L3875_i_Y < G7036_PortraitHeight; L3875_i_Y++) {
                        M771_BOX_BOTTOM(L3874_ai_Box_ZoomedPortraitPixel) = M770_BOX_TOP(L3874_ai_Box_ZoomedPortraitPixel) + G7043_PortraitHeightZoomFactor - 1;
                        F7260_FillScreenBox(L3874_ai_Box_ZoomedPortraitPixel, F7276_GetPixelColor(L3873_puc_Bitmap, L3876_i_X, L3875_i_Y, G7035_PortraitWidth, G7036_PortraitHeight));
                        M770_BOX_TOP(L3874_ai_Box_ZoomedPortraitPixel) += G7043_PortraitHeightZoomFactor;
                }
                M768_BOX_LEFT(L3874_ai_Box_ZoomedPortraitPixel) += G7042_PortraitWidthZoomFactor;
#endif
        }
        F0078_MOUSE_DisableScreenUpdate();
}

void F7032_DrawChampionNameOnTopOfScreen(int16_t P3681_i_ChampionIndex)
{
        REGISTER int16_t* L3877_pi_Box;
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
        char* L3878_pc_;
#endif


        L3877_pi_Box = G2273_aai_Box_ChampionNames[P3681_i_ChampionIndex];
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
        L3878_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], P3681_i_ChampionIndex, C01_CHAMPION_INFO_NAME);
#endif
        F7260_FillScreenBox(L3877_pi_Box, C01_COLOR_DARK_GRAY);
#ifdef MEDIA772_SU1E
        F7339_PrintTextToScreen(M768_BOX_LEFT(L3877_pi_Box) + 2, 9, (P3681_i_ChampionIndex == G7109_SelectedChampionIndex) ? C09_COLOR_GOLD : C15_COLOR_WHITE, C01_COLOR_DARK_GRAY, G7111_Games[C0_GAME_SOURCE].Party.Champions[P3681_i_ChampionIndex].Name);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
        F7339_PrintTextToScreen(M768_BOX_LEFT(L3877_pi_Box) + 2, 9, (P3681_i_ChampionIndex == G7109_SelectedChampionIndex) ? C09_COLOR_GOLD : C15_COLOR_WHITE, C01_COLOR_DARK_GRAY, L3878_pc_);
#endif
}

void F7033_DrawPortraitsAndNamesOnTopOfScreen(int16_t P3682_i_ChampionIndex, int16_t P3683_i_FillColor)
{
        int16_t L3879_ai_[4];


        F0077_MOUSE_EnableScreenUpdate_CPSE();
        if (P3682_i_ChampionIndex < G7114_LoadedChampionCount) {
                F7032_DrawChampionNameOnTopOfScreen(P3682_i_ChampionIndex);
                F7030_DrawFilledBox(G2275_aai_Box_Portraits[P3682_i_ChampionIndex], 1, P3683_i_FillColor, C01_COLOR_DARK_GRAY);
#ifdef MEDIA772_SU1E
                F7259_DrawBitmapOnScreen(G2243_OnScreenPortraitBitmaps[P3682_i_ChampionIndex], G2275_aai_Box_Portraits[P3682_i_ChampionIndex], 16, CM1_COLOR_NO_TRANSPARENCY);
#endif
#ifdef MEDIA762_AU1E
                F0132_VIDEO_Blit(G2243_OnScreenPortraitBitmaps[P3682_i_ChampionIndex], G0348_Bitmap_Screen, G2275_aai_Box_Portraits[P3682_i_ChampionIndex], 0, 0, 32, 320, CM1_COLOR_NO_TRANSPARENCY, 29, 200);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7259_DrawBitmapOnScreen(G2243_OnScreenPortraitBitmaps[P3682_i_ChampionIndex], G2275_aai_Box_Portraits[P3682_i_ChampionIndex], G7035_PortraitWidth, CM1_COLOR_NO_TRANSPARENCY, G7036_PortraitHeight);
#endif
        } else {
                F7317_MAIN_CopyBytes_Alt((char*)G2272_MouseInputs[P3682_i_ChampionIndex].Box, (char*)L3879_ai_, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(L3879_ai_));
                M771_BOX_BOTTOM(L3879_ai_) += 1;
                F7260_FillScreenBox(L3879_ai_, C00_COLOR_BLACK);
        }
        F0078_MOUSE_DisableScreenUpdate();
}

void F7034_DrawButton(REGISTER MOUSE2_INPUT* P3684_ps_, char* P3685_pc_String, int16_t P3686_i_FillColor)
{
        int16_t L3880_ai_Box[4];
        char L5825_ac_Unreferenced[8];
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        UDSTRUCT3 L3881_s_;
#endif


        F0077_MOUSE_EnableScreenUpdate_CPSE();
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        F7342_BuildUDSTRUCT3(P3685_pc_String, &L3881_s_);
#endif
        F7317_MAIN_CopyBytes_Alt((char*)P3684_ps_->Box, (char*)L3880_ai_Box, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)sizeof(L3880_ai_Box));
        F7030_DrawFilledBox(L3880_ai_Box, 2, P3686_i_FillColor, C00_COLOR_BLACK);
#ifdef MEDIA773_SU1E_AU1E
        F7339_PrintTextToScreen(((M768_BOX_LEFT(L3880_ai_Box) + M769_BOX_RIGHT(L3880_ai_Box)) >> 1) - (F0090_strlen(P3685_pc_String) * 3) + 1, M771_BOX_BOTTOM(L3880_ai_Box) - 2, C15_COLOR_WHITE, C00_COLOR_BLACK, P3685_pc_String);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        F7339_PrintTextToScreen(((M768_BOX_LEFT(L3880_ai_Box) + M769_BOX_RIGHT(L3880_ai_Box)) >> 1) - (L3881_s_.i_E >> 1), M771_BOX_BOTTOM(L3880_ai_Box) - 2, C15_COLOR_WHITE, C00_COLOR_BLACK, P3685_pc_String);
#endif
        F0078_MOUSE_DisableScreenUpdate();

}

void F7035_SetSelectedColorBox(int16_t P3687_i_ColorIndex, REGISTER int16_t* P3688_pi_Box)
{
        *P3688_pi_Box++ = G7024_SelectedColorBoxX1;
        *P3688_pi_Box++ = G7025_SelectedColorBoxX2;
#ifdef MEDIA773_SU1E_AU1E
        *P3688_pi_Box++ = (P3687_i_ColorIndex * 8) + G7026_SelectedColorBoxY1Base;
        *P3688_pi_Box = *(P3688_pi_Box - 1) + 8 - 2;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        *P3688_pi_Box++ = G7026_SelectedColorBoxY1Base + (P3687_i_ColorIndex * G7041_SelectedColorBoxHeight);
#endif
#ifdef MEDIA671_F31E_F31J_P31J
        *P3688_pi_Box = G7041_SelectedColorBoxHeight - 2 + *(P3688_pi_Box - 1);
#endif
#ifdef MEDIA699_X31J_AU2E_AU3E
        *P3688_pi_Box = *(P3688_pi_Box - 1) + G7041_SelectedColorBoxHeight - 2;
#endif
}

void F7036_SetSelectedColorIndex(int16_t P3689_i_)
{
        int16_t L3882_ai_[4];
        char L5826_ac_Unreferenced[8];


        if (P3689_i_ != G7107_SelectedColorIndex) {
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                if (G7107_SelectedColorIndex >= 0) {
                        F7035_SetSelectedColorBox(G7107_SelectedColorIndex, (int16_t*)&L3882_ai_);
                        F7030_DrawFilledBox(L3882_ai_, 1, C00_COLOR_BLACK, G2274_ColorPalette[G7107_SelectedColorIndex]);
                }
                F7035_SetSelectedColorBox(G7107_SelectedColorIndex = P3689_i_, (int16_t*)&L3882_ai_);
                F7030_DrawFilledBox(L3882_ai_, 1, C15_COLOR_WHITE, G2274_ColorPalette[G7107_SelectedColorIndex]);
                F0078_MOUSE_DisableScreenUpdate();
        }
}

void F7037_UpdateUndoBitmap(
)
{
        G2329_s_UndoPortrait.Modified = G2248_as_OnDiskPortraits[G7109_SelectedChampionIndex].Modified;
#ifdef MEDIA773_SU1E_AU1E
        F7317_MAIN_CopyBytes_Alt(G2243_OnScreenPortraitBitmaps[G7109_SelectedChampionIndex], G2329_s_UndoPortrait.PortraitBitmap, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        F7317_MAIN_CopyBytes_Alt((char*)G2243_OnScreenPortraitBitmaps[G7109_SelectedChampionIndex], G2329_s_UndoPortrait.PortraitBitmap, MASK0x0008_MEMREQ, MASK0x0400_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
#endif
}

void F7038_PrintChampionNameOrTitleForEdition(char* P3690_pc_, int16_t P3691_i_MouseInputIndex, int16_t P3692_i_)
{
        REGISTER int16_t* L3883_pi_Box;
        REGISTER int16_t L3885_i_;
        REGISTER int16_t L3886_i_;
        REGISTER int16_t L3884_i_;


        L3883_pi_Box = G2272_MouseInputs[P3691_i_MouseInputIndex].Box;
        L3884_i_ = F0090_strlen(P3690_pc_);
        G7104_TextCursorVisible = C0_FALSE;
        F7260_FillScreenBox(L3883_pi_Box, C01_COLOR_DARK_GRAY);
        F7339_PrintTextToScreen(L3885_i_ = M768_BOX_LEFT(L3883_pi_Box) + 2, L3886_i_ = M771_BOX_BOTTOM(L3883_pi_Box) - 2, C09_COLOR_GOLD, C01_COLOR_DARK_GRAY, P3690_pc_);
#ifdef MEDIA773_SU1E_AU1E
        F7339_PrintTextToScreen((L3884_i_ * 6) + L3885_i_, L3886_i_, C09_COLOR_GOLD, C01_COLOR_DARK_GRAY, &G7003_[19 - (P3692_i_ - L3884_i_)]);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        F7339_PrintTextToScreen((L3884_i_ * G7053_TextCharacterWidth) + L3885_i_, L3886_i_, C09_COLOR_GOLD, C01_COLOR_DARK_GRAY, &G7003_[19 - (P3692_i_ - L3884_i_)]);
#endif
}

void F7039_DrawHealthOrStaminaOrMana(char* P3693_pc_Name, int16_t P3694_i_Value, int16_t P3695_i_ScreenY)
{
#ifdef MEDIA773_SU1E_AU1E
        char L3887_ac_[20];
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        char L3887_ac_[30];
#endif


        F7101_sprintf(L3887_ac_, "%s %d", P3693_pc_Name, P3694_i_Value);
#ifdef MEDIA773_SU1E_AU1E
        F7339_PrintTextToScreen(17, P3695_i_ScreenY, C13_COLOR_LIGHTEST_GRAY, C00_COLOR_BLACK, L3887_ac_);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        F7339_PrintTextToScreen(G7029_HealthStaminaManaScreenX, P3695_i_ScreenY, C13_COLOR_LIGHTEST_GRAY, C00_COLOR_BLACK, L3887_ac_);
#endif
}

void F7040_SelectChampion(REGISTER int16_t P3696_i_ChampionIndex, BOOLEAN P3697_B_UpdateUndoBitmap)
{
        REGISTER int16_t L3896_i_;
        REGISTER int16_t L3888_i_;
        REGISTER int16_t L3895_i_;
        REGISTER long L3889_l_;
        int16_t L3890_ai_Box[4];
#ifdef MEDIA773_SU1E_AU1E
        char L3891_ac_[20];
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        char L3891_ac_[30];
#endif
#ifdef MEDIA772_SU1E
        register CHAMPION* L3892_pc_Champion;
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
        char* L3892_pc_ChampionName;
        char* L3893_pc_ChampionTitle;
        SKILL* L3894_ps_;
#endif


        if ((L3896_i_ = G7109_SelectedChampionIndex) != P3696_i_ChampionIndex) {
                G7109_SelectedChampionIndex = P3696_i_ChampionIndex;
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                if (L3896_i_ >= 0) {
                        F7033_DrawPortraitsAndNamesOnTopOfScreen(L3896_i_, C00_COLOR_BLACK);
                }
                if (P3697_B_UpdateUndoBitmap) {
                        F7037_UpdateUndoBitmap();
                }
                F7033_DrawPortraitsAndNamesOnTopOfScreen(P3696_i_ChampionIndex, C15_COLOR_WHITE);
#ifdef MEDIA772_SU1E
                F7259_DrawBitmapOnScreen(G2267_auc_Graphic_Mirror, G2276_ai_Box_Mirror, 24, CM1_COLOR_NO_TRANSPARENCY);
                F7259_DrawBitmapOnScreen(G2243_OnScreenPortraitBitmaps[P3696_i_ChampionIndex], G2279_ai_Box_SelectedPortraitSmall, 16, C01_COLOR_DARK_GRAY);
#endif
#ifdef MEDIA762_AU1E
                F0132_VIDEO_Blit(G7117_Bitmap_Mirror, G0348_Bitmap_Screen, G2276_ai_Box_Mirror, 0, 0, 48, 320, CM1_COLOR_NO_TRANSPARENCY, 41, 200);
                F0132_VIDEO_Blit(G2243_OnScreenPortraitBitmaps[P3696_i_ChampionIndex], G0348_Bitmap_Screen, G2279_ai_Box_SelectedPortraitSmall, 0, 0, 32, 320, C01_COLOR_DARK_GRAY, 29, 200);
#endif
#ifdef MEDIA773_SU1E_AU1E
                F7260_FillScreenBox(G2269_aai_Box_StatisticsArea, C00_COLOR_BLACK);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7259_DrawBitmapOnScreen(G7117_Bitmap_Mirror, G2276_ai_Box_Mirror, G7037_MirrorBitmap_Width, CM1_COLOR_NO_TRANSPARENCY, G7038_MirrorBitmap_Height);
                F7259_DrawBitmapOnScreen(G2243_OnScreenPortraitBitmaps[P3696_i_ChampionIndex], G2279_ai_Box_SelectedPortraitSmall, G7035_PortraitWidth, C01_COLOR_DARK_GRAY, G7036_PortraitHeight);
                F7271_ClearStatisticsArea();
#endif
#ifdef MEDIA772_SU1E
                L3892_pc_Champion = &G7111_Games[C0_GAME_SOURCE].Party.Champions[P3696_i_ChampionIndex];
                F7038_PrintChampionNameOrTitleForEdition(L3892_pc_Champion->Name, 13, 7);
                F7038_PrintChampionNameOrTitleForEdition(L3892_pc_Champion->Title, 14, 19);
                F7027_DrawTextCursor(C0_EDIT_CHAMPION_NAME, F0090_strlen(L3892_pc_Champion->Name));
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                L3892_pc_ChampionName = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], P3696_i_ChampionIndex, C01_CHAMPION_INFO_NAME);
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                L3893_pc_ChampionTitle = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], P3696_i_ChampionIndex, C02_CHAMPION_INFO_TITLE);
#endif
                F7038_PrintChampionNameOrTitleForEdition(L3892_pc_ChampionName, 13, 7);
#ifdef MEDIA762_AU1E
                L3893_pc_ChampionTitle = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], P3696_i_ChampionIndex, C02_CHAMPION_INFO_TITLE);
#endif
                F7038_PrintChampionNameOrTitleForEdition(L3893_pc_ChampionTitle, 14, 19);
                F7027_DrawTextCursor(C0_EDIT_CHAMPION_NAME, F0090_strlen(L3892_pc_ChampionName));
#endif
#ifdef MEDIA773_SU1E_AU1E
                L3888_i_ = 121;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                L3888_i_ = G7028_;
#endif
                for (L3896_i_ = 0; L3896_i_ <= 3; L3896_i_++) {
#ifdef MEDIA772_SU1E
                        L3889_l_ = L3892_pc_Champion->Skills[L3896_i_].Experience;
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                        L3894_ps_ = (SKILL*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], P3696_i_ChampionIndex, C27_CHAMPION_INFO_SKILLS);
                        L3889_l_ = L3894_ps_[L3896_i_].Experience;
#endif
                        L3895_i_ = 0;
                        while (L3889_l_ >= 500) {
                                L3889_l_ >>= 1;
                                L3895_i_++;
                        }
                        if (L3895_i_) {
                                if (--L3895_i_ >= 15) {
                                        L3895_i_ = 15;
                                }
                                F7101_sprintf(L3891_ac_, "%s %s", G0428_apc_SkillLevelNames[L3895_i_], G0417_apc_BaseSkillNames[L3896_i_]);
#ifdef MEDIA773_SU1E_AU1E
                                F7339_PrintTextToScreen(17, L3888_i_, C13_COLOR_LIGHTEST_GRAY, C00_COLOR_BLACK, L3891_ac_);
                                L3888_i_ += 7;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                F7339_PrintTextToScreen(G7027_, L3888_i_, C13_COLOR_LIGHTEST_GRAY, C00_COLOR_BLACK, L3891_ac_);
                                L3888_i_ += G7052_TextLineSpacing;
#endif
                        }
                }
#ifdef MEDIA773_SU1E_AU1E
                if (121 + 28 > L3888_i_) {
                        M768_BOX_LEFT(L3890_ai_Box) = 17;
                        M769_BOX_RIGHT(L3890_ai_Box) = (6 * 19) + 17;
                        M770_BOX_TOP(L3890_ai_Box) = L3888_i_ - (7 - 1);
                        M771_BOX_BOTTOM(L3890_ai_Box) = (7 << 2) + 121;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                if (L3888_i_ < G7028_ + 28) {
                        M768_BOX_LEFT(L3890_ai_Box) = G7027_;
                        M769_BOX_RIGHT(L3890_ai_Box) = G7027_ + (G7053_TextCharacterWidth * 19);
                        M770_BOX_TOP(L3890_ai_Box) = L3888_i_ - (G7052_TextLineSpacing - 1);
                        M771_BOX_BOTTOM(L3890_ai_Box) = (G7052_TextLineSpacing * 4) + G7028_;
#endif
                        F7260_FillScreenBox(L3890_ai_Box, C00_COLOR_BLACK);
                }
#ifdef MEDIA772_SU1E
                F7039_DrawHealthOrStaminaOrMana("HEALTH     ", L3892_pc_Champion->MaximumHealth, 154);
                F7039_DrawHealthOrStaminaOrMana("STAMINA    ", L3892_pc_Champion->MaximumStamina / 10, 154 + 7);
                F7039_DrawHealthOrStaminaOrMana("MANA       ", L3892_pc_Champion->MaximumMana, 154 + 14);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                L3896_i_ = F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], P3696_i_ChampionIndex, C18_CHAMPION_INFO_MAXIMUMHEALTH);
#ifdef MEDIA762_AU1E
                F7039_DrawHealthOrStaminaOrMana("HEALTH     ", L3896_i_, 154);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7039_DrawHealthOrStaminaOrMana(G7021_HEALTH, L3896_i_, G7030_HealthScreenY);
#endif
                L3896_i_ = F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], P3696_i_ChampionIndex, C20_CHAMPION_INFO_MAXIMUMSTAMINA);
#ifdef MEDIA762_AU1E
                F7039_DrawHealthOrStaminaOrMana("STAMINA    ", L3896_i_ / 10, 154 + 7);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7039_DrawHealthOrStaminaOrMana(G7022_STAMINA, L3896_i_ / 10, G7030_HealthScreenY + G7052_TextLineSpacing);
#endif
                L3896_i_ = F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], P3696_i_ChampionIndex, C22_CHAMPION_INFO_MAXIMUMMANA);
#ifdef MEDIA762_AU1E
                F7039_DrawHealthOrStaminaOrMana("MANA       ", L3896_i_, 154 + 14);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7039_DrawHealthOrStaminaOrMana(G7023_MANA, L3896_i_, (G7052_TextLineSpacing << 1) + G7030_HealthScreenY);
#endif
#endif
                F7031_DrawZoomedPortrait();
                F0078_MOUSE_DisableScreenUpdate();
        }
}

void F7041_ProcessKeyboardInput(
#ifdef MEDIA773_SU1E_AU1E
register unsigned int16_t P3698_ui_)
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
REGISTER unsigned short P3698_ui_)
#endif
{ /* Edit champion name or title */
        REGISTER char* L3897_pc_;
        REGISTER int16_t L3898_i_MaximumLength;
        REGISTER int16_t L3902_i_CharacterIndex;
        REGISTER int16_t L3899_i_;
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
        char* L3900_pc_;
#endif
#ifdef MEDIA667_P31J
        REGISTER unsigned int16_t L3901_ui_;
#endif
#ifdef MEDIA680_F31E_F31J_X31J_AU1E_AU2E_AU3E
        unsigned int16_t L3901_ui_;
#endif


        if (G7114_LoadedChampionCount && (G7109_SelectedChampionIndex != -1)) {
                L3902_i_CharacterIndex = G7105_EditChampionNameOrTitleCharacterIndex;
                if ((L3899_i_ = G7106_EditChampionNameOrTitle) != 0) {
#ifdef MEDIA772_SU1E
                        L3897_pc_ = G7111_Games[C0_GAME_SOURCE].Party.Champions[G7109_SelectedChampionIndex].Title;
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                        L3897_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], G7109_SelectedChampionIndex, C02_CHAMPION_INFO_TITLE);
#endif
                        L3898_i_MaximumLength = 19;
                } else {
#ifdef MEDIA772_SU1E
                        L3897_pc_ = G7111_Games[C0_GAME_SOURCE].Party.Champions[G7109_SelectedChampionIndex].Name;
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                        L3897_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], G7109_SelectedChampionIndex, C01_CHAMPION_INFO_NAME);
#endif
                        L3898_i_MaximumLength = 7;
                }
                if (P3698_ui_ == 27) { /* ESC ? */
#ifdef MEDIA772_SU1E
                        F0008_MAIN_ClearBytes(L3897_pc_, (long)(L3898_i_MaximumLength + 1));
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                        F0008_MAIN_ClearBytes(L3897_pc_, (long)(L3898_i_MaximumLength + 1));
#endif
                        L3902_i_CharacterIndex = 0;
                } else {
#ifdef MEDIA773_SU1E_AU1E
                        if (P3698_ui_ == 0x4B00) { /* Left arrow */
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        if (P3698_ui_ == 0x5208) { /* Left arrow */
#endif
#ifdef MEDIA696_X31J_P31J_SU1E_AU1E_AU2E_AU3E
                                if (L3902_i_CharacterIndex == 0) {
                                        return;
                                }
                                F7027_DrawTextCursor(L3899_i_, L3902_i_CharacterIndex - 1);
                                return;
#endif
#ifdef MEDIA670_F31E_F31J
                                if (L3902_i_CharacterIndex)
                                        F7027_DrawTextCursor(L3899_i_, L3902_i_CharacterIndex - 1);
                                return;
#endif
                        }
#ifdef MEDIA773_SU1E_AU1E
                        if (P3698_ui_ == 0x4B34) { /* Home */
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        if (P3698_ui_ == 0x520E) { /* Home */
#endif
                                F7027_DrawTextCursor(L3899_i_, 0);
                                return;
                        }
#ifdef MEDIA773_SU1E_AU1E
                        if (P3698_ui_ == 0x4D00) { /* Right arrow */
                                if (L3902_i_CharacterIndex >= (int16_t)F0090_strlen(L3897_pc_)) {
#endif
#ifdef MEDIA695_X31J_P31J_AU2E_AU3E
                        if (P3698_ui_ == 0x5209) { /* Right arrow */
                                if (L3902_i_CharacterIndex >= F0090_strlen(L3897_pc_)) {
#endif
#ifdef MEDIA696_X31J_P31J_SU1E_AU1E_AU2E_AU3E
                                        return;
                                }
                                F7027_DrawTextCursor(L3899_i_, L3902_i_CharacterIndex + 1);
                                return;
#endif
#ifdef MEDIA670_F31E_F31J
                        if (P3698_ui_ == 0x5209) { /* Right arrow */
                                if (L3902_i_CharacterIndex < F0090_strlen(L3897_pc_)) {
                                        F7027_DrawTextCursor(L3899_i_, L3902_i_CharacterIndex + 1);
                                }
                                return;
#endif
                        }
#ifdef MEDIA773_SU1E_AU1E
                        if (P3698_ui_ == 0x4D36) { /* End */
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        if (P3698_ui_ == 0x520F) { /* End */
#endif
                                F7027_DrawTextCursor(L3899_i_, F0090_strlen(L3897_pc_));
                                return;
                        }
#ifdef MEDIA773_SU1E_AU1E
                        if (P3698_ui_ == 0x4800) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        if (P3698_ui_ == 0x520A) {
#endif
                                if (L3899_i_ == 0) {
                                        return;
                                }
#ifdef MEDIA772_SU1E
                                F7027_DrawTextCursor(C0_EDIT_CHAMPION_NAME, F0090_strlen(G7111_Games[C0_GAME_SOURCE].Party.Champions[G7109_SelectedChampionIndex].Name));
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                L3900_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], G7109_SelectedChampionIndex, C01_CHAMPION_INFO_NAME);
                                F7027_DrawTextCursor(C0_EDIT_CHAMPION_NAME, F0090_strlen(L3900_pc_));
#endif
                                return;
                        }
#ifdef MEDIA773_SU1E_AU1E
                        if (P3698_ui_ == 0x4838) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        if (P3698_ui_ == 0x520D) {
#endif
                                if (L3899_i_ == 0) {
                                        return;
                                }
                                F7027_DrawTextCursor(C0_EDIT_CHAMPION_NAME, 0);
                                return;
                        }
#ifdef MEDIA773_SU1E_AU1E
                        if (P3698_ui_ == 0x5000) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        if (P3698_ui_ == 0x520B) {
#endif
                                if (L3899_i_ != 0) {
                                        return;
                                }
#ifdef MEDIA772_SU1E
                                F7027_DrawTextCursor(C1_EDIT_CHAMPION_TITLE, F0090_strlen(G7111_Games[C0_GAME_SOURCE].Party.Champions[G7109_SelectedChampionIndex].Title));
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                L3900_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], G7109_SelectedChampionIndex, C02_CHAMPION_INFO_TITLE);
                                F7027_DrawTextCursor(C1_EDIT_CHAMPION_TITLE, F0090_strlen(L3900_pc_));
#endif
                                return;
                        }
#ifdef MEDIA773_SU1E_AU1E
                        if (P3698_ui_ == 0x5032) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        if (P3698_ui_ == 0x5210) {
#endif
                                if (L3899_i_ != 0) {
                                        return;
                                }
                                F7027_DrawTextCursor(C1_EDIT_CHAMPION_TITLE, 0);
                                return;
                        }
                        if (P3698_ui_ == 8) {
                                if (L3902_i_CharacterIndex == 0)
                                        return;
#ifdef MEDIA772_SU1E
                                F7317_MAIN_CopyBytes_Alt(&L3897_pc_[L3902_i_CharacterIndex], &L3897_pc_[L3902_i_CharacterIndex - 1], MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)(L3898_i_MaximumLength - L3902_i_CharacterIndex) + 1);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                for (L3901_ui_ = L3902_i_CharacterIndex - 1; L3901_ui_ <= F0090_strlen(L3897_pc_); L3901_ui_++) {
                                        L3897_pc_[L3901_ui_] = L3897_pc_[L3901_ui_ + 1];
                                }
#endif
                                L3902_i_CharacterIndex--;
                        } else {
#ifdef MEDIA772_SU1E
                                if ((P3698_ui_ >= 'a') && (P3698_ui_ <= 'z')) {
                                        P3698_ui_ += 'A' - 'a';
                                }
#endif
#ifdef MEDIA762_AU1E
                                P3698_ui_ = (((P3698_ui_ & 0xDF) >= 'A') && ((P3698_ui_ & 0xDF) <= 'Z')) ? (P3698_ui_ & 0xDF) : P3698_ui_;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                P3698_ui_ = ((P3698_ui_ < 'a') || (P3698_ui_ > 'z')) ? P3698_ui_ : P3698_ui_ + 'A' - 'a';
#endif
                                if (L3902_i_CharacterIndex >= L3898_i_MaximumLength) {
                                        return;
                                }
#ifdef MEDIA772_SU1E
                                if (((P3698_ui_ < 'A') || (P3698_ui_ > 'Z')) && (P3698_ui_ != '.') && (P3698_ui_ != ',') && (P3698_ui_ != ';') && (P3698_ui_ != ':') && ((P3698_ui_ != ' ') || !L3902_i_CharacterIndex)) {
#endif
#ifdef MEDIA762_AU1E
                                if ((((P3698_ui_ & 0xDF) < 'A') || ((P3698_ui_ & 0xDF) > 'Z')) && (P3698_ui_ != '.') && (P3698_ui_ != ',') && (P3698_ui_ != ';') && (P3698_ui_ != ':') && ((P3698_ui_ != ' ') || !L3902_i_CharacterIndex)) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                if (((P3698_ui_ < 'A') || (P3698_ui_ > 'Z')) && ((P3698_ui_ < 'a') || (P3698_ui_ > 'z')) && (P3698_ui_ != '.') && (P3698_ui_ != ',') && (P3698_ui_ != ';') && (P3698_ui_ != ':') && ((P3698_ui_ != ' ') || !L3902_i_CharacterIndex)
#ifdef MEDIA768_AU2E_AU3E
                                    && (P3698_ui_ != '\'') && (P3698_ui_ != '-')
#endif
                                   ) {
#endif
                                        return;
                                }
#ifdef MEDIA772_SU1E
                                F7317_MAIN_CopyBytes_Alt(&L3897_pc_[L3902_i_CharacterIndex], &L3897_pc_[L3902_i_CharacterIndex + 1], MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, (long)(F0024_MAIN_GetMinimumValue(F0090_strlen(L3897_pc_), L3898_i_MaximumLength - 1) - L3902_i_CharacterIndex));
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                for (L3901_ui_ = L3898_i_MaximumLength - 1; L3901_ui_ > L3902_i_CharacterIndex; L3901_ui_--) { /* Insert letter */
                                        L3897_pc_[L3901_ui_] = L3897_pc_[L3901_ui_ - 1];
                                }
                                L3897_pc_[L3898_i_MaximumLength] = '\0';
#endif
                                L3897_pc_[L3902_i_CharacterIndex] = P3698_ui_;
                                L3902_i_CharacterIndex++;
                        }
                }
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                F7038_PrintChampionNameOrTitleForEdition(L3897_pc_, L3899_i_ + 13, L3898_i_MaximumLength);
                if (L3899_i_ == 0) {
                        F7032_DrawChampionNameOnTopOfScreen(G7109_SelectedChampionIndex);
                }
                F7027_DrawTextCursor(L3899_i_, L3902_i_CharacterIndex);
                F0078_MOUSE_DisableScreenUpdate();
        }
}

void F7042_DrawChampionEditorScreen(
)
{
        int16_t L3903_ai_[4];
        REGISTER int16_t L3904_i_;


        F0077_MOUSE_EnableScreenUpdate_CPSE();
#ifdef MEDIA772_SU1E
        F0008_MAIN_ClearBytes(G0348_Bitmap_Screen, (long)M075_BITMAP_BYTE_COUNT(320, 200));
#endif
#ifdef MEDIA762_AU1E
        F0008_MAIN_ClearBytes(G0348_Bitmap_Screen, (long)M075_BITMAP_BYTE_COUNT(320, 200));
#endif
#ifdef MEDIA773_SU1E_AU1E
        F7034_DrawButton(&G2272_MouseInputs[10], "LOAD CHAMPIONS", C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[11], "SAVE CHAMPIONS", C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[12], "MAKE NEW ADVENTURE", C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[7], "REVERT", C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[8], "UNDO", C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[16], "QUIT", C02_COLOR_LIGHT_GRAY);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        F7257_ClearScreen();
        F7034_DrawButton(&G2272_MouseInputs[10], G7054_LOAD_CHAMPIONS, C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[11], G7055_SAVE_CHAMPIONS, C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[12], G7056_MAKE_NEW_ADVENTURE, C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[7], G7057_REVERT, C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[8], G7058_UNDO, C02_COLOR_LIGHT_GRAY);
        F7034_DrawButton(&G2272_MouseInputs[16], G7059_QUIT, C02_COLOR_LIGHT_GRAY);
#endif
        F7030_DrawFilledBox(G2277_ai_Box_SelectedPortraitZoomed, 3, C03_COLOR_DARK_BROWN, C00_COLOR_BLACK);
        F7030_DrawFilledBox(G2278_ai_Box_ColorPalette, 2, C02_COLOR_LIGHT_GRAY, C00_COLOR_BLACK);
        F7040_SelectChampion(0, C1_TRUE);
        for (L3904_i_ = 1; L3904_i_ < G7114_LoadedChampionCount; L3904_i_++) {
                F7033_DrawPortraitsAndNamesOnTopOfScreen(L3904_i_, C00_COLOR_BLACK);
        }
        F7036_SetSelectedColorIndex(0);
        for (L3904_i_ = 1; L3904_i_ < 16; L3904_i_++) {
                F7035_SetSelectedColorBox(L3904_i_, (int16_t*)&L3903_ai_);
                F7260_FillScreenBox(L3903_ai_, G2274_ColorPalette[L3904_i_]);
        }
        F0078_MOUSE_DisableScreenUpdate();
}

BOOLEAN F7043_IsClickOnColorPaletteProcessed(int16_t P3699_i_X, int16_t P3700_i_Multiple)
{
#define AP3700_i_Y          P3700_i_Multiple
#define AP3700_i_ColorIndex P3700_i_Multiple
        if (F7006_IsPointInBox(G2272_MouseInputs[6].Box, P3699_i_X, AP3700_i_Y) == 0) {
                return C0_FALSE;
        }
        AP3700_i_Y -= G7026_SelectedColorBoxY1Base;
#ifdef MEDIA773_SU1E_AU1E
        AP3700_i_ColorIndex /= 8;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        AP3700_i_ColorIndex /= G7041_SelectedColorBoxHeight;
#endif
        if ((AP3700_i_ColorIndex >= 0) && (AP3700_i_ColorIndex <= 15)) {
                F7036_SetSelectedColorIndex(AP3700_i_ColorIndex);
        }
        return C1_TRUE;
}

void F7044_DrawPortraitPixel(
#ifdef MEDIA671_F31E_F31J_P31J
REGISTER int16_t P3701_i_X, int16_t P3702_i_Y)
{
        int16_t L3905_i_Color;
#endif
#ifdef MEDIA700_X31J_SU1E_AU1E_AU2E_AU3E
register int16_t P3701_i_X, register int16_t P3702_i_Y)
{
        register int16_t L3905_i_Color;
#endif
        int16_t L3906_ai_Box[4];
        REGISTER int16_t L3907_i_SelectedChampionIndex;


        L3905_i_Color = G2274_ColorPalette[G7107_SelectedColorIndex];
        L3907_i_SelectedChampionIndex = G7109_SelectedChampionIndex;
        G2248_as_OnDiskPortraits[L3907_i_SelectedChampionIndex].Modified = C1_TRUE;
#ifdef MEDIA772_SU1E
        F7277_SetPixelColor(G2243_OnScreenPortraitBitmaps[L3907_i_SelectedChampionIndex], P3701_i_X, P3702_i_Y, L3905_i_Color, 16);
        F7277_SetPixelColor(G0348_Bitmap_Screen, M768_BOX_LEFT(G2275_aai_Box_Portraits[L3907_i_SelectedChampionIndex]) + P3701_i_X, M770_BOX_TOP(G2275_aai_Box_Portraits[L3907_i_SelectedChampionIndex]) + P3702_i_Y, L3905_i_Color, C160_BYTE_WIDTH_SCREEN);
        F7277_SetPixelColor(G0348_Bitmap_Screen, M768_BOX_LEFT(G2279_ai_Box_SelectedPortraitSmall) + P3701_i_X, M770_BOX_TOP(G2279_ai_Box_SelectedPortraitSmall) + P3702_i_Y, (L3905_i_Color == C01_COLOR_DARK_GRAY) ? F7276_GetPixelColor(G2267_auc_Graphic_Mirror, P3701_i_X + 6, P3702_i_Y + 6, 24) : L3905_i_Color, C160_BYTE_WIDTH_SCREEN);
#endif
#ifdef MEDIA762_AU1E
        F7277_SetPixelColor(G2243_OnScreenPortraitBitmaps[L3907_i_SelectedChampionIndex], P3701_i_X, P3702_i_Y, L3905_i_Color, 16, 29);
        F7277_SetPixelColor(G0348_Bitmap_Screen, M768_BOX_LEFT(G2275_aai_Box_Portraits[L3907_i_SelectedChampionIndex]) + P3701_i_X, M770_BOX_TOP(G2275_aai_Box_Portraits[L3907_i_SelectedChampionIndex]) + P3702_i_Y, L3905_i_Color, C160_BYTE_WIDTH_SCREEN, 200);
        F7277_SetPixelColor(G0348_Bitmap_Screen, M768_BOX_LEFT(G2279_ai_Box_SelectedPortraitSmall) + P3701_i_X, M770_BOX_TOP(G2279_ai_Box_SelectedPortraitSmall) + P3702_i_Y, (L3905_i_Color == C01_COLOR_DARK_GRAY) ? F7276_GetPixelColor(G7117_Bitmap_Mirror, P3701_i_X + 6, P3702_i_Y + 6, 24, 41) : L3905_i_Color, C160_BYTE_WIDTH_SCREEN, 200);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        F7277_SetPixelColor(G2243_OnScreenPortraitBitmaps[L3907_i_SelectedChampionIndex], P3701_i_X, P3702_i_Y, L3905_i_Color, G7035_PortraitWidth, G7036_PortraitHeight);
        F7258_DrawScreenPixel(M768_BOX_LEFT(G2275_aai_Box_Portraits[L3907_i_SelectedChampionIndex]) + P3701_i_X, M770_BOX_TOP(G2275_aai_Box_Portraits[L3907_i_SelectedChampionIndex]) + P3702_i_Y, L3905_i_Color);
        F7258_DrawScreenPixel(M768_BOX_LEFT(G2279_ai_Box_SelectedPortraitSmall) + P3701_i_X, M770_BOX_TOP(G2279_ai_Box_SelectedPortraitSmall) + P3702_i_Y, (L3905_i_Color == C01_COLOR_DARK_GRAY) ? F7276_GetPixelColor(G7117_Bitmap_Mirror, P3701_i_X + G7039_MirrorPortraitLeftMargin, P3702_i_Y + G7040_MirrorPortraitTopMargin, G7037_MirrorBitmap_Width, G7038_MirrorBitmap_Height) : L3905_i_Color); /* C01_COLOR_DARK_GRAY is replaced by mirror pixels (transparency) */
#endif
#ifdef MEDIA773_SU1E_AU1E
        M768_BOX_LEFT(L3906_ai_Box) = (P3701_i_X * 3) + M768_BOX_LEFT(G2277_ai_Box_SelectedPortraitZoomed);
        M769_BOX_RIGHT(L3906_ai_Box) = 3 + M768_BOX_LEFT(L3906_ai_Box) - 1;
        M770_BOX_TOP(L3906_ai_Box) = (P3702_i_Y * 3) + M770_BOX_TOP(G2277_ai_Box_SelectedPortraitZoomed);
        M771_BOX_BOTTOM(L3906_ai_Box) = 3 + M770_BOX_TOP(L3906_ai_Box) - 1;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        L3906_ai_Box[0] = (P3701_i_X * G7042_PortraitWidthZoomFactor) + M768_BOX_LEFT(G2277_ai_Box_SelectedPortraitZoomed);
        L3906_ai_Box[1] = L3906_ai_Box[0] + (G7042_PortraitWidthZoomFactor - 1);
        L3906_ai_Box[2] = (P3702_i_Y * G7043_PortraitHeightZoomFactor) + M770_BOX_TOP(G2277_ai_Box_SelectedPortraitZoomed);
        L3906_ai_Box[3] = L3906_ai_Box[2] + (G7043_PortraitHeightZoomFactor - 1);
#endif
        F7260_FillScreenBox(L3906_ai_Box, L3905_i_Color);
}

BOOLEAN F7045_IsPortraitPixelDrawn(REGISTER int16_t P3703_i_X, REGISTER int16_t P3704_i_Y, int16_t P3705_i_)
{
        P3703_i_X -= M768_BOX_LEFT(G2277_ai_Box_SelectedPortraitZoomed); /* Convert screen X to portrait X */
#ifdef MEDIA773_SU1E_AU1E
        P3703_i_X /= 3;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        P3703_i_X /= G7042_PortraitWidthZoomFactor;
#endif
        P3704_i_Y -= M770_BOX_TOP(G2277_ai_Box_SelectedPortraitZoomed); /* Convert screen Y to portrait Y */
#ifdef MEDIA773_SU1E_AU1E
        P3704_i_Y /= 3;
        if ((P3703_i_X < 0) || (P3703_i_X >= 32) || (P3704_i_Y < 0) || (P3704_i_Y >= 29)) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        P3704_i_Y /= G7043_PortraitHeightZoomFactor;
        if ((P3703_i_X < 0) || (P3703_i_X >= G7035_PortraitWidth) || (P3704_i_Y < 0) || (P3704_i_Y >= G7036_PortraitHeight)) {
#endif
                return C0_FALSE;
        }
        if (P3705_i_ || (P3703_i_X != G7102_) || (P3704_i_Y != G7103_)) {
                G7102_ = P3703_i_X;
                G7103_ = P3704_i_Y;
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                F7044_DrawPortraitPixel(P3703_i_X, P3704_i_Y);
                F0078_MOUSE_DisableScreenUpdate();
        }
        return C1_TRUE;
}

void F7046_FloodFillBitmapArea(REGISTER int16_t P3706_i_X, REGISTER int16_t P3707_i_Y)
{
#ifdef MEDIA773_SU1E_AU1E
        register unsigned char* L3908_puc_;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        REGISTER int16_t* L3908_pi_;
#endif
        REGISTER unsigned char* L3909_puc_Bitmap;
        REGISTER int16_t L3910_i_;
        REGISTER int16_t L3911_i_;
#ifdef MEDIA773_SU1E_AU1E
        unsigned char L3912_auc_[1860];
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        int16_t* L3912_pi_;
        long L3913_l_;
#endif


#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        L3912_pi_ = NULL;
        L3913_l_ = ((G7035_PortraitWidth * G7036_PortraitHeight) + 2) * 4;
        L3912_pi_ = (int16_t*)F7023_Alloc(L3913_l_, MASK0x0400_MEMREQ);
#endif
        P3706_i_X -= M768_BOX_LEFT(G2277_ai_Box_SelectedPortraitZoomed);
#ifdef MEDIA773_SU1E_AU1E
        P3706_i_X /= 3;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        P3706_i_X /= G7042_PortraitWidthZoomFactor;
#endif
        P3707_i_Y -= M770_BOX_TOP(G2277_ai_Box_SelectedPortraitZoomed);
#ifdef MEDIA773_SU1E_AU1E
        P3707_i_Y /= 3;
        if ((P3706_i_X >= 0) && (P3706_i_X < 32) && (P3707_i_Y >= 0) && (P3707_i_Y < 29)) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        P3707_i_Y /= G7043_PortraitHeightZoomFactor;
        if ((P3706_i_X >= 0) && (P3706_i_X < G7035_PortraitWidth) && (P3707_i_Y >= 0) && (P3707_i_Y < G7036_PortraitHeight)) {
#endif
                L3909_puc_Bitmap = G2243_OnScreenPortraitBitmaps[G7109_SelectedChampionIndex];
#ifdef MEDIA772_SU1E
                L3911_i_ = F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y, 16);
#endif
#ifdef MEDIA762_AU1E
                L3911_i_ = F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y, 16, 29);
#endif
#ifdef MEDIA773_SU1E_AU1E
                if (L3911_i_ != G2274_ColorPalette[G7107_SelectedColorIndex]) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                L3911_i_ = F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y, G7035_PortraitWidth, G7036_PortraitHeight);
                if (G2274_ColorPalette[G7107_SelectedColorIndex] != L3911_i_) {
#endif
                        L3910_i_ = 1;
#ifdef MEDIA773_SU1E_AU1E
                        L3908_puc_ = L3912_auc_;
                        *L3908_puc_ = P3706_i_X;
                        *(L3908_puc_ + 1) = P3707_i_Y;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        L3908_pi_ = L3912_pi_;
                        *L3908_pi_ = P3706_i_X;
                        *(L3908_pi_ + 1) = P3707_i_Y;
#endif
                        F0077_MOUSE_EnableScreenUpdate_CPSE();
                        do {
#ifdef MEDIA773_SU1E_AU1E
                                F7044_DrawPortraitPixel(P3706_i_X = *L3908_puc_, P3707_i_Y = *(L3908_puc_ + 1));
                                if (P3707_i_Y) {
#ifdef MEDIA772_SU1E
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y - 1, 16) == L3911_i_) {
#endif
#ifdef MEDIA762_AU1E
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y - 1, 16, 29) == L3911_i_) {
#endif
                                                *L3908_puc_++ = P3706_i_X;
                                                *L3908_puc_++ = P3707_i_Y - 1;
                                                L3910_i_++;
                                        }
                                }
                                if ((29 - 1) > P3707_i_Y) {
#ifdef MEDIA772_SU1E
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y + 1, 16) == L3911_i_) {
#endif
#ifdef MEDIA762_AU1E
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y + 1, 16, 29) == L3911_i_) {
#endif
                                                *L3908_puc_++ = P3706_i_X;
                                                *L3908_puc_++ = P3707_i_Y + 1;
                                                L3910_i_++;
                                        }
                                }
                                if (P3706_i_X) {
#ifdef MEDIA772_SU1E
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X - 1, P3707_i_Y, 16) == L3911_i_) {
#endif
#ifdef MEDIA762_AU1E
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X - 1, P3707_i_Y, 16, 29) == L3911_i_) {
#endif
                                                *L3908_puc_++ = P3706_i_X - 1;
                                                *L3908_puc_++ = P3707_i_Y;
                                                L3910_i_++;
                                        }
                                }
                                if ((32 - 1) > P3706_i_X) {
#ifdef MEDIA772_SU1E
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X + 1, P3707_i_Y, 16) == L3911_i_) {
#endif
#ifdef MEDIA762_AU1E
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X + 1, P3707_i_Y, 16, 29) == L3911_i_) {
#endif
                                                *L3908_puc_++ = P3706_i_X + 1;
                                                *L3908_puc_++ = P3707_i_Y;
                                                L3910_i_++;
                                        }
                                }
                                L3908_puc_ -= 2;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                F7044_DrawPortraitPixel(P3706_i_X = *L3908_pi_, P3707_i_Y = *(L3908_pi_ + 1));
                                if (P3707_i_Y) {
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y - 1, G7035_PortraitWidth, G7036_PortraitHeight) == L3911_i_) {
                                                *L3908_pi_++ = P3706_i_X;
                                                *L3908_pi_++ = P3707_i_Y - 1;
                                                L3910_i_++;
                                        }
                                }
                                if (P3707_i_Y < (G7036_PortraitHeight - 1)) {
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X, P3707_i_Y + 1, G7035_PortraitWidth, G7036_PortraitHeight) == L3911_i_) {
                                                *L3908_pi_++ = P3706_i_X;
                                                *L3908_pi_++ = P3707_i_Y + 1;
                                                L3910_i_++;
                                        }
                                }
                                if (P3706_i_X) {
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X - 1, P3707_i_Y, G7035_PortraitWidth, G7036_PortraitHeight) == L3911_i_) {
                                                *L3908_pi_++ = P3706_i_X - 1;
                                                *L3908_pi_++ = P3707_i_Y;
                                                L3910_i_++;
                                        }
                                }
                                if (P3706_i_X < (G7035_PortraitWidth - 1)) {
                                        if (F7276_GetPixelColor(L3909_puc_Bitmap, P3706_i_X + 1, P3707_i_Y, G7035_PortraitWidth, G7036_PortraitHeight) == L3911_i_) {
                                                *L3908_pi_++ = P3706_i_X + 1;
                                                *L3908_pi_++ = P3707_i_Y;
                                                L3910_i_++;
                                        }
                                }
                                L3908_pi_ -= 2;
#endif
                        } while (--L3910_i_);
                        F0078_MOUSE_DisableScreenUpdate();
                }
        }
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        if (L3912_pi_) {
                F7024_Free(L3912_pi_);
        }
#endif
}

void F7047_SwapOnDiskAndOnScreenPortraits(
)
{
        REGISTER int16_t L3914_i_;


        for (L3914_i_ = 0; L3914_i_ < G7114_LoadedChampionCount; L3914_i_++) {
#ifdef MEDIA773_SU1E_AU1E
                F7317_MAIN_CopyBytes_Alt(G2248_as_OnDiskPortraits[L3914_i_].PortraitBitmap, G2328_s_TempPortrait.PortraitBitmap, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
                F7317_MAIN_CopyBytes_Alt(G2243_OnScreenPortraitBitmaps[L3914_i_], G2248_as_OnDiskPortraits[L3914_i_].PortraitBitmap, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
                F7317_MAIN_CopyBytes_Alt(G2328_s_TempPortrait.PortraitBitmap, G2243_OnScreenPortraitBitmaps[L3914_i_], MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                F7317_MAIN_CopyBytes_Alt((char*)G2248_as_OnDiskPortraits[L3914_i_].PortraitBitmap, G2328_s_TempPortrait.PortraitBitmap, MASK0x0400_MEMREQ, MASK0x0008_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
                F7317_MAIN_CopyBytes_Alt((char*)G2243_OnScreenPortraitBitmaps[L3914_i_], (char*)G2248_as_OnDiskPortraits[L3914_i_].PortraitBitmap, MASK0x0008_MEMREQ, MASK0x0400_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
                F7317_MAIN_CopyBytes_Alt((char*)G2328_s_TempPortrait.PortraitBitmap, (char*)G2243_OnScreenPortraitBitmaps[L3914_i_], MASK0x0400_MEMREQ, MASK0x0008_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
#endif
        }
}

void F7048_CopyPortraitsAfterGameLoaded(BOOLEAN P3708_B_DrawOnScreen)
{
        REGISTER int16_t L3915_i_;


        G7109_SelectedChampionIndex = -1;
#ifdef MEDIA762_AU1E
        for (L3915_i_ = 0; L3915_i_ < G7114_LoadedChampionCount; L3915_i_++) {
                G2248_as_OnDiskPortraits[L3915_i_].PortraitBitmap = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], L3915_i_, C31_CHAMPION_INFO_PORTRAIT);
        }
#endif
        for (L3915_i_ = 0; L3915_i_ < 4; L3915_i_++) {
                if (L3915_i_ < G7114_LoadedChampionCount) {
#ifdef MEDIA772_SU1E
                        G2248_as_OnDiskPortraits[L3915_i_].PortraitBitmap = G7111_Games[C0_GAME_SOURCE].Party.Champions[L3915_i_].Portrait;
                        F7317_MAIN_CopyBytes_Alt(G2248_as_OnDiskPortraits[L3915_i_].PortraitBitmap, G2243_OnScreenPortraitBitmaps[L3915_i_], MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
#endif
#ifdef MEDIA762_AU1E
                        F7317_MAIN_CopyBytes_Alt((char*)G2248_as_OnDiskPortraits[L3915_i_].PortraitBitmap, (char*)G2243_OnScreenPortraitBitmaps[L3915_i_], MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        G2248_as_OnDiskPortraits[L3915_i_].PortraitBitmap = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], L3915_i_, C31_CHAMPION_INFO_PORTRAIT);
                        F7317_MAIN_CopyBytes_Alt((char*)G2248_as_OnDiskPortraits[L3915_i_].PortraitBitmap, (char*)G2243_OnScreenPortraitBitmaps[L3915_i_], MASK0x0400_MEMREQ, MASK0x0008_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
#endif
                } else {
                        G2248_as_OnDiskPortraits[L3915_i_].PortraitBitmap = NULL;
#ifdef MEDIA772_SU1E
                        F0008_MAIN_ClearBytes(G2243_OnScreenPortraitBitmaps[L3915_i_], 464L);
#endif
#ifdef MEDIA762_AU1E
                        F0008_MAIN_ClearBytes(G2243_OnScreenPortraitBitmaps[L3915_i_], 464L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                        F7261_ClearBitmap(G2243_OnScreenPortraitBitmaps[L3915_i_], G7035_PortraitWidth, G7036_PortraitHeight);
#endif
                }
                G2248_as_OnDiskPortraits[L3915_i_].Modified = C0_FALSE;
        }
        if (P3708_B_DrawOnScreen) {
                if (G7114_LoadedChampionCount) {
                        F7040_SelectChampion(0, C1_TRUE);
                } else {
                        F7033_DrawPortraitsAndNamesOnTopOfScreen(0, C00_COLOR_BLACK);
                }
                for (L3915_i_ = 1; L3915_i_ < 4; L3915_i_++) {
                        F7033_DrawPortraitsAndNamesOnTopOfScreen(L3915_i_, C00_COLOR_BLACK);
                }
        }
}

#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
void F7049_CopyBackupPortrait(BACKUP_PORTRAIT* P3709_ps_Source, BACKUP_PORTRAIT* P3710_ps_Destination)
{
        P3710_ps_Destination->Modified = P3709_ps_Source->Modified;
        F7317_MAIN_CopyBytes_Alt((char*)P3709_ps_Source->PortraitBitmap, (char*)P3710_ps_Destination->PortraitBitmap, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
}
#endif

void F7050_MainLoop(
)
{
        REGISTER int16_t L3917_i_;
        REGISTER int16_t L3916_i_;
        UD_COMMAND L3918_s_Command;
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
        char* L3920_pc_;
        char* L3921_pc_;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        int16_t L3922_i_MouseX;
        int16_t L3923_i_MouseY;
#endif


#ifdef MEDIA772_SU1E
        G0578_B_UseByteBoxCoordinates = C0_FALSE;
#endif
        G7107_SelectedColorIndex = -1;
        F7048_CopyPortraitsAfterGameLoaded(C0_FALSE);
        F7042_DrawChampionEditorScreen();
        F7012_AddToInputInfoList(&G2280_);
        for (;;) { /*_Infinite loop_*/
                do {
                        switch (L3917_i_ = F7015_ProcessNextUDCommand(&L3918_s_Command) & 0xFF) {
                                case C01_COMMAND_SELECT_CHAMPION_1:
                                case C02_COMMAND_SELECT_CHAMPION_2:
                                case C03_COMMAND_SELECT_CHAMPION_3:
                                case C04_COMMAND_SELECT_CHAMPION_4:
                                        if (--L3917_i_ < G7114_LoadedChampionCount) {
                                                F7040_SelectChampion(L3917_i_, C1_TRUE);
                                        }
                                        break;
                                case C05_COMMAND_DRAW_PIXEL:
                                        F7037_UpdateUndoBitmap();
                                        F7045_IsPortraitPixelDrawn(L3918_s_Command.X, L3918_s_Command.Y, C1_TRUE);
#ifdef MEDIA772_SU1E
                                        while (G3506_ & 1) {
                                                if (F7045_IsPortraitPixelDrawn(G3503_i_MouseX, G3504_i_MouseY, C0_FALSE) == 0) {
#endif
#ifdef MEDIA762_AU1E
                                        while (F2008_IsLeftMouseButtonDown()) {
                                                if (F7045_IsPortraitPixelDrawn(F2009_GetMouseX(), F2010_GetMouseY(), C0_FALSE) == 0) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                        while (M007_GET(F7274_GetMouseStatus(&L3922_i_MouseX, &L3923_i_MouseY), MASK0x0002_MOUSE_LEFT_BUTTON)) {
                                                if (F7045_IsPortraitPixelDrawn(L3922_i_MouseX, L3923_i_MouseY, C0_FALSE) == 0) {
#endif
                                                        break;
                                                }
                                        }
                                        break;
                                case C06_COMMAND_DRAW_FLOOD_FILL: /* Draw selected pixel and all adjacent pixels of the same color */
                                        F7037_UpdateUndoBitmap();
                                        F7046_FloodFillBitmapArea(L3918_s_Command.X, L3918_s_Command.Y);
                                        break;
                                case C07_COMMAND_SELECT_COLOR_IN_PALETTE:
                                        F7043_IsClickOnColorPaletteProcessed(L3918_s_Command.X, L3918_s_Command.Y);
#ifdef MEDIA772_SU1E
                                        while (G3506_ & 1) {
                                                if (!F7043_IsClickOnColorPaletteProcessed(G3503_i_MouseX, G3504_i_MouseY)) {
#endif
#ifdef MEDIA762_AU1E
                                        while (F2008_IsLeftMouseButtonDown()) {
                                                if (!F7043_IsClickOnColorPaletteProcessed(F2009_GetMouseX(), F2010_GetMouseY())) {
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                        while (M007_GET(F7274_GetMouseStatus(&L3922_i_MouseX, &L3923_i_MouseY), MASK0x0002_MOUSE_LEFT_BUTTON)) {
                                                if (!F7043_IsClickOnColorPaletteProcessed(L3922_i_MouseX, L3923_i_MouseY)) {
#endif
                                                        break;
                                                }
                                        }
                                        break;
                                case C08_COMMAND_REVERT:
                                        F7248_InvertBox(G2272_MouseInputs[7].Box);
                                        L3916_i_ = G7109_SelectedChampionIndex;
                                        if (G2248_as_OnDiskPortraits[L3916_i_].Modified) {
                                                F7037_UpdateUndoBitmap();
                                                G2248_as_OnDiskPortraits[L3916_i_].Modified = C0_FALSE;
#ifdef MEDIA773_SU1E_AU1E
                                                F7317_MAIN_CopyBytes_Alt(G2248_as_OnDiskPortraits[L3916_i_].PortraitBitmap, G2243_OnScreenPortraitBitmaps[L3916_i_], MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                                F7317_MAIN_CopyBytes_Alt((char*)G2248_as_OnDiskPortraits[L3916_i_].PortraitBitmap, (char*)G2243_OnScreenPortraitBitmaps[L3916_i_], MASK0x0400_MEMREQ, MASK0x0008_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
#endif
                                                G7109_SelectedChampionIndex = -1;
                                                F7040_SelectChampion(L3916_i_, C0_FALSE);
                                        } else {
#ifdef MEDIA772_SU1E
                                                M526_WaitVerticalBlank();
                                                M526_WaitVerticalBlank();
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                                F7323_WaitVerticalBlank();
                                                F7323_WaitVerticalBlank();
#endif
                                        }
                                        F7248_InvertBox(G2272_MouseInputs[7].Box);
                                        break;
                                case C09_COMMAND_UNDO:
                                        F7248_InvertBox(G2272_MouseInputs[8].Box);
                                        L3916_i_ = G7109_SelectedChampionIndex;
                                        G2328_s_TempPortrait.Modified = G2248_as_OnDiskPortraits[L3916_i_].Modified;
                                        G2248_as_OnDiskPortraits[L3916_i_].Modified = G2329_s_UndoPortrait.Modified;
#ifdef MEDIA773_SU1E_AU1E
                                        F7317_MAIN_CopyBytes_Alt(G2243_OnScreenPortraitBitmaps[L3916_i_], G2328_s_TempPortrait.PortraitBitmap, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
                                        F7317_MAIN_CopyBytes_Alt(G2329_s_UndoPortrait.PortraitBitmap, G2243_OnScreenPortraitBitmaps[L3916_i_], MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
                                        F7317_MAIN_CopyBytes_Alt(&G2328_s_TempPortrait, &G2329_s_UndoPortrait, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 466L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                        F7317_MAIN_CopyBytes_Alt((char*)G2243_OnScreenPortraitBitmaps[L3916_i_], G2328_s_TempPortrait.PortraitBitmap, MASK0x0008_MEMREQ, MASK0x0400_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
                                        F7317_MAIN_CopyBytes_Alt(G2329_s_UndoPortrait.PortraitBitmap, (char*)G2243_OnScreenPortraitBitmaps[L3916_i_], MASK0x0400_MEMREQ, MASK0x0008_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
                                        F7049_CopyBackupPortrait(&G2328_s_TempPortrait, &G2329_s_UndoPortrait);
#endif
                                        G7109_SelectedChampionIndex = -1;
                                        F7040_SelectChampion(L3916_i_, C0_FALSE);
                                        F7248_InvertBox(G2272_MouseInputs[8].Box);
                                        break;
                                case C11_COMMAND_LOAD_CHAMPIONS:
                                        F7248_InvertBox(G2272_MouseInputs[10].Box);
                                        F7037_UpdateUndoBitmap();
                                        switch (F7004_LoadChampions()) {
                                                case 2: /* Portrait loaded */
                                                        L3916_i_ = G7109_SelectedChampionIndex;
#ifdef MEDIA773_SU1E_AU1E
                                                        F7317_MAIN_CopyBytes_Alt(&G2246_CMPData.Portrait, G2243_OnScreenPortraitBitmaps[L3916_i_], MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
                                                        F7317_MAIN_CopyBytes_Alt(G2243_OnScreenPortraitBitmaps[L3916_i_], G2248_as_OnDiskPortraits[L3916_i_].PortraitBitmap, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                                        F7251_ConvertBitmapFromAtariSTPlanar(G2246_CMPData.Portrait, G2243_OnScreenPortraitBitmaps[L3916_i_], G7035_PortraitWidth, G7036_PortraitHeight);
                                                        F7317_MAIN_CopyBytes_Alt((char*)G2243_OnScreenPortraitBitmaps[L3916_i_], (char*)G2248_as_OnDiskPortraits[L3916_i_].PortraitBitmap, MASK0x0008_MEMREQ, MASK0x0400_MEMREQ, F7249_GetBitmapByteCount(G7035_PortraitWidth, G7036_PortraitHeight));
#endif
                                                        G2248_as_OnDiskPortraits[L3916_i_].Modified = C0_FALSE;
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                                        L3920_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], L3916_i_, C01_CHAMPION_INFO_NAME);
                                                        L3921_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], L3916_i_, C02_CHAMPION_INFO_TITLE);
#endif
#ifdef MEDIA772_SU1E
                                                        F7317_MAIN_CopyBytes_Alt(&G2246_CMPData.Name, G7111_Games[C0_GAME_SOURCE].Party.Champions[L3916_i_].Name, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                                                        F7317_MAIN_CopyBytes_Alt(&G2246_CMPData.Title, G7111_Games[C0_GAME_SOURCE].Party.Champions[L3916_i_].Title, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 20L);
#endif
#ifdef MEDIA762_AU1E
                                                        F7317_MAIN_CopyBytes_Alt(&G2246_CMPData.Name, L3920_pc_, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                                                        F7317_MAIN_CopyBytes_Alt(&G2246_CMPData.Title, L3921_pc_, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 20L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                                        F7317_MAIN_CopyBytes_Alt(M772_CAST_PC(G2246_CMPData.Name), L3920_pc_, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8);
                                                        F7317_MAIN_CopyBytes_Alt(M772_CAST_PC(G2246_CMPData.Title), L3921_pc_, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 20);
#endif
                                                        G7109_SelectedChampionIndex = -1;
                                                        F7040_SelectChampion(L3916_i_, C0_FALSE);
                                                        break;
                                                case 1:  /* Game loaded */
                                                        F7048_CopyPortraitsAfterGameLoaded(C1_TRUE);
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                                case 0:
                                                case -1:
                                                case -2:
                                                case -3:
                                                        break;
#endif
                                        }
                                        F7248_InvertBox(G2272_MouseInputs[10].Box);
                                        break;
                                case C12_COMMAND_SAVE_CHAMPIONS:
                                        F7248_InvertBox(G2272_MouseInputs[11].Box);
#ifdef MEDIA773_SU1E_AU1E
                                        F7317_MAIN_CopyBytes_Alt(G2243_OnScreenPortraitBitmaps[G7109_SelectedChampionIndex], &G2246_CMPData.Portrait, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 464L);
#endif
#ifdef MEDIA772_SU1E
                                        F7317_MAIN_CopyBytes_Alt(G7111_Games[C0_GAME_SOURCE].Party.Champions[G7109_SelectedChampionIndex].Name, &G2246_CMPData.Name, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                                        F7317_MAIN_CopyBytes_Alt(G7111_Games[C0_GAME_SOURCE].Party.Champions[G7109_SelectedChampionIndex].Title, &G2246_CMPData.Title, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 20L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                        F7252_ConvertBitmapToAtariSTPlanar(M772_CAST_PC(G2243_OnScreenPortraitBitmaps[G7109_SelectedChampionIndex]), M772_CAST_PC(G2246_CMPData.Portrait), G7035_PortraitWidth, G7036_PortraitHeight);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                        L3920_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], G7109_SelectedChampionIndex, C01_CHAMPION_INFO_NAME);
                                        L3921_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], G7109_SelectedChampionIndex, C02_CHAMPION_INFO_TITLE);
#endif
#ifdef MEDIA762_AU1E
                                        F7317_MAIN_CopyBytes_Alt(L3920_pc_, &G2246_CMPData.Name, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8L);
                                        F7317_MAIN_CopyBytes_Alt(L3921_pc_, &G2246_CMPData.Title, MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 20L);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                        F7317_MAIN_CopyBytes_Alt(L3920_pc_, M772_CAST_PC(G2246_CMPData.Name), MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 8);
                                        F7317_MAIN_CopyBytes_Alt(L3921_pc_, M772_CAST_PC(G2246_CMPData.Title), MASK0x0400_MEMREQ, MASK0x0400_MEMREQ, 20);
#endif
                                        F7047_SwapOnDiskAndOnScreenPortraits();
                                        F7001_SaveChampions();
                                        F7047_SwapOnDiskAndOnScreenPortraits();
                                        F7248_InvertBox(G2272_MouseInputs[11].Box);
                                        break;
                                case C13_COMMAND_MAKE_NEW_ADVENTURE:
                                        F7248_InvertBox(G2272_MouseInputs[12].Box);
                                        if (F7086_IsReadyToMakeNewAdventure()) {
                                                if (!G7111_Games[C1_GAME_DESTINATION].GameLoaded) {
                                                        F7051_LoadGame(C1_GAME_DESTINATION);
                                                }
#ifdef MEDIA772_SU1E
                                                if (G7111_Games[C1_GAME_DESTINATION].GameLoaded && F1996_(&G7111_Games[C1_GAME_DESTINATION])) {
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                                if (G7111_Games[C1_GAME_DESTINATION].GameLoaded) {
#endif
                                                        F7047_SwapOnDiskAndOnScreenPortraits();
                                                        F7090_MakeNewAdventure();
                                                        F7047_SwapOnDiskAndOnScreenPortraits();
                                                        F7052_SaveGame(C1_GAME_DESTINATION);
                                                }
                                        }
                                        F7248_InvertBox(G2272_MouseInputs[12].Box);
                                        break;
                                case C14_COMMAND_EDIT_CHAMPION_NAME:
#ifdef MEDIA772_SU1E
                                        F7028_EditChampionNameOrTitle(L3918_s_Command.X, 0, G7111_Games[C0_GAME_SOURCE].Party.Champions[G7109_SelectedChampionIndex].Name);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                        L3920_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], G7109_SelectedChampionIndex, C01_CHAMPION_INFO_NAME);
                                        F7028_EditChampionNameOrTitle(L3918_s_Command.X, 0, L3920_pc_);
#endif
                                        break;
                                case C15_COMMAND_EDIT_CHAMPION_TITLE:
#ifdef MEDIA772_SU1E
                                        F7028_EditChampionNameOrTitle(L3918_s_Command.X, 1, G7111_Games[C0_GAME_SOURCE].Party.Champions[G7109_SelectedChampionIndex].Title);
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                                        L3921_pc_ = (char*)F7067_GetChampionInfo(&G7111_Games[C0_GAME_SOURCE], G7109_SelectedChampionIndex, C02_CHAMPION_INFO_TITLE);
                                        F7028_EditChampionNameOrTitle(L3918_s_Command.X, 1, L3921_pc_);
#endif
                                        break;
                                case C16_COMMAND_KEYBOARD_INPUT:
#ifdef MEDIA773_SU1E_AU1E
                                        F7041_ProcessKeyboardInput(L3918_s_Command.Y);
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                        F7041_ProcessKeyboardInput(F7016_GetKeyFromCommand(&L3918_s_Command));
#endif
                                        break;
                                case C17_COMMAND_QUIT:
                                        F7248_InvertBox(G2272_MouseInputs[16].Box);
#ifdef MEDIA762_AU1E
                                        F0077_MOUSE_EnableScreenUpdate_CPSE();
#endif
#ifdef MEDIA773_SU1E_AU1E
                                        return;
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                                        if (F7005_Quit(1) == 0) {
                                                return;
                                        }
                                        F7248_InvertBox(G2272_MouseInputs[16].Box);
#endif
                        }
#ifdef MEDIA672_F31E_F31J_P31J_SU1E_AU1E
                } while (G7108_BlinkingCursorTimer);
#endif
#ifdef MEDIA699_X31J_AU2E_AU3E
                } while (F2093_GetVerticalBlankCount() <= G7108_BlinkingCursorTimer);
#endif
#ifdef MEDIA772_SU1E
                M526_WaitVerticalBlank();
#endif
#ifdef MEDIA676_F31E_F31J_X31J_P31J_AU1E_AU2E_AU3E
                F7323_WaitVerticalBlank();
#endif
                F0077_MOUSE_EnableScreenUpdate_CPSE();
                if (G7104_TextCursorVisible) { /* Text cursor blinking */
                        G7104_TextCursorVisible = C0_FALSE;
                        F7260_FillScreenBox(G2271_ai_Box_EditText, C01_COLOR_DARK_GRAY);
                } else {
                        G7104_TextCursorVisible = C1_TRUE;
                        F7260_FillScreenBox(G2271_ai_Box_EditText, C15_COLOR_WHITE);
                }
                F0078_MOUSE_DisableScreenUpdate();
#ifdef MEDIA672_F31E_F31J_P31J_SU1E_AU1E
                G7108_BlinkingCursorTimer = 30;
#endif
#ifdef MEDIA699_X31J_AU2E_AU3E
                G7108_BlinkingCursorTimer = F2093_GetVerticalBlankCount() + 30;
#endif
        };
}

#ifdef MEDIA762_AU1E
void F2098_(
)
{
        G3933_ = F7023_Alloc((long)2000, MASK0x0008_MEMREQ);
        G2243_OnScreenPortraitBitmaps = F7023_Alloc((long)(4 * 464), MASK0x0008_MEMREQ);
        G7117_Bitmap_Mirror = F7023_Alloc((long)984, MASK0x0008_MEMREQ);
        F7317_MAIN_CopyBytes_Alt(G2267_auc_Graphic_Mirror, G7117_Bitmap_Mirror, MASK0x0400_MEMREQ, MASK0x0008_MEMREQ, (long)984);
        F2104_CHAMPION_ConvertBitmapToAtariSTPlanar(G7117_Bitmap_Mirror, 48, 41);
}

void F2099_(
)
{
        if (G3933_) {
                F7024_Free(G3933_);
                G3933_ = NULL,0; /* BUG0_00 Useless code. Useless comma */
        }
        if (G2243_OnScreenPortraitBitmaps) {
                F7024_Free(G2243_OnScreenPortraitBitmaps);
                G2243_OnScreenPortraitBitmaps = NULL,0; /* BUG0_00 Useless code. Useless comma */
        }
        if (G7117_Bitmap_Mirror) {
                F7024_Free(G7117_Bitmap_Mirror);
                G7117_Bitmap_Mirror = NULL,0; /* BUG0_00 Useless code. Useless comma */
        }
}
#endif
#endif
