-
Notifications
You must be signed in to change notification settings - Fork 4
/
emulator.c
3181 lines (3064 loc) · 147 KB
/
emulator.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
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "clem_types.h"
#include "emulator.h"
#include "clem_code.h"
#include "clem_debug.h"
#include "clem_util.h"
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
static uint8_t s_empty_ram[CLEM_IIGS_BANK_SIZE];
static struct ClemensOpcodeDesc sOpcodeDescriptions[256];
/*
* The Clemens Emulator
* =====================
* The Emulation Layer facilities practical I/O between a host application and
* the "internals" of the machine (CPU, FPI, MEGA2, I/O state.)
*
* "Practical I/O" comes from and is accessed by the 'Host' application. Input
* includes keyboard, mouse and gamepad events, disk images. Output includes
* video, speaker and other devices (TBD.) The emulator provides the
* controlling components for this I/O.
*
*
* Emulation
* ---------
* There are three major components executed in the emulation loop: the CPU,
* FPI and MEGA2. Wrapping these components is a 'bus controller' plus RAM and
* ROM units.
*
* The MEGA2, following the IIgs firmware/hardware references acts as a
* 'frontend' for the machine's I/O. Since Apple II uses memory mapped I/O to
* control devices, this mostly abstracts the I/O layer from the emulation
* loop.
*
* The loop performs the following:
* - execute CPU for a time slice until
* - a set number of clocks passes
* - a memory access occurs
* - ???
* - interrupts are checked per time-slice,
* - if triggered, set the CPU state accordingly
* - ???
*
* References
* ----------
* Numerous
* For the 65816, the WDC documentation and cycle counts from
* http://www.brutaldeluxe.fr/documentation/cortland/v7%2065SC816%20opcodes%20Cycle%20by%20cycle%20listing.pdf
* which were instrumental to handling the various timing quirks
*/
#define CLEM_I_PRINT_STATS(_clem_) \
do { \
struct Clemens65C816 *_cpu_ = &(_clem_)->cpu; \
uint8_t _P_ = _cpu_->regs.P; \
if (_cpu_->pins.emulation) { \
printf(ANSI_COLOR_GREEN "Clocks.... Cycles...." ANSI_COLOR_RESET \
" NV_BDIZC PC=%04X, PBR=%02X, DBR=%02X, S=%04X, D=%04X, " \
"B=%02X A=%02X, X=%02X, Y=%02X\n", \
_cpu_->regs.PC, _cpu_->regs.PBR, _cpu_->regs.DBR, _cpu_->regs.S, _cpu_->regs.D, \
(_cpu_->regs.A & 0xff00) >> 8, _cpu_->regs.A & 0x00ff, _cpu_->regs.X & 0x00ff, \
_cpu_->regs.Y & 0x00ff); \
printf(ANSI_COLOR_GREEN "%10.2f %10u" ANSI_COLOR_RESET " %c%c%c%c%c%c%c%c\n", \
(_clem_)->clocks_spent / (float)(_clem_)->clocks_step, (_cpu_)->cycles_spent, \
(_P_ & kClemensCPUStatus_Negative) ? '1' : '0', \
(_P_ & kClemensCPUStatus_Overflow) ? '1' : '0', '-', '-', \
(_P_ & kClemensCPUStatus_Decimal) ? '1' : '0', \
(_P_ & kClemensCPUStatus_IRQDisable) ? '1' : '0', \
(_P_ & kClemensCPUStatus_Zero) ? '1' : '0', \
(_P_ & kClemensCPUStatus_Carry) ? '1' : '0'); \
} else { \
printf(ANSI_COLOR_GREEN "Clocks.... Cycles...." ANSI_COLOR_RESET \
" NVMXDIZC PC=%04X, PBR=%02X, DBR=%02X, S=%04X, D=%04X, " \
"A=%04X, X=%04X, Y=%04X\n", \
_cpu_->regs.PC, _cpu_->regs.PBR, _cpu_->regs.DBR, _cpu_->regs.S, _cpu_->regs.D, \
_cpu_->regs.A, _cpu_->regs.X, _cpu_->regs.Y); \
printf(ANSI_COLOR_GREEN "%10.2f %10u" ANSI_COLOR_RESET " %c%c%c%c%c%c%c%c\n", \
(_clem_)->clocks_spent / (float)(_clem_)->clocks_step, (_cpu_)->cycles_spent, \
(_P_ & kClemensCPUStatus_Negative) ? '1' : '0', \
(_P_ & kClemensCPUStatus_Overflow) ? '1' : '0', \
(_P_ & kClemensCPUStatus_MemoryAccumulator) ? '1' : '0', \
(_P_ & kClemensCPUStatus_Index) ? '1' : '0', \
(_P_ & kClemensCPUStatus_Decimal) ? '1' : '0', \
(_P_ & kClemensCPUStatus_IRQDisable) ? '1' : '0', \
(_P_ & kClemensCPUStatus_Zero) ? '1' : '0', \
(_P_ & kClemensCPUStatus_Carry) ? '1' : '0'); \
} \
} while (0)
#if CLEM_COMPILE_DEFINE_JMP_LOGGING
#define CLEM_CPU_I_JSR_LOG(_clem_cpu_, _adr_) \
do { \
fprintf(stderr, "%02X:%04X: JSR $%04X\n", (_clem_cpu_)->regs.PBR, (_clem_cpu_)->regs.PC, \
_adr_); \
fflush(stderr); \
} while (0)
#define CLEM_CPU_I_JSL_LOG(_clem_cpu_, _adr_, _bank_) \
do { \
fprintf(stderr, "%02X:%04X: JSL $%02X%04X\n", (_clem_cpu_)->regs.PBR, \
(_clem_cpu_)->regs.PC, _bank_, _adr_); \
fflush(stderr); \
} while (0)
#define CLEM_CPU_I_RTS_LOG(_clem_cpu_, _adr_) \
do { \
fprintf(stderr, "%02X:%04X: RTS (%04X)\n", (_clem_cpu_)->regs.PBR, (_clem_cpu_)->regs.PC, \
_adr_); \
fflush(stderr); \
} while (0)
#define CLEM_CPU_I_RTL_LOG(_clem_cpu_, _adr_, _bank_) \
do { \
fprintf(stderr, "%02X:%04X: RTL (%02X%04X)\n", (_clem_cpu_)->regs.PBR, \
(_clem_cpu_)->regs.PC, _bank_, _adr_); \
fflush(stderr); \
} while (0)
#define CLEM_CPU_I_INTR_LOG(_clem_cpu_, _name_) \
do { \
fprintf(stderr, "%02X:%04X: INTR %s\n", (_clem_cpu_)->regs.PBR, (_clem_cpu_)->regs.PC, \
_name_); \
fflush(stderr); \
} while (0)
#define CLEM_CPU_I_RTI_LOG(_clem_cpu_, _adr_, _bank_) \
do { \
if ((_clem_cpu_)->pins.emulation) { \
fprintf(stderr, "%02X:%04X: RTI (%04X)\n", (_clem_cpu_)->regs.PBR, \
(_clem_cpu_)->regs.PC, _adr_); \
} else { \
fprintf(stderr, "%02X:%04X: RTI (%02X%04X)\n", (_clem_cpu_)->regs.PBR, \
(_clem_cpu_)->regs.PC, _bank_, _adr_); \
} \
fflush(stderr); \
} while (0)
#else
#define CLEM_CPU_I_JSR_LOG(_clem_cpu_, _adr_)
#define CLEM_CPU_I_JSL_LOG(_clem_cpu_, _adr_, _bank_)
#define CLEM_CPU_I_RTS_LOG(_clem_cpu_, _adr_)
#define CLEM_CPU_I_RTL_LOG(_clem_cpu_, _adr_, _bank_)
#define CLEM_CPU_I_INTR_LOG(_clem_cpu_, _name_)
#define CLEM_CPU_I_RTI_LOG(_clem_cpu_, _adr_, _bank_)
#endif
static inline void _opcode_instruction_define_mvn(struct ClemensInstruction *instr, uint8_t opcode,
uint8_t dest, uint8_t src) {
instr->desc = &sOpcodeDescriptions[opcode];
instr->opc_8 = false;
instr->value = src;
instr->bank = dest;
}
static inline void _opcode_instruction_define(struct ClemensInstruction *instr, uint8_t opcode,
uint16_t value, bool opc_8) {
instr->desc = &sOpcodeDescriptions[opcode];
instr->bank = 0x00;
instr->opc_8 = opc_8;
instr->value = value;
}
static inline void _opcode_instruction_define_simple(struct ClemensInstruction *instr,
uint8_t opcode) {
instr->desc = &sOpcodeDescriptions[opcode];
instr->opc = opcode;
instr->bank = 0x00;
instr->opc_8 = false;
instr->value = 0x0000;
}
static inline void _opcode_instruction_define_long(struct ClemensInstruction *instr, uint8_t opcode,
uint8_t bank, uint16_t addr) {
instr->desc = &sOpcodeDescriptions[opcode];
instr->bank = bank;
instr->opc_8 = false;
instr->value = addr;
}
static inline void _opcode_instruction_define_dp(struct ClemensInstruction *instr, uint8_t opcode,
uint8_t offset) {
instr->desc = &sOpcodeDescriptions[opcode];
instr->bank = 0x00;
instr->opc_8 = false;
instr->value = offset;
}
static void _opcode_description(uint8_t opcode, const char *name,
enum ClemensCPUAddrMode addr_mode) {
strncpy(sOpcodeDescriptions[opcode].name, name, 3);
sOpcodeDescriptions[opcode].name[3] = '\0';
sOpcodeDescriptions[opcode].addr_mode = addr_mode;
}
static void _opcode_print(ClemensMachine *clem, struct ClemensInstruction *inst) {
char operand[16];
operand[0] = '\0';
switch (inst->desc->addr_mode) {
case kClemensCPUAddrMode_None:
case kClemensCPUAddrMode_Count:
break;
case kClemensCPUAddrMode_Immediate:
if (inst->opc_8) {
snprintf(operand, sizeof(operand), "#$%02X", (uint8_t)inst->value);
} else {
snprintf(operand, sizeof(operand), "#$%04X", inst->value);
}
break;
case kClemensCPUAddrMode_Absolute:
snprintf(operand, sizeof(operand), "$%04X", inst->value);
break;
case kClemensCPUAddrMode_AbsoluteLong:
snprintf(operand, sizeof(operand), "$%02X%04X", inst->bank, inst->value);
break;
case kClemensCPUAddrMode_Absolute_X:
snprintf(operand, sizeof(operand), "$%04X, X", inst->value);
break;
case kClemensCPUAddrMode_Absolute_Y:
snprintf(operand, sizeof(operand), "$%04X, Y", inst->value);
break;
case kClemensCPUAddrMode_AbsoluteLong_X:
snprintf(operand, sizeof(operand), "$%02X%04X, X", inst->bank, inst->value);
break;
case kClemensCPUAddrMode_DirectPage:
snprintf(operand, sizeof(operand), "$%02X", inst->value);
break;
case kClemensCPUAddrMode_DirectPage_X:
snprintf(operand, sizeof(operand), "$%02X, X", inst->value);
break;
case kClemensCPUAddrMode_DirectPage_Y:
snprintf(operand, sizeof(operand), "$%02X, Y", inst->value);
break;
case kClemensCPUAddrMode_DirectPageIndirect:
snprintf(operand, sizeof(operand), "($%02X)", inst->value);
break;
case kClemensCPUAddrMode_DirectPageIndirectLong:
snprintf(operand, sizeof(operand), "[$%02X]", inst->value);
break;
case kClemensCPUAddrMode_DirectPage_X_Indirect:
snprintf(operand, sizeof(operand), "($%02X, X)", inst->value);
break;
case kClemensCPUAddrMode_DirectPage_Indirect_Y:
snprintf(operand, sizeof(operand), "($%02X), Y", inst->value);
break;
case kClemensCPUAddrMode_DirectPage_IndirectLong_Y:
snprintf(operand, sizeof(operand), "[$%02X], Y", inst->value);
break;
case kClemensCPUAddrMode_PCRelative:
snprintf(operand, sizeof(operand), "$%02X (%d)", inst->value, (int8_t)inst->value);
break;
case kClemensCPUAddrMode_PCRelativeLong:
snprintf(operand, sizeof(operand), "$%04X (%d)", inst->value, (int16_t)inst->value);
break;
case kClemensCPUAddrMode_PC:
snprintf(operand, sizeof(operand), "$%04X", inst->value);
break;
case kClemensCPUAddrMode_PCIndirect:
snprintf(operand, sizeof(operand), "($%04X)", inst->value);
break;
case kClemensCPUAddrMode_PCIndirect_X:
snprintf(operand, sizeof(operand), "($%04X, X)", inst->value);
break;
case kClemensCPUAddrMode_PCLong:
snprintf(operand, sizeof(operand), "$%02X%04X", inst->bank, inst->value);
break;
case kClemensCPUAddrMode_PCLongIndirect:
snprintf(operand, sizeof(operand), "[$%04X]", inst->value);
break;
case kClemensCPUAddrMode_Operand:
snprintf(operand, sizeof(operand), "%02X", inst->value);
break;
case kClemensCPUAddrMode_Stack_Relative:
snprintf(operand, sizeof(operand), "%02X, S", inst->value);
break;
case kClemensCPUAddrMode_Stack_Relative_Indirect_Y:
snprintf(operand, sizeof(operand), "(%02X, S), Y", inst->value);
break;
case kClemensCPUAddrMode_MoveBlock:
snprintf(operand, sizeof(operand), "s:%02X, d:%02X", inst->value & 0xff, inst->bank);
break;
}
if (clem->debug_flags & kClemensDebugFlag_StdoutOpcode) {
printf(ANSI_COLOR_BLUE "%02X:%04X " ANSI_COLOR_CYAN "%s" ANSI_COLOR_YELLOW
" %s" ANSI_COLOR_RESET "\n",
inst->pbr, inst->addr, inst->desc->name, operand);
}
if (clem->debug_flags & kClemensDebugFlag_DebugLogOpcode) {
char *debug_text = clem_debug_acquire_trace(32);
int debug_len = snprintf(debug_text, 32, "%2u %02X:%04X %s %s", inst->cycles_spent,
inst->pbr, inst->addr, inst->desc->name, operand);
memset(debug_text + debug_len, 0x20, 32 - debug_len);
debug_text[31] = '\n';
}
if ((clem->debug_flags & kClemensDebugFlag_OpcodeCallback) && clem->opcode_post) {
(*clem->opcode_post)(inst, operand, clem->debug_user_ptr);
}
}
void _clem_debug_memory_dump(ClemensMachine *clem, uint8_t mem_page, uint8_t mem_bank,
uint8_t page_count) {
char filename[64];
snprintf(filename, sizeof(filename), "mem_%02x_%04x_%u.bin", (uint16_t)mem_page << 8, mem_bank,
page_count);
filename[63] = '\0';
FILE *fp = fopen(filename, "wb");
if (fp) {
uint16_t mem_addr = (uint16_t)mem_page << 8;
while (page_count > 0) {
uint8_t mem_next_bank = mem_bank;
bool mega2 = false;
fwrite(_clem_get_memory_bank(clem, mem_bank, &mega2) + mem_addr, 256, 1, fp);
if (mem_addr + 0x0100 < mem_addr) {
_clem_next_dbr(clem, &mem_next_bank, mem_bank);
}
mem_addr += 0x0100;
mem_bank = mem_next_bank;
--page_count;
}
fclose(fp);
} else {
CLEM_WARN("Failed to dump memory %s", filename);
}
}
void _clem_init_instruction_map() {
_opcode_description(CLEM_OPC_ADC_IMM, "ADC", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_ADC_ABS, "ADC", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_ADC_ABSL, "ADC", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_ADC_DP, "ADC", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_ADC_DP_INDIRECT, "ADC", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_ADC_DP_INDIRECTL, "ADC",
kClemensCPUAddrMode_DirectPageIndirectLong);
_opcode_description(CLEM_OPC_ADC_ABS_IDX, "ADC", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_ADC_ABSL_IDX, "ADC", kClemensCPUAddrMode_AbsoluteLong_X);
_opcode_description(CLEM_OPC_ADC_ABS_IDY, "ADC", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_ADC_DP_IDX, "ADC", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_ADC_DP_IDX_INDIRECT, "ADC",
kClemensCPUAddrMode_DirectPage_X_Indirect);
_opcode_description(CLEM_OPC_ADC_DP_INDIRECT_IDY, "ADC",
kClemensCPUAddrMode_DirectPage_Indirect_Y);
_opcode_description(CLEM_OPC_ADC_DP_INDIRECTL_IDY, "ADC",
kClemensCPUAddrMode_DirectPage_IndirectLong_Y);
_opcode_description(CLEM_OPC_ADC_STACK_REL, "ADC", kClemensCPUAddrMode_Stack_Relative);
_opcode_description(CLEM_OPC_ADC_STACK_REL_INDIRECT_IDY, "ADC",
kClemensCPUAddrMode_Stack_Relative_Indirect_Y);
_opcode_description(CLEM_OPC_AND_IMM, "AND", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_AND_ABS, "AND", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_AND_ABSL, "AND", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_AND_DP, "AND", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_AND_DP_INDIRECT, "AND", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_AND_DP_INDIRECTL, "AND",
kClemensCPUAddrMode_DirectPageIndirectLong);
_opcode_description(CLEM_OPC_AND_ABS_IDX, "AND", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_AND_ABSL_IDX, "AND", kClemensCPUAddrMode_AbsoluteLong_X);
_opcode_description(CLEM_OPC_AND_ABS_IDY, "AND", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_AND_DP_IDX, "AND", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_AND_DP_IDX_INDIRECT, "AND",
kClemensCPUAddrMode_DirectPage_X_Indirect);
_opcode_description(CLEM_OPC_AND_DP_INDIRECT_IDY, "AND",
kClemensCPUAddrMode_DirectPage_Indirect_Y);
_opcode_description(CLEM_OPC_AND_DP_INDIRECTL_IDY, "AND",
kClemensCPUAddrMode_DirectPage_IndirectLong_Y);
_opcode_description(CLEM_OPC_AND_STACK_REL, "AND", kClemensCPUAddrMode_Stack_Relative);
_opcode_description(CLEM_OPC_AND_STACK_REL_INDIRECT_IDY, "AND",
kClemensCPUAddrMode_Stack_Relative_Indirect_Y);
_opcode_description(CLEM_OPC_ASL_A, "ASL", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_ASL_ABS, "ASL", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_ASL_DP, "ASL", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_ASL_ABS_IDX, "ASL", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_ASL_ABS_DP_IDX, "ASL", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_BCC, "BCC", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BCS, "BCS", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BEQ, "BEQ", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BIT_IMM, "BIT", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_BIT_ABS, "BIT", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_BIT_DP, "BIT", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_BIT_ABS_IDX, "BIT", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_BIT_DP_IDX, "BIT", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_BMI, "BMI", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BNE, "BNE", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BPL, "BPL", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BRA, "BRA", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BRL, "BRL", kClemensCPUAddrMode_PCRelativeLong);
_opcode_description(CLEM_OPC_BVC, "BVC", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BVS, "BVS", kClemensCPUAddrMode_PCRelative);
_opcode_description(CLEM_OPC_BRK, "BRK", kClemensCPUAddrMode_Operand);
_opcode_description(CLEM_OPC_CLC, "CLC", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_CLD, "CLD", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_CLI, "CLI", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_CLV, "CLV", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_CMP_IMM, "CMP", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_CMP_ABS, "CMP", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_CMP_ABSL, "CMP", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_CMP_DP, "CMP", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_CMP_DP_INDIRECT, "CMP", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_CMP_DP_INDIRECTL, "CMP",
kClemensCPUAddrMode_DirectPageIndirectLong);
_opcode_description(CLEM_OPC_CMP_ABS_IDX, "CMP", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_CMP_ABSL_IDX, "CMP", kClemensCPUAddrMode_AbsoluteLong_X);
_opcode_description(CLEM_OPC_CMP_ABS_IDY, "CMP", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_CMP_DP_IDX, "CMP", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_CMP_DP_IDX_INDIRECT, "CMP",
kClemensCPUAddrMode_DirectPage_X_Indirect);
_opcode_description(CLEM_OPC_CMP_DP_INDIRECT_IDY, "CMP",
kClemensCPUAddrMode_DirectPage_Indirect_Y);
_opcode_description(CLEM_OPC_CMP_DP_INDIRECTL_IDY, "CMP",
kClemensCPUAddrMode_DirectPage_IndirectLong_Y);
_opcode_description(CLEM_OPC_CMP_STACK_REL, "CMP", kClemensCPUAddrMode_Stack_Relative);
_opcode_description(CLEM_OPC_CMP_STACK_REL_INDIRECT_IDY, "CMP",
kClemensCPUAddrMode_Stack_Relative_Indirect_Y);
_opcode_description(CLEM_OPC_COP, "COP", kClemensCPUAddrMode_Operand);
_opcode_description(CLEM_OPC_CPX_IMM, "CPX", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_CPX_ABS, "CPX", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_CPX_DP, "CPX", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_CPY_IMM, "CPY", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_CPY_ABS, "CPY", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_CPY_DP, "CPY", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_DEC_A, "DEC", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_DEC_ABS, "DEC", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_DEC_DP, "DEC", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_DEC_ABS_IDX, "DEC", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_DEC_ABS_DP_IDX, "DEC", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_DEX, "DEX", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_DEY, "DEY", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_EOR_IMM, "EOR", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_EOR_ABS, "EOR", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_EOR_ABSL, "EOR", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_EOR_DP, "EOR", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_EOR_DP_INDIRECT, "EOR", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_EOR_DP_INDIRECTL, "EOR",
kClemensCPUAddrMode_DirectPageIndirectLong);
_opcode_description(CLEM_OPC_EOR_ABS_IDX, "EOR", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_EOR_ABSL_IDX, "EOR", kClemensCPUAddrMode_AbsoluteLong_X);
_opcode_description(CLEM_OPC_EOR_ABS_IDY, "EOR", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_EOR_DP_IDX, "EOR", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_EOR_DP_IDX_INDIRECT, "EOR",
kClemensCPUAddrMode_DirectPage_X_Indirect);
_opcode_description(CLEM_OPC_EOR_DP_INDIRECT_IDY, "EOR",
kClemensCPUAddrMode_DirectPage_Indirect_Y);
_opcode_description(CLEM_OPC_EOR_DP_INDIRECTL_IDY, "EOR",
kClemensCPUAddrMode_DirectPage_IndirectLong_Y);
_opcode_description(CLEM_OPC_EOR_STACK_REL, "EOR", kClemensCPUAddrMode_Stack_Relative);
_opcode_description(CLEM_OPC_EOR_STACK_REL_INDIRECT_IDY, "EOR",
kClemensCPUAddrMode_Stack_Relative_Indirect_Y);
_opcode_description(CLEM_OPC_INC_A, "INC", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_INC_ABS, "INC", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_INC_DP, "INC", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_INC_ABS_IDX, "INC", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_INC_ABS_DP_IDX, "INC", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_INX, "INX", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_INY, "INY", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_JMP_ABS, "JMP", kClemensCPUAddrMode_PC);
_opcode_description(CLEM_OPC_JMP_INDIRECT, "JMP", kClemensCPUAddrMode_PCIndirect);
_opcode_description(CLEM_OPC_JMP_INDIRECT_IDX, "JMP", kClemensCPUAddrMode_PCIndirect_X);
_opcode_description(CLEM_OPC_JMP_ABSL, "JML", kClemensCPUAddrMode_PCLong);
_opcode_description(CLEM_OPC_JMP_ABSL_INDIRECT, "JML", kClemensCPUAddrMode_PCLongIndirect);
_opcode_description(CLEM_OPC_JSL, "JSL", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_JSR, "JSR", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_JSR_INDIRECT_IDX, "JSR", kClemensCPUAddrMode_PCIndirect_X);
_opcode_description(CLEM_OPC_LDA_IMM, "LDA", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_LDA_ABS, "LDA", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_LDA_ABSL, "LDA", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_LDA_DP, "LDA", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_LDA_DP_INDIRECT, "LDA", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_LDA_DP_INDIRECTL, "LDA",
kClemensCPUAddrMode_DirectPageIndirectLong);
_opcode_description(CLEM_OPC_LDA_ABS_IDX, "LDA", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_LDA_ABSL_IDX, "LDA", kClemensCPUAddrMode_AbsoluteLong_X);
_opcode_description(CLEM_OPC_LDA_ABS_IDY, "LDA", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_LDA_DP_IDX, "LDA", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_LDA_DP_IDX_INDIRECT, "LDA",
kClemensCPUAddrMode_DirectPage_X_Indirect);
_opcode_description(CLEM_OPC_LDA_DP_INDIRECT_IDY, "LDA",
kClemensCPUAddrMode_DirectPage_Indirect_Y);
_opcode_description(CLEM_OPC_LDA_DP_INDIRECTL_IDY, "LDA",
kClemensCPUAddrMode_DirectPage_IndirectLong_Y);
_opcode_description(CLEM_OPC_LDA_STACK_REL, "LDA", kClemensCPUAddrMode_Stack_Relative);
_opcode_description(CLEM_OPC_LDA_STACK_REL_INDIRECT_IDY, "LDA",
kClemensCPUAddrMode_Stack_Relative_Indirect_Y);
_opcode_description(CLEM_OPC_LDX_IMM, "LDX", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_LDX_ABS, "LDX", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_LDX_DP, "LDX", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_LDX_ABS_IDY, "LDX", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_LDX_DP_IDY, "LDX", kClemensCPUAddrMode_DirectPage_Y);
_opcode_description(CLEM_OPC_LDY_IMM, "LDY", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_LDY_ABS, "LDY", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_LDY_DP, "LDY", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_LDY_ABS_IDX, "LDY", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_LDY_DP_IDX, "LDY", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_LSR_A, "LSR", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_LSR_ABS, "LSR", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_LSR_DP, "LSR", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_LSR_ABS_IDX, "LSR", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_LSR_ABS_DP_IDX, "LSR", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_MVN, "MVN", kClemensCPUAddrMode_MoveBlock);
_opcode_description(CLEM_OPC_MVP, "MVP", kClemensCPUAddrMode_MoveBlock);
_opcode_description(CLEM_OPC_NOP, "NOP", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_ORA_IMM, "ORA", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_ORA_ABS, "ORA", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_ORA_ABSL, "ORA", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_ORA_DP, "ORA", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_ORA_DP_INDIRECT, "ORA", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_ORA_DP_INDIRECTL, "ORA",
kClemensCPUAddrMode_DirectPageIndirectLong);
_opcode_description(CLEM_OPC_ORA_ABS_IDX, "ORA", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_ORA_ABSL_IDX, "ORA", kClemensCPUAddrMode_AbsoluteLong_X);
_opcode_description(CLEM_OPC_ORA_ABS_IDY, "ORA", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_ORA_DP_IDX, "ORA", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_ORA_DP_IDX_INDIRECT, "ORA",
kClemensCPUAddrMode_DirectPage_X_Indirect);
_opcode_description(CLEM_OPC_ORA_DP_INDIRECT_IDY, "ORA",
kClemensCPUAddrMode_DirectPage_Indirect_Y);
_opcode_description(CLEM_OPC_ORA_DP_INDIRECTL_IDY, "ORA",
kClemensCPUAddrMode_DirectPage_IndirectLong_Y);
_opcode_description(CLEM_OPC_ORA_STACK_REL, "ORA", kClemensCPUAddrMode_Stack_Relative);
_opcode_description(CLEM_OPC_ORA_STACK_REL_INDIRECT_IDY, "ORA",
kClemensCPUAddrMode_Stack_Relative_Indirect_Y);
_opcode_description(CLEM_OPC_PEA_ABS, "PEA", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_PEI_DP_INDIRECT, "PEI", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_PER, "PER", kClemensCPUAddrMode_PCRelativeLong);
_opcode_description(CLEM_OPC_PHA, "PHA", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PHB, "PHB", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PHD, "PHD", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PHK, "PHK", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PHP, "PHP", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PHX, "PHX", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PHY, "PHY", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PLA, "PLA", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PLB, "PLB", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PLD, "PLD", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PLP, "PLP", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PLX, "PLX", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_PLY, "PLY", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_REP, "REP", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_ROL_A, "ROL", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_ROL_ABS, "ROL", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_ROL_DP, "ROL", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_ROL_ABS_IDX, "ROL", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_ROL_ABS_DP_IDX, "ROL", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_ROR_A, "ROR", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_ROR_ABS, "ROR", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_ROR_DP, "ROR", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_ROR_ABS_IDX, "ROR", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_ROR_ABS_DP_IDX, "ROR", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_RTI, "RTI", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_RTL, "RTL", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_RTS, "RTS", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_SBC_IMM, "SBC", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_SBC_ABS, "SBC", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_SBC_ABSL, "SBC", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_SBC_DP, "SBC", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_SBC_DP_INDIRECT, "SBC", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_SBC_DP_INDIRECTL, "SBC",
kClemensCPUAddrMode_DirectPageIndirectLong);
_opcode_description(CLEM_OPC_SBC_ABS_IDX, "SBC", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_SBC_ABSL_IDX, "SBC", kClemensCPUAddrMode_AbsoluteLong_X);
_opcode_description(CLEM_OPC_SBC_ABS_IDY, "SBC", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_SBC_DP_IDX, "SBC", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_SBC_DP_IDX_INDIRECT, "SBC",
kClemensCPUAddrMode_DirectPage_X_Indirect);
_opcode_description(CLEM_OPC_SBC_DP_INDIRECT_IDY, "SBC",
kClemensCPUAddrMode_DirectPage_Indirect_Y);
_opcode_description(CLEM_OPC_SBC_DP_INDIRECTL_IDY, "SBC",
kClemensCPUAddrMode_DirectPage_IndirectLong_Y);
_opcode_description(CLEM_OPC_SBC_STACK_REL, "SBC", kClemensCPUAddrMode_Stack_Relative);
_opcode_description(CLEM_OPC_SBC_STACK_REL_INDIRECT_IDY, "SBC",
kClemensCPUAddrMode_Stack_Relative_Indirect_Y);
_opcode_description(CLEM_OPC_SEC, "SEC", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_SED, "SED", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_SEI, "SEI", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_SEP, "SEP", kClemensCPUAddrMode_Immediate);
_opcode_description(CLEM_OPC_STA_ABS, "STA", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_STA_ABSL, "STA", kClemensCPUAddrMode_AbsoluteLong);
_opcode_description(CLEM_OPC_STA_DP, "STA", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_STA_DP_INDIRECT, "STA", kClemensCPUAddrMode_DirectPageIndirect);
_opcode_description(CLEM_OPC_STA_DP_INDIRECTL, "STA",
kClemensCPUAddrMode_DirectPageIndirectLong);
_opcode_description(CLEM_OPC_STA_ABS_IDX, "STA", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_STA_ABSL_IDX, "STA", kClemensCPUAddrMode_AbsoluteLong_X);
_opcode_description(CLEM_OPC_STA_ABS_IDY, "STA", kClemensCPUAddrMode_Absolute_Y);
_opcode_description(CLEM_OPC_STA_DP_IDX, "STA", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_STA_DP_IDX_INDIRECT, "STA",
kClemensCPUAddrMode_DirectPage_X_Indirect);
_opcode_description(CLEM_OPC_STA_DP_INDIRECT_IDY, "STA",
kClemensCPUAddrMode_DirectPage_Indirect_Y);
_opcode_description(CLEM_OPC_STA_DP_INDIRECTL_IDY, "STA",
kClemensCPUAddrMode_DirectPage_IndirectLong_Y);
_opcode_description(CLEM_OPC_STA_STACK_REL, "STA", kClemensCPUAddrMode_Stack_Relative);
_opcode_description(CLEM_OPC_STA_STACK_REL_INDIRECT_IDY, "STA",
kClemensCPUAddrMode_Stack_Relative_Indirect_Y);
_opcode_description(CLEM_OPC_STP, "STP", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_STX_ABS, "STX", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_STX_DP, "STX", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_STX_DP_IDY, "STX", kClemensCPUAddrMode_DirectPage_Y);
_opcode_description(CLEM_OPC_STY_ABS, "STY", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_STY_DP, "STY", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_STY_DP_IDX, "STY", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_STZ_ABS, "STZ", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_STZ_DP, "STZ", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_STZ_ABS_IDX, "STZ", kClemensCPUAddrMode_Absolute_X);
_opcode_description(CLEM_OPC_STZ_DP_IDX, "STZ", kClemensCPUAddrMode_DirectPage_X);
_opcode_description(CLEM_OPC_TRB_ABS, "TRB", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_TRB_DP, "TRB", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_TSB_ABS, "TSB", kClemensCPUAddrMode_Absolute);
_opcode_description(CLEM_OPC_TSB_DP, "TSB", kClemensCPUAddrMode_DirectPage);
_opcode_description(CLEM_OPC_TAX, "TAX", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TAY, "TAY", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TCD, "TCD", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TDC, "TDC", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TCS, "TCS", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TSC, "TSC", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TSX, "TSX", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TXA, "TXA", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TXS, "TXS", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TXY, "TXY", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TYA, "TYA", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_TYX, "TYX", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_WAI, "WAI", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_WDM, "WDM", kClemensCPUAddrMode_Operand);
_opcode_description(CLEM_OPC_XBA, "XBA", kClemensCPUAddrMode_None);
_opcode_description(CLEM_OPC_XCE, "XCE", kClemensCPUAddrMode_None);
}
bool clemens_is_initialized_simple(const ClemensMachine *machine) {
return (machine->mem.fpi_bank_map[0] != NULL);
}
bool clemens_is_initialized(const ClemensMachine *machine) {
if (!clemens_is_initialized_simple(machine)) {
return false;
}
if (!machine->mem.fpi_bank_map[1]) {
return false;
}
if (!machine->tspec.clocks_step) {
return false;
}
return true;
}
bool clemens_is_resetting(const ClemensMachine *clem) {
return (!clem->cpu.pins.resbIn) || clem->cpu.state_type == kClemensCPUStateType_Reset;
}
void clemens_host_setup(ClemensMachine *clem, ClemensLoggerFn logger, void *debug_user_ptr) {
clem->logger_fn = logger;
clem->debug_user_ptr = debug_user_ptr;
// TODO: remove this once the debug context singleton limitation is removed
// (see clem_debug.c)
clemens_debug_context(clem);
}
void clemens_opcode_callback(ClemensMachine *clem, ClemensOpcodeCallback callback) {
if (callback) {
clem->debug_flags |= kClemensDebugFlag_OpcodeCallback;
} else {
clem->debug_flags &= ~kClemensDebugFlag_OpcodeCallback;
}
clem->opcode_post = callback;
}
void clemens_create_page_mapping(struct ClemensMemoryPageInfo *page, uint8_t page_idx,
uint8_t bank_read_idx, uint8_t bank_write_idx) {
clem_mem_create_page_mapping(page, page_idx, bank_read_idx, bank_write_idx);
}
int clemens_init(ClemensMachine *machine, uint32_t speed_factor, uint32_t clocks_step, void *rom,
unsigned int fpi_rom_bank_count, void *e0bank, void *e1bank, void *fpiRAM,
unsigned int fpi_ram_bank_count) {
unsigned idx, rom_bank_idx;
clemens_simple_init(machine, speed_factor, clocks_step, fpiRAM, fpi_ram_bank_count);
if (rom == NULL) {
return -1;
}
if (fpi_ram_bank_count < 2 || fpiRAM == NULL || e0bank == NULL || e1bank == NULL) {
return -2;
}
/* memory organization for the FPI */
/* TODO: Support ROM 01 */
rom_bank_idx = 0x100 - fpi_rom_bank_count;
for (idx = rom_bank_idx; idx < 0x100; ++idx) {
machine->mem.fpi_bank_used[idx] = true;
machine->mem.fpi_bank_map[idx] =
(uint8_t *)rom + CLEM_IIGS_BANK_SIZE * (idx - rom_bank_idx);
}
/* TODO: remap non used banks to used banks per the wrapping mechanism on
the IIgs
*/
machine->mem.fpi_bank_map[CLEM_IIGS_EMPTY_RAM_BANK] = s_empty_ram;
machine->mem.fpi_bank_used[CLEM_IIGS_EMPTY_RAM_BANK] = true;
machine->mem.mega2_bank_map[0x00] = (uint8_t *)e0bank;
memset(machine->mem.mega2_bank_map[0x00], 0, CLEM_IIGS_BANK_SIZE);
machine->mem.mega2_bank_map[0x01] = (uint8_t *)e1bank;
memset(machine->mem.mega2_bank_map[0x01], 0, CLEM_IIGS_BANK_SIZE);
return 0;
}
void clemens_simple_init(ClemensMachine *machine, uint32_t speed_factor, uint32_t clocks_step,
void *fpiRAM, unsigned int fpi_ram_bank_count) {
machine->cpu.pins.resbIn = true;
machine->cpu.pins.irqbIn = true;
_clem_timespec_init(&machine->tspec, clocks_step);
if (fpi_ram_bank_count > 256)
fpi_ram_bank_count = 256;
for (unsigned i = 0; i < fpi_ram_bank_count; ++i) {
machine->mem.fpi_bank_used[i] = true;
machine->mem.fpi_bank_map[i] = ((uint8_t *)fpiRAM) + (i * CLEM_IIGS_BANK_SIZE);
memset(machine->mem.fpi_bank_map[i], 0, CLEM_IIGS_BANK_SIZE);
}
/* all non mapped FPI banks will map to empty memory until overridden by
application or the full IIgs emulator initializtion function
(clemens_init)
*/
memset(s_empty_ram, 0, CLEM_IIGS_BANK_SIZE);
for (unsigned i = fpi_ram_bank_count; i < 0xff; ++i) {
machine->mem.fpi_bank_used[i] = false;
machine->mem.fpi_bank_map[i] = s_empty_ram;
}
memset(&machine->mem.bank_page_map, 0, sizeof(machine->mem.bank_page_map));
}
void clemens_register() {
/* internal tables used to define opcode attributes */
for (unsigned i = 0; i < 256; ++i) {
_opcode_description((uint8_t)i, "...", kClemensCPUAddrMode_None);
}
_clem_init_instruction_map();
}
void clemens_debug_context(ClemensMachine *clem) { clem_debug_context(clem); }
#define CLEM_LOAD_HEX_STATE_BEGIN '\0'
#define CLEM_LOAD_HEX_STATE_ERROR -1
#define CLEM_LOAD_HEX_STATE_CR '\r'
#define CLEM_LOAD_HEX_STATE_LENGTH ':'
#define CLEM_LOAD_HEX_STATE_ADR16 'a'
#define CLEM_LOAD_HEX_STATE_RECORD 'R'
#define CLEM_LOAD_HEX_STATE_DATA 'd'
#define CLEM_LOAD_HEX_STATE_CHKSUM '+'
#define CLEM_LOAD_HEX_STATE_EOL '.'
#define CLEM_LOAD_HEX_STATE_EOF '!'
#define CLEM_LOAD_HEX_RECORD_DATA 0x00
#define CLEM_LOAD_HEX_RECORD_EOF 0x01
#define CLEM_LOAD_HEX_RECORD_NONE 0xFF
bool clemens_load_hex(ClemensMachine *clem, const char *hex, const char *hex_end, unsigned bank) {
const char *line = hex;
const char *next = line;
unsigned token_len = 0;
char state = CLEM_LOAD_HEX_STATE_BEGIN;
uint8_t *clem_memory = NULL;
unsigned hex_byte_length = 0;
unsigned hex_address16 = 0;
unsigned hex_recordtype = CLEM_LOAD_HEX_RECORD_NONE;
unsigned tmp;
unsigned data;
uint8_t chksum = 0;
while ((hex_end && line < hex_end) || *line) {
char cur_state = state;
if (state == CLEM_LOAD_HEX_STATE_EOF) {
break;
}
token_len = (unsigned)(next - line);
switch (cur_state) {
case CLEM_LOAD_HEX_STATE_ERROR:
return false;
case CLEM_LOAD_HEX_STATE_CR:
if (*next == '\n')
state = CLEM_LOAD_HEX_STATE_BEGIN;
else
state = CLEM_LOAD_HEX_STATE_ERROR;
break;
case CLEM_LOAD_HEX_STATE_BEGIN:
if (*next == ':')
state = CLEM_LOAD_HEX_STATE_LENGTH;
else if (isspace(*next))
state = CLEM_LOAD_HEX_STATE_BEGIN;
else
state = CLEM_LOAD_HEX_STATE_ERROR;
break;
case CLEM_LOAD_HEX_STATE_LENGTH:
if (token_len == 2) {
hex_byte_length = 0;
if (!_clem_util_hex_value(&hex_byte_length, line, next)) {
state = CLEM_LOAD_HEX_STATE_ERROR;
} else {
chksum = (uint8_t)(hex_byte_length & 0xff);
clem_memory = clem->mem.fpi_bank_map[bank];
if (clem_memory) {
state = CLEM_LOAD_HEX_STATE_ADR16;
--next; /* backtrack since there's no delim */
} else {
state = CLEM_LOAD_HEX_STATE_ERROR;
}
}
}
break;
case CLEM_LOAD_HEX_STATE_ADR16:
if (token_len == 4) {
if (_clem_util_hex_value(&tmp, line, next)) {
hex_address16 = (tmp & 0xffff);
chksum += (uint8_t)((hex_address16 >> 8) & 0xff);
chksum += (uint8_t)(hex_address16 & 0xff);
state = CLEM_LOAD_HEX_STATE_RECORD;
--next; /* backtrack since there's no delim */
} else {
state = CLEM_LOAD_HEX_STATE_ERROR;
}
}
break;
case CLEM_LOAD_HEX_STATE_RECORD:
if (token_len == 2) {
if (!_clem_util_hex_value(&hex_recordtype, line, next)) {
state = CLEM_LOAD_HEX_STATE_ERROR;
} else {
hex_recordtype &= 0xff;
chksum += (uint8_t)(hex_recordtype);
if (hex_recordtype == CLEM_LOAD_HEX_RECORD_DATA) {
state = CLEM_LOAD_HEX_STATE_DATA;
--next; /* backtrack since there's no delim */
} else if (hex_recordtype == CLEM_LOAD_HEX_RECORD_EOF) {
state = CLEM_LOAD_HEX_STATE_CHKSUM;
--next; /* backtrack since there's no delim */
} else {
/* TODO: support more record types */
state = CLEM_LOAD_HEX_STATE_ERROR;
}
}
}
break;
case CLEM_LOAD_HEX_STATE_DATA:
/* hex data */
tmp = token_len / 2;
if (!(token_len % 2) && tmp > 0) {
--tmp;
if (_clem_util_hex_value(&data, line + tmp * 2, next)) {
chksum += (uint8_t)(data & 0xff);
clem_memory[(hex_address16 + tmp) & 0xffff] = ((uint8_t)(data & 0xff));
} else {
state = CLEM_LOAD_HEX_STATE_ERROR;
}
if (tmp + 1 >= hex_byte_length) {
state = CLEM_LOAD_HEX_STATE_CHKSUM;
--next; /* backtrack since there's no delim */
}
}
break;
case CLEM_LOAD_HEX_STATE_CHKSUM:
if (token_len == 2) {
chksum = 0x01 + (~chksum);
if (_clem_util_hex_value(&tmp, line, next) && chksum == (tmp & 0xff)) {
if (hex_recordtype == CLEM_LOAD_HEX_RECORD_EOF) {
state = CLEM_LOAD_HEX_STATE_EOF;
} else {
state = CLEM_LOAD_HEX_STATE_EOL;
}
} else {
state = CLEM_LOAD_HEX_STATE_ERROR;
}
}
break;
case CLEM_LOAD_HEX_STATE_EOL:
/* ignores the remainder until we hit a newline, which is
handled at the start of this loop
*/
if (*next == '\r')
state = CLEM_LOAD_HEX_STATE_CR;
else if (*next == '\n')
state = CLEM_LOAD_HEX_STATE_BEGIN;
break;
}
if (!(*next)) {
line = next;
} else {
++next;
if (state != cur_state) {
line = next;
}
}
}
return true;
}
unsigned clemens_out_hex_data_from_memory(char *hex, const uint8_t *memory,
unsigned out_hex_byte_limit, unsigned adr) {
unsigned byte_amt = out_hex_byte_limit >> 1; /* 2 digits per byte */
unsigned byte_idx;
unsigned chksum = 0;
if (!byte_amt)
return UINT_MAX;
/* intel hex has a limit of 255 per line - and callers should be aware of
this.
*/
if (byte_amt > 256)
return UINT_MAX;
for (byte_idx = 0; byte_idx < byte_amt; ++byte_idx) {
uint8_t byte = memory[(adr + byte_idx) & 0xffff];
hex[byte_idx * 2] = g_decimal_to_hex[(byte & 0xf0) >> 4];
hex[byte_idx * 2 + 1] = g_decimal_to_hex[(byte & 0x0f)];
chksum += byte;
}
hex[byte_idx * 2] = '\0';
return chksum;
}
unsigned clemens_out_hex_data_body(const ClemensMachine *clem, char *hex,
unsigned out_hex_byte_limit, unsigned bank, unsigned adr) {
const uint8_t *memory;
if (bank == 0xe0 || bank == 0xe1) {
memory = clem->mem.mega2_bank_map[bank & 0x1];
} else {
memory = clem->mem.fpi_bank_map[bank & 0xff];
}
return clemens_out_hex_data_from_memory(hex, memory, out_hex_byte_limit, adr);
}
void clemens_out_bin_data(const ClemensMachine *clem, uint8_t *out, unsigned out_byte_cnt,
uint8_t bank, uint16_t adr) {
const uint8_t *memory;
unsigned left0, right0;
if (bank == 0xe0 || bank == 0xe1) {
memory = clem->mem.mega2_bank_map[bank & 0x1];
} else {
memory = clem->mem.fpi_bank_map[bank & 0xff];
}
if (out_byte_cnt > 0x10000) {
out_byte_cnt = 0x10000; /* one bank maximum byte copy */
}
/* extreme edge case, but the API allows this - wraparound */
left0 = adr;
right0 = (unsigned)adr + out_byte_cnt;