#include #include #include #include #include #include #include typedef enum { cstA4, cstA3, cstA2, cstA1, cstA0, cstFree } TCanvasSizeType; typedef enum { coPortrait, coLandscape } TCanvasOrientation; typedef unsigned char byte; struct TCanvasInfor { TCanvasSizeType SizeType; TCanvasOrientation Orientation; unsigned short DotsPerInch; int Width; int Height; }; struct TBmp { char *map; int w, h; }; struct carpetdesign { short drive, track, sector, head, byte, needle; char *map; } carpet; struct BIOSDiskData { byte service; byte drive; byte head; byte track; byte sector; byte nsector; REALPTR buffer; REALPTR proc_addrp; }; void init_carpet_drive(char ab) { if (ab == 'a') carpet.drive = 0; else carpet.drive = 1; // 5.25 carpet.track = 80; carpet.sector = 15; carpet.head = 2; carpet.byte = 512; carpet.needle = 1356; } void make_disk_buf(TBmp *bmp) { short i, j, k, n, total, pcl_cnt, clutch_cnt; char x, pcl=0, clutch=0; char *map, *ip; char buf[14] = { 0x59, 0x30, 0x00, 0x01, 0x00, 0x01, 0x05, 0x4c, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01 }; char comp[4] = { 0x3F, 0xCF, 0xF3, 0xFC }; memset(carpet.map, 0xF6, carpet.track * carpet.head * carpet.sector * carpet.byte); map = carpet.map + (carpet.head * carpet.sector * carpet.byte); memcpy(map, buf, 14); map += 14; x = bmp->h / 256; *map = x; map++; x = bmp->h % 256; *map = x; map = carpet.map + (carpet.head * carpet.sector * carpet.byte) + 0x100; total = 515; // 5.25 pcl_cnt = 170; clutch_cnt = 339; for (i = bmp->h - 1, n = 1; i >= 0; i--, n++, map += total) { ip = bmp->map + i * bmp->w; memset(map, 0, pcl_cnt); memset(map + pcl_cnt, 0xFF, clutch_cnt); for (j = 0; j < carpet.needle; j++) { if (j < bmp->w) { switch (*ip - 1) { case 1 : pcl = 0; clutch = 0; break; // H/L case 2 : pcl = 0; clutch = 2; break; // M/L case 3 : pcl = 0; clutch = 1; break; // L/L case 4 : pcl = 1; clutch = 0; break; // H/C case 5 : pcl = 1; clutch = 2; break; // M/C case 6 : pcl = 1; clutch = 1; break; // L/C case 7 : pcl = 0; clutch = 3; break; // Á¶Á÷¾ø½¿ } *(map + j / 8) |= (pcl << (7 - j % 8)); *(map + j / 4 + pcl_cnt) &= comp[j % 4]; *(map + j / 4 + pcl_cnt) |= (clutch << ((3 - j % 4) * 2)); if (j < carpet.needle-1) ip++; } else break; } for(k = 0; k < 3; k++) { *(map + (total - 6) + k * 2) = n / 256; *(map + (total - 5) + k * 2) = n % 256; } } } int loadfromfile(char *fn) { FILE *fp = NULL; TCanvasInfor ci; TBmp bitmap; int size, k; char *ip; unsigned short infor; struct Tversion { char Texpia; char Method; unsigned short Number; } ver; if ((fp = fopen(fn, "r")) == NULL) printf("file not open!\n"); fread(&ver, 4, 1, fp); if (ver.Texpia == 'P' && ver.Method == 'T' && ver.Number >= 210) { fread(&ci, sizeof(TCanvasInfor), 1, fp); fseek(fp, 34, SEEK_SET); for (k = 0; k < 256; k++) { // palette start fread(&infor, 2, 1, fp); if (infor & 0x10) { // include user color fseek(fp, 11, SEEK_CUR); } else { fseek(fp, 7, SEEK_CUR); } } fseek(fp, 8002, SEEK_CUR); bitmap.w = ci.Width; bitmap.h = ci.Height; size = ci.Width * ci.Height; bitmap.map = NULL; bitmap.map = new char[size]; if (bitmap.map == NULL) printf("Memory is not enough!\n"); ip = bitmap.map; for (int i = 0; i < bitmap.h; i++, ip += bitmap.w) { k = fread(ip, bitmap.w, 1, fp); } fclose(fp); make_disk_buf(&bitmap); delete[] bitmap.map; return 1; } else { printf("Processing is stop, because it is dos pattern.\n"); return 0; } } int sectordisk(BIOSDiskData *data) { RMC_BLK rmode_reg; rmode_reg.eax = (data->service << 8) + data->nsector; rmode_reg.ecx = (data->track << 8) + data->sector; rmode_reg.edx = (data->head << 8) + data->drive; rmode_reg.es = RP_SEG(data->buffer); rmode_reg.ebx = RP_OFF(data->buffer); if (_dx_call_real(data->proc_addrp, &rmode_reg, 0)) return -1; return (rmode_reg.eax >> 8) & 0xFF; } pragma On(Optimize_for_space); int carpet_disk_make() { int r, size; unsigned short para_addr = 0, largest; FARPTR pm_addrp, bp; BIOSDiskData data; char *cdp; if (_dx_real_alloc(480, ¶_addr, &largest)) { printf("alloc error\n"); goto fail;} FP_SET(pm_addrp, para_addr<<4, 0x34); _dx_toreal(pm_addrp, carpet.sector * carpet.byte, &data.buffer); if (_dx_rmiv_get(0x13, &data.proc_addrp)) { printf("proc_addrp error\n"); goto fail;} data.service = 0x03; data.drive = carpet.drive; data.sector = 1; data.nsector = carpet.sector; cdp = carpet.map; size = carpet.sector * carpet.byte; for (data.track = 0; data.track < carpet.track; data.track++) { for (data.head = 0; data.head < carpet.head; data.head++) { bp = pm_addrp; for (short b = 0; b < size; b++) { *bp++ = *cdp++; } r = sectordisk(&data); if (r && r!=6) { printf("write disk error\n"); goto fail; } } printf("."); } printf("\n"); _dx_real_free(para_addr); return 0; fail: if (para_addr) _dx_real_free(para_addr); return -1; } pragma Off(Optimize_for_space); void main(int argc, char **argv) { if (argc == 1 || argc > 3) { printf("try again, makedisk [filename] [destination drive]\n"); return; } if (argv[1][0] == '?') { printf("makedisk [filename] [destination drive]\n"); printf("ex) makedisk sample.cpt a: \n"); } else { printf("Wait a monment........, Now go processing!\n"); init_carpet_drive(tolower(argv[2][0])); //a : 0 b : 1 carpet.map = new char[1228800]; if (!loadfromfile(argv[1])) goto fail; carpet_disk_make(); delete[] carpet.map; printf("Making disk is successful!\n"); } return; fail: delete[] carpet.map; }