krnl386.exe16: Make a couple of functions static.
[wine.git] / dlls / krnl386.exe16 / int2f.c
blob92055b06f42a17df4d715b32abefd1dbcb20c96b
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 WORD cdrom_selector; /* Protected mode selector for CDROM_HEAP */
57 } CDROM_HEAP;
59 static void do_int2f_16( CONTEXT *context );
60 static void MSCDEX_Handler( CONTEXT *context );
62 /**********************************************************************
63 * DOSVM_Int2fHandler
65 * Handler for int 2fh (multiplex).
67 void WINAPI DOSVM_Int2fHandler( CONTEXT *context )
69 TRACE("Subfunction 0x%X\n", AX_reg(context));
71 switch(AH_reg(context))
73 case 0x10:
74 SET_AL( context, 0xff ); /* share is installed */
75 break;
77 case 0x11: /* Network Redirector / IFSFUNC */
78 switch (LOBYTE(context->Eax))
80 case 0x00: /* Install check */
81 /* not installed */
82 break;
83 case 0x80: /* Enhanced services - Install check */
84 /* not installed */
85 break;
86 default:
87 INT_BARF( context, 0x2f );
88 break;
90 break;
92 case 0x12:
93 switch (LOBYTE(context->Eax))
95 case 0x2e: /* get or set DOS error table address */
96 switch (DL_reg(context))
98 /* Four tables: even commands are 'get', odd are 'set' */
99 /* DOS 5.0+ ignores "set" commands */
100 case 0x01:
101 case 0x03:
102 case 0x05:
103 case 0x07:
104 case 0x09:
105 break;
106 /* Instead of having a message table in DOS-space, */
107 /* we can use a special case for MS-DOS to force */
108 /* the secondary interface. */
109 case 0x00:
110 case 0x02:
111 case 0x04:
112 case 0x06:
113 context->SegEs = 0x0001;
114 SET_DI( context, 0x0000 );
115 break;
116 case 0x08:
117 FIXME("No real-mode handler for errors yet! (bye!)\n");
118 break;
119 default:
120 INT_BARF(context, 0x2f);
122 break;
123 default:
124 INT_BARF(context, 0x2f);
126 break;
128 case 0x15: /* mscdex */
129 MSCDEX_Handler(context);
130 break;
132 case 0x16:
133 do_int2f_16( context );
134 break;
136 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
137 /* Not supported yet, do nothing */
138 break;
140 case 0x43:
141 FIXME("check for XMS (not supported)\n");
142 SET_AL( context, 0x42 ); /* != 0x80 */
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 0xbc:
232 if (AL_reg(context) == 0x00 && BX_reg(context) == 0x3f3f) {
233 /* MVSOUND.SYS - Install check: not installed */
234 } else {
235 INT_BARF( context, 0x2f );
237 break;
238 case 0xbd: /* some Novell network install check ??? */
239 SET_AX( context, 0xa5a5 ); /* pretend to have Novell IPX installed */
240 break;
241 case 0xbf: /* REDIRIFS.EXE */
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 0xd2:
253 switch(LOBYTE(context->Eax))
255 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
256 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
257 && DX_reg(context) == 0x3432)
258 TRACE("Check for QEMM v5.0+ (not installed)\n");
259 break;
260 default:
261 INT_BARF( context, 0x2f );
262 break;
264 break;
265 case 0xd7: /* Banyan Vines */
266 switch (LOBYTE(context->Eax))
268 case 0x01: /* Install check - Get Int Number */
269 /* not installed */
270 break;
271 default:
272 INT_BARF( context, 0x2f );
273 break;
275 break;
276 case 0xde:
277 switch(LOBYTE(context->Eax))
279 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
280 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
281 && DX_reg(context) == 0x8f4f)
282 TRACE("Check for QDPMI.SYS (not installed)\n");
283 break;
284 default:
285 INT_BARF( context, 0x2f );
286 break;
288 break;
289 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
290 break;
291 default:
292 INT_BARF( context, 0x2f );
293 break;
298 /**********************************************************************
299 * do_int2f_16
301 static void do_int2f_16( CONTEXT *context )
303 DWORD addr;
305 switch(LOBYTE(context->Eax))
307 case 0x00: /* Windows enhanced mode installation check */
308 SET_AX( context, LOWORD(GetVersion16()) );
309 break;
311 case 0x0a: /* Get Windows version and type */
312 SET_AX( context, 0 );
313 SET_BX( context, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
314 SET_CX( context, 3 );
315 break;
317 case 0x0b: /* Identify Windows-aware TSRs */
318 /* we don't have any pre-Windows TSRs */
319 break;
321 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
322 /* We can mock this up. But not today... */
323 FIXME("Get Shell Parameters\n");
324 break;
326 case 0x80: /* Release time-slice */
327 /* Linux sched_yield() still keeps burning CPU cycles
328 * if the current process is the only one in highest priority list
329 * (as Linux will immediately return to this process to waste
330 * more CPU cycles), so sched_yield() is essentially useless for us
331 * (poor API, if you ask me: its return code should indicate
332 * whether other processes did run in between, in order for us
333 * to be able to decide whether to do an additional Sleep() or not...)
334 * Thus we better unconditionally use a well-balanced Sleep()
335 * instead to really make sure the process calling int 0x2f/0x1680
336 * *doesn't* use 100% CPU...
338 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
339 SET_AL( context, 0 );
340 break;
342 case 0x81: /* Begin critical section. */
343 /* FIXME? */
344 break;
346 case 0x82: /* End critical section. */
347 /* FIXME? */
348 break;
350 case 0x83: /* Return Current Virtual Machine ID */
351 /* Virtual Machines are usually created/destroyed when Windows runs
352 * DOS programs. Since we never do, we are always in the System VM.
353 * According to Ralf Brown's Interrupt List, never return 0. But it
354 * seems to work okay (returning 0), just to be sure we return 1.
356 SET_BX( context, 1 ); /* VM 1 is probably the System VM */
357 break;
359 case 0x84: /* Get device API entry point */
361 HMODULE16 mod = GetModuleHandle16("kernel");
362 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
363 if (!addr) /* not supported */
364 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
365 context->SegEs = SELECTOROF(addr);
366 SET_DI( context, OFFSETOF(addr) );
368 break;
370 case 0x86: /* DPMI detect mode */
371 SET_AX( context, 0 ); /* Running under DPMI */
372 break;
374 case 0x87: /* DPMI installation check */
376 SYSTEM_INFO si;
377 GetSystemInfo(&si);
378 SET_AX( context, 0x0000 ); /* DPMI Installed */
379 SET_BX( context, 0x0001 ); /* 32bits available */
380 SET_CL( context, si.wProcessorLevel );
381 SET_DX( context, 0x005a ); /* DPMI major/minor 0.90 */
382 SET_SI( context, 0 ); /* # of para. of DOS extended private data */
383 context->SegEs = 0; /* no DPMI switch */
384 SET_DI( context, 0 ); /* ES:DI is DPMI switch entry point */
385 break;
387 case 0x8a: /* DPMI get vendor-specific API entry point. */
388 /* The 1.0 specs say this should work with all 0.9 hosts. */
389 break;
391 default:
392 INT_BARF( context, 0x2f );
396 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
397 * must be <size> aligned
398 * <size> could be WORD, DWORD...
399 * in this case, we would need two macros, one for read, the other one for write
400 * Note: PTR_AT can be used as an l-value
402 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
404 #define CDFRAMES_PERSEC 75
405 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
406 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
407 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
408 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
409 (toc).TrackData[idx - (toc).FirstTrack].Adr)
411 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
413 val[3] = 0; /* zero */
414 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
415 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
416 val[0] = frame % CDFRAMES_PERSEC; /* frames */
419 static BOOL is_cdrom(int drive)
421 char root[] = "A:\\";
422 root[0] += drive;
423 return (GetDriveTypeA(root) == DRIVE_CDROM);
426 /***********************************************************************
427 * CDROM_FillHeap
429 * Initialize CDROM heap.
432 static void CDROM_FillHeap( CDROM_HEAP *heap )
434 int drive, count;
436 /* Count the number of contiguous CDROM drives
438 for (drive = count = 0; drive < 26; drive++) {
439 if (is_cdrom(drive)) {
440 while (is_cdrom(drive + count)) count++;
441 break;
444 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
445 heap->hdr.drive = (drive < 26) ? drive : 0;
446 heap->hdr.units = count;
447 heap->hdr.reserved = 0;
450 /**********************************************************************
451 * CDROM_GetHeap
453 * Get pointer for CDROM heap (CDROM_HEAP).
454 * Creates and initializes heap on first call.
456 static CDROM_HEAP *CDROM_GetHeap( void )
458 static CDROM_HEAP *heap_pointer = NULL;
460 if ( !heap_pointer )
462 WORD heap_selector;
464 /* allocate a new DOS data segment */
465 heap_pointer = DOSVM_AllocDataUMB( sizeof(CDROM_HEAP), &heap_selector );
466 heap_pointer->cdrom_selector = heap_selector;
467 CDROM_FillHeap( heap_pointer );
470 return heap_pointer;
473 static void MSCDEX_Request(BYTE *driver_request)
475 BYTE* io_stru;
476 BYTE Error = 255; /* No Error */
477 char devName[] = "\\\\.\\@:";
478 HANDLE h;
479 CDROM_TOC toc;
480 CDROM_SUB_Q_DATA_FORMAT fmt;
481 SUB_Q_CHANNEL_DATA data;
482 DWORD br;
483 BOOL present = TRUE;
485 /* FIXME
486 * the following tests are wrong because lots of functions don't require the
487 * tray to be closed with a CD inside
489 TRACE("CDROM device driver -> command <%d>\n", driver_request[2]);
491 /* set status to 0 */
492 PTR_AT(driver_request, 3, WORD) = 0;
493 devName[4] = 'A' + CDROM_GetHeap()->hdr.drive + driver_request[1];
494 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
495 if (h == INVALID_HANDLE_VALUE) {
496 WARN("Couldn't open cdrom handle\n");
497 driver_request[4] |= 0x80;
498 driver_request[3] = 1; /* unknown unit */
499 return;
502 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
503 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
504 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
505 &data, sizeof(data), &br, NULL)) {
506 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
508 if (driver_request[2] != 6 && driver_request[2] != 15)
510 driver_request[4] |= 0x80;
511 driver_request[3] = 2; /* drive not ready */
512 CloseHandle(h);
513 return;
515 present = FALSE;
517 else
519 driver_request[4] |= 0x80;
520 driver_request[3] = 1; /* unknown unit */
521 CloseHandle(h);
522 return;
526 switch (driver_request[2]) {
527 case 3:
528 io_stru = MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
530 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
531 switch (io_stru[0]) {
532 #if 0
533 case 0: /* Get device Header */
535 static LPSTR ptr = 0;
536 if (ptr == 0) {
537 ptr = SEGPTR_ALLOC(22);
538 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
539 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
540 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
541 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
542 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
543 PTR_AT(ptr, 11, char) = 'I';
544 PTR_AT(ptr, 12, char) = 'N';
545 PTR_AT(ptr, 13, char) = 'E';
546 PTR_AT(ptr, 14, char) = '_';
547 PTR_AT(ptr, 15, char) = 'C';
548 PTR_AT(ptr, 16, char) = 'D';
549 PTR_AT(ptr, 17, char) = '_';
550 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
551 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
552 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
554 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
556 break;
557 #endif
559 case 1: /* location of head */
560 switch (io_stru[1]) {
561 case 0:
562 PTR_AT(io_stru, 2, DWORD) =
563 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
564 break;
565 case 1:
566 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
567 io_stru + 2);
568 break;
569 default:
570 ERR("CD-ROM driver: unsupported addressing mode !!\n");
571 Error = 0x0c;
573 TRACE(" ----> HEAD LOCATION <%d>\n", PTR_AT(io_stru, 2, DWORD));
574 break;
576 case 4: /* Audio channel info */
577 io_stru[1] = 0;
578 io_stru[2] = 0xff;
579 io_stru[3] = 1;
580 io_stru[4] = 0xff;
581 io_stru[5] = 2;
582 io_stru[6] = 0;
583 io_stru[7] = 3;
584 io_stru[8] = 0;
585 TRACE(" ----> AUDIO CHANNEL INFO\n");
586 break;
588 case 6: /* device status */
589 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
590 /* 290 =>
591 * 1 Supports HSG and Red Book addressing modes
592 * 0 Supports audio channel manipulation
594 * 1 Supports prefetching requests
595 * 0 Reserved
596 * 0 No interleaving
597 * 1 Data read and plays audio/video tracks
599 * 0 Read only
600 * 0 Supports only cooked reading
601 * 0 Door locked
602 * 0 see below (Door closed/opened)
604 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
605 TRACE(" ----> DEVICE STATUS <0x%08x>\n", PTR_AT(io_stru, 1, DWORD));
606 break;
608 case 8: /* Volume size */
609 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
610 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
611 TRACE(" ----> VOLUME SIZE <%d>\n", PTR_AT(io_stru, 1, DWORD));
612 break;
614 case 9: /* media changed ? */
615 /* answers don't know... -1/1 for yes/no would be better */
616 io_stru[1] = 0; /* FIXME? 1? */
617 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
618 break;
620 case 10: /* audio disk info */
621 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
622 io_stru[2] = toc.LastTrack; /* ending track */
623 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
624 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
626 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08x>\n",
627 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
628 break;
630 case 11: /* audio track info */
631 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
632 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
633 /* starting point if the track */
634 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
635 } else {
636 PTR_AT(io_stru, 2, DWORD) = 0;
637 io_stru[6] = 0;
639 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08x:%d]\n",
640 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
641 break;
643 case 12: /* get Q-Channel info */
644 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
645 io_stru[2] = data.CurrentPosition.TrackNumber;
646 io_stru[3] = 0; /* FIXME ?? */
648 /* why the heck did MS use another format for 0MSF information... sigh */
650 BYTE bTmp[4];
652 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
653 io_stru[ 4] = bTmp[2];
654 io_stru[ 5] = bTmp[1];
655 io_stru[ 6] = bTmp[0];
656 io_stru[ 7] = 0;
658 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
659 io_stru[ 8] = bTmp[2];
660 io_stru[ 9] = bTmp[1];
661 io_stru[10] = bTmp[0];
662 io_stru[11] = 0;
664 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
665 io_stru[ 1], io_stru[ 2], io_stru[ 3],
666 io_stru[ 4], io_stru[ 5], io_stru[ 6],
667 io_stru[ 8], io_stru[ 9], io_stru[10],
668 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
669 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
670 break;
672 case 15: /* Audio status info */
673 /* !!!! FIXME FIXME FIXME !! */
674 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
675 if (!present) {
676 PTR_AT(io_stru, 3, DWORD) = 0;
677 PTR_AT(io_stru, 7, DWORD) = 0;
678 } else {
679 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
680 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
682 TRACE("Audio status info: status=%04x startLoc=%d endLoc=%d\n",
683 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
684 break;
686 default:
687 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
688 Error = 0x0c;
689 break;
691 break;
693 case 12:
694 io_stru = MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
696 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
697 switch (io_stru[0]) {
698 case 0: /* eject */
699 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
700 TRACE(" ----> EJECT\n");
701 break;
702 case 2: /* reset drive */
703 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
704 TRACE(" ----> RESET\n");
705 break;
706 case 3: /* Audio Channel Control */
707 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
708 break;
709 case 5: /* close tray */
710 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
711 TRACE(" ----> CLOSE TRAY\n");
712 break;
713 default:
714 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
715 Error = 0x0c;
716 break;
718 break;
720 case 128: /* read long */
722 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
723 PTR_AT(driver_request, 14, WORD)));
724 DWORD at = PTR_AT(driver_request, 20, DWORD);
725 WORD num = PTR_AT(driver_request, 18, WORD);
726 RAW_READ_INFO rri;
728 switch (driver_request[13]) {
729 case 1: /* Red book addressing mode = 0:m:s:f */
730 /* FIXME : frame <=> msf conversion routines could be shared
731 * between mscdex and mcicda
733 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
734 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
735 LOBYTE(LOWORD(at));
736 /* fall through */
737 case 0: /* HSG addressing mode */
738 switch (PTR_AT(driver_request, 24, BYTE))
740 case 0: /* cooked */
741 ReadFile(h, dst, num * 2048, &br, NULL);
742 break;
743 case 1:
744 /* FIXME: computation is wrong */
745 rri.DiskOffset.u.HighPart = 0;
746 rri.DiskOffset.u.LowPart = at << 11;
747 rri.TrackMode = YellowMode2;
748 rri.SectorCount = num;
749 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
750 dst, num * 2352, &br, NULL);
751 break;
752 default:
753 ERR("Unsupported read mode !!\n");
754 Error = 0x0c;
755 break;
757 break;
758 default:
759 ERR("Unsupported address mode !!\n");
760 Error = 0x0c;
761 break;
764 break;
766 case 131: /* seek */
768 DWORD at;
769 CDROM_SEEK_AUDIO_MSF seek;
771 at = PTR_AT(driver_request, 20, DWORD);
773 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%d]\n", driver_request[13], at);
775 switch (driver_request[13]) {
776 case 1: /* Red book addressing mode = 0:m:s:f */
777 /* FIXME : frame <=> msf conversion routines could be shared
778 * between mscdex and mcicda
780 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
781 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
782 LOBYTE(LOWORD(at));
783 /* fall through */
784 case 0: /* HSG addressing mode */
785 seek.M = at / CDFRAMES_PERMIN;
786 seek.S = (at / CDFRAMES_PERSEC) % 60;
787 seek.F = at % CDFRAMES_PERSEC;
788 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
789 NULL, 0, &br, NULL);
790 break;
791 default:
792 ERR("Unsupported address mode !!\n");
793 Error = 0x0c;
794 break;
797 break;
799 case 132: /* play */
801 DWORD beg, end;
802 CDROM_PLAY_AUDIO_MSF play;
804 beg = end = PTR_AT(driver_request, 14, DWORD);
805 end += PTR_AT(driver_request, 18, DWORD);
807 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%d-%d]\n", driver_request[13], beg, end);
809 switch (driver_request[13]) {
810 case 1:
811 /* Red book addressing mode = 0:m:s:f */
812 /* FIXME : frame <=> msf conversion routines could be shared
813 * between mscdex and mcicda
815 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
816 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
817 LOBYTE(HIWORD(beg));
818 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
819 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
820 LOBYTE(HIWORD(end));
821 /* fall through */
822 case 0: /* HSG addressing mode */
823 play.StartingM = beg / CDFRAMES_PERMIN;
824 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
825 play.StartingF = beg % CDFRAMES_PERSEC;
826 play.EndingM = end / CDFRAMES_PERMIN;
827 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
828 play.EndingF = end % CDFRAMES_PERSEC;
829 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
830 NULL, 0, &br, NULL);
831 break;
832 default:
833 ERR("Unsupported address mode !!\n");
834 Error = 0x0c;
835 break;
838 break;
840 case 133:
841 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
842 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
843 TRACE(" --> STOP AUDIO (Paused)\n");
844 } else {
845 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
846 TRACE(" --> STOP AUDIO (Stopped)\n");
848 break;
850 case 136:
851 TRACE(" --> RESUME AUDIO\n");
852 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
853 break;
855 default:
856 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
857 Error = 0x0c;
860 /* setting error codes if any */
861 if (Error < 255) {
862 driver_request[4] |= 0x80;
863 driver_request[3] = Error;
866 CloseHandle(h);
867 /* setting status bits
868 * 3 == playing && done
869 * 1 == done
871 driver_request[4] |=
872 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
875 static void MSCDEX_Handler(CONTEXT* context)
877 int drive, count;
878 char* p;
880 switch (LOBYTE(context->Eax)) {
881 case 0x00: /* Installation check */
882 /* Count the number of contiguous CDROM drives
884 for (drive = count = 0; drive < 26; drive++) {
885 if (is_cdrom(drive)) {
886 while (is_cdrom(drive + count)) count++;
887 break;
890 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
891 SET_BX( context, count );
892 SET_CX( context, (drive < 26) ? drive : 0 );
893 break;
895 case 0x01: /* get drive device list */
897 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
898 CDROM_DEVICE_HEADER* dev = &cdrom_heap->hdr;
899 SEGPTR ptr_dev = MAKESEGPTR( cdrom_heap->cdrom_selector, FIELD_OFFSET(CDROM_HEAP, hdr) );
901 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
902 for (drive = 0; drive < dev->units; drive++) {
903 *p = drive; /* subunit */
904 ++p;
905 *(DWORD*)p = ptr_dev;
906 p += sizeof(DWORD);
908 TRACE("Get drive device list\n");
910 break;
912 case 0x0B: /* drive check */
913 SET_AX( context, is_cdrom(CX_reg(context)) );
914 SET_BX( context, 0xADAD );
915 break;
917 case 0x0C: /* get version */
918 SET_BX( context, 0x020a );
919 TRACE("Version number => %04x\n", BX_reg(context));
920 break;
922 case 0x0D: /* get drive letters */
923 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
924 memset(p, 0, 26);
925 for (drive = 0; drive < 26; drive++) {
926 if (is_cdrom(drive)) *p++ = drive;
928 TRACE("Get drive letters\n");
929 break;
931 case 0x10: /* direct driver access */
933 BYTE* driver_request;
934 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
936 if (!is_cdrom(CX_reg(context))) {
937 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
938 SET_CFLAG( context );
939 SET_AX( context, 0x000f ); /* invalid drive */
940 return;
943 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
945 if (!driver_request) {
946 /* FIXME - to be deleted ?? */
947 ERR("ES:BX==0 ! SEGFAULT ?\n");
948 ERR("-->BX=0x%04x, ES=0x%04x, DS=0x%04x, CX=0x%04x\n",
949 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
950 driver_request[4] |= 0x80;
951 driver_request[3] = 5; /* bad request length */
952 return;
955 driver_request[1] = CX_reg(context) - cdrom_heap->hdr.drive;
956 MSCDEX_Request(driver_request);
958 break;
959 default:
960 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
961 break;