#include <string.h>
-#include <semaphore.h>
#include "tools.h"
#include "bus.h"
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
void release_bus(void) {
//dprint("release bus\n");
pin_status.ready = 1;
- sem_post(&sem_bus_wait);
}
/*
/*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) {
}
/*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);
}
}
}
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);
}
/*
#include <stdlib.h>
#include <time.h>
#include <string.h>
-#include <pthread.h>
-#include <semaphore.h>
#include "clock.h"
#include "tools.h"
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;
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;
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);
-
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-#include <pthread.h>
-#include <semaphore.h>
#include "tools.h"
#include "clock.h"
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;
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;
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);
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
-#include <pthread.h>
-#include <semaphore.h>
#include "tools.h"
#include "clock.h"
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
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);
}