#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA712_I34E_I34M_F31E_F31J_P31J
unsigned char HUGE* G8210_puc_Bitmap;
unsigned char HUGE* G8206_;


FUNC_DEF void F8283_( /* Same as F0790_, both are present in F31E and F31J. Maybe static */
unsigned int16_t P2342_ui_,
char P2343_c_)
{
#ifdef MEDIA709_I34E_I34M_P31J
        asm     cld
        asm     les     di, G8210_puc_Bitmap
        asm     mov     bx, P2342_ui_
        asm     shr     bx, 1
        asm     jnb     loc_1021A
        asm     add     di, bx
        asm     mov     al, es:[di]
        asm     and     al, 0F0h
        asm     or      al, P2343_c_
        asm     stosb
        asm     jmp     loc_1022B
        loc_1021A:
        asm     add     di, bx
        asm     mov     ah, P2343_c_
        asm     mov     cl, 4
        asm     shl     ah, cl
        asm     mov     al, es:[di]
        asm     and     al, 0Fh
        asm     or      al, ah
        asm     stosb
        loc_1022B: ;
#endif
#ifdef MEDIA670_F31E_F31J
        int L6512_ = P2342_ui_ >> 1;


        if (P2342_ui_ & 1) {
                G8210_puc_Bitmap[L6512_] = (G8210_puc_Bitmap[L6512_] & 0x0F) | (P2343_c_ << 4);
        } else {
                G8210_puc_Bitmap[L6512_] = (G8210_puc_Bitmap[L6512_] & 0xF0) | (P2343_c_ & 0x0F);
        }
#endif
}

FUNC_DEF void F8284_(
unsigned int16_t P2344_ui_,
char P2345_c_Color,
unsigned int16_t P2346_i_) /* Similar but not same as F0685_IMG3_LineColorFilling. Maybe static */
{
#ifdef MEDIA709_I34E_I34M_P31J
        asm     cld
        asm     les     di, G8210_puc_Bitmap
        asm     mov     bx, P2344_ui_
        asm     mov     cx, P2346_i_
        asm     mov     ah, P2345_c_Color
        asm     shr     bx, 1
        asm     jb      loc_10CB0
        asm     add     di, bx
        asm     jmp     loc_10253
        loc_10CB0:
        asm     add     di, bx
        asm     mov     al, es:[di]
        asm     and     al, 0F0h
        asm     or      al, ah
        asm     stosb
        asm     dec     cx
        asm     jz      loc_1027B
        loc_10253:
        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_10269
        asm     stosb
        loc_10269:
        asm     rep stosw
        asm     or      cx, cx
        asm     jnz     loc_10269
        asm     popf
        asm     jnb     loc_1027B
        asm     mov     al, es:[di]
        asm     and     ax, 0F00Fh
        asm     or      al, ah
        asm     stosb
        loc_1027B: ;
#endif
#ifdef MEDIA670_F31E_F31J
        unsigned int16_t L6514_ = P2344_ui_ >> 1;
        char L6571_;


        if (P2344_ui_ & 1) {
                G8210_puc_Bitmap[L6514_] = (G8210_puc_Bitmap[L6514_] & 0x0F) | (P2345_c_Color << 4);
                L6514_++;
                P2346_i_--;
        }
        L6571_ = (P2345_c_Color << 4) | P2345_c_Color;
        while (P2346_i_ > 1) {
                G8210_puc_Bitmap[L6514_++] = L6571_;
                P2346_i_ -= 2;
        }
        if (P2346_i_)
                G8210_puc_Bitmap[L6514_] = (G8210_puc_Bitmap[L6514_] & 0xF0) | (L6571_ & 0x0F);
#endif
}

#ifdef MEDIA709_I34E_I34M_P31J
#include "IMAGE5.C"
#endif

#ifdef MEDIA670_F31E_F31J
FUNC_DEF static void F1003_(
unsigned int16_t P2494_i_SourcePixelIndex,
int16_t P2495_i_DestinationPixelIndex,
int16_t P2496_i_PixelCount)
{
                while (P2496_i_PixelCount-- > 0) {
                        if (P2494_i_SourcePixelIndex & 1) {
                                F8283_(P2495_i_DestinationPixelIndex++, G8206_[P2494_i_SourcePixelIndex >> 1] & 0x0F);
                        } else {
                                F8283_(P2495_i_DestinationPixelIndex++, G8206_[P2494_i_SourcePixelIndex >> 1] >> 4);
                        }
                        P2494_i_SourcePixelIndex++;
                }
}
#endif

FUNC_DEF void F8286_( /* Same as F0686_IMG_CopyFromPreviousLine. Maybe static */
unsigned int16_t P2350_ui_,
unsigned int16_t P2351_ui_,
int16_t P2352_i_)
{
#ifdef MEDIA709_I34E_I34M_P31J
        asm     cld
        asm     les     di, G8210_puc_Bitmap
        asm     mov     si, di
        asm     mov     bx, P2350_ui_
        asm     mov     dx, P2351_ui_
        asm     mov     cx, P2352_i_
        asm     shr     dx, 1
        asm     shr     bx, 1
        asm     pushf
        asm     add     di, bx
        asm     add     si, dx
        asm     popf
        asm     jnb     loc_10373
        asm     mov     dl, es:[di]
        asm     lods    byte ptr es:[si]
        asm     and     dl, 0F0h
        asm     and     al, 0Fh
        asm     or      al, dl
        asm     stosb
        asm     dec     cx
        asm     jz      loc_10388
        loc_10373:
        asm     inc     cx
        asm     shr     cx, 1
        asm     shr     cx, 1
        asm     jnb     loc_1037C
        asm     movs    byte ptr es:[di], byte ptr es:[si]
        loc_1037C:
        asm     push    ds
        asm     mov     ax, es
        asm     mov     ds, ax
        loc_10381:
        asm     rep movsw
        asm     or      cx, cx
        asm     jnz     loc_10381
        asm     pop     ds
        loc_10388: ;
#endif
#ifdef MEDIA670_F31E_F31J
        unsigned int16_t L6516_ = P2350_ui_ >> 1;
        unsigned int16_t L6515_ = P2351_ui_ >> 1;


        if (P2350_ui_ & 1) {
                G8210_puc_Bitmap[L6516_] = (G8210_puc_Bitmap[L6516_] & 0x0F) | (G8210_puc_Bitmap[L6515_] & 0xF0);
                L6516_++;
                L6515_++;
                P2352_i_--;
        }
        while (P2352_i_ > 1) {
                G8210_puc_Bitmap[L6516_++] = G8210_puc_Bitmap[L6515_++];
                P2352_i_ -= 2;
        }
        if (P2352_i_ > 0)
                G8210_puc_Bitmap[L6516_] = (G8210_puc_Bitmap[L6516_] & 0xF0) | (G8210_puc_Bitmap[L6515_] & 0x0F);
#endif
}

FUNC_DEF void F0690_CopyPixelLineToScreenWithoutTransparency(
unsigned int16_t P2355_ui_DestinationPixelIndex,
unsigned int16_t P2356_ui_PixelCount)
{
#ifdef MEDIA709_I34E_I34M_P31J
        (*(G2156_VideoDriver->VIDRV_00_CopyPixelsToScreenWithoutTransparency))(G8210_puc_Bitmap, P2355_ui_DestinationPixelIndex, P2355_ui_DestinationPixelIndex, P2356_ui_PixelCount);
#endif
#ifdef MEDIA670_F31E_F31J
        int L6569_;


        L6569_ = ((P2355_ui_DestinationPixelIndex / 320) << 10) + (P2355_ui_DestinationPixelIndex % 320);
        F2276_(L6569_, P2356_ui_PixelCount, G8210_puc_Bitmap + (P2355_ui_DestinationPixelIndex >> 1));
#endif
}

FUNC_DEF void F8288_(
unsigned char HUGE* P2454_puc_BitmapA,
unsigned char HUGE* P2455_puc_BitmapB)
{
        int16_t L2105_i_;
        int16_t L2106_i_;
        unsigned int16_t L2107_ui_;
        unsigned int16_t L2108_ui_;
        unsigned char L2109_uc_;
        unsigned int16_t L2110_ui_;
        unsigned int16_t L2112_ui_;
        unsigned int16_t L2111_ui_;


        G8206_ = P2454_puc_BitmapA;
        G8210_puc_Bitmap = P2455_puc_BitmapB;
        L2105_i_ = *(G8206_ + 1) | (*(G8206_) << 8);
        L2106_i_ = *(G8206_ + 3) | (*(G8206_ + 2) << 8);
        G8206_ += 4;
        L2107_ui_ = M104_EVEN_INTEGER(L2105_i_);
        L2108_ui_ = L2107_ui_ * L2106_i_;
        L2110_ui_ = L2112_ui_ = 0;
        do {
                if (((L2109_uc_ = *G8206_++) & 0x80) == 0) {
                        L2111_ui_ = (L2109_uc_ >> 4) + 1;
                        F8284_(L2112_ui_, L2109_uc_ & 0x0F, L2111_ui_);
                        L2112_ui_ += L2111_ui_;
                } else {
                        switch (L2109_uc_ & 0x30) {
                                case 0x00:
                                        if ((L2109_uc_ & 0x40) == 0) {
                                                L2111_ui_ = *G8206_++ + 1;
                                        } else {
                                                L2111_ui_ = (*(G8206_ + 1) | (*G8206_ << 8)) + 1;
                                                G8206_ += 2;
                                        }
                                        F8284_(L2112_ui_, L2109_uc_ & 0x0F, L2111_ui_);
                                        L2112_ui_ += L2111_ui_;
                                        break;
                                case 0x10:
                                        if ((L2109_uc_ & 0x40) == 0) {
                                                L2111_ui_ = *G8206_++ + 1;
                                        } else {
                                                L2111_ui_ = (*(G8206_ + 1) | (*G8206_ << 8)) + 1;
                                                G8206_ += 2;
                                        }
                                        if (L2111_ui_ & 1) {
                                                F8283_(L2112_ui_, L2109_uc_ & 0x0F);
                                                L2112_ui_++;
                                                L2111_ui_--;
                                        }
#ifdef MEDIA709_I34E_I34M_P31J
                                        F0680_CopyPixelsToScreenWithoutTransparency(0, L2112_ui_, L2111_ui_);
#endif
#ifdef MEDIA670_F31E_F31J
                                        F1003_(0, L2112_ui_, L2111_ui_);
#endif
                                        G8206_ += L2111_ui_ >> 1;
                                        L2112_ui_ += L2111_ui_;
                                        break;
                                case 0x20:
#ifdef MEDIA709_I34E_I34M_P31J
                                        if (L2110_ui_ < L2112_ui_) {
                                                F0690_CopyPixelLineToScreenWithoutTransparency(L2110_ui_, L2112_ui_ - L2110_ui_);
                                        }
#endif
                                        L2111_ui_ = (L2109_uc_ & 0x0F) | ((L2109_uc_ >> 2) & 0x10);
                                        if (L2111_ui_ == 29) {
                                                L2111_ui_ = *G8206_++ + 1;
                                        } else {
                                                if (L2111_ui_ == 30) {
                                                        L2111_ui_ = *G8206_++ + 257;
                                                } else {
                                                        if (L2111_ui_ == 31) {
                                                                L2111_ui_ = (*(G8206_ + 1) | (*G8206_ << 8)) + 1;
                                                                G8206_ += 2;
                                                        } else {
                                                                L2111_ui_++;
                                                        }
                                                }
                                        }
                                        L2112_ui_ += L2111_ui_;
                                        L2110_ui_ = L2112_ui_;
                                        break;
                                case 0x30:
                                        if ((L2109_uc_ & 0x40) == 0) {
                                                L2111_ui_ = *G8206_++ + 1;
                                        } else {
                                                L2111_ui_ = (*(G8206_ + 1) | (*G8206_ << 8)) + 1;
                                                G8206_ += 2;
                                        }
                                        F8286_(L2112_ui_, L2112_ui_ - L2107_ui_, L2111_ui_);
                                        L2112_ui_ += L2111_ui_;
                                        F8283_(L2112_ui_++, L2109_uc_ & 0x0F);
                        }
                }
        } while (L2112_ui_ < L2108_ui_);
#ifdef MEDIA709_I34E_I34M_P31J
        if (L2110_ui_ < L2112_ui_) {
                F0690_CopyPixelLineToScreenWithoutTransparency(L2110_ui_, L2112_ui_ - L2110_ui_);
        }
#endif
}
#endif
