OSDN Git Service

[General][Qt] Merge upstream, datarecorder with sound.
[csp-qt/common_source_project-fm7.git] / source / src / vm / hc20 / memory.h
1 /*
2         EPSON HC-20 Emulator 'eHC-20'
3
4         Author : Takeda.Toshiya
5         Date   : 2011.05.23-
6
7         [ memory ]
8 */
9
10 #ifndef _MEMORY_H_
11 #define _MEMORY_H_
12
13 #include "../vm.h"
14 #include "../../emu.h"
15 #include "../device.h"
16
17 #define SIG_MEMORY_PORT_2       0
18 #define SIG_MEMORY_PORT_3       1
19 #define SIG_MEMORY_PORT_4       2
20 #define SIG_MEMORY_SIO_MAIN     3
21 #define SIG_MEMORY_SIO_TF20     4
22 #define SIG_MEMORY_RTC_IRQ      5
23
24 #define CMT_BUFFER_SIZE         0x40000
25
26 class BEEP;
27 class FIFO;
28
29 class MEMORY : public DEVICE
30 {
31 private:
32         BEEP *d_beep;
33         DEVICE *d_cpu, *d_rtc, *d_sio_tf20;
34         
35         uint8 wdmy[0x2000];
36         uint8 rdmy[0x2000];
37         uint8* wbank[8];
38         uint8* rbank[8];
39         
40         // memory with expansion unit
41         uint8 ram[0x8000];      // 0000h-7fffh
42         uint8 rom[0x8000];      // 8000h-ffffh (internal)
43         uint8 ext[0x4000];      // 8000h-bfffh
44         
45         FIFO *cmd_buf;
46         bool sio_select;
47         bool special_cmd_masked;
48         uint8 slave_mem[0x10000];
49         
50         struct {
51                 double freq;
52                 int period;
53                 int remain;
54         } sound[256];
55         int sound_ptr;
56         int sound_count;
57         uint8 sound_reply;
58         double sound_freq;
59         double tone_table[57];
60         
61         uint8 key_stat[256], key_flag[256];
62         int key_data, key_strobe, key_intmask;
63         
64         FILEIO* cmt_fio;
65         bool cmt_play, cmt_rec;
66         _TCHAR cmt_file_path[_MAX_PATH];
67         int cmt_count;
68         uint8 cmt_buffer[CMT_BUFFER_SIZE];
69         
70         typedef struct {
71                 uint8 buffer[80];
72                 int bank;
73                 int addr;
74         } lcd_t;
75         lcd_t lcd[6];
76         
77         scrntype lcd_render[32][120];
78         scrntype pd, pb;
79         uint8 lcd_select, lcd_data;
80         int lcd_clock;
81         
82         int int_status;
83         int int_mask;
84         
85         void update_sound();
86         void update_keyboard();
87         void update_intr();
88         void send_to_slave(uint8 val);
89         void send_to_main(uint8 val);
90         
91 public:
92         MEMORY(VM* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu) {}
93         ~MEMORY() {}
94         
95         // common functions
96         void initialize();
97         void release();
98         void reset();
99         void write_data8(uint32 addr, uint32 data);
100         uint32 read_data8(uint32 addr);
101         void write_signal(int id, uint32 data, uint32 mask);
102         void event_callback(int event_id, int err);
103         void save_state(FILEIO* state_fio);
104         bool load_state(FILEIO* state_fio);
105         
106         // unique functions
107         void set_context_beep(BEEP* device)
108         {
109                 d_beep = device;
110         }
111         void set_context_cpu(DEVICE* device)
112         {
113                 d_cpu = device;
114         }
115         void set_context_rtc(DEVICE* device)
116         {
117                 d_rtc = device;
118         }
119         void set_context_sio_tf20(DEVICE* device)
120         {
121                 d_sio_tf20 = device;
122         }
123         void notify_power_off();
124         void key_down(int code);
125         void key_up(int code);
126         void play_tape(_TCHAR* file_path);
127         void rec_tape(_TCHAR* file_path);
128         void close_tape();
129         bool tape_inserted()
130         {
131                 return (cmt_play || cmt_rec);
132         }
133         int get_tape_ptr(void);
134         void draw_screen();
135 };
136
137 #endif
138