OSDN Git Service

[VM] Merge Upstream 2019-02-19.Only for DEVICES, not MACHINES YET.
[csp-qt/common_source_project-fm7.git] / source / src / vm / v9938.h
1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles, Nathan Woods
3 /***************************************************************************
4
5     v9938 / v9958 emulation
6
7 ***************************************************************************/
8
9 #pragma once
10
11 #ifndef __V9938_H__
12 #define __V9938_H__
13
14 //#include "vm.h"
15 //#include "../emu.h"
16 #include "device.h"
17
18
19
20 //**************************************************************************
21 //  DEVICE CONFIGURATION MACROS
22 //**************************************************************************
23 /*
24 #define MCFG_V9938_ADD(_tag, _screen, _vramsize, _clock) \
25         MCFG_DEVICE_ADD(_tag, V9938, _clock) \
26         MCFG_VIDEO_SET_SCREEN(_screen) \
27         v9938_device::static_set_vram_size(*device, _vramsize);
28 #define MCFG_V9958_ADD(_tag, _screen, _vramsize, _clock) \
29         MCFG_DEVICE_ADD(_tag, V9958, _clock) \
30         MCFG_VIDEO_SET_SCREEN(_screen) \
31         v9938_device::static_set_vram_size(*device, _vramsize);
32
33 #define MCFG_V99X8_SCREEN_ADD_NTSC(_screen_tag, _v9938_tag, _clock) \
34         MCFG_SCREEN_ADD(_screen_tag, RASTER) \
35         MCFG_SCREEN_RAW_PARAMS(_clock, \
36                 v99x8_device::HTOTAL, \
37                 0, \
38                 v99x8_device::HVISIBLE - 1, \
39                 v99x8_device::VTOTAL_NTSC * 2, \
40                 v99x8_device::VERTICAL_ADJUST * 2, \
41                 v99x8_device::VVISIBLE_NTSC * 2 - 1 - v99x8_device::VERTICAL_ADJUST * 2) \
42         MCFG_SCREEN_UPDATE_DEVICE(_v9938_tag, v9938_device, screen_update) \
43         MCFG_SCREEN_PALETTE(_v9938_tag":palette")
44
45 #define MCFG_V99X8_SCREEN_ADD_PAL(_screen_tag, _v9938_tag, _clock) \
46         MCFG_SCREEN_ADD(_screen_tag, RASTER) \
47         MCFG_SCREEN_RAW_PARAMS(_clock, \
48                 v99x8_device::HTOTAL, \
49                 0, \
50                 v99x8_device::HVISIBLE - 1, \
51                 v99x8_device::VTOTAL_PAL * 2, \
52                 v99x8_device::VERTICAL_ADJUST * 2, \
53                 v99x8_device::VVISIBLE_PAL * 2 - 1 - v99x8_device::VERTICAL_ADJUST * 2) \
54         MCFG_SCREEN_UPDATE_DEVICE(_v9938_tag, v9938_device, screen_update) \
55         MCFG_SCREEN_PALETTE(_v9938_tag":palette")
56
57 #define MCFG_V99X8_INTERRUPT_CALLBACK(_irq) \
58         downcast<v99x8_device *>(device)->set_interrupt_callback(DEVCB_##_irq);
59 */
60
61 //**************************************************************************
62 //  GLOBAL VARIABLES
63 //**************************************************************************
64
65 // device type definition
66 //extern const device_type V9938;
67 //extern const device_type V9958;
68
69
70
71 //**************************************************************************
72 //  TYPE DEFINITIONS
73 //**************************************************************************
74
75 // ======================> v99x8_device
76
77 class v99x8_device :    public DEVICE
78 {
79 protected:
80         int __SCREEN_WIDTH;
81         int __SCREEN_HEIGHT;
82         // construction/destruction
83         //v99x8_device(VM_TEMPLATE* parent_vm, EMU* parent_emu) : DEVICE(parent_vm, parent_emu){}
84         v99x8_device(VM_TEMPLATE* parent_vm, EMU* parent_emu);
85
86 public:
87         //template<class _irq> void set_interrupt_callback(_irq irq) {
88         //      m_int_callback.set_callback(irq);
89         //}
90         int get_transpen();
91         //bitmap_ind16 &get_bitmap() { return m_bitmap; }
92         //void update_mouse_state(int mx_delta, int my_delta, int button_state);
93
94         //UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
95
96         //DECLARE_READ8_MEMBER( read );
97         //DECLARE_WRITE8_MEMBER( write );
98
99         UINT8 vram_r();
100         UINT8 status_r();
101         void palette_w(UINT8 data);
102         void vram_w(UINT8 data);
103         void command_w(UINT8 data);
104         void register_w(UINT8 data);
105
106         //static void static_set_vram_size(device_t &device, UINT32 vram_size);
107
108         /* RESET pin */
109         //void reset_line(int state) { if (state==ASSERT_LINE) device_reset(); }
110
111         static const int HTOTAL = 684;
112         static const int HVISIBLE = 544;
113         static const int VTOTAL_NTSC = 262;
114         static const int VTOTAL_PAL = 313;
115         static const int VVISIBLE_NTSC = 26 + 192 + 25;
116         static const int VVISIBLE_PAL = 53 + 192 + 49;
117         // Looking at some youtube videos of real units on real monitors
118         // there appear to be small vertical timing differences. Some (LCD)
119         // monitors show the full borders, other CRT monitors seem to
120         // display ~5 lines less at the top and bottom of the screen.
121         static const int VERTICAL_ADJUST = 5;
122         static const int TOP_ERASE = 13;
123         static const int VERTICAL_SYNC = 3;
124
125 protected:
126         //static const device_timer_id TIMER_LINE = 0;
127         //const address_space_config      m_space_config;
128         //address_space*                  m_vram_space;
129
130         int m_model;
131
132         // device overrides
133         //virtual void device_start() override;
134         //virtual void device_reset() override;
135         //virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
136         void device_start();
137         void device_reset();
138         void device_timer(int v);
139
140         // device_memory_interface overrides
141         //virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_DATA) const override { return (spacenum == AS_DATA) ? &m_space_config : nullptr; }
142
143         void configure_pal_ntsc();
144         void set_screen_parameters();
145
146 private:
147         // internal helpers
148         inline int position_offset(UINT8 value) { value &= 0x0f; return (value < 8) ? -value : 16 - value; }
149         void reset_palette();
150         void vram_write(int offset, int data);
151         int vram_read(int offset);
152         void check_int();
153         void register_write(int reg, int data);
154
155         void default_border(const scrntype_t *pens, scrntype_t *ln);
156         void graphic7_border(const scrntype_t *pens, scrntype_t *ln);
157         void graphic5_border(const scrntype_t *pens, scrntype_t *ln);
158         void mode_text1(const scrntype_t *pens, scrntype_t *ln, int line);
159         void mode_text2(const scrntype_t *pens, scrntype_t *ln, int line);
160         void mode_multi(const scrntype_t *pens, scrntype_t *ln, int line);
161         void mode_graphic1(const scrntype_t *pens, scrntype_t *ln, int line);
162         void mode_graphic23(const scrntype_t *pens, scrntype_t *ln, int line);
163         void mode_graphic4(const scrntype_t *pens, scrntype_t *ln, int line);
164         void mode_graphic5(const scrntype_t *pens, scrntype_t *ln, int line);
165         void mode_graphic6(const scrntype_t *pens, scrntype_t *ln, int line);
166         void mode_graphic7(const scrntype_t *pens, scrntype_t *ln, int line);
167 //  template<typename _PixelType, int _Width> void mode_yae(const scrntype_t *pens, _PixelType *ln, int line);
168 //  template<typename _PixelType, int _Width> void mode_yjk(const scrntype_t *pens, _PixelType *ln, int line);
169         void mode_unknown(const scrntype_t *pens, scrntype_t *ln, int line);
170         void default_draw_sprite(const scrntype_t *pens, scrntype_t *ln, UINT8 *col);
171         void graphic5_draw_sprite(const scrntype_t *pens, scrntype_t *ln, UINT8 *col);
172         void graphic7_draw_sprite(const scrntype_t *pens, scrntype_t *ln, UINT8 *col);
173
174         void sprite_mode1(int line, UINT8 *col);
175         void sprite_mode2(int line, UINT8 *col);
176         void set_mode();
177         void refresh_16(int line);
178         void refresh_line(int line);
179
180         void interrupt_start_vblank();
181
182         int VDPVRMP(UINT8 M, int MX, int X, int Y);
183
184         UINT8 VDPpoint5(int MXS, int SX, int SY);
185         UINT8 VDPpoint6(int MXS, int SX, int SY);
186         UINT8 VDPpoint7(int MXS, int SX, int SY);
187         UINT8 VDPpoint8(int MXS, int SX, int SY);
188
189         UINT8 VDPpoint(UINT8 SM, int MXS, int SX, int SY);
190
191         void VDPpsetlowlevel(int addr, UINT8 CL, UINT8 M, UINT8 OP);
192
193         void VDPpset5(int MXD, int DX, int DY, UINT8 CL, UINT8 OP);
194         void VDPpset6(int MXD, int DX, int DY, UINT8 CL, UINT8 OP);
195         void VDPpset7(int MXD, int DX, int DY, UINT8 CL, UINT8 OP);
196         void VDPpset8(int MXD, int DX, int DY, UINT8 CL, UINT8 OP);
197
198         void VDPpset(UINT8 SM, int MXD, int DX, int DY, UINT8 CL, UINT8 OP);
199
200         int get_vdp_timing_value(const int *);
201
202         void srch_engine();
203         void line_engine();
204         void lmmv_engine();
205         void lmmm_engine();
206         void lmcm_engine();
207         void lmmc_engine();
208         void hmmv_engine();
209         void hmmm_engine();
210         void ymmm_engine();
211         void hmmc_engine();
212
213         inline bool v9938_second_field();
214
215         void cpu_to_vdp(UINT8 V);
216         UINT8 vdp_to_cpu();
217         void report_vdp_command(UINT8 Op);
218         UINT8 command_unit_w(UINT8 Op);
219         void update_command();
220
221         // general
222         int m_offset_x, m_offset_y, m_visible_y, m_mode;
223         // palette
224         int m_pal_write_first, m_cmd_write_first;
225         UINT8 m_pal_write, m_cmd_write;
226         UINT8 m_pal_reg[32], m_stat_reg[10], m_cont_reg[48], m_read_ahead;
227         UINT8 m_v9958_sp_mode;
228
229         // memory
230         UINT16 m_address_latch;
231         int m_vram_size;
232
233         // interrupt
234         UINT8 m_int_state;
235         //devcb_write_line   m_int_callback;
236         int m_scanline;
237         // blinking
238         int m_blink, m_blink_count;
239         // mouse
240         UINT8 m_mx_delta, m_my_delta;
241         // mouse & lightpen
242         UINT8 m_button_state;
243         // palette
244         UINT16 m_pal_ind16[16];
245         UINT16 m_pal_ind256[256];
246         // render bitmap
247         //bitmap_ind16 m_bitmap;
248         // Command unit
249         typedef struct mmc_s {
250                 int SX,SY;
251                 int DX,DY;
252                 int TX,TY;
253                 int NX,NY;
254                 int MX;
255                 int ASX,ADX,ANX;
256                 UINT8 CL;
257                 UINT8 LO;
258                 UINT8 CM;
259                 UINT8 MXS, MXD;
260         } mmc_t;
261         mmc_t m_mmc;
262         int  m_vdp_ops_count;
263         void (v99x8_device::*m_vdp_engine)();
264
265         struct v99x8_mode
266         {
267                 UINT8 m;
268                 void (v99x8_device::*visible_16)(const scrntype_t *, scrntype_t*, int);
269                 void (v99x8_device::*border_16)(const scrntype_t *, scrntype_t*);
270                 void (v99x8_device::*sprites)(int, UINT8*);
271                 void (v99x8_device::*draw_sprite_16)(const scrntype_t *, scrntype_t*, UINT8*);
272         } ;
273         static const v99x8_mode s_modes[];
274         //required_device<palette_device> m_palette;
275         //emu_timer *m_line_timer;
276         UINT8 m_pal_ntsc;
277         int m_scanline_start;
278         int m_vblank_start;
279         int m_scanline_max;
280         int m_height;
281 protected:
282         static UINT16 s_pal_indYJK[0x20000];
283
284         /*
285            for common source code project
286          */
287 private:
288         // output signals
289         outputs_t outputs_irq;
290         uint8_t vram[0x20000];
291         scrntype_t screen[(512 + 32)*246*2]; // (LONG_WIDTH) * (m_vblank_start*2)
292         /* for m_vram_space of MAME/MESS */
293         inline int read_byte(int address){if (address<m_vram_size) return vram[address];else return 0xff;}
294         inline void write_byte(int address, int val){if (address<m_vram_size) vram[address]=val;}
295         /* for m_palette and palette of MAME/MESS */
296         scrntype_t pens[19780];
297         void save_load_state(FILEIO* state_fio, bool is_save);
298 protected:
299         /* for m_palette and palette of MAME/MESS */
300         virtual void init_palette()=0;
301         inline void set_pen_color(int index, int r, int g, int b){if (index<19780) pens[index]=RGB_COLOR(r,g,b);}
302         inline int pal3bit(int i) {return (i&7)*36;}
303         inline int pal5bit(int i) {return (i&31)<<3;}
304 public:
305         // common functions
306         void initialize();
307         void reset();
308         void write_io8(uint32_t addr, uint32_t data);
309         uint32_t read_io8(uint32_t addr);
310         void event_vline(int v, int clock);
311         void write_signal(int id, uint32_t data, uint32_t mask);
312         bool process_state(FILEIO* state_fio, bool loading);
313         const _TCHAR *get_device_name()
314         {
315                 return _T("v99x8");
316         }
317         
318         // unique functions
319         void set_context_irq(DEVICE* device, int id, uint32_t mask)
320         {
321                 register_output_signal(&outputs_irq, device, id, mask);
322         }
323         void draw_screen();
324 };
325
326
327 class v9938_device : public v99x8_device
328 {
329 public:
330         v9938_device(VM_TEMPLATE* parent_vm, EMU* parent_emu);
331
332         //DECLARE_PALETTE_INIT(v9938);
333 protected:
334         //virtual machine_config_constructor device_mconfig_additions() const override;
335         void init_palette();
336 };
337
338 class v9958_device : public v99x8_device
339 {
340 public:
341         v9958_device(VM_TEMPLATE* parent_vm, EMU* parent_emu);
342
343         //DECLARE_PALETTE_INIT(v9958);
344
345 protected:
346         //virtual machine_config_constructor device_mconfig_additions() const override;
347         void init_palette();
348 };
349
350 #define SIG_VDP_COMMAND_COMPLETION      0
351
352 #endif
353
354 /*
355         Common Source Code Project
356         MSX Series (experimental)
357
358         Origin : mame0172s.zip
359                 mame.zip\src\devices\video\v9938.h
360         modified by umaiboux
361         Date   : 2016.04.xx-
362
363         [ V99x8 ]
364 */