Skip to content

Commit 960035b

Browse files
committed
update latch
1 parent 77b82dc commit 960035b

File tree

4 files changed

+63
-25
lines changed

4 files changed

+63
-25
lines changed

CpuCommon.h

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,71 @@
11
#pragma once
22

3+
// Copyright 2015 by Joseph Forgion
4+
// This file is part of VCC (Virtual Color Computer).
35
//
4-
// access cc flags
6+
// VCC (Virtual Color Computer) is free software: you can redistribute it and/or
7+
// modify it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// VCC (Virtual Color Computer) is distributed in the hope that it will be
12+
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License along
17+
// with VCC. If not, see <http://www.gnu.org/licenses/>.
18+
//
19+
// 2025/05/22 - Craig Allsop - Interrupt handling.
20+
//
21+
22+
// no includes here, included by 6809.c, 6309.c
23+
24+
//
25+
// Access cc flags as boolean
526
//
627
static inline bool CC(char flag)
728
{
829
return cc[flag] ? true : false;
930
}
1031

1132
//
12-
// interrupt lines (active low)
33+
// Interrupt lines reading from output of the latch
1334
//
14-
static inline bool FIRQ() { return InterruptLatch & Bit(INT_FIRQ) ? true : false; }
15-
static inline bool IRQ() { return InterruptLatch & Bit(INT_IRQ) ? true : false; }
16-
static inline bool NMI() { return InterruptLatch & Bit(INT_NMI) ? true : false; }
35+
static inline bool FIRQ() { return InterruptLatch.Q & Bit(INT_FIRQ) ? true : false; }
36+
static inline bool IRQ() { return InterruptLatch.Q & Bit(INT_IRQ) ? true : false; }
37+
static inline bool NMI() { return InterruptLatch.Q & Bit(INT_NMI) ? true : false; }
1738

1839
//
19-
// latch the interrupt lines, done per instruction top of state A (see figure 15, 6809 spec)
40+
// Latch the interrupt lines
41+
// This done per instruction top of state A (see figure 15, 6809 spec) and also waiting in SYNC
2042
//
2143
static inline void LatchInterrupts()
2244
{
23-
InterruptLatch = 0;
45+
uint8_t OR = 0;
2446
for (int is = 0; is < IS_MAX; ++is)
25-
InterruptLatch |= InterruptLine[is];
47+
OR |= InterruptLine[is];
48+
49+
// clock next input
50+
InterruptLatch.Clock(OR);
2651
}
2752

2853
//
29-
// clear the nmi interrupt
54+
// Clear the nmi interrupt
3055
//
3156
static inline void ClearNMI()
3257
{
3358
InterruptLine[IS_NMI] &= BitMask(INT_NMI);
59+
LatchInterrupts();
3460
}
3561

3662
//
37-
// clear state of all interrupt lines
38-
//
39-
static inline void ClearInterrupt(Interrupt interrupt)
40-
{
41-
for (int is = 0; is < IS_MAX; ++is)
42-
InterruptLine[is] &= BitMask(interrupt);
43-
}
44-
45-
//
46-
// clear state of all interrupt lines
63+
// Clear state of all interrupt lines
4764
//
4865
static inline void ClearInterrupts()
4966
{
50-
InterruptLatch = 0;
5167
for (int is = 0; is < IS_MAX; ++is)
5268
InterruptLine[is] = 0;
69+
InterruptLatch.Reset();
5370
}
5471

defines.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,24 @@ namespace VCC
155155
void Check() {}
156156
};
157157
#endif
158+
159+
// d type flip flop
160+
struct DFF
161+
{
162+
uint8_t D{}; // d input
163+
uint8_t Q{}; // q output
164+
165+
void Reset()
166+
{
167+
D = Q = 0;
168+
}
169+
170+
void Clock(uint8_t d)
171+
{
172+
Q = D;
173+
D = d;
174+
}
175+
};
158176
}
159177

160178
struct SystemState

hd6309.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static unsigned int temp32;
129129
static int stemp32;
130130
static unsigned char temp8;
131131
static unsigned char InterruptLine[IS_MAX] = { 0 };
132-
static unsigned char InterruptLatch = 0;
132+
static VCC::DFF InterruptLatch;
133133
static unsigned char Source=0,Dest=0;
134134
static unsigned char postbyte=0;
135135
static short unsigned postword=0;
@@ -7544,8 +7544,9 @@ void HD6309AssertInterupt(InterruptSource src, Interrupt interrupt)
75447544
assert(src >= IS_NMI && src < IS_MAX);
75457545
assert(interrupt >= INT_IRQ && interrupt <= INT_NMI);
75467546

7547-
SyncWaiting=0;
7548-
InterruptLine[src] |= Bit(interrupt);
7547+
if (SyncWaiting)
7548+
LatchInterrupts();
7549+
SyncWaiting = 0;
75497550

75507551
if (EmuState.Debugger.IsTracing())
75517552
EmuState.Debugger.TraceCaptureInterruptRequest(interrupt, CycleCounter, HD6309GetState());

mc6809.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ static unsigned int temp32;
6363
static unsigned short temp16;
6464
static unsigned char temp8;
6565
static unsigned char InterruptLine[IS_MAX] = { 0 };
66-
static unsigned char InterruptLatch = 0;
66+
static VCC::DFF InterruptLatch;
6767
static unsigned char Source=0,Dest=0;
6868
static unsigned char postbyte=0;
6969
static short unsigned postword=0;
@@ -3229,8 +3229,10 @@ void MC6809AssertInterupt(InterruptSource src, Interrupt interrupt)
32293229
assert(src >= IS_NMI && src < IS_MAX);
32303230
assert(interrupt >= INT_IRQ && interrupt <= INT_NMI);
32313231

3232-
SyncWaiting = 0;
32333232
InterruptLine[src] |= Bit(interrupt);
3233+
if (SyncWaiting)
3234+
LatchInterrupts();
3235+
SyncWaiting = 0;
32343236

32353237
if (EmuState.Debugger.IsTracing())
32363238
EmuState.Debugger.TraceCaptureInterruptRequest(interrupt, CycleCounter, MC6809GetState());

0 commit comments

Comments
 (0)