Added YUV routines needed for v4l driver, and in the future possibly
[wine/gsoc-2012-control.git] / dlls / winedos / int2f.c
blobf1f68f31a09bb9acf6459eaf3afb6d18a5d6f5d8
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 "wine/debug.h"
32 #include "ntstatus.h"
33 #include "winioctl.h"
34 #include "ntddstor.h"
35 #include "ntddcdrm.h"
36 #include "dosexe.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(int);
40 /* base WPROCS.DLL ordinal number for VxDs */
41 #define VXD_BASE 400
43 static void do_int2f_16( CONTEXT86 *context );
44 static void MSCDEX_Handler( CONTEXT86 *context );
46 /**********************************************************************
47 * DOSVM_Int2fHandler (WINEDOS16.147)
49 * Handler for int 2fh (multiplex).
51 void WINAPI DOSVM_Int2fHandler( CONTEXT86 *context )
53 TRACE("Subfunction 0x%X\n", AX_reg(context));
55 switch(AH_reg(context))
57 case 0x10:
58 SET_AL( context, 0xff ); /* share is installed */
59 break;
61 case 0x11: /* Network Redirector / IFSFUNC */
62 switch (LOBYTE(context->Eax))
64 case 0x00: /* Install check */
65 /* not installed */
66 break;
67 case 0x80: /* Enhanced services - Install check */
68 /* not installed */
69 break;
70 default:
71 INT_BARF( context, 0x2f );
72 break;
74 break;
76 case 0x12:
77 switch (LOBYTE(context->Eax))
79 case 0x2e: /* get or set DOS error table address */
80 switch (DL_reg(context))
82 /* Four tables: even commands are 'get', odd are 'set' */
83 /* DOS 5.0+ ignores "set" commands */
84 case 0x01:
85 case 0x03:
86 case 0x05:
87 case 0x07:
88 case 0x09:
89 break;
90 /* Instead of having a message table in DOS-space, */
91 /* we can use a special case for MS-DOS to force */
92 /* the secondary interface. */
93 case 0x00:
94 case 0x02:
95 case 0x04:
96 case 0x06:
97 context->SegEs = 0x0001;
98 SET_DI( context, 0x0000 );
99 break;
100 case 0x08:
101 FIXME("No real-mode handler for errors yet! (bye!)\n");
102 break;
103 default:
104 INT_BARF(context, 0x2f);
106 break;
107 default:
108 INT_BARF(context, 0x2f);
110 break;
112 case 0x15: /* mscdex */
113 MSCDEX_Handler(context);
114 break;
116 case 0x16:
117 do_int2f_16( context );
118 break;
120 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
121 /* Not supported yet, do nothing */
122 break;
124 case 0x43:
125 #if 1
126 switch (LOBYTE(context->Eax))
128 case 0x00: /* XMS v2+ installation check */
129 WARN("XMS is not fully implemented\n");
130 SET_AL( context, 0x80 );
131 break;
132 case 0x10: /* XMS v2+ get driver address */
134 context->SegEs = DOSVM_dpmi_segments->xms_seg;
135 SET_BX( context, 0 );
136 break;
138 default:
139 INT_BARF( context, 0x2f );
141 #else
142 FIXME("check for XMS (not supported)\n");
143 SET_AL( context, 0x42 ); /* != 0x80 */
144 #endif
145 break;
147 case 0x45:
148 switch (LOBYTE(context->Eax))
150 case 0x00:
151 case 0x01:
152 case 0x02:
153 case 0x03:
154 case 0x04:
155 case 0x05:
156 case 0x06:
157 case 0x07:
158 case 0x08:
159 /* Microsoft Profiler - not installed */
160 break;
161 default:
162 INT_BARF( context, 0x2f );
164 break;
166 case 0x4a:
167 switch(LOBYTE(context->Eax))
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 :-/ */
177 default:
178 INT_BARF( context, 0x2f );
180 break;
181 case 0x4b:
182 switch(LOBYTE(context->Eax))
184 case 0x01:
185 case 0x02:
186 case 0x03:
187 case 0x04:
188 case 0x05:
189 FIXME("Task Switcher - not implemented\n");
190 break;
191 default:
192 INT_BARF( context, 0x2f );
194 break;
195 case 0x56: /* INTERLNK */
196 switch(LOBYTE(context->Eax))
198 case 0x01: /* check if redirected drive */
199 SET_AL( context, 0 ); /* not redirected */
200 break;
201 default:
202 INT_BARF( context, 0x2f );
204 break;
205 case 0x7a: /* NOVELL NetWare */
206 switch (LOBYTE(context->Eax))
208 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
209 SET_AL( context, 0 );
210 break;
211 case 0x20: /* Get VLM Call Address */
212 /* return nothing -> NetWare not installed */
213 break;
214 default:
215 INT_BARF( context, 0x2f );
216 break;
218 break;
219 case 0xb7: /* append */
220 SET_AL( context, 0 ); /* not installed */
221 break;
222 case 0xb8: /* network */
223 switch (LOBYTE(context->Eax))
225 case 0x00: /* Install check */
226 /* not installed */
227 break;
228 default:
229 INT_BARF( context, 0x2f );
230 break;
232 break;
233 case 0xbc:
234 if (AL_reg(context) == 0x00 && BX_reg(context) == 0x3f3f) {
235 /* MVSOUND.SYS - Install check: not installed */
236 } else {
237 INT_BARF( context, 0x2f );
239 break;
240 case 0xbd: /* some Novell network install check ??? */
241 SET_AX( context, 0xa5a5 ); /* pretend to have Novell IPX installed */
242 break;
243 case 0xbf: /* REDIRIFS.EXE */
244 switch (LOBYTE(context->Eax))
246 case 0x00: /* Install check */
247 /* not installed */
248 break;
249 default:
250 INT_BARF( context, 0x2f );
251 break;
253 break;
254 case 0xd2:
255 switch(LOBYTE(context->Eax))
257 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
258 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
259 && DX_reg(context) == 0x3432)
260 TRACE("Check for QEMM v5.0+ (not installed)\n");
261 break;
262 default:
263 INT_BARF( context, 0x2f );
264 break;
266 break;
267 case 0xd7: /* Banyan Vines */
268 switch (LOBYTE(context->Eax))
270 case 0x01: /* Install check - Get Int Number */
271 /* not installed */
272 break;
273 default:
274 INT_BARF( context, 0x2f );
275 break;
277 break;
278 case 0xde:
279 switch(LOBYTE(context->Eax))
281 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
282 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
283 && DX_reg(context) == 0x8f4f)
284 TRACE("Check for QDPMI.SYS (not installed)\n");
285 break;
286 default:
287 INT_BARF( context, 0x2f );
288 break;
290 break;
291 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
292 break;
293 default:
294 INT_BARF( context, 0x2f );
295 break;
300 /**********************************************************************
301 * do_int2f_16
303 static void do_int2f_16( CONTEXT86 *context )
305 DWORD addr;
307 switch(LOBYTE(context->Eax))
309 case 0x00: /* Windows enhanced mode installation check */
310 SET_AX( context, (GetWinFlags16() & WF_ENHANCED) ? LOWORD(GetVersion16()) : 0 );
311 break;
313 case 0x0a: /* Get Windows version and type */
314 SET_AX( context, 0 );
315 SET_BX( context, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
316 SET_CX( context, (GetWinFlags16() & WF_ENHANCED) ? 3 : 2 );
317 break;
319 case 0x0b: /* Identify Windows-aware TSRs */
320 /* we don't have any pre-Windows TSRs */
321 break;
323 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
324 /* We can mock this up. But not today... */
325 FIXME("Get Shell Parameters\n");
326 break;
328 case 0x80: /* Release time-slice */
329 /* Linux sched_yield() still keeps burning CPU cycles
330 * if the current process is the only one in highest priority list
331 * (as Linux will immediately return to this process to waste
332 * more CPU cycles), so sched_yield() is essentially useless for us
333 * (poor API, if you ask me: its return code should indicate
334 * whether other processes did run in between, in order for us
335 * to be able to decide whether to do an additional Sleep() or not...)
336 * Thus we better unconditionally use a well-balanced Sleep()
337 * instead to really make sure the process calling int 0x2f/0x1680
338 * *doesn't* use 100% CPU...
340 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
341 SET_AL( context, 0 );
342 break;
344 case 0x81: /* Begin critical section. */
345 /* FIXME? */
346 break;
348 case 0x82: /* End critical section. */
349 /* FIXME? */
350 break;
352 case 0x83: /* Return Current Virtual Machine ID */
353 /* Virtual Machines are usually created/destroyed when Windows runs
354 * DOS programs. Since we never do, we are always in the System VM.
355 * According to Ralf Brown's Interrupt List, never return 0. But it
356 * seems to work okay (returning 0), just to be sure we return 1.
358 SET_BX( context, 1 ); /* VM 1 is probably the System VM */
359 break;
361 case 0x84: /* Get device API entry point */
363 HMODULE16 mod = GetModuleHandle16("wprocs");
364 if (mod < 32) mod = LoadLibrary16( "wprocs" );
365 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
366 if (!addr) /* not supported */
367 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
368 context->SegEs = SELECTOROF(addr);
369 SET_DI( context, OFFSETOF(addr) );
371 break;
373 case 0x86: /* DPMI detect mode */
374 SET_AX( context, 0 ); /* Running under DPMI */
375 break;
377 case 0x87: /* DPMI installation check */
379 SYSTEM_INFO si;
380 GetSystemInfo(&si);
381 SET_AX( context, 0x0000 ); /* DPMI Installed */
382 SET_BX( context, 0x0001 ); /* 32bits available */
383 SET_CL( context, si.wProcessorLevel );
384 SET_DX( context, 0x005a ); /* DPMI major/minor 0.90 */
385 SET_SI( context, 0 ); /* # of para. of DOS extended private data */
386 context->SegEs = DOSVM_dpmi_segments->dpmi_seg;
387 SET_DI( context, 0 ); /* ES:DI is DPMI switch entry point */
388 break;
390 case 0x8a: /* DPMI get vendor-specific API entry point. */
391 /* The 1.0 specs say this should work with all 0.9 hosts. */
392 break;
394 default:
395 INT_BARF( context, 0x2f );
399 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
400 * must be <size> aligned
401 * <size> could be WORD, DWORD...
402 * in this case, we would need two macros, one for read, the other one for write
403 * Note: PTR_AT can be used as an l-value
405 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
407 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
408 #if 0
409 /**********************************************************************
410 * MSCDEX_Dump [internal]
412 * Dumps mscdex requests to int debug channel.
414 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
416 int i;
417 BYTE buf[2048];
418 BYTE* ptr;
419 BYTE* ios;
421 ptr = buf;
422 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
423 for (i = 0; i < req[0]; i++) {
424 ptr += sprintf(ptr, "%02x ", req[i]);
427 switch (req[2]) {
428 case 3:
429 case 12:
430 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
431 ios = (dorealmode) ? PTR_REAL_TO_LIN( PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)) :
432 MapSL(MAKESEGPTR(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)));
434 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
435 ptr += sprintf(ptr, "%02x ", ios[i]);
436 if ((i & 0x1F) == 0x1F) {
437 *ptr++ = '\n';
438 *ptr = 0;
441 break;
443 TRACE("%s\n", buf);
445 #else
446 #define MSCDEX_Dump(pfx, req, drm)
447 #endif
449 #define CDFRAMES_PERSEC 75
450 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
451 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
452 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
453 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
454 (toc).TrackData[idx - (toc).FirstTrack].Adr)
456 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
458 val[3] = 0; /* zero */
459 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
460 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
461 val[0] = frame % CDFRAMES_PERSEC; /* frames */
464 static int is_cdrom( int drive)
466 char root[] = "A:\\";
467 root[0] += drive;
468 return (GetDriveTypeA(root) == DRIVE_CDROM);
471 static void MSCDEX_Handler(CONTEXT86* context)
473 int drive, count;
474 char* p;
476 switch (LOBYTE(context->Eax)) {
477 case 0x00: /* Installation check */
478 /* Count the number of contiguous CDROM drives
480 for (drive = count = 0; drive < 26; drive++) {
481 if (is_cdrom(drive)) {
482 while (is_cdrom(drive + count)) count++;
483 break;
486 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
487 SET_BX( context, count );
488 SET_CX( context, (drive < 26) ? drive : 0 );
489 break;
491 case 0x0B: /* drive check */
492 SET_AX( context, is_cdrom(CX_reg(context)) );
493 SET_BX( context, 0xADAD );
494 break;
496 case 0x0C: /* get version */
497 SET_BX( context, 0x020a );
498 TRACE("Version number => %04x\n", BX_reg(context));
499 break;
501 case 0x0D: /* get drive letters */
502 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
503 memset(p, 0, 26);
504 for (drive = 0; drive < 26; drive++) {
505 if (is_cdrom(drive)) *p++ = drive;
507 TRACE("Get drive letters\n");
508 break;
510 case 0x10: /* direct driver access */
512 BYTE* driver_request;
513 BYTE* io_stru;
514 BYTE Error = 255; /* No Error */
515 int dorealmode = ISV86(context);
516 char devName[] = "\\\\.\\@:";
517 HANDLE h;
518 CDROM_TOC toc;
519 CDROM_SUB_Q_DATA_FORMAT fmt;
520 SUB_Q_CHANNEL_DATA data;
521 DWORD br;
522 DWORD present = TRUE;
524 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
526 if (!driver_request) {
527 /* FIXME - to be deleted ?? */
528 ERR("ES:BX==0 ! SEGFAULT ?\n");
529 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
530 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
531 driver_request[4] |= 0x80;
532 driver_request[3] = 5; /* bad request length */
533 return;
535 /* FIXME
536 * the following tests are wrong because lots of functions don't require the
537 * tray to be closed with a CD inside
539 TRACE("CDROM device driver -> command <%d>\n", (unsigned char)driver_request[2]);
541 if (!is_cdrom(CX_reg(context))) {
542 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
543 driver_request[4] |= 0x80;
544 driver_request[3] = 1; /* unknown unit */
545 return;
548 MSCDEX_Dump("Beg", driver_request, dorealmode);
550 /* set status to 0 */
551 PTR_AT(driver_request, 3, WORD) = 0;
552 devName[4] = 'A' + CX_reg(context);
553 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
554 if (!h) {
555 WARN("Couldn't open cdrom handle\n");
556 driver_request[4] |= 0x80;
557 driver_request[3] = 1; /* unknown unit */
558 return;
561 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
562 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
563 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
564 &data, sizeof(data), &br, NULL)) {
565 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
567 if (driver_request[2] != 6 && driver_request[2] != 15)
569 driver_request[4] |= 0x80;
570 driver_request[3] = 2; /* drive not ready */
571 CloseHandle(h);
572 return;
574 present = FALSE;
576 else
578 driver_request[4] |= 0x80;
579 driver_request[3] = 1; /* unknown unit */
580 CloseHandle(h);
581 return;
585 switch (driver_request[2]) {
586 case 3:
587 io_stru = (dorealmode) ?
588 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD) ) :
589 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
591 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
592 switch (io_stru[0]) {
593 #if 0
594 case 0: /* Get device Header */
596 static LPSTR ptr = 0;
597 if (ptr == 0) {
598 ptr = SEGPTR_ALLOC(22);
599 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
600 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
601 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
602 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
603 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
604 PTR_AT(ptr, 11, char) = 'I';
605 PTR_AT(ptr, 12, char) = 'N';
606 PTR_AT(ptr, 13, char) = 'E';
607 PTR_AT(ptr, 14, char) = '_';
608 PTR_AT(ptr, 15, char) = 'C';
609 PTR_AT(ptr, 16, char) = 'D';
610 PTR_AT(ptr, 17, char) = '_';
611 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
612 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
613 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
615 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
617 break;
618 #endif
620 case 1: /* location of head */
621 switch (io_stru[1]) {
622 case 0:
623 PTR_AT(io_stru, 2, DWORD) =
624 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
625 break;
626 case 1:
627 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
628 io_stru + 2);
629 break;
630 default:
631 ERR("CD-ROM driver: unsupported addressing mode !!\n");
632 Error = 0x0c;
634 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
635 break;
637 case 4: /* Audio channel info */
638 io_stru[1] = 0;
639 io_stru[2] = 0xff;
640 io_stru[3] = 1;
641 io_stru[4] = 0xff;
642 io_stru[5] = 2;
643 io_stru[6] = 0;
644 io_stru[7] = 3;
645 io_stru[8] = 0;
646 TRACE(" ----> AUDIO CHANNEL INFO\n");
647 break;
649 case 6: /* device status */
650 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
651 /* 290 =>
652 * 1 Supports HSG and Red Book addressing modes
653 * 0 Supports audio channel manipulation
655 * 1 Supports prefetching requests
656 * 0 Reserved
657 * 0 No interleaving
658 * 1 Data read and plays audio/video tracks
660 * 0 Read only
661 * 0 Supports only cooked reading
662 * 0 Door locked
663 * 0 see below (Door closed/opened)
665 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
666 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
667 break;
669 case 8: /* Volume size */
670 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
671 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
672 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
673 break;
675 case 9: /* media changed ? */
676 /* answers don't know... -1/1 for yes/no would be better */
677 io_stru[1] = 0; /* FIXME? 1? */
678 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
679 break;
681 case 10: /* audio disk info */
682 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
683 io_stru[2] = toc.LastTrack; /* ending track */
684 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
685 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
687 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
688 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
689 break;
691 case 11: /* audio track info */
692 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
693 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
694 /* starting point if the track */
695 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
696 } else {
697 PTR_AT(io_stru, 2, DWORD) = 0;
698 io_stru[6] = 0;
700 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
701 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
702 break;
704 case 12: /* get Q-Channel info */
705 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
706 io_stru[2] = data.CurrentPosition.TrackNumber;
707 io_stru[3] = 0; /* FIXME ?? */
709 /* why the heck did MS use another format for 0MSF information... sigh */
711 BYTE bTmp[4];
713 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
714 io_stru[ 4] = bTmp[2];
715 io_stru[ 5] = bTmp[1];
716 io_stru[ 6] = bTmp[0];
717 io_stru[ 7] = 0;
719 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
720 io_stru[ 8] = bTmp[2];
721 io_stru[ 9] = bTmp[1];
722 io_stru[10] = bTmp[0];
723 io_stru[11] = 0;
725 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
726 io_stru[ 1], io_stru[ 2], io_stru[ 3],
727 io_stru[ 4], io_stru[ 5], io_stru[ 6],
728 io_stru[ 8], io_stru[ 9], io_stru[10],
729 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
730 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
731 break;
733 case 15: /* Audio status info */
734 /* !!!! FIXME FIXME FIXME !! */
735 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
736 if (!present) {
737 PTR_AT(io_stru, 3, DWORD) = 0;
738 PTR_AT(io_stru, 7, DWORD) = 0;
739 } else {
740 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
741 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
743 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
744 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
745 break;
747 default:
748 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
749 Error = 0x0c;
750 break;
752 break;
754 case 12:
755 io_stru = (dorealmode) ?
756 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)) :
757 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
759 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
760 switch (io_stru[0]) {
761 case 0: /* eject */
762 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
763 TRACE(" ----> EJECT\n");
764 break;
765 case 2: /* reset drive */
766 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
767 TRACE(" ----> RESET\n");
768 break;
769 case 3: /* Audio Channel Control */
770 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
771 break;
772 case 5: /* close tray */
773 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
774 TRACE(" ----> CLOSE TRAY\n");
775 break;
776 default:
777 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
778 Error = 0x0c;
779 break;
781 break;
783 case 128: /* read long */
785 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
786 PTR_AT(driver_request, 14, WORD)));
787 DWORD at = PTR_AT(driver_request, 20, DWORD);
788 WORD num = PTR_AT(driver_request, 18, WORD);
789 RAW_READ_INFO rri;
791 switch (driver_request[13]) {
792 case 1: /* Red book addressing mode = 0:m:s:f */
793 /* FIXME : frame <=> msf conversion routines could be shared
794 * between mscdex and mcicda
796 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
797 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
798 LOBYTE(LOWORD(at));
799 /* fall through */
800 case 0: /* HSG addressing mode */
801 switch (PTR_AT(driver_request, 24, BYTE))
803 case 0: /* cooked */
804 ReadFile(h, dst, num * 2048, &br, NULL);
805 break;
806 case 1:
807 /* FIXME: computation is wrong */
808 rri.DiskOffset.u.HighPart = 0;
809 rri.DiskOffset.u.LowPart = at << 11;
810 rri.TrackMode = YellowMode2;
811 rri.SectorCount = num;
812 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
813 dst, num * 2352, &br, NULL);
814 break;
815 default:
816 ERR("Unsupported read mode !!\n");
817 Error = 0x0c;
818 break;
820 break;
821 default:
822 ERR("Unsupported address mode !!\n");
823 Error = 0x0c;
824 break;
827 break;
829 case 131: /* seek */
831 DWORD at;
832 CDROM_SEEK_AUDIO_MSF seek;
834 at = PTR_AT(driver_request, 20, DWORD);
836 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
837 (BYTE)driver_request[13], at);
839 switch (driver_request[13]) {
840 case 1: /* Red book addressing mode = 0:m:s:f */
841 /* FIXME : frame <=> msf conversion routines could be shared
842 * between mscdex and mcicda
844 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
845 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
846 LOBYTE(LOWORD(at));
847 /* fall through */
848 case 0: /* HSG addressing mode */
849 seek.M = at / CDFRAMES_PERMIN;
850 seek.S = (at / CDFRAMES_PERSEC) % 60;
851 seek.F = at % CDFRAMES_PERSEC;
852 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
853 NULL, 0, &br, NULL);
854 break;
855 default:
856 ERR("Unsupported address mode !!\n");
857 Error = 0x0c;
858 break;
861 break;
863 case 132: /* play */
865 DWORD beg, end;
866 CDROM_PLAY_AUDIO_MSF play;
868 beg = end = PTR_AT(driver_request, 14, DWORD);
869 end += PTR_AT(driver_request, 18, DWORD);
871 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
872 (BYTE)driver_request[13], beg, end);
874 switch (driver_request[13]) {
875 case 1:
876 /* Red book addressing mode = 0:m:s:f */
877 /* FIXME : frame <=> msf conversion routines could be shared
878 * between mscdex and mcicda
880 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
881 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
882 LOBYTE(HIWORD(beg));
883 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
884 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
885 LOBYTE(HIWORD(end));
886 /* fall through */
887 case 0: /* HSG addressing mode */
888 play.StartingM = beg / CDFRAMES_PERMIN;
889 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
890 play.StartingF = beg % CDFRAMES_PERSEC;
891 play.EndingM = end / CDFRAMES_PERMIN;
892 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
893 play.EndingF = end % CDFRAMES_PERSEC;
894 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
895 NULL, 0, &br, NULL);
896 break;
897 default:
898 ERR("Unsupported address mode !!\n");
899 Error = 0x0c;
900 break;
903 break;
905 case 133:
906 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
907 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
908 TRACE(" --> STOP AUDIO (Paused)\n");
909 } else {
910 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
911 TRACE(" --> STOP AUDIO (Stopped)\n");
913 break;
915 case 136:
916 TRACE(" --> RESUME AUDIO\n");
917 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
918 break;
920 default:
921 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
922 Error = 0x0c;
925 /* setting error codes if any */
926 if (Error < 255) {
927 driver_request[4] |= 0x80;
928 driver_request[3] = Error;
931 CloseHandle(h);
932 /* setting status bits
933 * 3 == playing && done
934 * 1 == done
936 driver_request[4] |=
937 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
939 MSCDEX_Dump("End", driver_request, dorealmode);
941 break;
942 default:
943 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
944 break;