OSDN Git Service

project start.
authorastoria-d <astoria-d@mail.goo.ne.jp>
Tue, 12 Feb 2013 03:53:12 +0000 (12:53 +0900)
committerastoria-d <astoria-d@mail.goo.ne.jp>
Tue, 12 Feb 2013 03:53:12 +0000 (12:53 +0900)
emulator/Makefile [new file with mode: 0644]
emulator/bus.c [new file with mode: 0644]
emulator/clock.c [new file with mode: 0644]
emulator/clock.h [new file with mode: 0644]
emulator/emu-main.c [new file with mode: 0644]
emulator/tools.c [new file with mode: 0644]
emulator/tools.h [new file with mode: 0644]

diff --git a/emulator/Makefile b/emulator/Makefile
new file mode 100644 (file)
index 0000000..712e794
--- /dev/null
@@ -0,0 +1,30 @@
+
+BIN=motonesemu
+
+OBJS=emu-main.o clock.o tools.o bus.o \
+
+
+#LIBS=-L../libs -lmotones
+
+INCLUDE=-I../include
+
+CFLAGS=-g $(INCLUDE)
+
+all:   $(BIN)
+
+$(BIN): $(OBJS) ../libs
+       gcc -o $(BIN) $(OBJS) $(LIBS)
+
+.c.o: 
+       gcc $(CFLAGS) -c $<
+
+test:
+       make
+       ./test.sh
+
+clean:
+       -rm $(OBJS) $(BIN) \
+               
+
+
+
diff --git a/emulator/bus.c b/emulator/bus.c
new file mode 100644 (file)
index 0000000..2cbca97
--- /dev/null
@@ -0,0 +1,4 @@
+
+static char addr_bus [16];
+static char data_bus [8];
+
diff --git a/emulator/clock.c b/emulator/clock.c
new file mode 100644 (file)
index 0000000..3f4855c
--- /dev/null
@@ -0,0 +1,42 @@
+
+#include <time.h>
+#include "tools.h"
+#include "clock.h"
+
+static int exit_loop;
+
+struct clock_handler {
+    struct slist l;
+    clock_handler_t *handler;
+};
+
+static struct clock_handler *handler_list;
+
+void clock_loop(void) {
+    struct timespec ts;
+    struct clock_handler *ch;
+
+    ts.tv_sec = 0;
+    ts.tv_nsec = 1;
+
+    while (!exit_loop) {
+        ch = handler_list;
+        while (ch != NULL) {
+            if (!ch->handler())
+                break;
+            ch = ch->l.next;
+        }
+        nanosleep(&ts, NULL);
+    }
+}
+
+int register_clock_hander(clock_handler_t *handler) {
+    return TRUE;
+}
+
+int init_clock(void) {
+    exit_loop = FALSE;
+    handler_list = NULL;
+    return TRUE;
+}
+
diff --git a/emulator/clock.h b/emulator/clock.h
new file mode 100644 (file)
index 0000000..d416610
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef __clock_h__
+#define __clock_h__
+
+typedef int (clock_handler_t) (void);
+
+void clock_loop(void);
+int init_clock(void);
+
+int register_clock_hander(clock_handler_t *handler);
+
+#endif /*__clock_h__*/
+
diff --git a/emulator/emu-main.c b/emulator/emu-main.c
new file mode 100644 (file)
index 0000000..6f6647f
--- /dev/null
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include "tools.h"
+#include "clock.h"
+
+static int init_datas(void) {
+    int ret;
+
+    ret = init_clock();
+    if (!ret) {
+        fprintf(stderr, "clock init err.\n");
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
+int main(int argc, char* argv[]) {
+    int ret;
+    printf("motonesemu start...\n");
+
+    ret = init_datas();
+    if (!ret) {
+        fprintf(stderr, "initialization failure...\n");
+        return RT_ERROR;
+    }
+
+    clock_loop();
+
+    return 0;
+}
+
diff --git a/emulator/tools.c b/emulator/tools.c
new file mode 100644 (file)
index 0000000..7d60556
--- /dev/null
@@ -0,0 +1,95 @@
+
+#include <stdio.h>
+#include "tools.h"
+
+void dprint(char* s, char* arg1, unsigned int arg2, unsigned int arg3, 
+        unsigned int arg4, unsigned int arg5, unsigned int arg6) {
+     printf(s, arg1, arg2, arg3, arg4, arg5, arg6 );
+    /*
+     **/
+}
+
+void slist_add_tail (struct slist* dest, struct slist* node) {
+    struct slist *p = dest;
+    struct slist *pp = dest;
+    while( (p = p->next) != NULL ) {
+        pp = p;
+    }
+    pp->next = node;
+}
+
+int slist_count (struct slist* head) {
+    int ret = 0;
+    struct slist* p = head;
+    while( p != NULL ) {
+        p = p->next;
+        ret++;
+    }
+    return ret;
+}
+
+void dlist_init (struct dlist* node) {
+    node->next = node->prev = NULL;
+}
+
+void dlist_add_next (struct dlist* dest, struct dlist* node) {
+    struct dlist* next_node = dest->next;
+
+    if (next_node) {
+        next_node->prev = node;
+    }
+    dest->next = node;
+    node->prev = dest;
+    node->next = next_node;
+}
+
+void dlist_add_prev (struct dlist* dest, struct dlist* node) {
+    struct dlist* prev_node = dest->prev;
+
+    if (prev_node) {
+        prev_node->next = node;
+    }
+    dest->prev = node;
+    node->prev = prev_node;
+    node->next = dest;
+}
+
+void dlist_add_tail (struct dlist* dest, struct dlist* node) {
+    struct dlist* next_node = dest->next;
+    struct dlist* tail_node = dest;
+
+    while (next_node != NULL) {
+        tail_node = next_node;
+        next_node = tail_node->next;
+    }
+    dlist_add_next(tail_node, node);
+}
+
+int dlist_remove (struct dlist* node) {
+    struct dlist* next_node = node->next;
+    struct dlist* prev_node = node->prev;
+
+    int ret = FALSE;
+    if (next_node) {
+        ret = TRUE; 
+        next_node->prev = prev_node;
+    }
+    if (prev_node) {
+        ret = TRUE; 
+        prev_node->next = next_node;
+    }
+    return ret;
+}
+
+
+int dlist_count (struct dlist* head) {
+    int ret = 0;
+    struct dlist* p = head;
+    while( p != NULL ) {
+        p = p->next;
+        ret++;
+    }
+    return ret;
+}
+
+
diff --git a/emulator/tools.h b/emulator/tools.h
new file mode 100644 (file)
index 0000000..98c8b26
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef __tools_h__
+#define __tools_h__
+
+struct slist {
+    struct slist *next;
+} ;
+
+struct dlist {
+    struct dlist *prev;
+    struct dlist *next;
+} ;
+
+
+void slist_add_tail (struct slist* dest, struct slist* node) ;
+int slist_count (struct slist* head);
+
+void dlist_init (struct dlist* node) ;
+void dlist_add_next (struct dlist* dest, struct dlist* node) ;
+void dlist_add_prev (struct dlist* dest, struct dlist* node) ;
+int dlist_remove (struct dlist* node) ;
+int dlist_count (struct dlist* head);
+
+#define TRUE 1
+#define FALSE 0
+
+#define RT_OK 0
+#define RT_ERROR -1
+
+#endif /*__tools_h__*/
+