Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ gt7cvt | Convert a gt7 magtape dump to a SIMH magtape
hpconvert | Convert an HP disc image between SIMH and HPDrive formats
imd2dsk | Convert an ImageDisk (IMD) file to DSK (pure data)
indent | Convert simulator sources to 4-column tabs
lbn2pbn | Logical-to-physical converter for single-sided floppy disk images
lbn2pbn | Logical-to-physical (and reverse) converter for single-sided floppy disk images
littcvt | Remove density maker from litt format tapes
m8376 | Assembles 8 PROM files into a 32bit binary file
mt2tpc | Convert a simh simulated magtape to TPC format
Expand Down
17 changes: 10 additions & 7 deletions converters/lbn2pbn/lbn2pbn.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
#include <stdlib.h>
#include <string.h>

#define SECTOR_MIN_SIZE 128
#define SECTOR_MAX_SIZE 512


inline
static size_t filesize(FILE* fp)
Expand Down Expand Up @@ -162,8 +165,8 @@ int main(int argc, char* argv[])
break;
case 'B':
sector_size = atoi(optarg);
if ((sector_size & (sector_size - 1))
|| sector_size < 128 || sector_size > 512) {
if (sector_size < SECTOR_MIN_SIZE || sector_size > SECTOR_MAX_SIZE
|| (sector_size & (sector_size - 1))) {
sector_size = 0;
}
break;
Expand Down Expand Up @@ -198,26 +201,26 @@ int main(int argc, char* argv[])

if (!(in = fopen(infile, "rb"))) {
perror(infile);
return 1;
return EXIT_FAILURE;
}

size = filesize(in);
q = tracks * sectors;
max_size = q * sector_size;
if (size > max_size) {
fprintf(stderr, "%s: file size (%zd) may not exceed %zu\n", infile, size, max_size);
return 1;
return EXIT_FAILURE;
}

if (!(out = fopen(outfile, "wb"))) {
perror(outfile);
return 1;
return EXIT_FAILURE;
}

rewind(in);
round = lcm(sectors, interleave);
for (p = 0; p < q; ++p) {
char sector[512];
static unsigned char sector[SECTOR_MAX_SIZE];
int n = lbn2pbn(p);
#ifdef _DEBUG
printf("LBN %4d (%2d / %2d) = PBN %4d (%2d / %2d)\n",
Expand All @@ -236,5 +239,5 @@ int main(int argc, char* argv[])

fclose(out);
fclose(in);
return 0;
return EXIT_SUCCESS;
}