Skip to content

Commit

Permalink
apple/adbmodem.cpp: Fixed clock to the SCC 3.68 MHz from the schemati…
Browse files Browse the repository at this point in the history
…cs, brings ADB timings exactly to spec. [R. Belmont]

apple/macii.cpp, apple/maciici.cpp: With the adjusted timings, adbmodem now works with the Mac II/IIx/IIcx/IIci, and SE/30.
      This corrects the jerky mouse movements caused by macadb HLE mode (GitHub issue #12189). [R. Belmont]

apple/maciifx.cpp: Corrected ADB hookup, PIC now transmits valid ADB but doesn't appear to receive it. [R. Belmont]
  • Loading branch information
rb6502 committed Jun 11, 2024
1 parent f3886a1 commit ca90696
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/mame/apple/adbmodem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void adbmodem_device::adbmodem_map(address_map &map)

void adbmodem_device::device_add_mconfig(machine_config &config)
{
PIC1654S(config, m_maincpu, 15.6672_MHz_XTAL/4);
PIC1654S(config, m_maincpu, 3.6864_MHz_XTAL);
m_maincpu->set_addrmap(AS_PROGRAM, &adbmodem_device::adbmodem_map);
m_maincpu->read_a().set(FUNC(adbmodem_device::porta_r));
m_maincpu->write_a().set(FUNC(adbmodem_device::porta_w));
Expand Down
2 changes: 0 additions & 2 deletions src/mame/apple/apple2gs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,6 @@ TIMER_DEVICE_CALLBACK_MEMBER(apple2gs_state::apple2_interrupt)

if (scanline == (192+BORDER_TOP))
{
m_macadb->adb_vblank();
m_vbl = true;

// VBL interrupt
Expand Down Expand Up @@ -3794,7 +3793,6 @@ void apple2gs_state::apple2gs(machine_config &config)
m_adbmicro->write_p<3>().set(FUNC(apple2gs_state::adbmicro_p3_out));

MACADB(config, m_macadb, A2GS_MASTER_CLOCK/8);
m_macadb->set_mcu_mode(true);
m_macadb->adb_data_callback().set(FUNC(apple2gs_state::set_adb_line));

RTC3430042(config, m_rtc, XTAL(32'768));
Expand Down
32 changes: 0 additions & 32 deletions src/mame/apple/macii.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ namespace {
#define MAC_H_TOTAL (704) // (512+192)
#define MAC_V_TOTAL (370) // (342+28)

#define MACII_USE_ADBMODEM (0)

// Mac driver data

class mac_state:public driver_device
Expand Down Expand Up @@ -212,7 +210,6 @@ class mac_state:public driver_device

TIMER_CALLBACK_MEMBER(mac_adbrefresh_tick);
TIMER_CALLBACK_MEMBER(mac_scanline_tick);
void mac_adb_via_out_cb2(int state);
uint8_t mac_via_in_a();
uint8_t mac_via_in_b();
void mac_via_out_a(uint8_t data);
Expand Down Expand Up @@ -537,17 +534,6 @@ void mac_state::mac_iwm_w(offs_t offset, uint16_t data, uint16_t mem_mask)
m_maincpu->adjust_icount(-5);
}

void mac_state::mac_adb_via_out_cb2(int state)
{
// printf("VIA OUT CB2 = %x\n", state);
#if !MACII_USE_ADBMODEM
if (m_macadb)
{
m_macadb->adb_data_w(state);
}
#endif
}

/* *************************************************************************
* VIA
* *************************************************************************
Expand Down Expand Up @@ -610,10 +596,6 @@ uint8_t mac_state::mac_via_in_b()
{
int val = 0;

#if !MACII_USE_ADBMODEM
val |= m_macadb->get_adb_state() << 4;
#endif

if (!m_adb_irq_pending)
{
val |= 0x08;
Expand Down Expand Up @@ -651,11 +633,7 @@ void mac_state::mac_via_out_b(uint8_t data)
}
}

#if MACII_USE_ADBMODEM
m_adbmodem->set_via_state((data & 0x30) >> 4);
#else
m_macadb->mac_adb_newaction((data & 0x30) >> 4);
#endif

m_rtc->ce_w((data & 0x04) >> 2);
m_rtc->data_w(data & 0x01);
Expand Down Expand Up @@ -1113,7 +1091,6 @@ void mac_state::macii(machine_config &config)
m_via1->readpb_handler().set(FUNC(mac_state::mac_via_in_b));
m_via1->writepa_handler().set(FUNC(mac_state::mac_via_out_a));
m_via1->writepb_handler().set(FUNC(mac_state::mac_via_out_b));
m_via1->cb2_handler().set(FUNC(mac_state::mac_adb_via_out_cb2));
m_via1->irq_handler().set(FUNC(mac_state::mac_via_irq));

R65NC22(config, m_via2, C7M/10);
Expand All @@ -1123,25 +1100,16 @@ void mac_state::macii(machine_config &config)
m_via2->writepb_handler().set(FUNC(mac_state::mac_via2_out_b));
m_via2->irq_handler().set(FUNC(mac_state::mac_via2_irq));

#if MACII_USE_ADBMODEM
ADBMODEM(config, m_adbmodem, C7M);
m_adbmodem->via_clock_callback().set(m_via1, FUNC(via6522_device::write_cb1));
m_adbmodem->via_data_callback().set(m_via1, FUNC(via6522_device::write_cb2));
m_adbmodem->linechange_callback().set(m_macadb, FUNC(macadb_device::adb_linechange_w));
m_adbmodem->irq_callback().set(FUNC(mac_state::adb_irq_w));
m_via1->cb2_handler().set(m_adbmodem, FUNC(adbmodem_device::set_via_data));
config.set_perfect_quantum(m_maincpu);
#endif

MACADB(config, m_macadb, C15M);
#if !MACII_USE_ADBMODEM
m_macadb->set_mcu_mode(false);
m_macadb->via_clock_callback().set(m_via1, FUNC(via6522_device::write_cb1));
m_macadb->via_data_callback().set(m_via1, FUNC(via6522_device::write_cb2));
m_macadb->adb_irq_callback().set(FUNC(mac_state::adb_irq_w));
#else
m_macadb->adb_data_callback().set(m_adbmodem, FUNC(adbmodem_device::set_adb_line));
#endif

RAM(config, m_ram);
m_ram->set_default_size("2M");
Expand Down
40 changes: 26 additions & 14 deletions src/mame/apple/maciici.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "emu.h"

#include "adbmodem.h"
#include "egret.h"
#include "macadb.h"
#include "macrtc.h"
Expand Down Expand Up @@ -58,6 +59,7 @@ class maciici_state : public driver_device
m_rbv(*this, "rbv"),
m_macadb(*this, "macadb"),
m_ram(*this, RAM_TAG),
m_adbmodem(*this, "adbmodem"),
m_asc(*this, "asc"),
m_scsibus1(*this, "scsi"),
m_ncr5380(*this, "scsi:7:ncr5380"),
Expand All @@ -70,6 +72,7 @@ class maciici_state : public driver_device
{
}

void maciixi_base(machine_config &config);
void maciici(machine_config &config);
void maciisi(machine_config &config);

Expand All @@ -83,6 +86,7 @@ class maciici_state : public driver_device
required_device<rbv_device> m_rbv;
required_device<macadb_device> m_macadb;
required_device<ram_device> m_ram;
optional_device<adbmodem_device> m_adbmodem;
required_device<asc_device> m_asc;
required_device<nscsi_bus_device> m_scsibus1;
required_device<ncr5380_device> m_ncr5380;
Expand Down Expand Up @@ -340,15 +344,13 @@ uint8_t maciici_state::via_in_a_iisi()

uint8_t maciici_state::via_in_b()
{
u8 val = m_macadb->get_adb_state() << 4;
u8 val = m_rtc->data_r();

if (!m_adb_irq_pending)
{
val |= 0x08;
}

val |= m_rtc->data_r();

return val;
}

Expand All @@ -373,9 +375,9 @@ void maciici_state::via_out_a(uint8_t data)
void maciici_state::via_out_b(uint8_t data)
{
// printf("%s VIA1 OUT B: %02x\n", machine().describe_context().c_str(), data);
m_macadb->mac_adb_newaction((data & 0x30) >> 4);
m_adbmodem->set_via_state((data & 0x30) >> 4);

m_rtc->ce_w(BIT(data, 2));
m_rtc->ce_w(BIT(data, 2));
m_rtc->data_w(BIT(data, 0));
m_rtc->clk_w(BIT(data, 1));
}
Expand All @@ -388,7 +390,7 @@ void maciici_state::via_out_b_iisi(uint8_t data)

void maciici_state::via_out_cb2(int state)
{
m_macadb->adb_data_w(state);
// m_macadb->adb_data_w(state);
}

void maciici_state::via_out_cb2_iisi(int state)
Expand Down Expand Up @@ -503,7 +505,7 @@ INPUT_PORTS_END
/***************************************************************************
MACHINE DRIVERS
***************************************************************************/
void maciici_state::maciici(machine_config &config)
void maciici_state::maciixi_base(machine_config &config)
{
M68030(config, m_maincpu, 25000000);
m_maincpu->set_addrmap(AS_PROGRAM, &maciici_state::maciici_map);
Expand Down Expand Up @@ -610,29 +612,39 @@ void maciici_state::maciici(machine_config &config)
NUBUS_SLOT(config, "nbc", "nubus", mac_nubus_cards, nullptr);
NUBUS_SLOT(config, "nbd", "nubus", mac_nubus_cards, nullptr);
NUBUS_SLOT(config, "nbe", "nubus", mac_nubus_cards, nullptr);
}

void maciici_state::maciici(machine_config &config)
{
maciixi_base(config);

ADBMODEM(config, m_adbmodem, C7M);
m_adbmodem->via_clock_callback().set(m_via1, FUNC(via6522_device::write_cb1));
m_adbmodem->via_data_callback().set(m_via1, FUNC(via6522_device::write_cb2));
m_adbmodem->linechange_callback().set(m_macadb, FUNC(macadb_device::adb_linechange_w));
m_adbmodem->irq_callback().set(FUNC(maciici_state::adb_irq_w));
m_via1->cb2_handler().set(m_adbmodem, FUNC(adbmodem_device::set_via_data));
config.set_perfect_quantum(m_maincpu);

MACADB(config, m_macadb, C15M);
m_macadb->set_mcu_mode(false);
m_macadb->via_clock_callback().set(m_via1, FUNC(via6522_device::write_cb1));
m_macadb->via_data_callback().set(m_via1, FUNC(via6522_device::write_cb2));
m_macadb->adb_irq_callback().set(FUNC(maciici_state::adb_irq_w));
m_macadb->adb_data_callback().set(m_adbmodem, FUNC(adbmodem_device::set_adb_line));
}

void maciici_state::maciisi(machine_config &config)
{
maciici(config);
maciixi_base(config);

M68030(config.replace(), m_maincpu, 20000000);
m_maincpu->set_addrmap(AS_PROGRAM, &maciici_state::maciici_map);
m_maincpu->set_dasm_override(std::function(&mac68k_dasm_override), "mac68k_dasm_override");

MACADB(config.replace(), m_macadb, C15M);

m_via1->readpa_handler().set(FUNC(maciici_state::via_in_a_iisi));
m_via1->readpb_handler().set(FUNC(maciici_state::via_in_b_iisi));
m_via1->writepb_handler().set(FUNC(maciici_state::via_out_b_iisi));
m_via1->cb2_handler().set(FUNC(maciici_state::via_out_cb2_iisi));

MACADB(config, m_macadb, C15M);

EGRET(config, m_egret, XTAL(32'768));
m_egret->set_default_bios_tag("344s0100");
m_egret->reset_callback().set(FUNC(maciici_state::egret_reset_w));
Expand Down
2 changes: 1 addition & 1 deletion src/mame/apple/maciifx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ void maciifx_state::maciifx(machine_config &config)
swimpic.prd_callback().set(m_fdc, FUNC(applefdintf_device::read));
swimpic.pwr_callback().set(m_fdc, FUNC(applefdintf_device::write));
swimpic.hint_callback().set(FUNC(maciifx_state::oss_interrupt<6>));
swimpic.gpout0_callback().set(m_macadb, FUNC(macadb_device::adb_data_w));
swimpic.gpout0_callback().set(m_macadb, FUNC(macadb_device::adb_linechange_w)).invert();
swimpic.gpin_callback().set(FUNC(maciifx_state::adbin_r));

m_fdc->dat1byte_cb().set("swimpic", FUNC(applepic_device::reqa_w));
Expand Down

0 comments on commit ca90696

Please sign in to comment.