1 // license:GPL-2.0+
2 // copyright-holders:Juergen Buchmueller, Krzysztof Strzecha, Robbbert
3 /*****************************************************************************
4  *
5  * ZX-80/ZX-81 and derivatives
6  *
7  ****************************************************************************/
8 
9 #ifndef MAME_INCLUDES_ZX_H
10 #define MAME_INCLUDES_ZX_H
11 
12 #pragma once
13 
14 #include "cpu/z80/z80.h"
15 #include "imagedev/cassette.h"
16 #include "machine/ram.h"
17 #include "sound/spkrdev.h"
18 
19 #include "emupal.h"
20 #include "screen.h"
21 
22 #include "formats/tzx_cas.h"
23 #include "formats/zx81_p.h"
24 
25 
26 class zx_state : public driver_device
27 {
28 public:
zx_state(const machine_config & mconfig,device_type type,const char * tag)29 	zx_state(const machine_config &mconfig, device_type type, const char *tag) :
30 		driver_device(mconfig, type, tag),
31 		m_maincpu(*this, "maincpu"),
32 		m_ram(*this, RAM_TAG),
33 		m_cassette(*this, "cassette"),
34 		m_softlist(*this, "cass_list"),
35 		m_speaker(*this, "speaker"),
36 		m_region_maincpu(*this, "maincpu"),
37 		m_region_gfx1(*this, "gfx1"),
38 		m_io_row0(*this, "ROW0"),
39 		m_io_row1(*this, "ROW1"),
40 		m_io_row2(*this, "ROW2"),
41 		m_io_row3(*this, "ROW3"),
42 		m_io_row4(*this, "ROW4"),
43 		m_io_row5(*this, "ROW5"),
44 		m_io_row6(*this, "ROW6"),
45 		m_io_row7(*this, "ROW7"),
46 		m_io_config(*this, "CONFIG"),
47 		m_screen(*this, "screen")
48 	{ }
49 
50 	void zx81(machine_config &config);
51 	void zx81_spk(machine_config &config);
52 	void ts1000(machine_config &config);
53 	void pc8300(machine_config &config);
54 	void pow3000(machine_config &config);
55 	void ts1500(machine_config &config);
56 	void zx80(machine_config &config);
57 
58 	void init_zx();
59 
60 private:
61 	uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
62 
63 	uint8_t ula_high_r(offs_t offset);
64 	uint8_t ula_low_r(offs_t offset);
65 	void refresh_w(offs_t offset, uint8_t data);
66 	uint8_t zx80_io_r(offs_t offset);
67 	uint8_t zx81_io_r(offs_t offset);
68 	uint8_t pc8300_io_r(offs_t offset);
69 	uint8_t pow3000_io_r(offs_t offset);
70 	void zx80_io_w(offs_t offset, uint8_t data);
71 	void zx81_io_w(offs_t offset, uint8_t data);
72 
73 	virtual void machine_reset() override;
74 	virtual void video_start() override;
75 	void zx_tape_input();
76 	void zx_ula_hsync();
77 
78 	void pc8300_io_map(address_map &map);
79 	void pow3000_io_map(address_map &map);
80 	void ula_map(address_map &map);
81 	void zx80_io_map(address_map &map);
82 	void zx80_map(address_map &map);
83 	void zx81_io_map(address_map &map);
84 	void zx81_map(address_map &map);
85 
86 	enum
87 	{
88 		TIMER_TAPE_INPUT,
89 		TIMER_ULA_HSYNC
90 	};
91 
92 	required_device<z80_device> m_maincpu;
93 	required_device<ram_device> m_ram;
94 	required_device<cassette_image_device> m_cassette;
95 	required_device<software_list_device> m_softlist;
96 	optional_device<speaker_sound_device> m_speaker;
97 	required_memory_region m_region_maincpu;
98 	optional_memory_region m_region_gfx1;
99 	required_ioport m_io_row0;
100 	required_ioport m_io_row1;
101 	required_ioport m_io_row2;
102 	required_ioport m_io_row3;
103 	required_ioport m_io_row4;
104 	required_ioport m_io_row5;
105 	required_ioport m_io_row6;
106 	required_ioport m_io_row7;
107 	optional_ioport m_io_config;
108 	required_device<screen_device> m_screen;
109 
110 	address_space *m_program;
111 	emu_timer *m_tape_input, *m_ula_hsync;
112 
113 	bool m_vsync_active, m_hsync_active, m_nmi_on, m_nmi_generator_active;
114 	uint64_t m_base_vsync_clock, m_vsync_start_time;
115 	uint32_t m_ypos;
116 
117 	uint8_t m_prev_refresh;
118 	uint8_t m_speaker_state;
119 
120 	std::unique_ptr<bitmap_ind16> m_bitmap_render;
121 	std::unique_ptr<bitmap_ind16> m_bitmap_buffer;
122 
123 	uint16_t m_ula_char_buffer;
124 	double m_cassette_cur_level;
125 
126 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
127 
128 	void drop_sync();
129 	void recalc_hsync();
130 };
131 
132 #endif // MAME_INCLUDES_ZX_H
133