Guest User

Untitled

a guest
May 22nd, 2011
149
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. static char mask[] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 };
  3. static int addr[] = { 0x000, 0x060, 0x060*2, 0x060*3, 0x060*4, 0x060*5, 0x060*6, 0x060*7, };
  4.  
  5. static char number_font[] = {
  6.     0x3e, 0x41, 0x41, 0x41, 0x3e, 0x00, /*0*/
  7.     0x00, 0x42, 0x7f, 0x40, 0x00, 0x00, /*1*/
  8.     0x42, 0x61, 0x51, 0x49, 0x46, 0x00, /*2*/
  9.     0x22, 0x41, 0x49, 0x49, 0x36, 0x00, /*3*/
  10.     0x1c, 0x13, 0x10, 0x7f, 0x10, 0x00, /*4*/
  11.     0x2f, 0x49, 0x49, 0x49, 0x31, 0x00, /*5*/
  12.     0x3e, 0x49, 0x49, 0x49, 0x32, 0x00, /*6*/
  13.     0x01, 0x01, 0x71, 0x09, 0x07, 0x00, /*7*/
  14.     0x36, 0x49, 0x49, 0x49, 0x36, 0x00, /*8*/
  15.     0x26, 0x49, 0x49, 0x49, 0x3e, 0x00, /*9*/
  16.     0x7c, 0x12, 0x11, 0x12, 0x7c, 0x00, /*A*/
  17.     0x7f, 0x49, 0x49, 0x49, 0x36, 0x00, /*B*/
  18.     0x3e, 0x41, 0x41, 0x41, 0x22, 0x00, /*C*/
  19.     0x7f, 0x41, 0x41, 0x41, 0x3e, 0x00, /*D*/
  20.     0x7f, 0x49, 0x49, 0x49, 0x49, 0x00, /*E*/
  21.     0x7f, 0x09, 0x09, 0x09, 0x09, 0x00, /*F*/
  22.     0x08, 0x08, 0x08, 0x08, 0x08, 0x00, /*-*/
  23. };
  24.  
  25. static int font_offset[] = { 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 60, 66, 72, 78, 84, 90, 96 };
  26.  
  27. void print_digit(int x, int y, int digit)
  28. {
  29.     char *ad = (char *)0x1000 + addr[y] + x;
  30.     char *font_pos = number_font + font_offset[digit];
  31.     char i;
  32.     for(i=0; i<6; i++)
  33.         ad[i] = font_pos[i];
  34. }
  35.  
  36. int digits[] = { 0, 1, 10, 100, 1000, 10000 };
  37. void print_dec(char x, char y, int num)
  38. {
  39.     if(num < 0)
  40.     {
  41.         print_digit(x, y, 16); /* - */
  42.         print_dec(x + 6, y, -num);
  43.         return;
  44.     }
  45.     else
  46.     {
  47.         char i, j;
  48.         for(i=5; i>1; i--)
  49.             if(digits[i] <= num)
  50.                 break;
  51.         for(; i>0; i--)
  52.         {
  53.             for(j=0; j<10; j++)
  54.             {
  55.                 if(num < digits[i])
  56.                     break;
  57.                 num -= digits[i];
  58.             }
  59.             print_digit(x, y, j);
  60.             x += 6;
  61.         }
  62.     }
  63. }
  64.  
  65. void print_hex(char x, char y, unsigned num)
  66. {
  67.     char i;
  68.     for(i=12; i>=0; i-=4, x+=6)
  69.         print_digit(x, y, (num >>i) & 0x0f);
  70. }
  71.  
  72. void print_bin(char x, char y, unsigned num)
  73. {
  74.     char i;
  75.     for(i=15; i>=0; i--, x+=6)
  76.         print_digit(x, y, (num >>i) & 0x01);
  77. }
  78.  
  79. void draw_pixel(char x, char y)
  80. {
  81.     char m = mask[y & 0x07];
  82.     *(char *)(0x1000 + addr[y >> 3] + x) |=  m;
  83. }
  84.  
  85. void draw_circle(char xc, char yc, char r)
  86. {
  87.     unsigned int x= r, y= 0;    
  88.     int          cd2= 0;    
  89.    
  90.     if (!r) return;
  91.     draw_pixel(xc-r, yc);
  92.     draw_pixel(xc+r, yc);
  93.     draw_pixel(xc, yc-r);
  94.     draw_pixel(xc, yc+r);
  95.  
  96.     while (x > y)
  97.     {
  98.         cd2-= (--x) - (++y);
  99.         if (cd2 < 0) cd2+=x++;
  100.  
  101.         draw_pixel(xc-x, yc-y);
  102.         draw_pixel(xc-y, yc-x);
  103.         draw_pixel(xc+y, yc-x);
  104.         draw_pixel(xc+x, yc-y);
  105.         draw_pixel(xc-x, yc+y);
  106.         draw_pixel(xc-y, yc+x);
  107.         draw_pixel(xc+y, yc+x);
  108.         draw_pixel(xc+x, yc+y);
  109.      }
  110. }
  111.  
  112. int main()
  113. {
  114.     char a, i;
  115.    
  116.     for(i=0; i<=0xe; i++)
  117.         print_digit(3 + font_offset[i], 6, i);
  118.  
  119.     for(a = 0; a <80; a++)
  120.         draw_pixel(a+10, 5 +(a>>1));
  121.     draw_circle(25, 20, 15);
  122.     draw_circle(35, 25, 21);
  123.     draw_circle(63, 30, 29);
  124.     draw_circle(63, 30, 26);
  125.  
  126.     for(;;)
  127.         ;
  128.     return 0;
  129. }
RAW Paste Data