Fix SM_CYVTHUMB, SM_CXSMSIZE, SM_CXMENUCHECK and SM_CYMENUCHECK.
[wine/multimedia.git] / msdos / int2f.c
blob9adc43dcaea052978e1088081884ba2d13f965e8
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>
27 #include "wine/winbase16.h"
28 #include "miscemu.h"
29 #include "module.h"
30 /* #define DEBUG_INT */
31 #include "wine/debug.h"
32 #include "winioctl.h"
33 #include "ntddstor.h"
34 #include "ntddcdrm.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(int);
38 /* base WPROCS.DLL ordinal number for VxDs */
39 #define VXD_BASE 400
41 static void do_int2f_16( CONTEXT86 *context );
42 static void MSCDEX_Handler( CONTEXT86 *context );
44 /**********************************************************************
45 * INT_Int2fHandler (WPROCS.147)
47 * Handler for int 2fh (multiplex).
49 void WINAPI INT_Int2fHandler( CONTEXT86 *context )
51 TRACE("Subfunction 0x%X\n", AX_reg(context));
53 switch(AH_reg(context))
55 case 0x10:
56 SET_AL( context, 0xff ); /* share is installed */
57 break;
59 case 0x11: /* Network Redirector / IFSFUNC */
60 switch (LOBYTE(context->Eax))
62 case 0x00: /* Install check */
63 /* not installed */
64 break;
65 case 0x80: /* Enhanced services - Install check */
66 /* not installed */
67 break;
68 default:
69 INT_BARF( context, 0x2f );
70 break;
72 break;
74 case 0x12:
75 switch (LOBYTE(context->Eax))
77 case 0x2e: /* get or set DOS error table address */
78 switch (DL_reg(context))
80 /* Four tables: even commands are 'get', odd are 'set' */
81 /* DOS 5.0+ ignores "set" commands */
82 case 0x01:
83 case 0x03:
84 case 0x05:
85 case 0x07:
86 case 0x09:
87 break;
88 /* Instead of having a message table in DOS-space, */
89 /* we can use a special case for MS-DOS to force */
90 /* the secondary interface. */
91 case 0x00:
92 case 0x02:
93 case 0x04:
94 case 0x06:
95 context->SegEs = 0x0001;
96 SET_DI( context, 0x0000 );
97 break;
98 case 0x08:
99 FIXME("No real-mode handler for errors yet! (bye!)\n");
100 break;
101 default:
102 INT_BARF(context, 0x2f);
104 break;
105 default:
106 INT_BARF(context, 0x2f);
108 break;
110 case 0x15: /* mscdex */
111 MSCDEX_Handler(context);
112 break;
114 case 0x16:
115 do_int2f_16( context );
116 break;
118 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
119 /* Not supported yet, do nothing */
120 break;
122 case 0x43:
123 #if 1
124 switch (LOBYTE(context->Eax))
126 case 0x00: /* XMS v2+ installation check */
127 WARN("XMS is not fully implemented\n");
128 SET_AL( context, 0x80 );
129 break;
130 case 0x10: /* XMS v2+ get driver address */
132 context->SegEs = DOSMEM_dpmi_segments.xms_seg;
133 SET_BX( context, 0 );
134 break;
136 default:
137 INT_BARF( context, 0x2f );
139 #else
140 FIXME("check for XMS (not supported)\n");
141 SET_AL( context, 0x42 ); /* != 0x80 */
142 #endif
143 break;
145 case 0x45:
146 switch (LOBYTE(context->Eax))
148 case 0x00:
149 case 0x01:
150 case 0x02:
151 case 0x03:
152 case 0x04:
153 case 0x05:
154 case 0x06:
155 case 0x07:
156 case 0x08:
157 /* Microsoft Profiler - not installed */
158 break;
159 default:
160 INT_BARF( context, 0x2f );
162 break;
164 case 0x4a:
165 switch(LOBYTE(context->Eax))
167 case 0x10: /* smartdrv */
168 break; /* not installed */
169 case 0x11: /* dblspace */
170 break; /* not installed */
171 case 0x12: /* realtime compression interface */
172 break; /* not installed */
173 case 0x32: /* patch IO.SYS (???) */
174 break; /* we have no IO.SYS, so we can't patch it :-/ */
175 default:
176 INT_BARF( context, 0x2f );
178 break;
179 case 0x4b:
180 switch(LOBYTE(context->Eax))
182 case 0x01:
183 case 0x02:
184 case 0x03:
185 case 0x04:
186 case 0x05:
187 FIXME("Task Switcher - not implemented\n");
188 break;
189 default:
190 INT_BARF( context, 0x2f );
192 break;
193 case 0x56: /* INTERLNK */
194 switch(LOBYTE(context->Eax))
196 case 0x01: /* check if redirected drive */
197 SET_AL( context, 0 ); /* not redirected */
198 break;
199 default:
200 INT_BARF( context, 0x2f );
202 break;
203 case 0x7a: /* NOVELL NetWare */
204 switch (LOBYTE(context->Eax))
206 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
207 SET_AL( context, 0 );
208 break;
209 case 0x20: /* Get VLM Call Address */
210 /* return nothing -> NetWare not installed */
211 break;
212 default:
213 INT_BARF( context, 0x2f );
214 break;
216 break;
217 case 0xb7: /* append */
218 SET_AL( context, 0 ); /* not installed */
219 break;
220 case 0xb8: /* network */
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 0xbd: /* some Novell network install check ??? */
232 SET_AX( context, 0xa5a5 ); /* pretend to have Novell IPX installed */
233 break;
234 case 0xbf: /* REDIRIFS.EXE */
235 switch (LOBYTE(context->Eax))
237 case 0x00: /* Install check */
238 /* not installed */
239 break;
240 default:
241 INT_BARF( context, 0x2f );
242 break;
244 break;
245 case 0xd2:
246 switch(LOBYTE(context->Eax))
248 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
249 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
250 && DX_reg(context) == 0x3432)
251 TRACE("Check for QEMM v5.0+ (not installed)\n");
252 break;
253 default:
254 INT_BARF( context, 0x2f );
255 break;
257 break;
258 case 0xd7: /* Banyan Vines */
259 switch (LOBYTE(context->Eax))
261 case 0x01: /* Install check - Get Int Number */
262 /* not installed */
263 break;
264 default:
265 INT_BARF( context, 0x2f );
266 break;
268 break;
269 case 0xde:
270 switch(LOBYTE(context->Eax))
272 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
273 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
274 && DX_reg(context) == 0x8f4f)
275 TRACE("Check for QDPMI.SYS (not installed)\n");
276 break;
277 default:
278 INT_BARF( context, 0x2f );
279 break;
281 break;
282 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
283 break;
284 default:
285 INT_BARF( context, 0x2f );
286 break;
291 /**********************************************************************
292 * do_int2f_16
294 static void do_int2f_16( CONTEXT86 *context )
296 DWORD addr;
298 switch(LOBYTE(context->Eax))
300 case 0x00: /* Windows enhanced mode installation check */
301 SET_AX( context, (GetWinFlags16() & WF_ENHANCED) ? LOWORD(GetVersion16()) : 0 );
302 break;
304 case 0x0a: /* Get Windows version and type */
305 SET_AX( context, 0 );
306 SET_BX( context, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
307 SET_CX( context, (GetWinFlags16() & WF_ENHANCED) ? 3 : 2 );
308 break;
310 case 0x0b: /* Identify Windows-aware TSRs */
311 /* we don't have any pre-Windows TSRs */
312 break;
314 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
315 /* We can mock this up. But not today... */
316 FIXME("Get Shell Parameters\n");
317 break;
319 case 0x80: /* Release time-slice */
320 /* Linux sched_yield() still keeps burning CPU cycles
321 * if the current process is the only one in highest priority list
322 * (as Linux will immediately return to this process to waste
323 * more CPU cycles), so sched_yield() is essentially useless for us
324 * (poor API, if you ask me: its return code should indicate
325 * whether other processes did run in between, in order for us
326 * to be able to decide whether to do an additional Sleep() or not...)
327 * Thus we better unconditionally use a well-balanced Sleep()
328 * instead to really make sure the process calling int 0x2f/0x1680
329 * *doesn't* use 100% CPU...
331 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
332 SET_AL( context, 0 );
333 break;
335 case 0x81: /* Begin critical section. */
336 /* FIXME? */
337 break;
339 case 0x82: /* End critical section. */
340 /* FIXME? */
341 break;
343 case 0x83: /* Return Current Virtual Machine ID */
344 /* Virtual Machines are usually created/destroyed when Windows runs
345 * DOS programs. Since we never do, we are always in the System VM.
346 * According to Ralf Brown's Interrupt List, never return 0. But it
347 * seems to work okay (returning 0), just to be sure we return 1.
349 SET_BX( context, 1 ); /* VM 1 is probably the System VM */
350 break;
352 case 0x84: /* Get device API entry point */
354 HMODULE16 mod = GetModuleHandle16("wprocs");
355 if (mod < 32) mod = LoadLibrary16( "wprocs" );
356 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
357 if (!addr) /* not supported */
358 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
359 context->SegEs = SELECTOROF(addr);
360 SET_DI( context, OFFSETOF(addr) );
362 break;
364 case 0x86: /* DPMI detect mode */
365 SET_AX( context, 0 ); /* Running under DPMI */
366 break;
368 case 0x87: /* DPMI installation check */
370 SYSTEM_INFO si;
371 GetSystemInfo(&si);
372 SET_AX( context, 0x0000 ); /* DPMI Installed */
373 SET_BX( context, 0x0001 ); /* 32bits available */
374 SET_CL( context, si.wProcessorLevel );
375 SET_DX( context, 0x005a ); /* DPMI major/minor 0.90 */
376 SET_SI( context, 0 ); /* # of para. of DOS extended private data */
377 context->SegEs = DOSMEM_dpmi_segments.dpmi_seg;
378 SET_DI( context, 0 ); /* ES:DI is DPMI switch entry point */
379 break;
381 case 0x8a: /* DPMI get vendor-specific API entry point. */
382 /* The 1.0 specs say this should work with all 0.9 hosts. */
383 break;
385 default:
386 INT_BARF( context, 0x2f );
390 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
391 * must be <size> aligned
392 * <size> could be WORD, DWORD...
393 * in this case, we would need two macros, one for read, the other one for write
394 * Note: PTR_AT can be used as an l-value
396 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
398 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
399 #if 0
400 /**********************************************************************
401 * MSCDEX_Dump [internal]
403 * Dumps mscdex requests to int debug channel.
405 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
407 int i;
408 BYTE buf[2048];
409 BYTE* ptr;
410 BYTE* ios;
412 ptr = buf;
413 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
414 for (i = 0; i < req[0]; i++) {
415 ptr += sprintf(ptr, "%02x ", req[i]);
418 switch (req[2]) {
419 case 3:
420 case 12:
421 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
422 ios = (dorealmode) ? PTR_REAL_TO_LIN( PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)) :
423 MapSL(MAKESEGPTR(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)));
425 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
426 ptr += sprintf(ptr, "%02x ", ios[i]);
427 if ((i & 0x1F) == 0x1F) {
428 *ptr++ = '\n';
429 *ptr = 0;
432 break;
434 TRACE("%s\n", buf);
436 #else
437 #define MSCDEX_Dump(pfx, req, drm)
438 #endif
440 #define CDFRAMES_PERSEC 75
441 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
442 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
443 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
444 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
445 (toc).TrackData[idx - (toc).FirstTrack].Adr)
447 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
449 val[3] = 0; /* zero */
450 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
451 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
452 val[0] = frame % CDFRAMES_PERSEC; /* frames */
455 static int is_cdrom( int drive)
457 char root[] = "A:\\";
458 root[0] += drive;
459 return (GetDriveTypeA(root) == DRIVE_CDROM);
462 static void MSCDEX_Handler(CONTEXT86* context)
464 int drive, count;
465 char* p;
467 switch (LOBYTE(context->Eax)) {
468 case 0x00: /* Installation check */
469 /* Count the number of contiguous CDROM drives
471 for (drive = count = 0; drive < 26; drive++) {
472 if (is_cdrom(drive)) {
473 while (is_cdrom(drive + count)) count++;
474 break;
477 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
478 SET_BX( context, count );
479 SET_CX( context, (drive < 26) ? drive : 0 );
480 break;
482 case 0x0B: /* drive check */
483 SET_AX( context, is_cdrom(CX_reg(context)) );
484 SET_BX( context, 0xADAD );
485 break;
487 case 0x0C: /* get version */
488 SET_BX( context, 0x020a );
489 TRACE("Version number => %04x\n", BX_reg(context));
490 break;
492 case 0x0D: /* get drive letters */
493 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
494 memset(p, 0, 26);
495 for (drive = 0; drive < 26; drive++) {
496 if (is_cdrom(drive)) *p++ = drive;
498 TRACE("Get drive letters\n");
499 break;
501 case 0x10: /* direct driver access */
503 BYTE* driver_request;
504 BYTE* io_stru;
505 BYTE Error = 255; /* No Error */
506 int dorealmode = ISV86(context);
507 char devName[] = "\\\\.\\@:";
508 HANDLE h;
509 CDROM_TOC toc;
510 CDROM_SUB_Q_DATA_FORMAT fmt;
511 SUB_Q_CHANNEL_DATA data;
512 DWORD br;
513 DWORD present = TRUE;
515 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
517 if (!driver_request) {
518 /* FIXME - to be deleted ?? */
519 ERR("ES:BX==0 ! SEGFAULT ?\n");
520 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
521 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
522 driver_request[4] |= 0x80;
523 driver_request[3] = 5; /* bad request length */
524 return;
526 /* FIXME
527 * the following tests are wrong because lots of functions don't require the
528 * tray to be closed with a CD inside
530 TRACE("CDROM device driver -> command <%d>\n", (unsigned char)driver_request[2]);
532 if (!is_cdrom(CX_reg(context))) {
533 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
534 driver_request[4] |= 0x80;
535 driver_request[3] = 1; /* unknown unit */
536 return;
539 MSCDEX_Dump("Beg", driver_request, dorealmode);
541 /* set status to 0 */
542 PTR_AT(driver_request, 3, WORD) = 0;
543 devName[4] = 'A' + CX_reg(context);
544 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
545 if (!h) {
546 WARN("Couldn't open cdrom handle\n");
547 driver_request[4] |= 0x80;
548 driver_request[3] = 1; /* unknown unit */
549 return;
552 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
553 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
554 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
555 &data, sizeof(data), &br, NULL)) {
556 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
558 if (driver_request[2] != 6 && driver_request[2] != 15)
560 driver_request[4] |= 0x80;
561 driver_request[3] = 2; /* drive not ready */
562 CloseHandle(h);
563 return;
565 present = FALSE;
567 else
569 driver_request[4] |= 0x80;
570 driver_request[3] = 1; /* unknown unit */
571 CloseHandle(h);
572 return;
576 switch (driver_request[2]) {
577 case 3:
578 io_stru = (dorealmode) ?
579 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD) ) :
580 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
582 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
583 switch (io_stru[0]) {
584 #if 0
585 case 0: /* Get device Header */
587 static LPSTR ptr = 0;
588 if (ptr == 0) {
589 ptr = SEGPTR_ALLOC(22);
590 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
591 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
592 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
593 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
594 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
595 PTR_AT(ptr, 11, char) = 'I';
596 PTR_AT(ptr, 12, char) = 'N';
597 PTR_AT(ptr, 13, char) = 'E';
598 PTR_AT(ptr, 14, char) = '_';
599 PTR_AT(ptr, 15, char) = 'C';
600 PTR_AT(ptr, 16, char) = 'D';
601 PTR_AT(ptr, 17, char) = '_';
602 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
603 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
604 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
606 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
608 break;
609 #endif
611 case 1: /* location of head */
612 switch (io_stru[1]) {
613 case 0:
614 PTR_AT(io_stru, 2, DWORD) =
615 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
616 break;
617 case 1:
618 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
619 io_stru + 2);
620 break;
621 default:
622 ERR("CD-ROM driver: unsupported addressing mode !!\n");
623 Error = 0x0c;
625 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
626 break;
628 case 4: /* Audio channel info */
629 io_stru[1] = 0;
630 io_stru[2] = 0xff;
631 io_stru[3] = 1;
632 io_stru[4] = 0xff;
633 io_stru[5] = 2;
634 io_stru[6] = 0;
635 io_stru[7] = 3;
636 io_stru[8] = 0;
637 TRACE(" ----> AUDIO CHANNEL INFO\n");
638 break;
640 case 6: /* device status */
641 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
642 /* 290 =>
643 * 1 Supports HSG and Red Book addressing modes
644 * 0 Supports audio channel manipulation
646 * 1 Supports prefetching requests
647 * 0 Reserved
648 * 0 No interleaving
649 * 1 Data read and plays audio/video tracks
651 * 0 Read only
652 * 0 Supports only cooked reading
653 * 0 Door locked
654 * 0 see below (Door closed/opened)
656 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
657 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
658 break;
660 case 8: /* Volume size */
661 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
662 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
663 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
664 break;
666 case 9: /* media changed ? */
667 /* answers don't know... -1/1 for yes/no would be better */
668 io_stru[1] = 0; /* FIXME? 1? */
669 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
670 break;
672 case 10: /* audio disk info */
673 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
674 io_stru[2] = toc.LastTrack; /* ending track */
675 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
676 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
678 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
679 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
680 break;
682 case 11: /* audio track info */
683 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
684 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
685 /* starting point if the track */
686 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
687 } else {
688 PTR_AT(io_stru, 2, DWORD) = 0;
689 io_stru[6] = 0;
691 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
692 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
693 break;
695 case 12: /* get Q-Channel info */
696 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
697 io_stru[2] = data.CurrentPosition.TrackNumber;
698 io_stru[3] = 0; /* FIXME ?? */
700 /* why the heck did MS use another format for 0MSF information... sigh */
702 BYTE bTmp[4];
704 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
705 io_stru[ 4] = bTmp[2];
706 io_stru[ 5] = bTmp[1];
707 io_stru[ 6] = bTmp[0];
708 io_stru[ 7] = 0;
710 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
711 io_stru[ 8] = bTmp[2];
712 io_stru[ 9] = bTmp[1];
713 io_stru[10] = bTmp[0];
714 io_stru[11] = 0;
716 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
717 io_stru[ 1], io_stru[ 2], io_stru[ 3],
718 io_stru[ 4], io_stru[ 5], io_stru[ 6],
719 io_stru[ 8], io_stru[ 9], io_stru[10],
720 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
721 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
722 break;
724 case 15: /* Audio status info */
725 /* !!!! FIXME FIXME FIXME !! */
726 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
727 if (!present) {
728 PTR_AT(io_stru, 3, DWORD) = 0;
729 PTR_AT(io_stru, 7, DWORD) = 0;
730 } else {
731 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
732 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
734 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
735 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
736 break;
738 default:
739 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
740 Error = 0x0c;
741 break;
743 break;
745 case 12:
746 io_stru = (dorealmode) ?
747 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)) :
748 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
750 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
751 switch (io_stru[0]) {
752 case 0: /* eject */
753 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
754 TRACE(" ----> EJECT\n");
755 break;
756 case 2: /* reset drive */
757 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
758 TRACE(" ----> RESET\n");
759 break;
760 case 3: /* Audio Channel Control */
761 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
762 break;
763 case 5: /* close tray */
764 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
765 TRACE(" ----> CLOSE TRAY\n");
766 break;
767 default:
768 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
769 Error = 0x0c;
770 break;
772 break;
774 case 128: /* read long */
776 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
777 PTR_AT(driver_request, 14, WORD)));
778 DWORD at = PTR_AT(driver_request, 20, DWORD);
779 WORD num = PTR_AT(driver_request, 18, WORD);
780 RAW_READ_INFO rri;
782 switch (driver_request[13]) {
783 case 1: /* Red book addressing mode = 0:m:s:f */
784 /* FIXME : frame <=> msf conversion routines could be shared
785 * between mscdex and mcicda
787 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
788 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
789 LOBYTE(LOWORD(at));
790 /* fall through */
791 case 0: /* HSG addressing mode */
792 switch (PTR_AT(driver_request, 24, BYTE))
794 case 0: /* cooked */
795 ReadFile(h, dst, num * 2048, &br, NULL);
796 break;
797 case 1:
798 /* FIXME: computation is wrong */
799 rri.DiskOffset.s.HighPart = 0;
800 rri.DiskOffset.s.LowPart = at << 11;
801 rri.TrackMode = YellowMode2;
802 rri.SectorCount = num;
803 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
804 dst, num * 2352, &br, NULL);
805 break;
806 default:
807 ERR("Unsupported read mode !!\n");
808 Error = 0x0c;
809 break;
811 break;
812 default:
813 ERR("Unsupported address mode !!\n");
814 Error = 0x0c;
815 break;
818 break;
820 case 131: /* seek */
822 DWORD at;
823 CDROM_SEEK_AUDIO_MSF seek;
825 at = PTR_AT(driver_request, 20, DWORD);
827 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n",
828 (BYTE)driver_request[13], at);
830 switch (driver_request[13]) {
831 case 1: /* Red book addressing mode = 0:m:s:f */
832 /* FIXME : frame <=> msf conversion routines could be shared
833 * between mscdex and mcicda
835 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
836 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
837 LOBYTE(LOWORD(at));
838 /* fall through */
839 case 0: /* HSG addressing mode */
840 seek.M = at / CDFRAMES_PERMIN;
841 seek.S = (at / CDFRAMES_PERSEC) % 60;
842 seek.F = at % CDFRAMES_PERSEC;
843 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
844 NULL, 0, &br, NULL);
845 break;
846 default:
847 ERR("Unsupported address mode !!\n");
848 Error = 0x0c;
849 break;
852 break;
854 case 132: /* play */
856 DWORD beg, end;
857 CDROM_PLAY_AUDIO_MSF play;
859 beg = end = PTR_AT(driver_request, 14, DWORD);
860 end += PTR_AT(driver_request, 18, DWORD);
862 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n",
863 (BYTE)driver_request[13], beg, end);
865 switch (driver_request[13]) {
866 case 1:
867 /* Red book addressing mode = 0:m:s:f */
868 /* FIXME : frame <=> msf conversion routines could be shared
869 * between mscdex and mcicda
871 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
872 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
873 LOBYTE(HIWORD(beg));
874 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
875 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
876 LOBYTE(HIWORD(end));
877 /* fall through */
878 case 0: /* HSG addressing mode */
879 play.StartingM = beg / CDFRAMES_PERMIN;
880 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
881 play.StartingF = beg % CDFRAMES_PERSEC;
882 play.EndingM = end / CDFRAMES_PERMIN;
883 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
884 play.EndingF = end % CDFRAMES_PERSEC;
885 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
886 NULL, 0, &br, NULL);
887 break;
888 default:
889 ERR("Unsupported address mode !!\n");
890 Error = 0x0c;
891 break;
894 break;
896 case 133:
897 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
898 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
899 TRACE(" --> STOP AUDIO (Paused)\n");
900 } else {
901 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
902 TRACE(" --> STOP AUDIO (Stopped)\n");
904 break;
906 case 136:
907 TRACE(" --> RESUME AUDIO\n");
908 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
909 break;
911 default:
912 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
913 Error = 0x0c;
916 /* setting error codes if any */
917 if (Error < 255) {
918 driver_request[4] |= 0x80;
919 driver_request[3] = Error;
922 CloseHandle(h);
923 /* setting status bits
924 * 3 == playing && done
925 * 1 == done
927 driver_request[4] |=
928 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
930 MSCDEX_Dump("End", driver_request, dorealmode);
932 break;
933 default:
934 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
935 break;