OSDN Git Service

[VM][STATE] Apply new framework to some VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / mc6844.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2017.04.14-
6
7         [ MC6844 ]
8 */
9
10 #ifndef _MC6844_H_
11 #define _MC6844_H_
12
13 //#include "vm.h"
14 //#include "../emu.h"
15 #include "device.h"
16
17 #define SIG_MC6844_TX_RQ_0      0
18 #define SIG_MC6844_TX_RQ_1      1
19 #define SIG_MC6844_TX_RQ_2      2
20 #define SIG_MC6844_TX_RQ_3      3
21
22 class MC6844 : public DEVICE
23 {
24 private:
25         DEVICE* d_memory;
26         
27         struct {
28                 DEVICE *device;
29                 pair_t address_reg;
30                 pair_t byte_count_reg;
31                 uint8_t channel_ctrl_reg;
32         } dma[4];
33         
34         uint8_t priority_ctrl_reg;
35         uint8_t interrupt_ctrl_reg;
36         uint8_t data_chain_reg;
37         
38         outputs_t outputs_irq;
39         
40         void transfer(int ch);
41         void update_irq();
42         
43 public:
44         MC6844(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                 
53 //              for(int i = 0; i < 4; i++) {
54 //                      dma[i].device = vm->dummy;
55 //              }
56 //              d_memory = vm->dummy;
57                 for(int i = 0; i < 4; i++) {
58                         dma[i].device = __dev;
59                 }
60                 d_memory = __dev;
61                 initialize_output_signals(&outputs_irq);
62                 set_device_name(_T("MC6844 DMAC"));
63         }
64         ~MC6844() {}
65         
66         // common functions
67         void reset();
68         void write_io8(uint32_t addr, uint32_t data);
69         uint32_t read_io8(uint32_t addr);
70         void write_signal(int id, uint32_t data, uint32_t mask);
71         bool process_state(FILEIO* state_fio, bool loading);
72         
73         // unique functions
74         void set_context_memory(DEVICE* device)
75         {
76                 d_memory = device;
77         }
78         void set_context_ch0(DEVICE* device)
79         {
80                 dma[0].device = device;
81         }
82         void set_context_ch1(DEVICE* device)
83         {
84                 dma[1].device = device;
85         }
86         void set_context_ch2(DEVICE* device)
87         {
88                 dma[2].device = device;
89         }
90         void set_context_ch3(DEVICE* device)
91         {
92                 dma[3].device = device;
93         }
94 };
95
96 #endif
97