From: Christian Groessler Date: Sat, 1 Mar 2014 12:10:01 +0000 (+0100) Subject: make 'w2cas' a targetutil X-Git-Tag: V2.15~141^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=69f81f6d67a2fb3127adbca68f508c65c1d4dd33;p=cc65 make 'w2cas' a targetutil --- diff --git a/doc/atari.sgml b/doc/atari.sgml index 781fdf03b..867f25c1d 100644 --- a/doc/atari.sgml +++ b/doc/atari.sgml @@ -230,7 +230,7 @@ The size of a cassette boot file is restricted to 32K. Larger programs would need to be split in more parts and the parts to be loaded manually. To write the generated file to a cassette, a utility to run -on an Atari is provided ( diff --git a/libsrc/Makefile b/libsrc/Makefile index 3d8277ae5..89f952376 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -102,6 +102,7 @@ MKINC = $(GEOS) \ nes TARGETUTIL = apple2 \ + atari \ geos-apple GEOSDIRS = common \ diff --git a/libsrc/atari/targetutil/Makefile.inc b/libsrc/atari/targetutil/Makefile.inc new file mode 100644 index 000000000..eb371e111 --- /dev/null +++ b/libsrc/atari/targetutil/Makefile.inc @@ -0,0 +1,14 @@ +ifeq ($(TARGET),atari) + +DEPS += ../wrk/$(TARGET)/w2cas.d + +../wrk/$(TARGET)/w2cas.o: CC65FLAGS:=-O -W error +../wrk/$(TARGET)/w2cas.o: $(SRCDIR)/targetutil/w2cas.c | ../wrk/$(TARGET) + $(COMPILE_recipe) + +../targetutil/W2CAS.COM: ../wrk/$(TARGET)/w2cas.o ../lib/$(TARGET).lib | ../targetutil + $(LD65) -o $@ -t $(TARGET) $^ + +$(TARGET): ../targetutil/W2CAS.COM + +endif diff --git a/libsrc/atari/targetutil/w2cas.c b/libsrc/atari/targetutil/w2cas.c new file mode 100644 index 000000000..050218cfe --- /dev/null +++ b/libsrc/atari/targetutil/w2cas.c @@ -0,0 +1,186 @@ +/* w2cas.c -- write file to cassette + * + * This program writes a boot file (typically linked with + * 'atari-cassette.cfg') to the cassette. + * Only files < 32K are supported, since the loading of + * larger files requires a special loader inside the program. + * + * Christian Groessler, chris@groessler.org, 2014 + */ + +#include +#include +#include +#include +#include <6502.h> +#include +#include + +static int verbose = 1; +static char C_dev[] = "C:"; + +static struct __iocb *findfreeiocb(void) +{ + struct __iocb *iocb = &IOCB; /* first IOCB (#0) */ + int i; + + for (i = 0; i < 8; i++) { + if (iocb->handler == 0xff) + return iocb; + iocb++; + } + return NULL; +} + +int main(int argc, char **argv) +{ + char *filename, *x; + char buf[20]; + FILE *file; + unsigned char *buffer; + size_t filen, buflen = 32768l + 1; + struct regs regs; + struct __iocb *iocb = findfreeiocb(); + int iocb_num; + + if (! iocb) { + fprintf(stderr, "couldn't find a free iocb\n"); + if (_dos_type != 1) + cgetc(); + return 1; + } + iocb_num = (iocb - &IOCB) * 16; + if (verbose) + printf("using iocb index $%02X ($%04X)\n", iocb_num, iocb); + + if (argc < 2) { + printf("\nfilename: "); + x = fgets(buf, 19, stdin); + printf("\n"); + if (! x) + return 1; + if (*x && *(x + strlen(x) - 1) == '\n') + *(x + strlen(x) - 1) = 0; + filename = x; + } + else { + filename = *(argv+1); + } + + /* allocate buffer */ + buffer = malloc(buflen); + if (! buffer) { + buflen = _heapmaxavail(); /* get as much as we can */ + buffer = malloc(buflen); + if (! buffer) { + fprintf(stderr, "cannot alloc %ld bytes -- aborting...\n", (long)buflen); + if (_dos_type != 1) + cgetc(); + return 1; + } + } + if (verbose) + printf("buffer size: %ld bytes\n", (long)buflen); + + /* open file */ + file = fopen(filename, "rb"); + if (! file) { + free(buffer); + fprintf(stderr, "cannot open '%s': %s\n", filename, strerror(errno)); + if (_dos_type != 1) + cgetc(); + return 1; + } + + /* read file -- file length must be < 32K */ + if (verbose) + printf("reading input file...\n"); + filen = fread(buffer, 1, buflen, file); + if (! filen) { + fprintf(stderr, "read error\n"); + file_err: + fclose(file); + free(buffer); + if (_dos_type != 1) + cgetc(); + return 1; + } + if (filen > 32767l) { + fprintf(stderr, "file is too large (must be < 32768)\n"); + goto file_err; + } + if (filen == buflen) { /* we have a buffer < 32768 and the file fits into it (and is most probably larger) */ + fprintf(stderr, "not enough memory\n"); + goto file_err; + } + if (verbose) + printf("file size: %ld bytes\n", (long)filen); + + /* close input file */ + fclose(file); + + /* open cassette */ + if (verbose) + printf("opening cassette...\n"); + iocb->buffer = C_dev; + iocb->aux1 = 8; /* open for output */ + iocb->aux2 = 128; /* short breaks and no stop between data blocks */ + iocb->command = IOCB_OPEN; + regs.x = iocb_num; + regs.pc = 0xe456; /* CIOV */ + + _sys(®s); + if (regs.y != 1) { + fprintf(stderr, "CIO call to open cassette returned %d\n", regs.y); + free(buffer); + if (_dos_type != 1) + cgetc(); + return 1; + } + + /* write file */ + if (verbose) + printf("writing to cassette...\n"); + iocb->buffer = buffer; + iocb->buflen = filen; + iocb->command = IOCB_PUTCHR; + regs.x = iocb_num; + regs.pc = 0xe456; /* CIOV */ + + _sys(®s); + if (regs.y != 1) { + fprintf(stderr, "CIO call to write file returned %d\n", regs.y); + free(buffer); + + iocb->command = IOCB_CLOSE; + regs.x = iocb_num; + regs.pc = 0xe456; /* CIOV */ + _sys(®s); + + if (_dos_type != 1) + cgetc(); + return 1; + } + + /* free buffer */ + free(buffer); + + /* close cassette */ + iocb->command = IOCB_CLOSE; + regs.x = iocb_num; + regs.pc = 0xe456; /* CIOV */ + _sys(®s); + + if (regs.y != 1) { + fprintf(stderr, "CIO call to close cassette returned %d\n", regs.y); + if (_dos_type != 1) + cgetc(); + return 1; + } + + /* all is fine */ + printf("success\n"); + if (_dos_type != 1) + cgetc(); + return 0; +} diff --git a/util/atari/w2cas.c b/util/atari/w2cas.c deleted file mode 100644 index 050218cfe..000000000 --- a/util/atari/w2cas.c +++ /dev/null @@ -1,186 +0,0 @@ -/* w2cas.c -- write file to cassette - * - * This program writes a boot file (typically linked with - * 'atari-cassette.cfg') to the cassette. - * Only files < 32K are supported, since the loading of - * larger files requires a special loader inside the program. - * - * Christian Groessler, chris@groessler.org, 2014 - */ - -#include -#include -#include -#include -#include <6502.h> -#include -#include - -static int verbose = 1; -static char C_dev[] = "C:"; - -static struct __iocb *findfreeiocb(void) -{ - struct __iocb *iocb = &IOCB; /* first IOCB (#0) */ - int i; - - for (i = 0; i < 8; i++) { - if (iocb->handler == 0xff) - return iocb; - iocb++; - } - return NULL; -} - -int main(int argc, char **argv) -{ - char *filename, *x; - char buf[20]; - FILE *file; - unsigned char *buffer; - size_t filen, buflen = 32768l + 1; - struct regs regs; - struct __iocb *iocb = findfreeiocb(); - int iocb_num; - - if (! iocb) { - fprintf(stderr, "couldn't find a free iocb\n"); - if (_dos_type != 1) - cgetc(); - return 1; - } - iocb_num = (iocb - &IOCB) * 16; - if (verbose) - printf("using iocb index $%02X ($%04X)\n", iocb_num, iocb); - - if (argc < 2) { - printf("\nfilename: "); - x = fgets(buf, 19, stdin); - printf("\n"); - if (! x) - return 1; - if (*x && *(x + strlen(x) - 1) == '\n') - *(x + strlen(x) - 1) = 0; - filename = x; - } - else { - filename = *(argv+1); - } - - /* allocate buffer */ - buffer = malloc(buflen); - if (! buffer) { - buflen = _heapmaxavail(); /* get as much as we can */ - buffer = malloc(buflen); - if (! buffer) { - fprintf(stderr, "cannot alloc %ld bytes -- aborting...\n", (long)buflen); - if (_dos_type != 1) - cgetc(); - return 1; - } - } - if (verbose) - printf("buffer size: %ld bytes\n", (long)buflen); - - /* open file */ - file = fopen(filename, "rb"); - if (! file) { - free(buffer); - fprintf(stderr, "cannot open '%s': %s\n", filename, strerror(errno)); - if (_dos_type != 1) - cgetc(); - return 1; - } - - /* read file -- file length must be < 32K */ - if (verbose) - printf("reading input file...\n"); - filen = fread(buffer, 1, buflen, file); - if (! filen) { - fprintf(stderr, "read error\n"); - file_err: - fclose(file); - free(buffer); - if (_dos_type != 1) - cgetc(); - return 1; - } - if (filen > 32767l) { - fprintf(stderr, "file is too large (must be < 32768)\n"); - goto file_err; - } - if (filen == buflen) { /* we have a buffer < 32768 and the file fits into it (and is most probably larger) */ - fprintf(stderr, "not enough memory\n"); - goto file_err; - } - if (verbose) - printf("file size: %ld bytes\n", (long)filen); - - /* close input file */ - fclose(file); - - /* open cassette */ - if (verbose) - printf("opening cassette...\n"); - iocb->buffer = C_dev; - iocb->aux1 = 8; /* open for output */ - iocb->aux2 = 128; /* short breaks and no stop between data blocks */ - iocb->command = IOCB_OPEN; - regs.x = iocb_num; - regs.pc = 0xe456; /* CIOV */ - - _sys(®s); - if (regs.y != 1) { - fprintf(stderr, "CIO call to open cassette returned %d\n", regs.y); - free(buffer); - if (_dos_type != 1) - cgetc(); - return 1; - } - - /* write file */ - if (verbose) - printf("writing to cassette...\n"); - iocb->buffer = buffer; - iocb->buflen = filen; - iocb->command = IOCB_PUTCHR; - regs.x = iocb_num; - regs.pc = 0xe456; /* CIOV */ - - _sys(®s); - if (regs.y != 1) { - fprintf(stderr, "CIO call to write file returned %d\n", regs.y); - free(buffer); - - iocb->command = IOCB_CLOSE; - regs.x = iocb_num; - regs.pc = 0xe456; /* CIOV */ - _sys(®s); - - if (_dos_type != 1) - cgetc(); - return 1; - } - - /* free buffer */ - free(buffer); - - /* close cassette */ - iocb->command = IOCB_CLOSE; - regs.x = iocb_num; - regs.pc = 0xe456; /* CIOV */ - _sys(®s); - - if (regs.y != 1) { - fprintf(stderr, "CIO call to close cassette returned %d\n", regs.y); - if (_dos_type != 1) - cgetc(); - return 1; - } - - /* all is fine */ - printf("success\n"); - if (_dos_type != 1) - cgetc(); - return 0; -}