asoft-utils: add new bin2data utility

This commit is contained in:
Vince Weaver 2016-12-16 13:36:48 -05:00
parent 56f0a711eb
commit c7f04713b3
3 changed files with 70 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -0,0 +1,54 @@
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
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<bytes;i++) {
read(fd,&c,1);
if (i%16==0) {
printf("%d DATA ",line);
line+=10;
}
printf("%d",c);
if ((i%16!=15) && (i!=(bytes-1))) printf(",");
else printf("\n");
}
close(fd);
return 0;
}