1 // license:BSD-3-Clause
2 // copyright-holders:Takahiro Nogi, Uki
3 #ifndef MAME_INCLUDES_FROMANC2_H
4 #define MAME_INCLUDES_FROMANC2_H
5 
6 #pragma once
7 
8 #include "machine/gen_latch.h"
9 #include "machine/eepromser.h"
10 #include "machine/ins8250.h"
11 #include "emupal.h"
12 #include "tilemap.h"
13 
14 class fromanc2_state : public driver_device
15 {
16 public:
fromanc2_state(const machine_config & mconfig,device_type type,const char * tag)17 	fromanc2_state(const machine_config &mconfig, device_type type, const char *tag)
18 		: driver_device(mconfig, type, tag),
19 		m_maincpu(*this, "maincpu"),
20 		m_audiocpu(*this, "audiocpu"),
21 		m_subcpu(*this, "sub"),
22 		m_eeprom(*this, "eeprom"),
23 		m_gfxdecode(*this, "gfxdecode"),
24 		m_lpalette(*this, "lpalette"),
25 		m_rpalette(*this, "rpalette"),
26 		m_soundlatch(*this, "soundlatch"),
27 		m_soundlatch2(*this, "soundlatch2"),
28 		m_uart(*this, "uart")
29 	{ }
30 
31 	void fromanc2(machine_config &config);
32 	void fromancr(machine_config &config);
33 	void fromanc4(machine_config &config);
34 
35 	void init_fromanc4();
36 	void init_fromanc2();
37 
38 	DECLARE_READ_LINE_MEMBER(subcpu_int_r);
39 	DECLARE_READ_LINE_MEMBER(sndcpu_nmi_r);
40 	DECLARE_READ_LINE_MEMBER(subcpu_nmi_r);
41 
42 private:
43 	/* memory pointers */
44 	std::unique_ptr<uint16_t[]>   m_videoram[2][4];
45 	std::unique_ptr<uint8_t[]>    m_bankedram;
46 
47 	/* video-related */
48 	tilemap_t  *m_tilemap[2][4];
49 	int      m_scrollx[2][4];
50 	int      m_scrolly[2][4];
51 	int      m_gfxbank[2][4];
52 
53 	/* misc */
54 	int      m_portselect;
55 	uint8_t    m_subcpu_int_flag;
56 	uint8_t    m_subcpu_nmi_flag;
57 	uint8_t    m_sndcpu_nmi_flag;
58 	uint16_t   m_datalatch1;
59 	uint8_t    m_datalatch_2h;
60 	uint8_t    m_datalatch_2l;
61 
62 	/* devices */
63 	required_device<cpu_device> m_maincpu;
64 	required_device<cpu_device> m_audiocpu;
65 	optional_device<cpu_device> m_subcpu;
66 	optional_device<eeprom_serial_93cxx_device> m_eeprom;
67 	required_device<gfxdecode_device> m_gfxdecode;
68 	required_device<palette_device> m_lpalette;
69 	required_device<palette_device> m_rpalette;
70 	required_device<generic_latch_8_device> m_soundlatch;
71 	required_device<generic_latch_8_device> m_soundlatch2;
72 	optional_device<ns16550_device> m_uart;
73 
74 	void sndcmd_w(uint16_t data);
75 	void portselect_w(uint16_t data);
76 	uint16_t keymatrix_r();
77 	void fromancr_gfxbank_eeprom_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
78 	void subcpu_w(uint16_t data);
79 	uint16_t subcpu_r();
80 	uint8_t maincpu_r_l();
81 	uint8_t maincpu_r_h();
82 	void maincpu_w_l(uint8_t data);
83 	void maincpu_w_h(uint8_t data);
84 	void subcpu_nmi_clr(uint8_t data);
85 	uint8_t sndcpu_nmi_clr();
86 	void subcpu_rombank_w(uint8_t data);
87 	void fromanc2_videoram_0_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
88 	void fromanc2_videoram_1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
89 	void fromanc2_videoram_2_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
90 	void fromanc2_videoram_3_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
91 	void fromanc2_gfxreg_0_w(offs_t offset, uint16_t data);
92 	void fromanc2_gfxreg_1_w(offs_t offset, uint16_t data);
93 	void fromanc2_gfxreg_2_w(offs_t offset, uint16_t data);
94 	void fromanc2_gfxreg_3_w(offs_t offset, uint16_t data);
95 	void fromanc2_gfxbank_0_w(uint16_t data);
96 	void fromanc2_gfxbank_1_w(uint16_t data);
97 	void fromancr_videoram_0_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
98 	void fromancr_videoram_1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
99 	void fromancr_videoram_2_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
100 	void fromancr_gfxreg_0_w(offs_t offset, uint16_t data);
101 	void fromancr_gfxreg_1_w(offs_t offset, uint16_t data);
102 	void fromanc4_videoram_0_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
103 	void fromanc4_videoram_1_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
104 	void fromanc4_videoram_2_w(offs_t offset, uint16_t data, uint16_t mem_mask = ~0);
105 	void fromanc4_gfxreg_0_w(offs_t offset, uint16_t data);
106 	void fromanc4_gfxreg_1_w(offs_t offset, uint16_t data);
107 	void fromanc4_gfxreg_2_w(offs_t offset, uint16_t data);
108 
109 	template<int VRAM, int Layer> TILE_GET_INFO_MEMBER(fromanc2_get_tile_info);
110 	template<int VRAM, int Layer> TILE_GET_INFO_MEMBER(fromancr_get_tile_info);
111 	virtual void machine_reset() override;
112 	DECLARE_MACHINE_START(fromanc2);
113 	DECLARE_VIDEO_START(fromanc2);
114 	DECLARE_VIDEO_START(fromancr);
115 	DECLARE_MACHINE_START(fromanc4);
116 	DECLARE_VIDEO_START(fromanc4);
117 	uint32_t screen_update_left(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
118 	uint32_t screen_update_right(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
119 	inline void fromanc2_dispvram_w( offs_t offset, uint16_t data, uint16_t mem_mask, int vram, int layer );
120 	inline void fromancr_vram_w(offs_t offset, uint16_t data, uint16_t mem_mask, int layer );
121 	void fromancr_gfxbank_w( int data );
122 	inline void fromanc4_vram_w( offs_t offset, uint16_t data, uint16_t mem_mask, int layer );
123 	void fromanc2_main_map(address_map &map);
124 	void fromanc2_sound_io_map(address_map &map);
125 	void fromanc2_sound_map(address_map &map);
126 	void fromanc2_sub_io_map(address_map &map);
127 	void fromanc2_sub_map(address_map &map);
128 	void fromanc4_main_map(address_map &map);
129 	void fromancr_main_map(address_map &map);
130 };
131 
132 #endif // MAME_INCLUDES_FROMANC2_H
133