forked from FIX94/fixGB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cpu.c
1748 lines (1547 loc) · 51.7 KB
/
cpu.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2017 FIX94
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
#include <stdio.h>
#include <stdbool.h>
#include <inttypes.h>
#include "cpu.h"
#include "apu.h"
#include "ppu.h"
#include "mem.h"
#include "input.h"
#define P_FLAG_C (1<<4)
#define P_FLAG_H (1<<5)
#define P_FLAG_N (1<<6)
#define P_FLAG_Z (1<<7)
//from main.c
extern bool gbEmuGBSPlayback;
extern uint16_t gbsLoadAddr;
extern uint16_t gbsInitAddr;
extern uint16_t gbsPlayAddr;
extern uint16_t gbsSP;
extern uint8_t cpuTimer;
extern bool gbCgbMode;
extern bool gbCgbBootrom;
//initalized elsewhere
uint8_t cpuAddSpeed = 1;
bool cpuCgbSpeed = false;
//used externally
bool cpuDoStopSwitch;
bool cpu_oam_dma;
bool cpu_oam_dma_running;
uint16_t cpu_oam_dma_addr;
static uint16_t sp, pc, cpuTmp16;
static uint8_t a,b,c,d,e,f,h,l,cpuTmp;
//gbs stuff
static bool gbsInitRet, gbsPlayRet;
static uint8_t sub_in_val;
static bool irqEnable;
static bool cpuHaltLoop,cpuStopLoop,cpuHaltBug,cpuPrevInAny;
static uint8_t curInstr;
static bool cpu_oam_dma_started;
static uint8_t cpu_oam_dma_pos;
bool cpuDmaHalt;
static void cpuSetupActionArr();
static const uint8_t *cpu_action_arr;
static uint8_t cpu_arr_pos;
static inline void cpuSetNopArr();
void cpuInit()
{
sub_in_val=0,cpuTmp=0,cpuTmp16=0;
if(gbCgbBootrom)
{
//will get set up in Bootrom
a=0,b=0,c=0,d=0,e=0,f=0,h=0,l=0;
sp=0;
pc=0;
}
else
{
if(gbCgbMode) //From GBC Bootrom
a=0x11,b=0,c=0,d=0,e=0x08,f=0x80,h=0,l=0x7C;
else //From GB Bootrom
a=0x01,b=0,c=0x13,d=0,e=0xD8,f=0xB0,h=1,l=0x4D;
sp = 0xFFFE; //Boot Stack Pointer
pc = 0x0100; //hardcoded ROM entrypoint
}
irqEnable = false;
cpuHaltLoop = false;
cpuStopLoop = false;
cpuHaltBug = false;
cpuPrevInAny = false;
cpuDoStopSwitch = false;
cpu_oam_dma = false;
cpu_oam_dma_running = false;
cpu_oam_dma_addr = 0;
cpuSetupActionArr();
//gbs stuff
gbsInitRet = false; //for first init
gbsPlayRet = true; //for first play call
curInstr = 0;
cpu_oam_dma_started = false;
cpu_oam_dma_pos = 0;
cpuDmaHalt = false;
cpuSetNopArr();
}
static inline void setAImmRegStats()
{
f &= ~(P_FLAG_C|P_FLAG_H|P_FLAG_N|P_FLAG_Z);
if(a == 0) f |= P_FLAG_Z;
}
static inline void cpuAdd16(uint16_t x)
{
uint32_t r1,r2;
r1=((h<<8)|l)+(x);
r2=(((h<<8)|l)&0xFFF)+((x)&0xFFF);
uint8_t tf = (uint8_t)(f&P_FLAG_Z);
if(r1 > 0xFFFF)
tf |= P_FLAG_C;
if(r2 > 0x0FFF)
tf |= P_FLAG_H;
l = r1;
h = r1 >> 8;
f = tf;
}
static inline int16_t cpuAddSp16(uint8_t add)
{
int32_t n = (int8_t)add;
uint32_t r1,r2,r3;
r1=sp+n;
r2=(sp&0xFF)+(n&0xFF);
r3=(sp&0xF)+(n&0xF);
uint8_t tf = 0;
if(r2 > 0xFF)
tf |= P_FLAG_C;
if(r3 > 0x0F)
tf |= P_FLAG_H;
f = tf;
return (uint16_t)r1;
}
static inline void setAddSubCmpFlags(uint16_t r1, uint16_t r2)
{
if(((uint8_t)r2)==0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
if(r2>0xFF)
f |= P_FLAG_C;
else
f &= ~P_FLAG_C;
if(r1>0xF)
f |= P_FLAG_H;
else
f &= ~P_FLAG_H;
}
static inline uint8_t cpuDoAdd8(uint8_t x, uint8_t y)
{
uint16_t r1,r2;
r1=(uint16_t)((x&0xF)+(y&0xF));
r2=(uint16_t)(x+y);
setAddSubCmpFlags(r1, r2);
f &= ~P_FLAG_N;
return (uint8_t)r2;
}
static void cpuAdd8(uint8_t *reg)
{
a = cpuDoAdd8(a,*reg);
}
static inline uint8_t cpuDoSub8(uint8_t x, uint8_t y)
{
uint16_t r1,r2;
r1=(uint16_t)((x&0xF)-(y&0xF));
r2=(uint16_t)(x-y);
setAddSubCmpFlags(r1, r2);
f |= P_FLAG_N;
return (uint8_t)r2;
}
static void cpuSub8(uint8_t *reg)
{
a = cpuDoSub8(a,*reg);
}
static void cpuCmp8(uint8_t *reg)
{
cpuDoSub8(a,*reg);
}
static void cpuSbc8(uint8_t *reg)
{
uint16_t r1,r2;
uint8_t x = *reg;
r1=(uint16_t)((a&0xF)-((x)&0xF)-((f&P_FLAG_C)?1:0));
r2=(uint16_t)(a-(x)-((f&P_FLAG_C)?1:0));
a=(uint8_t)r2;
setAddSubCmpFlags(r1, r2);
f |= P_FLAG_N;
}
static void cpuAdc8(uint8_t *reg)
{
uint16_t r1,r2;
uint8_t x = *reg;
r1=(uint16_t)((a&0xF)+((x)&0xF)+((f&P_FLAG_C)?1:0));
r2=(uint16_t)(a+(x)+((f&P_FLAG_C)?1:0));
a=(uint8_t)r2;
setAddSubCmpFlags(r1, r2);
f &= ~P_FLAG_N;
}
static void cpuXOR(uint8_t *reg)
{
a ^= (*reg);
setAImmRegStats();
}
static void cpuOR(uint8_t *reg)
{
a |= (*reg);
setAImmRegStats();
}
static void cpuAND(uint8_t *reg)
{
a &= (*reg);
setAImmRegStats();
f |= P_FLAG_H;
}
static void cpuCPL(uint8_t *reg)
{
uint8_t val = (*reg);
f |= (P_FLAG_H|P_FLAG_N);
*reg = ~val;
}
//rotate WITHOUT old carry used
static void cpuRLC(uint8_t *reg)
{
uint8_t val = (*reg);
f &= ~(P_FLAG_H|P_FLAG_N);
if(val&0x80)
f |= P_FLAG_C;
else
f &= ~P_FLAG_C;
val <<= 1;
if(f & P_FLAG_C)
val |= 1;
if(val == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
*reg = val;
}
//rotate WITHOUT old carry used
static void cpuRRC(uint8_t *reg)
{
uint8_t val = (*reg);
f &= ~(P_FLAG_H|P_FLAG_N);
if(val&1)
f |= P_FLAG_C;
else
f &= ~P_FLAG_C;
val >>= 1;
if(f & P_FLAG_C)
val |= 0x80;
if(val == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
*reg = val;
}
//rotate WITH old carry used
static void cpuRL(uint8_t *reg)
{
uint8_t val = (*reg);
uint8_t oldF = f;
f &= ~(P_FLAG_H|P_FLAG_N);
if(val&0x80)
f |= P_FLAG_C;
else
f &= ~P_FLAG_C;
val <<= 1;
if(oldF & P_FLAG_C)
val |= 1;
if(val == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
*reg = val;
}
//rotate WITH old carry used
static void cpuRR(uint8_t *reg)
{
uint8_t val = (*reg);
uint8_t oldF = f;
f &= ~(P_FLAG_H|P_FLAG_N);
if(val&1)
f |= P_FLAG_C;
else
f &= ~P_FLAG_C;
val >>= 1;
if(oldF & P_FLAG_C)
val |= 0x80;
if(val == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
*reg = val;
}
//Direct calls for a
static void cpuRLCA()
{
cpuRLC(&a);
f &= ~P_FLAG_Z;
}
static void cpuRRCA()
{
cpuRRC(&a);
f &= ~P_FLAG_Z;
}
static void cpuRLA()
{
cpuRL(&a);
f &= ~P_FLAG_Z;
}
static void cpuRRA()
{
cpuRR(&a);
f &= ~P_FLAG_Z;
}
//shift left
static void cpuSLA(uint8_t *reg)
{
uint8_t val = (*reg);
f &= ~(P_FLAG_H|P_FLAG_N);
if(val&0x80)
f |= P_FLAG_C;
else
f &= ~P_FLAG_C;
val <<= 1;
if(val == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
*reg = val;
}
//shift right arithmetic
static void cpuSRA(uint8_t *reg)
{
uint8_t val = (*reg);
uint8_t oldSign = (val&0x80);
f &= ~(P_FLAG_H|P_FLAG_N);
if(val&1)
f |= P_FLAG_C;
else
f &= ~P_FLAG_C;
val >>= 1;
val |= oldSign;
if(val == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
*reg = val;
}
//shift right logical
static void cpuSRL(uint8_t *reg)
{
uint8_t val = (*reg);
f &= ~(P_FLAG_H|P_FLAG_N);
if(val&1)
f |= P_FLAG_C;
else
f &= ~P_FLAG_C;
val >>= 1;
if(val == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
*reg = val;
}
static void cpuSWAP(uint8_t *reg)
{
uint8_t val = (*reg);
f &= ~(P_FLAG_H|P_FLAG_N|P_FLAG_C);
uint8_t vL = val&0xF;
val>>=4;
val|=vL<<4;
if(val == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
*reg = val;
}
static void cpuBIT(uint8_t *reg)
{
uint8_t val = (*reg);
f &= ~P_FLAG_N;
f |= P_FLAG_H;
if((val&(1<<sub_in_val)) == 0)
f |= P_FLAG_Z;
else
f &= ~P_FLAG_Z;
}
static void cpuSET(uint8_t *reg)
{
uint8_t val = (*reg);
val |= (1<<sub_in_val);
*reg = val;
}
static void cpuRES(uint8_t *reg)
{
uint8_t val = (*reg);
val &= ~(1<<sub_in_val);
*reg = val;
}
static void cpuHALT(uint8_t *none)
{
(void)none;
//HALT bug, PC wont increase next instruction!
if(!irqEnable && memGetCurIrqList())
cpuHaltBug = true;
else //enters HALT mode normall
cpuHaltLoop = true;
}
static void cpuBcInc()
{
uint16_t tmp = c | b<<8;
tmp++;
c = tmp&0xFF;
b = tmp>>8;
}
static void cpuDeInc()
{
uint16_t tmp = e | d<<8;
tmp++;
e = tmp&0xFF;
d = tmp>>8;
}
static void cpuHlInc()
{
uint16_t tmp = l | h<<8;
tmp++;
l = tmp&0xFF;
h = tmp>>8;
}
static void cpuSpInc()
{
sp++;
}
static void cpuBcDec()
{
uint16_t tmp = c | b<<8;
tmp--;
c = tmp&0xFF;
b = tmp>>8;
}
static void cpuDeDec()
{
uint16_t tmp = e | d<<8;
tmp--;
e = tmp&0xFF;
d = tmp>>8;
}
static void cpuHlDec()
{
uint16_t tmp = l | h<<8;
tmp--;
l = tmp&0xFF;
h = tmp>>8;
}
static void cpuSpDec()
{
sp--;
}
static void cpuNoAction(uint8_t *reg) { (void)reg; };
static void cpuLDa(uint8_t *reg) { a = (*reg); }
static void cpuLDb(uint8_t *reg) { b = (*reg); }
static void cpuLDc(uint8_t *reg) { c = (*reg); }
static void cpuLDd(uint8_t *reg) { d = (*reg); }
static void cpuLDe(uint8_t *reg) { e = (*reg); }
static void cpuLDl(uint8_t *reg) { l = (*reg); }
static void cpuLDh(uint8_t *reg) { h = (*reg); }
static void cpuSTbc(uint8_t *reg) { memSet8(c | b<<8, (*reg)); }
static void cpuSTde(uint8_t *reg) { memSet8(e | d<<8, (*reg)); }
static void cpuSThl(uint8_t *reg) { memSet8(l | h<<8, (*reg)); }
static void cpuSTt16(uint8_t *reg) { memSet8(cpuTmp16, (*reg)); }
static void cpuSThlInc(uint8_t *reg) { cpuSThl(reg); cpuHlInc(); }
static void cpuSThlDec(uint8_t *reg) { cpuSThl(reg); cpuHlDec(); }
static void cpuInc(uint8_t *reg)
{
uint8_t tf = f&P_FLAG_C;
*reg = cpuDoAdd8(*reg,1);
f&=~P_FLAG_C;
f|=tf;
}
static void cpuDec(uint8_t *reg)
{
uint8_t tf = f&P_FLAG_C;
*reg = cpuDoSub8(*reg,1);
f&=~P_FLAG_C;
f|=tf;
}
static void cpuDAA(uint8_t *reg)
{
int16_t in = *reg;
if (!(f & P_FLAG_N))
{
if ((f & P_FLAG_H) || (in & 0xF) > 9)
in += 0x06;
if ((f & P_FLAG_C) || in > 0x9F)
in += 0x60;
}
else
{
if (f & P_FLAG_H)
in = (in - 6) & 0xFF;
if (f & P_FLAG_C)
in -= 0x60;
}
f &= ~(P_FLAG_H | P_FLAG_Z);
if ((in & 0x100) == 0x100)
f |= P_FLAG_C;
in &= 0xFF;
if (in == 0)
f |= P_FLAG_Z;
*reg = (uint8_t)in;
}
static void cpuSetStopLoop()
{
printf("CPU: Frozen until Button is pressed\n");
cpuStopLoop = true;
}
static void cpuSTOP(uint8_t *none)
{
(void)none;
//printf("CPU called STOP instruction\n");
if(cpuDoStopSwitch)
{
cpuSetSpeed(!cpuCgbSpeed);
cpuDoStopSwitch = false;
}
else
cpuSetStopLoop();
//takes up 2 instructions?
pc++;
}
enum {
CPU_GET_INSTRUCTION = 0,
CPU_GET_SUBINSTRUCTION,
CPU_DELAY_CYCLE,
CPU_ACTION_GET_INSTRUCTION,
CPU_A_ACTION_GET_INSTRUCTION,
CPU_B_ACTION_GET_INSTRUCTION,
CPU_C_ACTION_GET_INSTRUCTION,
CPU_D_ACTION_GET_INSTRUCTION,
CPU_E_ACTION_GET_INSTRUCTION,
CPU_H_ACTION_GET_INSTRUCTION,
CPU_L_ACTION_GET_INSTRUCTION,
CPU_ACTION_WRITE,
CPU_A_ACTION_WRITE,
CPU_B_ACTION_WRITE,
CPU_C_ACTION_WRITE,
CPU_D_ACTION_WRITE,
CPU_E_ACTION_WRITE,
CPU_H_ACTION_WRITE,
CPU_L_ACTION_WRITE,
CPU_BC_ACTION_ADD,
CPU_DE_ACTION_ADD,
CPU_HL_ACTION_ADD,
CPU_SP_ACTION_ADD,
CPU_HL_ADD_SPECIAL,
CPU_SP_ADD_SPECIAL,
CPU_ACTION_WRITE8_HL,
CPU_TMP_ADD_PC,
CPU_TMP_READ8_BC,
CPU_TMP_READ8_DE,
CPU_TMP_READ8_HL,
CPU_TMP_READ8_HL_INC,
CPU_TMP_READ8_HL_DEC,
CPU_TMP_READ8_PC_INC,
CPU_TMP_READ8_PC_INC_JRNZ_CHK,
CPU_TMP_READ8_PC_INC_JRZ_CHK,
CPU_TMP_READ8_PC_INC_JRNC_CHK,
CPU_TMP_READ8_PC_INC_JRC_CHK,
CPU_TMP_READ8_SP_INC,
CPU_PCL_FROM_TMP_PCH_READ8_SP_INC,
CPU_C_FROM_TMP_B_READ8_SP_INC,
CPU_E_FROM_TMP_D_READ8_SP_INC,
CPU_L_FROM_TMP_H_READ8_SP_INC,
CPU_F_FROM_TMP_A_READ8_SP_INC,
CPU_TMP_READHIGH_A,
CPU_TMP_WRITEHIGH_A,
CPU_C_READHIGH_A,
CPU_C_WRITEHIGH_A,
CPU_SP_FROM_HL,
CPU_SP_WRITE8_A_DEC,
CPU_SP_WRITE8_B_DEC,
CPU_SP_WRITE8_C_DEC,
CPU_SP_WRITE8_D_DEC,
CPU_SP_WRITE8_E_DEC,
CPU_SP_WRITE8_F_DEC,
CPU_SP_WRITE8_H_DEC,
CPU_SP_WRITE8_L_DEC,
CPU_SP_WRITE8_PCH_DEC,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_T16,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_00,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_08,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_10,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_18,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_20,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_28,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_30,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_38,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_40,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_48,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_50,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_58,
CPU_SP_WRITE8_PCL_DEC_PC_FROM_60,
CPU_A_READ8_TMP16,
CPU_A_READ8_PC_INC,
CPU_B_READ8_PC_INC,
CPU_C_READ8_PC_INC,
CPU_D_READ8_PC_INC,
CPU_E_READ8_PC_INC,
CPU_L_READ8_PC_INC,
CPU_H_READ8_PC_INC,
CPU_PCL_FROM_TMP_PCH_READ8_PC,
CPU_SPL_FROM_TMP_SPH_READ8_PC_INC,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_CNZ_CHK,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_CNC_CHK,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_CZ_CHK,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_CC_CHK,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_JPNZ_CHK,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_JPNC_CHK,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_JPZ_CHK,
CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_JPC_CHK,
CPU_TMP16_WRITE8_SPL_INC,
CPU_TMP16_WRITE8_SPH,
CPU_DI_GET_INSTRUCTION,
CPU_EI_GET_INSTRUCTION,
CPU_GET_INSTRUCTION_EI,
CPU_SCF_GET_INSTRUCTION,
CPU_CCF_GET_INSTRUCTION,
CPU_PC_FROM_HL_GET_INSTRUCTION,
CPU_PC_FROM_T16,
CPU_RET_NZ_CHK,
CPU_RET_NC_CHK,
CPU_RET_Z_CHK,
CPU_RET_C_CHK,
};
/* arrays for multiple similar instructions */
static const uint8_t cpu_imm_arr[1] = { CPU_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_a_arr[1] = { CPU_A_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_b_arr[1] = { CPU_B_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_c_arr[1] = { CPU_C_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_d_arr[1] = { CPU_D_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_e_arr[1] = { CPU_E_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_h_arr[1] = { CPU_H_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_l_arr[1] = { CPU_L_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_bc_arr[2] = { CPU_TMP_READ8_BC, CPU_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_de_arr[2] = { CPU_TMP_READ8_DE, CPU_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_hl_arr[2] = { CPU_TMP_READ8_HL, CPU_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_pc_arr[2] = { CPU_TMP_READ8_PC_INC, CPU_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_hl_inc_arr[2] = { CPU_TMP_READ8_HL_INC, CPU_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_hl_dec_arr[2] = { CPU_TMP_READ8_HL_DEC, CPU_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_delay_arr[2] = { CPU_DELAY_CYCLE, CPU_ACTION_GET_INSTRUCTION };
static const uint8_t cpu_imm_hl_st_arr[3] = { CPU_TMP_READ8_HL, CPU_ACTION_WRITE8_HL, CPU_GET_INSTRUCTION };
/* arrays for single special instructions */
static const uint8_t cpu_nop_arr[1] = { CPU_GET_INSTRUCTION };
static const uint8_t cpu_sub_arr[1] = { CPU_GET_SUBINSTRUCTION };
static const uint8_t cpu_hljmp_arr[1] = { CPU_PC_FROM_HL_GET_INSTRUCTION };
static const uint8_t cpu_sp_from_hl_arr[2] = { CPU_SP_FROM_HL, CPU_GET_INSTRUCTION };
static const uint8_t cpu_absjmp_arr[4] = { CPU_TMP_READ8_PC_INC, CPU_PCL_FROM_TMP_PCH_READ8_PC, CPU_DELAY_CYCLE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_absjmpnz_arr[4] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_JPNZ_CHK, CPU_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_absjmpnc_arr[4] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_JPNC_CHK, CPU_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_absjmpz_arr[4] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_JPZ_CHK, CPU_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_absjmpc_arr[4] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_JPC_CHK, CPU_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_abscall_arr[6] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_abscallnz_arr[6] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_CNZ_CHK, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_abscallnc_arr[6] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_CNC_CHK, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_abscallz_arr[6] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_CZ_CHK, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_abscallc_arr[6] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC_CC_CHK, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_T16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ret_arr[4] = { CPU_TMP_READ8_SP_INC, CPU_PCL_FROM_TMP_PCH_READ8_SP_INC, CPU_DELAY_CYCLE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_reti_arr[4] = { CPU_TMP_READ8_SP_INC, CPU_PCL_FROM_TMP_PCH_READ8_SP_INC, CPU_DELAY_CYCLE, CPU_EI_GET_INSTRUCTION };
static const uint8_t cpu_retnz_arr[5] = { CPU_RET_NZ_CHK, CPU_TMP_READ8_SP_INC, CPU_PCL_FROM_TMP_PCH_READ8_SP_INC, CPU_DELAY_CYCLE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_retnc_arr[5] = { CPU_RET_NC_CHK, CPU_TMP_READ8_SP_INC, CPU_PCL_FROM_TMP_PCH_READ8_SP_INC, CPU_DELAY_CYCLE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_retz_arr[5] = { CPU_RET_Z_CHK, CPU_TMP_READ8_SP_INC, CPU_PCL_FROM_TMP_PCH_READ8_SP_INC, CPU_DELAY_CYCLE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_retc_arr[5] = { CPU_RET_C_CHK, CPU_TMP_READ8_SP_INC, CPU_PCL_FROM_TMP_PCH_READ8_SP_INC, CPU_DELAY_CYCLE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst00_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_00, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst08_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_08, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst10_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_10, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst18_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_18, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst20_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_20, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst28_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_28, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst30_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_30, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst38_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_38, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst40_arr[5] = { CPU_DELAY_CYCLE, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_40, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst48_arr[5] = { CPU_DELAY_CYCLE, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_48, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst50_arr[5] = { CPU_DELAY_CYCLE, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_50, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst58_arr[5] = { CPU_DELAY_CYCLE, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_58, CPU_GET_INSTRUCTION };
static const uint8_t cpu_rst60_arr[5] = { CPU_DELAY_CYCLE, CPU_DELAY_CYCLE, CPU_SP_WRITE8_PCH_DEC, CPU_SP_WRITE8_PCL_DEC_PC_FROM_60, CPU_GET_INSTRUCTION };
static const uint8_t cpu_push_bc_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_B_DEC, CPU_SP_WRITE8_C_DEC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_push_de_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_D_DEC, CPU_SP_WRITE8_E_DEC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_push_hl_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_H_DEC, CPU_SP_WRITE8_L_DEC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_push_af_arr[4] = { CPU_DELAY_CYCLE, CPU_SP_WRITE8_A_DEC, CPU_SP_WRITE8_F_DEC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_pop_bc_arr[3] = { CPU_TMP_READ8_SP_INC, CPU_C_FROM_TMP_B_READ8_SP_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_pop_de_arr[3] = { CPU_TMP_READ8_SP_INC, CPU_E_FROM_TMP_D_READ8_SP_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_pop_hl_arr[3] = { CPU_TMP_READ8_SP_INC, CPU_L_FROM_TMP_H_READ8_SP_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_pop_af_arr[3] = { CPU_TMP_READ8_SP_INC, CPU_F_FROM_TMP_A_READ8_SP_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_a_arr[2] = { CPU_A_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_b_arr[2] = { CPU_B_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_c_arr[2] = { CPU_C_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_d_arr[2] = { CPU_D_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_e_arr[2] = { CPU_E_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_h_arr[2] = { CPU_H_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_l_arr[2] = { CPU_L_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ldhc_a_arr[2] = { CPU_C_READHIGH_A, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ldh_a_arr[3] = { CPU_TMP_READ8_PC_INC, CPU_TMP_READHIGH_A, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_bc_arr[3] = { CPU_C_READ8_PC_INC, CPU_B_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_de_arr[3] = { CPU_E_READ8_PC_INC, CPU_D_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_hl_arr[3] = { CPU_L_READ8_PC_INC, CPU_H_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_sp_arr[3] = { CPU_TMP_READ8_PC_INC, CPU_SPL_FROM_TMP_SPH_READ8_PC_INC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld16_a_arr[4] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC, CPU_A_READ8_TMP16, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st_a_arr[2] = { CPU_A_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st_b_arr[2] = { CPU_B_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st_c_arr[2] = { CPU_C_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st_d_arr[2] = { CPU_D_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st_e_arr[2] = { CPU_E_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st_h_arr[2] = { CPU_H_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st_l_arr[2] = { CPU_L_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st_imm_arr[3] = { CPU_TMP_READ8_PC_INC, CPU_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_sthc_a_arr[2] = { CPU_C_WRITEHIGH_A, CPU_GET_INSTRUCTION };
static const uint8_t cpu_sth_a_arr[3] = { CPU_TMP_READ8_PC_INC, CPU_TMP_WRITEHIGH_A, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st16_a_arr[4] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC, CPU_A_ACTION_WRITE, CPU_GET_INSTRUCTION };
static const uint8_t cpu_st16_sp_arr[5] = { CPU_TMP_READ8_PC_INC, CPU_T16L_FROM_TMP_T16H_READ8_PC_INC, CPU_TMP16_WRITE8_SPL_INC, CPU_TMP16_WRITE8_SPH, CPU_GET_INSTRUCTION };
static const uint8_t cpu_jr_arr[3] = { CPU_TMP_READ8_PC_INC, CPU_TMP_ADD_PC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_jrnz_arr[3] = { CPU_TMP_READ8_PC_INC_JRNZ_CHK, CPU_TMP_ADD_PC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_jrz_arr[3] = { CPU_TMP_READ8_PC_INC_JRZ_CHK, CPU_TMP_ADD_PC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_jrnc_arr[3] = { CPU_TMP_READ8_PC_INC_JRNC_CHK, CPU_TMP_ADD_PC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_jrc_arr[3] = { CPU_TMP_READ8_PC_INC_JRC_CHK, CPU_TMP_ADD_PC, CPU_GET_INSTRUCTION };
static const uint8_t cpu_di_arr[1] = { CPU_DI_GET_INSTRUCTION };
static const uint8_t cpu_ei_arr[1] = { CPU_GET_INSTRUCTION_EI };
static const uint8_t cpu_scf_arr[1] = { CPU_SCF_GET_INSTRUCTION };
static const uint8_t cpu_ccf_arr[1] = { CPU_CCF_GET_INSTRUCTION };
static const uint8_t cpu_add_bc_arr[2] = { CPU_BC_ACTION_ADD, CPU_GET_INSTRUCTION };
static const uint8_t cpu_add_de_arr[2] = { CPU_DE_ACTION_ADD, CPU_GET_INSTRUCTION };
static const uint8_t cpu_add_hl_arr[2] = { CPU_HL_ACTION_ADD, CPU_GET_INSTRUCTION };
static const uint8_t cpu_add_sp_arr[2] = { CPU_SP_ACTION_ADD, CPU_GET_INSTRUCTION };
static const uint8_t cpu_ld_hl_add_sp_imm_arr[3] = { CPU_TMP_READ8_PC_INC, CPU_HL_ADD_SPECIAL, CPU_GET_INSTRUCTION };
static const uint8_t cpu_add_sp_imm_arr[4] = { CPU_TMP_READ8_PC_INC, CPU_SP_ADD_SPECIAL, CPU_DELAY_CYCLE, CPU_GET_INSTRUCTION };
static inline void cpuSetNopArr()
{
cpu_action_arr = cpu_nop_arr;
cpu_arr_pos = 0;
}
static const uint8_t *cpu_instr_arr[256] = {
cpu_nop_arr, cpu_ld_bc_arr, cpu_st_a_arr, cpu_imm_delay_arr, //0x00-0x03
cpu_imm_b_arr, cpu_imm_b_arr, cpu_ld_b_arr, cpu_imm_a_arr, //0x04-0x07
cpu_st16_sp_arr, cpu_add_bc_arr, cpu_imm_bc_arr, cpu_imm_delay_arr, //0x08-0x0B
cpu_imm_c_arr, cpu_imm_c_arr, cpu_ld_c_arr, cpu_imm_a_arr, //0x0C-0x0F
cpu_imm_arr, cpu_ld_de_arr, cpu_st_a_arr, cpu_imm_delay_arr, //0x10-0x13
cpu_imm_d_arr, cpu_imm_d_arr, cpu_ld_d_arr, cpu_imm_a_arr, //0x14-0x17
cpu_jr_arr, cpu_add_de_arr, cpu_imm_de_arr, cpu_imm_delay_arr, //0x18-0x1B
cpu_imm_e_arr, cpu_imm_e_arr, cpu_ld_e_arr, cpu_imm_a_arr, //0x1C-0x1F
cpu_jrnz_arr, cpu_ld_hl_arr, cpu_st_a_arr, cpu_imm_delay_arr, //0x20-0x23
cpu_imm_h_arr, cpu_imm_h_arr, cpu_ld_h_arr, cpu_imm_a_arr, //0x24-0x27
cpu_jrz_arr, cpu_add_hl_arr, cpu_imm_hl_inc_arr, cpu_imm_delay_arr, //0x28-0x2B
cpu_imm_l_arr, cpu_imm_l_arr, cpu_ld_l_arr, cpu_imm_a_arr, //0x2C-0x2F
cpu_jrnc_arr, cpu_ld_sp_arr, cpu_st_a_arr, cpu_imm_delay_arr, //0x30-0x33
cpu_imm_hl_st_arr, cpu_imm_hl_st_arr, cpu_st_imm_arr, cpu_scf_arr, //0x34-0x37
cpu_jrc_arr, cpu_add_sp_arr, cpu_imm_hl_dec_arr, cpu_imm_delay_arr, //0x38-0x3B
cpu_imm_a_arr, cpu_imm_a_arr, cpu_ld_a_arr, cpu_ccf_arr, //0x3C-0x3F
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x40-0x43
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x44-0x47
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x48-0x4B
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x4C-0x4F
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x50-0x53
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x54-0x57
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x58-0x5B
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x5C-0x5F
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x60-0x63
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x64-0x67
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x68-0x6B
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x6C-0x6F
cpu_st_b_arr, cpu_st_c_arr, cpu_st_d_arr, cpu_st_e_arr, //0x70-0x73
cpu_st_h_arr, cpu_st_l_arr, cpu_imm_arr, cpu_st_a_arr, //0x74-0x77
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x78-0x7B
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x7C-0x7F
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x80-0x83
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x84-0x87
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x88-0x8B
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x8C-0x8F
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x90-0x93
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x94-0x97
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0x98-0x9B
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0x9C-0x9F
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0xA0-0xA3
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0xA4-0xA7
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0xA8-0xAB
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0xAC-0xAF
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0xB0-0xB3
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0xB4-0xB7
cpu_imm_b_arr, cpu_imm_c_arr, cpu_imm_d_arr, cpu_imm_e_arr, //0xB8-0xBB
cpu_imm_h_arr, cpu_imm_l_arr, cpu_imm_hl_arr, cpu_imm_a_arr, //0xBC-0xBF
cpu_retnz_arr, cpu_pop_bc_arr, cpu_absjmpnz_arr, cpu_absjmp_arr, //0xC0-0xC3
cpu_abscallnz_arr, cpu_push_bc_arr, cpu_imm_pc_arr, cpu_rst00_arr, //0xC4-0xC7
cpu_retz_arr, cpu_ret_arr, cpu_absjmpz_arr, cpu_sub_arr, //0xC8-0xCB
cpu_abscallz_arr, cpu_abscall_arr, cpu_imm_pc_arr, cpu_rst08_arr, //0xCC-0xCF
cpu_retnc_arr, cpu_pop_de_arr, cpu_absjmpnc_arr, NULL, //0xD0-0xD3 (0xD3=Invalid)
cpu_abscallnc_arr, cpu_push_de_arr, cpu_imm_pc_arr, cpu_rst10_arr, //0xD4-0xD7
cpu_retc_arr, cpu_reti_arr, cpu_absjmpc_arr, NULL, //0xD8-0xDB (0xDB=Invalid)
cpu_abscallc_arr, NULL, cpu_imm_pc_arr, cpu_rst18_arr, //0xDC-0xDF (0xDD=Invalid)
cpu_sth_a_arr, cpu_pop_hl_arr, cpu_sthc_a_arr, NULL, //0xE0-0xE3 (0xE3=Invalid)
NULL, cpu_push_hl_arr, cpu_imm_pc_arr, cpu_rst20_arr, //0xE4-0xE7 (0xE4=Invalid)
cpu_add_sp_imm_arr, cpu_hljmp_arr, cpu_st16_a_arr, NULL, //0xE8-0xEB (0xEB=Invalid)
NULL, NULL, cpu_imm_pc_arr, cpu_rst28_arr, //0xEC-0xEF (0xEC=Invalid, 0xED=Invalid)
cpu_ldh_a_arr, cpu_pop_af_arr, cpu_ldhc_a_arr, cpu_di_arr, //0xF0-0xF3
NULL, cpu_push_af_arr, cpu_imm_pc_arr, cpu_rst30_arr, //0xF4-0xF7 (0xF4=Invalid)
cpu_ld_hl_add_sp_imm_arr, cpu_sp_from_hl_arr, cpu_ld16_a_arr, cpu_ei_arr, //0xF8-0xFB
NULL, NULL, cpu_imm_pc_arr, cpu_rst38_arr, //0xFC-0xFF (0xFC=Invalid, 0xFD=Invalid)
};
typedef void (*cpu_action_t)(uint8_t*);
static cpu_action_t cpu_actions_arr[256];
static cpu_action_t cpu_action_func;
static void cpuSetupActionArr()
{
cpu_actions_arr[0x00] = cpuNoAction; cpu_actions_arr[0x01] = cpuNoAction; cpu_actions_arr[0x02] = cpuSTbc; cpu_actions_arr[0x03] = cpuBcInc;
cpu_actions_arr[0x04] = cpuInc; cpu_actions_arr[0x05] = cpuDec; cpu_actions_arr[0x06] = cpuNoAction; cpu_actions_arr[0x07] = cpuRLCA;
cpu_actions_arr[0x08] = cpuNoAction; cpu_actions_arr[0x09] = cpuNoAction; cpu_actions_arr[0x0A] = cpuLDa; cpu_actions_arr[0x0B] = cpuBcDec;
cpu_actions_arr[0x0C] = cpuInc; cpu_actions_arr[0x0D] = cpuDec; cpu_actions_arr[0x0E] = cpuNoAction; cpu_actions_arr[0x0F] = cpuRRCA;
cpu_actions_arr[0x10] = cpuSTOP; cpu_actions_arr[0x11] = cpuNoAction; cpu_actions_arr[0x12] = cpuSTde; cpu_actions_arr[0x13] = cpuDeInc;
cpu_actions_arr[0x14] = cpuInc; cpu_actions_arr[0x15] = cpuDec; cpu_actions_arr[0x16] = cpuNoAction; cpu_actions_arr[0x17] = cpuRLA;
cpu_actions_arr[0x18] = cpuNoAction; cpu_actions_arr[0x19] = cpuNoAction; cpu_actions_arr[0x1A] = cpuLDa; cpu_actions_arr[0x1B] = cpuDeDec;
cpu_actions_arr[0x1C] = cpuInc; cpu_actions_arr[0x1D] = cpuDec; cpu_actions_arr[0x1E] = cpuNoAction; cpu_actions_arr[0x1F] = cpuRRA;
cpu_actions_arr[0x20] = cpuNoAction; cpu_actions_arr[0x21] = cpuNoAction; cpu_actions_arr[0x22] = cpuSThlInc; cpu_actions_arr[0x23] = cpuHlInc;
cpu_actions_arr[0x24] = cpuInc; cpu_actions_arr[0x25] = cpuDec; cpu_actions_arr[0x26] = cpuNoAction; cpu_actions_arr[0x27] = cpuDAA;
cpu_actions_arr[0x28] = cpuNoAction; cpu_actions_arr[0x29] = cpuNoAction; cpu_actions_arr[0x2A] = cpuLDa; cpu_actions_arr[0x2B] = cpuHlDec;
cpu_actions_arr[0x2C] = cpuInc; cpu_actions_arr[0x2D] = cpuDec; cpu_actions_arr[0x2E] = cpuNoAction; cpu_actions_arr[0x2F] = cpuCPL;
cpu_actions_arr[0x30] = cpuNoAction; cpu_actions_arr[0x31] = cpuNoAction; cpu_actions_arr[0x32] = cpuSThlDec; cpu_actions_arr[0x33] = cpuSpInc;
cpu_actions_arr[0x34] = cpuInc; cpu_actions_arr[0x35] = cpuDec; cpu_actions_arr[0x36] = cpuSThl; cpu_actions_arr[0x37] = cpuNoAction;
cpu_actions_arr[0x38] = cpuNoAction; cpu_actions_arr[0x39] = cpuNoAction; cpu_actions_arr[0x3A] = cpuLDa; cpu_actions_arr[0x3B] = cpuSpDec;
cpu_actions_arr[0x3C] = cpuInc; cpu_actions_arr[0x3D] = cpuDec; cpu_actions_arr[0x3E] = cpuNoAction; cpu_actions_arr[0x3F] = cpuNoAction;
cpu_actions_arr[0x40] = cpuLDb; cpu_actions_arr[0x41] = cpuLDb; cpu_actions_arr[0x42] = cpuLDb; cpu_actions_arr[0x43] = cpuLDb;
cpu_actions_arr[0x44] = cpuLDb; cpu_actions_arr[0x45] = cpuLDb; cpu_actions_arr[0x46] = cpuLDb; cpu_actions_arr[0x47] = cpuLDb;
cpu_actions_arr[0x48] = cpuLDc; cpu_actions_arr[0x49] = cpuLDc; cpu_actions_arr[0x4A] = cpuLDc; cpu_actions_arr[0x4B] = cpuLDc;