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