1 /*
2  *	Vector06c disc generator
3  *
4  */
5 
6 #include "appmake.h"
7 
8 
9 static char             *binname      = NULL;
10 static char             *crtfile      = NULL;
11 static char             *outfile      = NULL;
12 static char              help         = 0;
13 
14 
15 /* Options that are available for this module */
16 option_t vector06c_options[] = {
17     { 'h', "help",     "Display this help",          OPT_BOOL,  &help},
18     { 'b', "binfile",  "Linked binary file",         OPT_STR,   &binname },
19     { 'c', "crt0file", "crt0 file used in linking",  OPT_STR,   &crtfile },
20     { 'o', "output",   "Name of output file",        OPT_STR,   &outfile },
21     {  0 ,  NULL,       NULL,                        OPT_NONE,  NULL }
22 };
23 
24 
25 
26 int vector06c_exec(char *target)
27 {
28     char    *buf = NULL;
29     char    filename[FILENAME_MAX+1];
30     FILE    *fpin;
31     disc_handle *h;
32     long    pos;
33     int     t,s,head = 0;
34     int     offs;
35 
36     if ( help )
37         return -1;
38 
39     if ( binname == NULL ) {
40         return -1;
41     }
42 
43     strcpy(filename, binname);
44     if ( ( fpin = fopen_bin(binname, crtfile) ) == NULL ) {
45         exit_log(1,"Cannot open binary file <%s>\n",binname);
46     }
47 
48     if (fseek(fpin, 0, SEEK_END)) {
49         fclose(fpin);
50         exit_log(1,"Couldn't determine size of file\n");
51     }
52 
53     pos = ftell(fpin);
54     fseek(fpin, 0L, SEEK_SET);
55     buf = must_malloc(pos);
56     if (pos != fread(buf, 1, pos, fpin)) { fclose(fpin); exit_log(1, "Could not read required data from <%s>\n",binname); }
57     fclose(fpin);
58 
59     h = cpm_create_with_format("vector06c");
60 
61     disc_write_boot_track(h, buf, 512);
62 
63     offs = 512;
64     head = t = 0;
65     s = 1;
66     while ( offs < pos ) {
67         disc_write_sector(h,t,s,head,&buf[offs]);
68         offs += 512;
69         s++;
70         if ( s == 10 ) {
71            head ^= 1;
72            if ( head == 0 ) {
73                t++;
74            }
75            s = 0;
76         }
77     }
78 
79 
80     suffix_change(filename, ".fdd");
81     disc_write_raw(h, filename);
82     free(buf);
83 
84     return 0;
85 }
86 
87