1 // license:BSD-3-Clause
2 // copyright-holders:Aaron Giles
3 /*************************************************************************
4 
5     Atari GT hardware
6 
7 *************************************************************************/
8 
9 #include "audio/cage.h"
10 #include "machine/adc0808.h"
11 #include "machine/atarigen.h"
12 #include "machine/timer.h"
13 #include "video/atarirle.h"
14 #include "emupal.h"
15 #include "tilemap.h"
16 
17 #define CRAM_ENTRIES        0x4000
18 #define TRAM_ENTRIES        0x4000
19 #define MRAM_ENTRIES        0x8000
20 
21 #define ADDRSEQ_COUNT   4
22 
23 class atarigt_state : public atarigen_state
24 {
25 public:
atarigt_state(const machine_config & mconfig,device_type type,const char * tag)26 	atarigt_state(const machine_config &mconfig, device_type type, const char *tag) :
27 		atarigen_state(mconfig, type, tag),
28 		m_palette(*this, "palette"),
29 		m_colorram(*this, "colorram", 32),
30 		m_adc(*this, "adc"),
31 		m_playfield_tilemap(*this, "playfield"),
32 		m_alpha_tilemap(*this, "alpha"),
33 		m_rle(*this, "rle"),
34 		m_service_io(*this, "SERVICE"),
35 		m_coin_io(*this, "COIN"),
36 		m_fake_io(*this, "FAKE"),
37 		m_mo_command(*this, "mo_command"),
38 		m_cage(*this, "cage")
39 	{ }
40 
41 	bool           m_is_primrage;
42 	required_device<palette_device> m_palette;
43 	required_shared_ptr<uint16_t> m_colorram;
44 
45 	optional_device<adc0808_device> m_adc;
46 
47 	required_device<tilemap_device> m_playfield_tilemap;
48 	required_device<tilemap_device> m_alpha_tilemap;
49 	required_device<atari_rle_objects_device> m_rle;
50 
51 	optional_ioport m_service_io;
52 	optional_ioport m_coin_io;
53 	optional_ioport m_fake_io;
54 
55 	bool            m_scanline_int_state;
56 	bool            m_video_int_state;
57 
58 	bitmap_ind16    m_pf_bitmap;
59 	bitmap_ind16    m_an_bitmap;
60 
61 	uint8_t           m_playfield_tile_bank;
62 	uint8_t           m_playfield_color_bank;
63 	uint16_t          m_playfield_xscroll;
64 	uint16_t          m_playfield_yscroll;
65 
66 	uint32_t          m_tram_checksum;
67 
68 	required_shared_ptr<uint32_t> m_mo_command;
69 	optional_device<atari_cage_device> m_cage;
70 
71 	void            (atarigt_state::*m_protection_w)(address_space &space, offs_t offset, uint16_t data);
72 	void            (atarigt_state::*m_protection_r)(address_space &space, offs_t offset, uint16_t *data);
73 
74 	bool            m_ignore_writes;
75 	offs_t          m_protaddr[ADDRSEQ_COUNT];
76 	uint8_t           m_protmode;
77 	uint16_t          m_protresult;
78 	std::unique_ptr<uint8_t[]> m_protdata;
79 
80 	INTERRUPT_GEN_MEMBER(scanline_int_gen);
81 	DECLARE_WRITE_LINE_MEMBER(video_int_write_line);
82 	void scanline_int_ack_w(uint32_t data = 0);
83 	void video_int_ack_w(uint32_t data = 0);
84 	TIMER_DEVICE_CALLBACK_MEMBER(scanline_update);
85 	uint32_t special_port2_r();
86 	uint32_t special_port3_r();
87 	uint8_t analog_port_r(offs_t offset);
88 	void latch_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
89 	void mo_command_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
90 	void led_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
91 	uint32_t sound_data_r(offs_t offset, uint32_t mem_mask = ~0);
92 	void sound_data_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
93 	uint32_t colorram_protection_r(address_space &space, offs_t offset, uint32_t mem_mask = ~0);
94 	void colorram_protection_w(address_space &space, offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
95 	void tmek_pf_w(offs_t offset, uint32_t data, uint32_t mem_mask = ~0);
96 
97 	void cage_irq_callback(uint8_t data);
98 
99 	void atarigt_colorram_w(offs_t address, uint16_t data, uint16_t mem_mask);
100 	uint16_t atarigt_colorram_r(offs_t address);
101 	void init_primrage();
102 	void init_tmek();
103 	TILE_GET_INFO_MEMBER(get_alpha_tile_info);
104 	TILE_GET_INFO_MEMBER(get_playfield_tile_info);
105 	TILEMAP_MAPPER_MEMBER(atarigt_playfield_scan);
106 	virtual void machine_start() override;
107 	DECLARE_VIDEO_START(atarigt);
108 	uint32_t screen_update_atarigt(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
109 	void atarigt(machine_config &config);
110 	void tmek(machine_config &config);
111 	void primrage20(machine_config &config);
112 	void primrage(machine_config &config);
113 	void main_map(address_map &map);
114 private:
115 	void tmek_update_mode(offs_t offset);
116 	void tmek_protection_w(address_space &space, offs_t offset, uint16_t data);
117 	void tmek_protection_r(address_space &space, offs_t offset, uint16_t *data);
118 	void primrage_update_mode(offs_t offset);
119 	void primrage_protection_w(address_space &space, offs_t offset, uint16_t data);
120 	void primrage_protection_r(address_space &space, offs_t offset, uint16_t *data);
121 	void compute_fake_pots(int *pots);
122 };
123