Release 960114
[wine] / miscemu / interrupts.c
1 /*
2  * Interrupt vectors emulation
3  *
4  * Copyright 1995 Alexandre Julliard
5  */
6
7 #include "windows.h"
8 #include "drive.h"
9 #include "miscemu.h"
10 #include "msdos.h"
11 #include "module.h"
12 #include "registers.h"
13 #include "stackframe.h"
14 #include "stddebug.h"
15 #include "debug.h"
16
17 static SEGPTR INT_Vectors[256];
18
19   /* Ordinal number for interrupt 0 handler in WINPROCS.DLL */
20 #define FIRST_INTERRUPT_ORDINAL 100
21
22
23 /**********************************************************************
24  *          INT_Init
25  */
26 BOOL INT_Init(void)
27 {
28     WORD vector;
29     HMODULE hModule = GetModuleHandle( "WINPROCS" );
30
31     for (vector = 0; vector < 256; vector++)
32     {
33         if (!(INT_Vectors[vector] = MODULE_GetEntryPoint( hModule,
34                                              FIRST_INTERRUPT_ORDINAL+vector )))
35         {
36             fprintf(stderr,"Internal error: no vector for int %02x\n",vector);
37             return FALSE;
38         }
39     }
40     return TRUE;
41 }
42
43
44 /**********************************************************************
45  *          INT_GetHandler
46  *
47  * Return the interrupt vector for a given interrupt.
48  */
49 SEGPTR INT_GetHandler( BYTE intnum )
50 {
51     return INT_Vectors[intnum];
52 }
53
54
55 /**********************************************************************
56  *          INT_SetHandler
57  *
58  * Set the interrupt handler for a given interrupt.
59  */
60 void INT_SetHandler( BYTE intnum, SEGPTR handler )
61 {
62     dprintf_int( stddeb, "Set interrupt vector %02x <- %04x:%04x\n",
63                  intnum, HIWORD(handler), LOWORD(handler) );
64     INT_Vectors[intnum] = handler;
65 }
66
67
68 /**********************************************************************
69  *          INT_DummyHandler
70  */
71 void INT_DummyHandler( struct sigcontext_struct context )
72 {
73     INT_BARF( &context,
74               CURRENT_STACK16->ordinal_number - FIRST_INTERRUPT_ORDINAL );
75 }
76
77
78 /**********************************************************************
79  *          INT_Int11Handler
80  *
81  * Handler for int 11h (get equipment list).
82  */
83 void INT_Int11Handler( struct sigcontext_struct context )
84 {
85     int diskdrives = 0;
86     int parallelports = 0;
87     int serialports = 0;
88     int x;
89
90 /* borrowed from Ralph Brown's interrupt lists 
91
92                     bits 15-14: number of parallel devices
93                     bit     13: [Conv] Internal modem
94                     bit     12: reserved
95                     bits 11- 9: number of serial devices
96                     bit      8: reserved
97                     bits  7- 6: number of diskette drives minus one
98                     bits  5- 4: Initial video mode:
99                                     00b = EGA,VGA,PGA
100                                     01b = 40 x 25 color
101                                     10b = 80 x 25 color
102                                     11b = 80 x 25 mono
103                     bit      3: reserved
104                     bit      2: [PS] =1 if pointing device
105                                 [non-PS] reserved
106                     bit      1: =1 if math co-processor
107                     bit      0: =1 if diskette available for boot
108 */
109 /*  Currently the only of these bits correctly set are:
110                 bits 15-14              } Added by William Owen Smith, 
111                 bits 11-9               } wos@dcs.warwick.ac.uk
112                 bits 7-6
113                 bit  2                  (always set)
114 */
115
116     if (DRIVE_IsValid(0)) diskdrives++;
117     if (DRIVE_IsValid(1)) diskdrives++;
118     if (diskdrives) diskdrives--;
119         
120     for (x=0; x!=MAX_PORTS; x++)
121     {
122         if (COM[x].devicename)
123             serialports++;
124         if (LPT[x].devicename)
125             parallelports++;
126     }
127     if (serialports > 7)                /* 3 bits -- maximum value = 7 */
128         serialports=7;
129     if (parallelports > 3)              /* 2 bits -- maximum value = 3 */
130         parallelports=3;
131     
132     AX_reg(&context) = (diskdrives << 6) | (serialports << 9) | 
133                        (parallelports << 14) | 0x02;
134 }
135
136
137 /**********************************************************************
138  *          INT_Int12Handler
139  *
140  * Handler for int 12h (get memory size).
141  */
142 void INT_Int12Handler( struct sigcontext_struct context )
143 {
144     AX_reg(&context) = 640;
145 }
146
147
148 /**********************************************************************
149  *          INT_Int15Handler
150  *
151  * Handler for int 15h.
152  */
153 void INT_Int15Handler( struct sigcontext_struct context )
154 {
155     INT_BARF( &context, 0x15 );
156 }
157
158
159 /**********************************************************************
160  *          INT_Int16Handler
161  *
162  * Handler for int 16h (keyboard).
163  */
164 void INT_Int16Handler( struct sigcontext_struct context )
165 {
166     INT_BARF( &context, 0x16 );
167 }