imagehlp: Use the IMAGE_FIRST_SECTION helper macro.
[wine.git] / dlls / krnl386.exe16 / int2f.c
blobfcb9ebd7d792352b40335c7b763c9c0d6e7cd3b3
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 #include "wine/winbase16.h"
29 #include "wine/debug.h"
30 #include "winternl.h"
31 #include "winioctl.h"
32 #include "ntddstor.h"
33 #include "ntddcdrm.h"
34 #include "dosexe.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(int);
38 /* base KERNEL ordinal number for VxDs */
39 #define VXD_BASE 900
41 typedef struct
43 DOS_DEVICE_HEADER hdr;
45 WORD reserved; /* must be 0 */
46 BYTE drive; /* drive letter (0=A:, 1=B:, ...) */
47 BYTE units; /* number of supported units */
48 } CDROM_DEVICE_HEADER;
50 typedef struct
52 CDROM_DEVICE_HEADER hdr;
53 WORD cdrom_selector; /* Protected mode selector for CDROM_HEAP */
54 } CDROM_HEAP;
56 static void do_int2f_16( CONTEXT *context );
57 static void MSCDEX_Handler( CONTEXT *context );
59 /**********************************************************************
60 * DOSVM_Int2fHandler
62 * Handler for int 2fh (multiplex).
64 void WINAPI DOSVM_Int2fHandler( CONTEXT *context )
66 TRACE("Subfunction 0x%X\n", AX_reg(context));
68 switch(AH_reg(context))
70 case 0x10:
71 SET_AL( context, 0xff ); /* share is installed */
72 break;
74 case 0x11: /* Network Redirector / IFSFUNC */
75 switch (LOBYTE(context->Eax))
77 case 0x00: /* Install check */
78 /* not installed */
79 break;
80 case 0x80: /* Enhanced services - Install check */
81 /* not installed */
82 break;
83 default:
84 INT_BARF( context, 0x2f );
85 break;
87 break;
89 case 0x12:
90 switch (LOBYTE(context->Eax))
92 case 0x2e: /* get or set DOS error table address */
93 switch (DL_reg(context))
95 /* Four tables: even commands are 'get', odd are 'set' */
96 /* DOS 5.0+ ignores "set" commands */
97 case 0x01:
98 case 0x03:
99 case 0x05:
100 case 0x07:
101 case 0x09:
102 break;
103 /* Instead of having a message table in DOS-space, */
104 /* we can use a special case for MS-DOS to force */
105 /* the secondary interface. */
106 case 0x00:
107 case 0x02:
108 case 0x04:
109 case 0x06:
110 context->SegEs = 0x0001;
111 SET_DI( context, 0x0000 );
112 break;
113 case 0x08:
114 FIXME("No real-mode handler for errors yet! (bye!)\n");
115 break;
116 default:
117 INT_BARF(context, 0x2f);
119 break;
120 default:
121 INT_BARF(context, 0x2f);
123 break;
125 case 0x15: /* mscdex */
126 MSCDEX_Handler(context);
127 break;
129 case 0x16:
130 do_int2f_16( context );
131 break;
133 case 0x1a: /* ANSI.SYS / AVATAR.SYS Install Check */
134 /* Not supported yet, do nothing */
135 break;
137 case 0x43:
138 FIXME("check for XMS (not supported)\n");
139 SET_AL( context, 0x42 ); /* != 0x80 */
140 break;
142 case 0x45:
143 switch (LOBYTE(context->Eax))
145 case 0x00:
146 case 0x01:
147 case 0x02:
148 case 0x03:
149 case 0x04:
150 case 0x05:
151 case 0x06:
152 case 0x07:
153 case 0x08:
154 /* Microsoft Profiler - not installed */
155 break;
156 default:
157 INT_BARF( context, 0x2f );
159 break;
161 case 0x4a:
162 switch(LOBYTE(context->Eax))
164 case 0x10: /* smartdrv */
165 break; /* not installed */
166 case 0x11: /* dblspace */
167 break; /* not installed */
168 case 0x12: /* realtime compression interface */
169 break; /* not installed */
170 case 0x32: /* patch IO.SYS (???) */
171 break; /* we have no IO.SYS, so we can't patch it :-/ */
172 default:
173 INT_BARF( context, 0x2f );
175 break;
176 case 0x4b:
177 switch(LOBYTE(context->Eax))
179 case 0x01:
180 case 0x02:
181 case 0x03:
182 case 0x04:
183 case 0x05:
184 FIXME("Task Switcher - not implemented\n");
185 break;
186 default:
187 INT_BARF( context, 0x2f );
189 break;
190 case 0x56: /* INTERLNK */
191 switch(LOBYTE(context->Eax))
193 case 0x01: /* check if redirected drive */
194 SET_AL( context, 0 ); /* not redirected */
195 break;
196 default:
197 INT_BARF( context, 0x2f );
199 break;
200 case 0x7a: /* NOVELL NetWare */
201 switch (LOBYTE(context->Eax))
203 case 0x0: /* Low-level Netware installation check AL=0 not installed.*/
204 SET_AL( context, 0 );
205 break;
206 case 0x20: /* Get VLM Call Address */
207 /* return nothing -> NetWare not installed */
208 break;
209 default:
210 INT_BARF( context, 0x2f );
211 break;
213 break;
214 case 0xb7: /* append */
215 SET_AL( context, 0 ); /* not installed */
216 break;
217 case 0xb8: /* network */
218 switch (LOBYTE(context->Eax))
220 case 0x00: /* Install check */
221 /* not installed */
222 break;
223 default:
224 INT_BARF( context, 0x2f );
225 break;
227 break;
228 case 0xbc:
229 if (AL_reg(context) == 0x00 && BX_reg(context) == 0x3f3f) {
230 /* MVSOUND.SYS - Install check: not installed */
231 } else {
232 INT_BARF( context, 0x2f );
234 break;
235 case 0xbd: /* some Novell network install check ??? */
236 SET_AX( context, 0xa5a5 ); /* pretend to have Novell IPX installed */
237 break;
238 case 0xbf: /* REDIRIFS.EXE */
239 switch (LOBYTE(context->Eax))
241 case 0x00: /* Install check */
242 /* not installed */
243 break;
244 default:
245 INT_BARF( context, 0x2f );
246 break;
248 break;
249 case 0xd2:
250 switch(LOBYTE(context->Eax))
252 case 0x01: /* Quarterdeck RPCI - QEMM/QRAM - PCL-838.EXE functions */
253 if(BX_reg(context) == 0x5145 && CX_reg(context) == 0x4D4D
254 && DX_reg(context) == 0x3432)
255 TRACE("Check for QEMM v5.0+ (not installed)\n");
256 break;
257 default:
258 INT_BARF( context, 0x2f );
259 break;
261 break;
262 case 0xd7: /* Banyan Vines */
263 switch (LOBYTE(context->Eax))
265 case 0x01: /* Install check - Get Int Number */
266 /* not installed */
267 break;
268 default:
269 INT_BARF( context, 0x2f );
270 break;
272 break;
273 case 0xde:
274 switch(LOBYTE(context->Eax))
276 case 0x01: /* Quarterdeck QDPMI.SYS - DESQview */
277 if(BX_reg(context) == 0x4450 && CX_reg(context) == 0x4d49
278 && DX_reg(context) == 0x8f4f)
279 TRACE("Check for QDPMI.SYS (not installed)\n");
280 break;
281 default:
282 INT_BARF( context, 0x2f );
283 break;
285 break;
286 case 0xfa: /* Watcom debugger check, returns 0x666 if installed */
287 break;
288 default:
289 INT_BARF( context, 0x2f );
290 break;
295 /**********************************************************************
296 * do_int2f_16
298 static void do_int2f_16( CONTEXT *context )
300 DWORD addr;
302 switch(LOBYTE(context->Eax))
304 case 0x00: /* Windows enhanced mode installation check */
305 SET_AX( context, LOWORD(GetVersion16()) );
306 break;
308 case 0x0a: /* Get Windows version and type */
309 SET_AX( context, 0 );
310 SET_BX( context, (LOWORD(GetVersion16()) << 8) | (LOWORD(GetVersion16()) >> 8) );
311 SET_CX( context, 3 );
312 break;
314 case 0x0b: /* Identify Windows-aware TSRs */
315 /* we don't have any pre-Windows TSRs */
316 break;
318 case 0x11: /* Get Shell Parameters - (SHELL= in CONFIG.SYS) */
319 /* We can mock this up. But not today... */
320 FIXME("Get Shell Parameters\n");
321 break;
323 case 0x80: /* Release time-slice */
324 /* Linux sched_yield() still keeps burning CPU cycles
325 * if the current process is the only one in highest priority list
326 * (as Linux will immediately return to this process to waste
327 * more CPU cycles), so sched_yield() is essentially useless for us
328 * (poor API, if you ask me: its return code should indicate
329 * whether other processes did run in between, in order for us
330 * to be able to decide whether to do an additional Sleep() or not...)
331 * Thus we better unconditionally use a well-balanced Sleep()
332 * instead to really make sure the process calling int 0x2f/0x1680
333 * *doesn't* use 100% CPU...
335 Sleep(55); /* just wait 55ms (one "timer tick") for now. */
336 SET_AL( context, 0 );
337 break;
339 case 0x81: /* Begin critical section. */
340 /* FIXME? */
341 break;
343 case 0x82: /* End critical section. */
344 /* FIXME? */
345 break;
347 case 0x83: /* Return Current Virtual Machine ID */
348 /* Virtual Machines are usually created/destroyed when Windows runs
349 * DOS programs. Since we never do, we are always in the System VM.
350 * According to Ralf Brown's Interrupt List, never return 0. But it
351 * seems to work okay (returning 0), just to be sure we return 1.
353 SET_BX( context, 1 ); /* VM 1 is probably the System VM */
354 break;
356 case 0x84: /* Get device API entry point */
358 HMODULE16 mod = GetModuleHandle16("kernel");
359 addr = (DWORD)GetProcAddress16( mod, (LPCSTR)(VXD_BASE + BX_reg(context)) );
360 if (!addr) /* not supported */
361 ERR("Accessing unknown VxD %04x - Expect a failure now.\n", BX_reg(context) );
362 context->SegEs = SELECTOROF(addr);
363 SET_DI( context, OFFSETOF(addr) );
365 break;
367 case 0x86: /* DPMI detect mode */
368 SET_AX( context, 0 ); /* Running under DPMI */
369 break;
371 case 0x87: /* DPMI installation check */
373 SYSTEM_INFO si;
374 GetSystemInfo(&si);
375 SET_AX( context, 0x0000 ); /* DPMI Installed */
376 SET_BX( context, 0x0001 ); /* 32bits available */
377 SET_CL( context, si.wProcessorLevel );
378 SET_DX( context, 0x005a ); /* DPMI major/minor 0.90 */
379 SET_SI( context, 0 ); /* # of para. of DOS extended private data */
380 context->SegEs = 0; /* no DPMI switch */
381 SET_DI( context, 0 ); /* ES:DI is DPMI switch entry point */
382 break;
384 case 0x8a: /* DPMI get vendor-specific API entry point. */
385 /* The 1.0 specs say this should work with all 0.9 hosts. */
386 break;
388 default:
389 INT_BARF( context, 0x2f );
393 /* FIXME: this macro may have to be changed on architectures where <size> reads/writes
394 * must be <size> aligned
395 * <size> could be WORD, DWORD...
396 * in this case, we would need two macros, one for read, the other one for write
397 * Note: PTR_AT can be used as an l-value
399 #define PTR_AT(_ptr, _ofs, _typ) (*((_typ*)(((char*)_ptr)+(_ofs))))
401 #define CDFRAMES_PERSEC 75
402 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
403 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
404 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc).TrackData[idx - (toc).FirstTrack].Address)
405 #define CTRL_OF_TOC(toc, idx) (((toc).TrackData[idx - (toc).FirstTrack].Control << 4) | \
406 (toc).TrackData[idx - (toc).FirstTrack].Adr)
408 static void MSCDEX_StoreMSF(DWORD frame, BYTE* val)
410 val[3] = 0; /* zero */
411 val[2] = frame / CDFRAMES_PERMIN; /* minutes */
412 val[1] = (frame / CDFRAMES_PERSEC) % 60; /* seconds */
413 val[0] = frame % CDFRAMES_PERSEC; /* frames */
416 static BOOL is_cdrom(int drive)
418 char root[] = "A:\\";
419 root[0] += drive;
420 return (GetDriveTypeA(root) == DRIVE_CDROM);
423 /***********************************************************************
424 * CDROM_FillHeap
426 * Initialize CDROM heap.
429 static void CDROM_FillHeap( CDROM_HEAP *heap )
431 int drive, count;
433 /* Count the number of contiguous CDROM drives
435 for (drive = count = 0; drive < 26; drive++) {
436 if (is_cdrom(drive)) {
437 while (is_cdrom(drive + count)) count++;
438 break;
441 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
442 heap->hdr.drive = (drive < 26) ? drive : 0;
443 heap->hdr.units = count;
444 heap->hdr.reserved = 0;
447 /**********************************************************************
448 * CDROM_GetHeap
450 * Get pointer for CDROM heap (CDROM_HEAP).
451 * Creates and initializes heap on first call.
453 static CDROM_HEAP *CDROM_GetHeap( void )
455 static CDROM_HEAP *heap_pointer = NULL;
457 if ( !heap_pointer )
459 WORD heap_selector = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, sizeof(CDROM_HEAP) );
460 heap_pointer = GlobalLock16( heap_selector );
461 heap_pointer->cdrom_selector = heap_selector;
462 CDROM_FillHeap( heap_pointer );
465 return heap_pointer;
468 static void MSCDEX_Request(BYTE *driver_request)
470 BYTE* io_stru;
471 BYTE Error = 255; /* No Error */
472 char devName[] = "\\\\.\\@:";
473 HANDLE h;
474 CDROM_TOC toc;
475 CDROM_SUB_Q_DATA_FORMAT fmt;
476 SUB_Q_CHANNEL_DATA data;
477 DWORD br;
478 BOOL present = TRUE;
480 /* FIXME
481 * the following tests are wrong because lots of functions don't require the
482 * tray to be closed with a CD inside
484 TRACE("CDROM device driver -> command <%d>\n", driver_request[2]);
486 /* set status to 0 */
487 PTR_AT(driver_request, 3, WORD) = 0;
488 devName[4] = 'A' + CDROM_GetHeap()->hdr.drive + driver_request[1];
489 h = CreateFileA(devName, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0);
490 if (h == INVALID_HANDLE_VALUE) {
491 WARN("Couldn't open cdrom handle\n");
492 driver_request[4] |= 0x80;
493 driver_request[3] = 1; /* unknown unit */
494 return;
497 fmt.Format = IOCTL_CDROM_CURRENT_POSITION;
498 if (!DeviceIoControl(h, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, NULL) ||
499 !DeviceIoControl(h, IOCTL_CDROM_READ_Q_CHANNEL, &fmt, sizeof(fmt),
500 &data, sizeof(data), &br, NULL)) {
501 if (GetLastError() == STATUS_NO_MEDIA_IN_DEVICE)
503 if (driver_request[2] != 6 && driver_request[2] != 15)
505 driver_request[4] |= 0x80;
506 driver_request[3] = 2; /* drive not ready */
507 CloseHandle(h);
508 return;
510 present = FALSE;
512 else
514 driver_request[4] |= 0x80;
515 driver_request[3] = 1; /* unknown unit */
516 CloseHandle(h);
517 return;
521 switch (driver_request[2]) {
522 case 3:
523 io_stru = MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
525 TRACE(" --> IOCTL INPUT <%d>\n", io_stru[0]);
526 switch (io_stru[0]) {
527 #if 0
528 case 0: /* Get device Header */
530 static LPSTR ptr = 0;
531 if (ptr == 0) {
532 ptr = SEGPTR_ALLOC(22);
533 PTR_AT(ptr, 0, DWORD) = ~1; /* Next Device Driver */
534 PTR_AT(ptr, 4, WORD) = 0xC800; /* Device attributes */
535 PTR_AT(ptr, 6, WORD) = 0x1234; /* Pointer to device strategy routine: FIXME */
536 PTR_AT(ptr, 8, WORD) = 0x3142; /* Pointer to device interrupt routine: FIXME */
537 PTR_AT(ptr, 10, char) = 'W'; /* 8-byte character device name field */
538 PTR_AT(ptr, 11, char) = 'I';
539 PTR_AT(ptr, 12, char) = 'N';
540 PTR_AT(ptr, 13, char) = 'E';
541 PTR_AT(ptr, 14, char) = '_';
542 PTR_AT(ptr, 15, char) = 'C';
543 PTR_AT(ptr, 16, char) = 'D';
544 PTR_AT(ptr, 17, char) = '_';
545 PTR_AT(ptr, 18, WORD) = 0; /* Reserved (must be zero) */
546 PTR_AT(ptr, 20, BYTE) = 0; /* Drive letter (must be zero) */
547 PTR_AT(ptr, 21, BYTE) = 1; /* Number of units supported (one or more) FIXME*/
549 PTR_AT(io_stru, DWORD, 0) = SEGPTR_GET(ptr);
551 break;
552 #endif
554 case 1: /* location of head */
555 switch (io_stru[1]) {
556 case 0:
557 PTR_AT(io_stru, 2, DWORD) =
558 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress);
559 break;
560 case 1:
561 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
562 io_stru + 2);
563 break;
564 default:
565 ERR("CD-ROM driver: unsupported addressing mode !!\n");
566 Error = 0x0c;
568 TRACE(" ----> HEAD LOCATION <%ld>\n", PTR_AT(io_stru, 2, DWORD));
569 break;
571 case 4: /* Audio channel info */
572 io_stru[1] = 0;
573 io_stru[2] = 0xff;
574 io_stru[3] = 1;
575 io_stru[4] = 0xff;
576 io_stru[5] = 2;
577 io_stru[6] = 0;
578 io_stru[7] = 3;
579 io_stru[8] = 0;
580 TRACE(" ----> AUDIO CHANNEL INFO\n");
581 break;
583 case 6: /* device status */
584 PTR_AT(io_stru, 1, DWORD) = 0x00000290;
585 /* 290 =>
586 * 1 Supports HSG and Red Book addressing modes
587 * 0 Supports audio channel manipulation
589 * 1 Supports prefetching requests
590 * 0 Reserved
591 * 0 No interleaving
592 * 1 Data read and plays audio/video tracks
594 * 0 Read only
595 * 0 Supports only cooked reading
596 * 0 Door locked
597 * 0 see below (Door closed/opened)
599 if (!present) PTR_AT(io_stru, 1, DWORD) |= 1;
600 TRACE(" ----> DEVICE STATUS <0x%08lx>\n", PTR_AT(io_stru, 1, DWORD));
601 break;
603 case 8: /* Volume size */
604 PTR_AT(io_stru, 1, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1) -
605 FRAME_OF_TOC(toc, toc.FirstTrack) - 1;
606 TRACE(" ----> VOLUME SIZE <%ld>\n", PTR_AT(io_stru, 1, DWORD));
607 break;
609 case 9: /* media changed ? */
610 /* answers don't know... -1/1 for yes/no would be better */
611 io_stru[1] = 0; /* FIXME? 1? */
612 TRACE(" ----> MEDIA CHANGED <%d>\n", io_stru[1]);
613 break;
615 case 10: /* audio disk info */
616 io_stru[1] = toc.FirstTrack; /* starting track of the disc */
617 io_stru[2] = toc.LastTrack; /* ending track */
618 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, toc.LastTrack + 1) -
619 FRAME_OF_TOC(toc, toc.FirstTrack) - 1, io_stru + 3);
621 TRACE(" ----> AUDIO DISK INFO <%d-%d/%08lx>\n",
622 io_stru[1], io_stru[2], PTR_AT(io_stru, 3, DWORD));
623 break;
625 case 11: /* audio track info */
626 if (io_stru[1] >= toc.FirstTrack && io_stru[1] <= toc.LastTrack) {
627 MSCDEX_StoreMSF(FRAME_OF_TOC(toc, io_stru[1]), io_stru + 2);
628 /* starting point if the track */
629 io_stru[6] = CTRL_OF_TOC(toc, io_stru[1]);
630 } else {
631 PTR_AT(io_stru, 2, DWORD) = 0;
632 io_stru[6] = 0;
634 TRACE(" ----> AUDIO TRACK INFO[%d] = [%08lx:%d]\n",
635 io_stru[1], PTR_AT(io_stru, 2, DWORD), io_stru[6]);
636 break;
638 case 12: /* get Q-Channel info */
639 io_stru[1] = CTRL_OF_TOC(toc, data.CurrentPosition.TrackNumber);
640 io_stru[2] = data.CurrentPosition.TrackNumber;
641 io_stru[3] = 0; /* FIXME ?? */
643 /* why the heck did MS use another format for 0MSF information... sigh */
645 BYTE bTmp[4];
647 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.TrackRelativeAddress), bTmp);
648 io_stru[ 4] = bTmp[2];
649 io_stru[ 5] = bTmp[1];
650 io_stru[ 6] = bTmp[0];
651 io_stru[ 7] = 0;
653 MSCDEX_StoreMSF(FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress), bTmp);
654 io_stru[ 8] = bTmp[2];
655 io_stru[ 9] = bTmp[1];
656 io_stru[10] = bTmp[0];
657 io_stru[11] = 0;
659 TRACE("Q-Channel info: Ctrl/adr=%02x TNO=%02x X=%02x rtt=%02x:%02x:%02x rtd=%02x:%02x:%02x (cf=%08x, tp=%08x)\n",
660 io_stru[ 1], io_stru[ 2], io_stru[ 3],
661 io_stru[ 4], io_stru[ 5], io_stru[ 6],
662 io_stru[ 8], io_stru[ 9], io_stru[10],
663 FRAME_OF_ADDR(data.CurrentPosition.AbsoluteAddress),
664 FRAME_OF_TOC(toc, data.CurrentPosition.TrackNumber));
665 break;
667 case 15: /* Audio status info */
668 /* !!!! FIXME FIXME FIXME !! */
669 PTR_AT(io_stru, 1, WORD) = 2 | ((data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_PAUSED) ? 1 : 0);
670 if (!present) {
671 PTR_AT(io_stru, 3, DWORD) = 0;
672 PTR_AT(io_stru, 7, DWORD) = 0;
673 } else {
674 PTR_AT(io_stru, 3, DWORD) = FRAME_OF_TOC(toc, toc.FirstTrack);
675 PTR_AT(io_stru, 7, DWORD) = FRAME_OF_TOC(toc, toc.LastTrack + 1);
677 TRACE("Audio status info: status=%04x startLoc=%ld endLoc=%ld\n",
678 PTR_AT(io_stru, 1, WORD), PTR_AT(io_stru, 3, DWORD), PTR_AT(io_stru, 7, DWORD));
679 break;
681 default:
682 FIXME("IOCTL INPUT: Unimplemented <%d>!!\n", io_stru[0]);
683 Error = 0x0c;
684 break;
686 break;
688 case 12:
689 io_stru = MapSL( MAKESEGPTR(PTR_AT(driver_request, 16, WORD), PTR_AT(driver_request, 14, WORD)));
691 TRACE(" --> IOCTL OUTPUT <%d>\n", io_stru[0]);
692 switch (io_stru[0]) {
693 case 0: /* eject */
694 DeviceIoControl(h, IOCTL_STORAGE_EJECT_MEDIA, NULL, 0, NULL, 0, &br, NULL);
695 TRACE(" ----> EJECT\n");
696 break;
697 case 2: /* reset drive */
698 DeviceIoControl(h, IOCTL_STORAGE_RESET_DEVICE, NULL, 0, NULL, 0, &br, NULL);
699 TRACE(" ----> RESET\n");
700 break;
701 case 3: /* Audio Channel Control */
702 FIXME(" ----> AUDIO CHANNEL CONTROL (NIY)\n");
703 break;
704 case 5: /* close tray */
705 DeviceIoControl(h, IOCTL_STORAGE_LOAD_MEDIA, NULL, 0, NULL, 0, &br, NULL);
706 TRACE(" ----> CLOSE TRAY\n");
707 break;
708 default:
709 FIXME(" IOCTL OUTPUT: Unimplemented <%d>!!\n", io_stru[0]);
710 Error = 0x0c;
711 break;
713 break;
715 case 128: /* read long */
717 LPVOID dst = MapSL(MAKESEGPTR(PTR_AT(driver_request, 16, WORD),
718 PTR_AT(driver_request, 14, WORD)));
719 DWORD at = PTR_AT(driver_request, 20, DWORD);
720 WORD num = PTR_AT(driver_request, 18, WORD);
721 RAW_READ_INFO rri;
723 switch (driver_request[13]) {
724 case 1: /* Red book addressing mode = 0:m:s:f */
725 /* FIXME : frame <=> msf conversion routines could be shared
726 * between mscdex and mcicda
728 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
729 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
730 LOBYTE(LOWORD(at));
731 /* fall through */
732 case 0: /* HSG addressing mode */
733 switch (PTR_AT(driver_request, 24, BYTE))
735 case 0: /* cooked */
736 ReadFile(h, dst, num * 2048, &br, NULL);
737 break;
738 case 1:
739 /* FIXME: computation is wrong */
740 rri.DiskOffset.u.HighPart = 0;
741 rri.DiskOffset.u.LowPart = at << 11;
742 rri.TrackMode = YellowMode2;
743 rri.SectorCount = num;
744 DeviceIoControl(h, IOCTL_CDROM_RAW_READ, &rri, sizeof(rri),
745 dst, num * 2352, &br, NULL);
746 break;
747 default:
748 ERR("Unsupported read mode !!\n");
749 Error = 0x0c;
750 break;
752 break;
753 default:
754 ERR("Unsupported address mode !!\n");
755 Error = 0x0c;
756 break;
759 break;
761 case 131: /* seek */
763 DWORD at;
764 CDROM_SEEK_AUDIO_MSF seek;
766 at = PTR_AT(driver_request, 20, DWORD);
768 TRACE(" --> SEEK AUDIO mode :<0x%02X>, [%ld]\n", driver_request[13], at);
770 switch (driver_request[13]) {
771 case 1: /* Red book addressing mode = 0:m:s:f */
772 /* FIXME : frame <=> msf conversion routines could be shared
773 * between mscdex and mcicda
775 at = LOBYTE(HIWORD(at)) * CDFRAMES_PERMIN +
776 HIBYTE(LOWORD(at)) * CDFRAMES_PERSEC +
777 LOBYTE(LOWORD(at));
778 /* fall through */
779 case 0: /* HSG addressing mode */
780 seek.M = at / CDFRAMES_PERMIN;
781 seek.S = (at / CDFRAMES_PERSEC) % 60;
782 seek.F = at % CDFRAMES_PERSEC;
783 DeviceIoControl(h, IOCTL_CDROM_SEEK_AUDIO_MSF, &seek, sizeof(seek),
784 NULL, 0, &br, NULL);
785 break;
786 default:
787 ERR("Unsupported address mode !!\n");
788 Error = 0x0c;
789 break;
792 break;
794 case 132: /* play */
796 DWORD beg, end;
797 CDROM_PLAY_AUDIO_MSF play;
799 beg = end = PTR_AT(driver_request, 14, DWORD);
800 end += PTR_AT(driver_request, 18, DWORD);
802 TRACE(" --> PLAY AUDIO mode :<0x%02X>, [%ld-%ld]\n", driver_request[13], beg, end);
804 switch (driver_request[13]) {
805 case 1:
806 /* Red book addressing mode = 0:m:s:f */
807 /* FIXME : frame <=> msf conversion routines could be shared
808 * between mscdex and mcicda
810 beg = LOBYTE(LOWORD(beg)) * CDFRAMES_PERMIN +
811 HIBYTE(LOWORD(beg)) * CDFRAMES_PERSEC +
812 LOBYTE(HIWORD(beg));
813 end = LOBYTE(LOWORD(end)) * CDFRAMES_PERMIN +
814 HIBYTE(LOWORD(end)) * CDFRAMES_PERSEC +
815 LOBYTE(HIWORD(end));
816 /* fall through */
817 case 0: /* HSG addressing mode */
818 play.StartingM = beg / CDFRAMES_PERMIN;
819 play.StartingS = (beg / CDFRAMES_PERSEC) % 60;
820 play.StartingF = beg % CDFRAMES_PERSEC;
821 play.EndingM = end / CDFRAMES_PERMIN;
822 play.EndingS = (end / CDFRAMES_PERSEC) % 60;
823 play.EndingF = end % CDFRAMES_PERSEC;
824 DeviceIoControl(h, IOCTL_CDROM_PLAY_AUDIO_MSF, &play, sizeof(play),
825 NULL, 0, &br, NULL);
826 break;
827 default:
828 ERR("Unsupported address mode !!\n");
829 Error = 0x0c;
830 break;
833 break;
835 case 133:
836 if (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) {
837 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
838 TRACE(" --> STOP AUDIO (Paused)\n");
839 } else {
840 DeviceIoControl(h, IOCTL_CDROM_STOP_AUDIO, NULL, 0, NULL, 0, &br, NULL);
841 TRACE(" --> STOP AUDIO (Stopped)\n");
843 break;
845 case 136:
846 TRACE(" --> RESUME AUDIO\n");
847 DeviceIoControl(h, IOCTL_CDROM_PAUSE_AUDIO, NULL, 0, NULL, 0, &br, NULL);
848 break;
850 default:
851 FIXME(" ioctl unimplemented <%d>\n", driver_request[2]);
852 Error = 0x0c;
855 /* setting error codes if any */
856 if (Error < 255) {
857 driver_request[4] |= 0x80;
858 driver_request[3] = Error;
861 CloseHandle(h);
862 /* setting status bits
863 * 3 == playing && done
864 * 1 == done
866 driver_request[4] |=
867 (data.CurrentPosition.Header.AudioStatus == AUDIO_STATUS_IN_PROGRESS) ? 3 : 1;
870 static void MSCDEX_Handler(CONTEXT* context)
872 int drive, count;
873 char* p;
875 switch (LOBYTE(context->Eax)) {
876 case 0x00: /* Installation check */
877 /* Count the number of contiguous CDROM drives
879 for (drive = count = 0; drive < 26; drive++) {
880 if (is_cdrom(drive)) {
881 while (is_cdrom(drive + count)) count++;
882 break;
885 TRACE("Installation check: %d cdroms, starting at %d\n", count, drive);
886 SET_BX( context, count );
887 SET_CX( context, (drive < 26) ? drive : 0 );
888 break;
890 case 0x01: /* get drive device list */
892 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
893 CDROM_DEVICE_HEADER* dev = &cdrom_heap->hdr;
894 SEGPTR ptr_dev = MAKESEGPTR( cdrom_heap->cdrom_selector, FIELD_OFFSET(CDROM_HEAP, hdr) );
896 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
897 for (drive = 0; drive < dev->units; drive++) {
898 *p = drive; /* subunit */
899 ++p;
900 *(DWORD*)p = ptr_dev;
901 p += sizeof(DWORD);
903 TRACE("Get drive device list\n");
905 break;
907 case 0x0B: /* drive check */
908 SET_AX( context, is_cdrom(CX_reg(context)) );
909 SET_BX( context, 0xADAD );
910 break;
912 case 0x0C: /* get version */
913 SET_BX( context, 0x020a );
914 TRACE("Version number => %04x\n", BX_reg(context));
915 break;
917 case 0x0D: /* get drive letters */
918 p = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
919 memset(p, 0, 26);
920 for (drive = 0; drive < 26; drive++) {
921 if (is_cdrom(drive)) *p++ = drive;
923 TRACE("Get drive letters\n");
924 break;
926 case 0x10: /* direct driver access */
928 BYTE* driver_request;
929 CDROM_HEAP* cdrom_heap = CDROM_GetHeap();
931 if (!is_cdrom(CX_reg(context))) {
932 WARN("Request made doesn't match a CD ROM drive (%d)\n", CX_reg(context));
933 SET_CFLAG( context );
934 SET_AX( context, 0x000f ); /* invalid drive */
935 return;
938 driver_request = CTX_SEG_OFF_TO_LIN(context, context->SegEs, context->Ebx);
940 if (!driver_request) {
941 /* FIXME - to be deleted ?? */
942 ERR("ES:BX==0 ! SEGFAULT ?\n");
943 ERR("-->BX=0x%04x, ES=0x%04lx, DS=0x%04lx, CX=0x%04x\n",
944 BX_reg(context), context->SegEs, context->SegDs, CX_reg(context));
945 driver_request[4] |= 0x80;
946 driver_request[3] = 5; /* bad request length */
947 return;
950 driver_request[1] = CX_reg(context) - cdrom_heap->hdr.drive;
951 MSCDEX_Request(driver_request);
953 break;
954 default:
955 FIXME("Unimplemented MSCDEX function 0x%02X.\n", LOBYTE(context->Eax));
956 break;