/* This program extracts the machine code generated by the compiler from an included source code file to a BIN file containing raw machine code without any executable or object code header and structures */

#ifndef COMPILE_H
#include "COMPILE.H"
#endif
#ifdef MEDIA208_S10EA_S20E_G20E_A20E_A31E_SU1E
extern CODE_START();
extern CODE_END();

#ifdef MEDIA209_S10EA_S20E_SU1E
#include <OSBIND.H>


asm {
        CODE_START:
}
#include "BIN.C"
asm {
        CODE_END:
}


int16_t main(
)
{
        int16_t FileHandle;


        if ((FileHandle = Fcreate("BIN.BIN", C0_FILE_ATTRIBUTES)) < 0) {
                printf("Unable to create BIN.BIN, aborting.");
        } else {
                Fwrite(FileHandle, (long)(CODE_END) - (long)(CODE_START), CODE_START);
                Fclose(FileHandle);
        }
}
#endif
#ifdef MEDIA387_G20E
/* Only useful with APW. With MPW there is no need for this code */
#include <stdio.h>

#include "GRAPH21.C"


int16_t main(
)
{
        FILE* FileHandle;


        if ((FileHandle = fopen("GRAPH21.BIN", "wb")) == NULL) {
                printf("Unable to create GRAPH21.BIN, aborting.");
        } else {
                fwrite(F0914_Graphic21, (int16_t)((long)main - (long)F0914_Graphic21), 1, FileHandle);
                fclose(FileHandle);
        }
        return 0; /* If not 0 then execution of the program from an Exec file in APW shell stops */
}
#endif
#ifdef MEDIA432_A20E
#include <functions.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h>


#asm
        _CODE_START:
        public _CODE_START
#endasm
#include "BIN.C"
#asm
        _CODE_END:
        public _CODE_END
#endasm


int16_t main(
)
{
        FILE_HANDLE FileHandle;


        if ((FileHandle = Open("BIN.BIN", MODE_NEWFILE)) == NULL) {
                printf("Unable to create BIN.BIN, aborting.");
        } else {
                Write(FileHandle, CODE_START, (long)(CODE_END) - (long)(CODE_START));
                M572_CloseFile(FileHandle);
        }
}
#endif
#ifdef MEDIA618_A31E
#include <stdio.h>

CODE_START() {
}

#if EXEID == 23
#include "GRAPH21.C"
#define BIN "GRAPH21.BIN"
#endif
#if EXEID == 24
#include "GRAPH538.C"
#define BIN "GRAPH676.BIN"
#endif

CODE_END() {
}

int16_t main(
)
{
        FILE* FileHandle;
        char Padding[2] = { 0, 0 };


        if ((FileHandle = fopen(BIN, "wb")) == NULL) {
                printf("Unable to create BIN, aborting.");
        } else {
                fwrite(*((char**)((char*)CODE_START + 2)) + 2, (long)(*((char**)((char*)CODE_END + 2))) - (long)(*((char**)((char*)CODE_START + 2)) + 2), 1, FileHandle); /* Address of a function returns an address in the jumptable */
#if EXEID == 24
                fwrite(Padding, 2, 1, FileHandle);
#endif
                fclose(FileHandle);
        }
}
#endif
#endif
