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-08-01 22:13
中国DOS联盟论坛 » DOS开发编程 & 发展交流 (开发室) » How to write a program in C language to control the CD-ROM drive? View 2,121 Replies 13
Original Poster Posted 2004-08-19 00:00 ·  中国 云南 红河哈尼族彝族自治州 开远市 电信
中级用户
★★
Credits 478
Posts 132
Joined 2003-07-02 00:00
23-year member
UID 6296
Gender Male
Status Offline
Found some materials, all are in assembly, but I don't understand assembly. How to write it in C language? Thanks
Floor 2 Posted 2004-08-19 00:00 ·  中国 河北 唐山 联通
初级用户
Credits 183
Posts 31
Joined 2002-11-30 00:00
23-year member
UID 371
Gender Male
Status Offline
One should know one's limits, and should not be overreaching!
我的论坛 http://zjp-vlk.vicp.net/bbs 我在它就在!
Floor 3 Posted 2004-08-20 00:00 ·  中国 辽宁 抚顺 联通
银牌会员
★★★
Credits 1,186
Posts 510
Joined 2004-07-30 00:00
22-year member
UID 29279
Gender Male
Status Offline
Is the English of the 2nd floor very good? Translate some shares!
Floor 4 Posted 2004-08-20 00:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
The following program is a small program I shrank from a CD player program a few years ago to open and close the CD drive, for you to play with. But there is a shortcoming, it can only run in pure DOS. When running in the DOS window of Win9x, if there is no disc in the CD drive, it cannot be opened, but it can be closed.

#include<dos.h>
int ppp=0;
unsigned int cdnum;
char getbuff,setbuff;
char stop={0x0d,0,0x85,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char setcd={0x1a,0,0x0c,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
char getcd={0x1a,0,0x03,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

main()
{int i; char ch;
_BX=0;
_AX=0x1500;
geninterrupt(0x2f);
if(ppp==0){cdnum=_CX;ppp=1;}
_AX=FP_OFF(getbuff);
_BX=FP_SEG(getbuff);
getcd=_AL;
getcd=_AH;
getcd=_BL;
getcd=_BH;
_AX=FP_OFF(setbuff);
_BX=FP_SEG(setbuff);
setcd=_AL;
setcd=_AH;
setcd=_BL;
setcd=_BH;
for(i=0;i<2;i++)
{
getcd=5;
getbuff=0x06;
_ES=FP_SEG(getcd);
_BX=FP_OFF(getcd);
_CX=cdnum;
_AX=0x1510;
geninterrupt(0x2f);
}
ch=getbuff&0x01;
if(ch==0)i=0;
else i=1;
if(i==0)
{_ES=FP_SEG(stop); /*Stop CD*/
_BX=FP_OFF(stop);
_CX=cdnum;
_AX=0x1510;
geninterrupt(0x2f);
setcd=1; /*Open CD*/
setbuff=0;
_ES=FP_SEG(setcd);
_BX=FP_OFF(setcd);
_CX=cdnum;
_AX=0x1510;
geninterrupt(0x2f);
}
else
{ /*Close CD*/
setcd=1;
setbuff=5;
_ES=FP_SEG(setcd);
_BX=FP_OFF(setcd);
_CX=cdnum;
_AX=0x1510;
geninterrupt(0x2f);
}
}


[ Last edited by JonePeng on 2006-5-1 at 00:48 ]
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 5 Posted 2004-08-21 00:00 ·  中国 云南 红河哈尼族彝族自治州 个旧市 电信
中级用户
★★
Credits 478
Posts 132
Joined 2003-07-02 00:00
23-year member
UID 6296
Gender Male
Status Offline
The following is the statement from zhaojinpo on 2004-8-19 22:22:40: You can see the introduction from http://www.he.net/~marcj/cdrom.html! The source code is at ftp://ftp.he.net/pub/marcj/cdrom.c

Floor 6 Posted 2004-08-23 00:00 ·  中国 广东 广州 白云区 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
ftp://ftp.he.net/pub/marcj/cdrom.c I tried it, but there seems to be some problem. Why is there no reaction from the CD drive? It doesn't open, close, or read the disc! The LZ means to compile a program to open and close the CD drive, and the above C program I adapted works well. Rename the compiled EXE to EJ.EXE. Just press EJ and hit Enter under DOS to open the CD drive, and input again to close it. I always like to use it. ^_^
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 7 Posted 2004-08-25 00:00 ·  中国 云南 红河哈尼族彝族自治州 弥勒市 电信
中级用户
★★
Credits 478
Posts 132
Joined 2003-07-02 00:00
23-year member
UID 6296
Gender Male
Status Offline
Yes, I used the file ftp://ftp.he.net/pub/marcj/cdrom.c, but it seems to be of no use and there's no response. The program on the 4th floor is pretty good, thank you.
Floor 8 Posted 2006-04-22 21:18 ·  中国 广西 柳州 电信
初级用户
Credits 70
Posts 22
Joined 2006-04-22 17:34
20-year member
UID 54267
Gender Male
Status Offline
I hope to use port programming instead of interrupts to write??
Floor 9 Posted 2006-04-24 11:39 ·  中国 香港
银牌会员
★★★
阿林
Credits 1,410
Posts 497
Joined 2004-06-28 00:00
22-year member
UID 27551
Gender Male
From 九龍,香港
Status Offline
QCDROM "Assembly Language Master" (I said) produced, supports UltraDMA, quite stable, with SHSUCDX V3.03A (Jack R. Ellis modified version) is even more "fast"!

http://johnson.tmfc.net/freedos

There are QCDROM and SHCDX33A downloads!

[ Last edited by johnsonlam on 2006-4-24 at 11:40 ]
我 的 網 站 - http://optimizr.dyndns.org
Floor 10 Posted 2006-04-25 03:07 ·  中国 广西 柳州 电信
初级用户
Credits 70
Posts 22
Joined 2006-04-22 17:34
20-year member
UID 54267
Gender Male
Status Offline
I want to ask about the statement of the moderator on the 4th floor:
for(i=0;i<2;i++) and ch=getbuff&0x01;
What is the function of i<, and it seems that lt, amp are not defined?

[ Last edited by qingfen on 2006-4-26 at 01:10 ]
Floor 11 Posted 2006-05-01 00:51 ·  中国 广东 广州 电信
金牌会员
★★★★
D◎$ Fαп
Credits 4,562
Posts 1,883
Joined 2004-01-19 00:00
22-year member
UID 15812
Gender Male
From 广东广州
Status Offline
Originally posted by qingfen at 2006-4-25 03:07:
for(i=0;i < 2;i++) and ch=getbuff & 0x01;
What is the function of i <, and it seems that lt and amp are not defined?


Previously, this forum was a DVBBS forum, which was particularly sensitive to the "&" and less-than symbols in the source code, turning "&" into "&amp" and less-than signs into "%lt" and so on. Now the source code on the 4th floor has been updated.
----====≡≡≡≡ 我的至爱,永远是MSDOS!≡≡≡≡====----
Floor 12 Posted 2006-05-03 10:16 ·  中国 黑龙江 大庆 联通
初级用户
Credits 131
Posts 12
Joined 2004-03-02 00:00
22-year member
UID 18948
Gender Male
Status Offline
What is the principle of controlling the CD-ROM drive switch? Are all CD-ROM drives the same? Is there an introduction in some "XXX Interrupt Compendium"?
Floor 13 Posted 2006-05-05 13:12 ·  中国 广西 柳州 电信
初级用户
Credits 70
Posts 22
Joined 2006-04-22 17:34
20-year member
UID 54267
Gender Male
Status Offline
Oh, that's how it is. But how can Windows system be compatible with so many CD-ROM drives? And what's the difference between kernel drivers and device drivers?
Floor 14 Posted 2006-05-05 20:56 ·  中国 广东 中山 电信
高级用户
★★★
Credits 972
Posts 420
Joined 2004-05-16 00:00
22-year member
UID 24467
Gender Male
Status Offline
Bend it yourself regarding ATAPI Spec
平生进退如飙风
Forum Jump: