From e67e939fb9414fd338fae58429f34a30c574a18a Mon Sep 17 00:00:00 2001 From: Serge Vakulenko Date: Fri, 20 Nov 2015 22:44:37 -0800 Subject: [PATCH] Add aclock game. --- rootfs.manifest | 1 + src/games/.gitignore | 1 + src/games/Makefile | 2 +- src/games/aclock.c | 175 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 1 deletion(-) create mode 100644 src/games/aclock.c diff --git a/rootfs.manifest b/rootfs.manifest index 90b71a1..618ccce 100644 --- a/rootfs.manifest +++ b/rootfs.manifest @@ -671,6 +671,7 @@ default filemode 0775 dir /games file /games/adventure +file /games/aclock file /games/arithmetic file /games/atc file /games/backgammon diff --git a/src/games/.gitignore b/src/games/.gitignore index 7bf379f..eb5a089 100644 --- a/src/games/.gitignore +++ b/src/games/.gitignore @@ -1,3 +1,4 @@ +aclock arithmetic banner bcd diff --git a/src/games/Makefile b/src/games/Makefile index ff559ab..4049eca 100644 --- a/src/games/Makefile +++ b/src/games/Makefile @@ -18,7 +18,7 @@ SUBDIR = adventure atc backgammon battlestar boggle btlgammon \ # C programs that live in the current directory and do not need # explicit make lines. # -STD = banner arithmetic bcd cfscores factor fish morse \ +STD = banner aclock arithmetic bcd cfscores factor fish morse \ number ppt wump # C programs that live in the current directory and need explicit make lines. diff --git a/src/games/aclock.c b/src/games/aclock.c new file mode 100644 index 0000000..0762cd5 --- /dev/null +++ b/src/games/aclock.c @@ -0,0 +1,175 @@ +/* + * aclock - ascii clock for UNIX Console + * + * Copyright (c) 1994-2013 Antoni Sawicki + * Version 2.3 (unix-termcap); Mountain View, July 2013 + * + * Ported to RetroBSD by Serge Vakulenko + */ +#include +#include +#include +#include +#include + +#define FontWH_Ratio 2 + +void cls(void) +{ + printf("\33[2J"); +} + +void draw_point(int x, int y, char c) +{ + printf("\33[%u;%uH%c", y+1, x+1, c); +} + +void draw_text(int x, int y, char *string) +{ + printf("\33[%u;%uH%s", y+1, x+1, string); +} + +int icos(int n, int maxval) +{ + static const int tab[] = { + 1000000000, 994521895, 978147600, 951056516, 913545457, + 866025403, 809016994, 743144825, 669130606, 587785252, + 500000000, 406736643, 309016994, 207911690, 104528463, + 0, -104528463, -207911690, -309016994, -406736643, + -499999999, -587785252, -669130606, -743144825, -809016994, + -866025403, -913545457, -951056516, -978147600, -994521895, + -1000000000, -994521895, -978147600, -951056516, -913545457, + -866025403, -809016994, -743144825, -669130606, -587785252, + -500000000, -406736643, -309016994, -207911690, -104528463, + 0, 104528463, 207911690, 309016994, 406736643, + 500000000, 587785252, 669130606, 743144825, 809016994, + 866025403, 913545457, 951056516, 978147600, 994521895, + }; + if (n < 0) + n += 60; + return tab[n%60] / 1000 * maxval / 1000000; +} + +int isin(int n, int maxval) +{ + static const int tab[] = { + 0, 104528463, 207911690, 309016994, 406736643, + 499999999, 587785252, 669130606, 743144825, 809016994, + 866025403, 913545457, 951056516, 978147600, 994521895, + 1000000000, 994521895, 978147600, 951056516, 913545457, + 866025403, 809016994, 743144825, 669130606, 587785252, + 499999999, 406736643, 309016994, 207911690, 104528463, + 0, -104528463, -207911690, -309016994, -406736643, + -500000000, -587785252, -669130606, -743144825, -809016994, + -866025403, -913545457, -951056516, -978147600, -994521895, + -1000000000,-994521895, -978147600, -951056516, -913545457, + -866025403, -809016994, -743144825, -669130606, -587785252, + -499999999, -406736643, -309016994, -207911690, -104528463, + }; + if (n < 0) + n += 60; + return tab[n%60] / 1000 * maxval / 1000000; +} + +void draw_circle(int hand_max, int sYcen, int sXcen) +{ + int x, y, r; + char c; + + for (r=0; r<60; r++) { + x = icos(r, hand_max) * FontWH_Ratio + sXcen; + y = isin(r, hand_max) + sYcen; + switch (r) { + case 0: + case 5: + case 10: + case 15: + case 20: + case 25: + case 30: + case 35: + case 40: + case 45: + case 50: + case 55: + c='o'; + break; + default: + c='.'; + break; + } + draw_point(x, y, c); + } +} + +void draw_hand(int minute, int hlength, char c, int sXcen, int sYcen) +{ + int x, y, n; + + for (n=1; ntm_hour*5) + (ltime->tm_min/10), 2*hand_max/3, 'h', sXcen, sYcen); + draw_hand(ltime->tm_min, hand_max-2, 'm', sXcen, sYcen); + draw_hand(ltime->tm_sec, hand_max-1, '.', sXcen, sYcen); + + draw_text(sXcen - 4, sYcen - (3*hand_max/5), "RetroBSD"); + sprintf(digital_time, "[%02d:%02d:%02d]", ltime->tm_hour, ltime->tm_min, ltime->tm_sec); + draw_text(sXcen - 5, sYcen + (3*hand_max/5), digital_time); + + fflush(stdout); + sleep(1); + + draw_hand((ltime->tm_hour*5) + (ltime->tm_min/10), 2*hand_max/3, ' ', sXcen, sYcen); + draw_hand(ltime->tm_min, hand_max-2, ' ', sXcen, sYcen); + draw_hand(ltime->tm_sec, hand_max-1, ' ', sXcen, sYcen); + } + return 0; +}