-
Notifications
You must be signed in to change notification settings - Fork 4
/
imshow.c
76 lines (62 loc) · 1.54 KB
/
imshow.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
#include"types.h"
#include "user.h"
#include "fcntl.h"
int main(int argc, char** argv) {
int fd;
if( (fd = open("display",O_WRONLY)) == 0) {
exit();
}
int img;
if( (img = open("cover.raw",0)) == 0) {
exit();
}
// switch modes to VGA 0x13
if(ioctl(fd,1,0x13) < 0) {
printf(2,"error: ioctl to switch to VGA mode failed.\n");
exit();
}
int k;
char buf[1000];
for(k=0;k<64;k++) {
int readbytes = read(img,buf,1000);
if(readbytes!=1000) {
printf(1,"Huh, only read %d bytes from file\n",readbytes);
}
int wrotebytes = write(fd,buf,1000);
if(wrotebytes!=1000) {
printf(1,"Huh, only wrote %d bytes to display\n",wrotebytes);
}
}
sleep(100);
int beats;
for(beats=0;beats<8;beats++) {
int fade;
for(fade=63;fade>0;fade-=3) {
// the value is a 32-bit struct containing (palette#, R, G, B)
if(ioctl(fd,2,0x0f<<24 | 63 << 16 | fade << 8 | fade ) < 0) {
printf(2,"Error setting palette color.\n");
}
sleep(1);
}
for(fade=0;fade<63;fade+=3) {
if(ioctl(fd,2,0x0f<<24 | 63 << 16 | fade << 8 | fade ) < 0) {
printf(2,"Error setting palette color.\n");
}
sleep(1);
}
if(ioctl(fd,2,0x0f<<24 | 63 << 16 | 63 << 8 | 63 ) < 0) {
printf(2,"Error setting palette color.\n");
}
if(beats%2)
sleep(100);
else
sleep(10);
}
// switch back to text
if(ioctl(fd,1,0x3) < 0) {
printf(2,"error: ioctl to restore screen to text failed.\n");
exit();
}
exit();
return 0;
}