Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. /* Copyright (c) 1997-2017, FenixOS Developers
  2. All Rights Reserved.
  3.  
  4. This file is subject to the terms and conditions defined in
  5. file 'LICENSE', which is part of this source code package.
  6. */
  7.  
  8. /*! \file video.c This file holds implementations of functions
  9. presenting output to the VGA screen. */
  10. #include <stdint.h>
  11.  
  12. /*! Max number of columns in the VGA buffer. */
  13. #define MAX_COLS (80)
  14. /*! Max number of columns in the VGA buffer. */
  15. #define MAX_ROWS (25)
  16.  
  17. struct screen_position {
  18. unsigned char character; /*!< The character part of the byte tuple used for
  19. each screen position. */
  20. unsigned char attribute; /*!< The character part of the byte tuple used for
  21. each screen position. */
  22. };
  23. /*!< Defines a VGA text mode screen position. */
  24.  
  25. struct screen {
  26. struct screen_position positions[MAX_ROWS][MAX_COLS];
  27. /*!< The VGA screen. It is organized as a two dimensional array. */
  28. };
  29. /*!< Defines a VGA text mode screen. */
  30.  
  31. /*! points to the VGA screen. */
  32. static struct screen* const screen_pointer = (struct screen*) 0xB8000;
  33. uint16_t const colorByte = 0x0f;
  34.  
  35. void printCharArray(const char* string, uint16_t x,uint16_t y) {
  36. volatile uint16_t * location;
  37. uint16_t newy = y;
  38. uint16_t newx = x;
  39. location = (volatile uint16_t *)0xB8000 + (y * 80 + x);
  40. newx++;
  41. if (newx == 80) {
  42. newx = 0;
  43. newy++;
  44. }
  45. *location = *string | colorByte << 8;
  46. if (*string+1 == '/n') {
  47. printCharArray(string + 2, newx, newy + 1);
  48. } else if (*string+1 != '/0') {
  49. printCharArray(string + 1, newx, newy);
  50. }
  51. }
  52.  
  53. void kprints(const char* string) {
  54. uint16_t y = 0;
  55. uint16_t x = 0;
  56. printCharArray(string, x, y);
  57. }
  58.  
  59. void kprinthex(const register uint32_t value) {
  60. volatile uint16_t * location;
  61. location = (volatile uint16_t *)0xB8000 ;
  62. uint16_t number = 0;
  63. uint32_t newValue = value;
  64. while (newValue) {
  65. uint16_t temp = value == '1' ? 1 : 0;
  66. number = (value << 1) | temp;
  67. newValue = newValue << 1;
  68. }
  69. *location = number | colorByte << 8;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement