DRIVER=dummy-driver
-OBJS=display.o window.o communication.o
+OBJS=display.o window.o vgashm.o
+DRIVER_OBJS=vgashm.o dummy-driver.o
LIBS=-L../libs -lmotones -pthread
$(BIN): $(OBJS) ../libs
gcc -o $(BIN) $(OBJS) $(LFLAGS)
-$(DRIVER): $(DRIVER).o
- gcc -o $(DRIVER) $(CFLAGS) $(DRIVER).c
+$(DRIVER): $(DRIVER_OBJS)
+ gcc -o $(DRIVER) $(DRIVER_OBJS)
.c.o:
gcc $(CFLAGS) -c $<
+++ /dev/null
-#include <stdio.h>
-#include <time.h>
-#include <pthread.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-
-#include "tools.h"
-#include "vga.h"
-
-void draw_point(int x, int y, char r, char g, char b);
-void set_pixel_color(int x, int y, int r, int g, int b);
-static struct rgb15 *disp_data;
-
-static pthread_t com_thread_id;
-
-static void *com_loop(void* arg) {
- int posx, posy;
-
- while (1) {
- struct timespec ts = {0, 100};
- for (posy = 0; posy < VGA_HEIGHT; posy++) {
- for (posx = 0; posx < VGA_WIDTH; posx++) {
- int pos = posx + VGA_WIDTH * posy;
- set_pixel_color(posx, posy,
- to16bit(disp_data[pos].r),
- to16bit(disp_data[pos].g),
- to16bit(disp_data[pos].b));
- }
- }
- nanosleep(&ts, NULL);
- }
- /*
- */
-
- /*
- while (1) {
- int x, y;
- int r,g,b;
- struct timespec ts = {0, 10};
-
- for (y = 0; y < VGA_HEIGHT; y++) {
- for (x = 0; x < VGA_WIDTH; x++) {
- set_pixel_color(x, y, r, g, b);
- }
- }
- r = rand();
- g = rand();
- b = rand();
- //dprint("sleep while...\n");
- nanosleep(&ts, NULL);
- }
- */
-
- return NULL;
-}
-
-static int shm_init(void) {
- key_t key;
- int shmid;
-
- //create shared memory
- key = ftok(VGA_SHM, VGA_SHM_PRJ_ID);
- if (key == -1) {
- fprintf(stderr, "error preparing shared memory.\n");
- return FALSE;
- }
-
- if((shmid = shmget(key, VGA_SHM_SIZE, IPC_CREAT|IPC_EXCL|0666)) == -1)
- {
- 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)
- {
- fprintf(stderr, "error opening shared memory.\n");
- return FALSE;
- }
- }
-
- /* Attach (map) the shared memory segment into the current process */
- if((disp_data = (struct rgb15 *)shmat(shmid, 0, 0)) == (struct rgb15*)-1)
- {
- fprintf(stderr, "error attaching shared memory.\n");
- return FALSE;
- }
- return TRUE;
-}
-
-int comm_init(void) {
- int ret;
- pthread_attr_t attr;
-
- ret = shm_init();
- if (!ret)
- return FALSE;
-
- ret = pthread_attr_init(&attr);
- if (ret != RT_OK)
- return FALSE;
-
- com_thread_id = 0;
- ret = pthread_create(&com_thread_id, &attr, com_loop, NULL);
- if (ret != RT_OK)
- return FALSE;
-
- return TRUE;
-}
-
#include "tools.h"
int window_start(int argc, char** argv);
-int comm_init(void);
-int receiver_init(void);
int window_init(void);
return -1;
}
- ret = comm_init();
- if (!ret) {
- fprintf(stderr, "comm init error.\n");
- return -1;
- }
- //return main_file();
return window_start(argc, argv);
}
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
-#include <sys/types.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
#include <ctype.h>
#include <string.h>
#include "vga.h"
static struct rgb15 *disp_data;
+void *vga_shm_get(void);
//struct timespec sleep_inteval = {0, 1};
disp_data[pos].b = to5bit(0xffff);
}
- /*
- disp_data[pos].r = to5bit(0xffff);
- disp_data[pos].g = to5bit(0);
- disp_data[pos].b = to5bit(0xffff);
- */
}
}
}
int main(int argc, char** argv) {
- key_t key;
- int shmid;
-
+ //register signal handler
//signal(SIGPIPE, SIG_IGN);
signal(SIGPIPE, pipe_sig_handler);
-
- //create shared memory
- key = ftok(VGA_SHM, VGA_SHM_PRJ_ID);
- if (key == -1) {
- fprintf(stderr, "error preparing shared memory.\n");
- return -1;
- }
-
- if((shmid = shmget(key, VGA_SHM_SIZE, IPC_CREAT|IPC_EXCL|0666)) == -1)
- {
- 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)
- {
- fprintf(stderr, "error opening shared memory.\n");
- return -1;
- }
- }
-
- /* Attach (map) the shared memory segment into the current process */
- if((disp_data = (struct rgb15 *)shmat(shmid, 0, 0)) == (struct rgb15*)-1)
+
+ /* get vga shared memory */
+ if((disp_data = (struct rgb15 *)vga_shm_get()) == NULL)
{
fprintf(stderr, "error attaching shared memory.\n");
return -1;
memset(disp_data, 0, sizeof(VGA_SHM_SIZE));
init_color1();
- while (1) {
- sleep(1);
- }
-
return 0;
}
#define VGA_WIDTH 640
#define VGA_HEIGHT 480
+/*
struct vga_pulse {
//vertical sync bit
unsigned int v_sync :1;
unsigned int b :5;
};
-
+#define DISPLAY_PORT 9999
+*/
struct rgb15 {
unsigned int r :5;
unsigned int g :5;
#define to5bit(col16) col16 * 0x1F / 0xFFFF
#define to16bit(col5) col5 * 0xFFFF / 0x1F
-#define DISPLAY_PORT 9999
#define VGA_SHM "vgadisp"
#define VGA_SHM_PRJ_ID 'm'
#define VGA_SHM_SIZE VGA_WIDTH * VGA_HEIGHT * sizeof (struct rgb15)
+#define VGA_REFRESH_RATE 60
--- /dev/null
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+
+#include "tools.h"
+#include "vga.h"
+
+void *vga_shm_get(void) {
+ void* ret;
+ key_t key;
+ int shmid;
+
+ //create shared memory
+ key = ftok(VGA_SHM, VGA_SHM_PRJ_ID);
+ if (key == -1) {
+ fprintf(stderr, "error preparing shared memory.\n");
+ return NULL;
+ }
+
+ if((shmid = shmget(key, VGA_SHM_SIZE, IPC_CREAT|IPC_EXCL|0666)) == -1)
+ {
+ 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)
+ {
+ fprintf(stderr, "error opening shared memory.\n");
+ return NULL;
+ }
+ }
+
+ /* Attach (map) the shared memory segment into the current process */
+ if((ret = shmat(shmid, 0, 0)) == (void*)-1)
+ {
+ fprintf(stderr, "error attaching shared memory.\n");
+ return NULL;
+ }
+
+ return ret;
+}
+
#include "tools.h"
#include "vga.h"
-int pix_buf[VGA_WIDTH][VGA_HEIGHT][3];
-GdkPixmap *pixmap = NULL;
-GdkGC *gc = NULL;
-
-void set_pixel_color(int x, int y, int r, int g, int b) {
- //g_print ("set pix...\n");
- pix_buf[x][y][0] = r;
- pix_buf[x][y][1] = g;
- pix_buf[x][y][2] = b;
-}
+void *vga_shm_get(void);
+
+static struct rgb15 *disp_data;
+static GdkPixmap *pixmap = NULL;
+static GdkGC *gc = NULL;
GdkGC *set_color(gushort r, gushort g, gushort b)
{
for (y = 0; y < VGA_HEIGHT; y++) {
for (x = 0; x < VGA_WIDTH; x++) {
- if (x%2 || y%2)
- continue;
+ int pos = x + VGA_WIDTH * y;
- set_color(pix_buf[x][y][0],
- pix_buf[x][y][1],
- pix_buf[x][y][2]);
+ //if (x%2 || y%2)
+ // continue;
+
+ set_color( to16bit(disp_data[pos].r),
+ to16bit(disp_data[pos].g),
+ to16bit(disp_data[pos].b));
gdk_draw_point (pixmap, gc, x, y);
}
}
}
void expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data){
+ //copy pixmap to the window
gdk_draw_pixmap(widget->window,
widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
pixmap,
gc = gdk_gc_new(window->window);
- gtk_timeout_add(1, repaint, (gpointer) drawing_area);
+ gtk_timeout_add(1000 / VGA_REFRESH_RATE, repaint, (gpointer) drawing_area);
gtk_main();
gdk_threads_leave();
return 0;
}
+static int shm_init(void) {
+
+ /* get vga shared memory */
+ if((disp_data = (struct rgb15 *)vga_shm_get()) == NULL)
+ {
+ fprintf(stderr, "error attaching shared memory.\n");
+ return FALSE;
+ }
+ return TRUE;
+}
+
int window_init(void) {
- memset(pix_buf, 0, sizeof(pix_buf));
+ int ret;
+ disp_data = NULL;
+ ret = shm_init();
+ if (!ret)
+ return FALSE;
+
return TRUE;
}