Skip to content

Commit 9889072

Browse files
committed
Refactor interrupts to assert/deassert interrupt line
1 parent f2548af commit 9889072

22 files changed

+345
-306
lines changed

CpuCommon.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#pragma once
2+
3+
//
4+
// access cc flags
5+
//
6+
static inline bool CC(char flag)
7+
{
8+
return cc[flag] ? true : false;
9+
}
10+
11+
//
12+
// interrupt lines (active low)
13+
//
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; }
17+
18+
//
19+
// latch the interrupt lines, done per instruction top of state A (see figure 15, 6809 spec)
20+
//
21+
static inline void LatchInterrupts()
22+
{
23+
InterruptLatch = 0;
24+
for (int is = 0; is < IS_MAX; ++is)
25+
InterruptLatch |= InterruptLine[is];
26+
}
27+
28+
//
29+
// clear the nmi interrupt
30+
//
31+
static inline void ClearNMI()
32+
{
33+
InterruptLine[IS_NMI] &= BitMask(INT_NMI);
34+
}
35+
36+
//
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
47+
//
48+
static inline void ClearInterrupts()
49+
{
50+
InterruptLatch = 0;
51+
for (int is = 0; is < IS_MAX; ++is)
52+
InterruptLine[is] = 0;
53+
}
54+

FD502/fd502.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,16 @@ This file is part of VCC (Virtual Color Computer).
3030
#include "wd1793.h"
3131
#include "distortc.h"
3232
#include "fd502.h"
33-
#include "..\fileops.h"
33+
#include "../fileops.h"
34+
#include "../MachineDefs.h"
3435
#define EXTROMSIZE 16384
3536

3637
using namespace std;
3738

3839
extern DiskInfo Drive[5];
3940
typedef unsigned char (*MEMREAD8)(unsigned short);
4041
typedef void (*MEMWRITE8)(unsigned char,unsigned short);
41-
typedef void (*ASSERTINTERUPT) (unsigned char,unsigned char);
42+
typedef void (*ASSERTINTERUPT)(InterruptSource, Interrupt);
4243
typedef void (*DMAMEMPOINTERS) ( MEMREAD8,MEMWRITE8);
4344
typedef void (*DYNAMICMENUCALLBACK)( char *,int, int);
4445
static unsigned char ExternalRom[EXTROMSIZE];
@@ -47,7 +48,7 @@ static unsigned char RGBDiskRom[EXTROMSIZE];
4748
static char FloppyPath[MAX_PATH];
4849
static char RomFileName[MAX_PATH]="";
4950
static char TempRomFileName[MAX_PATH]="";
50-
void (*AssertInt)(unsigned char,unsigned char)=NULL;
51+
void (*AssertInt)(InterruptSource,Interrupt)=NULL;
5152
static void (*DynamicMenuCallback)( char *,int, int)=NULL;
5253
static unsigned char (*MemRead8)(unsigned short);
5354
static void (*MemWrite8)(unsigned char,unsigned short);

FD502/fd502.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ This file is part of VCC (Virtual Color Computer).
1717
You should have received a copy of the GNU General Public License
1818
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
1919
*/
20-
extern "C" void (*AssertInt)(unsigned char, unsigned char);
20+
21+
#include "../MachineDefs.h"
22+
23+
extern "C" void (*AssertInt)(InterruptSource, Interrupt);
2124
void BuildDynaMenu(void);
2225
#define HEAD 0
2326
#define SLAVE 1

FD502/wd1793.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ void DispatchCommand(unsigned char Tmp)
991991
StatusReg=READY;
992992
ExecTimeWaiter=1;
993993
if ((Tmp & 15) != 0)
994-
AssertInt(NMI,0);
994+
AssertInt(IS_NMI, INT_NMI);
995995
// WriteLog("FORCEINTERUPT",0);
996996
break;
997997

@@ -1394,9 +1394,9 @@ long GetSectorInfo (SectorInfo *Sector,unsigned char *TempBuffer)
13941394
void CommandDone(void)
13951395
{
13961396
if (InteruptEnable)
1397-
AssertInt(NMI,0);
1398-
TransferBufferSize=0;
1399-
CurrentCommand=IDLE;
1397+
AssertInt(IS_NMI, INT_NMI);
1398+
TransferBufferSize=0;
1399+
CurrentCommand=IDLE;
14001400
}
14011401

14021402
//Stolen from MESS

HardDisk/harddisk.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ This file is part of VCC (Virtual Color Computer).
2525
#include "cc3vhd.h"
2626
#include "defines.h"
2727
#include "cloud9.h"
28-
#include "..\fileops.h"
28+
#include "../fileops.h"
29+
#include "../MachineDefs.h"
2930

3031
#define DEF_HD_SIZE 132480
3132

@@ -38,10 +39,10 @@ static char HardDiskPath[MAX_PATH];
3839

3940
typedef unsigned char (*MEMREAD8)(unsigned short);
4041
typedef void (*MEMWRITE8)(unsigned char,unsigned short);
41-
typedef void (*ASSERTINTERUPT) (unsigned char,unsigned char);
42+
typedef void (*ASSERTINTERUPT)(InterruptSource, Interrupt);
4243
typedef void (*DMAMEMPOINTERS) ( MEMREAD8,MEMWRITE8);
4344
typedef void (*DYNAMICMENUCALLBACK)( char *,int, int);
44-
static void (*AssertInt)(unsigned char,unsigned char)=NULL;
45+
static void (*AssertInt)(InterruptSource, Interrupt)=NULL;
4546
static unsigned char (*MemRead8)(unsigned short);
4647
static void (*MemWrite8)(unsigned char,unsigned short);
4748
static unsigned char *Memory=NULL;

MachineDefs.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ namespace VCC
7373
}
7474

7575
// Common CPU defs (counting from 1 because legacy)
76-
enum { IRQ = 1, FIRQ, NMI };
76+
enum Interrupt { INT_IRQ = 1, INT_FIRQ, INT_NMI };
77+
78+
// Interrupt sources keep track of their own state, NMI is its own source and always uses this.
79+
enum InterruptSource { IS_NMI, IS_PIA0_HSYNC, IS_PIA0_VSYNC, IS_PIA1_CD, IS_PIA1_CART, IS_GIME, IS_MAX };
7780

7881
// make nth bit 0-7
7982
inline constexpr uint8_t Bit(uint8_t n) { return 1 << n; }
@@ -84,8 +87,8 @@ inline constexpr uint8_t BitMask(uint8_t n) { return ~Bit(n); }
8487
extern void (*CPUInit)(void);
8588
extern int (*CPUExec)(int);
8689
extern void (*CPUReset)(void);
87-
extern void (*CPUAssertInterupt)(unsigned char, unsigned char);
88-
extern void (*CPUDeAssertInterupt)(unsigned char);
90+
extern void (*CPUAssertInterupt)(InterruptSource, Interrupt);
91+
extern void (*CPUDeAssertInterupt)(InterruptSource, Interrupt);
8992
extern void (*CPUForcePC)(unsigned short);
9093
extern void (*CPUSetBreakpoints)(const std::vector<unsigned short>&);
9194
extern void (*CPUSetTraceTriggers)(const std::vector<unsigned short>&);

OpDecoder.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ namespace VCC { namespace Debugger
123123
{
124124
switch (irq)
125125
{
126-
case IRQ:
126+
case INT_IRQ:
127127
return IRQType::InterruptRequest;
128-
case FIRQ:
128+
case INT_FIRQ:
129129
return IRQType::FastInterruptRequest;
130-
case NMI:
130+
case INT_NMI:
131131
return IRQType::NonMaskableInterrupt;
132132
}
133133
return IRQType();

Vcc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ void (*CPUReset)(void)=NULL;
104104
void (*CPUSetBreakpoints)(const std::vector<unsigned short>&) = NULL;
105105
void (*CPUSetTraceTriggers)(const std::vector<unsigned short>&) = NULL;
106106
VCC::CPUState (*CPUGetState)() = NULL;
107-
void (*CPUAssertInterupt)(unsigned char,unsigned char)=NULL;
108-
void (*CPUDeAssertInterupt)(unsigned char)=NULL;
107+
void (*CPUAssertInterupt)(InterruptSource, Interrupt)=NULL;
108+
void (*CPUDeAssertInterupt)(InterruptSource, Interrupt)=NULL;
109109
void (*CPUForcePC)(unsigned short)=NULL;
110110
void FullScreenToggle(void);
111111
void save_key_down(unsigned char kb_char, unsigned char OEMscan);

Vcc.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@
376376
<ItemGroup>
377377
<ClInclude Include="audio.h" />
378378
<ClInclude Include="BuildConfig.h" />
379+
<ClInclude Include="CpuCommon.h" />
379380
<ClInclude Include="DirectX.h" />
380381
<ClInclude Include="IDisplay.h" />
381382
<ClInclude Include="IDisplayDebug.h" />

Vcc.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,9 @@
262262
<ClInclude Include="DirectX.h">
263263
<Filter>Source</Filter>
264264
</ClInclude>
265+
<ClInclude Include="CpuCommon.h">
266+
<Filter>Headers</Filter>
267+
</ClInclude>
265268
</ItemGroup>
266269
<ItemGroup>
267270
<Image Include="resources\3guys.bmp">

0 commit comments

Comments
 (0)