aboutsummaryrefslogtreecommitdiff
path: root/fenders.c
diff options
context:
space:
mode:
Diffstat (limited to 'fenders.c')
-rw-r--r--fenders.c67
1 files changed, 55 insertions, 12 deletions
diff --git a/fenders.c b/fenders.c
index 55ad709..fc44754 100644
--- a/fenders.c
+++ b/fenders.c
@@ -20,17 +20,20 @@ extern int optind, opterr, optopt;
#define SELF "fenders"
#define BANNER SELF " v" VERSION " by B. Watson (WTFPL)\n"
#define DEFAULT_TITLE "atari arcade"
-#define OPTIONS "hrscit:v"
+#define OPTIONS "hrsbcdiIt:v"
char *usage =
BANNER
"Install Fenders 3-sector loader in boot sectors of an ATR image\n"
"Usage: " SELF " -[hrcsiv] [-t title] infile.atr [outfile.atr]\n"
" -h Print this help message\n"
+ " -b Create infile as a blank ATR, update it in-place.\n"
" -r DON'T reboot (coldstart) the Atari if Reset is pressed\n"
" -c Rotate colors during load\n"
- " -s Screen off after load\n"
+ " -d Delete DOS.SYS and DUP.SYS\n"
+ " -s Screen off after load\n"
" -i In-place update (original renamed to end in ~)\n"
+ " -I In-place update (NO backup)\n"
" -v Set inverse video bit in title (blue/red text)\n"
" -t title Set title (up to 20 chars, default: '" DEFAULT_TITLE "')\n";
@@ -130,11 +133,19 @@ void set_screen_off(density dens) {
fendersdbl_bin[OFFSET_SCREENOFF_DD] = 0x8d;
}
+/* TODO: error checking */
+void call_axe(const char *args, const char *fname) {
+ char cmd[8192];
+ sprintf(cmd, "axe %s %s", args, fname);
+ fprintf(stderr, SELF ": calling axe, cmd is: %s\n", cmd);
+ system(cmd);
+}
+
int main(int argc, char **argv) {
int coldstart = 1, rot_color = 0, screen_off = 0;
int c, res, size, inverse = 0;
char title[21];
- int in_place = 0;
+ int in_place = 0, rm_backup = 0, rm_dos_dup = 0, create_blank = 0;
char rename_to[4096];
unsigned char buf[384], *bin;
char *infile = "-", *outfile = "-";
@@ -156,10 +167,18 @@ int main(int argc, char **argv) {
coldstart = 0;
break;
+ case 'b':
+ create_blank = 1;
+ in_place = 1;
+ rm_backup = 1;
+
case 'c':
rot_color = 1;
break;
+ case 'd':
+ rm_dos_dup = 1;
+
case 's':
screen_off = 1;
break;
@@ -172,6 +191,11 @@ int main(int argc, char **argv) {
in_place = 1;
break;
+ case 'I':
+ in_place = 1;
+ rm_backup = 1;
+ break;
+
case 'v':
inverse = 1;
break;
@@ -211,7 +235,13 @@ int main(int argc, char **argv) {
rename_to[len] = '~';
rename_to[len + 1] = '\0';
- fprintf(stderr, SELF ": Backing up %s to %s\n", infile, rename_to);
+ if(!rm_backup)
+ fprintf(stderr, SELF ": Backing up %s to %s\n", infile, rename_to);
+
+ if(create_blank) {
+ call_axe("-b", infile);
+ }
+
if(link(infile, rename_to)) {
perror("link()");
exit(1);
@@ -233,6 +263,7 @@ int main(int argc, char **argv) {
perror(infile);
exit(1);
}
+ if(rm_backup) unlink(infile);
}
/* read ATR header */
@@ -384,14 +415,6 @@ int main(int argc, char **argv) {
DOS 3 or 4).
*/
- /* TODO: add option to delete DOS.SYS and DUP.SYS (or more likely,
- delete them by default, and add option to allow user to keep them).
- */
-
- /* TODO: option that creates a new, blank image, with bootloader
- already on it? There's already "atrsize -b" for creating a blank
- image... */
-
/* write the rest of the loader code code to sector 720.
The code in the boot sectors will load sector 720. */
if(fwrite(bin+384, 1, 256, out) < 256) {
@@ -413,6 +436,26 @@ int main(int argc, char **argv) {
c = 1;
}
+ fclose(in);
+ fclose(out);
+
+ if(rm_dos_dup) {
+ /* TODO: check for enhanced density! */
+ if(dens != SD) {
+ fprintf(stderr, SELF
+ ": -d option only works on single-density.\n");
+ exit(2);
+ }
+ if(strcmp(outfile, "-") == 0) {
+ fprintf(stderr, SELF
+ ": Can't use -d option with standard output.\n");
+ exit(2);
+ }
+ call_axe("-D DOS.SYS", outfile);
+ call_axe("-D DUP.SYS", outfile);
+ call_axe("-D AUTORUN.SYS", outfile);
+ }
+
/* ...and I'm spent! */
return c;
}