summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/includes/kc.h
blob: f975a6301ad9e57940118e4a44461bdf6613ec35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
// license:GPL-2.0+
// copyright-holders:Kevin Thacker,Sandro Ronco
/*****************************************************************************
 *
 * includes/kc.h
 *
 ****************************************************************************/

#ifndef MAME_INCLUDES_KC_H
#define MAME_INCLUDES_KC_H

/* Devices */
#include "imagedev/cassette.h"
#include "machine/ram.h"
#include "machine/timer.h"

// Components
#include "cpu/z80/z80.h"
#include "machine/z80daisy.h"
#include "machine/z80ctc.h"
#include "machine/z80pio.h"
#include "machine/ram.h"
#include "machine/kc_keyb.h"
#include "machine/rescap.h"
#include "sound/spkrdev.h"
#include "sound/wave.h"
#include "screen.h"

// Devices
#include "imagedev/cassette.h"
#include "imagedev/snapquik.h"

// Expansions
#include "bus/kc/kc.h"
#include "bus/kc/ram.h"
#include "bus/kc/rom.h"
#include "bus/kc/d002.h"
#include "bus/kc/d004.h"

// Formats
#include "formats/kc_cas.h"

// from service manual
#define KC85_3_CLOCK 1751938
#define KC85_4_CLOCK 1773447

#define KC85_4_SCREEN_PIXEL_RAM_SIZE 0x04000
#define KC85_4_SCREEN_COLOUR_RAM_SIZE 0x04000

#define KC85_PALETTE_SIZE 24
#define KC85_SCREEN_WIDTH 320
#define KC85_SCREEN_HEIGHT 256

// cassette input polling frequency
#define KC_CASSETTE_TIMER_FREQUENCY attotime::from_hz(44100)

class kc_state : public driver_device
{
public:
	kc_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag)
		, m_maincpu(*this, "maincpu")
		, m_z80pio(*this, "z80pio")
		, m_z80ctc(*this, "z80ctc")
		, m_ram(*this, RAM_TAG)
		, m_speaker(*this, "speaker")
		, m_cassette(*this, "cassette")
		, m_screen(*this, "screen")
		, m_expansions(*this, {"m8", "mc", "exp"})
	{ }

	required_device<cpu_device> m_maincpu;
	required_device<z80pio_device> m_z80pio;
	required_device<z80ctc_device> m_z80ctc;
	required_device<ram_device> m_ram;
	required_device<speaker_sound_device> m_speaker;
	required_device<cassette_image_device> m_cassette;
	required_device<screen_device> m_screen;
	required_device_array<kcexp_slot_device, 3> m_expansions;

	// defined in machine/kc.c
	virtual void machine_start() override;
	virtual void machine_reset() override;

	// modules read/write
	DECLARE_READ8_MEMBER ( expansion_read );
	DECLARE_WRITE8_MEMBER( expansion_write );
	DECLARE_READ8_MEMBER ( expansion_4000_r );
	DECLARE_WRITE8_MEMBER( expansion_4000_w );
	DECLARE_READ8_MEMBER ( expansion_8000_r );
	DECLARE_WRITE8_MEMBER( expansion_8000_w );
	DECLARE_READ8_MEMBER ( expansion_c000_r );
	DECLARE_WRITE8_MEMBER( expansion_c000_w );
	DECLARE_READ8_MEMBER ( expansion_e000_r );
	DECLARE_WRITE8_MEMBER( expansion_e000_w );
	DECLARE_READ8_MEMBER ( expansion_io_read );
	DECLARE_WRITE8_MEMBER( expansion_io_write );

	// bankswitch
	virtual void update_0x00000();
	virtual void update_0x04000();
	virtual void update_0x08000();
	virtual void update_0x0c000();
	virtual void update_0x0e000();

	// PIO callback
	DECLARE_READ8_MEMBER( pio_porta_r );
	DECLARE_READ8_MEMBER( pio_portb_r );
	DECLARE_WRITE_LINE_MEMBER( pio_ardy_cb);
	DECLARE_WRITE_LINE_MEMBER( pio_brdy_cb);
	DECLARE_WRITE8_MEMBER( pio_porta_w );
	DECLARE_WRITE8_MEMBER( pio_portb_w );

	// CTC callback
	DECLARE_WRITE_LINE_MEMBER( ctc_zc0_callback );
	DECLARE_WRITE_LINE_MEMBER( ctc_zc1_callback );

	// keyboard
	DECLARE_WRITE_LINE_MEMBER( keyboard_cb );

	// cassette
	void update_cassette(int state);
	void cassette_set_motor(int motor_state);

	// speaker
	void speaker_update();

	// defined in video/kc.c
	virtual void video_start() override;
	virtual uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	DECLARE_WRITE_LINE_MEMBER( video_toggle_blink_state );
	void video_draw_8_pixels(bitmap_ind16 &bitmap, int x, int y, uint8_t colour_byte, uint8_t gfx_byte);

	// driver state
	uint8_t *             m_ram_base;
	uint8_t *             m_video_ram;
	int                 m_pio_data[2];
	int                 m_high_resolution;
	uint8_t               m_ardy;
	uint8_t               m_brdy;
	int                 m_kc85_blink_state;
	int                 m_k0_line;
	int                 m_k1_line;
	uint8_t               m_speaker_level;

	// cassette
	emu_timer *         m_cassette_timer;
	emu_timer *         m_cassette_oneshot_timer;
	int                 m_astb;
	int                 m_cassette_in;

	DECLARE_PALETTE_INIT(kc85);
	TIMER_CALLBACK_MEMBER(kc_cassette_oneshot_timer);
	TIMER_CALLBACK_MEMBER(kc_cassette_timer_callback);
	TIMER_DEVICE_CALLBACK_MEMBER(kc_scanline);

	DECLARE_QUICKLOAD_LOAD_MEMBER( kc );
	void kc85_3(machine_config &config);
	void kc85_3_io(address_map &map);
	void kc85_3_mem(address_map &map);
};


class kc85_4_state : public kc_state
{
public:
	kc85_4_state(const machine_config &mconfig, device_type type, const char *tag)
		: kc_state(mconfig, type, tag)
		{ }

	// defined in machine/kc.c
	virtual void machine_reset() override;

	virtual void update_0x04000() override;
	virtual void update_0x08000() override;
	virtual void update_0x0c000() override;

	DECLARE_READ8_MEMBER( kc85_4_86_r );
	DECLARE_READ8_MEMBER( kc85_4_84_r );
	DECLARE_WRITE8_MEMBER( kc85_4_86_w );
	DECLARE_WRITE8_MEMBER( kc85_4_84_w );

	// defined in video/kc.c
	virtual void video_start() override;
	virtual uint32_t screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) override;
	void video_control_w(int data);

	// driver state
	uint8_t               m_port_84_data;
	uint8_t               m_port_86_data;
	uint8_t *             m_display_video_ram;
	void kc85_4(machine_config &config);
	void kc85_5(machine_config &config);
	void kc85_4_io(address_map &map);
	void kc85_4_mem(address_map &map);
};

#endif // MAME_INCLUDES_KC_H