-
Notifications
You must be signed in to change notification settings - Fork 6
/
timer-8018x.inc
93 lines (71 loc) · 1.92 KB
/
timer-8018x.inc
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
//-------------------------------------------------------------------------------
// EMU86 - 8018X timers
//-------------------------------------------------------------------------------
#define TIMER0_COUNT 0 // timer 0 count register
#define TIMER0_MAX 1 // timer 0 max A register
#define TIMER0_MODE 3 // timer 0 mode & control register
#define TIMER2_COUNT 8 // timer 2 count register
#define TIMER2_MAX 9 // timer 2 max register
#define TIMER2_MODE 11 // timer 2 mode & control register
static word_t timer_regs [TIMER_REG_COUNT];
#define TIMER_MODE_EN 0x8000 // timer enabled
// Timer device procedure
// Called from main emulator loop
void timer_proc (void)
{
int timer2 = 0;
if (timer_regs [TIMER2_MODE] & TIMER_MODE_EN)
{
timer_regs [TIMER2_COUNT]++;
if (timer_regs [TIMER2_COUNT] == timer_regs [TIMER2_MAX]) {
timer_regs [TIMER2_COUNT] = 0;
timer2 = 1;
}
}
if (timer_regs [TIMER0_MODE] & TIMER_MODE_EN)
{
if (timer2) timer_regs [TIMER0_COUNT]++;
if (timer_regs [TIMER0_COUNT] == timer_regs [TIMER0_MAX]) {
timer_regs [TIMER0_COUNT] = 0;
int_line_set (INT_LINE_TIMER0, 1);
}
else
{
int_line_set (INT_LINE_TIMER0, 0);
}
}
}
// Timer I/O read
int timer_io_read (word_t p, word_t * w)
{
int r = p >> 1;
*w = timer_regs [r];
return 0;
}
// Timer I/O write
int timer_io_write (word_t p, word_t w)
{
int r = p >> 1;
timer_regs [r] = w;
return 0;
}
// Timer initialization
void timer_init ()
{
#ifdef MCU_8018X_EB
timer_regs [TIMER0_MODE] = 0;
timer_regs [TIMER0_COUNT] = 0;
timer_regs [TIMER0_MAX] = 0;
timer_regs [TIMER2_MODE] = 0;
timer_regs [TIMER2_COUNT] = 0;
timer_regs [TIMER2_MAX] = 0;
#endif
#ifdef MCU_R8810
timer_regs [TIMER0_MODE] = TIMER_MODE_EN;
timer_regs [TIMER0_COUNT] = 0;
timer_regs [TIMER0_MAX] = 1000;
timer_regs [TIMER2_MODE] = TIMER_MODE_EN;
timer_regs [TIMER2_COUNT] = 0;
timer_regs [TIMER2_MAX] = 5000;
#endif
}