Add commands to change name of HELLO program

Both dos33 and mkdos33fs now support this
This commit is contained in:
Vince Weaver 2012-09-21 00:51:25 -04:00
parent 310cb6b3e0
commit dc16365eea
4 changed files with 90 additions and 9 deletions

View File

@ -44,3 +44,8 @@ RELEASE 0.0.8
+ Fix some minor bugs + Fix some minor bugs
RELEASE 0.0.10 RELEASE 0.0.10
21 September 2012
+ Add -f option to mkdos33fs that lets you specify the name of
the HELLO file
+ Add HELLO option to dos33 that does something similar

1
TODO
View File

@ -1,3 +1,4 @@
pcx2hgr: pcx2hgr:
error checking error checking
complain if not 140x160 or 140x192 complain if not 140x160 or 140x192

55
dos33.c
View File

@ -959,7 +959,7 @@ keep_deleting:
return 0; return 0;
} }
static int dump_sector() { static int dump_sector(void) {
int i,j; int i,j;
for(i=0;i<16;i++) { for(i=0;i<16;i++) {
@ -983,8 +983,19 @@ static int dos33_dump(int fd) {
unsigned char tslist[BYTES_PER_SECTOR]; unsigned char tslist[BYTES_PER_SECTOR];
int result; int result;
/* Read Track 1 Sector 9 */
lseek(fd,DISK_OFFSET(1,9),SEEK_SET);
result=read(fd,sector_buffer,BYTES_PER_SECTOR);
printf("Finding name of startup file, Track 1 Sector 9 offset $75\n");
dump_sector();
printf("Startup Filename: ");
for(i=0;i<30;i++) printf("%c",sector_buffer[0x75+i]&0x7f);
printf("\n");
dos33_read_vtoc(fd); dos33_read_vtoc(fd);
printf("\nVTOC Sector:\n");
dump_sector(); dump_sector();
printf("\n\n"); printf("\n\n");
@ -1032,7 +1043,7 @@ repeat_catalog:
lseek(fd,DISK_OFFSET(catalog_t,catalog_s),SEEK_SET); lseek(fd,DISK_OFFSET(catalog_t,catalog_s),SEEK_SET);
result=read(fd,sector_buffer,BYTES_PER_SECTOR); result=read(fd,sector_buffer,BYTES_PER_SECTOR);
dump_sector(sector_buffer); dump_sector();
for(file=0;file<7;file++) { for(file=0;file<7;file++) {
printf("\n\n"); printf("\n\n");
@ -1105,7 +1116,27 @@ continue_dump:;
return 0; return 0;
} }
int dos33_rename_hello(int fd, char *new_name) {
char buffer[BYTES_PER_SECTOR];
int i;
lseek(fd,DISK_OFFSET(1,9),SEEK_SET);
read(fd,buffer,BYTES_PER_SECTOR);
for(i=0;i<30;i++) {
if (i<strlen(new_name)) {
buffer[0x75+i]=new_name[i]|0x80;
}
else {
buffer[0x75+i]=' '|0x80;
}
}
lseek(fd,DISK_OFFSET(1,9),SEEK_SET);
write(fd,buffer,BYTES_PER_SECTOR);
return 0;
}
int display_help(char *name) { int display_help(char *name) {
printf("\ndos33 version %s\n",VERSION); printf("\ndos33 version %s\n",VERSION);
@ -1126,6 +1157,7 @@ int display_help(char *name) {
printf("\tRENAME apple_file_old apple_file_new\n"); printf("\tRENAME apple_file_old apple_file_new\n");
printf("\tUNDELETE apple_file\n"); printf("\tUNDELETE apple_file\n");
printf("\tDUMP\n"); printf("\tDUMP\n");
printf("\tHELLO apple_file\n");
#if 0 #if 0
printf("\tINIT\n"); printf("\tINIT\n");
printf("\tCOPY\n"); printf("\tCOPY\n");
@ -1146,6 +1178,7 @@ int display_help(char *name) {
#define COMMAND_RENAME 9 #define COMMAND_RENAME 9
#define COMMAND_COPY 10 #define COMMAND_COPY 10
#define COMMAND_DUMP 11 #define COMMAND_DUMP 11
#define COMMAND_HELLO 12
int main(int argc, char **argv) { int main(int argc, char **argv) {
@ -1235,6 +1268,9 @@ int main(int argc, char **argv) {
else if (!strncmp(temp_string,"DUMP",4)) { else if (!strncmp(temp_string,"DUMP",4)) {
command=COMMAND_DUMP; command=COMMAND_DUMP;
} }
else if (!strncmp(temp_string,"HELLO",5)) {
command=COMMAND_HELLO;
}
else { else {
display_help(argv[0]); display_help(argv[0]);
goto exit_program; goto exit_program;
@ -1487,7 +1523,22 @@ int main(int argc, char **argv) {
dos33_undelete_file(dos_fd,catalog_entry,apple_filename); dos33_undelete_file(dos_fd,catalog_entry,apple_filename);
break; break;
case COMMAND_HELLO:
if (argc+extra_ops<4) {
fprintf(stderr,"Error! Need file_name\n");
fprintf(stderr,"%s %s HELLO apple_filename\n",argv[0],image);
goto exit_and_close;
}
catalog_entry=dos33_check_file_exists(dos_fd,argv[firstarg+2],
FILE_NORMAL);
if (catalog_entry<0) {
fprintf(stderr,
"Warning! File %s does not exist\n",argv[firstarg+2]);
}
dos33_rename_hello(dos_fd,argv[firstarg+2]);
break;
case COMMAND_INIT: case COMMAND_INIT:
/* use common code from mkdos33fs? */ /* use common code from mkdos33fs? */
case COMMAND_COPY: case COMMAND_COPY:

View File

@ -14,11 +14,12 @@ void usage(char *binary,int help) {
printf("\thttp://www.deater.net/weave/vmwprod/apple/\n\n"); printf("\thttp://www.deater.net/weave/vmwprod/apple/\n\n");
if (help) { if (help) {
printf("Usage:\t%s [-t track] [-s sector] [-b size] " printf("Usage:\t%s [-t track] [-s sector] [-b size] "
"[-d filename] device_name\n\n",binary); "[-d filename] [-f filename] device_name\n\n",binary);
printf("\t-t tracks : number of tracks in filesystem\n"); printf("\t-t tracks : number of tracks in filesystem\n");
printf("\t-s sectors : number of sectors in filesystem\n"); printf("\t-s sectors : number of sectors in filesystem\n");
printf("\t-b blocksize : size of sector, in bytes\n"); printf("\t-b blocksize : size of sector, in bytes\n");
printf("\t-d filename : file to copy first 3 tracks over from\n"); printf("\t-d filename : file to copy first 3 tracks over from\n");
printf("\t-f filename : name of BASIC file to autoboot. Default is HELLO\n");
printf("\n\n"); printf("\n\n");
} }
exit(0); exit(0);
@ -34,9 +35,11 @@ int main(int argc, char **argv) {
int i,c,copy_dos=0; int i,c,copy_dos=0;
int result; int result;
char boot_filename[30]="HELLO ";
/* Parse Command Line Arguments */ /* Parse Command Line Arguments */
while ((c = getopt (argc, argv,"t:s:b:d:hv"))!=-1) { while ((c = getopt (argc, argv,"t:s:b:d:f:hv"))!=-1) {
switch (c) { switch (c) {
case 't': num_tracks=strtol(optarg,&endptr,10); case 't': num_tracks=strtol(optarg,&endptr,10);
@ -54,6 +57,16 @@ int main(int argc, char **argv) {
strncpy(dos_src,optarg,BUFSIZ); strncpy(dos_src,optarg,BUFSIZ);
break; break;
case 'f':
if (strlen(optarg)>30) {
fprintf(stderr,"Auto boot filename too long!\n");
exit(1);
}
memcpy(boot_filename,optarg,strlen(optarg));
for(i=strlen(optarg);i<30;i++) boot_filename[i]=' ';
// printf("Writing boot filename \"%s\"\n",boot_filename);
break;
case 'v': usage(argv[0],0); case 'v': usage(argv[0],0);
case 'h': usage(argv[0],1); case 'h': usage(argv[0],1);
@ -92,7 +105,7 @@ int main(int argc, char **argv) {
buffer=calloc(1,sizeof(char)*block_size); buffer=calloc(1,sizeof(char)*block_size);
/* Open device */ /* Open device */
fd=open(device,O_WRONLY|O_CREAT,0666); fd=open(device,O_RDWR|O_CREAT,0666);
if (fd<0) { if (fd<0) {
fprintf(stderr,"Error opening %s\n",device); fprintf(stderr,"Error opening %s\n",device);
goto end_of_program; goto end_of_program;
@ -119,6 +132,18 @@ int main(int argc, char **argv) {
} }
close(dos_fd); close(dos_fd);
/* Set boot filename */
/* Track 1 sector 9 */
lseek(fd,((1*num_sectors)+9)*block_size,SEEK_SET);
result=read(fd,buffer,block_size);
/* filename begins at offset 75 */
for(i=0;i<30;i++) {
buffer[0x75+i]=boot_filename[i]|0x80;
}
lseek(fd,((1*num_sectors)+9)*block_size,SEEK_SET);
result=write(fd,buffer,block_size);
} }
/* clear buffer */ /* clear buffer */
@ -159,6 +184,7 @@ int main(int argc, char **argv) {
buffer[VTOC_FREE_BITMAPS+2]=0x00; buffer[VTOC_FREE_BITMAPS+2]=0x00;
buffer[VTOC_FREE_BITMAPS+3]=0x00; buffer[VTOC_FREE_BITMAPS+3]=0x00;
/* if copying dos reserve tracks 1 and 2 as well */
if (copy_dos) { if (copy_dos) {
buffer[VTOC_FREE_BITMAPS+4]=0x00; buffer[VTOC_FREE_BITMAPS+4]=0x00;
buffer[VTOC_FREE_BITMAPS+5]=0x00; buffer[VTOC_FREE_BITMAPS+5]=0x00;
@ -177,8 +203,6 @@ int main(int argc, char **argv) {
buffer[VTOC_FREE_BITMAPS+17*4+2]=0x00; buffer[VTOC_FREE_BITMAPS+17*4+2]=0x00;
buffer[VTOC_FREE_BITMAPS+17*4+3]=0x00; buffer[VTOC_FREE_BITMAPS+17*4+3]=0x00;
/* Write out VTOC to disk */ /* Write out VTOC to disk */
lseek(fd,((17*num_sectors)+0)*block_size,SEEK_SET); lseek(fd,((17*num_sectors)+0)*block_size,SEEK_SET);
result=write(fd,buffer,block_size); result=write(fd,buffer,block_size);