timer - Start implementing timer

This commit is contained in:
madmaurice 2023-09-19 23:20:42 +02:00
parent 6263386b11
commit da91ec4d1b
3 changed files with 43 additions and 1 deletions

View file

@ -1,6 +1,6 @@
TARGETS := libemu.a vgbc vgbc.test vgbc.inspect vgbc.gbdif vgbc.lcdtest TARGETS := libemu.a vgbc vgbc.test vgbc.inspect vgbc.gbdif vgbc.lcdtest
sfml_packages := sfml-graphics sfml_packages := sfml-graphics sfml-system
sfml_CXXFLAGS := $(shell pkg-config --cflags $(sfml_packages)) sfml_CXXFLAGS := $(shell pkg-config --cflags $(sfml_packages))
sfml_LDFLAGS := $(shell pkg-config --libs $(sfml_packages)) sfml_LDFLAGS := $(shell pkg-config --libs $(sfml_packages))
@ -21,6 +21,7 @@ modules_libemu.a := memory/device.o \
lcd/lcd.o \ lcd/lcd.o \
lcd/palette.o \ lcd/palette.o \
input/joypad.o \ input/joypad.o \
timer/timer.o \
modules_vgbc := main.o libemu.a modules_vgbc := main.o libemu.a
verb_vgbc := link verb_vgbc := link

24
timer/timer.cpp Normal file
View file

@ -0,0 +1,24 @@
#include <timer/timer.h>
void TimerDiv::write8(u16 addr, u8 data)
{
switch(addr) {
case 0x0000: // DIV
divClock.restart();
break;
}
}
u8 TimerDiv::read8(u16 addr)
{
switch(addr) {
case 0x0000: // DIV
{
sf::Time elapsed = divClock.getElapsedTime();
sf::Int64 regval = elapsed.asMicroseconds();
return (regval * 16384 / 1000000) & 0xFF;
}
default:
return 0x00;
}
}

17
timer/timer.h Normal file
View file

@ -0,0 +1,17 @@
#pragma once
#include <cpu/cpu.h>
#include <misc/types.h>
#include <memory/device.h>
#include <SFML/System/Clock.hpp>
class TimerDiv : public Mem_device {
private:
sf::Clock divClock;
public:
TimerDiv() = default;
virtual void write8(u16 addr, u8 data);
virtual u8 read8(u16 addr);
};