Release 960114
[wine/gsoc-2012-control.git] / miscemu / dosmem.c
blob4568eb8ecd0bb4fe5cd7af51900114b8b2fab6cf
1 /*
2 * DOS memory emulation
4 * Copyright 1995 Alexandre Julliard
5 */
7 #include <signal.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "windows.h"
12 #include "global.h"
13 #include "ldt.h"
14 #include "miscemu.h"
15 #include "module.h"
16 #include "xmalloc.h"
19 HANDLE DOSMEM_BiosSeg; /* BIOS data segment at 0x40:0 */
22 #pragma pack(1)
24 typedef struct
26 WORD Com1Addr; /* 00: COM1 I/O address */
27 WORD Com2Addr; /* 02: COM2 I/O address */
28 WORD Com3Addr; /* 04: COM3 I/O address */
29 WORD Com4Addr; /* 06: COM4 I/O address */
30 WORD Lpt1Addr; /* 08: LPT1 I/O address */
31 WORD Lpt2Addr; /* 0a: LPT2 I/O address */
32 WORD Lpt3Addr; /* 0c: LPT3 I/O address */
33 WORD Lpt4Addr; /* 0e: LPT4 I/O address */
34 WORD InstalledHardware; /* 10: Installed hardware flags */
35 BYTE POSTstatus; /* 12: Power-On Self Test status */
36 WORD MemSize WINE_PACKED; /* 13: Base memory size in Kb */
37 WORD unused1 WINE_PACKED; /* 15: Manufacturing test scratch pad */
38 BYTE KbdFlags1; /* 17: Keyboard flags 1 */
39 BYTE KbdFlags2; /* 18: Keyboard flags 2 */
40 BYTE unused2; /* 19: Keyboard driver workspace */
41 WORD NextKbdCharPtr; /* 1a: Next character in kbd buffer */
42 WORD FirstKbdCharPtr; /* 1c: First character in kbd buffer */
43 WORD KbdBuffer[16]; /* 1e: Keyboard buffer */
44 BYTE DisketteStatus1; /* 3e: Diskette recalibrate status */
45 BYTE DisketteStatus2; /* 3f: Diskette motor status */
46 BYTE DisketteStatus3; /* 40: Diskette motor timeout */
47 BYTE DisketteStatus4; /* 41: Diskette last operation status */
48 BYTE DiskStatus[7]; /* 42: Disk status/command bytes */
49 BYTE VideoMode; /* 49: Video mode */
50 WORD VideoColumns; /* 4a: Number of columns */
51 WORD VideoPageSize; /* 4c: Video page size in bytes */
52 WORD VideoPageStartAddr; /* 4e: Video page start address */
53 BYTE VideoCursorPos[16]; /* 50: Cursor position for 8 pages */
54 WORD VideoCursorType; /* 60: Video cursor type */
55 BYTE VideoCurPage; /* 62: Video current page */
56 WORD VideoCtrlAddr WINE_PACKED; /* 63: Video controller address */
57 BYTE VideoReg1; /* 65: Video mode select register */
58 BYTE VideoReg2; /* 66: Video CGA palette register */
59 DWORD ResetEntry WINE_PACKED; /* 67: Warm reset entry point */
60 BYTE LastIRQ; /* 6b: Last unexpected interrupt */
61 DWORD Ticks; /* 6c: Ticks since midnight */
62 BYTE TicksOverflow; /* 70: Timer overflow if past midnight */
63 BYTE CtrlBreakFlag; /* 71: Ctrl-Break flag */
64 WORD ResetFlag; /* 72: POST Reset flag */
65 BYTE DiskOpStatus; /* 74: Last hard-disk operation status */
66 BYTE NbHardDisks; /* 75: Number of hard disks */
67 BYTE DiskCtrlByte; /* 76: Disk control byte */
68 BYTE DiskIOPort; /* 77: Disk I/O port offset */
69 BYTE LptTimeout[4]; /* 78: Timeouts for parallel ports */
70 BYTE ComTimeout[4]; /* 7c: Timeouts for serial ports */
71 WORD KbdBufferStart; /* 80: Keyboard buffer start */
72 WORD KbdBufferEnd; /* 82: Keyboard buffer end */
73 } BIOSDATA;
75 #pragma pack(4)
78 static BIOSDATA *pBiosData = NULL;
81 /***********************************************************************
82 * DOSMEM_Init
84 * Create the dos memory segments, and store them into the KERNEL
85 * exported values. MODULE_Init() must already have been called.
87 BOOL DOSMEM_Init(void)
89 HMODULE hModule = GetModuleHandle( "KERNEL" );
90 char *dosmem;
92 /* Allocate 7 64k segments for 0000, A000, B000, C000, D000, E000, F000. */
94 dosmem = xmalloc( 0x70000 );
96 MODULE_SetEntryPoint( hModule, 183, /* KERNEL.183: __0000H */
97 GLOBAL_CreateBlock( GMEM_FIXED, dosmem,
98 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
99 DOSMEM_BiosSeg = GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x400, 0x100,
100 hModule, FALSE, FALSE, FALSE, NULL );
102 MODULE_SetEntryPoint( hModule, 193, /* KERNEL.193: __0040H */
103 DOSMEM_BiosSeg );
104 MODULE_SetEntryPoint( hModule, 174, /* KERNEL.174: __A000H */
105 GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x10000,
106 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
107 MODULE_SetEntryPoint( hModule, 181, /* KERNEL.181: __B000H */
108 GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x20000,
109 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
110 MODULE_SetEntryPoint( hModule, 182, /* KERNEL.182: __B800H */
111 GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x28000,
112 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
113 MODULE_SetEntryPoint( hModule, 195, /* KERNEL.195: __C000H */
114 GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x30000,
115 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
116 MODULE_SetEntryPoint( hModule, 179, /* KERNEL.179: __D000H */
117 GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x40000,
118 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
119 MODULE_SetEntryPoint( hModule, 190, /* KERNEL.190: __E000H */
120 GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x50000,
121 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
122 MODULE_SetEntryPoint( hModule, 173, /* KERNEL.173: __ROMBIOS */
123 GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x60000,
124 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
125 MODULE_SetEntryPoint( hModule, 194, /* KERNEL.194: __F000H */
126 GLOBAL_CreateBlock( GMEM_FIXED, dosmem + 0x60000,
127 0x10000, hModule, FALSE, FALSE, FALSE, NULL ));
128 DOSMEM_FillBiosSegment();
130 return TRUE;
134 /***********************************************************************
135 * DOSMEM_Alarm
137 * Increment the BIOS tick counter.
139 static void DOSMEM_Alarm(void)
141 pBiosData->Ticks = INT1A_GetTicksSinceMidnight();
142 printf( "Ticks = %ld\n", pBiosData->Ticks );
144 signal( SIGALRM, DOSMEM_Alarm );
145 alarm( 1 );
150 /***********************************************************************
151 * DOSMEM_FillBiosSegment
153 * Fill the BIOS data segment with dummy values.
155 void DOSMEM_FillBiosSegment(void)
157 pBiosData = (BIOSDATA *)GlobalLock( DOSMEM_BiosSeg );
159 /* Clear all unused values */
160 memset( pBiosData, 0, sizeof(*pBiosData) );
162 /* FIXME: should check the number of configured drives and ports */
164 pBiosData->Com1Addr = 0x3e8;
165 pBiosData->Com2Addr = 0x2e8;
166 pBiosData->Lpt1Addr = 0x378;
167 pBiosData->Lpt2Addr = 0x278;
168 pBiosData->InstalledHardware = 0x8443;
169 pBiosData->MemSize = 640;
170 pBiosData->NextKbdCharPtr = 0x1e;
171 pBiosData->FirstKbdCharPtr = 0x1e;
172 pBiosData->VideoMode = 0;
173 pBiosData->VideoColumns = 80;
174 pBiosData->VideoPageSize = 80 * 25 * 2;
175 pBiosData->VideoPageStartAddr = 0xb800;
176 pBiosData->VideoCtrlAddr = 0x3d4;
177 pBiosData->Ticks = INT1A_GetTicksSinceMidnight();
178 pBiosData->NbHardDisks = 2;
179 pBiosData->KbdBufferStart = 0x1e;
180 pBiosData->KbdBufferEnd = 0x3e;
183 signal( SIGALRM, DOSMEM_Alarm );
184 alarm( 1 );