attotime: Add to_string() to get a human-readable version of the time [O. Galibert]

6522via: Correct vocabulary, raise cb2 on shift in to make open-collector work correctly [O. Galibert]
mackbd: Fix/partially rewrite [O. Galibert]
mac128: Make emulated keyboard work [O. Galibert]
This commit is contained in:
Olivier Galibert 2020-05-06 13:24:42 +02:00
parent 310a4f9a36
commit 1921d81e64
6 changed files with 153 additions and 145 deletions

View File

@ -19,7 +19,7 @@
2017-Feb-15 Edstrom 2017-Feb-15 Edstrom
Fixed shift registers to be more accurate, eg 50/50 duty cycle, latching Fixed shift registers to be more accurate, eg 50/50 duty cycle, latching
on correct flanks and leading and trailing flanks added + logging. on correct edges and leading and trailing edges added + logging.
*/ */
#include "emu.h" #include "emu.h"
@ -386,7 +386,7 @@ void via6522_device::clear_int(int data)
void via6522_device::shift_out() void via6522_device::shift_out()
{ {
// Only shift out msb on falling flank // Only shift out msb on falling edge
if (m_shift_counter & 1) if (m_shift_counter & 1)
{ {
LOGSHIFT(" %s shift Out SR: %02x->", tag(), m_sr); LOGSHIFT(" %s shift Out SR: %02x->", tag(), m_sr);
@ -399,26 +399,26 @@ void via6522_device::shift_out()
if (m_shift_counter == 1 && SO_EXT_CONTROL(m_acr)) if (m_shift_counter == 1 && SO_EXT_CONTROL(m_acr))
{ {
LOGINT("SHIFT EXT out INT request "); LOGINT("SHIFT EXT out INT request ");
set_int(INT_SR); // IRQ on last falling flank for external clock (mode 7) set_int(INT_SR); // IRQ on last falling edge for external clock (mode 7)
} }
} }
else // Check for INT condition, eg the last and raising flank of the 15-0 falling/raising flanks else // Check for INT condition, eg the last and raising edge of the 15-0 falling/raising edges
{ {
if (!SO_T2_RATE(m_acr)) // The T2 continous shifter doesn't do interrupts (mode 4) if (!SO_T2_RATE(m_acr)) // The T2 continous shifter doesn't do interrupts (mode 4)
{ {
if (m_shift_counter == 0 && (SO_O2_CONTROL(m_acr) || SO_T2_CONTROL(m_acr))) if (m_shift_counter == 0 && (SO_O2_CONTROL(m_acr) || SO_T2_CONTROL(m_acr)))
{ {
LOGINT("SHIFT O2/T2 out INT request "); LOGINT("SHIFT O2/T2 out INT request ");
set_int(INT_SR); // IRQ on last raising flank for internal clock (mode 5-6) set_int(INT_SR); // IRQ on last raising edge for internal clock (mode 5-6)
} }
} }
} }
m_shift_counter = (m_shift_counter - 1) & 0x0f; // Count all flanks m_shift_counter = (m_shift_counter - 1) & 0x0f; // Count all edges
} }
void via6522_device::shift_in() void via6522_device::shift_in()
{ {
// Only shift in data on raising flank // Only shift in data on raising edge
if ( !(m_shift_counter & 1) ) if ( !(m_shift_counter & 1) )
{ {
LOGSHIFT("%s shift In SR: %02x->", tag(), m_sr); LOGSHIFT("%s shift In SR: %02x->", tag(), m_sr);
@ -429,10 +429,10 @@ void via6522_device::shift_in()
{ {
LOGINT("SHIFT in INT request "); LOGINT("SHIFT in INT request ");
// set_int(INT_SR);// TODO: this interrupt is 1-2 clock cycles too early // set_int(INT_SR);// TODO: this interrupt is 1-2 clock cycles too early
m_shift_irq_timer->adjust(clocks_to_attotime(2)/2); // Delay IRQ 2 flanks for all shift INs (mode 1-3) m_shift_irq_timer->adjust(clocks_to_attotime(2)/2); // Delay IRQ 2 edges for all shift INs (mode 1-3)
} }
} }
m_shift_counter = (m_shift_counter - 1) & 0x0f; // Count all flanks m_shift_counter = (m_shift_counter - 1) & 0x0f; // Count all edges
} }
void via6522_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) void via6522_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
@ -440,7 +440,7 @@ void via6522_device::device_timer(emu_timer &timer, device_timer_id id, int para
switch (id) switch (id)
{ {
case TIMER_SHIFT_IRQ: // This timer event is a delayed IRQ for improved cycle accuracy case TIMER_SHIFT_IRQ: // This timer event is a delayed IRQ for improved cycle accuracy
set_int(INT_SR); // triggered from shift_in or shift_out on the last rising flank set_int(INT_SR); // triggered from shift_in or shift_out on the last rising edge
m_shift_irq_timer->adjust(attotime::never); // Not needed really... m_shift_irq_timer->adjust(attotime::never); // Not needed really...
break; break;
case TIMER_SHIFT: case TIMER_SHIFT:
@ -448,7 +448,7 @@ void via6522_device::device_timer(emu_timer &timer, device_timer_id id, int para
m_out_cb1 ^= 1; m_out_cb1 ^= 1;
m_cb1_handler(m_out_cb1); m_cb1_handler(m_out_cb1);
// we call shift methods for all flanks // we call shift methods for all edges
if (SO_T2_RATE(m_acr) || SO_T2_CONTROL(m_acr) || SO_O2_CONTROL(m_acr)) if (SO_T2_RATE(m_acr) || SO_T2_CONTROL(m_acr) || SO_O2_CONTROL(m_acr))
{ {
shift_out(); shift_out();
@ -711,7 +711,7 @@ u8 via6522_device::read(offs_t offset)
LOGSHIFT(" - ACR: %02x ", m_acr); LOGSHIFT(" - ACR: %02x ", m_acr);
if (SI_O2_CONTROL(m_acr) || SO_O2_CONTROL(m_acr)) if (SI_O2_CONTROL(m_acr) || SO_O2_CONTROL(m_acr))
{ {
m_shift_timer->adjust(clocks_to_attotime(8) / 2); // 8 flanks to start shifter from a read m_shift_timer->adjust(clocks_to_attotime(8) / 2); // 8 edges to start shifter from a read
LOGSHIFT(" - read SR starts O2 timer "); LOGSHIFT(" - read SR starts O2 timer ");
} }
else if (SI_T2_CONTROL(m_acr) || SO_T2_CONTROL(m_acr)) else if (SI_T2_CONTROL(m_acr) || SO_T2_CONTROL(m_acr))
@ -903,7 +903,7 @@ void via6522_device::write(offs_t offset, u8 data)
LOGSHIFT(" - ACR is: %02x ", m_acr); LOGSHIFT(" - ACR is: %02x ", m_acr);
if (SO_O2_CONTROL(m_acr) || SI_O2_CONTROL(m_acr)) if (SO_O2_CONTROL(m_acr) || SI_O2_CONTROL(m_acr))
{ {
m_shift_timer->adjust(clocks_to_attotime(8) / 2); // 8 flanks to start shifter from a write m_shift_timer->adjust(clocks_to_attotime(8) / 2); // 8 edges to start shifter from a write
LOGSHIFT(" - write SR starts O2 timer"); LOGSHIFT(" - write SR starts O2 timer");
} }
else if (SO_T2_RATE(m_acr) || SO_T2_CONTROL(m_acr) || SI_T2_CONTROL(m_acr)) else if (SO_T2_RATE(m_acr) || SO_T2_CONTROL(m_acr) || SI_T2_CONTROL(m_acr))
@ -966,6 +966,13 @@ void via6522_device::write(offs_t offset, u8 data)
m_t1->adjust(clocks_to_attotime(counter1 + IFR_DELAY)); m_t1->adjust(clocks_to_attotime(counter1 + IFR_DELAY));
m_t1_active = 1; m_t1_active = 1;
} }
if (SI_T2_CONTROL(m_acr) || SI_O2_CONTROL(m_acr) || SI_EXT_CONTROL(m_acr))
{
m_out_cb2 = 1;
m_cb2_handler(m_out_cb2);
}
LOGSHIFT("\n"); LOGSHIFT("\n");
} }
break; break;

View File

@ -153,3 +153,20 @@ const char *attotime::as_string(int precision) const
} }
return buffer; return buffer;
} }
//-------------------------------------------------
// to_string - return a human-readable string
// describing an attotime for use in logs
//-------------------------------------------------
std::string attotime::to_string() const
{
attotime t = *this;
const char *sign = "";
if(t.seconds() < 0) {
t = attotime::zero-t;
sign = "-";
}
int nsec = t.attoseconds() / ATTOSECONDS_PER_NANOSECOND;
return util::string_format("%s%04d.%03d,%03d,%03d", sign, int(t.seconds()), nsec/1000000, (nsec/1000)%1000, nsec % 1000);
}

View File

@ -122,6 +122,9 @@ public:
/** Convert to string using at @p precision */ /** Convert to string using at @p precision */
const char *as_string(int precision = 9) const; const char *as_string(int precision = 9) const;
/** Convert to string for human readability in logs */
std::string to_string() const;
/** @return the attoseconds portion. */ /** @return the attoseconds portion. */
constexpr attoseconds_t attoseconds() const noexcept { return m_attoseconds; } constexpr attoseconds_t attoseconds() const noexcept { return m_attoseconds; }
/** @return the seconds portion. */ /** @return the seconds portion. */

View File

@ -115,7 +115,7 @@ c0 8 data bits, Rx disabled
#define C3_7M (15.6672_MHz_XTAL / 4).value() #define C3_7M (15.6672_MHz_XTAL / 4).value()
// uncomment to run i8021 keyboard in original Mac/512(e)/Plus // uncomment to run i8021 keyboard in original Mac/512(e)/Plus
//#define MAC_USE_EMULATED_KBD (1) #define MAC_USE_EMULATED_KBD (1)
/* tells which model is being emulated (set by macxxx_init) */ /* tells which model is being emulated (set by macxxx_init) */
enum mac128model_t enum mac128model_t
@ -958,14 +958,12 @@ void mac128_state::keyboard_init()
WRITE_LINE_MEMBER(mac128_state::mac_kbd_clk_in) WRITE_LINE_MEMBER(mac128_state::mac_kbd_clk_in)
{ {
printf("CLK: %d\n", state^1);
m_via->write_cb1(state ? 0 : 1); m_via->write_cb1(state ? 0 : 1);
} }
WRITE_LINE_MEMBER(mac128_state::mac_via_out_cb2) WRITE_LINE_MEMBER(mac128_state::mac_via_out_cb2)
{ {
printf("Sending %d to kbd (PC=%x)\n", state, m_maincpu->pc()); m_mackbd->datain_w(state);
m_mackbd->data_w(state ? ASSERT_LINE : CLEAR_LINE);
} }
#else // keyboard HLE #else // keyboard HLE

View File

@ -19,7 +19,7 @@
Port 0: Port 0:
x------- Clock to Mac x------- Clock, pulled up, driven by the 8021
-x------ Caps Lock -x------ Caps Lock
--x----- Row 5 readback (tied to Vcc for keypad) --x----- Row 5 readback (tied to Vcc for keypad)
---x---- Row 4 readback ---x---- Row 4 readback
@ -43,7 +43,7 @@
x--- Command/Apple x--- Command/Apple
-x-- Shift -x-- Shift
--x- Column 0 strobe --x- Column 0 strobe
---x Data to Mac ---x Data, pulled up, driven by both sides
The T1 line is "Option". The T1 line is "Option".
@ -78,76 +78,76 @@ ROM_END
static INPUT_PORTS_START( mackbd ) static INPUT_PORTS_START( mackbd )
PORT_START("COL0") PORT_START("COL0")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G') PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_G) PORT_CHAR('g') PORT_CHAR('G')
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H') PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_H) PORT_CHAR('h') PORT_CHAR('H')
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F') PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_F) PORT_CHAR('f') PORT_CHAR('F')
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_D) PORT_CHAR('d') PORT_CHAR('D')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_S) PORT_CHAR('s') PORT_CHAR('S')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A) PORT_CHAR('a') PORT_CHAR('A') PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_A) PORT_CHAR('a') PORT_CHAR('A')
PORT_START("COL1") PORT_START("COL1")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B) PORT_CHAR('b') PORT_CHAR('B') PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_B) PORT_CHAR('b') PORT_CHAR('B')
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_UNKNOWN) PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN)
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V') PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_V) PORT_CHAR('v') PORT_CHAR('V')
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_C) PORT_CHAR('c') PORT_CHAR('C')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_X) PORT_CHAR('x') PORT_CHAR('X')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z') PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Z) PORT_CHAR('z') PORT_CHAR('Z')
PORT_START("COL2") PORT_START("COL2")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T') PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_T) PORT_CHAR('t') PORT_CHAR('T')
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y') PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Y) PORT_CHAR('y') PORT_CHAR('Y')
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R') PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_R) PORT_CHAR('r') PORT_CHAR('R')
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_E) PORT_CHAR('e') PORT_CHAR('E')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_W) PORT_CHAR('w') PORT_CHAR('W')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q') PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_Q) PORT_CHAR('q') PORT_CHAR('Q')
PORT_START("COL3") PORT_START("COL3")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%') PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_5) PORT_CHAR('5') PORT_CHAR('%')
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('^') PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_6) PORT_CHAR('6') PORT_CHAR('^')
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$') PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_4) PORT_CHAR('4') PORT_CHAR('$')
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_3) PORT_CHAR('3') PORT_CHAR('#')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('@') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_2) PORT_CHAR('2') PORT_CHAR('@')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!') PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_1) PORT_CHAR('1') PORT_CHAR('!')
PORT_START("COL4") PORT_START("COL4")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')') PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_0) PORT_CHAR('0') PORT_CHAR(')')
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('*') PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_8) PORT_CHAR('8') PORT_CHAR('*')
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('_') PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_MINUS) PORT_CHAR('-') PORT_CHAR('_')
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_7) PORT_CHAR('7') PORT_CHAR('&')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR('(') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_9) PORT_CHAR('9') PORT_CHAR('(')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS) PORT_CHAR('=') PORT_CHAR('+') PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_EQUALS) PORT_CHAR('=') PORT_CHAR('+')
PORT_START("COL5") PORT_START("COL5")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P') PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_P) PORT_CHAR('p') PORT_CHAR('P')
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I') PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_I) PORT_CHAR('i') PORT_CHAR('I')
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('[') PORT_CHAR('{') PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_OPENBRACE) PORT_CHAR('[') PORT_CHAR('{')
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_U) PORT_CHAR('u') PORT_CHAR('U')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_O) PORT_CHAR('o') PORT_CHAR('O')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE) PORT_CHAR(']') PORT_CHAR('}') PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_CLOSEBRACE) PORT_CHAR(']') PORT_CHAR('}')
PORT_START("COL6") PORT_START("COL6")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON) PORT_CHAR(';') PORT_CHAR(':') PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COLON) PORT_CHAR(';') PORT_CHAR(':')
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K') PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_K) PORT_CHAR('k') PORT_CHAR('K')
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR('\'') PORT_CHAR('"') PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_QUOTE) PORT_CHAR('\'') PORT_CHAR('"')
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_J) PORT_CHAR('j') PORT_CHAR('J')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_L) PORT_CHAR('l') PORT_CHAR('L')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ENTER) PORT_CHAR('\r') PORT_NAME("Return") PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_ENTER) PORT_CHAR('\r') PORT_NAME("Return")
PORT_START("COL7") PORT_START("COL7")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>') PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_STOP) PORT_CHAR('.') PORT_CHAR('>')
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M') PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_M) PORT_CHAR('m') PORT_CHAR('M')
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N') PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_N) PORT_CHAR('n') PORT_CHAR('N')
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SLASH) PORT_CHAR('/') PORT_CHAR('?')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_COMMA) PORT_CHAR(',') PORT_CHAR('<')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH) PORT_CHAR('\\') PORT_CHAR('|') PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSLASH) PORT_CHAR('\\') PORT_CHAR('|')
PORT_START("COL8") PORT_START("COL8")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_UNKNOWN) PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_UNKNOWN)
PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_UNKNOWN) PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_UNKNOWN)
PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8) PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_BACKSPACE) PORT_CHAR(8)
PORT_BIT(0x0008, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TILDE) PORT_CHAR('`') PORT_CHAR('~') PORT_BIT(0x0004, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TILDE) PORT_CHAR('`') PORT_CHAR('~')
PORT_BIT(0x0010, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ') PORT_BIT(0x0002, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_SPACE) PORT_CHAR(' ')
PORT_BIT(0x0020, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TAB) PORT_CHAR('\t') PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_CODE(KEYCODE_TAB) PORT_CHAR('\t')
PORT_START("MODS") PORT_START("MODS")
PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Caps Lock") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE PORT_BIT(0x0001, IP_ACTIVE_LOW, IPT_KEYBOARD) PORT_NAME("Caps Lock") PORT_CODE(KEYCODE_CAPSLOCK) PORT_TOGGLE
@ -193,6 +193,7 @@ ioport_constructor mackbd_device::device_input_ports() const
mackbd_device::mackbd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) : mackbd_device::mackbd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
device_t(mconfig, MACKBD, tag, owner, clock), device_t(mconfig, MACKBD, tag, owner, clock),
m_maincpu(*this, MACKBD_CPU_TAG), m_maincpu(*this, MACKBD_CPU_TAG),
m_col(*this, "COL%u", 0U),
m_clkout_handler(*this), m_clkout_handler(*this),
m_dataout_handler(*this) m_dataout_handler(*this)
{ {
@ -205,6 +206,8 @@ mackbd_device::mackbd_device(const machine_config &mconfig, const char *tag, dev
void mackbd_device::device_start() void mackbd_device::device_start()
{ {
m_clkout_handler.resolve_safe(); m_clkout_handler.resolve_safe();
m_dataout_handler.resolve_safe();
m_sync = timer_alloc(0);
} }
@ -214,92 +217,71 @@ void mackbd_device::device_start()
void mackbd_device::device_reset() void mackbd_device::device_reset()
{ {
p0 = p1 = p2 = 0; p0 = p1 = p2 = 0xff;
p0 = 0x3f; datain = true;
data_from_mac = data_to_mac = 0; m_clkout_handler(1);
m_dataout_handler(1);
} }
void mackbd_device::scan_kbd_col(int col) u8 mackbd_device::p0_r()
{ {
char tempcol[8]; u8 ret = p0;
uint16_t keydata;
// read the selected col for(int i=0; i<8; i++)
sprintf(tempcol, "COL%d", col); if(!(p1 & (1<<i)))
keydata = ioport(tempcol)->read(); ret &= m_col[i+1]->read();
p0 &= ~0x3f; if(!(p2 & 0x02))
p0 |= (keydata & 0x3f); ret &= m_col[0]->read();
// set modifier bits in p2
p2 = ioport("MODS")->read() & 0xc;
}
uint8_t mackbd_device::p0_r()
{
uint8_t ret = p0;
// capslock // capslock
if (ioport("MODS")->read() & 0x1) if(!ioport("MODS")->read() & 0x1)
{ ret &= ~0x40;
ret |= 0x40;
}
return ret; return ret;
} }
void mackbd_device::p0_w(uint8_t data) void mackbd_device::p0_w(u8 data)
{ {
if (!(data & 2)) u8 delta = p0 ^ data;
{ p0 = data;
scan_kbd_col(0);
}
if (data & 0x80) if(delta & 0x80)
{ m_sync->adjust(attotime::zero);
m_clkout_handler(ASSERT_LINE);
}
else
{
m_clkout_handler(CLEAR_LINE);
// machine().scheduler().boost_interleave(attotime::zero, attotime::from_usec(10));
}
} }
uint8_t mackbd_device::p1_r() void mackbd_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
m_clkout_handler(p0 & 0x80 ? ASSERT_LINE : CLEAR_LINE);
}
u8 mackbd_device::p1_r()
{ {
return p1; return p1;
} }
void mackbd_device::p1_w(uint8_t data) void mackbd_device::p1_w(u8 data)
{ {
data ^= 0xff; p1 = data;
if (data & 0x01) scan_kbd_col(1);
if (data & 0x02) scan_kbd_col(2);
if (data & 0x04) scan_kbd_col(3);
if (data & 0x08) scan_kbd_col(4);
if (data & 0x10) scan_kbd_col(5);
if (data & 0x20) scan_kbd_col(6);
if (data & 0x40) scan_kbd_col(7);
if (data & 0x80) scan_kbd_col(8);
} }
uint8_t mackbd_device::p2_r() u8 mackbd_device::p2_r()
{ {
return p2 | data_from_mac; // Keypad has bit 5 connected to GND, but this is the keyboard.
u8 ret = p2;
if(!datain)
ret &= 0xfe;
ret &= ioport("MODS")->read() | ~0x0c;
return ret;
} }
void mackbd_device::p2_w(uint8_t data) void mackbd_device::p2_w(u8 data)
{ {
// prevent key scan accesses to the port from messing with the data line (how does this work on h/w?) p2 = data;
if (m_maincpu->pc() != 0x19e && m_maincpu->pc() != 0x1a3) m_dataout_handler(p2 & datain & 1);
{
data_to_mac = data_from_mac = (data & 1);
// printf("data to/from mac = %d (PC=%x)\n", data_to_mac, m_maincpu->pc());
}
} }
WRITE_LINE_MEMBER(mackbd_device::data_w) void mackbd_device::datain_w(int state)
{ {
data_from_mac = (state == ASSERT_LINE) ? 1 : 0; datain = state;
} }

View File

@ -18,14 +18,11 @@ public:
// config helper // config helper
auto clkout_handler() { return m_clkout_handler.bind(); } auto clkout_handler() { return m_clkout_handler.bind(); }
auto dataout_handler() { return m_dataout_handler.bind(); } auto dataout_handler() { return m_dataout_handler.bind(); }
void datain_w(int state);
// construction/destruction // construction/destruction
mackbd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock); mackbd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock);
void p0_w(uint8_t data);
DECLARE_WRITE_LINE_MEMBER(data_w);
protected: protected:
// device-level overrides // device-level overrides
virtual void device_start() override; virtual void device_start() override;
@ -33,22 +30,26 @@ protected:
virtual void device_add_mconfig(machine_config &config) override; virtual void device_add_mconfig(machine_config &config) override;
virtual const tiny_rom_entry *device_rom_region() const override; virtual const tiny_rom_entry *device_rom_region() const override;
virtual ioport_constructor device_input_ports() const override; virtual ioport_constructor device_input_ports() const override;
virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
required_device<cpu_device> m_maincpu;
private: private:
uint8_t p0, p1, p2, data_from_mac, data_to_mac; required_device<cpu_device> m_maincpu;
required_ioport_array<9> m_col;
devcb_write_line m_clkout_handler; devcb_write_line m_clkout_handler;
devcb_write_line m_dataout_handler; devcb_write_line m_dataout_handler;
emu_timer *m_sync;
u8 p0, p1, p2;
bool datain;
void scan_kbd_col(int col); void scan_kbd_col(int col);
uint8_t p0_r(); u8 p0_r();
uint8_t p1_r(); void p0_w(u8 data);
void p1_w(uint8_t data); u8 p1_r();
uint8_t p2_r(); void p1_w(u8 data);
void p2_w(uint8_t data); u8 p2_r();
void p2_w(u8 data);
}; };
// device type definition // device type definition