-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEmulator.cs
1321 lines (1260 loc) · 45 KB
/
Emulator.cs
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
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Timers;
using System.ComponentModel;
using System.Collections.ObjectModel;
namespace Emulator
{
[System.Serializable]
public class InterpreterInvalidRegisterException : System.Exception
{
public InterpreterInvalidRegisterException() { }
public InterpreterInvalidRegisterException(string message) : base(message) { }
public InterpreterInvalidRegisterException(string message, System.Exception inner) : base(message, inner) { }
protected InterpreterInvalidRegisterException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context) : base(info, context) { }
}
public class Emulator : INotifyPropertyChanged
{
private static List<string> _registerNames = new List<string> { "b", "c", "d", "e", "h", "l", "m", "a" };
public delegate void OutPortValueChangedEventHandler(int port, byte value);
public delegate void InPortReadEventHandler(int port);
public delegate void InputResetRequestedEventHandler();
public event OutPortValueChangedEventHandler? OnOutPortValueChanged;
public event PropertyChangedEventHandler? PropertyChanged;
public event InPortReadEventHandler? OnInPortRead;
public event InputResetRequestedEventHandler? OnInputResetRequested;
private Timer _timer;
/// <summary>
/// Program counter value of the processor, tells which operation is executed<para/>
/// Only exists as a representation since _operationCounter is the actual value used for picking operations
/// </summary>
private int _programCounter = 0;
private Registers _registers;
private ProcessorFlags _flags;
public ProcessorFlags Flags => _flags;
public Registers Registers => _registers;
private Memory _memory;
public Memory Memory { get => _memory; set => _memory = value; }
private byte[] _outputPorts = new byte[16];
private byte[] _inputPorts = new byte[16];
public byte[] OutputPorts => _outputPorts;
/// <summary>
/// List of all available jump destinations
/// </summary>
public Dictionary<string, int> _jumpDestinations = new Dictionary<string, int>();
private int _stepsBeforeSleep = 1;
private int _currentStepCounter = 0;
public int StepsBeforeSleep => _stepsBeforeSleep;
public int CurrentStepCounter => _currentStepCounter;
public bool IsRunning { get; set; } = true;
/// <summary>
/// Helper function that returns value stored in the register<para/>
/// If name is invalid InterpreterInvalidRegisterException is thrown
/// </summary>
/// <param name="name">Name of the register</param>
/// <returns></returns>
public byte GetRegisterValue(string name)
{
name = name.ToLower();
switch (name)
{
case "a":
return _registers.A;
case "b":
return _registers.B;
case "c":
return _registers.C;
case "d":
return _registers.D;
case "e":
return _registers.E;
case "h":
return _registers.H;
case "l":
return _registers.L;
// M register is a special case, as it is not in fact a register, but rather a memory cell at HL
case "m":
{
ushort address = (ushort)(((int)Registers.H << 8) | (int)Registers.L);
return Memory[address];
}
default:
throw new InterpreterInvalidRegisterException($"Register {name} is not part of the processor");
}
}
/// <summary>
/// Helper function that sets value stored in the register<para/>
/// If name is invalid InterpreterInvalidRegisterException is thrown
/// </summary>
/// <param name="name">Name of the register</param>
/// <param name="value">Value that will be assigned</param>
/// <returns></returns>
public void SetRegisterValue(string name, byte value)
{
name = name.ToLower();
switch (name)
{
case "a":
_registers.A = value;
break;
case "b":
_registers.B = value;
break;
case "c":
_registers.C = value;
break;
case "d":
_registers.D = value;
break;
case "e":
_registers.E = value;
break;
case "h":
_registers.H = value;
break;
case "l":
_registers.L = value;
break;
// M register is a special case, as it is not in fact a register, but rather a memory cell at HL
case "m":
{
ushort address = (ushort)(((int)Registers.H << 8) | (int)Registers.L);
Memory[address] = value;
}
break;
default:
throw new InterpreterInvalidRegisterException($"Register {name} is not part of the processor");
}
}
public void SetCode(ProcessedCodeInfo code)
{
_jumpDestinations = code.JumpDestinations;
_memory.WriteRom(code.CommandBytes.ToArray());
}
/// <summary>
/// Pushes value stored in the pair of registers advancing the stack pointer
/// </summary>
/// <param name="pairName"></param>
public void PushStack(string pairName)
{
byte h = 0;
byte l = 0;
switch (pairName.ToLower())
{
case "b":
h = Registers.B;
l = Registers.C;
break;
case "d":
h = Registers.D;
l = Registers.E;
break;
case "h":
h = Registers.H;
l = Registers.L;
break;
}
ushort sp = _memory.StackPointer;
_memory[sp] = h;
_memory[(ushort)(sp - 1)] = l;
sp -= 2;
_memory.StackPointer = sp;
}
/// <summary>
/// Pushes value onto the stack
/// </summary>
public void PushStack(ushort value)
{
ushort sp = _memory.StackPointer;
_memory[sp] = (byte)((value & 0xFF00) >> 8);
_memory[(ushort)(sp - 1)] = (byte)(value & 0x00FF);
sp -= 2;
_memory.StackPointer = sp;
}
public void PopStack(string destinationPairName)
{
ushort sp = _memory.StackPointer;
byte h = _memory[(ushort)(sp + 2)];
byte l = _memory[(ushort)(sp + 1)];
switch (destinationPairName)
{
case "b":
Registers.B = h;
Registers.C = l;
break;
case "d":
Registers.D = h;
Registers.E = l;
break;
case "h":
Registers.H = h;
Registers.L = l;
break;
}
sp += 2;
_memory.StackPointer = sp;
}
public ushort PopStack()
{
ushort sp = _memory.StackPointer;
byte h = _memory[(ushort)(sp + 2)];
byte l = _memory[(ushort)(sp + 1)];
sp += 2;
_memory.StackPointer = sp;
return (ushort)((h << 8) | l);
}
public Emulator()
{
_registers = new Registers();
_flags = new ProcessorFlags();
//TODO: uncomment to get access to full 64kb
//_memory = new Memory(0, ushort.MaxValue, 0);
_memory = new Memory();
_timer = new Timer(100);
_timer.Enabled = false;
_timer.Elapsed += _onTimerTimeout;
_memory.OnOutPortValueChanged += _onOutPortValueChanged;
}
/// <summary>
/// Set value of the object that mimics out port
/// </summary>
/// <param name="port">Port id</param>
/// <param name="value"></param>
public void SetOut(int port, byte value)
{
//because ports are meant to be dynamic this technically does write to that port
//there is just
//no output for it
if (port >= _outputPorts.Length || port < 0)
{
return;
}
_outputPorts[port] = value;
OnOutPortValueChanged?.Invoke(port, value);
}
/// <summary>
/// Set value of the object that mimics in port
/// </summary>
/// <param name="port">Port id</param>
/// <param name="value"></param>
public void SetIn(int port, byte value)
{
if (port >= _inputPorts.Length || port < 0)
{
return;
}
_memory[(ushort)(port + _memory.MemoryData.InOutPortsStartLocation)] = value;
_inputPorts[port] = value;
}
public void JumpTo(string destination)
{
ProgramCounter = _jumpDestinations[destination];
}
public int ProgramCounter
{
get => _programCounter;
set
{
_programCounter = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("ProgramCounter"));
}
}
/// <summary>
/// Checks parity of the number by check if the amount of 1s in the number is even <para/>
/// I have no idea what is the parity for, but original processor had it so why not
/// </summary>
/// <param name="val"></param>
/// <returns></returns>
public bool Parity(ushort val)
{
int count = 0;
for (int i = 0; i < 8; i++)
{
count += val & 1;
val >>= 1;
}
return (count % 2) == 0;
}
/// <summary>
/// Updates flags based on the value
/// </summary>
public void CheckFlags(ushort value)
{
//everything except carry works on one cell sized value
ushort clean = (ushort)(value & 0xff);
_flags.S = 0x80 == (clean & 0x80);//just check if the sign bit is true
_flags.Z = clean == 0;
_flags.Ac = clean > 0x09;
_flags.P = Parity(clean);
_flags.C = value > 0xff;
}
public void CheckFlagsArith(ushort value)
{
Flags.Z = (value & 0x00FF) == 0;
Flags.S = (value & 0x80) == 0x80;
Flags.P = Parity((ushort)(value & 0x00FF));
Flags.Ac = value > 0x09;
}
/// <summary>
/// Set group of flags, intended for cmp operation
/// </summary>
/// <param name="z"></param>
/// <param name="s"></param>
/// <param name="p"></param>
/// <param name="cy"></param>
public void SetFlags(bool z, bool s, bool p, bool c)
{
_flags.Z = z;
_flags.S = s;
_flags.P = p;
_flags.C = c;
}
/// <summary>
/// Function that selects which register's value to use for _or
/// </summary>
private bool _ora(byte op)
{
if (op < 0xb0 || op > 0xb7)
{
return false;
}
int id = op - 0xb0;
_or(GetRegisterValue(_registerNames[id]));
_programCounter++;
return true;
}
/// <summary>
/// Function that selects which register's value to use for _and
/// </summary>
private bool _ana(byte op)
{
if (op < 0xa0 || op > 0xa7)
{
return false;
}
int id = op - 0xa0;
_and(GetRegisterValue(_registerNames[id]));
_programCounter++;
return true;
}
/// <summary>
/// Function that selects which register's value to use for _xor
/// </summary>
private bool _xra(byte op)
{
if (op < 0xa8 || op > 0xaf)
{
return false;
}
int id = op - 0xa8;
_xor(GetRegisterValue(_registerNames[id]));
_programCounter++;
return true;
}
private void _or(byte value)
{
ushort result = (ushort)(Registers.A | value);
CheckFlags(result);
Flags.C = false;
Flags.Ac = false;
Registers.A = (byte)(result & 0x00FF);
}
private void _and(byte value)
{
ushort result = (ushort)(Registers.A & value);
CheckFlags(result);
Flags.C = false;
Flags.Ac = false;
Registers.A = (byte)(result & 0x00FF);
}
private void _xor(byte value)
{
ushort result = (ushort)(Registers.A ^ value);
CheckFlags(result);
Flags.C = false;
Flags.Ac = false;
Registers.A = (byte)(result & 0x00FF);
}
private bool _mov(byte op)
{
int movCheck = op & 0xF0;
int movSubCheck = op & 0x0F;
switch (movCheck)
{
case 0x40:
SetRegisterValue(movSubCheck > 0x7 ? "c" : "b", GetRegisterValue(_registerNames[movSubCheck > 0x7 ? movSubCheck - 0x8 : movSubCheck]));
break;
case 0x50:
SetRegisterValue(movSubCheck > 0x7 ? "e" : "d", GetRegisterValue(_registerNames[movSubCheck > 0x7 ? movSubCheck - 0x8 : movSubCheck]));
break;
case 0x60:
SetRegisterValue(movSubCheck > 0x7 ? "l" : "h", GetRegisterValue(_registerNames[movSubCheck > 0x7 ? movSubCheck - 0x8 : movSubCheck]));
break;
case 0x70:
SetRegisterValue(movSubCheck > 0x7 ? "a" : "m", GetRegisterValue(_registerNames[movSubCheck > 0x7 ? movSubCheck - 0x8 : movSubCheck]));
break;
default:
return false;
}
ProgramCounter++;
return true;
}
private void _jmp()
{
ushort dest = (ushort)(_memory[(ushort)(ProgramCounter + 1)] | _memory[(ushort)(ProgramCounter + 2)] << 8);
ProgramCounter = dest;
}
private bool _add(byte op)
{
int high = op & 0xf0;
int low = op & 0x0f;
if (high != 0x80) // add commands are in 0x80 column
{
return false;
}
byte value = GetRegisterValue(_registerNames[low > 0x7 ? low - 0x8 : low]);
int carry = (low > 0x7 ? (Flags.C ? 1 : 0) : 0);
ushort result = (ushort)(Registers.A + value + carry);
Registers.A = (byte)result;
ProgramCounter++;
CheckFlags(result);
return true;
}
private void _compare(byte value)
{
int result = Registers.A - value;
Flags.Z = result == 0;
Flags.S = 0x80 == (result & 0x80);
Flags.P = Parity((ushort)result);
Flags.C = Registers.A < value;
}
private bool _cmp(byte op)
{
if (op < 0xb8 || op > 0xbf)
{
return false;
}
int id = op - 0xb8;
_compare(GetRegisterValue(_registerNames[id]));
_programCounter++;
return true;
}
private bool _sub(byte op)
{
int high = op & 0xf0;
int low = op & 0x0f;
if (high != 0x90) // add commands are in 0x80 column
{
return false;
}
byte value = GetRegisterValue(_registerNames[low > 0x7 ? low - 0x8 : low]);
int carry = (low > 0x7 ? (Flags.C ? 1 : 0) : 0);
ushort result = (ushort)(Registers.A - value - carry);
Registers.A = (byte)result;
ProgramCounter++;
CheckFlags(result);
return true;
}
private void _call()
{
ushort ret = (ushort)(ProgramCounter + 2);
PushStack(ret);
_jmp();
}
private void _increment(string name)
{
ushort result = (ushort)(GetRegisterValue(name) + 1);
SetRegisterValue(name, (byte)result);
CheckFlagsArith(result);
}
private void _decrement(string name)
{
ushort result = (ushort)(GetRegisterValue(name) - 1);
SetRegisterValue(name, (byte)result);
Flags.Z = result == 0;
Flags.S = (result & 0x80) == 0x80;
Flags.P = Parity(result);
}
private bool _inr(byte op)
{
if (op < 0x04 || op > 0x3c)
{
return false;
}
switch (op)
{
case 0x04:
_increment("B");
break;
case 0x0c:
_increment("C");
break;
case 0x14:
_increment("D");
break;
case 0x1c:
_increment("E");
break;
case 0x24:
_increment("H");
break;
case 0x2c:
_increment("L");
break;
case 0x34:
_increment("M");
break;
case 0x3c:
_increment("A");
break;
default:
return false;
}
_programCounter++;
return true;
}
private bool _dcr(byte op)
{
switch (op)
{
case 0x05:
_decrement("B");
break;
case 0x0d:
_decrement("C");
break;
case 0x15:
_decrement("D");
break;
case 0x1d:
_decrement("E");
break;
case 0x25:
_decrement("H");
break;
case 0x2d:
_decrement("L");
break;
case 0x35:
_decrement("M");
break;
case 0x3d:
_decrement("A");
break;
default:
return false;
}
_programCounter++;
return true;
}
public void Step()
{
byte op = _memory[(ushort)ProgramCounter];
switch (op)
{
case 0:
ProgramCounter++;
break;
case 0x06://mvi b
Registers.B = _memory[(ushort)(ProgramCounter + 1)];
ProgramCounter += 2;
break;
case 0x0E://mvi c
Registers.C = _memory[(ushort)(ProgramCounter + 1)];
ProgramCounter += 2;
break;
case 0x16://mvi d
Registers.D = _memory[(ushort)(ProgramCounter + 1)];
ProgramCounter += 2;
break;
case 0x1e: //mvi e
Registers.E = _memory[(ushort)(ProgramCounter + 1)];
ProgramCounter += 2;
break;
case 0x26: //mvi h
Registers.H = _memory[(ushort)(ProgramCounter + 1)];
ProgramCounter += 2;
break;
case 0x2e: //mvi e
Registers.L = _memory[(ushort)(ProgramCounter + 1)];
ProgramCounter += 2;
break;
case 0x36: //mvi m
SetRegisterValue("M", _memory[(ushort)(ProgramCounter + 1)]);
ProgramCounter += 2;
break;
case 0x3e: //mvi a
Registers.A = _memory[(ushort)(ProgramCounter + 1)];
ProgramCounter += 2;
break;
case 0xc6://adi
{
ushort result = (ushort)(Registers.A + _memory[(ushort)(ProgramCounter + 1)]);
Registers.A = (byte)result;
CheckFlags(result);
ProgramCounter += 2;
}
break;
case 0xce://aci
{
ushort result = (ushort)(Registers.A + _memory[(ushort)(ProgramCounter + 1)] + (Flags.C ? 1 : 0));
Registers.A = (byte)result;
CheckFlags(result);
ProgramCounter += 2;
}
break;
case 0xd6://sui
{
ushort result = (ushort)(Registers.A - _memory[(ushort)(ProgramCounter + 1)]);
Registers.A = (byte)result;
CheckFlags(result);
ProgramCounter += 2;
}
break;
case 0xde://sbi
{
ushort result = (ushort)(Registers.A - _memory[(ushort)(ProgramCounter + 1)] - (Flags.C ? 1 : 0));
Registers.A = (byte)result;
CheckFlags(result);
ProgramCounter += 2;
}
break;
case 0xc3://jump
_jmp();
break;
case 0xca://jz
if (_flags.Z)
{
_jmp();
}
else
{
ProgramCounter += 3;
}
break;
case 0xc2://jnz
if (!_flags.Z)
{
_jmp();
}
else
{
ProgramCounter += 3;
}
break;
case 0xf2://jp
if (!_flags.S)
{
_jmp();
}
else
{
ProgramCounter += 3;
}
break;
case 0xfa://jm
if (_flags.S)
{
_jmp();
}
else
{
ProgramCounter += 3;
}
break;
case 0xda://jc
if (_flags.C)
{
_jmp();
}
else
{
ProgramCounter += 3;
}
break;
case 0xd2://jnc
if (!_flags.C)
{
_jmp();
}
else
{
ProgramCounter += 3;
}
break;
case 0xea://jpe
if (!_flags.P)
{
_jmp();
}
else
{
ProgramCounter += 3;
}
break;
case 0xe2://jpo
if (_flags.P)
{
_jmp();
}
else
{
ProgramCounter += 3;
}
break;
case 0xc5://push b
PushStack("b");
ProgramCounter++;
break;
case 0xd5://push d
PushStack("d");
ProgramCounter++;
break;
case 0xe5://push h
PushStack("h");
ProgramCounter++;
break;
case 0xc1://pop b
PopStack("b");
ProgramCounter++;
break;
case 0xd1://pop d
PopStack("d");
ProgramCounter++;
break;
case 0xe1://pop h
PopStack("h");
ProgramCounter++;
break;
case 0x37://stc
Flags.C = true;
ProgramCounter++;
break;
case 0x32: // sta
{
ushort dest = (ushort)(_memory[(ushort)(ProgramCounter + 1)] | _memory[(ushort)(ProgramCounter + 2)] << 8);
_memory[dest] = Registers.A;
ProgramCounter += 3;
}
break;
case 0x3A: // lda
{
ushort dest = (ushort)(_memory[(ushort)(ProgramCounter + 1)] | _memory[(ushort)(ProgramCounter + 2)] << 8);
Registers.A = _memory[dest];
ProgramCounter += 3;
}
break;
case 0x01://lxi b
{
Registers.C = _memory[(ushort)(ProgramCounter + 1)];
Registers.B = _memory[(ushort)(ProgramCounter + 2)];
ProgramCounter += 3;
}
break;
case 0x11://lxi d
{
Registers.E = _memory[(ushort)(ProgramCounter + 1)];
Registers.D = _memory[(ushort)(ProgramCounter + 2)];
ProgramCounter += 3;
}
break;
case 0x21://lxi h
{
Registers.L = _memory[(ushort)(ProgramCounter + 1)];
Registers.H = _memory[(ushort)(ProgramCounter + 2)];
ProgramCounter += 3;
}
break;
case 0x31://lxi sp
{
ushort dest = (ushort)(_memory[(ushort)(ProgramCounter + 1)] | _memory[(ushort)(ProgramCounter + 2)] << 8);
_memory.StackPointer = dest;
ProgramCounter += 3;
}
break;
case 0xcd: //call
_call();
break;
case 0xc9://ret
ProgramCounter = PopStack();
break;
case 0xc8: // rz
if (Flags.Z)
{
ProgramCounter = PopStack();
}
else
{
ProgramCounter += 1;
}
break;
case 0xc0://rnz
if (!Flags.Z)
{
ProgramCounter = PopStack();
}
else
{
ProgramCounter += 1;
}
break;
case 0xf8: // rm
if (Flags.S)
{
ProgramCounter = PopStack();
}
else
{
ProgramCounter += 1;
}
break;
case 0xf0://rp
if (!Flags.S)
{
ProgramCounter = PopStack();
}
else
{
ProgramCounter += 1;
}
break;
case 0xD8: // rc
if (Flags.C)
{
ProgramCounter = PopStack();
}
else
{
ProgramCounter += 1;
}
break;
case 0xD0://rnc
if (!Flags.C)
{
ProgramCounter = PopStack();
}
else
{
ProgramCounter += 1;
}
break;
case 0xe8: // rpe
if (Flags.P)
{
ProgramCounter = PopStack();
}
else
{
ProgramCounter += 1;
}
break;
case 0xe0://rpo
if (!Flags.P)
{
ProgramCounter = PopStack();
}
else
{
ProgramCounter += 1;
}
break;
case 0xcc: // cz
if (Flags.Z)
{
_call();
}
else
{
ProgramCounter += 3;
}
break;
case 0xc4://cnz
if (!Flags.Z)
{
_call();
}
else
{
ProgramCounter += 3;
}
break;
case 0xfC: // cm
if (Flags.S)
{
_call();
}
else
{
ProgramCounter += 3;
}
break;
case 0xf4://cp
if (!Flags.S)
{
_call();
}
else
{
ProgramCounter += 3;
}
break;
case 0xdc: // cc
if (Flags.C)
{
_call();
}
else
{
ProgramCounter += 3;
}
break;
case 0xD4://cnc
if (!Flags.C)
{
_call();
}
else
{
ProgramCounter += 3;
}
break;
case 0xec: // cpe
if (Flags.P)
{
_call();
}
else
{
ProgramCounter += 3;
}
break;
case 0xe4://cpo
if (!Flags.P)
{
_call();
}
else
{
ProgramCounter += 3;
}
break;
case 0xf6://ori
_or(_memory[(ushort)(ProgramCounter + 1)]);
ProgramCounter += 2;
break;