1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles, Nathan Woods
3 /***************************************************************************
5 v9938 / v9958 emulation
7 ***************************************************************************/
20 //**************************************************************************
21 // DEVICE CONFIGURATION MACROS
22 //**************************************************************************
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);
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, \
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")
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, \
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")
57 #define MCFG_V99X8_INTERRUPT_CALLBACK(_irq) \
58 downcast<v99x8_device *>(device)->set_interrupt_callback(DEVCB_##_irq);
61 //**************************************************************************
63 //**************************************************************************
65 // device type definition
66 //extern const device_type V9938;
67 //extern const device_type V9958;
71 //**************************************************************************
73 //**************************************************************************
75 // ======================> v99x8_device
77 class v99x8_device : public DEVICE
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);
87 //template<class _irq> void set_interrupt_callback(_irq irq) {
88 // m_int_callback.set_callback(irq);
91 //bitmap_ind16 &get_bitmap() { return m_bitmap; }
92 //void update_mouse_state(int mx_delta, int my_delta, int button_state);
94 //UINT32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
96 //DECLARE_READ8_MEMBER( read );
97 //DECLARE_WRITE8_MEMBER( write );
101 void palette_w(UINT8 data);
102 void vram_w(UINT8 data);
103 void command_w(UINT8 data);
104 void register_w(UINT8 data);
106 //static void static_set_vram_size(device_t &device, UINT32 vram_size);
109 //void reset_line(int state) { if (state==ASSERT_LINE) device_reset(); }
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;
126 //static const device_timer_id TIMER_LINE = 0;
127 //const address_space_config m_space_config;
128 //address_space* m_vram_space;
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;
138 void device_timer(int v);
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; }
143 void configure_pal_ntsc();
144 void set_screen_parameters();
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);
153 void register_write(int reg, int data);
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);
174 void sprite_mode1(int line, UINT8 *col);
175 void sprite_mode2(int line, UINT8 *col);
177 void refresh_16(int line);
178 void refresh_line(int line);
180 void interrupt_start_vblank();
182 int VDPVRMP(UINT8 M, int MX, int X, int Y);
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);
189 UINT8 VDPpoint(UINT8 SM, int MXS, int SX, int SY);
191 void VDPpsetlowlevel(int addr, UINT8 CL, UINT8 M, UINT8 OP);
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);
198 void VDPpset(UINT8 SM, int MXD, int DX, int DY, UINT8 CL, UINT8 OP);
200 int get_vdp_timing_value(const int *);
213 inline bool v9938_second_field();
215 void cpu_to_vdp(UINT8 V);
217 void report_vdp_command(UINT8 Op);
218 UINT8 command_unit_w(UINT8 Op);
219 void update_command();
222 int m_offset_x, m_offset_y, m_visible_y, m_mode;
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;
230 UINT16 m_address_latch;
235 //devcb_write_line m_int_callback;
238 int m_blink, m_blink_count;
240 UINT8 m_mx_delta, m_my_delta;
242 UINT8 m_button_state;
244 UINT16 m_pal_ind16[16];
245 UINT16 m_pal_ind256[256];
247 //bitmap_ind16 m_bitmap;
249 typedef struct mmc_s {
263 void (v99x8_device::*m_vdp_engine)();
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*);
273 static const v99x8_mode s_modes[];
274 //required_device<palette_device> m_palette;
275 //emu_timer *m_line_timer;
277 int m_scanline_start;
282 static UINT16 s_pal_indYJK[0x20000];
285 for common source code project
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);
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;}
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()
319 void set_context_irq(DEVICE* device, int id, uint32_t mask)
321 register_output_signal(&outputs_irq, device, id, mask);
327 class v9938_device : public v99x8_device
330 v9938_device(VM_TEMPLATE* parent_vm, EMU* parent_emu);
332 //DECLARE_PALETTE_INIT(v9938);
334 //virtual machine_config_constructor device_mconfig_additions() const override;
338 class v9958_device : public v99x8_device
341 v9958_device(VM_TEMPLATE* parent_vm, EMU* parent_emu);
343 //DECLARE_PALETTE_INIT(v9958);
346 //virtual machine_config_constructor device_mconfig_additions() const override;
350 #define SIG_VDP_COMMAND_COMPLETION 0
355 Common Source Code Project
356 MSX Series (experimental)
358 Origin : mame0172s.zip
359 mame.zip\src\devices\video\v9938.h