Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

322 lines
10 KiB

  1. // CONSOLE.H
  2. //
  3. // (C) Copyright Microsoft Corp., 1988-1994
  4. //
  5. // Interfaces for the console
  6. //
  7. // Origin: Chicago
  8. //
  9. // Change history:
  10. //
  11. // Date Who Description
  12. // --------- --------- -------------------------------------------------
  13. // 15-Apr-93 Steve Lewin-Berlin (Cypress Software) created
  14. // 15-Feb-94 JonT Code cleanup and precompiled headers
  15. #include <vmdapriv.h>
  16. // Console flags
  17. // WARNING: Don't change these without updating vcond\vconsole.h
  18. #define CF_FullscreenSizeOK 1 // ON if switch to fullscreen allowed
  19. // (available)
  20. // (available)
  21. #define CF_InputEOF 8 // ON if input EOF not consumed yet
  22. #define CF_Fullscreen 16 // ON if console is in full screen mode
  23. #define CF_ConagentTop 32 // ON if conagent is top level process in console
  24. #define CF_AttributeSet 64 // ON if attribute specified
  25. #define CF_Closing 128 // ON if not accepting new process attaches
  26. #define CF_ConagentWasHere 256 // ON if a kernel-launched conagent successfully rendezvous'd with conapp
  27. #define CF_PendingSetTitle 512 // ON if SetConsoleTitle() message pending
  28. #define CF_ConagentIsDone 1024 // ON if CF_Closing on and conagent is finished
  29. #ifdef NEC_98
  30. #define CF_ForceSetNative 2048 // ON if temporary native mode
  31. #endif //NEC_98
  32. // Returned by VCOND_ReadInput
  33. #define READ_EOF 0x80000000
  34. // Screen buffer state
  35. //
  36. typedef enum _SB_STATE {
  37. SB_PHYSICAL,
  38. SB_NATIVE,
  39. SB_MEMORY
  40. } SB_STATE;
  41. // Screen buffer flags (bit masks)
  42. #define fCursorVisible 1
  43. #define fAttributeValid 2
  44. #define fChanged 4
  45. // Other defaults, etc
  46. #define DEFAULT_ATTRIBUTE 07
  47. #define SetFlag(f, mask) (f |= (mask))
  48. #define ClearFlag(f, mask) (f &= (~mask))
  49. #define TestFlag(f, mask) (f & (mask))
  50. //----------------------------------------------------------------
  51. // Global variables
  52. //----------------------------------------------------------------
  53. extern HANDLE hheapConsole;
  54. //----------------------------------------------------------------
  55. // Macros
  56. //----------------------------------------------------------------
  57. #define Coord2Dword(c) ( * (DWORD *) &(c) )
  58. #define Dword2Coord(c) ( * (COORD *) &(c) )
  59. #define LockConsole(pConsole) EnterCrst(&(pConsole->csCRST))
  60. #define UnlockConsole(pConsole) LeaveCrst(&(pConsole->csCRST));
  61. #define LockSB(pSB) EnterCrst(&(((SCREENBUFFER *)(pSB))->csCRST));
  62. #define UnlockSB(pSB) LeaveCrst(&(((SCREENBUFFER *)(pSB))->csCRST));
  63. #define MAXCOLS 1024
  64. // WARNING: if this definition changes, update the definition in
  65. // VMDOSAPP\TTYNGRAB.C
  66. //
  67. typedef struct _countedattr {
  68. WORD count;
  69. char Attr;
  70. } COUNTEDATTR;
  71. // WARNING: if this definition changes, update the definition in
  72. // VMDOSAPP\TTYNGRAB.C
  73. //
  74. typedef struct _packedline {
  75. COUNTEDATTR *AttribArray; // If not NULL, points to run-length encoded attribute array
  76. char Attrib; // Attribute for entire line if AttribArray is NULL
  77. char ascii[]; // Character data
  78. } PACKEDLINE;
  79. typedef PACKEDLINE *SCREEN[];
  80. //----------------------------------------------------------------
  81. // SCREENBUFFER object
  82. //
  83. // WARNING: if this definition changes, update the definition in
  84. // VMDOSAPP\GRABEMU.ASM
  85. //
  86. typedef struct _screen_buffer {
  87. // WinOldAp references the following fields:
  88. COMMON_OBJECT // base of every object structure
  89. COORD cBufsize; // Number of rows/cols in buffer
  90. SCREEN * Screen; // Screen data
  91. COORD cCursorPosition; // Current position of cursor
  92. DWORD dwCursorSize; // Percent of cursor fill (1 - 100)
  93. SMALL_RECT srWindow; // Window (top, left, bottom, right of visible region)
  94. WORD flags; // Screen buffer flags
  95. // WinOldAp does not reference the rest of the structure
  96. SB_STATE State; // Physical, Native, or Memory
  97. CRST csCRST; // critical section for synching access to internal data
  98. struct _console *pConsole; // Pointer to owning console
  99. WORD wAttribute; // Current default text attribute (color)
  100. DWORD flOutputMode; // Output mode flags
  101. #ifdef NEC_98
  102. BYTE chDBCSLead; // Holds if last string terinated at DBCS lead byte
  103. #endif
  104. } SCREENBUFFER;
  105. #define MAXINCHARS 256 // Number of input characters to buffer
  106. typedef struct _inbuffer {
  107. char cbBuf[MAXINCHARS]; // Input buffer
  108. SHORT curPos[MAXINCHARS]; // Remembers cursor pos
  109. WORD wReadIdx; // Next index to read from
  110. WORD wWriteIdx; // Next index to write to
  111. WORD wBufCount; // Count of characters in buffer
  112. #ifdef DBCS
  113. WORD wStatus; // DBCS status flags
  114. #endif
  115. } INBUFFER;
  116. #ifdef DBCS
  117. // Status flag for DBCS handling
  118. #define BEGIN_TRAILBYTE 0x0001 // Buffer begin with DBCS trail byte
  119. #endif
  120. #define MAXTITLESIZE cbPathMax
  121. //----------------------------------------------------------------
  122. // CONSOLE object
  123. //
  124. // WARNING: if this definition changes, update the definition in
  125. // VMDOSAPP\GRABEMU.ASM and the definition in
  126. // CORE\WIN32\VCOND\VCONSOLE.H
  127. //
  128. typedef struct _console {
  129. // WinOldAp references the following fields:
  130. COMMON_NSOBJECT // base of every object structure - waitable (Input Buffer)
  131. SCREENBUFFER * psbActiveScreenBuffer; // Pointer to active screen buffer (if any)
  132. COORD cMaxSize; // Max size of this console (maintained by WinOldAp)
  133. DWORD flags; // Various console flags
  134. DWORD pidOwner; // pid of first console "owner"
  135. DWORD tidOwner; // tid of first console "owner"
  136. // WinOldAp does not reference the rest of the structure
  137. COORD cOriginalSize; // Size inherited from DOS
  138. CRST csCRST; // critical section for synching access to lists, etc.
  139. struct _lst * plstOwners; // pointer to list of owners (processes)
  140. struct _lst * plstBuffers; // pointer to list of screen buffers
  141. DWORD dwLastExitCode; // Most recent exit code by a process in this console group
  142. char szTitle[MAXTITLESIZE]; // Title (truncated and displayed by WinOldAp)
  143. DWORD VID; // ID used by VCOND
  144. HANDLE hVM; // Process handle of VM which supports this console for i/o
  145. HANDLE hDisplay; // hwnd of display port (used by WinOldAp)
  146. PDB * ppdbControlFocus; // Process which holds current control focus for this console
  147. PDB * ppdbTermConProvider; // console provider to terminate
  148. INBUFFER inbuf; // Input buffer
  149. WORD wDefaultAttribute; // Default screen buffer attribute
  150. struct _evt * evtDoneWithVM; // Signalled when all VM communication done
  151. } CONSOLE;
  152. //----------------------------------------------------------------
  153. // Function Prototypes
  154. //
  155. //----------------------------------------------------------------
  156. // Console
  157. //----------------------------------------------------------------
  158. VOID KERNENTRY SetControlFocus(void);
  159. DWORD KERNENTRY CreateConsole(HANDLE hvm, HANDLE hwnd);
  160. VOID KERNENTRY DisposeConsole(CONSOLE *pConsole);
  161. DWORD KERNENTRY AttachProcessToConsole(CONSOLE *pConsole, PTDB ptdb, PPDB ppdb);
  162. VOID KERNENTRY UnattachProcessFromConsole(CONSOLE *pConsole, PDB *ppdb);
  163. VOID KERNENTRY RemoveOwnerFromList(CONSOLE *pConsole, PDB *ppdb);
  164. DWORD KERNENTRY AddScreenBufferToList(CONSOLE *pConsole, SCREENBUFFER *pSB);
  165. VOID KERNENTRY RemoveScreenBufferFromList(CONSOLE *pConsole, SCREENBUFFER *pSB);
  166. VOID KERNENTRY DisposeScreenBuffer(SCREENBUFFER *pSB);
  167. VOID KERNENTRY SetConsoleStartupInfo(PDB *ppdb, char *szFile);
  168. //----------------------------------------------------------------
  169. // ScreenBuffer (CONSBUF)
  170. //----------------------------------------------------------------
  171. BOOL KERNENTRY SB_SetActive(SCREENBUFFER *pSB);
  172. BOOL KERNENTRY SB_SetCursorPosition(SCREENBUFFER *pSB,
  173. COORD dwCursorPosition);
  174. SCREENBUFFER * KERNENTRY SB_Create(CONSOLE *pConsole,
  175. BOOL bAllocateMemory);
  176. BOOL KERNENTRY SB_GetInfo(SCREENBUFFER *pSB,
  177. CONSOLE_SCREEN_BUFFER_INFO *lpCSBI);
  178. BOOL KERNENTRY SB_SetCursorInfo(SCREENBUFFER *pSB,
  179. CONST CONSOLE_CURSOR_INFO *lpConsoleCursorInfo);
  180. DWORD KERNENTRY SB_StringOut(SCREENBUFFER *pSB,
  181. LPSTR lpBuffer,
  182. DWORD cchToWrite);
  183. VOID KERNENTRY SB_WriteConsoleOutput(SCREENBUFFER *pSB,
  184. CONST CHAR_INFO *lpBuffer,
  185. COORD srcSize,
  186. COORD srcOrigin,
  187. SMALL_RECT *lpsrDest);
  188. VOID KERNENTRY SB_WriteConsoleOutputCharacters(SCREENBUFFER *pSB,
  189. LPCSTR lpBuffer,
  190. DWORD nChars,
  191. COORD cLoc);
  192. VOID KERNENTRY SB_ReadConsoleOutputCharacters(SCREENBUFFER *pSB,
  193. LPSTR lpCharacter,
  194. DWORD nLength,
  195. COORD cLoc);
  196. VOID KERNENTRY SB_ReadConsoleOutputAttributes(SCREENBUFFER *pSB,
  197. LPWORD lpAttribute,
  198. DWORD nLength,
  199. COORD cLoc);
  200. VOID KERNENTRY SB_FillConsoleOutputAttribute(SCREENBUFFER *pSB,
  201. WORD wAttribute,
  202. DWORD nLength,
  203. COORD cLoc);
  204. VOID KERNENTRY SB_WriteAttribute(SCREENBUFFER *pSB,
  205. CONST WORD *lpAttribute,
  206. DWORD nLength,
  207. COORD cLoc);
  208. VOID KERNENTRY SB_GetCursorInfo(SCREENBUFFER *pSB,
  209. PCONSOLE_CURSOR_INFO lpConsoleCursorInfo);
  210. VOID KERNENTRY SB_FillConsoleOutputCharacter(SCREENBUFFER *pSB,
  211. char cCharacter,
  212. DWORD nLength,
  213. COORD cLoc);
  214. VOID KERNENTRY SB_SetAttribute(SCREENBUFFER *pSB,
  215. WORD attr);
  216. VOID KERNENTRY SB_ReadOutput(SCREENBUFFER *pSB,
  217. PCHAR_INFO lpBuffer,
  218. COORD dwBufferSize,
  219. COORD dwBufferCoord,
  220. PSMALL_RECT lpReadRegion);
  221. BOOL KERNENTRY SB_Scroll(SCREENBUFFER *pSB,
  222. CONST SMALL_RECT *psrScroll,
  223. CONST SMALL_RECT *psrClip,
  224. COORD cDest,
  225. CONST CHAR_INFO *pciFill);
  226. BOOL KERNENTRY SB_SetWindow(SCREENBUFFER *pSB,
  227. BOOL bAbsolute,
  228. CONST SMALL_RECT *psrWindow);
  229. DWORD KERNENTRY SB_GetLargestConsole(SCREENBUFFER *pSB);
  230. BOOL KERNENTRY SB_SetSize(SCREENBUFFER *pSB, COORD cSize);
  231. HANDLE KERNENTRY NewHandleToActiveScreenBuffer(PDB *ppdb);
  232. HANDLE KERNENTRY NewHandleToInputBuffer(PDB *ppdb);
  233. CONSOLE * KERNENTRY CreateNewConsole(WORD wShowWindow);
  234. BOOL KERNENTRY FInitConsoleHeap(void);
  235. VOID KERNENTRY TerminateConsoleHeap(VOID);
  236. VOID * KERNENTRY ConsoleAlloc(DWORD cbSize);
  237. VOID * KERNENTRY ConsoleAlloc0(DWORD cbSize);
  238. BOOL KERNENTRY ConsoleFree(VOID *pvMem);
  239. VOID KERNENTRY SB_ReturnToPhysical(CONSOLE *pConsole);
  240. BOOL KERNENTRY SB_ForceToPhysical(CONSOLE *pConsole);
  241. BOOL KERNENTRY InternalReadConsoleChars(CONSOLE * pConsole,
  242. LPSTR lpBuffer,
  243. DWORD cchToRead,
  244. LPDWORD lpNumberOfCharsRead);
  245.