OSDN Git Service

Merge branch 'master' of git.sourceforge.jp:/gitroot/motonesemu/motonesemu
[motonesemu/motonesemu.git] / display / dummy-driver.c
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <time.h>
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <ctype.h>
7 #include <string.h>
8
9 #include "tools.h"
10 #include "vga.h"
11
12 static struct rgb15 *disp_data;
13 void *vga_shm_get(void);
14 void vga_shm_free(void* addr);
15
16 struct timespec sleep_inteval = {0, 1000000 / VGA_REFRESH_RATE};
17
18 static void init_color1(void) {
19     int x,y;
20     for (y = 0; y < VGA_HEIGHT; y++) {
21         for (x = 0; x < VGA_WIDTH; x++) {
22             int pos = x + VGA_WIDTH * y;
23             if (x < VGA_WIDTH / 7) {
24                 //75% white
25                 disp_data[pos].r = to5bit(0xffff) * 3 / 4;
26                 disp_data[pos].g = to5bit(0xffff) * 3 / 4;
27                 disp_data[pos].b = to5bit(0xffff) * 3 / 4;
28             }
29             else if (x < VGA_WIDTH * 2 / 7) {
30                 //yellow
31                 disp_data[pos].r = to5bit(0xffff);
32                 disp_data[pos].g = to5bit(0xffff);
33                 disp_data[pos].b = to5bit(0);
34             }
35             else if (x < VGA_WIDTH * 3 / 7) {
36                 //cian
37                 disp_data[pos].r = to5bit(0);
38                 disp_data[pos].g = to5bit(0xffff);
39                 disp_data[pos].b = to5bit(0xffff);
40             }
41             else if (x < VGA_WIDTH * 4 / 7) {
42                 //green
43                 disp_data[pos].r = 0;
44                 disp_data[pos].g = to5bit(0xffff);
45                 disp_data[pos].b = 0;
46             }
47             else if (x < VGA_WIDTH * 5 / 7) {
48                 //magenda
49                 disp_data[pos].r = to5bit(0xffff);
50                 disp_data[pos].g = to5bit(0);
51                 disp_data[pos].b = to5bit(0xffff);
52             }
53             else if (x < VGA_WIDTH * 6 / 7) {
54                 //red
55                 disp_data[pos].r = to5bit(0xffff);
56                 disp_data[pos].g = 0;
57                 disp_data[pos].b = 0;
58             }
59             else if (x < VGA_WIDTH * 7 / 7) {
60                 //blue
61                 disp_data[pos].r = 0;
62                 disp_data[pos].g = 0;
63                 disp_data[pos].b = to5bit(0xffff);
64             }
65
66         }
67     }
68 }
69
70 static void init_color2(void) {
71     int x,y;
72     for (y = 0; y < VGA_HEIGHT; y++) {
73         for (x = 0; x < VGA_WIDTH; x++) {
74             int pos = x + VGA_WIDTH * y;
75             if (y < VGA_HEIGHT / 7) {
76                 //75% white
77                 disp_data[pos].r = to5bit(0xffff) * 3 / 4;
78                 disp_data[pos].g = to5bit(0xffff) * 3 / 4;
79                 disp_data[pos].b = to5bit(0xffff) * 3 / 4;
80             }
81             else if (y < VGA_HEIGHT * 2 / 7) {
82                 //yellow
83                 disp_data[pos].r = to5bit(0xffff);
84                 disp_data[pos].g = to5bit(0xffff);
85                 disp_data[pos].b = to5bit(0);
86             }
87             else if (y < VGA_HEIGHT * 3 / 7) {
88                 //cian
89                 disp_data[pos].r = to5bit(0);
90                 disp_data[pos].g = to5bit(0xffff);
91                 disp_data[pos].b = to5bit(0xffff);
92             }
93             else if (y < VGA_HEIGHT * 4 / 7) {
94                 //green
95                 disp_data[pos].r = 0;
96                 disp_data[pos].g = to5bit(0xffff);
97                 disp_data[pos].b = 0;
98             }
99             else if (y < VGA_HEIGHT * 5 / 7) {
100                 //magenda
101                 disp_data[pos].r = to5bit(0xffff);
102                 disp_data[pos].g = to5bit(0);
103                 disp_data[pos].b = to5bit(0xffff);
104             }
105             else if (y < VGA_HEIGHT * 6 / 7) {
106                 //red
107                 disp_data[pos].r = to5bit(0xffff);
108                 disp_data[pos].g = 0;
109                 disp_data[pos].b = 0;
110             }
111             else if (y < VGA_HEIGHT * 7 / 7) {
112                 //blue
113                 disp_data[pos].r = 0;
114                 disp_data[pos].g = 0;
115                 disp_data[pos].b = to5bit(0xffff);
116             }
117
118         }
119     }
120 }
121
122 static void move_color1(void) {
123     init_color1();
124     int x, y;
125     static struct rgb15 v_line[VGA_HEIGHT];
126
127     while (1) {
128         for (y = 0; y < VGA_HEIGHT; y++) {
129             v_line[y] = disp_data[y * VGA_WIDTH];
130         }
131         for (y = 0; y < VGA_HEIGHT; y++) {
132             for (x = 0; x < VGA_WIDTH - 1; x++) {
133                 int pos = x + VGA_WIDTH * y;
134                 disp_data[pos] = disp_data[pos + 1];
135             }
136             disp_data[VGA_WIDTH * y - 1] = v_line[y];
137         }
138         nanosleep(&sleep_inteval, NULL);
139     }
140 }
141
142 static void move_color2(void) {
143     init_color2();
144     int y;
145     static struct rgb15 h_line[VGA_WIDTH];
146
147     while (1) {
148         memcpy(h_line, disp_data, sizeof(h_line));
149         for (y = 0; y < VGA_HEIGHT - 1; y++) {
150             memcpy( disp_data + VGA_WIDTH * y, disp_data + VGA_WIDTH * (y + 1), sizeof(h_line));
151         }
152         memcpy(disp_data + VGA_WIDTH * (VGA_HEIGHT - 1), h_line, sizeof(h_line));
153         nanosleep(&sleep_inteval, NULL);
154     }
155 }
156
157 static void print_usage(void) {
158     printf("dummy-driver app usage:\n");
159     printf("    dummy-driver [1-4]\n");
160     printf("    1: vertical color pattern test\n");
161     printf("    2: horiontal color pattern test\n");
162     printf("    3: vertical color pattern w/ scroll test\n");
163     printf("    4: horizontal color pattern w/ scroll test\n");
164     printf("    [no option]: reset shared memory\n");
165 }
166
167 int main(int argc, char** argv) {
168     print_usage();
169     
170     /* get vga shared memory */
171     if((disp_data = (struct rgb15 *)vga_shm_get()) == NULL)
172     {
173         fprintf(stderr, "error attaching shared memory.\n");
174         return -1;
175     }
176
177     memset(disp_data, 0, VGA_SHM_SIZE);
178
179     if (argc > 1) {
180         if ( !strcmp(argv[1],"2") )
181             init_color2();
182         else if ( !strcmp(argv[1],"3") )
183             move_color1();
184         else if ( !strcmp(argv[1],"4") )
185             move_color2();
186         else
187             init_color1();
188     }
189
190     vga_shm_free(disp_data);
191     
192     return 0;
193 }
194
195