#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA678_F31E_F31J_X31J_P31J_SU1E_AU1E_AU2E_AU3E
BOOLEAN F7063_LoadDungeon(REGISTER GAME* P3584_ps_)
{
        REGISTER int16_t L3966_i_;
        REGISTER int16_t L3964_i_;
        REGISTER int16_t L3965_i_;
        REGISTER unsigned int16_t L3967_i_;
        int16_t L3968_i_;
        int16_t L3969_i_ = 0;
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        int16_t L6050_i_Unreferenced;


        P3584_ps_->Dungeon.Header = (DUNGEON_HEADER*)F7023_Alloc((long)sizeof(DUNGEON_HEADER), MASK0x0400_MEMREQ);
        F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.Header, &L3969_i_, sizeof(DUNGEON_HEADER));
#endif
#ifdef MEDIA772_SU1E
        P3584_ps_->Dungeon.Header = (DUNGEON_HEADER*)F7023_Alloc((long)sizeof(DUNGEON_HEADER));
#endif
#ifdef MEDIA762_AU1E
        P3584_ps_->Dungeon.Header = (DUNGEON_HEADER*)F2095_AllocateMemory((long)sizeof(DUNGEON_HEADER));
#endif
#ifdef MEDIA773_SU1E_AU1E
        if (F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.Header, &L3969_i_, sizeof(DUNGEON_HEADER)) == 0) {
                goto loc_166C;
        }
#endif
        L3966_i_ = P3584_ps_->Dungeon.Header->MapCount;
#ifdef MEDIA772_SU1E
        P3584_ps_->Dungeon.Maps = (MAP*)F7023_Alloc(L3966_i_ * sizeof(MAP));
#endif
#ifdef MEDIA762_AU1E
        P3584_ps_->Dungeon.Maps = (MAP*)F2095_AllocateMemory((long)(L3966_i_ * sizeof(MAP)));
#endif
#ifdef MEDIA773_SU1E_AU1E
        if (F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.Maps, &L3969_i_, L3966_i_ * sizeof(MAP)) == 0) {
                goto loc_166C;
        }
#endif
#ifdef MEDIA772_SU1E
        P3584_ps_->Dungeon.MapsFirstColumnIndex = (int16_t*)F7023_Alloc((long)(L3966_i_ << 1));
#endif
#ifdef MEDIA762_AU1E
        P3584_ps_->Dungeon.MapsFirstColumnIndex = (int16_t*)F2095_AllocateMemory((long)(L3966_i_ << 1));
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        P3584_ps_->Dungeon.Maps = (MAP*)F7023_Alloc((long)(L3966_i_ * sizeof(MAP)), MASK0x0400_MEMREQ);
        F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.Maps, &L3969_i_, L3966_i_ * sizeof(MAP));
        P3584_ps_->Dungeon.MapsFirstColumnIndex = (int16_t*)F7023_Alloc((long)(L3966_i_ << 1), MASK0x0400_MEMREQ);
#endif
        for (L3967_i_ = L3965_i_ = 0; L3965_i_ < L3966_i_; L3965_i_++) {
                P3584_ps_->Dungeon.MapsFirstColumnIndex[L3965_i_] = L3967_i_;
                L3967_i_ += P3584_ps_->Dungeon.Maps[L3965_i_].A.Width + 1;
        }
        P3584_ps_->Dungeon.ColumnCount = L3967_i_;
        L3965_i_ = P3584_ps_->Dungeon.Header->SquareFirstThingCount;
#ifdef MEDIA772_SU1E
        P3584_ps_->Dungeon.ColumnsCumulativeSquareThingCount = (unsigned int16_t*)F7023_Alloc((long)(L3967_i_ * sizeof(int16_t)));
        P3584_ps_->Dungeon.SquareFirstThings = (THING*)F7023_Alloc(P3584_ps_->Dungeon.Header->SquareFirstThingCount * sizeof(int16_t));
        P3584_ps_->Dungeon.TextData = (unsigned int16_t*)F7023_Alloc((long)P3584_ps_->Dungeon.Header->TextDataWordCount * sizeof(int16_t));
#endif
#ifdef MEDIA762_AU1E
        P3584_ps_->Dungeon.ColumnsCumulativeSquareThingCount = (unsigned int16_t*)F2095_AllocateMemory((long)(L3967_i_ * sizeof(int16_t)));
        P3584_ps_->Dungeon.SquareFirstThings = (THING*)F2095_AllocateMemory((long)(P3584_ps_->Dungeon.Header->SquareFirstThingCount * sizeof(int16_t)));
        P3584_ps_->Dungeon.TextData = (unsigned int16_t*)F2095_AllocateMemory((long)P3584_ps_->Dungeon.Header->TextDataWordCount * sizeof(int16_t));
#endif
#ifdef MEDIA773_SU1E_AU1E
        if (F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.ColumnsCumulativeSquareThingCount, &L3969_i_, L3967_i_ * sizeof(int16_t)) == 0) {
                goto loc_166C;
        }
        if (F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.SquareFirstThings, &L3969_i_, L3965_i_ * sizeof(int16_t)) == 0) {
                goto loc_166C;
        }
        if (F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.TextData, &L3969_i_, P3584_ps_->Dungeon.Header->TextDataWordCount * sizeof(int16_t)) == 0) {
                goto loc_166C;
        }
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
        P3584_ps_->Dungeon.ColumnsCumulativeSquareThingCount = (unsigned int16_t*)F7023_Alloc((long)(L3967_i_ * sizeof(int16_t)), MASK0x0400_MEMREQ);
        P3584_ps_->Dungeon.SquareFirstThings = (THING*)F7023_Alloc((long)(P3584_ps_->Dungeon.Header->SquareFirstThingCount * sizeof(int16_t)), MASK0x0400_MEMREQ);
        P3584_ps_->Dungeon.TextData = (unsigned int16_t*)F7023_Alloc((long)(P3584_ps_->Dungeon.Header->TextDataWordCount * sizeof(int16_t)), MASK0x0400_MEMREQ);
        F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.ColumnsCumulativeSquareThingCount, &L3969_i_, L3967_i_ * sizeof(int16_t));
        F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.SquareFirstThings, &L3969_i_, L3965_i_ * sizeof(int16_t));
        F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.TextData, &L3969_i_, P3584_ps_->Dungeon.Header->TextDataWordCount * sizeof(int16_t));
#endif
        for (L3964_i_ = 0; L3964_i_ < 16; L3964_i_++) {
                L3965_i_ = P3584_ps_->Dungeon.Header->ThingCount[L3964_i_];
                L3967_i_ = G0235_auc_Graphic559_ThingDataByteCount[L3964_i_];
#ifdef MEDIA772_SU1E
                P3584_ps_->Dungeon.ThingData[L3964_i_] = F7023_Alloc((long)(P3584_ps_->Dungeon.Header->ThingCount[L3964_i_] * L3967_i_));
                if (F7059_ReadDungeonPartWithChecksum(P3584_ps_->Dungeon.ThingData[L3964_i_], &L3969_i_, L3967_i_ * L3965_i_) == 0) {
#endif
#ifdef MEDIA762_AU1E
                P3584_ps_->Dungeon.ThingData[L3964_i_] = F2095_AllocateMemory((long)(P3584_ps_->Dungeon.Header->ThingCount[L3964_i_] * L3967_i_));
                if (F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.ThingData[L3964_i_], &L3969_i_, L3967_i_ * L3965_i_) == 0) {
#endif
#ifdef MEDIA773_SU1E_AU1E
                        goto loc_166C;
                }
        }
#ifdef MEDIA772_SU1E
        P3584_ps_->Dungeon.RawMapData = F7023_Alloc((long)P3584_ps_->Dungeon.Header->RawMapDataByteCount);
#endif
#ifdef MEDIA762_AU1E
        P3584_ps_->Dungeon.RawMapData = F2095_AllocateMemory((long)P3584_ps_->Dungeon.Header->RawMapDataByteCount);
#endif
        if (F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.RawMapData, &L3969_i_, P3584_ps_->Dungeon.Header->RawMapDataByteCount) == 0) {
                goto loc_166C;
        }
        if ((F1999_FILE_Read(&L3968_i_, 2) == 0) || (L3968_i_ == L3969_i_)) {
                return C1_TRUE;
        }
        loc_166C:
#endif
#ifdef MEDIA677_F31E_F31J_X31J_P31J_AU2E_AU3E
                P3584_ps_->Dungeon.ThingData[L3964_i_] = F7023_Alloc((long)(P3584_ps_->Dungeon.Header->ThingCount[L3964_i_] * L3967_i_), MASK0x0400_MEMREQ);
                F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.ThingData[L3964_i_], &L3969_i_, L3967_i_ * L3965_i_);
        }
        P3584_ps_->Dungeon.RawMapData = F7023_Alloc((long)P3584_ps_->Dungeon.Header->RawMapDataByteCount, MASK0x0400_MEMREQ);
        F7059_ReadDungeonPartWithChecksum((unsigned char*)P3584_ps_->Dungeon.RawMapData, &L3969_i_, P3584_ps_->Dungeon.Header->RawMapDataByteCount);
        F7137_FileOperation(G7004_SavedGameFileHandle, C0xF00A_OPERATION_READ, C16_FILEOP_BYTE_COUNT, (long)2, C15_FILEOP_SET_BUFFER, (long)&L3968_i_, 0);
        if (L3968_i_ != L3969_i_) {
                F7112_FallbackToLastProgramState(C0_FALSE, 23003, 0L);
        }
        return C1_TRUE;
#endif
        return C0_FALSE;
}
#endif
