OSDN Git Service

vga test and display done
authorastoria-d <astoria-d@mail.goo.ne.jp>
Fri, 8 Mar 2013 03:37:21 +0000 (12:37 +0900)
committerastoria-d <astoria-d@mail.goo.ne.jp>
Fri, 8 Mar 2013 03:37:21 +0000 (12:37 +0900)
display/dummy-driver.c
display/vgashm.c
display/window.c

index 422e537..8a53f48 100644 (file)
@@ -12,8 +12,9 @@
 
 static struct rgb15 *disp_data;
 void *vga_shm_get(void);
+void vga_shm_free(void* addr);
 
-//struct timespec sleep_inteval = {0, 1};
+struct timespec sleep_inteval = {0, 1000000 / VGA_REFRESH_RATE};
 
 static void pipe_sig_handler(int p) {
     printf("sigpipe!\n");
@@ -72,10 +73,109 @@ static void init_color1(void) {
     }
 }
 
+static void init_color2(void) {
+    int x,y;
+    for (y = 0; y < VGA_HEIGHT; y++) {
+        for (x = 0; x < VGA_WIDTH; x++) {
+            int pos = x + VGA_WIDTH * y;
+            if (y < VGA_HEIGHT / 7) {
+                //75% white
+                disp_data[pos].r = to5bit(0xffff) * 3 / 4;
+                disp_data[pos].g = to5bit(0xffff) * 3 / 4;
+                disp_data[pos].b = to5bit(0xffff) * 3 / 4;
+            }
+            else if (y < VGA_HEIGHT * 2 / 7) {
+                //yellow
+                disp_data[pos].r = to5bit(0xffff);
+                disp_data[pos].g = to5bit(0xffff);
+                disp_data[pos].b = to5bit(0);
+            }
+            else if (y < VGA_HEIGHT * 3 / 7) {
+                //cian
+                disp_data[pos].r = to5bit(0);
+                disp_data[pos].g = to5bit(0xffff);
+                disp_data[pos].b = to5bit(0xffff);
+            }
+            else if (y < VGA_HEIGHT * 4 / 7) {
+                //green
+                disp_data[pos].r = 0;
+                disp_data[pos].g = to5bit(0xffff);
+                disp_data[pos].b = 0;
+            }
+            else if (y < VGA_HEIGHT * 5 / 7) {
+                //magenda
+                disp_data[pos].r = to5bit(0xffff);
+                disp_data[pos].g = to5bit(0);
+                disp_data[pos].b = to5bit(0xffff);
+            }
+            else if (y < VGA_HEIGHT * 6 / 7) {
+                //red
+                disp_data[pos].r = to5bit(0xffff);
+                disp_data[pos].g = 0;
+                disp_data[pos].b = 0;
+            }
+            else if (y < VGA_HEIGHT * 7 / 7) {
+                //blue
+                disp_data[pos].r = 0;
+                disp_data[pos].g = 0;
+                disp_data[pos].b = to5bit(0xffff);
+            }
+
+        }
+    }
+}
+
+static void move_color1(void) {
+    init_color1();
+    int x, y;
+    static struct rgb15 v_line[VGA_HEIGHT];
+
+    while (1) {
+        for (y = 0; y < VGA_HEIGHT; y++) {
+            v_line[y] = disp_data[y * VGA_WIDTH];
+        }
+        for (y = 0; y < VGA_HEIGHT; y++) {
+            for (x = 0; x < VGA_WIDTH - 1; x++) {
+                int pos = x + VGA_WIDTH * y;
+                disp_data[pos] = disp_data[pos + 1];
+            }
+            disp_data[VGA_WIDTH * y - 1] = v_line[y];
+        }
+        nanosleep(&sleep_inteval, NULL);
+    }
+}
+
+static void move_color2(void) {
+    init_color2();
+    int y;
+    static struct rgb15 h_line[VGA_WIDTH];
+
+    while (1) {
+        memcpy(h_line, disp_data, sizeof(h_line));
+        for (y = 0; y < VGA_HEIGHT - 1; y++) {
+            memcpy( disp_data + VGA_WIDTH * y, disp_data + VGA_WIDTH * (y + 1), sizeof(h_line));
+        }
+        memcpy(disp_data + VGA_WIDTH * (VGA_HEIGHT - 1), h_line, sizeof(h_line));
+        nanosleep(&sleep_inteval, NULL);
+    }
+}
+
+static void print_usage(void) {
+    printf("dummy-driver app usage:\n");
+    printf("    dummy-driver [1-4]\n");
+    printf("    1: vertical color pattern test\n");
+    printf("    2: horiontal color pattern test\n");
+    printf("    3: vertical color pattern w/ scroll test\n");
+    printf("    4: horizontal color pattern w/ scroll test\n");
+    printf("    [no option]: reset shared memory\n");
+}
+
 int main(int argc, char** argv) {
     //register signal handler
     //signal(SIGPIPE, SIG_IGN);
     signal(SIGPIPE, pipe_sig_handler);
+
+    print_usage();
     
     /* get vga shared memory */
     if((disp_data = (struct rgb15 *)vga_shm_get()) == NULL)
@@ -84,8 +184,20 @@ int main(int argc, char** argv) {
         return -1;
     }
 
-    memset(disp_data, 0, sizeof(VGA_SHM_SIZE));
-    init_color1();
+    memset(disp_data, 0, VGA_SHM_SIZE);
+
+    if (argc > 1) {
+        if ( !strcmp(argv[1],"2") )
+            init_color2();
+        else if ( !strcmp(argv[1],"3") )
+            move_color1();
+        else if ( !strcmp(argv[1],"4") )
+            move_color2();
+        else
+            init_color1();
+    }
+
+    vga_shm_free(disp_data);
     
     return 0;
 }
index cebceb2..c554374 100644 (file)
@@ -20,7 +20,7 @@ void *vga_shm_get(void) {
 
     if((shmid = shmget(key, VGA_SHM_SIZE, IPC_CREAT|IPC_EXCL|0666)) == -1) 
     {
-        printf("Shared memory segment exists - opening as client\n");
+        //printf("Shared memory segment exists - opening as client\n");
 
         /* Segment probably already exists - try as a client */
         if((shmid = shmget(key, VGA_SHM_SIZE, 0)) == -1) 
@@ -40,3 +40,7 @@ void *vga_shm_get(void) {
     return ret;
 }
 
+void vga_shm_free(void* addr) {
+    shmdt(addr);
+}
+
index 1112389..584969e 100644 (file)
@@ -10,6 +10,7 @@ void *vga_shm_get(void);
 static struct rgb15 *disp_data;
 static GdkPixmap *pixmap = NULL;
 static GdkGC *gc = NULL;
+static int first_draw;
 
 GdkGC *set_color(gushort r, gushort g, gushort b)
 {
@@ -28,6 +29,13 @@ gint repaint(gpointer data){
 
     int x, y;
 
+    if (first_draw) {
+        //on first paint event, fill bgcolor with black.
+        first_draw = FALSE;
+        set_color(0, 0, 0);
+        gdk_draw_rectangle (pixmap, gc, TRUE, 0, 0, VGA_WIDTH, VGA_HEIGHT);
+    }
+
     //g_print ("draw...\n");
     x = y = 0;
     for (y = 0; y < VGA_HEIGHT; y++) {
@@ -35,8 +43,8 @@ gint repaint(gpointer data){
 
             int pos = x + VGA_WIDTH * y;
 
-            //if (x%2 || y%2)
-             //   continue;
+            if (x%2 || y%2)
+                continue;
 
             set_color( to16bit(disp_data[pos].r), 
                     to16bit(disp_data[pos].g),
@@ -75,10 +83,6 @@ int window_start(int argc, char** argv)
     GtkWidget *window;
     GtkWidget *drawing_area;
 
-    //init thread 
-    g_thread_init (NULL);
-    gdk_threads_init ();
-
     //get thread lock
     gdk_threads_enter();
 
@@ -125,10 +129,18 @@ static int shm_init(void) {
 int window_init(void) {
     int ret;
     disp_data = NULL;
+    first_draw = TRUE;
+
     ret = shm_init();
     if (!ret)
         return FALSE;
    
+    memset(disp_data, 0, sizeof(VGA_SHM_SIZE));
+
+    //init thread 
+    g_thread_init (NULL);
+    gdk_threads_init ();
+
     return TRUE;
 }