#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA459_P20JA_P20JB_P31J
/*
There are two PC-9801 color modes:
8-color mode (8 colors palette, compatible with older machines): each color component R, G, B is defined on 1 bit (values 0 or 1). VRAM is organized in 3 bitplanes.
16-color mode (4096 colors palette): each color component R, G, B is defined on 4 bits (values 0 to 15). An additional bitplane is present in 16-color mode.
The game uses screen resolution 640x400 in both modes. Each pixel of a game image is drawn on screen using 2x2=4 pixels
In 16-color mode, the four pixels are the same color. In 8-color mode, the four pixels may have different colors (dithering).
*/

typedef struct {
#if EXETYPE == C20_NEC8
        unsigned int16_t Index :5;
        unsigned int16_t Flag  :1;
        unsigned int16_t Color :6;
#endif
#if EXETYPE == C21_NEC16
        unsigned char Index;
        unsigned char Red;
        unsigned char Green;
        unsigned char Blue;
#endif
} COLOR_DEF;

typedef struct {
        int16_t Flag  :1;
        int16_t Color :6;
} COLOR_NEC8;

typedef struct {
        unsigned char PalType; /* NEC16: 0 = Palette change, 1 = actual colors */
        COLOR_DEF* ColorDef;
} COLOR_PALETTE;

unsigned int16_t _stklen = 500;
#if EXETYPE == C20_NEC8
/*
#define C0_PC98_BLACK   0
#define C1_PC98_BLUE    1
#define C2_PC98_GREEN   2
#define C3_PC98_CYAN    3
#define C4_PC98_RED     4
#define C5_PC98_MAGENTA 5
#define C6_PC98_YELLOW  6
#define C7_PC98_WHITE   7

COLOR_DEF G8147_CREDITS[17] = {
        {  0, 1, (C0_PC98_BLACK  << 3) | C0_PC98_BLACK },
        {  1, 0, (C6_PC98_YELLOW << 3) | C6_PC98_YELLOW },
        {  2, 1, (C3_PC98_CYAN   << 3) | C3_PC98_CYAN },
        {  3, 0, (C1_PC98_BLUE   << 3) | C1_PC98_BLUE },
        {  4, 1, (C3_PC98_CYAN   << 3) | C3_PC98_CYAN },
        {  5, 1, (C0_PC98_BLACK  << 3) | C0_PC98_BLACK },
        {  6, 1, (C2_PC98_GREEN  << 3) | C2_PC98_GREEN },
        {  7, 1, (C1_PC98_BLUE   << 3) | C1_PC98_BLUE },
        {  8, 1, (C1_PC98_BLUE   << 3) | C0_PC98_BLACK },
        {  9, 1, (C3_PC98_CYAN   << 3) | C7_PC98_WHITE },
        { 10, 1, (C1_PC98_BLUE   << 3) | C0_PC98_BLACK },
        { 11, 1, (C3_PC98_CYAN   << 3) | C3_PC98_CYAN },
        { 12, 1, (C3_PC98_CYAN   << 3) | C3_PC98_CYAN },
        { 13, 1, (C0_PC98_BLACK  << 3) | C0_PC98_BLACK },
        { 14, 1, (C0_PC98_BLACK  << 3) | C0_PC98_BLACK },
        { 15, 1, (C7_PC98_WHITE  << 3) | C7_PC98_WHITE },
        { 31, 0, 0 }
};
*/

int16_t G8147_CREDITS[17]   = { 0x0020, 0x0D81, 0x06E2, 0x0243, 0x06E4, 0x0025, 0x04A6, 0x0267, 0x0068, 0x0EE9, 0x006A, 0x06EB, 0x06EC, 0x002D, 0x002E, 0x0FEF, 0x001F };
int16_t G8148_ENTRANCE[17]  = { 0x0020, 0x0E01, 0x01E2, 0x0243, 0x06C4, 0x04A5, 0x00A6, 0x0487, 0x0648, 0x0269, 0x066A, 0x024B, 0x002C, 0x0FCD, 0x006E, 0x0FEF, 0x001F };
int16_t G8149_ICON[17]      = { 0x0020, 0x01E1, 0x0FC2, 0x0063, 0x0DA4, 0x0245, 0x0486, 0x04A7, 0x0268, 0x02E9, 0x0EEA, 0x06EB, 0x0E0C, 0x0FCD, 0x092E, 0x0FEF, 0x001F };
int16_t G8150_INVENTORY[17] = { 0x0020, 0x01E1, 0x0FC2, 0x0063, 0x0DA4, 0x0245, 0x0486, 0x04A7, 0x0268, 0x02E9, 0x0EEA, 0x06EB, 0x0E0C, 0x0FCD, 0x092E, 0x0FEF, 0x001F };
int16_t G8151_LIGHT0[17]    = { 0x0020, 0x0E01, 0x01E2, 0x0063, 0x0DA4, 0x0245, 0x0486, 0x04A7, 0x0268, 0x0269, 0x0FCA, 0x06EB, 0x002C, 0x0FCD, 0x092E, 0x0FEF, 0x001F };
int16_t G8152_LIGHT1[17]    = { 0x0020, 0x0021, 0x01E2, 0x0063, 0x0DA4, 0x0245, 0x0486, 0x04A7, 0x0268, 0x0269, 0x0FCA, 0x06EB, 0x002C, 0x0FCD, 0x092E, 0x0FEF, 0x001F };
int16_t G8153_LIGHT2[17]    = { 0x0020, 0x0021, 0x0E02, 0x0203, 0x0DA4, 0x0065, 0x00A6, 0x0487, 0x0248, 0x0249, 0x01EA, 0x06CB, 0x002C, 0x01ED, 0x090E, 0x0FCF, 0x001F };
int16_t G8154_LIGHT3[17]    = { 0x0020, 0x0021, 0x0022, 0x0023, 0x0DA4, 0x0205, 0x0406, 0x00A7, 0x0068, 0x0069, 0x0E0A, 0x00EB, 0x002C, 0x0E0D, 0x012E, 0x0FCF, 0x001F };
int16_t G8155_LIGHT4[17]    = { 0x0020, 0x0021, 0x0022, 0x0023, 0x0DA4, 0x0025, 0x0026, 0x0407, 0x0208, 0x0209, 0x002A, 0x060B, 0x002C, 0x0E0D, 0x080E, 0x01EF, 0x001F };
int16_t G8156_LIGHT5[17]    = { 0x0020, 0x0021, 0x0022, 0x0023, 0x0DA4, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x0E0F, 0x001F };
int16_t G8157_BLACK[17]     = { 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x001F };
int16_t G8158_BLUE[17]      = { 0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F, 0x001F };
int16_t G8267_TITLE[17]     = { 0x0020, 0x0021, 0x0022, 0x06C3, 0x0664, 0x06C5, 0x0666, 0x0EE7, 0x06E8, 0x0029, 0x002A, 0x064B, 0x026C, 0x002D, 0x002E, 0x0FEF, 0x001F };
int16_t G8268_SWOOSH[16]    = {         0x0FE1, 0x0FE2, 0x0FE3, 0x0FE4, 0x0FE5, 0x0FE6, 0x0FE7, 0x0028, 0x0FE9, 0x0FCA, 0x0FEB, 0x0FCC, 0x01ED, 0x06EE, 0x06EF, 0x001F };
#ifdef MEDIA472_P20JB_P31J
int16_t G8269_[17]          = { 0x0000, 0x0801, 0x0822, 0x0903, 0x0924, 0x0985, 0x09A6, 0x0447, 0x06E8, 0x0E09, 0x0E2A, 0x0FCB, 0x02CC, 0x026D, 0x024E, 0x0FEF, 0x001F };
int16_t G8270_[17]          = { 0x0000, 0x0661, 0x0442, 0x0643, 0x0244, 0x0225, 0x0826, 0x0927, 0x0E08, 0x0E29, 0x0FCA, 0x0FEB, 0x044C, 0x02CD, 0x0ECE, 0x07EF, 0x001F };
int16_t G8271_[17]          = { 0x0020, 0x0E01, 0x01E2, 0x0643, 0x06C4, 0x0445, 0x0806, 0x0827, 0x02C8, 0x0269, 0x02EA, 0x064B, 0x002C, 0x0FCD, 0x020E, 0x0FEF, 0x001F };
int16_t G8272_[17]          = { 0x0000, 0x0241, 0x04A2, 0x0823, 0x06C4, 0x0C25, 0x0846, 0x0FE7, 0x0228, 0x0609, 0x080A, 0x062B, 0x0C2C, 0x086D, 0x0E2E, 0x0E0F, 0x001F };
#endif
#ifdef MEDIA457_P20JA
COLOR_PALETTE G8273_as_ColorPalettes[26] = {
#endif
#ifdef MEDIA472_P20JB_P31J
COLOR_PALETTE G8273_as_ColorPalettes[30] = {
#endif
        { 0, (COLOR_DEF*)G8151_LIGHT0 },       /* C00_LIGHT0 */
        { 0, (COLOR_DEF*)G8152_LIGHT1 },       /* C01_LIGHT1 */
        { 0, (COLOR_DEF*)G8153_LIGHT2 },       /* C02_LIGHT2 */
        { 0, (COLOR_DEF*)G8154_LIGHT3 },       /* C03_LIGHT3 */
        { 0, (COLOR_DEF*)G8155_LIGHT4 },       /* C04_LIGHT4 */
        { 0, (COLOR_DEF*)G8156_LIGHT5 },       /* C05_LIGHT5 */
        { 1, (COLOR_DEF*)G8147_CREDITS },      /* C06_CREDITS */
        { 1, (COLOR_DEF*)G8148_ENTRANCE },     /* C07_ENTRANCE_DM */
        { 0, (COLOR_DEF*)G8150_INVENTORY },    /* C08_INVENTORY */
        { 1, (COLOR_DEF*)G8149_ICON },         /* C09_ICON */
        { 1, (COLOR_DEF*)G8157_BLACK },        /* C10_ENTRANCE_BLACK */
        { 1, (COLOR_DEF*)G8158_BLUE },         /* C11_BLUE */
        { 1, (COLOR_DEF*)G8267_TITLE },        /* C12_PRESENTS */
        { 1, (COLOR_DEF*)G8267_TITLE },        /* C13_DUNGEON */
        { 1, (COLOR_DEF*)G8267_TITLE },        /* C14_MASTER */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C15_SWOOSH_BLACK */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C16_SWOOSH1 */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C17_SWOOSH2 */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C18_SWOOSH3 */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C19_SWOOSH4 */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C20_SWOOSH5 */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C21_SWOOSH6 */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C22_SWOOSH7 */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C23_SWOOSH8 */
        { 1, (COLOR_DEF*)G8268_SWOOSH },       /* C24_SWOOSH9 */
        { 1, (COLOR_DEF*)G8268_SWOOSH }        /* C25_SWOOSH10 */
#ifdef MEDIA472_P20JB_P31J                   
        ,                                      
        { 1, (COLOR_DEF*)G8269_ },             /* C26_SWITCH (CSB menu: Story, Champion Editor, Game) */
        { 1, (COLOR_DEF*)G8270_ },
        { 1, (COLOR_DEF*)G8271_ },             /* C28_ENTRANCE_CSB */
        { 1, (COLOR_DEF*)G8272_ }
#endif
        };
COLOR_NEC8 G8275_[14][6] = {
        { 1, 11,    1, 11,    0, 11,    1,  0,    1,  0,    1,  0 },
        { 0, 18,    0, 18,    1,  2,    0, 16,    1,  0,    1,  0 },
        { 0, 11,    0, 11,    1,  0,    1,  0,    1,  0,    1,  0 },
        { 0, 11,    0, 11,    1,  0,    1,  0,    1,  0,    1,  0 },
        { 1, 36,    1, 36,    0, 36,    1,  4,    0, 32,    1,  0 },
        { 0, 36,    0, 36,    1,  4,    0, 32,    1,  0,    1,  0 },
        { 0, 45,    0, 45,    1,  5,    0, 40,    1,  0,    1,  0 },
        { 1, 45,    1, 45,    0, 45,    1,  5,    0, 40,    1,  0 },
        { 1, 11,    1, 11,    0, 11,    1,  0,    1,  0,    1,  0 },
        { 1, 11,    1, 11,    0, 11,    1,  0,    1,  0,    1,  0 },
        { 1,  1,    1,  1,    0,  8,    1,  0,    1,  0,    1,  0 },
        { 0,  8,    0,  8,    1,  0,    1,  0,    1,  0,    1,  0 },
        { 1, 59,    1, 59,    1, 59,    1, 59,    1, 59,    1, 59 },
        { 0,  0,    0,  0,    0,  0,    0,  0,    0,  0,    0,  0 } };
#endif
#if EXETYPE == C21_NEC16
COLOR_DEF G8276_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x00, 0x2D, 0x2D },
        { 0x02, 0x3F, 0x3F, 0x1B },
        { 0x03, 0x24, 0x12, 0x00 },
        { 0x04, 0x3F, 0x3F, 0x24 },
        { 0x05, 0x00, 0x00, 0x00 },
        { 0x06, 0x00, 0x24, 0x00 },
        { 0x07, 0x2D, 0x00, 0x00 },
        { 0x08, 0x36, 0x24, 0x12 },
        { 0x09, 0x3F, 0x3F, 0x2D },
        { 0x0A, 0x3F, 0x24, 0x12 },
        { 0x0B, 0x3F, 0x36, 0x00 },
        { 0x0C, 0x3F, 0x2D, 0x00 },
        { 0x0D, 0x00, 0x00, 0x00 },
        { 0x0E, 0x1B, 0x09, 0x00 },
        { 0x0F, 0x3F, 0x3F, 0x36 },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8277_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x1B, 0x1B, 0x1B },
        { 0x02, 0x24, 0x24, 0x24 },
        { 0x03, 0x24, 0x12, 0x00 },
        { 0x04, 0x36, 0x2D, 0x24 },
        { 0x05, 0x00, 0x36, 0x00 },
        { 0x06, 0x00, 0x24, 0x00 },
        { 0x07, 0x00, 0x2D, 0x00 },
        { 0x08, 0x24, 0x1B, 0x12 },
        { 0x09, 0x3F, 0x00, 0x00 },
        { 0x0A, 0x2D, 0x24, 0x1B },
        { 0x0B, 0x1B, 0x12, 0x09 },
        { 0x0C, 0x12, 0x12, 0x12 },
        { 0x0D, 0x2D, 0x2D, 0x2D },
        { 0x0E, 0x1B, 0x09, 0x00 },
        { 0x0F, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8278_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x1B, 0x1B, 0x1B },
        { 0x02, 0x24, 0x24, 0x24 },
        { 0x03, 0x1B, 0x09, 0x00 },
        { 0x04, 0x00, 0x36, 0x36 },
        { 0x05, 0x24, 0x12, 0x00 },
        { 0x06, 0x00, 0x24, 0x00 },
        { 0x07, 0x00, 0x36, 0x00 },
        { 0x08, 0x3F, 0x00, 0x00 },
        { 0x09, 0x3F, 0x2D, 0x00 },
        { 0x0A, 0x36, 0x24, 0x1B },
        { 0x0B, 0x3F, 0x3F, 0x00 },
        { 0x0C, 0x12, 0x12, 0x12 },
        { 0x0D, 0x2D, 0x2D, 0x2D },
        { 0x0E, 0x00, 0x00, 0x3F },
        { 0x0F, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
char G8279_[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
char G8280_[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
char G8281_[16] = { 0, 0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11,  0, 13, 14, 15 };
char G8282_[16] = { 0, 0, 0, 0, 4, 3, 0, 6, 3, 0,  2,  5,  0,  2,  0, 13 };
char G8283_[16] = { 0, 0, 0, 0, 4, 3, 0, 6, 3, 0,  2,  5,  0,  2,  0, 13 };
char G8284_[16] = { 0, 0, 0, 0, 4, 3, 0, 6, 3, 0,  2,  5,  0,  2,  0, 13 };
char G8285_[16] = { 0, 0, 0, 0, 4, 0, 0, 0, 0, 0,  0,  0,  0,  0,  0,  2 };
COLOR_DEF G8286_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x00, 0x00, 0x00 },
        { 0x02, 0x00, 0x00, 0x00 },
        { 0x03, 0x00, 0x00, 0x00 },
        { 0x04, 0x00, 0x00, 0x00 },
        { 0x05, 0x00, 0x00, 0x00 },
        { 0x06, 0x00, 0x00, 0x00 },
        { 0x07, 0x00, 0x00, 0x00 },
        { 0x08, 0x00, 0x00, 0x00 },
        { 0x09, 0x00, 0x00, 0x00 },
        { 0x0A, 0x00, 0x00, 0x00 },
        { 0x0B, 0x00, 0x00, 0x00 },
        { 0x0C, 0x00, 0x00, 0x00 },
        { 0x0D, 0x00, 0x00, 0x00 },
        { 0x0E, 0x00, 0x00, 0x00 },
        { 0x0F, 0x00, 0x00, 0x00 },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8287_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x00, 0x00, 0x00 },
        { 0x02, 0x00, 0x00, 0x00 },
        { 0x03, 0x00, 0x00, 0x00 },
        { 0x04, 0x00, 0x00, 0x00 },
        { 0x05, 0x00, 0x00, 0x00 },
        { 0x06, 0x00, 0x00, 0x00 },
        { 0x07, 0x00, 0x00, 0x00 },
        { 0x08, 0x00, 0x00, 0x00 },
        { 0x09, 0x00, 0x00, 0x00 },
        { 0x0A, 0x00, 0x00, 0x00 },
        { 0x0B, 0x00, 0x00, 0x00 },
        { 0x0C, 0x00, 0x00, 0x00 },
        { 0x0D, 0x00, 0x00, 0x00 },
        { 0x0E, 0x00, 0x00, 0x00 },
        { 0x0F, 0x00, 0x00, 0x00 },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8288_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x00, 0x00, 0x00 },
        { 0x02, 0x00, 0x00, 0x00 },
        { 0x03, 0x00, 0x00, 0x00 },
        { 0x04, 0x00, 0x00, 0x00 },
        { 0x05, 0x00, 0x00, 0x00 },
        { 0x06, 0x00, 0x00, 0x00 },
        { 0x07, 0x00, 0x00, 0x00 },
        { 0x08, 0x00, 0x00, 0x00 },
        { 0x09, 0x00, 0x00, 0x00 },
        { 0x0A, 0x00, 0x00, 0x00 },
        { 0x0B, 0x00, 0x00, 0x00 },
        { 0x0C, 0x00, 0x00, 0x00 },
        { 0x0D, 0x00, 0x00, 0x00 },
        { 0x0E, 0x00, 0x00, 0x00 },
        { 0x0F, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8289_[10] = {
        { 0x03, 0x2F, 0x27, 0x0F },
        { 0x04, 0x27, 0x17, 0x0F },
        { 0x05, 0x37, 0x2F, 0x0F },
        { 0x06, 0x2F, 0x17, 0x0F },
        { 0x07, 0x37, 0x37, 0x17 },
        { 0x08, 0x3F, 0x3F, 0x0F },
        { 0x0B, 0x1F, 0x0F, 0x07 },
        { 0x0C, 0x3F, 0x00, 0x00 },
        { 0x0F, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8290_[2] = {
        { 0x0C, 0x3F, 0x00, 0x00 },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8291_[2] = {
        { 0x01, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8292_[2] = {
        { 0x02, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8293_[2] = {
        { 0x03, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8294_[2] = {
        { 0x04, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8295_[2] = {
        { 0x05, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8296_[2] = {
        { 0x06, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8297_[2] = {
        { 0x07, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8298_[5] = {
        { 0x08, 0x3F, 0x3F, 0x3F },
        { 0x09, 0x3F, 0x3F, 0x3F },
        { 0x0A, 0x2F, 0x2F, 0x2F },
        { 0x0F, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8299_[5] = {
        { 0x08, 0x00, 0x00, 0x00 },
        { 0x0B, 0x3F, 0x3F, 0x3F },
        { 0x0C, 0x2F, 0x2F, 0x2F },
        { 0x0D, 0x1F, 0x1F, 0x1F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8300_[3] = {
        { 0x0E, 0x3F, 0x3F, 0x00 },
        { 0x0F, 0x3F, 0x3F, 0x00 },
        { 0xFF, 0x00, 0x00, 0x00 } };
#ifdef MEDIA472_P20JB_P31J
COLOR_DEF G8301_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x00, 0x00, 0x14 },
        { 0x02, 0x00, 0x00, 0x1C },
        { 0x03, 0x00, 0x00, 0x24 },
        { 0x04, 0x00, 0x00, 0x34 },
        { 0x05, 0x00, 0x18, 0x2C },
        { 0x06, 0x00, 0x24, 0x28 },
        { 0x07, 0x1C, 0x14, 0x0C },
        { 0x08, 0x3F, 0x3F, 0x00 },
        { 0x09, 0x14, 0x14, 0x14 },
        { 0x0A, 0x20, 0x20, 0x20 },
        { 0x0B, 0x28, 0x28, 0x28 },
        { 0x0C, 0x28, 0x1C, 0x14 },
        { 0x0D, 0x3F, 0x00, 0x00 },
        { 0x0E, 0x28, 0x08, 0x08 },
        { 0x0F, 0x3F, 0x30, 0x28 },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8302_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x33, 0x1B, 0x0B },
        { 0x02, 0x1F, 0x13, 0x07 },
        { 0x03, 0x2B, 0x17, 0x0B },
        { 0x04, 0x3F, 0x03, 0x03 },
        { 0x05, 0x2F, 0x03, 0x03 },
        { 0x06, 0x03, 0x03, 0x2F },
        { 0x07, 0x03, 0x03, 0x3F },
        { 0x08, 0x17, 0x17, 0x17 },
        { 0x09, 0x1F, 0x1F, 0x1F },
        { 0x0A, 0x2F, 0x2F, 0x2F },
        { 0x0B, 0x37, 0x37, 0x37 },
        { 0x0C, 0x23, 0x1B, 0x13 },
        { 0x0D, 0x27, 0x23, 0x17 },
        { 0x0E, 0x33, 0x27, 0x1B },
        { 0x0F, 0x3B, 0x2B, 0x1F },
        { 0xFF, 0x00, 0x00, 0x00 } };
COLOR_DEF G8303_[17] = {
        { 0x00, 0x00, 0x00, 0x00 },
        { 0x01, 0x1B, 0x1B, 0x1B },
        { 0x02, 0x23, 0x23, 0x23 },
        { 0x03, 0x23, 0x13, 0x03 },
        { 0x04, 0x33, 0x2B, 0x23 },
        { 0x05, 0x13, 0x0B, 0x0B },
        { 0x06, 0x03, 0x03, 0x23 },
        { 0x07, 0x03, 0x03, 0x2B },
        { 0x08, 0x23, 0x1B, 0x13 },
        { 0x09, 0x3F, 0x03, 0x03 },
        { 0x0A, 0x2B, 0x23, 0x1B },
        { 0x0B, 0x1B, 0x13, 0x0B },
        { 0x0C, 0x13, 0x13, 0x13 },
        { 0x0D, 0x2B, 0x2B, 0x2B },
        { 0x0E, 0x1B, 0x0B, 0x03 },
        { 0x0F, 0x3F, 0x3F, 0x3F },
        { 0xFF, 0x00, 0x00, 0x00 } };
#endif
#ifdef MEDIA457_P20JA
COLOR_PALETTE G8273_as_ColorPalettes[26] = {
#endif
#ifdef MEDIA472_P20JB_P31J
COLOR_PALETTE G8273_as_ColorPalettes[29] = {
#endif
        { 0, (COLOR_DEF*)G8280_ },      /* C00_LIGHT0 */
        { 0, (COLOR_DEF*)G8281_ },      /* C01_LIGHT1 */
        { 0, (COLOR_DEF*)G8282_ },      /* C02_LIGHT2 */
        { 0, (COLOR_DEF*)G8283_ },      /* C03_LIGHT3 */
        { 0, (COLOR_DEF*)G8284_ },      /* C04_LIGHT4 */
        { 0, (COLOR_DEF*)G8285_ },      /* C05_LIGHT5 */
        { 1, G8276_ },                  /* C06_CREDITS */
        { 1, G8277_ },                  /* C07_ENTRANCE_DM */
        { 0, (COLOR_DEF*)G8279_ },      /* C08_INVENTORY */
        { 1, G8278_ },                  /* C09_ICON */
        { 1, G8286_ },                  /* C10_ENTRANCE_BLACK */
        { 1, G8287_ },                  /* C11_BLUE */
        { 1, G8288_ },                  /* C12_PRESENTS */
        { 1, G8289_ },                  /* C13_DUNGEON */
        { 1, G8290_ },                  /* C14_MASTER */
        { 1, G8286_ },                  /* C15_SWOOSH_BLACK */
        { 1, G8291_ },                  /* C16_SWOOSH1 */
        { 1, G8292_ },                  /* C17_SWOOSH2 */
        { 1, G8293_ },                  /* C18_SWOOSH3 */
        { 1, G8294_ },                  /* C19_SWOOSH4 */
        { 1, G8295_ },                  /* C20_SWOOSH5 */
        { 1, G8296_ },                  /* C21_SWOOSH6 */
        { 1, G8297_ },                  /* C22_SWOOSH7 */
        { 1, G8298_ },                  /* C23_SWOOSH8 */
        { 1, G8299_ },                  /* C24_SWOOSH9 */
        { 1, G8300_ }                   /* C25_SWOOSH10 */
#ifdef MEDIA472_P20JB_P31J
        ,
        { 1, G8301_ },                  /* 26 */
        { 1, G8302_ },                  /* 27 */
        { 1, G8303_ }                   /* 28 */
#endif
        };
char G8275_[13][6] = {
        { 0x05, 0x05, 0x03, 0x03, 0x03, 0x00 },
        { 0x02, 0x02, 0x02, 0x02, 0x02, 0x00 },
        { 0x05, 0x05, 0x03, 0x03, 0x03, 0x00 },
        { 0x03, 0x03, 0x00, 0x00, 0x00, 0x00 },
        { 0x0E, 0x0E, 0x02, 0x02, 0x02, 0x00 },
        { 0x02, 0x02, 0x00, 0x00, 0x00, 0x00 },
        { 0x08, 0x08, 0x03, 0x03, 0x03, 0x00 },
        { 0x0E, 0x0E, 0x02, 0x02, 0x02, 0x00 },
        { 0x09, 0x09, 0x02, 0x02, 0x02, 0x00 },
        { 0x08, 0x08, 0x09, 0x09, 0x09, 0x02 },
        { 0x08, 0x08, 0x09, 0x09, 0x09, 0x02 },
        { 0x09, 0x09, 0x02, 0x02, 0x02, 0x00 },
        { 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A } };
#endif
char G8307_ = 255;
#ifdef MEDIA457_P20JA
int16_t G8308_i_VerticalBlankCount = 0;
#endif
extern char G8138_[160];
char* G8134_pc_VideoMemory = G8138_;
#if EXETYPE == C20_NEC8
int16_t G8311_i_CurrentNonViewportPaletteIndex = -1;
#endif
int16_t G8312_i_CurrentViewportPaletteIndex = -1;
#ifdef MEDIA472_P20JB_P31J
BOOLEAN G8313_B_InterruptInstalled = C0_FALSE;
#endif


unsigned char* G2159_puc_Bitmap_Source;
#ifdef MEDIA457_P20JA
int16_t G8322_;
int16_t G8323_;
#endif
BOOLEAN G8315_B_VerticalBlankOccured;
char G8138_[160];
#ifdef MEDIA457_P20JA
int16_t G8324_;
int16_t G8133_PrefixedBitmap[512];
#endif
#ifdef MEDIA472_P20JB_P31J
#if EXETYPE == C20_NEC8
int16_t G8133_PrefixedBitmap[327];
#endif
#if EXETYPE == C21_NEC16
int16_t G8133_PrefixedBitmap[435];
#endif
#endif
#if EXETYPE == C20_NEC8
COLOR_DEF G8319_as_CurrentNonViewportPalette[16];
COLOR_DEF G8320_as_CurrentViewportPalette[16];
#endif


FUNC_DEF void F8140_ScrollMessageAreaUp(
char huge* P3189_pc_,
char huge* P3190_pc_,
int16_t P3191_i_)
{
        if (P3189_pc_ > P3190_pc_) {
                asm     cld
                asm     push    ds
                asm     lds     si, P3189_pc_
                asm     les     di, P3190_pc_
                asm     mov     cx, P3191_i_
                asm     shr     cx, 1
                asm     pushf
                loc_1038A:
                asm     rep movsw
                asm     or      cx, cx
                asm     jnz     loc_1038A
                asm     popf
                asm     jnb     loc_10394
                asm     movsb
                loc_10394:
                asm     pop     ds
        } else {
                (int16_t)P3189_pc_ += P3191_i_ - 1;
                (int16_t)P3190_pc_ += P3191_i_ - 1;
                asm     std
                asm     push    ds
                asm     lds     si, P3189_pc_
                asm     les     di, P3190_pc_
                asm     mov     cx, P3191_i_
                loc_103B0:
                asm     rep movsb
                asm     or      cx, cx
                asm     jnz     loc_103B0
                asm     pop     ds
        }
}

#ifdef MEDIA469_P20JB
FUNC_DEF void F8383_Unreferenced(
)
{
        asm     V8382000_      dw 400h dup(0)
        asm     V8384000_      dw 400h dup(0)
}
#endif

#if EXETYPE == C20_NEC8
FUNC_DEF void F8382_PrepareV8382000FromPalette(
COLOR_DEF* P3461_ps_)
{
        int16_t L3126_i_ColorIndex;
        char L3127_c_;
        char L3128_c_;
        char L3129_c_;
        char L3130_c_;
        char L3131_c_;
        char L3132_c_;
        char L3133_c_;
        char L3134_c_;
        char L3135_c_;
        char L3136_c_;
        char L3137_c_;
        char L3138_c_;


        for (L3126_i_ColorIndex = 0; L3126_i_ColorIndex < 256; L3126_i_ColorIndex++) {
                L3127_c_ = P3461_ps_[L3126_i_ColorIndex >> 4].Flag;
                L3129_c_ = P3461_ps_[L3126_i_ColorIndex >> 4].Color;
                L3128_c_ = P3461_ps_[L3126_i_ColorIndex & 0x0F].Flag;
                L3130_c_ = P3461_ps_[L3126_i_ColorIndex & 0x0F].Color;
                L3131_c_ = L3132_c_ = L3133_c_ = L3134_c_ = 0;
                L3135_c_ = L3136_c_ = L3137_c_ = L3138_c_ = 0;
                if (L3129_c_ & 1) {
                        L3131_c_ |= 0x80;
                        L3132_c_ |= 8;
                }
                if (L3129_c_ & 8) {
                        L3131_c_ |= 0x40;
                        L3132_c_ |= 4;
                }
                if (L3129_c_ & 2) {
                        L3133_c_ |= 0x80;
                        L3134_c_ |= 8;
                }
                if (L3129_c_ & 0x10) {
                        L3133_c_ |= 0x40;
                        L3134_c_ |= 4;
                }
                if (L3129_c_ & 4) {
                        L3135_c_ |= 0x80;
                        L3136_c_ |= 8;
                }
                if (L3129_c_ & 0x20) {
                        L3135_c_ |= 0x40;
                        L3136_c_ |= 4;
                }
                if (L3127_c_) {
                        L3137_c_ |= 0xC0;
                        L3138_c_ |= 0x0C;
                } else {
                        L3137_c_ |= 0x80;
                        L3138_c_ |= 8;
                }
                if (L3130_c_ & 1) {
                        L3131_c_ |= 0x20;
                        L3132_c_ |= 2;
                }
                if (L3130_c_ & 8) {
                        L3131_c_ |= 0x10;
                        L3132_c_ |= 1;
                }
                if (L3130_c_ & 2) {
                        L3133_c_ |= 0x20;
                        L3134_c_ |= 2;
                }
                if (L3130_c_ & 0x10) {
                        L3133_c_ |= 0x10;
                        L3134_c_ |= 1;
                }
                if (L3130_c_ & 4) {
                        L3135_c_ |= 0x20;
                        L3136_c_ |= 2;
                }
                if (L3130_c_ & 0x20) {
                        L3135_c_ |= 0x10;
                        L3136_c_ |= 1;
                }
                if (L3128_c_) {
                        L3137_c_ |= 0x30;
                        L3138_c_ |= 0x03;
                } else {
                        L3137_c_ |= 0x20;
                        L3138_c_ |= 2;
                }
                asm     mov     bx, L3126_i_ColorIndex
                asm     add     bx, bx
                asm     mov     ah, L3131_c_
                asm     mov     al, L3133_c_
                asm     mov     cs:V8382000_+bx, ax
                asm     mov     ah, L3132_c_
                asm     mov     al, L3134_c_
                asm     mov     cs:V8382000_+bx+512, ax
                asm     mov     ah, L3135_c_
                asm     mov     al, L3137_c_
                asm     mov     cs:V8382000_+bx+1024, ax
                asm     mov     ah, L3136_c_
                asm     mov     al, L3138_c_
                asm     mov     cs:V8382000_+bx+1536, ax
        }
#ifdef MEDIA468_P20JA_P31J
        asm     jmp     loc_10C67
        asm     V8382000_      dw 400h dup(0)
        loc_10C67: ;
#endif
}

FUNC_DEF void F8384_(
COLOR_DEF* P3462_ps_)
{
        int16_t L3139_i_;
        char L3140_c_;
        char L3141_c_;
        char L3142_c_;
        char L3143_c_;
        char L3144_c_;
        char L3145_c_;
        char L3146_c_;
        char L3147_c_;
        char L3148_c_;
        char L3149_c_;
        char L3150_c_;
        char L3151_c_;


        for (L3139_i_ = 0; L3139_i_ < 256; L3139_i_++) {
                L3140_c_ = P3462_ps_[L3139_i_ >> 4].Flag;
                L3142_c_ = P3462_ps_[L3139_i_ >> 4].Color;
                L3141_c_ = P3462_ps_[L3139_i_ & 0x0F].Flag;
                L3143_c_ = P3462_ps_[L3139_i_ & 0x0F].Color;
                L3144_c_ = L3145_c_ = L3146_c_ = L3147_c_ = 0;
                L3148_c_ = L3149_c_ = L3150_c_ = L3151_c_ = 0;
                if (L3142_c_ & 1) {
                        L3144_c_ |= 0x80;
                        L3145_c_ |= 8;
                }
                if (L3142_c_ & 8) {
                        L3144_c_ |= 0x40;
                        L3145_c_ |= 4;
                }
                if (L3142_c_ & 2) {
                        L3146_c_ |= 0x80;
                        L3147_c_ |= 8;
                }
                if (L3142_c_ & 0x10) {
                        L3146_c_ |= 0x40;
                        L3147_c_ |= 4;
                }
                if (L3142_c_ & 4) {
                        L3148_c_ |= 0x80;
                        L3149_c_ |= 8;
                }
                if (L3142_c_ & 0x20) {
                        L3148_c_ |= 0x40;
                        L3149_c_ |= 4;
                }
                if (L3140_c_) {
                        L3150_c_ |= 0xC0;
                        L3151_c_ |= 0x0C;
                } else {
                        L3150_c_ |= 0x80;
                        L3151_c_ |= 8;
                }
                if (L3143_c_ & 1) {
                        L3144_c_ |= 0x20;
                        L3145_c_ |= 2;
                }
                if (L3143_c_ & 8) {
                        L3144_c_ |= 0x10;
                        L3145_c_ |= 1;
                }
                if (L3143_c_ & 2) {
                        L3146_c_ |= 0x20;
                        L3147_c_ |= 2;
                }
                if (L3143_c_ & 0x10) {
                        L3146_c_ |= 0x10;
                        L3147_c_ |= 1;
                }
                if (L3143_c_ & 4) {
                        L3148_c_ |= 0x20;
                        L3149_c_ |= 2;
                }
                if (L3143_c_ & 0x20) {
                        L3148_c_ |= 0x10;
                        L3149_c_ |= 1;
                }
                if (L3141_c_) {
                        L3150_c_ |= 0x30;
                        L3151_c_ |= 0x03;
                } else {
                        L3150_c_ |= 0x20;
                        L3151_c_ |= 2;
                }
                asm     mov     bx, L3139_i_
                asm     add     bx, bx
                asm     mov     ah, L3144_c_
                asm     mov     al, L3146_c_
                asm     mov     cs:V8384000_+bx, ax
                asm     mov     ah, L3145_c_
                asm     mov     al, L3147_c_
                asm     mov     cs:V8384000_+bx+512, ax
                asm     mov     ah, L3148_c_
                asm     mov     al, L3150_c_
                asm     mov     cs:V8384000_+bx+1024, ax
                asm     mov     ah, L3149_c_
                asm     mov     al, L3151_c_
                asm     mov     cs:V8384000_+bx+1536, ax
        }
        asm     jmp     loc_11565
#ifdef MEDIA468_P20JA_P31J
        asm     V8384000_      dw 400h dup(0)
#endif
        asm     V8384001_BitPlane0Offset      dw 0A800h      /* Bit plane 0 segment (Blue) */
        asm     V8384002_BitPlane2Offset      dw 0B800h      /* Bit plane 2 segment (Green) */
        loc_11565: ;
}
#endif
#if EXETYPE == C21_NEC16
FUNC_DEF void F8382_PrepareV8382000FromPalette(
char* P3463_pc_)
{
        int16_t L3152_i_;
        char L3153_c_;


        for (L3152_i_ = 0; L3152_i_ < 256; L3152_i_++) {
                L3153_c_ = (P3463_pc_[L3152_i_ >> 4] << 4) | P3463_pc_[L3152_i_ & 0x0F];
                asm     mov     bx, L3152_i_
                asm     add     bx, bx
                asm     mov     ah, L3153_c_
                asm     mov     dx, 0
                asm     test    ah, 80h
                asm     jz      loc_103B9
                asm     or      dx, 0C000h
                loc_103B9:
                asm     test    ah, 8
                asm     jz      loc_103C2
                asm     or      dx, 3000h
                loc_103C2:
                asm     test    ah, 40h
                asm     jz      loc_103CB
                asm     or      dx, 0C0h
                loc_103CB:
                asm     test    ah, 4
                asm     jz      loc_103D3
                asm     or      dx, 30h
                loc_103D3:
                asm     mov     cs:V8382000_+bx, dx
                asm     mov     dx, 0
                asm     test    ah, 80h
                asm     jz      loc_103E4
                asm     or      dx, 0C00h
                loc_103E4:
                asm     test    ah, 8
                asm     jz      loc_103ED
                asm     or      dx, 300h
                loc_103ED:
                asm     test    ah, 40h
                asm     jz      loc_103F5
                asm     or      dx, 0Ch
                loc_103F5:
                asm     test    ah, 4
                asm     jz      loc_103FD
                asm     or      dx, 3
                loc_103FD:
                asm     mov     cs:V8382000_+bx+512, dx
                asm     mov     dx, 0
                asm     test    ah, 20h
                asm     jz      loc_1040E
                asm     or      dx, 0C000h
                loc_1040E:
                asm     test    ah, 2
                asm     jz      loc_10417
                asm     or      dx, 3000h
                loc_10417:
                asm     test    ah, 10h
                asm     jz      loc_10420
                asm     or      dx, 0C0h
                loc_10420:
                asm     test    ah, 1
                asm     jz      loc_10428
                asm     or      dx, 30h
                loc_10428:
                asm     mov     cs:V8382000_+bx+1024, dx
                asm     mov     dx, 0
                asm     test    ah, 20h
                asm     jz      loc_10439
                asm     or      dx, 0C00h
                loc_10439:
                asm     test    ah, 2
                asm     jz      loc_10442
                asm     or      dx, 300h
                loc_10442:
                asm     test    ah, 10h
                asm     jz      loc_1044A
                asm     or      dx, 0Ch
                loc_1044A:
                asm     test    ah, 1
                asm     jz      loc_10452
                asm     or      dx, 3
                loc_10452:
                asm     mov     cs:V8382000_+bx+1536, dx
        }
#ifdef MEDIA468_P20JA_P31J
        asm     jmp     loc_10C67
        asm     V8382000_      dw 400h dup(0)
        loc_10C67: ;
#endif
}

FUNC_DEF void F8384_(
char* P3464_pc_)
{
        int16_t L3154_i_;
        char L3155_c_;


        for (L3154_i_ = 0; L3154_i_ < 256; L3154_i_++) {
                L3155_c_ = (P3464_pc_[L3154_i_ >> 4] << 4) | P3464_pc_[L3154_i_ & 0x0F];
                asm     mov     bx, L3154_i_
                asm     add     bx, bx
                asm     mov     ah, L3155_c_
                asm     mov     dx, 0
                asm     test    ah, 80h
                asm     jz      loc_10CB1
                asm     or      dx, 0C000h
                loc_10CB1:
                asm     test    ah, 8
                asm     jz      loc_10CBA
                asm     or      dx, 3000h
                loc_10CBA:
                asm     test    ah, 40h
                asm     jz      loc_10CC3
                asm     or      dx, 0C0h
                loc_10CC3:
                asm     test    ah, 4
                asm     jz      loc_10CCB
                asm     or      dx, 30h
                loc_10CCB:
                asm     mov     cs:V8384000_+bx, dx
                asm     mov     dx, 0
                asm     test    ah, 80h
                asm     jz      loc_10CDC
                asm     or      dx, 0C00h
                loc_10CDC:
                asm     test    ah, 8
                asm     jz      loc_10CE5
                asm     or      dx, 300h
                loc_10CE5:
                asm     test    ah, 40h
                asm     jz      loc_10CED
                asm     or      dx, 0Ch
                loc_10CED:
                asm     test    ah, 4
                asm     jz      loc_10CF5
                asm     or      dx, 3
                loc_10CF5:
                asm     mov     cs:V8384000_+bx+512, dx
                asm     mov     dx, 0
                asm     test    ah, 20h
                asm     jz      loc_10D06
                asm     or      dx, 0C000h
                loc_10D06:
                asm     test    ah, 2
                asm     jz      loc_10D0F
                asm     or      dx, 3000h
                loc_10D0F:
                asm     test    ah, 10h
                asm     jz      loc_10D18
                asm     or      dx, 0C0h
                loc_10D18:
                asm     test    ah, 1
                asm     jz      loc_10D20
                asm     or      dx, 30h
                loc_10D20:
                asm     mov     cs:V8384000_+bx+1024, dx
                asm     mov     dx, 0
                asm     test    ah, 20h
                asm     jz      loc_10D31
                asm     or      dx, 0C00h
                loc_10D31:
                asm     test    ah, 2
                asm     jz      loc_10D3A
                asm     or      dx, 300h
                loc_10D3A:
                asm     test    ah, 10h
                asm     jz      loc_10D42
                asm     or      dx, 0Ch
                loc_10D42:
                asm     test    ah, 1
                asm     jz      loc_10D4A
                asm     or      dx, 3
                loc_10D4A:
                asm     mov     cs:V8384000_+bx+1536, dx
        }
        asm     jmp     loc_11565
#ifdef MEDIA468_P20JA_P31J
        asm     V8384000_      dw 400h dup(0)
#endif
        asm     V8384001_BitPlane0Offset      dw 0A800h      /* Bit plane 0 segment (Blue) */
        asm     V8384002_BitPlane2Offset      dw 0B800h      /* Bit plane 2 segment (Green) */
        asm     V8384003_      dw 0E000h      /* Bit plane 3 segment (Intensity) */
        loc_11565: ;
}
#endif

FUNC_DEF void F8147_(
unsigned char* P2504_puc_,
int16_t P2505_i_)
{
        asm     push    ds
        asm     push    bp
        asm     cld
        asm     mov     di, P2505_i_
        asm     lds     si, P2504_puc_
        asm     mov     cl, 2
        asm     xor     bh, bh
        loc_1157B:
        asm     push    si
        asm     push    di
        asm     mov     ch, 44h
        loc_1157F:
        asm     push    cx
        asm     push    si
        asm     push    di
        asm     mov     bp, 1Ch
        loc_11585:
        asm     mov     es, bp
        asm     lodsw
        asm     xor     bx, bx
        asm     xchg    bl, ah
        asm     mov     bp, ax
        asm     add     bx, bx
        asm     mov     cx, V8384000_+bx+512
        asm     mov     dx, V8384000_+bx+1536
        asm     add     bp, bp
        asm     or      cx, V8384000_+bp
        asm     or      dx, V8384000_+bp+1024
        asm     lodsw
        asm     xor     bx, bx
        asm     xchg    bl, ah
        asm     mov     bp, ax
        asm     add     bx, bx
        asm     mov     ax, V8384000_+bx+512
        asm     mov     bx, V8384000_+bx+1536
        asm     add     bp, bp
        asm     or      ax, V8384000_+bp
        asm     or      bx, V8384000_+bp+1024
        asm     xchg    ch, al
        asm     xchg    dh, bl
        asm     mov     bp, es
        asm     mov     es, cs:V8384001_BitPlane0Offset
#if EXETYPE == C20_NEC8
        asm     mov     es:[di], bx
        asm     and     bx, dx
        asm     mov     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bx
        asm     mov     es:[di-8000h], ax
        asm     and     ax, dx
        asm     mov     es:[di-7FB0h], ax
#endif
#if EXETYPE == C21_NEC16
        asm     mov     es:[di], dx
        asm     mov     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dx
        asm     mov     es:[di-8000h], bx
        asm     mov     es:[di-7FB0h], bx
#endif
        asm     mov     es, cs:V8384002_BitPlane2Offset
        asm     mov     es:[di], cx
#if EXETYPE == C20_NEC8
        asm     and     cx, dx
#endif
        asm     mov     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], cx
#if EXETYPE == C20_NEC8
        asm     add     di, 2
#endif
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384003_
        asm     stosw
        asm     mov     es:[di+4Eh], ax
#endif
        asm     dec     bp
        asm     jz      loc_115FC
        asm     jmp     loc_11585
        loc_115FC:
        asm     pop     di
        asm     pop     si
        asm     add     di, 320
        asm     add     si, 0E0h
        asm     pop     cx
        asm     dec     ch
        asm     jz      loc_1160E
        asm     jmp     loc_1157F
        loc_1160E:
        asm     pop     di
        asm     pop     si
        asm     add     di, 160
        asm     add     si, 70h
        asm     dec     cl
        asm     jz      loc_1161E
        asm     jmp     loc_1157B
        loc_1161E:
        asm     pop     bp
        asm     pop     ds
}

#include "IMAGE5.C"

#ifdef MEDIA469_P20JB
FUNC_DEF void F8390_Unreferenced(
)
{
        asm     V8389000_   db 200h dup(0)
}
#endif

FUNC_DEF void F8389_(
unsigned char P3470_uc_)
{
        unsigned int16_t L3156_ui_;
        unsigned int16_t L3157_ui_;


        if (G8307_ != P3470_uc_) {
                G8307_ = P3470_uc_;
                for (L3156_ui_ = 0; L3156_ui_ < 256; L3156_ui_++) {
                        if ((L3156_ui_ & 0x0F) != P3470_uc_) {
                                L3157_ui_ = 0x3003;
                        } else {
                                L3157_ui_ = 0;
                        }
                        if ((L3156_ui_ >> 4) != P3470_uc_) {
                                L3157_ui_ |= 0xC00C;
                        }
                        asm     mov     bx, L3156_ui_
                        asm     mov     ax, L3157_ui_
                        asm     mov     cs:V8389000_+bx, ah
                        asm     mov     cs:V8389000_+bx+256, al
                }
        }
#ifdef MEDIA468_P20JA_P31J
        asm     jmp     loc_11CC4
        asm     V8389000_   db 200h dup(0)
        loc_11CC4: ;
#endif
}

FUNC_DEF void F0682_CopyPixelLineToScreenWithTransparency(
int16_t P2325_i_A,
int16_t P2326_i_DestinationOffset,
int16_t P2327_i_PixelCount)
{
        asm     push    ds
        asm     cld
        asm     les     si, G2159_puc_Bitmap_Source
#ifdef MEDIA472_P20JB_P31J
        asm     mov     ax, es
        asm     dec     ax
        asm     mov     es, ax
        asm     add     si, 10h
#endif
        asm     mov     ax, P2325_i_A
        asm     mov     bx, P2326_i_DestinationOffset
        asm     mov     di, bx
        asm     shr     ax, 1           /* Least significant bit is pushed into CF */
        asm     rcl     bx, 1           /* Rotate 9 bits (Carry Flag CF and bx) left */
        asm     shl     bx, 1           /* bx = bx * 2 */
        asm     and     bx, 0Eh         /* bx = P2326_i_DestinationOffset */
        asm     add     si, ax          /* si += P2325_i_A / 2 */

        asm     shr     di, 1
        asm     shr     di, 1
        asm     mov     ax, di
        asm     mov     ch, 80
        asm     div     ch
        asm     mov     cl, ah          /* cl = P2326_i_DestinationOffset / 320 = Destination Y */

        asm     mov     ch, 160
        asm     mul     ch
        asm     xor     ch, ch
        asm     add     ax, cx
        asm     mov     di, ax
        asm     push    bp
        asm     mov     bp, P2327_i_PixelCount
        asm     mov     ax, es
        asm     mov     ds, ax
        asm     add     bx, offset V8391000_jumptable2
        asm     jmp     word ptr cs:[bx]
        asm     V8391000_jumptable2      dw      asm_loc_11D23
        asm     dw      asm_loc_11EDE
        asm     dw      asm_loc_11FF3
        asm     dw      asm_loc_11E28
        asm     dw      asm_loc_11E37
        asm     dw      asm_loc_12003
        asm     dw      asm_loc_12013
        asm     dw      asm_loc_11E47
        loc_11D23:
        asm     asm_loc_11D23:
        asm     push    bp
        asm     shr     bp, 1
        asm     shr     bp, 1
        asm     inc     bp
        loc_11D29:
        asm     mov     es, bp
        asm     mov     bp, [si]
        asm     and     bp, 0FFh
        asm     mov     dl, V8389000_+bp
        asm     add     bp, bp
        asm     mov     ax, V8382000_+bp
        asm     mov     bx, V8382000_+bp+1024
        asm     mov     bp, [si+1]
        asm     and     bp, 0FFh
        asm     or      dl, V8389000_+bp+256
        asm     add     bp, bp
        asm     or      ax, V8382000_+bp+512
        asm     or      bx, V8382000_+bp+1536
        asm     mov     bp, es
        asm     dec     bp
        asm     jz      loc_11DBB
        asm     mov     dh, dl
        asm     and     ax, dx
        asm     and     bx, dx
        asm     not     dl
        asm     mov     es, cs:V8384001_BitPlane0Offset
        asm     and     es:[di], dl
#if EXETYPE == C20_NEC8
        asm     or      es:[di], bh
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     and     bh, bl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bh
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], ah
        asm     and     es:[di-7FB0h], dl
        asm     and     ah, bl
        asm     or      es:[di-7FB0h], ah
#endif
#if EXETYPE == C21_NEC16
        asm     or      es:[di], bl
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bl
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], bh
        asm     and     es:[di-7FB0h], dl
        asm     or      es:[di-7FB0h], bh
#endif
        asm     mov     es, cs:V8384002_BitPlane2Offset
        asm     and     es:[di], dl
        asm     or      es:[di], al
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
#if EXETYPE == C20_NEC8
        asm     and     al, bl
#endif
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], al
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384003_
        asm     and     es:[di], dl
        asm     or      es:[di], ah
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
#endif
        asm     inc     di
        asm     add     si, 2
        asm     jmp     loc_11D29
        loc_11DBB:
        asm     pop     bp
        asm     and     bp, 3
        asm     jnz     loc_11DC4
        asm     jmp     loc_120BC
        loc_11DC4:
        asm     mov     cx, bp
        asm     shl     cl, 1
        asm     mov     dh, 0FFh
        asm     shr     dh, cl
        asm     not     dh
        asm     and     dl, dh
        asm     mov     dh, dl
        asm     and     ax, dx
        asm     and     bx, dx
        asm     not     dx
        asm     mov     es, cs:V8384001_BitPlane0Offset
        asm     and     es:[di], dl
#if EXETYPE == C20_NEC8
        asm     or      es:[di], bh
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     and     bh, bl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bh
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], ah
        asm     and     es:[di-7FB0h], dl
        asm     and     ah, bl
        asm     or      es:[di-7FB0h], ah
#endif
#if EXETYPE == C21_NEC16
        asm     or      es:[di], bl
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bl
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], bh
        asm     and     es:[di-7FB0h], dl
        asm     or      es:[di-7FB0h], bh
#endif
        asm     mov     es, cs:V8384002_BitPlane2Offset
        asm     and     es:[di], dl
        asm     or      es:[di], al
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
#if EXETYPE == C20_NEC8
        asm     and     al, bl
#endif
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], al
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384003_
        asm     and     es:[di], dl
        asm     or      es:[di], ah
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
#endif
        asm     jmp     loc_120BC
        asm     asm_loc_11E28:
        asm     mov     dl, 3Fh
        asm     call    F8392_
        asm     add     si, 2
        asm     inc     di
        asm     sub     bp, 3
        asm     jmp     loc_11D23
        asm     asm_loc_11E37:
        asm     mov     dl, 0Fh
        asm     dec     si
        asm     call    F8392_
        asm     add     si, 2
        asm     inc     di
        asm     sub     bp, 2
        asm     jmp     loc_11D23
        asm     asm_loc_11E47:
        asm     mov     dl, 3
        asm     dec     si
        asm     call    F8392_
        asm     add     si, 2
        asm     inc     di
        asm     dec     bp
        asm     jmp     loc_11D23

        asm     F8392_:
        asm     push    bp
        asm     mov     bp, [si]
        asm     and     bp, 0FFh
        asm     mov     dh, V8389000_+bp
        asm     add     bp, bp
        asm     mov     ax, V8382000_+bp
        asm     mov     bx, V8382000_+bp+1024
        asm     mov     bp, [si+1]
        asm     and     bp, 0FFh
        asm     or      dh, V8389000_+bp+256
        asm     add     bp, bp
        asm     or      ax, V8382000_+bp+512
        asm     or      bx, V8382000_+bp+1536
        asm     and     dl, dh
        asm     mov     dh, dl
        asm     and     ax, dx
        asm     and     bx, dx
        asm     not     dl
        asm     mov     es, cs:V8384001_BitPlane0Offset
        asm     and     es:[di], dl
#if EXETYPE == C20_NEC8
        asm     or      es:[di], bh
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     and     bh, bl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bh
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], ah
        asm     and     es:[di-7FB0h], dl
        asm     and     ah, bl
        asm     or      es:[di-7FB0h], ah
#endif
#if EXETYPE == C21_NEC16
        asm     or      es:[di], bl
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bl
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], bh
        asm     and     es:[di-7FB0h], dl
        asm     or      es:[di-7FB0h], bh
#endif
        asm     mov     es, cs:V8384002_BitPlane2Offset
        asm     and     es:[di], dl
        asm     or      es:[di], al
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
#if EXETYPE == C20_NEC8
        asm     and     al, bl
#endif
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], al
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384003_
        asm     and     es:[di], dl
        asm     or      es:[di], ah
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
#endif
        asm     pop     bp
        asm     retn

        loc_11EDE:
        asm     asm_loc_11EDE:
        asm     push    bp
        asm     shr     bp, 1
        asm     shr     bp, 1
        asm     inc     bp
        loc_11EE4:
        asm     mov     es, bp
        asm     mov     bp, [si]
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     and     bp, 0FFh
        asm     mov     dl, V8389000_+bp
        asm     add     bp, bp
        asm     mov     ax, V8382000_+bp
        asm     mov     bx, V8382000_+bp+1024
        asm     mov     bp, [si+1]
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     and     bp, 0FFh
        asm     or      dl, V8389000_+bp+256
        asm     add     bp, bp
        asm     or      ax, V8382000_+bp+512
        asm     or      bx, V8382000_+bp+1536
        asm     mov     bp, es
        asm     dec     bp
        asm     jz      loc_11F86
        asm     mov     dh, dl
        asm     and     ax, dx
        asm     and     bx, dx
        asm     not     dl
        asm     mov     es, cs:V8384001_BitPlane0Offset
        asm     and     es:[di], dl
#if EXETYPE == C20_NEC8
        asm     or      es:[di], bh
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     and     bh, bl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bh
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], ah
        asm     and     es:[di-7FB0h], dl
        asm     and     ah, bl
        asm     or      es:[di-7FB0h], ah
#endif
#if EXETYPE == C21_NEC16
        asm     or      es:[di], bl
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bl
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], bh
        asm     and     es:[di-7FB0h], dl
        asm     or      es:[di-7FB0h], bh
#endif
        asm     mov     es, cs:V8384002_BitPlane2Offset
        asm     and     es:[di], dl
        asm     or      es:[di], al
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
#if EXETYPE == C20_NEC8
        asm     and     al, bl
#endif
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], al
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384003_
        asm     and     es:[di], dl
        asm     or      es:[di], ah
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
#endif
        asm     inc     di
        asm     add     si, 2
        asm     jmp     loc_11EE4
        loc_11F86:
        asm     pop     bp
        asm     and     bp, 3
        asm     jnz     loc_11F8F
        asm     jmp     loc_120BC
        loc_11F8F:
        asm     mov     cx, bp
        asm     shl     cl, 1
        asm     mov     dh, 0FFh
        asm     shr     dh, cl
        asm     not     dh
        asm     and     dl, dh
        asm     mov     dh, dl
        asm     and     ax, dx
        asm     and     bx, dx
        asm     not     dx
        asm     mov     es, cs:V8384001_BitPlane0Offset
        asm     and     es:[di], dl
#if EXETYPE == C20_NEC8
        asm     or      es:[di], bh
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     and     bh, bl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bh
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], ah
        asm     and     es:[di-7FB0h], dl
        asm     and     ah, bl
        asm     or      es:[di-7FB0h], ah
#endif
#if EXETYPE == C21_NEC16
        asm     or      es:[di], bl
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bl
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], bh
        asm     and     es:[di-7FB0h], dl
        asm     or      es:[di-7FB0h], bh
#endif
        asm     mov     es, cs:V8384002_BitPlane2Offset
        asm     and     es:[di], dl
        asm     or      es:[di], al
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
#if EXETYPE == C20_NEC8
        asm     and     al, bl
#endif
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], al
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384003_
        asm     and     es:[di], dl
        asm     or      es:[di], ah
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
#endif
        asm     jmp     loc_120BC
        asm     asm_loc_11FF3:
        asm     mov     dl, 3Fh
        asm     dec     si
        asm     call    F8393_
        asm     add     si, 2
        asm     inc     di
        asm     sub     bp, 3
        asm     jmp     loc_11EDE
        asm     asm_loc_12003:
        asm     mov     dl, 0Fh
        asm     dec     si
        asm     call    F8393_
        asm     add     si, 2
        asm     inc     di
        asm     sub     bp, 2
        asm     jmp     loc_11EDE
        asm     asm_loc_12013:
        asm     mov     dl, 3
        asm     sub     si, 2
        asm     call    F8393_
        asm     add     si, 2
        asm     inc     di
        asm     dec     bp
        asm     jmp     loc_11EDE

        asm     F8393_:
        asm     push    bp
        asm     mov     bp, [si]
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     and     bp, 0FFh
        asm     mov     dh, V8389000_+bp
        asm     add     bp, bp
        asm     mov     ax, V8382000_+bp
        asm     mov     bx, V8382000_+bp+1024
        asm     mov     bp, [si+1]
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     rol     bp, 1
        asm     and     bp, 0FFh
        asm     or      dh, V8389000_+bp+256
        asm     add     bp, bp
        asm     or      ax, V8382000_+bp+512
        asm     or      bx, V8382000_+bp+1536
        asm     and     dl, dh
        asm     mov     dh, dl
        asm     and     ax, dx
        asm     and     bx, dx
        asm     not     dl
        asm     mov     es, cs:V8384001_BitPlane0Offset
        asm     and     es:[di], dl
#if EXETYPE == C20_NEC8
        asm     or      es:[di], bh
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     and     bh, bl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bh
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], ah
        asm     and     es:[di-7FB0h], dl
        asm     and     ah, bl
        asm     or      es:[di-7FB0h], ah
#endif
#if EXETYPE == C21_NEC16
        asm     or      es:[di], bl
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], bl
        asm     and     es:[di-8000h], dl
        asm     or      es:[di-8000h], bh
        asm     and     es:[di-7FB0h], dl
        asm     or      es:[di-7FB0h], bh
#endif
        asm     mov     es, cs:V8384002_BitPlane2Offset
        asm     and     es:[di], dl
        asm     or      es:[di], al
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
#if EXETYPE == C20_NEC8
        asm     and     al, bl
#endif
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], al
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384003_
        asm     and     es:[di], dl
        asm     or      es:[di], ah
        asm     and     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], dl
        asm     or      es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
#endif
        asm     pop     bp
        asm     retn

        loc_120BC:
        asm     pop     bp
        asm     pop     ds
}

FUNC_DEF void F0681_CopyPixelLineToScreenWithoutTransparencyFlippedHorizontally(
)
{ /* int16_t P3474_i_SourceOffset, int16_t P3475_i_DestinationOffset, int16_t P3476_i_PixelCount */
}

FUNC_DEF void F0683_CopyPixelLineToScreenWithTransparencyFlippedHorizontally(
)
{ /* int16_t P3477_i_SourceOffset, int16_t P3478_i_DestinationOffset, int16_t P3479_i_PixelCount, int16_t P3480_i_TransparentColor */
}

FUNC_DEF void F8143_CopyPixelLineFromScreenWithoutTransparency(
)
{ /* int16_t P3481_i_SourceOffset, int16_t P3482_i_DestinationOffset, int16_t P3483_i_PixelCount */
}

FUNC_DEF void F8144_CopyPixelLineFromScreenWithoutTransparencyFlippedHorizontally(
)
{ /* int16_t P3484_i_SourceOffset, int16_t P3485_i_DestinationOffset, int16_t P3486_i_PixelCount */
}

FUNC_DEF void F8151_VIDRV_02_Blit( /* Similar to F0684_Blit */
unsigned char* P2333_puc_Bitmap_Source,
unsigned char* P2334_puc_Bitmap_Destination,
int16_t* P2335_pi_Box,
int16_t P2336_i_X,
int16_t P2337_i_Y,
int16_t P2338_i_SourceWidth,
int16_t P2339_i_DestinationWidth,
int16_t P2340_i_TransparentColor,
int16_t P2341_i_Flip)
{
        int16_t L2504_i_Left; /* Cannot be a 'Box' array */
        int16_t L2505_i_Right;
        int16_t L2506_i_Top;
        int16_t L2507_i_Bottom;
        unsigned int16_t L2508_ui_Height;
        unsigned int16_t L2509_ui_Width;
        unsigned int16_t L2510_ui_LineIndex;
#ifdef MEDIA468_P20JA_P31J
        int16_t L3165_i_Unreferenced = 0;
#endif
        int16_t L2511_i_SourcePixelIndex;
        int16_t L2512_i_DestinationPixelIndex;


        ASM_STUB_PREFIX
        G2159_puc_Bitmap_Source = P2333_puc_Bitmap_Source;
        L2504_i_Left = M768_BOX_LEFT(P2335_pi_Box);
        L2505_i_Right = M769_BOX_RIGHT(P2335_pi_Box);
        L2506_i_Top = M770_BOX_TOP(P2335_pi_Box);
        L2507_i_Bottom = M771_BOX_BOTTOM(P2335_pi_Box);
        P2338_i_SourceWidth = M104_EVEN_INTEGER(P2338_i_SourceWidth);
        P2339_i_DestinationWidth = M104_EVEN_INTEGER(P2339_i_DestinationWidth);
        L2509_ui_Width = L2505_i_Right - L2504_i_Left + 1;
        L2508_ui_Height = L2507_i_Bottom - L2506_i_Top + 1;
        if ((L2509_ui_Width <= 0) || (L2508_ui_Height <= 0)) {
                return;
        }
        L2512_i_DestinationPixelIndex = (L2506_i_Top * P2339_i_DestinationWidth) + L2504_i_Left;
        switch (P2341_i_Flip) {
                default:
                        L2511_i_SourcePixelIndex = (P2337_i_Y * P2338_i_SourceWidth) + P2336_i_X;
                        if (P2334_puc_Bitmap_Destination == NULL) {
                                if (P2340_i_TransparentColor >= 0) {
                                        F8389_(P2340_i_TransparentColor);
                                }
                                for (L2510_ui_LineIndex = 0; L2510_ui_LineIndex < L2508_ui_Height; L2510_ui_LineIndex++) {
                                        if (P2340_i_TransparentColor < 0) {
                                                F0680_CopyPixelsToScreenWithoutTransparency(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                        } else {
                                                F0682_CopyPixelLineToScreenWithTransparency(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                        }
                                        L2511_i_SourcePixelIndex += P2338_i_SourceWidth;
                                        L2512_i_DestinationPixelIndex += P2339_i_DestinationWidth;
                                }
                                break;
                        } else {
                                if (P2333_puc_Bitmap_Source == NULL) {
                                        for (L2510_ui_LineIndex = 0; L2510_ui_LineIndex < L2508_ui_Height; L2510_ui_LineIndex++) {
                                                if (P2340_i_TransparentColor < 0) {
                                                        F8143_CopyPixelLineFromScreenWithoutTransparency(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                                } else {
                                                }
                                                L2511_i_SourcePixelIndex += P2338_i_SourceWidth;
                                                L2512_i_DestinationPixelIndex += P2339_i_DestinationWidth;
                                        }
                                }
                        }
                        break;
                case MASK0x0002_FLIP_VERTICAL:
                        L2511_i_SourcePixelIndex = ((P2337_i_Y + L2508_ui_Height - 1) * P2338_i_SourceWidth) + P2336_i_X;
                        if (P2334_puc_Bitmap_Destination == NULL) {
                                for (L2510_ui_LineIndex = 0; L2510_ui_LineIndex < L2508_ui_Height; L2510_ui_LineIndex++) {
                                        if (P2340_i_TransparentColor < 0) {
                                                F0680_CopyPixelsToScreenWithoutTransparency(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                        } else {
                                                F0682_CopyPixelLineToScreenWithTransparency(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                        }
                                        L2511_i_SourcePixelIndex -= P2338_i_SourceWidth;
                                        L2512_i_DestinationPixelIndex += P2339_i_DestinationWidth;
                                }
                        } else {
                                if (P2333_puc_Bitmap_Source == NULL) {
                                        for (L2510_ui_LineIndex = 0; L2510_ui_LineIndex < L2508_ui_Height; L2510_ui_LineIndex++) {
                                                if (P2340_i_TransparentColor < 0) {
                                                        F8143_CopyPixelLineFromScreenWithoutTransparency(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                                } else {
                                                }
                                                L2511_i_SourcePixelIndex -= P2338_i_SourceWidth;
                                                L2512_i_DestinationPixelIndex += P2339_i_DestinationWidth;
                                        }
                                }
                        }
                        break;
                case MASK0x0001_FLIP_HORIZONTAL:
                        L2511_i_SourcePixelIndex = (P2337_i_Y * P2338_i_SourceWidth) + P2336_i_X;
                        if (P2334_puc_Bitmap_Destination == NULL) {
                                for (L2510_ui_LineIndex = 0; L2510_ui_LineIndex < L2508_ui_Height; L2510_ui_LineIndex++) {
                                        if (P2340_i_TransparentColor < 0) {
                                                F0681_CopyPixelLineToScreenWithoutTransparencyFlippedHorizontally(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                        } else {
                                                F0683_CopyPixelLineToScreenWithTransparencyFlippedHorizontally(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width, P2340_i_TransparentColor);
                                        }
                                        L2511_i_SourcePixelIndex += P2338_i_SourceWidth;
                                        L2512_i_DestinationPixelIndex += P2339_i_DestinationWidth;
                                }
                        } else {
                                if (P2333_puc_Bitmap_Source == NULL) {
                                        for (L2510_ui_LineIndex = 0; L2510_ui_LineIndex < L2508_ui_Height; L2510_ui_LineIndex++) {
                                                if (P2340_i_TransparentColor < 0) {
                                                        F8144_CopyPixelLineFromScreenWithoutTransparencyFlippedHorizontally(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                                } else {
                                                }
                                                L2511_i_SourcePixelIndex += P2338_i_SourceWidth;
                                                L2512_i_DestinationPixelIndex += P2339_i_DestinationWidth;
                                        }
                                }
                        }
                        break;
                case MASK0x0001_FLIP_HORIZONTAL | MASK0x0002_FLIP_VERTICAL:
                        L2511_i_SourcePixelIndex = ((P2337_i_Y + L2508_ui_Height - 1) * P2338_i_SourceWidth) + P2336_i_X;
                        if (P2334_puc_Bitmap_Destination == NULL) {
                                for (L2510_ui_LineIndex = 0; L2510_ui_LineIndex < L2508_ui_Height; L2510_ui_LineIndex++) {
                                        if (P2340_i_TransparentColor < 0) {
                                                F0681_CopyPixelLineToScreenWithoutTransparencyFlippedHorizontally(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                        } else {
                                                F0683_CopyPixelLineToScreenWithTransparencyFlippedHorizontally(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width, P2340_i_TransparentColor);
                                        }
                                        L2511_i_SourcePixelIndex -= P2338_i_SourceWidth;
                                        L2512_i_DestinationPixelIndex += P2339_i_DestinationWidth;
                                }
                        } else {
                                if (P2333_puc_Bitmap_Source == NULL) {
                                        for (L2510_ui_LineIndex = 0; L2510_ui_LineIndex < L2508_ui_Height; L2510_ui_LineIndex++) {
                                                if (P2340_i_TransparentColor < 0) {
                                                        F8144_CopyPixelLineFromScreenWithoutTransparencyFlippedHorizontally(L2511_i_SourcePixelIndex, L2512_i_DestinationPixelIndex, L2509_ui_Width);
                                                } else {
                                                }
                                                L2511_i_SourcePixelIndex -= P2338_i_SourceWidth;
                                                L2512_i_DestinationPixelIndex += P2339_i_DestinationWidth;
                                        }
                                }
                        }
        }
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8399_ReplaceInterrupt10VectorVerticalBlank(
)
{
        asm     jmp     loc_123A7
        asm     V8399000_VerticalBlankInteruptVectorBackup     dd 0
        loc_123A7:
        asm     mov     ax, 350Ah
        asm     int     21h             /* DOS - 2+ - GET INTERRUPT VECTOR */
                                        /* AL = interrupt number */
                                        /* Return: ES:BX = value of interrupt vector */
        asm     mov     word ptr cs:V8399000_VerticalBlankInteruptVectorBackup, bx
        asm     mov     word ptr cs:V8399000_VerticalBlankInteruptVectorBackup+2, es
        asm     push    ds
        asm     mov     dx, seg Vector
        asm     mov     ds, dx
        asm     mov     dx, offset Vector
        asm     mov     ax, 250Ah
        asm     int     21h             /* DOS - SET INTERRUPT VECTOR */
                                        /* AL = interrupt number */
                                        /* DS:DX = new vector to be used for specified interrupt */
        asm     pop     ds
        asm     in      al, 2           /* Read Interrupt Mask Register from port 2 */
        asm     and     al, 0FBh        /* Clear bit 2 (CRT Vsync) in Interrupt Mask Register to enable interrupts */
        asm     out     2, al           /* Write updated Interrupt Mask Register to port 2 */
        asm     out     64h, al         /* CRT vertical sync interrupt reset (write any value to port 64h) so that the next vertical sync will trigger the interrupt */
        asm     jmp     locret_123E7
        asm     Vector:
        asm     push    ax
#ifdef MEDIA457_P20JA
        asm     push    es
#endif
        asm     push    ds
#ifdef MEDIA457_P20JA
        asm     push    bx
        asm     push    cx
        asm     push    dx
        asm     push    si
        asm     push    di
#endif
        asm     mov     ax, cs:V0000000_DataSegment
        asm     mov     ds, ax
        G8315_B_VerticalBlankOccured = C1_TRUE;
#ifdef MEDIA457_P20JA
        G8308_i_VerticalBlankCount++;
        asm     pop     di
        asm     pop     si
        asm     pop     dx
        asm     pop     cx
        asm     pop     bx
#endif
        asm     pop     ds
#ifdef MEDIA457_P20JA
        asm     pop     es
#endif
        asm     mov     al, 20h
        asm     out     0, al           /* Write 20h to port 0, to send EOI (End Of Interrupt) to notify the PIC (Programmable Interrupt Controller) */
        asm     out     64h, al         /* CRT vertical sync interrupt reset (write any value to port 64h) so that the next vertical sync will trigger the interrupt */
        asm     pop     ax
        asm     iret
        locret_123E7: ;
}

FUNC_DEF void F8400_RestoreInterrupt10Vector(
)
{
        asm     in      al, 2           /* Read Interrupt Mask Register from port 2 */
        asm     or      al, 4           /* Set bit 2 (CRT Vsync) in Interrupt Mask Register to disable interrupts */
        asm     out     2, al           /* Write updated Interrupt Mask Register to port 2 */
        asm     push    ds
        asm     mov     dx, word ptr cs:V8399000_VerticalBlankInteruptVectorBackup+2
        asm     mov     ds, dx
        asm     mov     dx, word ptr cs:V8399000_VerticalBlankInteruptVectorBackup
        asm     mov     ax, 250Ah
        asm     int     21h             /* DOS - SET INTERRUPT VECTOR */
                                        /* AL = interrupt number */
                                        /* DS:DX = new vector to be used for specified interrupt */
        asm     pop     ds
}

FUNC_DEF void F8153_VIDRV_07_WaitVerticalBlank(
)
{
#ifdef MEDIA468_P20JA_P31J
        int16_t L3168_i_Unreferenced = 0;


#endif
        ASM_STUB_PREFIX
        G8315_B_VerticalBlankOccured = C0_FALSE;
        while (G8315_B_VerticalBlankOccured == C0_FALSE);
#ifdef MEDIA457_P20JA
        asm     pushf
        asm     cli
        asm     popf
#endif
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8137_SetMultiplePixels(
#ifdef MEDIA457_P20JA
int16_t P2483_i_PixelIndex,
#endif
char P2484_c_Color,
int16_t P2485_i_PixelCount)
{
#ifdef MEDIA457_P20JA
        asm     cld
        asm     les     di, G8134_pc_VideoMemory
        asm     mov     bx, P2483_i_PixelIndex
        asm     mov     cx, P2485_i_PixelCount
        asm     mov     ah, P2484_c_Color
        asm     shr     bx, 1
        asm     pushf
        asm     add     di, bx
        asm     popf
        asm     jnb     loc_103A2
        asm     mov     al, es:[di]
        asm     and     al, 0F0h
        asm     or      al, ah
        asm     stosb
        asm     dec     cx
        asm     jz      loc_103CA
        loc_103A2:
        asm     mov     al, ah
        asm     shl     al, 1
        asm     shl     al, 1
        asm     shl     al, 1
        asm     shl     al, 1
        asm     or      al, ah
        asm     mov     ah, al
        asm     shr     cx, 1
        asm     pushf
        asm     shr     cx, 1
        asm     jnb     loc_103B8
        asm     stosb
        loc_103B8:
        asm     rep stosw
#if EXETYPE == C21_NEC16
        asm     or      cx, cx
        asm     jnz     loc_103B8
#endif
        asm     popf
        asm     jnb     loc_103CA
        asm     mov     al, es:[di]
        asm     and     ax, 0F00Fh
        asm     or      al, ah
        asm     stosb
        loc_103CA: ;
#endif
#ifdef MEDIA472_P20JB_P31J
        asm     cld
        asm     les     di, G8134_pc_VideoMemory
        asm     mov     cx, P2485_i_PixelCount
        asm     mov     al, P2484_c_Color
        loc_12438:
        asm     rep stosb
        asm     or      cx, cx
        asm     jnz     loc_12438
        asm     stosb
#endif
}

FUNC_DEF void F8152_VIDRV_01_FillBox(
unsigned char* P2516_puc_Bitmap,
int16_t* P2517_pi_Box,
char P3501_c_)
{
        int16_t L2513_i_Left;
        int16_t L2514_i_Right;
        int16_t L2515_i_Top;
        int16_t L2516_i_Bottom;
        int16_t L2517_i_Height;
        unsigned int16_t L2518_ui_Width;
        int16_t L2519_i_DestinationOffset;
        unsigned int16_t L2520_ui_LineIndex;


        ASM_STUB_PREFIX
        L2513_i_Left = M768_BOX_LEFT(P2517_pi_Box);
        L2514_i_Right = M769_BOX_RIGHT(P2517_pi_Box);
        L2515_i_Top = M770_BOX_TOP(P2517_pi_Box);
        L2516_i_Bottom = M771_BOX_BOTTOM(P2517_pi_Box);
        L2518_ui_Width = L2514_i_Right - L2513_i_Left + 1;
        L2517_i_Height = L2516_i_Bottom - L2515_i_Top + 1;
        L2519_i_DestinationOffset = L2515_i_Top * 320 + L2513_i_Left;
#ifdef MEDIA457_P20JA
        F8137_SetMultiplePixels(0, P3501_c_, L2518_ui_Width);
#endif
#ifdef MEDIA472_P20JB_P31J
        F8137_SetMultiplePixels(P3501_c_ | (P3501_c_ << 4), (L2518_ui_Width + 1) >> 1);
#endif
        G2159_puc_Bitmap_Source = G8138_;
        for (L2520_ui_LineIndex = 0; L2520_ui_LineIndex < L2517_i_Height; L2520_ui_LineIndex++) {
                F0680_CopyPixelsToScreenWithoutTransparency(0, L2519_i_DestinationOffset, L2518_ui_Width);
                L2519_i_DestinationOffset += 320;
        }
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8404_(
int16_t P3502_i_,
int16_t P3503_i_)
{
        asm     mov     si, P3503_i_
        asm     mov     di, P3502_i_
        asm     mov     ax, di
        asm     shr     di, 1
        asm     shr     di, 1
        asm     push    ax
        asm     mov     ax, di
        asm     mov     ch, C80_BITPLANE_LINE_BYTE_COUNT
        asm     div     ch
        asm     mov     cl, ah
        asm     mov     ch, 0A0h
        asm     mul     ch
        asm     xor     ch, ch
        asm     add     ax, cx
        asm     mov     di, ax
        asm     pop     ax
        asm     and     ax, 3
        asm     jz      loc_12521
        asm     mov     cl, al
        asm     mov     al, 4
        asm     sub     al, cl
        asm     sub     si, ax
        asm     jge     loc_1250E
        asm     jmp     loc_12554
        loc_1250E:
        asm     shl     cl, 1
        asm     mov     ah, 0FFh
        asm     shr     ah, cl
#if EXETYPE == C20_NEC8
        asm     mov     bx, 0A800h      /* Bit plane 0 segment (Blue) */
        asm     mov     es, bx
        asm     xor     es:[di], ah
        asm     xor     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
        asm     mov     bx, 0B800h      /* Bit plane 2 segment (Green) */
        asm     mov     es, bx
#endif
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384002_BitPlane2Offset
#endif
        asm     xor     es:[di], ah
        asm     xor     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
        asm     inc     di
        loc_12521:
        asm     push    si
        asm     shr     si, 1
        asm     shr     si, 1
        asm     jz      loc_12538
        loc_12528:
#if EXETYPE == C20_NEC8
        asm     mov     bx, 0A800h      /* Bit plane 0 segment (Blue) */
        asm     mov     es, bx
        asm     not     byte ptr es:[di]
        asm     not     byte ptr es:[di+C80_BITPLANE_LINE_BYTE_COUNT]
        asm     mov     bx, 0B800h      /* Bit plane 2 segment (Green) */
        asm     mov     es, bx
#endif
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384002_BitPlane2Offset
#endif
        asm     not     byte ptr es:[di]
        asm     not     byte ptr es:[di+C80_BITPLANE_LINE_BYTE_COUNT]
        asm     inc     di
        asm     dec     si
        asm     jnz     loc_12528
        loc_12538:
        asm     pop     ax
        asm     mov     cl, al
        asm     and     cl, 3
        asm     jz      loc_12554
        asm     shl     cl, 1
        asm     mov     ah, 0FFh
        asm     shr     ah, cl
        asm     not     ah
#if EXETYPE == C20_NEC8
        asm     mov     bx, 0A800h      /* Bit plane 0 segment (Blue) */
        asm     mov     es, bx
        asm     xor     es:[di], ah
        asm     xor     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
        asm     mov     bx, 0B800h      /* Bit plane 2 segment (Green) */
        asm     mov     es, bx
#endif
#if EXETYPE == C21_NEC16
        asm     mov     es, cs:V8384002_BitPlane2Offset
#endif
        asm     xor     es:[di], ah
        asm     xor     es:[di+C80_BITPLANE_LINE_BYTE_COUNT], ah
        loc_12554: ;
}

FUNC_DEF void F8154_VIDRV_05_InvertBox(
int16_t P2520_i_X1,
int16_t P2521_i_X2,
int16_t P2522_i_Y1,
int16_t P2523_i_Y2)
{
        int16_t L2522_i_;
        int16_t L3178_i_;
#ifdef MEDIA468_P20JA_P31J
        int16_t L3179_i_Unreferenced = 0;
#endif
        int16_t L2521_i_;
        int16_t L2525_i_;


        ASM_STUB_PREFIX
        L2522_i_ = P2521_i_X2 - P2520_i_X1 + 1;
        L3178_i_ = P2523_i_Y2 - P2522_i_Y1 + 1;
        L2525_i_ = P2522_i_Y1 * 320 + P2520_i_X1;
        for (L2521_i_ = 0; L2521_i_ < L3178_i_; L2521_i_++) {
                F8404_(L2525_i_, L2522_i_);
                L2525_i_ += 320;
        }
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8155_VIDRV_06_HatchScreenBox(
int16_t P2524_i_X1,
int16_t P2525_i_X2,
int16_t P2526_i_Y1,
int16_t P2527_i_Y2)
{
        int16_t L2528_i_;
        int16_t L2526_i_;
        int16_t L2527_i_;
#ifdef MEDIA468_P20JA_P31J
        int16_t L3185_i_Unreferenced = 0;
#endif
        int16_t L2529_i_;
        int16_t L2530_i_;


        ASM_STUB_PREFIX
        F8389_(15);
        L2527_i_ = P2525_i_X2 - P2524_i_X1 + 1;
        L2528_i_ = (L2527_i_ + 1) >> 1;
        L2526_i_ = P2526_i_Y1 * 320 + P2524_i_X1;
        G2159_puc_Bitmap_Source = G8138_;
        for (L2530_i_ = P2526_i_Y1; L2530_i_ <= P2527_i_Y2; L2530_i_++) {
                for (L2529_i_ = 0; L2529_i_ < L2528_i_; L2529_i_++) {
                        if (L2530_i_ & 1) {
                                G8138_[L2529_i_] = 0x0F;
                        } else {
                                G8138_[L2529_i_] = 0xF0;
                        }
                }
                F0682_CopyPixelLineToScreenWithTransparency(0, L2526_i_, L2527_i_);
                L2526_i_ += 320;
        }
        ASM_STUB_SUFFIX
}

#ifdef MEDIA457_P20JA
FUNC_DEF void F8167_VIDRV_03_BlitMousePointerPrefixedBitmapFromScreen(
int16_t P2552_i_X,
int16_t P2553_i_Y)
{
        unsigned int16_t L2550_ui_;
        unsigned int16_t L2551_ui_;
        int16_t L3191_i_Unreferenced = 0;


        ASM_STUB_PREFIX
        G8324_ = 200 - P2553_i_Y;
        if (G8324_ > 18) {
                G8324_ = 18;
        }
        G8322_ = P2552_i_X >> 2;
        G8323_ = 80 - G8322_;
        if (G8323_ > 6) {
                G8323_ = 6;
        }
        G8322_ += P2553_i_Y * 160;
        asm     cld
        asm     mov     si, G8322_
        asm     mov     di, offset G8133_PrefixedBitmap
        asm     mov     ax, ds
        asm     mov     es, ax
        asm     mov     bx, G8323_
        asm     mov     dx, G8324_
        asm     shl     dx, 1
        asm     push    ds
        loc_12AF0:
        asm     push    si
        asm     mov     ax, 0A800h      /* Bit plane 0 segment (Blue) */
        asm     mov     ds, ax
        asm     mov     cx, bx
        loc_12AF8:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12AF8
        asm     pop     si
        asm     push    si
        asm     mov     ax, 0B000h      /* Bit plane 1 segment (Red) */
        asm     mov     ds, ax
        asm     mov     cx, bx
        loc_12B07:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12B07
        asm     pop     si
        asm     push    si
        asm     mov     ax, 0B800h      /* Bit plane 2 segment (Green) */
        asm     mov     ds, ax
        asm     mov     cx, bx
        loc_12B16:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12B16
        asm     pop     si
#if EXETYPE == C21_NEC16
        asm     push    si
        asm     mov     ax, 0E000h      /* Bit plane 3 segment (Intensity) */
        asm     mov     ds, ax
        asm     mov     cx, bx
        loc_12B25:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12B25
        asm     pop     si
#endif
        asm     add     si, C80_BITPLANE_LINE_BYTE_COUNT
        asm     dec     dx
        asm     jnz     loc_12AF0
        asm     pop     ds
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8168_VIDRV_04_BlitMousePointerPrefixedBitmapToScreen(
)
{
        int16_t L3192_i_Unreferenced = 0;


        ASM_STUB_PREFIX
        asm     cld
        asm     mov     bx, G8323_
        asm     mov     dx, G8324_
        asm     shl     dx, 1
        asm     mov     di, G8322_
        asm     push    ds
        asm     mov     si, offset G8133_PrefixedBitmap
        loc_12B61:
        asm     push    di
        asm     mov     ax, 0A800h      /* Bit plane 0 segment (Blue) */
        asm     mov     es, ax
        asm     mov     cx, bx
        loc_12B69:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12B69
        asm     pop     di
        asm     push    di
        asm     mov     ax, 0B000h      /* Bit plane 1 segment (Red) */
        asm     mov     es, ax
        asm     mov     cx, bx
        loc_12B78:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12B78
        asm     pop     di
        asm     push    di
        asm     mov     ax, 0B800h      /* Bit plane 2 segment (Green) */
        asm     mov     es, ax
        asm     mov     cx, bx
        loc_12B87:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12B87
        asm     pop     di
#if EXETYPE == C21_NEC16
        asm     push    di
        asm     mov     ax, 0E000h      /* Bit plane 3 segment (Intensity) */
        asm     mov     es, ax
        asm     mov     cx, bx
        loc_12B96:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12B96
        asm     pop     di
#endif
        asm     add     di, C80_BITPLANE_LINE_BYTE_COUNT
        asm     dec     dx
        asm     jnz     loc_12B61
        asm     pop     ds
        ASM_STUB_SUFFIX
}
#endif

#if EXETYPE == C20_NEC8
FUNC_DEF void F8157_VIDRV_08_SetMultipleColorsInPalette(
int16_t P2529_i_PaletteIndex,
COLOR_DEF* P3515_ps_)
{
        COLOR_DEF* L3193_ps_;
        unsigned int16_t L3194_ui_PaletteType;
        char L2535_c_ColorIndex;
#ifdef MEDIA468_P20JA_P31J
        int16_t L3196_i_Unreferenced = 0;
#endif
        int16_t L2536_i_;


        ASM_STUB_PREFIX
        if (P2529_i_PaletteIndex == -1) {
                L3193_ps_ = P3515_ps_;
                L3194_ui_PaletteType = 1; /* Palette for non viewport */
                G8311_i_CurrentNonViewportPaletteIndex = -2;
        } else {
                L3193_ps_ = G8273_as_ColorPalettes[P2529_i_PaletteIndex].ColorDef;
                L3194_ui_PaletteType = G8273_as_ColorPalettes[P2529_i_PaletteIndex].PalType;
        }
        if (!L3194_ui_PaletteType) { /* 0: Palette for viewport */
                if (P2529_i_PaletteIndex != G8312_i_CurrentViewportPaletteIndex) {
                        G8312_i_CurrentViewportPaletteIndex = P2529_i_PaletteIndex;
                        for (L2536_i_ = 0; L2536_i_ < 16; L2536_i_++) {
                                if ((L2535_c_ColorIndex = L3193_ps_[L2536_i_].Index) == 0x1F) {
                                        break;
                                }
                                G8320_as_CurrentViewportPalette[L2535_c_ColorIndex].Flag = L3193_ps_[L2536_i_].Flag;
                                G8320_as_CurrentViewportPalette[L2535_c_ColorIndex].Color = L3193_ps_[L2536_i_].Color;
                        }
                        F8384_(G8320_as_CurrentViewportPalette);
                }
        } else { /* 1: Palette for non viewport */
                if (P2529_i_PaletteIndex != G8311_i_CurrentNonViewportPaletteIndex) {
                        G8311_i_CurrentNonViewportPaletteIndex = P2529_i_PaletteIndex;
                        for (L2536_i_ = 0; L2536_i_ < 16; L2536_i_++) {
                                if ((L2535_c_ColorIndex = L3193_ps_[L2536_i_].Index) == 0x1F) {
                                        break;
                                }
                                G8319_as_CurrentNonViewportPalette[L2535_c_ColorIndex].Flag = L3193_ps_[L2536_i_].Flag;
                                G8319_as_CurrentNonViewportPalette[L2535_c_ColorIndex].Color = L3193_ps_[L2536_i_].Color;
                        }
                        F8382_PrepareV8382000FromPalette(G8319_as_CurrentNonViewportPalette);
                }
        }
        ASM_STUB_SUFFIX
}

#ifdef MEDIA472_P20JB_P31J
FUNC_DEF void F8409_VIDRV_17_SetSingleColorInPalette1(
int16_t P3516_i_ColorIndex,
int16_t P3517_i_)
{
        ASM_STUB_PREFIX
        if (P3516_i_ColorIndex < 0) {
                G8311_i_CurrentNonViewportPaletteIndex = -2;
                F8382_PrepareV8382000FromPalette(G8319_as_CurrentNonViewportPalette);
        } else {
                if (P3516_i_ColorIndex < 16) {
                        G8319_as_CurrentNonViewportPalette[P3516_i_ColorIndex].Index = P3516_i_ColorIndex;
                        G8319_as_CurrentNonViewportPalette[P3516_i_ColorIndex].Flag = P3517_i_ & 1;
                        G8319_as_CurrentNonViewportPalette[P3516_i_ColorIndex].Color = P3517_i_ >> 1;
                }
        }
        ASM_STUB_SUFFIX
}
#endif
#endif

#if EXETYPE == C21_NEC16
FUNC_DEF void F8157_VIDRV_08_SetMultipleColorsInPalette(
int16_t P3518_i_PaletteIndex)
{
        unsigned char (*L3198_auc_)[4]; /*COLOR_DEF* L3198_auc_;*/
        char* L3199_pc_;
        unsigned char L3200_uc_;
        unsigned char L3201_uc_;
        unsigned char L3202_uc_;
        unsigned char L3203_uc_;
#ifdef MEDIA468_P20JA_P31J
        int16_t L3204_i_Unreferenced = 0;
#endif
        int16_t L3205_i_;


        ASM_STUB_PREFIX
        if (G8273_as_ColorPalettes[P3518_i_PaletteIndex].PalType == 0) {
                L3199_pc_ = (char*)G8273_as_ColorPalettes[P3518_i_PaletteIndex].ColorDef;
                if (P3518_i_PaletteIndex != G8312_i_CurrentViewportPaletteIndex) {
                        G8312_i_CurrentViewportPaletteIndex = P3518_i_PaletteIndex;
                        F8384_(L3199_pc_);
                }
        } else {
                L3198_auc_ = (unsigned char (*)[4])G8273_as_ColorPalettes[P3518_i_PaletteIndex].ColorDef;
                for (L3205_i_ = 0; L3205_i_ < 16; L3205_i_++) {
                        if ((L3203_uc_ = L3198_auc_[L3205_i_][0]) == 255) {
                                break;
                        }
                        L3200_uc_ = L3198_auc_[L3205_i_][1] >> 2;
                        L3202_uc_ = L3198_auc_[L3205_i_][3] >> 2;
                        L3201_uc_ = L3198_auc_[L3205_i_][2] >> 2;
                        asm     mov     al, L3203_uc_
                        asm     out     0A8h, al            /* In 16-color mode, A8h is color index (low 4 bits) and AAh, ACh, AEh are 4-bit wide registers for G, R, and B values */
                        asm     mov     al, L3200_uc_
                        asm     out     0ACh, al            /* Red component */
                        asm     mov     al, L3201_uc_
                        asm     out     0AAh, al            /* Green component */
                        asm     mov     al, L3202_uc_
                        asm     out     0AEh, al            /* Blue component */
                }
        }
        ASM_STUB_SUFFIX
}

#ifdef MEDIA472_P20JB_P31J
FUNC_DEF void F8230_VIDRV_16_SetSingleColorComponentsInPalette(
int16_t P3234_i_ColorIndex,
char P3235_c_Red,
char P3236_c_Green,
char P3237_c_Blue)
{
#ifdef MEDIA667_P31J
        int16_t L3206_i_Unreferenced = 0;


#endif
        ASM_STUB_PREFIX
        asm     mov     al, P3234_i_ColorIndex
        asm     out     0A8h, al            /* In 16-color mode, A8h is color index (low 4 bits) and AAh, ACh, AEh are 4-bit wide registers for G, R, and B values */
        asm     mov     al, P3235_c_Red
        asm     out     0ACh, al            /* Red component */
        asm     mov     al, P3236_c_Green
        asm     out     0AAh, al            /* Green component */
        asm     mov     al, P3237_c_Blue
        asm     out     0AEh, al            /* Blue component */
        ASM_STUB_SUFFIX
}
#endif
#endif

FUNC_DEF void F8159_VIDRV_11_PALETTE_SetCurtain(
char P2532_c_State)
{
#ifdef MEDIA468_P20JA_P31J
        int16_t L3207_i_Unreferenced = 0;


#endif
        ASM_STUB_PREFIX
        F8153_VIDRV_07_WaitVerticalBlank();
        if (P2532_c_State == C0_BLACK_PALETTE) {
                /* PC-98 I/O ports A8h, AAh, ACh and AEh control the color palette */
#if EXETYPE == C20_NEC8
                asm     mov     al, 0           /* In 8-color mode, the 3 least significant bits of each nibble in these registers defines a color in the palette in this format: 0GRB0GRB */
                asm     out     0A8h, al        /* Set color 3 to GRB=000 (Black) and color 7 to GRB=000 (Black) */
                asm     out     0AAh, al        /* Set color 1 to GRB=000 (Black) and color 5 to GRB=000 (Black) */
                asm     out     0ACh, al        /* Set color 2 to GRB=000 (Black) and color 6 to GRB=000 (Black) */
                asm     out     0AEh, al        /* Set color 0 to GRB=000 (Black) and color 4 to GRB=000 (Black) */
#endif
#if EXETYPE == C21_NEC16
                loc_1277D:
                asm     in      al, 0A0h        /* Read GDC status register */
                asm     xor     al, 24h
                asm     test    al, 24h
                asm     jnz     loc_1277D       /* Wait for vertical sync (bit 0x20 set in GDC status register) and GDC FIFO is empty (bit 0x04 set in GDC status register) */
                asm     mov     al, 0Ch
                asm     out     0A2h, al        /* Write GDC command 'STOP' to GDC command register to stop dislaying the screen */
#endif
        } else {
#if EXETYPE == C20_NEC8
                asm     mov     al, 37h         /* Set color 3 to GRB=3=011 (Magenta) and color 7 to GRB=7=111 (White) */
                asm     out     0A8h, al
                asm     mov     al, 15h         /* Set color 1 to GRB=1=001 (Blue) and color 5 to GRB=5=101 (Cyan) */
                asm     out     0AAh, al
                asm     mov     al, 26h         /* Set color 2 to GRB=2=010 (Red) and color 6 to GRB=6=110 (Yellow) */
                asm     out     0ACh, al
                asm     mov     al, 04h         /* Set color 0 to GRB=0=000 (Black) and color 4 to GRB=4=100 (Green) */
                asm     out     0AEh, al
#endif
#if EXETYPE == C21_NEC16
                loc_1278B:
                asm     in      al, 0A0h        /* Read GDC status register */
                asm     xor     al, 24h
                asm     test    al, 24h
                asm     jnz     loc_1278B       /* Wait for vertical sync (bit 0x20 set in GDC status register) and GDC FIFO is empty (bit 0x04 set in GDC status register) */
                asm     mov     al, 0Dh
                asm     out     0A2h, al        /* Write GDC command 'START' to GDC command register to start dislaying the screen  */
#endif
        }
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8160_VIDRV_12_SetCreatureReplacementColors(
int16_t P2533_i_,
int16_t P2534_i_)
{
#if EXETYPE == C20_NEC8
        COLOR_DEF* L2539_ps_;
#endif
#if EXETYPE == C21_NEC16
        char* L2539_ps_;
#endif
#ifdef MEDIA468_P20JA_P31J
        int16_t L3209_i_Unreferenced = 0;
#endif
        int16_t L2540_i_;


        ASM_STUB_PREFIX
        for (L2540_i_ = 0; L2540_i_ < 6; L2540_i_++) {
#if EXETYPE == C20_NEC8
                L2539_ps_ = G8273_as_ColorPalettes[L2540_i_].ColorDef;
                L2539_ps_[P2533_i_].Flag = G8275_[P2534_i_][L2540_i_].Flag;
                L2539_ps_[P2533_i_].Color = G8275_[P2534_i_][L2540_i_].Color;
#endif
#if EXETYPE == C21_NEC16
                L2539_ps_ = (char*)G8273_as_ColorPalettes[L2540_i_].ColorDef;
                L2539_ps_[P2533_i_] = G8275_[P2534_i_][L2540_i_];
#endif
        }
        G8312_i_CurrentViewportPaletteIndex = -1;
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8161_VIDRV_09_BlitViewPort(
unsigned char* P2535_puc_Bitmap,
int16_t* P2536_pi_Box)
{
#ifdef MEDIA468_P20JA_P31J
        int16_t L3211_i_Unreferenced = 0;


#endif
        ASM_STUB_PREFIX
        F8147_(P2535_puc_Bitmap, M770_BOX_TOP(P2536_pi_Box) * C160_BYTE_WIDTH_SCREEN);
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8162_VIDRV_10_ScrollMessageAreaUp(
int16_t* P2537_pi_Box,
unsigned int16_t P3529_ui_)
{
#ifdef MEDIA468_P20JA_P31J
        int16_t L3212_i_Unreferenced = 0;
#endif
        int16_t L2541_i_;
        int16_t L3215_i_;


        ASM_STUB_PREFIX
        L3215_i_ = (M769_BOX_RIGHT(P2537_pi_Box) - M768_BOX_LEFT(P2537_pi_Box) + 1) >> 2;
        for (L2541_i_ = M770_BOX_TOP(P2537_pi_Box) + P3529_ui_; L2541_i_ <= M771_BOX_BOTTOM(P2537_pi_Box); L2541_i_++) {
                F8140_ScrollMessageAreaUp((char*)(0xA8000000 | (L2541_i_ * 160U     )), (char*)(0xA8000000 | ((L2541_i_ - P3529_ui_) * 160U     )), L3215_i_);
                F8140_ScrollMessageAreaUp((char*)(0xA8000000 | (L2541_i_ * 160U + 80)), (char*)(0xA8000000 | ((L2541_i_ - P3529_ui_) * 160U + 80)), L3215_i_);
                F8140_ScrollMessageAreaUp((char*)(0xB0000000 | (L2541_i_ * 160U     )), (char*)(0xB0000000 | ((L2541_i_ - P3529_ui_) * 160U     )), L3215_i_);
                F8140_ScrollMessageAreaUp((char*)(0xB0000000 | (L2541_i_ * 160U + 80)), (char*)(0xB0000000 | ((L2541_i_ - P3529_ui_) * 160U + 80)), L3215_i_);
                F8140_ScrollMessageAreaUp((char*)(0xB8000000 | (L2541_i_ * 160U     )), (char*)(0xB8000000 | ((L2541_i_ - P3529_ui_) * 160U     )), L3215_i_);
                F8140_ScrollMessageAreaUp((char*)(0xB8000000 | (L2541_i_ * 160U + 80)), (char*)(0xB8000000 | ((L2541_i_ - P3529_ui_) * 160U + 80)), L3215_i_);
#ifdef MEDIA472_P20JB_P31J
#if EXETYPE == C21_NEC16
                F8140_ScrollMessageAreaUp((char*)(0xE0000000 | (L2541_i_ * 160U     )), (char*)(0xE0000000 | ((L2541_i_ - P3529_ui_) * 160U     )), L3215_i_);
                F8140_ScrollMessageAreaUp((char*)(0xE0000000 | (L2541_i_ * 160U + 80)), (char*)(0xE0000000 | ((L2541_i_ - P3529_ui_) * 160U + 80)), L3215_i_);
#endif
#endif
        }
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8163_VIDRV_00_CopyPixelsToScreenWithoutTransparency(
unsigned char* P2539_puc_Bitmap,
unsigned int16_t P2540_ui_SourcePixelIndex,
unsigned int16_t P2541_ui_DestinationPixelIndex,
unsigned int16_t P2542_ui_PixelCount)
{
#ifdef MEDIA457_P20JA
        int16_t L3213_i_Unreferenced = 0;
#endif
#ifdef MEDIA472_P20JB_P31J
        long L3216_l_PixelCount;
        int16_t L3217_i_FirstLinePixelCount = 0;
#endif


        ASM_STUB_PREFIX
        G2159_puc_Bitmap_Source = P2539_puc_Bitmap;
#ifdef MEDIA457_P20JA
        F0680_CopyPixelsToScreenWithoutTransparency(P2540_ui_SourcePixelIndex, P2541_ui_DestinationPixelIndex, P2542_ui_PixelCount);
#endif
#ifdef MEDIA472_P20JB_P31J
        L3217_i_FirstLinePixelCount = 320 - (P2541_ui_DestinationPixelIndex % 320);
        if (L3217_i_FirstLinePixelCount > P2542_ui_PixelCount) {
                L3217_i_FirstLinePixelCount = P2542_ui_PixelCount;
        }
        if (L3217_i_FirstLinePixelCount) { /* Copy pixels on first line */
                F0680_CopyPixelsToScreenWithoutTransparency(P2540_ui_SourcePixelIndex, P2541_ui_DestinationPixelIndex, L3217_i_FirstLinePixelCount);
                P2542_ui_PixelCount -= L3217_i_FirstLinePixelCount;
                P2541_ui_DestinationPixelIndex += L3217_i_FirstLinePixelCount;
                P2540_ui_SourcePixelIndex += L3217_i_FirstLinePixelCount;
        }
        L3216_l_PixelCount = P2542_ui_PixelCount;
        while (L3216_l_PixelCount > 320) { /* Copy full lines of pixels */
                F0680_CopyPixelsToScreenWithoutTransparency(P2540_ui_SourcePixelIndex, P2541_ui_DestinationPixelIndex, 320);
                L3216_l_PixelCount -= 320;
                P2541_ui_DestinationPixelIndex += 320;
                P2540_ui_SourcePixelIndex += 320;
        }
        if (L3216_l_PixelCount > 0) { /* Copy pixels remaining on last line */
                F0680_CopyPixelsToScreenWithoutTransparency(P2540_ui_SourcePixelIndex, P2541_ui_DestinationPixelIndex, L3216_l_PixelCount);
        }
#endif
        ASM_STUB_SUFFIX
}

#ifdef MEDIA472_P20JB_P31J
FUNC_DEF void F8164_VIDRV_13_InitializeUnusedGlobalVariables(
char** P2543_pc_A,
char** P2544_pc_B)
{
        *P2543_pc_A = NULL;
        *P2544_pc_B = NULL;
}

FUNC_DEF long F8165_VIDRV_14_GetPrefixedBitmapByteCountOrBlitFromScreenNoTransparency(
int16_t* P2545_pi_, /* Pointer to a box followed by bitmap */
unsigned int16_t P2546_ui_X,
int16_t P2547_i_Y,
int16_t P2548_i_Width,
unsigned int16_t P2549_ui_Height,
int16_t P2550_i_Operation)
{
        int16_t* L2542_pi_Box = P2545_pi_;
        unsigned int16_t L3219_ui_;
        int16_t L3220_i_;
        long L2543_l_;
        int16_t L3223_i_Unreferenced;
        int16_t L3224_i_Unreferenced;


        ASM_STUB_PREFIX
        L3219_ui_ = (P2548_i_Width + (P2546_ui_X & 3) + 3) >> 2;
        if (P2550_i_Operation == 0) { /* GetPrefixedBitmapByteCount */
#if EXETYPE == C20_NEC8
                L2543_l_ = (char*)(((long)L3219_ui_ * 6 * P2549_ui_Height) + 6);
#endif
#if EXETYPE == C21_NEC16
                L2543_l_ = (char*)(((long)L3219_ui_ * 8 * P2549_ui_Height) + 6);
#endif
        } else {
                L3220_i_ = P2546_ui_X >> 2;
                L3220_i_ += P2547_i_Y * 160;
                *L2542_pi_Box = L3220_i_;
                *(L2542_pi_Box + 1) = L3219_ui_;
                *(L2542_pi_Box + 2) = P2549_ui_Height;
                P2545_pi_ += 3;
                asm     cld
                asm     mov     si, L3220_i_
                asm     les     di, P2545_pi_
                asm     mov     bx, L3219_ui_
                asm     mov     dx, P2549_ui_Height
                asm     shl     dx, 1
                asm     push    ds
                loc_12B64:
                asm     push    si
                asm     mov     ax, 0A800h      /* Bit plane 0 segment (Blue) */
                asm     mov     ds, ax
                asm     mov     cx, bx
                loc_12B6C:
                asm     rep movsb
                asm     or      cx, cx
                asm     jnz     loc_12B6C
                asm     pop     si
                asm     push    si
                asm     mov     ax, 0B000h      /* Bit plane 1 segment (Red) */
                asm     mov     ds, ax
                asm     mov     cx, bx
                loc_12B7B:
                asm     rep movsb
                asm     or      cx, cx
                asm     jnz     loc_12B7B
                asm     pop     si
                asm     push    si
                asm     mov     ax, 0B800h      /* Bit plane 2 segment (Green) */
                asm     mov     ds, ax
                asm     mov     cx, bx
                loc_12B8A:
                asm     rep movsb
                asm     or      cx, cx
                asm     jnz     loc_12B8A
                asm     pop     si
#if EXETYPE == C21_NEC16
                asm     push    si
                asm     mov     ax, 0E000h      /* Bit plane 3 segment (Intensity) */
                asm     mov     ds, ax
                asm     mov     cx, bx
                loc_12B99:
                asm     rep movsb
                asm     or      cx, cx
                asm     jnz     loc_12B99
                asm     pop     si
#endif
                asm     mov     ax, di
                asm     and     di, 0Fh
                asm     shr     ax, 1
                asm     shr     ax, 1
                asm     shr     ax, 1
                asm     shr     ax, 1
                asm     mov     cx, es
                asm     add     cx, ax
                asm     mov     es, cx
                asm     add     si, C80_BITPLANE_LINE_BYTE_COUNT
                asm     dec     dx
                asm     jnz     loc_12B64
                asm     pop     ds
        }
        ASM_STUB_SUFFIX
        return L2543_l_;
}

FUNC_DEF void F8166_VIDRV_15_BlitToScreenNoTransparency(
int16_t* P2551_pi_)
{
        int16_t* L2545_pi_ = P2551_pi_;
        int16_t L2548_i_;
        int16_t L2549_i_;
        int16_t L2546_i_;
        int16_t L3229_i_Unreferenced;
        int16_t L3230_i_Unreferenced;


        ASM_STUB_PREFIX
        L2546_i_ = *L2545_pi_;
        L2548_i_ = *(L2545_pi_ + 1);
        L2549_i_ = *(L2545_pi_ + 2);
        P2551_pi_ += 3;
        asm     cld
        asm     mov     bx, L2548_i_
        asm     mov     dx, L2549_i_
        asm     shl     dx, 1
        asm     mov     di, L2546_i_
        asm     push    ds
        asm     lds     si, P2551_pi_
        loc_12C0A:
        asm     push    di
        asm     mov     ax, 0A800h      /* Bit plane 0 segment (Blue) */
        asm     mov     es, ax
        asm     mov     cx, bx
        loc_12C12:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12C12
        asm     pop     di
        asm     push    di
        asm     mov     ax, 0B000h      /* Bit plane 1 segment (Red) */
        asm     mov     es, ax
        asm     mov     cx, bx
        loc_12C21:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12C21
        asm     pop     di
        asm     push    di
        asm     mov     ax, 0B800h      /* Bit plane 2 segment (Green) */
        asm     mov     es, ax
        asm     mov     cx, bx
        loc_12C30:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12C30
        asm     pop     di
#if EXETYPE == C21_NEC16
        asm     push    di
        asm     mov     ax, 0E000h      /* Bit plane 3 segment (Intensity) */
        asm     mov     es, ax
        asm     mov     cx, bx
        loc_12C3F:
        asm     rep movsb
        asm     or      cx, cx
        asm     jnz     loc_12C3F
        asm     pop     di
#endif
        asm     mov     ax, si
        asm     and     si, 0Fh
        asm     shr     ax, 1
        asm     shr     ax, 1
        asm     shr     ax, 1
        asm     shr     ax, 1
        asm     mov     cx, ds
        asm     add     cx, ax
        asm     mov     ds, cx
        asm     add     di, C80_BITPLANE_LINE_BYTE_COUNT
        asm     dec     dx
        asm     jnz     loc_12C0A
        asm     pop     ds
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8167_VIDRV_03_BlitMousePointerPrefixedBitmapFromScreen(
int16_t P3543_i_,
int16_t P3544_i_)
{
        unsigned int16_t L3231_ui_;
        unsigned int16_t L3232_ui_;


        ASM_STUB_PREFIX
        L3231_ui_ = 320 - P3543_i_;
        if (L3231_ui_ > 18) {
                L3231_ui_ = 18;
        }
        L3232_ui_ = 200 - P3544_i_;
        if (L3232_ui_ > 18) {
                L3232_ui_ = 18;
        }
        F8165_VIDRV_14_GetPrefixedBitmapByteCountOrBlitFromScreenNoTransparency(G8133_PrefixedBitmap, P3543_i_, P3544_i_, L3231_ui_, L3232_ui_, 1);
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8168_VIDRV_04_BlitMousePointerPrefixedBitmapToScreen(
)
{
#ifdef MEDIA667_P31J
        int16_t L3233_i_Unreferenced = 0;


#endif
        ASM_STUB_PREFIX
        F8166_VIDRV_15_BlitToScreenNoTransparency(G8133_PrefixedBitmap);
        ASM_STUB_SUFFIX
}

FUNC_DEF void F8422_LoadANKCharacterPatterns( /* Load 256 ANK character patterns into memory at 0A100h
Access to the ANK (Alphabetic, Numeric and Katakana characters) from the KCG (Kanji Character Generator) by the CPU is only possible during Vsync interrupts, otherwise the CRTC (CRT Controller) has exclusive access
This function adds a custom Vsync interrupt vector to copy one character pattern from ROM to memory during each of the next 256 Vsync cycles, then it disables itself.
Kanji are 16x16 pixels / bits = 32 bytes. ANK are half-width at 8x16 pixels / bits = 16 bytes
Port A1h: Less significant byte of the JIS character code
Port A3h: Most significant byte of the JIS character code
Port A5h: Select which part of the bit pattern to read/write using port A9h
Port A9h: Read/write 8 bits specified by A5h in the pattern of character selected with A1h and A3h */
)
{
        if (G8313_B_InterruptInstalled) {
                return;
        }
        F8399_ReplaceInterrupt10VectorVerticalBlank();
        G8313_B_InterruptInstalled = C1_TRUE;
        asm     jmp     loc_12CEE
        asm     V8422000_Counter       dw 0
        asm     V8422001_VerticalBlankInteruptVectorBackup       dd 0
        loc_12CEE:
        asm     mov     ax, 350Ah
        asm     int     21h             /* DOS - 2+ - GET INTERRUPT VECTOR */
                                        /* AL = interrupt number */
                                        /* Return: ES:BX = value of interrupt vector */
        asm     mov     word ptr cs:V8422001_VerticalBlankInteruptVectorBackup, bx
        asm     mov     word ptr cs:V8422001_VerticalBlankInteruptVectorBackup+2, es
        asm     push    ds
        asm     mov     dx, seg IntVector
        asm     mov     ds, dx
        asm     mov     dx, offset IntVector
        asm     mov     ax, 250Ah
        asm     int     21h             /* DOS - SET INTERRUPT VECTOR */
                                        /* AL = interrupt number */
                                        /* DS:DX = new vector to be used for specified interrupt */
        asm     pop     ds
        asm     jmp     loc_12D54
        asm     IntVector:
        asm     cmp     cs:V8422000_Counter, 100h
        asm     jz      loc_12D4F
        asm     push    ax
        asm     push    es
        asm     push    di
        asm     push    cx
        asm     cld
        asm     mov     ax, cs:V8422000_Counter
        asm     mov     di, ax
        asm     out     0A3h, al        /* Character code high byte (0..255) */
        asm     mov     al, 0
        asm     out     0A1h, al        /* Character code low byte (0) */
        asm     mov     ax, 0A100h      /* Target address (segment) in ES */
        asm     mov     es, ax
        asm     shl     di, 1
        asm     shl     di, 1
        asm     shl     di, 1
        asm     shl     di, 1           /* Target address (offset) in DI. 16 bytes for each ANK character */
        asm     mov     ah, 0           /* Part of the character pattern to read (0..15) */
        asm     mov     cx, 10h         /* Loop counter */
        loc_12D3B:
        asm     mov     al, ah
        asm     out     0A5h, al        /* Part of the character pattern to read */
        asm     in      al, 0A9h        /* Read one part of the character pattern */
        asm     stosb                   /* Store AL at address ES:DI */
        asm     inc     ah
        asm     loop    loc_12D3B       /* Decrease cx and loop if not 0 */
        asm     pop     cx
        asm     pop     di
        asm     pop     es
        asm     pop     ax
        asm     inc     cs:V8422000_Counter
        loc_12D4F:
        asm     jmp     cs:V8422001_VerticalBlankInteruptVectorBackup
        loc_12D54:
        asm     cmp     cs:V8422000_Counter, 100h
        asm     jnz     loc_12D54
        asm     push    ds
        asm     mov     dx, word ptr cs:V8422001_VerticalBlankInteruptVectorBackup+2
        asm     mov     ds, dx
        asm     mov     dx, word ptr cs:V8422001_VerticalBlankInteruptVectorBackup
        asm     mov     ax, 250Ah
        asm     int     21h             /* DOS - SET INTERRUPT VECTOR */
                                        /* AL = interrupt number */
                                        /* DS:DX = new vector to be used for specified interrupt */
        asm     pop     ds
        F8400_RestoreInterrupt10Vector();
}

FUNC_DEF int16_t F8170_Return0(
)
{
        return 0;
}

FUNC_DEF void F8171_ExecuteProgram(
char* P2554_pc_FileName,
char* P2555_pc_)
{
        asm     jmp     loc_12515
        asm     V8171000_ParamBlock     dw 0
        asm     V8171001_               dd 0
        asm                             dd V8171002_
        asm                             dd V8171002_
        asm     V8171002_               db 0, 0Bh dup(20h), 19h dup(0)
        asm     V8171003_               dd 0
        loc_12515:
        asm     les     ax, P2555_pc_
        asm     mov     word ptr cs:V8171001_, ax
        asm     mov     ax, es
        asm     mov     word ptr cs:V8171001_+2, ax
        asm     push    ds
        asm     mov     bx, offset V8171000_ParamBlock
        asm     mov     ax, cs
        asm     mov     es, ax
        asm     lds     dx, P2554_pc_FileName
        asm     mov     ax, 4B00h
        asm     mov     word ptr cs:V8171003_, sp
        asm     mov     word ptr cs:V8171003_+2, ss
        asm     cld
        asm     int     21h     /* DOS - 2+ - LOAD OR EXECUTE (EXEC) */
                                /* DS:DX -> ASCIZ filename */
                                /* ES:BX -> parameter block */
                                /* AL = subfunc: load & execute program */
        asm     mov     ss, word ptr cs:V8171003_+2
        asm     mov     sp, word ptr cs:V8171003_
        asm     pop     ds
}
#endif

FUNC_DEF void F8425_ClearAllVRAM(
)
{
#ifdef MEDIA472_P20JB_P31J
        asm     cld
#endif
        asm     mov     ax, 0A000h      /* Text area */
        asm     mov     es, ax
        asm     mov     di, 0
        asm     mov     cx, 8000h       /* 64K */
        asm     mov     al, 20h         /* Write space characters */
        loc_12DFC:
        asm     rep stosb
        asm     or      cx, cx
        asm     jnz     loc_12DFC
        asm     mov     ax, 0A800h      /* Bit plane 0 segment (Blue) */
        asm     mov     es, ax
        asm     mov     di, 0
        asm     mov     cx, 8000h       /* 64K */
        asm     mov     al, 0           /* Write 0 */
        loc_12E0F:
        asm     rep stosb
        asm     or      cx, cx
        asm     jnz     loc_12E0F
        asm     mov     ax, 0B000h      /* Bit plane 1 segment (Red) */
        asm     mov     es, ax
        asm     mov     di, 0
        asm     mov     cx, 8000h       /* 64K */
        asm     mov     al, 0           /* Write 0 */
        loc_12E22:
        asm     rep stosb
        asm     or      cx, cx
        asm     jnz     loc_12E22
        asm     mov     ax, 0B800h      /* Bit plane 2 segment (Green) */
        asm     mov     es, ax
        asm     mov     di, 0
        asm     mov     cx, 8000h       /* 64K */
        asm     mov     al, 0           /* Write 0 */
        loc_12E35:
        asm     rep stosb
        asm     or      cx, cx
        asm     jnz     loc_12E35
#ifdef MEDIA472_P20JB_P31J
#if EXETYPE == C21_NEC16
        asm     mov     ax, 0E000h      /* Bit plane 3 segment (Intensity) */
        asm     mov     es, ax
        asm     mov     di, 0
        asm     mov     cx, 8000h       /* 64K */
        asm     mov     al, 0           /* Write 0 */
        loc_12E48:
        asm     rep stosb
        asm     or      cx, cx
        asm     jnz     loc_12E48
#endif
#endif
}

#ifdef MEDIA457_P20JA
char* G8141_apc_VideoDriverVector[13] = {
#endif
#ifdef MEDIA472_P20JB_P31J
char* G8141_apc_VideoDriverVector[21] = {
#endif
        (char*)F8163_VIDRV_00_CopyPixelsToScreenWithoutTransparency,                              /*  0 */
        (char*)F8152_VIDRV_01_FillBox,                              /*  1 */
        (char*)F8151_VIDRV_02_Blit,                          /*  2 */
        (char*)F8167_VIDRV_03_BlitMousePointerPrefixedBitmapFromScreen,                              /*  3 */
        (char*)F8168_VIDRV_04_BlitMousePointerPrefixedBitmapToScreen,                              /*  4 */
        (char*)F8154_VIDRV_05_InvertBox,                              /*  5 */
        (char*)F8155_VIDRV_06_HatchScreenBox,                              /*  6 */
        (char*)F8153_VIDRV_07_WaitVerticalBlank,              /*  7 */
        (char*)F8157_VIDRV_08_SetMultipleColorsInPalette,    /*  8 */
        (char*)F8161_VIDRV_09_BlitViewPort,                  /*  9 */
        (char*)F8162_VIDRV_10_ScrollMessageAreaUp,                              /* 10 */
        (char*)F8159_VIDRV_11_PALETTE_SetCurtain,            /* 11 */
        (char*)F8160_VIDRV_12_SetCreatureReplacementColors   /* 12 */
#ifdef MEDIA472_P20JB_P31J
        ,
        (char*)F8164_VIDRV_13_InitializeUnusedGlobalVariables,                              /* 13 */
        (char*)F8165_VIDRV_14_GetPrefixedBitmapByteCountOrBlitFromScreenNoTransparency,                              /* 14 */
        (char*)F8166_VIDRV_15_BlitToScreenNoTransparency,                              /* 15 */
#if EXETYPE == C20_NEC8
        (char*)F8170_Return0,                               /* 16 */
        (char*)F8409_VIDRV_17_SetSingleColorInPalette1,      /* 17 */
#endif
#if EXETYPE == C21_NEC16
        (char*)F8230_VIDRV_16_SetSingleColorComponentsInPalette,      /* 16 */
        (char*)F8170_Return0,                               /* 17 */
#endif
        (char*)F8170_Return0,                               /* 18 */
        (char*)F8170_Return0,                               /* 19 */
        (char*)F8170_Return0                                /* 20 */
#endif
        };

FUNC_DEF void main(
int16_t argc,
char* argv[])
{
#ifdef MEDIA457_P20JA
        char L3234_ac_InitialColorPalette[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
#endif
#ifdef MEDIA472_P20JB_P31J
        unsigned char L2556_auc_ArgumentString[80] = "";
        unsigned char L2554_uc_ArgumentCharacter;
        int16_t L2555_i_CharacterIndex;
        int16_t L2558_i_ArgumentIndex;
#if EXETYPE == C21_NEC16
        char L3234_ac_InitialColorPalette[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
#endif
        int16_t L2557_i_ArgumentCharacterIndex;
#endif


        asm     mov     ax, ds
        asm     mov     cs:V0000000_DataSegment, ax   /* Backup DS of this program so that functions in this program can access the data segment when they are called via interrupt interface from the main program */
        asm     mov     ah, 40h     /* Display the graphics screen */
        asm     int     18h
        asm     mov     ah, 42h     /* Graphics mode */
        asm     mov     ch, 0C0h    /* Specify: Front screen, color, VRAM area = ALL. This sets resolution to 640x400 pixels */
        asm     int     18h
        asm     mov     ah, 12h     /* Hide cursor */
        asm     int     18h
#if EXETYPE == C21_NEC16
        asm     mov     al, 1
        asm     out     6Ah, al     /* Enable 16 color mode */
#endif
#ifdef MEDIA472_P20JB_P31J
        for (L2558_i_ArgumentIndex = 2, L2555_i_CharacterIndex = 1; L2558_i_ArgumentIndex < argc; L2558_i_ArgumentIndex++) { /* Prepare command line arguments */
                if (L2555_i_CharacterIndex > 1) {
                        L2556_auc_ArgumentString[L2555_i_CharacterIndex++] = ' ';
                }
                for (L2557_i_ArgumentCharacterIndex = 0; L2557_i_ArgumentCharacterIndex < 80; L2557_i_ArgumentCharacterIndex++) {
                        if ((L2554_uc_ArgumentCharacter = argv[L2558_i_ArgumentIndex][L2557_i_ArgumentCharacterIndex]) == '\0') {
                                break;
                        }
                        L2556_auc_ArgumentString[L2555_i_CharacterIndex++] = L2554_uc_ArgumentCharacter;
                }
                L2556_auc_ArgumentString[L2555_i_CharacterIndex] = '\r';
        }
        L2556_auc_ArgumentString[L2555_i_CharacterIndex] = '\r';
        L2556_auc_ArgumentString[0] = L2555_i_CharacterIndex - 1;
#endif
        F8425_ClearAllVRAM();
#ifdef MEDIA472_P20JB_P31J
        F8422_LoadANKCharacterPatterns();
        for (;;) { /*_Infinite loop_*/
#endif
                F8399_ReplaceInterrupt10VectorVerticalBlank();
#ifdef MEDIA457_P20JA
                F8382_PrepareV8382000FromPalette(L3234_ac_InitialColorPalette);
#endif
#ifdef MEDIA472_P20JB_P31J
#if EXETYPE == C20_NEC8
                F8157_VIDRV_08_SetMultipleColorsInPalette(C00_LIGHT0, NULL);
#endif
#if EXETYPE == C21_NEC16
                F8382_PrepareV8382000FromPalette(L3234_ac_InitialColorPalette);
#endif
#endif
                setvect(C255_DM_VIDEO_INTERRUPT, (void interrupt (*)())&G8141_apc_VideoDriverVector);
#ifdef MEDIA457_P20JA /* Run the next program with the first 4 arguments */
                spawnlp(P_WAIT, argv[1], argv[1], argv[2], argv[3], argv[4], NULL);
#endif
#ifdef MEDIA472_P20JB_P31J /* Run the next program with all arguments (up to 80 characters maximum) */
                F8171_ExecuteProgram(argv[1], L2556_auc_ArgumentString);
#endif
                F8400_RestoreInterrupt10Vector();
                F8425_ClearAllVRAM();
#ifdef MEDIA457_P20JA
                asm     mov     ah, 11h     /* Show cursor */
                asm     int     18h
#endif
#ifdef MEDIA472_P20JB_P31J
        }
#endif
        asm     jmp     loc_1311E
        asm     V0000000_DataSegment     dw 0
        loc_1311E: ;
}
#endif
