-
Notifications
You must be signed in to change notification settings - Fork 0
/
MC146818.h
94 lines (69 loc) · 2.15 KB
/
MC146818.h
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
91
92
93
94
//
// MC146818.h
// MIPS_Emulator
//
// Created by Matt on 5/12/16.
// Copyright © 2016 Matt. All rights reserved.
//
#ifndef MC146818_h
#define MC146818_h
#include "Device.h"
#include "MMIO_Device.h"
#include "Clockable_Device.h"
#include "Interruptable_Device.h"
#include <string>
#include <ctime>
#include <thread>
#include <atomic>
class MC146818 : public Device, public MMIO_Device, public Clockable_Device, public Interruptable_Device {
private:
// List of port addresses
std::vector<uint32_t> addresses;
//#define CMOS_BASE 0x14000070
// Also map to 0
#define CMOS_BASEPHYS 0x70u
// Address offset
const uint32_t addrOffset = 0x0;
// 64 Byte array
uint8_t registers[64];
// Time variables
time_t utctime;
struct tm* ptm;
// CPU Handle for interrupts
CPU* cpu;
// Changing interval to signal clock updates
uint32_t cycleInterval;
// Updates clock registers
void updateClock();
public:
// Constructor
MC146818();
// Destructor
~MC146818();
/*
* MMIO Device Interface
*/
// Called by MMU to initialize the device
void initDevice();
// Called by MMU to get address mappings
std::vector<uint32_t> getAddresses();
// Called by MMU to read a byte
uint8_t readByte(uint32_t address);
// Called by MMU to store a byte
void storeByte(uint32_t address, uint8_t value);
/*
* Clockable Device Interface
*/
// Used to get the interval between executions
uint32_t getCycleInterval();
// Indicates to the CPU that the interval is enabled
bool isEnabled();
// Called by CPU when cycle interval is reached
void onCycleExecute();
/*
* Interruptable Device Interface
*/
// Gets a pointer to the CPU so it can call sendInterrupt etc.
void getCPUHandle(CPU* cpu);
};
#endif /* MC146818_h */