[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: NIB and DSK questions
On Feb 7, 6:17 pm, mmpho...@macgui.com (Mark Stock) wrote:
> Egan Ford wrote:
> > 1. Is there a CLI tool (with source, preferably POSIX) that will
> > convert unprotected NIB to DSK? I've searched and have not found much
> > (with links that still exist). BTW, is there a NIB format description
> > floating around anywhere?
>
> > 2. From time to time I encounter a DSK file that is not 143360 in
> > length. Is the assumption that the rest of the file is zeros?
>
> > Thanks.
>
> Here's a program for item 2. I used this make some very old partial DSK
> files somewhat to mostly usable again.
> To build and use it:
>
> make zerofill
> /zerofill < undersized.dsk > therightsize.dsk
>
> http://hoop-la.ca/apple2/src/zerofill.c
>
> #include <stdio.h>
>
> #define DISK_LENGTH 143360
>
> int main(int argc, char * argv[])
> {
> int c;
> int i;
> int not_end_of_file;
>
> not_end_of_file = 1;
> for (i = 0; i < DISK_LENGTH; i++) {
> if (not_end_of_file) {
> c = getchar();
> if (c == EOF) {
> c = not_end_of_file = 0;
> }
> }
> putchar(c);
> }
>
> return 0;
>
>
>
>
>
>
>
> }
Thanks.
Here is my perl version if any are interested.
my $dsk = shift;
if(-s $dsk < 143360) {
open(DSK,">>$dsk") || die("Cannot append to '$dsk'");
print DSK chr(0) x (143360 - (-s $dsk));
close DSK;
}
While I am at it, here is my .po to .do, quick and dirty, needs error
checking:
#include <stdio.h>
typedef struct s {
unsigned char bytes[256];
} sector;
typedef struct t {
sector sectors[16];
} track;
typedef struct d {
track tracks[35];
} disk;
int main(int argc, char **argv)
{
disk po;
FILE *ifp, *ofp;
int i,j,k;
unsigned int xref[]={0x0,0xE,0xD,0xC,0xB,0xA,
0x9,0x8,0x7,0x6,0x5,0x4,0x3,0x2,0x1,0xF};
if ((ifp = fopen(argv[1], "rb")) == NULL) {
fprintf(stderr,"Cannot read: %s\n\n",argv[1]);
return 1;
}
if ((ofp = fopen(argv[2], "w")) == NULL) {
fprintf(stderr,"Cannot write: %s\n\n",argv[2]);
return 1;
}
fread(&po, 143360, 1, ifp);
for(i=0;i<35;i++)
for(j=0;j<16;j++)
for(k=0;k<256;k++)
fprintf(ofp,"%c",po.tracks[i].sectors[xref[j]].bytes[k]);
return 0;
}