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
27 #define WIN32_NO_STATUS
28 #include "wine/winbase16.h"
29 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(int);
38 /* base KERNEL ordinal number for VxDs */
43 DOS_DEVICE_HEADER hdr
;
45 WORD reserved
; /* must be 0 */
46 BYTE drive
; /* drive letter (0=A:, 1=B:, ...) */
47 BYTE units
; /* number of supported units */
48 } CDROM_DEVICE_HEADER
;
52 CDROM_DEVICE_HEADER hdr
;
53 WORD cdrom_selector
; /* Protected mode selector for CDROM_HEAP */
56 static void do_int2f_16( CONTEXT
*context
);
57 static void MSCDEX_Handler( CONTEXT
*context
);
59 /**********************************************************************
62 * Handler for int 2fh (multiplex).
64 void WINAPI
DOSVM_Int2fHandler( CONTEXT
*context
)
66 TRACE("Subfunction 0x%X\n", AX_reg(context
));
68 switch(AH_reg(context
))
71 SET_AL( context
, 0xff ); /* share is installed */
74 case 0x11: /* Network Redirector / IFSFUNC */
75 switch (LOBYTE(context
->Eax
))
77 case 0x00: /* Install check */
80 case 0x80: /* Enhanced services - Install check */
84 INT_BARF( context
, 0x2f );
90 switch (LOBYTE(context
->Eax
))
92 case 0x2e: /* get or set DOS error table address */
93 switch (DL_reg(context
))
95 /* Four tables: even commands are 'get', odd are 'set' */
96 /* DOS 5.0+ ignores "set" commands */
103 /* Instead of having a message table in DOS-space, */
104 /* we can use a special case for MS-DOS to force */
105 /* the secondary interface. */
110 context
->SegEs
= 0x0001;
111 SET_DI( context
, 0x0000 );
114 FIXME("No real-mode handler for errors yet! (bye!)\n");
117 INT_BARF(context
, 0x2f);
121 INT_BARF(context
, 0x2f);
125 case 0x15: /* mscdex */
126 MSCDEX_Handler(context
);
130 do_int2f_16( context
);
133 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
134 /* Not supported yet, do nothing */
138 FIXME("check for XMS (not supported)\n");
139 SET_AL( context
, 0x42 ); /* != 0x80 */
143 switch (LOBYTE(context
->Eax
))
154 /* Microsoft Profiler - not installed */
157 INT_BARF( context
, 0x2f );
162 switch(LOBYTE(context
->Eax
))
164 case 0x10: /* smartdrv */
165 break; /* not installed */
166 case 0x11: /* dblspace */
167 break; /* not installed */
168 case 0x12: /* realtime compression interface */
169 break; /* not installed */
170 case 0x32: /* patch IO.SYS (???) */
171 break; /* we have no IO.SYS, so we can't patch it :-/ */
173 INT_BARF( context
, 0x2f );
177 switch(LOBYTE(context
->Eax
))
184 FIXME("Task Switcher - not implemented\n");
187 INT_BARF( context
, 0x2f );
190 case 0x56: /* INTERLNK */
191 switch(LOBYTE(context
->Eax
))
193 case 0x01: /* check if redirected drive */
194 SET_AL( context
, 0 ); /* not redirected */
197 INT_BARF( context
, 0x2f );
200 case 0x7a: /* NOVELL NetWare */
201 switch (LOBYTE(context
->Eax
))
203 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
204 SET_AL( context
, 0 );
206 case 0x20: /* Get VLM Call Address */
207 /* return nothing -> NetWare not installed */
210 INT_BARF( context
, 0x2f );
214 case 0xb7: /* append */
215 SET_AL( context
, 0 ); /* not installed */
217 case 0xb8: /* network */
218 switch (LOBYTE(context
->Eax
))
220 case 0x00: /* Install check */
224 INT_BARF( context
, 0x2f );
229 if (AL_reg(context
) == 0x00 && BX_reg(context
) == 0x3f3f) {
230 /* MVSOUND.SYS - Install check: not installed */
232 INT_BARF( context
, 0x2f );
235 case 0xbd: /* some Novell network install check ??? */
236 SET_AX( context
, 0xa5a5 ); /* pretend to have Novell IPX installed */
238 case 0xbf: /* REDIRIFS.EXE */
239 switch (LOBYTE(context
->Eax
))
241 case 0x00: /* Install check */
245 INT_BARF( context
, 0x2f );
250 switch(LOBYTE(context
->Eax
))
252 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
253 if(BX_reg(context
) == 0x5145 && CX_reg(context
) == 0x4D4D
254 && DX_reg(context
) == 0x3432)
255 TRACE("Check for QEMM v5.0+ (not installed)\n");
258 INT_BARF( context
, 0x2f );
262 case 0xd7: /* Banyan Vines */
263 switch (LOBYTE(context
->Eax
))
265 case 0x01: /* Install check - Get Int Number */
269 INT_BARF( context
, 0x2f );
274 switch(LOBYTE(context
->Eax
))
276 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
277 if(BX_reg(context
) == 0x4450 && CX_reg(context
) == 0x4d49
278 && DX_reg(context
) == 0x8f4f)
279 TRACE("Check for QDPMI.SYS (not installed)\n");
282 INT_BARF( context
, 0x2f );
286 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
289 INT_BARF( context
, 0x2f );
295 /**********************************************************************
298 static void do_int2f_16( CONTEXT
*context
)
302 switch(LOBYTE(context
->Eax
))
304 case 0x00: /* Windows enhanced mode installation check */
305 SET_AX( context
, LOWORD(GetVersion16()) );
308 case 0x0a: /* Get Windows version and type */
309 SET_AX( context
, 0 );
310 SET_BX( context
, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
311 SET_CX( context
, 3 );
314 case 0x0b: /* Identify Windows-aware TSRs */
315 /* we don't have any pre-Windows TSRs */
318 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
319 /* We can mock this up. But not today... */
320 FIXME("Get Shell Parameters\n");
323 case 0x80: /* Release time-slice */
324 /* Linux sched_yield() still keeps burning CPU cycles
325 * if the current process is the only one in highest priority list
326 * (as Linux will immediately return to this process to waste
327 * more CPU cycles), so sched_yield() is essentially useless for us
328 * (poor API, if you ask me: its return code should indicate
329 * whether other processes did run in between, in order for us
330 * to be able to decide whether to do an additional Sleep() or not...)
331 * Thus we better unconditionally use a well-balanced Sleep()
332 * instead to really make sure the process calling int 0x2f/0x1680
333 * *doesn't* use 100% CPU...
335 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
336 SET_AL( context
, 0 );
339 case 0x81: /* Begin critical section. */
343 case 0x82: /* End critical section. */
347 case 0x83: /* Return Current Virtual Machine ID */
348 /* Virtual Machines are usually created/destroyed when Windows runs
349 * DOS programs. Since we never do, we are always in the System VM.
350 * According to Ralf Brown's Interrupt List, never return 0. But it
351 * seems to work okay (returning 0), just to be sure we return 1.
353 SET_BX( context
, 1 ); /* VM 1 is probably the System VM */
356 case 0x84: /* Get device API entry point */
358 HMODULE16 mod
= GetModuleHandle16("kernel");
359 addr
= (DWORD
)GetProcAddress16( mod
, (LPCSTR
)(VXD_BASE
+ BX_reg(context
)) );
360 if (!addr
) /* not supported */
361 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context
) );
362 context
->SegEs
= SELECTOROF(addr
);
363 SET_DI( context
, OFFSETOF(addr
) );
367 case 0x86: /* DPMI detect mode */
368 SET_AX( context
, 0 ); /* Running under DPMI */
371 case 0x87: /* DPMI installation check */
375 SET_AX( context
, 0x0000 ); /* DPMI Installed */
376 SET_BX( context
, 0x0001 ); /* 32bits available */
377 SET_CL( context
, si
.wProcessorLevel
);
378 SET_DX( context
, 0x005a ); /* DPMI major/minor 0.90 */
379 SET_SI( context
, 0 ); /* # of para. of DOS extended private data */
380 context
->SegEs
= 0; /* no DPMI switch */
381 SET_DI( context
, 0 ); /* ES:DI is DPMI switch entry point */
384 case 0x8a: /* DPMI get vendor-specific API entry point. */
385 /* The 1.0 specs say this should work with all 0.9 hosts. */
389 INT_BARF( context
, 0x2f );
393 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
394 * must be <size> aligned
395 * <size> could be WORD, DWORD...
396 * in this case, we would need two macros, one for read, the other one for write
397 * Note: PTR_AT can be used as an l-value
399 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
401 #define CDFRAMES_PERSEC 75
402 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
403 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
404 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
405 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
406 (toc).TrackData[idx - (toc).FirstTrack].Adr)
408 static void MSCDEX_StoreMSF(DWORD frame
, BYTE
* val
)
410 val
[3] = 0; /* zero */
411 val
[2] = frame
/ CDFRAMES_PERMIN
; /* minutes */
412 val
[1] = (frame
/ CDFRAMES_PERSEC
) % 60; /* seconds */
413 val
[0] = frame
% CDFRAMES_PERSEC
; /* frames */
416 static BOOL
is_cdrom(int drive
)
418 char root
[] = "A:\\";
420 return (GetDriveTypeA(root
) == DRIVE_CDROM
);
423 /***********************************************************************
426 * Initialize CDROM heap.
429 static void CDROM_FillHeap( CDROM_HEAP
*heap
)
433 /* Count the number of contiguous CDROM drives
435 for (drive
= count
= 0; drive
< 26; drive
++) {
436 if (is_cdrom(drive
)) {
437 while (is_cdrom(drive
+ count
)) count
++;
441 TRACE("Installation check: %d cdroms, starting at %d\n", count
, drive
);
442 heap
->hdr
.drive
= (drive
< 26) ? drive
: 0;
443 heap
->hdr
.units
= count
;
444 heap
->hdr
.reserved
= 0;
447 /**********************************************************************
450 * Get pointer for CDROM heap (CDROM_HEAP).
451 * Creates and initializes heap on first call.
453 static CDROM_HEAP
*CDROM_GetHeap( void )
455 static CDROM_HEAP
*heap_pointer
= NULL
;
459 WORD heap_selector
= GlobalAlloc16( GMEM_FIXED
| GMEM_ZEROINIT
, sizeof(CDROM_HEAP
) );
460 heap_pointer
= GlobalLock16( heap_selector
);
461 heap_pointer
->cdrom_selector
= heap_selector
;
462 CDROM_FillHeap( heap_pointer
);
468 static void MSCDEX_Request(BYTE
*driver_request
)
471 BYTE Error
= 255; /* No Error */
472 char devName
[] = "\\\\.\\@:";
475 CDROM_SUB_Q_DATA_FORMAT fmt
;
476 SUB_Q_CHANNEL_DATA data
;
481 * the following tests are wrong because lots of functions don't require the
482 * tray to be closed with a CD inside
484 TRACE("CDROM device driver -> command <%d>\n", driver_request
[2]);
486 /* set status to 0 */
487 PTR_AT(driver_request
, 3, WORD
) = 0;
488 devName
[4] = 'A' + CDROM_GetHeap()->hdr
.drive
+ driver_request
[1];
489 h
= CreateFileA(devName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
, 0, 0);
490 if (h
== INVALID_HANDLE_VALUE
) {
491 WARN("Couldn't open cdrom handle\n");
492 driver_request
[4] |= 0x80;
493 driver_request
[3] = 1; /* unknown unit */
497 fmt
.Format
= IOCTL_CDROM_CURRENT_POSITION
;
498 if (!DeviceIoControl(h
, IOCTL_CDROM_READ_TOC
, NULL
, 0, &toc
, sizeof(toc
), &br
, NULL
) ||
499 !DeviceIoControl(h
, IOCTL_CDROM_READ_Q_CHANNEL
, &fmt
, sizeof(fmt
),
500 &data
, sizeof(data
), &br
, NULL
)) {
501 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE
)
503 if (driver_request
[2] != 6 && driver_request
[2] != 15)
505 driver_request
[4] |= 0x80;
506 driver_request
[3] = 2; /* drive not ready */
514 driver_request
[4] |= 0x80;
515 driver_request
[3] = 1; /* unknown unit */
521 switch (driver_request
[2]) {
523 io_stru
= MapSL( MAKESEGPTR(PTR_AT(driver_request
, 16, WORD
), PTR_AT(driver_request
, 14, WORD
)));
525 TRACE(" --> IOCTL INPUT <%d>\n", io_stru
[0]);
526 switch (io_stru
[0]) {
528 case 0: /* Get device Header */
530 static LPSTR ptr
= 0;
532 ptr
= SEGPTR_ALLOC(22);
533 PTR_AT(ptr
, 0, DWORD
) = ~1; /* Next Device Driver */
534 PTR_AT(ptr
, 4, WORD
) = 0xC800; /* Device attributes */
535 PTR_AT(ptr
, 6, WORD
) = 0x1234; /* Pointer to device strategy routine: FIXME */
536 PTR_AT(ptr
, 8, WORD
) = 0x3142; /* Pointer to device interrupt routine: FIXME */
537 PTR_AT(ptr
, 10, char) = 'W'; /* 8-byte character device name field */
538 PTR_AT(ptr
, 11, char) = 'I';
539 PTR_AT(ptr
, 12, char) = 'N';
540 PTR_AT(ptr
, 13, char) = 'E';
541 PTR_AT(ptr
, 14, char) = '_';
542 PTR_AT(ptr
, 15, char) = 'C';
543 PTR_AT(ptr
, 16, char) = 'D';
544 PTR_AT(ptr
, 17, char) = '_';
545 PTR_AT(ptr
, 18, WORD
) = 0; /* Reserved (must be zero) */
546 PTR_AT(ptr
, 20, BYTE
) = 0; /* Drive letter (must be zero) */
547 PTR_AT(ptr
, 21, BYTE
) = 1; /* Number of units supported (one or more) FIXME*/
549 PTR_AT(io_stru
, DWORD
, 0) = SEGPTR_GET(ptr
);
554 case 1: /* location of head */
555 switch (io_stru
[1]) {
557 PTR_AT(io_stru
, 2, DWORD
) =
558 FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
);
561 MSCDEX_StoreMSF(FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
),
565 ERR("CD-ROM driver: unsupported addressing mode !!\n");
568 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru
, 2, DWORD
));
571 case 4: /* Audio channel info */
580 TRACE(" ----> AUDIO CHANNEL INFO\n");
583 case 6: /* device status */
584 PTR_AT(io_stru
, 1, DWORD
) = 0x00000290;
586 * 1 Supports HSG and Red Book addressing modes
587 * 0 Supports audio channel manipulation
589 * 1 Supports prefetching requests
592 * 1 Data read and plays audio/video tracks
595 * 0 Supports only cooked reading
597 * 0 see below (Door closed/opened)
599 if (!present
) PTR_AT(io_stru
, 1, DWORD
) |= 1;
600 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru
, 1, DWORD
));
603 case 8: /* Volume size */
604 PTR_AT(io_stru
, 1, DWORD
) = FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) -
605 FRAME_OF_TOC(toc
, toc
.FirstTrack
) - 1;
606 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru
, 1, DWORD
));
609 case 9: /* media changed ? */
610 /* answers don't know... -1/1 for yes/no would be better */
611 io_stru
[1] = 0; /* FIXME? 1? */
612 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru
[1]);
615 case 10: /* audio disk info */
616 io_stru
[1] = toc
.FirstTrack
; /* starting track of the disc */
617 io_stru
[2] = toc
.LastTrack
; /* ending track */
618 MSCDEX_StoreMSF(FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1) -
619 FRAME_OF_TOC(toc
, toc
.FirstTrack
) - 1, io_stru
+ 3);
621 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
622 io_stru
[1], io_stru
[2], PTR_AT(io_stru
, 3, DWORD
));
625 case 11: /* audio track info */
626 if (io_stru
[1] >= toc
.FirstTrack
&& io_stru
[1] <= toc
.LastTrack
) {
627 MSCDEX_StoreMSF(FRAME_OF_TOC(toc
, io_stru
[1]), io_stru
+ 2);
628 /* starting point if the track */
629 io_stru
[6] = CTRL_OF_TOC(toc
, io_stru
[1]);
631 PTR_AT(io_stru
, 2, DWORD
) = 0;
634 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
635 io_stru
[1], PTR_AT(io_stru
, 2, DWORD
), io_stru
[6]);
638 case 12: /* get Q-Channel info */
639 io_stru
[1] = CTRL_OF_TOC(toc
, data
.CurrentPosition
.TrackNumber
);
640 io_stru
[2] = data
.CurrentPosition
.TrackNumber
;
641 io_stru
[3] = 0; /* FIXME ?? */
643 /* why the heck did MS use another format for 0MSF information... sigh */
647 MSCDEX_StoreMSF(FRAME_OF_ADDR(data
.CurrentPosition
.TrackRelativeAddress
), bTmp
);
648 io_stru
[ 4] = bTmp
[2];
649 io_stru
[ 5] = bTmp
[1];
650 io_stru
[ 6] = bTmp
[0];
653 MSCDEX_StoreMSF(FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
), bTmp
);
654 io_stru
[ 8] = bTmp
[2];
655 io_stru
[ 9] = bTmp
[1];
656 io_stru
[10] = bTmp
[0];
659 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
660 io_stru
[ 1], io_stru
[ 2], io_stru
[ 3],
661 io_stru
[ 4], io_stru
[ 5], io_stru
[ 6],
662 io_stru
[ 8], io_stru
[ 9], io_stru
[10],
663 FRAME_OF_ADDR(data
.CurrentPosition
.AbsoluteAddress
),
664 FRAME_OF_TOC(toc
, data
.CurrentPosition
.TrackNumber
));
667 case 15: /* Audio status info */
668 /* !!!! FIXME FIXME FIXME !! */
669 PTR_AT(io_stru
, 1, WORD
) = 2 | ((data
.CurrentPosition
.Header
.AudioStatus
== AUDIO_STATUS_PAUSED
) ? 1 : 0);
671 PTR_AT(io_stru
, 3, DWORD
) = 0;
672 PTR_AT(io_stru
, 7, DWORD
) = 0;
674 PTR_AT(io_stru
, 3, DWORD
) = FRAME_OF_TOC(toc
, toc
.FirstTrack
);
675 PTR_AT(io_stru
, 7, DWORD
) = FRAME_OF_TOC(toc
, toc
.LastTrack
+ 1);
677 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
678 PTR_AT(io_stru
, 1, WORD
), PTR_AT(io_stru
, 3, DWORD
), PTR_AT(io_stru
, 7, DWORD
));
682 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru
[0]);
689 io_stru
= MapSL( MAKESEGPTR(PTR_AT(driver_request
, 16, WORD
), PTR_AT(driver_request
, 14, WORD
)));
691 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru
[0]);
692 switch (io_stru
[0]) {
694 DeviceIoControl(h
, IOCTL_STORAGE_EJECT_MEDIA
, NULL
, 0, NULL
, 0, &br
, NULL
);
695 TRACE(" ----> EJECT\n");
697 case 2: /* reset drive */
698 DeviceIoControl(h
, IOCTL_STORAGE_RESET_DEVICE
, NULL
, 0, NULL
, 0, &br
, NULL
);
699 TRACE(" ----> RESET\n");
701 case 3: /* Audio Channel Control */
702 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
704 case 5: /* close tray */
705 DeviceIoControl(h
, IOCTL_STORAGE_LOAD_MEDIA
, NULL
, 0, NULL
, 0, &br
, NULL
);
706 TRACE(" ----> CLOSE TRAY\n");
709 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru
[0]);
715 case 128: /* read long */
717 LPVOID dst
= MapSL(MAKESEGPTR(PTR_AT(driver_request
, 16, WORD
),
718 PTR_AT(driver_request
, 14, WORD
)));
719 DWORD at
= PTR_AT(driver_request
, 20, DWORD
);
720 WORD num
= PTR_AT(driver_request
, 18, WORD
);
723 switch (driver_request
[13]) {
724 case 1: /* Red book addressing mode = 0:m:s:f */
725 /* FIXME : frame <=> msf conversion routines could be shared
726 * between mscdex and mcicda
728 at
= LOBYTE(HIWORD(at
)) * CDFRAMES_PERMIN
+
729 HIBYTE(LOWORD(at
)) * CDFRAMES_PERSEC
+
732 case 0: /* HSG addressing mode */
733 switch (PTR_AT(driver_request
, 24, BYTE
))
736 ReadFile(h
, dst
, num
* 2048, &br
, NULL
);
739 /* FIXME: computation is wrong */
740 rri
.DiskOffset
.u
.HighPart
= 0;
741 rri
.DiskOffset
.u
.LowPart
= at
<< 11;
742 rri
.TrackMode
= YellowMode2
;
743 rri
.SectorCount
= num
;
744 DeviceIoControl(h
, IOCTL_CDROM_RAW_READ
, &rri
, sizeof(rri
),
745 dst
, num
* 2352, &br
, NULL
);
748 ERR("Unsupported read mode !!\n");
754 ERR("Unsupported address mode !!\n");
764 CDROM_SEEK_AUDIO_MSF seek
;
766 at
= PTR_AT(driver_request
, 20, DWORD
);
768 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n", driver_request
[13], at
);
770 switch (driver_request
[13]) {
771 case 1: /* Red book addressing mode = 0:m:s:f */
772 /* FIXME : frame <=> msf conversion routines could be shared
773 * between mscdex and mcicda
775 at
= LOBYTE(HIWORD(at
)) * CDFRAMES_PERMIN
+
776 HIBYTE(LOWORD(at
)) * CDFRAMES_PERSEC
+
779 case 0: /* HSG addressing mode */
780 seek
.M
= at
/ CDFRAMES_PERMIN
;
781 seek
.S
= (at
/ CDFRAMES_PERSEC
) % 60;
782 seek
.F
= at
% CDFRAMES_PERSEC
;
783 DeviceIoControl(h
, IOCTL_CDROM_SEEK_AUDIO_MSF
, &seek
, sizeof(seek
),
787 ERR("Unsupported address mode !!\n");
797 CDROM_PLAY_AUDIO_MSF play
;
799 beg
= end
= PTR_AT(driver_request
, 14, DWORD
);
800 end
+= PTR_AT(driver_request
, 18, DWORD
);
802 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n", driver_request
[13], beg
, end
);
804 switch (driver_request
[13]) {
806 /* Red book addressing mode = 0:m:s:f */
807 /* FIXME : frame <=> msf conversion routines could be shared
808 * between mscdex and mcicda
810 beg
= LOBYTE(LOWORD(beg
)) * CDFRAMES_PERMIN
+
811 HIBYTE(LOWORD(beg
)) * CDFRAMES_PERSEC
+
813 end
= LOBYTE(LOWORD(end
)) * CDFRAMES_PERMIN
+
814 HIBYTE(LOWORD(end
)) * CDFRAMES_PERSEC
+
817 case 0: /* HSG addressing mode */
818 play
.StartingM
= beg
/ CDFRAMES_PERMIN
;
819 play
.StartingS
= (beg
/ CDFRAMES_PERSEC
) % 60;
820 play
.StartingF
= beg
% CDFRAMES_PERSEC
;
821 play
.EndingM
= end
/ CDFRAMES_PERMIN
;
822 play
.EndingS
= (end
/ CDFRAMES_PERSEC
) % 60;
823 play
.EndingF
= end
% CDFRAMES_PERSEC
;
824 DeviceIoControl(h
, IOCTL_CDROM_PLAY_AUDIO_MSF
, &play
, sizeof(play
),
828 ERR("Unsupported address mode !!\n");
836 if (data
.CurrentPosition
.Header
.AudioStatus
== AUDIO_STATUS_IN_PROGRESS
) {
837 DeviceIoControl(h
, IOCTL_CDROM_PAUSE_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
);
838 TRACE(" --> STOP AUDIO (Paused)\n");
840 DeviceIoControl(h
, IOCTL_CDROM_STOP_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
);
841 TRACE(" --> STOP AUDIO (Stopped)\n");
846 TRACE(" --> RESUME AUDIO\n");
847 DeviceIoControl(h
, IOCTL_CDROM_PAUSE_AUDIO
, NULL
, 0, NULL
, 0, &br
, NULL
);
851 FIXME(" ioctl unimplemented <%d>\n", driver_request
[2]);
855 /* setting error codes if any */
857 driver_request
[4] |= 0x80;
858 driver_request
[3] = Error
;
862 /* setting status bits
863 * 3 == playing && done
867 (data
.CurrentPosition
.Header
.AudioStatus
== AUDIO_STATUS_IN_PROGRESS
) ? 3 : 1;
870 static void MSCDEX_Handler(CONTEXT
* context
)
875 switch (LOBYTE(context
->Eax
)) {
876 case 0x00: /* Installation check */
877 /* Count the number of contiguous CDROM drives
879 for (drive
= count
= 0; drive
< 26; drive
++) {
880 if (is_cdrom(drive
)) {
881 while (is_cdrom(drive
+ count
)) count
++;
885 TRACE("Installation check: %d cdroms, starting at %d\n", count
, drive
);
886 SET_BX( context
, count
);
887 SET_CX( context
, (drive
< 26) ? drive
: 0 );
890 case 0x01: /* get drive device list */
892 CDROM_HEAP
* cdrom_heap
= CDROM_GetHeap();
893 CDROM_DEVICE_HEADER
* dev
= &cdrom_heap
->hdr
;
894 SEGPTR ptr_dev
= MAKESEGPTR( cdrom_heap
->cdrom_selector
, FIELD_OFFSET(CDROM_HEAP
, hdr
) );
896 p
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
897 for (drive
= 0; drive
< dev
->units
; drive
++) {
898 *p
= drive
; /* subunit */
900 *(DWORD
*)p
= ptr_dev
;
903 TRACE("Get drive device list\n");
907 case 0x0B: /* drive check */
908 SET_AX( context
, is_cdrom(CX_reg(context
)) );
909 SET_BX( context
, 0xADAD );
912 case 0x0C: /* get version */
913 SET_BX( context
, 0x020a );
914 TRACE("Version number => %04x\n", BX_reg(context
));
917 case 0x0D: /* get drive letters */
918 p
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
920 for (drive
= 0; drive
< 26; drive
++) {
921 if (is_cdrom(drive
)) *p
++ = drive
;
923 TRACE("Get drive letters\n");
926 case 0x10: /* direct driver access */
928 BYTE
* driver_request
;
929 CDROM_HEAP
* cdrom_heap
= CDROM_GetHeap();
931 if (!is_cdrom(CX_reg(context
))) {
932 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context
));
933 SET_CFLAG( context
);
934 SET_AX( context
, 0x000f ); /* invalid drive */
938 driver_request
= CTX_SEG_OFF_TO_LIN(context
, context
->SegEs
, context
->Ebx
);
940 if (!driver_request
) {
941 /* FIXME - to be deleted ?? */
942 ERR("ES:BX==0 ! SEGFAULT ?\n");
943 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
944 BX_reg(context
), context
->SegEs
, context
->SegDs
, CX_reg(context
));
945 driver_request
[4] |= 0x80;
946 driver_request
[3] = 5; /* bad request length */
950 driver_request
[1] = CX_reg(context
) - cdrom_heap
->hdr
.drive
;
951 MSCDEX_Request(driver_request
);
955 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context
->Eax
));