| version 1.4, 2004/01/22 01:10:04 | version 1.7, 2004/01/30 01:29:13 | 
| Line 8 | Line 8 | 
 |  |  | 
 | // ---- fdd | // ---- fdd | 
 |  |  | 
| void newdisk_fdd(const char *fname, BYTE type, const char *label) { | void newdisk_fdd(const char *fname, REG8 type, const char *label) { | 
 |  |  | 
 | _D88HEAD        d88head; | _D88HEAD        d88head; | 
 | FILEH           fh; | FILEH           fh; | 
| Line 27  void newdisk_fdd(const char *fname, BYTE | Line 27  void newdisk_fdd(const char *fname, BYTE | 
 |  |  | 
 | // ---- hdd | // ---- hdd | 
 |  |  | 
 | static const char vhd_ver[] = "VHD1.00"; |  | 
 |  |  | 
 | static BOOL writezero(FILEH fh, UINT size) { | static BOOL writezero(FILEH fh, UINT size) { | 
 |  |  | 
 | BYTE    work[256]; | BYTE    work[256]; | 
| Line 45  static BOOL writezero(FILEH fh, UINT siz | Line 43  static BOOL writezero(FILEH fh, UINT siz | 
 | return(SUCCESS); | return(SUCCESS); | 
 | } | } | 
 |  |  | 
| static void writehddipl(FILEH fh, UINT ssize) { | static BOOL writehddipl(FILEH fh, UINT ssize, UINT32 tsize) { | 
 |  |  | 
 | BYTE    work[1024]; | BYTE    work[1024]; | 
 |  | UINT    size; | 
 |  |  | 
 | ZeroMemory(work, sizeof(work)); | ZeroMemory(work, sizeof(work)); | 
 | CopyMemory(work, hdddiskboot, sizeof(hdddiskboot)); | CopyMemory(work, hdddiskboot, sizeof(hdddiskboot)); | 
| Line 55  static void writehddipl(FILEH fh, UINT s | Line 54  static void writehddipl(FILEH fh, UINT s | 
 | work[ssize - 2] = 0x55; | work[ssize - 2] = 0x55; | 
 | work[ssize - 1] = 0xaa; | work[ssize - 1] = 0xaa; | 
 | } | } | 
| file_write(fh, work, sizeof(work)); | if (file_write(fh, work, sizeof(work)) != sizeof(work)) { | 
|  | return(FAILURE); | 
|  | } | 
|  | if (tsize > sizeof(work)) { | 
|  | tsize -= sizeof(work); | 
|  | ZeroMemory(work, sizeof(work)); | 
|  | while(tsize) { | 
|  | size = min(tsize, sizeof(work)); | 
|  | tsize -= size; | 
|  | if (file_write(fh, work, size) != size) { | 
|  | return(FAILURE); | 
|  | } | 
|  | } | 
|  | } | 
|  | return(SUCCESS); | 
 | } | } | 
 |  |  | 
 | void newdisk_thd(const char *fname, UINT hddsize) { | void newdisk_thd(const char *fname, UINT hddsize) { | 
| Line 63  void newdisk_thd(const char *fname, UINT | Line 76  void newdisk_thd(const char *fname, UINT | 
 | FILEH   fh; | FILEH   fh; | 
 | BYTE    work[256]; | BYTE    work[256]; | 
 | UINT    size; | UINT    size; | 
 |  | BOOL    r; | 
 |  |  | 
 | if ((fname == NULL) || (hddsize < 5) || (hddsize > 256)) { | if ((fname == NULL) || (hddsize < 5) || (hddsize > 256)) { | 
| return; | goto ndthd_err; | 
 | } | } | 
 | fh = file_create(fname); | fh = file_create(fname); | 
| if (fh != FILEH_INVALID) { | if (fh == FILEH_INVALID) { | 
| ZeroMemory(work, 256); | goto ndthd_err; | 
| size = hddsize * 15; |  | 
| STOREINTELWORD(work, size); |  | 
| file_write(fh, work, 256); |  | 
| writehddipl(fh, 256); |  | 
| file_close(fh); |  | 
 | } | } | 
 |  | ZeroMemory(work, 256); | 
 |  | size = hddsize * 15; | 
 |  | STOREINTELWORD(work, size); | 
 |  | r = (file_write(fh, work, 256) != 256); | 
 |  | r |= writehddipl(fh, 256, 0); | 
 |  | file_close(fh); | 
 |  | if (r) { | 
 |  | file_delete(fname); | 
 |  | } | 
 |  |  | 
 |  | ndthd_err: | 
 |  | return; | 
 |  | } | 
 |  |  | 
 |  | void newdisk_nhd(const char *fname, UINT hddsize) { | 
 |  |  | 
 |  | FILEH   fh; | 
 |  | NHDHDR  nhd; | 
 |  | UINT    size; | 
 |  | BOOL    r; | 
 |  |  | 
 |  | if ((fname == NULL) || (hddsize < 5) || (hddsize > 512)) { | 
 |  | goto ndnhd_err; | 
 |  | } | 
 |  | fh = file_create(fname); | 
 |  | if (fh == FILEH_INVALID) { | 
 |  | goto ndnhd_err; | 
 |  | } | 
 |  | ZeroMemory(&nhd, sizeof(nhd)); | 
 |  | CopyMemory(&nhd.sig, sig_nhd, 15); | 
 |  | STOREINTELDWORD(nhd.headersize, sizeof(nhd)); | 
 |  | size = hddsize * 16; | 
 |  | STOREINTELDWORD(nhd.cylinders, size); | 
 |  | STOREINTELWORD(nhd.surfaces, 8); | 
 |  | STOREINTELWORD(nhd.sectors, 32); | 
 |  | STOREINTELWORD(nhd.sectorsize, 256); | 
 |  | r = (file_write(fh, &nhd, sizeof(nhd)) != sizeof(nhd)); | 
 |  | r |= writehddipl(fh, 256, size * 8 * 32 * 256); | 
 |  | file_close(fh); | 
 |  | if (r) { | 
 |  | file_delete(fname); | 
 |  | } | 
 |  |  | 
 |  | ndnhd_err: | 
 |  | return; | 
 | } | } | 
 |  |  | 
 | // hddtype = 0:5MB / 1:10MB / 2:15MB / 3:20MB / 5:30MB / 6:40MB | // hddtype = 0:5MB / 1:10MB / 2:15MB / 3:20MB / 5:30MB / 6:40MB | 
| Line 84  void newdisk_hdi(const char *fname, UINT | Line 138  void newdisk_hdi(const char *fname, UINT | 
 | const SASIHDD   *sasi; | const SASIHDD   *sasi; | 
 | FILEH           fh; | FILEH           fh; | 
 | HDIHDR          hdi; | HDIHDR          hdi; | 
| UINT32          tmp; | UINT32          size; | 
|  | BOOL            r; | 
 |  |  | 
 | hddtype &= 7; | hddtype &= 7; | 
 | if ((fname == NULL) || (hddtype == 7)) { | if ((fname == NULL) || (hddtype == 7)) { | 
| return; | goto ndhdi_err; | 
 | } | } | 
 | sasi = sasihdd + hddtype; | sasi = sasihdd + hddtype; | 
 | fh = file_create(fname); | fh = file_create(fname); | 
| if (fh != FILEH_INVALID) { | if (fh == FILEH_INVALID) { | 
| ZeroMemory(&hdi, sizeof(hdi)); | goto ndhdi_err; | 
| tmp = 256 * sasi->sectors * sasi->surfaces * sasi->cylinders; | } | 
| //              STOREINTELDWORD(hdi.hddtype, 0);                                // ??? | ZeroMemory(&hdi, sizeof(hdi)); | 
| STOREINTELDWORD(hdi.headersize, 4096); | size = 256 * sasi->sectors * sasi->surfaces * sasi->cylinders; | 
| STOREINTELDWORD(hdi.hddsize, tmp); | //      STOREINTELDWORD(hdi.hddtype, 0); | 
| STOREINTELDWORD(hdi.sectorsize, 256); | STOREINTELDWORD(hdi.headersize, 4096); | 
| STOREINTELDWORD(hdi.sectors, sasi->sectors); | STOREINTELDWORD(hdi.hddsize, size); | 
| STOREINTELDWORD(hdi.surfaces, sasi->surfaces); | STOREINTELDWORD(hdi.sectorsize, 256); | 
| STOREINTELDWORD(hdi.cylinders, sasi->cylinders); | STOREINTELDWORD(hdi.sectors, sasi->sectors); | 
| file_write(fh, &hdi, sizeof(hdi)); | STOREINTELDWORD(hdi.surfaces, sasi->surfaces); | 
| writezero(fh, 4096 - sizeof(hdi)); | STOREINTELDWORD(hdi.cylinders, sasi->cylinders); | 
| writehddipl(fh, 256); | r = (file_write(fh, &hdi, sizeof(hdi)) != sizeof(hdi)); | 
| file_close(fh); | r |= writezero(fh, 4096 - sizeof(hdi)); | 
|  | r |= writehddipl(fh, 256, size); | 
|  | file_close(fh); | 
|  | if (r) { | 
|  | file_delete(fname); | 
 | } | } | 
 |  |  | 
 |  | ndhdi_err: | 
 |  | return; | 
 | } | } | 
 |  |  | 
 | void newdisk_vhd(const char *fname, UINT hddsize) { | void newdisk_vhd(const char *fname, UINT hddsize) { | 
| Line 114  void newdisk_vhd(const char *fname, UINT | Line 176  void newdisk_vhd(const char *fname, UINT | 
 | FILEH   fh; | FILEH   fh; | 
 | VHDHDR  vhd; | VHDHDR  vhd; | 
 | UINT    tmp; | UINT    tmp; | 
 |  | BOOL    r; | 
 |  |  | 
 | if ((fname == NULL) || (hddsize < 2) || (hddsize > 512)) { | if ((fname == NULL) || (hddsize < 2) || (hddsize > 512)) { | 
| return; | goto ndvhd_err; | 
 | } | } | 
 | fh = file_create(fname); | fh = file_create(fname); | 
| if (fh != FILEH_INVALID) { | if (fh == FILEH_INVALID) { | 
| ZeroMemory(&vhd, sizeof(vhd)); | goto ndvhd_err; | 
| CopyMemory(&vhd.sig, vhd_ver, 7); | } | 
| STOREINTELWORD(vhd.mbsize, (UINT16)hddsize); | ZeroMemory(&vhd, sizeof(vhd)); | 
| STOREINTELWORD(vhd.sectorsize, 256); | CopyMemory(&vhd.sig, sig_vhd, 7); | 
| vhd.sectors = 32; | STOREINTELWORD(vhd.mbsize, (UINT16)hddsize); | 
| vhd.surfaces = 8; | STOREINTELWORD(vhd.sectorsize, 256); | 
| tmp = hddsize * 16;             // = * 1024 * 1024 / (8 * 32 * 256); | vhd.sectors = 32; | 
| STOREINTELWORD(vhd.cylinders, (UINT16)tmp); | vhd.surfaces = 8; | 
| tmp *= 8 * 32; | tmp = hddsize * 16;             // = * 1024 * 1024 / (8 * 32 * 256); | 
| STOREINTELDWORD(vhd.totals, tmp); | STOREINTELWORD(vhd.cylinders, (UINT16)tmp); | 
| file_write(fh, &vhd, sizeof(vhd)); | tmp *= 8 * 32; | 
| writehddipl(fh, 256); | STOREINTELDWORD(vhd.totals, tmp); | 
| file_close(fh); | r = (file_write(fh, &vhd, sizeof(vhd)) != sizeof(vhd)); | 
|  | r |= writehddipl(fh, 256, 0); | 
|  | file_close(fh); | 
|  | if (r) { | 
|  | file_delete(fname); | 
 | } | } | 
 |  |  | 
 |  | ndvhd_err: | 
 |  | return; | 
 | } | } | 
 |  |  |