OSDN Git Service

041763815ed0fcf7d3f4a1f7ca05c3ff100b8d88
[motonesemu/motonesemu.git] / emulator / ppu.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <time.h>
4 #include <string.h>
5 #include <pthread.h>
6 #include <semaphore.h>
7
8 #include "clock.h"
9 #include "tools.h"
10
11 struct ppu_cpu_pin {
12     unsigned int ce     :1;     /*chip enable*/
13     unsigned int rw     :1;     /*assert on write.*/
14     unsigned int vblank :1;     /*connected to nmi*/
15 };
16
17 struct ppu_register {
18     unsigned char control1;     /*write only*/
19     unsigned char control2;     /*write only*/
20     unsigned char status;       /*read only*/
21     unsigned char sprite_addr;
22     unsigned char sprite_data;
23     unsigned char scroll;
24     unsigned char vram_addr;
25     unsigned char vram_data;
26 };
27
28 struct ppu_cart_pin {
29     unsigned int rd     :1;     /*read*/
30     unsigned int wr     :1;     /*write.*/
31 };
32
33 static struct ppu_cpu_pin  ppu_pin;
34 static struct ppu_cart_pin cart_pin;
35 struct ppu_register ppu_reg;
36
37
38 static pthread_t ppu_thread_id;
39 static int ppu_end_loop;
40 static sem_t ppu_sem_id;
41
42 /*
43  * JAPAN/US uses NTSC standard.
44  * 
45  * NTSC: 
46  * ---------------------------------------------------------
47  * Frames per second                            60 
48  * Time per frame (milliseconds)                16.67 
49  * Scanlines per frame (of which is V-Blank)    262 (20) 
50  * CPU cycles per scanline                      113.33 
51  * Resolution                                   256 x 224 
52  * CPU speed                                    1.79 MHz 
53  *
54  * */
55
56 void set_ppu_addr(unsigned char data) {
57 }
58
59 unsigned char get_ppu_data(void) {
60     return 0;
61 }
62
63 void set_ppu_data(unsigned char data) {
64 }
65
66 static void *ppu_loop(void* arg) {
67     //struct timespec ts = {CPU_CLOCK_SEC, CPU_CLOCK_NSEC / 10};
68
69     while (!ppu_end_loop) {
70         sem_wait(&ppu_sem_id);
71         ;
72     }
73     return NULL;
74 }
75
76 int init_ppu(void) {
77     int ret;
78     pthread_attr_t attr;
79
80     ppu_end_loop = FALSE;
81
82     memset(&ppu_reg, 0, sizeof(ppu_reg));
83     ppu_pin.ce = 0;
84     ppu_pin.rw = 0;
85     cart_pin.rd = 0;
86     cart_pin.wr = 0;
87
88     ret = sem_init(&ppu_sem_id, 0, 0);
89     if (ret != RT_OK) {
90         return FALSE;
91     }
92
93     ret = pthread_attr_init(&attr);
94     if (ret != RT_OK) {
95         return FALSE;
96     }
97
98     ppu_thread_id = 0;
99     ret = pthread_create(&ppu_thread_id, &attr, ppu_loop, NULL);
100     if (ret != RT_OK) {
101         return FALSE;
102     }
103
104     return TRUE;
105 }
106
107 void clean_ppu(void) {
108     void* ret;
109
110     ppu_end_loop = TRUE;
111     sem_post(&ppu_sem_id);
112     pthread_join(ppu_thread_id, &ret);
113
114     sem_destroy(&ppu_sem_id);
115     dprint("ppu thread joined.\n");
116
117 }
118
119