中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-09-09 19:25
47,812 topics / 349,914 posts / today 0 new / 48,268 members
DOS开发编程 & 发展交流 (开发室) » The original program to extend int13 to read the MBR (hard disk master boot record), and read the hard disk serial number through the port
Printable Version  8,599 / 27
Floor1 qb45 Posted 2004-08-09 00:00
高级用户 Posts 194 Credits 677
The basic BIOS Int 13H call is a disk basic input/output interrupt call provided by BIOS. It can complete functions such as disk (including hard disk and floppy disk) reset, read/write, verification, positioning, diagnosis, formatting, etc.
It uses the CHS addressing method, so it can only access a hard disk of about 8 GB at most.
The purpose of extending the Int13H interface is to expand the functions of BIOS, so that it can support hard disks with more than 1024 cylinders, as well as functions such as locking, unlocking and ejecting of removable media.
DAP is based on the absolute sector address, so using DAP, Int13H can easily surpass the limit of 1024 cylinders because it doesn't need the concept of CHS at all.
I debugged successfully under win98 and dos71 with qb45
'In qbasic, to call the interrupt, 1 must add the L command, such as QB/L 2. Must reference qb.bi', as follows


[ Last edited by qb45 on 2006-7-9 at 11:14 ]
Floor2 Kinglion Posted 2004-08-23 00:00
铂金会员 Posts 1,924 Credits 5,798 From 金獅電腦軟體工作室
Floor3 DOSforever Posted 2005-05-30 00:00
金牌会员 Posts 2,239 Credits 4,639
Excuse me, everyone, why can't I use the extended int13h when I directly fill in the DAP parameters of the sector to be read in debug? For example, to read the content of the first physical sector of the first hard disk to the address 3333:3333, should the DAP data packet be as follows:

10 00 01 00 33 33 33 33 00 00 00 00 00 00 00 00

debug
-a
mmmm:nnnn mov ah,42
mmmm:nnnn mov dl,80
mmmm:nnnn mov di,2000
mmmm:nnnn int13
mmmm:nnnn int3
mmmm:nnnn
-e2000 10 00 01 00 33 33 33 33 00 00 00 00 00 00 00 00
-g

After execution, an error is returned under DOS7.10, and even if I check the memory address 3333:3333, there is no data to be read. It crashes in the DOS window of Win98, and a warm boot doesn't work.
Floor4 qb45 Posted 2005-06-10 00:00
高级用户 Posts 194 Credits 677
The structure of the Disk Address Packet (DAP) is as follows: (DAP is based on absolute sector addresses and can easily exceed the limit of 1024 cylinders)

struct DiskAddressPacket
BYTE PacketSize; // Packet size:
// (Fixed value, always equal to 16, that is, 10H, refers to the storage space occupied by this structure)
BYTE Reserved; // ==0
WORD BlockCount; // Number of data blocks to be transferred (in sectors)
DWORD BufferAddr; // Transfer buffer address (segment:offset)
QWORD BlockNum; // Absolute starting block address of the disk

In the extended Int13H call, the following register conventions are generally used:
ds:si ==> Disk address packet (disk address packet)
dl ==> Drive number
ah ==> Function code / return code

Please take a close look at the call specification of the extended INT13, and you will find that
ds:si ==> Disk address packet
而你的程序中是
mmmm:nnnn mov di,2000

You have made SI into DI! If you know a little Qbasic, you can find this mistake from my program!
Floor5 DOSforever Posted 2005-06-30 00:00
金牌会员 Posts 2,239 Credits 4,639
Thanks to the previous answer, according to your method, it can indeed be successfully read!
But the information I initially obtained does write DI, and it is mentioned more than once in this article. The following is the relevant information I found. Almost all the detailed explanations of extended int13h on the Internet are derived from this same article. Later, I re-read it according to the error you pointed out, and I found that in the "3. Interface Specification" section, it does write "ds:SI == disk address packet". But in the subsequent "3. API Details", all the entry parameters are written as "ds:DI = disk address packet". I don't know if it's a typo by the author or my misunderstanding?
http://www.kaijia.net/info_Print.asp?ArticleID=542


[ Last edited by dosforever on 2005-7-22 at 12:57 ]
Floor6 qb45 Posted 2005-07-05 00:00
高级用户 Posts 194 Credits 677
I have the same experience as you. At that time, I needed to use QBASIC language to make a disk editor. Because the old INT13 had limitations, so I searched everywhere for materials. I also posted a thread in this forum asking where I could find such materials. As a result, a netizen gave me a foreigner's interrupt大全 website, and the materials were very complete. Unfortunately, I couldn't understand English. Later, I found Chinese materials in Luo Yunbin's assembly language. I then referred to this material to experiment with reading a sector in QBASIC, but it didn't succeed. Later, I experimented many times, got stuck many times, and my hair turned white many times. At that time, I really thought QBASIC didn't have this ability. Then I thought again, all are programming languages, QBASIC should be able to do it, there's nothing that can't be done. When there was no operating system at that time, QBASIC was also used as an operating system. Didn't Bill Gates say: Give me BASIC, and there's nothing that can't be done! Then I asked experts everywhere. Fortunately, I met a netizen on QQ who was proficient in programming and English. I asked him to read the English for me. Haha, it turned out that the Chinese material was wrong! I felt that the person who translated this material deliberately made mistakes. He might think that as long as you are fond of programming and willing to study, you can find the mistakes. In fact, there are not only this mistake in this material, the most important mistake is this one, and then there is another mistake. When you read the first 63 sectors, there is no problem, but as long as you read and write more than 63 sectors, you will find that what is read is not what you want! There are a total of 3 mistakes in this material! You can look at the English materials. I don't remember the specific website, but you can still find the help thread I posted in this forum. There are netizens who gave this website. I also mentioned the technical materials download area in the "Data Recovery Forum", and the mistakes in the INT13 Chinese materials. They made some changes, but not very well. But in the programming discussion area of the forum, there are experts who wrote threads pointing out these 3 mistakes.
Floor7 TurboY Posted 2005-08-31 16:08
中级用户 Posts 99 Credits 322 From 湖北
I was also tricked by that material. The program has been having problems and I don't know where they are. It turns out it's the fault of SI and DI. It seems that it's better to not fully rely on books.
Floor8 qb45 Posted 2005-08-31 16:46
高级用户 Posts 194 Credits 677
Yeah, in many programming materials, there are some very small but crucial errors. Sometimes the author can't verify it. Now the internet is popular with you copying me and me copying you, and finally everyone has the same flavor!

Fortunately, I only know qbasic, so the troubles are relatively less. When I encounter problems I can't solve, I can just say: QBASIC may not have this ability

[ Last edited by qb45 on 2005-8-31 at 17:01 ]
Floor9 GOTOmsdos Posted 2006-06-30 18:21
铂金会员 Posts 1,827 Credits 5,154
Haven't learned QB, try it, seems to understand,
Now just give it a try, come back later...
Floor10 GOTOmsdos Posted 2006-06-30 19:45
铂金会员 Posts 1,827 Credits 5,154
It worked!

Another:
I don't know QB, I don't know if QB can get the address at once?

In the code of qb45:
Can the MKI$ variable take out an address value from buffdat$?
The following code is divided into two times:
d1% = varSEG(buffdat$)
d2% = SADD(buffdat$)
Because, after buffdat is created, its address is fixed.
There is no need to decompose its address, right?
Floor11 GOTOmsdos Posted 2006-06-30 20:36
铂金会员 Posts 1,827 Credits 5,154
Calling the extended 13h interrupt in C language to read and write large hard drives is solved!

The main code is as follows: (tested correctly)

#include <dos.h>
#include <stdio.h>
void main(){
unsigned char buf[51200];
FILE *f;
union REGS in,out;
struct DiskAddressPacket
{
unsigned char PacketSize; /* Packet size (16 bytes) */
unsigned char Reserved; /* ==0 */
unsigned int BlockCount; /* Number of data blocks to transfer (in sectors) */
unsigned long BufferAddr;/* Transfer buffer address (segment:offset) */
unsigned long BlockNum;/* Starting absolute block address of the disk */
/*unsigned long ab; */
}dap={16,0,100,0,16434495};
dap.BufferAddr=(unsigned long)buf;

in.h.ah = 0x42;
in.h.dl = 0x80;
in.x.si = &dap;
/* Disk Address Packet (Disk Address Packet) */

int86(0x13,&in,&out);

f=fopen("int13ext.dat","wb+");
fwrite(buf,512,100,f);
fclose(f);
}
Floor12 GOTOmsdos Posted 2006-06-30 20:41
铂金会员 Posts 1,827 Credits 5,154
Also found a small oddity:
In the program for testing my read/write small hard disk,按理说it should only be able to read and write 1023 (3FF, 1111111111) cylinders (0-1022)
But, it can read and write 1024 cylinders!
Puzzled!
Anyone who knows, please speak up...
Floor13 GOTOmsdos Posted 2006-06-30 20:49
铂金会员 Posts 1,827 Credits 5,154
TO DOSforever:
In DEBUG, you first need to load the DAP, right?
How did you load it?
Floor14 DOSforever Posted 2006-06-30 22:07
金牌会员 Posts 2,239 Credits 4,639
Hehe he he……
It was , didn't I write above how it was ? Pay attention to the middle

-e2000 10 00 01 00 33 33 33 33 00 00 00 00 00 00 00 00

That line. That is, manually fill in a specific parameter to test the extended call of int13h.

Originally, the forum where I posted this was DVBBS, and after switching to DISCUZ!, there was some deformation in typesetting. What should be line-wrapped is not line-wrapped, all crowded together.
Floor15 GOTOmsdos Posted 2006-07-01 00:55
铂金会员 Posts 1,827 Credits 5,154
Oh, I didn't pay much attention just now,
Now, I know, I'll try it later...
Thanks.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023