OSDN Git Service

[GENERAL] Merge upstream 2018-02-27.
[csp-qt/common_source_project-fm7.git] / source / src / vm / z80ctc.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2006.08.18 -
6
7         [ Z80CTC ]
8 */
9
10 #ifndef _Z80CTC_H_
11 #define _Z80CTC_H_
12
13 //#include "vm.h"
14 //#include "../emu.h"
15 #include "device.h"
16
17 #define SIG_Z80CTC_TRIG_0       0
18 #define SIG_Z80CTC_TRIG_1       1
19 #define SIG_Z80CTC_TRIG_2       2
20 #define SIG_Z80CTC_TRIG_3       3
21
22 class Z80CTC : public DEVICE
23 {
24 private:
25         struct {
26                 uint8_t control;
27                 bool slope;
28                 uint16_t count;
29                 uint16_t constant;
30                 uint8_t vector;
31                 int clocks;
32                 int prescaler;
33                 bool freeze;
34                 bool start;
35                 bool latch;
36                 bool prev_in;
37                 bool first_constant;
38                 // constant clock
39                 uint64_t freq;
40                 int clock_id;
41                 int sysclock_id;
42                 uint32_t input;
43                 uint32_t period;
44                 uint32_t prev;
45                 // interrupt
46                 bool req_intr;
47                 bool in_service;
48                 // output signals
49                 outputs_t outputs;
50         } counter[4];
51         uint64_t cpu_clocks;
52
53         bool   _E_Z80CTC_CLOCKS;
54         double __Z80CTC_CLOCKS;
55         
56         void input_clock(int ch, int clock);
57         void input_sysclock(int ch, int clock);
58         void update_event(int ch, int err);
59         
60         // daisy chain
61         DEVICE *d_cpu, *d_child;
62         bool iei, oei;
63         uint32_t intr_bit;
64         void update_intr();
65         
66 public:
67         Z80CTC(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
68         {
69                 memset(counter, 0, sizeof(counter));
70                 for(int i = 0; i < 4; i++) {
71                         initialize_output_signals(&counter[i].outputs);
72                         counter[i].freq = 0;
73                         counter[i].prev_in = false;
74                 }
75                 d_cpu = d_child = NULL;
76                 _E_Z80CTC_CLOCKS = false;
77                 __Z80CTC_CLOCKS = 1.0;
78                 set_device_name(_T("Z80 CTC"));
79         }
80         ~Z80CTC() {}
81         
82         // common functions
83         void initialize();
84         void reset();
85         void write_io8(uint32_t addr, uint32_t data);
86         uint32_t read_io8(uint32_t addr);
87         void write_signal(int id, uint32_t data, uint32_t mask);
88         void event_callback(int event_id, int err);
89         void update_timing(int new_clocks, double new_frames_per_sec, int new_lines_per_frame)
90         {
91                 cpu_clocks = new_clocks;
92         }
93         void save_state(FILEIO* state_fio);
94         bool load_state(FILEIO* state_fio);
95         // interrupt common functions
96         void set_context_intr(DEVICE* device, uint32_t bit)
97         {
98                 d_cpu = device;
99                 intr_bit = bit;
100         }
101         void set_context_child(DEVICE* device)
102         {
103                 d_child = device;
104         }
105         void set_intr_iei(bool val);
106         uint32_t get_intr_ack();
107         void notify_intr_reti();
108         
109         // unique functions
110         void set_context_zc0(DEVICE* device, int id, uint32_t mask)
111         {
112                 register_output_signal(&counter[0].outputs, device, id, mask);
113         }
114         void set_context_zc1(DEVICE* device, int id, uint32_t mask)
115         {
116                 register_output_signal(&counter[1].outputs, device, id, mask);
117         }
118         void set_context_zc2(DEVICE* device, int id, uint32_t mask)
119         {
120                 register_output_signal(&counter[2].outputs, device, id, mask);
121         }
122         void set_constant_clock(int ch, uint32_t hz)
123         {
124                 counter[ch].freq = hz;
125         }
126 };
127
128 #endif