OSDN Git Service

stop using separate threads for cpu and rom, ram, ppu due to performance issue..
authorastoria-d <astoria-d@mail.goo.ne.jp>
Mon, 18 Mar 2013 00:58:04 +0000 (09:58 +0900)
committerastoria-d <astoria-d@mail.goo.ne.jp>
Mon, 18 Mar 2013 00:58:04 +0000 (09:58 +0900)
emulator/bus.c
emulator/ppu.c
emulator/ram.c
emulator/rom.c

index e468e88..5e1ce96 100644 (file)
@@ -1,5 +1,4 @@
 #include <string.h>
-#include <semaphore.h>
 
 #include "tools.h"
 #include "bus.h"
@@ -24,7 +23,6 @@ struct cpu_pin {
 static unsigned short addr_bus;
 static unsigned char data_bus;
 static struct cpu_pin pin_status;
-static sem_t sem_bus_wait;
 
 /*
  * NES memory map
@@ -52,7 +50,6 @@ static sem_t sem_bus_wait;
 void release_bus(void) {
     //dprint("release bus\n");
     pin_status.ready = 1;
-    sem_post(&sem_bus_wait);
 }
 
 /*
@@ -64,9 +61,6 @@ void start_bus(void) {
         /*case rom*/
         pin_status.ready = 0;
         set_rom_ce_pin(TRUE);
-
-        //wait for the bus ready.
-        sem_wait(&sem_bus_wait);
     }
     else if ((addr_bus & IO_APU_BIT) == IO_APU_BIT) {
     }
@@ -74,18 +68,11 @@ void start_bus(void) {
         /*case ppu*/
         pin_status.ready = 0;
         set_ppu_ce_pin(TRUE);
-
-        //wait for the bus ready.
-        //dprint("wait for ppu done\n");
-        sem_wait(&sem_bus_wait);
     }
     else {
         /*case ram*/
         pin_status.ready = 0;
         set_ram_ce_pin(TRUE);
-
-        //wait for the bus ready.
-        sem_wait(&sem_bus_wait);
     }
 }
 
@@ -178,22 +165,15 @@ void set_rw_pin(int rw) {
 }
 
 int init_bus(void) {
-    int ret;
-
     addr_bus = 0;
     data_bus = 0;
     memset(&pin_status, 0, sizeof(struct cpu_pin));
     pin_status.ready = 1;
 
-    ret = sem_init(&sem_bus_wait, 0, 0);
-    if (ret != RT_OK)
-        return FALSE;
-
     return TRUE;
 }
 
 void clean_bus(void){
-    sem_destroy(&sem_bus_wait);
 }
 
 /*
index 559b761..c519299 100644 (file)
@@ -2,8 +2,6 @@
 #include <stdlib.h>
 #include <time.h>
 #include <string.h>
-#include <pthread.h>
-#include <semaphore.h>
 
 #include "clock.h"
 #include "tools.h"
@@ -32,9 +30,6 @@ static struct ppu_cart_pin cart_pin;
 static unsigned short ppu_addr;
 static unsigned char ppu_data;
 
-static pthread_t ppu_thread_id;
-static int ppu_end_loop;
-static sem_t ppu_sem_id;
 static unsigned char* vga_shared_buf;
 
 
@@ -107,37 +102,25 @@ void set_ppu_rw_pin(int rw) {
 void set_ppu_ce_pin(int ce) {
     ppu_pin.ce = ce;
     //let ram i/o on the bus.
-    if (ce)
-        sem_post(&ppu_sem_id);
+    if (ce) {
+        if (ppu_pin.rw) {
+            //write cycle
+            ppucore_write_func[ppu_addr](ppu_data);
+        }
+        else {
+            //read cycle
+            ppu_data = ppucore_read_func[ppu_addr]();
+        }
+        release_bus();
+    }
 }
 
 /*dummy I/O func*/
 static void null_write(unsigned char d){}
 static unsigned char null_read(void){return 0;}
 
-static void *ppu_loop(void* arg) {
-    while (!ppu_end_loop) {
-        sem_wait(&ppu_sem_id);
-        if (ppu_pin.ce) {
-            if (ppu_pin.rw) {
-                //write cycle
-                ppucore_write_func[ppu_addr](ppu_data);
-            }
-            else {
-                //read cycle
-                ppu_data = ppucore_read_func[ppu_addr]();
-            }
-            release_bus();
-        }
-    }
-    return NULL;
-}
-
 int init_ppu(void) {
     int ret;
-    pthread_attr_t attr;
-
-    ppu_end_loop = FALSE;
 
     ppu_pin.ce = 0;
     ppu_pin.rw = 0;
@@ -162,37 +145,12 @@ int init_ppu(void) {
         return FALSE;
     }
 
-    ret = sem_init(&ppu_sem_id, 0, 0);
-    if (ret != RT_OK) {
-        return FALSE;
-    }
-
-    ret = pthread_attr_init(&attr);
-    if (ret != RT_OK) {
-        return FALSE;
-    }
-
-    ppu_thread_id = 0;
-    ret = pthread_create(&ppu_thread_id, &attr, ppu_loop, NULL);
-    if (ret != RT_OK) {
-        return FALSE;
-    }
-
     return TRUE;
 }
 
 void clean_ppu(void) {
-    void* ret;
-
-    ppu_end_loop = TRUE;
-    sem_post(&ppu_sem_id);
-    pthread_join(ppu_thread_id, &ret);
-    sem_destroy(&ppu_sem_id);
-    dprint("ppu thread joined.\n");
-
     clean_ppucore();
     vga_shm_free(vga_shared_buf);
-
 }
 
 
index 91efad6..0fb135d 100644 (file)
@@ -1,8 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-#include <pthread.h>
-#include <semaphore.h>
 
 #include "tools.h"
 #include "clock.h"
@@ -19,10 +17,6 @@ static struct ram_pin ram_pin_status;
 static unsigned short ram_addr;
 static unsigned char ram_data;
 
-static pthread_t ram_thread_id;
-static int ram_end_loop;
-static sem_t ram_sem_id;
-
 #define RAM_2K 0x0800
 
 unsigned char * ram_buffer;
@@ -50,35 +44,20 @@ void set_ram_we_pin(int we) {
 void set_ram_ce_pin(int ce) {
     ram_pin_status.ce = ce;
     //let ram i/o on the bus.
-    if (ce)
-        sem_post(&ram_sem_id);
-}
-
-static void *ram_loop(void* arg) {
-    //ram data load delay is 1/10 (dummy interval)
-
-    while (!ram_end_loop) {
-        sem_wait(&ram_sem_id);
-        if (ram_pin_status.ce) {
-            if (ram_pin_status.oe) {
-                //read cycle
-                ram_data = ram_buffer[ram_addr];
-            }
-            else if (ram_pin_status.we) {
-                //write cycle
-                ram_buffer[ram_addr] = ram_data;
-            }
-            release_bus();
+    if (ce) {
+        if (ram_pin_status.oe) {
+            //read cycle
+            ram_data = ram_buffer[ram_addr];
         }
+        else if (ram_pin_status.we) {
+            //write cycle
+            ram_buffer[ram_addr] = ram_data;
+        }
+        release_bus();
     }
-    return NULL;
 }
 
 int init_ram(void) {
-    int ret;
-    pthread_attr_t attr;
-    //struct sched_param sched;
-
     ram_buffer = malloc(RAM_2K);
     if (!ram_buffer)
         return FALSE;
@@ -89,51 +68,10 @@ int init_ram(void) {
     ram_pin_status.we = 0;
     ram_pin_status.ce = 0;
 
-    ram_end_loop = FALSE;
-
-    ret = sem_init(&ram_sem_id, 0, 0);
-    if (ret != RT_OK) {
-        free(ram_buffer);
-        return FALSE;
-    }
-
-    ret = pthread_attr_init(&attr);
-    if (ret != RT_OK) {
-        free(ram_buffer);
-        return FALSE;
-    }
-
-#if 0
-    dprint("priority min:%d, max:%d\n", 
-            sched_get_priority_min(SCHED_OTHER), sched_get_priority_max(SCHED_OTHER));
-    sched.sched_priority = 0;
-    ret = pthread_attr_setschedparam(&attr, &sched);
-    if (ret != RT_OK) {
-        free(ram_buffer);
-        return FALSE;
-    }
-#endif
-
-    ram_thread_id = 0;
-    ret = pthread_create(&ram_thread_id, &attr, ram_loop, NULL);
-    if (ret != RT_OK) {
-        free(ram_buffer);
-        return FALSE;
-    }
-
     return TRUE;
 }
 
 void clean_ram(void) {
-    void* ret;
-    ram_end_loop = TRUE;
-    //join the running thread.
-    sem_post(&ram_sem_id);
-    pthread_join(ram_thread_id, &ret);
-
-    sem_destroy(&ram_sem_id);
-    dprint("ram thread joined.\n");
-
     if (ram_buffer)
         free(ram_buffer);
 }
index f54d57a..d9ac257 100644 (file)
@@ -1,8 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
-#include <pthread.h>
-#include <semaphore.h>
 
 #include "tools.h"
 #include "clock.h"
@@ -17,9 +15,6 @@ struct rom_pin {
 static struct rom_pin rom_pin_status;
 static unsigned short rom_addr;
 static unsigned char rom_data;
-static pthread_t rom_thread_id;
-static int rom_end_loop;
-static sem_t rom_sem_id;
 
 #define ROM_32K 0x8000
 
@@ -48,61 +43,23 @@ unsigned char get_rom_data(void) {
 void set_rom_ce_pin(int ce) {
     rom_pin_status.ce = ce;
     //let rom write the value on the bus.
-    if (ce)
-        sem_post(&rom_sem_id);
-}
-
-static void *rom_loop(void* arg) {
-    //rom data load delay is 1/10 (dummy interval)
-
-    while (!rom_end_loop) {
-        sem_wait(&rom_sem_id);
-        if (rom_pin_status.ce) {
+    if (ce) {
             rom_data = rom_buffer[rom_addr];
             release_bus();
-        }
     }
-    return NULL;
 }
 
 int init_rom(void) {
-    int ret;
-    pthread_attr_t attr;
-
     rom_buffer = NULL;
     rom_addr = 0;
     rom_data = 0;
     rom_pin_status.rw = 0;
     rom_pin_status.ce = 0;
 
-    rom_end_loop = FALSE;
-
-    ret = sem_init(&rom_sem_id, 0, 0);
-    if (ret != RT_OK)
-        return FALSE;
-
-    ret = pthread_attr_init(&attr);
-    if (ret != RT_OK)
-        return FALSE;
-
-    rom_thread_id = 0;
-    ret = pthread_create(&rom_thread_id, &attr, rom_loop, NULL);
-    if (ret != RT_OK)
-        return FALSE;
-
     return TRUE;
 }
 
 void clean_rom(void) {
-    void* ret;
-    rom_end_loop = TRUE;
-    //join the running thread.
-    sem_post(&rom_sem_id);
-    pthread_join(rom_thread_id, &ret);
-
-    sem_destroy(&rom_sem_id);
-    dprint("rom thread joined.\n");
-
     if (rom_buffer)
         free(rom_buffer);
 }