China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-20 11:20
中国DOS联盟论坛 » DOS软件下载 & 游戏分享 (下载室) » Wrote a software for converting HD-COPY IMG to ordinary IMA format floppy disk images View 8,251 Replies 22
Floor 16 Posted 2018-03-22 09:56 ·  中国 四川 成都 电信
初级用户
Credits 22
Posts 8
Joined 2018-03-19 00:55
8-year member
UID 182714
Gender Male
Status Offline
Originally posted by crshen at 2018-3-21 15:36:
Reply to rgwan:
After testing, the program can basically decompress the img of HD-copy, but there are some flaws in the source code:
1. The for loop of i is obviously wrong. Check the img format document, byte tracks; // total tracks - 1 ...


Thanks for pointing out the error. It has been modified and re-released on GitHub.... Because I have few images on hand, and this thing has always been in a temporary tool state, so I didn't care too much about code efficiency and unreproducible error problems.

In addition, for relatively new GCC, the judgment of escByte will actually be optimized and expanded to the outside. I wrote such code without thinking carefully.

Express my apologies to everyone.
Floor 17 Posted 2018-03-22 10:11 ·  中国 四川 成都 电信
初级用户
Credits 22
Posts 8
Joined 2018-03-19 00:55
8-year member
UID 182714
Gender Male
Status Offline
Originally posted by crshen at 2018-3-21 15:51:
First of all, thank RGwan for sharing the source code. Here is the DOS version I modified, which can be compiled with TC2.0 or BC3.1.

Due to the memory limitation of DOS, it is impossible to directly apply for a large memory like in protected mode, so ...


In addition, I also uploaded the code you modified to GitHub for sharing.
Floor 18 Posted 2018-12-23 10:15 ·  中国 天津 联通
初级用户
Credits 72
Posts 39
Joined 2018-12-17 22:14
7-year member
UID 183286
Gender Male
From 天津静海
Status Offline
Floor 19 Posted 2020-03-26 20:28 ·  中国 湖北 天门 电信
中级用户
★★
绝不写垃圾帖
Credits 322
Posts 99
Joined 2004-07-03 00:00
21-year member
UID 27774
Gender Male
From 湖北
Status Offline
That's really good!
Recently, I just came across an HD-COPY image file. I didn't find undisk, but I found this instead.
从95年开始用DOS3.2,96年在Windows3.1里认识了鼠标,97年开始用Win95,98年装过NetWare,99年迷过Linux,现在用WinXP、WinME和DOS7.1。一回首,从盲到忙,从忙到茫。
Floor 20 Posted 2020-04-16 14:33 ·  中国 广东 茂名 联通
新手上路
Credits 10
Posts 4
Joined 2020-04-15 16:32
6-year member
UID 183957
Gender Male
Status Offline
if not exist "dest" (md "dest")

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

Write any batch file, create a new .bat in the same directory as dehd-cmd.

Looking forward to a 64-bit support, support for IMG built-in directories (some old software extracts without the original directory), can be batch processed.

[ Last edited by kmcc123 on 2020-4-16 at 14:35 ]
Floor 21 Posted 2023-09-23 22:15 ·  中国 广东 惠州 电信
新手上路
Credits 6
Posts 3
Joined 2023-09-23 09:11
2-year member
UID 185201
Gender Male
Status Offline
The dehd - cmd.exe extraction program can smoothly extract IMG files in HDCPY format. Thanks to the hard - working code writing and sharing. I was just trying to find some DOS - related things when it came. In order to view on WIN10 conveniently and selectively extract the needed files, a shell program running on WIN10 is made and placed on the site, number 2430.

The program adds a right - click menu on WIN10. When the mouse right - clicks and selects a certain IMG and clicks, the shell program will extract the selected program to a temporary directory, and then hand it over to the 7z program to open the IMA file in the temporary folder, and the user can view the extraction, etc. When the 7z window is closed, the temporary files are deleted. Since I need it, I quickly wrote a few lines. It's a VB6 console program, and it works for me. There is an installation and usage instruction Readme.pdf in the compressed package.
Floor 22 Posted 2023-09-25 10:49 ·  中国 广东 惠州 电信
新手上路
Credits 6
Posts 3
Joined 2023-09-23 09:11
2-year member
UID 185201
Gender Male
Status Offline
```vb
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 '/* A standard track capacity */
Dim plain As Integer
Dim shdcopy As String '/* Store compressed track data */
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) '/* A standard track capacity */
shdcopy = String(nBytesPerTrack, &H00) '/* Store compressed track data */

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 '/* The mapped is an empty track */
splain = String(nBytesPerTrack, &H00)
Put #2,, splain


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 '/* Decompress the track content of RLE compression */
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
```
Floor 23 Posted 2023-09-25 12:21 ·  中国 广东 惠州 电信
新手上路
Credits 6
Posts 3
Joined 2023-09-23 09:11
2-year member
UID 185201
Gender Male
Status Offline
重写的代码使用了dehd - cmd.exe的原始代码,此外,当在最后一个磁道继续时出现的一个小错误通过简单关闭文件并返回0来强制程序结束以完成操作。

#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; /* Skip the file header marked with the volume label */
nImgDataAddr = nActualImgAddr + 2 + 168; /* Start of track data */
}
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); /* A standard track capacity */
hdcopy = (unsigned char *)malloc(nBytesPerTrack); /* Store compressed track data */
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) /* The map is an empty track */
{
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++) /* Decompress the track content of RLE compression */
{
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;
}
Forum Jump: