summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/includes/apple2.h
blob: 4c629fce5101270eabdf21e2e230f3f8015ce896 (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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/***************************************************************************

    includes/apple2.h

    Include file to handle emulation of the Apple II series.

***************************************************************************/

#ifndef APPLE2_H_
#define APPLE2_H_

#include "machine/a2bus.h"
#include "machine/a2eauxslot.h"
#include "machine/applefdc.h"
#include "machine/ram.h"

#define AUXSLOT_TAG "auxbus"

/***************************************************************************
    SOFTSWITCH VALUES
***************************************************************************/

#define VAR_80STORE     0x000001
#define VAR_RAMRD       0x000002
#define VAR_RAMWRT      0x000004
#define VAR_INTCXROM    0x000008
#define VAR_ALTZP       0x000010
#define VAR_SLOTC3ROM   0x000020
#define VAR_80COL       0x000040
#define VAR_ALTCHARSET  0x000080
#define VAR_TEXT        0x000100
#define VAR_MIXED       0x000200
#define VAR_PAGE2       0x000400
#define VAR_HIRES       0x000800
#define VAR_AN0         0x001000
#define VAR_AN1         0x002000
#define VAR_AN2         0x004000
#define VAR_AN3         0x008000
#define VAR_LCRAM       0x010000
#define VAR_LCRAM2      0x020000
#define VAR_LCWRITE     0x040000
#define VAR_ROMSWITCH   0x080000
#define VAR_TK2000RAM   0x100000        // ROM/RAM switch for TK2000

#define VAR_DHIRES      VAR_AN3


/***************************************************************************
    SPECIAL KEYS
***************************************************************************/

#define SPECIALKEY_CAPSLOCK     0x01
#define SPECIALKEY_SHIFT        0x06
#define SPECIALKEY_CONTROL      0x08
#define SPECIALKEY_BUTTON0      0x10    /* open apple */
#define SPECIALKEY_BUTTON1      0x20    /* closed apple */
#define SPECIALKEY_BUTTON2      0x40
#define SPECIALKEY_RESET        0x80


/***************************************************************************
    OTHER
***************************************************************************/

/* -----------------------------------------------------------------------
 * New Apple II memory manager
 * ----------------------------------------------------------------------- */

#define APPLE2_MEM_AUX      0x40000000
#define APPLE2_MEM_SLOT     0x80000000
#define APPLE2_MEM_ROM      0xC0000000
#define APPLE2_MEM_FLOATING 0xFFFFFFFF
#define APPLE2_MEM_MASK     0x00FFFFFF

enum machine_type_t
{
	APPLE_II,           // Apple II/II+
	APPLE_IIE,			// Apple IIe with aux slots
	APPLE_IIEPLUS,      // Apple IIc/IIgs/IIc+ with permanent aux memory
	TK2000,             // Microdigital TK2000
	LASER128,           // Laser 128/128EX/128EX2
	SPACE84             // "Space 84" with flipped text mode
};

enum bank_disposition_t
{
	A2MEM_IO        = 0,    /* this is always handlers; never banked memory */
	A2MEM_MONO      = 1,    /* this is a bank where read and write are always in unison */
	A2MEM_DUAL      = 2     /* this is a bank where read and write can go different places */
};

struct apple2_meminfo
{
	UINT32 read_mem;
	read8_delegate *read_handler;
	UINT32 write_mem;
	write8_delegate *write_handler;
};

struct apple2_memmap_entry
{
	offs_t begin;
	offs_t end;
	void (*get_meminfo)(running_machine &machine, offs_t begin, offs_t end, apple2_meminfo *meminfo);
	bank_disposition_t bank_disposition;
};

struct apple2_memmap_config
{
	int first_bank;
	UINT8 *auxmem;
	UINT32 auxmem_length;
	const apple2_memmap_entry *memmap;
};

class apple2_state : public driver_device
{
public:
	apple2_state(const machine_config &mconfig, device_type type, const char *tag)
		: driver_device(mconfig, type, tag),
		m_maincpu(*this, "maincpu"),
		m_ram(*this, RAM_TAG),
		m_a2bus(*this, "a2bus"),
		m_a2eauxslot(*this, AUXSLOT_TAG),
		m_joy1x(*this, "joystick_1_x"),
		m_joy1y(*this, "joystick_1_y"),
		m_joy2x(*this, "joystick_2_x"),
		m_joy2y(*this, "joystick_2_y"),
		m_joybuttons(*this, "joystick_buttons"),
		m_kb0(*this, "keyb_0"),
		m_kb1(*this, "keyb_1"),
		m_kb2(*this, "keyb_2"),
		m_kb3(*this, "keyb_3"),
		m_kb4(*this, "keyb_4"),
		m_kb5(*this, "keyb_5"),
		m_kb6(*this, "keyb_6"),
		m_kbspecial(*this, "keyb_special"),
		m_kbrepeat(*this, "keyb_repeat"),
		m_resetdip(*this, "reset_dip"),
		m_kpad1(*this, "keypad_1"),
		m_kpad2(*this, "keypad_2"),
		m_kbprepeat(*this, "keyb_repeat")
	{ }

	required_device<cpu_device> m_maincpu;
	required_device<ram_device> m_ram;
	required_device<a2bus_device> m_a2bus;
	optional_device<a2eauxslot_device> m_a2eauxslot;

	optional_ioport m_joy1x, m_joy1y, m_joy2x, m_joy2y, m_joybuttons;
	required_ioport m_kb0, m_kb1, m_kb2, m_kb3, m_kb4, m_kb5, m_kb6, m_kbspecial;
	optional_ioport m_kbrepeat;
	optional_ioport m_resetdip;
	optional_ioport m_kpad1, m_kpad2;
	optional_ioport m_kbprepeat;

	UINT32 m_flags, m_flags_mask;
	INT32 m_a2_cnxx_slot;
	UINT32 m_a2_mask;
	UINT32 m_a2_set;
	int m_a2_speaker_state;
	double m_joystick_x1_time;
	double m_joystick_y1_time;
	double m_joystick_x2_time;
	double m_joystick_y2_time;
	apple2_memmap_config m_mem_config;
	apple2_meminfo *m_current_meminfo;
	int m_fdc_diskreg;
	unsigned int *m_ay3600_keys;
	UINT8 m_keycode;
	UINT8 m_keycode_unmodified;
	UINT8 m_keywaiting;
	UINT8 m_keystilldown;
	UINT8 m_keymodreg;
	int m_reset_flag;
	int m_last_key;
	int m_last_key_unmodified;
	unsigned int m_time_until_repeat;
	const UINT8 *m_a2_videoram, *m_a2_videoaux, *m_textgfx_data;
	UINT32 m_a2_videomask, m_textgfx_datalen;
	UINT32 m_old_a2;
	int m_fgcolor;
	int m_bgcolor;
	int m_flash;
	int m_alt_charset_value;
	UINT16 *m_hires_artifact_map;
	UINT16 *m_dhires_artifact_map;
	bool m_monochrome_dhr;
	int m_inh_slot;

	UINT8 *m_rambase;

	UINT8 *m_rom, *m_slot_ram;
	UINT32 m_rom_length, m_slot_length;

	machine_type_t m_machinetype;

	device_a2eauxslot_card_interface *m_auxslotdevice;

	READ8_MEMBER(apple2_c0xx_r);
	WRITE8_MEMBER(apple2_c0xx_w);
	READ8_MEMBER(apple2_c080_r);
	WRITE8_MEMBER(apple2_c080_w);

	READ8_MEMBER ( apple2_c00x_r );
	READ8_MEMBER ( apple2_c01x_r );
	READ8_MEMBER ( apple2_c02x_r );
	READ8_MEMBER ( apple2_c03x_r );
	READ8_MEMBER ( apple2_c05x_r );
	READ8_MEMBER ( apple2_c06x_r );
	READ8_MEMBER ( apple2_c07x_r );
	WRITE8_MEMBER ( apple2_c00x_w );
	WRITE8_MEMBER ( apple2_c01x_w );
	WRITE8_MEMBER ( apple2_c02x_w );
	WRITE8_MEMBER ( apple2_c03x_w );
	WRITE8_MEMBER ( apple2_c05x_w );
	WRITE8_MEMBER ( apple2_c07x_w );

	READ8_MEMBER ( apple2_mainram0000_r );
	READ8_MEMBER ( apple2_mainram0200_r );
	READ8_MEMBER ( apple2_mainram0400_r );
	READ8_MEMBER ( apple2_mainram0800_r );
	READ8_MEMBER ( apple2_mainram2000_r );
	READ8_MEMBER ( apple2_mainram4000_r );
	READ8_MEMBER ( apple2_mainramc000_r );
	READ8_MEMBER ( apple2_mainramd000_r );
	READ8_MEMBER ( apple2_mainrame000_r );
	READ8_MEMBER ( apple2_auxram0000_r );
	READ8_MEMBER ( apple2_auxram0200_r );
	READ8_MEMBER ( apple2_auxram0400_r );
	READ8_MEMBER ( apple2_auxram0800_r );
	READ8_MEMBER ( apple2_auxram2000_r );
	READ8_MEMBER ( apple2_auxram4000_r );
	READ8_MEMBER ( apple2_auxramc000_r );
	READ8_MEMBER ( apple2_auxramd000_r );
	READ8_MEMBER ( apple2_auxrame000_r );

	WRITE8_MEMBER ( apple2_mainram0000_w );
	WRITE8_MEMBER ( apple2_mainram0200_w );
	WRITE8_MEMBER ( apple2_mainram0400_w );
	WRITE8_MEMBER ( apple2_mainram0800_w );
	WRITE8_MEMBER ( apple2_mainram2000_w );
	WRITE8_MEMBER ( apple2_mainram4000_w );
	WRITE8_MEMBER ( apple2_mainramc000_w );
	WRITE8_MEMBER ( apple2_mainramd000_w );
	WRITE8_MEMBER ( apple2_mainrame000_w );
	WRITE8_MEMBER ( apple2_auxram0000_w );
	WRITE8_MEMBER ( apple2_auxram0200_w );
	WRITE8_MEMBER ( apple2_auxram0400_w );
	WRITE8_MEMBER ( apple2_auxram0800_w );
	WRITE8_MEMBER ( apple2_auxram2000_w );
	WRITE8_MEMBER ( apple2_auxram4000_w );
	WRITE8_MEMBER ( apple2_auxramc000_w );
	WRITE8_MEMBER ( apple2_auxramd000_w );
	WRITE8_MEMBER ( apple2_auxrame000_w );

	READ8_MEMBER ( apple2_c1xx_r );
	WRITE8_MEMBER ( apple2_c1xx_w );
	READ8_MEMBER ( apple2_c3xx_r );
	WRITE8_MEMBER ( apple2_c3xx_w );
	READ8_MEMBER ( apple2_c4xx_r );
	WRITE8_MEMBER ( apple2_c4xx_w );

	READ8_MEMBER ( apple2_c800_r );
	WRITE8_MEMBER ( apple2_c800_w );
	READ8_MEMBER ( apple2_ce00_r );
	WRITE8_MEMBER ( apple2_ce00_w );

	READ8_MEMBER ( apple2_inh_d000_r );
	WRITE8_MEMBER ( apple2_inh_d000_w );
	READ8_MEMBER ( apple2_inh_e000_r );
	WRITE8_MEMBER ( apple2_inh_e000_w );

	READ8_MEMBER(read_floatingbus);

	READ8_MEMBER(apple2_cfff_r);
	WRITE8_MEMBER(apple2_cfff_w);

	void apple2_refresh_delegates();
	int apple2_pressed_specialkey(UINT8 key);

	read8_delegate read_delegates_master[4];
	write8_delegate write_delegates_master[3];
	write8_delegate write_delegates_0000[2];
	write8_delegate write_delegates_0200[2];
	write8_delegate write_delegates_0400[2];
	write8_delegate write_delegates_0800[2];
	write8_delegate write_delegates_2000[2];
	write8_delegate write_delegates_4000[2];
	write8_delegate write_delegates_c000[2];
	write8_delegate write_delegates_d000[2];
	write8_delegate write_delegates_e000[2];
	read8_delegate read_delegates_0000[2];
	read8_delegate read_delegates_0200[2];
	read8_delegate read_delegates_0400[2];
	read8_delegate read_delegates_0800[2];
	read8_delegate read_delegates_2000[2];
	read8_delegate read_delegates_4000[2];
	read8_delegate read_delegates_c000[2];
	read8_delegate read_delegates_d000[2];
	read8_delegate read_delegates_e000[2];
	read8_delegate rd_c000;
	write8_delegate wd_c000;
	read8_delegate rd_c080;
	write8_delegate wd_c080;
	read8_delegate rd_cfff;
	write8_delegate wd_cfff;
	read8_delegate rd_c800;
	write8_delegate wd_c800;
	read8_delegate rd_ce00;
	write8_delegate wd_ce00;
	read8_delegate rd_inh_d000;
	write8_delegate wd_inh_d000;
	read8_delegate rd_inh_e000;
	write8_delegate wd_inh_e000;
	DECLARE_MACHINE_START(apple2);
	DECLARE_MACHINE_START(apple2e);
	DECLARE_VIDEO_START(apple2);
	DECLARE_PALETTE_INIT(apple2);
	DECLARE_MACHINE_START(apple2orig);
	DECLARE_VIDEO_START(apple2p);
	DECLARE_VIDEO_START(apple2e);
	DECLARE_VIDEO_START(apple2c);
	DECLARE_MACHINE_START(tk2000);
	DECLARE_MACHINE_START(laser128);
	DECLARE_MACHINE_START(space84);
	UINT32 screen_update_apple2(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
	TIMER_DEVICE_CALLBACK_MEMBER(apple2_interrupt);
	DECLARE_WRITE8_MEMBER(a2bus_irq_w);
	DECLARE_WRITE8_MEMBER(a2bus_nmi_w);
	DECLARE_WRITE8_MEMBER(a2bus_inh_w);
	void apple2_update_memory_postload();
	virtual void machine_reset();
	void apple2_setup_memory(const apple2_memmap_config *config);
	void apple2_update_memory();
};


/*----------- defined in drivers/apple2.c -----------*/

INPUT_PORTS_EXTERN( apple2ep );



/*----------- defined in machine/apple2.c -----------*/

extern const applefdc_interface apple2_fdc_interface;

void apple2_iwm_setdiskreg(running_machine &machine, UINT8 data);
UINT8 apple2_iwm_getdiskreg(running_machine &machine);

void apple2_init_common(running_machine &machine);





UINT8 apple2_getfloatingbusvalue(running_machine &machine);
DECLARE_READ8_HANDLER( apple2_c0xx_r );
DECLARE_WRITE8_HANDLER( apple2_c0xx_w );
DECLARE_READ8_HANDLER( apple2_c080_r );
DECLARE_WRITE8_HANDLER( apple2_c080_w );

INT8 apple2_slotram_r(running_machine &machine, int slotnum, int offset);

void apple2_setvar(running_machine &machine, UINT32 val, UINT32 mask);

int apple2_pressed_specialkey(running_machine &machine, UINT8 key);

/*----------- defined in video/apple2.c -----------*/

void apple2_video_start(running_machine &machine, const UINT8 *vram, const UINT8 *aux_vram, UINT32 ignored_softswitches, int hires_modulo);


#endif /* APPLE2_H_ */