Interrupt handling outside of the instruction loop

This commit is contained in:
tudnai 2020-05-02 22:35:59 -07:00
parent bae447ad32
commit 361726b0a4
4 changed files with 57 additions and 46 deletions

View File

@ -435,8 +435,8 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "341"
endingLineNumber = "341"
landmarkName = "ViewController"
landmarkType = "3">
landmarkName = "keyUp(with:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -659,8 +659,8 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "558"
endingLineNumber = "558"
landmarkName = "viewDidLoad()"
landmarkType = "7">
landmarkName = "ViewController"
landmarkType = "3">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -1037,8 +1037,8 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "211"
endingLineNumber = "211"
landmarkName = "keyDown(with:)"
landmarkType = "7">
landmarkName = "ViewController"
landmarkType = "3">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
@ -1217,22 +1217,6 @@
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "0E209547-21F4-4FB5-86B3-FF23E9289861"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "src/cpu/6502.c"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "719"
endingLineNumber = "719"
landmarkName = "m6502_Run()"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
@ -1277,7 +1261,7 @@
endingColumnNumber = "9223372036854775807"
startingLineNumber = "788"
endingLineNumber = "788"
landmarkName = "getFileSize(fullPath)"
landmarkName = "read_rom(bundlePath, filename, rom, addr)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>

View File

@ -141,6 +141,16 @@ class ViewController: NSViewController {
// m6502.pc = resetAddr
m6502.interrupt = SOFTRESET;
let saved_frm_set = clk_6502_per_frm_set;
clk_6502_per_frm_set = 0
clk_6502_per_frm_max = 0
// wait for 1 ms to allow the simulation to halt
usleep(10000);
softReset()
clk_6502_per_frm_set = saved_frm_set
}

View File

@ -131,7 +131,6 @@ typedef struct {
This idea is that "INLINE" would work only if it is
located in the same source file -- hence the include...
**/
#include "6502_instructions.h"
INLINE flags_t getFlags() {
flags_t f = {
@ -162,6 +161,7 @@ INLINE void setFlags( uint8_t byte ) {
m6502.N = flags.N; // Negative Flag
}
#include "6502_instructions.h"
INLINE int m6502_Step() {
@ -672,6 +672,36 @@ unsigned long long epoch = 0;
unsigned int clkfrm = 0;
void interrupt_IRQ() {
m6502.PC = memread16(IRQ_VECTOR);
// TODO: PUSH things onto stack?
}
void interrupt_NMI() {
m6502.PC = memread16(NMI_VECTOR);
// TODO: PUSH things onto stack?
}
void hardReset() {
m6502.PC = memread16(RESET_VECTOR);
// make sure it will be a cold reset...
memwrite(0x3F4, 0);
m6502.SP = 0xFF;
// N V - B D I Z C
// 0 0 1 0 0 1 0 1
setFlags(0x25);
}
void softReset() {
// m6502.PC = memread16(SOFTRESET_VECTOR);
m6502.PC = memread16( RESET_VECTOR );
m6502.SP = 0xFF;
// N V - B D I Z C
// 0 0 1 0 0 1 0 1
setFlags(0x25);
}
void m6502_Run() {
static unsigned int clk = 0;
@ -702,35 +732,19 @@ void m6502_Run() {
return;
case IRQ:
m6502.PC = memread16(IRQ_VECTOR);
// TODO: PUSH things onto stack?
interrupt_IRQ();
break;
case NMI:
m6502.PC = memread16(NMI_VECTOR);
// TODO: PUSH things onto stack?
interrupt_NMI();
break;
case HARDRESET:
m6502.PC = memread16(RESET_VECTOR);
// make sure it will be a cold reset...
memwrite(0x3F4, 0);
m6502.SP = 0xFF;
// N V - B D I Z C
// 0 0 1 0 0 1 0 1
m6502.SR = 0x25;
hardReset();
break;
case SOFTRESET:
// m6502.PC = memread16(SOFTRESET_VECTOR);
m6502.PC = memread16( RESET_VECTOR );
m6502.SP = 0xFF;
// N V - B D I Z C
// 0 0 1 0 0 1 0 1
m6502.SR = 0x25;
softReset();
break;
default:

View File

@ -161,7 +161,10 @@ extern void m6502_Run(void);
extern void kbdInput ( uint8_t code );
extern void setIO ( uint16_t ioaddr, uint8_t val );
INLINE flags_t getFlags( void );
INLINE void setFlags( uint8_t byte );
extern void interrupt_IRQ(void);
extern void interrupt_NMI(void);
extern void hardReset(void);
extern void softReset(void);
#endif /* __6502_H__ */