1 // license:BSD-3-Clause
2 // copyright-holders:Paul Leaman, Couriersud
3 /***************************************************************************
4 
5     1942
6 
7 ***************************************************************************/
8 #ifndef MAME_INCLUDES_1942_H
9 #define MAME_INCLUDES_1942_H
10 
11 #pragma once
12 
13 #include "machine/gen_latch.h"
14 #include "machine/timer.h"
15 #include "emupal.h"
16 #include "tilemap.h"
17 #include "screen.h"
18 
19 class _1942_state : public driver_device
20 {
21 public:
_1942_state(const machine_config & mconfig,device_type type,const char * tag)22 	_1942_state(const machine_config &mconfig, device_type type, const char *tag)
23 		: driver_device(mconfig, type, tag)
24 		, m_screen(*this, "screen")
25 		, m_spriteram(*this, "spriteram")
26 		, m_fg_videoram(*this, "fg_videoram")
27 		, m_bg_videoram(*this, "bg_videoram")
28 		, m_audiocpu(*this, "audiocpu")
29 		, m_maincpu(*this, "maincpu")
30 		, m_gfxdecode(*this, "gfxdecode")
31 		, m_palette(*this, "palette")
32 		, m_soundlatch(*this, "soundlatch")
33 	{ }
34 
35 	void driver_init() override;
36 
37 	TILE_GET_INFO_MEMBER(get_fg_tile_info);
38 	TILE_GET_INFO_MEMBER(get_bg_tile_info);
39 
40 	void _1942(machine_config &config);
41 
42 protected:
43 	void machine_start() override;
44 	void machine_reset() override;
45 	void video_start() override;
46 
47 	void _1942_map(address_map &map);
48 	void sound_map(address_map &map);
49 
50 	void _1942_bankswitch_w(uint8_t data);
51 	void _1942_fgvideoram_w(offs_t offset, uint8_t data);
52 	void _1942_bgvideoram_w(offs_t offset, uint8_t data);
53 	void _1942_palette_bank_w(uint8_t data);
54 	void _1942_scroll_w(offs_t offset, uint8_t data);
55 	void _1942_c804_w(uint8_t data);
56 	void _1942_palette(palette_device &palette) const;
57 	TIMER_DEVICE_CALLBACK_MEMBER(_1942_scanline);
58 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
59 	virtual void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
60 
61 	required_device<screen_device> m_screen;
62 
63 	/* memory pointers */
64 	required_shared_ptr<uint8_t> m_spriteram;
65 	required_shared_ptr<uint8_t> m_fg_videoram;
66 	required_shared_ptr<uint8_t> m_bg_videoram;
67 
68 	required_device<cpu_device> m_audiocpu;
69 	required_device<cpu_device> m_maincpu;
70 	required_device<gfxdecode_device> m_gfxdecode;
71 	required_device<palette_device> m_palette;
72 	required_device<generic_latch_8_device> m_soundlatch;
73 
74 	/* video-related */
75 	tilemap_t *m_fg_tilemap;
76 	tilemap_t *m_bg_tilemap;
77 	int m_palette_bank;
78 	uint8_t m_scroll[2];
79 	void create_palette(palette_device &palette) const;
80 	uint8_t m_sprite_bufs[2][512];
81 };
82 
83 class _1942p_state : public _1942_state
84 {
85 public:
_1942p_state(const machine_config & mconfig,device_type type,const char * tag)86 	_1942p_state(const machine_config &mconfig, device_type type, const char *tag)
87 		: _1942_state(mconfig, type, tag)
88 		, m_protopal(*this, "protopal")
89 	{ }
90 
91 	void _1942p(machine_config &config);
92 
93 protected:
94 	void video_start() override;
95 
96 	void _1942p_map(address_map &map);
97 	void _1942p_sound_io(address_map &map);
98 	void _1942p_sound_map(address_map &map);
99 
100 	void _1942p_f600_w(uint8_t data);
101 	void _1942p_palette_w(offs_t offset, uint8_t data);
102 
103 	void _1942p_palette(palette_device &palette) const;
104 
105 	void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect) override;
106 
107 	required_shared_ptr<uint8_t> m_protopal;
108 };
109 
110 #endif // MAME_INCLUDES_1942_H
111