1#include "../../include/timer.hpp"
2#include "../../include/interrupt_controller.hpp"
5 : ic(interrupt_controller)
9void Timer::step(
int cycles) {
10 div_counter += cycles;
13 tima_counter += cycles;
16 case 0: threshold = 1024;
break;
17 case 1: threshold = 16;
break;
18 case 2: threshold = 64;
break;
19 case 3: threshold = 256;
break;
22 while (tima_counter >= threshold) {
23 tima_counter -= threshold;
27 ic.request_interrupt(InterruptType::Timer);
35u8 Timer::read(u16 address)
const {
37 case 0xFF04:
return (div_counter >> 8) & 0xFF;
38 case 0xFF05:
return tima;
39 case 0xFF06:
return tma;
40 case 0xFF07:
return tac;
45void Timer::write(u16 address, u8 value) {
47 case 0xFF04: div_counter = 0;
break;
48 case 0xFF05: tima = value;
break;
49 case 0xFF06: tma = value;
break;
50 case 0xFF07: tac = value;
break;