OSDN Git Service

b15433b46320869b7ad9d89d411b516cfaa6f78f
[motonesemu/motonesemu.git] / emulator / ioapu.c
1 #include "tools.h"
2 #include "apu.h"
3
4 static unsigned short apu_addr;
5 static unsigned char apu_data;
6
7 #define APU_IO_SIZE 0x20
8
9 /*
10  * apucore r/w func ptr.
11  * */
12 void set_dma_data(unsigned char data);
13 void release_bus(void);
14 int get_rw_pin(void);
15
16 typedef void (apu_write_t)(unsigned char);
17 typedef unsigned char (apu_read_t)(void);
18
19 static apu_write_t *apu_write_func[APU_IO_SIZE];
20 static apu_read_t *apu_read_func[APU_IO_SIZE];
21
22 void set_apu_addr(unsigned short addr) {
23     dprint("set_apu_addr: %02x\n", addr);
24     apu_addr = addr;
25 }
26
27 unsigned char get_apu_data(void) {
28     return apu_data;
29 }
30
31 void set_apu_data(unsigned char data) {
32     dprint("set_apu_data: %02x\n", data);
33     apu_data = data;
34 }
35
36 void set_apu_start(int ce) {
37     //let ram i/o on the bus.
38     if (ce) {
39         if (get_rw_pin()) {
40             //write cycle
41             apu_write_func[apu_addr](apu_data);
42         }
43         else {
44             //read cycle
45             apu_data = apu_read_func[apu_addr]();
46         }
47         release_bus();
48     }
49 }
50
51
52 /*dummy I/O func*/
53 static void null_write(unsigned char d){}
54 static unsigned char null_read(void){return 0;}
55
56 int init_apu(void) {
57     int i;
58     apu_addr = 0;
59     apu_data = 0;
60
61     //fill null function
62     for (i = 0; i < APU_IO_SIZE; i++) {
63         apu_write_func[i] = null_write;
64     }
65     for (i = 0; i < APU_IO_SIZE; i++) {
66         apu_read_func[i] = null_read;
67     }
68     //dma func
69     apu_write_func[0x14] = set_dma_data;
70
71     return TRUE;
72 }
73
74 void clean_apu(void) {
75 }
76