Skip to content

Commit ca2930c

Browse files
al20878tlhackque
authored andcommitted
LBN2PBN: Apply minor fixes and mention reverse conversion in README
1 parent 405010f commit ca2930c

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ gt7cvt | Convert a gt7 magtape dump to a SIMH magtape
2727
hpconvert | Convert an HP disc image between SIMH and HPDrive formats
2828
imd2dsk | Convert an ImageDisk (IMD) file to DSK (pure data)
2929
indent | Convert simulator sources to 4-column tabs
30-
lbn2pbn | Logical-to-physical converter for single-sided floppy disk images
30+
lbn2pbn | Logical-to-physical (and reverse) converter for single-sided floppy disk images
3131
littcvt | Remove density maker from litt format tapes
3232
m8376 | Assembles 8 PROM files into a 32bit binary file
3333
mt2tpc | Convert a simh simulated magtape to TPC format

converters/lbn2pbn/lbn2pbn.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
#include <stdlib.h>
4545
#include <string.h>
4646

47+
#define SECTOR_MIN_SIZE 128
48+
#define SECTOR_MAX_SIZE 512
49+
4750

4851
inline
4952
static size_t filesize(FILE* fp)
@@ -162,8 +165,8 @@ int main(int argc, char* argv[])
162165
break;
163166
case 'B':
164167
sector_size = atoi(optarg);
165-
if ((sector_size & (sector_size - 1))
166-
|| sector_size < 128 || sector_size > 512) {
168+
if (sector_size < SECTOR_MIN_SIZE || sector_size > SECTOR_MAX_SIZE
169+
|| (sector_size & (sector_size - 1))) {
167170
sector_size = 0;
168171
}
169172
break;
@@ -198,26 +201,26 @@ int main(int argc, char* argv[])
198201

199202
if (!(in = fopen(infile, "rb"))) {
200203
perror(infile);
201-
return 1;
204+
return EXIT_FAILURE;
202205
}
203206

204207
size = filesize(in);
205208
q = tracks * sectors;
206209
max_size = q * sector_size;
207210
if (size > max_size) {
208211
fprintf(stderr, "%s: file size (%zd) may not exceed %zu\n", infile, size, max_size);
209-
return 1;
212+
return EXIT_FAILURE;
210213
}
211214

212215
if (!(out = fopen(outfile, "wb"))) {
213216
perror(outfile);
214-
return 1;
217+
return EXIT_FAILURE;
215218
}
216219

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

237240
fclose(out);
238241
fclose(in);
239-
return 0;
242+
return EXIT_SUCCESS;
240243
}

0 commit comments

Comments
 (0)