1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 * DOS interrupt 2fh handler
5 * Cdrom - device driver emulation - Audio features.
6 * Copyright (c) 1998 Petr Tomasek <tomasek@etf.cuni.cz>
7 * Copyright (c) 1999,2002 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 #define WIN32_NO_STATUS
30 #define NONAMELESSUNION
31 #include "wine/winbase16.h"
32 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(int);
41 /* base KERNEL ordinal number for VxDs */
46 DOS_DEVICE_HEADER hdr
;
48 WORD reserved
; /* must be 0 */
49 BYTE drive
; /* drive letter (0=A:, 1=B:, ...) */
50 BYTE units
; /* number of supported units */
51 } CDROM_DEVICE_HEADER
;
55 CDROM_DEVICE_HEADER hdr
;
58 WORD cdrom_segment
; /* Real mode segment for CDROM_HEAP */
59 WORD cdrom_selector
; /* Protected mode selector for CDROM_HEAP */
62 static void do_int2f_16( CONTEXT
*context
);
63 static void MSCDEX_Handler( CONTEXT
*context
);
65 /**********************************************************************
68 * Handler for int 2fh (multiplex).
70 void WINAPI
DOSVM_Int2fHandler( CONTEXT
*context
)
72 TRACE("Subfunction 0x%X\n", AX_reg(context
));
74 switch(AH_reg(context
))
77 SET_AL( context
, 0xff ); /* share is installed */
80 case 0x11: /* Network Redirector / IFSFUNC */
81 switch (LOBYTE(context
->Eax
))
83 case 0x00: /* Install check */
86 case 0x80: /* Enhanced services - Install check */
90 INT_BARF( context
, 0x2f );
96 switch (LOBYTE(context
->Eax
))
98 case 0x2e: /* get or set DOS error table address */
99 switch (DL_reg(context
))
101 /* Four tables: even commands are 'get', odd are 'set' */
102 /* DOS 5.0+ ignores "set" commands */
109 /* Instead of having a message table in DOS-space, */
110 /* we can use a special case for MS-DOS to force */
111 /* the secondary interface. */
116 context
->SegEs
= 0x0001;
117 SET_DI( context
, 0x0000 );
120 FIXME("No real-mode handler for errors yet! (bye!)\n");
123 INT_BARF(context
, 0x2f);
127 INT_BARF(context
, 0x2f);
131 case 0x15: /* mscdex */
132 MSCDEX_Handler(context
);
136 do_int2f_16( context
);
139 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
140 /* Not supported yet, do nothing */
145 switch (LOBYTE(context
->Eax
))
147 case 0x00: /* XMS v2+ installation check */
148 WARN("XMS is not fully implemented\n");
149 SET_AL( context
, 0x80 );
151 case 0x10: /* XMS v2+ get driver address */
153 context
->SegEs
= DOSVM_dpmi_segments
->xms_seg
;
154 SET_BX( context
, 0 );
158 INT_BARF( context
, 0x2f );
161 FIXME("check for XMS (not supported)\n");
162 SET_AL( context
, 0x42 ); /* != 0x80 */
167 switch (LOBYTE(context
->Eax
))
178 /* Microsoft Profiler - not installed */
181 INT_BARF( context
, 0x2f );
186 switch(LOBYTE(context
->Eax
))
188 case 0x10: /* smartdrv */
189 break; /* not installed */
190 case 0x11: /* dblspace */
191 break; /* not installed */
192 case 0x12: /* realtime compression interface */
193 break; /* not installed */
194 case 0x32: /* patch IO.SYS (???) */
195 break; /* we have no IO.SYS, so we can't patch it :-/ */
197 INT_BARF( context
, 0x2f );
201 switch(LOBYTE(context
->Eax
))
208 FIXME("Task Switcher - not implemented\n");
211 INT_BARF( context
, 0x2f );
214 case 0x56: /* INTERLNK */
215 switch(LOBYTE(context
->Eax
))
217 case 0x01: /* check if redirected drive */
218 SET_AL( context
, 0 ); /* not redirected */
221 INT_BARF( context
, 0x2f );
224 case 0x7a: /* NOVELL NetWare */
225 switch (LOBYTE(context
->Eax
))
227 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
228 SET_AL( context
, 0 );
230 case 0x20: /* Get VLM Call Address */
231 /* return nothing -> NetWare not installed */
234 INT_BARF( context
, 0x2f );
238 case 0xb7: /* append */
239 SET_AL( context
, 0 ); /* not installed */
241 case 0xb8: /* network */
242 switch (LOBYTE(context
->Eax
))
244 case 0x00: /* Install check */
248 INT_BARF( context
, 0x2f );
253 if (AL_reg(context
) == 0x00 && BX_reg(context
) == 0x3f3f) {
254 /* MVSOUND.SYS - Install check: not installed */
256 INT_BARF( context
, 0x2f );
259 case 0xbd: /* some Novell network install check ??? */
260 SET_AX( context
, 0xa5a5 ); /* pretend to have Novell IPX installed */
262 case 0xbf: /* REDIRIFS.EXE */
263 switch (LOBYTE(context
->Eax
))
265 case 0x00: /* Install check */
269 INT_BARF( context
, 0x2f );
274 switch(LOBYTE(context
->Eax
))
276 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
277 if(BX_reg(context
) == 0x5145 && CX_reg(context
) == 0x4D4D
278 && DX_reg(context
) == 0x3432)
279 TRACE("Check for QEMM v5.0+ (not installed)\n");
282 INT_BARF( context
, 0x2f );
286 case 0xd7: /* Banyan Vines */
287 switch (LOBYTE(context
->Eax
))
289 case 0x01: /* Install check - Get Int Number */
293 INT_BARF( context
, 0x2f );
298 switch(LOBYTE(context
->Eax
))
300 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
301 if(BX_reg(context
) == 0x4450 && CX_reg(context
) == 0x4d49
302 && DX_reg(context
) == 0x8f4f)
303 TRACE("Check for QDPMI.SYS (not installed)\n");
306 INT_BARF( context
, 0x2f );
310 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
313 INT_BARF( context
, 0x2f );
319 /**********************************************************************
322 static void do_int2f_16( CONTEXT
*context
)
326 switch(LOBYTE(context
->Eax
))
328 case 0x00: /* Windows enhanced mode installation check */
329 SET_AX( context
, LOWORD(GetVersion16()) );
332 case 0x0a: /* Get Windows version and type */
333 SET_AX( context
, 0 );
334 SET_BX( context
, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
335 SET_CX( context
, 3 );
338 case 0x0b: /* Identify Windows-aware TSRs */
339 /* we don't have any pre-Windows TSRs */
342 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
343 /* We can mock this up. But not today... */
344 FIXME("Get Shell Parameters\n");
347 case 0x80: /* Release time-slice */
348 /* Linux sched_yield() still keeps burning CPU cycles
349 * if the current process is the only one in highest priority list
350 * (as Linux will immediately return to this process to waste
351 * more CPU cycles), so sched_yield() is essentially useless for us
352 * (poor API, if you ask me: its return code should indicate
353 * whether other processes did run in between, in order for us
354 * to be able to decide whether to do an additional Sleep() or not...)
355 * Thus we better unconditionally use a well-balanced Sleep()
356 * instead to really make sure the process calling int 0x2f/0x1680
357 * *doesn't* use 100% CPU...
359 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
360 SET_AL( context
, 0 );
363 case 0x81: /* Begin critical section. */
367 case 0x82: /* End critical section. */
371 case 0x83: /* Return Current Virtual Machine ID */
372 /* Virtual Machines are usually created/destroyed when Windows runs
373 * DOS programs. Since we never do, we are always in the System VM.
374 * According to Ralf Brown's Interrupt List, never return 0. But it
375 * seems to work okay (returning 0), just to be sure we return 1.
377 SET_BX( context
, 1 ); /* VM 1 is probably the System VM */
380 case 0x84: /* Get device API entry point */
382 HMODULE16 mod
= GetModuleHandle16("kernel");
383 addr
= (DWORD
)GetProcAddress16( mod
, (LPCSTR
)(VXD_BASE
+ BX_reg(context
)) );
384 if (!addr
) /* not supported */
385 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context
) );
386 context
->SegEs
= SELECTOROF(addr
);
387 SET_DI( context
, OFFSETOF(addr
) );
391 case 0x86: /* DPMI detect mode */
392 SET_AX( context
, 0 ); /* Running under DPMI */
395 case 0x87: /* DPMI installation check */
399 SET_AX( context
, 0x0000 ); /* DPMI Installed */
400 SET_BX( context
, 0x0001 ); /* 32bits available */
401 SET_CL( context
, si
.wProcessorLevel
);
402 SET_DX( context
, 0x005a ); /* DPMI major/minor 0.90 */
403 SET_SI( context
, 0 ); /* # of para. of DOS extended private data */
404 context
->SegEs
= DOSVM_dpmi_segments
->dpmi_seg
;
405 SET_DI( context
, 0 ); /* ES:DI is DPMI switch entry point */
408 case 0x8a: /* DPMI get vendor-specific API entry point. */
409 /* The 1.0 specs say this should work with all 0.9 hosts. */
413 INT_BARF( context
, 0x2f );
417 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
418 * must be <size> aligned
419 * <size> could be WORD, DWORD...
420 * in this case, we would need two macros, one for read, the other one for write
421 * Note: PTR_AT can be used as an l-value
423 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
425 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
427 /**********************************************************************
428 * MSCDEX_Dump [internal]
430 * Dumps mscdex requests to int debug channel.
432 static void MSCDEX_Dump(char* pfx
, BYTE
* req
, int dorealmode
)
440 ptr
+= sprintf(ptr
, "%s\tCommand => ", pfx
);
441 for (i
= 0; i
< req
[0]; i
++) {
442 ptr
+= sprintf(ptr
, "%02x ", req
[i
]);
448 ptr
+= sprintf(ptr
, "\n\t\t\t\tIO_struct => ");
449 ios
= (dorealmode
) ? PTR_REAL_TO_LIN( PTR_AT(req
, 16, WORD
), PTR_AT(req
, 14, WORD
)) :
450 MapSL(MAKESEGPTR(PTR_AT(req
, 16, WORD
), PTR_AT(req
, 14, WORD
)));
452 for (i
= 0; i
< PTR_AT(req
, 18, WORD
); i
++) {
453 ptr
+= sprintf(ptr
, "%02x ", ios
[i
]);
454 if ((i
& 0x1F) == 0x1F) {
464 #define MSCDEX_Dump(pfx, req, drm)
467 #define CDFRAMES_PERSEC 75
468 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
469 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
470 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
471 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
472 (toc).TrackData[idx - (toc).FirstTrack].Adr)
474 static void MSCDEX_StoreMSF(DWORD frame
, BYTE
* val
)
476 val
[3] = 0; /* zero */
477 val
[2] = frame
/ CDFRAMES_PERMIN
; /* minutes */
478 val
[1] = (frame
/ CDFRAMES_PERSEC
) % 60; /* seconds */
479 val
[0] = frame
% CDFRAMES_PERSEC
; /* frames */
482 static BOOL
is_cdrom(int drive
)
484 char root
[] = "A:\\";
486 return (GetDriveTypeA(root
) == DRIVE_CDROM
);
489 /***********************************************************************
492 * Initialize CDROM heap.
495 static void CDROM_FillHeap( CDROM_HEAP
*heap
)
499 /* Count the number of contiguous CDROM drives
501 for (drive
= count
= 0; drive
< 26; drive
++) {
502 if (is_cdrom(drive
)) {
503 while (is_cdrom(drive
+ count
)) count
++;
507 TRACE("Installation check: %d cdroms, starting at %d\n", count
, drive
);
508 heap
->hdr
.drive
= (drive
< 26) ? drive
: 0;
509 heap
->hdr
.units
= count
;
510 heap
->hdr
.reserved
= 0;
513 /**********************************************************************
516 * Get pointer for CDROM heap (CDROM_HEAP).
517 * Creates and initializes heap on first call.
519 static CDROM_HEAP
*CDROM_GetHeap( void )
521 static CDROM_HEAP
*heap_pointer
= NULL
;
528 /* allocate a new DOS data segment */
529 heap_pointer
= DOSVM_AllocDataUMB( sizeof(CDROM_HEAP
),
533 heap_pointer
->cdrom_segment
= heap_segment
;
534 heap_pointer
->cdrom_selector
= heap_selector
;
535 CDROM_FillHeap( heap_pointer
);
541 static void MSCDEX_Request(BYTE
*driver_request
, BOOL dorealmode
)
544 BYTE Error
= 255; /* No Error */
545 char devName
[] = "\\\\.\\@:";
548 CDROM_SUB_Q_DATA_FORMAT fmt
;
549 SUB_Q_CHANNEL_DATA data
;
554 * the following tests are wrong because lots of functions don't require the
555 * tray to be closed with a CD inside
557 TRACE("CDROM device driver -> command <%d>\n", driver_request
[2]);
559 MSCDEX_Dump("Beg", driver_request
, dorealmode
);
561 /* set status to 0 */
562 PTR_AT(driver_request
, 3, WORD
) = 0;
563 devName
[4] = 'A' + CDROM_GetHeap()->hdr
.drive
+ driver_request
[1];
564 h
= CreateFileA(devName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
565 if (h
== INVALID_HANDLE_VALUE
) {
566 WARN("Couldn't open cdrom handle\n");
567 driver_request
[4] |= 0x80;
568 driver_request
[3] = 1; /* unknown unit */
572 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
573 if (!DeviceIoControl(h
, IOCTL_CDROM_READ_TOC
, NULL
, 0, &toc
, sizeof(toc
), &br
, NULL
) ||
574 !DeviceIoControl(h
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
575 &data
, sizeof(data
), &br
, NULL
)) {
576 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE
)
578 if (driver_request
[2] != 6 && driver_request
[2] != 15)
580 driver_request
[4] |= 0x80;
581 driver_request
[3] = 2; /* drive not ready */
589 driver_request
[4] |= 0x80;
590 driver_request
[3] = 1; /* unknown unit */
596 switch (driver_request
[2]) {
598 io_stru
= (dorealmode
) ?
599 PTR_REAL_TO_LIN( PTR_AT(driver_request
, 16, WORD
), PTR_AT(driver_request
, 14, WORD
) ) :
600 MapSL( MAKESEGPTR(PTR_AT(driver_request
, 16, WORD
), PTR_AT(driver_request
, 14, WORD
)));
602 TRACE(" --> IOCTL INPUT <%d>\n", io_stru
[0]);
603 switch (io_stru
[0]) {
605 case 0: /* Get device Header */
607 static LPSTR ptr
= 0;
609 ptr
= SEGPTR_ALLOC(22);
610 PTR_AT(ptr
, 0, DWORD
) = ~1; /* Next Device Driver */
611 PTR_AT(ptr
, 4, WORD
) = 0xC800; /* Device attributes */
612 PTR_AT(ptr
, 6, WORD
) = 0x1234; /* Pointer to device strategy routine: FIXME */
613 PTR_AT(ptr
, 8, WORD
) = 0x3142; /* Pointer to device interrupt routine: FIXME */
614 PTR_AT(ptr
, 10, char) = 'W'; /* 8-byte character device name field */
615 PTR_AT(ptr
, 11, char) = 'I';
616 PTR_AT(ptr
, 12, char) = 'N';
617 PTR_AT(ptr
, 13, char) = 'E';
618 PTR_AT(ptr
, 14, char) = '_';
619 PTR_AT(ptr
, 15, char) = 'C';
620 PTR_AT(ptr
, 16, char) = 'D';
621 PTR_AT(ptr
, 17, char) = '_';
622 PTR_AT(ptr
, 18, WORD
) = 0; /* Reserved (must be zero) */
623 PTR_AT(ptr
, 20, BYTE
) = 0; /* Drive letter (must be zero) */
624 PTR_AT(ptr
, 21, BYTE
) = 1; /* Number of units supported (one or more) FIXME*/
626 PTR_AT(io_stru
, DWORD
, 0) = SEGPTR_GET(ptr
);
631 case 1: /* location of head */
632 switch (io_stru
[1]) {
634 PTR_AT(io_stru
, 2, DWORD
) =
635 FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
);
638 MSCDEX_StoreMSF(FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
),
642 ERR("CD-ROM driver: unsupported addressing mode !!\n");
645 TRACE(" ----> HEAD LOCATION <%d>\n", PTR_AT(io_stru
, 2, DWORD
));
648 case 4: /* Audio channel info */
657 TRACE(" ----> AUDIO CHANNEL INFO\n");
660 case 6: /* device status */
661 PTR_AT(io_stru
, 1, DWORD
) = 0x00000290;
663 * 1 Supports HSG and Red Book addressing modes
664 * 0 Supports audio channel manipulation
666 * 1 Supports prefetching requests
669 * 1 Data read and plays audio/video tracks
672 * 0 Supports only cooked reading
674 * 0 see below (Door closed/opened)
676 if (!present
) PTR_AT(io_stru
, 1, DWORD
) |= 1;
677 TRACE(" ----> DEVICE STATUS <0x%08x>\n", PTR_AT(io_stru
, 1, DWORD
));
680 case 8: /* Volume size */
681 PTR_AT(io_stru
, 1, DWORD
) = FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) -
682 FRAME_OF_TOC(toc
, toc
.FirstTrack
) - 1;
683 TRACE(" ----> VOLUME SIZE <%d>\n", PTR_AT(io_stru
, 1, DWORD
));
686 case 9: /* media changed ? */
687 /* answers don't know... -1/1 for yes/no would be better */
688 io_stru
[1] = 0; /* FIXME? 1? */
689 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru
[1]);
692 case 10: /* audio disk info */
693 io_stru
[1] = toc
.FirstTrack
; /* starting track of the disc */
694 io_stru
[2] = toc
.LastTrack
; /* ending track */
695 MSCDEX_StoreMSF(FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) -
696 FRAME_OF_TOC(toc
, toc
.FirstTrack
) - 1, io_stru
+ 3);
698 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08x>\n",
699 io_stru
[1], io_stru
[2], PTR_AT(io_stru
, 3, DWORD
));
702 case 11: /* audio track info */
703 if (io_stru
[1] >= toc
.FirstTrack
&& io_stru
[1] <= toc
.LastTrack
) {
704 MSCDEX_StoreMSF(FRAME_OF_TOC(toc
, io_stru
[1]), io_stru
+ 2);
705 /* starting point if the track */
706 io_stru
[6] = CTRL_OF_TOC(toc
, io_stru
[1]);
708 PTR_AT(io_stru
, 2, DWORD
) = 0;
711 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08x:%d]\n",
712 io_stru
[1], PTR_AT(io_stru
, 2, DWORD
), io_stru
[6]);
715 case 12: /* get Q-Channel info */
716 io_stru
[1] = CTRL_OF_TOC(toc
, data
.CurrentPosition
.TrackNumber
);
717 io_stru
[2] = data
.CurrentPosition
.TrackNumber
;
718 io_stru
[3] = 0; /* FIXME ?? */
720 /* why the heck did MS use another format for 0MSF information... sigh */
724 MSCDEX_StoreMSF(FRAME_OF_ADDR(data
.CurrentPosition
.TrackRelativeAddress
), bTmp
);
725 io_stru
[ 4] = bTmp
[2];
726 io_stru
[ 5] = bTmp
[1];
727 io_stru
[ 6] = bTmp
[0];
730 MSCDEX_StoreMSF(FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
), bTmp
);
731 io_stru
[ 8] = bTmp
[2];
732 io_stru
[ 9] = bTmp
[1];
733 io_stru
[10] = bTmp
[0];
736 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
737 io_stru
[ 1], io_stru
[ 2], io_stru
[ 3],
738 io_stru
[ 4], io_stru
[ 5], io_stru
[ 6],
739 io_stru
[ 8], io_stru
[ 9], io_stru
[10],
740 FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
),
741 FRAME_OF_TOC(toc
, data
.CurrentPosition
.TrackNumber
));
744 case 15: /* Audio status info */
745 /* !!!! FIXME FIXME FIXME !! */
746 PTR_AT(io_stru
, 1, WORD
) = 2 | ((data
.CurrentPosition
.Header
.AudioStatus
== AUDIO_STATUS_PAUSED
) ? 1 : 0);
748 PTR_AT(io_stru
, 3, DWORD
) = 0;
749 PTR_AT(io_stru
, 7, DWORD
) = 0;
751 PTR_AT(io_stru
, 3, DWORD
) = FRAME_OF_TOC(toc
, toc
.FirstTrack
);
752 PTR_AT(io_stru
, 7, DWORD
) = FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1);
754 TRACE("Audio status info: status=%04x startLoc=%d endLoc=%d\n",
755 PTR_AT(io_stru
, 1, WORD
), PTR_AT(io_stru
, 3, DWORD
), PTR_AT(io_stru
, 7, DWORD
));
759 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru
[0]);
766 io_stru
= (dorealmode
) ?
767 PTR_REAL_TO_LIN( PTR_AT(driver_request
, 16, WORD
), PTR_AT(driver_request
, 14, WORD
)) :
768 MapSL( MAKESEGPTR(PTR_AT(driver_request
, 16, WORD
), PTR_AT(driver_request
, 14, WORD
)));
770 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru
[0]);
771 switch (io_stru
[0]) {
773 DeviceIoControl(h
, IOCTL_STORAGE_EJECT_MEDIA
, NULL
, 0, NULL
, 0, &br
, NULL
);
774 TRACE(" ----> EJECT\n");
776 case 2: /* reset drive */
777 DeviceIoControl(h
, IOCTL_STORAGE_RESET_DEVICE
, NULL
, 0, NULL
, 0, &br
, NULL
);
778 TRACE(" ----> RESET\n");
780 case 3: /* Audio Channel Control */
781 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
783 case 5: /* close tray */
784 DeviceIoControl(h
, IOCTL_STORAGE_LOAD_MEDIA
, NULL
, 0, NULL
, 0, &br
, NULL
);
785 TRACE(" ----> CLOSE TRAY\n");
788 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru
[0]);
794 case 128: /* read long */
796 LPVOID dst
= MapSL(MAKESEGPTR(PTR_AT(driver_request
, 16, WORD
),
797 PTR_AT(driver_request
, 14, WORD
)));
798 DWORD at
= PTR_AT(driver_request
, 20, DWORD
);
799 WORD num
= PTR_AT(driver_request
, 18, WORD
);
802 switch (driver_request
[13]) {
803 case 1: /* Red book addressing mode = 0:m:s:f */
804 /* FIXME : frame <=> msf conversion routines could be shared
805 * between mscdex and mcicda
807 at
= LOBYTE(HIWORD(at
)) * CDFRAMES_PERMIN
+
808 HIBYTE(LOWORD(at
)) * CDFRAMES_PERSEC
+
811 case 0: /* HSG addressing mode */
812 switch (PTR_AT(driver_request
, 24, BYTE
))
815 ReadFile(h
, dst
, num
* 2048, &br
, NULL
);
818 /* FIXME: computation is wrong */
819 rri
.DiskOffset
.u
.HighPart
= 0;
820 rri
.DiskOffset
.u
.LowPart
= at
<< 11;
821 rri
.TrackMode
= YellowMode2
;
822 rri
.SectorCount
= num
;
823 DeviceIoControl(h
, IOCTL_CDROM_RAW_READ
, &rri
, sizeof(rri
),
824 dst
, num
* 2352, &br
, NULL
);
827 ERR("Unsupported read mode !!\n");
833 ERR("Unsupported address mode !!\n");
843 CDROM_SEEK_AUDIO_MSF seek
;
845 at
= PTR_AT(driver_request
, 20, DWORD
);
847 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%d]\n", driver_request
[13], at
);
849 switch (driver_request
[13]) {
850 case 1: /* Red book addressing mode = 0:m:s:f */
851 /* FIXME : frame <=> msf conversion routines could be shared
852 * between mscdex and mcicda
854 at
= LOBYTE(HIWORD(at
)) * CDFRAMES_PERMIN
+
855 HIBYTE(LOWORD(at
)) * CDFRAMES_PERSEC
+
858 case 0: /* HSG addressing mode */
859 seek
.M
= at
/ CDFRAMES_PERMIN
;
860 seek
.S
= (at
/ CDFRAMES_PERSEC
) % 60;
861 seek
.F
= at
% CDFRAMES_PERSEC
;
862 DeviceIoControl(h
, IOCTL_CDROM_SEEK_AUDIO_MSF
, &seek
, sizeof(seek
),
866 ERR("Unsupported address mode !!\n");
876 CDROM_PLAY_AUDIO_MSF play
;
878 beg
= end
= PTR_AT(driver_request
, 14, DWORD
);
879 end
+= PTR_AT(driver_request
, 18, DWORD
);
881 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%d-%d]\n", driver_request
[13], beg
, end
);
883 switch (driver_request
[13]) {
885 /* Red book addressing mode = 0:m:s:f */
886 /* FIXME : frame <=> msf conversion routines could be shared
887 * between mscdex and mcicda
889 beg
= LOBYTE(LOWORD(beg
)) * CDFRAMES_PERMIN
+
890 HIBYTE(LOWORD(beg
)) * CDFRAMES_PERSEC
+
892 end
= LOBYTE(LOWORD(end
)) * CDFRAMES_PERMIN
+
893 HIBYTE(LOWORD(end
)) * CDFRAMES_PERSEC
+
896 case 0: /* HSG addressing mode */
897 play
.StartingM
= beg
/ CDFRAMES_PERMIN
;
898 play
.StartingS
= (beg
/ CDFRAMES_PERSEC
) % 60;
899 play
.StartingF
= beg
% CDFRAMES_PERSEC
;
900 play
.EndingM
= end
/ CDFRAMES_PERMIN
;
901 play
.EndingS
= (end
/ CDFRAMES_PERSEC
) % 60;
902 play
.EndingF
= end
% CDFRAMES_PERSEC
;
903 DeviceIoControl(h
, IOCTL_CDROM_PLAY_AUDIO_MSF
, &play
, sizeof(play
),
907 ERR("Unsupported address mode !!\n");
915 if (data
.CurrentPosition
.Header
.AudioStatus
== AUDIO_STATUS_IN_PROGRESS
) {
916 DeviceIoControl(h
, IOCTL_CDROM_PAUSE_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
);
917 TRACE(" --> STOP AUDIO (Paused)\n");
919 DeviceIoControl(h
, IOCTL_CDROM_STOP_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
);
920 TRACE(" --> STOP AUDIO (Stopped)\n");
925 TRACE(" --> RESUME AUDIO\n");
926 DeviceIoControl(h
, IOCTL_CDROM_PAUSE_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
);
930 FIXME(" ioctl unimplemented <%d>\n", driver_request
[2]);
934 /* setting error codes if any */
936 driver_request
[4] |= 0x80;
937 driver_request
[3] = Error
;
941 /* setting status bits
942 * 3 == playing && done
946 (data
.CurrentPosition
.Header
.AudioStatus
== AUDIO_STATUS_IN_PROGRESS
) ? 3 : 1;
948 MSCDEX_Dump("End", driver_request
, dorealmode
);
951 static void MSCDEX_Handler(CONTEXT
* context
)
956 switch (LOBYTE(context
->Eax
)) {
957 case 0x00: /* Installation check */
958 /* Count the number of contiguous CDROM drives
960 for (drive
= count
= 0; drive
< 26; drive
++) {
961 if (is_cdrom(drive
)) {
962 while (is_cdrom(drive
+ count
)) count
++;
966 TRACE("Installation check: %d cdroms, starting at %d\n", count
, drive
);
967 SET_BX( context
, count
);
968 SET_CX( context
, (drive
< 26) ? drive
: 0 );
971 case 0x01: /* get drive device list */
973 CDROM_HEAP
* cdrom_heap
= CDROM_GetHeap();
974 CDROM_DEVICE_HEADER
* dev
= &cdrom_heap
->hdr
;
975 SEGPTR ptr_dev
= ISV86(context
)
976 ? MAKESEGPTR( cdrom_heap
->cdrom_segment
,
977 FIELD_OFFSET(CDROM_HEAP
, hdr
) )
978 : MAKESEGPTR( cdrom_heap
->cdrom_selector
,
979 FIELD_OFFSET(CDROM_HEAP
, hdr
) );
981 p
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
982 for (drive
= 0; drive
< dev
->units
; drive
++) {
983 *p
= drive
; /* subunit */
985 *(DWORD
*)p
= ptr_dev
;
988 TRACE("Get drive device list\n");
992 case 0x0B: /* drive check */
993 SET_AX( context
, is_cdrom(CX_reg(context
)) );
994 SET_BX( context
, 0xADAD );
997 case 0x0C: /* get version */
998 SET_BX( context
, 0x020a );
999 TRACE("Version number => %04x\n", BX_reg(context
));
1002 case 0x0D: /* get drive letters */
1003 p
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
1005 for (drive
= 0; drive
< 26; drive
++) {
1006 if (is_cdrom(drive
)) *p
++ = drive
;
1008 TRACE("Get drive letters\n");
1011 case 0x10: /* direct driver access */
1013 BYTE
* driver_request
;
1014 CDROM_HEAP
* cdrom_heap
= CDROM_GetHeap();
1016 if (!is_cdrom(CX_reg(context
))) {
1017 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context
));
1018 SET_CFLAG( context
);
1019 SET_AX( context
, 0x000f ); /* invalid drive */
1023 driver_request
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
1025 if (!driver_request
) {
1026 /* FIXME - to be deleted ?? */
1027 ERR("ES:BX==0 ! SEGFAULT ?\n");
1028 ERR("-->BX=0x%04x, ES=0x%04x, DS=0x%04x, CX=0x%04x\n",
1029 BX_reg(context
), context
->SegEs
, context
->SegDs
, CX_reg(context
));
1030 driver_request
[4] |= 0x80;
1031 driver_request
[3] = 5; /* bad request length */
1035 driver_request
[1] = CX_reg(context
) - cdrom_heap
->hdr
.drive
;
1036 MSCDEX_Request(driver_request
, ISV86(context
));
1040 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context
->Eax
));
1046 static void WINAPI
cdrom_strategy(CONTEXT
*ctx
);
1047 static void WINAPI
cdrom_interrupt(CONTEXT
*ctx
);
1050 static const WINEDEV cdromdev
=
1053 ATTR_CHAR
|ATTR_REMOVABLE
|ATTR_IOCTL
,
1054 cdrom_strategy
, cdrom_interrupt
1057 static REQUEST_HEADER
*cdrom_driver_request
;
1059 /* Return to caller */
1060 static void do_lret(CONTEXT
*ctx
)
1062 WORD
*stack
= CTX_SEG_OFF_TO_LIN(ctx
, ctx
->SegSs
, ctx
->Esp
);
1064 ctx
->Eip
= *(stack
++);
1065 ctx
->SegCs
= *(stack
++);
1066 ctx
->Esp
+= 2*sizeof(WORD
);
1069 static void WINAPI
cdrom_strategy(CONTEXT
*ctx
)
1071 cdrom_driver_request
= CTX_SEG_OFF_TO_LIN(ctx
, ctx
->SegEs
, ctx
->Ebx
);
1075 static void WINAPI
cdrom_interrupt(CONTEXT
*ctx
)
1077 if (cdrom_driver_request
->unit
> CDROM_GetHeap()->hdr
.units
)
1078 cdrom_driver_request
->status
= STAT_ERROR
| 1; /* unknown unit */
1080 MSCDEX_Request((BYTE
*)cdrom_driver_request
, ISV86(ctx
));
1085 /**********************************************************************
1086 * MSCDEX_InstallCDROM [internal]
1088 * Install the CDROM driver into the DOS device driver chain.
1090 void MSCDEX_InstallCDROM(void)
1092 CDROM_HEAP
*cdrom_heap
= CDROM_GetHeap();
1094 DOSDEV_SetupDevice( &cdromdev
,
1095 cdrom_heap
->cdrom_segment
,
1096 FIELD_OFFSET(CDROM_HEAP
, hdr
),
1097 FIELD_OFFSET(CDROM_HEAP
, thunk
) );