1
0

video.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. /*++
  2. Copyright (c) 2016 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. video.c
  9. Abstract:
  10. This module implements support for basic printing to the screen.
  11. Author:
  12. Evan Green 7-Mar-2016
  13. Environment:
  14. Kernel
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <minoca/kernel/kernel.h>
  20. #include "keinit.h"
  21. #include <minoca/lib/basevid.h>
  22. #include "kep.h"
  23. //
  24. // ---------------------------------------------------------------- Definitions
  25. //
  26. //
  27. // ------------------------------------------------------ Data Type Definitions
  28. //
  29. //
  30. // ----------------------------------------------- Internal Function Prototypes
  31. //
  32. //
  33. // -------------------------------------------------------------------- Globals
  34. //
  35. BASE_VIDEO_CONTEXT KeVideoContext;
  36. //
  37. // ------------------------------------------------------------------ Functions
  38. //
  39. VOID
  40. KeVideoPrintString (
  41. ULONG XCoordinate,
  42. ULONG YCoordinate,
  43. PCSTR String
  44. )
  45. /*++
  46. Routine Description:
  47. This routine prints a null-terminated string to the screen at the
  48. specified location.
  49. Arguments:
  50. Context - Supplies a pointer to the initialized base video context.
  51. XCoordinate - Supplies the X coordinate of the location on the screen
  52. to write to.
  53. YCoordinate - Supplies the Y cooordinate of the location on the screen
  54. to write to.
  55. String - Supplies the string to print.
  56. Return Value:
  57. None.
  58. --*/
  59. {
  60. VidPrintString(&KeVideoContext, XCoordinate, YCoordinate, String);
  61. return;
  62. }
  63. VOID
  64. KeVideoPrintHexInteger (
  65. ULONG XCoordinate,
  66. ULONG YCoordinate,
  67. ULONG Number
  68. )
  69. /*++
  70. Routine Description:
  71. This routine prints an integer to the screen in the specified location.
  72. Arguments:
  73. XCoordinate - Supplies the X coordinate of the location on the screen
  74. to write to.
  75. YCoordinate - Supplies the Y cooordinate of the location on the screen
  76. to write to.
  77. Number - Supplies the signed integer to print.
  78. Return Value:
  79. None.
  80. --*/
  81. {
  82. VidPrintHexInteger(&KeVideoContext, XCoordinate, YCoordinate, Number);
  83. return;
  84. }
  85. VOID
  86. KeVideoPrintInteger (
  87. ULONG XCoordinate,
  88. ULONG YCoordinate,
  89. LONG Number
  90. )
  91. /*++
  92. Routine Description:
  93. This routine prints an integer to the screen in the specified location.
  94. Arguments:
  95. Context - Supplies a pointer to the initialized base video context.
  96. XCoordinate - Supplies the X coordinate of the location on the screen
  97. to write to.
  98. YCoordinate - Supplies the Y cooordinate of the location on the screen
  99. to write to.
  100. Number - Supplies the signed integer to print.
  101. Return Value:
  102. None.
  103. --*/
  104. {
  105. VidPrintInteger(&KeVideoContext, XCoordinate, YCoordinate, Number);
  106. return;
  107. }
  108. VOID
  109. KeVideoClearScreen (
  110. LONG MinimumX,
  111. LONG MinimumY,
  112. LONG MaximumX,
  113. LONG MaximumY
  114. )
  115. /*++
  116. Routine Description:
  117. This routine clears a portion of the video screen.
  118. Arguments:
  119. MinimumX - Supplies the minimum X coordinate of the rectangle to clear,
  120. inclusive.
  121. MinimumY - Supplies the minimum Y coordinate of the rectangle to clear,
  122. inclusive.
  123. MaximumX - Supplies the maximum X coordinate of the rectangle to clear,
  124. exclusive.
  125. MaximumY - Supplies the maximum Y coordinate of the rectangle to clear,
  126. exclusive.
  127. Return Value:
  128. None.
  129. --*/
  130. {
  131. if (KeVideoContext.FrameBuffer == NULL) {
  132. return;
  133. }
  134. VidClearScreen(&KeVideoContext, MinimumX, MinimumY, MaximumX, MaximumY);
  135. return;
  136. }
  137. KSTATUS
  138. KeVideoGetDimensions (
  139. PULONG Width,
  140. PULONG Height,
  141. PULONG CellWidth,
  142. PULONG CellHeight,
  143. PULONG Columns,
  144. PULONG Rows
  145. )
  146. /*++
  147. Routine Description:
  148. This routine returns the dimensions of the kernel's video frame buffer.
  149. Arguments:
  150. Width - Supplies an optional pointer where the width in pixels will be
  151. returned. For text-based frame buffers, this will be equal to the
  152. number of text columns.
  153. Height - Supplies an optional pointer where the height in pixels will be
  154. returned. For text-based frame buffers, this will be equal to the
  155. number of text rows.
  156. CellWidth - Supplies an optional pointer where the width in pixels of a
  157. text character will be returned on success. For text-based frame
  158. buffers, 1 will be returned.
  159. CellHeight - Supplies an optional pointer where the height in pixels of a
  160. text character will be returned on success. For text-based frame
  161. buffers, 1 will be returned.
  162. Columns - Supplies an optional pointer where the number of text columns
  163. will be returned.
  164. Rows - Supplies an optional pointer where the number of text rows will be
  165. returned.
  166. Return Value:
  167. STATUS_SUCCESS on success.
  168. STATUS_NOT_INITIALIZED if there is no frame buffer.
  169. --*/
  170. {
  171. if (KeVideoContext.FrameBuffer == NULL) {
  172. return STATUS_NOT_INITIALIZED;
  173. }
  174. if (Width != NULL) {
  175. *Width = KeVideoContext.Width;
  176. }
  177. if (Height != NULL) {
  178. *Height = KeVideoContext.Height;
  179. }
  180. if (CellWidth != NULL) {
  181. *CellWidth = KeVideoContext.Font->CellWidth;
  182. }
  183. if (CellHeight != NULL) {
  184. *CellHeight = KeVideoContext.Font->CellHeight;
  185. }
  186. if (Columns != NULL) {
  187. *Columns = KeVideoContext.Columns;
  188. }
  189. if (Rows != NULL) {
  190. *Rows = KeVideoContext.Rows;
  191. }
  192. return STATUS_SUCCESS;
  193. }
  194. KSTATUS
  195. KepInitializeBaseVideo (
  196. PKERNEL_INITIALIZATION_BLOCK Parameters
  197. )
  198. /*++
  199. Routine Description:
  200. This routine initializes the built in base video library, which is used in
  201. case of emergencies to display to the screen.
  202. Arguments:
  203. Parameters - Supplies a pointer to the kernel initialization block.
  204. Return Value:
  205. Status code.
  206. --*/
  207. {
  208. PSYSTEM_RESOURCE_FRAME_BUFFER FrameBuffer;
  209. PSYSTEM_RESOURCE_HEADER GenericHeader;
  210. KSTATUS Status;
  211. GenericHeader = KepGetSystemResource(SystemResourceFrameBuffer, FALSE);
  212. if (GenericHeader == NULL) {
  213. Status = STATUS_SUCCESS;
  214. goto InitializeBaseVideoEnd;
  215. }
  216. FrameBuffer = (PSYSTEM_RESOURCE_FRAME_BUFFER)GenericHeader;
  217. Status = VidInitialize(&KeVideoContext, FrameBuffer);
  218. if (!KSUCCESS(Status)) {
  219. goto InitializeBaseVideoEnd;
  220. }
  221. Status = STATUS_SUCCESS;
  222. InitializeBaseVideoEnd:
  223. return Status;
  224. }
  225. //
  226. // --------------------------------------------------------- Internal Functions
  227. //