Skip to content

Commit

Permalink
Peddle cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkwhoffmann committed Oct 2, 2024
1 parent 0953abf commit f15b3be
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 65 deletions.
28 changes: 14 additions & 14 deletions Emulator/Components/CPU/Peddle/Peddle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ template u16 Peddle::addrMask<MOS_6510>() const;
template u16 Peddle::addrMask<MOS_8502>() const;

void
Peddle::pullDownNmiLine(IntSource bit)
Peddle::pullDownNmiLine(u8 mask)
{
assert(bit != 0);

Expand All @@ -101,48 +101,48 @@ Peddle::pullDownNmiLine(IntSource bit)
edgeDetector.write(1);
}

nmiLine |= bit;
nmiLine |= mask;
}

void
Peddle::releaseNmiLine(IntSource source)
Peddle::releaseNmiLine(u8 mask)
{
nmiLine &= ~source;
nmiLine &= ~mask;
}

void
Peddle::pullDownIrqLine(IntSource source)
Peddle::pullDownIrqLine(u8 mask)
{
assert(source != 0);
assert(mask != 0);

irqLine |= source;
irqLine |= mask;
levelDetector.write(irqLine);
}

void
Peddle::releaseIrqLine(IntSource source)
Peddle::releaseIrqLine(u8 mask)
{
irqLine &= ~source;
irqLine &= ~mask;
levelDetector.write(irqLine);
}

void
Peddle::pullDownRdyLine(IntSource source)
Peddle::pullDownRdyLine(u8 mask)
{
assert(source != 0);
assert(mask != 0);

auto old = rdyLine;
rdyLine |= source;
rdyLine |= mask;
if (!old && rdyLine) rdyLineDown = clock;
}

void
Peddle::releaseRdyLine(IntSource source)
Peddle::releaseRdyLine(u8 mask)
{
assert(source != 0);

auto old = rdyLine;
rdyLine &= ~source;
rdyLine &= ~mask;
if (old && !rdyLine) rdyLineUp = clock;
}

Expand Down
49 changes: 26 additions & 23 deletions Emulator/Components/CPU/Peddle/Peddle.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,31 +98,34 @@ class Peddle : public SubComponent {

protected:

/* Ready line (RDY).
/* Ready line (RDY)
*
* The variable is usually 0 which means that the RDY line is high. If
* pulled low, that is, the variable has a value different to 0, the CPU
* freezes on the next read access.
* The variable is usually 0, indicating the RDY line is high. If the
* variable differs from 0, the RDY line is considered low. In this case,
* the CPU freezes on the next read (writes are unaffected). The variable
* is a bit mask since multiple sources can drive the RDY line low. The
* line is considered low precisely if one or more bits are set.
*/
IntSource rdyLine;
u8 rdyLine;

// Cycle of the most recent rising edge of the RDY line
i64 rdyLineUp;

// Cycle of the most recent falling edge of the RDY line
i64 rdyLineDown;

/* Interrupt lines
/* Interrupt lines (NMI and IRQ)
*
* Usally both variables equal 0 which means that the two interrupt lines
* are high. When an external component requests an interrupt, the NMI or
* the IRQ line is pulled low. In that case, the corresponding variable is
* set to a positive value which indicates the interrupt source. The
* variables are used in form of bit fields since both interrupt lines are
* driven by multiple sources.
* Usually, both variables equal 0, indicating the two interrupt lines are
* high. When an external component requests an interrupt, the NMI or the
* IRQ line is pulled low. In that case, the corresponding variable is set
* to a positive value, indicating the interrupt source. The variables are
* used as bit masks since both interrupt lines are driven by multiple
* sources. The corresponding line is considered low precisely if one or
* more bits are set.
*/
IntSource nmiLine;
IntSource irqLine;
u8 nmiLine;
u8 irqLine;

/* Edge detector (NMI line)
* https://wiki.nesdev.com/w/index.php/CPU_interrupts
Expand Down Expand Up @@ -282,19 +285,19 @@ class Peddle : public SubComponent {
public:

// Pulls down a line
void pullDownNmiLine(IntSource source);
void pullDownIrqLine(IntSource source);
void pullDownRdyLine(IntSource source);
void pullDownNmiLine(u8 mask);
void pullDownIrqLine(u8 mask);
void pullDownRdyLine(u8 mask);

// Releases a line
void releaseNmiLine(IntSource source);
void releaseIrqLine(IntSource source);
void releaseRdyLine(IntSource source);
void releaseNmiLine(u8 mask);
void releaseIrqLine(u8 mask);
void releaseRdyLine(u8 mask);

// Checks the status of a line
IntSource getNmiLine() const { return nmiLine; }
IntSource getIrqLine() const { return irqLine; }
IntSource getRdyLine() const { return rdyLine; }
u8 getNmiLine() const { return nmiLine; }
u8 getIrqLine() const { return irqLine; }
u8 getRdyLine() const { return rdyLine; }


//
Expand Down
41 changes: 22 additions & 19 deletions Emulator/Components/CPU/Peddle/PeddleExec_cpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,26 +305,29 @@ Peddle::execute()

case fetch:

// Check interrupt lines
if (unlikely(doNmi)) {

nmiWillTrigger();
IDLE_FETCH
edgeDetector.clear();
next = nmi_2;
doNmi = false;
doIrq = false; // NMI wins
return;

} else if (unlikely(doIrq)) {

irqWillTrigger();
IDLE_FETCH
next = irq_2;
doIrq = false;
return;
if constexpr (C != MOS_6507) {

// Check interrupt lines
if (unlikely(doNmi)) {

nmiWillTrigger();
IDLE_FETCH
edgeDetector.clear();
next = nmi_2;
doNmi = false;
doIrq = false; // NMI wins
return;

} else if (unlikely(doIrq)) {

irqWillTrigger();
IDLE_FETCH
next = irq_2;
doIrq = false;
return;
}
}

// Execute the Fetch phase
FETCH_OPCODE
next = actionFunc[instr];
Expand Down
7 changes: 0 additions & 7 deletions Emulator/Components/CPU/Peddle/PeddleTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ static constexpr isize V_FLAG = 0x40;
static constexpr isize N_FLAG = 0x80;


//
// Bit fields
//

// Interrupt source
typedef u8 IntSource;

/* State flags
*
* CPU_LOG_INSTRUCTION:
Expand Down
4 changes: 2 additions & 2 deletions Emulator/Media/Cartridges/CustomCartridges/Expert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ Expert::pressButton(isize nr)
u8 oldLine = cpu.getNmiLine();
u8 newLine = oldLine | INTSRC_EXP;

cpu.releaseNmiLine((IntSource)0xFF);
cpu.pullDownNmiLine((IntSource)newLine);
cpu.releaseNmiLine(0xFF);
cpu.pullDownNmiLine(newLine);
cpu.releaseNmiLine(INTSRC_EXP);
break;
}
Expand Down

0 comments on commit f15b3be

Please sign in to comment.