-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor RTC subsystem [WIP] #563
base: preview
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm the RTC guy for the KOS Sega Dreamcast SDK, and we also are using standard C time_t
in our RTC API like you are now... I know my opinion doesn't matter even remotely here, but I think this a fantastic API and just wanted to make like 2 teensy comments about marking the API deprecated for the Doxygen so it gets added to the top-level "deprecated" page. lol.
Keep up the good work.
By the way, if you guys ever do anything about "handling the |
Rasky informed me that LibDragon is already good on the 2038 problem: I haven't actually tested to see what our practical limit is on the newlib side. On the RTC side, we're realistically constrained between 1900-2099 (Joybus RTC limit) or 1996-2095 (64DD RTC limit) |
#include <libdragon.h> | ||
|
||
#define BLACK 0x000000FF | ||
#define WHITE 0xFFFFFFFF | ||
|
||
#define JOYSTICK_DEAD_ZONE 32 | ||
|
||
#define MAX(a,b) ({ typeof(a) _a = a; typeof(b) _b = b; _a > _b ? _a : _b; }) | ||
#define MIN(a,b) ({ typeof(a) _a = a; typeof(b) _b = b; _a < _b ? _a : _b; }) | ||
#define CLAMP(x, min, max) (MIN(MAX((x), (min)), (max))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these part of the C standard library yet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NOPE. I think they just got added to C23 for floats, but nah, nothing that I know of as a generic macro... I even have these in my own codebase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LibDragon has them in the "private header" #include "utils.h"
:
Lines 12 to 14 in 8fcaba6
#define MAX(a,b) ({ typeof(a) _a = a; typeof(b) _b = b; _a > _b ? _a : _b; }) | |
#define MIN(a,b) ({ typeof(a) _a = a; typeof(b) _b = b; _a < _b ? _a : _b; }) | |
#define CLAMP(x, min, max) (MIN(MAX((x), (min)), (max))) |
They seem useful enough that we should expose them to LibDragon devs, but they're generic enough that exposing them in <libdragon.h>
could cause naming conflicts. (Basically every C code base has these peppered around in some form or another).
I know LibDragon strongly encourages including the entire library as a single header, but I definitely see the benefits for utils.h
to be exposed as an "optional public header": #include <libdragon/utils.h>
or something.
This is another one of those "it's a little late to change now" things, but sometimes I wish LibDragon used a common prefix so that we wouldn't have to worry (as much) about namespace collisions with other libraries and user code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A solution could be hiding them behind an opt-in preprocessor define. Like Microsoft does for defining M_PI
and friends in math.h
. I think you always get them with GCC but with Microsoft's implementation, you need #define _USE_MATH_DEFINES
to have them defined.
Should the RTC subsystem be responsible for enforcing min/max dates based on RTC hardware limitations?
Unfortunately, both "potentially viable" options have a huge gaping caveat: EverDrive 3.0/X7 does not support Joybus RTC write commands. If we read-back, the write will always have failed, so the player can't even just set the time for the current play session. If we don't read-back, the write will always silently fail to persist, but at least the time can be set ephemerally. Animal Forest reads the Joybus RTC continously to update the time, so it would seem to favor the "read-back" approach, and I think this is actually the least-suprising, most-useful of the options. |
rtc_time_t
struct in favor of standard C time types.settimeofday
so standard C APIs can be used to get and set RTCStill left to do: