diff --git a/src/mess/drivers/apple2.c b/src/mess/drivers/apple2.c index d2cdc6d5ab7..9bb08b8f8c9 100644 --- a/src/mess/drivers/apple2.c +++ b/src/mess/drivers/apple2.c @@ -182,16 +182,10 @@ Apple 3.5 and Apple 5.25 drives - up to three devices #include "emu.h" -#include "cpu/m6502/m6502.h" -#include "cpu/m6502/m65c02.h" -#include "cpu/z80/z80.h" #include "imagedev/flopdrv.h" #include "imagedev/cassette.h" #include "formats/ap2_dsk.h" #include "includes/apple2.h" -#include "machine/ay3600.h" -#include "sound/speaker.h" -#include "machine/ram.h" #include "bus/a2bus/a2bus.h" #include "bus/a2bus/a2lang.h" @@ -678,6 +672,9 @@ static MACHINE_CONFIG_START( apple2_common, apple2_state ) MCFG_SOUND_ADD("a2speaker", SPEAKER_SOUND, 0) MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00) + /* keyboard controller */ + MCFG_DEVICE_ADD("ay3600", AY3600N, 0) + /* slot devices */ MCFG_A2BUS_BUS_ADD("a2bus", "maincpu", a2bus_intf) MCFG_A2BUS_SLOT_ADD("a2bus", "sl0", apple2_slot0_cards, "lang") diff --git a/src/mess/drivers/apple2gs.c b/src/mess/drivers/apple2gs.c index ef914a4eb58..1c7f01f81b7 100644 --- a/src/mess/drivers/apple2gs.c +++ b/src/mess/drivers/apple2gs.c @@ -354,6 +354,9 @@ static MACHINE_CONFIG_START( apple2gs, apple2gs_state ) MCFG_PALETTE_INIT_OVERRIDE(apple2gs_state, apple2gs ) MCFG_VIDEO_START_OVERRIDE(apple2gs_state, apple2gs ) + /* keyboard controller */ + MCFG_DEVICE_ADD("ay3600", AY3600N, 0) + /* sound hardware */ MCFG_SPEAKER_STANDARD_MONO("mono") MCFG_SOUND_ADD("a2speaker", SPEAKER_SOUND, 0) diff --git a/src/mess/drivers/apple3.c b/src/mess/drivers/apple3.c index bdb2a78ebde..029740a5d6d 100644 --- a/src/mess/drivers/apple3.c +++ b/src/mess/drivers/apple3.c @@ -71,6 +71,9 @@ static MACHINE_CONFIG_START( apple3, apple3_state ) MCFG_TIMER_DRIVER_ADD_SCANLINE("scantimer", apple3_state, apple3_interrupt, "screen", 0, 1) + /* keyboard controller */ + MCFG_DEVICE_ADD("ay3600", AY3600N, 0) + /* slot bus */ MCFG_A2BUS_BUS_ADD("a2bus", "maincpu", a2bus_intf) @@ -103,7 +106,7 @@ static MACHINE_CONFIG_START( apple3, apple3_state ) /* internal ram */ MCFG_RAM_ADD(RAM_TAG) MCFG_RAM_DEFAULT_SIZE("256K") - MCFG_RAM_EXTRA_OPTIONS("512K") + MCFG_RAM_EXTRA_OPTIONS("128K, 512K") MACHINE_CONFIG_END diff --git a/src/mess/includes/apple2.h b/src/mess/includes/apple2.h index fafd40c8a52..89497621d63 100644 --- a/src/mess/includes/apple2.h +++ b/src/mess/includes/apple2.h @@ -9,11 +9,16 @@ #ifndef APPLE2_H_ #define APPLE2_H_ +#include "cpu/m6502/m6502.h" +#include "cpu/m6502/m65c02.h" #include "bus/a2bus/a2bus.h" #include "bus/a2bus/a2eauxslot.h" #include "machine/applefdc.h" #include "machine/ram.h" #include "imagedev/cassette.h" +#include "machine/ay3600.h" +#include "sound/speaker.h" +#include "machine/ram.h" #define AUXSLOT_TAG "auxbus" @@ -45,20 +50,6 @@ #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 ***************************************************************************/ @@ -122,6 +113,7 @@ public: : driver_device(mconfig, type, tag), m_maincpu(*this, "maincpu"), m_ram(*this, RAM_TAG), + m_ay3600(*this, "ay3600"), m_a2bus(*this, "a2bus"), m_a2eauxslot(*this, AUXSLOT_TAG), m_joy1x(*this, "joystick_1_x"), @@ -147,6 +139,7 @@ public: required_device m_maincpu; required_device m_ram; + required_device m_ay3600; required_device m_a2bus; optional_device m_a2eauxslot; @@ -170,16 +163,6 @@ public: 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; @@ -191,6 +174,7 @@ public: UINT16 *m_dhires_artifact_map; bool m_monochrome_dhr; int m_inh_slot; + int m_reset_flag; UINT8 *m_rambase; @@ -354,6 +338,7 @@ public: void apple2_iwm_setdiskreg(UINT8 data); void apple2_init_common(); INT8 apple2_slotram_r(address_space &space, int slotnum, int offset); + int a2_no_ctrl_reset(); }; /*----------- defined in drivers/apple2.c -----------*/ INPUT_PORTS_EXTERN( apple2ep ); diff --git a/src/mess/includes/apple3.h b/src/mess/includes/apple3.h index 7d535be3fc1..7928f5cbb6f 100644 --- a/src/mess/includes/apple3.h +++ b/src/mess/includes/apple3.h @@ -16,6 +16,7 @@ #include "machine/applefdc.h" #include "machine/mos6551.h" #include "machine/6522via.h" +#include "machine/ay3600.h" #include "sound/speaker.h" #include "sound/dac.h" @@ -31,20 +32,26 @@ #define SPEAKER_TAG "a3spkr" #define DAC_TAG "a3dac" -class apple3_state : public apple2_state +class apple3_state : public driver_device { public: apple3_state(const machine_config &mconfig, device_type type, const char *tag) - : apple2_state(mconfig, type, tag), + : driver_device(mconfig, type, tag), + m_maincpu(*this, "maincpu"), + m_ram(*this, RAM_TAG), m_via_0(*this, "via6522_0"), m_via_1(*this, "via6522_1"), + m_ay3600(*this, "ay3600"), m_speaker(*this, SPEAKER_TAG), m_dac(*this, DAC_TAG) { } + required_device m_maincpu; + required_device m_ram; required_device m_via_0; required_device m_via_1; + required_device m_ay3600; required_device m_speaker; required_device m_dac; diff --git a/src/mess/machine/apple2.c b/src/mess/machine/apple2.c index 4f942f0cea3..b09be7e4c33 100644 --- a/src/mess/machine/apple2.c +++ b/src/mess/machine/apple2.c @@ -1140,6 +1140,7 @@ void apple2_state::machine_reset() { int need_intcxrom; + m_reset_flag = 0; m_rambase = m_ram->pointer(); apple2_refresh_delegates(); @@ -1166,7 +1167,11 @@ void apple2_state::machine_reset() m_joystick_x2_time = m_joystick_y2_time = 0; } - +int apple2_state::a2_no_ctrl_reset() +{ + return (((m_kbprepeat != NULL) && (m_resetdip == NULL)) || + ((m_resetdip != NULL) && !m_resetdip->read())); +} /* ----------------------------------------------------------------------- * Apple II interrupt; used to force partial updates @@ -1178,6 +1183,25 @@ TIMER_DEVICE_CALLBACK_MEMBER(apple2_state::apple2_interrupt) if((scanline % 8) == 0) machine().primary_screen->update_partial(machine().primary_screen->vpos()); + + if (apple2_pressed_specialkey(0x80) && + (a2_no_ctrl_reset() || (m_ay3600->keymod_r() & AY3600_KEYMOD_CONTROL))) + { + if (!m_reset_flag) + { + m_reset_flag = 1; + /* using PULSE_LINE does not allow us to press and hold key */ + m_maincpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); + } + return; + } + + if (m_reset_flag) + { + m_reset_flag = 0; + m_maincpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE); + machine().schedule_soft_reset(); + } } @@ -1587,7 +1611,7 @@ READ8_MEMBER ( apple2_state::apple2_c00x_r ) { /* Read the keyboard data and strobe */ g_profiler.start(PROFILER_C00X); - result = AY3600_keydata_strobe_r(space.machine()); + result = m_ay3600->keydata_strobe_r(); g_profiler.stop(); } @@ -1644,7 +1668,7 @@ READ8_MEMBER( apple2_state::apple2_c01x_r ) LOG(("a2 softswitch_r: %04x\n", offset + 0xc010)); switch (offset) { - case 0x00: result |= AY3600_anykey_clearstrobe_r(space.machine()); break; + case 0x00: result |= m_ay3600->anykey_clearstrobe_r(); break; case 0x01: result |= (m_flags & VAR_LCRAM2) ? 0x80 : 0x00; break; case 0x02: result |= (m_flags & VAR_LCRAM) ? 0x80 : 0x00; break; case 0x03: result |= (m_flags & VAR_RAMRD) ? 0x80 : 0x00; break; @@ -1678,7 +1702,7 @@ WRITE8_MEMBER( apple2_state::apple2_c01x_w ) { /* Clear the keyboard strobe - ignore the returned results */ g_profiler.start(PROFILER_C01X); - AY3600_anykey_clearstrobe_r(machine()); + m_ay3600->anykey_clearstrobe_r(); g_profiler.stop(); } @@ -1727,14 +1751,7 @@ READ8_MEMBER ( apple2_state::apple2_c03x_r ) { speaker_sound_device *speaker = space.machine().device("a2speaker"); - if (m_a2_speaker_state == 1) - { - m_a2_speaker_state = 0; - } - else - { - m_a2_speaker_state = 1; - } + m_a2_speaker_state ^= 1; speaker->level_w(m_a2_speaker_state); } } @@ -1829,15 +1846,15 @@ READ8_MEMBER ( apple2_state::apple2_c06x_r ) break; case 0x01: /* Open-Apple/Joystick button 0 */ - result = apple2_pressed_specialkey(SPECIALKEY_BUTTON0); + result = apple2_pressed_specialkey(0x10); break; case 0x02: /* Closed-Apple/Joystick button 1 */ - result = apple2_pressed_specialkey(SPECIALKEY_BUTTON1); + result = apple2_pressed_specialkey(0x20); break; case 0x03: /* Joystick button 2. Later revision motherboards connected this to SHIFT also */ - result = apple2_pressed_specialkey(SPECIALKEY_BUTTON2); + result = apple2_pressed_specialkey(0x40); break; case 0x04: /* X Joystick 1 axis */ @@ -2090,8 +2107,6 @@ void apple2_state::apple2_init_common() m_auxslotdevice = m_a2eauxslot->get_a2eauxslot_card(); } - AY3600_init(machine()); - /* state save registers */ save_item(NAME(m_flags)); machine().save().register_postload(save_prepost_delegate(FUNC(apple2_state::apple2_update_memory_postload), this)); @@ -2110,10 +2125,10 @@ void apple2_state::apple2_init_common() m_a2_mask &= ~(VAR_RAMRD | VAR_RAMWRT | VAR_80STORE | VAR_ALTZP | VAR_80COL); apple2_refresh_delegates(); + + m_ay3600->set_runtime_config(m_kpad1 != NULL, m_kbprepeat != NULL); } - - MACHINE_START_MEMBER(apple2_state,apple2) { apple2_memmap_config mem_cfg; diff --git a/src/mess/machine/apple2gs.c b/src/mess/machine/apple2gs.c index 089a97b2021..8c9beef6910 100644 --- a/src/mess/machine/apple2gs.c +++ b/src/mess/machine/apple2gs.c @@ -944,7 +944,7 @@ READ8_MEMBER( apple2gs_state::apple2gs_c0xx_r ) #if RUN_ADB_MICRO result = keyglu_816_read(GLU_KEYMOD); #else - result = AY3600_keymod_r(space.machine()); + result = m_ay3600->keymod_r(); #endif break; diff --git a/src/mess/machine/apple3.c b/src/mess/machine/apple3.c index b73acfe2cec..34c01e7428a 100644 --- a/src/mess/machine/apple3.c +++ b/src/mess/machine/apple3.c @@ -45,18 +45,11 @@ #include "emu.h" #include "includes/apple3.h" #include "includes/apple2.h" -#include "cpu/m6502/m6502.h" -#include "machine/6522via.h" -#include "machine/ay3600.h" #include "machine/applefdc.h" #include "machine/appldriv.h" -#include "machine/mos6551.h" -#include "machine/ram.h" - static void apple3_update_drives(device_t *device); - #define LOG_MEMORY 1 #define LOG_INDXADDR 1 @@ -71,14 +64,14 @@ READ8_MEMBER(apple3_state::apple3_c0xx_r) /* keystrobe */ case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: - result = AY3600_keydata_strobe_r(machine()); + result = m_ay3600->keydata_strobe_r(); break; /* modifier keys */ case 0x08: case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0E: case 0x0F: { - UINT8 tmp = AY3600_keymod_r(machine()); + UINT8 tmp = m_ay3600->keymod_r(); result = 0x7e; if (tmp & AY3600_KEYMOD_SHIFT) @@ -108,7 +101,7 @@ READ8_MEMBER(apple3_state::apple3_c0xx_r) case 0x14: case 0x15: case 0x16: case 0x17: case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1E: case 0x1F: - AY3600_anykey_clearstrobe_r(machine()); + m_ay3600->anykey_clearstrobe_r(); break; case 0x30: case 0x31: case 0x32: case 0x33: @@ -190,7 +183,7 @@ WRITE8_MEMBER(apple3_state::apple3_c0xx_w) case 0x14: case 0x15: case 0x16: case 0x17: case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1E: case 0x1F: - AY3600_anykey_clearstrobe_r(machine()); + m_ay3600->anykey_clearstrobe_r(); break; case 0x30: case 0x31: case 0x32: case 0x33: @@ -249,7 +242,7 @@ WRITE8_MEMBER(apple3_state::apple3_c0xx_w) TIMER_DEVICE_CALLBACK_MEMBER(apple3_state::apple3_interrupt) { - m_via_1->write_ca2((AY3600_keydata_strobe_r(machine()) & 0x80) ? 1 : 0); + m_via_1->write_ca2((m_ay3600->keydata_strobe_r() & 0x80) ? 1 : 0); m_via_1->write_cb1(machine().primary_screen->vblank()); m_via_1->write_cb2(machine().primary_screen->vblank()); } @@ -592,8 +585,6 @@ DRIVER_INIT_MEMBER(apple3_state,apple3) m_enable_mask = 0; apple3_update_drives(machine().device("fdc")); - AY3600_init(machine()); - m_flags = 0; m_via_0_a = ~0; m_via_1_a = ~0; @@ -620,6 +611,8 @@ DRIVER_INIT_MEMBER(apple3_state,apple3) m_via_1->write_pb7(1); apple3_update_memory(); + + m_ay3600->set_runtime_config(false, false); // no keypad (yet), no repeat key } READ8_MEMBER(apple3_state::apple3_memory_r) diff --git a/src/mess/machine/ay3600.c b/src/mess/machine/ay3600.c index 00e6311bf4b..8009a8ef99e 100644 --- a/src/mess/machine/ay3600.c +++ b/src/mess/machine/ay3600.c @@ -2,23 +2,15 @@ AY3600.c - Machine file to handle emulation of the AY-3600 keyboard controller. - - TODO: - -Make the caps lock functional, remove dependency on input_port_1. - Caps lock now functional. Barry Nelson 04/05/2001 - Still dependent on input_port_1 though. - -Rename variables from a2 to AY3600 - Done. Barry Nelson 04/05/2001 - Find the correct MAGIC_KEY_REPEAT_NUMBER - Use the keyboard ROM for building a remapping table? + GI AY-3600 keyboard controller device + Rewritten 2014 by R. Belmont, thanks to earlier efforts by + Barry Nelson and Nathan Woods. + ***************************************************************************/ #include "emu.h" #include "machine/ay3600.h" -#include "includes/apple2.h" - /*************************************************************************** PARAMETERS @@ -32,15 +24,18 @@ #define LOG(x) do { if (VERBOSE) logerror x; } while (0) - - /**************************************************************************/ -static TIMER_CALLBACK(AY3600_poll); +// bit order in the input port of the special keys +#define SPECIALKEY_CAPSLOCK 0x01 +#define SPECIALKEY_SHIFTL 0x04 +#define SPECIALKEY_SHIFTR 0x08 +#define SPECIALKEY_CONTROL 0x08 +#define SPECIALKEY_ALTL 0x10 +#define SPECIALKEY_ALTR 0x20 +#define SPECIALKEY_WIN 0x40 +#define SPECIALKEY_RESET 0x80 -static int AY3600_keyboard_queue_chars(running_machine &machine, const unicode_char *text, size_t text_len); -static bool AY3600_keyboard_accept_char(running_machine &machine, unicode_char ch); -static bool AY3600_keyboard_charqueue_empty(running_machine &machine); static const unsigned char ay3600_key_remap_2[9*8][4] = { /* norm ctrl shft both */ @@ -256,193 +251,167 @@ static const unsigned char ay3600_key_remap_2e[2][9*8][4] = } }; -#define A2_KEY_NORMAL 0 -#define A2_KEY_CONTROL 1 -#define A2_KEY_SHIFT 2 -#define A2_KEY_BOTH 3 +#define AY3600_KEY_NORMAL 0 +#define AY3600_KEY_CONTROL 1 +#define AY3600_KEY_SHIFT 2 +#define AY3600_KEY_BOTH 3 #define MAGIC_KEY_REPEAT_NUMBER 80 #define AY3600_KEYS_LENGTH 128 +const device_type AY3600N = &device_creator; -/*************************************************************************** - HELPER FUNCTIONS -***************************************************************************/ +//************************************************************************** +// LIVE DEVICE +//************************************************************************** -INLINE int a2_has_keypad(apple2_state *state) +//------------------------------------------------- +// ay3600n_device - constructor +//------------------------------------------------- + +ay3600n_device::ay3600n_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) + : device_t(mconfig, AY3600N, "AY-3600 keyboard controller", tag, owner, clock, "ay3600", __FILE__) { - return (state->m_kpad1 != NULL); + m_keypad = m_repeat = false; } -INLINE int a2_has_reset_dip(apple2_state *state) -{ - return (state->m_resetdip != NULL); -} - -INLINE int a2_has_repeat(apple2_state *state) -{ - return (state->m_kbprepeat != NULL); -} - -INLINE int a2_has_capslock(apple2_state *state) -{ - return !a2_has_repeat(state); /* BUG: Doesn't work with Ace */ -} - -INLINE int a2_no_ctrl_reset(apple2_state *state) -{ - return ((a2_has_repeat(state) && !a2_has_reset_dip(state)) || - (a2_has_reset_dip(state) && !state->m_resetdip->read())); -} - - /*************************************************************************** AY3600_init ***************************************************************************/ -int AY3600_init(running_machine &machine) +void ay3600n_device::device_start() { - apple2_state *state = machine.driver_data(); /* Init the key remapping table */ - state->m_ay3600_keys = auto_alloc_array_clear(machine, unsigned int, AY3600_KEYS_LENGTH); + m_ay3600_keys = auto_alloc_array_clear(machine(), unsigned int, AY3600_KEYS_LENGTH); /* We poll the keyboard periodically to scan the keys. This is actually consistent with how the AY-3600 keyboard controller works. */ - machine.scheduler().timer_pulse(attotime::from_hz(60), FUNC(AY3600_poll)); + m_timer = timer_alloc(0, NULL); + m_timer->adjust(attotime::never); - /* Set Caps Lock light to ON, since that's how we default it. */ - set_led_status(machine,1,1); - - state->m_keywaiting = 0; - state->m_keycode = 0; - state->m_keystilldown = 0; - state->m_keymodreg = AY3600_KEYMOD_CAPSLOCK; // caps lock on - - state->m_last_key = 0xff; /* necessary for special repeat key behaviour */ - state->m_last_key_unmodified = 0xff; /* necessary for special repeat key behaviour */ - state->m_time_until_repeat = MAGIC_KEY_REPEAT_NUMBER; - - machine.ioport().natkeyboard().configure( +/* machine.ioport().natkeyboard().configure( ioport_queue_chars_delegate(FUNC(AY3600_keyboard_queue_chars), &machine), ioport_accept_char_delegate(FUNC(AY3600_keyboard_accept_char), &machine), - ioport_charqueue_empty_delegate(FUNC(AY3600_keyboard_charqueue_empty), &machine)); + ioport_charqueue_empty_delegate(FUNC(AY3600_keyboard_charqueue_empty), &machine));*/ - return 0; + save_item(NAME(m_keycode)); + save_item(NAME(m_keycode_unmodified)); + save_item(NAME(m_keywaiting)); + save_item(NAME(m_keystilldown)); + save_item(NAME(m_keymodreg)); + save_item(NAME(m_last_key)); + save_item(NAME(m_last_key_unmodified)); + save_item(NAME(m_time_until_repeat)); } - - -/*************************************************************************** - AY3600_poll -***************************************************************************/ - -static TIMER_CALLBACK(AY3600_poll) +void ay3600n_device::device_reset() +{ + /* Set Caps Lock light to ON, since that's how we default it. */ + set_led_status(machine(), 1, 1); + + m_keywaiting = 0; + m_keycode = 0; + m_keystilldown = 0; + m_keymodreg = AY3600_KEYMOD_CAPSLOCK; // caps lock on + + m_last_key = 0xff; /* necessary for special repeat key behaviour */ + m_last_key_unmodified = 0xff; /* necessary for special repeat key behaviour */ + m_time_until_repeat = MAGIC_KEY_REPEAT_NUMBER; + + m_timer->adjust(attotime::from_hz(60), 0, attotime::from_hz(60)); +} + +void ay3600n_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) { - apple2_state *state = machine.driver_data(); int switchkey; /* Normal, Shift, Control, or both */ int port, num_ports, bit, data; int any_key_pressed = 0; /* Have we pressed a key? True/False */ int caps_lock = 0; int curkey; int curkey_unmodified; - ioport_port *portnames[] = { state->m_kb0, state->m_kb1, state->m_kb2, state->m_kb3, state->m_kb4, state->m_kb5, state->m_kb6, - state->m_kpad1, state->m_kpad2 }; + static const char *const portnames[] = + { + "keyb_0", "keyb_1", "keyb_2", "keyb_3", "keyb_4", "keyb_5", "keyb_6", + "keypad_1", "keypad_2" + }; /* check for these special cases because they affect the emulated key codes */ + /* does this machine have a special repeat key? */ + if (m_repeat) + m_time_until_repeat = machine().root_device().ioport("keyb_repeat")->read() & 0x01 ? 0 : ~0; - /* only repeat keys on a 2/2+ if special REPT key is pressed */ - if (a2_has_repeat(state)) - state->m_time_until_repeat = state->m_kbprepeat->read() & 0x01 ? 0 : ~0; + int special_state = machine().root_device().ioport("keyb_special")->read(); /* check caps lock and set LED here */ - if (state->apple2_pressed_specialkey(SPECIALKEY_CAPSLOCK)) + if (special_state & SPECIALKEY_CAPSLOCK) { caps_lock = 1; - set_led_status(machine,1,1); - state->m_keymodreg |= AY3600_KEYMOD_CAPSLOCK; + set_led_status(machine(), 1, 1); + m_keymodreg |= AY3600_KEYMOD_CAPSLOCK; } else { caps_lock = 0; - set_led_status(machine,1,0); - state->m_keymodreg &= ~AY3600_KEYMOD_CAPSLOCK; + set_led_status(machine(), 1, 0); + m_keymodreg &= ~AY3600_KEYMOD_CAPSLOCK; } - switchkey = A2_KEY_NORMAL; + switchkey = AY3600_KEY_NORMAL; /* shift key check */ - if (state->apple2_pressed_specialkey(SPECIALKEY_SHIFT)) + if (special_state & (SPECIALKEY_SHIFTL | SPECIALKEY_SHIFTR)) { - switchkey |= A2_KEY_SHIFT; - state->m_keymodreg |= AY3600_KEYMOD_SHIFT; + switchkey |= AY3600_KEY_SHIFT; + m_keymodreg |= AY3600_KEYMOD_SHIFT; } else { - state->m_keymodreg &= ~AY3600_KEYMOD_SHIFT; + m_keymodreg &= ~AY3600_KEYMOD_SHIFT; } - /* control key check - only one control key on the left side on the Apple */ - if (state->apple2_pressed_specialkey(SPECIALKEY_CONTROL)) + /* control key check - only one control key */ + if (special_state & SPECIALKEY_CONTROL) { - switchkey |= A2_KEY_CONTROL; - state->m_keymodreg |= AY3600_KEYMOD_CONTROL; + switchkey |= AY3600_KEY_CONTROL; + m_keymodreg |= AY3600_KEYMOD_CONTROL; } else { - state->m_keymodreg &= ~AY3600_KEYMOD_CONTROL; + m_keymodreg &= ~AY3600_KEYMOD_CONTROL; } /* apple key check */ - if (state->apple2_pressed_specialkey(SPECIALKEY_BUTTON0)) + if (special_state & SPECIALKEY_ALTL) { - state->m_keymodreg |= AY3600_KEYMOD_COMMAND; + m_keymodreg |= AY3600_KEYMOD_COMMAND; } else { - state->m_keymodreg &= ~AY3600_KEYMOD_COMMAND; + m_keymodreg &= ~AY3600_KEYMOD_COMMAND; } /* option key check */ - if (state->apple2_pressed_specialkey(SPECIALKEY_BUTTON1)) + if (special_state & SPECIALKEY_ALTR) { - state->m_keymodreg |= AY3600_KEYMOD_OPTION; + m_keymodreg |= AY3600_KEYMOD_OPTION; } else { - state->m_keymodreg &= ~AY3600_KEYMOD_OPTION; - } - - /* reset key check */ - if (state->apple2_pressed_specialkey(SPECIALKEY_RESET) && - (a2_no_ctrl_reset(state) || switchkey & A2_KEY_CONTROL)) - { - if (!state->m_reset_flag) - { - state->m_reset_flag = 1; - /* using PULSE_LINE does not allow us to press and hold key */ - state->m_maincpu->set_input_line(INPUT_LINE_RESET, ASSERT_LINE); - } - return; - } - if (state->m_reset_flag) - { - state->m_reset_flag = 0; - state->m_maincpu->set_input_line(INPUT_LINE_RESET, CLEAR_LINE); - machine.schedule_soft_reset(); + m_keymodreg &= ~AY3600_KEYMOD_OPTION; } /* run through real keys and see what's being pressed */ - num_ports = a2_has_keypad(state) ? 9 : 7; + num_ports = m_keypad ? 9 : 7; - state->m_keymodreg &= ~AY3600_KEYMOD_KEYPAD; + m_keymodreg &= ~AY3600_KEYMOD_KEYPAD; for (port = 0; port < num_ports; port++) { - data = portnames[port]->read(); + data = machine().root_device().ioport(portnames[port])->read(); for (bit = 0; bit < 8; bit++) { - if (a2_has_capslock(state)) + if (!m_repeat) { curkey = ay3600_key_remap_2e[caps_lock][port*8+bit][switchkey]; curkey_unmodified = ay3600_key_remap_2e[caps_lock][port*8+bit][0]; @@ -458,68 +427,67 @@ static TIMER_CALLBACK(AY3600_poll) if (port == 8) { - state->m_keymodreg |= AY3600_KEYMOD_KEYPAD; + m_keymodreg |= AY3600_KEYMOD_KEYPAD; } /* prevent overflow */ - if (state->m_ay3600_keys[port*8+bit] < 65000) - state->m_ay3600_keys[port*8+bit]++; + if (m_ay3600_keys[port*8+bit] < 65000) + m_ay3600_keys[port*8+bit]++; /* on every key press, reset the time until repeat and the key to repeat */ - if ((state->m_ay3600_keys[port*8+bit] == 1) && (curkey_unmodified != state->m_last_key_unmodified)) + if ((m_ay3600_keys[port*8+bit] == 1) && (curkey_unmodified != m_last_key_unmodified)) { - state->m_time_until_repeat = MAGIC_KEY_REPEAT_NUMBER; - state->m_last_key = curkey; - state->m_last_key_unmodified = curkey_unmodified; + m_time_until_repeat = MAGIC_KEY_REPEAT_NUMBER; + m_last_key = curkey; + m_last_key_unmodified = curkey_unmodified; } } else { - state->m_ay3600_keys[port*8+bit] = 0; + m_ay3600_keys[port*8+bit] = 0; } } } - state->m_keymodreg &= ~AY3600_KEYMOD_REPEAT; + m_keymodreg &= ~AY3600_KEYMOD_REPEAT; if (!any_key_pressed) { /* If no keys have been pressed, reset the repeat time and return */ - state->m_time_until_repeat = MAGIC_KEY_REPEAT_NUMBER; - state->m_last_key = 0xff; - state->m_last_key_unmodified = 0xff; + m_time_until_repeat = MAGIC_KEY_REPEAT_NUMBER; + m_last_key = 0xff; + m_last_key_unmodified = 0xff; } else { /* Otherwise, count down the repeat time */ - if (state->m_time_until_repeat > 0) - state->m_time_until_repeat--; + if (m_time_until_repeat > 0) + m_time_until_repeat--; /* Even if a key has been released, repeat it if it was the last key pressed */ /* If we should output a key, set the appropriate Apple II data lines */ - if (state->m_time_until_repeat == 0 || - state->m_time_until_repeat == MAGIC_KEY_REPEAT_NUMBER-1) + if (m_time_until_repeat == 0 || + m_time_until_repeat == MAGIC_KEY_REPEAT_NUMBER-1) { - state->m_keywaiting = 1; - state->m_keycode = state->m_last_key; - state->m_keycode_unmodified = state->m_last_key_unmodified; - state->m_keymodreg |= AY3600_KEYMOD_REPEAT; + m_keywaiting = 1; + m_keycode = m_last_key; + m_keycode_unmodified = m_last_key_unmodified; + m_keymodreg |= AY3600_KEYMOD_REPEAT; } } - state->m_keystilldown = (state->m_last_key_unmodified == state->m_keycode_unmodified); + m_keystilldown = (m_last_key_unmodified == m_keycode_unmodified); } /*************************************************************************** - AY3600_keydata_strobe_r ($C00x) + AY3600_keydata_strobe_r ***************************************************************************/ -int AY3600_keydata_strobe_r(running_machine &machine) +int ay3600n_device::keydata_strobe_r() { - apple2_state *state = machine.driver_data(); int rc; - rc = state->m_keycode | (state->m_keywaiting ? 0x80 : 0x00); + rc = m_keycode | (m_keywaiting ? 0x80 : 0x00); LOG(("AY3600_keydata_strobe_r(): rc=0x%02x\n", rc)); return rc; } @@ -527,35 +495,33 @@ int AY3600_keydata_strobe_r(running_machine &machine) /*************************************************************************** - AY3600_anykey_clearstrobe_r ($C01x) + AY3600_anykey_clearstrobe_r ***************************************************************************/ -int AY3600_anykey_clearstrobe_r(running_machine &machine) +int ay3600n_device::anykey_clearstrobe_r() { - apple2_state *state = machine.driver_data(); int rc; - state->m_keywaiting = 0; - rc = state->m_keycode | (state->m_keystilldown ? 0x80 : 0x00); + m_keywaiting = 0; + rc = m_keycode | (m_keystilldown ? 0x80 : 0x00); LOG(("AY3600_anykey_clearstrobe_r(): rc=0x%02x\n", rc)); return rc; } /*************************************************************************** - AY3600_keymod_r ($C025 - IIgs only) + AY3600_keymod_r ***************************************************************************/ -int AY3600_keymod_r(running_machine &machine) +int ay3600n_device::keymod_r() { - apple2_state *state = machine.driver_data(); - return state->m_keymodreg; + return m_keymodreg; } /*************************************************************************** Natural keyboard support ***************************************************************************/ -static UINT8 AY3600_get_keycode(unicode_char ch) +UINT8 ay3600n_device::AY3600_get_keycode(unicode_char ch) { UINT8 result; @@ -587,25 +553,28 @@ static UINT8 AY3600_get_keycode(unicode_char ch) -static int AY3600_keyboard_queue_chars(running_machine &machine, const unicode_char *text, size_t text_len) +int ay3600n_device::AY3600_keyboard_queue_chars(const unicode_char *text, size_t text_len) { - apple2_state *state = machine.driver_data(); - - if (state->m_keywaiting) + if (m_keywaiting) return 0; - state->m_keycode = AY3600_get_keycode(text[0]); - state->m_keywaiting = 1; + m_keycode = AY3600_get_keycode(text[0]); + m_keywaiting = 1; return 1; } - - -static bool AY3600_keyboard_accept_char(running_machine &machine, unicode_char ch) +bool ay3600n_device::AY3600_keyboard_accept_char(unicode_char ch) { return AY3600_get_keycode(ch) != 0; } -static bool AY3600_keyboard_charqueue_empty(running_machine &machine) +bool ay3600n_device::AY3600_keyboard_charqueue_empty() { return true; } + +void ay3600n_device::set_runtime_config(bool keypad, bool repeat) +{ + m_keypad = keypad; + m_repeat = repeat; +} + diff --git a/src/mess/machine/ay3600.h b/src/mess/machine/ay3600.h index d5dd1300934..a54d2e05c85 100644 --- a/src/mess/machine/ay3600.h +++ b/src/mess/machine/ay3600.h @@ -2,7 +2,7 @@ ay3600.h - Include file for AY3600 keyboard; used by Apple IIs + Include file for AY-3600 keyboard ***************************************************************************/ @@ -19,11 +19,52 @@ #define AY3600_KEYMOD_COMMAND 0x40 #define AY3600_KEYMOD_OPTION 0x80 -/*----------- defined in machine/ay3600.c -----------*/ +//************************************************************************** +// TYPE DEFINITIONS +//************************************************************************** -int AY3600_init(running_machine &machine); -int AY3600_anykey_clearstrobe_r(running_machine &machine); -int AY3600_keydata_strobe_r(running_machine &machine); -int AY3600_keymod_r(running_machine &machine); +// ======================> ay3600n_device + +class ay3600n_device : public device_t +{ +public: + // construction/destruction + ay3600n_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); + + // interface routines + int keydata_strobe_r(); + int anykey_clearstrobe_r(); + int keymod_r(); + + // config + void set_runtime_config(bool keypad, bool repeat); + +protected: + // device-level overrides + virtual void device_start(); + virtual void device_reset(); + virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); + +private: + UINT8 AY3600_get_keycode(unicode_char ch); + int AY3600_keyboard_queue_chars(const unicode_char *text, size_t text_len); + bool AY3600_keyboard_accept_char(unicode_char ch); + bool AY3600_keyboard_charqueue_empty(); + + bool m_keypad, m_repeat; + unsigned int *m_ay3600_keys; + UINT8 m_keycode; + UINT8 m_keycode_unmodified; + UINT8 m_keywaiting; + UINT8 m_keystilldown; + UINT8 m_keymodreg; + int m_last_key; + int m_last_key_unmodified; + unsigned int m_time_until_repeat; + emu_timer *m_timer; +}; + +// device type definition +extern const device_type AY3600N; #endif /* AY3600_H */