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
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
31 #define WIN32_NO_STATUS
32 #include "wine/winbase16.h"
33 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(int);
42 /* base WPROCS.DLL ordinal number for VxDs */
47 DOS_DEVICE_HEADER hdr;
49 WORD reserved; /* must be 0 */
50 BYTE drive; /* drive letter (0=A:, 1=B:, ...) */
51 BYTE units; /* number of supported units */
52 } CDROM_DEVICE_HEADER;
56 CDROM_DEVICE_HEADER hdr;
59 WORD cdrom_segment; /* Real mode segment for CDROM_HEAP */
60 WORD cdrom_selector; /* Protected mode selector for CDROM_HEAP */
63 static void do_int2f_16( CONTEXT86 *context );
64 static void MSCDEX_Handler( CONTEXT86 *context );
66 /**********************************************************************
67 * DOSVM_Int2fHandler (WINEDOS16.147)
69 * Handler for int 2fh (multiplex).
71 void WINAPI DOSVM_Int2fHandler( CONTEXT86 *context )
73 TRACE("Subfunction 0x%X\n", AX_reg(context));
75 switch(AH_reg(context))
78 SET_AL( context, 0xff ); /* share is installed */
81 case 0x11: /* Network Redirector / IFSFUNC */
82 switch (LOBYTE(context->Eax))
84 case 0x00: /* Install check */
87 case 0x80: /* Enhanced services - Install check */
91 INT_BARF( context, 0x2f );
97 switch (LOBYTE(context->Eax))
99 case 0x2e: /* get or set DOS error table address */
100 switch (DL_reg(context))
102 /* Four tables: even commands are 'get', odd are 'set' */
103 /* DOS 5.0+ ignores "set" commands */
110 /* Instead of having a message table in DOS-space, */
111 /* we can use a special case for MS-DOS to force */
112 /* the secondary interface. */
117 context->SegEs = 0x0001;
118 SET_DI( context, 0x0000 );
121 FIXME("No real-mode handler for errors yet! (bye!)\n");
124 INT_BARF(context, 0x2f);
128 INT_BARF(context, 0x2f);
132 case 0x15: /* mscdex */
133 MSCDEX_Handler(context);
137 do_int2f_16( context );
140 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
141 /* Not supported yet, do nothing */
146 switch (LOBYTE(context->Eax))
148 case 0x00: /* XMS v2+ installation check */
149 WARN("XMS is not fully implemented\n");
150 SET_AL( context, 0x80 );
152 case 0x10: /* XMS v2+ get driver address */
154 context->SegEs = DOSVM_dpmi_segments->xms_seg;
155 SET_BX( context, 0 );
159 INT_BARF( context, 0x2f );
162 FIXME("check for XMS (not supported)\n");
163 SET_AL( context, 0x42 ); /* != 0x80 */
168 switch (LOBYTE(context->Eax))
179 /* Microsoft Profiler - not installed */
182 INT_BARF( context, 0x2f );
187 switch(LOBYTE(context->Eax))
189 case 0x10: /* smartdrv */
190 break; /* not installed */
191 case 0x11: /* dblspace */
192 break; /* not installed */
193 case 0x12: /* realtime compression interface */
194 break; /* not installed */
195 case 0x32: /* patch IO.SYS (???) */
196 break; /* we have no IO.SYS, so we can't patch it :-/ */
198 INT_BARF( context, 0x2f );
202 switch(LOBYTE(context->Eax))
209 FIXME("Task Switcher - not implemented\n");
212 INT_BARF( context, 0x2f );
215 case 0x56: /* INTERLNK */
216 switch(LOBYTE(context->Eax))
218 case 0x01: /* check if redirected drive */
219 SET_AL( context, 0 ); /* not redirected */
222 INT_BARF( context, 0x2f );
225 case 0x7a: /* NOVELL NetWare */
226 switch (LOBYTE(context->Eax))
228 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
229 SET_AL( context, 0 );
231 case 0x20: /* Get VLM Call Address */
232 /* return nothing -> NetWare not installed */
235 INT_BARF( context, 0x2f );
239 case 0xb7: /* append */
240 SET_AL( context, 0 ); /* not installed */
242 case 0xb8: /* network */
243 switch (LOBYTE(context->Eax))
245 case 0x00: /* Install check */
249 INT_BARF( context, 0x2f );
254 if (AL_reg(context) == 0x00 && BX_reg(context) == 0x3f3f) {
255 /* MVSOUND.SYS - Install check: not installed */
257 INT_BARF( context, 0x2f );
260 case 0xbd: /* some Novell network install check ??? */
261 SET_AX( context, 0xa5a5 ); /* pretend to have Novell IPX installed */
263 case 0xbf: /* REDIRIFS.EXE */
264 switch (LOBYTE(context->Eax))
266 case 0x00: /* Install check */
270 INT_BARF( context, 0x2f );
275 switch(LOBYTE(context->Eax))
277 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
278 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
279 && DX_reg(context) == 0x3432)
280 TRACE("Check for QEMM v5.0+ (not installed)\n");
283 INT_BARF( context, 0x2f );
287 case 0xd7: /* Banyan Vines */
288 switch (LOBYTE(context->Eax))
290 case 0x01: /* Install check - Get Int Number */
294 INT_BARF( context, 0x2f );
299 switch(LOBYTE(context->Eax))
301 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
302 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
303 && DX_reg(context) == 0x8f4f)
304 TRACE("Check for QDPMI.SYS (not installed)\n");
307 INT_BARF( context, 0x2f );
311 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
314 INT_BARF( context, 0x2f );
320 /**********************************************************************
323 static void do_int2f_16( CONTEXT86 *context )
327 switch(LOBYTE(context->Eax))
329 case 0x00: /* Windows enhanced mode installation check */
330 SET_AX( context, (GetWinFlags16() & WF_ENHANCED) ? LOWORD(GetVersion16()) : 0 );
333 case 0x0a: /* Get Windows version and type */
334 SET_AX( context, 0 );
335 SET_BX( context, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
336 SET_CX( context, (GetWinFlags16() & WF_ENHANCED) ? 3 : 2 );
339 case 0x0b: /* Identify Windows-aware TSRs */
340 /* we don't have any pre-Windows TSRs */
343 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
344 /* We can mock this up. But not today... */
345 FIXME("Get Shell Parameters\n");
348 case 0x80: /* Release time-slice */
349 /* Linux sched_yield() still keeps burning CPU cycles
350 * if the current process is the only one in highest priority list
351 * (as Linux will immediately return to this process to waste
352 * more CPU cycles), so sched_yield() is essentially useless for us
353 * (poor API, if you ask me: its return code should indicate
354 * whether other processes did run in between, in order for us
355 * to be able to decide whether to do an additional Sleep() or not...)
356 * Thus we better unconditionally use a well-balanced Sleep()
357 * instead to really make sure the process calling int 0x2f/0x1680
358 * *doesn't* use 100% CPU...
360 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
361 SET_AL( context, 0 );
364 case 0x81: /* Begin critical section. */
368 case 0x82: /* End critical section. */
372 case 0x83: /* Return Current Virtual Machine ID */
373 /* Virtual Machines are usually created/destroyed when Windows runs
374 * DOS programs. Since we never do, we are always in the System VM.
375 * According to Ralf Brown's Interrupt List, never return 0. But it
376 * seems to work okay (returning 0), just to be sure we return 1.
378 SET_BX( context, 1 ); /* VM 1 is probably the System VM */
381 case 0x84: /* Get device API entry point */
383 HMODULE16 mod = GetModuleHandle16("wprocs");
384 if (mod < 32) mod = LoadLibrary16( "wprocs" );
385 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
386 if (!addr) /* not supported */
387 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
388 context->SegEs = SELECTOROF(addr);
389 SET_DI( context, OFFSETOF(addr) );
393 case 0x86: /* DPMI detect mode */
394 SET_AX( context, 0 ); /* Running under DPMI */
397 case 0x87: /* DPMI installation check */
401 SET_AX( context, 0x0000 ); /* DPMI Installed */
402 SET_BX( context, 0x0001 ); /* 32bits available */
403 SET_CL( context, si.wProcessorLevel );
404 SET_DX( context, 0x005a ); /* DPMI major/minor 0.90 */
405 SET_SI( context, 0 ); /* # of para. of DOS extended private data */
406 context->SegEs = DOSVM_dpmi_segments->dpmi_seg;
407 SET_DI( context, 0 ); /* ES:DI is DPMI switch entry point */
410 case 0x8a: /* DPMI get vendor-specific API entry point. */
411 /* The 1.0 specs say this should work with all 0.9 hosts. */
415 INT_BARF( context, 0x2f );
419 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
420 * must be <size> aligned
421 * <size> could be WORD, DWORD...
422 * in this case, we would need two macros, one for read, the other one for write
423 * Note: PTR_AT can be used as an l-value
425 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
427 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
429 /**********************************************************************
430 * MSCDEX_Dump [internal]
432 * Dumps mscdex requests to int debug channel.
434 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
442 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
443 for (i = 0; i < req[0]; i++) {
444 ptr += sprintf(ptr, "%02x ", req[i]);
450 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
451 ios = (dorealmode) ? PTR_REAL_TO_LIN( PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)) :
452 MapSL(MAKESEGPTR(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)));
454 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
455 ptr += sprintf(ptr, "%02x ", ios[i]);
456 if ((i & 0x1F) == 0x1F) {
466 #define MSCDEX_Dump(pfx, req, drm)
469 #define CDFRAMES_PERSEC 75
470 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
471 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
472 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
473 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
474 (toc).TrackData[idx - (toc).FirstTrack].Adr)
476 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
478 val[3] = 0; /* zero */
479 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
480 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
481 val[0] = frame % CDFRAMES_PERSEC; /* frames */
484 static int is_cdrom( int drive)
486 char root[] = "A:\\";
488 return (GetDriveTypeA(root) == DRIVE_CDROM);
491 /***********************************************************************
494 * Initialize CDROM heap.
497 static void CDROM_FillHeap( CDROM_HEAP *heap )
501 /* Count the number of contiguous CDROM drives
503 for (drive = count = 0; drive < 26; drive++) {
504 if (is_cdrom(drive)) {
505 while (is_cdrom(drive + count)) count++;
509 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
510 heap->hdr.drive = (drive < 26) ? drive : 0;
511 heap->hdr.units = count;
512 heap->hdr.reserved = 0;
515 /**********************************************************************
518 * Get pointer for CDROM heap (CDROM_HEAP).
519 * Creates and initializes heap on first call.
521 static CDROM_HEAP *CDROM_GetHeap( void )
523 static CDROM_HEAP *heap_pointer = NULL;
530 /* allocate a new DOS data segment */
531 heap_pointer = DOSVM_AllocDataUMB( sizeof(CDROM_HEAP),
535 heap_pointer->cdrom_segment = heap_segment;
536 heap_pointer->cdrom_selector = heap_selector;
537 CDROM_FillHeap( heap_pointer );
543 static void MSCDEX_Request(BYTE *driver_request, BOOL dorealmode)
546 BYTE Error = 255; /* No Error */
547 char devName[] = "\\\\.\\@:";
550 CDROM_SUB_Q_DATA_FORMAT fmt;
551 SUB_Q_CHANNEL_DATA data;
553 DWORD present = TRUE;
556 * the following tests are wrong because lots of functions don't require the
557 * tray to be closed with a CD inside
559 TRACE("CDROM device driver -> command <%d>\n", (unsigned char)driver_request[2]);
561 MSCDEX_Dump("Beg", driver_request, dorealmode);
563 /* set status to 0 */
564 PTR_AT(driver_request, 3, WORD) = 0;
565 devName[4] = 'A' + CDROM_GetHeap()->hdr.drive + driver_request[1];
566 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
568 WARN("Couldn't open cdrom handle\n");
569 driver_request[4] |= 0x80;
570 driver_request[3] = 1; /* unknown unit */
574 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
575 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
576 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
577 &data, sizeof(data), &br, NULL)) {
578 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
580 if (driver_request[2] != 6 && driver_request[2] != 15)
582 driver_request[4] |= 0x80;
583 driver_request[3] = 2; /* drive not ready */
591 driver_request[4] |= 0x80;
592 driver_request[3] = 1; /* unknown unit */
598 switch (driver_request[2]) {
600 io_stru = (dorealmode) ?
601 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD) ) :
602 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
604 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
605 switch (io_stru[0]) {
607 case 0: /* Get device Header */
609 static LPSTR ptr = 0;
611 ptr = SEGPTR_ALLOC(22);
612 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
613 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
614 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
615 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
616 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
617 PTR_AT(ptr, 11, char) = 'I';
618 PTR_AT(ptr, 12, char) = 'N';
619 PTR_AT(ptr, 13, char) = 'E';
620 PTR_AT(ptr, 14, char) = '_';
621 PTR_AT(ptr, 15, char) = 'C';
622 PTR_AT(ptr, 16, char) = 'D';
623 PTR_AT(ptr, 17, char) = '_';
624 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
625 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
626 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
628 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
633 case 1: /* location of head */
634 switch (io_stru[1]) {
636 PTR_AT(io_stru, 2, DWORD) =
637 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
640 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
644 ERR("CD-ROM driver: unsupported addressing mode !!\n");
647 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
650 case 4: /* Audio channel info */
659 TRACE(" ----> AUDIO CHANNEL INFO\n");
662 case 6: /* device status */
663 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
665 * 1 Supports HSG and Red Book addressing modes
666 * 0 Supports audio channel manipulation
668 * 1 Supports prefetching requests
671 * 1 Data read and plays audio/video tracks
674 * 0 Supports only cooked reading
676 * 0 see below (Door closed/opened)
678 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
679 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
682 case 8: /* Volume size */
683 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
684 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
685 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
688 case 9: /* media changed ? */
689 /* answers don't know... -1/1 for yes/no would be better */
690 io_stru[1] = 0; /* FIXME? 1? */
691 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
694 case 10: /* audio disk info */
695 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
696 io_stru[2] = toc.LastTrack; /* ending track */
697 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
698 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
700 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
701 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
704 case 11: /* audio track info */
705 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
706 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
707 /* starting point if the track */
708 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
710 PTR_AT(io_stru, 2, DWORD) = 0;
713 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
714 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
717 case 12: /* get Q-Channel info */
718 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
719 io_stru[2] = data.CurrentPosition.TrackNumber;
720 io_stru[3] = 0; /* FIXME ?? */
722 /* why the heck did MS use another format for 0MSF information... sigh */
726 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
727 io_stru[ 4] = bTmp[2];
728 io_stru[ 5] = bTmp[1];
729 io_stru[ 6] = bTmp[0];
732 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
733 io_stru[ 8] = bTmp[2];
734 io_stru[ 9] = bTmp[1];
735 io_stru[10] = bTmp[0];
738 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
739 io_stru[ 1], io_stru[ 2], io_stru[ 3],
740 io_stru[ 4], io_stru[ 5], io_stru[ 6],
741 io_stru[ 8], io_stru[ 9], io_stru[10],
742 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
743 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
746 case 15: /* Audio status info */
747 /* !!!! FIXME FIXME FIXME !! */
748 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
750 PTR_AT(io_stru, 3, DWORD) = 0;
751 PTR_AT(io_stru, 7, DWORD) = 0;
753 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
754 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
756 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
757 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
761 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
768 io_stru = (dorealmode) ?
769 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)) :
770 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
772 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
773 switch (io_stru[0]) {
775 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
776 TRACE(" ----> EJECT\n");
778 case 2: /* reset drive */
779 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
780 TRACE(" ----> RESET\n");
782 case 3: /* Audio Channel Control */
783 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
785 case 5: /* close tray */
786 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
787 TRACE(" ----> CLOSE TRAY\n");
790 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
796 case 128: /* read long */
798 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
799 PTR_AT(driver_request, 14, WORD)));
800 DWORD at = PTR_AT(driver_request, 20, DWORD);
801 WORD num = PTR_AT(driver_request, 18, WORD);
804 switch (driver_request[13]) {
805 case 1: /* Red book addressing mode = 0:m:s:f */
806 /* FIXME : frame <=> msf conversion routines could be shared
807 * between mscdex and mcicda
809 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
810 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
813 case 0: /* HSG addressing mode */
814 switch (PTR_AT(driver_request, 24, BYTE))
817 ReadFile(h, dst, num * 2048, &br, NULL);
820 /* FIXME: computation is wrong */
821 rri.DiskOffset.u.HighPart = 0;
822 rri.DiskOffset.u.LowPart = at << 11;
823 rri.TrackMode = YellowMode2;
824 rri.SectorCount = num;
825 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
826 dst, num * 2352, &br, NULL);
829 ERR("Unsupported read mode !!\n");
835 ERR("Unsupported address mode !!\n");
845 CDROM_SEEK_AUDIO_MSF seek;
847 at = PTR_AT(driver_request, 20, DWORD);
849 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
850 (BYTE)driver_request[13], at);
852 switch (driver_request[13]) {
853 case 1: /* Red book addressing mode = 0:m:s:f */
854 /* FIXME : frame <=> msf conversion routines could be shared
855 * between mscdex and mcicda
857 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
858 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
861 case 0: /* HSG addressing mode */
862 seek.M = at / CDFRAMES_PERMIN;
863 seek.S = (at / CDFRAMES_PERSEC) % 60;
864 seek.F = at % CDFRAMES_PERSEC;
865 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
869 ERR("Unsupported address mode !!\n");
879 CDROM_PLAY_AUDIO_MSF play;
881 beg = end = PTR_AT(driver_request, 14, DWORD);
882 end += PTR_AT(driver_request, 18, DWORD);
884 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
885 (BYTE)driver_request[13], beg, end);
887 switch (driver_request[13]) {
889 /* Red book addressing mode = 0:m:s:f */
890 /* FIXME : frame <=> msf conversion routines could be shared
891 * between mscdex and mcicda
893 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
894 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
896 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
897 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
900 case 0: /* HSG addressing mode */
901 play.StartingM = beg / CDFRAMES_PERMIN;
902 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
903 play.StartingF = beg % CDFRAMES_PERSEC;
904 play.EndingM = end / CDFRAMES_PERMIN;
905 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
906 play.EndingF = end % CDFRAMES_PERSEC;
907 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
911 ERR("Unsupported address mode !!\n");
919 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
920 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
921 TRACE(" --> STOP AUDIO (Paused)\n");
923 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
924 TRACE(" --> STOP AUDIO (Stopped)\n");
929 TRACE(" --> RESUME AUDIO\n");
930 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
934 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
938 /* setting error codes if any */
940 driver_request[4] |= 0x80;
941 driver_request[3] = Error;
945 /* setting status bits
946 * 3 == playing && done
950 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
952 MSCDEX_Dump("End", driver_request, dorealmode);
955 static void MSCDEX_Handler(CONTEXT86* context)
960 switch (LOBYTE(context->Eax)) {
961 case 0x00: /* Installation check */
962 /* Count the number of contiguous CDROM drives
964 for (drive = count = 0; drive < 26; drive++) {
965 if (is_cdrom(drive)) {
966 while (is_cdrom(drive + count)) count++;
970 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
971 SET_BX( context, count );
972 SET_CX( context, (drive < 26) ? drive : 0 );
975 case 0x01: /* get drive device list */
977 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
978 CDROM_DEVICE_HEADER* dev = &cdrom_heap->hdr;
979 SEGPTR ptr_dev = ISV86(context)
980 ? MAKESEGPTR( cdrom_heap->cdrom_segment,
981 FIELD_OFFSET(CDROM_HEAP, hdr) )
982 : MAKESEGPTR( cdrom_heap->cdrom_selector,
983 FIELD_OFFSET(CDROM_HEAP, hdr) );
985 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
986 for (drive = 0; drive < dev->units; drive++) {
987 *p = drive; /* subunit */
989 *(DWORD*)p = ptr_dev;
992 TRACE("Get drive device list\n");
996 case 0x0B: /* drive check */
997 SET_AX( context, is_cdrom(CX_reg(context)) );
998 SET_BX( context, 0xADAD );
1001 case 0x0C: /* get version */
1002 SET_BX( context, 0x020a );
1003 TRACE("Version number => %04x\n", BX_reg(context));
1006 case 0x0D: /* get drive letters */
1007 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
1009 for (drive = 0; drive < 26; drive++) {
1010 if (is_cdrom(drive)) *p++ = drive;
1012 TRACE("Get drive letters\n");
1015 case 0x10: /* direct driver access */
1017 BYTE* driver_request;
1018 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
1020 if (!is_cdrom(CX_reg(context))) {
1021 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
1022 SET_CFLAG( context );
1023 SET_AX( context, 0x000f ); /* invalid drive */
1027 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
1029 if (!driver_request) {
1030 /* FIXME - to be deleted ?? */
1031 ERR("ES:BX==0 ! SEGFAULT ?\n");
1032 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
1033 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
1034 driver_request[4] |= 0x80;
1035 driver_request[3] = 5; /* bad request length */
1039 driver_request[1] = CX_reg(context) - cdrom_heap->hdr.drive;
1040 MSCDEX_Request(driver_request, ISV86(context));
1044 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
1050 static void WINAPI cdrom_strategy(CONTEXT86*ctx);
1051 static void WINAPI cdrom_interrupt(CONTEXT86*ctx);
1054 static const WINEDEV cdromdev =
1057 ATTR_CHAR|ATTR_REMOVABLE|ATTR_IOCTL,
1058 cdrom_strategy, cdrom_interrupt
1061 static REQUEST_HEADER *cdrom_driver_request;
1063 /* Return to caller */
1064 static void do_lret(CONTEXT86*ctx)
1066 WORD *stack = CTX_SEG_OFF_TO_LIN(ctx, ctx->SegSs, ctx->Esp);
1068 ctx->Eip = *(stack++);
1069 ctx->SegCs = *(stack++);
1070 ctx->Esp += 2*sizeof(WORD);
1073 static void WINAPI cdrom_strategy(CONTEXT86*ctx)
1075 cdrom_driver_request = CTX_SEG_OFF_TO_LIN(ctx, ctx->SegEs, ctx->Ebx);
1079 static void WINAPI cdrom_interrupt(CONTEXT86*ctx)
1081 if (cdrom_driver_request->unit > CDROM_GetHeap()->hdr.units)
1082 cdrom_driver_request->status = STAT_ERROR | 1; /* unknown unit */
1084 MSCDEX_Request((BYTE*)cdrom_driver_request, ISV86(ctx));
1089 /**********************************************************************
1090 * MSCDEX_InstallCDROM [internal]
1092 * Install the CDROM driver into the DOS device driver chain.
1094 void MSCDEX_InstallCDROM(void)
1096 CDROM_HEAP *cdrom_heap = CDROM_GetHeap();
1098 DOSDEV_SetupDevice( &cdromdev,
1099 cdrom_heap->cdrom_segment,
1100 FIELD_OFFSET(CDROM_HEAP, hdr),
1101 FIELD_OFFSET(CDROM_HEAP, thunk) );