#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA772_SU1E
int16_t G3404_VDIHandle;
unsigned int16_t G3525_VDIPB_contrl[12];
int16_t G3534_VDIPB_intin[128];
int16_t G3535_VDIPB_intout[128];
int16_t G3537_VDIPB_ptsin[128];
int16_t G3536_VDIPB_ptsout[128];
#if (EXETYPE == C07_HINT)
unsigned char* G3676_;
#endif



#if ((EXETYPE == C05_ANIM) || (EXETYPE == C04_SWITCH) || (EXETYPE == C06_CEDT))
void F1524_VerticalBlankClearPalette(int16_t P5099_) {
        long L5212_l_SupervisorStack;


        switch (P5099_) {
                case 1:
                        L5212_l_SupervisorStack = Super(0L);
                        asm {
                                jsr     @Tloc_13C4
                        }
                        Super(L5212_l_SupervisorStack);
                        return;
                case 2:
                        L5212_l_SupervisorStack = Super(0L);
                        asm {
                                jsr     @Tloc_13D6
                        }
                        Super(L5212_l_SupervisorStack);
                        return;
                default:
                        return;
        }
        asm {
                @Tloc_13A8:
                        movem.l d0/a0,-(sp)
                        movea.w #0x8240,a0      /* Color registers address */
                        moveq   #7,d0
                @Tloc_13B2:
                        clr.l   (a0)+           /* Set all colors to black */
                        dbf     d0,@Tloc_13B2
                        movem.l (sp)+,d0/a0
                        rte
                @Tloc_13BE:
                        jmp     (0).l
                @Tloc_13C4:
                        lea     (@Tloc_13BE+2),a0
                        move.l  (0x70).w,(a0)
                        lea     @Tloc_13A8,a0
                        move.l  a0,(0x70).w    /* Vertical blank exception vector */
                        rts
                @Tloc_13D6:
                        clr.l   (0x45A).w     /* colorptr */
                        lea     (@Tloc_13BE+2),a0
                        move.l  (a0),(0x70).w
                        rts
        }
}
#endif

#if (EXETYPE == C07_HINT)
void F1870_AddVerticalBlankClearPalette(
)
{
        long L5525_l_SupervisorStack;


        L5525_l_SupervisorStack = Super(0L);
        asm {
                        move.l  (0x70).w,G3676_(a5)
                        lea     @Tloc_2A02,a0
                        move.l  a0,(0x70).w
                        bra.s   @Tloc_2A18
                @Tloc_2A02:
                        movem.l d0/a0,-(sp)
                        movea.w #0x8240,a0
                        moveq   #7,d0
                @Tloc_2A0C:
                        clr.l   (a0)+
                        dbf     d0,@Tloc_2A0C
                        movem.l (sp)+,d0/a0
                        rte
                @Tloc_2A18:
        }
        Super(L5525_l_SupervisorStack);
}

void F1871_RemoveVerticalBlankClearPalette(
)
{
        long L5526_l_SupervisorStack;


        L5526_l_SupervisorStack = Super(0L);
        asm {
                clr.l   (0x45A).w               /* colorptr */
                move.l  G3676_(a5),(0x70).w
        }
        Super(L5526_l_SupervisorStack);
}
#endif

void F1525_OpenVDIWorkstation(int16_t P5100_) {
        int16_t L5213_;
        int16_t L5215_[11];
        int16_t L5216_[57];


        F1535_AES_appl_init();
        G3404_VDIHandle = F1577_AES_graf_handle(&L5213_, &L5213_, &L5213_, &L5213_);
        L5213_ = 0;
        while (L5213_ < 10) {
                L5215_[L5213_++] = 1;
        }
        L5215_[10] = 2;
        if (P5100_ == 0) {
                F1610_VDI_v_opnvwk(L5215_, &G3404_VDIHandle, L5216_);
        } else {
#if ((EXETYPE == C05_ANIM) || (EXETYPE == C04_SWITCH) || (EXETYPE == C06_CEDT))
                F1524_VerticalBlankClearPalette(1);
#endif
#if (EXETYPE == C07_HINT)
                F1870_AddVerticalBlankClearPalette();
#endif
                F1608_VDI_v_opnwk(L5215_, &G3404_VDIHandle, L5216_);
#if ((EXETYPE == C05_ANIM) || (EXETYPE == C04_SWITCH) || (EXETYPE == C06_CEDT))
                F1524_VerticalBlankClearPalette(2);
#endif
#if (EXETYPE == C07_HINT)
                F1871_RemoveVerticalBlankClearPalette();
#endif
        }
}

void F1526_CloseWorkstationAndExitApplication(
)
{
        F1611_VDI_v_clsvwk(G3404_VDIHandle);
        F1536_AES_appl_exit();
}
#endif
