forked from snes9xgit/snes9x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpuexec.h
102 lines (91 loc) · 2.27 KB
/
cpuexec.h
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
/*****************************************************************************\
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
This file is licensed under the Snes9x License.
For further information, consult the LICENSE file in the root directory.
\*****************************************************************************/
#ifndef _CPUEXEC_H_
#define _CPUEXEC_H_
#include "ppu.h"
#ifdef DEBUGGER
#include "debug.h"
#endif
struct SOpcodes
{
void (*S9xOpcode) (void);
};
struct SICPU
{
struct SOpcodes *S9xOpcodes;
uint8 *S9xOpLengths;
uint8 _Carry;
uint8 _Zero;
uint8 _Negative;
uint8 _Overflow;
uint32 ShiftedPB;
uint32 ShiftedDB;
uint32 Frame;
uint32 FrameAdvanceCount;
};
extern struct SICPU ICPU;
extern struct SOpcodes S9xOpcodesE1[256];
extern struct SOpcodes S9xOpcodesM1X1[256];
extern struct SOpcodes S9xOpcodesM1X0[256];
extern struct SOpcodes S9xOpcodesM0X1[256];
extern struct SOpcodes S9xOpcodesM0X0[256];
extern struct SOpcodes S9xOpcodesSlow[256];
extern uint8 S9xOpLengthsM1X1[256];
extern uint8 S9xOpLengthsM1X0[256];
extern uint8 S9xOpLengthsM0X1[256];
extern uint8 S9xOpLengthsM0X0[256];
void S9xMainLoop (void);
void S9xReset (void);
void S9xSoftReset (void);
void S9xDoHEventProcessing (void);
static inline void S9xUnpackStatus (void)
{
ICPU._Zero = (Registers.PL & Zero) == 0;
ICPU._Negative = (Registers.PL & Negative);
ICPU._Carry = (Registers.PL & Carry);
ICPU._Overflow = (Registers.PL & Overflow) >> 6;
}
static inline void S9xPackStatus (void)
{
Registers.PL &= ~(Zero | Negative | Carry | Overflow);
Registers.PL |= ICPU._Carry | ((ICPU._Zero == 0) << 1) | (ICPU._Negative & 0x80) | (ICPU._Overflow << 6);
}
static inline void S9xFixCycles (void)
{
if (CheckEmulation())
{
ICPU.S9xOpcodes = S9xOpcodesE1;
ICPU.S9xOpLengths = S9xOpLengthsM1X1;
}
else
if (CheckMemory())
{
if (CheckIndex())
{
ICPU.S9xOpcodes = S9xOpcodesM1X1;
ICPU.S9xOpLengths = S9xOpLengthsM1X1;
}
else
{
ICPU.S9xOpcodes = S9xOpcodesM1X0;
ICPU.S9xOpLengths = S9xOpLengthsM1X0;
}
}
else
{
if (CheckIndex())
{
ICPU.S9xOpcodes = S9xOpcodesM0X1;
ICPU.S9xOpLengths = S9xOpLengthsM0X1;
}
else
{
ICPU.S9xOpcodes = S9xOpcodesM0X0;
ICPU.S9xOpLengths = S9xOpLengthsM0X0;
}
}
}
#endif