Subversion Repositories Kolibri OS

Rev

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

  1. #include <kos32sys.h>
  2.  
  3. #define B_SZ    10
  4.  
  5. static char * Title="BinClock";
  6.  
  7. static void draw_small_box(int x,int y,int is_on)
  8. {
  9.  draw_bar(x,y,B_SZ,B_SZ,is_on ? 0xFF0000 : 0x103000);
  10. }
  11.  
  12. static void draw_box_group(int x,int y,int num)
  13. {
  14.  int i,j;
  15.  char buf[2];
  16.  buf[0]=(num&(1+2+4+8))+'0';
  17.  buf[1]='\0';
  18.  for(i=0;i<4;i++)
  19.  {
  20.   j=(B_SZ+2)*i;
  21.   draw_small_box(x,y+((B_SZ+2)*i),num & (1<<(3-i)) ? 1 : 0);
  22.  }
  23.  draw_bar(x,y+((B_SZ+2)*4),B_SZ,B_SZ,0x800000);
  24.  draw_text_sys(buf,x+2,y+((B_SZ+2)*4)+3,1,0xFFFFFF);
  25. }
  26.  
  27. static void draw_bcd_num(int x,int y,int num)
  28. {
  29.  int v1,v2;
  30.  v1=(num>>4)&(1+2+4+8);
  31.  v2=num & (1+2+4+8);
  32.  draw_box_group(x,y,v1);
  33.  draw_box_group(x+B_SZ+2,y,v2);
  34. }
  35.  
  36. static void draw_hms(int x,int y)
  37. {
  38.  unsigned t;
  39.  int h,m,s;
  40.  __asm__ __volatile__("int $0x40" : "=a"(t) : "a"(3));
  41.  s=(t & 0x00FF0000)>>16;
  42.  m=(t & 0x0000FF00)>>8;
  43.  h=(t & 0x000000FF);
  44.  draw_bcd_num(x,y,h);
  45.  x+=((B_SZ+2)<<1)+2;
  46.  draw_bcd_num(x,y,m);
  47.  x+=((B_SZ+2)<<1)+2;
  48.  draw_bcd_num(x,y,s);
  49. }
  50.  
  51. static void draw_h(void)
  52. {
  53.  draw_hms(22,28);
  54. }
  55.  
  56. static void paint(void)
  57. {
  58.  BeginDraw();
  59.  DrawWindow(100,100,40+((B_SZ+2)*6)+4,30+((B_SZ+2)*4)+16,Title,0x80,0x13);
  60.  draw_bar(20,26,((B_SZ+2)*6)+4+2,4+((B_SZ+1)*4)+2,0);
  61.  draw_h();
  62.  EndDraw();
  63. }
  64.  
  65. int main(void)
  66. {
  67.  int i;
  68.  paint();
  69.  for(;;)
  70.  {
  71.   i=wait_for_event(20);
  72.   draw_h();
  73.   switch(i)
  74.   {
  75.    case 1:
  76.     paint();
  77.     continue;
  78.    case 2:
  79.     get_key();
  80.     continue;
  81.    case 3:
  82.     if(get_os_button()==1) return 0;
  83.     continue;
  84.   }
  85.  }
  86. }
  87.