166 lines
3.5 KiB
C
166 lines
3.5 KiB
C
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <time.h>
|
|
#include <math.h>
|
|
#include <emscripten.h>
|
|
|
|
const unsigned char TEXT[] = "\
|
|
ESXISTXFÜNF\
|
|
ZEHNZWANZIG\
|
|
DREIVIERTEL\
|
|
VORGESTNACH\
|
|
HALBXELFÜNF\
|
|
EINSXLEZWEI\
|
|
DREIXTXVIER\
|
|
SECHSXXACHT\
|
|
SIEBENZWÖLF\
|
|
ZEHNEUNXUHR";
|
|
|
|
typedef unsigned long long uint64;
|
|
typedef unsigned __int128 uint128;
|
|
|
|
#define ES_IST ((uint128) 0b11 << 0 | 0b111 << 3 )
|
|
#define FÜNF_PRE ((uint128) 0b1111 << 7 )
|
|
#define FÜNFZEHN ((uint128) 0b11111111 << 7 )
|
|
#define ZEHN_PRE ((uint128) 0b1111 << 11 )
|
|
#define ZWANZIG ((uint128) 0b1111111 << 15 )
|
|
#define DREIVIERTEL ((uint128) 0b11111111111 << 22 )
|
|
#define VIERTEL ((uint128) 0b1111111 << 26 )
|
|
#define VOR ((uint128) 0b111 << 33 )
|
|
#define NACH ((uint128) 0b1111 << 40 )
|
|
#define HALB ((uint128) 0b1111 << 44 )
|
|
#define ELF ((uint128) 0b111 << 49 )
|
|
#define FÜNF_UHR ((uint128) 0b1111 << 51 )
|
|
#define EINS ((uint128) 0b1111 << 55 )
|
|
#define ZWEI ((uint128) 0b1111 << 62 )
|
|
#define DREI ((uint128) 0b1111 << 66 )
|
|
#define VIER ((uint128) 0b1111 << 73 )
|
|
#define SECHS ((uint128) 0b11111 << 77 )
|
|
#define ACHT ((uint128) 0b1111 << 84 )
|
|
#define SIEBEN ((uint128) 0b111111 << 88 )
|
|
#define ZWÖLF ((uint128) 0b11111 << 94 )
|
|
#define ZEHN_UHR ((uint128) 0b1111 << 99 )
|
|
#define NEUN ((uint128) 0b1111 << 102)
|
|
#define UHR ((uint128) 0b111 << 107)
|
|
#define STELLE ((uint128) 0b11 << 38 | 0b11 << 49 | 0b11 << 60)
|
|
#define GESTELLT ((uint128) 0b1111 << 36 | 0b11 << 49 | 0b1 << 60 | 0b1 << 71)
|
|
|
|
uint128 HOURS[] = {
|
|
ZWÖLF, EINS, ZWEI, DREI, VIER, FÜNF_UHR,
|
|
SECHS, SIEBEN, ACHT, NEUN, ZEHN_UHR, ELF
|
|
};
|
|
uint128 PARTS[] = {
|
|
UHR, FÜNF_PRE, ZEHN_PRE, VIERTEL,
|
|
ZWANZIG, FÜNF_PRE | HALB, HALB
|
|
};
|
|
|
|
uint128 active = 0;
|
|
|
|
void print128(uint128 n) {
|
|
printf("0x%016llx%016llx\n",
|
|
(uint64) (n >> 64), (uint64) n & 0xFFFFFFFFFFFFFFFF);
|
|
}
|
|
|
|
void set(uint128 seg) {
|
|
active |= seg;
|
|
}
|
|
|
|
void reset(void) {
|
|
active = 0;
|
|
set(ES_IST);
|
|
}
|
|
|
|
void settime(time_t ts) {
|
|
|
|
unsigned int second = ts % 60;
|
|
|
|
unsigned int minute = (ts / 60) % 60;
|
|
float fminute = (float) minute + (float) second / 60;
|
|
minute = 5 * (unsigned int) roundf(fminute / 5);
|
|
|
|
unsigned int hour = (ts / (60*60) + 1) % 12;
|
|
|
|
//printf("%02d:%02d\n", hour, minute);
|
|
|
|
int before = 0;
|
|
|
|
if (minute >= 25) {
|
|
hour = (hour+1) % 12;
|
|
before = 1;
|
|
minute = 60-minute;
|
|
if (minute == 35) {
|
|
minute = 25;
|
|
before = 0;
|
|
}
|
|
}
|
|
|
|
//printf("%02d %s %02d\n", minute, before ? "vor" : "nach", hour);
|
|
|
|
if (minute == 25)
|
|
before = !before;
|
|
|
|
reset();
|
|
|
|
if (minute != 0 && minute != 30)
|
|
set(before ? (uint128) VOR : (uint128) NACH);
|
|
|
|
set((uint128) HOURS[hour]);
|
|
set((uint128) PARTS[minute/5]);
|
|
|
|
}
|
|
|
|
void dump() {
|
|
|
|
const int ROWS = 10;
|
|
const int COLS = 11;
|
|
|
|
const char WHITE_PRE[] = "<em>";
|
|
const char WHITE_PST[] = "</em>";
|
|
const char GRAY_PRE[] = "";
|
|
const char GRAY_PST[] = "";
|
|
|
|
uint128 buffer = active;
|
|
|
|
int ci = 0;
|
|
|
|
for (int bi = 0; bi < sizeof(TEXT); bi++) {
|
|
|
|
int col = ci % COLS;
|
|
int row = ci / COLS;
|
|
if (col == 0)
|
|
printf("\n ");
|
|
|
|
const char* color_pre = (buffer & (uint128) 1) ? WHITE_PRE : GRAY_PRE;
|
|
const char* color_pst = (buffer & (uint128) 1) ? WHITE_PST : GRAY_PST;
|
|
|
|
printf(" %s%c", color_pre, TEXT[bi]);
|
|
if (TEXT[bi] >> 5 == 0b110)
|
|
putc(TEXT[++bi], stdout);
|
|
printf("%s", color_pst);
|
|
|
|
buffer = buffer >> 1;
|
|
ci++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void render(void) {
|
|
|
|
printf("clear\n");
|
|
time_t ts = time(NULL);
|
|
settime(ts);
|
|
dump();
|
|
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
emscripten_set_main_loop(render, 1, 1);
|
|
|
|
return 0;
|
|
|
|
}
|