Updated.
[wine/multimedia.git] / dlls / winedos / int2f.c
blobc7b2069bb55eed1716bc24331670dfd08895207e
1 /* -*- tab-width: 8; c-basic-offset: 4 -*- */
2 /*
3 * DOS interrupt 2fh handler
5 * Cdrom - device driver emulation - Audio features.
6 * Copyright (c) 1998 Petr Tomasek <tomasek@etf.cuni.cz>
7 * Copyright (c) 1999,2002 Eric Pouech
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "config.h"
26 #include <string.h>
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
30 #include "wine/winbase16.h"
31 #include "miscemu.h"
32 #include "wine/debug.h"
33 #include "ntstatus.h"
34 #include "winioctl.h"
35 #include "ntddstor.h"
36 #include "ntddcdrm.h"
37 #include "dosexe.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(int);
41 /* base WPROCS.DLL ordinal number for VxDs */
42 #define VXD_BASE 400
44 static void do_int2f_16( CONTEXT86 *context );
45 static void MSCDEX_Handler( CONTEXT86 *context );
47 /**********************************************************************
48 * DOSVM_Int2fHandler (WINEDOS16.147)
50 * Handler for int 2fh (multiplex).
52 void WINAPI DOSVM_Int2fHandler( CONTEXT86 *context )
54 TRACE("Subfunction 0x%X\n", AX_reg(context));
56 switch(AH_reg(context))
58 case 0x10:
59 SET_AL( context, 0xff ); /* share is installed */
60 break;
62 case 0x11: /* Network Redirector / IFSFUNC */
63 switch (LOBYTE(context->Eax))
65 case 0x00: /* Install check */
66 /* not installed */
67 break;
68 case 0x80: /* Enhanced services - Install check */
69 /* not installed */
70 break;
71 default:
72 INT_BARF( context, 0x2f );
73 break;
75 break;
77 case 0x12:
78 switch (LOBYTE(context->Eax))
80 case 0x2e: /* get or set DOS error table address */
81 switch (DL_reg(context))
83 /* Four tables: even commands are 'get', odd are 'set' */
84 /* DOS 5.0+ ignores "set" commands */
85 case 0x01:
86 case 0x03:
87 case 0x05:
88 case 0x07:
89 case 0x09:
90 break;
91 /* Instead of having a message table in DOS-space, */
92 /* we can use a special case for MS-DOS to force */
93 /* the secondary interface. */
94 case 0x00:
95 case 0x02:
96 case 0x04:
97 case 0x06:
98 context->SegEs = 0x0001;
99 SET_DI( context, 0x0000 );
100 break;
101 case 0x08:
102 FIXME("No real-mode handler for errors yet! (bye!)\n");
103 break;
104 default:
105 INT_BARF(context, 0x2f);
107 break;
108 default:
109 INT_BARF(context, 0x2f);
111 break;
113 case 0x15: /* mscdex */
114 MSCDEX_Handler(context);
115 break;
117 case 0x16:
118 do_int2f_16( context );
119 break;
121 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
122 /* Not supported yet, do nothing */
123 break;
125 case 0x43:
126 #if 1
127 switch (LOBYTE(context->Eax))
129 case 0x00: /* XMS v2+ installation check */
130 WARN("XMS is not fully implemented\n");
131 SET_AL( context, 0x80 );
132 break;
133 case 0x10: /* XMS v2+ get driver address */
135 context->SegEs = DOSVM_dpmi_segments->xms_seg;
136 SET_BX( context, 0 );
137 break;
139 default:
140 INT_BARF( context, 0x2f );
142 #else
143 FIXME("check for XMS (not supported)\n");
144 SET_AL( context, 0x42 ); /* != 0x80 */
145 #endif
146 break;
148 case 0x45:
149 switch (LOBYTE(context->Eax))
151 case 0x00:
152 case 0x01:
153 case 0x02:
154 case 0x03:
155 case 0x04:
156 case 0x05:
157 case 0x06:
158 case 0x07:
159 case 0x08:
160 /* Microsoft Profiler - not installed */
161 break;
162 default:
163 INT_BARF( context, 0x2f );
165 break;
167 case 0x4a:
168 switch(LOBYTE(context->Eax))
170 case 0x10: /* smartdrv */
171 break; /* not installed */
172 case 0x11: /* dblspace */
173 break; /* not installed */
174 case 0x12: /* realtime compression interface */
175 break; /* not installed */
176 case 0x32: /* patch IO.SYS (???) */
177 break; /* we have no IO.SYS, so we can't patch it :-/ */
178 default:
179 INT_BARF( context, 0x2f );
181 break;
182 case 0x4b:
183 switch(LOBYTE(context->Eax))
185 case 0x01:
186 case 0x02:
187 case 0x03:
188 case 0x04:
189 case 0x05:
190 FIXME("Task Switcher - not implemented\n");
191 break;
192 default:
193 INT_BARF( context, 0x2f );
195 break;
196 case 0x56: /* INTERLNK */
197 switch(LOBYTE(context->Eax))
199 case 0x01: /* check if redirected drive */
200 SET_AL( context, 0 ); /* not redirected */
201 break;
202 default:
203 INT_BARF( context, 0x2f );
205 break;
206 case 0x7a: /* NOVELL NetWare */
207 switch (LOBYTE(context->Eax))
209 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
210 SET_AL( context, 0 );
211 break;
212 case 0x20: /* Get VLM Call Address */
213 /* return nothing -> NetWare not installed */
214 break;
215 default:
216 INT_BARF( context, 0x2f );
217 break;
219 break;
220 case 0xb7: /* append */
221 SET_AL( context, 0 ); /* not installed */
222 break;
223 case 0xb8: /* network */
224 switch (LOBYTE(context->Eax))
226 case 0x00: /* Install check */
227 /* not installed */
228 break;
229 default:
230 INT_BARF( context, 0x2f );
231 break;
233 break;
234 case 0xbc:
235 if (AL_reg(context) == 0x00 && BX_reg(context) == 0x3f3f) {
236 /* MVSOUND.SYS - Install check: not installed */
237 } else {
238 INT_BARF( context, 0x2f );
240 break;
241 case 0xbd: /* some Novell network install check ??? */
242 SET_AX( context, 0xa5a5 ); /* pretend to have Novell IPX installed */
243 break;
244 case 0xbf: /* REDIRIFS.EXE */
245 switch (LOBYTE(context->Eax))
247 case 0x00: /* Install check */
248 /* not installed */
249 break;
250 default:
251 INT_BARF( context, 0x2f );
252 break;
254 break;
255 case 0xd2:
256 switch(LOBYTE(context->Eax))
258 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
259 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
260 && DX_reg(context) == 0x3432)
261 TRACE("Check for QEMM v5.0+ (not installed)\n");
262 break;
263 default:
264 INT_BARF( context, 0x2f );
265 break;
267 break;
268 case 0xd7: /* Banyan Vines */
269 switch (LOBYTE(context->Eax))
271 case 0x01: /* Install check - Get Int Number */
272 /* not installed */
273 break;
274 default:
275 INT_BARF( context, 0x2f );
276 break;
278 break;
279 case 0xde:
280 switch(LOBYTE(context->Eax))
282 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
283 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
284 && DX_reg(context) == 0x8f4f)
285 TRACE("Check for QDPMI.SYS (not installed)\n");
286 break;
287 default:
288 INT_BARF( context, 0x2f );
289 break;
291 break;
292 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
293 break;
294 default:
295 INT_BARF( context, 0x2f );
296 break;
301 /**********************************************************************
302 * do_int2f_16
304 static void do_int2f_16( CONTEXT86 *context )
306 DWORD addr;
308 switch(LOBYTE(context->Eax))
310 case 0x00: /* Windows enhanced mode installation check */
311 SET_AX( context, (GetWinFlags16() & WF_ENHANCED) ? LOWORD(GetVersion16()) : 0 );
312 break;
314 case 0x0a: /* Get Windows version and type */
315 SET_AX( context, 0 );
316 SET_BX( context, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
317 SET_CX( context, (GetWinFlags16() & WF_ENHANCED) ? 3 : 2 );
318 break;
320 case 0x0b: /* Identify Windows-aware TSRs */
321 /* we don't have any pre-Windows TSRs */
322 break;
324 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
325 /* We can mock this up. But not today... */
326 FIXME("Get Shell Parameters\n");
327 break;
329 case 0x80: /* Release time-slice */
330 /* Linux sched_yield() still keeps burning CPU cycles
331 * if the current process is the only one in highest priority list
332 * (as Linux will immediately return to this process to waste
333 * more CPU cycles), so sched_yield() is essentially useless for us
334 * (poor API, if you ask me: its return code should indicate
335 * whether other processes did run in between, in order for us
336 * to be able to decide whether to do an additional Sleep() or not...)
337 * Thus we better unconditionally use a well-balanced Sleep()
338 * instead to really make sure the process calling int 0x2f/0x1680
339 * *doesn't* use 100% CPU...
341 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
342 SET_AL( context, 0 );
343 break;
345 case 0x81: /* Begin critical section. */
346 /* FIXME? */
347 break;
349 case 0x82: /* End critical section. */
350 /* FIXME? */
351 break;
353 case 0x83: /* Return Current Virtual Machine ID */
354 /* Virtual Machines are usually created/destroyed when Windows runs
355 * DOS programs. Since we never do, we are always in the System VM.
356 * According to Ralf Brown's Interrupt List, never return 0. But it
357 * seems to work okay (returning 0), just to be sure we return 1.
359 SET_BX( context, 1 ); /* VM 1 is probably the System VM */
360 break;
362 case 0x84: /* Get device API entry point */
364 HMODULE16 mod = GetModuleHandle16("wprocs");
365 if (mod < 32) mod = LoadLibrary16( "wprocs" );
366 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
367 if (!addr) /* not supported */
368 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
369 context->SegEs = SELECTOROF(addr);
370 SET_DI( context, OFFSETOF(addr) );
372 break;
374 case 0x86: /* DPMI detect mode */
375 SET_AX( context, 0 ); /* Running under DPMI */
376 break;
378 case 0x87: /* DPMI installation check */
380 SYSTEM_INFO si;
381 GetSystemInfo(&si);
382 SET_AX( context, 0x0000 ); /* DPMI Installed */
383 SET_BX( context, 0x0001 ); /* 32bits available */
384 SET_CL( context, si.wProcessorLevel );
385 SET_DX( context, 0x005a ); /* DPMI major/minor 0.90 */
386 SET_SI( context, 0 ); /* # of para. of DOS extended private data */
387 context->SegEs = DOSVM_dpmi_segments->dpmi_seg;
388 SET_DI( context, 0 ); /* ES:DI is DPMI switch entry point */
389 break;
391 case 0x8a: /* DPMI get vendor-specific API entry point. */
392 /* The 1.0 specs say this should work with all 0.9 hosts. */
393 break;
395 default:
396 INT_BARF( context, 0x2f );
400 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
401 * must be <size> aligned
402 * <size> could be WORD, DWORD...
403 * in this case, we would need two macros, one for read, the other one for write
404 * Note: PTR_AT can be used as an l-value
406 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
408 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
409 #if 0
410 /**********************************************************************
411 * MSCDEX_Dump [internal]
413 * Dumps mscdex requests to int debug channel.
415 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
417 int i;
418 BYTE buf[2048];
419 BYTE* ptr;
420 BYTE* ios;
422 ptr = buf;
423 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
424 for (i = 0; i < req[0]; i++) {
425 ptr += sprintf(ptr, "%02x ", req[i]);
428 switch (req[2]) {
429 case 3:
430 case 12:
431 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
432 ios = (dorealmode) ? PTR_REAL_TO_LIN( PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)) :
433 MapSL(MAKESEGPTR(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)));
435 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
436 ptr += sprintf(ptr, "%02x ", ios[i]);
437 if ((i & 0x1F) == 0x1F) {
438 *ptr++ = '\n';
439 *ptr = 0;
442 break;
444 TRACE("%s\n", buf);
446 #else
447 #define MSCDEX_Dump(pfx, req, drm)
448 #endif
450 #define CDFRAMES_PERSEC 75
451 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
452 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
453 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
454 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
455 (toc).TrackData[idx - (toc).FirstTrack].Adr)
457 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
459 val[3] = 0; /* zero */
460 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
461 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
462 val[0] = frame % CDFRAMES_PERSEC; /* frames */
465 static int is_cdrom( int drive)
467 char root[] = "A:\\";
468 root[0] += drive;
469 return (GetDriveTypeA(root) == DRIVE_CDROM);
472 static void MSCDEX_Handler(CONTEXT86* context)
474 int drive, count;
475 char* p;
477 switch (LOBYTE(context->Eax)) {
478 case 0x00: /* Installation check */
479 /* Count the number of contiguous CDROM drives
481 for (drive = count = 0; drive < 26; drive++) {
482 if (is_cdrom(drive)) {
483 while (is_cdrom(drive + count)) count++;
484 break;
487 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
488 SET_BX( context, count );
489 SET_CX( context, (drive < 26) ? drive : 0 );
490 break;
492 case 0x0B: /* drive check */
493 SET_AX( context, is_cdrom(CX_reg(context)) );
494 SET_BX( context, 0xADAD );
495 break;
497 case 0x0C: /* get version */
498 SET_BX( context, 0x020a );
499 TRACE("Version number => %04x\n", BX_reg(context));
500 break;
502 case 0x0D: /* get drive letters */
503 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
504 memset(p, 0, 26);
505 for (drive = 0; drive < 26; drive++) {
506 if (is_cdrom(drive)) *p++ = drive;
508 TRACE("Get drive letters\n");
509 break;
511 case 0x10: /* direct driver access */
513 BYTE* driver_request;
514 BYTE* io_stru;
515 BYTE Error = 255; /* No Error */
516 int dorealmode = ISV86(context);
517 char devName[] = "\\\\.\\@:";
518 HANDLE h;
519 CDROM_TOC toc;
520 CDROM_SUB_Q_DATA_FORMAT fmt;
521 SUB_Q_CHANNEL_DATA data;
522 DWORD br;
523 DWORD present = TRUE;
525 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
527 if (!driver_request) {
528 /* FIXME - to be deleted ?? */
529 ERR("ES:BX==0 ! SEGFAULT ?\n");
530 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
531 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
532 driver_request[4] |= 0x80;
533 driver_request[3] = 5; /* bad request length */
534 return;
536 /* FIXME
537 * the following tests are wrong because lots of functions don't require the
538 * tray to be closed with a CD inside
540 TRACE("CDROM device driver -> command <%d>\n", (unsigned char)driver_request[2]);
542 if (!is_cdrom(CX_reg(context))) {
543 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
544 driver_request[4] |= 0x80;
545 driver_request[3] = 1; /* unknown unit */
546 return;
549 MSCDEX_Dump("Beg", driver_request, dorealmode);
551 /* set status to 0 */
552 PTR_AT(driver_request, 3, WORD) = 0;
553 devName[4] = 'A' + CX_reg(context);
554 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
555 if (!h) {
556 WARN("Couldn't open cdrom handle\n");
557 driver_request[4] |= 0x80;
558 driver_request[3] = 1; /* unknown unit */
559 return;
562 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
563 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
564 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
565 &data, sizeof(data), &br, NULL)) {
566 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
568 if (driver_request[2] != 6 && driver_request[2] != 15)
570 driver_request[4] |= 0x80;
571 driver_request[3] = 2; /* drive not ready */
572 CloseHandle(h);
573 return;
575 present = FALSE;
577 else
579 driver_request[4] |= 0x80;
580 driver_request[3] = 1; /* unknown unit */
581 CloseHandle(h);
582 return;
586 switch (driver_request[2]) {
587 case 3:
588 io_stru = (dorealmode) ?
589 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD) ) :
590 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
592 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
593 switch (io_stru[0]) {
594 #if 0
595 case 0: /* Get device Header */
597 static LPSTR ptr = 0;
598 if (ptr == 0) {
599 ptr = SEGPTR_ALLOC(22);
600 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
601 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
602 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
603 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
604 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
605 PTR_AT(ptr, 11, char) = 'I';
606 PTR_AT(ptr, 12, char) = 'N';
607 PTR_AT(ptr, 13, char) = 'E';
608 PTR_AT(ptr, 14, char) = '_';
609 PTR_AT(ptr, 15, char) = 'C';
610 PTR_AT(ptr, 16, char) = 'D';
611 PTR_AT(ptr, 17, char) = '_';
612 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
613 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
614 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
616 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
618 break;
619 #endif
621 case 1: /* location of head */
622 switch (io_stru[1]) {
623 case 0:
624 PTR_AT(io_stru, 2, DWORD) =
625 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
626 break;
627 case 1:
628 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
629 io_stru + 2);
630 break;
631 default:
632 ERR("CD-ROM driver: unsupported addressing mode !!\n");
633 Error = 0x0c;
635 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
636 break;
638 case 4: /* Audio channel info */
639 io_stru[1] = 0;
640 io_stru[2] = 0xff;
641 io_stru[3] = 1;
642 io_stru[4] = 0xff;
643 io_stru[5] = 2;
644 io_stru[6] = 0;
645 io_stru[7] = 3;
646 io_stru[8] = 0;
647 TRACE(" ----> AUDIO CHANNEL INFO\n");
648 break;
650 case 6: /* device status */
651 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
652 /* 290 =>
653 * 1 Supports HSG and Red Book addressing modes
654 * 0 Supports audio channel manipulation
656 * 1 Supports prefetching requests
657 * 0 Reserved
658 * 0 No interleaving
659 * 1 Data read and plays audio/video tracks
661 * 0 Read only
662 * 0 Supports only cooked reading
663 * 0 Door locked
664 * 0 see below (Door closed/opened)
666 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
667 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
668 break;
670 case 8: /* Volume size */
671 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
672 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
673 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
674 break;
676 case 9: /* media changed ? */
677 /* answers don't know... -1/1 for yes/no would be better */
678 io_stru[1] = 0; /* FIXME? 1? */
679 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
680 break;
682 case 10: /* audio disk info */
683 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
684 io_stru[2] = toc.LastTrack; /* ending track */
685 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
686 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
688 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
689 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
690 break;
692 case 11: /* audio track info */
693 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
694 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
695 /* starting point if the track */
696 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
697 } else {
698 PTR_AT(io_stru, 2, DWORD) = 0;
699 io_stru[6] = 0;
701 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
702 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
703 break;
705 case 12: /* get Q-Channel info */
706 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
707 io_stru[2] = data.CurrentPosition.TrackNumber;
708 io_stru[3] = 0; /* FIXME ?? */
710 /* why the heck did MS use another format for 0MSF information... sigh */
712 BYTE bTmp[4];
714 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
715 io_stru[ 4] = bTmp[2];
716 io_stru[ 5] = bTmp[1];
717 io_stru[ 6] = bTmp[0];
718 io_stru[ 7] = 0;
720 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
721 io_stru[ 8] = bTmp[2];
722 io_stru[ 9] = bTmp[1];
723 io_stru[10] = bTmp[0];
724 io_stru[11] = 0;
726 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
727 io_stru[ 1], io_stru[ 2], io_stru[ 3],
728 io_stru[ 4], io_stru[ 5], io_stru[ 6],
729 io_stru[ 8], io_stru[ 9], io_stru[10],
730 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
731 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
732 break;
734 case 15: /* Audio status info */
735 /* !!!! FIXME FIXME FIXME !! */
736 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
737 if (!present) {
738 PTR_AT(io_stru, 3, DWORD) = 0;
739 PTR_AT(io_stru, 7, DWORD) = 0;
740 } else {
741 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
742 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
744 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
745 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
746 break;
748 default:
749 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
750 Error = 0x0c;
751 break;
753 break;
755 case 12:
756 io_stru = (dorealmode) ?
757 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)) :
758 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
760 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
761 switch (io_stru[0]) {
762 case 0: /* eject */
763 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
764 TRACE(" ----> EJECT\n");
765 break;
766 case 2: /* reset drive */
767 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
768 TRACE(" ----> RESET\n");
769 break;
770 case 3: /* Audio Channel Control */
771 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
772 break;
773 case 5: /* close tray */
774 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
775 TRACE(" ----> CLOSE TRAY\n");
776 break;
777 default:
778 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
779 Error = 0x0c;
780 break;
782 break;
784 case 128: /* read long */
786 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
787 PTR_AT(driver_request, 14, WORD)));
788 DWORD at = PTR_AT(driver_request, 20, DWORD);
789 WORD num = PTR_AT(driver_request, 18, WORD);
790 RAW_READ_INFO rri;
792 switch (driver_request[13]) {
793 case 1: /* Red book addressing mode = 0:m:s:f */
794 /* FIXME : frame <=> msf conversion routines could be shared
795 * between mscdex and mcicda
797 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
798 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
799 LOBYTE(LOWORD(at));
800 /* fall through */
801 case 0: /* HSG addressing mode */
802 switch (PTR_AT(driver_request, 24, BYTE))
804 case 0: /* cooked */
805 ReadFile(h, dst, num * 2048, &br, NULL);
806 break;
807 case 1:
808 /* FIXME: computation is wrong */
809 rri.DiskOffset.s.HighPart = 0;
810 rri.DiskOffset.s.LowPart = at << 11;
811 rri.TrackMode = YellowMode2;
812 rri.SectorCount = num;
813 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
814 dst, num * 2352, &br, NULL);
815 break;
816 default:
817 ERR("Unsupported read mode !!\n");
818 Error = 0x0c;
819 break;
821 break;
822 default:
823 ERR("Unsupported address mode !!\n");
824 Error = 0x0c;
825 break;
828 break;
830 case 131: /* seek */
832 DWORD at;
833 CDROM_SEEK_AUDIO_MSF seek;
835 at = PTR_AT(driver_request, 20, DWORD);
837 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
838 (BYTE)driver_request[13], at);
840 switch (driver_request[13]) {
841 case 1: /* Red book addressing mode = 0:m:s:f */
842 /* FIXME : frame <=> msf conversion routines could be shared
843 * between mscdex and mcicda
845 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
846 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
847 LOBYTE(LOWORD(at));
848 /* fall through */
849 case 0: /* HSG addressing mode */
850 seek.M = at / CDFRAMES_PERMIN;
851 seek.S = (at / CDFRAMES_PERSEC) % 60;
852 seek.F = at % CDFRAMES_PERSEC;
853 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
854 NULL, 0, &br, NULL);
855 break;
856 default:
857 ERR("Unsupported address mode !!\n");
858 Error = 0x0c;
859 break;
862 break;
864 case 132: /* play */
866 DWORD beg, end;
867 CDROM_PLAY_AUDIO_MSF play;
869 beg = end = PTR_AT(driver_request, 14, DWORD);
870 end += PTR_AT(driver_request, 18, DWORD);
872 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
873 (BYTE)driver_request[13], beg, end);
875 switch (driver_request[13]) {
876 case 1:
877 /* Red book addressing mode = 0:m:s:f */
878 /* FIXME : frame <=> msf conversion routines could be shared
879 * between mscdex and mcicda
881 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
882 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
883 LOBYTE(HIWORD(beg));
884 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
885 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
886 LOBYTE(HIWORD(end));
887 /* fall through */
888 case 0: /* HSG addressing mode */
889 play.StartingM = beg / CDFRAMES_PERMIN;
890 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
891 play.StartingF = beg % CDFRAMES_PERSEC;
892 play.EndingM = end / CDFRAMES_PERMIN;
893 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
894 play.EndingF = end % CDFRAMES_PERSEC;
895 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
896 NULL, 0, &br, NULL);
897 break;
898 default:
899 ERR("Unsupported address mode !!\n");
900 Error = 0x0c;
901 break;
904 break;
906 case 133:
907 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
908 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
909 TRACE(" --> STOP AUDIO (Paused)\n");
910 } else {
911 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
912 TRACE(" --> STOP AUDIO (Stopped)\n");
914 break;
916 case 136:
917 TRACE(" --> RESUME AUDIO\n");
918 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
919 break;
921 default:
922 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
923 Error = 0x0c;
926 /* setting error codes if any */
927 if (Error < 255) {
928 driver_request[4] |= 0x80;
929 driver_request[3] = Error;
932 CloseHandle(h);
933 /* setting status bits
934 * 3 == playing && done
935 * 1 == done
937 driver_request[4] |=
938 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
940 MSCDEX_Dump("End", driver_request, dorealmode);
942 break;
943 default:
944 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
945 break;