1 // license:BSD-3-Clause
2 // copyright-holders:Phil Stroffolino, Manuel Abadia
3 /*************************************************************************
4 
5     Combat School
6 
7 *************************************************************************/
8 #ifndef MAME_INCLUDES_COMBATSC_H
9 #define MAME_INCLUDES_COMBATSC_H
10 
11 #pragma once
12 
13 #include "machine/gen_latch.h"
14 #include "sound/upd7759.h"
15 #include "sound/msm5205.h"
16 #include "video/k007121.h"
17 #include "emupal.h"
18 #include "screen.h"
19 #include "tilemap.h"
20 
21 class combatsc_state : public driver_device
22 {
23 public:
combatsc_state(const machine_config & mconfig,device_type type,const char * tag)24 	combatsc_state(const machine_config &mconfig, device_type type, const char *tag) :
25 		driver_device(mconfig, type, tag),
26 		m_maincpu(*this, "maincpu"),
27 		m_audiocpu(*this, "audiocpu"),
28 		m_k007121_1(*this, "k007121_1"),
29 		m_k007121_2(*this, "k007121_2"),
30 		m_upd7759(*this, "upd"),
31 		m_msm(*this, "msm"),
32 		m_screen(*this, "screen"),
33 		m_gfxdecode(*this, "gfxdecode"),
34 		m_palette(*this, "palette"),
35 		m_soundlatch(*this, "soundlatch"),
36 		m_track_ports(*this, {"TRACK0_Y", "TRACK0_X", "TRACK1_Y", "TRACK1_X"})
37 	{
38 	}
39 
40 	/* memory pointers */
41 	uint8_t *    m_videoram;
42 	uint8_t *    m_scrollram;
43 	uint8_t *    m_io_ram;
44 	std::unique_ptr<uint8_t[]>    m_spriteram[2];
45 
46 	/* video-related */
47 	tilemap_t *m_bg_tilemap[2];
48 	tilemap_t *m_textlayer;
49 	uint8_t m_scrollram0[0x40];
50 	uint8_t m_scrollram1[0x40];
51 	int m_priority;
52 
53 	int  m_vreg;
54 	int  m_bank_select; /* 0x00..0x1f */
55 	int  m_video_circuit; /* 0 or 1 */
56 	bool m_textflip;
57 	uint8_t *m_page[2];
58 
59 	/* misc */
60 	uint8_t m_pos[4];
61 	uint8_t m_sign[4];
62 	int m_prot[2];
63 	int m_boost;
64 	emu_timer *m_interleave_timer;
65 
66 
67 	/* devices */
68 	required_device<cpu_device> m_maincpu;
69 	required_device<cpu_device> m_audiocpu;
70 	optional_device<k007121_device> m_k007121_1;
71 	optional_device<k007121_device> m_k007121_2;
72 	optional_device<upd7759_device> m_upd7759;
73 	optional_device<msm5205_device> m_msm;
74 	required_device<screen_device> m_screen;
75 	required_device<gfxdecode_device> m_gfxdecode;
76 	required_device<palette_device> m_palette;
77 	required_device<generic_latch_8_device> m_soundlatch;
78 
79 	optional_ioport_array<4> m_track_ports;
80 
81 	void combatsc_vreg_w(uint8_t data);
82 	uint8_t combatscb_io_r(offs_t offset);
83 	void combatscb_priority_w(uint8_t data);
84 	void combatsc_bankselect_w(uint8_t data);
85 	void combatscb_io_w(offs_t offset, uint8_t data);
86 	void combatscb_bankselect_w(address_space &space, uint8_t data);
87 	void combatsc_coin_counter_w(uint8_t data);
88 	uint8_t trackball_r(offs_t offset);
89 	void protection_w(offs_t offset, uint8_t data);
90 	uint8_t protection_r(offs_t offset);
91 	uint8_t unk_r();
92 	void protection_clock_w(uint8_t data);
93 	void combatsc_sh_irqtrigger_w(uint8_t data);
94 	uint8_t combatsc_video_r(offs_t offset);
95 	void combatsc_video_w(offs_t offset, uint8_t data);
96 	void combatsc_pf_control_w(offs_t offset, uint8_t data);
97 	uint8_t combatsc_scrollram_r(offs_t offset);
98 	void combatsc_scrollram_w(offs_t offset, uint8_t data);
99 	uint8_t combatsc_busy_r();
100 	void combatsc_play_w(uint8_t data);
101 	void combatsc_voice_reset_w(uint8_t data);
102 	void combatsc_portA_w(uint8_t data);
103 	void combatscb_msm_w(uint8_t data);
104 	void combatscb_sound_irq_ack(uint8_t data);
105 	void init_combatsc();
106 	TILE_GET_INFO_MEMBER(get_tile_info0);
107 	TILE_GET_INFO_MEMBER(get_tile_info1);
108 	TILE_GET_INFO_MEMBER(get_text_info);
109 	TILE_GET_INFO_MEMBER(get_tile_info0_bootleg);
110 	TILE_GET_INFO_MEMBER(get_tile_info1_bootleg);
111 	TILE_GET_INFO_MEMBER(get_text_info_bootleg);
112 	virtual void machine_reset() override;
113 	DECLARE_MACHINE_START(combatsc);
114 	DECLARE_VIDEO_START(combatsc);
115 	void combatsc_palette(palette_device &palette) const;
116 	DECLARE_MACHINE_START(combatscb);
117 	DECLARE_VIDEO_START(combatscb);
118 	void combatscb_palette(palette_device &palette) const;
119 	uint32_t screen_update_combatsc(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
120 	uint32_t screen_update_combatscb(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
121 	void draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect, const uint8_t *source, int circuit, bitmap_ind8 &priority_bitmap, uint32_t pri_mask );
122 	void bootleg_draw_sprites( bitmap_ind16 &bitmap, const rectangle &cliprect, const uint8_t *source, int circuit );
123 	void combatscb(machine_config &config);
124 	void combatsc(machine_config &config);
125 	void combatsc_map(address_map &map);
126 	void combatsc_sound_map(address_map &map);
127 	void combatscb_map(address_map &map);
128 	void combatscb_sound_map(address_map &map);
129 };
130 
131 #endif // MAME_INCLUDES_COMBATSC_H
132