OSDN Git Service

[VM] Add vm_template.h . This class, VM_TEMPLATE:: must be mother of VM:: .See fm7...
[csp-qt/common_source_project-fm7.git] / source / src / vm / upd71071.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2007.08.14 -
6
7         [ uPD71071 ]
8 */
9
10 #ifndef _UPD71071_H_
11 #define _UPD71071_H_
12
13 //#include "vm.h"
14 //#include "../emu.h"
15 #include "device.h"
16
17 #define SIG_UPD71071_CH0        0
18 #define SIG_UPD71071_CH1        1
19 #define SIG_UPD71071_CH2        2
20 #define SIG_UPD71071_CH3        3
21
22 class UPD71071 : public DEVICE
23 {
24 private:
25         DEVICE* d_mem;
26 //#ifdef SINGLE_MODE_DMA
27         DEVICE* d_dma;
28 //#endif
29         outputs_t outputs_tc;
30         
31         struct {
32                 DEVICE* dev;
33                 uint32_t areg, bareg;
34                 uint16_t creg, bcreg;
35                 uint8_t mode;
36         } dma[4];
37         
38         uint8_t b16, selch, base;
39         uint16_t cmd, tmp;
40         uint8_t req, sreq, mask, tc;
41
42         bool _SINGLE_MODE_DMA;
43 public:
44         UPD71071(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
45         {
46                 // TIP: if((DEVICE::prev_device == NULL) || (DEVICE::this_device_id == 0)) DEVICE must be DUMMY.
47                 // And, at this device, should not be FIRST DEVICE. 20170613 Ohta.
48                 DEVICE *__dev = this;
49                 while((__dev->prev_device != NULL) && (__dev->this_device_id > 0)) {
50                         __dev = __dev->prev_device;
51                 }
52                 for(int i = 0; i < 4; i++) {
53                         //dma[i].dev = vm->dummy;
54                         dma[i].dev = __dev;
55                 }
56                 d_mem = __dev;
57 //#ifdef SINGLE_MODE_DMA
58                 d_dma = NULL;
59 //#endif
60                 _SINGLE_MODE_DMA = false;
61                 initialize_output_signals(&outputs_tc);
62                 set_device_name(_T("uPD71071 DMAC"));
63         }
64         ~UPD71071() {}
65         
66         // common functions
67         void initialize();
68         void reset();
69         void write_io8(uint32_t addr, uint32_t data);
70         uint32_t read_io8(uint32_t addr);
71         void write_signal(int id, uint32_t data, uint32_t mask);
72         void do_dma();
73         void decl_state();
74         void save_state(FILEIO* state_fio);
75         bool load_state(FILEIO* state_fio);
76         // unique functions
77         void set_context_memory(DEVICE* device)
78         {
79                 d_mem = device;
80         }
81         void set_context_ch0(DEVICE* device)
82         {
83                 dma[0].dev = device;
84         }
85         void set_context_ch1(DEVICE* device)
86         {
87                 dma[1].dev = device;
88         }
89         void set_context_ch2(DEVICE* device)
90         {
91                 dma[2].dev = device;
92         }
93         void set_context_ch3(DEVICE* device)
94         {
95                 dma[3].dev = device;
96         }
97 //#ifdef SINGLE_MODE_DMA
98         void set_context_child_dma(DEVICE* device)
99         {
100                 d_dma = device;
101         }
102 //#endif
103         void set_context_tc(DEVICE* device, int id, uint32_t mask)
104         {
105                 register_output_signal(&outputs_tc, device, id, mask);
106         }
107 };
108
109 #endif
110