#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA634_A31E_A31M_X31J
#ifdef MEDIA692_X31J
#undef F0466_EXPAND_GraphicToBitmap
#undef F0129_VIDEO_BlitShrinkWithPaletteChanges
#undef F0130_VIDEO_FlipHorizontal
#undef F0131_VIDEO_FlipVertical
#endif

extern FTL_LIBRARY* F9008_OpenPRIM();
extern FTL_LIBRARY* F9006_OpenMEM1();

extern void F9086_GRF1_06_Blit();
extern BOOLEAN F9093_AllocateWorkingMemory();
extern unsigned char* MEM1_06_Allocate();
extern void F9094_FreeWorkingMemory();

#ifdef MEDIA619_A31E_A31M
#include "BLTSHRNK.C"
#endif
#include "EXPAND.C"

#ifdef MEDIA619_A31E_A31M
struct RastPort G3262_s_RastPort;
struct BitMap G3263_s_BitMap;
BOOLEAN G3208_B_ = C1_TRUE;
char G3209_[4] = { 0xAA, 0xAA, 0x55, 0x55 };
#endif
#ifdef MEDIA692_X31J
unsigned char G3098_[16] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
unsigned char* G3084_puc_X68000_4096bytes;
unsigned char* G3083_puc_X68000_256bytes;
#endif


#ifdef MEDIA619_A31E_A31M
void F1129_(
register PLANEPTR P2818_,
unsigned int16_t P2819_ui_ColorIndex,
register int16_t P2820_i_Width,
register int16_t P2821_i_Height)
{
        register unsigned int16_t L3396_ui_;


        L3396_ui_ = RASSIZE(P2820_i_Width, P2821_i_Height);
        InitBitMap(&G3263_s_BitMap, 4L, (long)P2820_i_Width, (long)P2821_i_Height);
        if (G3208_B_) {
                InitRastPort(&G3262_s_RastPort);
                G3262_s_RastPort.BitMap = &G3263_s_BitMap;
                G3208_B_ = C0_FALSE;
        }
        G3263_s_BitMap.Planes[0] = P2818_;
        G3263_s_BitMap.Planes[1] = P2818_ + L3396_ui_;
        G3263_s_BitMap.Planes[2] = P2818_ + L3396_ui_ * 2;
        G3263_s_BitMap.Planes[3] = P2818_ + L3396_ui_ * 3;
        SetAPen(&G3262_s_RastPort, (long)P2819_ui_ColorIndex);
}
#endif

void F9077_GRF1_08_FillBox(
#ifdef MEDIA619_A31E_A31M
PLANEPTR P4214_,
register int16_t* P4213_pi_XYZ,
#endif
#ifdef MEDIA692_X31J
unsigned char* P4214_,
int16_t* P4213_pi_XYZ,
#endif
char P4215_c_ColorIndex,
#ifdef MEDIA619_A31E_A31M
int16_t P4216_i_Width,
int16_t P4217_i_Height)
#endif
#ifdef MEDIA692_X31J
int16_t P4216_i_Width)
#endif
{
        ASM_STUB_PREFIX
#ifdef MEDIA619_A31E_A31M
        if ((P4213_pi_XYZ != NULL) && (P4214_ != NULL)) {
                F1129_(P4214_, P4215_c_ColorIndex, P4216_i_Width, P4217_i_Height);
                SetDrMd(&G3262_s_RastPort, JAM1);
                RectFill(&G3262_s_RastPort, (long)M704_ZONE_LEFT(P4213_pi_XYZ), (long)M706_ZONE_TOP(P4213_pi_XYZ), (long)(P4213_pi_XYZ[0] + P4213_pi_XYZ[2]) - 1, (long)(P4213_pi_XYZ[1] + P4213_pi_XYZ[3]) - 1);
                /* (long)M705_ZONE_RIGHT(P4213_pi_XYZ), (long)M707_ZONE_BOTTOM(P4213_pi_XYZ)); */
                WaitBlit();
        }
#endif
#ifdef MEDIA692_X31J
        asm {
                        movem.l d3-d7,-(sp)
                        move.l  P4213_pi_XYZ(a6),d0
                        beq.w   @Tloc_7DA
                        movea.l d0,a0
                        movem.w (a0)+,d3-d6
                        subq.w  #1,d5
                        bmi.s   @Tloc_7DA
                        subq.w  #1,d6
                        bmi.s   @Tloc_7DA
                        lea     G3098_(a5),a0
                        moveq   #0,d1
                        move.b  P4215_c_ColorIndex(a6),d1
                        adda.w  d1,a0
                        move.b  (a0),d2
                        movea.l P4214_(a6),a1
                        move.w  P4216_i_Width(a6),d1
                        addq.w  #1,d1
                        lsr.w   #1,d1
                        mulu.w  d1,d4
                        adda.l  d4,a1
                        move.w  d5,d7
                        lsr.w   #1,d3
                        adda.w  d3,a1
                        bcc.s   @Tloc_798
                        lea     @Tloc_7B8,a0
                        addq.w  #3,d7
                        moveq   #0xF,d4
                        and.b   d2,d4
                        bra.s   @Tloc_7A8
                @Tloc_798:
                        tst.w   d7
                        bne.s   @Tloc_7A2
                        lea     @Tloc_7CC,a0
                        bra.s   @Tloc_7A6
                @Tloc_7A2:
                        lea     @Tloc_7C4,a0
                @Tloc_7A6:
                        addq.w  #2,d7
                @Tloc_7A8:
                        lsr.w   #1,d7
                        bcs.s   @Tloc_7B2
                        moveq   #0xFFFFFFF0,d3
                        and.b   d2,d3
                        moveq   #0xF,d0
                @Tloc_7B2:
                        sub.w   d7,d1
                        move.w  d5,d7
                        jmp     (a0)
                @Tloc_7B8:
                        andi.b  #0xF0,(a1)
                        or.b    d4,(a1)+
                        subq.w  #1,d7
                        beq.s   @Tloc_7CC
                        bcs.s   @Tloc_7D0
                @Tloc_7C4:
                        move.b  d2,(a1)+
                        subq.w  #2,d7
                        bhi.s   @Tloc_7C4
                        bcs.s   @Tloc_7D0
                @Tloc_7CC:
                        and.b   d0,(a1)
                        or.b    d3,(a1)+
                @Tloc_7D0:
                        subq.w  #1,d6
                        bcs.s   @Tloc_7DA
                        move.w  d5,d7
                        adda.w  d1,a1
                        jmp     (a0)
                @Tloc_7DA:
                        movem.l (sp)+,d3-d7
        }
#endif
        ASM_STUB_SUFFIX
}

void F1032_GRF1_12_HatchBox(
unsigned char* P2760_puc_Bitmap,
#ifdef MEDIA619_A31E_A31M
register int16_t* P2761_pi_XYZ,
#endif
#ifdef MEDIA692_X31J
int16_t* P2761_pi_XYZ,
#endif
char P2762_c_,
int16_t P2780_,
int16_t P2822_) /* Similar to F1032_GRF1_12_HatchBox */
{
        ASM_STUB_PREFIX
#ifdef MEDIA619_A31E_A31M
        if ((P2761_pi_XYZ != NULL) && (P2760_puc_Bitmap != NULL)) {
                F1129_(P2760_puc_Bitmap, P2762_c_, P2780_, P2822_);
                G3262_s_RastPort.AreaPtrn = G3209_;
                G3262_s_RastPort.AreaPtSz = 1;
                SetDrMd(&G3262_s_RastPort, JAM1);
                RectFill(&G3262_s_RastPort, (long)M704_ZONE_LEFT(P2761_pi_XYZ), (long)M706_ZONE_TOP(P2761_pi_XYZ), (long)(P2761_pi_XYZ[0] + P2761_pi_XYZ[2]) - 1, (long)(P2761_pi_XYZ[1] + P2761_pi_XYZ[3]) - 1);
                /* (long)M705_ZONE_RIGHT(P2761_pi_XYZ), (long)M707_ZONE_BOTTOM(P2761_pi_XYZ)); */
                G3262_s_RastPort.AreaPtrn = NULL;
                G3262_s_RastPort.AreaPtSz = 0;
                WaitBlit();
        }
#endif
        ASM_STUB_SUFFIX
}

void F9079_GRF1_13_InvertBox(
char* P4218_,
int16_t* P4219_pi_XYZ,
int16_t P4220_i_Width,
int16_t P4221_i_Height)
{
#ifdef MEDIA692_X31J
        long L6016_l_SupervisorStack;
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA619_A31E_A31M
        if ((P4219_pi_XYZ != NULL) && (P4218_ != NULL)) {
                F1129_(P4218_, CM1_COLOR_NO_TRANSPARENCY, P4220_i_Width, P4221_i_Height);
                SetDrMd(&G3262_s_RastPort, COMPLEMENT);
                G3262_s_RastPort.Mask = 0x0F;
                RectFill(&G3262_s_RastPort, (long)M704_ZONE_LEFT(P4219_pi_XYZ), (long)M706_ZONE_TOP(P4219_pi_XYZ), (long)(P4219_pi_XYZ[0] + P4219_pi_XYZ[2]) - 1, (long)(P4219_pi_XYZ[1] + P4219_pi_XYZ[3]) - 1);
                /* (long)M705_ZONE_RIGHT(P4219_pi_XYZ), (long)M707_ZONE_BOTTOM(P4219_pi_XYZ)); */
                WaitBlit();
        }
#endif
        ASM_STUB_SUFFIX
}

#ifdef MEDIA619_A31E_A31M
#include "FLIPHORI.C"
#include "CONVBOXC.C"
#include "BLITMASK.C"
#include "BLITAMIG.C"
#endif

void F9086_GRF1_06_Blit(
#ifdef MEDIA619_A31E_A31M
register unsigned int16_t* P4196_pui_Bitmap_Source,
register unsigned int16_t* P4197_pui_Bitmap_Destination,
#endif
#ifdef MEDIA692_X31J
unsigned int16_t* P4196_pui_Bitmap_Source,
unsigned int16_t* P4197_pui_Bitmap_Destination,
#endif
int16_t* P4198_pi_XYZ,
int16_t P4199_i_X,
int16_t P4200_i_Y,
int16_t P4201_i_SourceByteWidth,
int16_t P4202_i_DestinationByteWidth,
#ifdef MEDIA619_A31E_A31M
char P4203_c_TransparentColor,
int16_t P4204_i_SourceHeight,
int16_t P4205_i_DestinationHeight)
#endif
#ifdef MEDIA692_X31J
char P4203_c_TransparentColor)
#endif
{
#ifdef MEDIA619_A31E_A31M
        int16_t L4693_ai_XYZ[4];
#endif


        ASM_STUB_PREFIX
#ifdef MEDIA619_A31E_A31M
        if ((P4198_pi_XYZ != NULL) && (P4197_pui_Bitmap_Destination != NULL)) {
                F1132_ConvertBoxCoordinates(P4198_pi_XYZ, L4693_ai_XYZ);
                F1013_Blit_Amiga(P4196_pui_Bitmap_Source, P4197_pui_Bitmap_Destination, L4693_ai_XYZ, P4199_i_X, P4200_i_Y, P4201_i_SourceByteWidth, P4202_i_DestinationByteWidth, P4203_c_TransparentColor, P4204_i_SourceHeight, P4205_i_DestinationHeight);
        }
#endif
#ifdef MEDIA692_X31J
        if (P4196_pui_Bitmap_Source) {
                asm {
                                movem.l d3-d7/a2-a5,-(sp)
                                move.l  P4198_pi_XYZ(a6),d0
                                beq.w   @Tloc_AAE
                                movea.l d0,a2
                                movea.l P4196_pui_Bitmap_Source(a6),a0
                                move.w  P4201_i_SourceByteWidth(a6),d1
                                addq.w  #1,d1
                                lsr.w   #1,d1
                                movea.w d1,a3
                                movea.l P4197_pui_Bitmap_Destination(a6),a1
                                move.w  P4202_i_DestinationByteWidth(a6),d7
                                addq.w  #1,d7
                                lsr.w   #1,d7
                                movea.w d7,a4
                                move.w  P4199_i_X(a6),d4
                                move.w  P4200_i_Y(a6),d3
                                moveq   #0,d5
                                moveq   #0,d6
                                mulu.w  d1,d3
                                adda.l  d3,a0
                                lsr.w   #1,d4
                                adda.w  d4,a0
                                addx.b  d5,d5
                                moveq   #0,d1
                                moveq   #0,d2
                                moveq   #0,d3
                                moveq   #0,d4
                                move.w  (a2)+,d4
                                move.w  (a2)+,d3
                                move.w  (a2)+,d2
                                add.w   d4,d2
                                subq.w  #1,d2
                                btst    d1,d2
                                bne.s   @Tloc_872
                                move.b  #0xF0,d6
                                bra.s   @Tloc_876
                        @Tloc_872:
                                move.b  #0xFF,d6
                        @Tloc_876:
                                sub.w   d4,d2
                                move.w  d2,d0
                                lsr.w   #1,d2
                                move.w  (a2)+,d1
                                subq.w  #1,d1
                                swap    d6
                                mulu.w  d7,d3
                                adda.l  d3,a1
                                lsr.w   #1,d4
                                adda.w  d4,a1
                                addx.b  d6,d6
                                swap    d5
                                tst.w   d6
                                beq.s   @Tloc_898
                                move.b  #0xF,d5
                                bra.s   @Tloc_89C
                        @Tloc_898:
                                move.b  #0xFF,d5
                        @Tloc_89C:
                                swap    d6
                                move.b  d6,d4
                                and.b   d5,d4
                                beq.s   @Tloc_8A6
                                subq.w  #1,d2
                        @Tloc_8A6:
                                suba.w  d2,a3
                                subq.w  #1,a3
                                suba.w  d2,a4
                                subq.w  #1,a4
                                tst.w   d2
                                bpl.s   @Tloc_8BC
                                tst.w   d0
                                bne.s   @Tloc_8BA
                                and.b   d5,d6
                                bra.s   @Tloc_8BC
                        @Tloc_8BA:
                                or.b    d5,d6
                        @Tloc_8BC:
                                moveq   #0,d0
                                move.b  P4203_c_TransparentColor(a6),d0
                                bmi.s   @Tloc_8D0
                                moveq   #8,d4
                                move.w  d0,d3
                                asl.w   d4,d3
                                movea.l G3084_puc_X68000_4096bytes(a5),a2
                                adda.w  d3,a2
                        @Tloc_8D0:
                                swap    d6
                                swap    d5
                                eor.w   d5,d6
                                bne.w   @Tloc_97A
                                swap    d6
                                swap    d5
                                tst.b   d0
                                bpl.s   @Tloc_92A
                        @Tloc_8E2:
                                move.w  d2,d3
                                bmi.s   @Tloc_912
                                move.b  (a0)+,d0
                                move.b  (a1),d4
                                eor.b   d4,d0
                                and.b   d5,d0
                                eor.b   d4,d0
                                move.b  d0,(a1)+
                                subq.w  #1,d3
                                bmi.s   @Tloc_912
                                move.w  a0,d0
                                move.w  a1,d7
                                or.w    d0,d7
                                andi.w  #1,d7
                                bne.s   @Tloc_90C
                                bra.s   @Tloc_906
                        @Tloc_904:
                                move.l  (a0)+,(a1)+
                        @Tloc_906:
                                subq.w  #4,d3
                        @Tloc_908:
                                bge.s   @Tloc_904
                                addq.w  #4,d3
                        @Tloc_90C:
                                move.b  (a0)+,(a1)+
                                dbf     d3,@Tloc_90C
                        @Tloc_912:
                                move.b  (a0),d0
                                move.b  (a1),d4
                                eor.b   d4,d0
                                and.b   d6,d0
                                eor.b   d4,d0
                                move.b  d0,(a1)
                                adda.l  a3,a0
                                adda.l  a4,a1
                                dbf     d1,@Tloc_8E2
                                bra.w   @Tloc_AAE
                        @Tloc_92A:
                                swap    d1
                                move.w  d2,d3
                                bmi.s   @Tloc_95A
                                move.b  (a0)+,d0
                                move.b  (a2,d0.w),d1
                                move.b  (a1),d4
                                eor.b   d4,d0
                                and.b   d1,d0
                                and.b   d5,d0
                                eor.b   d4,d0
                                move.b  d0,(a1)+
                                subq.w  #1,d3
                                bmi.s   @Tloc_95A
                        @Tloc_946:
                                move.b  (a0)+,d0
                                move.b  (a2,d0.w),d1
                                move.b  (a1),d4
                                eor.b   d4,d0
                                and.b   d1,d0
                                eor.b   d4,d0
                                move.b  d0,(a1)+
                                dbf     d3,@Tloc_946
                        @Tloc_95A:
                                move.b  (a0),d0
                                move.b  (a2,d0.w),d1
                                move.b  (a1),d4
                                eor.b   d4,d0
                                and.b   d1,d0
                                and.b   d6,d0
                                eor.b   d4,d0
                                move.b  d0,(a1)
                                adda.l  a3,a0
                                adda.l  a4,a1
                                swap    d1
                                dbf     d1,@Tloc_92A
                                bra.w   @Tloc_AAE
                        @Tloc_97A:
                                move.l  a6,-(sp)
                                movea.l G3083_puc_X68000_256bytes(a5),a5
                                move.b  #0xF,d6
                                moveq   #0,d7
                                tst.b   d0
                                bpl.w   @Tloc_A10
                                moveq   #0,d0
                                tst.w   d5
                                bne.s   @Tloc_998
                                lea     @Tloc_9AE,a6
                                bra.s   @Tloc_99E
                        @Tloc_998:
                                lea     @Tloc_9A4,a6
                                subq.l  #1,a3
                        @Tloc_99E:
                                move.b  #0xF0,d5
                        @Tloc_9A2:
                                jmp     (a6)
                        @Tloc_9A4:
                                move.b  (a0)+,d7
                                move.b  (a5,d7.w),d7
                                and.b   d5,d7
                                swap    d7
                        @Tloc_9AE:
                                move.w  d2,d3
                                bmi.s   @Tloc_9EA
                                move.b  (a0)+,d0
                                move.b  (a5,d0.w),d0
                                move.b  d0,d7
                                and.b   d5,d7
                                and.b   d6,d0
                                swap    d7
                                or.b    d7,d0
                                move.b  (a1),d4
                                eor.b   d4,d0
                                swap    d5
                                and.b   d5,d0
                                swap    d5
                                eor.b   d4,d0
                                move.b  d0,(a1)+
                                subq.w  #1,d3
                                bmi.s   @Tloc_9EA
                        @Tloc_9D4:
                                move.b  (a0)+,d0
                                move.b  (a5,d0.w),d0
                                move.b  d0,d7
                                and.b   d5,d7
                                and.b   d6,d0
                                swap    d7
                                or.b    d7,d0
                                move.b  d0,(a1)+
                                dbf     d3,@Tloc_9D4
                        @Tloc_9EA:
                                move.b  (a0),d0
                                move.b  (a5,d0.w),d0
                                and.b   d6,d0
                                swap    d7
                                or.b    d7,d0
                                move.b  (a1),d4
                                eor.b   d4,d0
                                swap    d6
                                and.b   d6,d0
                                swap    d6
                                eor.b   d4,d0
                                move.b  d0,(a1)
                                adda.l  a3,a0
                                adda.l  a4,a1
                                dbf     d1,@Tloc_9A2
                                bra.w   @Tloc_AAC
                        @Tloc_A10:
                                moveq   #0,d0
                                tst.w   d5
                                bne.s   @Tloc_A1C
                                lea     @Tloc_A34,a6
                                bra.s   @Tloc_A22
                        @Tloc_A1C:
                                lea     @Tloc_A2A,a6
                                subq.l  #1,a3
                        @Tloc_A22:
                                move.b  #0xF0,d5
                        @Tloc_A26:
                                swap    d1
                                jmp     (a6)
                        @Tloc_A2A:
                                move.b  (a0)+,d7
                                move.b  (a5,d7.w),d7
                                and.b   d5,d7
                                swap    d7
                        @Tloc_A34:
                                move.w  d2,d3
                                bmi.s   @Tloc_A82
                                move.b  (a0)+,d0
                                move.b  (a5,d0.w),d0
                                move.b  d0,d7
                                and.b   d5,d7
                                and.b   d6,d0
                                swap    d7
                                or.b    d7,d0
                                move.b  (a2,d0.w),d1
                                move.b  (a1),d4
                                eor.b   d4,d0
                                swap    d5
                                and.b   d5,d0
                                swap    d5
                                and.b   d1,d0
                                eor.b   d4,d0
                                move.b  d0,(a1)+
                                subq.w  #1,d3
                                bmi.s   @Tloc_A82
                        @Tloc_A60:
                                move.b  (a0)+,d0
                                move.b  (a5,d0.w),d0
                                move.b  d0,d7
                                and.b   d5,d7
                                and.b   d6,d0
                                swap    d7
                                or.b    d7,d0
                                move.b  (a2,d0.w),d1
                                move.b  (a1),d4
                                eor.b   d4,d0
                                and.b   d1,d0
                                eor.b   d4,d0
                                move.b  d0,(a1)+
                                dbf     d3,@Tloc_A60
                        @Tloc_A82:
                                move.b  (a0),d0
                                move.b  (a5,d0.w),d0
                                and.b   d6,d0
                                swap    d7
                                or.b    d7,d0
                                move.b  (a2,d0.w),d1
                                move.b  (a1),d4
                                eor.b   d4,d0
                                swap    d6
                                and.b   d6,d0
                                swap    d6
                                and.b   d1,d0
                                eor.b   d4,d0
                                move.b  d0,(a1)
                                adda.l  a3,a0
                                adda.l  a4,a1
                                swap    d1
                                dbf     d1,@Tloc_A26
                        @Tloc_AAC:
                                movea.l (sp)+,a6
                        @Tloc_AAE:
                                movem.l (sp)+,d3-d7/a2-a5
                }
        }
#endif
        ASM_STUB_SUFFIX
}

void F9087_GRF1_07_Empty(
int16_t P4206_)
{
        ASM_STUB_PREFIX
        ASM_STUB_SUFFIX
}

#ifdef MEDIA692_X31J
#include "FLIPHORI.C"
#endif
#include "FLIPVERT.C"
#ifdef MEDIA692_X31J
#include "BLTSHRNK.C"
#include "BLITMASK.C"
#endif

unsigned long F9089_GRF1_04_GetBitmapMemorySize(
int16_t P4208_i_Width,
int16_t P4209_i_Height)
{
        ASM_STUB_PREFIX
        ASM_STUB_SUFFIX /* BUGX_XX Suffix should be placed below next line of code. No consequence as no global variable is accessed */
#ifdef MEDIA619_A31E_A31M
        return (unsigned long)((int16_t)((P4208_i_Width + 15) & 0xFFF0) >> 1) * P4209_i_Height;
#endif
#ifdef MEDIA692_X31J
        return M103_BITMAP_BYTE_COUNT(P4208_i_Width, P4209_i_Height);
#endif
}

#ifdef MEDIA619_A31E_A31M
unsigned int16_t* G3249_pui_BlitterTemporaryBitplane;
#endif
FTL_LIBRARY* G9017_MEM1_Library;

void F9090_GRF1_15_GetBlitterTemporaryBitplane(
#ifdef MEDIA619_A31E_A31M
unsigned int16_t** P4207_ppui_BlitterTemporaryBitplane)
#endif
#ifdef MEDIA692_X31J
unsigned char** P4207_ppui_BlitterTemporaryBitplane)
#endif
{
        ASM_STUB_PREFIX
#ifdef MEDIA619_A31E_A31M
        *P4207_ppui_BlitterTemporaryBitplane = G3249_pui_BlitterTemporaryBitplane;
#endif
#ifdef MEDIA692_X31J
        P4207_ppui_BlitterTemporaryBitplane[0] = G3084_puc_X68000_4096bytes;
        P4207_ppui_BlitterTemporaryBitplane[1] = G3083_puc_X68000_256bytes;
#endif
        ASM_STUB_SUFFIX
}

GRF1_FTL_LIBRARY* F9091_(
long P2855_,
#ifdef MEDIA619_A31E_A31M
GRF1_FTL_LIBRARY* P2856_)
#endif
#ifdef MEDIA692_X31J
register GRF1_FTL_LIBRARY* P2856_)
#endif
{
        if (F9008_OpenPRIM(P2855_, 4) == NULL) {
                return NULL;
        }
        if ((G9017_MEM1_Library = F9006_OpenMEM1(1)) == NULL) {
                return NULL;
        }
#ifdef MEDIA619_A31E_A31M
        F1088_OpenAmigaStuff();
#endif
        G9000_GRF1base = P2856_;
#ifdef MEDIA655_A31M
        G9000_GRF1base->_w_0x36_BaseLineStridePixelCount = 16;
        G9000_GRF1base->_w_0x38 = 0;
        G9000_GRF1base->_w_0x3A = 1;
#endif
        if (!F9093_AllocateWorkingMemory()) {
#ifdef MEDIA655_A31M
                F1089_CloseAmigaStuff();
#endif
                return NULL;
        }
#ifdef MEDIA692_X31J
        P2856_->_w_0x36_BaseLineStridePixelCount = 2;
        P2856_->_w_0x38 = 0;
        P2856_->_w_0x3A = 0;
#endif
        return P2856_;
}

void F9092_GRF1_03_Expunge(
)
{
        ASM_STUB_PREFIX
#ifdef MEDIA619_A31E_A31M
        F9094_FreeWorkingMemory();
        F1089_CloseAmigaStuff();
#endif
#ifdef MEDIA692_X31J
        if (G3083_puc_X68000_256bytes) {
                MEM1_07_Free(G3083_puc_X68000_256bytes);
        }
        if (G3084_puc_X68000_4096bytes) {
                MEM1_07_Free(G3084_puc_X68000_4096bytes);
        }
#endif
        F9007_CloseMEM1(G9017_MEM1_Library);
        F9009_ClosePRIM();
        ASM_STUB_SUFFIX
}

BOOLEAN F9093_AllocateWorkingMemory(
)
{
#ifdef MEDIA619_A31E_A31M
        return ((G3249_pui_BlitterTemporaryBitplane = MEM1_06_Allocate(8400L, MASK0x0008_MEMREQ)) != NULL) ? C1_TRUE : C0_FALSE;
#endif
#ifdef MEDIA692_X31J
        register unsigned char L5153_;
        register unsigned char L5154_;
        register unsigned char L5155_;
        register unsigned char L5156_;
        register unsigned char L5157_;


        if (G3083_puc_X68000_256bytes = MEM1_06_Allocate(256L, MASK0x0400_MEMREQ)) {
                L5153_ = 0;
                do {
                        G3083_puc_X68000_256bytes[L5153_] = (L5153_ << 4) | (L5153_ >> 4);
                        L5153_++;
                } while (L5153_);
                if (G3084_puc_X68000_4096bytes = MEM1_06_Allocate(4096L, MASK0x0400_MEMREQ)) {
                        L5156_ = 0;
                        do {
                                L5157_ = L5156_ & 0xF0;
                                L5155_ = L5156_ & 0x0F;
                                L5153_ = 0;
                                do {
                                        L5154_ = 0xFF;
                                        if ((L5153_ & 0x0F0) == L5157_) {
                                                L5154_ = 0x0F;
                                        }
                                        if ((L5153_ & 0x0F) == L5155_) {
                                                L5154_ &= 0xF0;
                                        }
                                        G3084_puc_X68000_4096bytes[(L5155_ << 8) + L5153_] = L5154_;
                                        L5153_++;
                                } while (L5153_);
                        } while ((L5156_ += 17) != (unsigned char)16);
                        return C1_TRUE;
                }
        }
        if (G3083_puc_X68000_256bytes) {
                MEM1_07_Free(G3083_puc_X68000_256bytes);
        }
        if (G3084_puc_X68000_4096bytes) {
                MEM1_07_Free(G3084_puc_X68000_4096bytes);
        }
        return C0_FALSE;
#endif
}

#ifdef MEDIA619_A31E_A31M
void F9094_FreeWorkingMemory(
)
{
        if (G3249_pui_BlitterTemporaryBitplane) {
                MEM1_07_Free(G3249_pui_BlitterTemporaryBitplane);
        }
        G3249_pui_BlitterTemporaryBitplane = NULL;
}
#endif
#endif
