Skip to content

Commit

Permalink
Fixes for MC68EZ328 (#13286)
Browse files Browse the repository at this point in the history
* MC68EZ328: Allow selection and use of Port A

On EZ and VZ, PASEL is reserved, and it was hard-coded to 0 (disabled).
However, the user manual notes: "In an 8-bit-only system, you can
configure these pins as a parallel I/O port by writing a 1 to the
WDTH8 bit of the SCR."

According to the MC68328 datasheet, something similar should be needed
to activate its Port B, but that change is not included here. Its PBSEL
is exposed, so there is likely no difference in emulation.

* MC68EZ328: Fuller implementation of timer

The existing implementation left the timer counter (TCN) at zero until
the compare value (TCMP) was reached. However, some software relies on
reading the TCN values to measure elapsed time.

The timer counter (TCN) now increments on every timer tick.
  • Loading branch information
isotherm authored Jan 30, 2025
1 parent ef9a3d7 commit a56c5f8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
52 changes: 26 additions & 26 deletions src/devices/machine/mc68328.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,15 @@ u16 mc68328_device::csd_lsw_r() // 0x11e, 0x12e, 0x13e, 0x14e
// MMU/chip-select hardware - EZ variant
//-------------------------------------------------

void mc68ez328_device::scr_w(u8 data)
{
if (data & SCR_WDTH8)
{
m_pasel = 0xff;
}
mc68328_base_device::scr_w(data);
}

u8 mc68ez328_device::revision_r(offs_t offset)
{
LOGMASKED(LOG_PLL, "%s: revision_r: Silicon Revision[%d] = %02x\n", machine().describe_context(), offset, 0x01);
Expand Down Expand Up @@ -2668,7 +2677,7 @@ void mc68328_base_device::update_gptimer_state()
}
else
{
timer->adjust(attotime::from_ticks(regs.tcmp, get_timer_frequency<Timer>()));
timer->adjust(attotime::from_hz(get_timer_frequency<Timer>()));
}
}
else
Expand All @@ -2683,40 +2692,31 @@ TIMER_CALLBACK_MEMBER(mc68328_base_device::timer_tick)
timer_regs &regs = get_timer_regs(Timer);
emu_timer *timer = get_timer(Timer);

regs.tcn = regs.tcmp;
regs.tstat |= TSTAT_COMP;

if ((regs.tctl & TCTL_FRR) == TCTL_FRR_RESTART)
u32 frequency = get_timer_frequency<Timer>();
if (frequency > 0)
{
u32 frequency = get_timer_frequency<Timer>();
if (frequency > 0)
{
attotime period = attotime::from_hz(frequency) * regs.tcmp;
regs.tcn = 0x0000;
timer->adjust(period);
}
else
{
timer->adjust(attotime::never);
}
attotime period = attotime::from_hz(frequency);
timer->adjust(period);
}
else
{
u32 frequency = get_timer_frequency<Timer>();
if (frequency > 0)
timer->adjust(attotime::never);
}

regs.tcn++;
if (regs.tcn == regs.tcmp)
{
regs.tstat |= TSTAT_COMP;
if ((regs.tctl & TCTL_FRR) == TCTL_FRR_RESTART)
{
attotime period = attotime::from_hz(frequency) * 0x10000;
timer->adjust(period);
regs.tcn = 0x0000;
}
else

if ((regs.tctl & TCTL_IRQEN) == TCTL_IRQEN_ENABLE)
{
timer->adjust(attotime::never);
set_interrupt_line(get_timer_int(Timer), 1);
}
}
if ((regs.tctl & TCTL_IRQEN) == TCTL_IRQEN_ENABLE)
{
set_interrupt_line(get_timer_int(Timer), 1);
}
}

template <int Timer>
Expand Down
4 changes: 3 additions & 1 deletion src/devices/machine/mc68328.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ class mc68328_base_device : public m68000_device
RTCHMSR_HOURS_SHIFT = 24,
};

void scr_w(u8 data);
virtual void scr_w(u8 data);

void grpbasea_w(u16 data);
void grpbaseb_w(u16 data);
Expand Down Expand Up @@ -1143,6 +1143,8 @@ class mc68ez328_device : public mc68328_base_device
INT_MEMIQ_MASK = (1 << INT_MEMIQ),
};

virtual void scr_w(u8 data) override;

void csa_w(offs_t offset, u16 data, u16 mem_mask);
void csb_w(offs_t offset, u16 data, u16 mem_mask);
void csc_w(offs_t offset, u16 data, u16 mem_mask);
Expand Down

0 comments on commit a56c5f8

Please sign in to comment.