From c7f04713b3012775278910d9a8d12c4e7f6e1d9c Mon Sep 17 00:00:00 2001 From: Vince Weaver Date: Fri, 16 Dec 2016 13:36:48 -0500 Subject: [PATCH] asoft-utils: add new bin2data utility --- asoft_basic-utils/Makefile | 11 ++++++-- asoft_basic-utils/README | 7 +++++ asoft_basic-utils/bin2data.c | 54 ++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 asoft_basic-utils/bin2data.c diff --git a/asoft_basic-utils/Makefile b/asoft_basic-utils/Makefile index a5f6bb85..21e1ad55 100644 --- a/asoft_basic-utils/Makefile +++ b/asoft_basic-utils/Makefile @@ -1,6 +1,7 @@ include ../Makefile.inc -all: asoft_detoken tokenize_asoft integer_detoken asoft_compact +all: asoft_detoken tokenize_asoft integer_detoken asoft_compact bin2data + asoft_compact: asoft_compact.o $(CC) $(LFLAGS) -o asoft_compact asoft_compact.o @@ -14,6 +15,12 @@ asoft_detoken: asoft_detoken.o asoft_detoken.o: asoft_detoken.c $(CC) $(CFLAGS) -c asoft_detoken.c +bin2data: bin2data.o + $(CC) $(LFLAGS) -o bin2data bin2data.o + +bin2data.o: bin2data.c + $(CC) $(CFLAGS) -c bin2data.c + integer_detoken: integer_detoken.o $(CC) $(LFLAGS) -o integer_detoken integer_detoken.o @@ -31,7 +38,7 @@ install: cp asoft_detoken tokenize_asoft integer_detoken $(INSTALL_LOC) clean: - rm -f *~ *.o asoft_detoken tokenize_asoft \ + rm -f *~ *.o asoft_detoken tokenize_asoft bin2data \ integer_detoken asoft_compact diff --git a/asoft_basic-utils/README b/asoft_basic-utils/README index b8c5ea85..6df4290a 100644 --- a/asoft_basic-utils/README +++ b/asoft_basic-utils/README @@ -29,3 +29,10 @@ asoft_compact: tries to compress your Applesoft basic program to make it as small as possible %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +bin2data: takes binary image and converts it to suitable + BASIC to poke into memory. + + Useful for getting machine language routines usable + in BASIC programs + diff --git a/asoft_basic-utils/bin2data.c b/asoft_basic-utils/bin2data.c new file mode 100644 index 00000000..ea3d7d11 --- /dev/null +++ b/asoft_basic-utils/bin2data.c @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + + +int main(int argc, char **argv) { + + int address=0x300; + int bytes=0,line=10,i; + struct stat file_info; + int fd; + unsigned char c; + + if (argc<2) { + printf("Usage:\t%s binfile [addr]\n\n",argv[0]); + return -1; + } + + if (argc>2) { + address=strtol(argv[2],NULL,0); + } + + if (stat(argv[1],&file_info)<0) { + fprintf(stderr,"Could not stat file %s\n\n",argv[1]); + return -1; + } + bytes=(int)file_info.st_size; + + fd=open(argv[1],O_RDONLY); + if (fd<0) { + fprintf(stderr,"Could not open file %s\n\n",argv[1]); + return -1; + } + + printf("%d FOR I=0 TO %d: READ X: POKE %d+I,X:NEXT I\n", + line,bytes,address); + + for(i=0;i