2024-01-04 23:20:35 +01:00
|
|
|
#include <sys/ksys.h>
|
2014-09-19 12:09:40 +02:00
|
|
|
|
2024-01-04 23:20:35 +01:00
|
|
|
#define B_SZ 10
|
2014-09-19 12:09:40 +02:00
|
|
|
|
2024-01-04 23:20:35 +01:00
|
|
|
static char* title = "BinClock";
|
2014-09-19 12:09:40 +02:00
|
|
|
|
2024-01-04 23:20:35 +01:00
|
|
|
static void draw_small_box(int x, int y, int is_on)
|
2014-09-19 12:09:40 +02:00
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
_ksys_draw_bar(x, y, B_SZ, B_SZ, is_on ? 0xFF0000 : 0x103000);
|
2014-09-19 12:09:40 +02:00
|
|
|
}
|
|
|
|
|
2024-01-04 23:20:35 +01:00
|
|
|
static void draw_box_group(int x, int y, int num)
|
2014-09-19 12:09:40 +02:00
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
int i, j;
|
|
|
|
char buf[2];
|
|
|
|
buf[0] = (num&(1+2+4+8))+'0';
|
|
|
|
buf[1] = '\0';
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
j = (B_SZ+2)*i;
|
|
|
|
draw_small_box(x,y+((B_SZ+2)*i),num & (1<<(3-i)) ? 1 : 0);
|
|
|
|
}
|
|
|
|
_ksys_draw_bar(x, y+((B_SZ+2)*4),B_SZ,B_SZ, 0x800000);
|
|
|
|
_ksys_draw_text(buf, x+2, y+((B_SZ+2)*4)+3, 1, 0xFFFFFF);
|
2014-09-19 12:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_bcd_num(int x,int y,int num)
|
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
int v1, v2;
|
|
|
|
v1 = (num>>4)&(1+2+4+8);
|
|
|
|
v2 = num&(1+2+4+8);
|
|
|
|
draw_box_group(x, y, v1);
|
|
|
|
draw_box_group(x+B_SZ+2, y ,v2);
|
2014-09-19 12:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_hms(int x,int y)
|
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
unsigned t;
|
|
|
|
int h, m, s;
|
|
|
|
__asm__ __volatile__("int $0x40" : "=a"(t) : "a"(3));
|
|
|
|
s = (t & 0x00FF0000)>>16;
|
|
|
|
m = (t & 0x0000FF00)>>8;
|
|
|
|
h = (t & 0x000000FF);
|
|
|
|
draw_bcd_num(x,y,h);
|
|
|
|
x+=((B_SZ+2)<<1)+2;
|
|
|
|
draw_bcd_num(x,y,m);
|
|
|
|
x+=((B_SZ+2)<<1)+2;
|
|
|
|
draw_bcd_num(x,y,s);
|
2014-09-19 12:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_h(void)
|
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
draw_hms(22, 28);
|
2014-09-19 12:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void paint(void)
|
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
_ksys_start_draw();
|
|
|
|
_ksys_create_window(100, 100, 40+((B_SZ+2)*6)+4,30+((B_SZ+2)*4)+16, title, 0x80, 0x13);
|
|
|
|
_ksys_draw_bar(20, 26, ((B_SZ+2)*6)+4+2,4+((B_SZ+1)*4)+2, 0);
|
|
|
|
draw_h();
|
|
|
|
_ksys_end_draw();
|
2014-09-19 12:09:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
2024-01-04 23:20:35 +01:00
|
|
|
int i;
|
2014-09-19 12:09:40 +02:00
|
|
|
paint();
|
2024-01-04 23:20:35 +01:00
|
|
|
|
|
|
|
for(;;) {
|
|
|
|
i = _ksys_wait_event_timeout(20);
|
|
|
|
draw_h();
|
|
|
|
switch(i) {
|
|
|
|
case 1:
|
|
|
|
paint();
|
|
|
|
continue;
|
|
|
|
case 2:
|
|
|
|
_ksys_get_key();
|
|
|
|
continue;
|
|
|
|
case 3:
|
|
|
|
if (_ksys_get_button() == 1) return 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-09-19 12:09:40 +02:00
|
|
|
}
|
2024-01-04 23:20:35 +01:00
|
|
|
|