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>
13 #include "wine/winbase16.h"
17 /* #define DEBUG_INT */
18 #include "debugtools.h"
21 DEFAULT_DEBUG_CHANNEL(int);
23 /* base WPROCS.DLL ordinal number for VxDs */
26 static void do_int2f_16( CONTEXT86 *context );
27 static void MSCDEX_Handler( CONTEXT86 *context );
29 /**********************************************************************
30 * INT_Int2fHandler (WPROCS.147)
32 * Handler for int 2fh (multiplex).
34 void WINAPI INT_Int2fHandler( CONTEXT86 *context )
36 TRACE("Subfunction 0x%X\n", AX_reg(context));
38 switch(AH_reg(context))
41 AL_reg(context) = 0xff; /* share is installed */
44 case 0x11: /* Network Redirector / IFSFUNC */
45 switch (LOBYTE(context->Eax))
47 case 0x00: /* Install check */
50 case 0x80: /* Enhanced services - Install check */
54 INT_BARF( context, 0x2f );
60 switch (LOBYTE(context->Eax))
62 case 0x2e: /* get or set DOS error table address */
63 switch (DL_reg(context))
65 /* Four tables: even commands are 'get', odd are 'set' */
66 /* DOS 5.0+ ignores "set" commands */
73 /* Instead of having a message table in DOS-space, */
74 /* we can use a special case for MS-DOS to force */
75 /* the secondary interface. */
80 context->SegEs = 0x0001;
81 DI_reg(context) = 0x0000;
84 FIXME("No real-mode handler for errors yet! (bye!)\n");
87 INT_BARF(context, 0x2f);
91 INT_BARF(context, 0x2f);
95 case 0x15: /* mscdex */
96 MSCDEX_Handler(context);
100 do_int2f_16( context );
103 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
104 /* Not supported yet, do nothing */
109 switch (LOBYTE(context->Eax))
111 case 0x00: /* XMS v2+ installation check */
112 WARN("XMS is not fully implemented\n");
113 AL_reg(context) = 0x80;
115 case 0x10: /* XMS v2+ get driver address */
117 context->SegEs = DOSMEM_xms_seg;
122 INT_BARF( context, 0x2f );
125 FIXME("check for XMS (not supported)\n");
126 AL_reg(context) = 0x42; /* != 0x80 */
131 switch (LOBYTE(context->Eax))
142 /* Microsoft Profiler - not installed */
145 INT_BARF( context, 0x2f );
150 switch(LOBYTE(context->Eax))
152 case 0x10: /* smartdrv */
153 break; /* not installed */
154 case 0x11: /* dblspace */
155 break; /* not installed */
156 case 0x12: /* realtime compression interface */
157 break; /* not installed */
158 case 0x32: /* patch IO.SYS (???) */
159 break; /* we have no IO.SYS, so we can't patch it :-/ */
161 INT_BARF( context, 0x2f );
165 switch(LOBYTE(context->Eax))
172 FIXME("Task Switcher - not implemented\n");
175 INT_BARF( context, 0x2f );
178 case 0x56: /* INTERLNK */
179 switch(LOBYTE(context->Eax))
181 case 0x01: /* check if redirected drive */
182 AL_reg(context) = 0; /* not redirected */
185 INT_BARF( context, 0x2f );
188 case 0x7a: /* NOVELL NetWare */
189 switch (LOBYTE(context->Eax))
191 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
194 case 0x20: /* Get VLM Call Address */
195 /* return nothing -> NetWare not installed */
198 INT_BARF( context, 0x2f );
202 case 0xb7: /* append */
203 LOBYTE(context->Eax) = 0; /* not installed */
205 case 0xb8: /* network */
206 switch (LOBYTE(context->Eax))
208 case 0x00: /* Install check */
212 INT_BARF( context, 0x2f );
216 case 0xbd: /* some Novell network install check ??? */
217 AX_reg(context) = 0xa5a5; /* pretend to have Novell IPX installed */
219 case 0xbf: /* REDIRIFS.EXE */
220 switch (LOBYTE(context->Eax))
222 case 0x00: /* Install check */
226 INT_BARF( context, 0x2f );
231 switch(LOBYTE(context->Eax))
233 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
234 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
235 && DX_reg(context) == 0x3432)
236 TRACE("Check for QEMM v5.0+ (not installed)\n");
239 INT_BARF( context, 0x2f );
243 case 0xd7: /* Banyan Vines */
244 switch (LOBYTE(context->Eax))
246 case 0x01: /* Install check - Get Int Number */
250 INT_BARF( context, 0x2f );
255 switch(LOBYTE(context->Eax))
257 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
258 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
259 && DX_reg(context) == 0x8f4f)
260 TRACE("Check for QDPMI.SYS (not installed)\n");
263 INT_BARF( context, 0x2f );
267 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
270 INT_BARF( context, 0x2f );
276 /**********************************************************************
279 static void do_int2f_16( CONTEXT86 *context )
283 switch(LOBYTE(context->Eax))
285 case 0x00: /* Windows enhanced mode installation check */
286 AX_reg(context) = (GetWinFlags16() & WF_ENHANCED) ?
287 LOWORD(GetVersion16()) : 0;
290 case 0x0a: /* Get Windows version and type */
292 BX_reg(context) = (LOWORD(GetVersion16()) << 8) |
293 (LOWORD(GetVersion16()) >> 8);
294 CX_reg(context) = (GetWinFlags16() & WF_ENHANCED) ? 3 : 2;
297 case 0x0b: /* Identify Windows-aware TSRs */
298 /* we don't have any pre-Windows TSRs */
301 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
302 /* We can mock this up. But not today... */
303 FIXME("Get Shell Parameters\n");
306 case 0x80: /* Release time-slice */
310 case 0x81: /* Begin critical section. */
314 case 0x82: /* End critical section. */
318 case 0x83: /* Return Current Virtual Machine ID */
319 /* Virtual Machines are usually created/destroyed when Windows runs
320 * DOS programs. Since we never do, we are always in the System VM.
321 * According to Ralf Brown's Interrupt List, never return 0. But it
322 * seems to work okay (returning 0), just to be sure we return 1.
324 BX_reg(context) = 1; /* VM 1 is probably the System VM */
327 case 0x84: /* Get device API entry point */
329 HMODULE16 mod = GetModuleHandle16("wprocs");
330 if (mod < 32) mod = LoadLibrary16( "wprocs" );
331 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
332 if (!addr) /* not supported */
333 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
334 context->SegEs = SELECTOROF(addr);
335 DI_reg(context) = OFFSETOF(addr);
339 case 0x86: /* DPMI detect mode */
340 AX_reg(context) = 0; /* Running under DPMI */
343 case 0x87: /* DPMI installation check */
344 #if 1 /* DPMI still breaks pkunzip */
345 if (ISV86(context)) break; /* so bail out for now if in v86 mode */
350 AX_reg(context) = 0x0000; /* DPMI Installed */
351 BX_reg(context) = 0x0001; /* 32bits available */
352 CL_reg(context) = si.wProcessorLevel;
353 DX_reg(context) = 0x005a; /* DPMI major/minor 0.90 */
354 SI_reg(context) = 0; /* # of para. of DOS extended private data */
355 context->SegEs = DOSMEM_dpmi_seg;
356 DI_reg(context) = 0; /* ES:DI is DPMI switch entry point */
359 case 0x8a: /* DPMI get vendor-specific API entry point. */
360 /* The 1.0 specs say this should work with all 0.9 hosts. */
364 INT_BARF( context, 0x2f );
368 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
369 * must be <size> aligned
370 * <size> could be WORD, DWORD...
371 * in this case, we would need two macros, one for read, the other one for write
372 * Note: PTR_AT can be used as an l-value
374 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
376 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
378 /**********************************************************************
379 * MSCDEX_Dump [internal]
381 * Dumps mscdex requests to int debug channel.
383 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
391 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
392 for (i = 0; i < req[0]; i++) {
393 ptr += sprintf(ptr, "%02x ", req[i]);
399 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
400 ios = (dorealmode) ? PTR_REAL_TO_LIN( PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)) :
401 MapSL(MAKESEGPTR(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)));
403 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
404 ptr += sprintf(ptr, "%02x ", ios[i]);
405 if ((i & 0x1F) == 0x1F) {
415 #define MSCDEX_Dump(pfx, req, drm)
418 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
420 val[3] = 0; /* zero */
421 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
422 val[1] = (frame - CDFRAMES_PERMIN * val[2]) / CDFRAMES_PERSEC; /* seconds */
423 val[0] = frame - CDFRAMES_PERMIN * val[2] - CDFRAMES_PERSEC * val[1]; /* frames */
426 static int is_cdrom( int drive)
428 char root[] = "A:\\";
430 return (GetDriveTypeA(root) == DRIVE_CDROM);
433 static void MSCDEX_Handler(CONTEXT86* context)
438 switch(LOBYTE(context->Eax)) {
439 case 0x00: /* Installation check */
440 /* Count the number of contiguous CDROM drives
442 for (drive = count = 0; drive < 26; drive++) {
443 if (is_cdrom(drive)) {
444 while (is_cdrom(drive + count)) count++;
448 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
449 BX_reg(context) = count;
450 CX_reg(context) = (drive < 26) ? drive : 0;
453 case 0x0B: /* drive check */
454 AX_reg(context) = is_cdrom(CX_reg(context));
455 BX_reg(context) = 0xADAD;
458 case 0x0C: /* get version */
459 BX_reg(context) = 0x020a;
460 TRACE("Version number => %04x\n", BX_reg(context));
463 case 0x0D: /* get drive letters */
464 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
466 for (drive = 0; drive < 26; drive++) {
467 if (is_cdrom(drive)) *p++ = drive;
469 TRACE("Get drive letters\n");
472 case 0x10: /* direct driver access */
474 static WINE_CDAUDIO wcda;
476 BYTE* driver_request;
478 BYTE Error = 255; /* No Error */
479 int dorealmode = ISV86(context);
481 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
483 if (!driver_request) {
484 /* FIXME - to be deleted ?? */
485 ERR("ES:BX==0 ! SEGFAULT ?\n");
486 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
487 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
488 driver_request[4] |= 0x80;
489 driver_request[3] = 5; /* bad request length */
493 * - the current implementation only supports a single CD ROM
495 CDROM_Open(&wcda, -1);
496 dev = CDROM_OpenDev(&wcda);
497 TRACE("CDROM device driver -> command <%d>\n", (unsigned char)driver_request[2]);
499 for (drive = 0; drive < 26; drive++) if (is_cdrom(drive)) break;
500 /* drive contains the first CD ROM */
501 if (CX_reg(context) != drive) {
502 WARN("Request made doesn't match a CD ROM drive (%d/%d)\n", CX_reg(context), drive);
503 driver_request[4] |= 0x80;
504 driver_request[3] = 1; /* unknown unit */
508 MSCDEX_Dump("Beg", driver_request, dorealmode);
510 /* set status to 0 */
511 PTR_AT(driver_request, 3, WORD) = 0;
512 CDROM_Audio_GetCDStatus(&wcda, dev);
514 switch (driver_request[2]) {
516 io_stru = (dorealmode) ?
517 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD) ) :
518 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
520 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
521 switch (io_stru[0]) {
523 case 0: /* Get device Header */
525 static LPSTR ptr = 0;
527 ptr = SEGPTR_ALLOC(22);
528 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
529 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
530 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
531 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
532 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
533 PTR_AT(ptr, 11, char) = 'I';
534 PTR_AT(ptr, 12, char) = 'N';
535 PTR_AT(ptr, 13, char) = 'E';
536 PTR_AT(ptr, 14, char) = '_';
537 PTR_AT(ptr, 15, char) = 'C';
538 PTR_AT(ptr, 16, char) = 'D';
539 PTR_AT(ptr, 17, char) = '_';
540 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
541 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
542 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
544 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
549 case 1: /* location of head */
550 switch (io_stru[1]) {
552 PTR_AT(io_stru, 2, DWORD) = wcda.dwCurFrame;
555 MSCDEX_StoreMSF(wcda.dwCurFrame, io_stru + 2);
558 ERR("CD-ROM driver: unsupported addressing mode !!\n");
561 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
564 case 4: /* Audio channel info */
573 TRACE(" ----> AUDIO CHANNEL INFO\n");
576 case 6: /* device status */
577 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
579 * 1 Supports HSG and Red Book addressing modes
580 * 0 Supports audio channel manipulation
582 * 1 Supports prefetching requests
585 * 1 Data read and plays audio/video tracks
588 * 0 Supports only cooked reading
590 * 0 see below (Door closed/opened)
592 if (wcda.cdaMode == WINE_CDA_OPEN)
594 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
597 case 8: /* Volume size */
598 PTR_AT(io_stru, 1, DWORD) = wcda.dwLastFrame;
599 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
602 case 9: /* media changed ? */
603 /* answers don't know... -1/1 for yes/no would be better */
604 io_stru[1] = 0; /* FIXME? 1? */
605 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
608 case 10: /* audio disk info */
609 io_stru[1] = wcda.nFirstTrack; /* starting track of the disc */
610 io_stru[2] = wcda.nLastTrack; /* ending track */
611 MSCDEX_StoreMSF(wcda.dwLastFrame, io_stru + 3);
613 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
614 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
617 case 11: /* audio track info */
618 if (io_stru[1] >= wcda.nFirstTrack && io_stru[1] <= wcda.nLastTrack) {
619 int nt = io_stru[1] - wcda.nFirstTrack;
620 MSCDEX_StoreMSF(wcda.lpdwTrackPos[nt], io_stru + 2);
621 /* starting point if the track */
622 io_stru[6] = (wcda.lpbTrackFlags[nt] & 0xF0) >> 4;
624 PTR_AT(io_stru, 2, DWORD) = 0;
627 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
628 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
631 case 12: /* get Q-Channel info */
632 io_stru[1] = wcda.lpbTrackFlags[wcda.nCurTrack - 1];
633 io_stru[2] = wcda.nCurTrack;
634 io_stru[3] = 0; /* FIXME ?? */
636 /* why the heck did MS use another format for 0MSF information... sigh */
640 MSCDEX_StoreMSF(wcda.dwCurFrame - wcda.lpdwTrackPos[wcda.nCurTrack - 1], bTmp);
641 io_stru[ 4] = bTmp[2];
642 io_stru[ 5] = bTmp[1];
643 io_stru[ 6] = bTmp[0];
646 MSCDEX_StoreMSF(wcda.dwCurFrame, bTmp);
647 io_stru[ 8] = bTmp[2];
648 io_stru[ 9] = bTmp[1];
649 io_stru[10] = bTmp[0];
652 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08lx, tp=%08lx)\n",
653 io_stru[ 1], io_stru[ 2], io_stru[ 3],
654 io_stru[ 4], io_stru[ 5], io_stru[ 6],
655 io_stru[ 8], io_stru[ 9], io_stru[10],
656 wcda.dwCurFrame, wcda.lpdwTrackPos[wcda.nCurTrack - 1]);
659 case 15: /* Audio status info */
660 /* !!!! FIXME FIXME FIXME !! */
661 PTR_AT(io_stru, 1, WORD) = 2 | ((wcda.cdaMode == WINE_CDA_PAUSE) ? 1 : 0);
662 if (wcda.cdaMode == WINE_CDA_OPEN) {
663 PTR_AT(io_stru, 3, DWORD) = 0;
664 PTR_AT(io_stru, 7, DWORD) = 0;
666 PTR_AT(io_stru, 3, DWORD) = wcda.lpdwTrackPos[0];
667 PTR_AT(io_stru, 7, DWORD) = wcda.lpdwTrackPos[wcda.nTracks - 1];
669 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
670 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
674 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
681 io_stru = (dorealmode) ?
682 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)) :
683 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
685 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
686 switch (io_stru[0]) {
688 CDROM_SetDoor(&wcda, 1, dev);
689 TRACE(" ----> EJECT\n");
691 case 2: /* reset drive */
692 CDROM_Reset(&wcda, dev);
693 TRACE(" ----> RESET\n");
695 case 3: /* Audio Channel Control */
696 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
698 case 5: /* close tray */
699 CDROM_SetDoor(&wcda, 0, dev);
700 TRACE(" ----> CLOSE TRAY\n");
703 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
713 at = PTR_AT(driver_request, 20, DWORD);
715 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
716 (BYTE)driver_request[13], at);
718 switch (driver_request[13]) {
719 case 1: /* Red book addressing mode = 0:m:s:f */
720 /* FIXME : frame <=> msf conversion routines could be shared
721 * between mscdex and mcicda
723 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
724 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
727 case 0: /* HSG addressing mode */
728 CDROM_Audio_Seek(&wcda, at, dev);
731 ERR("Unsupported address mode !!\n");
742 beg = end = PTR_AT(driver_request, 14, DWORD);
743 end += PTR_AT(driver_request, 18, DWORD);
745 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
746 (BYTE)driver_request[13], beg, end);
748 switch (driver_request[13]) {
749 case 1: /* Red book addressing mode = 0:m:s:f */
750 /* FIXME : frame <=> msf conversion routines could be shared
751 * between mscdex and mcicda
753 beg = LOBYTE(HIWORD(beg)) * CDFRAMES_PERMIN +
754 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
756 end = LOBYTE(HIWORD(end)) * CDFRAMES_PERMIN +
757 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
760 case 0: /* HSG addressing mode */
761 CDROM_Audio_Play(&wcda, beg, end, dev);
764 ERR("Unsupported address mode !!\n");
772 if (wcda.cdaMode == WINE_CDA_PLAY) {
773 CDROM_Audio_Pause(&wcda, 1, dev);
774 TRACE(" --> STOP AUDIO (Paused)\n");
776 CDROM_Audio_Stop(&wcda, dev);
777 TRACE(" --> STOP AUDIO (Stopped)\n");
782 TRACE(" --> RESUME AUDIO\n");
783 CDROM_Audio_Pause(&wcda, 0, dev);
787 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
791 /* setting error codes if any */
793 driver_request[4] |= 0x80;
794 driver_request[3] = Error;
799 /* setting status bits
800 * 3 == playing && done
803 driver_request[4] |= (wcda.cdaMode == WINE_CDA_PLAY) ? 3 : 1;
805 MSCDEX_Dump("End", driver_request, dorealmode);
809 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));