diff options
Diffstat (limited to 'src/czx81.c')
-rw-r--r-- | src/czx81.c | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/src/czx81.c b/src/czx81.c index 57d3525..ccdceba 100644 --- a/src/czx81.c +++ b/src/czx81.c @@ -18,17 +18,63 @@ #include "wide_curses.h" #include <stdlib.h> +#include <unistd.h> +#include <time.h> #include <locale.h> +static long TimeDiff(const struct timespec *start, + const struct timespec *end) +{ + long diff; + + diff = (end->tv_nsec - start->tv_nsec) + + (end->tv_sec - start->tv_sec) * 1000000000L; + + return diff; +} + int main(void) { + struct timespec start; + int quit = FALSE; + setlocale(LC_ALL, ""); + initscr(); - printw("Euro\n"); - printw("\u20ac\n"); - addwstr(L"\u20AC\n"); + raw(); + noecho(); + keypad(stdscr, TRUE); + nodelay(stdscr, TRUE); + + clock_gettime(CLOCK_MONOTONIC, &start); + + while(!quit) + { + struct timespec end; + struct timespec pause = {0}; + int ch; + + clear(); + + ch = getch(); + + if (ch == 3) + { + quit = TRUE; + } + + refresh(); + + clock_gettime(CLOCK_MONOTONIC, &end); + start = end; + pause.tv_nsec = 20000000 - TimeDiff(&start, &end); + + if (pause.tv_nsec > 0) + { + nanosleep(&pause, NULL); + } + } - getch(); endwin(); return EXIT_SUCCESS; |