1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 #pragma once
4 
5 #ifndef MAME_INCLUDES_VIP_H
6 #define MAME_INCLUDES_VIP_H
7 
8 #include "bus/vip/byteio.h"
9 #include "bus/vip/exp.h"
10 #include "cpu/cosmac/cosmac.h"
11 #include "imagedev/cassette.h"
12 #include "imagedev/snapquik.h"
13 #include "machine/ram.h"
14 #include "sound/discrete.h"
15 #include "video/cdp1861.h"
16 
17 #define SCREEN_TAG      "screen"
18 #define CDP1802_TAG     "u1"
19 #define CDP1861_TAG     "u2"
20 #define DISCRETE_TAG    "discrete"
21 
22 
23 class vip_state : public driver_device
24 {
25 public:
vip_state(const machine_config & mconfig,device_type type,const char * tag)26 	vip_state(const machine_config &mconfig, device_type type, const char *tag)
27 		: driver_device(mconfig, type, tag)
28 		, m_maincpu(*this, CDP1802_TAG)
29 		, m_vdc(*this, CDP1861_TAG)
30 		, m_cassette(*this, "cassette")
31 		, m_beeper(*this, DISCRETE_TAG)
32 		, m_byteio(*this, VIP_BYTEIO_PORT_TAG)
33 		, m_exp(*this, VIP_EXPANSION_SLOT_TAG)
34 		, m_ram(*this, RAM_TAG)
35 		, m_rom(*this, CDP1802_TAG)
36 		, m_chip8(*this, "chip8")
37 		, m_chip8x(*this, "chip8x")
38 		, m_run(*this, "RUN")
39 		, m_keypad(*this, "KEYPAD")
40 		, m_io_beeper(*this, "BEEPER")
41 		, m_8000(1)
42 		, m_vdc_int(CLEAR_LINE)
43 		, m_vdc_dma_out(CLEAR_LINE)
44 		, m_vdc_ef1(CLEAR_LINE)
45 		, m_exp_int(CLEAR_LINE)
46 		, m_exp_dma_out(CLEAR_LINE)
47 		, m_exp_dma_in(CLEAR_LINE)
48 		, m_byteio_ef3(CLEAR_LINE)
49 		, m_byteio_ef4(CLEAR_LINE)
50 		, m_exp_ef1(CLEAR_LINE)
51 		, m_exp_ef3(CLEAR_LINE)
52 		, m_exp_ef4(CLEAR_LINE)
53 		, m_leds(*this, "led%u", 0U)
54 	{ }
55 
56 	void vp111(machine_config &config);
57 	void vip(machine_config &config);
58 
59 	DECLARE_INPUT_CHANGED_MEMBER(reset_w);
60 	DECLARE_INPUT_CHANGED_MEMBER(beeper_w);
61 
62 private:
63 	uint32_t screen_update(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect);
64 
65 	void update_interrupts();
66 
67 	uint8_t read(offs_t offset);
68 	void write(offs_t offset, uint8_t data);
69 	uint8_t io_r(offs_t offset);
70 	void io_w(offs_t offset, uint8_t data);
71 
72 	DECLARE_READ_LINE_MEMBER(clear_r);
73 	DECLARE_READ_LINE_MEMBER(ef1_r);
74 	DECLARE_READ_LINE_MEMBER(ef2_r);
75 	DECLARE_READ_LINE_MEMBER(ef3_r);
76 	DECLARE_READ_LINE_MEMBER(ef4_r);
77 	DECLARE_WRITE_LINE_MEMBER(q_w);
78 
79 	DECLARE_WRITE_LINE_MEMBER(vdc_int_w);
80 	DECLARE_WRITE_LINE_MEMBER(vdc_dma_out_w);
81 	DECLARE_WRITE_LINE_MEMBER(vdc_ef1_w);
82 
83 	DECLARE_WRITE_LINE_MEMBER(byteio_inst_w);
84 
85 	DECLARE_WRITE_LINE_MEMBER(exp_int_w );
86 	DECLARE_WRITE_LINE_MEMBER(exp_dma_out_w);
87 	DECLARE_WRITE_LINE_MEMBER(exp_dma_in_w);
88 
89 	DECLARE_QUICKLOAD_LOAD_MEMBER(quickload_cb);
90 
91 	void vip_io(address_map &map);
92 	void vip_mem(address_map &map);
93 
94 	virtual void machine_start() override;
95 	virtual void machine_reset() override;
96 
97 	required_device<cosmac_device> m_maincpu;
98 	required_device<cdp1861_device> m_vdc;
99 	required_device<cassette_image_device> m_cassette;
100 	required_device<discrete_sound_device> m_beeper;
101 	required_device<vip_byteio_port_device> m_byteio;
102 	required_device<vip_expansion_slot_device> m_exp;
103 	required_device<ram_device> m_ram;
104 	required_memory_region m_rom;
105 	required_memory_region m_chip8;
106 	required_memory_region m_chip8x;
107 	required_ioport m_run;
108 	required_ioport m_keypad;
109 	required_ioport m_io_beeper;
110 
111 	// memory state
112 	int m_8000;
113 
114 	// interrupt state
115 	int m_vdc_int;
116 	int m_vdc_dma_out;
117 	int m_vdc_ef1;
118 	int m_exp_int;
119 	int m_exp_dma_out;
120 	int m_exp_dma_in;
121 	int m_byteio_ef3;
122 	int m_byteio_ef4;
123 	int m_exp_ef1;
124 	int m_exp_ef3;
125 	int m_exp_ef4;
126 
127 	// keyboard state
128 	int m_keylatch;
129 
130 	// expansion state
131 	uint8_t m_byteio_data;
132 	output_finder<3> m_leds;
133 };
134 
135 #endif
136