OSDN Git Service

[VM][WIP] Use namespace to devices per VMs.
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz700 / memory.h
1 /*
2         SHARP MZ-700 Emulator 'EmuZ-700'
3         SHARP MZ-800 Emulator 'EmuZ-800'
4         SHARP MZ-1500 Emulator 'EmuZ-1500'
5
6         Author : Takeda.Toshiya
7         Date   : 2008.06.05 -
8
9         [ memory ]
10 */
11
12 #ifndef _MZ700_MEMORY_H_
13 #define _MZ700_MEMORY_H_
14
15 #include "../vm.h"
16 #include "../../emu.h"
17 #include "../device.h"
18
19 #if defined(_MZ800)
20 class DISPLAY;
21 #endif
22
23 namespace MZ700 {
24         
25 class MEMORY : public DEVICE
26 {
27 private:
28         DEVICE *d_cpu, *d_pit, *d_pio;
29 #if defined(_MZ800)
30         DEVICE *d_pio_int;
31 #endif
32         
33         // memory
34         uint8_t* rbank[32];
35         uint8_t* wbank[32];
36         uint8_t wdmy[0x800];
37         uint8_t rdmy[0x800];
38         
39         uint8_t ipl[0x1000];    // IPL 4KB
40 #if defined(_MZ800)
41         uint8_t ext[0x2000];    // MZ-800 IPL 8KB
42 #elif defined(_MZ1500)
43         uint8_t ext[0x1800];    // MZ-1500 EXT 6KB
44 #endif
45         uint8_t font[0x1000];   // CGROM 4KB
46 #if defined(_MZ700)
47         uint8_t pcg[0x1000];    // PCG-700 2KB + Lower CGROM 2KB
48 #elif defined(_MZ1500)
49         uint8_t pcg[0x6000];    // MZ-1500 PCG 8KB * 3
50 #endif
51         uint8_t ram[0x10000];   // Main RAM 64KB
52 #if defined(_MZ800)
53         uint8_t vram[0x8000];   // MZ-800 VRAM 32KB
54 #else
55         uint8_t vram[0x1000];   // MZ-700/1500 VRAM 4KB
56 #endif
57         uint8_t mem_bank;
58 #if defined(_MZ700)
59         uint8_t pcg_data;
60         uint8_t pcg_addr;
61         uint8_t pcg_ctrl;
62 #elif defined(_MZ800)
63         uint8_t wf, rf;
64         uint8_t dmd;
65         uint32_t vram_addr_top;
66         bool is_mz800;
67 #elif defined(_MZ1500)
68         uint8_t pcg_bank;
69 #endif
70         
71         void update_map_low();
72         void update_map_middle();
73         void update_map_high();
74 #if defined(_MZ800)
75         int vram_page_mask(uint8_t f);
76         int vram_addr(int addr);
77 #endif
78         
79         // crtc
80 #if defined(_MZ800)
81         uint16_t sof;
82         uint8_t sw, ssa, sea;
83         uint8_t palette_sw, palette[4], palette16[16];
84 #elif defined(_MZ1500)
85         uint8_t priority, palette[8];
86 #endif
87         bool blink, tempo;
88         bool hblank, hsync;
89         bool vblank, vsync;
90 #if defined(_MZ700) || defined(_MZ1500)
91         bool hblank_vram;
92 #endif
93 #if defined(_MZ1500)
94         bool hblank_pcg;
95 #endif
96         void set_vblank(bool val);
97         void set_hblank(bool val);
98         
99         // renderer
100 #if defined(_MZ800)
101         uint8_t screen[200][640];
102         scrntype_t palette_mz800_pc[16];
103 #else
104         uint8_t screen[200][320];
105 #endif
106         scrntype_t palette_pc[8];
107         
108 #if defined(_MZ800)
109         void draw_line_320x200_2bpp(int v);
110         void draw_line_320x200_4bpp(int v);
111         void draw_line_640x200_1bpp(int v);
112         void draw_line_640x200_2bpp(int v);
113         void draw_line_mz700(int v);
114 #else
115         void draw_line(int v);
116 #endif
117         
118 public:
119         MEMORY(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu)
120         {
121                 set_device_name(_T("Memory Bus"));
122         }
123         ~MEMORY() {}
124         
125         // common functions
126         void initialize();
127         void reset();
128 #if defined(_MZ800)
129         void update_config();
130 #endif
131         void event_vline(int v, int clock);
132         void event_callback(int event_id, int err);
133         void write_data8(uint32_t addr, uint32_t data);
134         uint32_t read_data8(uint32_t addr);
135         void write_data8w(uint32_t addr, uint32_t data, int* wait);
136         uint32_t read_data8w(uint32_t addr, int* wait);
137         void write_io8(uint32_t addr, uint32_t data);
138 #if defined(_MZ800)
139         uint32_t read_io8(uint32_t addr);
140 #endif
141         bool process_state(FILEIO* state_fio, bool loading);
142         
143         // unique functions
144         void set_context_cpu(DEVICE* device)
145         {
146                 d_cpu = device;
147         }
148         void set_context_pit(DEVICE* device)
149         {
150                 d_pit = device;
151         }
152         void set_context_pio(DEVICE* device)
153         {
154                 d_pio = device;
155         }
156 #if defined(_MZ800)
157         void set_context_pio_int(DEVICE* device)
158         {
159                 d_pio_int = device;
160         }
161 #endif
162         void draw_screen();
163 };
164
165 }
166 #endif
167