#pragma once

#include <common.h>

typedef struct {
    u16 div;
    u8 tima;
    u8 tma;
    u8 tac;
    bool tima_needs_reset;
    bool tima_just_reset;
} timer_context;

typedef struct {
    timer_context ctx;
} timer_state;

void timer_save_state(timer_state*);
void timer_load_state(const timer_state*);

void timer_init();
void timer_tick();

void timer_write(u16 address, u8 value);
u8 timer_read(u16 address);

timer_context *timer_get_context();