1 // license:BSD-3-Clause
2 // copyright-holders:Stefan Jokisch
3 /*************************************************************************
4 
5     Atari Liberator hardware
6 
7 *************************************************************************/
8 #ifndef MAME_INCLUDES_LIBERATR_H
9 #define MAME_INCLUDES_LIBERATR_H
10 
11 #pragma once
12 
13 #include "cpu/m6502/m6502.h"
14 #include "machine/74259.h"
15 #include "machine/er2055.h"
16 #include "machine/watchdog.h"
17 #include "sound/pokey.h"
18 #include "screen.h"
19 
20 class liberatr_state : public driver_device
21 {
22 public:
liberatr_state(const machine_config & mconfig,device_type type,const char * tag)23 	liberatr_state(const machine_config &mconfig, device_type type, const char *tag)
24 		: driver_device(mconfig, type, tag)
25 		, m_earom(*this, "earom")
26 		, m_earom_data(0)
27 		, m_earom_control(0)
28 		, m_outlatch(*this, "outlatch")
29 		, m_screen(*this, "screen")
30 		, m_base_ram(*this, "base_ram")
31 		, m_planet_frame(*this, "planet_frame")
32 		, m_xcoord(*this, "xcoord")
33 		, m_ycoord(*this, "ycoord")
34 		, m_bitmapram(*this, "bitmapram")
35 		, m_colorram(*this, "colorram")
36 	{ }
37 
38 	void liberat2(machine_config &config);
39 	void liberatr(machine_config &config);
40 
41 private:
42 	virtual void machine_start() override;
43 	virtual void machine_reset() override;
44 	virtual void video_start() override;
45 
46 	void output_latch_w(offs_t offset, uint8_t data);
47 	DECLARE_WRITE_LINE_MEMBER(coin_counter_left_w);
48 	DECLARE_WRITE_LINE_MEMBER(coin_counter_right_w);
49 
50 	DECLARE_WRITE_LINE_MEMBER(trackball_reset_w);
51 	uint8_t port0_r();
52 
53 	void bitmap_w(offs_t offset, uint8_t data);
54 	uint8_t bitmap_xy_r();
55 	void bitmap_xy_w(uint8_t data);
56 
57 	uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
58 
59 	// early raster EAROM interface
60 	uint8_t earom_r();
61 	void earom_w(offs_t offset, uint8_t data);
62 	void earom_control_w(uint8_t data);
63 
64 	void liberat2_map(address_map &map);
65 	void liberatr_map(address_map &map);
66 
67 	// The following structure describes the (up to 32) line segments
68 	// that make up one horizontal line (latitude) for one display frame of the planet.
69 	// Note: this and the following structure is only used to collect the
70 	// data before it is packed for actual use.
71 	struct planet_frame_line
72 	{
73 		uint8_t segment_count;    // the number of segments on this line
74 		uint8_t max_x;            // the maximum value of x_array for this line
75 		uint8_t color_array[32];  // the color values
76 		uint8_t x_array[32];      // and maximum x values for each segment
77 	};
78 
79 	// The following structure describes the lines (latitudes)
80 	// that make up one complete display frame of the planet.
81 	// Note: this and the previous structure is only used to collect the
82 	// data before it is packed for actual use.
83 	struct planet_frame
84 	{
85 		planet_frame_line lines[0x80];
86 	};
87 
88 	// The following structure collects the 256 frames of the
89 	// planet (one per value of longitude).
90 	// The data is packed segment_count,segment_start,color,length,color,length,...  then
91 	//                    segment_count,segment_start,color,length,color,length...  for the next line, etc
92 	// for the 128 lines.
93 	struct planet
94 	{
95 		uint8_t *frames[256];
96 	};
97 
98 	void init_planet(planet &liberatr_planet, uint8_t *planet_rom);
99 	void get_pens(pen_t *pens);
100 	void draw_planet(bitmap_rgb32 &bitmap, pen_t *pens);
101 	void draw_bitmap(bitmap_rgb32 &bitmap, pen_t *pens);
102 
103 	// vector and early raster EAROM interface
104 	required_device<er2055_device> m_earom;
105 	uint8_t               m_earom_data;
106 	uint8_t               m_earom_control;
107 
108 	required_device<ls259_device> m_outlatch;
109 
110 	required_device<screen_device> m_screen;
111 	required_shared_ptr<uint8_t> m_base_ram;
112 	required_shared_ptr<uint8_t> m_planet_frame;
113 	required_shared_ptr<uint8_t> m_xcoord;
114 	required_shared_ptr<uint8_t> m_ycoord;
115 	required_shared_ptr<uint8_t> m_bitmapram;
116 	required_shared_ptr<uint8_t> m_colorram;
117 
118 	uint8_t       m_trackball_offset;
119 	uint8_t       m_ctrld;
120 	uint8_t       m_videoram[0x10000];
121 
122 	bool m_planet_select;
123 
124 	// The following array collects the 2 different planet
125 	// descriptions, which are selected by planetbit
126 	planet m_planets[2];
127 };
128 
129 #endif // MAME_INCLUDES_LIBERATR_H
130