-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfish.c
197 lines (158 loc) · 4.45 KB
/
fish.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include <stdint.h>
#include "ece391support.h"
#include "ece391syscall.h"
#include "blink.h"
#define NULL 0
#define WAIT 200
uint8_t *vmem_base_addr;
uint8_t *mp1_set_video_mode (void);
void add_frames(uint8_t *, uint8_t *, int32_t);
void ece391_memset(void* memory, char c, int n);
int32_t ece391_memcpy(void* dest, const void* src, int32_t n);
uint8_t file0[] = "frame0.txt";
uint8_t file1[] = "frame1.txt";
/* Extern the externally-visible MP1 functions */
extern int mp1_ioctl(unsigned long arg, unsigned long cmd);
extern void mp1_rtc_tasklet(unsigned long trash);
static struct mp1_blink_struct blink_array[80*25];
int main(void)
{
int rtc_fd, ret_val, i, garbage;
struct mp1_blink_struct blink_struct;
ece391_memset(blink_array, 0, sizeof(struct mp1_blink_struct)*80*25);
if(mp1_set_video_mode() == NULL) {
return -1;
}
rtc_fd = ece391_open((uint8_t*)"rtc");
add_frames(file0, file1, rtc_fd);
ret_val = 32;
ret_val = ece391_write(rtc_fd, &ret_val, 4);
for(i=0; i<WAIT; i++) {
ece391_read(rtc_fd, &garbage, 4);
mp1_rtc_tasklet(garbage);
}
blink_struct.on_char = 'I';
blink_struct.off_char = 'M';
blink_struct.on_length = 7;
blink_struct.off_length = 6;
blink_struct.location = 6*80+60;
mp1_ioctl((unsigned long)&blink_struct, RTC_ADD);
for(i=0; i<WAIT; i++) {
ece391_read(rtc_fd, &garbage, 4);
mp1_rtc_tasklet(garbage);
}
mp1_ioctl((40 << 16 | (6*80+60)), RTC_SYNC);
for(i=0; i<WAIT; i++) {
ece391_read(rtc_fd, &garbage, 4);
mp1_rtc_tasklet(garbage);
}
blink_struct.location = 60;
mp1_ioctl(i, RTC_REMOVE);
for(i=0; i<80*25; i++) {
ece391_read(rtc_fd, &garbage, 4);
mp1_rtc_tasklet(garbage);
}
ece391_close(rtc_fd);
return 0;
}
void
add_frames(uint8_t *f0, uint8_t *f1, int32_t rtc_fd)
{
int32_t row, col, offset = 40, eof0 = 0, eof1 = 0, num_bytes;
int32_t fd0, fd1;
struct mp1_blink_struct blink_struct;
uint8_t c0 = '0', c1 = '0';
blink_struct.on_length = 15;
blink_struct.off_length = 15;
row = 0;
if( (fd0 = ece391_open(f0)) < 0 ) {
ece391_halt(-1);
}
if( (fd1 = ece391_open(f1)) < 0 ) {
ece391_halt(-1);
}
while(eof0 == 0 || eof1 == 0) {
col = 0;
while(1) {
if(c0 != '\n') {
num_bytes = ece391_read(fd0, &c0, 1);
if(num_bytes == 0) {
c0 = '\n';
eof0 = 1;
}
}
if(c1 != '\n') {
num_bytes = ece391_read(fd1, &c1, 1);
if(num_bytes == 0) {
c1 = '\n';
eof1 = 1;
}
}
if(c0 == '\n' && c1 == '\n') {
break;
} else {
if((c0 != ' ' && c0 != '\n') || (c1 != ' ' && c1 != '\n')) {
blink_struct.on_char = ( (c0 == '\n') ? ' ' : c0);
blink_struct.off_char = ( (c1 == '\n') ? ' ' : c1);
blink_struct.location = row*80 + col + offset;
mp1_ioctl((unsigned long)&blink_struct, RTC_ADD);
}
}
col++;
}
if(eof0) {
c0 = '\n';
ece391_close(fd0);
} else {
c0 = '0';
}
if(eof1) {
c1 = '\n';
ece391_close(fd1);
} else {
c1 = '0';
}
row++;
}
}
uint8_t*
mp1_set_video_mode (void)
{
if(ece391_vidmap(&vmem_base_addr) == -1) {
return NULL;
} else {
return vmem_base_addr;
}
}
void* mp1_malloc(int32_t size)
{
int32_t i;
for(i=0; i< 80*25; i++) {
if(blink_array[i].location == 0) {
return &blink_array[i];
}
}
return NULL;
}
void mp1_free(void* memory)
{
ece391_memset(memory, 0, sizeof(struct mp1_blink_struct));
}
void ece391_memset(void* memory, char c, int n)
{
char* mem = (char*)memory;
int i;
for(i=0; i<n; i++) {
mem[i] = c;
}
}
int32_t ece391_memcpy(void* dest, const void* src, int32_t n)
{
int32_t i;
char* d = (char*)dest;
char* s = (char*)src;
for(i=0; i<n; i++) {
d[i] = s[i];
}
return 0;
}