Skip to content

Commit

Permalink
give appmake the ability to create plus3dos headed binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
pjshumphreys committed Sep 11, 2022
1 parent 87a9d41 commit b5a207a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
61 changes: 61 additions & 0 deletions src/appmake/zx-util.c
Expand Up @@ -2336,3 +2336,64 @@ int zx_plus3(struct zx_common *zxc, struct zx_tape *zxt, struct banked_memory *m
}
return 0;
}

int zx_dos(struct zx_common *zxc, struct zx_tape *zxt, struct banked_memory *memory)
{
uint8_t *ptr;
char output_name[FILENAME_MAX+1];
size_t origin;
size_t binary_length;
FILE *fpin;
FILE *fpout;
void *file_buf;
size_t file_len;

if (zxc->outfile == NULL) {
strcpy(output_name, zxc->binname);
suffix_change(output_name, ".dos");
} else {
strcpy(output_name, zxc->outfile);
}

if (strcmp(zxc->binname, output_name) == 0) {
exit_log(1, "Input and output file names must be different\n");
}

if (zxc->origin != -1) {
origin = zxc->origin;
} else if ((origin = get_org_addr(zxc->crtfile)) == -1) {
exit_log(1,"Could not find parameter ZORG (not z88dk compiled?)\n");
}

if ((fpin = fopen_bin(zxc->binname, zxc->crtfile)) == NULL) {
exit_log(1,"Can't open input file %s\n", zxc->binname);
}

if ((fpout = fopen(output_name, "wb")) == NULL) {
exit_log(1,"Can't open output file %s\n", output_name);
}

if (fseek(fpin, 0, SEEK_END)) {
fclose(fpin);
exit_log(1,"Couldn't determine size of file\n");
}

binary_length = ftell(fpin);
fseek(fpin, 0L, SEEK_SET);

// Read the binary
ptr = must_malloc(binary_length);
if (binary_length != fread(ptr, 1, binary_length, fpin)) { fclose(fpin); exit_log(1, "Could not read required data from <%s>\n",zxc->binname); }
fclose(fpin);

file_buf = zx3_layout_file(ptr, binary_length, origin, 3, &file_len);

fwrite(file_buf, 1, file_len, fpout);

fclose(fpout);

free(file_buf);
free(ptr);

return 0;
}
1 change: 1 addition & 0 deletions src/appmake/zx-util.h
Expand Up @@ -78,6 +78,7 @@ extern void zxn_construct_page_contents(unsigned char *mem, struct memory_bank *

extern int zx_tape(struct zx_common *zxc, struct zx_tape *zxt, struct banked_memory *memory);
extern int zx_plus3(struct zx_common *zxc, struct zx_tape *zxt, struct banked_memory *memory);
extern int zx_dos(struct zx_common *zxc, struct zx_tape *zxt, struct banked_memory *memory);
extern int zx_dot_command(struct zx_common *zxc, struct banked_memory *memory);
extern int zxn_dotn_command(struct zx_common *zxc, struct banked_memory *memory, int fillbyte);
extern int zx_sna(struct zx_common *zxc, struct zx_sna *zxs, struct banked_memory *memory, int is_zxn);
Expand Down
7 changes: 5 additions & 2 deletions src/appmake/zx.c
Expand Up @@ -106,6 +106,7 @@ static char sna = 0; // .sna 48k/128k snapshot
static char dot = 0; // esxdos dot command
static char bin = 0; // .bin output binaries with banks correctly merged
static char plus3 = 0; // Generate +3 disc
static char dos = 0; // Generate +3DOS headed file

/* Options that are available for this module */
option_t zx_options[] = {
Expand Down Expand Up @@ -139,6 +140,7 @@ option_t zx_options[] = {
{ 0, "clean", "Remove consumed source binaries\n", OPT_BOOL, &zxc.clean },

{ 0, "dot", "Make esxdos dot command instead of .tap\n", OPT_BOOL, &dot },
{ 0, "dos", "Make +3DOS headed binary instead of .tap\n", OPT_BOOL, &dos },
{ 0, "plus3", "Make Spectrum +3 .dsk instead of .tap\n", OPT_BOOL, &plus3 },

{ 0, "audio", "Create also a WAV file", OPT_BOOL, &zxt.audio },
Expand Down Expand Up @@ -193,7 +195,7 @@ int zx_exec(char *target)

// generate output

tap = !dot && !sna && !bin && !plus3;
tap = !dot && !sna && !bin && !plus3 && !dos;

if (tap && (zxc.main_fence > 0))
fprintf(stderr, "Warning: Main-fence is ignored for tap compiles\n");
Expand Down Expand Up @@ -473,7 +475,8 @@ int zx_exec(char *target)
return zx_tape(&zxc, &zxt, &memory);
}


if(dos)
return zx_dos(&zxc, &zxt, &memory);

if (plus3)
return zx_plus3(&zxc, &zxt, &memory);
Expand Down

0 comments on commit b5a207a

Please sign in to comment.