New file msvcrt/excpt.h. Move some stuff out of winnt.h into it.
[wine/testsucceed.git] / msdos / int2f.c
blob0a44ac36c39e5907440a729387dcee2f2a7f53a5
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3 * DOS interrupt 2fh handler
5 * Cdrom - device driver emulation - Audio features.
6 * (c) 1998 Petr Tomasek <tomasek@etf.cuni.cz>
7 * (c) 1999,2002 Eric Pouech
8 */
10 #include "config.h"
12 #include <string.h>
13 #include "wine/winbase16.h"
14 #include "miscemu.h"
15 #include "module.h"
16 /* #define DEBUG_INT */
17 #include "debugtools.h"
18 #include "winioctl.h"
19 #include "ntddstor.h"
20 #include "ntddcdrm.h"
22 DEFAULT_DEBUG_CHANNEL(int);
24 /* base WPROCS.DLL ordinal number for VxDs */
25 #define VXD_BASE 400
27 static void do_int2f_16( CONTEXT86 *context );
28 static void MSCDEX_Handler( CONTEXT86 *context );
30 /**********************************************************************
31 * INT_Int2fHandler (WPROCS.147)
33 * Handler for int 2fh (multiplex).
35 void WINAPI INT_Int2fHandler( CONTEXT86 *context )
37 TRACE("Subfunction 0x%X\n", AX_reg(context));
39 switch(AH_reg(context))
41 case 0x10:
42 AL_reg(context) = 0xff; /* share is installed */
43 break;
45 case 0x11: /* Network Redirector / IFSFUNC */
46 switch (LOBYTE(context->Eax))
48 case 0x00: /* Install check */
49 /* not installed */
50 break;
51 case 0x80: /* Enhanced services - Install check */
52 /* not installed */
53 break;
54 default:
55 INT_BARF( context, 0x2f );
56 break;
58 break;
60 case 0x12:
61 switch (LOBYTE(context->Eax))
63 case 0x2e: /* get or set DOS error table address */
64 switch (DL_reg(context))
66 /* Four tables: even commands are 'get', odd are 'set' */
67 /* DOS 5.0+ ignores "set" commands */
68 case 0x01:
69 case 0x03:
70 case 0x05:
71 case 0x07:
72 case 0x09:
73 break;
74 /* Instead of having a message table in DOS-space, */
75 /* we can use a special case for MS-DOS to force */
76 /* the secondary interface. */
77 case 0x00:
78 case 0x02:
79 case 0x04:
80 case 0x06:
81 context->SegEs = 0x0001;
82 DI_reg(context) = 0x0000;
83 break;
84 case 0x08:
85 FIXME("No real-mode handler for errors yet! (bye!)\n");
86 break;
87 default:
88 INT_BARF(context, 0x2f);
90 break;
91 default:
92 INT_BARF(context, 0x2f);
94 break;
96 case 0x15: /* mscdex */
97 MSCDEX_Handler(context);
98 break;
100 case 0x16:
101 do_int2f_16( context );
102 break;
104 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
105 /* Not supported yet, do nothing */
106 break;
108 case 0x43:
109 #if 1
110 switch (LOBYTE(context->Eax))
112 case 0x00: /* XMS v2+ installation check */
113 WARN("XMS is not fully implemented\n");
114 AL_reg(context) = 0x80;
115 break;
116 case 0x10: /* XMS v2+ get driver address */
118 context->SegEs = DOSMEM_xms_seg;
119 BX_reg(context) = 0;
120 break;
122 default:
123 INT_BARF( context, 0x2f );
125 #else
126 FIXME("check for XMS (not supported)\n");
127 AL_reg(context) = 0x42; /* != 0x80 */
128 #endif
129 break;
131 case 0x45:
132 switch (LOBYTE(context->Eax))
134 case 0x00:
135 case 0x01:
136 case 0x02:
137 case 0x03:
138 case 0x04:
139 case 0x05:
140 case 0x06:
141 case 0x07:
142 case 0x08:
143 /* Microsoft Profiler - not installed */
144 break;
145 default:
146 INT_BARF( context, 0x2f );
148 break;
150 case 0x4a:
151 switch(LOBYTE(context->Eax))
153 case 0x10: /* smartdrv */
154 break; /* not installed */
155 case 0x11: /* dblspace */
156 break; /* not installed */
157 case 0x12: /* realtime compression interface */
158 break; /* not installed */
159 case 0x32: /* patch IO.SYS (???) */
160 break; /* we have no IO.SYS, so we can't patch it :-/ */
161 default:
162 INT_BARF( context, 0x2f );
164 break;
165 case 0x4b:
166 switch(LOBYTE(context->Eax))
168 case 0x01:
169 case 0x02:
170 case 0x03:
171 case 0x04:
172 case 0x05:
173 FIXME("Task Switcher - not implemented\n");
174 break;
175 default:
176 INT_BARF( context, 0x2f );
178 break;
179 case 0x56: /* INTERLNK */
180 switch(LOBYTE(context->Eax))
182 case 0x01: /* check if redirected drive */
183 AL_reg(context) = 0; /* not redirected */
184 break;
185 default:
186 INT_BARF( context, 0x2f );
188 break;
189 case 0x7a: /* NOVELL NetWare */
190 switch (LOBYTE(context->Eax))
192 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
193 AL_reg(context) = 0;
194 break;
195 case 0x20: /* Get VLM Call Address */
196 /* return nothing -> NetWare not installed */
197 break;
198 default:
199 INT_BARF( context, 0x2f );
200 break;
202 break;
203 case 0xb7: /* append */
204 LOBYTE(context->Eax) = 0; /* not installed */
205 break;
206 case 0xb8: /* network */
207 switch (LOBYTE(context->Eax))
209 case 0x00: /* Install check */
210 /* not installed */
211 break;
212 default:
213 INT_BARF( context, 0x2f );
214 break;
216 break;
217 case 0xbd: /* some Novell network install check ??? */
218 AX_reg(context) = 0xa5a5; /* pretend to have Novell IPX installed */
219 break;
220 case 0xbf: /* REDIRIFS.EXE */
221 switch (LOBYTE(context->Eax))
223 case 0x00: /* Install check */
224 /* not installed */
225 break;
226 default:
227 INT_BARF( context, 0x2f );
228 break;
230 break;
231 case 0xd2:
232 switch(LOBYTE(context->Eax))
234 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
235 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
236 && DX_reg(context) == 0x3432)
237 TRACE("Check for QEMM v5.0+ (not installed)\n");
238 break;
239 default:
240 INT_BARF( context, 0x2f );
241 break;
243 break;
244 case 0xd7: /* Banyan Vines */
245 switch (LOBYTE(context->Eax))
247 case 0x01: /* Install check - Get Int Number */
248 /* not installed */
249 break;
250 default:
251 INT_BARF( context, 0x2f );
252 break;
254 break;
255 case 0xde:
256 switch(LOBYTE(context->Eax))
258 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
259 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
260 && DX_reg(context) == 0x8f4f)
261 TRACE("Check for QDPMI.SYS (not installed)\n");
262 break;
263 default:
264 INT_BARF( context, 0x2f );
265 break;
267 break;
268 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
269 break;
270 default:
271 INT_BARF( context, 0x2f );
272 break;
277 /**********************************************************************
278 * do_int2f_16
280 static void do_int2f_16( CONTEXT86 *context )
282 DWORD addr;
284 switch(LOBYTE(context->Eax))
286 case 0x00: /* Windows enhanced mode installation check */
287 AX_reg(context) = (GetWinFlags16() & WF_ENHANCED) ?
288 LOWORD(GetVersion16()) : 0;
289 break;
291 case 0x0a: /* Get Windows version and type */
292 AX_reg(context) = 0;
293 BX_reg(context) = (LOWORD(GetVersion16()) << 8) |
294 (LOWORD(GetVersion16()) >> 8);
295 CX_reg(context) = (GetWinFlags16() & WF_ENHANCED) ? 3 : 2;
296 break;
298 case 0x0b: /* Identify Windows-aware TSRs */
299 /* we don't have any pre-Windows TSRs */
300 break;
302 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
303 /* We can mock this up. But not today... */
304 FIXME("Get Shell Parameters\n");
305 break;
307 case 0x80: /* Release time-slice */
308 AL_reg(context) = 0;
309 break;
311 case 0x81: /* Begin critical section. */
312 /* FIXME? */
313 break;
315 case 0x82: /* End critical section. */
316 /* FIXME? */
317 break;
319 case 0x83: /* Return Current Virtual Machine ID */
320 /* Virtual Machines are usually created/destroyed when Windows runs
321 * DOS programs. Since we never do, we are always in the System VM.
322 * According to Ralf Brown's Interrupt List, never return 0. But it
323 * seems to work okay (returning 0), just to be sure we return 1.
325 BX_reg(context) = 1; /* VM 1 is probably the System VM */
326 break;
328 case 0x84: /* Get device API entry point */
330 HMODULE16 mod = GetModuleHandle16("wprocs");
331 if (mod < 32) mod = LoadLibrary16( "wprocs" );
332 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
333 if (!addr) /* not supported */
334 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
335 context->SegEs = SELECTOROF(addr);
336 DI_reg(context) = OFFSETOF(addr);
338 break;
340 case 0x86: /* DPMI detect mode */
341 AX_reg(context) = 0; /* Running under DPMI */
342 break;
344 case 0x87: /* DPMI installation check */
345 #if 1 /* DPMI still breaks pkunzip */
346 if (ISV86(context)) break; /* so bail out for now if in v86 mode */
347 #endif
349 SYSTEM_INFO si;
350 GetSystemInfo(&si);
351 AX_reg(context) = 0x0000; /* DPMI Installed */
352 BX_reg(context) = 0x0001; /* 32bits available */
353 CL_reg(context) = si.wProcessorLevel;
354 DX_reg(context) = 0x005a; /* DPMI major/minor 0.90 */
355 SI_reg(context) = 0; /* # of para. of DOS extended private data */
356 context->SegEs = DOSMEM_dpmi_seg;
357 DI_reg(context) = 0; /* ES:DI is DPMI switch entry point */
358 break;
360 case 0x8a: /* DPMI get vendor-specific API entry point. */
361 /* The 1.0 specs say this should work with all 0.9 hosts. */
362 break;
364 default:
365 INT_BARF( context, 0x2f );
369 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
370 * must be <size> aligned
371 * <size> could be WORD, DWORD...
372 * in this case, we would need two macros, one for read, the other one for write
373 * Note: PTR_AT can be used as an l-value
375 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
377 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
378 #if 0
379 /**********************************************************************
380 * MSCDEX_Dump [internal]
382 * Dumps mscdex requests to int debug channel.
384 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
386 int i;
387 BYTE buf[2048];
388 BYTE* ptr;
389 BYTE* ios;
391 ptr = buf;
392 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
393 for (i = 0; i < req[0]; i++) {
394 ptr += sprintf(ptr, "%02x ", req[i]);
397 switch (req[2]) {
398 case 3:
399 case 12:
400 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
401 ios = (dorealmode) ? PTR_REAL_TO_LIN( PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)) :
402 MapSL(MAKESEGPTR(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)));
404 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
405 ptr += sprintf(ptr, "%02x ", ios[i]);
406 if ((i & 0x1F) == 0x1F) {
407 *ptr++ = '\n';
408 *ptr = 0;
411 break;
413 TRACE("%s\n", buf);
415 #else
416 #define MSCDEX_Dump(pfx, req, drm)
417 #endif
419 #define CDFRAMES_PERSEC 75
420 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
421 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
422 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
423 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
424 (toc).TrackData[idx - (toc).FirstTrack].Adr)
426 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
428 val[3] = 0; /* zero */
429 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
430 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
431 val[0] = frame % CDFRAMES_PERSEC; /* frames */
434 static int is_cdrom( int drive)
436 char root[] = "A:\\";
437 root[0] += drive;
438 return (GetDriveTypeA(root) == DRIVE_CDROM);
441 static void MSCDEX_Handler(CONTEXT86* context)
443 int drive, count;
444 char* p;
446 switch (LOBYTE(context->Eax)) {
447 case 0x00: /* Installation check */
448 /* Count the number of contiguous CDROM drives
450 for (drive = count = 0; drive < 26; drive++) {
451 if (is_cdrom(drive)) {
452 while (is_cdrom(drive + count)) count++;
453 break;
456 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
457 BX_reg(context) = count;
458 CX_reg(context) = (drive < 26) ? drive : 0;
459 break;
461 case 0x0B: /* drive check */
462 AX_reg(context) = is_cdrom(CX_reg(context));
463 BX_reg(context) = 0xADAD;
464 break;
466 case 0x0C: /* get version */
467 BX_reg(context) = 0x020a;
468 TRACE("Version number => %04x\n", BX_reg(context));
469 break;
471 case 0x0D: /* get drive letters */
472 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
473 memset(p, 0, 26);
474 for (drive = 0; drive < 26; drive++) {
475 if (is_cdrom(drive)) *p++ = drive;
477 TRACE("Get drive letters\n");
478 break;
480 case 0x10: /* direct driver access */
482 BYTE* driver_request;
483 BYTE* io_stru;
484 BYTE Error = 255; /* No Error */
485 int dorealmode = ISV86(context);
486 char devName[] = "\\\\.\\@:";
487 HANDLE h;
488 CDROM_TOC toc;
489 CDROM_SUB_Q_DATA_FORMAT fmt;
490 SUB_Q_CHANNEL_DATA data;
491 DWORD br;
492 DWORD present = TRUE;
494 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
496 if (!driver_request) {
497 /* FIXME - to be deleted ?? */
498 ERR("ES:BX==0 ! SEGFAULT ?\n");
499 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
500 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
501 driver_request[4] |= 0x80;
502 driver_request[3] = 5; /* bad request length */
503 return;
505 /* FIXME
506 * the following tests are wrong because lots of functions don't require the
507 * tray to be closed with a CD inside
509 TRACE("CDROM device driver -> command <%d>\n", (unsigned char)driver_request[2]);
511 if (!is_cdrom(CX_reg(context))) {
512 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
513 driver_request[4] |= 0x80;
514 driver_request[3] = 1; /* unknown unit */
515 return;
518 MSCDEX_Dump("Beg", driver_request, dorealmode);
520 /* set status to 0 */
521 PTR_AT(driver_request, 3, WORD) = 0;
522 devName[4] = 'A' + CX_reg(context);
523 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
524 if (!h) {
525 WARN("Couldn't open cdrom handle\n");
526 driver_request[4] |= 0x80;
527 driver_request[3] = 1; /* unknown unit */
528 return;
531 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
532 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
533 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
534 &data, sizeof(data), &br, NULL)) {
535 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
537 if (driver_request[2] != 6 && driver_request[2] != 15)
539 driver_request[4] |= 0x80;
540 driver_request[3] = 2; /* drive not ready */
541 CloseHandle(h);
542 return;
544 present = FALSE;
546 else
548 driver_request[4] |= 0x80;
549 driver_request[3] = 1; /* unknown unit */
550 CloseHandle(h);
551 return;
555 switch (driver_request[2]) {
556 case 3:
557 io_stru = (dorealmode) ?
558 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD) ) :
559 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
561 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
562 switch (io_stru[0]) {
563 #if 0
564 case 0: /* Get device Header */
566 static LPSTR ptr = 0;
567 if (ptr == 0) {
568 ptr = SEGPTR_ALLOC(22);
569 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
570 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
571 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
572 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
573 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
574 PTR_AT(ptr, 11, char) = 'I';
575 PTR_AT(ptr, 12, char) = 'N';
576 PTR_AT(ptr, 13, char) = 'E';
577 PTR_AT(ptr, 14, char) = '_';
578 PTR_AT(ptr, 15, char) = 'C';
579 PTR_AT(ptr, 16, char) = 'D';
580 PTR_AT(ptr, 17, char) = '_';
581 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
582 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
583 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
585 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
587 break;
588 #endif
590 case 1: /* location of head */
591 switch (io_stru[1]) {
592 case 0:
593 PTR_AT(io_stru, 2, DWORD) =
594 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
595 break;
596 case 1:
597 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
598 io_stru + 2);
599 break;
600 default:
601 ERR("CD-ROM driver: unsupported addressing mode !!\n");
602 Error = 0x0c;
604 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
605 break;
607 case 4: /* Audio channel info */
608 io_stru[1] = 0;
609 io_stru[2] = 0xff;
610 io_stru[3] = 1;
611 io_stru[4] = 0xff;
612 io_stru[5] = 2;
613 io_stru[6] = 0;
614 io_stru[7] = 3;
615 io_stru[8] = 0;
616 TRACE(" ----> AUDIO CHANNEL INFO\n");
617 break;
619 case 6: /* device status */
620 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
621 /* 290 =>
622 * 1 Supports HSG and Red Book addressing modes
623 * 0 Supports audio channel manipulation
625 * 1 Supports prefetching requests
626 * 0 Reserved
627 * 0 No interleaving
628 * 1 Data read and plays audio/video tracks
630 * 0 Read only
631 * 0 Supports only cooked reading
632 * 0 Door locked
633 * 0 see below (Door closed/opened)
635 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
636 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
637 break;
639 case 8: /* Volume size */
640 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
641 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
642 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
643 break;
645 case 9: /* media changed ? */
646 /* answers don't know... -1/1 for yes/no would be better */
647 io_stru[1] = 0; /* FIXME? 1? */
648 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
649 break;
651 case 10: /* audio disk info */
652 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
653 io_stru[2] = toc.LastTrack; /* ending track */
654 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
655 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
657 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
658 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
659 break;
661 case 11: /* audio track info */
662 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
663 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
664 /* starting point if the track */
665 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
666 } else {
667 PTR_AT(io_stru, 2, DWORD) = 0;
668 io_stru[6] = 0;
670 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
671 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
672 break;
674 case 12: /* get Q-Channel info */
675 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
676 io_stru[2] = data.CurrentPosition.TrackNumber;
677 io_stru[3] = 0; /* FIXME ?? */
679 /* why the heck did MS use another format for 0MSF information... sigh */
681 BYTE bTmp[4];
683 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
684 io_stru[ 4] = bTmp[2];
685 io_stru[ 5] = bTmp[1];
686 io_stru[ 6] = bTmp[0];
687 io_stru[ 7] = 0;
689 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
690 io_stru[ 8] = bTmp[2];
691 io_stru[ 9] = bTmp[1];
692 io_stru[10] = bTmp[0];
693 io_stru[11] = 0;
695 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
696 io_stru[ 1], io_stru[ 2], io_stru[ 3],
697 io_stru[ 4], io_stru[ 5], io_stru[ 6],
698 io_stru[ 8], io_stru[ 9], io_stru[10],
699 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
700 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
701 break;
703 case 15: /* Audio status info */
704 /* !!!! FIXME FIXME FIXME !! */
705 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
706 if (!present) {
707 PTR_AT(io_stru, 3, DWORD) = 0;
708 PTR_AT(io_stru, 7, DWORD) = 0;
709 } else {
710 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
711 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
713 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
714 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
715 break;
717 default:
718 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
719 Error = 0x0c;
720 break;
722 break;
724 case 12:
725 io_stru = (dorealmode) ?
726 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)) :
727 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
729 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
730 switch (io_stru[0]) {
731 case 0: /* eject */
732 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
733 TRACE(" ----> EJECT\n");
734 break;
735 case 2: /* reset drive */
736 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
737 TRACE(" ----> RESET\n");
738 break;
739 case 3: /* Audio Channel Control */
740 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
741 break;
742 case 5: /* close tray */
743 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
744 TRACE(" ----> CLOSE TRAY\n");
745 break;
746 default:
747 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
748 Error = 0x0c;
749 break;
751 break;
753 case 128: /* read long */
755 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
756 PTR_AT(driver_request, 14, WORD)));
757 DWORD at = PTR_AT(driver_request, 20, DWORD);
758 WORD num = PTR_AT(driver_request, 18, WORD);
759 RAW_READ_INFO rri;
761 switch (driver_request[13]) {
762 case 1: /* Red book addressing mode = 0:m:s:f */
763 /* FIXME : frame <=> msf conversion routines could be shared
764 * between mscdex and mcicda
766 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
767 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
768 LOBYTE(LOWORD(at));
769 /* fall through */
770 case 0: /* HSG addressing mode */
771 switch (PTR_AT(driver_request, 24, BYTE))
773 case 0: /* cooked */
774 ReadFile(h, dst, num * 2048, &br, NULL);
775 break;
776 case 1:
777 /* FIXME: computation is wrong */
778 rri.DiskOffset.s.HighPart = 0;
779 rri.DiskOffset.s.LowPart = at << 11;
780 rri.TrackMode = YellowMode2;
781 rri.SectorCount = num;
782 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
783 dst, num * 2352, &br, NULL);
784 break;
785 default:
786 ERR("Unsupported read mode !!\n");
787 Error = 0x0c;
788 break;
790 break;
791 default:
792 ERR("Unsupported address mode !!\n");
793 Error = 0x0c;
794 break;
797 break;
799 case 131: /* seek */
801 DWORD at;
802 CDROM_SEEK_AUDIO_MSF seek;
804 at = PTR_AT(driver_request, 20, DWORD);
806 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
807 (BYTE)driver_request[13], at);
809 switch (driver_request[13]) {
810 case 1: /* Red book addressing mode = 0:m:s:f */
811 /* FIXME : frame <=> msf conversion routines could be shared
812 * between mscdex and mcicda
814 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
815 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
816 LOBYTE(LOWORD(at));
817 /* fall through */
818 case 0: /* HSG addressing mode */
819 seek.M = at / CDFRAMES_PERMIN;
820 seek.S = (at / CDFRAMES_PERSEC) % 60;
821 seek.F = at % CDFRAMES_PERSEC;
822 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
823 NULL, 0, &br, NULL);
824 break;
825 default:
826 ERR("Unsupported address mode !!\n");
827 Error = 0x0c;
828 break;
831 break;
833 case 132: /* play */
835 DWORD beg, end;
836 CDROM_PLAY_AUDIO_MSF play;
838 beg = end = PTR_AT(driver_request, 14, DWORD);
839 end += PTR_AT(driver_request, 18, DWORD);
841 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
842 (BYTE)driver_request[13], beg, end);
844 switch (driver_request[13]) {
845 case 1:
846 /* Red book addressing mode = 0:m:s:f */
847 /* FIXME : frame <=> msf conversion routines could be shared
848 * between mscdex and mcicda
850 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
851 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
852 LOBYTE(HIWORD(beg));
853 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
854 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
855 LOBYTE(HIWORD(end));
856 /* fall through */
857 case 0: /* HSG addressing mode */
858 play.StartingM = beg / CDFRAMES_PERMIN;
859 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
860 play.StartingF = beg % CDFRAMES_PERSEC;
861 play.EndingM = end / CDFRAMES_PERMIN;
862 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
863 play.EndingF = end % CDFRAMES_PERSEC;
864 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
865 NULL, 0, &br, NULL);
866 break;
867 default:
868 ERR("Unsupported address mode !!\n");
869 Error = 0x0c;
870 break;
873 break;
875 case 133:
876 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
877 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
878 TRACE(" --> STOP AUDIO (Paused)\n");
879 } else {
880 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
881 TRACE(" --> STOP AUDIO (Stopped)\n");
883 break;
885 case 136:
886 TRACE(" --> RESUME AUDIO\n");
887 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
888 break;
890 default:
891 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
892 Error = 0x0c;
895 /* setting error codes if any */
896 if (Error < 255) {
897 driver_request[4] |= 0x80;
898 driver_request[3] = Error;
901 CloseHandle(h);
902 /* setting status bits
903 * 3 == playing && done
904 * 1 == done
906 driver_request[4] |=
907 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
909 MSCDEX_Dump("End", driver_request, dorealmode);
911 break;
912 default:
913 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
914 break;