basevid.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*++
  2. Copyright (c) 2013 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. basevid.h
  9. Abstract:
  10. This header contains definitions for the base video library, which can
  11. print text onto a frame buffer.
  12. Author:
  13. Evan Green 30-Jan-2013
  14. --*/
  15. //
  16. // ------------------------------------------------------------------- Includes
  17. //
  18. //
  19. // --------------------------------------------------------------------- Macros
  20. //
  21. #define BASE_VIDEO_ATTRIBUTES(_ForegroundColor, _BackgroundColor) \
  22. ((_ForegroundColor) | ((_BackgroundColor) << BASE_VIDEO_BACKGROUND_SHIFT))
  23. //
  24. // This macro creates a base video color from red, green and blue components.
  25. // Valid values are between 0 and 255.
  26. //
  27. #define BASE_VIDEO_COLOR_RGB(_Red, _Green, _Blue) \
  28. ((((ULONG)(_Red) << 16) & 0x00FF0000) | \
  29. (((ULONG)(_Green) << 8) & 0x0000FF00) | \
  30. ((ULONG)(_Blue) & 0x000000FF))
  31. //
  32. // ---------------------------------------------------------------- Definitions
  33. //
  34. //
  35. // Define the attributes.
  36. //
  37. #define BASE_VIDEO_BACKGROUND_SHIFT 4
  38. #define BASE_VIDEO_COLOR_MASK 0x0F
  39. #define BASE_VIDEO_FOREGROUND_BOLD 0x0100
  40. #define BASE_VIDEO_BACKGROUND_BOLD 0x0200
  41. #define BASE_VIDEO_NEGATIVE 0x0400
  42. #define BASE_VIDEO_CURSOR 0x0800
  43. //
  44. // Define base video font flags.
  45. //
  46. //
  47. // Set this flag if the data is rotated by 90 degrees. That is, the first byte
  48. // contains the first column of data, rather than the first rows. This is done
  49. // to save space (as a 5x7 character can be listed as 5 bytes rather than 7).
  50. // The maximum sized font allowing rotation is 8x8.
  51. //
  52. #define BASE_VIDEO_FONT_ROTATED 0x00000001
  53. //
  54. // ------------------------------------------------------ Data Type Definitions
  55. //
  56. typedef ULONG BASE_VIDEO_COLOR, *PBASE_VIDEO_COLOR;
  57. typedef enum _ANSI_COLOR {
  58. AnsiColorDefault,
  59. AnsiColorBlack,
  60. AnsiColorRed,
  61. AnsiColorGreen,
  62. AnsiColorYellow,
  63. AnsiColorBlue,
  64. AnsiColorMagenta,
  65. AnsiColorCyan,
  66. AnsiColorWhite,
  67. AnsiColorCount
  68. } ANSI_COLOR, *PANSI_COLOR;
  69. typedef enum _BASE_VIDEO_MODE {
  70. BaseVideoInvalidMode,
  71. BaseVideoModeFrameBuffer,
  72. BaseVideoModeBiosText,
  73. } BASE_VIDEO_MODE, *PBASE_VIDEO_MODE;
  74. /*++
  75. Structure Description:
  76. This structure defines a base video console color pallette.
  77. Members:
  78. AnsiColor - Stores the array of colors to use for each of the ANSI colors.
  79. The color in the default slot is used for the foreground only.
  80. BoldAnsiColor - Stores the array of colors to use for each of the ANSI
  81. colors when the bold attribute is on. The color in the default slot is
  82. used for the foreground only.
  83. DefaultBackground - Stores the default background color to use.
  84. DefaultBoldBackground - Stores the default bold background color to use.
  85. CursorText - Stores the text color to use when the cursor is over it.
  86. CursorBackground - Stores the background color to use for the cursor.
  87. --*/
  88. typedef struct _BASE_VIDEO_PALETTE {
  89. BASE_VIDEO_COLOR AnsiColor[AnsiColorCount];
  90. BASE_VIDEO_COLOR BoldAnsiColor[AnsiColorCount];
  91. BASE_VIDEO_COLOR DefaultBackground;
  92. BASE_VIDEO_COLOR DefaultBoldBackground;
  93. BASE_VIDEO_COLOR CursorText;
  94. BASE_VIDEO_COLOR CursorBackground;
  95. } BASE_VIDEO_PALETTE, *PBASE_VIDEO_PALETTE;
  96. /*++
  97. Structure Description:
  98. This structure defines a basic base video color palette, for those that
  99. don't feel like redefining all the colors. Default values will be used for
  100. colors that are represented in the full color palette structure but not
  101. this one.
  102. Members:
  103. DefaultForeground - Stores the default foreground color.
  104. DefaultBoldForeground - Stores the default bold foreground color.
  105. DefaultBackground - Stores the default background color.
  106. DefaultBoldBackground - Stores the default bold background color.
  107. CursorText - Stores the text color to use when the cursor is over it.
  108. CursorBackground - Stores the background color to use for the cursor.
  109. --*/
  110. typedef struct _BASE_VIDEO_PARTIAL_PALETTE {
  111. BASE_VIDEO_COLOR DefaultForeground;
  112. BASE_VIDEO_COLOR DefaultBoldForeground;
  113. BASE_VIDEO_COLOR DefaultBackground;
  114. BASE_VIDEO_COLOR DefaultBoldBackground;
  115. BASE_VIDEO_COLOR CursorText;
  116. BASE_VIDEO_COLOR CursorBackground;
  117. } BASE_VIDEO_PARTIAL_PALETTE, *PBASE_VIDEO_PARTIAL_PALETTE;
  118. /*++
  119. Structure Description:
  120. This structure defines a single character cell in the base video library.
  121. Members:
  122. Attributes - Stores the character attributes.
  123. Character - Stores the character.
  124. --*/
  125. typedef struct _BASE_VIDEO_CHARACTER_DATA {
  126. USHORT Attributes;
  127. USHORT Character;
  128. } BASE_VIDEO_CHARACTER_DATA, *PBASE_VIDEO_CHARACTER_DATA;
  129. /*++
  130. Structure Description:
  131. This union defines a single character cell in the base video library.
  132. Members:
  133. AsUint32 - Accesses the data as a single 32-bit value.
  134. Data - Access the data members.
  135. --*/
  136. typedef union _BASE_VIDEO_CHARACTER {
  137. ULONG AsUint32;
  138. BASE_VIDEO_CHARACTER_DATA Data;
  139. } BASE_VIDEO_CHARACTER, *PBASE_VIDEO_CHARACTER;
  140. /*++
  141. Structure Description:
  142. This structure defines a base video font.
  143. Members:
  144. GlyphCount - Stores the number of glyphs in the data.
  145. FirstAsciiCode - Stores the ASCII code of the first glyph. Usually this is
  146. a space (0x20).
  147. GlyphBytesWidth - Stores the number of bytes of data in a character row.
  148. For rotated fonts, this is the number of bytes in a character column.
  149. GlyphWidth - Stores the width of the glyph data, in pixels.
  150. CellWidth - Stores the width of a character cell in pixels.
  151. GlyphHeight - Stores the height of a glyph, in pixels.
  152. CellHeight - Stores the height of a character cell, in pixels.
  153. Flags - Stores a bitfield of flags. See BASE_VIDEO_FONT_* definitions.
  154. Data - Stores a pointer to the font data itself.
  155. --*/
  156. typedef struct _BASE_VIDEO_FONT {
  157. UCHAR GlyphCount;
  158. UCHAR FirstAsciiCode;
  159. UCHAR GlyphBytesWidth;
  160. UCHAR GlyphWidth;
  161. UCHAR CellWidth;
  162. UCHAR GlyphHeight;
  163. UCHAR CellHeight;
  164. ULONG Flags;
  165. const UCHAR *Data;
  166. } BASE_VIDEO_FONT, *PBASE_VIDEO_FONT;
  167. /*++
  168. Structure Description:
  169. This structure stores the context for a base video frame buffer.
  170. Members:
  171. Mode - Stores the mode of the frame buffer.
  172. FrameBuffer - Stores the pointer to the linear frame buffer itself.
  173. Width - Stores the width of the visible area of the frame buffer in pixels.
  174. For text mode frame buffers, this is the screen width in character
  175. columns.
  176. Height - Stores the height of the frame buffer in pixels. For text mode
  177. frame buffers, this is the screen height in character rows.
  178. BitsPerPixel - Stores the number of bits in a pixel.
  179. PixelsPerScanLine - Stores the number of pixels in a line, both visible
  180. and invisible.
  181. RedMask - Stores the set of bits that represent the red channel in each
  182. pixel.
  183. GreenMask - Stores the set of bits that represent the green channel in
  184. each pixel.
  185. BlueMask - Stores the set of bits that represent the blue channel in each
  186. pixel.
  187. Palette - Stores the current palette, with colors in "idealized" form.
  188. PhysicalPalette - Stores the current palette, with colors in actual device
  189. pixel form.
  190. Font - Stores a pointer to the font information.
  191. Columns - Stores the number of text columns in the frame buffer.
  192. Rows - Stores the number of rows in the frame buffer.
  193. --*/
  194. typedef struct _BASE_VIDEO_CONTEXT {
  195. BASE_VIDEO_MODE Mode;
  196. PVOID FrameBuffer;
  197. ULONG Width;
  198. ULONG Height;
  199. ULONG BitsPerPixel;
  200. ULONG PixelsPerScanLine;
  201. ULONG RedMask;
  202. ULONG GreenMask;
  203. ULONG BlueMask;
  204. BASE_VIDEO_PALETTE Palette;
  205. BASE_VIDEO_PALETTE PhysicalPalette;
  206. PBASE_VIDEO_FONT Font;
  207. ULONG Columns;
  208. ULONG Rows;
  209. } BASE_VIDEO_CONTEXT, *PBASE_VIDEO_CONTEXT;
  210. //
  211. // -------------------------------------------------------------------- Globals
  212. //
  213. //
  214. // Define the different fonts that can be used.
  215. //
  216. extern BASE_VIDEO_FONT VidFontVga8x16;
  217. extern BASE_VIDEO_FONT VidFontVga9x16;
  218. extern BASE_VIDEO_FONT VidFontVerite8x16;
  219. extern BASE_VIDEO_FONT VidFontPs2Thin48x16;
  220. extern BASE_VIDEO_FONT VidFontIso8x16;
  221. extern BASE_VIDEO_FONT VidFont6x8;
  222. extern BASE_VIDEO_FONT VidFont4x6;
  223. //
  224. // Store a pointer to the default font to use when initializing new video
  225. // contexts.
  226. //
  227. extern PBASE_VIDEO_FONT VidDefaultFont;
  228. //
  229. // -------------------------------------------------------- Function Prototypes
  230. //
  231. KSTATUS
  232. VidInitialize (
  233. PBASE_VIDEO_CONTEXT Context,
  234. PSYSTEM_RESOURCE_FRAME_BUFFER FrameBuffer
  235. );
  236. /*++
  237. Routine Description:
  238. This routine initializes the base video library.
  239. Arguments:
  240. Context - Supplies a pointer to the video context to initialize.
  241. FrameBuffer - Supplies a pointer to the frame buffer parameters.
  242. Return Value:
  243. Status code.
  244. --*/
  245. VOID
  246. VidClearScreen (
  247. PBASE_VIDEO_CONTEXT Context,
  248. ULONG MinimumX,
  249. ULONG MinimumY,
  250. ULONG MaximumX,
  251. ULONG MaximumY
  252. );
  253. /*++
  254. Routine Description:
  255. This routine clears a region of the screen, filling it with the default
  256. fill character. If no frame buffer is present, this is a no-op.
  257. Arguments:
  258. Context - Supplies a pointer to the initialized base video context.
  259. MinimumX - Supplies the minimum X coordinate of the rectangle to clear,
  260. inclusive.
  261. MinimumY - Supplies the minimum Y coordinate of the rectangle to clear,
  262. inclusive.
  263. MaximumX - Supplies the maximum X coordinate of the rectangle to clear,
  264. exclusive.
  265. MaximumY - Supplies the maximum Y coordinate of the rectangle to clear,
  266. exclusive.
  267. Return Value:
  268. None.
  269. --*/
  270. VOID
  271. VidPrintString (
  272. PBASE_VIDEO_CONTEXT Context,
  273. ULONG XCoordinate,
  274. ULONG YCoordinate,
  275. PCSTR String
  276. );
  277. /*++
  278. Routine Description:
  279. This routine prints a null-terminated string to the screen at the
  280. specified location.
  281. Arguments:
  282. Context - Supplies a pointer to the initialized base video context.
  283. XCoordinate - Supplies the X coordinate of the location on the screen
  284. to write to.
  285. YCoordinate - Supplies the Y cooordinate of the location on the screen
  286. to write to.
  287. String - Supplies the string to print.
  288. Return Value:
  289. None.
  290. --*/
  291. VOID
  292. VidPrintHexInteger (
  293. PBASE_VIDEO_CONTEXT Context,
  294. ULONG XCoordinate,
  295. ULONG YCoordinate,
  296. ULONG Number
  297. );
  298. /*++
  299. Routine Description:
  300. This routine prints an integer to the screen in the specified location.
  301. Arguments:
  302. Context - Supplies a pointer to the initialized base video context.
  303. XCoordinate - Supplies the X coordinate of the location on the screen
  304. to write to.
  305. YCoordinate - Supplies the Y cooordinate of the location on the screen
  306. to write to.
  307. Number - Supplies the signed integer to print.
  308. Return Value:
  309. None.
  310. --*/
  311. VOID
  312. VidPrintInteger (
  313. PBASE_VIDEO_CONTEXT Context,
  314. ULONG XCoordinate,
  315. ULONG YCoordinate,
  316. LONG Number
  317. );
  318. /*++
  319. Routine Description:
  320. This routine prints an integer to the screen in the specified location.
  321. Arguments:
  322. Context - Supplies a pointer to the initialized base video context.
  323. XCoordinate - Supplies the X coordinate of the location on the screen
  324. to write to.
  325. YCoordinate - Supplies the Y cooordinate of the location on the screen
  326. to write to.
  327. Number - Supplies the signed integer to print.
  328. Return Value:
  329. None.
  330. --*/
  331. VOID
  332. VidPrintCharacters (
  333. PBASE_VIDEO_CONTEXT Context,
  334. ULONG XCoordinate,
  335. ULONG YCoordinate,
  336. PBASE_VIDEO_CHARACTER Characters,
  337. ULONG Count
  338. );
  339. /*++
  340. Routine Description:
  341. This routine prints a set of characters.
  342. Arguments:
  343. Context - Supplies a pointer to the initialized base video context.
  344. XCoordinate - Supplies the X coordinate of the location on the screen
  345. to write to.
  346. YCoordinate - Supplies the Y cooordinate of the location on the screen
  347. to write to.
  348. Characters - Supplies a pointer to the array of characters to write.
  349. Count - Supplies the number of characters in the array.
  350. Return Value:
  351. None.
  352. --*/
  353. VOID
  354. VidSetPalette (
  355. PBASE_VIDEO_CONTEXT Context,
  356. PBASE_VIDEO_PALETTE Palette,
  357. PBASE_VIDEO_PALETTE OldPalette
  358. );
  359. /*++
  360. Routine Description:
  361. This routine sets the current video palette. It is the caller's
  362. responsibility to synchronize both with printing and clearing the screen.
  363. Arguments:
  364. Context - Supplies a pointer to the initialized base video context.
  365. Palette - Supplies a pointer to the palette to set. This memory will be
  366. copied.
  367. OldPalette - Supplies an optional pointer where the old palette data will
  368. be returned.
  369. Return Value:
  370. None.
  371. --*/
  372. VOID
  373. VidSetPartialPalette (
  374. PBASE_VIDEO_CONTEXT Context,
  375. PBASE_VIDEO_PARTIAL_PALETTE PartialPalette
  376. );
  377. /*++
  378. Routine Description:
  379. This routine sets the current video palette. It is the caller's
  380. responsibility to synchronize both with printing and clearing the screen.
  381. Arguments:
  382. Context - Supplies a pointer to the initialized base video context.
  383. PartialPalette - Supplies a pointer to the palette to set. This memory will
  384. be copied. Values in the palette not specified here will be left
  385. unchanged.
  386. Return Value:
  387. None.
  388. --*/
  389. VOID
  390. VidGetPalette (
  391. PBASE_VIDEO_CONTEXT Context,
  392. PBASE_VIDEO_PALETTE Palette
  393. );
  394. /*++
  395. Routine Description:
  396. This routine gets the current video palette. It is the caller's
  397. responsibility to synchronize with anyone else that might be changing the
  398. palette.
  399. Arguments:
  400. Context - Supplies a pointer to the initialized base video context.
  401. Palette - Supplies a pointer where the palette will be returned.
  402. Return Value:
  403. None.
  404. --*/