From ce03a8525f0e3a6567dd6e86be434e2605d14851 Mon Sep 17 00:00:00 2001 From: crc <> Date: Wed, 29 Mar 2023 00:33:47 +0000 Subject: [PATCH] nga-c: move clock device to a separate file FossilOrigin-Name: 9e50173fae65b6fa1f486a089bcf487fdb7998c0090d120d441ee4df66663548 --- RELEASE-NOTES | 13 ++++++ vm/nga-c/dev-clock.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ vm/nga-c/retro.c | 81 +------------------------------------ 3 files changed, 109 insertions(+), 80 deletions(-) create mode 100644 vm/nga-c/dev-clock.c diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 9cd6de8..7c57c86 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -8,4 +8,17 @@ ================================================================ +* nga-c: split device code into separate source files + +================================================================ + +Development Notes: + +It is likely that starting with this release, the source +distribution will default to building an executable from +the amalgamation (example/amalgamate.retro) rather than +rebuilding the image with each build. A new Makefile target +will be added for those wanting or needing to build a +custom ngaImage. + ================================================================ diff --git a/vm/nga-c/dev-clock.c b/vm/nga-c/dev-clock.c new file mode 100644 index 0000000..bbb8a94 --- /dev/null +++ b/vm/nga-c/dev-clock.c @@ -0,0 +1,95 @@ +/*--------------------------------------------------------------------- + Copyright (c) 2008 - 2022, Charles Childers + + Portions are based on Ngaro, which was additionally copyright + by the following: + + Copyright (c) 2009 - 2010, Luke Parrish + Copyright (c) 2010, Marc Simpson + Copyright (c) 2010, Jay Skeer + Copyright (c) 2011, Kenneth Keating + ---------------------------------------------------------------------*/ + +/* Time and Date Functions --------------------------------------------*/ +#ifdef ENABLE_CLOCK +void clock_time(NgaState *vm) { + stack_push(vm, (CELL)time(NULL)); +} + +void clock_day(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)localtime(&t)->tm_mday); +} + +void clock_month(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)localtime(&t)->tm_mon + 1); +} + +void clock_year(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)localtime(&t)->tm_year + 1900); +} + +void clock_hour(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)localtime(&t)->tm_hour); +} + +void clock_minute(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)localtime(&t)->tm_min); +} + +void clock_second(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)localtime(&t)->tm_sec); +} + +void clock_day_utc(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)gmtime(&t)->tm_mday); +} + +void clock_month_utc(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)gmtime(&t)->tm_mon + 1); +} + +void clock_year_utc(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)gmtime(&t)->tm_year + 1900); +} + +void clock_hour_utc(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)gmtime(&t)->tm_hour); +} + +void clock_minute_utc(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)gmtime(&t)->tm_min); +} + +void clock_second_utc(NgaState *vm) { + time_t t = time(NULL); + stack_push(vm, (CELL)gmtime(&t)->tm_sec); +} + +Handler ClockActions[] = { + clock_time, + clock_day, clock_month, clock_year, + clock_hour, clock_minute, clock_second, + clock_day_utc, clock_month_utc, clock_year_utc, + clock_hour_utc, clock_minute_utc, clock_second_utc +}; + +void query_clock(NgaState *vm) { + stack_push(vm, 0); + stack_push(vm, 5); +} + +void io_clock(NgaState *vm) { + ClockActions[stack_pop(vm)](vm); +} +#endif diff --git a/vm/nga-c/retro.c b/vm/nga-c/retro.c index 49ce021..989accb 100644 --- a/vm/nga-c/retro.c +++ b/vm/nga-c/retro.c @@ -377,86 +377,7 @@ void query_blocks(NgaState *vm) { /* Time and Date Functions --------------------------------------------*/ #ifdef ENABLE_CLOCK -void clock_time(NgaState *vm) { - stack_push(vm, (CELL)time(NULL)); -} - -void clock_day(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)localtime(&t)->tm_mday); -} - -void clock_month(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)localtime(&t)->tm_mon + 1); -} - -void clock_year(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)localtime(&t)->tm_year + 1900); -} - -void clock_hour(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)localtime(&t)->tm_hour); -} - -void clock_minute(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)localtime(&t)->tm_min); -} - -void clock_second(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)localtime(&t)->tm_sec); -} - -void clock_day_utc(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)gmtime(&t)->tm_mday); -} - -void clock_month_utc(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)gmtime(&t)->tm_mon + 1); -} - -void clock_year_utc(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)gmtime(&t)->tm_year + 1900); -} - -void clock_hour_utc(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)gmtime(&t)->tm_hour); -} - -void clock_minute_utc(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)gmtime(&t)->tm_min); -} - -void clock_second_utc(NgaState *vm) { - time_t t = time(NULL); - stack_push(vm, (CELL)gmtime(&t)->tm_sec); -} - -Handler ClockActions[] = { - clock_time, - clock_day, clock_month, clock_year, - clock_hour, clock_minute, clock_second, - clock_day_utc, clock_month_utc, clock_year_utc, - clock_hour_utc, clock_minute_utc, clock_second_utc -}; - -void query_clock(NgaState *vm) { - stack_push(vm, 0); - stack_push(vm, 5); -} - -void io_clock(NgaState *vm) { - ClockActions[stack_pop(vm)](vm); -} +#include "dev-clock.c" #endif