-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathtv.c
112 lines (89 loc) · 1.53 KB
/
tv.c
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <stdio.h>
#include <signal.h>
#include <sys/time.h>
#include "usim.h"
#include "ucode.h"
#include "x11.h"
#define Black 0x000000
#define White 0xffffff
unsigned int tv_width = 768;
unsigned int tv_height = 897;
unsigned int tv_bitmap[(768 * 1024)];
int tv_csr;
void
tv_xbus_read(int offset, unsigned int *pv)
{
*pv = tv_csr;
}
void
tv_xbus_write(int offset, unsigned int v)
{
tv_csr = v;
tv_csr &= ~(1 << 4);
deassert_xbus_interrupt();
}
void
tv_post_60hz_interrupt(void)
{
tv_csr |= 1 << 4;
assert_xbus_interrupt();
}
void
sigalrm_handler(int arg)
{
tv_post_60hz_interrupt();
}
void
tv_write(int offset, unsigned int bits)
{
int i;
int h;
int v;
offset *= 32;
v = offset / tv_width;
h = offset % tv_width;
for (i = 0; i < 32; i++) {
tv_bitmap[offset + i] = (bits & 1) ? Black : White;
bits >>= 1;
}
accumulate_update(h, v, 32, 1);
}
void
tv_poll(void)
{
x11_event();
}
void
tv_read(int offset, unsigned int *pv)
{
unsigned long bits;
int i;
offset *= 32;
if (offset > tv_width * tv_height) {
printf("tv: tv_read past end; " "offset %o\n", offset);
*pv = 0;
return;
}
bits = 0;
for (i = 0; i < 32; i++) {
if (tv_bitmap[offset + i] == Black)
bits |= 1UL << i;
}
*pv = bits;
}
void
tv_init(void)
{
x11_init();
{
struct itimerval itimer;
int usecs;
signal(SIGVTALRM, sigalrm_handler);
usecs = 16000;
itimer.it_interval.tv_sec = 0;
itimer.it_interval.tv_usec = usecs;
itimer.it_value.tv_sec = 0;
itimer.it_value.tv_usec = usecs;
setitimer(ITIMER_VIRTUAL, &itimer, 0);
}
}