Advertisement
konalisp

vga.hxx

Nov 15th, 2014
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #ifndef __VGA_HXX__
  2. #define __VGA_HXX__
  3.  
  4. #include <stdint.h> // ...
  5. #include <stddef.h> // Compiler-provided header files.
  6.  
  7. namespace vga{
  8.  
  9.     enum color{ // Standard VGA colors.
  10.         COLOR_BLACK = 0,
  11.         COLOR_BLUE = 1,
  12.         COLOR_GREEN = 2,
  13.         COLOR_CYAN = 3,
  14.         COLOR_RED = 4,
  15.         COLOR_MAGENTA = 5,
  16.         COLOR_BROWN = 6,
  17.         COLOR_LIGHT_GREY = 7,
  18.         COLOR_DARK_GREY = 8,
  19.         COLOR_LIGHT_BLUE = 9,
  20.         COLOR_LIGHT_GREEN = 10,
  21.         COLOR_LIGHT_CYAN = 11,
  22.         COLOR_LIGHT_RED = 12,
  23.         COLOR_LIGHT_MAGENTA = 13,
  24.         COLOR_LIGHT_BROWN = 14,
  25.         COLOR_WHITE = 15
  26.     };
  27.  
  28.  
  29.     class vga{
  30.     public:
  31.    
  32.         vga(); /* Constructor, sets up things such as the
  33.               width and height of the VGA display. */
  34.    
  35.         void write(const char* data);
  36.         /* Writes the specified string to the VGA display. Uses the
  37.            current color scheme. */
  38.        
  39.         void write(const char* data, enum color fg, enum color bg);
  40.         /* Writes the specified string to the VGA display.
  41.            Takes colors as arguments to change the color scheme
  42.            before writing. */
  43.            
  44.         void write(int val);
  45.    
  46.         // Mostly internal functions
  47.    
  48.         uint8_t make_color(enum color fg, enum color bg);
  49.    
  50.         /* Makes a color that can be written to the VGA memory. */
  51.    
  52.         uint16_t make_entry(char c, uint8_t color);
  53.    
  54.         /* Makes a character entry that can be written to VGA memory. */
  55.    
  56.         void putc(char c, int x, int y);
  57.    
  58.         /* Puts the character 'c' at positions 'x' and 'y' */
  59.    
  60.         void putc(char c);
  61.    
  62.         /* Puts the character 'c' at the current position. */
  63.    
  64.         void clear();
  65.    
  66.         /* Clears the screen all at once. */
  67.    
  68.         void clear(int line);
  69.    
  70.         /* Clears a specified line from the screen. */
  71.        
  72.         void nl();
  73.        
  74.         char* itoa(int value, int base);
  75.  
  76.     protected:
  77.         int row; // Current character row.
  78.         int column; // Current character column.
  79.         uint8_t color; // Current colorscheme.
  80.    
  81.         int height; // Screen height.
  82.         int width; // Screen width.
  83.    
  84.     private:
  85.         uint16_t* buffer; // VGA memory.
  86.        
  87.     };
  88. };
  89.  
  90. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement