#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA774_SU1E_AU1E_AU2E
#ifdef MEDIA763_AU1E_AU2E
void F2012_(
)
{
        asm {
                        moveq   #0,d0
                        btst    #7,(0xBFE001).l
                        bne.s   @Tlocret_97F6
                        moveq   #-1,d0
                @Tlocret_97F6:
        }
}

void F2013_(
)
{
        asm {
                        moveq   #0,d0
                        btst    #7,(0xBFE001).l
                        bne.s   @Tlocret_97F6
                        moveq   #-1,d0
                @Tlocret_97F6:
        }
}
#endif

#ifdef MEDIA772_SU1E
void F1928_ForceMediaChangeDetection(int16_t P5771_) {
        long L5642_l_SupervisorStack;
        char* L5643_;
        char* L5734_;
        char* L5735_;
        char* L5736_;


        G3716_ac_TestFileName[0] = 'A' + P5771_;
        L5642_l_SupervisorStack = Super(0L);
        asm {
                jsr     @Tloc_75C8
        }
        Super(L5642_l_SupervisorStack);
        Fopen(G3716_ac_TestFileName, 0);
        L5642_l_SupervisorStack = Super(0L);
        asm {
                jsr     @Tloc_760A
        }
        Super(L5642_l_SupervisorStack);
        return;
        asm {
                @Tloc_75C8:
                        lea     @TA4Backup,a0
                        move.l  a4,(a0)
                        lea     @TA5Backup,a0
                        move.l  a5,(a0)
                        lea     @TA6Backup,a0
                        move.l  a6,(a0)
                        move.l  (0x472).w,L5643_(a6)
                        move.l  (0x47E).w,L5734_(a6)
                        move.l  (0x476).w,L5735_(a6)
                        lea     @Tloc_7636,a0
                        move.l  a0,(0x472).w
                        move.l  a0,L5736_(a6)
                        lea     @Tloc_7660,a0
                        move.l  a0,(0x47E).w
                        lea     @Tloc_767E,a0
                        move.l  a0,(0x476).w
                        rts
                @Tloc_760A:
                        move.l  (0x472).w,d0
                        move.l  L5736_(a6),d1
                        cmp.l   d0,d1
                        bne.s   @Tlocret_7628
                        move.l  L5643_(a6),(0x472).w
                        move.l  L5734_(a6),(0x47E).w
                        move.l  L5735_(a6),(0x476).w
                @Tlocret_7628:
                        rts
                @TA4Backup:
                        dc.l 0
                @TA5Backup:
                        dc.l 0
                @TA6Backup:
                        dc.l 0
                @Tloc_7636:
                        move.l  a6,-(sp)
                        movea.l @TA6Backup,a6
                        move.w  P5771_(a6),d0
                        cmp.w   8(sp),d0
                        bne.s   @Tloc_7658
                        move.l  L5643_(a6),(0x472).w
                        move.l  L5734_(a6),(0x47E).w
                        move.l  L5735_(a6),(0x476).w
                @Tloc_7658:
                        movea.l L5643_(a6),a0
                        movea.l (sp)+,a6
                        jmp     (a0)
                @Tloc_7660:
                        move.l  a6,-(sp)
                        movea.l @TA6Backup,a6
                        move.w  P5771_(a6),d0
                        cmp.w   8(sp),d0
                        bne.s   @Tloc_7676
                        moveq   #2,d0
                        movea.l (sp)+,a6
                        rts
                @Tloc_7676:
                        movea.l L5734_(a6),a0
                        movea.l (sp)+,a6
                        jmp     (a0)
                @Tloc_767E:
                        move.l  a6,-(sp)
                        movea.l @TA6Backup,a6
                        move.w  P5771_(a6),d0
                        cmp.w   0x12(sp),d0
                        bne.s   @Tloc_7694
                        moveq   #0xFFFFFFF2,d0
                        movea.l (sp)+,a6
                        rts
                @Tloc_7694:
                        movea.l L5735_(a6),a0
                        movea.l (sp)+,a6
                        jmp     (a0)
        }
}
#endif

long F1931_(int16_t P5774_, int16_t P5775_, ...) {
        register int16_t L5644_;
#ifdef MEDIA772_SU1E
        char* L5645_;
#endif
#ifdef MEDIA763_AU1E_AU2E
        long L5645_;
#endif
        long L5646_;
        int16_t L5647_i_IORequestIndex;
        long L5648_;
        char* L5649_;


#ifdef MEDIA773_SU1E_AU1E
        F1966_DebugEnter(20, P5775_);
#endif
        switch (P5775_) {
                case 40:
                        if (*((long*)(&P5775_ + 5)) == -1) {
                                if ((**((char**)(&P5775_ + 3)) == '0') || ((int16_t)F1931_(20, 13) < 2)) {
                                        L5649_ = (char*)32;
                                } else {
                                        L5649_ = (char*)33;
                                }
                        } else {
                                L5649_ = *((char**)(&P5775_ + 5));
                        }
                        F1859_SetIORequestValue(*((int16_t*)(&P5775_ + 2)), 256, L5649_);
                        F1859_SetIORequestValue(*((int16_t*)(&P5775_ + 2)), 2, (long)(*((char**)(&P5775_ + 3)) + 1));
#ifdef MEDIA772_SU1E
                        L5645_ = L5649_ - 32;
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5645_ = (long)L5649_ - 32;
#endif
                        break;
                case 8:
                        L5647_i_IORequestIndex = F1855_GetAvailableIORequestIndex();
                        if ((long)L5647_i_IORequestIndex != 0) {
                                F1956_EndProgram(P5774_, 18, 90L);
                        }
                        L5644_ = F1931_(P5774_, 40, (long)L5647_i_IORequestIndex, *((long*)(&P5775_ + 1)), *((long*)(&P5775_ + 3)));
#ifdef MEDIA772_SU1E
                        F1928_ForceMediaChangeDetection(L5644_);
#endif
                        L5648_ = F1857_PerformIORequestOperation(L5647_i_IORequestIndex, C02_OPEN_FILE);
                        F1857_PerformIORequestOperation(L5647_i_IORequestIndex, C10_CLOSE_FILE);
                        F1856_CloseFile(L5647_i_IORequestIndex);
                        if (L5648_ == 0) {
#ifdef MEDIA772_SU1E
                                L5645_ = (char*)1;
#endif
#ifdef MEDIA763_AU1E_AU2E
                                L5645_ = 1;
#endif
                        } else {
#ifdef MEDIA772_SU1E
                                L5645_ = (char*)0;
#endif
#ifdef MEDIA763_AU1E_AU2E
                                L5645_ = 0;
#endif
                        }
                        break;
                case 13:
                        L5647_i_IORequestIndex = F1855_GetAvailableIORequestIndex();
                        if (L5647_i_IORequestIndex == -1) {
                                F1956_EndProgram(P5774_, 18, 91L);
                        }
                        F1859_SetIORequestValue(L5647_i_IORequestIndex, 128, 32L);
                        L5648_ = F1857_PerformIORequestOperation(L5647_i_IORequestIndex, 22);
                        if (L5648_) {
                                F1956_EndProgram(P5774_, 18, 92L);
                        }
                        L5644_ = F1861_GetIORequestOutputValue(L5647_i_IORequestIndex);
                        F1856_CloseFile(L5647_i_IORequestIndex);
                        if (L5644_ > 2) {
                                L5644_ = 2;
                        }
#ifdef MEDIA772_SU1E
                        L5645_ = (char*)L5644_;
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5645_ = L5644_;
#endif
                        break;
                case 12:
#ifdef MEDIA772_SU1E
                        L5645_ = (char*)1;
#endif
#ifdef MEDIA763_AU1E_AU2E
                        L5645_ = 1;
#endif
                        F1955_Input_CPSX(-1, C02_UNINITIALIZE);
                        L5644_ = F1931_(20, 13);
                        L5646_ = (L5644_ > 1) ? -1L : 32L;
                        while (F1931_(20, 8, *((long*)(&P5775_ + 1)), L5646_) != 1) {
                                if (*((long*)(&P5775_ + 3)) == 0) {
#ifdef MEDIA772_SU1E
                                        L5645_ = (char*)0;
#endif
#ifdef MEDIA763_AU1E_AU2E
                                        L5645_ = 0;
#endif
                                        break;
                                }
                                F1885_(20, 8, *((STRUCT22B**)(&P5775_ + 3)));
                        }
                        break;
                default:
                        F1956_EndProgram(P5774_, 18, 62L);
        }
#ifdef MEDIA773_SU1E_AU1E
        F1967_DebugExit(20, P5775_);
#endif
#ifdef MEDIA772_SU1E
        return (long)L5645_;
#endif
#ifdef MEDIA763_AU1E_AU2E
        return L5645_;
#endif
}
#endif
