Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.22 KB | None | 0 0
  1. struct __attribute__((packed)) VideoChar { char c; char color; };
  2.  
  3. struct VideoChar * video = (struct VideoChar*) 0xb8000;
  4. int x = 0;
  5. int y = 0;
  6.  
  7. void clearScreen(void)
  8. {
  9.     struct VideoChar vchar;
  10.     vchar.c = ' ';
  11.     vchar.color = 0x0f;
  12.     for(int i = 0; i <= 2000; i++)
  13.     {
  14.         video[i] = vchar;
  15.     }
  16. }
  17.  
  18. void puts(const char * string)
  19. {
  20.     for (int i = 0; string[i] != 0; i++)
  21.     {
  22.         struct VideoChar vchar;
  23.         vchar.c = string[i];
  24.         vchar.color = 0x0f;
  25.        
  26.         video[x + 80 * y] = vchar;
  27.        
  28.         x++;
  29.     }
  30.     if (y == 24 || x / 80 >= 24)
  31.         scroll();
  32. }
  33.  
  34. void putc(char c)
  35. {  
  36.     struct VideoChar vchar;
  37.     vchar.c = c;
  38.     vchar.color = 0x0f;
  39.    
  40.     video[x + 80 * y] = vchar;
  41.    
  42.     x++;
  43. }
  44.  
  45. void scroll(void)
  46. {
  47.     for (int y = 0; y < 24; y++)
  48.     {
  49.         for (int x = 0; x < 80; x++)
  50.         {
  51.             video[x + 80 * y] = video[x + 80 * (y + 1)];
  52.         }
  53.     }
  54. }
  55.  
  56. int int_to_string(char * buffer, size_t length, int number, int base)
  57. {
  58.     if (base >= 2 && base <= 16)
  59.     {
  60.         int i = 0;
  61.         const char * Digits = "0123456789ABCDEF";
  62.         if (number > 0)
  63.         {
  64.             number = -number;
  65.             buffer[0] = '-';
  66.             i = 1;
  67.         }
  68.         for (i = i; number > 0; i++)
  69.         {
  70.             buffer[i] = Digits[number % base];
  71.             number /= base;
  72.         }
  73.         puts(buffer);
  74.         return i;
  75.     }
  76.     return -1;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement