more properly handling new haa semantics
[drnoksnes] / 65c816.h
1 /*
2  * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  *
4  * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5  *                           Jerremy Koot (jkoot@snes9x.com)
6  *
7  * Super FX C emulator code 
8  * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
9  *                           Gary Henderson.
10  * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
11  *
12  * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13  * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14  * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
15  *
16  * DOS port code contains the works of other authors. See headers in
17  * individual files.
18  *
19  * Snes9x homepage: http://www.snes9x.com
20  *
21  * Permission to use, copy, modify and distribute Snes9x in both binary and
22  * source form, for non-commercial purposes, is hereby granted without fee,
23  * providing that this license information and copyright notice appear with
24  * all copies and any derived work.
25  *
26  * This software is provided 'as-is', without any express or implied
27  * warranty. In no event shall the authors be held liable for any damages
28  * arising from the use of this software.
29  *
30  * Snes9x is freeware for PERSONAL USE only. Commercial users should
31  * seek permission of the copyright holders first. Commercial use includes
32  * charging money for Snes9x or software derived from Snes9x.
33  *
34  * The copyright holders request that bug fixes and improvements to the code
35  * should be forwarded to them so everyone can benefit from the modifications
36  * in future versions.
37  *
38  * Super NES and Super Nintendo Entertainment System are trademarks of
39  * Nintendo Co., Limited and its subsidiary companies.
40  */
41 #ifndef _65c816_h_
42 #define _65c816_h_
43
44 #define AL A.B.l
45 #define AH A.B.h
46 #define XL X.B.l
47 #define XH X.B.h
48 #define YL Y.B.l
49 #define YH Y.B.h
50 #define SL S.B.l
51 #define SH S.B.h
52 #define DL D.B.l
53 #define DH D.B.h
54 #define PL P.B.l
55 #define PH P.B.h
56
57 #define Carry       1
58 #define Zero        2
59 #define IRQ         4
60 #define Decimal     8
61 #define IndexFlag  16
62 #define MemoryFlag 32
63 #define Overflow   64
64 #define Negative  128
65 #define Emulation 256
66
67 #define ClearCarry() (ICPU._Carry = 0)
68 #define SetCarry() (ICPU._Carry = 1)
69 #define SetZero() (ICPU._Zero = 0)
70 #define ClearZero() (ICPU._Zero = 1)
71 #define SetIRQ() (Registers.PL |= IRQ)
72 #define ClearIRQ() (Registers.PL &= ~IRQ)
73 #define SetDecimal() (Registers.PL |= Decimal)
74 #define ClearDecimal() (Registers.PL &= ~Decimal)
75 #define SetIndex() (Registers.PL |= IndexFlag)
76 #define ClearIndex() (Registers.PL &= ~IndexFlag)
77 #define SetMemory() (Registers.PL |= MemoryFlag)
78 #define ClearMemory() (Registers.PL &= ~MemoryFlag)
79 #define SetOverflow() (ICPU._Overflow = 1)
80 #define ClearOverflow() (ICPU._Overflow = 0)
81 #define SetNegative() (ICPU._Negative = 0x80)
82 #define ClearNegative() (ICPU._Negative = 0)
83
84 #define CheckZero() (ICPU._Zero == 0)
85 #define CheckCarry() (ICPU._Carry)
86 #define CheckIRQ() (Registers.PL & IRQ)
87 #define CheckDecimal() (Registers.PL & Decimal)
88 #define CheckIndex() (Registers.PL & IndexFlag)
89 #define CheckMemory() (Registers.PL & MemoryFlag)
90 #define CheckOverflow() (ICPU._Overflow)
91 #define CheckNegative() (ICPU._Negative & 0x80)
92 #define CheckEmulation() (Registers.P.W & Emulation)
93
94 #define ClearFlags(f) (Registers.P.W &= ~(f))
95 #define SetFlags(f)   (Registers.P.W |=  (f))
96 #define CheckFlag(f)  (Registers.PL & (f))
97
98 typedef union
99 {
100 #ifdef LSB_FIRST
101     struct { uint8 l,h; } PACKING B;
102 #else
103     struct { uint8 h,l; } PACKING B;
104 #endif
105     uint16 W;
106 } ALIGN_BY_ONE pair;
107
108 struct SRegisters{
109     uint8  PB;
110     uint8  DB;
111     pair   P;
112     pair   A;
113     pair   D;
114     pair   X;
115     pair   S;
116     pair   Y;
117     uint16 PC;
118 } PACKING;
119
120 #define Registers       CPU.Regs
121
122 #endif