Mercurial > vba-clojure
comparison src/gb/gbCodes.h @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children | 1ff2c546f5ad |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 case 0x00: | |
2 // NOP | |
3 break; | |
4 case 0x01: | |
5 // LD BC, NNNN | |
6 BC.B.B0=gbReadMemory(PC.W++); | |
7 BC.B.B1=gbReadMemory(PC.W++); | |
8 break; | |
9 case 0x02: | |
10 // LD (BC),A | |
11 gbWriteMemory(BC.W,AF.B.B1); | |
12 break; | |
13 case 0x03: | |
14 // INC BC | |
15 BC.W++; | |
16 break; | |
17 case 0x04: | |
18 // INC B | |
19 BC.B.B1++; | |
20 AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[BC.B.B1]| (BC.B.B1&0x0F? 0:H_FLAG); | |
21 break; | |
22 case 0x05: | |
23 // DEC B | |
24 BC.B.B1--; | |
25 AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[BC.B.B1]| | |
26 ((BC.B.B1&0x0F)==0x0F? H_FLAG:0); | |
27 break; | |
28 case 0x06: | |
29 // LD B, NN | |
30 BC.B.B1=gbReadOpcode(PC.W++); | |
31 break; | |
32 case 0x07: | |
33 // RLCA | |
34 tempValue=AF.B.B1&0x80? C_FLAG:0; | |
35 AF.B.B1=((AF.B.B1<<1)|(AF.B.B1>>7)) & 0xFF; | |
36 AF.B.B0=tempValue; | |
37 break; | |
38 case 0x08: | |
39 // LD (NNNN), SP | |
40 tempRegister.B.B0=gbReadOpcode(PC.W++); | |
41 tempRegister.B.B1=gbReadOpcode(PC.W++); | |
42 gbWriteMemory(tempRegister.W++,SP.B.B0); | |
43 gbWriteMemory(tempRegister.W,SP.B.B1); | |
44 break; | |
45 case 0x09: | |
46 // ADD HL,BC | |
47 tempRegister.W=(HL.W+BC.W)&0xFFFF; | |
48 AF.B.B0= (AF.B.B0 & Z_FLAG)| ((HL.W^BC.W^tempRegister.W)&0x1000? H_FLAG:0)| | |
49 (((long)HL.W+(long)BC.W)&0x10000? C_FLAG:0); | |
50 HL.W=tempRegister.W; | |
51 break; | |
52 case 0x0a: | |
53 // LD A,(BC) | |
54 AF.B.B1=gbReadMemory(BC.W); | |
55 break; | |
56 case 0x0b: | |
57 // DEC BC | |
58 BC.W--; | |
59 break; | |
60 case 0x0c: | |
61 // INC C | |
62 BC.B.B0++; | |
63 AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[BC.B.B0]| (BC.B.B0&0x0F? 0:H_FLAG); | |
64 break; | |
65 case 0x0d: | |
66 // DEC C | |
67 BC.B.B0--; | |
68 AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[BC.B.B0]| | |
69 ((BC.B.B0&0x0F)==0x0F? H_FLAG:0); | |
70 break; | |
71 case 0x0e: | |
72 // LD C, NN | |
73 BC.B.B0=gbReadOpcode(PC.W++); | |
74 break; | |
75 case 0x0f: | |
76 // RRCA | |
77 tempValue=AF.B.B1&0x01; | |
78 AF.B.B1=(AF.B.B1>>1)|(tempValue? 0x80:0); | |
79 AF.B.B0=(tempValue<<4); | |
80 break; | |
81 case 0x10: | |
82 // STOP | |
83 opcode = gbReadOpcode(PC.W++); | |
84 if(gbCgbMode) { | |
85 if(gbReadMemoryQuick(0xff4d) & 1) { | |
86 gbSpeedSwitch(); | |
87 | |
88 if(gbSpeed == 0) | |
89 gbWriteMemoryQuick(0xff4d, 0x00); | |
90 else | |
91 gbWriteMemoryQuick(0xff4d, 0x80); | |
92 } | |
93 } | |
94 break; | |
95 case 0x11: | |
96 // LD DE, NNNN | |
97 DE.B.B0=gbReadMemory(PC.W++); | |
98 DE.B.B1=gbReadMemory(PC.W++); | |
99 break; | |
100 case 0x12: | |
101 // LD (DE),A | |
102 gbWriteMemory(DE.W,AF.B.B1); | |
103 break; | |
104 case 0x13: | |
105 // INC DE | |
106 DE.W++; | |
107 break; | |
108 case 0x14: | |
109 // INC D | |
110 DE.B.B1++; | |
111 AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[DE.B.B1]| (DE.B.B1&0x0F? 0:H_FLAG); | |
112 break; | |
113 case 0x15: | |
114 // DEC D | |
115 DE.B.B1--; | |
116 AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[DE.B.B1]| | |
117 ((DE.B.B1&0x0F)==0x0F? H_FLAG:0); | |
118 break; | |
119 case 0x16: | |
120 // LD D,NN | |
121 DE.B.B1=gbReadOpcode(PC.W++); | |
122 break; | |
123 case 0x17: | |
124 // RLA | |
125 tempValue=AF.B.B1&0x80? C_FLAG:0; | |
126 AF.B.B1=((AF.B.B1<<1)|((AF.B.B0&C_FLAG)>>4)) & 0xFF; | |
127 AF.B.B0=tempValue; | |
128 break; | |
129 case 0x18: | |
130 // JR NN | |
131 PC.W+=(s8)gbReadMemory(PC.W)+1; | |
132 break; | |
133 case 0x19: | |
134 // ADD HL,DE | |
135 tempRegister.W=(HL.W+DE.W)&0xFFFF; | |
136 AF.B.B0= (AF.B.B0 & Z_FLAG)| ((HL.W^DE.W^tempRegister.W)&0x1000? H_FLAG:0)| | |
137 (((long)HL.W+(long)DE.W)&0x10000? C_FLAG:0); | |
138 HL.W=tempRegister.W; | |
139 break; | |
140 case 0x1a: | |
141 // LD A,(DE) | |
142 AF.B.B1=gbReadMemory(DE.W); | |
143 break; | |
144 case 0x1b: | |
145 // DEC DE | |
146 DE.W--; | |
147 break; | |
148 case 0x1c: | |
149 // INC E | |
150 DE.B.B0++; | |
151 AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[DE.B.B0]| (DE.B.B0&0x0F? 0:H_FLAG); | |
152 break; | |
153 case 0x1d: | |
154 // DEC E | |
155 DE.B.B0--; | |
156 AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[DE.B.B0]| | |
157 ((DE.B.B0&0x0F)==0x0F? H_FLAG:0); | |
158 break; | |
159 case 0x1e: | |
160 // LD E,NN | |
161 DE.B.B0=gbReadOpcode(PC.W++); | |
162 break; | |
163 case 0x1f: | |
164 // RRA | |
165 tempValue=AF.B.B1&0x01; | |
166 AF.B.B1=(AF.B.B1>>1)|(AF.B.B0&C_FLAG? 0x80:0); | |
167 AF.B.B0=(tempValue<<4); | |
168 break; | |
169 case 0x20: | |
170 // JR NZ,NN | |
171 if(AF.B.B0&Z_FLAG) | |
172 PC.W++; | |
173 else { | |
174 PC.W+=(s8)gbReadMemory(PC.W)+1; | |
175 clockTicks++; | |
176 } | |
177 break; | |
178 case 0x21: | |
179 // LD HL,NNNN | |
180 HL.B.B0=gbReadMemory(PC.W++); | |
181 HL.B.B1=gbReadMemory(PC.W++); | |
182 break; | |
183 case 0x22: | |
184 // LDI (HL),A | |
185 gbWriteMemory(HL.W++,AF.B.B1); | |
186 break; | |
187 case 0x23: | |
188 // INC HL | |
189 HL.W++; | |
190 break; | |
191 case 0x24: | |
192 // INC H | |
193 HL.B.B1++; | |
194 AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[HL.B.B1]| (HL.B.B1&0x0F? 0:H_FLAG); | |
195 break; | |
196 case 0x25: | |
197 // DEC H | |
198 HL.B.B1--; | |
199 AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[HL.B.B1]| | |
200 ((HL.B.B1&0x0F)==0x0F? H_FLAG:0); | |
201 break; | |
202 case 0x26: | |
203 // LD H,NN | |
204 HL.B.B1=gbReadOpcode(PC.W++); | |
205 break; | |
206 case 0x27: | |
207 // DAA | |
208 tempRegister.W=AF.B.B1; | |
209 if(AF.B.B0&C_FLAG) tempRegister.W|=256; | |
210 if(AF.B.B0&H_FLAG) tempRegister.W|=512; | |
211 if(AF.B.B0&N_FLAG) tempRegister.W|=1024; | |
212 AF.W=DAATable[tempRegister.W]; | |
213 break; | |
214 case 0x28: | |
215 // JR Z,NN | |
216 if(AF.B.B0&Z_FLAG) { | |
217 PC.W+=(s8)gbReadMemory(PC.W)+1; | |
218 clockTicks++; | |
219 } else | |
220 PC.W++; | |
221 break; | |
222 case 0x29: | |
223 // ADD HL,HL | |
224 tempRegister.W=(HL.W+HL.W)&0xFFFF; AF.B.B0= (AF.B.B0 & Z_FLAG)| | |
225 ((HL.W^HL.W^tempRegister.W)&0x1000? H_FLAG:0)| | |
226 (((long)HL.W+(long)HL.W)&0x10000? C_FLAG:0); | |
227 HL.W=tempRegister.W; | |
228 break; | |
229 case 0x2a: | |
230 // LDI A,(HL) | |
231 AF.B.B1 = gbReadMemory(HL.W++); | |
232 break; | |
233 case 0x2b: | |
234 // DEC HL | |
235 HL.W--; | |
236 break; | |
237 case 0x2c: | |
238 // INC L | |
239 HL.B.B0++; | |
240 AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[HL.B.B0]| (HL.B.B0&0x0F? 0:H_FLAG); | |
241 break; | |
242 case 0x2d: | |
243 // DEC L | |
244 HL.B.B0--; | |
245 AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[HL.B.B0]| | |
246 ((HL.B.B0&0x0F)==0x0F? H_FLAG:0); | |
247 break; | |
248 case 0x2e: | |
249 // LD L,NN | |
250 HL.B.B0=gbReadOpcode(PC.W++); | |
251 break; | |
252 case 0x2f: | |
253 // CPL | |
254 AF.B.B1 ^= 255; | |
255 AF.B.B0|=N_FLAG|H_FLAG; | |
256 break; | |
257 case 0x30: | |
258 // JR NC,NN | |
259 if(AF.B.B0&C_FLAG) | |
260 PC.W++; | |
261 else { | |
262 PC.W+=(s8)gbReadMemory(PC.W)+1; | |
263 clockTicks++; | |
264 } | |
265 break; | |
266 case 0x31: | |
267 // LD SP,NNNN | |
268 SP.B.B0=gbReadMemory(PC.W++); | |
269 SP.B.B1=gbReadMemory(PC.W++); | |
270 break; | |
271 case 0x32: | |
272 // LDD (HL),A | |
273 gbWriteMemory(HL.W--,AF.B.B1); | |
274 break; | |
275 case 0x33: | |
276 // INC SP | |
277 SP.W++; | |
278 break; | |
279 case 0x34: | |
280 // INC (HL) | |
281 tempValue=(gbReadMemory(HL.W)+1) & 0xFF; | |
282 AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[tempValue]| (tempValue&0x0F? 0:H_FLAG); | |
283 gbWriteMemory(HL.W,tempValue); | |
284 break; | |
285 case 0x35: | |
286 // DEC (HL) | |
287 tempValue=(gbReadMemory(HL.W)-1) & 0xFF; | |
288 AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[tempValue]| | |
289 ((tempValue&0x0F)==0x0F? H_FLAG:0);gbWriteMemory(HL.W,tempValue); | |
290 break; | |
291 case 0x36: | |
292 // LD (HL),NN | |
293 gbWriteMemory(HL.W,gbReadOpcode(PC.W++)); | |
294 break; | |
295 case 0x37: | |
296 // SCF | |
297 AF.B.B0 = AF.B.B0 & Z_FLAG | C_FLAG; | |
298 break; | |
299 case 0x38: | |
300 // JR C,NN | |
301 if(AF.B.B0&C_FLAG) { | |
302 PC.W+=(s8)gbReadMemory(PC.W)+1; | |
303 clockTicks ++; | |
304 } else | |
305 PC.W++; | |
306 break; | |
307 case 0x39: | |
308 // ADD HL,SP | |
309 tempRegister.W=(HL.W+SP.W)&0xFFFF; | |
310 AF.B.B0= (AF.B.B0 & Z_FLAG)| ((HL.W^SP.W^tempRegister.W)&0x1000? H_FLAG:0)| | |
311 (((long)HL.W+(long)SP.W)&0x10000? C_FLAG:0); | |
312 HL.W=tempRegister.W; | |
313 break; | |
314 case 0x3a: | |
315 // LDD A,(HL) | |
316 AF.B.B1 = gbReadMemory(HL.W--); | |
317 break; | |
318 case 0x3b: | |
319 // DEC SP | |
320 SP.W--; | |
321 break; | |
322 case 0x3c: | |
323 // INC A | |
324 AF.B.B1++; | |
325 AF.B.B0= (AF.B.B0 & C_FLAG)|ZeroTable[AF.B.B1]| (AF.B.B1&0x0F? 0:H_FLAG); | |
326 break; | |
327 case 0x3d: | |
328 // DEC A | |
329 AF.B.B1--; | |
330 AF.B.B0= N_FLAG|(AF.B.B0 & C_FLAG)|ZeroTable[AF.B.B1]| | |
331 ((AF.B.B1&0x0F)==0x0F? H_FLAG:0); | |
332 break; | |
333 case 0x3e: | |
334 // LD A,NN | |
335 AF.B.B1=gbReadOpcode(PC.W++); | |
336 break; | |
337 case 0x3f: | |
338 // CCF | |
339 AF.B.B0^=C_FLAG;AF.B.B0&=~(N_FLAG|H_FLAG); | |
340 break; | |
341 case 0x40: | |
342 // LD B,B | |
343 BC.B.B1=BC.B.B1; | |
344 break; | |
345 case 0x41: | |
346 // LD B,C | |
347 BC.B.B1=BC.B.B0; | |
348 break; | |
349 case 0x42: | |
350 // LD B,D | |
351 BC.B.B1=DE.B.B1; | |
352 break; | |
353 case 0x43: | |
354 // LD B,E | |
355 BC.B.B1=DE.B.B0; | |
356 break; | |
357 case 0x44: | |
358 // LD B,H | |
359 BC.B.B1=HL.B.B1; | |
360 break; | |
361 case 0x45: | |
362 // LD B,L | |
363 BC.B.B1=HL.B.B0; | |
364 break; | |
365 case 0x46: | |
366 // LD B,(HL) | |
367 BC.B.B1=gbReadMemory(HL.W); | |
368 break; | |
369 case 0x47: | |
370 // LD B,A | |
371 BC.B.B1=AF.B.B1; | |
372 break; | |
373 case 0x48: | |
374 // LD C,B | |
375 BC.B.B0=BC.B.B1; | |
376 break; | |
377 case 0x49: | |
378 // LD C,C | |
379 BC.B.B0=BC.B.B0; | |
380 break; | |
381 case 0x4a: | |
382 // LD C,D | |
383 BC.B.B0=DE.B.B1; | |
384 break; | |
385 case 0x4b: | |
386 // LD C,E | |
387 BC.B.B0=DE.B.B0; | |
388 break; | |
389 case 0x4c: | |
390 // LD C,H | |
391 BC.B.B0=HL.B.B1; | |
392 break; | |
393 case 0x4d: | |
394 // LD C,L | |
395 BC.B.B0=HL.B.B0; | |
396 break; | |
397 case 0x4e: | |
398 // LD C,(HL) | |
399 BC.B.B0=gbReadMemory(HL.W); | |
400 break; | |
401 case 0x4f: | |
402 // LD C,A | |
403 BC.B.B0=AF.B.B1; | |
404 break; | |
405 case 0x50: | |
406 // LD D,B | |
407 DE.B.B1=BC.B.B1; | |
408 break; | |
409 case 0x51: | |
410 // LD D,C | |
411 DE.B.B1=BC.B.B0; | |
412 break; | |
413 case 0x52: | |
414 // LD D,D | |
415 DE.B.B1=DE.B.B1; | |
416 break; | |
417 case 0x53: | |
418 // LD D,E | |
419 DE.B.B1=DE.B.B0; | |
420 break; | |
421 case 0x54: | |
422 // LD D,H | |
423 DE.B.B1=HL.B.B1; | |
424 break; | |
425 case 0x55: | |
426 // LD D,L | |
427 DE.B.B1=HL.B.B0; | |
428 break; | |
429 case 0x56: | |
430 // LD D,(HL) | |
431 DE.B.B1=gbReadMemory(HL.W); | |
432 break; | |
433 case 0x57: | |
434 // LD D,A | |
435 DE.B.B1=AF.B.B1; | |
436 break; | |
437 case 0x58: | |
438 // LD E,B | |
439 DE.B.B0=BC.B.B1; | |
440 break; | |
441 case 0x59: | |
442 // LD E,C | |
443 DE.B.B0=BC.B.B0; | |
444 break; | |
445 case 0x5a: | |
446 // LD E,D | |
447 DE.B.B0=DE.B.B1; | |
448 break; | |
449 case 0x5b: | |
450 // LD E,E | |
451 DE.B.B0=DE.B.B0; | |
452 break; | |
453 case 0x5c: | |
454 // LD E,H | |
455 DE.B.B0=HL.B.B1; | |
456 break; | |
457 case 0x5d: | |
458 // LD E,L | |
459 DE.B.B0=HL.B.B0; | |
460 break; | |
461 case 0x5e: | |
462 // LD E,(HL) | |
463 DE.B.B0=gbReadMemory(HL.W); | |
464 break; | |
465 case 0x5f: | |
466 // LD E,A | |
467 DE.B.B0=AF.B.B1; | |
468 break; | |
469 case 0x60: | |
470 // LD H,B | |
471 HL.B.B1=BC.B.B1; | |
472 break; | |
473 case 0x61: | |
474 // LD H,C | |
475 HL.B.B1=BC.B.B0; | |
476 break; | |
477 case 0x62: | |
478 // LD H,D | |
479 HL.B.B1=DE.B.B1; | |
480 break; | |
481 case 0x63: | |
482 // LD H,E | |
483 HL.B.B1=DE.B.B0; | |
484 break; | |
485 case 0x64: | |
486 // LD H,H | |
487 HL.B.B1=HL.B.B1; | |
488 break; | |
489 case 0x65: | |
490 // LD H,L | |
491 HL.B.B1=HL.B.B0; | |
492 break; | |
493 case 0x66: | |
494 // LD H,(HL) | |
495 HL.B.B1=gbReadMemory(HL.W); | |
496 break; | |
497 case 0x67: | |
498 // LD H,A | |
499 HL.B.B1=AF.B.B1; | |
500 break; | |
501 case 0x68: | |
502 // LD L,B | |
503 HL.B.B0=BC.B.B1; | |
504 break; | |
505 case 0x69: | |
506 // LD L,C | |
507 HL.B.B0=BC.B.B0; | |
508 break; | |
509 case 0x6a: | |
510 // LD L,D | |
511 HL.B.B0=DE.B.B1; | |
512 break; | |
513 case 0x6b: | |
514 // LD L,E | |
515 HL.B.B0=DE.B.B0; | |
516 break; | |
517 case 0x6c: | |
518 // LD L,H | |
519 HL.B.B0=HL.B.B1; | |
520 break; | |
521 case 0x6d: | |
522 // LD L,L | |
523 HL.B.B0=HL.B.B0; | |
524 break; | |
525 case 0x6e: | |
526 // LD L,(HL) | |
527 HL.B.B0=gbReadMemory(HL.W); | |
528 break; | |
529 case 0x6f: | |
530 // LD L,A | |
531 HL.B.B0=AF.B.B1; | |
532 break; | |
533 case 0x70: | |
534 // LD (HL),B | |
535 gbWriteMemory(HL.W,BC.B.B1); | |
536 break; | |
537 case 0x71: | |
538 // LD (HL),C | |
539 gbWriteMemory(HL.W,BC.B.B0); | |
540 break; | |
541 case 0x72: | |
542 // LD (HL),D | |
543 gbWriteMemory(HL.W,DE.B.B1); | |
544 break; | |
545 case 0x73: | |
546 // LD (HL),E | |
547 gbWriteMemory(HL.W,DE.B.B0); | |
548 break; | |
549 case 0x74: | |
550 // LD (HL),H | |
551 gbWriteMemory(HL.W,HL.B.B1); | |
552 break; | |
553 case 0x75: | |
554 // LD (HL),L | |
555 gbWriteMemory(HL.W,HL.B.B0); | |
556 break; | |
557 case 0x76: | |
558 // HALT | |
559 if(IFF & 1) { | |
560 PC.W--; | |
561 IFF |= 0x80; | |
562 } else { | |
563 if((register_IE & register_IF) > 0) | |
564 IFF |= 0x100; | |
565 else { | |
566 PC.W--; | |
567 IFF |= 0x81; | |
568 } | |
569 } | |
570 break; | |
571 case 0x77: | |
572 // LD (HL),A | |
573 gbWriteMemory(HL.W,AF.B.B1); | |
574 break; | |
575 case 0x78: | |
576 // LD A,B | |
577 AF.B.B1=BC.B.B1; | |
578 break; | |
579 case 0x79: | |
580 // LD A,C | |
581 AF.B.B1=BC.B.B0; | |
582 break; | |
583 case 0x7a: | |
584 // LD A,D | |
585 AF.B.B1=DE.B.B1; | |
586 break; | |
587 case 0x7b: | |
588 // LD A,E | |
589 AF.B.B1=DE.B.B0; | |
590 break; | |
591 case 0x7c: | |
592 // LD A,H | |
593 AF.B.B1=HL.B.B1; | |
594 break; | |
595 case 0x7d: | |
596 // LD A,L | |
597 AF.B.B1=HL.B.B0; | |
598 break; | |
599 case 0x7e: | |
600 // LD A,(HL) | |
601 AF.B.B1=gbReadMemory(HL.W); | |
602 break; | |
603 case 0x7f: | |
604 // LD A,A | |
605 AF.B.B1=AF.B.B1; | |
606 break; | |
607 case 0x80: | |
608 // ADD B | |
609 tempRegister.W=AF.B.B1+BC.B.B1; | |
610 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
611 ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
612 AF.B.B1=tempRegister.B.B0; | |
613 break; | |
614 case 0x81: | |
615 // ADD C | |
616 tempRegister.W=AF.B.B1+BC.B.B0; | |
617 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
618 ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
619 AF.B.B1=tempRegister.B.B0; | |
620 break; | |
621 case 0x82: | |
622 // ADD D | |
623 tempRegister.W=AF.B.B1+DE.B.B1; | |
624 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
625 ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
626 AF.B.B1=tempRegister.B.B0; | |
627 break; | |
628 case 0x83: | |
629 // ADD E | |
630 tempRegister.W=AF.B.B1+DE.B.B0; | |
631 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
632 ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
633 AF.B.B1=tempRegister.B.B0; | |
634 break; | |
635 case 0x84: | |
636 // ADD H | |
637 tempRegister.W=AF.B.B1+HL.B.B1; | |
638 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
639 ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
640 AF.B.B1=tempRegister.B.B0; | |
641 break; | |
642 case 0x85: | |
643 // ADD L | |
644 tempRegister.W=AF.B.B1+HL.B.B0; | |
645 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
646 ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
647 AF.B.B1=tempRegister.B.B0; | |
648 break; | |
649 case 0x86: | |
650 // ADD (HL) | |
651 tempValue=gbReadMemory(HL.W); | |
652 tempRegister.W=AF.B.B1+tempValue; | |
653 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
654 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
655 AF.B.B1=tempRegister.B.B0; | |
656 break; | |
657 case 0x87: | |
658 // ADD A | |
659 tempRegister.W=AF.B.B1+AF.B.B1; | |
660 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
661 ((AF.B.B1^AF.B.B1^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
662 AF.B.B1=tempRegister.B.B0; | |
663 break; | |
664 case 0x88: | |
665 // ADC B: | |
666 tempRegister.W=AF.B.B1+BC.B.B1+(AF.B.B0&C_FLAG ? 1 : 0); | |
667 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
668 ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
669 AF.B.B1=tempRegister.B.B0; | |
670 break; | |
671 case 0x89: | |
672 // ADC C | |
673 tempRegister.W=AF.B.B1+BC.B.B0+(AF.B.B0&C_FLAG ? 1 : 0); | |
674 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
675 ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
676 AF.B.B1=tempRegister.B.B0; | |
677 break; | |
678 case 0x8a: | |
679 // ADC D | |
680 tempRegister.W=AF.B.B1+DE.B.B1+(AF.B.B0&C_FLAG ? 1 : 0); | |
681 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
682 ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
683 AF.B.B1=tempRegister.B.B0; | |
684 break; | |
685 case 0x8b: | |
686 // ADC E | |
687 tempRegister.W=AF.B.B1+DE.B.B0+(AF.B.B0&C_FLAG ? 1 : 0); | |
688 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
689 ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
690 AF.B.B1=tempRegister.B.B0; | |
691 break; | |
692 case 0x8c: | |
693 // ADC H | |
694 tempRegister.W=AF.B.B1+HL.B.B1+(AF.B.B0&C_FLAG ? 1 : 0); | |
695 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
696 ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); AF.B.B1=tempRegister.B.B0; | |
697 break; | |
698 case 0x8d: | |
699 // ADC L | |
700 tempRegister.W=AF.B.B1+HL.B.B0+(AF.B.B0&C_FLAG ? 1 : 0); | |
701 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
702 ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
703 AF.B.B1=tempRegister.B.B0; | |
704 break; | |
705 case 0x8e: | |
706 // ADC (HL) | |
707 tempValue=gbReadMemory(HL.W); | |
708 tempRegister.W=AF.B.B1+tempValue+(AF.B.B0&C_FLAG ? 1 : 0); | |
709 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
710 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0); | |
711 AF.B.B1=tempRegister.B.B0; | |
712 break; | |
713 case 0x8f: | |
714 // ADC A | |
715 tempRegister.W=AF.B.B1+AF.B.B1+(AF.B.B0&C_FLAG ? 1 : 0); | |
716 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
717 ((AF.B.B1^AF.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
718 AF.B.B1=tempRegister.B.B0; | |
719 break; | |
720 case 0x90: | |
721 // SUB B | |
722 tempRegister.W=AF.B.B1-BC.B.B1; | |
723 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
724 ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
725 AF.B.B1=tempRegister.B.B0; | |
726 break; | |
727 case 0x91: | |
728 // SUB C | |
729 tempRegister.W=AF.B.B1-BC.B.B0; | |
730 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
731 ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
732 AF.B.B1=tempRegister.B.B0; | |
733 break; | |
734 case 0x92: | |
735 // SUB D | |
736 tempRegister.W=AF.B.B1-DE.B.B1; | |
737 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
738 ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
739 AF.B.B1=tempRegister.B.B0; | |
740 break; | |
741 case 0x93: | |
742 // SUB E | |
743 tempRegister.W=AF.B.B1-DE.B.B0; | |
744 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
745 ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
746 AF.B.B1=tempRegister.B.B0; | |
747 break; | |
748 case 0x94: | |
749 // SUB H | |
750 tempRegister.W=AF.B.B1-HL.B.B1; | |
751 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
752 ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
753 AF.B.B1=tempRegister.B.B0; | |
754 break; | |
755 case 0x95: | |
756 // SUB L | |
757 tempRegister.W=AF.B.B1-HL.B.B0; | |
758 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
759 ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
760 AF.B.B1=tempRegister.B.B0; | |
761 break; | |
762 case 0x96: | |
763 // SUB (HL) | |
764 tempValue=gbReadMemory(HL.W); | |
765 tempRegister.W=AF.B.B1-tempValue; | |
766 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
767 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0); | |
768 AF.B.B1=tempRegister.B.B0; | |
769 break; | |
770 case 0x97: | |
771 // SUB A | |
772 AF.B.B1=0; | |
773 AF.B.B0=N_FLAG|Z_FLAG; | |
774 break; | |
775 case 0x98: | |
776 // SBC B | |
777 tempRegister.W=AF.B.B1-BC.B.B1-(AF.B.B0&C_FLAG ? 1 : 0); | |
778 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
779 ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
780 AF.B.B1=tempRegister.B.B0; | |
781 break; | |
782 case 0x99: | |
783 // SBC C | |
784 tempRegister.W=AF.B.B1-BC.B.B0-(AF.B.B0&C_FLAG ? 1 : 0); | |
785 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
786 ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
787 AF.B.B1=tempRegister.B.B0; | |
788 break; | |
789 case 0x9a: | |
790 // SBC D | |
791 tempRegister.W=AF.B.B1-DE.B.B1-(AF.B.B0&C_FLAG ? 1 : 0); | |
792 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
793 ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
794 AF.B.B1=tempRegister.B.B0; | |
795 break; | |
796 case 0x9b: | |
797 // SBC E | |
798 tempRegister.W=AF.B.B1-DE.B.B0-(AF.B.B0&C_FLAG ? 1 : 0); | |
799 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
800 ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
801 AF.B.B1=tempRegister.B.B0; | |
802 break; | |
803 case 0x9c: | |
804 // SBC H | |
805 tempRegister.W=AF.B.B1-HL.B.B1-(AF.B.B0&C_FLAG ? 1 : 0); | |
806 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
807 ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
808 AF.B.B1=tempRegister.B.B0; | |
809 break; | |
810 case 0x9d: | |
811 // SBC L | |
812 tempRegister.W=AF.B.B1-HL.B.B0-(AF.B.B0&C_FLAG ? 1 : 0); | |
813 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
814 ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
815 AF.B.B1=tempRegister.B.B0; | |
816 break; | |
817 case 0x9e: | |
818 // SBC (HL) | |
819 tempValue=gbReadMemory(HL.W); | |
820 tempRegister.W=AF.B.B1-tempValue-(AF.B.B0&C_FLAG ? 1 : 0); | |
821 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
822 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0); | |
823 AF.B.B1=tempRegister.B.B0; | |
824 break; | |
825 case 0x9f: | |
826 // SBC A | |
827 tempRegister.W=AF.B.B1-AF.B.B1-(AF.B.B0&C_FLAG ? 1 : 0); | |
828 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
829 ((AF.B.B1^AF.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
830 AF.B.B1=tempRegister.B.B0; | |
831 break; | |
832 case 0xa0: | |
833 // AND B | |
834 AF.B.B1&=BC.B.B1; | |
835 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
836 break; | |
837 case 0xa1: | |
838 // AND C | |
839 AF.B.B1&=BC.B.B0; | |
840 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
841 break; | |
842 case 0xa2: | |
843 // AND_D | |
844 AF.B.B1&=DE.B.B1; | |
845 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
846 break; | |
847 case 0xa3: | |
848 // AND E | |
849 AF.B.B1&=DE.B.B0; | |
850 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
851 break; | |
852 case 0xa4: | |
853 // AND H | |
854 AF.B.B1&=HL.B.B1; | |
855 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
856 break; | |
857 case 0xa5: | |
858 // AND L | |
859 AF.B.B1&=HL.B.B0; | |
860 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
861 break; | |
862 case 0xa6: | |
863 // AND (HL) | |
864 tempValue=gbReadMemory(HL.W); | |
865 AF.B.B1&=tempValue; | |
866 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
867 break; | |
868 case 0xa7: | |
869 // AND A | |
870 AF.B.B1&=AF.B.B1; | |
871 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
872 break; | |
873 case 0xa8: | |
874 // XOR B | |
875 AF.B.B1^=BC.B.B1; | |
876 AF.B.B0=ZeroTable[AF.B.B1]; | |
877 break; | |
878 case 0xa9: | |
879 // XOR C | |
880 AF.B.B1^=BC.B.B0; | |
881 AF.B.B0=ZeroTable[AF.B.B1]; | |
882 break; | |
883 case 0xaa: | |
884 // XOR D | |
885 AF.B.B1^=DE.B.B1; | |
886 AF.B.B0=ZeroTable[AF.B.B1]; | |
887 break; | |
888 case 0xab: | |
889 // XOR E | |
890 AF.B.B1^=DE.B.B0; | |
891 AF.B.B0=ZeroTable[AF.B.B1]; | |
892 break; | |
893 case 0xac: | |
894 // XOR H | |
895 AF.B.B1^=HL.B.B1; | |
896 AF.B.B0=ZeroTable[AF.B.B1]; | |
897 break; | |
898 case 0xad: | |
899 // XOR L | |
900 AF.B.B1^=HL.B.B0; | |
901 AF.B.B0=ZeroTable[AF.B.B1]; | |
902 break; | |
903 case 0xae: | |
904 // XOR (HL) | |
905 tempValue=gbReadMemory(HL.W); | |
906 AF.B.B1^=tempValue; | |
907 AF.B.B0=ZeroTable[AF.B.B1]; | |
908 break; | |
909 case 0xaf: | |
910 // XOR A | |
911 AF.B.B1=0; | |
912 AF.B.B0=Z_FLAG; | |
913 break; | |
914 case 0xb0: | |
915 // OR B | |
916 AF.B.B1|=BC.B.B1; | |
917 AF.B.B0=ZeroTable[AF.B.B1]; | |
918 break; | |
919 case 0xb1: | |
920 // OR C | |
921 AF.B.B1|=BC.B.B0; | |
922 AF.B.B0=ZeroTable[AF.B.B1]; | |
923 break; | |
924 case 0xb2: | |
925 // OR D | |
926 AF.B.B1|=DE.B.B1; | |
927 AF.B.B0=ZeroTable[AF.B.B1]; | |
928 break; | |
929 case 0xb3: | |
930 // OR E | |
931 AF.B.B1|=DE.B.B0; | |
932 AF.B.B0=ZeroTable[AF.B.B1]; | |
933 break; | |
934 case 0xb4: | |
935 // OR H | |
936 AF.B.B1|=HL.B.B1; | |
937 AF.B.B0=ZeroTable[AF.B.B1]; | |
938 break; | |
939 case 0xb5: | |
940 // OR L | |
941 AF.B.B1|=HL.B.B0; | |
942 AF.B.B0=ZeroTable[AF.B.B1]; | |
943 break; | |
944 case 0xb6: | |
945 // OR (HL) | |
946 tempValue=gbReadMemory(HL.W); | |
947 AF.B.B1|=tempValue; | |
948 AF.B.B0=ZeroTable[AF.B.B1]; | |
949 break; | |
950 case 0xb7: | |
951 // OR A | |
952 AF.B.B1|=AF.B.B1; | |
953 AF.B.B0=ZeroTable[AF.B.B1]; | |
954 break; | |
955 case 0xb8: | |
956 // CP B: | |
957 tempRegister.W=AF.B.B1-BC.B.B1; | |
958 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
959 ((AF.B.B1^BC.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
960 break; | |
961 case 0xb9: | |
962 // CP C | |
963 tempRegister.W=AF.B.B1-BC.B.B0; | |
964 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
965 ((AF.B.B1^BC.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
966 break; | |
967 case 0xba: | |
968 // CP D | |
969 tempRegister.W=AF.B.B1-DE.B.B1; | |
970 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
971 ((AF.B.B1^DE.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
972 break; | |
973 case 0xbb: | |
974 // CP E | |
975 tempRegister.W=AF.B.B1-DE.B.B0; | |
976 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
977 ((AF.B.B1^DE.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
978 break; | |
979 case 0xbc: | |
980 // CP H | |
981 tempRegister.W=AF.B.B1-HL.B.B1; | |
982 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
983 ((AF.B.B1^HL.B.B1^tempRegister.B.B0)&0x10?H_FLAG:0); | |
984 break; | |
985 case 0xbd: | |
986 // CP L | |
987 tempRegister.W=AF.B.B1-HL.B.B0; | |
988 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
989 ((AF.B.B1^HL.B.B0^tempRegister.B.B0)&0x10?H_FLAG:0); | |
990 break; | |
991 case 0xbe: | |
992 // CP (HL) | |
993 tempValue=gbReadMemory(HL.W); | |
994 tempRegister.W=AF.B.B1-tempValue; | |
995 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
996 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0); | |
997 break; | |
998 case 0xbf: | |
999 // CP A | |
1000 AF.B.B0=N_FLAG|Z_FLAG; | |
1001 break; | |
1002 case 0xc0: | |
1003 // RET NZ | |
1004 if(!(AF.B.B0&Z_FLAG)) { | |
1005 PC.B.B0=gbReadMemory(SP.W++); | |
1006 PC.B.B1=gbReadMemory(SP.W++); | |
1007 clockTicks += 3; | |
1008 } | |
1009 break; | |
1010 case 0xc1: | |
1011 // POP BC | |
1012 BC.B.B0=gbReadMemory(SP.W++); | |
1013 BC.B.B1=gbReadMemory(SP.W++); | |
1014 break; | |
1015 case 0xc2: | |
1016 // JP NZ,NNNN | |
1017 if(AF.B.B0&Z_FLAG) | |
1018 PC.W+=2; | |
1019 else { | |
1020 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1021 tempRegister.B.B1=gbReadMemory(PC.W); | |
1022 PC.W=tempRegister.W; | |
1023 clockTicks++; | |
1024 } | |
1025 break; | |
1026 case 0xc3: | |
1027 // JP NNNN | |
1028 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1029 tempRegister.B.B1=gbReadMemory(PC.W); | |
1030 PC.W=tempRegister.W; | |
1031 break; | |
1032 case 0xc4: | |
1033 // CALL NZ,NNNN | |
1034 if(AF.B.B0&Z_FLAG) | |
1035 PC.W+=2; | |
1036 else { | |
1037 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1038 tempRegister.B.B1=gbReadMemory(PC.W++); | |
1039 gbWriteMemory(--SP.W,PC.B.B1); | |
1040 gbWriteMemory(--SP.W,PC.B.B0); | |
1041 PC.W=tempRegister.W; | |
1042 clockTicks += 3; | |
1043 } | |
1044 break; | |
1045 case 0xc5: | |
1046 // PUSH BC | |
1047 gbWriteMemory(--SP.W,BC.B.B1); | |
1048 gbWriteMemory(--SP.W,BC.B.B0); | |
1049 break; | |
1050 case 0xc6: | |
1051 // ADD NN | |
1052 tempValue=gbReadOpcode(PC.W++); | |
1053 tempRegister.W=AF.B.B1+tempValue; | |
1054 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
1055 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10 ? H_FLAG:0); | |
1056 AF.B.B1=tempRegister.B.B0; | |
1057 break; | |
1058 case 0xc7: | |
1059 // RST 00 | |
1060 gbWriteMemory(--SP.W,PC.B.B1); | |
1061 gbWriteMemory(--SP.W,PC.B.B0); | |
1062 PC.W=0x0000; | |
1063 break; | |
1064 case 0xc8: | |
1065 // RET Z | |
1066 if(AF.B.B0&Z_FLAG) { | |
1067 PC.B.B0=gbReadMemory(SP.W++); | |
1068 PC.B.B1=gbReadMemory(SP.W++); | |
1069 clockTicks += 3; | |
1070 } | |
1071 break; | |
1072 case 0xc9: | |
1073 // RET | |
1074 PC.B.B0=gbReadMemory(SP.W++); | |
1075 PC.B.B1=gbReadMemory(SP.W++); | |
1076 break; | |
1077 case 0xca: | |
1078 // JP Z,NNNN | |
1079 if(AF.B.B0&Z_FLAG) { | |
1080 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1081 tempRegister.B.B1=gbReadMemory(PC.W); | |
1082 PC.W=tempRegister.W; | |
1083 clockTicks++; | |
1084 } else | |
1085 PC.W+=2; | |
1086 break; | |
1087 // CB done outside | |
1088 case 0xcc: | |
1089 // CALL Z,NNNN | |
1090 if(AF.B.B0&Z_FLAG) { | |
1091 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1092 tempRegister.B.B1=gbReadMemory(PC.W++); | |
1093 gbWriteMemory(--SP.W,PC.B.B1); | |
1094 gbWriteMemory(--SP.W,PC.B.B0); | |
1095 PC.W=tempRegister.W; | |
1096 clockTicks += 3; | |
1097 } else | |
1098 PC.W+=2; | |
1099 break; | |
1100 case 0xcd: | |
1101 // CALL NNNN | |
1102 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1103 tempRegister.B.B1=gbReadMemory(PC.W++); | |
1104 gbWriteMemory(--SP.W,PC.B.B1); | |
1105 gbWriteMemory(--SP.W,PC.B.B0); | |
1106 PC.W=tempRegister.W; | |
1107 break; | |
1108 case 0xce: | |
1109 // ADC NN | |
1110 tempValue=gbReadOpcode(PC.W++); | |
1111 tempRegister.W=AF.B.B1+tempValue+(AF.B.B0&C_FLAG ? 1 : 0); | |
1112 AF.B.B0= (tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
1113 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0); | |
1114 AF.B.B1=tempRegister.B.B0; | |
1115 break; | |
1116 case 0xcf: | |
1117 // RST 08 | |
1118 gbWriteMemory(--SP.W,PC.B.B1); | |
1119 gbWriteMemory(--SP.W,PC.B.B0); | |
1120 PC.W=0x0008; | |
1121 break; | |
1122 case 0xd0: | |
1123 // RET NC | |
1124 if(!(AF.B.B0&C_FLAG)) { | |
1125 PC.B.B0=gbReadMemory(SP.W++); | |
1126 PC.B.B1=gbReadMemory(SP.W++); | |
1127 clockTicks += 3; | |
1128 } | |
1129 break; | |
1130 case 0xd1: | |
1131 // POP DE | |
1132 DE.B.B0=gbReadMemory(SP.W++); | |
1133 DE.B.B1=gbReadMemory(SP.W++); | |
1134 break; | |
1135 case 0xd2: | |
1136 // JP NC,NNNN | |
1137 if(AF.B.B0&C_FLAG) | |
1138 PC.W+=2; | |
1139 else { | |
1140 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1141 tempRegister.B.B1=gbReadMemory(PC.W); | |
1142 PC.W=tempRegister.W; | |
1143 clockTicks++; | |
1144 } | |
1145 break; | |
1146 // D3 illegal | |
1147 case 0xd4: | |
1148 // CALL NC,NNNN | |
1149 if(AF.B.B0&C_FLAG) | |
1150 PC.W+=2; | |
1151 else { | |
1152 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1153 tempRegister.B.B1=gbReadMemory(PC.W++); | |
1154 gbWriteMemory(--SP.W,PC.B.B1); | |
1155 gbWriteMemory(--SP.W,PC.B.B0); | |
1156 PC.W=tempRegister.W; | |
1157 clockTicks += 3; | |
1158 } | |
1159 break; | |
1160 case 0xd5: | |
1161 // PUSH DE | |
1162 gbWriteMemory(--SP.W,DE.B.B1); | |
1163 gbWriteMemory(--SP.W,DE.B.B0); | |
1164 break; | |
1165 case 0xd6: | |
1166 // SUB NN | |
1167 tempValue=gbReadOpcode(PC.W++); | |
1168 tempRegister.W=AF.B.B1-tempValue; | |
1169 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
1170 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0); | |
1171 AF.B.B1=tempRegister.B.B0; | |
1172 break; | |
1173 case 0xd7: | |
1174 // RST 10 | |
1175 gbWriteMemory(--SP.W,PC.B.B1); | |
1176 gbWriteMemory(--SP.W,PC.B.B0); | |
1177 PC.W=0x0010; | |
1178 break; | |
1179 case 0xd8: | |
1180 // RET C | |
1181 if(AF.B.B0&C_FLAG) { | |
1182 PC.B.B0=gbReadMemory(SP.W++); | |
1183 PC.B.B1=gbReadMemory(SP.W++); | |
1184 clockTicks += 4; | |
1185 } | |
1186 break; | |
1187 case 0xd9: | |
1188 // RETI | |
1189 PC.B.B0=gbReadMemory(SP.W++); | |
1190 PC.B.B1=gbReadMemory(SP.W++); | |
1191 IFF |= 0x01; | |
1192 break; | |
1193 case 0xda: | |
1194 // JP C,NNNN | |
1195 if(AF.B.B0&C_FLAG) { | |
1196 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1197 tempRegister.B.B1=gbReadMemory(PC.W); | |
1198 PC.W=tempRegister.W; | |
1199 clockTicks++; | |
1200 } else | |
1201 PC.W+=2; | |
1202 break; | |
1203 // DB illegal | |
1204 case 0xdc: | |
1205 // CALL C,NNNN | |
1206 if(AF.B.B0&C_FLAG) { | |
1207 tempRegister.B.B0=gbReadMemory(PC.W++); | |
1208 tempRegister.B.B1=gbReadMemory(PC.W++); | |
1209 gbWriteMemory(--SP.W,PC.B.B1); | |
1210 gbWriteMemory(--SP.W,PC.B.B0); | |
1211 PC.W=tempRegister.W; | |
1212 clockTicks += 3; | |
1213 } else | |
1214 PC.W+=2; | |
1215 break; | |
1216 // DD illegal | |
1217 case 0xde: | |
1218 // SBC NN | |
1219 tempValue=gbReadOpcode(PC.W++); | |
1220 tempRegister.W=AF.B.B1-tempValue-(AF.B.B0&C_FLAG ? 1 : 0); | |
1221 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
1222 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0); | |
1223 AF.B.B1=tempRegister.B.B0; | |
1224 break; | |
1225 case 0xdf: | |
1226 // RST 18 | |
1227 gbWriteMemory(--SP.W,PC.B.B1); | |
1228 gbWriteMemory(--SP.W,PC.B.B0); | |
1229 PC.W=0x0018; | |
1230 break; | |
1231 case 0xe0: | |
1232 // LD (FF00+NN),A | |
1233 gbWriteMemory(0xff00 + gbReadOpcode(PC.W++),AF.B.B1); | |
1234 break; | |
1235 case 0xe1: | |
1236 // POP HL | |
1237 HL.B.B0=gbReadMemory(SP.W++); | |
1238 HL.B.B1=gbReadMemory(SP.W++); | |
1239 break; | |
1240 case 0xe2: | |
1241 // LD (FF00+C),A | |
1242 gbWriteMemory(0xff00 + BC.B.B0,AF.B.B1); | |
1243 break; | |
1244 // E3 illegal | |
1245 // E4 illegal | |
1246 case 0xe5: | |
1247 // PUSH HL | |
1248 gbWriteMemory(--SP.W,HL.B.B1); | |
1249 gbWriteMemory(--SP.W,HL.B.B0); | |
1250 break; | |
1251 case 0xe6: | |
1252 // AND NN | |
1253 tempValue=gbReadOpcode(PC.W++); | |
1254 AF.B.B1&=tempValue; | |
1255 AF.B.B0=H_FLAG|ZeroTable[AF.B.B1]; | |
1256 break; | |
1257 case 0xe7: | |
1258 // RST 20 | |
1259 gbWriteMemory(--SP.W,PC.B.B1); | |
1260 gbWriteMemory(--SP.W,PC.B.B0); | |
1261 PC.W=0x0020; | |
1262 break; | |
1263 case 0xe8: | |
1264 // ADD SP,NN | |
1265 offset = (s8)gbReadOpcode(PC.W++); | |
1266 | |
1267 if(offset >= 0) { | |
1268 tempRegister.W = SP.W + offset; | |
1269 AF.B.B0 = (SP.W > tempRegister.W ? C_FLAG : 0) | | |
1270 ((SP.W^offset^tempRegister.W)&0x1000? H_FLAG:0); | |
1271 SP.W = tempRegister.W; | |
1272 } else { | |
1273 tempRegister.W = SP.W + offset; | |
1274 AF.B.B0 = (SP.W < tempRegister.W ? C_FLAG : 0) | | |
1275 ((SP.W^offset^tempRegister.W)&0x1000?H_FLAG:0); | |
1276 SP.W = tempRegister.W; | |
1277 } | |
1278 break; | |
1279 case 0xe9: | |
1280 // LD PC,HL | |
1281 PC.W=HL.W; | |
1282 break; | |
1283 case 0xea: | |
1284 // LD (NNNN),A | |
1285 tempRegister.B.B0=gbReadOpcode(PC.W++); | |
1286 tempRegister.B.B1=gbReadOpcode(PC.W++); | |
1287 gbWriteMemory(tempRegister.W,AF.B.B1); | |
1288 break; | |
1289 // EB illegal | |
1290 // EC illegal | |
1291 // ED illegal | |
1292 case 0xee: | |
1293 // XOR NN | |
1294 tempValue=gbReadOpcode(PC.W++); | |
1295 AF.B.B1^=tempValue; | |
1296 AF.B.B0=ZeroTable[AF.B.B1]; | |
1297 break; | |
1298 case 0xef: | |
1299 // RST 28 | |
1300 gbWriteMemory(--SP.W,PC.B.B1); | |
1301 gbWriteMemory(--SP.W,PC.B.B0); | |
1302 PC.W=0x0028; | |
1303 break; | |
1304 case 0xf0: | |
1305 // LD A,(FF00+NN) | |
1306 AF.B.B1 = gbReadMemory(0xff00+gbReadOpcode(PC.W++)); | |
1307 break; | |
1308 case 0xf1: | |
1309 // POP AF | |
1310 AF.B.B0=gbReadMemory(SP.W++); | |
1311 AF.B.B1=gbReadMemory(SP.W++); | |
1312 break; | |
1313 case 0xf2: | |
1314 // LD A,(FF00+C) | |
1315 AF.B.B1 = gbReadMemory(0xff00+BC.B.B0); | |
1316 break; | |
1317 case 0xf3: | |
1318 // DI | |
1319 // IFF&=0xFE; | |
1320 IFF&=(~0x21); | |
1321 break; | |
1322 // F4 illegal | |
1323 case 0xf5: | |
1324 // PUSH AF | |
1325 gbWriteMemory(--SP.W,AF.B.B1); | |
1326 gbWriteMemory(--SP.W,AF.B.B0); | |
1327 break; | |
1328 case 0xf6: | |
1329 // OR NN | |
1330 tempValue=gbReadOpcode(PC.W++); | |
1331 AF.B.B1|=tempValue; | |
1332 AF.B.B0=ZeroTable[AF.B.B1]; | |
1333 break; | |
1334 case 0xf7: | |
1335 // RST 30 | |
1336 gbWriteMemory(--SP.W,PC.B.B1); | |
1337 gbWriteMemory(--SP.W,PC.B.B0); | |
1338 PC.W=0x0030; | |
1339 break; | |
1340 case 0xf8: | |
1341 // LD HL,SP+NN | |
1342 offset = (s8)gbReadOpcode(PC.W++); | |
1343 if(offset >= 0) { | |
1344 tempRegister.W = SP.W + offset; | |
1345 AF.B.B0 = (SP.W > tempRegister.W ? C_FLAG : 0) | | |
1346 ((SP.W^offset^tempRegister.W)&0x1000? H_FLAG:0); | |
1347 HL.W = tempRegister.W; | |
1348 } else { | |
1349 tempRegister.W = SP.W + offset; | |
1350 AF.B.B0 = (SP.W < tempRegister.W ? C_FLAG : 0) | | |
1351 ((SP.W^offset^tempRegister.W)&0x1000?H_FLAG:0); | |
1352 HL.W = tempRegister.W; | |
1353 } | |
1354 break; | |
1355 case 0xf9: | |
1356 // LD SP,HL | |
1357 SP.W=HL.W; | |
1358 break; | |
1359 case 0xfa: | |
1360 // LD A,(NNNN) | |
1361 tempRegister.B.B0=gbReadOpcode(PC.W++); | |
1362 tempRegister.B.B1=gbReadOpcode(PC.W++); | |
1363 AF.B.B1=gbReadMemory(tempRegister.W); | |
1364 break; | |
1365 case 0xfb: | |
1366 // EI | |
1367 IFF|=0x20; | |
1368 break; | |
1369 // FC illegal | |
1370 // FD illegal | |
1371 case 0xfe: | |
1372 // CP NN | |
1373 tempValue=gbReadOpcode(PC.W++); | |
1374 tempRegister.W=AF.B.B1-tempValue; | |
1375 AF.B.B0= N_FLAG|(tempRegister.B.B1?C_FLAG:0)|ZeroTable[tempRegister.B.B0]| | |
1376 ((AF.B.B1^tempValue^tempRegister.B.B0)&0x10?H_FLAG:0); | |
1377 break; | |
1378 case 0xff: | |
1379 // RST 38 | |
1380 gbWriteMemory(--SP.W,PC.B.B1); | |
1381 gbWriteMemory(--SP.W,PC.B.B0); | |
1382 PC.W=0x0038; | |
1383 break; | |
1384 default: | |
1385 systemMessage(0, N_("Unknown opcode %02x at %04x"), | |
1386 gbReadOpcode(PC.W-1),PC.W-1); | |
1387 emulating = false; | |
1388 return; |