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 */
27 /* base WPROCS.DLL ordinal number for VxDs */
30 static void do_int2f_16( CONTEXT
*context
);
31 static void MSCDEX_Handler( CONTEXT
*context
);
33 /**********************************************************************
36 * Handler for int 2fh (multiplex).
38 void WINAPI
INT_Int2fHandler( CONTEXT
*context
)
40 TRACE(int,"Subfunction 0x%X\n", AX_reg(context
));
42 switch(AH_reg(context
))
45 AL_reg(context
) = 0xff; /* share is installed */
48 case 0x11: /* Network Redirector / IFSFUNC */
49 switch (AL_reg(context
))
51 case 0x00: /* Install check */
54 case 0x80: /* Enhanced services - Install check */
58 INT_BARF( context
, 0x2f );
64 switch (AL_reg(context
))
66 case 0x2e: /* get or set DOS error table address */
67 switch (DL_reg(context
))
69 /* Four tables: even commands are 'get', odd are 'set' */
70 /* DOS 5.0+ ignores "set" commands */
77 /* Instead of having a message table in DOS-space, */
78 /* we can use a special case for MS-DOS to force */
79 /* the secondary interface. */
84 ES_reg(context
) = 0x0001;
85 DI_reg(context
) = 0x0000;
88 FIXME(int, "No real-mode handler for errors yet! (bye!)");
91 INT_BARF(context
, 0x2f);
95 INT_BARF(context
, 0x2f);
99 case 0x15: /* mscdex */
100 MSCDEX_Handler(context
);
104 do_int2f_16( context
);
107 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
108 /* Not supported yet, do nothing */
113 switch (AL_reg(context
))
115 case 0x00: /* XMS v2+ installation check */
116 WARN(int,"XMS is not fully implemented\n");
117 AL_reg(context
) = 0x80;
119 case 0x10: /* XMS v2+ get driver address */
121 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
122 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
123 GlobalUnlock16( GetCurrentTask() );
125 if (pModule
&& pModule
->lpDosTask
)
126 ES_reg(context
) = pModule
->lpDosTask
->xms_seg
;
134 INT_BARF( context
, 0x2f );
137 FIXME(int,"check for XMS (not supported)\n");
138 AL_reg(context
) = 0x42; /* != 0x80 */
143 switch (AL_reg(context
))
154 /* Microsoft Profiler - not installed */
157 INT_BARF( context
, 0x2f );
162 switch(AL_reg(context
))
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 );
176 case 0x56: /* INTERLNK */
177 switch(AL_reg(context
))
179 case 0x01: /* check if redirected drive */
180 AL_reg(context
) = 0; /* not redirected */
183 INT_BARF( context
, 0x2f );
186 case 0x7a: /* NOVELL NetWare */
187 switch (AL_reg(context
))
189 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
192 case 0x20: /* Get VLM Call Address */
193 /* return nothing -> NetWare not installed */
196 INT_BARF( context
, 0x2f );
200 case 0xb7: /* append */
201 AL_reg(context
) = 0; /* not installed */
203 case 0xb8: /* network */
204 switch (AL_reg(context
))
206 case 0x00: /* Install check */
210 INT_BARF( context
, 0x2f );
214 case 0xbd: /* some Novell network install check ??? */
215 AX_reg(context
) = 0xa5a5; /* pretend to have Novell IPX installed */
217 case 0xbf: /* REDIRIFS.EXE */
218 switch (AL_reg(context
))
220 case 0x00: /* Install check */
224 INT_BARF( context
, 0x2f );
228 case 0xd7: /* Banyan Vines */
229 switch (AL_reg(context
))
231 case 0x01: /* Install check - Get Int Number */
235 INT_BARF( context
, 0x2f );
239 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
242 INT_BARF( context
, 0x2f );
248 /**********************************************************************
251 static void do_int2f_16( CONTEXT
*context
)
255 switch(AL_reg(context
))
257 case 0x00: /* Windows enhanced mode installation check */
258 AX_reg(context
) = (GetWinFlags16() & WF_ENHANCED
) ?
259 LOWORD(GetVersion16()) : 0;
262 case 0x0a: /* Get Windows version and type */
264 BX_reg(context
) = (LOWORD(GetVersion16()) << 8) |
265 (LOWORD(GetVersion16()) >> 8);
266 CX_reg(context
) = (GetWinFlags16() & WF_ENHANCED
) ? 3 : 2;
269 case 0x0b: /* Identify Windows-aware TSRs */
270 /* we don't have any pre-Windows TSRs */
273 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
274 /* We can mock this up. But not today... */
275 FIXME(int, "Get Shell Parameters\n");
278 case 0x80: /* Release time-slice */
282 case 0x81: /* Begin critical section. */
286 case 0x82: /* End critical section. */
290 case 0x83: /* Return Current Virtual Machine ID */
291 /* Virtual Machines are usually created/destroyed when Windows runs
292 * DOS programs. Since we never do, we are always in the System VM.
293 * According to Ralf Brown's Interrupt List, never return 0. But it
294 * seems to work okay (returning 0), just to be sure we return 1.
296 BX_reg(context
) = 1; /* VM 1 is probably the System VM */
299 case 0x84: /* Get device API entry point */
300 addr
= (DWORD
)NE_GetEntryPoint( GetModuleHandle16("WPROCS"),
301 VXD_BASE
+ BX_reg(context
) );
302 if (!addr
) /* not supported */
304 ERR(int, "Accessing unknown VxD %04x - Expect a failure now.\n",
307 ES_reg(context
) = SELECTOROF(addr
);
308 DI_reg(context
) = OFFSETOF(addr
);
311 case 0x86: /* DPMI detect mode */
312 AX_reg(context
) = 0; /* Running under DPMI */
315 case 0x87: /* DPMI installation check */
316 #if 1 /* DPMI still breaks pkunzip */
317 if (ISV86(context
)) break; /* so bail out for now if in v86 mode */
320 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
321 NE_MODULE
*pModule
= pTask
? NE_GetPtr( pTask
->hModule
) : NULL
;
324 GlobalUnlock16( GetCurrentTask() );
326 AX_reg(context
) = 0x0000; /* DPMI Installed */
327 BX_reg(context
) = 0x0001; /* 32bits available */
328 CL_reg(context
) = si
.wProcessorLevel
;
329 DX_reg(context
) = 0x005a; /* DPMI major/minor 0.90 */
330 SI_reg(context
) = 0; /* # of para. of DOS extended private data */
331 #ifdef MZ_SUPPORTED /* ES:DI is DPMI switch entry point */
332 if (pModule
&& pModule
->lpDosTask
)
333 ES_reg(context
) = pModule
->lpDosTask
->dpmi_seg
;
340 case 0x8a: /* DPMI get vendor-specific API entry point. */
341 /* The 1.0 specs say this should work with all 0.9 hosts. */
345 INT_BARF( context
, 0x2f );
349 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
350 * must be <size> aligned
351 * <size> could be WORD, DWORD...
352 * in this case, we would need two macros, one for read, the other one for write
353 * Note: PTR_AT can be used as an l-value
355 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
357 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
359 /**********************************************************************
360 * MSCDEX_Dump [internal]
362 * Dumps mscdex requests to int debug channel.
364 static void MSCDEX_Dump(char* pfx
, BYTE
* req
, int dorealmode
)
372 ptr
+= sprintf(ptr
, "%s\tCommand => ", pfx
);
373 for (i
= 0; i
< req
[0]; i
++) {
374 ptr
+= sprintf(ptr
, "%02x ", req
[i
]);
380 ptr
+= sprintf(ptr
, "\n\t\t\t\tIO_struct => ");
382 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(req
, 14, WORD
), PTR_AT(req
, 16, WORD
))) :
383 PTR_SEG_OFF_TO_LIN(PTR_AT(req
, 16, WORD
), PTR_AT(req
, 14, WORD
));
385 for (i
= 0; i
< PTR_AT(req
, 18, WORD
); i
++) {
386 ptr
+= sprintf(ptr
, "%02x ", ios
[i
]);
387 if ((i
& 0x1F) == 0x1F) {
394 TRACE(int, "%s\n", buf
);
397 #define MSCDEX_Dump(pfx, req, drm)
400 static void MSCDEX_StoreMSF(DWORD frame
, BYTE
* val
)
402 val
[3] = 0; /* zero */
403 val
[2] = frame
/ CDFRAMES_PERMIN
; /* minutes */
404 val
[1] = (frame
- CDFRAMES_PERMIN
* val
[2]) / CDFRAMES_PERSEC
; /* seconds */
405 val
[0] = frame
- CDFRAMES_PERMIN
* val
[2] - CDFRAMES_PERSEC
* val
[1]; /* frames */
408 static void MSCDEX_Handler(CONTEXT
* context
)
413 switch(AL_reg(context
)) {
414 case 0x00: /* Installation check */
415 /* Count the number of contiguous CDROM drives
417 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++) {
418 if (DRIVE_GetType(drive
) == TYPE_CDROM
) {
419 while (DRIVE_GetType(drive
+ count
) == TYPE_CDROM
) count
++;
423 TRACE(int, "Installation check: %d cdroms, starting at %d\n", count
, drive
);
424 BX_reg(context
) = count
;
425 CX_reg(context
) = (drive
< MAX_DOS_DRIVES
) ? drive
: 0;
428 case 0x0B: /* drive check */
429 AX_reg(context
) = (DRIVE_GetType(CX_reg(context
)) == TYPE_CDROM
);
430 BX_reg(context
) = 0xADAD;
433 case 0x0C: /* get version */
434 BX_reg(context
) = 0x020a;
435 TRACE(int, "Version number => %04x\n", BX_reg(context
));
438 case 0x0D: /* get drive letters */
439 p
= CTX_SEG_OFF_TO_LIN(context
, ES_reg(context
), EBX_reg(context
));
440 memset(p
, 0, MAX_DOS_DRIVES
);
441 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++) {
442 if (DRIVE_GetType(drive
) == TYPE_CDROM
) *p
++ = drive
;
444 TRACE(int, "Get drive letters\n");
447 case 0x10: /* direct driver acces */
449 static WINE_CDAUDIO wcda
;
450 BYTE
* driver_request
;
452 BYTE Error
= 255; /* No Error */
453 int dorealmode
= ISV86(context
);
455 driver_request
= (dorealmode
) ?
456 DOSMEM_MapRealToLinear(MAKELONG(BX_reg(context
), ES_reg(context
))) :
457 PTR_SEG_OFF_TO_LIN(ES_reg(context
), BX_reg(context
));
459 if (!driver_request
) {
460 /* FIXME - to be deleted ?? */
461 ERR(int, "ES:BX==0 ! SEGFAULT ?\n");
462 ERR(int, "-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
463 BX_reg(context
), ES_reg(context
), DS_reg(context
), CX_reg(context
));
464 driver_request
[4] |= 0x80;
465 driver_request
[3] = 5; /* bad request length */
468 /* FIXME - would be better to open the device at the begining of the wine session...
469 * - the device is also never closed...
470 * - the current implementation only supports a single CD ROM
472 if (wcda
.unixdev
<= 0)
474 TRACE(int, "CDROM device driver -> command <%d>\n", (unsigned char)driver_request
[2]);
477 drive
< MAX_DOS_DRIVES
&& DRIVE_GetType(drive
) != TYPE_CDROM
;
479 /* drive contains the first CD ROM */
480 if (CX_reg(context
) != drive
) {
481 WARN(int, "Request made doesn't match a CD ROM drive (%d/%d)\n", CX_reg(context
), drive
);
482 driver_request
[4] |= 0x80;
483 driver_request
[3] = 1; /* unknown unit */
487 MSCDEX_Dump("Beg", driver_request
, dorealmode
);
489 /* set status to 0 */
490 PTR_AT(driver_request
, 3, WORD
) = 0;
491 CDAUDIO_GetCDStatus(&wcda
);
493 switch (driver_request
[2]) {
495 io_stru
= (dorealmode
) ?
496 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(driver_request
, 14, WORD
), PTR_AT(driver_request
, 16, WORD
))) :
497 PTR_SEG_OFF_TO_LIN(PTR_AT(driver_request
, 16, WORD
), PTR_AT(driver_request
, 14, WORD
));
499 TRACE(int, " --> IOCTL INPUT <%d>\n", io_stru
[0]);
500 switch (io_stru
[0]) {
502 case 0: /* Get device Header */
504 static LPSTR ptr
= 0;
506 ptr
= SEGPTR_ALLOC(22);
507 PTR_AT(ptr
, 0, DWORD
) = ~1; /* Next Device Driver */
508 PTR_AT(ptr
, 4, WORD
) = 0xC800; /* Device attributes */
509 PTR_AT(ptr
, 6, WORD
) = 0x1234; /* Pointer to device strategy routine: FIXME */
510 PTR_AT(ptr
, 8, WORD
) = 0x3142; /* Pointer to device interrupt routine: FIXME */
511 PTR_AT(ptr
, 10, char) = 'W'; /* 8-byte character device name field */
512 PTR_AT(ptr
, 11, char) = 'I';
513 PTR_AT(ptr
, 12, char) = 'N';
514 PTR_AT(ptr
, 13, char) = 'E';
515 PTR_AT(ptr
, 14, char) = '_';
516 PTR_AT(ptr
, 15, char) = 'C';
517 PTR_AT(ptr
, 16, char) = 'D';
518 PTR_AT(ptr
, 17, char) = '_';
519 PTR_AT(ptr
, 18, WORD
) = 0; /* Reserved (must be zero) */
520 PTR_AT(ptr
, 20, BYTE
) = 0; /* Drive letter (must be zero) */
521 PTR_AT(ptr
, 21, BYTE
) = 1; /* Number of units supported (one or more) FIXME*/
523 PTR_AT(io_stru
, DWORD
, 0) = SEGPTR_GET(ptr
);
528 case 1: /* location of head */
529 switch (io_stru
[1]) {
531 PTR_AT(io_stru
, 2, DWORD
) = wcda
.dwCurFrame
;
534 MSCDEX_StoreMSF(wcda
.dwCurFrame
, io_stru
+ 2);
537 ERR(int, "CDRom-Driver: Unsupported addressing mode !!\n");
540 TRACE(int, " ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru
, 2, DWORD
));
543 case 4: /* Audio channel info */
552 TRACE(int, " ----> AUDIO CHANNEL INFO\n");
555 case 6: /* device status */
556 PTR_AT(io_stru
, 1, DWORD
) = 0x00000290;
558 * 1 Supports HSG and Red Book addressing modes
559 * 0 Supports audio channel manipulation
561 * 1 Supports prefetching requests
564 * 1 Data read and plays audio/video tracks
567 * 0 Supports only cooked reading
569 * 0 see below (Door closed/opened)
571 if (wcda
.cdaMode
== WINE_CDA_OPEN
)
573 TRACE(int, " ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru
, 1, DWORD
));
576 case 8: /* Volume size */
577 PTR_AT(io_stru
, 1, DWORD
) = wcda
.dwTotalLen
;
578 TRACE(int, " ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru
, 1, DWORD
));
581 case 9: /* media changed ? */
582 /* answers don't know... -1/1 for yes/no would be better */
583 io_stru
[1] = 0; /* FIXME? 1? */
584 TRACE(int, " ----> MEDIA CHANGED <%d>\n", io_stru
[1]);
587 case 10: /* audio disk info */
588 io_stru
[1] = wcda
.nFirstTrack
; /* starting track of the disc */
589 io_stru
[2] = wcda
.nLastTrack
; /* ending track */
590 MSCDEX_StoreMSF(wcda
.dwTotalLen
, io_stru
+ 3);
592 TRACE(int, " ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
593 io_stru
[1], io_stru
[2], PTR_AT(io_stru
, 3, DWORD
));
596 case 11: /* audio track info */
597 if (io_stru
[1] >= wcda
.nFirstTrack
&& io_stru
[1] <= wcda
.nLastTrack
) {
598 int nt
= io_stru
[1] - wcda
.nFirstTrack
;
599 MSCDEX_StoreMSF(wcda
.lpdwTrackPos
[nt
], io_stru
+ 2);
600 /* starting point if the track */
601 io_stru
[6] = (wcda
.lpbTrackFlags
[nt
] & 0xF0) >> 4;
603 PTR_AT(io_stru
, 2, DWORD
) = 0;
606 TRACE(int, " ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
607 io_stru
[1], PTR_AT(io_stru
, 2, DWORD
), io_stru
[6]);
610 case 12: /* get Q-Channel info */
611 io_stru
[1] = wcda
.lpbTrackFlags
[wcda
.nCurTrack
- 1];
612 io_stru
[2] = wcda
.nCurTrack
;
613 io_stru
[3] = 0; /* FIXME ?? */
615 /* why the heck did MS use another format for 0MSF information... sigh */
619 MSCDEX_StoreMSF(wcda
.dwCurFrame
- wcda
.lpdwTrackPos
[wcda
.nCurTrack
- 1], bTmp
);
620 io_stru
[ 4] = bTmp
[2];
621 io_stru
[ 5] = bTmp
[1];
622 io_stru
[ 6] = bTmp
[0];
625 MSCDEX_StoreMSF(wcda
.dwCurFrame
, bTmp
);
626 io_stru
[ 8] = bTmp
[2];
627 io_stru
[ 9] = bTmp
[1];
628 io_stru
[10] = bTmp
[0];
631 TRACE(int, "Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08lx, tp=%08lx)\n",
632 io_stru
[ 1], io_stru
[ 2], io_stru
[ 3],
633 io_stru
[ 4], io_stru
[ 5], io_stru
[ 6],
634 io_stru
[ 8], io_stru
[ 9], io_stru
[10],
635 wcda
.dwCurFrame
, wcda
.lpdwTrackPos
[wcda
.nCurTrack
- 1]);
638 case 15: /* Audio status info */
639 /* !!!! FIXME FIXME FIXME !! */
640 PTR_AT(io_stru
, 1, WORD
) = 2 | ((wcda
.cdaMode
== WINE_CDA_PAUSE
) ? 1 : 0);
641 PTR_AT(io_stru
, 3, DWORD
) = wcda
.lpdwTrackPos
[0];
642 PTR_AT(io_stru
, 7, DWORD
) = wcda
.lpdwTrackPos
[wcda
.nTracks
- 1];
643 TRACE(int, "Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
644 PTR_AT(io_stru
, 1, WORD
), PTR_AT(io_stru
, 3, DWORD
), PTR_AT(io_stru
, 7, DWORD
));
648 FIXME(int, "IOCTL INPUT: Unimplemented <%d>!!\n", io_stru
[0]);
655 io_stru
= (dorealmode
) ?
656 DOSMEM_MapRealToLinear(MAKELONG(PTR_AT(driver_request
, 14, WORD
), PTR_AT(driver_request
, 16, WORD
))) :
657 PTR_SEG_OFF_TO_LIN(PTR_AT(driver_request
, 16, WORD
), PTR_AT(driver_request
, 14, WORD
));
659 TRACE(int, " --> IOCTL OUTPUT <%d>\n", io_stru
[0]);
660 switch (io_stru
[0]) {
662 CDAUDIO_SetDoor(&wcda
, 1);
663 TRACE(int, " ----> EJECT\n");
665 case 2: /* reset drive */
666 CDAUDIO_Reset(&wcda
);
667 TRACE(int, " ----> RESET\n");
669 case 3: /* Audio Channel Control */
670 FIXME(int, " ----> AUDIO CHANNEL CONTROL (NIY)\n");
672 case 5: /* close tray */
673 CDAUDIO_SetDoor(&wcda
, 0);
674 TRACE(int, " ----> CLOSE TRAY\n");
677 FIXME(int, " IOCTL OUPUT: Unimplemented <%d>!!\n", io_stru
[0]);
687 at
= PTR_AT(driver_request
, 20, DWORD
);
689 TRACE(int, " --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
690 (BYTE
)driver_request
[13], at
);
692 switch (driver_request
[13]) {
693 case 1: /* Red book addressing mode = 0:m:s:f */
694 /* FIXME : frame <=> msf conversion routines could be shared
695 * between mscdex and mcicda
697 at
= LOBYTE(HIWORD(at
)) * CDFRAMES_PERMIN
+
698 HIBYTE(LOWORD(at
)) * CDFRAMES_PERSEC
+
701 case 0: /* HSG addressing mode */
702 CDAUDIO_Seek(&wcda
, at
);
705 ERR(int, "Unsupported address mode !!\n");
716 beg
= end
= PTR_AT(driver_request
, 14, DWORD
);
717 end
+= PTR_AT(driver_request
, 18, DWORD
);
719 TRACE(int, " --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
720 (BYTE
)driver_request
[13], beg
, end
);
722 switch (driver_request
[13]) {
723 case 1: /* Red book addressing mode = 0:m:s:f */
724 /* FIXME : frame <=> msf conversion routines could be shared
725 * between mscdex and mcicda
727 beg
= LOBYTE(HIWORD(beg
)) * CDFRAMES_PERMIN
+
728 HIBYTE(LOWORD(beg
)) * CDFRAMES_PERSEC
+
730 end
= LOBYTE(HIWORD(end
)) * CDFRAMES_PERMIN
+
731 HIBYTE(LOWORD(end
)) * CDFRAMES_PERSEC
+
734 case 0: /* HSG addressing mode */
735 CDAUDIO_Play(&wcda
, beg
, end
);
738 ERR(int, "Unsupported address mode !!\n");
746 if (wcda
.cdaMode
== WINE_CDA_PLAY
) {
747 CDAUDIO_Pause(&wcda
, 1);
748 TRACE(int, " --> STOP AUDIO (Paused)\n");
751 TRACE(int, " --> STOP AUDIO (Stopped)\n");
756 TRACE(int, " --> RESUME AUDIO\n");
757 CDAUDIO_Pause(&wcda
, 0);
761 FIXME(int, " ioctl uninplemented <%d>\n", driver_request
[2]);
765 /* setting error codes if any */
767 driver_request
[4] |= 0x80;
768 driver_request
[3] = Error
;
771 /* setting status bits
772 * 3 == playing && done
775 driver_request
[4] |= (wcda
.cdaMode
== WINE_CDA_PLAY
) ? 3 : 1;
777 MSCDEX_Dump("End", driver_request
, dorealmode
);
781 FIXME(int, "Unimplemented MSCDEX function 0x%02X.\n", AL_reg(context
));