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>
16 #include "wine/winbase16.h"
25 /* #define DEBUG_INT */
26 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(int)
31 /* base WPROCS.DLL ordinal number for VxDs */
34 static void do_int2f_16( CONTEXT86 *context );
35 static void MSCDEX_Handler( CONTEXT86 *context );
37 /**********************************************************************
40 * Handler for int 2fh (multiplex).
42 void WINAPI INT_Int2fHandler( CONTEXT86 *context )
44 TRACE("Subfunction 0x%X\n", AX_reg(context));
46 switch(AH_reg(context))
49 AL_reg(context) = 0xff; /* share is installed */
52 case 0x11: /* Network Redirector / IFSFUNC */
53 switch (AL_reg(context))
55 case 0x00: /* Install check */
58 case 0x80: /* Enhanced services - Install check */
62 INT_BARF( context, 0x2f );
68 switch (AL_reg(context))
70 case 0x2e: /* get or set DOS error table address */
71 switch (DL_reg(context))
73 /* Four tables: even commands are 'get', odd are 'set' */
74 /* DOS 5.0+ ignores "set" commands */
81 /* Instead of having a message table in DOS-space, */
82 /* we can use a special case for MS-DOS to force */
83 /* the secondary interface. */
88 ES_reg(context) = 0x0001;
89 DI_reg(context) = 0x0000;
92 FIXME("No real-mode handler for errors yet! (bye!)");
95 INT_BARF(context, 0x2f);
99 INT_BARF(context, 0x2f);
103 case 0x15: /* mscdex */
104 MSCDEX_Handler(context);
108 do_int2f_16( context );
111 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
112 /* Not supported yet, do nothing */
117 switch (AL_reg(context))
119 case 0x00: /* XMS v2+ installation check */
120 WARN("XMS is not fully implemented\n");
121 AL_reg(context) = 0x80;
123 case 0x10: /* XMS v2+ get driver address */
126 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
127 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
128 GlobalUnlock16( GetCurrentTask() );
130 if (pModule && pModule->lpDosTask)
131 ES_reg(context) = pModule->lpDosTask->xms_seg;
139 INT_BARF( context, 0x2f );
142 FIXME("check for XMS (not supported)\n");
143 AL_reg(context) = 0x42; /* != 0x80 */
148 switch (AL_reg(context))
159 /* Microsoft Profiler - not installed */
162 INT_BARF( context, 0x2f );
167 switch(AL_reg(context))
169 case 0x10: /* smartdrv */
170 break; /* not installed */
171 case 0x11: /* dblspace */
172 break; /* not installed */
173 case 0x12: /* realtime compression interface */
174 break; /* not installed */
175 case 0x32: /* patch IO.SYS (???) */
176 break; /* we have no IO.SYS, so we can't patch it :-/ */
178 INT_BARF( context, 0x2f );
182 switch(AL_reg(context))
189 FIXME("Task Switcher - not implemented\n");
192 INT_BARF( context, 0x2f );
195 case 0x56: /* INTERLNK */
196 switch(AL_reg(context))
198 case 0x01: /* check if redirected drive */
199 AL_reg(context) = 0; /* not redirected */
202 INT_BARF( context, 0x2f );
205 case 0x7a: /* NOVELL NetWare */
206 switch (AL_reg(context))
208 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
211 case 0x20: /* Get VLM Call Address */
212 /* return nothing -> NetWare not installed */
215 INT_BARF( context, 0x2f );
219 case 0xb7: /* append */
220 AL_reg(context) = 0; /* not installed */
222 case 0xb8: /* network */
223 switch (AL_reg(context))
225 case 0x00: /* Install check */
229 INT_BARF( context, 0x2f );
233 case 0xbd: /* some Novell network install check ??? */
234 AX_reg(context) = 0xa5a5; /* pretend to have Novell IPX installed */
236 case 0xbf: /* REDIRIFS.EXE */
237 switch (AL_reg(context))
239 case 0x00: /* Install check */
243 INT_BARF( context, 0x2f );
248 switch(AL_reg(context))
250 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
251 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
252 && DX_reg(context) == 0x3432)
253 TRACE("Check for QEMM v5.0+ (not installed)\n");
256 INT_BARF( context, 0x2f );
260 case 0xd7: /* Banyan Vines */
261 switch (AL_reg(context))
263 case 0x01: /* Install check - Get Int Number */
267 INT_BARF( context, 0x2f );
272 switch(AL_reg(context))
274 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
275 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
276 && DX_reg(context) == 0x8f4f)
277 TRACE("Check for QDPMI.SYS (not installed)\n");
280 INT_BARF( context, 0x2f );
284 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
287 INT_BARF( context, 0x2f );
293 /**********************************************************************
296 static void do_int2f_16( CONTEXT86 *context )
300 switch(AL_reg(context))
302 case 0x00: /* Windows enhanced mode installation check */
303 AX_reg(context) = (GetWinFlags16() & WF_ENHANCED) ?
304 LOWORD(GetVersion16()) : 0;
307 case 0x0a: /* Get Windows version and type */
309 BX_reg(context) = (LOWORD(GetVersion16()) << 8) |
310 (LOWORD(GetVersion16()) >> 8);
311 CX_reg(context) = (GetWinFlags16() & WF_ENHANCED) ? 3 : 2;
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 */
327 case 0x81: /* Begin critical section. */
331 case 0x82: /* End critical section. */
335 case 0x83: /* Return Current Virtual Machine ID */
336 /* Virtual Machines are usually created/destroyed when Windows runs
337 * DOS programs. Since we never do, we are always in the System VM.
338 * According to Ralf Brown's Interrupt List, never return 0. But it
339 * seems to work okay (returning 0), just to be sure we return 1.
341 BX_reg(context) = 1; /* VM 1 is probably the System VM */
344 case 0x84: /* Get device API entry point */
345 addr = (DWORD)NE_GetEntryPoint( GetModuleHandle16("WPROCS"),
346 VXD_BASE + BX_reg(context) );
347 if (!addr) /* not supported */
349 ERR("Accessing unknown VxD %04x - Expect a failure now.\n",
352 ES_reg(context) = SELECTOROF(addr);
353 DI_reg(context) = OFFSETOF(addr);
356 case 0x86: /* DPMI detect mode */
357 AX_reg(context) = 0; /* Running under DPMI */
360 case 0x87: /* DPMI installation check */
361 #if 1 /* DPMI still breaks pkunzip */
362 if (ISV86(context)) break; /* so bail out for now if in v86 mode */
367 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
368 NE_MODULE *pModule = pTask ? NE_GetPtr( pTask->hModule ) : NULL;
370 GlobalUnlock16( GetCurrentTask() );
374 AX_reg(context) = 0x0000; /* DPMI Installed */
375 BX_reg(context) = 0x0001; /* 32bits available */
376 CL_reg(context) = si.wProcessorLevel;
377 DX_reg(context) = 0x005a; /* DPMI major/minor 0.90 */
378 SI_reg(context) = 0; /* # of para. of DOS extended private data */
379 #ifdef MZ_SUPPORTED /* ES:DI is DPMI switch entry point */
380 if (pModule && pModule->lpDosTask)
381 ES_reg(context) = pModule->lpDosTask->dpmi_seg;
388 case 0x8a: /* DPMI get vendor-specific API entry point. */
389 /* The 1.0 specs say this should work with all 0.9 hosts. */
393 INT_BARF( context, 0x2f );
397 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
398 * must be <size> aligned
399 * <size> could be WORD, DWORD...
400 * in this case, we would need two macros, one for read, the other one for write
401 * Note: PTR_AT can be used as an l-value
403 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
405 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
407 /**********************************************************************
408 * MSCDEX_Dump [internal]
410 * Dumps mscdex requests to int debug channel.
412 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
420 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
421 for (i = 0; i < req[0]; i++) {
422 ptr += sprintf(ptr, "%02x ", req[i]);
428 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
430 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(req, 14, WORD), PTR_AT(req, 16, WORD))) :
431 PTR_SEG_OFF_TO_LIN(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD));
433 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
434 ptr += sprintf(ptr, "%02x ", ios[i]);
435 if ((i & 0x1F) == 0x1F) {
445 #define MSCDEX_Dump(pfx, req, drm)
448 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
450 val[3] = 0; /* zero */
451 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
452 val[1] = (frame - CDFRAMES_PERMIN * val[2]) / CDFRAMES_PERSEC; /* seconds */
453 val[0] = frame - CDFRAMES_PERMIN * val[2] - CDFRAMES_PERSEC * val[1]; /* frames */
456 static void MSCDEX_Handler(CONTEXT86* context)
461 switch(AL_reg(context)) {
462 case 0x00: /* Installation check */
463 /* Count the number of contiguous CDROM drives
465 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++) {
466 if (DRIVE_GetType(drive) == TYPE_CDROM) {
467 while (DRIVE_GetType(drive + count) == TYPE_CDROM) count++;
471 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
472 BX_reg(context) = count;
473 CX_reg(context) = (drive < MAX_DOS_DRIVES) ? drive : 0;
476 case 0x0B: /* drive check */
477 AX_reg(context) = (DRIVE_GetType(CX_reg(context)) == TYPE_CDROM);
478 BX_reg(context) = 0xADAD;
481 case 0x0C: /* get version */
482 BX_reg(context) = 0x020a;
483 TRACE("Version number => %04x\n", BX_reg(context));
486 case 0x0D: /* get drive letters */
487 p = CTX_SEG_OFF_TO_LIN(context, ES_reg(context), EBX_reg(context));
488 memset(p, 0, MAX_DOS_DRIVES);
489 for (drive = 0; drive < MAX_DOS_DRIVES; drive++) {
490 if (DRIVE_GetType(drive) == TYPE_CDROM) *p++ = drive;
492 TRACE("Get drive letters\n");
495 case 0x10: /* direct driver access */
497 static WINE_CDAUDIO wcda;
498 BYTE* driver_request;
500 BYTE Error = 255; /* No Error */
501 int dorealmode = ISV86(context);
503 driver_request = (dorealmode) ?
504 DOSMEM_MapRealToLinear(MAKELONG(BX_reg(context), ES_reg(context))) :
505 PTR_SEG_OFF_TO_LIN(ES_reg(context), BX_reg(context));
507 if (!driver_request) {
508 /* FIXME - to be deleted ?? */
509 ERR("ES:BX==0 ! SEGFAULT ?\n");
510 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
511 BX_reg(context), ES_reg(context), DS_reg(context), CX_reg(context));
512 driver_request[4] |= 0x80;
513 driver_request[3] = 5; /* bad request length */
516 /* FIXME - would be better to open the device at the beginning of the wine session...
517 * - the device is also never closed...
518 * - the current implementation only supports a single CD ROM
520 if (wcda.unixdev <= 0)
521 CDROM_Open(&wcda, -1);
522 TRACE("CDROM device driver -> command <%d>\n", (unsigned char)driver_request[2]);
525 drive < MAX_DOS_DRIVES && DRIVE_GetType(drive) != TYPE_CDROM;
527 /* drive contains the first CD ROM */
528 if (CX_reg(context) != drive) {
529 WARN("Request made doesn't match a CD ROM drive (%d/%d)\n", CX_reg(context), drive);
530 driver_request[4] |= 0x80;
531 driver_request[3] = 1; /* unknown unit */
535 MSCDEX_Dump("Beg", driver_request, dorealmode);
537 /* set status to 0 */
538 PTR_AT(driver_request, 3, WORD) = 0;
539 CDROM_Audio_GetCDStatus(&wcda);
541 switch (driver_request[2]) {
543 io_stru = (dorealmode) ?
544 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(driver_request, 14, WORD), PTR_AT(driver_request, 16, WORD))) :
545 PTR_SEG_OFF_TO_LIN(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD));
547 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
548 switch (io_stru[0]) {
550 case 0: /* Get device Header */
552 static LPSTR ptr = 0;
554 ptr = SEGPTR_ALLOC(22);
555 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
556 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
557 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
558 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
559 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
560 PTR_AT(ptr, 11, char) = 'I';
561 PTR_AT(ptr, 12, char) = 'N';
562 PTR_AT(ptr, 13, char) = 'E';
563 PTR_AT(ptr, 14, char) = '_';
564 PTR_AT(ptr, 15, char) = 'C';
565 PTR_AT(ptr, 16, char) = 'D';
566 PTR_AT(ptr, 17, char) = '_';
567 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
568 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
569 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
571 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
576 case 1: /* location of head */
577 switch (io_stru[1]) {
579 PTR_AT(io_stru, 2, DWORD) = wcda.dwCurFrame;
582 MSCDEX_StoreMSF(wcda.dwCurFrame, io_stru + 2);
585 ERR("CDRom-Driver: Unsupported addressing mode !!\n");
588 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
591 case 4: /* Audio channel info */
600 TRACE(" ----> AUDIO CHANNEL INFO\n");
603 case 6: /* device status */
604 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
606 * 1 Supports HSG and Red Book addressing modes
607 * 0 Supports audio channel manipulation
609 * 1 Supports prefetching requests
612 * 1 Data read and plays audio/video tracks
615 * 0 Supports only cooked reading
617 * 0 see below (Door closed/opened)
619 if (wcda.cdaMode == WINE_CDA_OPEN)
621 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
624 case 8: /* Volume size */
625 PTR_AT(io_stru, 1, DWORD) = wcda.dwLastFrame;
626 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
629 case 9: /* media changed ? */
630 /* answers don't know... -1/1 for yes/no would be better */
631 io_stru[1] = 0; /* FIXME? 1? */
632 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
635 case 10: /* audio disk info */
636 io_stru[1] = wcda.nFirstTrack; /* starting track of the disc */
637 io_stru[2] = wcda.nLastTrack; /* ending track */
638 MSCDEX_StoreMSF(wcda.dwLastFrame, io_stru + 3);
640 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
641 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
644 case 11: /* audio track info */
645 if (io_stru[1] >= wcda.nFirstTrack && io_stru[1] <= wcda.nLastTrack) {
646 int nt = io_stru[1] - wcda.nFirstTrack;
647 MSCDEX_StoreMSF(wcda.lpdwTrackPos[nt], io_stru + 2);
648 /* starting point if the track */
649 io_stru[6] = (wcda.lpbTrackFlags[nt] & 0xF0) >> 4;
651 PTR_AT(io_stru, 2, DWORD) = 0;
654 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
655 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
658 case 12: /* get Q-Channel info */
659 io_stru[1] = wcda.lpbTrackFlags[wcda.nCurTrack - 1];
660 io_stru[2] = wcda.nCurTrack;
661 io_stru[3] = 0; /* FIXME ?? */
663 /* why the heck did MS use another format for 0MSF information... sigh */
667 MSCDEX_StoreMSF(wcda.dwCurFrame - wcda.lpdwTrackPos[wcda.nCurTrack - 1], bTmp);
668 io_stru[ 4] = bTmp[2];
669 io_stru[ 5] = bTmp[1];
670 io_stru[ 6] = bTmp[0];
673 MSCDEX_StoreMSF(wcda.dwCurFrame, bTmp);
674 io_stru[ 8] = bTmp[2];
675 io_stru[ 9] = bTmp[1];
676 io_stru[10] = bTmp[0];
679 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08lx, tp=%08lx)\n",
680 io_stru[ 1], io_stru[ 2], io_stru[ 3],
681 io_stru[ 4], io_stru[ 5], io_stru[ 6],
682 io_stru[ 8], io_stru[ 9], io_stru[10],
683 wcda.dwCurFrame, wcda.lpdwTrackPos[wcda.nCurTrack - 1]);
686 case 15: /* Audio status info */
687 /* !!!! FIXME FIXME FIXME !! */
688 PTR_AT(io_stru, 1, WORD) = 2 | ((wcda.cdaMode == WINE_CDA_PAUSE) ? 1 : 0);
689 if (wcda.cdaMode == WINE_CDA_OPEN) {
690 PTR_AT(io_stru, 3, DWORD) = 0;
691 PTR_AT(io_stru, 7, DWORD) = 0;
693 PTR_AT(io_stru, 3, DWORD) = wcda.lpdwTrackPos[0];
694 PTR_AT(io_stru, 7, DWORD) = wcda.lpdwTrackPos[wcda.nTracks - 1];
696 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
697 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
701 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
708 io_stru = (dorealmode) ?
709 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(driver_request, 14, WORD), PTR_AT(driver_request, 16, WORD))) :
710 PTR_SEG_OFF_TO_LIN(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD));
712 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
713 switch (io_stru[0]) {
715 CDROM_SetDoor(&wcda, 1);
716 TRACE(" ----> EJECT\n");
718 case 2: /* reset drive */
720 TRACE(" ----> RESET\n");
722 case 3: /* Audio Channel Control */
723 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
725 case 5: /* close tray */
726 CDROM_SetDoor(&wcda, 0);
727 TRACE(" ----> CLOSE TRAY\n");
730 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
740 at = PTR_AT(driver_request, 20, DWORD);
742 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
743 (BYTE)driver_request[13], at);
745 switch (driver_request[13]) {
746 case 1: /* Red book addressing mode = 0:m:s:f */
747 /* FIXME : frame <=> msf conversion routines could be shared
748 * between mscdex and mcicda
750 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
751 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
754 case 0: /* HSG addressing mode */
755 CDROM_Audio_Seek(&wcda, at);
758 ERR("Unsupported address mode !!\n");
769 beg = end = PTR_AT(driver_request, 14, DWORD);
770 end += PTR_AT(driver_request, 18, DWORD);
772 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
773 (BYTE)driver_request[13], beg, end);
775 switch (driver_request[13]) {
776 case 1: /* Red book addressing mode = 0:m:s:f */
777 /* FIXME : frame <=> msf conversion routines could be shared
778 * between mscdex and mcicda
780 beg = LOBYTE(HIWORD(beg)) * CDFRAMES_PERMIN +
781 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
783 end = LOBYTE(HIWORD(end)) * CDFRAMES_PERMIN +
784 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
787 case 0: /* HSG addressing mode */
788 CDROM_Audio_Play(&wcda, beg, end);
791 ERR("Unsupported address mode !!\n");
799 if (wcda.cdaMode == WINE_CDA_PLAY) {
800 CDROM_Audio_Pause(&wcda, 1);
801 TRACE(" --> STOP AUDIO (Paused)\n");
803 CDROM_Audio_Stop(&wcda);
804 TRACE(" --> STOP AUDIO (Stopped)\n");
809 TRACE(" --> RESUME AUDIO\n");
810 CDROM_Audio_Pause(&wcda, 0);
814 FIXME(" ioctl uninplemented <%d>\n", driver_request[2]);
818 /* setting error codes if any */
820 driver_request[4] |= 0x80;
821 driver_request[3] = Error;
824 /* setting status bits
825 * 3 == playing && done
828 driver_request[4] |= (wcda.cdaMode == WINE_CDA_PLAY) ? 3 : 1;
830 MSCDEX_Dump("End", driver_request, dorealmode);
834 FIXME("Unimplemented MSCDEX function 0x%02X.\n", AL_reg(context));