dos33_raw: update to put things in dos order by default

This commit is contained in:
Vince Weaver 2020-08-21 01:25:32 -04:00
parent f8eb0fd058
commit acbf9cb7c2
2 changed files with 59 additions and 10 deletions

View File

@ -8,25 +8,45 @@
/* usage: dos33_raw track sector file */
static void usage(char *exe_name) {
printf("Usage:\n");
printf("\t%s disk_image track sector file\n\n",exe_name);
printf("\t%s disk_image track sector file start count\n\n",exe_name);
exit(1);
}
static int dos33_sector_map[16]={
0, 7, 14, 6, 13, 5, 12, 4, 11, 3, 10, 2, 9, 1, 8, 15
};
static int goto_dos_track_sector(int fd, int track, int sector) {
int result,translated_sector;
translated_sector=dos33_sector_map[sector%16];
result=lseek(fd,(translated_sector*256)+(track*16*256),SEEK_SET);
printf("going to: T=%d S=%d (%d)\n",track,sector,translated_sector);
return result;
}
int main(int argc, char **argv) {
unsigned int track,sector;
unsigned int track,sector,start,count,total;
int disk_image_fd;
int file_fd;
unsigned char buffer[256];
int result;
int result,read_result;
if (argc<4) {
if (argc<6) {
usage(argv[0]);
}
track=atoi(argv[2]);
sector=atoi(argv[3]);
start=atoi(argv[5]);
count=atoi(argv[6]);
/* FIXME: check limits based on stat of file */
if (track>34) {
fprintf(stderr,"Warning! Unusual track number %d\n",track);
@ -50,23 +70,40 @@ int main(int argc, char **argv) {
exit(1);
}
result=lseek(disk_image_fd,(sector*256)+(track*16*256),SEEK_SET);
result=lseek(file_fd,(start*256),SEEK_SET);
if (result<0) {
fprintf(stderr,"Error seeking: %s\n",strerror(errno));
fprintf(stderr,"Error skipping: %s\n",strerror(errno));
exit(1);
}
total=0;
/* write until out of space */
while(1) {
result=read(file_fd,buffer,256);
if (result<0) break; /* error */
if (result==0) break; /* done */
result=write(disk_image_fd,buffer,result);
if (total>=count) break;
read_result=read(file_fd,buffer,256);
if (read_result<0) break; /* error */
if (read_result==0) break; /* done */
result=goto_dos_track_sector(disk_image_fd,track,sector);
if (result<0) {
fprintf(stderr,"Error seeking: %s\n",strerror(errno));
exit(1);
}
result=write(disk_image_fd,buffer,read_result);
if (result<0) {
fprintf(stderr,"Error writing image: %s\n",
strerror(errno));
break;
}
total++;
sector++;
if (sector==16) {
sector=0;
track++;
}
}
close(file_fd);

View File

@ -0,0 +1,12 @@
MEMORY {
ZP: start = $00, size = $1A, type = rw;
RAM: start = $1f00, size = $A000, file = %O;
}
SEGMENTS {
CODE: load = RAM, type = ro, align=$100;
RODATA: load = RAM, type = ro;
DATA: load = RAM, type = rw;
BSS: load = RAM, type = bss, define = yes;
ZEROPAGE: load = ZP, type = zp;
}