2 This turns a MMURTL operating system run file
\r
3 into an image just as it will appear in memory
\r
4 after it is loaded. The MMURTL OS loads at address 0
\r
5 and is assembled with that as the virtual address
\r
6 so no fixups are required. The data segment is first,
\r
7 then there will be padding up to the code segment
\r
8 which will begin at address 64K Linear (65536 or FFF:0
\r
11 THIS MUST BE COMPILED WITH THE LARGE MODEL (Borland or Turbo C)
\r
12 (e.g., BCC -ml MAKEIMG.C)
\r
15 #define U32 unsigned long
\r
17 #define U16 unsigned int
\r
19 #define U8 unsigned char
\r
30 #include "runfile.h"
\r
49 char osname[50] = {"MMURTL.RUN"}; /* default OS name */
\r
54 char far *pDataBuf1;
\r
55 char far *pDataBuf2;
\r
57 char far *pCodeBuf1;
\r
58 char far *pCodeBuf2;
\r
59 char far *pCodeBuf3;
\r
61 /*********************************************************
\r
62 This reads the MMURTL run file and writes it to disk
\r
63 as an image file as it would have been loaded by
\r
64 the MMURTL loader. This is used so we can place this
\r
65 on a disk to make it bootable.
\r
66 This is a tag/length/value file is described in the
\r
67 DASM documentation (in great detail).
\r
68 *********************************************************/
\r
70 void MakeImageFile(void)
\r
73 long i, dret, nobj, nread;
\r
74 char filetype, junk, *pin;
\r
78 nobj = fread (&tag, 1, 5, run_fh);
\r
83 printf("Invalid OS Run file. No End Tag Found.\r\n");
\r
91 nobj = fread (&filetype, 1, 1, run_fh);
\r
95 printf("File MUST be a run file\r\n");
\r
100 nobj = fread (&sStack, 1, 4, run_fh);
\r
101 if (nobj) nobj = fread (&sCode, 1, 4, run_fh);
\r
102 if (nobj) nobj = fread (&sData, 1, 4, run_fh);
\r
103 printf(" Code %ld\r\n", sCode);
\r
104 printf(" Data %ld\r\n", sData);
\r
107 nobj = fread (&offData, 1, 4, run_fh);
\r
110 nobj = fread (&offCode, 1, 4, run_fh);
\r
113 nobj = fread (&pStart, 1, 4, run_fh);
\r
116 printf("Reading code: %ld bytes\r\n", tag.len);
\r
117 CSegSize = tag.len;
\r
119 if (tag.len >= 32768)
\r
127 nobj = fread (pin++, 1, 1, run_fh);
\r
130 if (tag.len >= 32768)
\r
138 nobj = fread (pin++, 1, 1, run_fh);
\r
141 if (tag.len >= 32768)
\r
149 nobj = fread (pin++, 1, 1, run_fh);
\r
154 printf("Reading data: %ld bytes\r\n", tag.len);
\r
155 DSegSize = tag.len;
\r
156 if (tag.len >= 32768)
\r
164 nobj = fread (pin++, 1, 1, run_fh);
\r
167 if (tag.len >= 32768)
\r
175 nobj = fread (pin++, 1, 1, run_fh);
\r
182 while ((tag.len) && (nobj)) {
\r
183 nobj = fread (&i, 1, 4, run_fh);
\r
188 nobj = fread (&i, 1, 4, run_fh); /* Eat the end tag */
\r
192 while ((tag.len--) && (nobj))
\r
193 nobj = fread (&junk, 1, 1, run_fh);
\r
196 } /* end of switch */
\r
200 /***************************
\r
201 * Main program -- MMLoader
\r
202 ****************************/
\r
204 void main(S16 argc, S8 *argv[])
\r
210 out_fh = fopen("MMURTL.IMG", "wb");
\r
213 for(i=1; i < argc; ++i) {
\r
229 printf("Invalid option/swtich \n");
\r
238 strncpy(osname, argv[i], 39);
\r
242 printf("MMURTL Image File Maker. Ver 1.0 \r\n");
\r
244 printf("OS Filename specified: %s \r\n", osname);
\r
245 run_fh = fopen(osname, "rb");
\r
247 printf("Can't open: %s \r\n", osname);
\r
251 pDataBuf1 = malloc(32768); /* 32K */
\r
252 pDataBuf2 = malloc(32768); /* 32K */
\r
253 pCodeBuf1 = malloc(32768); /* 32K */
\r
254 pCodeBuf2 = malloc(32768); /* 32K */
\r
255 pCodeBuf3 = malloc(32768); /* 32K */
\r
259 fwrite(pDataBuf1, 1, 32768, out_fh); /* Write 32K of the Image */
\r
260 fwrite(pDataBuf2, 1, 32768, out_fh); /* Write 32K of the Image */
\r
262 fwrite(pCodeBuf1, 1, 32768, out_fh); /* Write 32K of the Image */
\r
263 fwrite(pCodeBuf2, 1, 32768, out_fh); /* Write 32K of the Image */
\r
264 fwrite(pCodeBuf3, 1, 32768, out_fh); /* Write 32K of the Image */
\r
268 printf("\r\nDone.\r\n");
\r
273 /*********************** End of Module *****************/
\r