Skip to content

Commit b77093c

Browse files
callsopejaquay
authored andcommitted
Fix interrupts / Crystal City
1 parent cd47f78 commit b77093c

30 files changed

+394
-395
lines changed

CpuCommon.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#pragma once
2+
3+
// Copyright 2015 by Joseph Forgion
4+
// This file is part of VCC (Virtual Color Computer).
5+
//
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
26+
//
27+
static inline bool CC(char flag)
28+
{
29+
return cc[flag] ? true : false;
30+
}
31+
32+
//
33+
// Interrupt lines reading from output of the latch
34+
//
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; }
38+
39+
//
40+
// Latch the interrupt lines
41+
// This done per instruction top of state A (see figure 15, 6809 spec) and also waiting in SYNC
42+
//
43+
static inline void LatchInterrupts()
44+
{
45+
uint8_t OR = 0;
46+
for (int is = 0; is < IS_MAX; ++is)
47+
OR |= InterruptLine[is];
48+
49+
// clock next input
50+
InterruptLatch.Clock(OR);
51+
}
52+
53+
//
54+
// Clear the nmi interrupt
55+
//
56+
static inline void ClearNMI()
57+
{
58+
InterruptLine[IS_NMI] &= BitMask(INT_NMI);
59+
LatchInterrupts();
60+
}
61+
62+
//
63+
// Clear state of all interrupt lines
64+
//
65+
static inline void ClearInterrupts()
66+
{
67+
for (int is = 0; is < IS_MAX; ++is)
68+
InterruptLine[is] = 0;
69+
InterruptLatch.Reset();
70+
}
71+

FD502/defines.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,5 @@ This file is part of VCC (Virtual Color Computer).
3636
#define QUERY 255
3737
#define INDEXTIME ((LINESPERFIELD * TARGETFRAMERATE)/5)
3838

39-
40-
//Common CPU defs
41-
#define IRQ 1
42-
#define FIRQ 2
43-
#define NMI 3
44-
4539
#endif
4640

FD502/fd502.cpp

Lines changed: 5 additions & 8 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-
static 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);
@@ -244,11 +245,7 @@ extern "C"
244245
}
245246
}
246247

247-
void CPUAssertInterupt(unsigned char Interupt,unsigned char Latencey)
248-
{
249-
AssertInt(Interupt,Latencey);
250-
return;
251-
}
248+
252249

253250
void CenterDialog(HWND hDlg)
254251
{

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-
void CPUAssertInterupt(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: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ This file is part of VCC (Virtual Color Computer).
3636
#include <stdlib.h>
3737
#include <winioctl.h>
3838
#include "defines.h"
39+
#include "../MachineDefs.h"
3940
#include "wd1793.h"
4041
#include "fd502.h"
4142
#include "fdrawcmd.h" // http://simonowen.com/fdrawcmd/
@@ -990,7 +991,7 @@ void DispatchCommand(unsigned char Tmp)
990991
StatusReg=READY;
991992
ExecTimeWaiter=1;
992993
if ((Tmp & 15) != 0)
993-
CPUAssertInterupt(NMI,0);
994+
AssertInt(IS_NMI, INT_NMI);
994995
// WriteLog("FORCEINTERUPT",0);
995996
break;
996997

@@ -1393,9 +1394,9 @@ long GetSectorInfo (SectorInfo *Sector,unsigned char *TempBuffer)
13931394
void CommandDone(void)
13941395
{
13951396
if (InteruptEnable)
1396-
CPUAssertInterupt(NMI,0);
1397-
TransferBufferSize=0;
1398-
CurrentCommand=IDLE;
1397+
AssertInt(IS_NMI, INT_NMI);
1398+
TransferBufferSize=0;
1399+
CurrentCommand=IDLE;
13991400
}
14001401

14011402
//Stolen from MESS

HardDisk/defines.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,5 @@ This file is part of VCC (Virtual Color Computer).
3636
#define QUERY 255
3737
#define INDEXTIME ((LINESPERFIELD * TARGETFRAMERATE)/5)
3838

39-
40-
//Common CPU defs
41-
#define IRQ 1
42-
#define FIRQ 2
43-
#define NMI 3
44-
4539
#endif
4640

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: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,23 @@ namespace VCC
7272

7373
}
7474

75-
// Common CPU defs
76-
#define IRQ 1
77-
#define FIRQ 2
78-
#define NMI 3
75+
// Common CPU defs (counting from 1 because legacy)
76+
enum Interrupt { INT_IRQ = 1, INT_FIRQ, INT_NMI };
7977

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 };
80+
81+
// make nth bit 0-7
82+
inline constexpr uint8_t Bit(uint8_t n) { return 1 << n; }
83+
84+
// make mask of nth bit 0-7
85+
inline constexpr uint8_t BitMask(uint8_t n) { return ~Bit(n); }
8086

8187
extern void (*CPUInit)(void);
8288
extern int (*CPUExec)(int);
8389
extern void (*CPUReset)(void);
84-
extern void (*CPUAssertInterupt)(unsigned char, unsigned char);
85-
extern void (*CPUDeAssertInterupt)(unsigned char);
90+
extern void (*CPUAssertInterupt)(InterruptSource, Interrupt);
91+
extern void (*CPUDeAssertInterupt)(InterruptSource, Interrupt);
8692
extern void (*CPUForcePC)(unsigned short);
8793
extern void (*CPUSetBreakpoints)(const std::vector<unsigned short>&);
8894
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();

Ramdisk/defines.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,4 @@
1919
#define INDEXTIME ((LINESPERFIELD * TARGETFRAMERATE)/5)
2020

2121

22-
//Common CPU defs
23-
#define IRQ 1
24-
#define FIRQ 2
25-
#define NMI 3
26-
2722

0 commit comments

Comments
 (0)