/* This program exports to a binary file the machine code generated by the Megamax C compiler for an included source code file
The purpose is to make use of the built-in assembler of the Megamax C compiler to build a BIN file containing raw 68000 machine code (without any executable or object code header and structures) */

#define Fcreate(a, b)   (long)gemdos(0x3C, a, b)
#define Fwrite(a, b, c) (long)gemdos(0x40, a, b, c)
#define Fclose(a)       (long)gemdos(0x3E, a)

#define C0_FILE_ATTRIBUTES 0

extern long gemdos();
extern CODE_START();
extern CODE_END();

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

int main() {
        int FileHandle;


        if ((FileHandle = Fcreate("ASM.BIN", C0_FILE_ATTRIBUTES)) < 0) {
                printf("Unable to create ASM.BIN, aborting.");
        } else {
                Fwrite(FileHandle, (long)(&CODE_END) - (long)(&CODE_START), &CODE_START);
                Fclose(FileHandle);
        }
}
