[nostalgia/core] Add ticksMs() function

This commit is contained in:
2020-07-14 01:07:07 -05:00
parent af494072fb
commit 745ea4a0ed
10 changed files with 74 additions and 48 deletions
+31 -2
View File
@@ -1,20 +1,45 @@
/*
* Copyright 2016 - 2019 gtalent2@gmail.com
* Copyright 2016 - 2020 gary@drinkingtea.net
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <nostalgia/core/config.hpp>
#include <nostalgia/core/core.hpp>
#include "addresses.hpp"
#include "irq.hpp"
extern "C" void isr();
namespace nostalgia::core {
// Timer Consts
constexpr auto NanoSecond = 1000000000;
constexpr auto MilliSecond = 1000;
constexpr int TicksMs59ns = (NanoSecond / MilliSecond) / 59.59;
extern volatile ox::Uint<config::GbaTimerBits> g_timerMs;
static void initIrq() {
REG_ISR = isr;
REG_IME = 1; // enable interrupts
}
static void initTimer() {
// make timer0 a ~1 millisecond timer
REG_TIMER0 = TicksMs59ns;
REG_TIMER0CTL = 0b11000011;
// enable interrupt for timer0
REG_IE |= Int_timer0;
}
ox::Error init(Context *ctx) {
oxReturnError(initGfx(ctx));
oxReturnError(initIrq(ctx));
initTimer();
initIrq();
return OxError(0);
}
@@ -24,4 +49,8 @@ ox::Error run(Context*) {
return OxError(0);
}
uint64_t ticksMs() {
return g_timerMs;
}
}