1 /*
2 ** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)
3 **
4 **
5 ** This program is free software; you can redistribute it and/or
6 ** modify it under the terms of version 2 of the GNU Library General
7 ** Public License as published by the Free Software Foundation.
8 **
9 ** This program is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 ** Library General Public License for more details.  To obtain a
13 ** copy of the GNU Library General Public License, write to the Free
14 ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
15 **
16 ** Any permitted reproduction of these routines, in whole or in part,
17 ** must bear this legend.
18 **
19 **
20 ** nes6502.h
21 **
22 ** NES custom 6502 CPU definitions / prototypes
23 ** $Id: nes6502.h,v 1.2 2003/05/01 22:34:19 benjihan Exp $
24 */
25 
26 /* straitm */
27 #include "types.h"
28 
29 /* NOTE: 16-bit addresses avoided like the plague: use 32-bit values
30 **       wherever humanly possible
31 */
32 #ifndef _NES6502_H_
33 #define _NES6502_H_
34 
35 /* Define this to enable decimal mode in ADC / SBC (not needed in NES) */
36 /*#define  NES6502_DECIMAL*/
37 
38 /* number of bank pointers the CPU emulation core handles */
39 #ifdef NSF_PLAYER
40 #define  NES6502_4KBANKS
41 #endif
42 
43 #ifdef NES6502_4KBANKS
44 #define  NES6502_NUMBANKS  16
45 #define  NES6502_BANKSHIFT 12
46 #else
47 #define  NES6502_NUMBANKS  8
48 #define  NES6502_BANKSHIFT 13
49 #endif
50 
51 #define  NES6502_BANKMASK  ((0x10000 / NES6502_NUMBANKS) - 1)
52 
53 /* Add memory access control flags. This is a ram shadow memory that holds
54  * for each memory bytes access flags for read, write and execute access.
55  * The nes6502_mem_access holds all new access (all mode all location). It is
56  * used to determine if the player has loop in playing time calculation.
57  */
58 #ifdef NES6502_MEM_ACCESS_CTRL
59 extern uint8 nes6502_mem_access;
60 # define NES6502_READ_ACCESS 1
61 # define NES6502_WRITE_ACCESS 2
62 # define NES6502_EXE_ACCESS 4
63 #endif /* #ifdef NES6502_MEM_ACCESS_CTRL */
64 
65 /* P (flag) register bitmasks */
66 #define  N_FLAG         0x80
67 #define  V_FLAG         0x40
68 #define  R_FLAG         0x20  /* Reserved, always 1 */
69 #define  B_FLAG         0x10
70 #define  D_FLAG         0x08
71 #define  I_FLAG         0x04
72 #define  Z_FLAG         0x02
73 #define  C_FLAG         0x01
74 
75 /* Vector addresses */
76 #define  NMI_VECTOR     0xFFFA
77 #define  RESET_VECTOR   0xFFFC
78 #define  IRQ_VECTOR     0xFFFE
79 
80 /* cycle counts for interrupts */
81 #define  INT_CYCLES     7
82 #define  RESET_CYCLES   6
83 
84 #define  NMI_MASK       0x01
85 #define  IRQ_MASK       0x02
86 
87 /* Stack is located on 6502 page 1 */
88 #define  STACK_OFFSET   0x0100
89 
90 typedef struct
91 {
92    uint32 min_range, max_range;
93    uint8 (*read_func)(uint32 address);
94 } nes6502_memread;
95 
96 typedef struct
97 {
98    uint32 min_range, max_range;
99    void (*write_func)(uint32 address, uint8 value);
100 } nes6502_memwrite;
101 
102 typedef struct
103 {
104    uint8 * mem_page[NES6502_NUMBANKS];  /* memory page pointers */
105 #ifdef NES6502_MEM_ACCESS_CTRL
106   uint8 * acc_mem_page[NES6502_NUMBANKS]; /* memory access page pointer */
107 #endif
108    nes6502_memread *read_handler;
109    nes6502_memwrite *write_handler;
110    int dma_cycles;
111    uint32 pc_reg;
112    uint8 a_reg, p_reg, x_reg, y_reg, s_reg;
113    uint8 int_pending;
114 } nes6502_context;
115 
116 #ifdef __cplusplus
117 extern "C" {
118 #endif /* __cplusplus */
119 
120 /* Functions which govern the 6502's execution */
121 extern void nes6502_init(void);
122 extern void nes6502_reset(void);
123 extern int nes6502_execute(int total_cycles);
124 extern void nes6502_nmi(void);
125 extern void nes6502_irq(void);
126 extern uint8 nes6502_getbyte(uint32 address);
127 extern uint32 nes6502_getcycles(boolean reset_flag);
128 extern void nes6502_setdma(int cycles);
129 
130 #ifdef NES6502_MEM_ACCESS_CTRL
131 extern void nes6502_chk_mem_access(uint8 * access, int flags);
132 #else
133 #define nes6502_chk_mem_access(access,flags)
134 #endif
135 
136 /* Context get/set */
137 extern void nes6502_setcontext(nes6502_context *cpu);
138 extern void nes6502_getcontext(nes6502_context *cpu);
139 
140 #ifdef __cplusplus
141 }
142 #endif /* __cplusplus */
143 
144 #endif /* _NES6502_H_ */
145 
146 /*
147 ** $Log: nes6502.h,v $
148 ** Revision 1.2  2003/05/01 22:34:19  benjihan
149 ** New NSF plugin
150 **
151 ** Revision 1.1  2003/04/08 20:53:00  ben
152 ** Adding more files...
153 **
154 ** Revision 1.4  2000/06/09 15:12:25  matt
155 ** initial revision
156 **
157 */
158