| version 1.1, 2003/10/16 17:58:27 | version 1.12, 2005/02/12 12:13:57 | 
| Line 1 | Line 1 | 
 | #include        "compiler.h" | #include        "compiler.h" | 
 |  | #if defined(OSLANG_UTF8) || defined(OSLANG_UCS2) | 
 |  | #include        "oemtext.h" | 
 |  | #endif | 
 | #include        "dosio.h" | #include        "dosio.h" | 
 | #include        "fddfile.h" |  | 
 | #include        "newdisk.h" | #include        "newdisk.h" | 
 |  | #include        "fddfile.h" | 
 |  | #include        "sxsi.h" | 
 |  | #include        "hddboot.res" | 
 |  |  | 
 |  |  | 
| static const BYTE hdddiskboot[] = { | // ---- fdd | 
| 0xb8,0x00,0x10,0xbb,0x00,0x80,0x8e,0xd0,0x8b,0xe3,0x8c,0xc8, |  | 
| 0x8e,0xd8,0xb8,0x00,0xa0,0x8e,0xc0,0xb9,0x00,0x10,0xb8,0x20, |  | 
| 0x00,0x33,0xff,0xfc,0xf3,0xab,0xb0,0xe1,0xb9,0xe0,0x1f,0xaa, |  | 
| 0x47,0xe2,0xfc,0xbe,0x44,0x00,0x33,0xff,0xe8,0x08,0x00,0xbf, |  | 
| 0xa0,0x00,0xe8,0x02,0x00,0xeb,0xfe,0x2e,0xad,0x85,0xc0,0x74, |  | 
| 0x06,0xab,0x83,0xc7,0x02,0xeb,0xf4,0xc3,0x04,0x33,0x04,0x4e, |  | 
| 0x05,0x4f,0x01,0x3c,0x05,0x49,0x05,0x47,0x05,0x23,0x05,0x39, |  | 
| 0x05,0x2f,0x05,0x24,0x05,0x61,0x01,0x3c,0x05,0x38,0x04,0x4f, |  | 
| 0x05,0x55,0x05,0x29,0x01,0x3c,0x05,0x5e,0x05,0x43,0x05,0x48, |  | 
| 0x04,0x35,0x04,0x6c,0x04,0x46,0x04,0x24,0x04,0x5e,0x04,0x3b, |  | 
| 0x04,0x73,0x01,0x25,0x00,0x00,0x05,0x47,0x05,0x23,0x05,0x39, |  | 
| 0x05,0x2f,0x05,0x24,0x05,0x61,0x01,0x3c,0x05,0x38,0x04,0x72, |  | 
| 0x21,0x5e,0x26,0x7e,0x18,0x65,0x01,0x24,0x05,0x6a,0x05,0x3b, |  | 
| 0x05,0x43,0x05,0x48,0x04,0x37,0x04,0x46,0x12,0x3c,0x04,0x35, |  | 
| 0x04,0x24,0x01,0x25,0x00,0x00}; |  | 
 |  |  | 
 |  | void newdisk_fdd(const OEMCHAR *fname, REG8 type, const OEMCHAR *label) { | 
 |  |  | 
| void newdisk_hdd(const char *fname, UINT hddsize) { | _D88HEAD        d88head; | 
|  | FILEH           fh; | 
|  |  | 
|  | ZeroMemory(&d88head, sizeof(d88head)); | 
|  | STOREINTELDWORD(d88head.fd_size, sizeof(d88head)); | 
|  | #if defined(OSLANG_UTF8) || defined(OSLANG_UCS2) | 
|  | oemtext_oemtosjis((char *)d88head.fd_name, sizeof(d88head.fd_name), | 
|  | label, (UINT)-1); | 
|  | #else | 
|  | milstr_ncpy((char *)d88head.fd_name, label, sizeof(d88head.fd_name)); | 
|  | #endif | 
|  | d88head.fd_type = type; | 
|  | fh = file_create(fname); | 
|  | if (fh != FILEH_INVALID) { | 
|  | file_write(fh, &d88head, sizeof(d88head)); | 
|  | file_close(fh); | 
|  | } | 
|  | } | 
|  |  | 
|  |  | 
|  | // ---- hdd | 
|  |  | 
|  | static BOOL writezero(FILEH fh, UINT size) { | 
|  |  | 
|  | UINT8   work[256]; | 
|  | UINT    wsize; | 
|  |  | 
|  | ZeroMemory(work, sizeof(work)); | 
|  | while(size) { | 
|  | wsize = min(size, sizeof(work)); | 
|  | if (file_write(fh, work, wsize) != wsize) { | 
|  | return(FAILURE); | 
|  | } | 
|  | size -= wsize; | 
|  | } | 
|  | return(SUCCESS); | 
|  | } | 
|  |  | 
|  | static BOOL writehddipl(FILEH fh, UINT ssize, UINT32 tsize) { | 
|  |  | 
|  | UINT8   work[1024]; | 
|  | UINT    size; | 
|  |  | 
|  | ZeroMemory(work, sizeof(work)); | 
|  | CopyMemory(work, hdddiskboot, sizeof(hdddiskboot)); | 
|  | if (ssize < 1024) { | 
|  | work[ssize - 2] = 0x55; | 
|  | work[ssize - 1] = 0xaa; | 
|  | } | 
|  | 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 OEMCHAR *fname, UINT hddsize) { | 
 |  |  | 
 | FILEH   fh; | FILEH   fh; | 
| BYTE    work[256]; | UINT8   work[256]; | 
 | UINT    size; | UINT    size; | 
| UINT    wsize; | 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); |  | 
| file_write(fh, hdddiskboot, sizeof(hdddiskboot)); |  | 
| ZeroMemory(work, sizeof(work)); |  | 
| size = 0x400 - sizeof(hdddiskboot); |  | 
| while(size) { |  | 
| wsize = min(size, sizeof(work)); |  | 
| size -= wsize; |  | 
| file_write(fh, work, wsize); |  | 
| } |  | 
| 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_fdd(const char *fname, BYTE type, const char *label) { | void newdisk_nhd(const OEMCHAR *fname, UINT hddsize) { | 
 |  |  | 
| _D88HEAD        d88head; | 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 * 15; | 
|  | STOREINTELDWORD(nhd.cylinders, size); | 
|  | STOREINTELWORD(nhd.surfaces, 8); | 
|  | STOREINTELWORD(nhd.sectors, 17); | 
|  | STOREINTELWORD(nhd.sectorsize, 512); | 
|  | r = (file_write(fh, &nhd, sizeof(nhd)) != sizeof(nhd)); | 
|  | r |= writehddipl(fh, 512, size * 8 * 17 * 512); | 
|  | file_close(fh); | 
|  | if (r) { | 
|  | file_delete(fname); | 
|  | } | 
|  |  | 
|  | ndnhd_err: | 
|  | return; | 
|  | } | 
|  |  | 
|  | // hddtype = 0:5MB / 1:10MB / 2:15MB / 3:20MB / 5:30MB / 6:40MB | 
|  | void newdisk_hdi(const OEMCHAR *fname, UINT hddtype) { | 
|  |  | 
|  | const SASIHDD   *sasi; | 
 | FILEH           fh; | FILEH           fh; | 
 |  | HDIHDR          hdi; | 
 |  | UINT32          size; | 
 |  | BOOL            r; | 
 |  |  | 
 |  | hddtype &= 7; | 
 |  | if ((fname == NULL) || (hddtype == 7)) { | 
 |  | goto ndhdi_err; | 
 |  | } | 
 |  | sasi = sasihdd + hddtype; | 
 |  | fh = file_create(fname); | 
 |  | if (fh == FILEH_INVALID) { | 
 |  | goto ndhdi_err; | 
 |  | } | 
 |  | ZeroMemory(&hdi, sizeof(hdi)); | 
 |  | size = 256 * sasi->sectors * sasi->surfaces * sasi->cylinders; | 
 |  | //      STOREINTELDWORD(hdi.hddtype, 0); | 
 |  | STOREINTELDWORD(hdi.headersize, 4096); | 
 |  | STOREINTELDWORD(hdi.hddsize, size); | 
 |  | STOREINTELDWORD(hdi.sectorsize, 256); | 
 |  | STOREINTELDWORD(hdi.sectors, sasi->sectors); | 
 |  | STOREINTELDWORD(hdi.surfaces, sasi->surfaces); | 
 |  | STOREINTELDWORD(hdi.cylinders, sasi->cylinders); | 
 |  | r = (file_write(fh, &hdi, sizeof(hdi)) != sizeof(hdi)); | 
 |  | r |= writezero(fh, 4096 - sizeof(hdi)); | 
 |  | r |= writehddipl(fh, 256, size); | 
 |  | file_close(fh); | 
 |  | if (r) { | 
 |  | file_delete(fname); | 
 |  | } | 
 |  |  | 
| ZeroMemory(&d88head, sizeof(d88head)); | ndhdi_err: | 
| STOREINTELDWORD(d88head.fd_size, sizeof(d88head)); | return; | 
| milstr_ncpy((char *)d88head.fd_name, label, sizeof(d88head.fd_name)); | } | 
| d88head.fd_type = type; |  | 
|  | void newdisk_vhd(const OEMCHAR *fname, UINT hddsize) { | 
|  |  | 
|  | FILEH   fh; | 
|  | VHDHDR  vhd; | 
|  | UINT    tmp; | 
|  | BOOL    r; | 
|  |  | 
|  | if ((fname == NULL) || (hddsize < 2) || (hddsize > 512)) { | 
|  | goto ndvhd_err; | 
|  | } | 
 | fh = file_create(fname); | fh = file_create(fname); | 
| if (fh != FILEH_INVALID) { | if (fh == FILEH_INVALID) { | 
| file_write(fh, &d88head, sizeof(d88head)); | goto ndvhd_err; | 
| file_close(fh); |  | 
 | } | } | 
 |  | ZeroMemory(&vhd, sizeof(vhd)); | 
 |  | CopyMemory(&vhd.sig, sig_vhd, 7); | 
 |  | STOREINTELWORD(vhd.mbsize, (UINT16)hddsize); | 
 |  | STOREINTELWORD(vhd.sectorsize, 256); | 
 |  | vhd.sectors = 32; | 
 |  | vhd.surfaces = 8; | 
 |  | tmp = hddsize * 16;             // = * 1024 * 1024 / (8 * 32 * 256); | 
 |  | STOREINTELWORD(vhd.cylinders, (UINT16)tmp); | 
 |  | tmp *= 8 * 32; | 
 |  | STOREINTELDWORD(vhd.totals, tmp); | 
 |  | 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; | 
 | } | } | 
 |  |  |