msvcrt: Add scheduler_resource_allocation_error class implementation.
[wine.git] / dlls / krnl386.exe16 / int2f.c
blobf5b5aaa0e548990771b78ed1a8f4e0fb40d6518b
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 "config.h"
26 #include <string.h>
28 #include "ntstatus.h"
29 #define WIN32_NO_STATUS
30 #define NONAMELESSUNION
31 #include "wine/winbase16.h"
32 #include "wine/debug.h"
33 #include "winternl.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 KERNEL ordinal number for VxDs */
42 #define VXD_BASE 900
44 typedef struct
46 DOS_DEVICE_HEADER hdr;
48 WORD reserved; /* must be 0 */
49 BYTE drive; /* drive letter (0=A:, 1=B:, ...) */
50 BYTE units; /* number of supported units */
51 } CDROM_DEVICE_HEADER;
53 typedef struct
55 CDROM_DEVICE_HEADER hdr;
56 WINEDEV_THUNK thunk;
58 WORD cdrom_segment; /* Real mode segment for CDROM_HEAP */
59 WORD cdrom_selector; /* Protected mode selector for CDROM_HEAP */
60 } CDROM_HEAP;
62 static void do_int2f_16( CONTEXT *context );
63 static void MSCDEX_Handler( CONTEXT *context );
65 /**********************************************************************
66 * DOSVM_Int2fHandler
68 * Handler for int 2fh (multiplex).
70 void WINAPI DOSVM_Int2fHandler( CONTEXT *context )
72 TRACE("Subfunction 0x%X\n", AX_reg(context));
74 switch(AH_reg(context))
76 case 0x10:
77 SET_AL( context, 0xff ); /* share is installed */
78 break;
80 case 0x11: /* Network Redirector / IFSFUNC */
81 switch (LOBYTE(context->Eax))
83 case 0x00: /* Install check */
84 /* not installed */
85 break;
86 case 0x80: /* Enhanced services - Install check */
87 /* not installed */
88 break;
89 default:
90 INT_BARF( context, 0x2f );
91 break;
93 break;
95 case 0x12:
96 switch (LOBYTE(context->Eax))
98 case 0x2e: /* get or set DOS error table address */
99 switch (DL_reg(context))
101 /* Four tables: even commands are 'get', odd are 'set' */
102 /* DOS 5.0+ ignores "set" commands */
103 case 0x01:
104 case 0x03:
105 case 0x05:
106 case 0x07:
107 case 0x09:
108 break;
109 /* Instead of having a message table in DOS-space, */
110 /* we can use a special case for MS-DOS to force */
111 /* the secondary interface. */
112 case 0x00:
113 case 0x02:
114 case 0x04:
115 case 0x06:
116 context->SegEs = 0x0001;
117 SET_DI( context, 0x0000 );
118 break;
119 case 0x08:
120 FIXME("No real-mode handler for errors yet! (bye!)\n");
121 break;
122 default:
123 INT_BARF(context, 0x2f);
125 break;
126 default:
127 INT_BARF(context, 0x2f);
129 break;
131 case 0x15: /* mscdex */
132 MSCDEX_Handler(context);
133 break;
135 case 0x16:
136 do_int2f_16( context );
137 break;
139 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
140 /* Not supported yet, do nothing */
141 break;
143 case 0x43:
144 #if 1
145 switch (LOBYTE(context->Eax))
147 case 0x00: /* XMS v2+ installation check */
148 WARN("XMS is not fully implemented\n");
149 SET_AL( context, 0x80 );
150 break;
151 case 0x10: /* XMS v2+ get driver address */
153 context->SegEs = DOSVM_dpmi_segments->xms_seg;
154 SET_BX( context, 0 );
155 break;
157 default:
158 INT_BARF( context, 0x2f );
160 #else
161 FIXME("check for XMS (not supported)\n");
162 SET_AL( context, 0x42 ); /* != 0x80 */
163 #endif
164 break;
166 case 0x45:
167 switch (LOBYTE(context->Eax))
169 case 0x00:
170 case 0x01:
171 case 0x02:
172 case 0x03:
173 case 0x04:
174 case 0x05:
175 case 0x06:
176 case 0x07:
177 case 0x08:
178 /* Microsoft Profiler - not installed */
179 break;
180 default:
181 INT_BARF( context, 0x2f );
183 break;
185 case 0x4a:
186 switch(LOBYTE(context->Eax))
188 case 0x10: /* smartdrv */
189 break; /* not installed */
190 case 0x11: /* dblspace */
191 break; /* not installed */
192 case 0x12: /* realtime compression interface */
193 break; /* not installed */
194 case 0x32: /* patch IO.SYS (???) */
195 break; /* we have no IO.SYS, so we can't patch it :-/ */
196 default:
197 INT_BARF( context, 0x2f );
199 break;
200 case 0x4b:
201 switch(LOBYTE(context->Eax))
203 case 0x01:
204 case 0x02:
205 case 0x03:
206 case 0x04:
207 case 0x05:
208 FIXME("Task Switcher - not implemented\n");
209 break;
210 default:
211 INT_BARF( context, 0x2f );
213 break;
214 case 0x56: /* INTERLNK */
215 switch(LOBYTE(context->Eax))
217 case 0x01: /* check if redirected drive */
218 SET_AL( context, 0 ); /* not redirected */
219 break;
220 default:
221 INT_BARF( context, 0x2f );
223 break;
224 case 0x7a: /* NOVELL NetWare */
225 switch (LOBYTE(context->Eax))
227 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
228 SET_AL( context, 0 );
229 break;
230 case 0x20: /* Get VLM Call Address */
231 /* return nothing -> NetWare not installed */
232 break;
233 default:
234 INT_BARF( context, 0x2f );
235 break;
237 break;
238 case 0xb7: /* append */
239 SET_AL( context, 0 ); /* not installed */
240 break;
241 case 0xb8: /* network */
242 switch (LOBYTE(context->Eax))
244 case 0x00: /* Install check */
245 /* not installed */
246 break;
247 default:
248 INT_BARF( context, 0x2f );
249 break;
251 break;
252 case 0xbc:
253 if (AL_reg(context) == 0x00 && BX_reg(context) == 0x3f3f) {
254 /* MVSOUND.SYS - Install check: not installed */
255 } else {
256 INT_BARF( context, 0x2f );
258 break;
259 case 0xbd: /* some Novell network install check ??? */
260 SET_AX( context, 0xa5a5 ); /* pretend to have Novell IPX installed */
261 break;
262 case 0xbf: /* REDIRIFS.EXE */
263 switch (LOBYTE(context->Eax))
265 case 0x00: /* Install check */
266 /* not installed */
267 break;
268 default:
269 INT_BARF( context, 0x2f );
270 break;
272 break;
273 case 0xd2:
274 switch(LOBYTE(context->Eax))
276 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
277 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
278 && DX_reg(context) == 0x3432)
279 TRACE("Check for QEMM v5.0+ (not installed)\n");
280 break;
281 default:
282 INT_BARF( context, 0x2f );
283 break;
285 break;
286 case 0xd7: /* Banyan Vines */
287 switch (LOBYTE(context->Eax))
289 case 0x01: /* Install check - Get Int Number */
290 /* not installed */
291 break;
292 default:
293 INT_BARF( context, 0x2f );
294 break;
296 break;
297 case 0xde:
298 switch(LOBYTE(context->Eax))
300 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
301 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
302 && DX_reg(context) == 0x8f4f)
303 TRACE("Check for QDPMI.SYS (not installed)\n");
304 break;
305 default:
306 INT_BARF( context, 0x2f );
307 break;
309 break;
310 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
311 break;
312 default:
313 INT_BARF( context, 0x2f );
314 break;
319 /**********************************************************************
320 * do_int2f_16
322 static void do_int2f_16( CONTEXT *context )
324 DWORD addr;
326 switch(LOBYTE(context->Eax))
328 case 0x00: /* Windows enhanced mode installation check */
329 SET_AX( context, LOWORD(GetVersion16()) );
330 break;
332 case 0x0a: /* Get Windows version and type */
333 SET_AX( context, 0 );
334 SET_BX( context, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
335 SET_CX( context, 3 );
336 break;
338 case 0x0b: /* Identify Windows-aware TSRs */
339 /* we don't have any pre-Windows TSRs */
340 break;
342 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
343 /* We can mock this up. But not today... */
344 FIXME("Get Shell Parameters\n");
345 break;
347 case 0x80: /* Release time-slice */
348 /* Linux sched_yield() still keeps burning CPU cycles
349 * if the current process is the only one in highest priority list
350 * (as Linux will immediately return to this process to waste
351 * more CPU cycles), so sched_yield() is essentially useless for us
352 * (poor API, if you ask me: its return code should indicate
353 * whether other processes did run in between, in order for us
354 * to be able to decide whether to do an additional Sleep() or not...)
355 * Thus we better unconditionally use a well-balanced Sleep()
356 * instead to really make sure the process calling int 0x2f/0x1680
357 * *doesn't* use 100% CPU...
359 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
360 SET_AL( context, 0 );
361 break;
363 case 0x81: /* Begin critical section. */
364 /* FIXME? */
365 break;
367 case 0x82: /* End critical section. */
368 /* FIXME? */
369 break;
371 case 0x83: /* Return Current Virtual Machine ID */
372 /* Virtual Machines are usually created/destroyed when Windows runs
373 * DOS programs. Since we never do, we are always in the System VM.
374 * According to Ralf Brown's Interrupt List, never return 0. But it
375 * seems to work okay (returning 0), just to be sure we return 1.
377 SET_BX( context, 1 ); /* VM 1 is probably the System VM */
378 break;
380 case 0x84: /* Get device API entry point */
382 HMODULE16 mod = GetModuleHandle16("kernel");
383 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
384 if (!addr) /* not supported */
385 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
386 context->SegEs = SELECTOROF(addr);
387 SET_DI( context, OFFSETOF(addr) );
389 break;
391 case 0x86: /* DPMI detect mode */
392 SET_AX( context, 0 ); /* Running under DPMI */
393 break;
395 case 0x87: /* DPMI installation check */
397 SYSTEM_INFO si;
398 GetSystemInfo(&si);
399 SET_AX( context, 0x0000 ); /* DPMI Installed */
400 SET_BX( context, 0x0001 ); /* 32bits available */
401 SET_CL( context, si.wProcessorLevel );
402 SET_DX( context, 0x005a ); /* DPMI major/minor 0.90 */
403 SET_SI( context, 0 ); /* # of para. of DOS extended private data */
404 context->SegEs = DOSVM_dpmi_segments->dpmi_seg;
405 SET_DI( context, 0 ); /* ES:DI is DPMI switch entry point */
406 break;
408 case 0x8a: /* DPMI get vendor-specific API entry point. */
409 /* The 1.0 specs say this should work with all 0.9 hosts. */
410 break;
412 default:
413 INT_BARF( context, 0x2f );
417 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
418 * must be <size> aligned
419 * <size> could be WORD, DWORD...
420 * in this case, we would need two macros, one for read, the other one for write
421 * Note: PTR_AT can be used as an l-value
423 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
425 /* Use #if 1 if you want full int 2f debug... normal users can leave it at 0 */
426 #if 0
427 /**********************************************************************
428 * MSCDEX_Dump [internal]
430 * Dumps mscdex requests to int debug channel.
432 static void MSCDEX_Dump(char* pfx, BYTE* req, int dorealmode)
434 int i;
435 BYTE buf[2048];
436 BYTE* ptr;
437 BYTE* ios;
439 ptr = buf;
440 ptr += sprintf(ptr, "%s\tCommand => ", pfx);
441 for (i = 0; i < req[0]; i++) {
442 ptr += sprintf(ptr, "%02x ", req[i]);
445 switch (req[2]) {
446 case 3:
447 case 12:
448 ptr += sprintf(ptr, "\n\t\t\t\tIO_struct => ");
449 ios = (dorealmode) ? PTR_REAL_TO_LIN( PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)) :
450 MapSL(MAKESEGPTR(PTR_AT(req, 16, WORD), PTR_AT(req, 14, WORD)));
452 for (i = 0; i < PTR_AT(req, 18, WORD); i++) {
453 ptr += sprintf(ptr, "%02x ", ios[i]);
454 if ((i & 0x1F) == 0x1F) {
455 *ptr++ = '\n';
456 *ptr = 0;
459 break;
461 TRACE("%s\n", buf);
463 #else
464 #define MSCDEX_Dump(pfx, req, drm)
465 #endif
467 #define CDFRAMES_PERSEC 75
468 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
469 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
470 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
471 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
472 (toc).TrackData[idx - (toc).FirstTrack].Adr)
474 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
476 val[3] = 0; /* zero */
477 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
478 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
479 val[0] = frame % CDFRAMES_PERSEC; /* frames */
482 static BOOL is_cdrom(int drive)
484 char root[] = "A:\\";
485 root[0] += drive;
486 return (GetDriveTypeA(root) == DRIVE_CDROM);
489 /***********************************************************************
490 * CDROM_FillHeap
492 * Initialize CDROM heap.
495 static void CDROM_FillHeap( CDROM_HEAP *heap )
497 int drive, count;
499 /* Count the number of contiguous CDROM drives
501 for (drive = count = 0; drive < 26; drive++) {
502 if (is_cdrom(drive)) {
503 while (is_cdrom(drive + count)) count++;
504 break;
507 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
508 heap->hdr.drive = (drive < 26) ? drive : 0;
509 heap->hdr.units = count;
510 heap->hdr.reserved = 0;
513 /**********************************************************************
514 * CDROM_GetHeap
516 * Get pointer for CDROM heap (CDROM_HEAP).
517 * Creates and initializes heap on first call.
519 static CDROM_HEAP *CDROM_GetHeap( void )
521 static CDROM_HEAP *heap_pointer = NULL;
523 if ( !heap_pointer )
525 WORD heap_segment;
526 WORD heap_selector;
528 /* allocate a new DOS data segment */
529 heap_pointer = DOSVM_AllocDataUMB( sizeof(CDROM_HEAP),
530 &heap_segment,
531 &heap_selector );
533 heap_pointer->cdrom_segment = heap_segment;
534 heap_pointer->cdrom_selector = heap_selector;
535 CDROM_FillHeap( heap_pointer );
538 return heap_pointer;
541 static void MSCDEX_Request(BYTE *driver_request, BOOL dorealmode)
543 BYTE* io_stru;
544 BYTE Error = 255; /* No Error */
545 char devName[] = "\\\\.\\@:";
546 HANDLE h;
547 CDROM_TOC toc;
548 CDROM_SUB_Q_DATA_FORMAT fmt;
549 SUB_Q_CHANNEL_DATA data;
550 DWORD br;
551 BOOL present = TRUE;
553 /* FIXME
554 * the following tests are wrong because lots of functions don't require the
555 * tray to be closed with a CD inside
557 TRACE("CDROM device driver -> command <%d>\n", driver_request[2]);
559 MSCDEX_Dump("Beg", driver_request, dorealmode);
561 /* set status to 0 */
562 PTR_AT(driver_request, 3, WORD) = 0;
563 devName[4] = 'A' + CDROM_GetHeap()->hdr.drive + driver_request[1];
564 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
565 if (h == INVALID_HANDLE_VALUE) {
566 WARN("Couldn't open cdrom handle\n");
567 driver_request[4] |= 0x80;
568 driver_request[3] = 1; /* unknown unit */
569 return;
572 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
573 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
574 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
575 &data, sizeof(data), &br, NULL)) {
576 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
578 if (driver_request[2] != 6 && driver_request[2] != 15)
580 driver_request[4] |= 0x80;
581 driver_request[3] = 2; /* drive not ready */
582 CloseHandle(h);
583 return;
585 present = FALSE;
587 else
589 driver_request[4] |= 0x80;
590 driver_request[3] = 1; /* unknown unit */
591 CloseHandle(h);
592 return;
596 switch (driver_request[2]) {
597 case 3:
598 io_stru = (dorealmode) ?
599 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD) ) :
600 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
602 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
603 switch (io_stru[0]) {
604 #if 0
605 case 0: /* Get device Header */
607 static LPSTR ptr = 0;
608 if (ptr == 0) {
609 ptr = SEGPTR_ALLOC(22);
610 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
611 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
612 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
613 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
614 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
615 PTR_AT(ptr, 11, char) = 'I';
616 PTR_AT(ptr, 12, char) = 'N';
617 PTR_AT(ptr, 13, char) = 'E';
618 PTR_AT(ptr, 14, char) = '_';
619 PTR_AT(ptr, 15, char) = 'C';
620 PTR_AT(ptr, 16, char) = 'D';
621 PTR_AT(ptr, 17, char) = '_';
622 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
623 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
624 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
626 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
628 break;
629 #endif
631 case 1: /* location of head */
632 switch (io_stru[1]) {
633 case 0:
634 PTR_AT(io_stru, 2, DWORD) =
635 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
636 break;
637 case 1:
638 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
639 io_stru + 2);
640 break;
641 default:
642 ERR("CD-ROM driver: unsupported addressing mode !!\n");
643 Error = 0x0c;
645 TRACE(" ----> HEAD LOCATION <%d>\n", PTR_AT(io_stru, 2, DWORD));
646 break;
648 case 4: /* Audio channel info */
649 io_stru[1] = 0;
650 io_stru[2] = 0xff;
651 io_stru[3] = 1;
652 io_stru[4] = 0xff;
653 io_stru[5] = 2;
654 io_stru[6] = 0;
655 io_stru[7] = 3;
656 io_stru[8] = 0;
657 TRACE(" ----> AUDIO CHANNEL INFO\n");
658 break;
660 case 6: /* device status */
661 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
662 /* 290 =>
663 * 1 Supports HSG and Red Book addressing modes
664 * 0 Supports audio channel manipulation
666 * 1 Supports prefetching requests
667 * 0 Reserved
668 * 0 No interleaving
669 * 1 Data read and plays audio/video tracks
671 * 0 Read only
672 * 0 Supports only cooked reading
673 * 0 Door locked
674 * 0 see below (Door closed/opened)
676 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
677 TRACE(" ----> DEVICE STATUS <0x%08x>\n", PTR_AT(io_stru, 1, DWORD));
678 break;
680 case 8: /* Volume size */
681 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
682 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
683 TRACE(" ----> VOLUME SIZE <%d>\n", PTR_AT(io_stru, 1, DWORD));
684 break;
686 case 9: /* media changed ? */
687 /* answers don't know... -1/1 for yes/no would be better */
688 io_stru[1] = 0; /* FIXME? 1? */
689 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
690 break;
692 case 10: /* audio disk info */
693 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
694 io_stru[2] = toc.LastTrack; /* ending track */
695 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
696 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
698 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08x>\n",
699 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
700 break;
702 case 11: /* audio track info */
703 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
704 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
705 /* starting point if the track */
706 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
707 } else {
708 PTR_AT(io_stru, 2, DWORD) = 0;
709 io_stru[6] = 0;
711 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08x:%d]\n",
712 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
713 break;
715 case 12: /* get Q-Channel info */
716 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
717 io_stru[2] = data.CurrentPosition.TrackNumber;
718 io_stru[3] = 0; /* FIXME ?? */
720 /* why the heck did MS use another format for 0MSF information... sigh */
722 BYTE bTmp[4];
724 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
725 io_stru[ 4] = bTmp[2];
726 io_stru[ 5] = bTmp[1];
727 io_stru[ 6] = bTmp[0];
728 io_stru[ 7] = 0;
730 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
731 io_stru[ 8] = bTmp[2];
732 io_stru[ 9] = bTmp[1];
733 io_stru[10] = bTmp[0];
734 io_stru[11] = 0;
736 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
737 io_stru[ 1], io_stru[ 2], io_stru[ 3],
738 io_stru[ 4], io_stru[ 5], io_stru[ 6],
739 io_stru[ 8], io_stru[ 9], io_stru[10],
740 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
741 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
742 break;
744 case 15: /* Audio status info */
745 /* !!!! FIXME FIXME FIXME !! */
746 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
747 if (!present) {
748 PTR_AT(io_stru, 3, DWORD) = 0;
749 PTR_AT(io_stru, 7, DWORD) = 0;
750 } else {
751 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
752 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
754 TRACE("Audio status info: status=%04x startLoc=%d endLoc=%d\n",
755 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
756 break;
758 default:
759 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
760 Error = 0x0c;
761 break;
763 break;
765 case 12:
766 io_stru = (dorealmode) ?
767 PTR_REAL_TO_LIN( PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)) :
768 MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
770 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
771 switch (io_stru[0]) {
772 case 0: /* eject */
773 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
774 TRACE(" ----> EJECT\n");
775 break;
776 case 2: /* reset drive */
777 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
778 TRACE(" ----> RESET\n");
779 break;
780 case 3: /* Audio Channel Control */
781 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
782 break;
783 case 5: /* close tray */
784 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
785 TRACE(" ----> CLOSE TRAY\n");
786 break;
787 default:
788 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
789 Error = 0x0c;
790 break;
792 break;
794 case 128: /* read long */
796 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
797 PTR_AT(driver_request, 14, WORD)));
798 DWORD at = PTR_AT(driver_request, 20, DWORD);
799 WORD num = PTR_AT(driver_request, 18, WORD);
800 RAW_READ_INFO rri;
802 switch (driver_request[13]) {
803 case 1: /* Red book addressing mode = 0:m:s:f */
804 /* FIXME : frame <=> msf conversion routines could be shared
805 * between mscdex and mcicda
807 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
808 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
809 LOBYTE(LOWORD(at));
810 /* fall through */
811 case 0: /* HSG addressing mode */
812 switch (PTR_AT(driver_request, 24, BYTE))
814 case 0: /* cooked */
815 ReadFile(h, dst, num * 2048, &br, NULL);
816 break;
817 case 1:
818 /* FIXME: computation is wrong */
819 rri.DiskOffset.u.HighPart = 0;
820 rri.DiskOffset.u.LowPart = at << 11;
821 rri.TrackMode = YellowMode2;
822 rri.SectorCount = num;
823 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
824 dst, num * 2352, &br, NULL);
825 break;
826 default:
827 ERR("Unsupported read mode !!\n");
828 Error = 0x0c;
829 break;
831 break;
832 default:
833 ERR("Unsupported address mode !!\n");
834 Error = 0x0c;
835 break;
838 break;
840 case 131: /* seek */
842 DWORD at;
843 CDROM_SEEK_AUDIO_MSF seek;
845 at = PTR_AT(driver_request, 20, DWORD);
847 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%d]\n", driver_request[13], at);
849 switch (driver_request[13]) {
850 case 1: /* Red book addressing mode = 0:m:s:f */
851 /* FIXME : frame <=> msf conversion routines could be shared
852 * between mscdex and mcicda
854 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
855 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
856 LOBYTE(LOWORD(at));
857 /* fall through */
858 case 0: /* HSG addressing mode */
859 seek.M = at / CDFRAMES_PERMIN;
860 seek.S = (at / CDFRAMES_PERSEC) % 60;
861 seek.F = at % CDFRAMES_PERSEC;
862 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
863 NULL, 0, &br, NULL);
864 break;
865 default:
866 ERR("Unsupported address mode !!\n");
867 Error = 0x0c;
868 break;
871 break;
873 case 132: /* play */
875 DWORD beg, end;
876 CDROM_PLAY_AUDIO_MSF play;
878 beg = end = PTR_AT(driver_request, 14, DWORD);
879 end += PTR_AT(driver_request, 18, DWORD);
881 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%d-%d]\n", driver_request[13], beg, end);
883 switch (driver_request[13]) {
884 case 1:
885 /* Red book addressing mode = 0:m:s:f */
886 /* FIXME : frame <=> msf conversion routines could be shared
887 * between mscdex and mcicda
889 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
890 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
891 LOBYTE(HIWORD(beg));
892 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
893 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
894 LOBYTE(HIWORD(end));
895 /* fall through */
896 case 0: /* HSG addressing mode */
897 play.StartingM = beg / CDFRAMES_PERMIN;
898 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
899 play.StartingF = beg % CDFRAMES_PERSEC;
900 play.EndingM = end / CDFRAMES_PERMIN;
901 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
902 play.EndingF = end % CDFRAMES_PERSEC;
903 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
904 NULL, 0, &br, NULL);
905 break;
906 default:
907 ERR("Unsupported address mode !!\n");
908 Error = 0x0c;
909 break;
912 break;
914 case 133:
915 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
916 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
917 TRACE(" --> STOP AUDIO (Paused)\n");
918 } else {
919 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
920 TRACE(" --> STOP AUDIO (Stopped)\n");
922 break;
924 case 136:
925 TRACE(" --> RESUME AUDIO\n");
926 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
927 break;
929 default:
930 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
931 Error = 0x0c;
934 /* setting error codes if any */
935 if (Error < 255) {
936 driver_request[4] |= 0x80;
937 driver_request[3] = Error;
940 CloseHandle(h);
941 /* setting status bits
942 * 3 == playing && done
943 * 1 == done
945 driver_request[4] |=
946 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
948 MSCDEX_Dump("End", driver_request, dorealmode);
951 static void MSCDEX_Handler(CONTEXT* context)
953 int drive, count;
954 char* p;
956 switch (LOBYTE(context->Eax)) {
957 case 0x00: /* Installation check */
958 /* Count the number of contiguous CDROM drives
960 for (drive = count = 0; drive < 26; drive++) {
961 if (is_cdrom(drive)) {
962 while (is_cdrom(drive + count)) count++;
963 break;
966 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
967 SET_BX( context, count );
968 SET_CX( context, (drive < 26) ? drive : 0 );
969 break;
971 case 0x01: /* get drive device list */
973 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
974 CDROM_DEVICE_HEADER* dev = &cdrom_heap->hdr;
975 SEGPTR ptr_dev = ISV86(context)
976 ? MAKESEGPTR( cdrom_heap->cdrom_segment,
977 FIELD_OFFSET(CDROM_HEAP, hdr) )
978 : MAKESEGPTR( cdrom_heap->cdrom_selector,
979 FIELD_OFFSET(CDROM_HEAP, hdr) );
981 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
982 for (drive = 0; drive < dev->units; drive++) {
983 *p = drive; /* subunit */
984 ++p;
985 *(DWORD*)p = ptr_dev;
986 p += sizeof(DWORD);
988 TRACE("Get drive device list\n");
990 break;
992 case 0x0B: /* drive check */
993 SET_AX( context, is_cdrom(CX_reg(context)) );
994 SET_BX( context, 0xADAD );
995 break;
997 case 0x0C: /* get version */
998 SET_BX( context, 0x020a );
999 TRACE("Version number => %04x\n", BX_reg(context));
1000 break;
1002 case 0x0D: /* get drive letters */
1003 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
1004 memset(p, 0, 26);
1005 for (drive = 0; drive < 26; drive++) {
1006 if (is_cdrom(drive)) *p++ = drive;
1008 TRACE("Get drive letters\n");
1009 break;
1011 case 0x10: /* direct driver access */
1013 BYTE* driver_request;
1014 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
1016 if (!is_cdrom(CX_reg(context))) {
1017 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
1018 SET_CFLAG( context );
1019 SET_AX( context, 0x000f ); /* invalid drive */
1020 return;
1023 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
1025 if (!driver_request) {
1026 /* FIXME - to be deleted ?? */
1027 ERR("ES:BX==0 ! SEGFAULT ?\n");
1028 ERR("-->BX=0x%04x, ES=0x%04x, DS=0x%04x, CX=0x%04x\n",
1029 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
1030 driver_request[4] |= 0x80;
1031 driver_request[3] = 5; /* bad request length */
1032 return;
1035 driver_request[1] = CX_reg(context) - cdrom_heap->hdr.drive;
1036 MSCDEX_Request(driver_request, ISV86(context));
1038 break;
1039 default:
1040 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
1041 break;
1045 /* prototypes */
1046 static void WINAPI cdrom_strategy(CONTEXT*ctx);
1047 static void WINAPI cdrom_interrupt(CONTEXT*ctx);
1049 /* device info */
1050 static const WINEDEV cdromdev =
1052 "WINE_CD_",
1053 ATTR_CHAR|ATTR_REMOVABLE|ATTR_IOCTL,
1054 cdrom_strategy, cdrom_interrupt
1057 static REQUEST_HEADER *cdrom_driver_request;
1059 /* Return to caller */
1060 static void do_lret(CONTEXT*ctx)
1062 WORD *stack = CTX_SEG_OFF_TO_LIN(ctx, ctx->SegSs, ctx->Esp);
1064 ctx->Eip = *(stack++);
1065 ctx->SegCs = *(stack++);
1066 ctx->Esp += 2*sizeof(WORD);
1069 static void WINAPI cdrom_strategy(CONTEXT*ctx)
1071 cdrom_driver_request = CTX_SEG_OFF_TO_LIN(ctx, ctx->SegEs, ctx->Ebx);
1072 do_lret( ctx );
1075 static void WINAPI cdrom_interrupt(CONTEXT*ctx)
1077 if (cdrom_driver_request->unit > CDROM_GetHeap()->hdr.units)
1078 cdrom_driver_request->status = STAT_ERROR | 1; /* unknown unit */
1079 else
1080 MSCDEX_Request((BYTE*)cdrom_driver_request, ISV86(ctx));
1082 do_lret( ctx );
1085 /**********************************************************************
1086 * MSCDEX_InstallCDROM [internal]
1088 * Install the CDROM driver into the DOS device driver chain.
1090 void MSCDEX_InstallCDROM(void)
1092 CDROM_HEAP *cdrom_heap = CDROM_GetHeap();
1094 DOSDEV_SetupDevice( &cdromdev,
1095 cdrom_heap->cdrom_segment,
1096 FIELD_OFFSET(CDROM_HEAP, hdr),
1097 FIELD_OFFSET(CDROM_HEAP, thunk) );