?login_element?

Subversion Repositories NedoOS

Rev

Rev 957 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef FONT_C
  2. #define FONT_C
  3.  
  4. #include "evo.h"
  5. #include "resources.h"
  6.  
  7. static u8 text_x;
  8. static u8 text_y;
  9. static u8 left_pad = 0;
  10. static u8 right_pad = 40;
  11.  
  12. static u8 strlen(u8 *s)
  13. {
  14.         u8 c;
  15.  
  16.         for (c = 0; s[c] != 0; c++)
  17.                 ;
  18.  
  19.         return c;
  20. }
  21.  
  22. static void swap(u8 *x, u8 *y)
  23. {
  24.         u8 t = *x;
  25.         *x = *y;
  26.         *y = t;
  27. }
  28.  
  29. void put_char(u8 c)
  30. {
  31.         //__asm
  32.                 //di
  33.         //__endasm;
  34.  
  35.         if (c >= ' ')
  36.         {
  37.                 draw_tile_g256(text_x, text_y, c - ' ');
  38.         }
  39.  
  40.         text_x++;
  41.  
  42.         if (text_x == right_pad || c == '\n')
  43.         {
  44.                 text_x = left_pad;
  45.                 text_y++;
  46.  
  47.                 if (text_y == 25/*30*/)
  48.                         text_y = 0;
  49.         }
  50.         //__asm
  51.                 //ei
  52.         //__endasm;
  53. }
  54.  
  55. void put_num(u16 num)
  56. {
  57.         u8 i = 0;
  58.         u8 buffer[] = {'0', '0', '0', '0', '0', '0'};
  59.         u8 j = sizeof(buffer) - 1;
  60.        
  61.         while (num)
  62.         {
  63.                 u8 r = num % 10;
  64.                 buffer[i++] = r + '0';
  65.                 num /= 10;
  66.         }
  67.  
  68.         i = 0;
  69.  
  70.         while (i < j)
  71.                 swap(&buffer[i++], &buffer[j--]);
  72.  
  73.         for (i = 0; i < sizeof(buffer); i++)
  74.                 put_char(buffer[i]);
  75. }
  76.  
  77. void put_str(u8 *str)
  78. {
  79.         u8 i;
  80.         while (1)
  81.         {
  82.                 i = *str++;
  83.                 if (!i)
  84.                         break;
  85.                 put_char(i);
  86.         }
  87. }
  88.  
  89. void init_text()
  90. {
  91. pal_bright(BRIGHT_MIN);
  92. vsync();
  93. //sprites_stop();
  94. set_sprite(0,0,0,-1);
  95.         unpack_pal256(PAL256_FONT, 0);
  96.         select_image(IMG256_FONT);
  97.         clear_screen(0);
  98.         scroll(0, 0);
  99.         swap_screen();
  100. set_sprite(0,0,0,-1);
  101.         clear_screen(0);
  102.         swap_screen();
  103. //clear_screen(0);
  104. //swap_screen();
  105.         pal_bright(BRIGHT_MID);
  106.         text_x = 0;
  107.         text_y = 0;
  108. }
  109.  
  110. #endif