1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 #ifndef MAME_INCLUDES_COSMICOS_H
4 #define MAME_INCLUDES_COSMICOS_H
5 
6 #pragma once
7 
8 #include "cpu/cosmac/cosmac.h"
9 #include "imagedev/cassette.h"
10 #include "imagedev/snapquik.h"
11 #include "machine/ram.h"
12 #include "machine/rescap.h"
13 #include "machine/timer.h"
14 #include "sound/cdp1864.h"
15 #include "sound/spkrdev.h"
16 #include "video/dm9368.h"
17 
18 #define CDP1802_TAG     "ic19"
19 #define CDP1864_TAG     "ic3"
20 #define DM9368_TAG      "ic10"
21 #define SCREEN_TAG      "screen"
22 
23 enum
24 {
25 	LED_RUN = 0,
26 	LED_LOAD,
27 	LED_PAUSE,
28 	LED_RESET,
29 	LED_D7,
30 	LED_D6,
31 	LED_D5,
32 	LED_D4,
33 	LED_D3,
34 	LED_D2,
35 	LED_D1,
36 	LED_D0,
37 	LED_Q,
38 	LED_CASSETTE
39 };
40 
41 class cosmicos_state : public driver_device
42 {
43 public:
cosmicos_state(const machine_config & mconfig,device_type type,const char * tag)44 	cosmicos_state(const machine_config &mconfig, device_type type, const char *tag) :
45 		driver_device(mconfig, type, tag),
46 		m_digit(0),
47 		m_maincpu(*this, CDP1802_TAG),
48 		m_cti(*this, CDP1864_TAG),
49 		m_led(*this, DM9368_TAG),
50 		m_cassette(*this, "cassette"),
51 		m_speaker(*this, "speaker"),
52 		m_ram(*this, RAM_TAG),
53 		m_rom(*this, CDP1802_TAG),
54 		m_key_row(*this, {"Y1", "Y2", "Y3", "Y4"}),
55 		m_io_data(*this, "DATA"),
56 		m_special(*this, "SPECIAL"),
57 		m_buttons(*this, "BUTTONS"),
58 		m_digits(*this, "digit%u", 0U),
59 		m_leds(*this, "led%u", 0U)
60 	{ }
61 
62 	uint8_t read(offs_t offset);
63 	void write(offs_t offset, uint8_t data);
64 	uint8_t video_off_r();
65 	uint8_t video_on_r();
66 	void audio_latch_w(uint8_t data);
67 	uint8_t hex_keyboard_r();
68 	void hex_keylatch_w(uint8_t data);
69 	uint8_t reset_counter_r();
70 	void segment_w(uint8_t data);
71 	uint8_t data_r();
72 	void display_w(uint8_t data);
73 	DECLARE_WRITE_LINE_MEMBER( dmaout_w );
74 	DECLARE_WRITE_LINE_MEMBER( efx_w );
75 	DECLARE_READ_LINE_MEMBER( wait_r );
76 	DECLARE_READ_LINE_MEMBER( clear_r );
77 	DECLARE_READ_LINE_MEMBER( ef1_r );
78 	DECLARE_READ_LINE_MEMBER( ef2_r );
79 	DECLARE_READ_LINE_MEMBER( ef3_r );
80 	DECLARE_READ_LINE_MEMBER( ef4_r );
81 	DECLARE_WRITE_LINE_MEMBER( q_w );
82 	uint8_t dma_r();
83 	void sc_w(uint8_t data);
84 	DECLARE_INPUT_CHANGED_MEMBER( data );
85 	DECLARE_INPUT_CHANGED_MEMBER( enter );
86 	DECLARE_INPUT_CHANGED_MEMBER( single_step );
87 	DECLARE_INPUT_CHANGED_MEMBER( run );
88 	DECLARE_INPUT_CHANGED_MEMBER( load );
89 	DECLARE_INPUT_CHANGED_MEMBER( cosmicos_pause );
90 	DECLARE_INPUT_CHANGED_MEMBER( reset );
91 	DECLARE_INPUT_CHANGED_MEMBER( clear_data );
92 	DECLARE_INPUT_CHANGED_MEMBER( memory_protect );
93 	DECLARE_INPUT_CHANGED_MEMBER( memory_disable );
94 
95 	DECLARE_QUICKLOAD_LOAD_MEMBER(quickload_cb);
96 	void init_cosmicos();
97 	TIMER_DEVICE_CALLBACK_MEMBER(digit_tick);
98 	TIMER_DEVICE_CALLBACK_MEMBER(int_tick);
99 	void cosmicos(machine_config &config);
100 	void cosmicos_io(address_map &map);
101 	void cosmicos_mem(address_map &map);
102 
103 private:
104 	void set_cdp1802_mode(int mode);
105 	void clear_input_data();
106 
107 	/* CPU state */
108 	int m_wait;
109 	int m_clear;
110 	int m_sc1;
111 
112 	/* memory state */
113 	uint8_t m_data;
114 	int m_boot;
115 	int m_ram_protect;
116 	int m_ram_disable;
117 
118 	/* keyboard state */
119 	uint8_t m_keylatch;
120 
121 	/* display state */
122 	uint8_t m_segment;
123 	int m_digit;
124 	int m_counter;
125 	int m_q;
126 	int m_dmaout;
127 	int m_efx;
128 	int m_video_on;
129 
130 	virtual void machine_start() override;
131 	virtual void machine_reset() override;
132 	required_device<cosmac_device> m_maincpu;
133 	required_device<cdp1864_device> m_cti;
134 	required_device<dm9368_device> m_led;
135 	required_device<cassette_image_device> m_cassette;
136 	required_device<speaker_sound_device> m_speaker;
137 	required_device<ram_device> m_ram;
138 	required_memory_region m_rom;
139 	required_ioport_array<4> m_key_row;
140 	required_ioport m_io_data;
141 	required_ioport m_special;
142 	required_ioport m_buttons;
143 	output_finder<10> m_digits;
144 	output_finder<14> m_leds;
145 };
146 
147 #endif // MAME_INCLUDES_COSMICOS_H
148