-
Notifications
You must be signed in to change notification settings - Fork 14
/
basetimer.cpp
90 lines (72 loc) · 2.02 KB
/
basetimer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
VeMUlator - A Dreamcast Visual Memory Unit emulator for libretro
Copyright (C) 2018 Mahmoud Jaoune
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "basetimer.h"
VE_VMS_BASETIMER::VE_VMS_BASETIMER(VE_VMS_RAM *_ram, VE_VMS_INTERRUPTS *_intHandler, VE_VMS_CPU *_cpu)
{
ram = _ram;
intHandler = _intHandler;
cpu = _cpu;
BTR = 0;
}
VE_VMS_BASETIMER::~VE_VMS_BASETIMER()
{
}
void VE_VMS_BASETIMER::runTimer()
{
int BTCR_data = ram->readByte_RAW(BTCR);
bool BTStarted = (BTCR_data & 64) != 0;
bool Int0Enabled = (BTCR_data & 1) != 0;
bool Int1Enabled = (BTCR_data & 4) != 0;
int int1cycle;
int cycleControl = ((BTCR_data & 16) >> 4) | ((BTCR_data & 32) >> 4);
switch (cycleControl)
{
case 0:
int1cycle = 32;
break;
case 1:
int1cycle = 128;
break;
case 2:
int1cycle = 512;
break;
case 3:
int1cycle = 2048;
break;
default:
int1cycle = 2048;
}
if(BTStarted)
{
BTR += 32786.0 / cpu->getCurrentFrequency();
//Throw interrupt 1 source when cycle chosen is reached
if(BTR >= int1cycle)
{
BTCR_data |= 8;
ram->writeByte_RAW(BTCR, BTCR_data);
if (Int1Enabled)
intHandler->setINT3();
}
if((BTR > 16383) || (BTR > 63 && ((BTCR_data & 128) != 0)))
{
//Throw full (14-bit) overflow interrupt (Interrupt 0 source)
BTCR_data |= 2;
ram->writeByte_RAW(BTCR, BTCR_data);
if(Int0Enabled)
intHandler->setINT3();
if(BTR > 16383) BTR = 0;
}
}
}