1 | /*****************************************************************************\ |
2 | Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. |
3 | This file is licensed under the Snes9x License. |
4 | For further information, consult the LICENSE file in the root directory. |
5 | \*****************************************************************************/ |
6 | |
7 | #ifndef _65C816_H_ |
8 | #define _65C816_H_ |
9 | |
10 | #define Carry 1 |
11 | #define Zero 2 |
12 | #define IRQ 4 |
13 | #define Decimal 8 |
14 | #define IndexFlag 16 |
15 | #define MemoryFlag 32 |
16 | #define Overflow 64 |
17 | #define Negative 128 |
18 | #define Emulation 256 |
19 | |
20 | #define SetCarry() (ICPU._Carry = 1) |
21 | #define ClearCarry() (ICPU._Carry = 0) |
22 | #define SetZero() (ICPU._Zero = 0) |
23 | #define ClearZero() (ICPU._Zero = 1) |
24 | #define SetIRQ() (Registers.PL |= IRQ) |
25 | #define ClearIRQ() (Registers.PL &= ~IRQ) |
26 | #define SetDecimal() (Registers.PL |= Decimal) |
27 | #define ClearDecimal() (Registers.PL &= ~Decimal) |
28 | #define SetIndex() (Registers.PL |= IndexFlag) |
29 | #define ClearIndex() (Registers.PL &= ~IndexFlag) |
30 | #define SetMemory() (Registers.PL |= MemoryFlag) |
31 | #define ClearMemory() (Registers.PL &= ~MemoryFlag) |
32 | #define SetOverflow() (ICPU._Overflow = 1) |
33 | #define ClearOverflow() (ICPU._Overflow = 0) |
34 | #define SetNegative() (ICPU._Negative = 0x80) |
35 | #define ClearNegative() (ICPU._Negative = 0) |
36 | |
37 | #define CheckCarry() (ICPU._Carry) |
38 | #define CheckZero() (ICPU._Zero == 0) |
39 | #define CheckIRQ() (Registers.PL & IRQ) |
40 | #define CheckDecimal() (Registers.PL & Decimal) |
41 | #define CheckIndex() (Registers.PL & IndexFlag) |
42 | #define CheckMemory() (Registers.PL & MemoryFlag) |
43 | #define CheckOverflow() (ICPU._Overflow) |
44 | #define CheckNegative() (ICPU._Negative & 0x80) |
45 | #define CheckEmulation() (Registers.P.W & Emulation) |
46 | |
47 | #define SetFlags(f) (Registers.P.W |= (f)) |
48 | #define ClearFlags(f) (Registers.P.W &= ~(f)) |
49 | #define CheckFlag(f) (Registers.PL & (f)) |
50 | |
51 | typedef union |
52 | { |
53 | #ifdef LSB_FIRST |
54 | struct { uint8 l, h; } B; |
55 | #else |
56 | struct { uint8 h, l; } B; |
57 | #endif |
58 | uint16 W; |
59 | } pair; |
60 | |
61 | typedef union |
62 | { |
63 | #ifdef LSB_FIRST |
64 | struct { uint8 xPCl, xPCh, xPB, z; } B; |
65 | struct { uint16 xPC, d; } W; |
66 | #else |
67 | struct { uint8 z, xPB, xPCh, xPCl; } B; |
68 | struct { uint16 d, xPC; } W; |
69 | #endif |
70 | uint32 xPBPC; |
71 | } PC_t; |
72 | |
73 | struct SRegisters |
74 | { |
75 | uint8 DB; |
76 | pair P; |
77 | pair A; |
78 | pair D; |
79 | pair S; |
80 | pair X; |
81 | pair Y; |
82 | PC_t PC; |
83 | }; |
84 | |
85 | #define AL A.B.l |
86 | #define AH A.B.h |
87 | #define XL X.B.l |
88 | #define XH X.B.h |
89 | #define YL Y.B.l |
90 | #define YH Y.B.h |
91 | #define SL S.B.l |
92 | #define SH S.B.h |
93 | #define DL D.B.l |
94 | #define DH D.B.h |
95 | #define PL P.B.l |
96 | #define PH P.B.h |
97 | #define PBPC PC.xPBPC |
98 | #define PCw PC.W.xPC |
99 | #define PCh PC.B.xPCh |
100 | #define PCl PC.B.xPCl |
101 | #define PB PC.B.xPB |
102 | |
103 | extern struct SRegisters Registers; |
104 | |
105 | #endif |
106 | |