#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// BIN2ISO (C) 2000 by DeXT
//
// This is a very simple utility to convert a BIN image (either RAW/2352 or Mode2/2336 format)
// to standard ISO format (2048 b/s). Structure of images are as follows:
//
// Mode 1 (2352): Sync (12), Address (3), Mode (1), Data (2048), ECC (288)
// Mode 2 (2352): Sync (12), Address (3), Mode (1), Subheader (8), Data (2048), ECC (280)
// Mode 2 (2336): Subheader (8), Data (2048), ECC (280)
//
// Mode2/2336 is the same as Mode2/2352 but without header (sync+addr+mode)
// Sector size is detected by the presence of Sync data
// Mode is detected from Mode field
//
// Tip for Mac users: for Mode2 tracks preserve Subheader
// (sub 8 from seek_header and write 2056 bytes per sector)
// Changelog:
// 2000/11/16 – added mode detection for RAW data images (adds Mode2/2352 support)
// ITs been GPL’d !!! (Thanks DeXT!)
/*
[COPY] — T2-COPYRIGHT-NOTE-BEGIN —
[COPY] This copyright note is auto-generated by ./scripts/Create-CopyPatch.
[COPY]
[COPY] T2 SDE: package/…/bin2iso/bin2iso.desc
[COPY] Copyright (C) 2006 The T2 SDE Project
[COPY]
[COPY] More information can be found in the files COPYING and README.
[COPY]
[COPY] This program is free software; you can redistribute it and/or modify
[COPY] it under the terms of the GNU General Public License as published by
[COPY] the Free Software Foundation; version 2 of the License. A copy of the
[COPY] GNU General Public License can be found in the file COPYING.
[COPY] — T2-COPYRIGHT-NOTE-END —
[I] A Bin to ISO converter
[T] The command line program bin2iso converts BIN image files to standard
[T] ISO image files.
[U] http://mange.dynup.net/linux/bin2iso/
[A] DeXT <de_xt@hotmail.com>
[M] Nagy Karoly Gabriel <karasz@x5.ro>
[C] extra/tool
[L] OpenSource
[S] Stable
[V] 0.2
[P] X —–5—9 800.000
[D] 117263323 bin2iso.c http://mange.dynup.net/linux/bin2iso/
[XMange] Last copyright recieved from:
http://svn.exactcode.de/t2/trunk/package/filesystem/bin2iso/bin2iso.desc
New URL is: https://mange.dynalias.org/linux/bin2iso/
*/
int main( int argc, char **argv )
{
int seek_header, seek_ecc, sector_size;
long i, source_length;
char buf[2352], destfilename[2354];
const char SYNC_HEADER[12] = { 0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0 };
FILE *fdest, *fsource;
printf(„Get version 0.4 instead: https://mange.dynalias.org/linux/bin2iso\n“);
return;
if (argc < 2) { printf(„Error: bad syntax\n\nUsage is: bin2iso image.bin [image.iso]\n“); exit(EXIT_FAILURE); } if (argc >= 3)
{
strcpy(destfilename, argv[2]);
}
else
{
strcpy(destfilename, argv[1]);
if (strlen(argv[1]) < 5 || strcmp(destfilename+strlen(argv[1])-4, „.bin“))
strcpy(destfilename+strlen(argv[1]), „.iso“);
else
strcpy(destfilename+strlen(argv[1])-4, „.iso“);
}
fsource = fopen(argv[1],“rb“);
fdest = fopen(destfilename,“wb“);
fread(buf, sizeof(char), 16, fsource);
if (memcmp(SYNC_HEADER, buf, 12))
{
seek_header = 8; // Mode2/2336 // ** Mac: change to 0
seek_ecc = 280;
sector_size = 2336;
}
else
{
switch(buf[15])
{
case 2:
seek_header = 24; // Mode2/2352 // ** Mac: change to 16
seek_ecc = 280;
sector_size = 2352;
break;
case 1:
seek_header = 16; // Mode1/2352
seek_ecc = 288;
sector_size = 2352;
break;
default:
printf(„Error: Unsupported track mode“);
exit(EXIT_FAILURE);
}
}
fseek(fsource, 0L, SEEK_END);
source_length = ftell(fsource)/sector_size;
fseek(fsource, 0L, SEEK_SET);
for(i = 0; i < source_length; i++)
{
fseek(fsource, seek_header, SEEK_CUR);
fread(buf, sizeof(char), 2048, fsource); // ** Mac: change to 2056 for Mode2
fwrite(buf, sizeof(char), 2048, fdest); // ** same as above
fseek(fsource, seek_ecc, SEEK_CUR);
}
fclose(fdest);
fclose(fsource);
exit(EXIT_SUCCESS);
}