--- /dev/null
+/* MakeImg.c\r
+ This turns a MMURTL operating system run file\r
+ into an image just as it will appear in memory\r
+ after it is loaded. The MMURTL OS loads at address 0\r
+ and is assembled with that as the virtual address\r
+ so no fixups are required. The data segment is first,\r
+ then there will be padding up to the code segment\r
+ which will begin at address 64K Linear (65536 or FFF:0\r
+ segmented).\r
+\r
+ THIS MUST BE COMPILED WITH THE LARGE MODEL (Borland or Turbo C)\r
+ (e.g., BCC -ml MAKEIMG.C)\r
+*/\r
+\r
+#define U32 unsigned long\r
+#define S32 long\r
+#define U16 unsigned int\r
+#define S16 int\r
+#define U8 unsigned char\r
+#define S8 char\r
+\r
+#define TRUE 1\r
+#define FALSE 1\r
+\r
+#include <ctype.h>\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <dos.h>\r
+#include "runfile.h"\r
+\r
+U32 fEOF = 0;\r
+\r
+long CSegSize = 0;\r
+long DSegSize = 0;\r
+\r
+char *ptest;\r
+\r
+long sStack = 0;\r
+long sCode = 0;\r
+long sData = 0;\r
+\r
+long offCode = 0;\r
+long offData = 0;\r
+long pStart = 0;\r
+\r
+struct tagtype tag;\r
+\r
+char osname[50] = {"MMURTL.RUN"}; /* default OS name */\r
+\r
+FILE *run_fh = 0;\r
+FILE *out_fh = 0;\r
+\r
+char far *pDataBuf1;\r
+char far *pDataBuf2;\r
+\r
+char far *pCodeBuf1;\r
+char far *pCodeBuf2;\r
+char far *pCodeBuf3;\r
+\r
+/*********************************************************\r
+ This reads the MMURTL run file and writes it to disk\r
+ as an image file as it would have been loaded by\r
+ the MMURTL loader. This is used so we can place this\r
+ on a disk to make it bootable.\r
+ This is a tag/length/value file is described in the\r
+ DASM documentation (in great detail).\r
+*********************************************************/\r
+\r
+void MakeImageFile(void)\r
+{\r
+int ii;\r
+long i, dret, nobj, nread;\r
+char filetype, junk, *pin;\r
+\r
+ while (1) {\r
+ tag.id = 0;\r
+ nobj = fread (&tag, 1, 5, run_fh);\r
+ if (nobj) {\r
+ ii = tag.id;\r
+ }\r
+ else {\r
+ printf("Invalid OS Run file. No End Tag Found.\r\n");\r
+ fclose(run_fh);\r
+ fclose(out_fh);\r
+ exit(1);\r
+ }\r
+\r
+ switch (tag.id) {\r
+ case IDTAG:\r
+ nobj = fread (&filetype, 1, 1, run_fh);\r
+ if (filetype == 1)\r
+ break;\r
+ else {\r
+ printf("File MUST be a run file\r\n");\r
+ exit(1);\r
+ }\r
+ break;\r
+ case SEGTAG:\r
+ nobj = fread (&sStack, 1, 4, run_fh);\r
+ if (nobj) nobj = fread (&sCode, 1, 4, run_fh);\r
+ if (nobj) nobj = fread (&sData, 1, 4, run_fh);\r
+ printf(" Code %ld\r\n", sCode);\r
+ printf(" Data %ld\r\n", sData);\r
+ break;\r
+ case DOFFTAG:\r
+ nobj = fread (&offData, 1, 4, run_fh);\r
+ break;\r
+ case COFFTAG:\r
+ nobj = fread (&offCode, 1, 4, run_fh);\r
+ break;\r
+ case STRTTAG:\r
+ nobj = fread (&pStart, 1, 4, run_fh);\r
+ break;\r
+ case CODETAG:\r
+ printf("Reading code: %ld bytes\r\n", tag.len);\r
+ CSegSize = tag.len;\r
+\r
+ if (tag.len >= 32768)\r
+ nread = 32768;\r
+ else\r
+ nread = tag.len;\r
+ tag.len -= nread;\r
+\r
+ pin = pCodeBuf1;\r
+ while (nread--) {\r
+ nobj = fread (pin++, 1, 1, run_fh);\r
+ }\r
+\r
+ if (tag.len >= 32768)\r
+ nread = 32768;\r
+ else\r
+ nread = tag.len;\r
+ tag.len -= nread;\r
+\r
+ pin = pCodeBuf2;\r
+ while (nread--) {\r
+ nobj = fread (pin++, 1, 1, run_fh);\r
+ }\r
+\r
+ if (tag.len >= 32768)\r
+ nread = 32768;\r
+ else\r
+ nread = tag.len;\r
+ tag.len -= nread;\r
+\r
+ pin = pCodeBuf3;\r
+ while (nread--) {\r
+ nobj = fread (pin++, 1, 1, run_fh);\r
+ }\r
+ break;\r
+\r
+ case DATATAG:\r
+ printf("Reading data: %ld bytes\r\n", tag.len);\r
+ DSegSize = tag.len;\r
+ if (tag.len >= 32768)\r
+ nread = 32768;\r
+ else\r
+ nread = tag.len;\r
+ tag.len -= nread;\r
+\r
+ pin = pDataBuf1;\r
+ while (nread--) {\r
+ nobj = fread (pin++, 1, 1, run_fh);\r
+ }\r
+\r
+ if (tag.len >= 32768)\r
+ nread = 32768;\r
+ else\r
+ nread = tag.len;\r
+ tag.len -= nread;\r
+\r
+ pin = pDataBuf2;\r
+ while (nread--) {\r
+ nobj = fread (pin++, 1, 1, run_fh);\r
+ }\r
+ break;\r
+ case CDFIXTAG:\r
+ case CCFIXTAG:\r
+ case DDFIXTAG:\r
+ case DCFIXTAG:\r
+ while ((tag.len) && (nobj)) {\r
+ nobj = fread (&i, 1, 4, run_fh);\r
+ tag.len-=4;\r
+ }\r
+ break;\r
+ case ENDTAG:\r
+ nobj = fread (&i, 1, 4, run_fh); /* Eat the end tag */\r
+ fclose(run_fh);\r
+ return;\r
+ default:\r
+ while ((tag.len--) && (nobj))\r
+ nobj = fread (&junk, 1, 1, run_fh);\r
+ break;\r
+\r
+ } /* end of switch */\r
+ }\r
+}\r
+\r
+/***************************\r
+* Main program -- MMLoader\r
+****************************/\r
+\r
+void main(S16 argc, S8 *argv[])\r
+{\r
+S8 *ptr;\r
+S16 i;\r
+char fName;\r
+\r
+ out_fh = fopen("MMURTL.IMG", "wb");\r
+ fName = 0;\r
+\r
+ for(i=1; i < argc; ++i) {\r
+ ptr = argv[i];\r
+ if (*ptr == '/') {\r
+ ptr++;\r
+ switch(*ptr) {\r
+ case 'U' :\r
+ case 'u' :\r
+ break;\r
+ case 'D' :\r
+ case 'd' :\r
+ break;\r
+ case 'O' :\r
+ case 'o' :\r
+ fName = 1;\r
+ break;\r
+ default:\r
+ printf("Invalid option/swtich \n");\r
+ if (run_fh)\r
+ fclose(run_fh);\r
+ exit(1);\r
+ break;\r
+ }\r
+ }\r
+ else {\r
+ if (fName)\r
+ strncpy(osname, argv[i], 39);\r
+ }\r
+ }\r
+\r
+ printf("MMURTL Image File Maker. Ver 1.0 \r\n");\r
+\r
+ printf("OS Filename specified: %s \r\n", osname);\r
+ run_fh = fopen(osname, "rb");\r
+ if (!run_fh) {\r
+ printf("Can't open: %s \r\n", osname);\r
+ exit(1);\r
+ }\r
+\r
+ pDataBuf1 = malloc(32768); /* 32K */\r
+ pDataBuf2 = malloc(32768); /* 32K */\r
+ pCodeBuf1 = malloc(32768); /* 32K */\r
+ pCodeBuf2 = malloc(32768); /* 32K */\r
+ pCodeBuf3 = malloc(32768); /* 32K */\r
+\r
+ MakeImageFile();\r
+\r
+ fwrite(pDataBuf1, 1, 32768, out_fh); /* Write 32K of the Image */\r
+ fwrite(pDataBuf2, 1, 32768, out_fh); /* Write 32K of the Image */\r
+\r
+ fwrite(pCodeBuf1, 1, 32768, out_fh); /* Write 32K of the Image */\r
+ fwrite(pCodeBuf2, 1, 32768, out_fh); /* Write 32K of the Image */\r
+ fwrite(pCodeBuf3, 1, 32768, out_fh); /* Write 32K of the Image */\r
+\r
+ fclose(out_fh);\r
+\r
+ printf("\r\nDone.\r\n");\r
+\r
+\r
+}\r
+\r
+/*********************** End of Module *****************/\r