OSDN Git Service

[General] Merge upstream : 2015-02-21.
[csp-qt/common_source_project-fm7.git] / source / src / vm / fp1100 / sub.h
1 /*
2         CASIO FP-1100 Emulator 'eFP-1100'
3
4         Author : Takeda.Toshiya
5         Date   : 2010.06.09-
6
7         [ sub pcb ]
8 */
9
10 #ifndef _SUB_H_
11 #define _SUB_H_
12
13 #include "../vm.h"
14 #include "../../emu.h"
15 #include "../device.h"
16
17 #define SIG_SUB_INT2    0
18 #define SIG_SUB_COMM    1
19 #define SIG_SUB_HSYNC   2
20 #define SIG_SUB_SO      3
21 #define SIG_SUB_EAR     4
22
23 class SUB : public DEVICE
24 {
25 private:
26         // to sub cpu
27         DEVICE *d_cpu;
28         // to main pcb
29         DEVICE *d_main;
30         // to beep
31         DEVICE *d_beep;
32         // to data recorder
33         DEVICE *d_drec;
34         // from/to crtc
35         DEVICE *d_crtc;
36         uint8 *regs;
37         
38         uint8 *wbank[0x200];
39         uint8 *rbank[0x200];
40         uint8 wdmy[0x80];
41         uint8 rdmy[0x80];
42         
43         uint8 ram[0x80];
44         uint8 vram_b[0x4000];
45         uint8 vram_r[0x4000];
46         uint8 vram_g[0x4000];
47         uint8 sub1[0x1000];
48         uint8 sub2[0x1000];
49         uint8 sub3[0x1000];
50         
51         uint8 pa, pb, pc;
52         uint8 comm_data;
53         
54         bool so;
55         uint8 clock;
56         
57         // 74LS74
58         struct {
59                 bool in_d, in_ck, in_s, in_r;
60                 bool out_q, out_nq;
61                 bool tmp_ck;
62                 void update()
63                 {
64                         if(!in_s && in_r) {
65                                 out_q = true;
66                                 out_nq = false;
67                         } else if(in_s && !in_r) {
68                                 out_q = false;
69                                 out_nq = true;
70                         } else if(!in_s && !in_r) {
71                                 out_q = out_nq = true; // undetermined
72                         } else if(!tmp_ck && in_ck) {
73                                 out_q = in_d;
74                                 out_nq = !in_d;
75                         }
76                         tmp_ck = in_ck;
77                 }
78         } b16_1, b16_2, g21_1, g21_2;
79         
80         // 74LS151
81         struct {
82                 bool in_d0, in_d1, in_d2, in_d3, in_d4, in_d5, in_d6, in_d7;
83                 bool in_a, in_b, in_c, in_s;
84                 bool out_y, out_ny;
85                 void update()
86                 {
87                         if(in_s) {
88                                 out_y = false;
89                         } else if(!in_a && !in_b && !in_c) {
90                                 out_y = in_d0;
91                         } else if( in_a && !in_b && !in_c) {
92                                 out_y = in_d1;
93                         } else if(!in_a &&  in_b && !in_c) {
94                                 out_y = in_d2;
95                         } else if( in_a &&  in_b && !in_c) {
96                                 out_y = in_d3;
97                         } else if(!in_a && !in_b &&  in_c) {
98                                 out_y = in_d4;
99                         } else if( in_a && !in_b &&  in_c) {
100                                 out_y = in_d5;
101                         } else if(!in_a &&  in_b &&  in_c) {
102                                 out_y = in_d6;
103                         } else if( in_a &&  in_b &&  in_c) {
104                                 out_y = in_d7;
105                         }
106                         out_ny = !out_y;
107                 }
108         } c15;
109         
110         // 74LS93
111         struct {
112                 bool in_a, in_b, in_rc1, in_rc2;
113                 bool out_qa, out_qb, out_qc;
114                 bool tmp_a, tmp_b;
115                 uint8 counter_a, counter_b;
116                 void update()
117                 {
118                         if(in_rc1 && in_rc2) {
119                                 counter_a = counter_b = 0;
120                         } else {
121                                 if(tmp_a && !in_a) {
122                                         counter_a++;
123                                 }
124                                 if(tmp_b && !in_b) {
125                                         counter_b++;
126                                 }
127                         }
128                         tmp_a = in_a;
129                         tmp_b = in_b;
130                         out_qa = ((counter_a & 1) != 0);
131                         out_qb = ((counter_b & 1) != 0);
132                         out_qc = ((counter_b & 2) != 0);
133                 }
134         } c16;
135         
136         // TC4024BP
137         struct {
138                 bool in_ck, in_clr;
139                 bool out_q5, out_q6;
140                 bool tmp_ck;
141                 uint8 counter;
142                 void update()
143                 {
144                         if(in_clr) {
145                                 counter = 0;
146                         } else if(tmp_ck && !in_ck) {
147                                 counter++;
148                         }
149                         tmp_ck = in_ck;
150                         out_q5 = ((counter & 0x10) != 0);
151                         out_q6 = ((counter & 0x20) != 0);
152                 }
153         } f21;
154         
155         void update_cmt();
156         
157         uint8 *key_stat;
158         uint8 key_sel, key_data;
159         
160         uint8 cursor_color;
161         bool hsync, wait;
162         uint8 cblink;
163         uint8 screen[400][640];
164         bool update_palette;
165         scrntype palette_pc[8];
166         
167         void key_update();
168         
169 public:
170         SUB(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
171         ~SUB() {}
172         
173         // common functions
174         void initialize();
175         void reset();
176         void write_data8(uint32 addr, uint32 data);
177         uint32 read_data8(uint32 addr);
178         void write_io8(uint32 addr, uint32 data);
179         uint32 read_io8(uint32 addr);
180         void write_signal(int id, uint32 data, uint32 mask);
181         void event_frame();
182         void event_callback(int event_id, int err);
183         void save_state(FILEIO* state_fio);
184         bool load_state(FILEIO* state_fio);
185         
186         // unique functions
187         void set_context_cpu(DEVICE *device)
188         {
189                 d_cpu = device;
190         }
191         void set_context_main(DEVICE *device)
192         {
193                 d_main = device;
194         }
195         void set_context_beep(DEVICE *device)
196         {
197                 d_beep = device;
198         }
199         void set_context_drec(DEVICE *device)
200         {
201                 d_drec = device;
202         }
203         void set_context_crtc(DEVICE *device, uint8* ptr)
204         {
205                 d_crtc = device;
206                 regs = ptr;
207         }
208         void key_down(int code);
209         void key_up(int code);
210         void draw_screen();
211 };
212
213 #endif