OSDN Git Service

[General][CMAKE] Integrate all devices to upstream 2015-12-17.
[csp-qt/common_source_project-fm7.git] / source / src / vm / io.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2008.12.29 -
6
7         [ i/o bus ]
8 */
9
10 #ifndef _IO_H_
11 #define _IO_H_
12
13 #include "vm.h"
14 #include "../emu.h"
15 #include "device.h"
16
17 #ifndef IO_ADDR_MAX
18 #define IO_ADDR_MAX 0x100
19 #endif
20 #define IO_ADDR_MASK (IO_ADDR_MAX - 1)
21
22 class IO : public DEVICE
23 {
24 private:
25         // i/o map
26         struct {
27                 DEVICE* dev;
28                 uint32 addr;
29                 int wait;
30                 bool is_flipflop;
31         } wr_table[IO_ADDR_MAX];
32         
33         struct {
34                 DEVICE* dev;
35                 uint32 addr;
36                 int wait;
37                 bool value_registered;
38                 uint32 value;
39         } rd_table[IO_ADDR_MAX];
40         
41         void write_port8(uint32 addr, uint32 data, bool is_dma);
42         uint32 read_port8(uint32 addr, bool is_dma);
43         void write_port16(uint32 addr, uint32 data, bool is_dma);
44         uint32 read_port16(uint32 addr, bool is_dma);
45         void write_port32(uint32 addr, uint32 data, bool is_dma);
46         uint32 read_port32(uint32 addr, bool is_dma);
47         
48 public:
49         IO(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
50         {
51                 memset(wr_table, 0, sizeof(wr_table));
52                 memset(rd_table, 0, sizeof(rd_table));
53                 
54                 // vm->dummy must be generated first !
55                 for(int i = 0; i < IO_ADDR_MAX; i++) {
56                         wr_table[i].dev = rd_table[i].dev = vm->dummy;
57                         wr_table[i].addr = rd_table[i].addr = i;
58                 }
59 #ifdef _IO_DEBUG_LOG
60                 cpu_index = 0;
61 #endif
62         }
63         ~IO() {}
64         
65         // common functions
66         void write_io8(uint32 addr, uint32 data);
67         uint32 read_io8(uint32 addr);
68         void write_io16(uint32 addr, uint32 data);
69         uint32 read_io16(uint32 addr);
70         void write_io32(uint32 addr, uint32 data);
71         uint32 read_io32(uint32 addr);
72         void write_io8w(uint32 addr, uint32 data, int* wait);
73         uint32 read_io8w(uint32 addr, int* wait);
74         void write_io16w(uint32 addr, uint32 data, int* wait);
75         uint32 read_io16w(uint32 addr, int* wait);
76         void write_io32w(uint32 addr, uint32 data, int* wait);
77         uint32 read_io32w(uint32 addr, int* wait);
78         void write_dma_io8(uint32 addr, uint32 data);
79         uint32 read_dma_io8(uint32 addr);
80         void write_dma_io16(uint32 addr, uint32 data);
81         uint32 read_dma_io16(uint32 addr);
82         void write_dma_io32(uint32 addr, uint32 data);
83         uint32 read_dma_io32(uint32 addr);
84         void save_state(FILEIO* state_fio);
85         bool load_state(FILEIO* state_fio);
86         
87         // unique functions
88         void set_iomap_single_r(uint32 addr, DEVICE* device);
89         void set_iomap_single_w(uint32 addr, DEVICE* device);
90         void set_iomap_single_rw(uint32 addr, DEVICE* device);
91         void set_iomap_alias_r(uint32 addr, DEVICE* device, uint32 alias);
92         void set_iomap_alias_w(uint32 addr, DEVICE* device, uint32 alias);
93         void set_iomap_alias_rw(uint32 addr, DEVICE* device, uint32 alias);
94         void set_iomap_range_r(uint32 s, uint32 e, DEVICE* device);
95         void set_iomap_range_w(uint32 s, uint32 e, DEVICE* device);
96         void set_iomap_range_rw(uint32 s, uint32 e, DEVICE* device);
97         
98         void set_iovalue_single_r(uint32 addr, uint32 value);
99         void set_iovalue_range_r(uint32 s, uint32 e, uint32 value);
100         void set_flipflop_single_rw(uint32 addr, uint32 value);
101         void set_flipflop_range_rw(uint32 s, uint32 e, uint32 value);
102         
103         void set_iowait_single_r(uint32 addr, int wait);
104         void set_iowait_single_w(uint32 addr, int wait);
105         void set_iowait_single_rw(uint32 addr, int wait);
106         void set_iowait_range_r(uint32 s, uint32 e, int wait);
107         void set_iowait_range_w(uint32 s, uint32 e, int wait);
108         void set_iowait_range_rw(uint32 s, uint32 e, int wait);
109         
110 #ifdef _IO_DEBUG_LOG
111         int cpu_index;
112 #endif
113 };
114
115 #endif
116