Browse code

Updating the VBA-M code to revision 1231.

Naram Qashat authored on 2014/09/08 12:20:28
Showing 1 changed files
... ...
@@ -1,5 +1,4 @@
1
-#ifndef GBAINLINE_H
2
-#define GBAINLINE_H
1
+#pragma once
3 2
 
4 3
 #include "../common/Port.h"
5 4
 #include "Sound.h"
... ...
@@ -8,8 +7,9 @@ extern const uint32_t objTilesAddress[3];
8 7
 
9 8
 extern bool stopState;
10 9
 extern bool holdState;
11
-extern int holdType;
12 10
 extern int cpuNextEvent;
11
+extern bool cpuDmaHack;
12
+extern uint32_t cpuDmaLast;
13 13
 extern bool timer0On;
14 14
 extern int timer0Ticks;
15 15
 extern int timer0ClockReload;
... ...
@@ -24,6 +24,8 @@ extern int timer3Ticks;
24 24
 extern int timer3ClockReload;
25 25
 extern int cpuTotalTicks;
26 26
 
27
+inline uint8_t CPUReadByteQuick(uint32_t addr) { return map[addr >> 24].address[addr & map[addr >> 24].mask]; }
28
+
27 29
 inline uint16_t CPUReadHalfWordQuick(uint32_t addr) { return READ16LE(&map[addr >> 24].address[addr & map[addr >> 24].mask]); }
28 30
 
29 31
 inline uint32_t CPUReadMemoryQuick(uint32_t addr) { return READ32LE(&map[addr >> 24].address[addr & map[addr >> 24].mask]); }
... ...
@@ -42,7 +44,7 @@ inline uint32_t CPUReadMemory(uint32_t address)
42 44
 			if (reg[15].I >> 24)
43 45
 			{
44 46
 				if (address < 0x4000)
45
-					value = READ32LE(&biosProtected);
47
+					value = READ32LE(&biosProtected[0]);
46 48
 				else
47 49
 					goto unreadable;
48 50
 			}
... ...
@@ -92,45 +94,32 @@ inline uint32_t CPUReadMemory(uint32_t address)
92 94
 			break;
93 95
 		case 13:
94 96
 		case 14:
95
-			return 0;
97
+		case 15:
98
+			value = 0;
99
+			break;
96 100
 		// default
97 101
 		default:
98 102
 		unreadable:
99
-			if (armState)
100
-				return CPUReadMemoryQuick(reg[15].I);
103
+			if (cpuDmaHack)
104
+				value = cpuDmaLast;
101 105
 			else
102
-				return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
106
+			{
107
+				if (armState)
108
+					return CPUReadMemoryQuick(reg[15].I);
109
+				else
110
+					return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
111
+			}
103 112
 	}
104 113
 
105 114
 	if (oldAddress & 3)
106 115
 	{
107
-#ifdef C_CORE
108 116
 		int shift = (oldAddress & 3) << 3;
109 117
 		value = (value >> shift) | (value << (32 - shift));
110
-#else
111
-# ifdef __GNUC__
112
-		asm("and $3, %%ecx;"
113
-			"shl $3 ,%%ecx;"
114
-			"ror %%cl, %0"
115
-			: "=r" (value)
116
-			: "r" (value), "c" (oldAddress));
117
-# else
118
-		__asm
119
-		{
120
-			mov ecx, oldAddress;
121
-			and ecx, 3;
122
-			shl ecx, 3;
123
-			ror [dword ptr value], cl;
124
-		}
125
-# endif
126
-#endif
127 118
 	}
128 119
 
129 120
 	return value;
130 121
 }
131 122
 
132
-extern uint32_t myROM[];
133
-
134 123
 inline uint32_t CPUReadHalfWord(uint32_t address)
135 124
 {
136 125
 	uint32_t value;
... ...
@@ -174,6 +163,8 @@ inline uint32_t CPUReadHalfWord(uint32_t address)
174 163
 						value = 0xFFFF - ((timer3Ticks - cpuTotalTicks) >> timer3ClockReload);
175 164
 				}
176 165
 			}
166
+			else if (address < 0x4000400 && ioReadable[address & 0x3fc])
167
+				value = 0;
177 168
 			else
178 169
 				goto unreadable;
179 170
 			break;
... ...
@@ -204,12 +195,24 @@ inline uint32_t CPUReadHalfWord(uint32_t address)
204 195
 			else
205 196
 				value = READ16LE(&rom[address & 0x1FFFFFE]);
206 197
 			break;
198
+		case 13:
199
+		case 14:
200
+		case 15:
201
+			value = 0;
202
+			break;
203
+		// default
207 204
 		default:
208 205
 		unreadable:
209
-			if (armState)
210
-				return CPUReadMemoryQuick(reg[15].I);
206
+			if (cpuDmaHack)
207
+				value = cpuDmaLast & 0xFFFF;
211 208
 			else
212
-				return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
209
+			{
210
+				if (armState)
211
+					value = CPUReadHalfWordQuick(reg[15].I + (address & 2));
212
+				else
213
+					value = CPUReadHalfWordQuick(reg[15].I);
214
+			}
215
+			return value;
213 216
 	}
214 217
 
215 218
 	if (oldAddress & 1)
... ...
@@ -220,13 +223,7 @@ inline uint32_t CPUReadHalfWord(uint32_t address)
220 223
 
221 224
 inline int16_t CPUReadHalfWordSigned(uint32_t address)
222 225
 {
223
-	uint32_t oldAddress = address;
224
-	if (address & 1)
225
-		address &= ~0x01;
226
-	int16_t value = static_cast<int16_t>(CPUReadHalfWord(address));
227
-	if (oldAddress & 1)
228
-		value = static_cast<int8_t>(value);
229
-	return value;
226
+	return static_cast<int16_t>(CPUReadHalfWord(address));
230 227
 }
231 228
 
232 229
 inline uint8_t CPUReadByte(uint32_t address)
... ...
@@ -239,7 +236,7 @@ inline uint8_t CPUReadByte(uint32_t address)
239 236
 				if (address < 0x4000)
240 237
 					return biosProtected[address & 3];
241 238
 				else
242
-					goto unreadable;
239
+					break;
243 240
 			}
244 241
 			return bios[address & 0x3FFF];
245 242
 		case 2:
... ...
@@ -250,7 +247,7 @@ inline uint8_t CPUReadByte(uint32_t address)
250 247
 			if (address < 0x4000400 && ioReadable[address & 0x3ff])
251 248
 				return ioMem[address & 0x3ff];
252 249
 			else
253
-				goto unreadable;
250
+				break;
254 251
 		case 5:
255 252
 			return paletteRAM[address & 0x3ff];
256 253
 		case 6:
... ...
@@ -268,12 +265,19 @@ inline uint8_t CPUReadByte(uint32_t address)
268 265
 		case 11:
269 266
 		case 12:
270 267
 			return rom[address & 0x1FFFFFF];
271
-		default:
272
-		unreadable:
273
-			if (armState)
274
-				return CPUReadMemoryQuick(reg[15].I);
275
-			else
276
-				return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
268
+		case 13:
269
+		case 14:
270
+		case 15:
271
+			return 0;
272
+	}
273
+	if (cpuDmaHack)
274
+		return cpuDmaLast & 0xFF;
275
+	else
276
+	{
277
+		if (armState)
278
+			return CPUReadByteQuick(reg[15].I + (address & 3));
279
+		else
280
+			return CPUReadByteQuick(reg[15].I + (address & 1));
277 281
 	}
278 282
 }
279 283
 
... ...
@@ -305,6 +309,7 @@ inline void CPUWriteMemory(uint32_t address, uint32_t value)
305 309
 				return;
306 310
 			if ((address & 0x18000) == 0x18000)
307 311
 				address &= 0x17fff;
312
+
308 313
 			WRITE32LE(&vram[address], value);
309 314
 			break;
310 315
 		case 0x07:
... ...
@@ -405,7 +410,6 @@ inline void CPUWriteByte(uint32_t address, uint8_t b)
405 410
 						if (b == 0x80)
406 411
 							stopState = true;
407 412
 						holdState = true;
408
-						holdType = -1;
409 413
 						cpuNextEvent = cpuTotalTicks;
410 414
 						break;
411 415
 					default: // every other register
... ...
@@ -415,7 +419,6 @@ inline void CPUWriteByte(uint32_t address, uint8_t b)
415 419
 						else
416 420
 							CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0xFF00) | b);
417 421
 				}
418
-				break;
419 422
 			}
420 423
 			break;
421 424
 		case 5:
... ...
@@ -441,5 +444,3 @@ inline void CPUWriteByte(uint32_t address, uint8_t b)
441 444
 			break;
442 445
 	}
443 446
 }
444
-
445
-#endif // GBAINLINE_H
Browse code

[GSF] Some more code cleanup, also removed a few files that were unneeded.

Naram Qashat authored on 2013/05/16 01:25:34
Showing 1 changed files
... ...
@@ -98,8 +98,8 @@ inline uint32_t CPUReadMemory(uint32_t address)
98 98
 		unreadable:
99 99
 			if (armState)
100 100
 				return CPUReadMemoryQuick(reg[15].I);
101
-			else 
102
-				return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
101
+			else
102
+				return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
103 103
 	}
104 104
 
105 105
 	if (oldAddress & 3)
... ...
@@ -108,13 +108,13 @@ inline uint32_t CPUReadMemory(uint32_t address)
108 108
 		int shift = (oldAddress & 3) << 3;
109 109
 		value = (value >> shift) | (value << (32 - shift));
110 110
 #else
111
-#ifdef __GNUC__
111
+# ifdef __GNUC__
112 112
 		asm("and $3, %%ecx;"
113 113
 			"shl $3 ,%%ecx;"
114 114
 			"ror %%cl, %0"
115 115
 			: "=r" (value)
116 116
 			: "r" (value), "c" (oldAddress));
117
-#else
117
+# else
118 118
 		__asm
119 119
 		{
120 120
 			mov ecx, oldAddress;
... ...
@@ -122,7 +122,7 @@ inline uint32_t CPUReadMemory(uint32_t address)
122 122
 			shl ecx, 3;
123 123
 			ror [dword ptr value], cl;
124 124
 		}
125
-#endif
125
+# endif
126 126
 #endif
127 127
 	}
128 128
 
... ...
@@ -204,16 +204,12 @@ inline uint32_t CPUReadHalfWord(uint32_t address)
204 204
 			else
205 205
 				value = READ16LE(&rom[address & 0x1FFFFFE]);
206 206
 			break;
207
-		case 13:
208
-		case 14:
209
-			return 0;
210
-		// default
211 207
 		default:
212 208
 		unreadable:
213 209
 			if (armState)
214 210
 				return CPUReadMemoryQuick(reg[15].I);
215 211
 			else
216
-				return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
212
+				return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
217 213
 	}
218 214
 
219 215
 	if (oldAddress & 1)
... ...
@@ -272,16 +268,12 @@ inline uint8_t CPUReadByte(uint32_t address)
272 268
 		case 11:
273 269
 		case 12:
274 270
 			return rom[address & 0x1FFFFFF];
275
-		case 13:
276
-		case 14:
277
-			return 0;
278
-		// default
279 271
 		default:
280 272
 		unreadable:
281 273
 			if (armState)
282 274
 				return CPUReadMemoryQuick(reg[15].I);
283 275
 			else
284
-				return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
276
+				return CPUReadHalfWordQuick(reg[15].I) | (CPUReadHalfWordQuick(reg[15].I) << 16);
285 277
 	}
286 278
 }
287 279
 
Browse code

[GSF] Massive code cleanup.

(As an aside, blargg's code style makes me go blarg myself.)

Naram Qashat authored on 2013/05/14 01:07:18
Showing 1 changed files
... ...
@@ -1,13 +1,8 @@
1 1
 #ifndef GBAINLINE_H
2 2
 #define GBAINLINE_H
3 3
 
4
-//#include "../System.h"
5 4
 #include "../common/Port.h"
6
-//#include "RTC.h"
7 5
 #include "Sound.h"
8
-//#include "agbprint.h"
9
-#include "GBAcpu.h"
10
-//#include "GBALink.h"
11 6
 
12 7
 extern const uint32_t objTilesAddress[3];
13 8
 
... ...
@@ -15,11 +10,6 @@ extern bool stopState;
15 10
 extern bool holdState;
16 11
 extern int holdType;
17 12
 extern int cpuNextEvent;
18
-extern bool cpuSramEnabled;
19
-extern bool cpuFlashEnabled;
20
-extern bool cpuEEPROMEnabled;
21
-extern bool cpuEEPROMSensorEnabled;
22
-extern uint32_t cpuDmaLast;
23 13
 extern bool timer0On;
24 14
 extern int timer0Ticks;
25 15
 extern int timer0ClockReload;
... ...
@@ -34,702 +24,430 @@ extern int timer3Ticks;
34 24
 extern int timer3ClockReload;
35 25
 extern int cpuTotalTicks;
36 26
 
37
-#define CPUReadByteQuick(addr) \
38
-  map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]
27
+inline uint16_t CPUReadHalfWordQuick(uint32_t addr) { return READ16LE(&map[addr >> 24].address[addr & map[addr >> 24].mask]); }
39 28
 
40
-#define CPUReadHalfWordQuick(addr) \
41
-  READ16LE(((uint16_t*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
29
+inline uint32_t CPUReadMemoryQuick(uint32_t addr) { return READ32LE(&map[addr >> 24].address[addr & map[addr >> 24].mask]); }
42 30
 
43
-#define CPUReadMemoryQuick(addr) \
44
-  READ32LE(((uint32_t*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
45
-
46
-static inline uint32_t CPUReadMemory(uint32_t address)
31
+inline uint32_t CPUReadMemory(uint32_t address)
47 32
 {
48
-  uint32_t value;
49
-  uint32_t oldAddress = address;
50
-
51
-  if(address & 3) {
52
-           address &= ~0x03;
53
-  }
54
-
55
-  switch(address >> 24) {
56
-  case 0:
57
-    if(reg[15].I >> 24) {
58
-      if(address < 0x4000) {
59
-#ifdef GBA_LOGGING
60
-        if(systemVerbose & VERBOSE_ILLEGAL_READ) {
61
-          log("Illegal word read from bios: %08x at %08x\n", address, armMode ?
62
-            armNextPC - 4 : armNextPC - 2);
63
-        }
64
-#endif
65
-
66
-        value = READ32LE(((uint32_t *)&biosProtected));
67
-      }
68
-      else goto unreadable;
69
-    } else
70
-      value = READ32LE(((uint32_t *)&bios[address & 0x3FFC]));
71
-    break;
72
-  case 2:
73
-    value = READ32LE(((uint32_t *)&workRAM[address & 0x3FFFC]));
74
-    break;
75
-  case 3:
76
-    value = READ32LE(((uint32_t *)&internalRAM[address & 0x7ffC]));
77
-    break;
78
-  case 4:
79
-	  if((address < 0x4000400) && ioReadable[address & 0x3fc]) {
80
-		  if(ioReadable[(address & 0x3fc) + 2]) {
81
-			  value = READ32LE(((uint32_t *)&ioMem[address & 0x3fC]));
82
-			  /*if ((address & 0x3fc) == COMM_JOY_RECV_L)
83
-				  UPDATE_REG(COMM_JOYSTAT, READ16LE(&ioMem[COMM_JOYSTAT]) & ~JOYSTAT_RECV);*/
84
-		  } else {
85
-			  value = READ16LE(((uint16_t *)&ioMem[address & 0x3fc]));
86
-		  }
87
-	  }
88
-	  else
89
-		  goto unreadable;
90
-	  break;
91
-  case 5:
92
-    value = READ32LE(((uint32_t *)&paletteRAM[address & 0x3fC]));
93
-    break;
94
-  case 6:
95
-    address = (address & 0x1fffc);
96
-    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
97
-    {
98
-      value = 0;
99
-      break;
100
-    }
101
-    if ((address & 0x18000) == 0x18000)
102
-      address &= 0x17fff;
103
-    value = READ32LE(((uint32_t *)&vram[address]));
104
-    break;
105
-  case 7:
106
-    value = READ32LE(((uint32_t *)&oam[address & 0x3FC]));
107
-    break;
108
-  case 8:
109
-  case 9:
110
-  case 10:
111
-  case 11:
112
-  case 12:
113
-    value = READ32LE(((uint32_t *)&rom[address&0x1FFFFFC]));
114
-    break;
115
-  case 13:
116
-    if(cpuEEPROMEnabled)
117
-      // no need to swap this
118
-      return /*eepromRead(address)*/0;
119
-    goto unreadable;
120
-  case 14:
121
-    if(cpuFlashEnabled | cpuSramEnabled)
122
-      // no need to swap this
123
-      return /*flashRead(address)*/0;
124
-    // default
125
-  default:
126
-unreadable:
127
-#ifdef GBA_LOGGING
128
-    if(systemVerbose & VERBOSE_ILLEGAL_READ) {
129
-      log("Illegal word read: %08x at %08x\n", address, armMode ?
130
-        armNextPC - 4 : armNextPC - 2);
131
-    }
132
-#endif
133
-
134
-      if(armState) {
135
-                return CPUReadMemoryQuick(reg[15].I);
136
-      } else {
137
-                return CPUReadHalfWordQuick(reg[15].I) |
138
-          CPUReadHalfWordQuick(reg[15].I) << 16;
139
-      }
140
-    }
141
-
142
-  if(oldAddress & 3) {
33
+	uint32_t value;
34
+	uint32_t oldAddress = address;
35
+
36
+	if (address & 3)
37
+		address &= ~0x03;
38
+
39
+	switch (address >> 24)
40
+	{
41
+		case 0:
42
+			if (reg[15].I >> 24)
43
+			{
44
+				if (address < 0x4000)
45
+					value = READ32LE(&biosProtected);
46
+				else
47
+					goto unreadable;
48
+			}
49
+			else
50
+				value = READ32LE(&bios[address & 0x3FFC]);
51
+			break;
52
+		case 2:
53
+			value = READ32LE(&workRAM[address & 0x3FFFC]);
54
+			break;
55
+		case 3:
56
+			value = READ32LE(&internalRAM[address & 0x7ffC]);
57
+			break;
58
+		case 4:
59
+			if (address < 0x4000400 && ioReadable[address & 0x3fc])
60
+			{
61
+				if (ioReadable[(address & 0x3fc) + 2])
62
+					value = READ32LE(&ioMem[address & 0x3fC]);
63
+				else
64
+					value = READ16LE(&ioMem[address & 0x3fc]);
65
+			}
66
+			else
67
+				goto unreadable;
68
+			break;
69
+		case 5:
70
+			value = READ32LE(&paletteRAM[address & 0x3fC]);
71
+			break;
72
+		case 6:
73
+			address &= 0x1fffc;
74
+			if ((DISPCNT & 7) > 2 && (address & 0x1C000) == 0x18000)
75
+			{
76
+				value = 0;
77
+				break;
78
+			}
79
+			if ((address & 0x18000) == 0x18000)
80
+				address &= 0x17fff;
81
+			value = READ32LE(&vram[address]);
82
+			break;
83
+		case 7:
84
+			value = READ32LE(&oam[address & 0x3FC]);
85
+			break;
86
+		case 8:
87
+		case 9:
88
+		case 10:
89
+		case 11:
90
+		case 12:
91
+			value = READ32LE(&rom[address & 0x1FFFFFC]);
92
+			break;
93
+		case 13:
94
+		case 14:
95
+			return 0;
96
+		// default
97
+		default:
98
+		unreadable:
99
+			if (armState)
100
+				return CPUReadMemoryQuick(reg[15].I);
101
+			else 
102
+				return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
103
+	}
104
+
105
+	if (oldAddress & 3)
106
+	{
143 107
 #ifdef C_CORE
144
-        int shift = (oldAddress & 3) << 3;
145
-    value = (value >> shift) | (value << (32 - shift));
108
+		int shift = (oldAddress & 3) << 3;
109
+		value = (value >> shift) | (value << (32 - shift));
146 110
 #else
147 111
 #ifdef __GNUC__
148
-    asm("and $3, %%ecx;"
149
-      "shl $3 ,%%ecx;"
150
-      "ror %%cl, %0"
151
-      : "=r" (value)
152
-      : "r" (value), "c" (oldAddress));
112
+		asm("and $3, %%ecx;"
113
+			"shl $3 ,%%ecx;"
114
+			"ror %%cl, %0"
115
+			: "=r" (value)
116
+			: "r" (value), "c" (oldAddress));
153 117
 #else
154
-    __asm {
155
-      mov ecx, oldAddress;
156
-      and ecx, 3;
157
-      shl ecx, 3;
158
-      ror [dword ptr value], cl;
159
-    }
118
+		__asm
119
+		{
120
+			mov ecx, oldAddress;
121
+			and ecx, 3;
122
+			shl ecx, 3;
123
+			ror [dword ptr value], cl;
124
+		}
160 125
 #endif
161 126
 #endif
162
-  }
127
+	}
163 128
 
164
-#ifdef GBA_LOGGING
165
-  if(oldAddress & 3) {
166
-          if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
167
-                  log("Unaligned word read from: %08x at %08x (%08x)\n", oldAddress, armMode ?
168
-                          armNextPC - 4 : armNextPC - 2, value);
169
-          }
170
-  }
171
-#endif
172
-  return value;
129
+	return value;
173 130
 }
174 131
 
175 132
 extern uint32_t myROM[];
176 133
 
177
-static inline uint32_t CPUReadHalfWord(uint32_t address)
134
+inline uint32_t CPUReadHalfWord(uint32_t address)
178 135
 {
179
-  uint32_t value;
180
-  uint32_t oldAddress = address;
181
-
182
-  if(address & 1) {
183
-          address &= ~0x01;
184
-  }
185
-
186
-  switch(address >> 24) {
187
-  case 0:
188
-    if (reg[15].I >> 24) {
189
-      if(address < 0x4000) {
190
-#ifdef GBA_LOGGING
191
-        if(systemVerbose & VERBOSE_ILLEGAL_READ) {
192
-          log("Illegal halfword read from bios: %08x at %08x\n", oldAddress, armMode ?
193
-            armNextPC - 4 : armNextPC - 2);
194
-        }
195
-#endif
196
-        value = READ16LE(((uint16_t *)&biosProtected[address&2]));
197
-      } else goto unreadable;
198
-    } else
199
-      value = READ16LE(((uint16_t *)&bios[address & 0x3FFE]));
200
-    break;
201
-  case 2:
202
-    value = READ16LE(((uint16_t *)&workRAM[address & 0x3FFFE]));
203
-    break;
204
-  case 3:
205
-    value = READ16LE(((uint16_t *)&internalRAM[address & 0x7ffe]));
206
-    break;
207
-  case 4:
208
-    if((address < 0x4000400) && ioReadable[address & 0x3fe])
209
-    {
210
-      value =  READ16LE(((uint16_t *)&ioMem[address & 0x3fe]));
211
-      if (((address & 0x3fe)>0xFF) && ((address & 0x3fe)<0x10E))
212
-      {
213
-        if (((address & 0x3fe) == 0x100) && timer0On)
214
-          value = 0xFFFF - ((timer0Ticks-cpuTotalTicks) >> timer0ClockReload);
215
-        else
216
-          if (((address & 0x3fe) == 0x104) && timer1On && !(TM1CNT & 4))
217
-            value = 0xFFFF - ((timer1Ticks-cpuTotalTicks) >> timer1ClockReload);
218
-          else
219
-            if (((address & 0x3fe) == 0x108) && timer2On && !(TM2CNT & 4))
220
-              value = 0xFFFF - ((timer2Ticks-cpuTotalTicks) >> timer2ClockReload);
221
-            else
222
-              if (((address & 0x3fe) == 0x10C) && timer3On && !(TM3CNT & 4))
223
-                value = 0xFFFF - ((timer3Ticks-cpuTotalTicks) >> timer3ClockReload);
224
-      }
225
-    }
226
-    else goto unreadable;
227
-    break;
228
-  case 5:
229
-    value = READ16LE(((uint16_t *)&paletteRAM[address & 0x3fe]));
230
-    break;
231
-  case 6:
232
-    address = (address & 0x1fffe);
233
-    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
234
-    {
235
-      value = 0;
236
-      break;
237
-    }
238
-    if ((address & 0x18000) == 0x18000)
239
-      address &= 0x17fff;
240
-    value = READ16LE(((uint16_t *)&vram[address]));
241
-    break;
242
-  case 7:
243
-    value = READ16LE(((uint16_t *)&oam[address & 0x3fe]));
244
-    break;
245
-  case 8:
246
-  case 9:
247
-  case 10:
248
-  case 11:
249
-  case 12:
250
-    if(address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)
251
-      value = /*rtcRead(address)*/0;
252
-    else
253
-      value = READ16LE(((uint16_t *)&rom[address & 0x1FFFFFE]));
254
-    break;
255
-  case 13:
256
-    if(cpuEEPROMEnabled)
257
-      // no need to swap this
258
-      return /*eepromRead(address)*/0;
259
-    goto unreadable;
260
-  case 14:
261
-    if(cpuFlashEnabled | cpuSramEnabled)
262
-      // no need to swap this
263
-      return /*flashRead(address)*/0;
264
-    // default
265
-  default:
266
-unreadable:
267
-#ifdef GBA_LOGGING
268
-    if(systemVerbose & VERBOSE_ILLEGAL_READ) {
269
-      log("Illegal halfword read: %08x at %08x\n", oldAddress, armMode ?
270
-        armNextPC - 4 : armNextPC - 2);
271
-    }
272
-#endif
273
-      if(armState) {
274
-                return CPUReadMemoryQuick(reg[15].I);
275
-      } else {
276
-                return CPUReadHalfWordQuick(reg[15].I) |
277
-                                CPUReadHalfWordQuick(reg[15].I) << 16;
278
-      }
279
-    }
280
-
281
-  if(oldAddress & 1) {
282
-    value = (value >> 8) | (value << 24);
283
-#ifdef GBA_LOGGING
284
-          if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
285
-                  log("Unaligned halfword read from: %08x at %08x (%08x)\n", oldAddress, armMode ?
286
-                          armNextPC - 4 : armNextPC - 2, value);
287
-          }
288
-#endif
289
-  }
290
-
291
-  return value;
136
+	uint32_t value;
137
+	uint32_t oldAddress = address;
138
+
139
+	if (address & 1)
140
+		address &= ~0x01;
141
+
142
+	switch (address >> 24)
143
+	{
144
+		case 0:
145
+			if (reg[15].I >> 24)
146
+			{
147
+				if (address < 0x4000)
148
+					value = READ16LE(&biosProtected[address & 2]);
149
+				else
150
+					goto unreadable;
151
+			}
152
+			else
153
+				value = READ16LE(&bios[address & 0x3FFE]);
154
+			break;
155
+		case 2:
156
+			value = READ16LE(&workRAM[address & 0x3FFFE]);
157
+			break;
158
+		case 3:
159
+			value = READ16LE(&internalRAM[address & 0x7ffe]);
160
+			break;
161
+		case 4:
162
+			if (address < 0x4000400 && ioReadable[address & 0x3fe])
163
+			{
164
+				value = READ16LE(&ioMem[address & 0x3fe]);
165
+				if ((address & 0x3fe) > 0xFF && (address & 0x3fe) < 0x10E)
166
+				{
167
+					if ((address & 0x3fe) == 0x100 && timer0On)
168
+						value = 0xFFFF - ((timer0Ticks - cpuTotalTicks) >> timer0ClockReload);
169
+					else if ((address & 0x3fe) == 0x104 && timer1On && !(TM1CNT & 4))
170
+						value = 0xFFFF - ((timer1Ticks - cpuTotalTicks) >> timer1ClockReload);
171
+					else if ((address & 0x3fe) == 0x108 && timer2On && !(TM2CNT & 4))
172
+						value = 0xFFFF - ((timer2Ticks - cpuTotalTicks) >> timer2ClockReload);
173
+					else if ((address & 0x3fe) == 0x10C && timer3On && !(TM3CNT & 4))
174
+						value = 0xFFFF - ((timer3Ticks - cpuTotalTicks) >> timer3ClockReload);
175
+				}
176
+			}
177
+			else
178
+				goto unreadable;
179
+			break;
180
+		case 5:
181
+			value = READ16LE(&paletteRAM[address & 0x3fe]);
182
+			break;
183
+		case 6:
184
+			address &= 0x1fffe;
185
+			if ((DISPCNT & 7) > 2 && (address & 0x1C000) == 0x18000)
186
+			{
187
+				value = 0;
188
+				break;
189
+			}
190
+			if ((address & 0x18000) == 0x18000)
191
+				address &= 0x17fff;
192
+			value = READ16LE(&vram[address]);
193
+			break;
194
+		case 7:
195
+			value = READ16LE(&oam[address & 0x3fe]);
196
+			break;
197
+		case 8:
198
+		case 9:
199
+		case 10:
200
+		case 11:
201
+		case 12:
202
+			if (address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)
203
+				value = 0;
204
+			else
205
+				value = READ16LE(&rom[address & 0x1FFFFFE]);
206
+			break;
207
+		case 13:
208
+		case 14:
209
+			return 0;
210
+		// default
211
+		default:
212
+		unreadable:
213
+			if (armState)
214
+				return CPUReadMemoryQuick(reg[15].I);
215
+			else
216
+				return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
217
+	}
218
+
219
+	if (oldAddress & 1)
220
+		value = (value >> 8) | (value << 24);
221
+
222
+	return value;
292 223
 }
293 224
 
294
-static inline int16_t CPUReadHalfWordSigned(uint32_t address)
225
+inline int16_t CPUReadHalfWordSigned(uint32_t address)
295 226
 {
296
-  uint32_t oldAddress = address;
297
-  if(address & 1) {
298
-    address &= ~0x01;
299
-  }
300
-  int16_t value = (int16_t)CPUReadHalfWord(address);
301
-  if((oldAddress & 1))
302
-  {
303
-    value = (int8_t)value;
304
-#ifdef GBA_LOGGING
305
-        if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
306
-                log("Unaligned signed halfword read from: %08x at %08x (%08x)\n", oldAddress, armMode ?
307
-                        armNextPC - 4 : armNextPC - 2, value);
308
-        }
309
-#endif
310
-  }
311
-  return value;
227
+	uint32_t oldAddress = address;
228
+	if (address & 1)
229
+		address &= ~0x01;
230
+	int16_t value = static_cast<int16_t>(CPUReadHalfWord(address));
231
+	if (oldAddress & 1)
232
+		value = static_cast<int8_t>(value);
233
+	return value;
312 234
 }
313 235
 
314
-static inline uint8_t CPUReadByte(uint32_t address)
236
+inline uint8_t CPUReadByte(uint32_t address)
315 237
 {
316
-  switch(address >> 24) {
317
-  case 0:
318
-    if (reg[15].I >> 24) {
319
-      if(address < 0x4000) {
320
-#ifdef GBA_LOGGING
321
-        if(systemVerbose & VERBOSE_ILLEGAL_READ) {
322
-          log("Illegal byte read from bios: %08x at %08x\n", address, armMode ?
323
-            armNextPC - 4 : armNextPC - 2);
324
-        }
325
-#endif
326
-        return biosProtected[address & 3];
327
-      } else goto unreadable;
328
-    }
329
-    return bios[address & 0x3FFF];
330
-  case 2:
331
-    return workRAM[address & 0x3FFFF];
332
-  case 3:
333
-    return internalRAM[address & 0x7fff];
334
-  case 4:
335
-    if((address < 0x4000400) && ioReadable[address & 0x3ff])
336
-      return ioMem[address & 0x3ff];
337
-    else goto unreadable;
338
-  case 5:
339
-    return paletteRAM[address & 0x3ff];
340
-  case 6:
341
-    address = (address & 0x1ffff);
342
-    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
343
-      return 0;
344
-    if ((address & 0x18000) == 0x18000)
345
-      address &= 0x17fff;
346
-    return vram[address];
347
-  case 7:
348
-    return oam[address & 0x3ff];
349
-  case 8:
350
-  case 9:
351
-  case 10:
352
-  case 11:
353
-  case 12:
354
-    return rom[address & 0x1FFFFFF];
355
-  case 13:
356
-    if(cpuEEPROMEnabled)
357
-      return /*eepromRead(address)*/0;
358
-    goto unreadable;
359
-  case 14:
360
-    if(cpuSramEnabled | cpuFlashEnabled)
361
-      return /*flashRead(address)*/0;
362
-    if(cpuEEPROMSensorEnabled) {
363
-      switch(address & 0x00008f00) {
364
-  case 0x8200:
365
-    return /*systemGetSensorX() & 255*/0;
366
-  case 0x8300:
367
-    return /*(systemGetSensorX() >> 8)|0x80*/0;
368
-  case 0x8400:
369
-    return /*systemGetSensorY() & 255*/0;
370
-  case 0x8500:
371
-    return /*systemGetSensorY() >> 8*/0;
372
-      }
373
-    }
374
-    // default
375
-  default:
376
-unreadable:
377
-#ifdef GBA_LOGGING
378
-    if(systemVerbose & VERBOSE_ILLEGAL_READ) {
379
-      log("Illegal byte read: %08x at %08x\n", address, armMode ?
380
-        armNextPC - 4 : armNextPC - 2);
381
-    }
382
-#endif
383
-      if(armState) {
384
-                         return CPUReadMemoryQuick(reg[15].I);
385
-      } else {
386
-                         return CPUReadHalfWordQuick(reg[15].I) |
387
-                                 CPUReadHalfWordQuick(reg[15].I) << 16;
388
-      }
389
-    }
238
+	switch (address >> 24)
239
+	{
240
+		case 0:
241
+			if (reg[15].I >> 24)
242
+			{
243
+				if (address < 0x4000)
244
+					return biosProtected[address & 3];
245
+				else
246
+					goto unreadable;
247
+			}
248
+			return bios[address & 0x3FFF];
249
+		case 2:
250
+			return workRAM[address & 0x3FFFF];
251
+		case 3:
252
+			return internalRAM[address & 0x7fff];
253
+		case 4:
254
+			if (address < 0x4000400 && ioReadable[address & 0x3ff])
255
+				return ioMem[address & 0x3ff];
256
+			else
257
+				goto unreadable;
258
+		case 5:
259
+			return paletteRAM[address & 0x3ff];
260
+		case 6:
261
+			address &= 0x1ffff;
262
+			if ((DISPCNT & 7) > 2 && (address & 0x1C000) == 0x18000)
263
+				return 0;
264
+			if ((address & 0x18000) == 0x18000)
265
+				address &= 0x17fff;
266
+			return vram[address];
267
+		case 7:
268
+			return oam[address & 0x3ff];
269
+		case 8:
270
+		case 9:
271
+		case 10:
272
+		case 11:
273
+		case 12:
274
+			return rom[address & 0x1FFFFFF];
275
+		case 13:
276
+		case 14:
277
+			return 0;
278
+		// default
279
+		default:
280
+		unreadable:
281
+			if (armState)
282
+				return CPUReadMemoryQuick(reg[15].I);
283
+			else
284
+				return CPUReadHalfWordQuick(reg[15].I) | CPUReadHalfWordQuick(reg[15].I) << 16;
285
+	}
390 286
 }
391 287
 
392
-static inline void CPUWriteMemory(uint32_t address, uint32_t value)
288
+inline void CPUWriteMemory(uint32_t address, uint32_t value)
393 289
 {
394
-
395
-#ifdef GBA_LOGGING
396
-  if(address & 3) {
397
-    if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
398
-      log("Unaligned word write: %08x to %08x from %08x\n",
399
-        value,
400
-        address,
401
-        armMode ? armNextPC - 4 : armNextPC - 2);
402
-    }
403
-  }
404
-#endif
405
-
406
-  address &= 0xFFFFFFFC;
407
-
408
-  switch(address >> 24) {
409
-  case 0x02:
410
-#ifdef BKPT_SUPPORT
411
-    if(*((uint32_t *)&freezeWorkRAM[address & 0x3FFFC]))
412
-      cheatsWriteMemory(address & 0x203FFFC,
413
-      value);
414
-    else
415
-#endif
416
-      WRITE32LE(((uint32_t *)&workRAM[address & 0x3FFFC]), value);
417
-    break;
418
-  case 0x03:
419
-#ifdef BKPT_SUPPORT
420
-    if(*((uint32_t *)&freezeInternalRAM[address & 0x7ffc]))
421
-      cheatsWriteMemory(address & 0x3007FFC,
422
-      value);
423
-    else
424
-#endif
425
-      WRITE32LE(((uint32_t *)&internalRAM[address & 0x7ffC]), value);
426
-    break;
427
-  case 0x04:
428
-    if(address < 0x4000400) {
429
-      CPUUpdateRegister((address & 0x3FC), value & 0xFFFF);
430
-      CPUUpdateRegister((address & 0x3FC) + 2, (value >> 16));
431
-    } else goto unwritable;
432
-    break;
433
-  case 0x05:
434
-#ifdef BKPT_SUPPORT
435
-    if(*((uint32_t *)&freezePRAM[address & 0x3fc]))
436
-      cheatsWriteMemory(address & 0x70003FC,
437
-      value);
438
-    else
439
-#endif
440
-      WRITE32LE(((uint32_t *)&paletteRAM[address & 0x3FC]), value);
441
-    break;
442
-  case 0x06:
443
-    address = (address & 0x1fffc);
444
-    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
445
-      return;
446
-    if ((address & 0x18000) == 0x18000)
447
-      address &= 0x17fff;
448
-
449
-#ifdef BKPT_SUPPORT
450
-    if(*((uint32_t *)&freezeVRAM[address]))
451
-      cheatsWriteMemory(address + 0x06000000, value);
452
-    else
453
-#endif
454
-
455
-      WRITE32LE(((uint32_t *)&vram[address]), value);
456
-    break;
457
-  case 0x07:
458
-#ifdef BKPT_SUPPORT
459
-    if(*((uint32_t *)&freezeOAM[address & 0x3fc]))
460
-      cheatsWriteMemory(address & 0x70003FC,
461
-      value);
462
-    else
463
-#endif
464
-      WRITE32LE(((uint32_t *)&oam[address & 0x3fc]), value);
465
-    break;
466
-  case 0x0D:
467
-    if(cpuEEPROMEnabled) {
468
-      //eepromWrite(address, value);
469
-      break;
470
-    }
471
-    goto unwritable;
472
-  /*case 0x0E:
473
-    if(*//*(!eepromInUse) | *//*cpuSramEnabled | cpuFlashEnabled) {
474
-      //(*cpuSaveGameFunc)(address, (u8)value);
475
-      break;
476
-    }*/
477
-    // default
478
-  default:
479
-unwritable:
480
-#ifdef GBA_LOGGING
481
-    if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
482
-      log("Illegal word write: %08x to %08x from %08x\n",
483
-        value,
484
-        address,
485
-        armMode ? armNextPC - 4 : armNextPC - 2);
486
-    }
487
-#endif
488
-    break;
489
-  }
290
+	address &= 0xFFFFFFFC;
291
+
292
+	switch (address >> 24)
293
+	{
294
+		case 0x02:
295
+			WRITE32LE(&workRAM[address & 0x3FFFC], value);
296
+			break;
297
+		case 0x03:
298
+			WRITE32LE(&internalRAM[address & 0x7ffC], value);
299
+			break;
300
+		case 0x04:
301
+			if (address < 0x4000400)
302
+			{
303
+				CPUUpdateRegister(address & 0x3FC, value & 0xFFFF);
304
+				CPUUpdateRegister((address & 0x3FC) + 2, value >> 16);
305
+			}
306
+			break;
307
+		case 0x05:
308
+			WRITE32LE(&paletteRAM[address & 0x3FC], value);
309
+			break;
310
+		case 0x06:
311
+			address &= 0x1fffc;
312
+			if ((DISPCNT & 7) > 2 && (address & 0x1C000) == 0x18000)
313
+				return;
314
+			if ((address & 0x18000) == 0x18000)
315
+				address &= 0x17fff;
316
+			WRITE32LE(&vram[address], value);
317
+			break;
318
+		case 0x07:
319
+			WRITE32LE(&oam[address & 0x3fc], value);
320
+	}
490 321
 }
491 322
 
492
-static inline void CPUWriteHalfWord(uint32_t address, uint16_t value)
323
+inline void CPUWriteHalfWord(uint32_t address, uint16_t value)
493 324
 {
494
-#ifdef GBA_LOGGING
495
-  if(address & 1) {
496
-    if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
497
-      log("Unaligned halfword write: %04x to %08x from %08x\n",
498
-        value,
499
-        address,
500
-        armMode ? armNextPC - 4 : armNextPC - 2);
501
-    }
502
-  }
503
-#endif
504
-
505
-  address &= 0xFFFFFFFE;
506
-
507
-  switch(address >> 24) {
508
-  case 2:
509
-#ifdef BKPT_SUPPORT
510
-    if(*((uint16_t *)&freezeWorkRAM[address & 0x3FFFE]))
511
-      cheatsWriteHalfWord(address & 0x203FFFE,
512
-      value);
513
-    else
514
-#endif
515
-      WRITE16LE(((uint16_t *)&workRAM[address & 0x3FFFE]),value);
516
-    break;
517
-  case 3:
518
-#ifdef BKPT_SUPPORT
519
-    if(*((uint16_t *)&freezeInternalRAM[address & 0x7ffe]))
520
-      cheatsWriteHalfWord(address & 0x3007ffe,
521
-      value);
522
-    else
523
-#endif
524
-      WRITE16LE(((uint16_t *)&internalRAM[address & 0x7ffe]), value);
525
-    break;
526
-  case 4:
527
-    if(address < 0x4000400)
528
-      CPUUpdateRegister(address & 0x3fe, value);
529
-    else goto unwritable;
530
-    break;
531
-  case 5:
532
-#ifdef BKPT_SUPPORT
533
-    if(*((uint16_t *)&freezePRAM[address & 0x03fe]))
534
-      cheatsWriteHalfWord(address & 0x70003fe,
535
-      value);
536
-    else
537
-#endif
538
-      WRITE16LE(((uint16_t *)&paletteRAM[address & 0x3fe]), value);
539
-    break;
540
-  case 6:
541
-    address = (address & 0x1fffe);
542
-    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
543
-      return;
544
-    if ((address & 0x18000) == 0x18000)
545
-      address &= 0x17fff;
546
-#ifdef BKPT_SUPPORT
547
-    if(*((uint16_t *)&freezeVRAM[address]))
548
-      cheatsWriteHalfWord(address + 0x06000000,
549
-      value);
550
-    else
551
-#endif
552
-      WRITE16LE(((uint16_t *)&vram[address]), value);
553
-    break;
554
-  case 7:
555
-#ifdef BKPT_SUPPORT
556
-    if(*((uint16_t *)&freezeOAM[address & 0x03fe]))
557
-      cheatsWriteHalfWord(address & 0x70003fe,
558
-      value);
559
-    else
560
-#endif
561
-      WRITE16LE(((uint16_t *)&oam[address & 0x3fe]), value);
562
-    break;
563
-  case 8:
564
-  case 9:
565
-   /* if(address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8) {
566
-      if(!rtcWrite(address, value))
567
-        goto unwritable;
568
-    } else if(!agbPrintWrite(address, value)) goto unwritable;*/
569
-    break;
570
-  case 13:
571
-    if(cpuEEPROMEnabled) {
572
-      //eepromWrite(address, (u8)value);
573
-      break;
574
-    }
575
-    goto unwritable;
576
-  /*case 14:
577
-    if(*//*(!eepromInUse) | *//*cpuSramEnabled | cpuFlashEnabled) {
578
-      //(*cpuSaveGameFunc)(address, (u8)value);
579
-      break;
580
-    }
581
-    goto unwritable;*/
582
-  default:
583
-unwritable:
584
-#ifdef GBA_LOGGING
585
-    if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
586
-      log("Illegal halfword write: %04x to %08x from %08x\n",
587
-        value,
588
-        address,
589
-        armMode ? armNextPC - 4 : armNextPC - 2);
590
-    }
591
-#endif
592
-    break;
593
-  }
325
+	address &= 0xFFFFFFFE;
326
+
327
+	switch (address >> 24)
328
+	{
329
+		case 2:
330
+			WRITE16LE(&workRAM[address & 0x3FFFE], value);
331
+			break;
332
+		case 3:
333
+			WRITE16LE(&internalRAM[address & 0x7ffe], value);
334
+			break;
335
+		case 4:
336
+			if (address < 0x4000400)
337
+				CPUUpdateRegister(address & 0x3fe, value);
338
+			break;
339
+		case 5:
340
+			WRITE16LE(&paletteRAM[address & 0x3fe], value);
341
+			break;
342
+		case 6:
343
+			address &= 0x1fffe;
344
+			if ((DISPCNT & 7) > 2 && (address & 0x1C000) == 0x18000)
345
+				return;
346
+			if ((address & 0x18000) == 0x18000)
347
+				address &= 0x17fff;
348
+			WRITE16LE(&vram[address], value);
349
+			break;
350
+		case 7:
351
+			WRITE16LE(&oam[address & 0x3fe], value);
352
+	}
594 353
 }
595 354
 
596
-static inline void CPUWriteByte(uint32_t address, uint8_t b)
355
+inline void CPUWriteByte(uint32_t address, uint8_t b)
597 356
 {
598
-  switch(address >> 24) {
599
-  case 2:
600
-#ifdef BKPT_SUPPORT
601
-    if(freezeWorkRAM[address & 0x3FFFF])
602
-      cheatsWriteByte(address & 0x203FFFF, b);
603
-    else
604
-#endif
605
-      workRAM[address & 0x3FFFF] = b;
606
-    break;
607
-  case 3:
608
-#ifdef BKPT_SUPPORT
609
-    if(freezeInternalRAM[address & 0x7fff])
610
-      cheatsWriteByte(address & 0x3007fff, b);
611
-    else
612
-#endif
613
-      internalRAM[address & 0x7fff] = b;
614
-    break;
615
-  case 4:
616
-    if(address < 0x4000400) {
617
-      switch(address & 0x3FF) {
618
-      case 0x60:
619
-      case 0x61:
620
-      case 0x62:
621
-      case 0x63:
622
-      case 0x64:
623
-      case 0x65:
624
-      case 0x68:
625
-      case 0x69:
626
-      case 0x6c:
627
-      case 0x6d:
628
-      case 0x70:
629
-      case 0x71:
630
-      case 0x72:
631
-      case 0x73:
632
-      case 0x74:
633
-      case 0x75:
634
-      case 0x78:
635
-      case 0x79:
636
-      case 0x7c:
637
-      case 0x7d:
638
-      case 0x80:
639
-      case 0x81:
640
-      case 0x84:
641
-      case 0x85:
642
-      case 0x90:
643
-      case 0x91:
644
-      case 0x92:
645
-      case 0x93:
646
-      case 0x94:
647
-      case 0x95:
648
-      case 0x96:
649
-      case 0x97:
650
-      case 0x98:
651
-      case 0x99:
652
-      case 0x9a:
653
-      case 0x9b:
654
-      case 0x9c:
655
-      case 0x9d:
656
-      case 0x9e:
657
-      case 0x9f:
658
-        soundEvent(address&0xFF, b);
659
-        break;
660
-      case 0x301: // HALTCNT, undocumented
661
-        if(b == 0x80)
662
-          stopState = true;
663
-        holdState = 1;
664
-        holdType = -1;
665
-        cpuNextEvent = cpuTotalTicks;
666
-        break;
667
-      default: // every other register
668
-        uint32_t lowerBits = address & 0x3fe;
669
-        if(address & 1) {
670
-          CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0x00FF) | (b << 8));
671
-        } else {
672
-          CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0xFF00) | b);
673
-        }
674
-      }
675
-      break;
676
-    } else goto unwritable;
677
-    break;
678
-  case 5:
679
-    // no need to switch
680
-    *((uint16_t *)&paletteRAM[address & 0x3FE]) = (b << 8) | b;
681
-    break;
682
-  case 6:
683
-    address = (address & 0x1fffe);
684
-    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
685
-      return;
686
-    if ((address & 0x18000) == 0x18000)
687
-      address &= 0x17fff;
688
-
689
-    // no need to switch
690
-    // byte writes to OBJ VRAM are ignored
691
-    if ((address) < objTilesAddress[((DISPCNT&7)+1)>>2])
692
-    {
693
-#ifdef BKPT_SUPPORT
694
-      if(freezeVRAM[address])
695
-        cheatsWriteByte(address + 0x06000000, b);
696
-      else
697
-#endif
698
-        *((uint16_t *)&vram[address]) = (b << 8) | b;
699
-    }
700
-    break;
701
-  case 7:
702
-    // no need to switch
703
-    // byte writes to OAM are ignored
704
-    //    *((uint16_t *)&oam[address & 0x3FE]) = (b << 8) | b;
705
-    break;
706
-  case 13:
707
-    if(cpuEEPROMEnabled) {
708
-      //eepromWrite(address, b);
709
-      break;
710
-    }
711
-    goto unwritable;
712
-  /*case 14:
713
-    if ((saveType != 5) && (*//*(!eepromInUse) | *//*cpuSramEnabled | cpuFlashEnabled)) {
714
-
715
-      //if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) {
716
-
717
-      //(*cpuSaveGameFunc)(address, b);
718
-      break;
719
-    }*/
720
-    // default
721
-  default:
722
-unwritable:
723
-#ifdef GBA_LOGGING
724
-    if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
725
-      log("Illegal byte write: %02x to %08x from %08x\n",
726
-        b,
727
-        address,
728
-        armMode ? armNextPC - 4 : armNextPC -2 );
729
-    }
730
-#endif
731
-    break;
732
-  }
357
+	switch (address >> 24)
358
+	{
359
+		case 2:
360
+			workRAM[address & 0x3FFFF] = b;
361
+			break;
362
+		case 3:
363
+			internalRAM[address & 0x7fff] = b;
364
+			break;
365
+		case 4:
366
+			if (address < 0x4000400)
367
+			{
368
+				switch (address & 0x3FF)
369
+				{
370
+					case 0x60:
371
+					case 0x61:
372
+					case 0x62:
373
+					case 0x63:
374
+					case 0x64:
375
+					case 0x65:
376
+					case 0x68:
377
+					case 0x69:
378
+					case 0x6c:
379
+					case 0x6d:
380
+					case 0x70:
381
+					case 0x71:
382
+					case 0x72:
383
+					case 0x73:
384
+					case 0x74:
385
+					case 0x75:
386
+					case 0x78:
387
+					case 0x79:
388
+					case 0x7c:
389
+					case 0x7d:
390
+					case 0x80:
391
+					case 0x81:
392
+					case 0x84:
393
+					case 0x85:
394
+					case 0x90:
395
+					case 0x91:
396
+					case 0x92:
397
+					case 0x93:
398
+					case 0x94:
399
+					case 0x95:
400
+					case 0x96:
401
+					case 0x97:
402
+					case 0x98:
403
+					case 0x99:
404
+					case 0x9a:
405
+					case 0x9b:
406
+					case 0x9c:
407
+					case 0x9d:
408
+					case 0x9e:
409
+					case 0x9f:
410
+						soundEvent(address & 0xFF, b);
411
+						break;
412
+					case 0x301: // HALTCNT, undocumented
413
+						if (b == 0x80)
414
+							stopState = true;
415
+						holdState = true;
416
+						holdType = -1;
417
+						cpuNextEvent = cpuTotalTicks;
418
+						break;
419
+					default: // every other register
420
+						uint32_t lowerBits = address & 0x3fe;
421
+						if (address & 1)
422
+							CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0x00FF) | (b << 8));
423
+						else
424
+							CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0xFF00) | b);
425
+				}
426
+				break;
427
+			}
428
+			break;
429
+		case 5:
430
+			// no need to switch
431
+			*reinterpret_cast<uint16_t *>(&paletteRAM[address & 0x3FE]) = (b << 8) | b;
432
+			break;
433
+		case 6:
434
+			address &= 0x1fffe;
435
+			if ((DISPCNT & 7) > 2 && (address & 0x1C000) == 0x18000)
436
+				return;
437
+			if ((address & 0x18000) == 0x18000)
438
+				address &= 0x17fff;
439
+
440
+			// no need to switch
441
+			// byte writes to OBJ VRAM are ignored
442
+			if (address < objTilesAddress[((DISPCNT & 7) + 1) >> 2])
443
+				*reinterpret_cast<uint16_t *>(&vram[address]) = (b << 8) | b;
444
+			break;
445
+		case 7:
446
+			// no need to switch
447
+			// byte writes to OAM are ignored
448
+			//*reinterpret_cast<uint16_t *>(&oam[address & 0x3FE]) = (b << 8) | b;
449
+			break;
450
+	}
733 451
 }
734 452
 
735 453
 #endif // GBAINLINE_H
Browse code

[GSF] Cleanup, a tiny bit of making sure it was like viogsf, also used the standard integer types and not VBA-M's typedefs.

Naram Qashat authored on 2013/05/10 17:45:36
Showing 1 changed files
... ...
@@ -9,7 +9,7 @@
9 9
 #include "GBAcpu.h"
10 10
 //#include "GBALink.h"
11 11
 
12
-extern const u32 objTilesAddress[3];
12
+extern const uint32_t objTilesAddress[3];
13 13
 
14 14
 extern bool stopState;
15 15
 extern bool holdState;
... ...
@@ -19,7 +19,7 @@ extern bool cpuSramEnabled;
19 19
 extern bool cpuFlashEnabled;
20 20
 extern bool cpuEEPROMEnabled;
21 21
 extern bool cpuEEPROMSensorEnabled;
22
-extern u32 cpuDmaLast;
22
+extern uint32_t cpuDmaLast;
23 23
 extern bool timer0On;
24 24
 extern int timer0Ticks;
25 25
 extern int timer0ClockReload;
... ...
@@ -38,15 +38,15 @@ extern int cpuTotalTicks;
38 38
   map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]
39 39
 
40 40
 #define CPUReadHalfWordQuick(addr) \
41
-  READ16LE(((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
41
+  READ16LE(((uint16_t*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
42 42
 
43 43
 #define CPUReadMemoryQuick(addr) \
44
-  READ32LE(((u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
44
+  READ32LE(((uint32_t*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
45 45
 
46
-static inline u32 CPUReadMemory(u32 address)
46
+static inline uint32_t CPUReadMemory(uint32_t address)
47 47
 {
48
-  u32 value;
49
-  u32 oldAddress = address;
48
+  uint32_t value;
49
+  uint32_t oldAddress = address;
50 50
 
51 51
   if(address & 3) {
52 52
            address &= ~0x03;
... ...
@@ -63,33 +63,33 @@ static inline u32 CPUReadMemory(u32 address)
63 63
         }
64 64
 #endif
65 65
 
66
-        value = READ32LE(((u32 *)&biosProtected));
66
+        value = READ32LE(((uint32_t *)&biosProtected));
67 67
       }
68 68
       else goto unreadable;
69 69
     } else
70
-      value = READ32LE(((u32 *)&bios[address & 0x3FFC]));
70
+      value = READ32LE(((uint32_t *)&bios[address & 0x3FFC]));
71 71
     break;
72 72
   case 2:
73
-    value = READ32LE(((u32 *)&workRAM[address & 0x3FFFC]));
73
+    value = READ32LE(((uint32_t *)&workRAM[address & 0x3FFFC]));
74 74
     break;
75 75
   case 3:
76
-    value = READ32LE(((u32 *)&internalRAM[address & 0x7ffC]));
76
+    value = READ32LE(((uint32_t *)&internalRAM[address & 0x7ffC]));
77 77
     break;
78 78
   case 4:
79 79
 	  if((address < 0x4000400) && ioReadable[address & 0x3fc]) {
80 80
 		  if(ioReadable[(address & 0x3fc) + 2]) {
81
-			  value = READ32LE(((u32 *)&ioMem[address & 0x3fC]));
81
+			  value = READ32LE(((uint32_t *)&ioMem[address & 0x3fC]));
82 82
 			  /*if ((address & 0x3fc) == COMM_JOY_RECV_L)
83 83
 				  UPDATE_REG(COMM_JOYSTAT, READ16LE(&ioMem[COMM_JOYSTAT]) & ~JOYSTAT_RECV);*/
84 84
 		  } else {
85
-			  value = READ16LE(((u16 *)&ioMem[address & 0x3fc]));
85
+			  value = READ16LE(((uint16_t *)&ioMem[address & 0x3fc]));
86 86
 		  }
87 87
 	  }
88 88
 	  else
89 89
 		  goto unreadable;
90 90
 	  break;
91 91
   case 5:
92
-    value = READ32LE(((u32 *)&paletteRAM[address & 0x3fC]));
92
+    value = READ32LE(((uint32_t *)&paletteRAM[address & 0x3fC]));
93 93
     break;
94 94
   case 6:
95 95
     address = (address & 0x1fffc);
... ...
@@ -100,17 +100,17 @@ static inline u32 CPUReadMemory(u32 address)
100 100
     }
101 101
     if ((address & 0x18000) == 0x18000)
102 102
       address &= 0x17fff;
103
-    value = READ32LE(((u32 *)&vram[address]));
103
+    value = READ32LE(((uint32_t *)&vram[address]));
104 104
     break;
105 105
   case 7:
106
-    value = READ32LE(((u32 *)&oam[address & 0x3FC]));
106
+    value = READ32LE(((uint32_t *)&oam[address & 0x3FC]));
107 107
     break;
108 108
   case 8:
109 109
   case 9:
110 110
   case 10:
111 111
   case 11:
112 112
   case 12:
113
-    value = READ32LE(((u32 *)&rom[address&0x1FFFFFC]));
113
+    value = READ32LE(((uint32_t *)&rom[address&0x1FFFFFC]));
114 114
     break;
115 115
   case 13:
116 116
     if(cpuEEPROMEnabled)
... ...
@@ -172,12 +172,12 @@ unreadable:
172 172
   return value;
173 173
 }
174 174
 
175
-extern u32 myROM[];
175
+extern uint32_t myROM[];
176 176
 
177
-static inline u32 CPUReadHalfWord(u32 address)
177
+static inline uint32_t CPUReadHalfWord(uint32_t address)
178 178
 {
179
-  u32 value;
180
-  u32 oldAddress = address;
179
+  uint32_t value;
180
+  uint32_t oldAddress = address;
181 181
 
182 182
   if(address & 1) {
183 183
           address &= ~0x01;
... ...
@@ -193,21 +193,21 @@ static inline u32 CPUReadHalfWord(u32 address)
193 193
             armNextPC - 4 : armNextPC - 2);
194 194
         }
195 195
 #endif
196
-        value = READ16LE(((u16 *)&biosProtected[address&2]));
196
+        value = READ16LE(((uint16_t *)&biosProtected[address&2]));
197 197
       } else goto unreadable;
198 198
     } else
199
-      value = READ16LE(((u16 *)&bios[address & 0x3FFE]));
199
+      value = READ16LE(((uint16_t *)&bios[address & 0x3FFE]));
200 200
     break;
201 201
   case 2:
202
-    value = READ16LE(((u16 *)&workRAM[address & 0x3FFFE]));
202
+    value = READ16LE(((uint16_t *)&workRAM[address & 0x3FFFE]));
203 203
     break;
204 204
   case 3:
205
-    value = READ16LE(((u16 *)&internalRAM[address & 0x7ffe]));
205
+    value = READ16LE(((uint16_t *)&internalRAM[address & 0x7ffe]));
206 206
     break;
207 207
   case 4:
208 208
     if((address < 0x4000400) && ioReadable[address & 0x3fe])
209 209
     {
210
-      value =  READ16LE(((u16 *)&ioMem[address & 0x3fe]));
210
+      value =  READ16LE(((uint16_t *)&ioMem[address & 0x3fe]));
211 211
       if (((address & 0x3fe)>0xFF) && ((address & 0x3fe)<0x10E))
212 212
       {
213 213
         if (((address & 0x3fe) == 0x100) && timer0On)
... ...
@@ -226,7 +226,7 @@ static inline u32 CPUReadHalfWord(u32 address)
226 226
     else goto unreadable;
227 227
     break;
228 228
   case 5:
229
-    value = READ16LE(((u16 *)&paletteRAM[address & 0x3fe]));
229
+    value = READ16LE(((uint16_t *)&paletteRAM[address & 0x3fe]));
230 230
     break;
231 231
   case 6:
232 232
     address = (address & 0x1fffe);
... ...
@@ -237,10 +237,10 @@ static inline u32 CPUReadHalfWord(u32 address)
237 237
     }
238 238
     if ((address & 0x18000) == 0x18000)
239 239
       address &= 0x17fff;
240
-    value = READ16LE(((u16 *)&vram[address]));
240
+    value = READ16LE(((uint16_t *)&vram[address]));
241 241
     break;
242 242
   case 7:
243
-    value = READ16LE(((u16 *)&oam[address & 0x3fe]));
243
+    value = READ16LE(((uint16_t *)&oam[address & 0x3fe]));
244 244
     break;
245 245
   case 8:
246 246
   case 9:
... ...
@@ -250,7 +250,7 @@ static inline u32 CPUReadHalfWord(u32 address)
250 250
     if(address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)
251 251
       value = /*rtcRead(address)*/0;
252 252
     else
253
-      value = READ16LE(((u16 *)&rom[address & 0x1FFFFFE]));
253
+      value = READ16LE(((uint16_t *)&rom[address & 0x1FFFFFE]));
254 254
     break;
255 255
   case 13:
256 256
     if(cpuEEPROMEnabled)
... ...
@@ -291,16 +291,16 @@ unreadable:
291 291
   return value;
292 292
 }
293 293
 
294
-static inline s16 CPUReadHalfWordSigned(u32 address)
294
+static inline int16_t CPUReadHalfWordSigned(uint32_t address)
295 295
 {
296
-  u32 oldAddress = address;
296
+  uint32_t oldAddress = address;
297 297
   if(address & 1) {
298 298
     address &= ~0x01;
299 299
   }
300
-  s16 value = (s16)CPUReadHalfWord(address);
300
+  int16_t value = (int16_t)CPUReadHalfWord(address);
301 301
   if((oldAddress & 1))
302 302
   {
303
-    value = (s8)value;
303
+    value = (int8_t)value;
304 304
 #ifdef GBA_LOGGING
305 305
         if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
306 306
                 log("Unaligned signed halfword read from: %08x at %08x (%08x)\n", oldAddress, armMode ?
... ...
@@ -311,7 +311,7 @@ static inline s16 CPUReadHalfWordSigned(u32 address)
311 311
   return value;
312 312
 }
313 313
 
314
-static inline u8 CPUReadByte(u32 address)
314
+static inline uint8_t CPUReadByte(uint32_t address)
315 315
 {
316 316
   switch(address >> 24) {
317 317
   case 0:
... ...
@@ -389,7 +389,7 @@ unreadable:
389 389
     }
390 390
 }
391 391
 
392
-static inline void CPUWriteMemory(u32 address, u32 value)
392
+static inline void CPUWriteMemory(uint32_t address, uint32_t value)
393 393
 {
394 394
 
395 395
 #ifdef GBA_LOGGING
... ...
@@ -408,21 +408,21 @@ static inline void CPUWriteMemory(u32 address, u32 value)
408 408
   switch(address >> 24) {
409 409
   case 0x02:
410 410
 #ifdef BKPT_SUPPORT
411
-    if(*((u32 *)&freezeWorkRAM[address & 0x3FFFC]))
411
+    if(*((uint32_t *)&freezeWorkRAM[address & 0x3FFFC]))
412 412
       cheatsWriteMemory(address & 0x203FFFC,
413 413
       value);
414 414
     else
415 415
 #endif
416
-      WRITE32LE(((u32 *)&workRAM[address & 0x3FFFC]), value);
416
+      WRITE32LE(((uint32_t *)&workRAM[address & 0x3FFFC]), value);
417 417
     break;
418 418
   case 0x03:
419 419
 #ifdef BKPT_SUPPORT
420
-    if(*((u32 *)&freezeInternalRAM[address & 0x7ffc]))
420
+    if(*((uint32_t *)&freezeInternalRAM[address & 0x7ffc]))
421 421
       cheatsWriteMemory(address & 0x3007FFC,
422 422
       value);
423 423
     else
424 424
 #endif
425
-      WRITE32LE(((u32 *)&internalRAM[address & 0x7ffC]), value);
425
+      WRITE32LE(((uint32_t *)&internalRAM[address & 0x7ffC]), value);
426 426
     break;
427 427
   case 0x04:
428 428
     if(address < 0x4000400) {
... ...
@@ -432,12 +432,12 @@ static inline void CPUWriteMemory(u32 address, u32 value)
432 432
     break;
433 433
   case 0x05:
434 434
 #ifdef BKPT_SUPPORT
435
-    if(*((u32 *)&freezePRAM[address & 0x3fc]))
435
+    if(*((uint32_t *)&freezePRAM[address & 0x3fc]))
436 436
       cheatsWriteMemory(address & 0x70003FC,
437 437
       value);
438 438
     else
439 439
 #endif
440
-      WRITE32LE(((u32 *)&paletteRAM[address & 0x3FC]), value);
440
+      WRITE32LE(((uint32_t *)&paletteRAM[address & 0x3FC]), value);
441 441
     break;
442 442
   case 0x06:
443 443
     address = (address & 0x1fffc);
... ...
@@ -447,21 +447,21 @@ static inline void CPUWriteMemory(u32 address, u32 value)
447 447
       address &= 0x17fff;
448 448
 
449 449
 #ifdef BKPT_SUPPORT
450
-    if(*((u32 *)&freezeVRAM[address]))
450
+    if(*((uint32_t *)&freezeVRAM[address]))
451 451
       cheatsWriteMemory(address + 0x06000000, value);
452 452
     else
453 453
 #endif
454 454
 
455
-      WRITE32LE(((u32 *)&vram[address]), value);
455
+      WRITE32LE(((uint32_t *)&vram[address]), value);
456 456
     break;
457 457
   case 0x07:
458 458
 #ifdef BKPT_SUPPORT
459
-    if(*((u32 *)&freezeOAM[address & 0x3fc]))
459
+    if(*((uint32_t *)&freezeOAM[address & 0x3fc]))
460 460
       cheatsWriteMemory(address & 0x70003FC,
461 461
       value);
462 462
     else
463 463
 #endif
464
-      WRITE32LE(((u32 *)&oam[address & 0x3fc]), value);
464
+      WRITE32LE(((uint32_t *)&oam[address & 0x3fc]), value);
465 465
     break;
466 466
   case 0x0D:
467 467
     if(cpuEEPROMEnabled) {
... ...
@@ -469,11 +469,11 @@ static inline void CPUWriteMemory(u32 address, u32 value)
469 469
       break;
470 470
     }
471 471
     goto unwritable;
472
-  case 0x0E:
473
-    if(/*(!eepromInUse) | */cpuSramEnabled | cpuFlashEnabled) {
472
+  /*case 0x0E:
473
+    if(*//*(!eepromInUse) | *//*cpuSramEnabled | cpuFlashEnabled) {
474 474
       //(*cpuSaveGameFunc)(address, (u8)value);
475 475
       break;
476
-    }
476
+    }*/
477 477
     // default
478 478
   default:
479 479
 unwritable:
... ...
@@ -489,7 +489,7 @@ unwritable:
489 489
   }
490 490
 }
491 491
 
492
-static inline void CPUWriteHalfWord(u32 address, u16 value)
492
+static inline void CPUWriteHalfWord(uint32_t address, uint16_t value)
493 493
 {
494 494
 #ifdef GBA_LOGGING
495 495
   if(address & 1) {
... ...
@@ -507,21 +507,21 @@ static inline void CPUWriteHalfWord(u32 address, u16 value)
507 507
   switch(address >> 24) {
508 508
   case 2:
509 509
 #ifdef BKPT_SUPPORT
510
-    if(*((u16 *)&freezeWorkRAM[address & 0x3FFFE]))
510
+    if(*((uint16_t *)&freezeWorkRAM[address & 0x3FFFE]))
511 511
       cheatsWriteHalfWord(address & 0x203FFFE,
512 512
       value);
513 513
     else
514 514
 #endif
515
-      WRITE16LE(((u16 *)&workRAM[address & 0x3FFFE]),value);
515
+      WRITE16LE(((uint16_t *)&workRAM[address & 0x3FFFE]),value);
516 516
     break;
517 517
   case 3:
518 518
 #ifdef BKPT_SUPPORT
519
-    if(*((u16 *)&freezeInternalRAM[address & 0x7ffe]))
519
+    if(*((uint16_t *)&freezeInternalRAM[address & 0x7ffe]))
520 520
       cheatsWriteHalfWord(address & 0x3007ffe,
521 521
       value);
522 522
     else
523 523
 #endif
524
-      WRITE16LE(((u16 *)&internalRAM[address & 0x7ffe]), value);
524
+      WRITE16LE(((uint16_t *)&internalRAM[address & 0x7ffe]), value);
525 525
     break;
526 526
   case 4:
527 527
     if(address < 0x4000400)
... ...
@@ -530,12 +530,12 @@ static inline void CPUWriteHalfWord(u32 address, u16 value)
530 530
     break;
531 531
   case 5:
532 532
 #ifdef BKPT_SUPPORT
533
-    if(*((u16 *)&freezePRAM[address & 0x03fe]))
533
+    if(*((uint16_t *)&freezePRAM[address & 0x03fe]))
534 534
       cheatsWriteHalfWord(address & 0x70003fe,
535 535
       value);
536 536
     else
537 537
 #endif
538
-      WRITE16LE(((u16 *)&paletteRAM[address & 0x3fe]), value);
538
+      WRITE16LE(((uint16_t *)&paletteRAM[address & 0x3fe]), value);
539 539
     break;
540 540
   case 6:
541 541
     address = (address & 0x1fffe);
... ...
@@ -544,21 +544,21 @@ static inline void CPUWriteHalfWord(u32 address, u16 value)
544 544
     if ((address & 0x18000) == 0x18000)
545 545
       address &= 0x17fff;
546 546
 #ifdef BKPT_SUPPORT
547
-    if(*((u16 *)&freezeVRAM[address]))
547
+    if(*((uint16_t *)&freezeVRAM[address]))
548 548
       cheatsWriteHalfWord(address + 0x06000000,
549 549
       value);
550 550
     else
551 551
 #endif
552
-      WRITE16LE(((u16 *)&vram[address]), value);
552
+      WRITE16LE(((uint16_t *)&vram[address]), value);
553 553
     break;
554 554
   case 7:
555 555
 #ifdef BKPT_SUPPORT
556
-    if(*((u16 *)&freezeOAM[address & 0x03fe]))
556
+    if(*((uint16_t *)&freezeOAM[address & 0x03fe]))
557 557
       cheatsWriteHalfWord(address & 0x70003fe,
558 558
       value);
559 559
     else
560 560
 #endif
561
-      WRITE16LE(((u16 *)&oam[address & 0x3fe]), value);
561
+      WRITE16LE(((uint16_t *)&oam[address & 0x3fe]), value);
562 562
     break;
563 563
   case 8:
564 564
   case 9:
... ...
@@ -573,12 +573,12 @@ static inline void CPUWriteHalfWord(u32 address, u16 value)
573 573
       break;
574 574
     }
575 575
     goto unwritable;
576
-  case 14:
577
-    if(/*(!eepromInUse) | */cpuSramEnabled | cpuFlashEnabled) {
576
+  /*case 14:
577
+    if(*//*(!eepromInUse) | *//*cpuSramEnabled | cpuFlashEnabled) {
578 578
       //(*cpuSaveGameFunc)(address, (u8)value);
579 579
       break;
580 580
     }
581
-    goto unwritable;
581
+    goto unwritable;*/
582 582
   default:
583 583
 unwritable:
584 584
 #ifdef GBA_LOGGING
... ...
@@ -593,7 +593,7 @@ unwritable:
593 593
   }
594 594
 }
595 595
 
596
-static inline void CPUWriteByte(u32 address, u8 b)
596
+static inline void CPUWriteByte(uint32_t address, uint8_t b)
597 597
 {
598 598
   switch(address >> 24) {
599 599
   case 2:
... ...
@@ -665,7 +665,7 @@ static inline void CPUWriteByte(u32 address, u8 b)
665 665
         cpuNextEvent = cpuTotalTicks;
666 666
         break;
667 667
       default: // every other register
668
-        u32 lowerBits = address & 0x3fe;
668
+        uint32_t lowerBits = address & 0x3fe;
669 669
         if(address & 1) {
670 670
           CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0x00FF) | (b << 8));
671 671
         } else {
... ...
@@ -677,7 +677,7 @@ static inline void CPUWriteByte(u32 address, u8 b)
677 677
     break;
678 678
   case 5:
679 679
     // no need to switch
680
-    *((u16 *)&paletteRAM[address & 0x3FE]) = (b << 8) | b;
680
+    *((uint16_t *)&paletteRAM[address & 0x3FE]) = (b << 8) | b;
681 681
     break;
682 682
   case 6:
683 683
     address = (address & 0x1fffe);
... ...
@@ -695,13 +695,13 @@ static inline void CPUWriteByte(u32 address, u8 b)
695 695
         cheatsWriteByte(address + 0x06000000, b);
696 696
       else
697 697
 #endif
698
-        *((u16 *)&vram[address]) = (b << 8) | b;
698
+        *((uint16_t *)&vram[address]) = (b << 8) | b;
699 699
     }
700 700
     break;
701 701
   case 7:
702 702
     // no need to switch
703 703
     // byte writes to OAM are ignored
704
-    //    *((u16 *)&oam[address & 0x3FE]) = (b << 8) | b;
704
+    //    *((uint16_t *)&oam[address & 0x3FE]) = (b << 8) | b;
705 705
     break;
706 706
   case 13:
707 707
     if(cpuEEPROMEnabled) {
... ...
@@ -709,14 +709,14 @@ static inline void CPUWriteByte(u32 address, u8 b)
709 709
       break;
710 710
     }
711 711
     goto unwritable;
712
-  case 14:
713
-    if ((saveType != 5) && (/*(!eepromInUse) | */cpuSramEnabled | cpuFlashEnabled)) {
712
+  /*case 14:
713
+    if ((saveType != 5) && (*//*(!eepromInUse) | *//*cpuSramEnabled | cpuFlashEnabled)) {
714 714
 
715 715
       //if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) {
716 716
 
717 717
       //(*cpuSaveGameFunc)(address, b);
718 718
       break;
719
-    }
719
+    }*/
720 720
     // default
721 721
   default:
722 722
 unwritable:
Browse code

Removed the save state loading from the 2SF player and updated the VBA-M code to the latest revision.

Naram Qashat authored on 2013/04/12 20:27:27
Showing 1 changed files
... ...
@@ -19,7 +19,6 @@ extern bool cpuSramEnabled;
19 19
 extern bool cpuFlashEnabled;
20 20
 extern bool cpuEEPROMEnabled;
21 21
 extern bool cpuEEPROMSensorEnabled;
22
-extern bool cpuDmaHack;
23 22
 extern u32 cpuDmaLast;
24 23
 extern bool timer0On;
25 24
 extern int timer0Ticks;
... ...
@@ -46,23 +45,20 @@ extern int cpuTotalTicks;
46 45
 
47 46
 static inline u32 CPUReadMemory(u32 address)
48 47
 {
49
-#ifdef GBA_LOGGING
48
+  u32 value;
49
+  u32 oldAddress = address;
50
+
50 51
   if(address & 3) {
51
-    if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
52
-      log("Unaligned word read: %08x at %08x\n", address, armMode ?
53
-        armNextPC - 4 : armNextPC - 2);
54
-    }
52
+           address &= ~0x03;
55 53
   }
56
-#endif
57 54
 
58
-  u32 value;
59 55
   switch(address >> 24) {
60 56
   case 0:
61 57
     if(reg[15].I >> 24) {
62 58
       if(address < 0x4000) {
63 59
 #ifdef GBA_LOGGING
64 60
         if(systemVerbose & VERBOSE_ILLEGAL_READ) {
65
-          log("Illegal word read: %08x at %08x\n", address, armMode ?
61
+          log("Illegal word read from bios: %08x at %08x\n", address, armMode ?
66 62
             armNextPC - 4 : armNextPC - 2);
67 63
         }
68 64
 #endif
... ...
@@ -135,21 +131,17 @@ unreadable:
135 131
     }
136 132
 #endif
137 133
 
138
-    if(cpuDmaHack) {
139
-      value = cpuDmaLast;
140
-    } else {
141 134
       if(armState) {
142
-        value = CPUReadMemoryQuick(reg[15].I);
135
+                return CPUReadMemoryQuick(reg[15].I);
143 136
       } else {
144
-        value = CPUReadHalfWordQuick(reg[15].I) |
137
+                return CPUReadHalfWordQuick(reg[15].I) |
145 138
           CPUReadHalfWordQuick(reg[15].I) << 16;
146 139
       }
147 140
     }
148
-  }
149 141
 
150
-  if(address & 3) {
142
+  if(oldAddress & 3) {
151 143
 #ifdef C_CORE
152
-    int shift = (address & 3) << 3;
144
+        int shift = (oldAddress & 3) << 3;
153 145
     value = (value >> shift) | (value << (32 - shift));
154 146
 #else
155 147
 #ifdef __GNUC__
... ...
@@ -157,10 +149,10 @@ unreadable:
157 149
       "shl $3 ,%%ecx;"
158 150
       "ror %%cl, %0"
159 151
       : "=r" (value)
160
-      : "r" (value), "c" (address));
152
+      : "r" (value), "c" (oldAddress));
161 153
 #else
162 154
     __asm {
163
-      mov ecx, address;
155
+      mov ecx, oldAddress;
164 156
       and ecx, 3;
165 157
       shl ecx, 3;
166 158
       ror [dword ptr value], cl;
... ...
@@ -168,6 +160,15 @@ unreadable:
168 160
 #endif
169 161
 #endif
170 162
   }
163
+
164
+#ifdef GBA_LOGGING
165
+  if(oldAddress & 3) {
166
+          if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
167
+                  log("Unaligned word read from: %08x at %08x (%08x)\n", oldAddress, armMode ?
168
+                          armNextPC - 4 : armNextPC - 2, value);
169
+          }
170
+  }
171
+#endif
171 172
   return value;
172 173
 }
173 174
 
... ...
@@ -175,16 +176,12 @@ extern u32 myROM[];
175 176
 
176 177
 static inline u32 CPUReadHalfWord(u32 address)
177 178
 {
178
-#ifdef GBA_LOGGING
179
+  u32 value;
180
+  u32 oldAddress = address;
181
+
179 182
   if(address & 1) {
180
-    if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
181
-      log("Unaligned halfword read: %08x at %08x\n", address, armMode ?
182
-        armNextPC - 4 : armNextPC - 2);
183
-    }
183
+          address &= ~0x01;
184 184
   }
185
-#endif
186
-
187
-  u32 value;
188 185
 
189 186
   switch(address >> 24) {
190 187
   case 0:
... ...
@@ -192,7 +189,7 @@ static inline u32 CPUReadHalfWord(u32 address)
192 189
       if(address < 0x4000) {
193 190
 #ifdef GBA_LOGGING
194 191
         if(systemVerbose & VERBOSE_ILLEGAL_READ) {
195
-          log("Illegal halfword read: %08x at %08x\n", address, armMode ?
192
+          log("Illegal halfword read from bios: %08x at %08x\n", oldAddress, armMode ?
196 193
             armNextPC - 4 : armNextPC - 2);
197 194
         }
198 195
 #endif
... ...
@@ -269,34 +266,48 @@ static inline u32 CPUReadHalfWord(u32 address)
269 266
 unreadable:
270 267
 #ifdef GBA_LOGGING
271 268
     if(systemVerbose & VERBOSE_ILLEGAL_READ) {
272
-      log("Illegal halfword read: %08x at %08x\n", address, armMode ?
269
+      log("Illegal halfword read: %08x at %08x\n", oldAddress, armMode ?
273 270
         armNextPC - 4 : armNextPC - 2);
274 271
     }
275 272
 #endif
276
-    if(cpuDmaHack) {
277
-      value = cpuDmaLast & 0xFFFF;
278
-    } else {
279 273
       if(armState) {
280
-        value = CPUReadHalfWordQuick(reg[15].I + (address & 2));
274
+                return CPUReadMemoryQuick(reg[15].I);
281 275
       } else {
282
-        value = CPUReadHalfWordQuick(reg[15].I);
276
+                return CPUReadHalfWordQuick(reg[15].I) |
277
+                                CPUReadHalfWordQuick(reg[15].I) << 16;
283 278
       }
284 279
     }
285
-    break;
286
-  }
287 280
 
288
-  if(address & 1) {
281
+  if(oldAddress & 1) {
289 282
     value = (value >> 8) | (value << 24);
283
+#ifdef GBA_LOGGING
284
+          if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
285
+                  log("Unaligned halfword read from: %08x at %08x (%08x)\n", oldAddress, armMode ?
286
+                          armNextPC - 4 : armNextPC - 2, value);
287
+          }
288
+#endif
290 289
   }
291 290
 
292 291
   return value;
293 292
 }
294 293
 
295
-static inline u16 CPUReadHalfWordSigned(u32 address)
294
+static inline s16 CPUReadHalfWordSigned(u32 address)
296 295
 {
297
-  u16 value = CPUReadHalfWord(address);
298
-  if((address & 1))
296
+  u32 oldAddress = address;
297
+  if(address & 1) {
298
+    address &= ~0x01;
299
+  }
300
+  s16 value = (s16)CPUReadHalfWord(address);
301
+  if((oldAddress & 1))
302
+  {
299 303
     value = (s8)value;
304
+#ifdef GBA_LOGGING
305
+        if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
306
+                log("Unaligned signed halfword read from: %08x at %08x (%08x)\n", oldAddress, armMode ?
307
+                        armNextPC - 4 : armNextPC - 2, value);
308
+        }
309
+#endif
310
+  }
300 311
   return value;
301 312
 }
302 313
 
... ...
@@ -308,7 +319,7 @@ static inline u8 CPUReadByte(u32 address)
308 319
       if(address < 0x4000) {
309 320
 #ifdef GBA_LOGGING
310 321
         if(systemVerbose & VERBOSE_ILLEGAL_READ) {
311
-          log("Illegal byte read: %08x at %08x\n", address, armMode ?
322
+          log("Illegal byte read from bios: %08x at %08x\n", address, armMode ?
312 323
             armNextPC - 4 : armNextPC - 2);
313 324
         }
314 325
 #endif
... ...
@@ -369,17 +380,13 @@ unreadable:
369 380
         armNextPC - 4 : armNextPC - 2);
370 381
     }
371 382
 #endif
372
-    if(cpuDmaHack) {
373
-      return cpuDmaLast & 0xFF;
374
-    } else {
375 383
       if(armState) {
376
-        return CPUReadByteQuick(reg[15].I+(address & 3));
384
+                         return CPUReadMemoryQuick(reg[15].I);
377 385
       } else {
378
-        return CPUReadByteQuick(reg[15].I+(address & 1));
386
+                         return CPUReadHalfWordQuick(reg[15].I) |
387
+                                 CPUReadHalfWordQuick(reg[15].I) << 16;
379 388
       }
380 389
     }
381
-    break;
382
-  }
383 390
 }
384 391
 
385 392
 static inline void CPUWriteMemory(u32 address, u32 value)
... ...
@@ -396,6 +403,8 @@ static inline void CPUWriteMemory(u32 address, u32 value)
396 403
   }
397 404
 #endif
398 405
 
406
+  address &= 0xFFFFFFFC;
407
+
399 408
   switch(address >> 24) {
400 409
   case 0x02:
401 410
 #ifdef BKPT_SUPPORT
... ...
@@ -493,6 +502,8 @@ static inline void CPUWriteHalfWord(u32 address, u16 value)
493 502
   }
494 503
 #endif
495 504
 
505
+  address &= 0xFFFFFFFE;
506
+
496 507
   switch(address >> 24) {
497 508
   case 2:
498 509
 #ifdef BKPT_SUPPORT
Browse code

Import actual code.

Naram Qashat authored on 2013/03/26 02:41:19
Showing 1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,724 @@
1
+#ifndef GBAINLINE_H
2
+#define GBAINLINE_H
3
+
4
+//#include "../System.h"
5
+#include "../common/Port.h"
6
+//#include "RTC.h"
7
+#include "Sound.h"
8
+//#include "agbprint.h"
9
+#include "GBAcpu.h"
10
+//#include "GBALink.h"
11
+
12
+extern const u32 objTilesAddress[3];
13
+
14
+extern bool stopState;
15
+extern bool holdState;
16
+extern int holdType;
17
+extern int cpuNextEvent;
18
+extern bool cpuSramEnabled;
19
+extern bool cpuFlashEnabled;
20
+extern bool cpuEEPROMEnabled;
21
+extern bool cpuEEPROMSensorEnabled;
22
+extern bool cpuDmaHack;
23
+extern u32 cpuDmaLast;
24
+extern bool timer0On;
25
+extern int timer0Ticks;
26
+extern int timer0ClockReload;
27
+extern bool timer1On;
28
+extern int timer1Ticks;
29
+extern int timer1ClockReload;
30
+extern bool timer2On;
31
+extern int timer2Ticks;
32
+extern int timer2ClockReload;
33
+extern bool timer3On;
34
+extern int timer3Ticks;
35
+extern int timer3ClockReload;
36
+extern int cpuTotalTicks;
37
+
38
+#define CPUReadByteQuick(addr) \
39
+  map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]
40
+
41
+#define CPUReadHalfWordQuick(addr) \
42
+  READ16LE(((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
43
+
44
+#define CPUReadMemoryQuick(addr) \
45
+  READ32LE(((u32*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
46
+
47
+static inline u32 CPUReadMemory(u32 address)
48
+{
49
+#ifdef GBA_LOGGING
50
+  if(address & 3) {
51
+    if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
52
+      log("Unaligned word read: %08x at %08x\n", address, armMode ?
53
+        armNextPC - 4 : armNextPC - 2);
54
+    }
55
+  }
56
+#endif
57
+
58
+  u32 value;
59
+  switch(address >> 24) {
60
+  case 0:
61
+    if(reg[15].I >> 24) {
62
+      if(address < 0x4000) {
63
+#ifdef GBA_LOGGING
64
+        if(systemVerbose & VERBOSE_ILLEGAL_READ) {
65
+          log("Illegal word read: %08x at %08x\n", address, armMode ?
66
+            armNextPC - 4 : armNextPC - 2);
67
+        }
68
+#endif
69
+
70
+        value = READ32LE(((u32 *)&biosProtected));
71
+      }
72
+      else goto unreadable;
73
+    } else
74
+      value = READ32LE(((u32 *)&bios[address & 0x3FFC]));
75
+    break;
76
+  case 2:
77
+    value = READ32LE(((u32 *)&workRAM[address & 0x3FFFC]));
78
+    break;
79
+  case 3:
80
+    value = READ32LE(((u32 *)&internalRAM[address & 0x7ffC]));
81
+    break;
82
+  case 4:
83
+	  if((address < 0x4000400) && ioReadable[address & 0x3fc]) {
84
+		  if(ioReadable[(address & 0x3fc) + 2]) {
85
+			  value = READ32LE(((u32 *)&ioMem[address & 0x3fC]));
86
+			  /*if ((address & 0x3fc) == COMM_JOY_RECV_L)
87
+				  UPDATE_REG(COMM_JOYSTAT, READ16LE(&ioMem[COMM_JOYSTAT]) & ~JOYSTAT_RECV);*/
88
+		  } else {
89
+			  value = READ16LE(((u16 *)&ioMem[address & 0x3fc]));
90
+		  }
91
+	  }
92
+	  else
93
+		  goto unreadable;
94
+	  break;
95
+  case 5:
96
+    value = READ32LE(((u32 *)&paletteRAM[address & 0x3fC]));
97
+    break;
98
+  case 6:
99
+    address = (address & 0x1fffc);
100
+    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
101
+    {
102
+      value = 0;
103
+      break;
104
+    }
105
+    if ((address & 0x18000) == 0x18000)
106
+      address &= 0x17fff;
107
+    value = READ32LE(((u32 *)&vram[address]));
108
+    break;
109
+  case 7:
110
+    value = READ32LE(((u32 *)&oam[address & 0x3FC]));
111
+    break;
112
+  case 8:
113
+  case 9:
114
+  case 10:
115
+  case 11:
116
+  case 12:
117
+    value = READ32LE(((u32 *)&rom[address&0x1FFFFFC]));
118
+    break;
119
+  case 13:
120
+    if(cpuEEPROMEnabled)
121
+      // no need to swap this
122
+      return /*eepromRead(address)*/0;
123
+    goto unreadable;
124
+  case 14:
125
+    if(cpuFlashEnabled | cpuSramEnabled)
126
+      // no need to swap this
127
+      return /*flashRead(address)*/0;
128
+    // default
129
+  default:
130
+unreadable:
131
+#ifdef GBA_LOGGING
132
+    if(systemVerbose & VERBOSE_ILLEGAL_READ) {
133
+      log("Illegal word read: %08x at %08x\n", address, armMode ?
134
+        armNextPC - 4 : armNextPC - 2);
135
+    }
136
+#endif
137
+
138
+    if(cpuDmaHack) {
139
+      value = cpuDmaLast;
140
+    } else {
141
+      if(armState) {
142
+        value = CPUReadMemoryQuick(reg[15].I);
143
+      } else {
144
+        value = CPUReadHalfWordQuick(reg[15].I) |
145
+          CPUReadHalfWordQuick(reg[15].I) << 16;
146
+      }
147
+    }
148
+  }
149
+
150
+  if(address & 3) {
151
+#ifdef C_CORE
152
+    int shift = (address & 3) << 3;
153
+    value = (value >> shift) | (value << (32 - shift));
154
+#else
155
+#ifdef __GNUC__
156
+    asm("and $3, %%ecx;"
157
+      "shl $3 ,%%ecx;"
158
+      "ror %%cl, %0"
159
+      : "=r" (value)
160
+      : "r" (value), "c" (address));
161
+#else
162
+    __asm {
163
+      mov ecx, address;
164
+      and ecx, 3;
165
+      shl ecx, 3;
166
+      ror [dword ptr value], cl;
167
+    }
168
+#endif
169
+#endif
170
+  }
171
+  return value;
172
+}
173
+
174
+extern u32 myROM[];
175
+
176
+static inline u32 CPUReadHalfWord(u32 address)
177
+{
178
+#ifdef GBA_LOGGING
179
+  if(address & 1) {
180
+    if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
181
+      log("Unaligned halfword read: %08x at %08x\n", address, armMode ?
182
+        armNextPC - 4 : armNextPC - 2);
183
+    }
184
+  }
185
+#endif
186
+
187
+  u32 value;
188
+
189
+  switch(address >> 24) {
190
+  case 0:
191
+    if (reg[15].I >> 24) {
192
+      if(address < 0x4000) {
193
+#ifdef GBA_LOGGING
194
+        if(systemVerbose & VERBOSE_ILLEGAL_READ) {
195
+          log("Illegal halfword read: %08x at %08x\n", address, armMode ?
196
+            armNextPC - 4 : armNextPC - 2);
197
+        }
198
+#endif
199
+        value = READ16LE(((u16 *)&biosProtected[address&2]));
200
+      } else goto unreadable;
201
+    } else
202
+      value = READ16LE(((u16 *)&bios[address & 0x3FFE]));
203
+    break;
204
+  case 2:
205
+    value = READ16LE(((u16 *)&workRAM[address & 0x3FFFE]));
206
+    break;
207
+  case 3:
208
+    value = READ16LE(((u16 *)&internalRAM[address & 0x7ffe]));
209
+    break;
210
+  case 4:
211
+    if((address < 0x4000400) && ioReadable[address & 0x3fe])
212
+    {
213
+      value =  READ16LE(((u16 *)&ioMem[address & 0x3fe]));
214
+      if (((address & 0x3fe)>0xFF) && ((address & 0x3fe)<0x10E))
215
+      {
216
+        if (((address & 0x3fe) == 0x100) && timer0On)
217
+          value = 0xFFFF - ((timer0Ticks-cpuTotalTicks) >> timer0ClockReload);
218
+        else
219
+          if (((address & 0x3fe) == 0x104) && timer1On && !(TM1CNT & 4))
220
+            value = 0xFFFF - ((timer1Ticks-cpuTotalTicks) >> timer1ClockReload);
221
+          else
222
+            if (((address & 0x3fe) == 0x108) && timer2On && !(TM2CNT & 4))
223
+              value = 0xFFFF - ((timer2Ticks-cpuTotalTicks) >> timer2ClockReload);
224
+            else
225
+              if (((address & 0x3fe) == 0x10C) && timer3On && !(TM3CNT & 4))
226
+                value = 0xFFFF - ((timer3Ticks-cpuTotalTicks) >> timer3ClockReload);
227
+      }
228
+    }
229
+    else goto unreadable;
230
+    break;
231
+  case 5:
232
+    value = READ16LE(((u16 *)&paletteRAM[address & 0x3fe]));
233
+    break;
234
+  case 6:
235
+    address = (address & 0x1fffe);
236
+    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
237
+    {
238
+      value = 0;
239
+      break;
240
+    }
241
+    if ((address & 0x18000) == 0x18000)
242
+      address &= 0x17fff;
243
+    value = READ16LE(((u16 *)&vram[address]));
244
+    break;
245
+  case 7:
246
+    value = READ16LE(((u16 *)&oam[address & 0x3fe]));
247
+    break;
248
+  case 8:
249
+  case 9:
250
+  case 10:
251
+  case 11:
252
+  case 12:
253
+    if(address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8)
254
+      value = /*rtcRead(address)*/0;
255
+    else
256
+      value = READ16LE(((u16 *)&rom[address & 0x1FFFFFE]));
257
+    break;
258
+  case 13:
259
+    if(cpuEEPROMEnabled)
260
+      // no need to swap this
261
+      return /*eepromRead(address)*/0;
262
+    goto unreadable;
263
+  case 14:
264
+    if(cpuFlashEnabled | cpuSramEnabled)
265
+      // no need to swap this
266
+      return /*flashRead(address)*/0;
267
+    // default
268
+  default:
269
+unreadable:
270
+#ifdef GBA_LOGGING
271
+    if(systemVerbose & VERBOSE_ILLEGAL_READ) {
272
+      log("Illegal halfword read: %08x at %08x\n", address, armMode ?
273
+        armNextPC - 4 : armNextPC - 2);
274
+    }
275
+#endif
276
+    if(cpuDmaHack) {
277
+      value = cpuDmaLast & 0xFFFF;
278
+    } else {
279
+      if(armState) {
280
+        value = CPUReadHalfWordQuick(reg[15].I + (address & 2));
281
+      } else {
282
+        value = CPUReadHalfWordQuick(reg[15].I);
283
+      }
284
+    }
285
+    break;
286
+  }
287
+
288
+  if(address & 1) {
289
+    value = (value >> 8) | (value << 24);
290
+  }
291
+
292
+  return value;
293
+}
294
+
295
+static inline u16 CPUReadHalfWordSigned(u32 address)
296
+{
297
+  u16 value = CPUReadHalfWord(address);
298
+  if((address & 1))
299
+    value = (s8)value;
300
+  return value;
301
+}
302
+
303
+static inline u8 CPUReadByte(u32 address)
304
+{
305
+  switch(address >> 24) {
306
+  case 0:
307
+    if (reg[15].I >> 24) {
308
+      if(address < 0x4000) {
309
+#ifdef GBA_LOGGING
310
+        if(systemVerbose & VERBOSE_ILLEGAL_READ) {
311
+          log("Illegal byte read: %08x at %08x\n", address, armMode ?
312
+            armNextPC - 4 : armNextPC - 2);
313
+        }
314
+#endif
315
+        return biosProtected[address & 3];
316
+      } else goto unreadable;
317
+    }
318
+    return bios[address & 0x3FFF];
319
+  case 2:
320
+    return workRAM[address & 0x3FFFF];
321
+  case 3:
322
+    return internalRAM[address & 0x7fff];
323
+  case 4:
324
+    if((address < 0x4000400) && ioReadable[address & 0x3ff])
325
+      return ioMem[address & 0x3ff];
326
+    else goto unreadable;
327
+  case 5:
328
+    return paletteRAM[address & 0x3ff];
329
+  case 6:
330
+    address = (address & 0x1ffff);
331
+    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
332
+      return 0;
333
+    if ((address & 0x18000) == 0x18000)
334
+      address &= 0x17fff;
335
+    return vram[address];
336
+  case 7:
337
+    return oam[address & 0x3ff];
338
+  case 8:
339
+  case 9:
340
+  case 10:
341
+  case 11:
342
+  case 12:
343
+    return rom[address & 0x1FFFFFF];
344
+  case 13:
345
+    if(cpuEEPROMEnabled)
346
+      return /*eepromRead(address)*/0;
347
+    goto unreadable;
348
+  case 14:
349
+    if(cpuSramEnabled | cpuFlashEnabled)
350
+      return /*flashRead(address)*/0;
351
+    if(cpuEEPROMSensorEnabled) {
352
+      switch(address & 0x00008f00) {
353
+  case 0x8200:
354
+    return /*systemGetSensorX() & 255*/0;
355
+  case 0x8300:
356
+    return /*(systemGetSensorX() >> 8)|0x80*/0;
357
+  case 0x8400:
358
+    return /*systemGetSensorY() & 255*/0;
359
+  case 0x8500:
360
+    return /*systemGetSensorY() >> 8*/0;
361
+      }
362
+    }
363
+    // default
364
+  default:
365
+unreadable:
366
+#ifdef GBA_LOGGING
367
+    if(systemVerbose & VERBOSE_ILLEGAL_READ) {
368
+      log("Illegal byte read: %08x at %08x\n", address, armMode ?
369
+        armNextPC - 4 : armNextPC - 2);
370
+    }
371
+#endif
372
+    if(cpuDmaHack) {
373
+      return cpuDmaLast & 0xFF;
374
+    } else {
375
+      if(armState) {
376
+        return CPUReadByteQuick(reg[15].I+(address & 3));
377
+      } else {
378
+        return CPUReadByteQuick(reg[15].I+(address & 1));
379
+      }
380
+    }
381
+    break;
382
+  }
383
+}
384
+
385
+static inline void CPUWriteMemory(u32 address, u32 value)
386
+{
387
+
388
+#ifdef GBA_LOGGING
389
+  if(address & 3) {
390
+    if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
391
+      log("Unaligned word write: %08x to %08x from %08x\n",
392
+        value,
393
+        address,
394
+        armMode ? armNextPC - 4 : armNextPC - 2);
395
+    }
396
+  }
397
+#endif
398
+
399
+  switch(address >> 24) {
400
+  case 0x02:
401
+#ifdef BKPT_SUPPORT
402
+    if(*((u32 *)&freezeWorkRAM[address & 0x3FFFC]))
403
+      cheatsWriteMemory(address & 0x203FFFC,
404
+      value);
405
+    else
406
+#endif
407
+      WRITE32LE(((u32 *)&workRAM[address & 0x3FFFC]), value);
408
+    break;
409
+  case 0x03:
410
+#ifdef BKPT_SUPPORT
411
+    if(*((u32 *)&freezeInternalRAM[address & 0x7ffc]))
412
+      cheatsWriteMemory(address & 0x3007FFC,
413
+      value);
414
+    else
415
+#endif
416
+      WRITE32LE(((u32 *)&internalRAM[address & 0x7ffC]), value);
417
+    break;
418
+  case 0x04:
419
+    if(address < 0x4000400) {
420
+      CPUUpdateRegister((address & 0x3FC), value & 0xFFFF);
421
+      CPUUpdateRegister((address & 0x3FC) + 2, (value >> 16));
422
+    } else goto unwritable;
423
+    break;
424
+  case 0x05:
425
+#ifdef BKPT_SUPPORT
426
+    if(*((u32 *)&freezePRAM[address & 0x3fc]))
427
+      cheatsWriteMemory(address & 0x70003FC,
428
+      value);
429
+    else
430
+#endif
431
+      WRITE32LE(((u32 *)&paletteRAM[address & 0x3FC]), value);
432
+    break;
433
+  case 0x06:
434
+    address = (address & 0x1fffc);
435
+    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
436
+      return;
437
+    if ((address & 0x18000) == 0x18000)
438
+      address &= 0x17fff;
439
+
440
+#ifdef BKPT_SUPPORT
441
+    if(*((u32 *)&freezeVRAM[address]))
442
+      cheatsWriteMemory(address + 0x06000000, value);
443
+    else
444
+#endif
445
+
446
+      WRITE32LE(((u32 *)&vram[address]), value);
447
+    break;
448
+  case 0x07:
449
+#ifdef BKPT_SUPPORT
450
+    if(*((u32 *)&freezeOAM[address & 0x3fc]))
451
+      cheatsWriteMemory(address & 0x70003FC,
452
+      value);
453
+    else
454
+#endif
455
+      WRITE32LE(((u32 *)&oam[address & 0x3fc]), value);
456
+    break;
457
+  case 0x0D:
458
+    if(cpuEEPROMEnabled) {
459
+      //eepromWrite(address, value);
460
+      break;
461
+    }
462
+    goto unwritable;
463
+  case 0x0E:
464
+    if(/*(!eepromInUse) | */cpuSramEnabled | cpuFlashEnabled) {
465
+      //(*cpuSaveGameFunc)(address, (u8)value);
466
+      break;
467
+    }
468
+    // default
469
+  default:
470
+unwritable:
471
+#ifdef GBA_LOGGING
472
+    if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
473
+      log("Illegal word write: %08x to %08x from %08x\n",
474
+        value,
475
+        address,
476
+        armMode ? armNextPC - 4 : armNextPC - 2);
477
+    }
478
+#endif
479
+    break;
480
+  }
481
+}
482
+
483
+static inline void CPUWriteHalfWord(u32 address, u16 value)
484
+{
485
+#ifdef GBA_LOGGING
486
+  if(address & 1) {
487
+    if(systemVerbose & VERBOSE_UNALIGNED_MEMORY) {
488
+      log("Unaligned halfword write: %04x to %08x from %08x\n",
489
+        value,
490
+        address,
491
+        armMode ? armNextPC - 4 : armNextPC - 2);
492
+    }
493
+  }
494
+#endif
495
+
496
+  switch(address >> 24) {
497
+  case 2:
498
+#ifdef BKPT_SUPPORT
499
+    if(*((u16 *)&freezeWorkRAM[address & 0x3FFFE]))
500
+      cheatsWriteHalfWord(address & 0x203FFFE,
501
+      value);
502
+    else
503
+#endif
504
+      WRITE16LE(((u16 *)&workRAM[address & 0x3FFFE]),value);
505
+    break;
506
+  case 3:
507
+#ifdef BKPT_SUPPORT
508
+    if(*((u16 *)&freezeInternalRAM[address & 0x7ffe]))
509
+      cheatsWriteHalfWord(address & 0x3007ffe,
510
+      value);
511
+    else
512
+#endif
513
+      WRITE16LE(((u16 *)&internalRAM[address & 0x7ffe]), value);
514
+    break;
515
+  case 4:
516
+    if(address < 0x4000400)
517
+      CPUUpdateRegister(address & 0x3fe, value);
518
+    else goto unwritable;
519
+    break;
520
+  case 5:
521
+#ifdef BKPT_SUPPORT
522
+    if(*((u16 *)&freezePRAM[address & 0x03fe]))
523
+      cheatsWriteHalfWord(address & 0x70003fe,
524
+      value);
525
+    else
526
+#endif
527
+      WRITE16LE(((u16 *)&paletteRAM[address & 0x3fe]), value);
528
+    break;
529
+  case 6:
530
+    address = (address & 0x1fffe);
531
+    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
532
+      return;
533
+    if ((address & 0x18000) == 0x18000)
534
+      address &= 0x17fff;
535
+#ifdef BKPT_SUPPORT
536
+    if(*((u16 *)&freezeVRAM[address]))
537
+      cheatsWriteHalfWord(address + 0x06000000,
538
+      value);
539
+    else
540
+#endif
541
+      WRITE16LE(((u16 *)&vram[address]), value);
542
+    break;
543
+  case 7:
544
+#ifdef BKPT_SUPPORT
545
+    if(*((u16 *)&freezeOAM[address & 0x03fe]))
546
+      cheatsWriteHalfWord(address & 0x70003fe,
547
+      value);
548
+    else
549
+#endif
550
+      WRITE16LE(((u16 *)&oam[address & 0x3fe]), value);
551
+    break;
552
+  case 8:
553
+  case 9:
554
+   /* if(address == 0x80000c4 || address == 0x80000c6 || address == 0x80000c8) {
555
+      if(!rtcWrite(address, value))
556
+        goto unwritable;
557
+    } else if(!agbPrintWrite(address, value)) goto unwritable;*/
558
+    break;
559
+  case 13:
560
+    if(cpuEEPROMEnabled) {
561
+      //eepromWrite(address, (u8)value);
562
+      break;
563
+    }
564
+    goto unwritable;
565
+  case 14:
566
+    if(/*(!eepromInUse) | */cpuSramEnabled | cpuFlashEnabled) {
567
+      //(*cpuSaveGameFunc)(address, (u8)value);
568
+      break;
569
+    }
570
+    goto unwritable;
571
+  default:
572
+unwritable:
573
+#ifdef GBA_LOGGING
574
+    if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
575
+      log("Illegal halfword write: %04x to %08x from %08x\n",
576
+        value,
577
+        address,
578
+        armMode ? armNextPC - 4 : armNextPC - 2);
579
+    }
580
+#endif
581
+    break;
582
+  }
583
+}
584
+
585
+static inline void CPUWriteByte(u32 address, u8 b)
586
+{
587
+  switch(address >> 24) {
588
+  case 2:
589
+#ifdef BKPT_SUPPORT
590
+    if(freezeWorkRAM[address & 0x3FFFF])
591
+      cheatsWriteByte(address & 0x203FFFF, b);
592
+    else
593
+#endif
594
+      workRAM[address & 0x3FFFF] = b;
595
+    break;
596
+  case 3:
597
+#ifdef BKPT_SUPPORT
598
+    if(freezeInternalRAM[address & 0x7fff])
599
+      cheatsWriteByte(address & 0x3007fff, b);
600
+    else
601
+#endif
602
+      internalRAM[address & 0x7fff] = b;
603
+    break;
604
+  case 4:
605
+    if(address < 0x4000400) {
606
+      switch(address & 0x3FF) {
607
+      case 0x60:
608
+      case 0x61:
609
+      case 0x62:
610
+      case 0x63:
611
+      case 0x64:
612
+      case 0x65:
613
+      case 0x68:
614
+      case 0x69:
615
+      case 0x6c:
616
+      case 0x6d:
617
+      case 0x70:
618
+      case 0x71:
619
+      case 0x72:
620
+      case 0x73:
621
+      case 0x74:
622
+      case 0x75:
623
+      case 0x78:
624
+      case 0x79:
625
+      case 0x7c:
626
+      case 0x7d:
627
+      case 0x80:
628
+      case 0x81:
629
+      case 0x84:
630
+      case 0x85:
631
+      case 0x90:
632
+      case 0x91:
633
+      case 0x92:
634
+      case 0x93:
635
+      case 0x94:
636
+      case 0x95:
637
+      case 0x96:
638
+      case 0x97:
639
+      case 0x98:
640
+      case 0x99:
641
+      case 0x9a:
642
+      case 0x9b:
643
+      case 0x9c:
644
+      case 0x9d:
645
+      case 0x9e:
646
+      case 0x9f:
647
+        soundEvent(address&0xFF, b);
648
+        break;
649
+      case 0x301: // HALTCNT, undocumented
650
+        if(b == 0x80)
651
+          stopState = true;
652
+        holdState = 1;
653
+        holdType = -1;
654
+        cpuNextEvent = cpuTotalTicks;
655
+        break;
656
+      default: // every other register
657
+        u32 lowerBits = address & 0x3fe;
658
+        if(address & 1) {
659
+          CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0x00FF) | (b << 8));
660
+        } else {
661
+          CPUUpdateRegister(lowerBits, (READ16LE(&ioMem[lowerBits]) & 0xFF00) | b);
662
+        }
663
+      }
664
+      break;
665
+    } else goto unwritable;
666
+    break;
667
+  case 5:
668
+    // no need to switch
669
+    *((u16 *)&paletteRAM[address & 0x3FE]) = (b << 8) | b;
670
+    break;
671
+  case 6:
672
+    address = (address & 0x1fffe);
673
+    if (((DISPCNT & 7) >2) && ((address & 0x1C000) == 0x18000))
674
+      return;
675
+    if ((address & 0x18000) == 0x18000)
676
+      address &= 0x17fff;
677
+
678
+    // no need to switch
679
+    // byte writes to OBJ VRAM are ignored
680
+    if ((address) < objTilesAddress[((DISPCNT&7)+1)>>2])
681
+    {
682
+#ifdef BKPT_SUPPORT
683
+      if(freezeVRAM[address])
684
+        cheatsWriteByte(address + 0x06000000, b);
685
+      else
686
+#endif
687
+        *((u16 *)&vram[address]) = (b << 8) | b;
688
+    }
689
+    break;
690
+  case 7:
691
+    // no need to switch
692
+    // byte writes to OAM are ignored
693
+    //    *((u16 *)&oam[address & 0x3FE]) = (b << 8) | b;
694
+    break;
695
+  case 13:
696
+    if(cpuEEPROMEnabled) {
697
+      //eepromWrite(address, b);
698
+      break;
699
+    }
700
+    goto unwritable;
701
+  case 14:
702
+    if ((saveType != 5) && (/*(!eepromInUse) | */cpuSramEnabled | cpuFlashEnabled)) {
703
+
704
+      //if(!cpuEEPROMEnabled && (cpuSramEnabled | cpuFlashEnabled)) {
705
+
706
+      //(*cpuSaveGameFunc)(address, b);
707
+      break;
708
+    }
709
+    // default
710
+  default:
711
+unwritable:
712
+#ifdef GBA_LOGGING
713
+    if(systemVerbose & VERBOSE_ILLEGAL_WRITE) {
714
+      log("Illegal byte write: %02x to %08x from %08x\n",
715
+        b,
716
+        address,
717
+        armMode ? armNextPC - 4 : armNextPC -2 );
718
+    }
719
+#endif
720
+    break;
721
+  }
722
+}
723
+
724
+#endif // GBAINLINE_H