1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
3 * DOS interrupt 2fh handler
5 * Cdrom - device driver emulation - Audio features.
6 * (c) 1998 Petr Tomasek <tomasek@etf.cuni.cz>
14 #include "wine/winbase16.h"
23 /* #define DEBUG_INT */
24 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(int)
29 /* base WPROCS.DLL ordinal number for VxDs */
32 static void do_int2f_16( CONTEXT86 *context );
33 static void MSCDEX_Handler( CONTEXT86 *context );
35 /**********************************************************************
38 * Handler for int 2fh (multiplex).
40 void WINAPI INT_Int2fHandler( CONTEXT86 *context )
42 TRACE("Subfunction 0x%X\n", AX_reg(context));
44 switch(AH_reg(context))
47 AL_reg(context) = 0xff; /* share is installed */
50 case 0x11: /* Network Redirector / IFSFUNC */
51 switch (AL_reg(context))
53 case 0x00: /* Install check */
56 case 0x80: /* Enhanced services - Install check */
60 INT_BARF( context, 0x2f );
66 switch (AL_reg(context))
68 case 0x2e: /* get or set DOS error table address */
69 switch (DL_reg(context))
71 /* Four tables: even commands are 'get', odd are 'set' */
72 /* DOS 5.0+ ignores "set" commands */
79 /* Instead of having a message table in DOS-space, */
80 /* we can use a special case for MS-DOS to force */
81 /* the secondary interface. */
86 ES_reg(context) = 0x0001;
87 DI_reg(context) = 0x0000;
90 FIXME("No real-mode handler for errors yet! (bye!)");
93 INT_BARF(context, 0x2f);
97 INT_BARF(context, 0x2f);
101 case 0x15: /* mscdex */
102 MSCDEX_Handler(context);
106 do_int2f_16( context );
109 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
110 /* Not supported yet, do nothing */
115 switch (AL_reg(context))
117 case 0x00: /* XMS v2+ installation check */
118 WARN("XMS is not fully implemented\n");
119 AL_reg(context) = 0x80;
121 case 0x10: /* XMS v2+ get driver address */
124 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
125 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
126 GlobalUnlock16( GetCurrentTask() );
128 if (pModule && pModule->lpDosTask)
129 ES_reg(context) = pModule->lpDosTask->xms_seg;
137 INT_BARF( context, 0x2f );
140 FIXME("check for XMS (not supported)\n");
141 AL_reg(context) = 0x42; /* != 0x80 */
146 switch (AL_reg(context))
157 /* Microsoft Profiler - not installed */
160 INT_BARF( context, 0x2f );
165 switch(AL_reg(context))
167 case 0x10: /* smartdrv */
168 break; /* not installed */
169 case 0x11: /* dblspace */
170 break; /* not installed */
171 case 0x12: /* realtime compression interface */
172 break; /* not installed */
173 case 0x32: /* patch IO.SYS (???) */
174 break; /* we have no IO.SYS, so we can't patch it :-/ */
176 INT_BARF( context, 0x2f );
180 switch(AL_reg(context))
187 FIXME("Task Switcher - not implemented\n");
190 INT_BARF( context, 0x2f );
193 case 0x56: /* INTERLNK */
194 switch(AL_reg(context))
196 case 0x01: /* check if redirected drive */
197 AL_reg(context) = 0; /* not redirected */
200 INT_BARF( context, 0x2f );
203 case 0x7a: /* NOVELL NetWare */
204 switch (AL_reg(context))
206 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
209 case 0x20: /* Get VLM Call Address */
210 /* return nothing -> NetWare not installed */
213 INT_BARF( context, 0x2f );
217 case 0xb7: /* append */
218 AL_reg(context) = 0; /* not installed */
220 case 0xb8: /* network */
221 switch (AL_reg(context))
223 case 0x00: /* Install check */
227 INT_BARF( context, 0x2f );
231 case 0xbd: /* some Novell network install check ??? */
232 AX_reg(context) = 0xa5a5; /* pretend to have Novell IPX installed */
234 case 0xbf: /* REDIRIFS.EXE */
235 switch (AL_reg(context))
237 case 0x00: /* Install check */
241 INT_BARF( context, 0x2f );
246 switch(AL_reg(context))
248 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
249 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
250 && DX_reg(context) == 0x3432)
251 TRACE("Check for QEMM v5.0+ (not installed)\n");
254 INT_BARF( context, 0x2f );
258 case 0xd7: /* Banyan Vines */
259 switch (AL_reg(context))
261 case 0x01: /* Install check - Get Int Number */
265 INT_BARF( context, 0x2f );
270 switch(AL_reg(context))
272 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
273 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
274 && DX_reg(context) == 0x8f4f)
275 TRACE("Check for QDPMI.SYS (not installed)\n");
278 INT_BARF( context, 0x2f );
282 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
285 INT_BARF( context, 0x2f );
291 /**********************************************************************
294 static void do_int2f_16( CONTEXT86 *context )
298 switch(AL_reg(context))
300 case 0x00: /* Windows enhanced mode installation check */
301 AX_reg(context) = (GetWinFlags16() & WF_ENHANCED) ?
302 LOWORD(GetVersion16()) : 0;
305 case 0x0a: /* Get Windows version and type */
307 BX_reg(context) = (LOWORD(GetVersion16()) << 8) |
308 (LOWORD(GetVersion16()) >> 8);
309 CX_reg(context) = (GetWinFlags16() & WF_ENHANCED) ? 3 : 2;
312 case 0x0b: /* Identify Windows-aware TSRs */
313 /* we don't have any pre-Windows TSRs */
316 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
317 /* We can mock this up. But not today... */
318 FIXME("Get Shell Parameters\n");
321 case 0x80: /* Release time-slice */
325 case 0x81: /* Begin critical section. */
329 case 0x82: /* End critical section. */
333 case 0x83: /* Return Current Virtual Machine ID */
334 /* Virtual Machines are usually created/destroyed when Windows runs
335 * DOS programs. Since we never do, we are always in the System VM.
336 * According to Ralf Brown's Interrupt List, never return 0. But it
337 * seems to work okay (returning 0), just to be sure we return 1.
339 BX_reg(context) = 1; /* VM 1 is probably the System VM */
342 case 0x84: /* Get device API entry point */
343 addr = (DWORD)NE_GetEntryPoint( GetModuleHandle16("WPROCS"),
344 VXD_BASE + BX_reg(context) );
345 if (!addr) /* not supported */
347 ERR("Accessing unknown VxD %04x - Expect a failure now.\n",
350 ES_reg(context) = SELECTOROF(addr);
351 DI_reg(context) = OFFSETOF(addr);
354 case 0x86: /* DPMI detect mode */
355 AX_reg(context) = 0; /* Running under DPMI */
358 case 0x87: /* DPMI installation check */
359 #if 1 /* DPMI still breaks pkunzip */
360 if (ISV86(context)) break; /* so bail out for now if in v86 mode */
365 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
366 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
368 GlobalUnlock16( GetCurrentTask() );
372 AX_reg(context) = 0x0000; /* DPMI Installed */
373 BX_reg(context) = 0x0001; /* 32bits available */
374 CL_reg(context) = si.wProcessorLevel;
375 DX_reg(context) = 0x005a; /* DPMI major/minor 0.90 */
376 SI_reg(context) = 0; /* # of para. of DOS extended private data */
377 #ifdef MZ_SUPPORTED /* ES:DI is DPMI switch entry point */
378 if (pModule && pModule->lpDosTask)
379 ES_reg(context) = pModule->lpDosTask->dpmi_seg;
386 case 0x8a: /* DPMI get vendor-specific API entry point. */
387 /* The 1.0 specs say this should work with all 0.9 hosts. */
391 INT_BARF( context, 0x2f );
395 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
396 * must be <size> aligned
397 * <size> could be WORD, DWORD...
398 * in this case, we would need two macros, one for read, the other one for write
399 * Note: PTR_AT can be used as an l-value
401 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
403 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
405 /**********************************************************************
406 * MSCDEX_Dump [internal]
408 * Dumps mscdex requests to int debug channel.
410 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
418 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
419 for (i = 0; i < req[0]; i++) {
420 ptr += sprintf(ptr, "%02x ", req[i]);
426 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
428 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(req, 14, WORD), PTR_AT(req, 16, WORD))) :
429 PTR_SEG_OFF_TO_LIN(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD));
431 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
432 ptr += sprintf(ptr, "%02x ", ios[i]);
433 if ((i & 0x1F) == 0x1F) {
443 #define MSCDEX_Dump(pfx, req, drm)
446 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
448 val[3] = 0; /* zero */
449 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
450 val[1] = (frame - CDFRAMES_PERMIN * val[2]) / CDFRAMES_PERSEC; /* seconds */
451 val[0] = frame - CDFRAMES_PERMIN * val[2] - CDFRAMES_PERSEC * val[1]; /* frames */
454 static void MSCDEX_Handler(CONTEXT86* context)
459 switch(AL_reg(context)) {
460 case 0x00: /* Installation check */
461 /* Count the number of contiguous CDROM drives
463 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++) {
464 if (DRIVE_GetType(drive) == TYPE_CDROM) {
465 while (DRIVE_GetType(drive + count) == TYPE_CDROM) count++;
469 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
470 BX_reg(context) = count;
471 CX_reg(context) = (drive < MAX_DOS_DRIVES) ? drive : 0;
474 case 0x0B: /* drive check */
475 AX_reg(context) = (DRIVE_GetType(CX_reg(context)) == TYPE_CDROM);
476 BX_reg(context) = 0xADAD;
479 case 0x0C: /* get version */
480 BX_reg(context) = 0x020a;
481 TRACE("Version number => %04x\n", BX_reg(context));
484 case 0x0D: /* get drive letters */
485 p = CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EBX_reg(context));
486 memset(p, 0, MAX_DOS_DRIVES);
487 for (drive = 0; drive < MAX_DOS_DRIVES; drive++) {
488 if (DRIVE_GetType(drive) == TYPE_CDROM) *p++ = drive;
490 TRACE("Get drive letters\n");
493 case 0x10: /* direct driver acces */
495 static WINE_CDAUDIO wcda;
496 BYTE* driver_request;
498 BYTE Error = 255; /* No Error */
499 int dorealmode = ISV86(context);
501 driver_request = (dorealmode) ?
502 DOSMEM_MapRealToLinear(MAKELONG(BX_reg(context), ES_reg(context))) :
503 PTR_SEG_OFF_TO_LIN(ES_reg(context), BX_reg(context));
505 if (!driver_request) {
506 /* FIXME - to be deleted ?? */
507 ERR("ES:BX==0 ! SEGFAULT ?\n");
508 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
509 BX_reg(context), ES_reg(context), DS_reg(context), CX_reg(context));
510 driver_request[4] |= 0x80;
511 driver_request[3] = 5; /* bad request length */
514 /* FIXME - would be better to open the device at the begining of the wine session...
515 * - the device is also never closed...
516 * - the current implementation only supports a single CD ROM
518 if (wcda.unixdev <= 0)
520 TRACE("CDROM device driver -> command <%d>\n", (unsigned char)driver_request[2]);
523 drive < MAX_DOS_DRIVES && DRIVE_GetType(drive) != TYPE_CDROM;
525 /* drive contains the first CD ROM */
526 if (CX_reg(context) != drive) {
527 WARN("Request made doesn't match a CD ROM drive (%d/%d)\n", CX_reg(context), drive);
528 driver_request[4] |= 0x80;
529 driver_request[3] = 1; /* unknown unit */
533 MSCDEX_Dump("Beg", driver_request, dorealmode);
535 /* set status to 0 */
536 PTR_AT(driver_request, 3, WORD) = 0;
537 CDAUDIO_GetCDStatus(&wcda);
539 switch (driver_request[2]) {
541 io_stru = (dorealmode) ?
542 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(driver_request, 14, WORD), PTR_AT(driver_request, 16, WORD))) :
543 PTR_SEG_OFF_TO_LIN(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD));
545 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
546 switch (io_stru[0]) {
548 case 0: /* Get device Header */
550 static LPSTR ptr = 0;
552 ptr = SEGPTR_ALLOC(22);
553 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
554 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
555 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
556 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
557 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
558 PTR_AT(ptr, 11, char) = 'I';
559 PTR_AT(ptr, 12, char) = 'N';
560 PTR_AT(ptr, 13, char) = 'E';
561 PTR_AT(ptr, 14, char) = '_';
562 PTR_AT(ptr, 15, char) = 'C';
563 PTR_AT(ptr, 16, char) = 'D';
564 PTR_AT(ptr, 17, char) = '_';
565 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
566 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
567 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
569 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
574 case 1: /* location of head */
575 switch (io_stru[1]) {
577 PTR_AT(io_stru, 2, DWORD) = wcda.dwCurFrame;
580 MSCDEX_StoreMSF(wcda.dwCurFrame, io_stru + 2);
583 ERR("CDRom-Driver: Unsupported addressing mode !!\n");
586 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
589 case 4: /* Audio channel info */
598 TRACE(" ----> AUDIO CHANNEL INFO\n");
601 case 6: /* device status */
602 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
604 * 1 Supports HSG and Red Book addressing modes
605 * 0 Supports audio channel manipulation
607 * 1 Supports prefetching requests
610 * 1 Data read and plays audio/video tracks
613 * 0 Supports only cooked reading
615 * 0 see below (Door closed/opened)
617 if (wcda.cdaMode == WINE_CDA_OPEN)
619 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
622 case 8: /* Volume size */
623 PTR_AT(io_stru, 1, DWORD) = wcda.dwTotalLen;
624 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
627 case 9: /* media changed ? */
628 /* answers don't know... -1/1 for yes/no would be better */
629 io_stru[1] = 0; /* FIXME? 1? */
630 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
633 case 10: /* audio disk info */
634 io_stru[1] = wcda.nFirstTrack; /* starting track of the disc */
635 io_stru[2] = wcda.nLastTrack; /* ending track */
636 MSCDEX_StoreMSF(wcda.dwTotalLen, io_stru + 3);
638 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
639 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
642 case 11: /* audio track info */
643 if (io_stru[1] >= wcda.nFirstTrack && io_stru[1] <= wcda.nLastTrack) {
644 int nt = io_stru[1] - wcda.nFirstTrack;
645 MSCDEX_StoreMSF(wcda.lpdwTrackPos[nt], io_stru + 2);
646 /* starting point if the track */
647 io_stru[6] = (wcda.lpbTrackFlags[nt] & 0xF0) >> 4;
649 PTR_AT(io_stru, 2, DWORD) = 0;
652 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
653 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
656 case 12: /* get Q-Channel info */
657 io_stru[1] = wcda.lpbTrackFlags[wcda.nCurTrack - 1];
658 io_stru[2] = wcda.nCurTrack;
659 io_stru[3] = 0; /* FIXME ?? */
661 /* why the heck did MS use another format for 0MSF information... sigh */
665 MSCDEX_StoreMSF(wcda.dwCurFrame - wcda.lpdwTrackPos[wcda.nCurTrack - 1], bTmp);
666 io_stru[ 4] = bTmp[2];
667 io_stru[ 5] = bTmp[1];
668 io_stru[ 6] = bTmp[0];
671 MSCDEX_StoreMSF(wcda.dwCurFrame, bTmp);
672 io_stru[ 8] = bTmp[2];
673 io_stru[ 9] = bTmp[1];
674 io_stru[10] = bTmp[0];
677 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08lx, tp=%08lx)\n",
678 io_stru[ 1], io_stru[ 2], io_stru[ 3],
679 io_stru[ 4], io_stru[ 5], io_stru[ 6],
680 io_stru[ 8], io_stru[ 9], io_stru[10],
681 wcda.dwCurFrame, wcda.lpdwTrackPos[wcda.nCurTrack - 1]);
684 case 15: /* Audio status info */
685 /* !!!! FIXME FIXME FIXME !! */
686 PTR_AT(io_stru, 1, WORD) = 2 | ((wcda.cdaMode == WINE_CDA_PAUSE) ? 1 : 0);
687 if (wcda.cdaMode == WINE_CDA_OPEN) {
688 PTR_AT(io_stru, 3, DWORD) = 0;
689 PTR_AT(io_stru, 7, DWORD) = 0;
691 PTR_AT(io_stru, 3, DWORD) = wcda.lpdwTrackPos[0];
692 PTR_AT(io_stru, 7, DWORD) = wcda.lpdwTrackPos[wcda.nTracks - 1];
694 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
695 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
699 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
706 io_stru = (dorealmode) ?
707 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(driver_request, 14, WORD), PTR_AT(driver_request, 16, WORD))) :
708 PTR_SEG_OFF_TO_LIN(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD));
710 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
711 switch (io_stru[0]) {
713 CDAUDIO_SetDoor(&wcda, 1);
714 TRACE(" ----> EJECT\n");
716 case 2: /* reset drive */
717 CDAUDIO_Reset(&wcda);
718 TRACE(" ----> RESET\n");
720 case 3: /* Audio Channel Control */
721 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
723 case 5: /* close tray */
724 CDAUDIO_SetDoor(&wcda, 0);
725 TRACE(" ----> CLOSE TRAY\n");
728 FIXME(" IOCTL OUPUT: Unimplemented <%d>!!\n", io_stru[0]);
738 at = PTR_AT(driver_request, 20, DWORD);
740 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
741 (BYTE)driver_request[13], at);
743 switch (driver_request[13]) {
744 case 1: /* Red book addressing mode = 0:m:s:f */
745 /* FIXME : frame <=> msf conversion routines could be shared
746 * between mscdex and mcicda
748 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
749 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
752 case 0: /* HSG addressing mode */
753 CDAUDIO_Seek(&wcda, at);
756 ERR("Unsupported address mode !!\n");
767 beg = end = PTR_AT(driver_request, 14, DWORD);
768 end += PTR_AT(driver_request, 18, DWORD);
770 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
771 (BYTE)driver_request[13], beg, end);
773 switch (driver_request[13]) {
774 case 1: /* Red book addressing mode = 0:m:s:f */
775 /* FIXME : frame <=> msf conversion routines could be shared
776 * between mscdex and mcicda
778 beg = LOBYTE(HIWORD(beg)) * CDFRAMES_PERMIN +
779 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
781 end = LOBYTE(HIWORD(end)) * CDFRAMES_PERMIN +
782 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
785 case 0: /* HSG addressing mode */
786 CDAUDIO_Play(&wcda, beg, end);
789 ERR("Unsupported address mode !!\n");
797 if (wcda.cdaMode == WINE_CDA_PLAY) {
798 CDAUDIO_Pause(&wcda, 1);
799 TRACE(" --> STOP AUDIO (Paused)\n");
802 TRACE(" --> STOP AUDIO (Stopped)\n");
807 TRACE(" --> RESUME AUDIO\n");
808 CDAUDIO_Pause(&wcda, 0);
812 FIXME(" ioctl uninplemented <%d>\n", driver_request[2]);
816 /* setting error codes if any */
818 driver_request[4] |= 0x80;
819 driver_request[3] = Error;
822 /* setting status bits
823 * 3 == playing && done
826 driver_request[4] |= (wcda.cdaMode == WINE_CDA_PLAY) ? 3 : 1;
828 MSCDEX_Dump("End", driver_request, dorealmode);
832 FIXME("Unimplemented MSCDEX function 0x%02X.\n", AL_reg(context));