1 // license:BSD-3-Clause
2 // copyright-holders:Mirko Buffoni
3 #ifndef MAME_INCLUDES_MARIO_H
4 #define MAME_INCLUDES_MARIO_H
5 
6 #pragma once
7 
8 #include "machine/gen_latch.h"
9 #include "machine/z80dma.h"
10 #include "emupal.h"
11 #include "tilemap.h"
12 
13 #define OLD_SOUND   (0)
14 
15 #if !OLD_SOUND
16 #include "machine/netlist.h"
17 #include "netlist/devices/net_lib.h"
18 #else
19 #include "sound/discrete.h"
20 #endif
21 
22 /*
23  * From the schematics:
24  *
25  * Video generation like dkong/dkongjr. However, clock is 24MHZ
26  * 7C -> 100 => 256 - 124 = 132 ==> 264 Scanlines
27  */
28 
29 #define MASTER_CLOCK            XTAL(24'000'000)
30 #define PIXEL_CLOCK             (MASTER_CLOCK / 4)
31 #define CLOCK_1H                (MASTER_CLOCK / 8)
32 #define CLOCK_16H               (CLOCK_1H / 16)
33 #define CLOCK_1VF               ((CLOCK_16H) / 12 / 2)
34 #define CLOCK_2VF               ((CLOCK_1VF) / 2)
35 
36 #define HTOTAL                  (384)
37 #define HBSTART                 (256)
38 #define HBEND                   (0)
39 #define VTOTAL                  (264)
40 #define VBSTART                 (240)
41 #define VBEND                   (16)
42 
43 #define Z80_MASTER_CLOCK        XTAL(8'000'000)
44 #define Z80_CLOCK               (Z80_MASTER_CLOCK / 2) /* verified on pcb */
45 
46 #define I8035_MASTER_CLOCK      XTAL(11'000'000) /* verified on pcb: 730Khz */
47 #define I8035_CLOCK             (I8035_MASTER_CLOCK)
48 
49 class mario_state : public driver_device
50 {
51 public:
mario_state(const machine_config & mconfig,device_type type,const char * tag)52 	mario_state(const machine_config &mconfig, device_type type, const char *tag) :
53 		driver_device(mconfig, type, tag),
54 		m_maincpu(*this, "maincpu"),
55 		m_audiocpu(*this, "audiocpu"),
56 		m_gfxdecode(*this, "gfxdecode"),
57 		m_palette(*this, "palette"),
58 		m_z80dma(*this, "z80dma"),
59 		m_soundlatch(*this, "soundlatch"),
60 		m_soundlatch2(*this, "soundlatch2"),
61 		m_soundlatch3(*this, "soundlatch3"),
62 		m_soundlatch4(*this, "soundlatch4"),
63 #if OLD_SOUND
64 		m_discrete(*this, "discrete"),
65 #else
66 		m_audio_snd0(*this, "snd_nl:snd0"),
67 		m_audio_snd1(*this, "snd_nl:snd1"),
68 		m_audio_snd7(*this, "snd_nl:snd7"),
69 		m_audio_dac(*this, "snd_nl:dac"),
70 #endif
71 		m_spriteram(*this, "spriteram"),
72 		m_videoram(*this, "videoram"),
73 		m_monitor(0)
74 	{ }
75 
76 	void mario_base(machine_config &config);
77 	void masao(machine_config &config);
78 	void masao_audio(machine_config &config);
79 	void mario(machine_config &config);
80 	void mario_audio(machine_config &config);
81 
82 private:
83 	/* devices */
84 	required_device<cpu_device> m_maincpu;
85 	required_device<cpu_device> m_audiocpu;
86 	required_device<gfxdecode_device> m_gfxdecode;
87 	required_device<palette_device> m_palette;
88 	required_device<z80dma_device> m_z80dma;
89 	optional_device<generic_latch_8_device> m_soundlatch;
90 	optional_device<generic_latch_8_device> m_soundlatch2;
91 	optional_device<generic_latch_8_device> m_soundlatch3;
92 	optional_device<generic_latch_8_device> m_soundlatch4;
93 #if OLD_SOUND
94 	optional_device<discrete_sound_device> m_discrete;
95 #else
96 	optional_device<netlist_mame_logic_input_device> m_audio_snd0;
97 	optional_device<netlist_mame_logic_input_device> m_audio_snd1;
98 	optional_device<netlist_mame_logic_input_device> m_audio_snd7;
99 	optional_device<netlist_mame_int_input_device> m_audio_dac;
100 #endif
101 
102 	/* memory pointers */
103 	required_shared_ptr<uint8_t> m_spriteram;
104 	required_shared_ptr<uint8_t> m_videoram;
105 
106 	/* sound state */
107 	uint8_t   m_last;
108 	uint8_t   m_portT;
109 	const char *m_eabank;
110 
111 	/* video state */
112 	uint8_t   m_gfx_bank;
113 	uint8_t   m_palette_bank;
114 	uint16_t  m_gfx_scroll;
115 	uint8_t   m_flip;
116 	tilemap_t *m_bg_tilemap;
117 	int m_monitor;
118 
119 	bool      m_nmi_mask;
120 	DECLARE_WRITE_LINE_MEMBER(nmi_mask_w);
121 	DECLARE_WRITE_LINE_MEMBER(coin_counter_1_w);
122 	DECLARE_WRITE_LINE_MEMBER(coin_counter_2_w);
123 	void mario_videoram_w(offs_t offset, uint8_t data);
124 	DECLARE_WRITE_LINE_MEMBER(gfx_bank_w);
125 	DECLARE_WRITE_LINE_MEMBER(palette_bank_w);
126 	void mario_scroll_w(uint8_t data);
127 	DECLARE_WRITE_LINE_MEMBER(flip_w);
128 	uint8_t mario_sh_p1_r();
129 	uint8_t mario_sh_p2_r();
130 	DECLARE_READ_LINE_MEMBER(mario_sh_t0_r);
131 	DECLARE_READ_LINE_MEMBER(mario_sh_t1_r);
132 	uint8_t mario_sh_tune_r(offs_t offset);
133 	void mario_sh_p1_w(uint8_t data);
134 	void mario_sh_p2_w(uint8_t data);
135 	void masao_sh_irqtrigger_w(uint8_t data);
136 	void mario_sh_tuneselect_w(uint8_t data);
137 	void mario_sh3_w(offs_t offset, uint8_t data);
138 	TILE_GET_INFO_MEMBER(get_bg_tile_info);
139 	virtual void video_start() override;
140 	virtual void sound_start() override;
141 	virtual void sound_reset() override;
142 	void mario_palette(palette_device &palette) const;
143 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
144 	DECLARE_WRITE_LINE_MEMBER(vblank_irq);
145 	void mario_sh_sound_w(uint8_t data);
146 	void mario_sh1_w(uint8_t data);
147 	void mario_sh2_w(uint8_t data);
148 	uint8_t memory_read_byte(offs_t offset);
149 	void memory_write_byte(offs_t offset, uint8_t data);
150 	void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
151 	void set_ea(int ea);
152 	void mario_io_map(address_map &map);
153 	void mario_map(address_map &map);
154 	void mario_sound_io_map(address_map &map);
155 	void mario_sound_map(address_map &map);
156 	void masao_map(address_map &map);
157 	void masao_sound_map(address_map &map);
158 };
159 
160 #endif // MAME_INCLUDES_MARIO_H
161