1 // -*- C++ -*-
2 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
3 // Copyright (C) 1999-2003 Forgotten
4 // Copyright (C) 2005 Forgotten and the VBA development team
5 
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or(at your option)
9 // any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 
20 #ifndef VBA_GBA_H
21 #define VBA_GBA_H
22 
23 #include "../mednafen.h"
24 
25 typedef struct {
26   uint8 *address;
27   uint32 mask;
28 } memoryMap;
29 
30 typedef union {
31   struct {
32 #ifdef MSB_FIRST
33     uint8 B3;
34     uint8 B2;
35     uint8 B1;
36     uint8 B0;
37 #else
38     uint8 B0;
39     uint8 B1;
40     uint8 B2;
41     uint8 B3;
42 #endif
43   } B;
44   struct {
45 #ifdef MSB_FIRST
46     uint16 W1;
47     uint16 W0;
48 #else
49     uint16 W0;
50     uint16 W1;
51 #endif
52   } W;
53 #ifdef MSB_FIRST
54   volatile uint32 I;
55 #else
56 	uint32 I;
57 #endif
58 } reg_pair;
59 
60 #ifndef NO_GBA_MAP
61 extern memoryMap map[256];
62 #endif
63 
64 extern bool busPrefetch;
65 extern bool busPrefetchEnable;
66 extern uint32 busPrefetchCount;
67 extern uint32 cpuPrefetch[2];
68 
69 
70 extern uint8 memoryWait[16];
71 extern uint8 memoryWait32[16];
72 extern uint8 memoryWaitSeq[16];
73 extern uint8 memoryWaitSeq32[16];
74 
75 extern reg_pair reg[45];
76 extern uint8 biosProtected[4];
77 
78 extern uint32 N_FLAG;
79 extern bool Z_FLAG;
80 extern bool C_FLAG;
81 extern bool V_FLAG;
82 extern bool armIrqEnable;
83 extern bool armState;
84 extern int armMode;
85 extern void (*cpuSaveGameFunc)(uint32,uint8);
86 
87 extern void doMirroring(bool);
88 extern void CPUUpdateRegister(uint32, uint16);
89 extern void applyTimer ();
90 
91 void CPUWriteMemory(uint32 address, uint32 value);
92 void CPUWriteHalfWord(uint32, uint16);
93 void CPUWriteByte(uint32, uint8);
94 
95 extern void CPUCheckDMA(int,int);
96 
97 extern void CPUSwitchMode(int mode, bool saveState, bool breakLoop);
98 extern void CPUSwitchMode(int mode, bool saveState);
99 extern void CPUUndefinedException();
100 extern void CPUSoftwareInterrupt();
101 extern void CPUSoftwareInterrupt(int comment);
102 extern void CPUUpdateCPSR();
103 extern void CPUUpdateFlags(bool breakLoop);
104 extern void CPUUpdateFlags();
105 
106 
107 extern uint8 cpuBitsSet[256];
108 extern uint8 cpuLowestBitSet[256];
109 
110 extern struct EmulatedSystem GBASystem;
111 
112 int32 MDFNGBA_GetTimerPeriod(int which);
113 
114 
115 #define R13_IRQ  18
116 #define R14_IRQ  19
117 #define SPSR_IRQ 20
118 #define R13_USR  26
119 #define R14_USR  27
120 #define R13_SVC  28
121 #define R14_SVC  29
122 #define SPSR_SVC 30
123 #define R13_ABT  31
124 #define R14_ABT  32
125 #define SPSR_ABT 33
126 #define R13_UND  34
127 #define R14_UND  35
128 #define SPSR_UND 36
129 #define R8_FIQ   37
130 #define R9_FIQ   38
131 #define R10_FIQ  39
132 #define R11_FIQ  40
133 #define R12_FIQ  41
134 #define R13_FIQ  42
135 #define R14_FIQ  43
136 #define SPSR_FIQ 44
137 
138 #include "Globals.h"
139 #include "eeprom.h"
140 #include "flash.h"
141 #include "RTC.h"
142 
143 extern RTC *GBA_RTC;
144 
145 int Load(const uint8_t *data, size_t size);
146 void CloseGame(void);
147 void DoSimpleCommand(int cmd);
148 void SetInput(unsigned port, const char *type, void *ptr);
149 void Emulate(EmulateSpecStruct *espec);
150 
151 extern MDFNGI EmulatedGBA;
152 extern bool use_mednafen_save_method;
153 
154 // Hardware Sensors
155 #define SENSOR_NONE (1 << 0)
156 #define SENSOR_SOLAR (1 << 1)
157 #define SENSOR_TILT (1 << 2)
158 #define SENSOR_GYRO (1 << 3)
159 #define SENSOR_RUMBLE (1 << 4)
160 
161 extern int hardware;
162 
163 extern uint8 systemGetSensorDarkness();
164 void systemCartridgeRumble(bool e);
165 int systemGetSensorZ();
166 
167 #endif //VBA_GBA_H
168