This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

myelin/src/common/splash.c

By: a guest on Dec 25th, 2011  |  syntax: C  |  size: 3.30 KB  |  views: 87  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <kernel/myelin.h>
  2. #include <kernel/console.h>
  3. #include <boot/splash.h>
  4.  
  5. /**
  6.  * \brief       Call a splash_action_function
  7.  */
  8. static void splash_do(splash_action_function func, void* arg)
  9. {
  10.         func(arg);
  11. }
  12.  
  13. /**
  14.  * \brief       Draw the progress bar
  15.  * \param num   Current action
  16.  * \param count Number of actions
  17.  * \param screen Screen information
  18.  * \param text  Action message
  19.  */
  20. static void splash_paint(int num, int count, struct splash_screen screen,
  21.                                                         const char* text)
  22. {
  23.         u32 i, j = screen.width - (count - num), k = screen.width;
  24.  
  25.         /*
  26.          * Draw bar outline
  27.          */
  28.         console.screen.fore = screen.line;
  29.         console.cursor.x = screen.x - 1;
  30.         console.cursor.y = screen.y - 1;
  31.  
  32.         console_writechar(218);
  33.         for (i = 0; i < k; ++i)
  34.                 console_writechar(196);
  35.         console_writechar(191);
  36.         console.cursor.x = screen.x - 1;
  37.         console.cursor.y++;
  38.  
  39.         console_writechar(179);
  40.         for (i = 0; i < k; ++i)
  41.                 console_writechar(' ');
  42.         console_writechar(179);
  43.         console.cursor.x = screen.x - 1;
  44.         console.cursor.y++;
  45.  
  46.         console_writechar(192);
  47.         for (i = 0; i < k; ++i)
  48.                 console_writechar(196);
  49.         console_writechar(217);
  50.         console.cursor.x = screen.x;
  51.         console.cursor.y++;
  52.  
  53.         /*
  54.          * Write message
  55.          */
  56.         console.screen.fore = screen.text;
  57.         console_writestring(text);
  58.  
  59.         /*
  60.          * Draw progress
  61.          */
  62.         console.screen.fore = screen.fill;
  63.         console.cursor.x = screen.x;
  64.         console.cursor.y = screen.y;
  65.         for (i = 0; i < j; ++i)
  66.                 console_writechar(219);
  67.         for (; j < k; ++j)
  68.                 console_writechar(' ');
  69. }
  70.  
  71. /**
  72.  * \brief       Draw a splash screen while booting the system
  73.  * \param screen Splash screen info
  74.  * \param actions Actions which need to be completed to boot the system
  75.  * \param count Number of actions
  76.  */
  77. void splash(struct splash_screen screen, struct splash_action* actions,
  78.                                                                 u32 count)
  79. {
  80.         u8 saved_fore   = console.screen.fore;
  81.         u8 saved_back   = console.screen.back;
  82.         u32 saved_flags = console.cursor.flags;
  83.  
  84.         u32 i = 0;
  85.         console.cursor.flags &= ~(CONSOLE_CURSOR_ENABLED);
  86.         console.screen.back = screen.back;
  87.         console_clear();
  88.  
  89.         if (!(screen.bar)) {
  90.                 console.cursor.x = console.cursor.y = 0;
  91.                 console.screen.fore = screen.text;
  92.                 console_writestring("MYELIN (booting)...\n\n");
  93.         }
  94.  
  95.         while (i < count) {
  96.                 if (screen.bar) {
  97.                         console_clear();
  98.                         console.cursor.x = console.cursor.y = 0;
  99.                         console.screen.fore = screen.text;
  100.                         console_writestring("MYELIN (booting)...\n\n");
  101.                         splash_paint(i + 1, count, screen, actions[i].msg);
  102.                         splash_do(actions[i].func, actions[i].arg);
  103.                 } else {
  104.                         /*
  105.                          * Save y co-ord in case a callback function prints its
  106.                          * own text
  107.                          */
  108.                         unsigned y1 = console.cursor.y, y2;
  109.                         console.screen.fore = screen.text;
  110.                         console_writestring(actions[i].msg);
  111.  
  112.                         console.cursor.x = 0;
  113.                         console.cursor.y++;
  114.                         splash_do(actions[i].func, actions[i].arg);
  115.  
  116.                         console.cursor.x = console.screen.columns - 7;
  117.                         y2 = console.cursor.y;
  118.                         console.cursor.y = y1;
  119.  
  120.                         console.screen.fore = screen.line;
  121.                         console_writestring("[");
  122.                         console.screen.fore = screen.fill;
  123.                         console_writestring("DONE");
  124.                         console.screen.fore = screen.line;
  125.                         console_writestring("]\n");
  126.                         console.cursor.x = 0;
  127.                         console.cursor.y = y2;
  128.                 }
  129.                 ++i;
  130.         }
  131.  
  132.         console.screen.fore  = saved_fore;
  133.         console.screen.back  = saved_back;
  134.         console.cursor.flags = saved_flags;
  135. }
clone this paste RAW Paste Data