kernel32: Update version to Win 10.
[wine.git] / dlls / krnl386.exe16 / int2f.c
bloba50486c28d2d38358c4aad0208f23c266c768855
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include <string.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #define NONAMELESSUNION
29 #include "wine/winbase16.h"
30 #include "wine/debug.h"
31 #include "winternl.h"
32 #include "winioctl.h"
33 #include "ntddstor.h"
34 #include "ntddcdrm.h"
35 #include "dosexe.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(int);
39 /* base KERNEL ordinal number for VxDs */
40 #define VXD_BASE 900
42 typedef struct
44 DOS_DEVICE_HEADER hdr;
46 WORD reserved; /* must be 0 */
47 BYTE drive; /* drive letter (0=A:, 1=B:, ...) */
48 BYTE units; /* number of supported units */
49 } CDROM_DEVICE_HEADER;
51 typedef struct
53 CDROM_DEVICE_HEADER hdr;
54 WORD cdrom_selector; /* Protected mode selector for CDROM_HEAP */
55 } CDROM_HEAP;
57 static void do_int2f_16( CONTEXT *context );
58 static void MSCDEX_Handler( CONTEXT *context );
60 /**********************************************************************
61 * DOSVM_Int2fHandler
63 * Handler for int 2fh (multiplex).
65 void WINAPI DOSVM_Int2fHandler( CONTEXT *context )
67 TRACE("Subfunction 0x%X\n", AX_reg(context));
69 switch(AH_reg(context))
71 case 0x10:
72 SET_AL( context, 0xff ); /* share is installed */
73 break;
75 case 0x11: /* Network Redirector / IFSFUNC */
76 switch (LOBYTE(context->Eax))
78 case 0x00: /* Install check */
79 /* not installed */
80 break;
81 case 0x80: /* Enhanced services - Install check */
82 /* not installed */
83 break;
84 default:
85 INT_BARF( context, 0x2f );
86 break;
88 break;
90 case 0x12:
91 switch (LOBYTE(context->Eax))
93 case 0x2e: /* get or set DOS error table address */
94 switch (DL_reg(context))
96 /* Four tables: even commands are 'get', odd are 'set' */
97 /* DOS 5.0+ ignores "set" commands */
98 case 0x01:
99 case 0x03:
100 case 0x05:
101 case 0x07:
102 case 0x09:
103 break;
104 /* Instead of having a message table in DOS-space, */
105 /* we can use a special case for MS-DOS to force */
106 /* the secondary interface. */
107 case 0x00:
108 case 0x02:
109 case 0x04:
110 case 0x06:
111 context->SegEs = 0x0001;
112 SET_DI( context, 0x0000 );
113 break;
114 case 0x08:
115 FIXME("No real-mode handler for errors yet! (bye!)\n");
116 break;
117 default:
118 INT_BARF(context, 0x2f);
120 break;
121 default:
122 INT_BARF(context, 0x2f);
124 break;
126 case 0x15: /* mscdex */
127 MSCDEX_Handler(context);
128 break;
130 case 0x16:
131 do_int2f_16( context );
132 break;
134 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
135 /* Not supported yet, do nothing */
136 break;
138 case 0x43:
139 FIXME("check for XMS (not supported)\n");
140 SET_AL( context, 0x42 ); /* != 0x80 */
141 break;
143 case 0x45:
144 switch (LOBYTE(context->Eax))
146 case 0x00:
147 case 0x01:
148 case 0x02:
149 case 0x03:
150 case 0x04:
151 case 0x05:
152 case 0x06:
153 case 0x07:
154 case 0x08:
155 /* Microsoft Profiler - not installed */
156 break;
157 default:
158 INT_BARF( context, 0x2f );
160 break;
162 case 0x4a:
163 switch(LOBYTE(context->Eax))
165 case 0x10: /* smartdrv */
166 break; /* not installed */
167 case 0x11: /* dblspace */
168 break; /* not installed */
169 case 0x12: /* realtime compression interface */
170 break; /* not installed */
171 case 0x32: /* patch IO.SYS (???) */
172 break; /* we have no IO.SYS, so we can't patch it :-/ */
173 default:
174 INT_BARF( context, 0x2f );
176 break;
177 case 0x4b:
178 switch(LOBYTE(context->Eax))
180 case 0x01:
181 case 0x02:
182 case 0x03:
183 case 0x04:
184 case 0x05:
185 FIXME("Task Switcher - not implemented\n");
186 break;
187 default:
188 INT_BARF( context, 0x2f );
190 break;
191 case 0x56: /* INTERLNK */
192 switch(LOBYTE(context->Eax))
194 case 0x01: /* check if redirected drive */
195 SET_AL( context, 0 ); /* not redirected */
196 break;
197 default:
198 INT_BARF( context, 0x2f );
200 break;
201 case 0x7a: /* NOVELL NetWare */
202 switch (LOBYTE(context->Eax))
204 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
205 SET_AL( context, 0 );
206 break;
207 case 0x20: /* Get VLM Call Address */
208 /* return nothing -> NetWare not installed */
209 break;
210 default:
211 INT_BARF( context, 0x2f );
212 break;
214 break;
215 case 0xb7: /* append */
216 SET_AL( context, 0 ); /* not installed */
217 break;
218 case 0xb8: /* network */
219 switch (LOBYTE(context->Eax))
221 case 0x00: /* Install check */
222 /* not installed */
223 break;
224 default:
225 INT_BARF( context, 0x2f );
226 break;
228 break;
229 case 0xbc:
230 if (AL_reg(context) == 0x00 && BX_reg(context) == 0x3f3f) {
231 /* MVSOUND.SYS - Install check: not installed */
232 } else {
233 INT_BARF( context, 0x2f );
235 break;
236 case 0xbd: /* some Novell network install check ??? */
237 SET_AX( context, 0xa5a5 ); /* pretend to have Novell IPX installed */
238 break;
239 case 0xbf: /* REDIRIFS.EXE */
240 switch (LOBYTE(context->Eax))
242 case 0x00: /* Install check */
243 /* not installed */
244 break;
245 default:
246 INT_BARF( context, 0x2f );
247 break;
249 break;
250 case 0xd2:
251 switch(LOBYTE(context->Eax))
253 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
254 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
255 && DX_reg(context) == 0x3432)
256 TRACE("Check for QEMM v5.0+ (not installed)\n");
257 break;
258 default:
259 INT_BARF( context, 0x2f );
260 break;
262 break;
263 case 0xd7: /* Banyan Vines */
264 switch (LOBYTE(context->Eax))
266 case 0x01: /* Install check - Get Int Number */
267 /* not installed */
268 break;
269 default:
270 INT_BARF( context, 0x2f );
271 break;
273 break;
274 case 0xde:
275 switch(LOBYTE(context->Eax))
277 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
278 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
279 && DX_reg(context) == 0x8f4f)
280 TRACE("Check for QDPMI.SYS (not installed)\n");
281 break;
282 default:
283 INT_BARF( context, 0x2f );
284 break;
286 break;
287 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
288 break;
289 default:
290 INT_BARF( context, 0x2f );
291 break;
296 /**********************************************************************
297 * do_int2f_16
299 static void do_int2f_16( CONTEXT *context )
301 DWORD addr;
303 switch(LOBYTE(context->Eax))
305 case 0x00: /* Windows enhanced mode installation check */
306 SET_AX( context, LOWORD(GetVersion16()) );
307 break;
309 case 0x0a: /* Get Windows version and type */
310 SET_AX( context, 0 );
311 SET_BX( context, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
312 SET_CX( context, 3 );
313 break;
315 case 0x0b: /* Identify Windows-aware TSRs */
316 /* we don't have any pre-Windows TSRs */
317 break;
319 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
320 /* We can mock this up. But not today... */
321 FIXME("Get Shell Parameters\n");
322 break;
324 case 0x80: /* Release time-slice */
325 /* Linux sched_yield() still keeps burning CPU cycles
326 * if the current process is the only one in highest priority list
327 * (as Linux will immediately return to this process to waste
328 * more CPU cycles), so sched_yield() is essentially useless for us
329 * (poor API, if you ask me: its return code should indicate
330 * whether other processes did run in between, in order for us
331 * to be able to decide whether to do an additional Sleep() or not...)
332 * Thus we better unconditionally use a well-balanced Sleep()
333 * instead to really make sure the process calling int 0x2f/0x1680
334 * *doesn't* use 100% CPU...
336 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
337 SET_AL( context, 0 );
338 break;
340 case 0x81: /* Begin critical section. */
341 /* FIXME? */
342 break;
344 case 0x82: /* End critical section. */
345 /* FIXME? */
346 break;
348 case 0x83: /* Return Current Virtual Machine ID */
349 /* Virtual Machines are usually created/destroyed when Windows runs
350 * DOS programs. Since we never do, we are always in the System VM.
351 * According to Ralf Brown's Interrupt List, never return 0. But it
352 * seems to work okay (returning 0), just to be sure we return 1.
354 SET_BX( context, 1 ); /* VM 1 is probably the System VM */
355 break;
357 case 0x84: /* Get device API entry point */
359 HMODULE16 mod = GetModuleHandle16("kernel");
360 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
361 if (!addr) /* not supported */
362 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
363 context->SegEs = SELECTOROF(addr);
364 SET_DI( context, OFFSETOF(addr) );
366 break;
368 case 0x86: /* DPMI detect mode */
369 SET_AX( context, 0 ); /* Running under DPMI */
370 break;
372 case 0x87: /* DPMI installation check */
374 SYSTEM_INFO si;
375 GetSystemInfo(&si);
376 SET_AX( context, 0x0000 ); /* DPMI Installed */
377 SET_BX( context, 0x0001 ); /* 32bits available */
378 SET_CL( context, si.wProcessorLevel );
379 SET_DX( context, 0x005a ); /* DPMI major/minor 0.90 */
380 SET_SI( context, 0 ); /* # of para. of DOS extended private data */
381 context->SegEs = 0; /* no DPMI switch */
382 SET_DI( context, 0 ); /* ES:DI is DPMI switch entry point */
383 break;
385 case 0x8a: /* DPMI get vendor-specific API entry point. */
386 /* The 1.0 specs say this should work with all 0.9 hosts. */
387 break;
389 default:
390 INT_BARF( context, 0x2f );
394 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
395 * must be <size> aligned
396 * <size> could be WORD, DWORD...
397 * in this case, we would need two macros, one for read, the other one for write
398 * Note: PTR_AT can be used as an l-value
400 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
402 #define CDFRAMES_PERSEC 75
403 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
404 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
405 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
406 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
407 (toc).TrackData[idx - (toc).FirstTrack].Adr)
409 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
411 val[3] = 0; /* zero */
412 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
413 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
414 val[0] = frame % CDFRAMES_PERSEC; /* frames */
417 static BOOL is_cdrom(int drive)
419 char root[] = "A:\\";
420 root[0] += drive;
421 return (GetDriveTypeA(root) == DRIVE_CDROM);
424 /***********************************************************************
425 * CDROM_FillHeap
427 * Initialize CDROM heap.
430 static void CDROM_FillHeap( CDROM_HEAP *heap )
432 int drive, count;
434 /* Count the number of contiguous CDROM drives
436 for (drive = count = 0; drive < 26; drive++) {
437 if (is_cdrom(drive)) {
438 while (is_cdrom(drive + count)) count++;
439 break;
442 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
443 heap->hdr.drive = (drive < 26) ? drive : 0;
444 heap->hdr.units = count;
445 heap->hdr.reserved = 0;
448 /**********************************************************************
449 * CDROM_GetHeap
451 * Get pointer for CDROM heap (CDROM_HEAP).
452 * Creates and initializes heap on first call.
454 static CDROM_HEAP *CDROM_GetHeap( void )
456 static CDROM_HEAP *heap_pointer = NULL;
458 if ( !heap_pointer )
460 WORD heap_selector = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, sizeof(CDROM_HEAP) );
461 heap_pointer = GlobalLock16( heap_selector );
462 heap_pointer->cdrom_selector = heap_selector;
463 CDROM_FillHeap( heap_pointer );
466 return heap_pointer;
469 static void MSCDEX_Request(BYTE *driver_request)
471 BYTE* io_stru;
472 BYTE Error = 255; /* No Error */
473 char devName[] = "\\\\.\\@:";
474 HANDLE h;
475 CDROM_TOC toc;
476 CDROM_SUB_Q_DATA_FORMAT fmt;
477 SUB_Q_CHANNEL_DATA data;
478 DWORD br;
479 BOOL present = TRUE;
481 /* FIXME
482 * the following tests are wrong because lots of functions don't require the
483 * tray to be closed with a CD inside
485 TRACE("CDROM device driver -> command <%d>\n", driver_request[2]);
487 /* set status to 0 */
488 PTR_AT(driver_request, 3, WORD) = 0;
489 devName[4] = 'A' + CDROM_GetHeap()->hdr.drive + driver_request[1];
490 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
491 if (h == INVALID_HANDLE_VALUE) {
492 WARN("Couldn't open cdrom handle\n");
493 driver_request[4] |= 0x80;
494 driver_request[3] = 1; /* unknown unit */
495 return;
498 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
499 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
500 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
501 &data, sizeof(data), &br, NULL)) {
502 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
504 if (driver_request[2] != 6 && driver_request[2] != 15)
506 driver_request[4] |= 0x80;
507 driver_request[3] = 2; /* drive not ready */
508 CloseHandle(h);
509 return;
511 present = FALSE;
513 else
515 driver_request[4] |= 0x80;
516 driver_request[3] = 1; /* unknown unit */
517 CloseHandle(h);
518 return;
522 switch (driver_request[2]) {
523 case 3:
524 io_stru = MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
526 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
527 switch (io_stru[0]) {
528 #if 0
529 case 0: /* Get device Header */
531 static LPSTR ptr = 0;
532 if (ptr == 0) {
533 ptr = SEGPTR_ALLOC(22);
534 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
535 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
536 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
537 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
538 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
539 PTR_AT(ptr, 11, char) = 'I';
540 PTR_AT(ptr, 12, char) = 'N';
541 PTR_AT(ptr, 13, char) = 'E';
542 PTR_AT(ptr, 14, char) = '_';
543 PTR_AT(ptr, 15, char) = 'C';
544 PTR_AT(ptr, 16, char) = 'D';
545 PTR_AT(ptr, 17, char) = '_';
546 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
547 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
548 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
550 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
552 break;
553 #endif
555 case 1: /* location of head */
556 switch (io_stru[1]) {
557 case 0:
558 PTR_AT(io_stru, 2, DWORD) =
559 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
560 break;
561 case 1:
562 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
563 io_stru + 2);
564 break;
565 default:
566 ERR("CD-ROM driver: unsupported addressing mode !!\n");
567 Error = 0x0c;
569 TRACE(" ----> HEAD LOCATION <%d>\n", PTR_AT(io_stru, 2, DWORD));
570 break;
572 case 4: /* Audio channel info */
573 io_stru[1] = 0;
574 io_stru[2] = 0xff;
575 io_stru[3] = 1;
576 io_stru[4] = 0xff;
577 io_stru[5] = 2;
578 io_stru[6] = 0;
579 io_stru[7] = 3;
580 io_stru[8] = 0;
581 TRACE(" ----> AUDIO CHANNEL INFO\n");
582 break;
584 case 6: /* device status */
585 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
586 /* 290 =>
587 * 1 Supports HSG and Red Book addressing modes
588 * 0 Supports audio channel manipulation
590 * 1 Supports prefetching requests
591 * 0 Reserved
592 * 0 No interleaving
593 * 1 Data read and plays audio/video tracks
595 * 0 Read only
596 * 0 Supports only cooked reading
597 * 0 Door locked
598 * 0 see below (Door closed/opened)
600 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
601 TRACE(" ----> DEVICE STATUS <0x%08x>\n", PTR_AT(io_stru, 1, DWORD));
602 break;
604 case 8: /* Volume size */
605 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
606 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
607 TRACE(" ----> VOLUME SIZE <%d>\n", PTR_AT(io_stru, 1, DWORD));
608 break;
610 case 9: /* media changed ? */
611 /* answers don't know... -1/1 for yes/no would be better */
612 io_stru[1] = 0; /* FIXME? 1? */
613 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
614 break;
616 case 10: /* audio disk info */
617 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
618 io_stru[2] = toc.LastTrack; /* ending track */
619 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
620 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
622 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08x>\n",
623 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
624 break;
626 case 11: /* audio track info */
627 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
628 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
629 /* starting point if the track */
630 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
631 } else {
632 PTR_AT(io_stru, 2, DWORD) = 0;
633 io_stru[6] = 0;
635 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08x:%d]\n",
636 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
637 break;
639 case 12: /* get Q-Channel info */
640 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
641 io_stru[2] = data.CurrentPosition.TrackNumber;
642 io_stru[3] = 0; /* FIXME ?? */
644 /* why the heck did MS use another format for 0MSF information... sigh */
646 BYTE bTmp[4];
648 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
649 io_stru[ 4] = bTmp[2];
650 io_stru[ 5] = bTmp[1];
651 io_stru[ 6] = bTmp[0];
652 io_stru[ 7] = 0;
654 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
655 io_stru[ 8] = bTmp[2];
656 io_stru[ 9] = bTmp[1];
657 io_stru[10] = bTmp[0];
658 io_stru[11] = 0;
660 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
661 io_stru[ 1], io_stru[ 2], io_stru[ 3],
662 io_stru[ 4], io_stru[ 5], io_stru[ 6],
663 io_stru[ 8], io_stru[ 9], io_stru[10],
664 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
665 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
666 break;
668 case 15: /* Audio status info */
669 /* !!!! FIXME FIXME FIXME !! */
670 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
671 if (!present) {
672 PTR_AT(io_stru, 3, DWORD) = 0;
673 PTR_AT(io_stru, 7, DWORD) = 0;
674 } else {
675 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
676 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
678 TRACE("Audio status info: status=%04x startLoc=%d endLoc=%d\n",
679 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
680 break;
682 default:
683 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
684 Error = 0x0c;
685 break;
687 break;
689 case 12:
690 io_stru = MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
692 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
693 switch (io_stru[0]) {
694 case 0: /* eject */
695 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
696 TRACE(" ----> EJECT\n");
697 break;
698 case 2: /* reset drive */
699 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
700 TRACE(" ----> RESET\n");
701 break;
702 case 3: /* Audio Channel Control */
703 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
704 break;
705 case 5: /* close tray */
706 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
707 TRACE(" ----> CLOSE TRAY\n");
708 break;
709 default:
710 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
711 Error = 0x0c;
712 break;
714 break;
716 case 128: /* read long */
718 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
719 PTR_AT(driver_request, 14, WORD)));
720 DWORD at = PTR_AT(driver_request, 20, DWORD);
721 WORD num = PTR_AT(driver_request, 18, WORD);
722 RAW_READ_INFO rri;
724 switch (driver_request[13]) {
725 case 1: /* Red book addressing mode = 0:m:s:f */
726 /* FIXME : frame <=> msf conversion routines could be shared
727 * between mscdex and mcicda
729 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
730 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
731 LOBYTE(LOWORD(at));
732 /* fall through */
733 case 0: /* HSG addressing mode */
734 switch (PTR_AT(driver_request, 24, BYTE))
736 case 0: /* cooked */
737 ReadFile(h, dst, num * 2048, &br, NULL);
738 break;
739 case 1:
740 /* FIXME: computation is wrong */
741 rri.DiskOffset.u.HighPart = 0;
742 rri.DiskOffset.u.LowPart = at << 11;
743 rri.TrackMode = YellowMode2;
744 rri.SectorCount = num;
745 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
746 dst, num * 2352, &br, NULL);
747 break;
748 default:
749 ERR("Unsupported read mode !!\n");
750 Error = 0x0c;
751 break;
753 break;
754 default:
755 ERR("Unsupported address mode !!\n");
756 Error = 0x0c;
757 break;
760 break;
762 case 131: /* seek */
764 DWORD at;
765 CDROM_SEEK_AUDIO_MSF seek;
767 at = PTR_AT(driver_request, 20, DWORD);
769 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%d]\n", driver_request[13], at);
771 switch (driver_request[13]) {
772 case 1: /* Red book addressing mode = 0:m:s:f */
773 /* FIXME : frame <=> msf conversion routines could be shared
774 * between mscdex and mcicda
776 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
777 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
778 LOBYTE(LOWORD(at));
779 /* fall through */
780 case 0: /* HSG addressing mode */
781 seek.M = at / CDFRAMES_PERMIN;
782 seek.S = (at / CDFRAMES_PERSEC) % 60;
783 seek.F = at % CDFRAMES_PERSEC;
784 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
785 NULL, 0, &br, NULL);
786 break;
787 default:
788 ERR("Unsupported address mode !!\n");
789 Error = 0x0c;
790 break;
793 break;
795 case 132: /* play */
797 DWORD beg, end;
798 CDROM_PLAY_AUDIO_MSF play;
800 beg = end = PTR_AT(driver_request, 14, DWORD);
801 end += PTR_AT(driver_request, 18, DWORD);
803 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%d-%d]\n", driver_request[13], beg, end);
805 switch (driver_request[13]) {
806 case 1:
807 /* Red book addressing mode = 0:m:s:f */
808 /* FIXME : frame <=> msf conversion routines could be shared
809 * between mscdex and mcicda
811 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
812 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
813 LOBYTE(HIWORD(beg));
814 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
815 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
816 LOBYTE(HIWORD(end));
817 /* fall through */
818 case 0: /* HSG addressing mode */
819 play.StartingM = beg / CDFRAMES_PERMIN;
820 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
821 play.StartingF = beg % CDFRAMES_PERSEC;
822 play.EndingM = end / CDFRAMES_PERMIN;
823 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
824 play.EndingF = end % CDFRAMES_PERSEC;
825 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
826 NULL, 0, &br, NULL);
827 break;
828 default:
829 ERR("Unsupported address mode !!\n");
830 Error = 0x0c;
831 break;
834 break;
836 case 133:
837 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
838 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
839 TRACE(" --> STOP AUDIO (Paused)\n");
840 } else {
841 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
842 TRACE(" --> STOP AUDIO (Stopped)\n");
844 break;
846 case 136:
847 TRACE(" --> RESUME AUDIO\n");
848 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
849 break;
851 default:
852 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
853 Error = 0x0c;
856 /* setting error codes if any */
857 if (Error < 255) {
858 driver_request[4] |= 0x80;
859 driver_request[3] = Error;
862 CloseHandle(h);
863 /* setting status bits
864 * 3 == playing && done
865 * 1 == done
867 driver_request[4] |=
868 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
871 static void MSCDEX_Handler(CONTEXT* context)
873 int drive, count;
874 char* p;
876 switch (LOBYTE(context->Eax)) {
877 case 0x00: /* Installation check */
878 /* Count the number of contiguous CDROM drives
880 for (drive = count = 0; drive < 26; drive++) {
881 if (is_cdrom(drive)) {
882 while (is_cdrom(drive + count)) count++;
883 break;
886 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
887 SET_BX( context, count );
888 SET_CX( context, (drive < 26) ? drive : 0 );
889 break;
891 case 0x01: /* get drive device list */
893 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
894 CDROM_DEVICE_HEADER* dev = &cdrom_heap->hdr;
895 SEGPTR ptr_dev = MAKESEGPTR( cdrom_heap->cdrom_selector, FIELD_OFFSET(CDROM_HEAP, hdr) );
897 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
898 for (drive = 0; drive < dev->units; drive++) {
899 *p = drive; /* subunit */
900 ++p;
901 *(DWORD*)p = ptr_dev;
902 p += sizeof(DWORD);
904 TRACE("Get drive device list\n");
906 break;
908 case 0x0B: /* drive check */
909 SET_AX( context, is_cdrom(CX_reg(context)) );
910 SET_BX( context, 0xADAD );
911 break;
913 case 0x0C: /* get version */
914 SET_BX( context, 0x020a );
915 TRACE("Version number => %04x\n", BX_reg(context));
916 break;
918 case 0x0D: /* get drive letters */
919 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
920 memset(p, 0, 26);
921 for (drive = 0; drive < 26; drive++) {
922 if (is_cdrom(drive)) *p++ = drive;
924 TRACE("Get drive letters\n");
925 break;
927 case 0x10: /* direct driver access */
929 BYTE* driver_request;
930 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
932 if (!is_cdrom(CX_reg(context))) {
933 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
934 SET_CFLAG( context );
935 SET_AX( context, 0x000f ); /* invalid drive */
936 return;
939 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
941 if (!driver_request) {
942 /* FIXME - to be deleted ?? */
943 ERR("ES:BX==0 ! SEGFAULT ?\n");
944 ERR("-->BX=0x%04x, ES=0x%04x, DS=0x%04x, CX=0x%04x\n",
945 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
946 driver_request[4] |= 0x80;
947 driver_request[3] = 5; /* bad request length */
948 return;
951 driver_request[1] = CX_reg(context) - cdrom_heap->hdr.drive;
952 MSCDEX_Request(driver_request);
954 break;
955 default:
956 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
957 break;