diff options
author | Ben Bridle <ben@derelict.engineering> | 2024-11-22 16:01:31 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2024-11-22 16:07:48 +1300 |
commit | e05888d141bc64e92d81859af0d87627e6fbc477 (patch) | |
tree | 8d4008de05045c5721cfa6ba49aa4c39cb12cf2f /arm9/source/devices/clock.c | |
parent | 2acaa6cb6c54c246b7f152f91d0428325c5b3ebd (diff) | |
download | bedrock-nds-e05888d141bc64e92d81859af0d87627e6fbc477.zip |
Simplify clock device implementation
Two pairs of generic get/set functions now do the role of the previous
pair of custom get/set functions for each timer.
Diffstat (limited to 'arm9/source/devices/clock.c')
-rw-r--r-- | arm9/source/devices/clock.c | 42 |
1 files changed, 5 insertions, 37 deletions
diff --git a/arm9/source/devices/clock.c b/arm9/source/devices/clock.c index 6f3ce85..6ecee1d 100644 --- a/arm9/source/devices/clock.c +++ b/arm9/source/devices/clock.c @@ -11,22 +11,10 @@ void uptime_handler(void) { uptime++; } // Check if any timer has expired. bool check_timers(ClockDevice *clk) { bool output = FALSE; - if (clk->t1.end && clk->t1.end <= uptime) { - clk->t1.end = 0; - output = TRUE; - } - if (clk->t2.end && clk->t2.end <= uptime) { - clk->t2.end = 0; - output = TRUE; - } - if (clk->t3.end && clk->t3.end <= uptime) { - clk->t3.end = 0; - output = TRUE; - } - if (clk->t4.end && clk->t4.end <= uptime) { - clk->t4.end = 0; - output = TRUE; - } + if (clk->t1.end && clk->t1.end <= uptime) { clk->t1.end = 0; output = TRUE; } + if (clk->t2.end && clk->t2.end <= uptime) { clk->t2.end = 0; output = TRUE; } + if (clk->t3.end && clk->t3.end <= uptime) { clk->t3.end = 0; output = TRUE; } + if (clk->t4.end && clk->t4.end <= uptime) { clk->t4.end = 0; output = TRUE; } return output; } @@ -34,8 +22,7 @@ u8 get_timer_high(ClockTimer *t) { if (t->end > uptime) { t->read = t->end - uptime; } else { - t->end = 0; - t->read = 0; + t->end = 0; t->read = 0; } return HIGH(t->read); } @@ -56,25 +43,6 @@ void set_timer_low(ClockTimer *t, u8 low) { } } -u8 get_timer1_high(ClockDevice *clock) { return get_timer_high(&clock->t1); } -u8 get_timer1_low( ClockDevice *clock) { return get_timer_low( &clock->t1); } -u8 get_timer2_high(ClockDevice *clock) { return get_timer_high(&clock->t2); } -u8 get_timer2_low( ClockDevice *clock) { return get_timer_low( &clock->t2); } -u8 get_timer3_high(ClockDevice *clock) { return get_timer_high(&clock->t3); } -u8 get_timer3_low( ClockDevice *clock) { return get_timer_low( &clock->t3); } -u8 get_timer4_high(ClockDevice *clock) { return get_timer_high(&clock->t4); } -u8 get_timer4_low( ClockDevice *clock) { return get_timer_low( &clock->t4); } - -void set_timer1_high(ClockDevice *clock, u8 high) { set_timer_high(&clock->t1, high); } -void set_timer1_low( ClockDevice *clock, u8 low) { set_timer_low( &clock->t1, low); } -void set_timer2_high(ClockDevice *clock, u8 high) { set_timer_high(&clock->t2, high); } -void set_timer2_low( ClockDevice *clock, u8 low) { set_timer_low( &clock->t2, low); } -void set_timer3_high(ClockDevice *clock, u8 high) { set_timer_high(&clock->t3, high); } -void set_timer3_low( ClockDevice *clock, u8 low) { set_timer_low( &clock->t3, low); } -void set_timer4_high(ClockDevice *clock, u8 high) { set_timer_high(&clock->t4, high); } -void set_timer4_low( ClockDevice *clock, u8 low) { set_timer_low( &clock->t4, low); } - - void init_clock(void) { // Start a 256Hz timer to increment the uptime value. timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(256), uptime_handler); |