This repository has been archived by the owner on Nov 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPU.OLD
executable file
·124 lines (88 loc) · 2.36 KB
/
CPU.OLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//CPU handler starts/stops cpu etc
//routines for handling roms
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <process.h>
#include "dd.h"
#include "types.h"
#include "message.h"
#include "file.h"
#include "keyb.h"
//#include "6502.h"
#include "m6502.h"
#include "nes.h"
#include "nesvideo.h"
byte CPUpaused=0; //flag for when cpu is paused
byte CPURunning=0; //flag for when cpu is running
int volatile cycles;
void startframe();
void startvblank();
#include "timing.h"
extern volatile byte frame;
//are we currently in a virtual frame ? (emulating)
volatile byte inemu=0;
//get current virtual scanline being draw
int getscanline()
{
if (frame) return (m6502clockticks/HBLANKCYCLES)+8; //*232/FRAMECYCLES; //during frame (assume 232 lines pre-vblank)
else return 0; //during vblank
}
//ticked (once per virtual frame)
void tickemu()
{
if (!CPURunning) return;
if (inemu) return;
inemu=1;
if (ram[0x2000]&0x80) //generate vblank?
m6502nmi();
sl.reset(); //reset scrolllist
//execute during vblank
startvblank();
m6502exec(VBLANKCYCLES);
//execute during virtual frame...
m6502clockticks=0; //reset clock ticks
startframe();
m6502exec(FRAMECYCLES);
sl.resolve(224);
//done
cycles+=CYCLESPERTICK;
inemu=0;
}
void m_execute()
{
if (!romloaded) {msg.error("ROM not loaded"); return;}
if (CPURunning) {msg.error("CPU already running"); return;}
if (resetNEShardware()!=0)
{ msg.error("Unable to reset NES hardware"); return;}
msg.printf(3,"CPU emulation started");
CPURunning=1;
CPUpaused=0;
}
void m_stop()
{
if (!romloaded) return;
CPUpaused=0;
if (CPURunning) msg.printf(3,"CPU emulation stopped");
CPURunning=0;
}
void m_resume()
{
if (!romloaded) {msg.error("ROM not loaded"); return;}
if (CPURunning) {msg.error("CPU already running"); return;}
if (!CPUpaused) {msg.error("CPU not paused"); return;}
msg.printf(3,"CPU emulation resumed");
CPURunning=1;
CPUpaused=0;
}
void m_pause()
{
if (!romloaded) return;
if (!CPURunning) {msg.error("CPU not running"); return;}
CPUpaused=1;
CPURunning=0;
msg.printf(3,"CPU emulation paused");
}
//-----------------------------------------------------------
//-----------------------------------------------------------