#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA671_F31E_F31J_P31J
#ifdef MEDIA670_F31E_F31J
unsigned char* G7169_puc_AvailableRAMBottom;
long G7168_AvailableRAMByteCount;


long F2242_MEM_AVAIL(
void
)
{
        unsigned long L6495_;
        unsigned long L6494_;
        unsigned char* L6493_;


        L6495_ = 0;
        L6494_ = 400000;
        while (L6494_ > 1000) {
                if ((L6493_ = malloc(L6495_ + L6494_)) != NULL) {
                        free(L6493_);
                        L6495_ = L6495_ + L6494_;
                        continue;
                }
                L6494_ >>= 1;
        }
        return L6495_ & 0xFFFFFFFE;
}

unsigned char* F2243_CallMalloc(
long P6104_ FINAL_SEPARATOR
{
        return malloc(P6104_);
}

void F2244_CallFree(
unsigned char* P6105_ FINAL_SEPARATOR
{
        free(P6105_);
}
#endif

void F7335_AllocateAllRAM(
)
{
#ifdef MEDIA667_P31J
        G7168_AvailableRAMByteCount = coreleft();
        if ((G7169_puc_AvailableRAMBottom = farmalloc(G7168_AvailableRAMByteCount)) == NULL) {
#endif
#ifdef MEDIA670_F31E_F31J
        G7168_AvailableRAMByteCount = F2242_MEM_AVAIL();
        if ((G7169_puc_AvailableRAMBottom = (unsigned char*)(F2243_CallMalloc(G7168_AvailableRAMByteCount))) == NULL) {
#endif
                exit(0);
        }
#ifdef MEDIA667_P31J
        F0699_InitVideoInterrupt();
        F0713_InitIOInterrupt();
#endif
#ifdef MEDIA670_F31E_F31J
        F2245_INIT_TOWNS();
#endif
        F0066_MOUSE_Initialize();
        F0451_FLOPPY_Initialize();
}

void F7336_FreeAllRAM(
)
{
#ifdef MEDIA667_P31J
        farfree(G7169_puc_AvailableRAMBottom);
#endif
#ifdef MEDIA670_F31E_F31J
        F2247_RESTORE_TOWNS();
        F2244_CallFree(M774_CAST_PUC(G7169_puc_AvailableRAMBottom));
#endif
}
#endif
