Add support for interrupts in 32-bit code.
[wine/multimedia.git] / include / miscemu.h
blob31464f8bb9084438f9a535d44965adcb3c47b242
1 /*
2 * Misc. emulation definitions
4 * Copyright 1995 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __WINE_MISCEMU_H
22 #define __WINE_MISCEMU_H
24 #include "winnt.h"
25 #include "selectors.h"
26 #include "wine/windef16.h"
28 /* msdos/dosconf.c */
29 extern int DOSCONF_ReadConfig(void);
31 /* msdos/dosmem.c */
32 #include "pshpack1.h"
34 typedef struct
36 WORD Com1Addr; /* 00: COM1 I/O address */
37 WORD Com2Addr; /* 02: COM2 I/O address */
38 WORD Com3Addr; /* 04: COM3 I/O address */
39 WORD Com4Addr; /* 06: COM4 I/O address */
40 WORD Lpt1Addr; /* 08: LPT1 I/O address */
41 WORD Lpt2Addr; /* 0a: LPT2 I/O address */
42 WORD Lpt3Addr; /* 0c: LPT3 I/O address */
43 WORD Lpt4Addr; /* 0e: LPT4 I/O address */
44 WORD InstalledHardware; /* 10: Installed hardware flags */
45 BYTE POSTstatus; /* 12: Power-On Self Test status */
46 WORD MemSize WINE_PACKED; /* 13: Base memory size in Kb */
47 WORD unused1 WINE_PACKED; /* 15: Manufacturing test scratch pad */
48 BYTE KbdFlags1; /* 17: Keyboard flags 1 */
49 BYTE KbdFlags2; /* 18: Keyboard flags 2 */
50 BYTE unused2; /* 19: Keyboard driver workspace */
51 WORD NextKbdCharPtr; /* 1a: Next character in kbd buffer */
52 WORD FirstKbdCharPtr; /* 1c: First character in kbd buffer */
53 WORD KbdBuffer[16]; /* 1e: Keyboard buffer */
54 BYTE DisketteStatus1; /* 3e: Diskette recalibrate status */
55 BYTE DisketteStatus2; /* 3f: Diskette motor status */
56 BYTE DisketteStatus3; /* 40: Diskette motor timeout */
57 BYTE DisketteStatus4; /* 41: Diskette last operation status */
58 BYTE DiskStatus[7]; /* 42: Disk status/command bytes */
59 BYTE VideoMode; /* 49: Video mode */
60 WORD VideoColumns; /* 4a: Number of columns */
61 WORD VideoPageSize; /* 4c: Video page size in bytes */
62 WORD VideoPageStartAddr; /* 4e: Video page start address */
63 BYTE VideoCursorPos[16]; /* 50: Cursor position for 8 pages, column/row order */
64 WORD VideoCursorType; /* 60: Video cursor type */
65 BYTE VideoCurPage; /* 62: Video current page */
66 WORD VideoCtrlAddr WINE_PACKED; /* 63: Video controller address */
67 BYTE VideoReg1; /* 65: Video mode select register */
68 BYTE VideoReg2; /* 66: Video CGA palette register */
69 DWORD ResetEntry WINE_PACKED; /* 67: Warm reset entry point */
70 BYTE LastIRQ; /* 6b: Last unexpected interrupt */
71 DWORD Ticks; /* 6c: Ticks since midnight */
72 BYTE TicksOverflow; /* 70: Timer overflow if past midnight */
73 BYTE CtrlBreakFlag; /* 71: Ctrl-Break flag */
74 WORD ResetFlag; /* 72: POST Reset flag */
75 BYTE DiskOpStatus; /* 74: Last hard-disk operation status */
76 BYTE NbHardDisks; /* 75: Number of hard disks */
77 BYTE DiskCtrlByte; /* 76: Disk control byte */
78 BYTE DiskIOPort; /* 77: Disk I/O port offset */
79 BYTE LptTimeout[4]; /* 78: Timeouts for parallel ports */
80 BYTE ComTimeout[4]; /* 7c: Timeouts for serial ports */
81 WORD KbdBufferStart; /* 80: Keyboard buffer start */
82 WORD KbdBufferEnd; /* 82: Keyboard buffer end */
83 BYTE RowsOnScreenMinus1; /* 84: EGA only */
84 WORD BytesPerChar WINE_PACKED; /* 85: EGA only */
85 BYTE ModeOptions; /* 87: EGA only */
86 BYTE FeatureBitsSwitches; /* 88: EGA only */
87 BYTE VGASettings; /* 89: VGA misc settings */
88 BYTE DisplayCombination; /* 8A: VGA display combinations */
89 BYTE DiskDataRate; /* 8B: Last disk data rate selected */
90 } BIOSDATA;
92 typedef struct
94 DWORD StaticFuncTable; /* 00: static functionality table */
95 BYTE VideoMode; /* 04: video mode in effect */
96 WORD NumberColumns; /* 05: number of columns */
97 WORD RegenBufLen; /* 07: length of regen buffer in bytes */
98 WORD RegenBufAddr; /* 09: starting address of regen buffer */
99 WORD CursorPos[8]; /* 0B: cursor position for page 0..7 */
100 WORD CursorType; /* 1B: cursor "type" (start/stop scan lines) */
101 BYTE ActivePage; /* 1D: active display page */
102 WORD CRTCPort; /* 1E: CRTC port address */
103 BYTE Port3x8; /* 20: current setting of PORT 03x8h */
104 BYTE Port3x9; /* 21: current setting of PORT 03x9h */
105 BYTE NumberRows; /* 22: number of rows - 1 */
106 WORD BytesPerChar; /* 23: bytes/character */
107 BYTE DCCActive; /* 25: display combination code of active display */
108 BYTE DCCAlternate; /* 26: DCC of alternate display */
109 WORD NumberColors; /* 27: number of colors supported in current mode (0000h = mono) */
110 BYTE NumberPages; /* 29: number of pages supported in current mode */
111 BYTE NumberScanlines; /* 2A: number of scan lines active */
112 BYTE CharBlockPrimary; /* 2B: primary character block */
113 BYTE CharBlockSecondary; /* 2C: secondary character block */
114 BYTE MiscFlags; /* 2D: miscellaneous flags */
115 BYTE NonVGASupport; /* 2E: non-VGA mode support */
116 BYTE _reserved1[2]; /* 2F: */
117 BYTE VideoMem; /* 31: video memory available */
118 BYTE SavePointerState; /* 32: save pointer state flags */
119 BYTE DisplayStatus; /* 33: display information and status */
120 BYTE _reserved2[12]; /* 34: */
122 } VIDEOSTATE;
124 typedef struct
126 BYTE ModeSupport[7]; /* 00: modes supported 1..7 */
127 BYTE ScanlineSupport; /* 07: scan lines supported */
128 BYTE NumberCharBlocks; /* 08: total number of character blocks */
129 BYTE ActiveCharBlocks; /* 09: max. number of active character blocks */
130 WORD MiscFlags; /* 0A: miscellaneous function support flags */
131 WORD _reserved1; /* 0C: */
132 BYTE SavePointerFlags; /* 0E: save pointer function flags */
133 BYTE _reserved2; /* OF: */
135 } VIDEOFUNCTIONALITY;
137 typedef struct
139 DWORD Signature;
140 BYTE Minor;
141 BYTE Major;
142 DWORD StaticVendorString;
143 DWORD CapabilitiesFlags;
144 DWORD StaticModeList;
145 } VESAINFO;
147 /* layout of BIOS extra data starting at f000:e000 */
148 typedef struct
150 VIDEOFUNCTIONALITY vid_func;
151 VIDEOSTATE vid_state;
152 VESAINFO vesa_info;
153 char vesa_string[32];
154 WORD vesa_modes[40];
155 } BIOS_EXTRA;
157 #define BIOS_EXTRA_PTR ((BIOS_EXTRA *)0xfe000)
158 #define BIOS_EXTRA_SEGPTR MAKESEGPTR(0xf000,0xe000)
160 #include "poppack.h"
162 extern WORD DOSMEM_0000H;
163 extern WORD DOSMEM_BiosDataSeg;
164 extern WORD DOSMEM_BiosSysSeg;
165 extern DWORD DOSMEM_CollateTable;
167 /* various real-mode code stubs */
168 struct DPMI_segments
170 WORD wrap_seg;
171 WORD xms_seg;
172 WORD dpmi_seg;
173 WORD dpmi_sel;
174 WORD int48_seg;
175 WORD int48_sel;
178 /* 48-bit segmented pointers for DOS DPMI32 */
179 typedef struct {
180 WORD selector;
181 DWORD offset;
182 } SEGPTR48, FARPROC48;
184 extern struct DPMI_segments DOSMEM_dpmi_segments;
185 extern const struct DPMI_segments *DOSMEM_GetDPMISegments(void);
187 extern BOOL DOSMEM_Init(BOOL);
188 extern void DOSMEM_Tick(WORD timer);
189 extern WORD DOSMEM_AllocSelector(WORD);
190 extern LPVOID DOSMEM_GetBlock(UINT size, WORD* p);
191 extern BOOL DOSMEM_FreeBlock(void* ptr);
192 extern LPVOID DOSMEM_ResizeBlock(void* ptr, UINT size, WORD* p);
193 extern UINT DOSMEM_Available(void);
194 extern LPVOID DOSMEM_MapRealToLinear(DWORD); /* real-mode to linear */
195 extern LPVOID DOSMEM_MapDosToLinear(UINT); /* linear DOS to Wine */
196 extern UINT DOSMEM_MapLinearToDos(LPVOID); /* linear Wine to DOS */
198 /* memory/instr.c */
199 extern BOOL INSTR_EmulateInstruction( CONTEXT86 *context );
201 /* msdos/interrupts.c */
202 typedef void (WINAPI *INTPROC)(CONTEXT86*);
203 extern FARPROC16 INT_GetPMHandler( BYTE intnum );
204 extern void INT_SetPMHandler( BYTE intnum, FARPROC16 handler );
205 extern FARPROC48 INT_GetPMHandler48( BYTE intnum );
206 extern void INT_SetPMHandler48( BYTE intnum, FARPROC48 handler );
208 /* msdos/ioports.c */
209 extern DWORD IO_inport( int port, int count );
210 extern void IO_outport( int port, int count, DWORD value );
212 /* msdos/int11.c */
213 extern void WINAPI INT_Int11Handler(CONTEXT86*);
215 /* msdos/int12.c */
216 extern void WINAPI INT_Int12Handler(CONTEXT86*);
218 /* msdos/int13.c */
219 extern void WINAPI INT_Int13Handler(CONTEXT86*);
221 /* msdos/int15.c */
222 extern void WINAPI INT_Int15Handler(CONTEXT86*);
224 /* msdos/int1a.c */
225 extern DWORD INT1A_GetTicksSinceMidnight(void);
226 extern void WINAPI INT_Int1aHandler(CONTEXT86*);
228 /* msdos/int20.c */
229 extern void WINAPI INT_Int20Handler(CONTEXT86*);
231 /* msdos/int25.c */
232 extern void WINAPI INT_Int25Handler(CONTEXT86*);
234 /* msdos/int26.c */
235 extern void WINAPI INT_Int26Handler(CONTEXT86*);
237 /* msdos/int2a.c */
238 extern void WINAPI INT_Int2aHandler(CONTEXT86*);
240 /* msdos/int2f.c */
241 extern void WINAPI INT_Int2fHandler(CONTEXT86*);
243 /* fpu.c */
244 extern void WINAPI INT_Int34Handler(CONTEXT86*);
245 extern void WINAPI INT_Int35Handler(CONTEXT86*);
246 extern void WINAPI INT_Int36Handler(CONTEXT86*);
247 extern void WINAPI INT_Int37Handler(CONTEXT86*);
248 extern void WINAPI INT_Int38Handler(CONTEXT86*);
249 extern void WINAPI INT_Int39Handler(CONTEXT86*);
250 extern void WINAPI INT_Int3aHandler(CONTEXT86*);
251 extern void WINAPI INT_Int3bHandler(CONTEXT86*);
252 extern void WINAPI INT_Int3cHandler(CONTEXT86*);
253 extern void WINAPI INT_Int3dHandler(CONTEXT86*);
254 extern void WINAPI INT_Int3eHandler(CONTEXT86*);
256 /* msdos/dpmi.c */
257 typedef void (WINAPI *RMCBPROC)(CONTEXT86*);
258 extern void WINAPI INT_Int31Handler(CONTEXT86*);
259 extern BOOL DPMI_LoadDosSystem(void);
260 extern FARPROC16 WINAPI DPMI_AllocInternalRMCB(RMCBPROC);
261 extern void WINAPI DPMI_FreeInternalRMCB(FARPROC16);
262 extern int DPMI_CallRMProc(CONTEXT86*,LPWORD,int,int);
264 /* misc/ppdev.c */
266 extern BOOL IO_pp_outp(int port, DWORD* res);
267 extern int IO_pp_inp(int port, DWORD* res);
268 extern char IO_pp_init(void);
270 #define PTR_REAL_TO_LIN(seg,off) \
271 ((void*)(((unsigned int)(seg) << 4) + LOWORD(off)))
273 /* NOTE: Interrupts might get called from three modes: real mode, 16-bit, and
274 * (via DeviceIoControl) 32-bit. For automatic conversion of pointer
275 * parameters, interrupt handlers should use CTX_SEG_OFF_TO_LIN with
276 * the contents of a segment register as second and the contents of
277 * a *32-bit* general register as third parameter, e.g.
278 * CTX_SEG_OFF_TO_LIN( context, DS_reg(context), EDX_reg(context) )
279 * This will generate a linear pointer in all three cases:
280 * Real-Mode: Seg*16 + LOWORD(Offset)
281 * 16-bit: convert (Seg, LOWORD(Offset)) to linear
282 * 32-bit: use Offset as linear address (DeviceIoControl!)
284 * Real-mode is recognized by checking the V86 bit in the flags register,
285 * 32-bit mode is recognized by checking whether 'seg' is a system selector
286 * (0 counts also as 32-bit segment).
288 #define CTX_SEG_OFF_TO_LIN(context,seg,off) \
289 (ISV86(context) ? PTR_REAL_TO_LIN((seg),(off)) : \
290 (!seg || IS_SELECTOR_SYSTEM(seg))? (void *)(ULONG_PTR)(off) : MapSL(MAKESEGPTR((seg),(off))))
292 #define INT_BARF(context,num) \
293 ERR( "int%x: unknown/not implemented parameters:\n" \
294 "int%x: AX %04x, BX %04x, CX %04x, DX %04x, " \
295 "SI %04x, DI %04x, DS %04x, ES %04x\n", \
296 (num), (num), LOWORD((context)->Eax), LOWORD((context)->Ebx), \
297 LOWORD((context)->Ecx), LOWORD((context)->Edx), LOWORD((context)->Esi), \
298 LOWORD((context)->Edi), (WORD)(context)->SegDs, (WORD)(context)->SegEs )
300 /* Macros for easier access to i386 context registers */
302 #define AX_reg(context) ((WORD)(context)->Eax)
303 #define BX_reg(context) ((WORD)(context)->Ebx)
304 #define CX_reg(context) ((WORD)(context)->Ecx)
305 #define DX_reg(context) ((WORD)(context)->Edx)
306 #define SI_reg(context) ((WORD)(context)->Esi)
307 #define DI_reg(context) ((WORD)(context)->Edi)
309 #define AL_reg(context) ((BYTE)(context)->Eax)
310 #define AH_reg(context) ((BYTE)((context)->Eax >> 8))
311 #define BL_reg(context) ((BYTE)(context)->Ebx)
312 #define BH_reg(context) ((BYTE)((context)->Ebx >> 8))
313 #define CL_reg(context) ((BYTE)(context)->Ecx)
314 #define CH_reg(context) ((BYTE)((context)->Ecx >> 8))
315 #define DL_reg(context) ((BYTE)(context)->Edx)
316 #define DH_reg(context) ((BYTE)((context)->Edx >> 8))
318 #define SET_CFLAG(context) ((context)->EFlags |= 0x0001)
319 #define RESET_CFLAG(context) ((context)->EFlags &= ~0x0001)
320 #define SET_ZFLAG(context) ((context)->EFlags |= 0x0040)
321 #define RESET_ZFLAG(context) ((context)->EFlags &= ~0x0040)
322 #define ISV86(context) ((context)->EFlags & 0x00020000)
324 #define SET_AX(context,val) ((context)->Eax = ((context)->Eax & ~0xffff) | (WORD)(val))
325 #define SET_BX(context,val) ((context)->Ebx = ((context)->Ebx & ~0xffff) | (WORD)(val))
326 #define SET_CX(context,val) ((context)->Ecx = ((context)->Ecx & ~0xffff) | (WORD)(val))
327 #define SET_DX(context,val) ((context)->Edx = ((context)->Edx & ~0xffff) | (WORD)(val))
328 #define SET_SI(context,val) ((context)->Esi = ((context)->Esi & ~0xffff) | (WORD)(val))
329 #define SET_DI(context,val) ((context)->Edi = ((context)->Edi & ~0xffff) | (WORD)(val))
331 #define SET_AL(context,val) ((context)->Eax = ((context)->Eax & ~0xff) | (BYTE)(val))
332 #define SET_BL(context,val) ((context)->Ebx = ((context)->Ebx & ~0xff) | (BYTE)(val))
333 #define SET_CL(context,val) ((context)->Ecx = ((context)->Ecx & ~0xff) | (BYTE)(val))
334 #define SET_DL(context,val) ((context)->Edx = ((context)->Edx & ~0xff) | (BYTE)(val))
336 #define SET_AH(context,val) ((context)->Eax = ((context)->Eax & ~0xff00) | (((BYTE)(val)) << 8))
337 #define SET_BH(context,val) ((context)->Ebx = ((context)->Ebx & ~0xff00) | (((BYTE)(val)) << 8))
338 #define SET_CH(context,val) ((context)->Ecx = ((context)->Ecx & ~0xff00) | (((BYTE)(val)) << 8))
339 #define SET_DH(context,val) ((context)->Edx = ((context)->Edx & ~0xff00) | (((BYTE)(val)) << 8))
341 #endif /* __WINE_MISCEMU_H */