中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-24 20:12
中国DOS联盟论坛 » DOS软件下载 & 游戏分享 (下载室) » 写了个HD-COPY IMG转普通IMA格式软盘镜像的软件 查看 8,307 回复 22
16 发表于 2018-03-22 09:56 ·  中国 四川 成都 电信
初级用户
积分 22
发帖 8
注册 2018-03-19 00:55
8年会员
UID 182714
性别 男
状态 离线
Originally posted by crshen at 2018-3-21 15:36:
回复rgwan:
经测试,程序已基本能解压HD-copy的img,但是源码中存在些瑕疵:
1、i 的 for 循环明显错误,查看img格式文档,byte tracks; // total tracks - 1 ...


感谢指出错误.已改并重新发布到GitHub....因为我手上的镜像较少,加上这东西一直属于临时工具的状态,因此便没有过多在意代码效率和无法复现的错误问题。

另外对于比较新的GCC,escByte的判断其实会被优化展开到外部。没有细想就写下了这样的代码。

向大家表示抱歉。
17 发表于 2018-03-22 10:11 ·  中国 四川 成都 电信
初级用户
积分 22
发帖 8
注册 2018-03-19 00:55
8年会员
UID 182714
性别 男
状态 离线
Originally posted by crshen at 2018-3-21 15:51:
首先感谢rgwan分享源码,这里是我修改的DOS版本,可用TC2.0或BC3.1编译。

由于DOS内存限制,不可能像保护模式下那样直接申请一个大内存,故 ...


另外我也将您修改后的代码发上GitHub分享啦。
18 发表于 2018-12-23 10:15 ·  中国 天津 联通
初级用户
积分 72
发帖 39
注册 2018-12-17 22:14
7年会员
UID 183286
性别 男
来自 天津静海
状态 离线
不能这么说
19 发表于 2020-03-26 20:28 ·  中国 湖北 天门 电信
中级用户
★★
绝不写垃圾帖
积分 322
发帖 99
注册 2004-07-03 00:00
21年会员
UID 27774
性别 男
来自 湖北
状态 离线
真不错!
最近正好遇到个HD-COPY的映像文件,没有找到undisk,结果找到了这个。
从95年开始用DOS3.2,96年在Windows3.1里认识了鼠标,97年开始用Win95,98年装过NetWare,99年迷过Linux,现在用WinXP、WinME和DOS7.1。一回首,从盲到忙,从忙到茫。
20 发表于 2020-04-16 14:33 ·  中国 广东 茂名 联通
新手上路
积分 10
发帖 4
注册 2020-04-15 16:32
6年会员
UID 183957
性别 男
状态 离线
if not exist "dest" (md "dest")

for /f "tokens=*" %%i in ('dir/s/b/a-d *.img') do dehd-cmd.exe "dest\%%i"

写任意目批处理,新建一个bat,与dehd-cmd同一目录
期待出个支持64位、支持IMG内置目录(有些老软件解出没有原目录),能批处理

[ Last edited by kmcc123 on 2020-4-16 at 14:35 ]
21 基于dehd-cmd.exe的壳程序,可在WIN10上运行。 发表于 2023-09-23 22:15 ·  中国 广东 惠州 电信
新手上路
积分 6
发帖 3
注册 2023-09-23 09:11
2年会员
UID 185201
性别 男
状态 离线
dehd-cmd.exe解压程序可以顺利解压 HDCPY 方式的IMG文件,谢谢辛苦写码并分享,正想办法要查一些DOS的东西呢它就来了。为了方便在WIN10上查看并选择性地解压出需要的文件,做了个WIN10运行的壳程序放在站上了,第2430号。
程序在WIN10上添加了右键菜单,当鼠标右键选中某个IMG后点击,会启动壳程序,壳程序将选中的程序解压到临时目录,然后交给7z程序打开临时文件夹中的 IMA 文件,用户可查看解压等。当关闭7z窗口时,删除临时文件。 由于自己需要,草草写了几句,VB6的console程序,自己用着还行。压缩包里有安装和使用说明 Readme.pdf
22 基于dehd-cmd.exe代码改写的VisualFreeBASIC5.8.11代码 发表于 2023-09-25 10:49 ·  中国 广东 惠州 电信
新手上路
积分 6
发帖 3
注册 2023-09-23 09:11
2年会员
UID 185201
性别 男
状态 离线
Sub Form1_Command1_BN_Clicked(hWndForm As hWnd, hWndControl As hWnd)
Command1.Enabled = False
Dim sBuffer As String
Dim pnDataTrkMap As String
Dim splain As String '/* 一个标准磁道容量 */
Dim plain As Integer
Dim shdcopy As String '/* 存放压缩磁道数据 */
Dim hdcopy As Integer
Dim nFinPos As Unsigned Long
Dim nDataLen As Unsigned Integer
Dim stempString As String
Dim iContFlag As Integer
Dim nTrackCount As Integer, nSecPerTrack As Integer, nBytesPerTrack As Integer _
,nActualImgAddr As Integer, nImgDataAddr As Integer, escByte As Integer, repeatByte As Integer, repeat As Integer

Open "1.IMG" For Binary Access Read As #1
Open "11.IMA" For Binary Access Write As #2

Seek #1, 1
sBuffer = Input(2, #1)

If ((sBuffer[0] = &Hff) And (sBuffer[1] = &H18)) Then
'Source img is an HD-COPY 2.0 Image
nActualImgAddr = 14 'skip volume label
nImgDataAddr = nActualImgAddr + 2 + 168 'Start position of data
Else
'Source img may be an HD-COPY 1.7 Image
nActualImgAddr = 0
nImgDataAddr = nActualImgAddr + 2 + 164
End If

Seek #1, nActualImgAddr + 1
sBuffer = Input(2, #1)

nTrackCount = sBuffer[0] 'Readout is (actual overall tracks - 1) e.g. (80-1) = 79
nSecPerTrack = sBuffer[1]
nBytesPerTrack = 512 * nSecPerTrack

'Debug.Print "nTrackCount and nSecPerTrack", nTrackCount, nSecPerTrack
'for a example, nSecPerTrack=15, and nBytesPerTrack = 512*nSecPerTrack, total disk = 512*nSecPerTrack*nTrackCount

Seek #1, nActualImgAddr + 2 + 1 '/* tracks_map */
pnDataTrkMap = Input(2 * (nTrackCount + 1), #1)

'Debug.Print Len(pnDataTrkMap)

plain = 0
hdcopy = 0
iContFlag = 0
splain = String(nBytesPerTrack, &H00) '/* 一个标准磁道容量 */
shdcopy = String(nBytesPerTrack, &H00) '/* 存放压缩磁道数据 */

nFinPos = nImgDataAddr
'Debug.Print("Working hard,please wait...")
Seek #2, 1

For i As Integer = 0 To nTrackCount
For j As Integer = 0 To 1
iContFlag = 0
If (pnDataTrkMap[(i * 2) + j] <> &H01) Then '/* 映射为空磁道 */
splain = String(nBytesPerTrack, &H00)
Put #2,, splain

'Continue in C, but set a flag in FreeBASIC for Continue purpose
iContFlag = 1
End If

If iContFlag = 0 Then
Seek #1, nFinPos + 1
sBuffer = Input(2, #1)
nDataLen = sBuffer[0] + (sBuffer[1] Shl 8) '/* little endian */
shdcopy = Input(nDataLen, #1)

nFinPos = nFinPos + 2 + nDataLen
escByte = shdcopy[0]

For k As Integer = 1 To nDataLen - 1 '/* RLE压缩的磁道内容解压 */
If shdcopy[k] = escByte Then
k = k +1
repeatByte = shdcopy[k]: k = k +1
repeat = shdcopy[k]
For r As Integer = 0 To repeat - 1
splain[plain] = repeatByte: plain = plain + 1
Next r
Else
splain[plain] = shdcopy[k]: plain = plain + 1
End If
Next k
plain- = nBytesPerTrack
Put #2,, splain
End If
Next j
'Debug.Print i
Next i

Close #1
Close #2
MsgBox("Conversion completed!", "Information", MB_OK Or MB_ICONINFORMATION)
Command1.Enabled = True
End Sub
23 基于dehd-cmd.exe代码改写的VC6代码 发表于 2023-09-25 12:21 ·  中国 广东 惠州 电信
新手上路
积分 6
发帖 3
注册 2023-09-23 09:11
2年会员
UID 185201
性别 男
状态 离线
'The rewritten codes uses dehd-cmd.exe originall codes,
'in addition, one minor error skipped off when continue
'occurs at the final track by JUST close the files and
'return 0 to force the program to END for Completion.
'
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv)
{
FILE *fpin, *fpout;
unsigned int nBytesPerTrack;
unsigned char repeatByte;
unsigned char *buffer, *hdcopy, *plain, *pnDataTrkMap;
unsigned long nTrackCount, nSecPerTrack, nActualImgAddr, nImgDataAddr, escByte, repeat;
unsigned long nDataLen;
unsigned long nFinPos;
unsigned long i, j, k, r;

if (argc != 3)
{
fprintf(stderr, "Usage: %s <HD-COPY Image> <IMA plain floppy image>\n\n", argv);
fprintf(stderr, "This small tool decompress HD-COPY image to plain floppy image.\n");
fprintf(stderr, "Therefore, you can use old HD-COPY img on modern PC or Virtual Machine.\n\n");
fprintf(stderr, "Zhiyuan Wan <h@iloli.bid> 2018, License WTFPL.\nAlgorithm analyze from <https://github.com/ciel-yu/devnotes>. Thanks him!\n");
fprintf(stderr, "Modified to suit old DOS by crshen <crshen@qq.com>.\n\n");
exit(-1);
}

fpin = fopen(argv, "rb");
if (!fpin)
{
fprintf(stderr, "Can't open source HD-COPY image!\n");
exit(-1);
}

fpout = fopen(argv, "wb+");
if (!fpout)
{
fprintf(stderr, "Can't save plain floppy image!\n");
exit(-1);
}

buffer = (unsigned char *)malloc(2);

fseek(fpin, 0, SEEK_SET);
fread(buffer, 2, 1, fpin);
if (buffer == 0xff && buffer == 0x18)
{
printf("Source img is an HD-COPY 2.0 Image\n");
nActualImgAddr = 14; /* 跳过标有卷标的文件头 */
nImgDataAddr = nActualImgAddr + 2 + 168; /* 磁道数据起始 */
}
else
{
printf("Source img may be an HD-COPY 1.7 Image\n");
nActualImgAddr = 0;
nImgDataAddr = nActualImgAddr + 2 + 164;
}

fseek(fpin, nActualImgAddr, SEEK_SET);
fread(buffer, 2, 1, fpin);
nTrackCount = buffer; /* total tracks - 1 */
nSecPerTrack = buffer;
nBytesPerTrack = 512 * nSecPerTrack;
printf("nTrackCount = %d, nSecPerTrack = %d\n", nTrackCount, nSecPerTrack);

pnDataTrkMap = (unsigned char *)malloc(2 * (nTrackCount + 1));
fseek(fpin, nActualImgAddr + 2, SEEK_SET); /* tracks_map */
fread(pnDataTrkMap, 2 * (nTrackCount + 1), 1, fpin);

plain = (unsigned char *)malloc(nBytesPerTrack); /* 一个标准磁道容量 */
hdcopy = (unsigned char *)malloc(nBytesPerTrack); /* 存放压缩磁道数据 */
nFinPos = nImgDataAddr;
printf("Working hard,please wait...\n");
fseek(fpout, 0, SEEK_SET);

for (i = 0; i <= nTrackCount; i++)
{
for (j = 0; j < 2; j++)
{
if (pnDataTrkMap != 0x01) /* 映射为空磁道 */
{
memset(plain, 0x00, nBytesPerTrack);
fwrite(plain, nBytesPerTrack, 1, fpout);
if (i==nTrackCount)
{
fclose(fpin);
fclose(fpout);
return 0;
}
else{ continue;}
}

fseek(fpin, nFinPos, SEEK_SET);
fread(buffer, 2, 1, fpin);
nDataLen = buffer + (buffer << 8); /* little endian */
memset(hdcopy, 0x00, nBytesPerTrack);
fread(hdcopy, nDataLen, 1, fpin);
nFinPos = nFinPos + 2 + nDataLen;
escByte = hdcopy;
for (k = 1; k < nDataLen; k++) /* RLE压缩的磁道内容解压 */
{
if (hdcopy == escByte)
{
k++;
repeatByte = hdcopy;
repeat = hdcopy;
for (r = 0; r < repeat; r++)
{
*(plain++) = repeatByte;
}
}
else
{
*(plain++) = hdcopy;
}
}
plain -= nBytesPerTrack;
fwrite(plain, nBytesPerTrack, 1, fpout);
}
}

fclose(fpin);
fclose(fpout);
free(hdcopy);
free(buffer);
free(pnDataTrkMap);
free(plain);
printf("Decompress operation completed.\n");
return 0;
}
论坛跳转: