From e4e41d710d2bb468b21b4a5e58edff4828101bc3 Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Mon, 2 Aug 2021 00:50:55 -0400 Subject: [PATCH] prodos: add utility for reading text files also add in more complete 2mg support --- utils/prodos-utils/Makefile | 13 ++++++- utils/prodos-utils/prodos.c | 64 ++++++++++++++++++++++++++++++--- utils/prodos-utils/prodos_cat.c | 32 +++++++++++++++++ 3 files changed, 103 insertions(+), 6 deletions(-) create mode 100644 utils/prodos-utils/prodos_cat.c diff --git a/utils/prodos-utils/Makefile b/utils/prodos-utils/Makefile index e6d4a6ae..97cc92fb 100644 --- a/utils/prodos-utils/Makefile +++ b/utils/prodos-utils/Makefile @@ -2,7 +2,7 @@ include ../../Makefile.inc CFLAGS := $(CFLAGS) -g -all: prodos mkprodosfs +all: prodos mkprodosfs prodos_cat ### @@ -21,6 +21,17 @@ prodos.o: prodos.c prodos.h $(CC) $(CFLAGS) -g -c prodos.c +### + +prodos_cat: prodos_cat.o + $(CC) $(LFLAGS) -o prodos_cat prodos_cat.o + +#### + +prodos_cat.o: prodos_cat.c + $(CC) $(CFLAGS) -c prodos_cat.c + + ### mkprodosfs: mkprodosfs.o prodos_read.o prodos_volume_bitmap.o diff --git a/utils/prodos-utils/prodos.c b/utils/prodos-utils/prodos.c index c359dc5a..ecf2fa6f 100644 --- a/utils/prodos-utils/prodos.c +++ b/utils/prodos-utils/prodos.c @@ -12,7 +12,7 @@ #include "prodos.h" static int ignore_errors=0; -int debug=1; +int debug=0; /* Read volume directory into a buffer */ static int prodos_read_voldir(int fd, struct voldir_t *voldir, @@ -967,7 +967,7 @@ int main(int argc, char **argv) { printf("checking extension: %s\n",&image[strlen(image)-4]); } - /* Try to autodetch interleave based on filename */ + /* Try to autodetect interleave based on filename */ if (strlen(image)>4) { if (!strncmp(&image[strlen(image)-4],".dsk",4)) { @@ -983,9 +983,15 @@ int main(int argc, char **argv) { read(prodos_fd,header,64); - image_offset=(header[8]|(header[9]<<8)); + image_offset= (header[24])| + (header[25]<<8)| + (header[26]<<16)| + (header[27]<<24); - image_format=header[12]; + image_format=(header[12])| + (header[13]<<8)| + (header[14]<<16)| + (header[15]<<24); if (image_format==0) { interleave=PRODOS_INTERLEAVE_DOS33; @@ -1011,9 +1017,57 @@ int main(int argc, char **argv) { string[4]=0; printf("creator: %s\n",string); - printf("Header size: %d\n",image_offset); + printf("Header size: %d\n", + (header[8]|(header[9]<<8))); + printf("Version: %d\n", (header[10]|(header[11]<<8))); + + printf("Flags: $%X\n", + (header[16])| + (header[17]<<8)| + (header[18]<<16)| + (header[19]<<24)); + + printf("ProDOS blocks: $%X\n", + (header[20])| + (header[21]<<8)| + (header[22]<<16)| + (header[23]<<24)); + + printf("Image offset: $%X\n",image_offset); + + printf("Bytes of data: %d\n", + (header[28])| + (header[29]<<8)| + (header[30]<<16)| + (header[31]<<24)); + + printf("Offset to comment: $%X\n", + (header[32])| + (header[33]<<8)| + (header[34]<<16)| + (header[35]<<24)); + + printf("Length of comment: %d\n", + (header[36])| + (header[37]<<8)| + (header[38]<<16)| + (header[39]<<24)); + + printf("Offset to creator comment: $%X\n", + (header[40])| + (header[41]<<8)| + (header[42]<<16)| + (header[43]<<24)); + + printf("Length of creator comment: %d\n", + (header[44])| + (header[45]<<8)| + (header[46]<<16)| + (header[47]<<24)); + + } } } diff --git a/utils/prodos-utils/prodos_cat.c b/utils/prodos-utils/prodos_cat.c new file mode 100644 index 00000000..37b5ccb9 --- /dev/null +++ b/utils/prodos-utils/prodos_cat.c @@ -0,0 +1,32 @@ +#include +#include +#include + +int main(int argc, char **argv) { + + FILE *fff; + + int result; + + if (argc<1) { + fff=stdin; + } + else { + fff=fopen(argv[1],"rb"); + if (fff==NULL) { + fprintf(stderr,"Error opening %s: %s\n", + argv[1],strerror(errno)); + return -1; + } + } + + while(1) { + result=fgetc(fff); + if (result<0) break; + if (result==13) putchar('\n'); + else putchar(result); + + } + + return 0; +}