65 std::string instruction =
"ADC.b #$01";
66 std::vector<std::string> tokens = asm_parser.
Tokenize(instruction);
68 std::vector<std::string> expected_tokens = {
"ADC",
".b",
"#",
"$",
"01"};
69 EXPECT_THAT(tokens, ::testing::ContainerEq(expected_tokens));
71 auto opcode = asm_parser.
Parse(instruction);
72 EXPECT_EQ(opcode[0], 0x69);
77 std::vector<uint8_t> data = {0x00, 0x01, 0x02, 0x03, 0x04};
80 EXPECT_CALL(memory, ReadByte(0)).WillOnce(Return(0x00));
81 EXPECT_CALL(memory, ReadByte(1)).WillOnce(Return(0x01));
82 EXPECT_CALL(memory, ReadByte(2)).WillOnce(Return(0x02));
83 EXPECT_CALL(memory, ReadByte(3)).WillOnce(Return(0x03));
84 EXPECT_CALL(memory, ReadByte(4)).WillOnce(Return(0x04));
85 EXPECT_CALL(memory, ReadByte(63999)).WillOnce(Return(0x00));
92 EXPECT_EQ(memory.
ReadByte(63999), 0x00);
100 cpu.SetAccumulatorSize(
true);
101 std::vector<uint8_t> data = {0x69, 0x15, 0x01};
102 mock_memory.SetMemoryContents(data);
104 cpu.ExecuteInstruction(cpu.ReadOpcode());
106 EXPECT_EQ(cpu.A, 0x00);
107 EXPECT_TRUE(cpu.GetCarryFlag());
113 std::vector<uint8_t> data = {0x61, 0x10};
114 mock_memory.SetMemoryContents(data);
115 mock_memory.InsertMemory(0x2012, {0x00, 0x30});
116 mock_memory.InsertMemory(0x3000, {0x06});
119 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
120 EXPECT_CALL(mock_memory, ReadWord(0x2012)).WillOnce(Return(0x3000));
121 EXPECT_CALL(mock_memory, ReadByte(0x3000)).WillOnce(Return(0x06));
123 cpu.ExecuteInstruction(0x61);
124 EXPECT_EQ(cpu.A, 0x09);
129 std::vector<uint8_t> data = {0x63, 0x02};
130 mock_memory.SetMemoryContents(data);
131 mock_memory.InsertMemory(0x0201, {0x06});
133 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
134 EXPECT_CALL(mock_memory, ReadByte(0x0201))
135 .WillOnce(Return(0x06));
137 cpu.ExecuteInstruction(0x63);
138 EXPECT_EQ(cpu.A, 0x09);
144 std::vector<uint8_t> data = {0x65, 0x10};
145 mock_memory.SetMemoryContents(data);
146 mock_memory.InsertMemory(0x2010, {0x05});
148 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
149 EXPECT_CALL(mock_memory, ReadByte(0x2010)).WillOnce(Return(0x05));
151 cpu.ExecuteInstruction(0x65);
152 EXPECT_EQ(cpu.A, 0x06);
158 std::vector<uint8_t> data = {0x67, 0x10};
159 mock_memory.SetMemoryContents(data);
160 mock_memory.InsertMemory(0x2010, {0x05, 0x00, 0x30});
161 mock_memory.InsertMemory(0x030005, {0x06});
163 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
164 EXPECT_CALL(mock_memory, ReadWordLong(0x2010)).WillOnce(Return(0x300005));
165 EXPECT_CALL(mock_memory, ReadWord(0x300005)).WillOnce(Return(0x06));
167 cpu.ExecuteInstruction(0x67);
168 EXPECT_EQ(cpu.A, 0x09);
173 cpu.SetAccumulatorSize(
true);
174 std::vector<uint8_t> data = {0x01};
175 mock_memory.SetMemoryContents(data);
177 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(0x01));
179 cpu.ExecuteInstruction(0x69);
180 EXPECT_EQ(cpu.A, 0x02);
185 cpu.SetAccumulatorSize(
true);
186 std::vector<uint8_t> data = {0x69,
static_cast<uint8_t
>(-20)};
187 mock_memory.SetMemoryContents(data);
189 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(-20));
191 cpu.ExecuteInstruction(0x69);
192 EXPECT_EQ(cpu.A,
static_cast<uint8_t
>(-10));
198 std::vector<uint8_t> data = {0x6D, 0x03, 0x00, 0x05, 0x00};
199 mock_memory.SetMemoryContents(data);
201 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x0003));
203 EXPECT_CALL(mock_memory, ReadWord(0x0003)).WillOnce(Return(0x0005));
205 cpu.ExecuteInstruction(0x6D);
206 EXPECT_EQ(cpu.A, 0x06);
211 cpu.SetAccumulatorSize(
false);
212 cpu.SetCarryFlag(
false);
213 std::vector<uint8_t> data = {0x6F, 0x04, 0x00, 0x00, 0x05, 0x00};
214 mock_memory.SetMemoryContents(data);
216 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x0004));
217 EXPECT_CALL(mock_memory, ReadWord(0x0004)).WillOnce(Return(0x0005));
219 cpu.ExecuteInstruction(0x6F);
220 EXPECT_EQ(cpu.A, 0x06);
227 std::vector<uint8_t> data = {0x71, 0x10};
228 mock_memory.SetMemoryContents(data);
229 mock_memory.InsertMemory(0x2010, {0x00, 0x30});
230 mock_memory.InsertMemory(0x3002, {0x06});
232 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
233 EXPECT_CALL(mock_memory, ReadWord(0x2010)).WillOnce(Return(0x3000));
234 EXPECT_CALL(mock_memory, ReadByte(0x3002)).WillOnce(Return(0x06));
236 cpu.ExecuteInstruction(0x71);
237 EXPECT_EQ(cpu.A, 0x09);
243 std::vector<uint8_t> data = {0x72, 0x10};
244 mock_memory.SetMemoryContents(data);
245 mock_memory.InsertMemory(0x2010, {0x00, 0x30});
246 mock_memory.InsertMemory(0x3000, {0x05});
248 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
249 EXPECT_CALL(mock_memory, ReadWord(0x2010)).WillOnce(Return(0x3000));
250 EXPECT_CALL(mock_memory, ReadByte(0x3000)).WillOnce(Return(0x05));
252 cpu.ExecuteInstruction(0x72);
253 EXPECT_EQ(cpu.A, 0x07);
260 std::vector<uint8_t> data = {0x73, 0x02};
261 mock_memory.SetMemoryContents(data);
262 mock_memory.InsertMemory(0x0201, {0x00, 0x30});
263 mock_memory.InsertMemory(0x103002, {0x06});
265 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
266 EXPECT_CALL(mock_memory, ReadWord(0x0201)).WillOnce(Return(0x3000));
267 EXPECT_CALL(mock_memory, ReadByte(0x103002)).WillOnce(Return(0x06));
269 cpu.ExecuteInstruction(0x73);
270 EXPECT_EQ(cpu.A, 0x09);
277 std::vector<uint8_t> data = {0x75, 0x10};
278 mock_memory.SetMemoryContents(data);
279 mock_memory.InsertMemory(0x2012, {0x06});
281 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
282 EXPECT_CALL(mock_memory, ReadByte(0x2012)).WillOnce(Return(0x06));
284 cpu.ExecuteInstruction(0x75);
285 EXPECT_EQ(cpu.A, 0x09);
293 std::vector<uint8_t> data = {0x77, 0x10};
294 mock_memory.SetMemoryContents(data);
295 mock_memory.InsertMemory(0x2010, {0x05, 0x00, 0x01});
296 mock_memory.InsertMemory(0x010007, {0x06});
298 EXPECT_CALL(mock_memory, ReadWordLong(0x2010)).WillOnce(Return(0x010005));
299 EXPECT_CALL(mock_memory, ReadWord(0x010007)).WillOnce(Return(0x06));
301 cpu.ExecuteInstruction(0x77);
302 EXPECT_EQ(cpu.A, 0x09);
309 std::vector<uint8_t> data = {0x79, 0x03, 0x00, 0x00, 0x05, 0x00};
310 mock_memory.SetMemoryContents(data);
312 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x0003));
313 EXPECT_CALL(mock_memory, ReadWord(0x200005)).WillOnce(Return(0x0005));
315 mock_memory.InsertMemory(0x200005, {0x05});
317 cpu.ExecuteInstruction(0x79);
318 EXPECT_EQ(cpu.A, 0x08);
325 cpu.SetCarryFlag(
false);
326 cpu.SetAccumulatorSize(
false);
327 std::vector<uint8_t> data = {0x7D, 0x03, 0x00};
328 mock_memory.SetMemoryContents(data);
330 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x0003));
331 EXPECT_CALL(mock_memory, ReadWord(0x200005)).WillOnce(Return(0x0005));
333 mock_memory.InsertMemory(0x200005, {0x05});
335 cpu.ExecuteInstruction(0x7D);
336 EXPECT_EQ(cpu.A, 0x08);
342 cpu.SetCarryFlag(
false);
343 cpu.SetAccumulatorSize(
false);
344 std::vector<uint8_t> data = {0x7F, 0x00, 0x00, 0x01};
345 mock_memory.SetMemoryContents(data);
346 mock_memory.InsertMemory(0x010000, {0x03, 0x05});
348 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x010000));
349 EXPECT_CALL(mock_memory, ReadWord(0x010002)).WillOnce(Return(0x0005));
351 cpu.ExecuteInstruction(0x7F);
352 EXPECT_EQ(cpu.A, 0x08);
363 std::vector<uint8_t> data = {0x21, 0x10};
364 mock_memory.SetMemoryContents(data);
365 mock_memory.InsertMemory(0x2012, {0x00, 0x30});
366 mock_memory.InsertMemory(0x3000, {0b10101010});
369 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
372 EXPECT_CALL(mock_memory, ReadWord(0x2012)).WillOnce(Return(0x3000));
375 EXPECT_CALL(mock_memory, ReadByte(0x3000)).WillOnce(Return(0b10101010));
377 cpu.ExecuteInstruction(0x21);
379 EXPECT_EQ(cpu.A, 0b10100000);
385 std::vector<uint8_t> data = {0x23, 0x02};
386 mock_memory.SetMemoryContents(data);
387 mock_memory.InsertMemory(0x0201, {0b10101010});
389 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
392 EXPECT_CALL(mock_memory, ReadByte(0x0201)).WillOnce(Return(0b10101010));
394 cpu.ExecuteInstruction(0x23);
396 EXPECT_EQ(cpu.A, 0b10100000);
402 std::vector<uint8_t> data = {0x25, 0x10};
403 mock_memory.SetMemoryContents(data);
404 mock_memory.InsertMemory(0x2010, {0b10101010});
407 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
410 EXPECT_CALL(mock_memory, ReadByte(0x2010)).WillOnce(Return(0b10101010));
412 cpu.ExecuteInstruction(0x25);
414 EXPECT_EQ(cpu.A, 0b10100000);
421 std::vector<uint8_t> data = {0x27, 0x10};
422 mock_memory.SetMemoryContents(data);
423 mock_memory.InsertMemory(0x2010, {0x05, 0x00, 0x30});
424 mock_memory.InsertMemory(0x300005, {0b10101010});
427 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
430 EXPECT_CALL(mock_memory, ReadWordLong(0x2010)).WillOnce(Return(0x300005));
433 EXPECT_CALL(mock_memory, ReadByte(0x300005)).WillOnce(Return(0b10101010));
435 cpu.ExecuteInstruction(0x27);
437 EXPECT_EQ(cpu.A, 0b10100000);
453 std::vector<uint8_t> data = {0x2D, 0x03, 0x00, 0b10101010, 0x01, 0x02};
454 mock_memory.SetMemoryContents(data);
457 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x0003));
460 EXPECT_CALL(mock_memory, ReadWord(0x0003)).WillOnce(Return(0b10101010));
462 cpu.ExecuteInstruction(0x2D);
464 EXPECT_THAT(cpu.PC, testing::Eq(0x03));
465 EXPECT_EQ(cpu.A, 0b10101010);
471 std::vector<uint8_t> data = {0x2F, 0x04, 0x00, 0x00, 0x05, 0x00};
473 mock_memory.SetMemoryContents(data);
474 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x000004));
476 EXPECT_CALL(mock_memory, ReadWordLong(0x0004)).WillOnce(Return(0x000005));
478 cpu.ExecuteInstruction(0x2F);
479 EXPECT_EQ(cpu.A, 0x01);
486 std::vector<uint8_t> data = {0x31, 0x10};
487 mock_memory.SetMemoryContents(data);
488 mock_memory.InsertMemory(0x2010, {0x00, 0x30});
489 mock_memory.InsertMemory(0x3002, {0b10101010});
492 EXPECT_CALL(mock_memory, ReadWord(0x2010)).WillOnce(Return(0x3000));
494 cpu.ExecuteInstruction(0x31);
496 EXPECT_EQ(cpu.A, 0b10100000);
502 std::vector<uint8_t> data = {0x32, 0x10};
503 mock_memory.SetMemoryContents(data);
504 mock_memory.InsertMemory(0x2010, {0x00, 0x30});
505 mock_memory.InsertMemory(0x3000, {0b10101010});
508 EXPECT_CALL(mock_memory, ReadWord(0x2010)).WillOnce(Return(0x3000));
510 cpu.ExecuteInstruction(0x32);
512 EXPECT_EQ(cpu.A, 0b10100000);
519 mock_memory.SetSP(0x01FF);
520 std::vector<uint8_t> data = {0x33, 0x02};
521 mock_memory.SetMemoryContents(data);
522 mock_memory.InsertMemory(0x0201, {0x00, 0x30});
523 mock_memory.InsertMemory(0x103002, {0b10101010});
525 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
526 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
527 EXPECT_CALL(mock_memory, ReadWord(0x0201)).WillOnce(Return(0x3000));
528 EXPECT_CALL(mock_memory, ReadByte(0x103002)).WillOnce(Return(0b10101010));
529 cpu.ExecuteInstruction(0x33);
531 EXPECT_EQ(cpu.A, 0b10100000);
538 std::vector<uint8_t> data = {0x35, 0x10};
539 mock_memory.SetMemoryContents(data);
540 mock_memory.InsertMemory(0x2012, {0b10101010});
543 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
544 EXPECT_CALL(mock_memory, ReadByte(0x2012)).WillOnce(Return(0b10101010));
546 cpu.ExecuteInstruction(0x35);
548 EXPECT_EQ(cpu.A, 0b10100000);
555 std::vector<uint8_t> data = {0x37, 0x10};
556 mock_memory.SetMemoryContents(data);
557 mock_memory.InsertMemory(0x2010, {0x05, 0x00, 0x30});
558 mock_memory.InsertMemory(0x300005, {0b10101010});
560 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
561 EXPECT_CALL(mock_memory, ReadWordLong(0x2010)).WillOnce(Return(0x300005));
562 EXPECT_CALL(mock_memory, ReadByte(0x300007)).WillOnce(Return(0b10101010));
564 cpu.ExecuteInstruction(0x37);
566 EXPECT_EQ(cpu.A, 0b10100000);
572 std::vector<uint8_t> data = {0x39, 0x03, 0x00,
573 0b00000000, 0b10101010, 0b01010101};
574 mock_memory.SetMemoryContents(data);
577 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x0003));
580 uint16_t address = 0x0003 + cpu.Y;
583 EXPECT_CALL(mock_memory, ReadByte(address)).WillOnce(Return(0b10101010));
585 cpu.ExecuteInstruction(0x39);
587 EXPECT_THAT(cpu.PC, testing::Eq(0x03));
588 EXPECT_EQ(cpu.A, 0b10100000);
594 std::vector<uint8_t> data = {0x3D, 0x03, 0x00,
595 0b00000000, 0b10101010, 0b01010101};
596 mock_memory.SetMemoryContents(data);
597 mock_memory.InsertMemory(0x200005, {0b10101010});
600 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x0003));
603 uint16_t address = 0x0003 +
static_cast<uint16_t
>(cpu.X & 0xFF);
606 EXPECT_CALL(mock_memory, ReadByte(address)).WillOnce(Return(0b10101010));
608 cpu.ExecuteInstruction(0x3D);
611 EXPECT_EQ(cpu.A, 0b10100000);
618 std::vector<uint8_t> data = {0x3F, 0x03, 0x00, 0x00,
619 0b00000000, 0b10101010, 0b01010101};
620 mock_memory.SetMemoryContents(data);
623 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x0003));
626 uint16_t address = 0x0003 +
static_cast<uint16_t
>(cpu.X & 0xFF);
629 EXPECT_CALL(mock_memory, ReadByte(address)).WillOnce(Return(0b10101010));
631 cpu.ExecuteInstruction(0x3F);
633 EXPECT_THAT(cpu.PC, testing::Eq(0x04));
634 EXPECT_EQ(cpu.A, 0b10100000);
643 std::vector<uint8_t> data = {0x06, 0x10};
644 mock_memory.SetMemoryContents(data);
645 mock_memory.InsertMemory(0x1010, {0x40});
647 cpu.ExecuteInstruction(0x06);
648 EXPECT_TRUE(cpu.GetCarryFlag());
649 EXPECT_FALSE(cpu.GetZeroFlag());
650 EXPECT_TRUE(cpu.GetNegativeFlag());
656 std::vector<uint8_t> data = {0x0A};
657 mock_memory.SetMemoryContents(data);
659 cpu.ExecuteInstruction(0x0A);
660 EXPECT_EQ(cpu.A, 0x80);
661 EXPECT_TRUE(cpu.GetCarryFlag());
662 EXPECT_FALSE(cpu.GetZeroFlag());
663 EXPECT_TRUE(cpu.GetNegativeFlag());
667 std::vector<uint8_t> data = {0x0E, 0x10, 0x20};
668 mock_memory.SetMemoryContents(data);
669 mock_memory.InsertMemory(0x2010, {0x40});
671 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2010));
672 EXPECT_CALL(mock_memory, ReadByte(0x2010)).WillOnce(Return(0x40));
674 cpu.ExecuteInstruction(0x0E);
675 EXPECT_TRUE(cpu.GetCarryFlag());
676 EXPECT_TRUE(cpu.GetZeroFlag());
677 EXPECT_FALSE(cpu.GetNegativeFlag());
683 std::vector<uint8_t> data = {0x16, 0x10};
684 mock_memory.SetMemoryContents(data);
685 mock_memory.InsertMemory(0x1012, {0x40});
687 cpu.ExecuteInstruction(0x16);
688 EXPECT_TRUE(cpu.GetCarryFlag());
689 EXPECT_FALSE(cpu.GetZeroFlag());
690 EXPECT_TRUE(cpu.GetNegativeFlag());
695 std::vector<uint8_t> data = {0x1E, 0x10, 0x20};
696 mock_memory.SetMemoryContents(data);
697 mock_memory.InsertMemory(0x2012, {0x40});
699 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2010));
700 EXPECT_CALL(mock_memory, ReadByte(0x2012)).WillOnce(Return(0x40));
702 cpu.ExecuteInstruction(0x1E);
703 EXPECT_TRUE(cpu.GetCarryFlag());
704 EXPECT_TRUE(cpu.GetZeroFlag());
705 EXPECT_FALSE(cpu.GetNegativeFlag());
712 cpu.SetCarryFlag(
false);
713 std::vector<uint8_t> data = {0x90, 0x05, 0x01};
714 mock_memory.SetMemoryContents(data);
716 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(5));
718 cpu.ExecuteInstruction(0x90);
719 EXPECT_EQ(cpu.PC, 0x05);
723 cpu.SetCarryFlag(
true);
724 std::vector<uint8_t> data = {0x90, 0x02, 0x01};
725 mock_memory.SetMemoryContents(data);
727 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(2));
729 cpu.ExecuteInstruction(0x90);
731 EXPECT_EQ(cpu.PC, 2);
738 cpu.SetCarryFlag(
true);
739 std::vector<uint8_t> data = {0xB0, 0x07, 0x02};
740 mock_memory.SetMemoryContents(data);
742 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(0x07));
744 cpu.ExecuteInstruction(0xB0);
745 EXPECT_EQ(cpu.PC, 0x07);
749 cpu.SetCarryFlag(
false);
750 std::vector<uint8_t> data = {0x10, 0x02, 0x01};
751 mock_memory.SetMemoryContents(data);
752 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(2));
753 cpu.ExecuteInstruction(0xB0);
754 EXPECT_EQ(cpu.PC, 2);
762 cpu.SetZeroFlag(
true);
763 std::vector<uint8_t> data = {0xF0, 0x09};
764 mock_memory.SetMemoryContents(data);
766 cpu.ExecuteInstruction(0xF0);
768 EXPECT_EQ(cpu.PC, 0x09);
772 cpu.SetZeroFlag(
false);
773 std::vector<uint8_t> data = {0xF0, 0x03};
774 mock_memory.SetMemoryContents(data);
776 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(0x03));
778 cpu.ExecuteInstruction(0xF0);
780 EXPECT_EQ(cpu.PC, 0x02);
784 cpu.SetZeroFlag(
true);
785 cpu.SetOverflowFlag(
true);
786 std::vector<uint8_t> data = {0xF0, 0x03};
787 mock_memory.SetMemoryContents(data);
789 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(0x03));
791 cpu.ExecuteInstruction(0xF0);
793 EXPECT_EQ(cpu.PC, 0x03);
797 cpu.SetZeroFlag(
false);
798 cpu.SetOverflowFlag(
true);
799 std::vector<uint8_t> data = {0xF0, 0x03, 0x02};
800 mock_memory.SetMemoryContents(data);
802 EXPECT_CALL(mock_memory, ReadByte(_)).WillOnce(Return(0x03));
804 cpu.ExecuteInstruction(0xF0);
806 EXPECT_EQ(cpu.PC, 0x02);
816 std::vector<uint8_t> data = {0x24, 0x10};
817 mock_memory.SetMemoryContents(data);
818 mock_memory.InsertMemory(0x1010, {0x81});
821 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
824 EXPECT_CALL(mock_memory, ReadByte(0x1010)).WillOnce(Return(0x81));
826 cpu.ExecuteInstruction(0x24);
827 EXPECT_TRUE(cpu.GetNegativeFlag());
828 EXPECT_FALSE(cpu.GetOverflowFlag());
829 EXPECT_FALSE(cpu.GetZeroFlag());
835 std::vector<uint8_t> data = {0x00, 0x10};
836 mock_memory.SetMemoryContents(data);
837 mock_memory.InsertMemory(0x0010, {0x81});
840 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
843 EXPECT_CALL(mock_memory, ReadByte(0x0010)).WillOnce(Return(0x81));
845 cpu.ExecuteInstruction(0x24);
846 EXPECT_TRUE(cpu.GetNegativeFlag());
847 EXPECT_FALSE(cpu.GetOverflowFlag());
848 EXPECT_FALSE(cpu.GetZeroFlag());
856 std::vector<uint8_t> data = {0x34, 0x10};
857 mock_memory.SetMemoryContents(data);
858 mock_memory.InsertMemory(0x1012, {0x81});
861 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
864 EXPECT_CALL(mock_memory, ReadByte(0x1012)).WillOnce(Return(0x81));
866 cpu.ExecuteInstruction(0x34);
867 EXPECT_TRUE(cpu.GetNegativeFlag());
868 EXPECT_FALSE(cpu.GetOverflowFlag());
869 EXPECT_FALSE(cpu.GetZeroFlag());
876 std::vector<uint8_t> data = {0x00, 0x10};
877 mock_memory.SetMemoryContents(data);
878 mock_memory.InsertMemory(0x0012, {0x81});
881 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x10));
884 EXPECT_CALL(mock_memory, ReadByte(0x0012)).WillOnce(Return(0x81));
886 cpu.ExecuteInstruction(0x3C);
887 EXPECT_TRUE(cpu.GetNegativeFlag());
888 EXPECT_FALSE(cpu.GetOverflowFlag());
889 EXPECT_FALSE(cpu.GetZeroFlag());
895 std::vector<uint8_t> data = {0x24, 0x00, 0x10};
896 mock_memory.SetMemoryContents(data);
897 mock_memory.InsertMemory(0x0010, {0x81});
900 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
903 EXPECT_CALL(mock_memory, ReadByte(0x0010)).WillOnce(Return(0x81));
905 cpu.ExecuteInstruction(0x24);
906 EXPECT_TRUE(cpu.GetNegativeFlag());
907 EXPECT_FALSE(cpu.GetOverflowFlag());
908 EXPECT_FALSE(cpu.GetZeroFlag());
988 std::vector<uint8_t> data = {0x00};
989 mock_memory.SetMemoryContents(data);
990 mock_memory.InsertMemory(0xFFFE, {0x10, 0x20});
992 EXPECT_CALL(mock_memory, ReadWord(0xFFFE)).WillOnce(Return(0x2010));
994 cpu.ExecuteInstruction(0x00);
995 EXPECT_EQ(cpu.PC, 0x2010);
996 EXPECT_TRUE(cpu.GetInterruptFlag());
1003 std::vector<uint8_t> data = {0x82, 0x10, 0x20};
1004 mock_memory.SetMemoryContents(data);
1006 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2010));
1008 cpu.ExecuteInstruction(0x82);
1009 EXPECT_EQ(cpu.PC, 0x2010);
1093 cpu.SetAccumulatorSize(
true);
1098 std::vector<uint8_t> data = {0xC1, 0x10};
1099 mock_memory.SetMemoryContents(data);
1100 mock_memory.InsertMemory(0x1012, {0x00, 0x30});
1101 mock_memory.InsertMemory(0x013000, {0x40});
1103 cpu.ExecuteInstruction(0xC1);
1105 EXPECT_TRUE(cpu.GetCarryFlag());
1106 EXPECT_FALSE(cpu.GetZeroFlag());
1107 EXPECT_TRUE(cpu.GetNegativeFlag());
1112 mock_memory.SetSP(0x01FF);
1113 std::vector<uint8_t> data = {0xC3, 0x02};
1114 mock_memory.SetMemoryContents(data);
1115 mock_memory.InsertMemory(0x0201, {0x40, 0x9F});
1117 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
1118 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
1119 EXPECT_CALL(mock_memory, ReadByte(0x0201)).WillOnce(Return(0x30));
1122 cpu.ExecuteInstruction(0xC3);
1124 EXPECT_TRUE(cpu.GetCarryFlag());
1125 EXPECT_FALSE(cpu.GetZeroFlag());
1126 EXPECT_FALSE(cpu.GetNegativeFlag());
1128 mock_memory.InsertMemory(0x0002, {0xC3, 0x03});
1130 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
1131 EXPECT_CALL(mock_memory, ReadByte(0x0003)).WillOnce(Return(0x03));
1132 EXPECT_CALL(mock_memory, ReadByte(0x0202)).WillOnce(Return(0x9F));
1134 cpu.status = 0b00110000;
1135 cpu.ExecuteInstruction(0xC3);
1137 EXPECT_TRUE(cpu.GetCarryFlag());
1138 EXPECT_FALSE(cpu.GetZeroFlag());
1139 EXPECT_TRUE(cpu.GetNegativeFlag());
1145 cpu.SetAccumulatorSize(
true);
1147 mock_memory.InsertMemory(0x0000, {0xC5});
1150 cpu.ExecuteInstruction(0xC5);
1153 EXPECT_TRUE(cpu.GetCarryFlag());
1154 EXPECT_FALSE(cpu.GetZeroFlag());
1155 EXPECT_TRUE(cpu.GetNegativeFlag());
1161 cpu.SetAccumulatorSize(
true);
1165 mock_memory.InsertMemory(0x0000, {0xC7, 0x02});
1169 mock_memory.InsertMemory(0x1002, {0x00, 0x00, 0x01});
1170 mock_memory.InsertMemory(0x010000, {0x40});
1173 cpu.ExecuteInstruction(0xC7);
1176 EXPECT_TRUE(cpu.GetCarryFlag());
1177 EXPECT_FALSE(cpu.GetZeroFlag());
1178 EXPECT_FALSE(cpu.GetNegativeFlag());
1184 cpu.SetAccumulatorSize(
true);
1186 mock_memory.InsertMemory(0x0000, {0x40});
1189 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(::testing::Return(0x40));
1192 cpu.ExecuteInstruction(0xC9);
1195 EXPECT_TRUE(cpu.GetCarryFlag());
1196 EXPECT_FALSE(cpu.GetZeroFlag());
1197 EXPECT_FALSE(cpu.GetNegativeFlag());
1202 cpu.SetAccumulatorSize(
false);
1204 mock_memory.InsertMemory(0x0000, {0x34, 0x12});
1207 cpu.ExecuteInstruction(0xCD);
1210 EXPECT_TRUE(cpu.GetCarryFlag());
1211 EXPECT_FALSE(cpu.GetZeroFlag());
1212 EXPECT_TRUE(cpu.GetNegativeFlag());
1217 cpu.status = 0b00000001;
1218 std::vector<uint8_t> data = {0xCF, 0x04, 0x00, 0x00, 0x05, 0x00};
1220 mock_memory.SetMemoryContents(data);
1221 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x000004));
1223 EXPECT_CALL(mock_memory, ReadWord(0x0004)).WillOnce(Return(0x000005));
1225 cpu.ExecuteInstruction(0xCF);
1227 EXPECT_FALSE(cpu.GetCarryFlag());
1228 EXPECT_FALSE(cpu.GetZeroFlag());
1229 EXPECT_TRUE(cpu.GetNegativeFlag());
1233 cpu.SetAccumulatorSize(
true);
1235 std::vector<uint8_t> data = {0xD1, 0x3C};
1236 mock_memory.SetMemoryContents(data);
1237 mock_memory.InsertMemory(0x00023C, {0x00, 0x10});
1239 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
1240 EXPECT_CALL(mock_memory, ReadWord(0x00023C)).WillOnce(Return(0x1000));
1242 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x7F));
1245 cpu.ExecuteInstruction(0xD1);
1248 EXPECT_TRUE(cpu.GetCarryFlag());
1249 EXPECT_FALSE(cpu.GetZeroFlag());
1250 EXPECT_TRUE(cpu.GetNegativeFlag());
1257 mock_memory.SetSP(0x01FF);
1258 std::vector<uint8_t> data = {0xD3, 0x02};
1259 mock_memory.SetMemoryContents(data);
1260 mock_memory.InsertMemory(0x0201, {0x00, 0x30});
1261 mock_memory.InsertMemory(0x103002, {0x06});
1263 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
1264 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
1265 EXPECT_CALL(mock_memory, ReadWord(0x0201)).WillOnce(Return(0x3000));
1266 EXPECT_CALL(mock_memory, ReadByte(0x103002)).WillOnce(Return(0x06));
1269 cpu.ExecuteInstruction(0xD3);
1272 EXPECT_TRUE(cpu.GetCarryFlag());
1273 EXPECT_FALSE(cpu.GetZeroFlag());
1274 EXPECT_TRUE(cpu.GetNegativeFlag());
1280 cpu.SetAccumulatorSize(
true);
1283 mock_memory.InsertMemory(0x0000, {0xD5});
1287 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(::testing::Return(0x40));
1288 EXPECT_CALL(mock_memory, ReadByte(0x0042)).WillOnce(::testing::Return(0x40));
1291 cpu.ExecuteInstruction(0xD5);
1294 EXPECT_TRUE(cpu.GetCarryFlag());
1295 EXPECT_FALSE(cpu.GetZeroFlag());
1296 EXPECT_FALSE(cpu.GetNegativeFlag());
1303 std::vector<uint8_t> data = {0xD7, 0x10};
1304 mock_memory.SetMemoryContents(data);
1305 mock_memory.InsertMemory(0x2010, {0x05, 0x00, 0x30});
1306 mock_memory.InsertMemory(0x300005, {0b10101010});
1308 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x10));
1309 EXPECT_CALL(mock_memory, ReadWordLong(0x2010)).WillOnce(Return(0x300005));
1310 EXPECT_CALL(mock_memory, ReadByte(0x300007)).WillOnce(Return(0b10101010));
1313 cpu.ExecuteInstruction(0xD7);
1316 EXPECT_TRUE(cpu.GetCarryFlag());
1317 EXPECT_FALSE(cpu.GetZeroFlag());
1318 EXPECT_FALSE(cpu.GetNegativeFlag());
1323 cpu.SetAccumulatorSize(
false);
1326 mock_memory.InsertMemory(0x0000, {0xD9});
1329 cpu.ExecuteInstruction(0xD9);
1332 EXPECT_TRUE(cpu.GetCarryFlag());
1333 EXPECT_FALSE(cpu.GetZeroFlag());
1334 EXPECT_TRUE(cpu.GetNegativeFlag());
1339 cpu.SetAccumulatorSize(
false);
1342 mock_memory.InsertMemory(0x0000, {0xDD});
1345 cpu.ExecuteInstruction(0xDD);
1348 EXPECT_TRUE(cpu.GetCarryFlag());
1349 EXPECT_FALSE(cpu.GetZeroFlag());
1350 EXPECT_TRUE(cpu.GetNegativeFlag());
1355 cpu.SetAccumulatorSize(
false);
1358 mock_memory.InsertMemory(0x0000, {0xDF});
1361 cpu.ExecuteInstruction(0xDF);
1364 EXPECT_TRUE(cpu.GetCarryFlag());
1365 EXPECT_FALSE(cpu.GetZeroFlag());
1366 EXPECT_TRUE(cpu.GetNegativeFlag());
1392 cpu.SetIndexSize(
false);
1393 cpu.SetAccumulatorSize(
false);
1395 std::vector<uint8_t> data = {0xE0, 0x34, 0x12};
1396 mock_memory.SetMemoryContents(data);
1397 cpu.ExecuteInstruction(0xE0);
1398 ASSERT_TRUE(cpu.GetZeroFlag());
1402 cpu.SetIndexSize(
false);
1405 std::vector<uint8_t> data = {0xE0, 0xFF, 0xFF};
1406 mock_memory.SetMemoryContents(data);
1407 cpu.ExecuteInstruction(0xE0);
1408 ASSERT_TRUE(cpu.GetNegativeFlag());
1413 cpu.SetIndexSize(
false);
1416 std::vector<uint8_t> data = {0xE4, 0x34, 0x12};
1417 mock_memory.SetMemoryContents(data);
1418 cpu.ExecuteInstruction(0xE4);
1419 ASSERT_TRUE(cpu.GetCarryFlag());
1423 cpu.SetIndexSize(
false);
1426 std::vector<uint8_t> data = {0xEC, 0x34, 0x12};
1427 mock_memory.SetMemoryContents(data);
1428 cpu.ExecuteInstruction(0xEC);
1429 ASSERT_TRUE(cpu.GetCarryFlag());
1433 cpu.SetIndexSize(
false);
1434 cpu.SetAccumulatorSize(
false);
1436 std::vector<uint8_t> data = {0xC0, 0x78, 0x56};
1437 mock_memory.SetMemoryContents(data);
1438 cpu.ExecuteInstruction(0xC0);
1439 ASSERT_TRUE(cpu.GetZeroFlag());
1443 cpu.SetIndexSize(
false);
1446 std::vector<uint8_t> data = {0xC0, 0x01, 0x80};
1447 mock_memory.SetMemoryContents(data);
1448 cpu.ExecuteInstruction(0xC0);
1449 ASSERT_TRUE(cpu.GetNegativeFlag());
1454 cpu.SetIndexSize(
false);
1457 std::vector<uint8_t> data = {0xC4, 0x34, 0x12};
1458 mock_memory.SetMemoryContents(data);
1459 cpu.ExecuteInstruction(0xC4);
1460 ASSERT_TRUE(cpu.GetCarryFlag());
1464 cpu.SetIndexSize(
false);
1467 std::vector<uint8_t> data = {0xCC, 0x34, 0x12};
1468 mock_memory.SetMemoryContents(data);
1469 cpu.ExecuteInstruction(0xCC);
1470 ASSERT_TRUE(cpu.GetCarryFlag());
1494 std::vector<uint8_t> data = {0xC6, 0x7F};
1495 mock_memory.SetMemoryContents(data);
1496 mock_memory.InsertMemory(0x107F, {0x02});
1498 cpu.ExecuteInstruction(0xC6);
1499 EXPECT_EQ(0x01, mock_memory.ReadByte(0x107F));
1505 std::vector<uint8_t> data = {0xCE, 0x00, 0x10};
1506 mock_memory.SetMemoryContents(data);
1507 mock_memory.InsertMemory(0x1000, {0x02});
1509 cpu.ExecuteInstruction(0xCE);
1510 EXPECT_EQ(0x01, mock_memory.ReadByte(0x1000));
1518 std::vector<uint8_t> data = {0xD6, 0x7F};
1519 mock_memory.SetMemoryContents(data);
1520 mock_memory.InsertMemory(0x1081, {0x02});
1522 cpu.ExecuteInstruction(0xD6);
1523 EXPECT_EQ(0x01, mock_memory.ReadByte(0x1081));
1530 std::vector<uint8_t> data = {0xDE, 0x00, 0x10};
1531 mock_memory.SetMemoryContents(data);
1532 mock_memory.InsertMemory(0x1002, {0x02});
1534 cpu.ExecuteInstruction(0xDE);
1535 EXPECT_EQ(0x01, mock_memory.ReadByte(0x1002));
1582 std::vector<uint8_t> data = {0x41, 0x7E};
1583 mock_memory.SetMemoryContents(data);
1584 mock_memory.InsertMemory(0x0080, {0x00, 0x10});
1585 mock_memory.InsertMemory(0x1000, {0b01010101});
1587 cpu.ExecuteInstruction(0x41);
1588 EXPECT_EQ(cpu.A, 0b11111111);
1594 mock_memory.SetSP(0x01FF);
1595 std::vector<uint8_t> data = {0x43, 0x02};
1596 mock_memory.SetMemoryContents(data);
1597 mock_memory.InsertMemory(0x0201, {0b01010101});
1599 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
1600 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
1601 EXPECT_CALL(mock_memory, ReadByte(0x0201)).WillOnce(Return(0b01010101));
1603 cpu.ExecuteInstruction(0x43);
1604 EXPECT_EQ(cpu.A, 0b11111111);
1610 std::vector<uint8_t> data = {0x45, 0x7F};
1611 mock_memory.SetMemoryContents(data);
1612 mock_memory.InsertMemory(0x007F, {0b01010101});
1614 cpu.ExecuteInstruction(0x45);
1615 EXPECT_EQ(cpu.A, 0b11111111);
1621 std::vector<uint8_t> data = {0x47, 0x7F};
1622 mock_memory.SetMemoryContents(data);
1623 mock_memory.InsertMemory(0x007F, {0x00, 0x10, 0x00});
1624 mock_memory.InsertMemory(0x1000, {0b01010101});
1626 cpu.ExecuteInstruction(0x47);
1627 EXPECT_EQ(cpu.A, 0b11111111);
1633 std::vector<uint8_t> data = {0x49, 0b01010101};
1634 mock_memory.SetMemoryContents(data);
1636 cpu.ExecuteInstruction(0x49);
1637 EXPECT_EQ(cpu.A, 0b11111111);
1643 std::vector<uint8_t> data = {0x4D, 0x00, 0x10};
1644 mock_memory.SetMemoryContents(data);
1645 mock_memory.InsertMemory(0x1000, {0b01010101});
1647 cpu.ExecuteInstruction(0x4D);
1648 EXPECT_EQ(cpu.A, 0b11111111);
1654 std::vector<uint8_t> data = {0x4F, 0x00, 0x10, 0x00};
1655 mock_memory.SetMemoryContents(data);
1656 mock_memory.InsertMemory(0x1000, {0b01010101});
1658 cpu.ExecuteInstruction(0x4F);
1659 EXPECT_EQ(cpu.A, 0b11111111);
1666 std::vector<uint8_t> data = {0x51, 0x7E};
1667 mock_memory.SetMemoryContents(data);
1668 mock_memory.InsertMemory(0x007E, {0x00, 0x10});
1669 mock_memory.InsertMemory(0x1002, {0b01010101});
1671 cpu.ExecuteInstruction(0x51);
1672 EXPECT_EQ(cpu.A, 0b11111111);
1678 std::vector<uint8_t> data = {0x52, 0x7E};
1679 mock_memory.SetMemoryContents(data);
1680 mock_memory.InsertMemory(0x007E, {0x00, 0x10});
1681 mock_memory.InsertMemory(0x1000, {0b01010101});
1683 cpu.ExecuteInstruction(0x52);
1684 EXPECT_EQ(cpu.A, 0b11111111);
1691 std::vector<uint8_t> data = {0x53, 0x02};
1692 mock_memory.SetMemoryContents(data);
1693 mock_memory.InsertMemory(0x0201, {0x00, 0x10});
1694 mock_memory.InsertMemory(0x1002, {0b01010101});
1696 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
1697 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
1698 EXPECT_CALL(mock_memory, ReadWord(0x0201)).WillOnce(Return(0x1000));
1699 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0b01010101));
1701 cpu.ExecuteInstruction(0x53);
1702 EXPECT_EQ(cpu.A, 0b11111111);
1709 std::vector<uint8_t> data = {0x55, 0x7E};
1710 mock_memory.SetMemoryContents(data);
1711 mock_memory.InsertMemory(0x0080, {0b01010101});
1713 cpu.ExecuteInstruction(0x55);
1714 EXPECT_EQ(cpu.A, 0b11111111);
1721 std::vector<uint8_t> data = {0x51, 0x7E};
1722 mock_memory.SetMemoryContents(data);
1723 mock_memory.InsertMemory(0x007E, {0x00, 0x10, 0x00});
1724 mock_memory.InsertMemory(0x1002, {0b01010101});
1726 cpu.ExecuteInstruction(0x51);
1727 EXPECT_EQ(cpu.A, 0b11111111);
1735 std::vector<uint8_t> data = {0x59, 0x7C, 0x00};
1736 mock_memory.SetMemoryContents(data);
1737 mock_memory.InsertMemory(0x007E, {0b01010101});
1739 cpu.ExecuteInstruction(0x59);
1740 EXPECT_EQ(cpu.A, 0b11111111);
1748 std::vector<uint8_t> data = {0x5D, 0x7C, 0x00};
1749 mock_memory.SetMemoryContents(data);
1750 mock_memory.InsertMemory(0x007E, {0b01010101});
1752 cpu.ExecuteInstruction(0x5D);
1753 EXPECT_EQ(cpu.A, 0b11111111);
1761 std::vector<uint8_t> data = {0x5F, 0x7C, 0x00, 0x00};
1762 mock_memory.SetMemoryContents(data);
1763 mock_memory.InsertMemory(0x007E, {0b01010101});
1765 cpu.ExecuteInstruction(0x5F);
1766 EXPECT_EQ(cpu.A, 0b11111111);
1788 cpu.SetAccumulatorSize(
true);
1790 std::vector<uint8_t> data = {0xE6, 0x20};
1791 mock_memory.SetMemoryContents(data);
1792 mock_memory.InsertMemory(0x0220, {0x40});
1794 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x20));
1795 EXPECT_CALL(mock_memory, ReadByte(0x0220)).WillOnce(Return(0x40));
1797 cpu.ExecuteInstruction(0xE6);
1798 EXPECT_EQ(mock_memory[0x0220], 0x41);
1799 EXPECT_FALSE(cpu.GetNegativeFlag());
1800 EXPECT_FALSE(cpu.GetZeroFlag());
1804 std::vector<uint8_t> data = {0xEE, 0x00, 0x10};
1805 mock_memory.SetMemoryContents(data);
1806 mock_memory.InsertMemory(0x1000, {0x40});
1808 cpu.SetAccumulatorSize(
false);
1809 cpu.ExecuteInstruction(0xEE);
1810 EXPECT_EQ(mock_memory[0x1000], 0x41);
1811 EXPECT_FALSE(cpu.GetNegativeFlag());
1812 EXPECT_FALSE(cpu.GetZeroFlag());
1817 std::vector<uint8_t> data = {0xE6, 0x20};
1818 mock_memory.SetMemoryContents(data);
1819 mock_memory.InsertMemory(0x0220, {0xFF});
1821 cpu.SetAccumulatorSize(
true);
1822 cpu.ExecuteInstruction(0xE6);
1823 EXPECT_FALSE(cpu.GetNegativeFlag());
1824 EXPECT_TRUE(cpu.GetZeroFlag());
1828 std::vector<uint8_t> data = {0xEE, 0x00, 0x10};
1829 mock_memory.SetMemoryContents(data);
1830 mock_memory.InsertMemory(0x1000, {0xFF});
1832 cpu.SetAccumulatorSize(
false);
1833 cpu.ExecuteInstruction(0xEE);
1834 EXPECT_FALSE(cpu.GetNegativeFlag());
1835 EXPECT_FALSE(cpu.GetZeroFlag());
1839 std::vector<uint8_t> data = {0xE6, 0x80};
1840 mock_memory.SetMemoryContents(data);
1842 cpu.SetAccumulatorSize(
true);
1843 cpu.ExecuteInstruction(0xE6);
1844 EXPECT_FALSE(cpu.GetNegativeFlag());
1845 EXPECT_FALSE(cpu.GetZeroFlag());
1851 std::vector<uint8_t> data = {0xF6, 0x20};
1852 mock_memory.SetMemoryContents(data);
1853 mock_memory.InsertMemory(0x0221, {0x40});
1855 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x20));
1856 EXPECT_CALL(mock_memory, ReadByte(0x0221)).WillOnce(Return(0x40));
1858 cpu.ExecuteInstruction(0xF6);
1859 EXPECT_EQ(mock_memory[0x0221], 0x41);
1860 EXPECT_FALSE(cpu.GetNegativeFlag());
1861 EXPECT_FALSE(cpu.GetZeroFlag());
1866 std::vector<uint8_t> data = {0xFE, 0x00, 0x10};
1867 mock_memory.SetMemoryContents(data);
1868 mock_memory.InsertMemory(0x1001, {0x40});
1870 cpu.SetAccumulatorSize(
false);
1871 cpu.ExecuteInstruction(0xFE);
1872 EXPECT_EQ(mock_memory[0x1001], 0x41);
1873 EXPECT_FALSE(cpu.GetNegativeFlag());
1874 EXPECT_FALSE(cpu.GetZeroFlag());
1910 std::vector<uint8_t> data = {0x4C, 0x05, 0x20};
1911 mock_memory.SetMemoryContents(data);
1913 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2005));
1915 cpu.ExecuteInstruction(0x4C);
1916 cpu.ExecuteInstruction(0xEA);
1918 EXPECT_EQ(cpu.PC, 0x2006);
1922 std::vector<uint8_t> data = {0x6C, 0x03, 0x20, 0x05, 0x30};
1923 mock_memory.SetMemoryContents(data);
1925 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2003));
1926 EXPECT_CALL(mock_memory, ReadWord(0x2003)).WillOnce(Return(0x3005));
1928 cpu.ExecuteInstruction(0x6C);
1929 EXPECT_EQ(cpu.PC, 0x3005);
1938 std::vector<uint8_t> data = {0x5C, 0x05, 0x00, 0x03};
1939 mock_memory.SetMemoryContents(data);
1940 mock_memory.InsertMemory(0x030005, {0x00, 0x20, 0x00});
1942 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x030005));
1944 cpu.ExecuteInstruction(0x5C);
1945 EXPECT_EQ(cpu.PC, 0x0005);
1946 EXPECT_EQ(cpu.PB, 0x03);
1951 std::vector<uint8_t> data = {0x7C, 0x05, 0x20, 0x00};
1952 mock_memory.SetMemoryContents(data);
1953 mock_memory.InsertMemory(0x2007, {0x30, 0x05});
1955 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2005));
1956 EXPECT_CALL(mock_memory, ReadWord(0x2007)).WillOnce(Return(0x3005));
1958 cpu.ExecuteInstruction(0x7C);
1959 EXPECT_EQ(cpu.PC, 0x3005);
1963 std::vector<uint8_t> data = {0xDC, 0x05, 0x20, 0x00};
1964 mock_memory.SetMemoryContents(data);
1965 mock_memory.InsertMemory(0x2005, {0x01, 0x30, 0x05});
1967 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2005));
1968 EXPECT_CALL(mock_memory, ReadWordLong(0x2005)).WillOnce(Return(0x013005));
1970 cpu.ExecuteInstruction(0xDC);
1971 EXPECT_EQ(cpu.PC, 0x3005);
1972 EXPECT_EQ(cpu.PB, 0x01);
1979 std::vector<uint8_t> data = {0x20, 0x05, 0x20};
1980 mock_memory.SetMemoryContents(data);
1982 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2005));
1983 EXPECT_CALL(mock_memory, PushWord(0x0000)).Times(1);
1985 cpu.ExecuteInstruction(0x20);
1986 EXPECT_EQ(cpu.PC, 0x2005);
1989 cpu.ExecuteInstruction(0x60);
1990 EXPECT_EQ(cpu.PC, 0x0003);
1997 std::vector<uint8_t> data = {0x22, 0x05, 0x20, 0x00};
1998 mock_memory.SetMemoryContents(data);
2000 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x002005));
2001 EXPECT_CALL(mock_memory, PushLong(0x0000)).Times(1);
2003 cpu.ExecuteInstruction(0x22);
2004 EXPECT_EQ(cpu.PC, 0x002005);
2009 std::vector<uint8_t> data = {0xFC, 0x05, 0x20, 0x00};
2010 mock_memory.SetMemoryContents(data);
2011 mock_memory.InsertMemory(0x2007, {0x00, 0x20, 0x00});
2013 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x2005));
2014 EXPECT_CALL(mock_memory, ReadWord(0x2007)).WillOnce(Return(0x002000));
2016 cpu.ExecuteInstruction(0xFC);
2017 EXPECT_EQ(cpu.PC, 0x2000);
2024 cpu.SetAccumulatorSize(
true);
2027 std::vector<uint8_t> data = {0xA1, 0x3C};
2028 mock_memory.SetMemoryContents(data);
2029 mock_memory.InsertMemory(0x00023E, {0x00, 0x10});
2031 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2032 EXPECT_CALL(mock_memory, ReadWord(0x00023E)).WillOnce(Return(0x1000));
2034 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x80));
2036 cpu.ExecuteInstruction(0xA1);
2037 EXPECT_EQ(cpu.A, 0x80);
2038 EXPECT_TRUE(cpu.GetNegativeFlag());
2039 EXPECT_FALSE(cpu.GetZeroFlag());
2043 cpu.SetAccumulatorSize(
true);
2045 mock_memory.SetSP(0x01FF);
2046 std::vector<uint8_t> data = {0xA3, 0x02};
2047 mock_memory.SetMemoryContents(data);
2048 mock_memory.InsertMemory(0x0201, {0x7F});
2050 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
2051 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
2052 EXPECT_CALL(mock_memory, ReadByte(0x0201)).WillOnce(Return(0x7F));
2054 cpu.ExecuteInstruction(0xA3);
2055 EXPECT_EQ(cpu.A, 0x7F);
2056 EXPECT_FALSE(cpu.GetNegativeFlag());
2057 EXPECT_FALSE(cpu.GetZeroFlag());
2061 cpu.SetAccumulatorSize(
true);
2063 std::vector<uint8_t> data = {0xA5, 0x3C, 0x00};
2064 mock_memory.SetMemoryContents(data);
2065 mock_memory.InsertMemory(0x00023C, {0x80});
2067 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2068 EXPECT_CALL(mock_memory, ReadByte(0x00023C)).WillOnce(Return(0x80));
2070 cpu.ExecuteInstruction(0xA5);
2071 EXPECT_EQ(cpu.A, 0x80);
2072 EXPECT_TRUE(cpu.GetNegativeFlag());
2073 EXPECT_FALSE(cpu.GetZeroFlag());
2077 cpu.SetAccumulatorSize(
true);
2079 std::vector<uint8_t> data = {0xA7, 0x3C, 0x00};
2080 mock_memory.SetMemoryContents(data);
2081 mock_memory.InsertMemory(0x00023C, {0x00, 0x10, 0x00});
2083 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2084 EXPECT_CALL(mock_memory, ReadWordLong(0x00023C)).WillOnce(Return(0x1000));
2086 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x80));
2088 cpu.ExecuteInstruction(0xA7);
2089 EXPECT_EQ(cpu.A, 0x80);
2090 EXPECT_TRUE(cpu.GetNegativeFlag());
2091 EXPECT_FALSE(cpu.GetZeroFlag());
2095 cpu.SetAccumulatorSize(
true);
2096 std::vector<uint8_t> data = {0xA9, 0xFF};
2097 mock_memory.SetMemoryContents(data);
2099 cpu.ExecuteInstruction(0xA9);
2100 EXPECT_EQ(cpu.A, 0xFF);
2101 EXPECT_TRUE(cpu.GetNegativeFlag());
2102 EXPECT_FALSE(cpu.GetZeroFlag());
2106 std::vector<uint8_t> data = {0xA9, 0x7F, 0xFF};
2107 mock_memory.SetMemoryContents(data);
2109 cpu.SetAccumulatorSize(
false);
2110 cpu.ExecuteInstruction(0xA9);
2111 EXPECT_EQ(cpu.A, 0xFF7F);
2112 EXPECT_TRUE(cpu.GetNegativeFlag());
2113 EXPECT_FALSE(cpu.GetZeroFlag());
2117 cpu.SetAccumulatorSize(
true);
2118 std::vector<uint8_t> data = {0xAD, 0x7F, 0xFF};
2119 mock_memory.SetMemoryContents(data);
2120 mock_memory.InsertMemory(0x7FFF, {0x7F});
2122 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2124 EXPECT_CALL(mock_memory, ReadByte(0x7FFF)).WillOnce(Return(0x7F));
2126 cpu.SetAccumulatorSize(
true);
2127 cpu.ExecuteInstruction(0xAD);
2128 EXPECT_EQ(cpu.A, 0x7F);
2129 EXPECT_FALSE(cpu.GetZeroFlag());
2133 cpu.SetAccumulatorSize(
true);
2134 std::vector<uint8_t> data = {0xAF, 0x7F, 0xFF, 0x00};
2135 mock_memory.SetMemoryContents(data);
2136 mock_memory.InsertMemory(0x7FFF, {0x7F});
2138 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x7FFF));
2140 EXPECT_CALL(mock_memory, ReadByte(0x7FFF)).WillOnce(Return(0x7F));
2142 cpu.SetAccumulatorSize(
true);
2143 cpu.ExecuteInstruction(0xAF);
2144 EXPECT_EQ(cpu.A, 0x7F);
2145 EXPECT_FALSE(cpu.GetZeroFlag());
2149 cpu.SetAccumulatorSize(
true);
2152 std::vector<uint8_t> data = {0xB1, 0x3C};
2153 mock_memory.SetMemoryContents(data);
2154 mock_memory.InsertMemory(0x00023C, {0x00, 0x10});
2155 mock_memory.InsertMemory(0x1002, {0x80});
2157 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2158 EXPECT_CALL(mock_memory, ReadWord(0x00023C)).WillOnce(Return(0x1000));
2160 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0x80));
2162 cpu.ExecuteInstruction(0xB1);
2163 EXPECT_EQ(cpu.A, 0x80);
2164 EXPECT_TRUE(cpu.GetNegativeFlag());
2165 EXPECT_FALSE(cpu.GetZeroFlag());
2169 cpu.SetAccumulatorSize(
true);
2171 std::vector<uint8_t> data = {0xA1, 0x3C};
2172 mock_memory.SetMemoryContents(data);
2173 mock_memory.InsertMemory(0x00023C, {0x00, 0x10});
2175 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2176 EXPECT_CALL(mock_memory, ReadWord(0x00023C)).WillOnce(Return(0x1000));
2178 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x7F));
2180 cpu.ExecuteInstruction(0xB2);
2181 EXPECT_EQ(cpu.A, 0x7F);
2182 EXPECT_FALSE(cpu.GetZeroFlag());
2186 cpu.SetAccumulatorSize(
true);
2189 std::vector<uint8_t> data = {0xB3, 0x02};
2190 mock_memory.SetMemoryContents(data);
2191 mock_memory.InsertMemory(0x0201, {0x00, 0x10});
2193 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
2194 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
2195 EXPECT_CALL(mock_memory, ReadWord(0x0201)).WillOnce(Return(0x1000));
2197 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0x80));
2199 cpu.ExecuteInstruction(0xB3);
2200 EXPECT_EQ(cpu.A, 0x80);
2201 EXPECT_TRUE(cpu.GetNegativeFlag());
2202 EXPECT_FALSE(cpu.GetZeroFlag());
2206 cpu.SetAccumulatorSize(
true);
2209 std::vector<uint8_t> data = {0xB5, 0x3C};
2210 mock_memory.SetMemoryContents(data);
2211 mock_memory.InsertMemory(0x00023E, {0x7F});
2213 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2214 EXPECT_CALL(mock_memory, ReadByte(0x00023E)).WillOnce(Return(0x80));
2216 cpu.ExecuteInstruction(0xB5);
2217 EXPECT_EQ(cpu.A, 0x80);
2218 EXPECT_TRUE(cpu.GetNegativeFlag());
2219 EXPECT_FALSE(cpu.GetZeroFlag());
2223 cpu.SetAccumulatorSize(
true);
2226 std::vector<uint8_t> data = {0xB7, 0x3C};
2227 mock_memory.SetMemoryContents(data);
2228 mock_memory.InsertMemory(0x00023C, {0x00, 0x10, 0x00});
2230 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2231 EXPECT_CALL(mock_memory, ReadWordLong(0x00023C)).WillOnce(Return(0x1000));
2233 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0x80));
2235 cpu.ExecuteInstruction(0xB7);
2236 EXPECT_EQ(cpu.A, 0x80);
2237 EXPECT_TRUE(cpu.GetNegativeFlag());
2238 EXPECT_FALSE(cpu.GetZeroFlag());
2242 cpu.SetAccumulatorSize(
true);
2244 std::vector<uint8_t> data = {0xB9, 0x7F, 0xFF};
2245 mock_memory.SetMemoryContents(data);
2246 mock_memory.InsertMemory(0x8001, {0x80});
2248 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2250 EXPECT_CALL(mock_memory, ReadByte(0x8001)).WillOnce(Return(0x80));
2252 cpu.ExecuteInstruction(0xB9);
2253 EXPECT_EQ(cpu.A, 0x80);
2254 EXPECT_FALSE(cpu.GetZeroFlag());
2258 cpu.SetAccumulatorSize(
true);
2260 std::vector<uint8_t> data = {0xBD, 0x7F, 0xFF};
2261 mock_memory.SetMemoryContents(data);
2262 mock_memory.InsertMemory(0x8001, {0x80});
2264 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2266 EXPECT_CALL(mock_memory, ReadByte(0x8001)).WillOnce(Return(0x80));
2268 cpu.ExecuteInstruction(0xBD);
2269 EXPECT_EQ(cpu.A, 0x80);
2270 EXPECT_FALSE(cpu.GetZeroFlag());
2274 cpu.SetAccumulatorSize(
true);
2276 std::vector<uint8_t> data = {0xBF, 0x7F, 0xFF, 0x00};
2277 mock_memory.SetMemoryContents(data);
2278 mock_memory.InsertMemory(0x8001, {0x80});
2280 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x7FFF));
2282 EXPECT_CALL(mock_memory, ReadByte(0x8001)).WillOnce(Return(0x80));
2284 cpu.ExecuteInstruction(0xBF);
2285 EXPECT_EQ(cpu.A, 0x80);
2286 EXPECT_FALSE(cpu.GetZeroFlag());
2302 cpu.SetIndexSize(
true);
2303 std::vector<uint8_t> data = {0xA6, 0x80};
2304 mock_memory.SetMemoryContents(data);
2305 mock_memory.InsertMemory(0x0080, {0x42});
2307 cpu.ExecuteInstruction(0xA6);
2308 EXPECT_EQ(cpu.X, 0x42);
2309 EXPECT_FALSE(cpu.GetZeroFlag());
2313 cpu.SetIndexSize(
true);
2314 std::vector<uint8_t> data = {0xAE, 0x7F, 0xFF};
2315 mock_memory.SetMemoryContents(data);
2316 mock_memory.InsertMemory(0x7FFF, {0x42});
2318 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2320 cpu.ExecuteInstruction(0xAE);
2321 EXPECT_EQ(cpu.X, 0x42);
2322 EXPECT_FALSE(cpu.GetZeroFlag());
2326 cpu.SetIndexSize(
true);
2328 std::vector<uint8_t> data = {0xB6, 0x80};
2329 mock_memory.SetMemoryContents(data);
2330 mock_memory.InsertMemory(0x0082, {0x42});
2332 cpu.ExecuteInstruction(0xB6);
2333 EXPECT_EQ(cpu.X, 0x42);
2334 EXPECT_FALSE(cpu.GetZeroFlag());
2338 cpu.SetIndexSize(
true);
2340 std::vector<uint8_t> data = {0xBE, 0x7F, 0xFF};
2341 mock_memory.SetMemoryContents(data);
2342 mock_memory.InsertMemory(0x8001, {0x42});
2344 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2346 cpu.ExecuteInstruction(0xBE);
2347 EXPECT_EQ(cpu.X, 0x42);
2348 EXPECT_FALSE(cpu.GetZeroFlag());
2364 cpu.SetIndexSize(
true);
2365 std::vector<uint8_t> data = {0xA4, 0x80};
2366 mock_memory.SetMemoryContents(data);
2367 mock_memory.InsertMemory(0x0080, {0x42});
2369 cpu.ExecuteInstruction(0xA4);
2370 EXPECT_EQ(cpu.Y, 0x42);
2371 EXPECT_FALSE(cpu.GetZeroFlag());
2375 cpu.SetIndexSize(
true);
2376 std::vector<uint8_t> data = {0xAC, 0x7F, 0xFF};
2377 mock_memory.SetMemoryContents(data);
2378 mock_memory.InsertMemory(0x7FFF, {0x42});
2380 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2382 cpu.ExecuteInstruction(0xAC);
2383 EXPECT_EQ(cpu.Y, 0x42);
2384 EXPECT_FALSE(cpu.GetZeroFlag());
2388 cpu.SetIndexSize(
true);
2390 std::vector<uint8_t> data = {0xB4, 0x80};
2391 mock_memory.SetMemoryContents(data);
2392 mock_memory.InsertMemory(0x0082, {0x42});
2394 cpu.ExecuteInstruction(0xB4);
2395 EXPECT_EQ(cpu.Y, 0x42);
2396 EXPECT_FALSE(cpu.GetZeroFlag());
2400 cpu.SetIndexSize(
true);
2402 std::vector<uint8_t> data = {0xBC, 0x7F, 0xFF};
2403 mock_memory.SetMemoryContents(data);
2404 mock_memory.InsertMemory(0x8001, {0x42});
2406 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2408 cpu.ExecuteInstruction(0xBC);
2409 EXPECT_EQ(cpu.Y, 0x42);
2410 EXPECT_FALSE(cpu.GetZeroFlag());
2416 cpu.SetAccumulatorSize(
true);
2417 std::vector<uint8_t> data = {0x46, 0x80};
2418 mock_memory.SetMemoryContents(data);
2419 mock_memory.InsertMemory(0x0080, {0x42});
2421 cpu.ExecuteInstruction(0x46);
2422 EXPECT_EQ(mock_memory[0x0080], 0x21);
2423 EXPECT_FALSE(cpu.GetNegativeFlag());
2424 EXPECT_FALSE(cpu.GetZeroFlag());
2437 cpu.SetAccumulatorSize(
true);
2438 std::vector<uint8_t> data = {0x4E, 0x7F, 0xFF};
2439 mock_memory.SetMemoryContents(data);
2440 mock_memory.InsertMemory(0x7FFF, {0x42});
2442 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2444 cpu.ExecuteInstruction(0x4E);
2445 EXPECT_EQ(mock_memory[0x7FFF], 0x21);
2446 EXPECT_FALSE(cpu.GetNegativeFlag());
2447 EXPECT_FALSE(cpu.GetZeroFlag());
2451 cpu.SetAccumulatorSize(
true);
2453 std::vector<uint8_t> data = {0x56, 0x80};
2454 mock_memory.SetMemoryContents(data);
2455 mock_memory.InsertMemory(0x0082, {0x42});
2457 cpu.ExecuteInstruction(0x56);
2458 EXPECT_EQ(mock_memory[0x0082], 0x21);
2459 EXPECT_FALSE(cpu.GetNegativeFlag());
2460 EXPECT_FALSE(cpu.GetZeroFlag());
2464 cpu.SetAccumulatorSize(
true);
2466 std::vector<uint8_t> data = {0x5E, 0x7F, 0xFF};
2467 mock_memory.SetMemoryContents(data);
2468 mock_memory.InsertMemory(0x8001, {0x42});
2470 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2472 cpu.ExecuteInstruction(0x5E);
2473 EXPECT_EQ(mock_memory[0x8001], 0x21);
2474 EXPECT_FALSE(cpu.GetNegativeFlag());
2475 EXPECT_FALSE(cpu.GetZeroFlag());
2482 cpu.SetAccumulatorSize(
true);
2485 std::vector<uint8_t> data = {0x01, 0x3C};
2486 mock_memory.SetMemoryContents(data);
2487 mock_memory.InsertMemory(0x00023E, {0x00, 0x10});
2489 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2490 EXPECT_CALL(mock_memory, ReadWord(0x00023E)).WillOnce(Return(0x1000));
2492 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x80));
2494 cpu.ExecuteInstruction(0x01);
2495 EXPECT_EQ(cpu.A, 0x80);
2496 EXPECT_TRUE(cpu.GetNegativeFlag());
2497 EXPECT_FALSE(cpu.GetZeroFlag());
2501 cpu.SetAccumulatorSize(
true);
2503 mock_memory.SetSP(0x01FF);
2504 std::vector<uint8_t> data = {0x03, 0x02};
2505 mock_memory.SetMemoryContents(data);
2506 mock_memory.InsertMemory(0x0201, {0x7F});
2508 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
2509 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
2510 EXPECT_CALL(mock_memory, ReadByte(0x0201)).WillOnce(Return(0x7F));
2512 cpu.ExecuteInstruction(0x03);
2513 EXPECT_EQ(cpu.A, 0x7F);
2514 EXPECT_FALSE(cpu.GetNegativeFlag());
2515 EXPECT_FALSE(cpu.GetZeroFlag());
2519 cpu.SetAccumulatorSize(
true);
2521 std::vector<uint8_t> data = {0x05, 0x3C, 0x00};
2522 mock_memory.SetMemoryContents(data);
2523 mock_memory.InsertMemory(0x00023C, {0x80});
2525 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2526 EXPECT_CALL(mock_memory, ReadByte(0x00023C)).WillOnce(Return(0x80));
2528 cpu.ExecuteInstruction(0x05);
2529 EXPECT_EQ(cpu.A, 0x80);
2530 EXPECT_TRUE(cpu.GetNegativeFlag());
2531 EXPECT_FALSE(cpu.GetZeroFlag());
2535 cpu.SetAccumulatorSize(
true);
2537 std::vector<uint8_t> data = {0x07, 0x3C, 0x00};
2538 mock_memory.SetMemoryContents(data);
2539 mock_memory.InsertMemory(0x00023C, {0x00, 0x10, 0x00});
2541 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2542 EXPECT_CALL(mock_memory, ReadWordLong(0x00023C)).WillOnce(Return(0x1000));
2544 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x80));
2546 cpu.ExecuteInstruction(0x07);
2547 EXPECT_EQ(cpu.A, 0x80);
2548 EXPECT_TRUE(cpu.GetNegativeFlag());
2549 EXPECT_FALSE(cpu.GetZeroFlag());
2553 cpu.SetAccumulatorSize(
true);
2554 std::vector<uint8_t> data = {0x09, 0xFF};
2555 mock_memory.SetMemoryContents(data);
2557 cpu.ExecuteInstruction(0x09);
2558 EXPECT_EQ(cpu.A, 0xFF);
2559 EXPECT_TRUE(cpu.GetNegativeFlag());
2560 EXPECT_FALSE(cpu.GetZeroFlag());
2564 cpu.SetAccumulatorSize(
true);
2565 std::vector<uint8_t> data = {0x0D, 0x7F, 0xFF};
2566 mock_memory.SetMemoryContents(data);
2567 mock_memory.InsertMemory(0x7FFF, {0x7F});
2569 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2571 EXPECT_CALL(mock_memory, ReadByte(0x7FFF)).WillOnce(Return(0x7F));
2573 cpu.SetAccumulatorSize(
true);
2574 cpu.ExecuteInstruction(0x0D);
2575 EXPECT_EQ(cpu.A, 0x7F);
2576 EXPECT_FALSE(cpu.GetZeroFlag());
2580 cpu.SetAccumulatorSize(
true);
2581 std::vector<uint8_t> data = {0x0F, 0x7F, 0xFF, 0x00};
2582 mock_memory.SetMemoryContents(data);
2583 mock_memory.InsertMemory(0x7FFF, {0x7F});
2585 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x7FFF));
2587 EXPECT_CALL(mock_memory, ReadByte(0x7FFF)).WillOnce(Return(0x7F));
2589 cpu.SetAccumulatorSize(
true);
2590 cpu.ExecuteInstruction(0x0F);
2591 EXPECT_EQ(cpu.A, 0x7F);
2592 EXPECT_FALSE(cpu.GetZeroFlag());
2596 cpu.SetAccumulatorSize(
true);
2599 std::vector<uint8_t> data = {0x11, 0x3C};
2600 mock_memory.SetMemoryContents(data);
2601 mock_memory.InsertMemory(0x00023C, {0x00, 0x10});
2602 mock_memory.InsertMemory(0x1002, {0x80});
2604 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2605 EXPECT_CALL(mock_memory, ReadWord(0x00023C)).WillOnce(Return(0x1000));
2607 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0x80));
2609 cpu.ExecuteInstruction(0x11);
2610 EXPECT_EQ(cpu.A, 0x80);
2611 EXPECT_TRUE(cpu.GetNegativeFlag());
2612 EXPECT_FALSE(cpu.GetZeroFlag());
2616 cpu.SetAccumulatorSize(
true);
2618 std::vector<uint8_t> data = {0x12, 0x3C};
2619 mock_memory.SetMemoryContents(data);
2620 mock_memory.InsertMemory(0x00023C, {0x00, 0x10});
2622 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2623 EXPECT_CALL(mock_memory, ReadWord(0x00023C)).WillOnce(Return(0x1000));
2625 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x7F));
2627 cpu.ExecuteInstruction(0x12);
2628 EXPECT_EQ(cpu.A, 0x7F);
2629 EXPECT_FALSE(cpu.GetZeroFlag());
2633 cpu.SetAccumulatorSize(
true);
2636 std::vector<uint8_t> data = {0x13, 0x02};
2637 mock_memory.SetMemoryContents(data);
2638 mock_memory.InsertMemory(0x0201, {0x00, 0x10});
2640 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
2641 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x02));
2642 EXPECT_CALL(mock_memory, ReadWord(0x0201)).WillOnce(Return(0x1000));
2644 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0x80));
2646 cpu.ExecuteInstruction(0x13);
2647 EXPECT_EQ(cpu.A, 0x80);
2648 EXPECT_TRUE(cpu.GetNegativeFlag());
2649 EXPECT_FALSE(cpu.GetZeroFlag());
2653 cpu.SetAccumulatorSize(
true);
2656 std::vector<uint8_t> data = {0x15, 0x3C};
2657 mock_memory.SetMemoryContents(data);
2658 mock_memory.InsertMemory(0x00023E, {0x80});
2660 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2661 EXPECT_CALL(mock_memory, ReadByte(0x00023E)).WillOnce(Return(0x80));
2663 cpu.ExecuteInstruction(0x15);
2664 EXPECT_EQ(cpu.A, 0x80);
2665 EXPECT_TRUE(cpu.GetNegativeFlag());
2666 EXPECT_FALSE(cpu.GetZeroFlag());
2670 cpu.SetAccumulatorSize(
true);
2673 std::vector<uint8_t> data = {0x17, 0x3C};
2674 mock_memory.SetMemoryContents(data);
2675 mock_memory.InsertMemory(0x00023C, {0x00, 0x10, 0x00});
2677 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
2678 EXPECT_CALL(mock_memory, ReadWordLong(0x00023C)).WillOnce(Return(0x1000));
2680 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0x80));
2682 cpu.ExecuteInstruction(0x17);
2683 EXPECT_EQ(cpu.A, 0x80);
2684 EXPECT_TRUE(cpu.GetNegativeFlag());
2685 EXPECT_FALSE(cpu.GetZeroFlag());
2689 cpu.SetAccumulatorSize(
true);
2691 std::vector<uint8_t> data = {0x19, 0x7F, 0xFF};
2692 mock_memory.SetMemoryContents(data);
2693 mock_memory.InsertMemory(0x8001, {0x7F});
2695 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2697 EXPECT_CALL(mock_memory, ReadByte(0x8001)).WillOnce(Return(0x7F));
2699 cpu.ExecuteInstruction(0x19);
2700 EXPECT_EQ(cpu.A, 0x7F);
2701 EXPECT_FALSE(cpu.GetZeroFlag());
2705 cpu.SetAccumulatorSize(
true);
2707 std::vector<uint8_t> data = {0x1D, 0x7F, 0xFF};
2708 mock_memory.SetMemoryContents(data);
2709 mock_memory.InsertMemory(0x8001, {0x7F});
2711 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2713 EXPECT_CALL(mock_memory, ReadByte(0x8001)).WillOnce(Return(0x7F));
2715 cpu.ExecuteInstruction(0x1D);
2716 EXPECT_EQ(cpu.A, 0x7F);
2717 EXPECT_FALSE(cpu.GetZeroFlag());
2721 cpu.SetAccumulatorSize(
true);
2723 std::vector<uint8_t> data = {0x1F, 0x7F, 0xFF, 0x00};
2724 mock_memory.SetMemoryContents(data);
2725 mock_memory.InsertMemory(0x8001, {0x7F});
2727 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x7FFF));
2729 EXPECT_CALL(mock_memory, ReadByte(0x8001)).WillOnce(Return(0x7F));
2731 cpu.ExecuteInstruction(0x1F);
2732 EXPECT_EQ(cpu.A, 0x7F);
2733 EXPECT_FALSE(cpu.GetZeroFlag());
2739 cpu.SetAccumulatorSize(
true);
2740 std::vector<uint8_t> data = {0xF4, 0x7F, 0xFF};
2741 mock_memory.SetMemoryContents(data);
2743 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2744 EXPECT_CALL(mock_memory, PushWord(0x7FFF));
2746 cpu.ExecuteInstruction(0xF4);
2750 cpu.SetAccumulatorSize(
true);
2751 std::vector<uint8_t> data = {0xD4, 0x3C, 0x00};
2752 mock_memory.SetMemoryContents(data);
2753 mock_memory.InsertMemory(0x00003C, {0x00, 0x10});
2755 EXPECT_CALL(mock_memory, ReadWord(0x000001)).WillOnce(Return(0x3C));
2756 EXPECT_CALL(mock_memory, ReadWord(0x00003C)).WillOnce(Return(0x1000));
2758 EXPECT_CALL(mock_memory, PushWord(0x1000));
2760 cpu.ExecuteInstruction(0xD4);
2764 cpu.SetAccumulatorSize(
true);
2765 std::vector<uint8_t> data = {0x62, 0x7F, 0xFF};
2766 mock_memory.SetMemoryContents(data);
2768 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
2769 EXPECT_CALL(mock_memory, PushWord(0x7FFF));
2771 cpu.ExecuteInstruction(0x62);
2863 cpu.SetAccumulatorSize(
true);
2865 std::vector<uint8_t> data = {0x68};
2866 mock_memory.SetMemoryContents(data);
2867 mock_memory.InsertMemory(0x0001, {0x7F});
2869 EXPECT_CALL(mock_memory, PopByte()).WillOnce(Return(0x7F));
2871 cpu.ExecuteInstruction(0x68);
2872 EXPECT_EQ(cpu.A, 0x7F);
2876 cpu.SetAccumulatorSize(
false);
2878 std::vector<uint8_t> data = {0x68};
2879 mock_memory.SetMemoryContents(data);
2880 mock_memory.InsertMemory(0x0001, {0x7F, 0xFF});
2882 EXPECT_CALL(mock_memory, PopWord()).WillOnce(Return(0x7FFF));
2884 cpu.ExecuteInstruction(0x68);
2885 EXPECT_EQ(cpu.A, 0x7FFF);
2889 cpu.SetAccumulatorSize(
true);
2891 std::vector<uint8_t> data = {0xAB};
2892 mock_memory.SetMemoryContents(data);
2893 mock_memory.InsertMemory(0x0001, {0x7F});
2895 EXPECT_CALL(mock_memory, PopByte()).WillOnce(Return(0x7F));
2897 cpu.ExecuteInstruction(0xAB);
2898 EXPECT_EQ(cpu.DB, 0x7F);
2902 cpu.SetAccumulatorSize(
true);
2904 std::vector<uint8_t> data = {0x2B};
2905 mock_memory.SetMemoryContents(data);
2906 mock_memory.InsertMemory(0x0001, {0x7F, 0xFF});
2908 EXPECT_CALL(mock_memory, PopWord()).WillOnce(Return(0x7FFF));
2910 cpu.ExecuteInstruction(0x2B);
2911 EXPECT_EQ(cpu.D, 0x7FFF);
2915 cpu.SetAccumulatorSize(
true);
2917 std::vector<uint8_t> data = {0x28};
2918 mock_memory.SetMemoryContents(data);
2919 mock_memory.InsertMemory(0x0001, {0x7F});
2921 EXPECT_CALL(mock_memory, PopByte()).WillOnce(Return(0x7F));
2923 cpu.ExecuteInstruction(0x28);
2924 EXPECT_EQ(cpu.status, 0x7F);
2928 cpu.SetAccumulatorSize(
true);
2930 std::vector<uint8_t> data = {0xFA};
2931 mock_memory.SetMemoryContents(data);
2932 mock_memory.InsertMemory(0x0001, {0x7F});
2934 EXPECT_CALL(mock_memory, PopByte()).WillOnce(Return(0x7F));
2936 cpu.ExecuteInstruction(0xFA);
2937 EXPECT_EQ(cpu.X, 0x7F);
2941 cpu.SetIndexSize(
false);
2944 std::vector<uint8_t> data = {0xFA};
2945 mock_memory.SetMemoryContents(data);
2946 mock_memory.InsertMemory(0x01FF, {0x7F, 0xFF});
2948 EXPECT_CALL(mock_memory, PopWord()).WillOnce(Return(0x7FFF));
2950 cpu.ExecuteInstruction(0xFA);
2951 EXPECT_EQ(cpu.X, 0x7FFF);
2955 cpu.SetIndexSize(
true);
2957 std::vector<uint8_t> data = {0x7A};
2958 mock_memory.SetMemoryContents(data);
2959 mock_memory.InsertMemory(0x0001, {0x7F});
2961 EXPECT_CALL(mock_memory, PopByte()).WillOnce(Return(0x7F));
2963 cpu.ExecuteInstruction(0x7A);
2964 EXPECT_EQ(cpu.Y, 0x7F);
2968 cpu.SetIndexSize(
false);
2970 std::vector<uint8_t> data = {0x7A};
2971 mock_memory.SetMemoryContents(data);
2972 mock_memory.InsertMemory(0x0001, {0x7F, 0xFF});
2974 EXPECT_CALL(mock_memory, PopWord()).WillOnce(Return(0x7FFF));
2976 cpu.ExecuteInstruction(0x7A);
2977 EXPECT_EQ(cpu.Y, 0x7FFF);
3014 cpu.SetNegativeFlag(
true);
3015 cpu.SetZeroFlag(
false);
3016 EXPECT_TRUE(cpu.GetNegativeFlag());
3017 EXPECT_FALSE(cpu.GetZeroFlag());
3019 EXPECT_CALL(mock_memory, PushByte(0x80)).WillOnce(Return());
3023 cpu.SetNegativeFlag(
false);
3024 cpu.SetZeroFlag(
true);
3025 EXPECT_FALSE(cpu.GetNegativeFlag());
3026 EXPECT_TRUE(cpu.GetZeroFlag());
3028 EXPECT_CALL(mock_memory, PopByte()).WillOnce(Return(0x80));
3031 EXPECT_TRUE(cpu.GetNegativeFlag());
3032 EXPECT_FALSE(cpu.GetZeroFlag());
3092 EXPECT_CALL(mock_memory, PopByte()).WillOnce(Return(0x34));
3093 cpu.ExecuteInstruction(0x28);
3094 EXPECT_EQ(cpu.status, 0x34);
3126 std::vector<uint8_t> data = {0xE2, 0x30,
3128 mock_memory.SetMemoryContents(data);
3130 cpu.ExecuteInstruction(0xE2);
3131 EXPECT_EQ(cpu.status, 0x30);
3137 cpu.SetAccumulatorSize(
true);
3138 std::vector<uint8_t> data = {0x26, 0x80};
3139 mock_memory.SetMemoryContents(data);
3140 mock_memory.InsertMemory(0x0080, {0x42});
3142 cpu.ExecuteInstruction(0x26);
3143 EXPECT_EQ(mock_memory[0x0080], 0x84);
3144 EXPECT_TRUE(cpu.GetNegativeFlag());
3145 EXPECT_FALSE(cpu.GetZeroFlag());
3158 cpu.SetAccumulatorSize(
true);
3159 std::vector<uint8_t> data = {0x2E, 0x7F, 0xFF};
3160 mock_memory.SetMemoryContents(data);
3161 mock_memory.InsertMemory(0x7FFF, {0x42});
3163 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3165 cpu.ExecuteInstruction(0x2E);
3166 EXPECT_EQ(mock_memory[0x7FFF], 0x84);
3167 EXPECT_TRUE(cpu.GetNegativeFlag());
3168 EXPECT_FALSE(cpu.GetZeroFlag());
3172 cpu.SetAccumulatorSize(
true);
3174 std::vector<uint8_t> data = {0x36, 0x80};
3175 mock_memory.SetMemoryContents(data);
3176 mock_memory.InsertMemory(0x0082, {0x42});
3178 cpu.ExecuteInstruction(0x36);
3179 EXPECT_EQ(mock_memory[0x0082], 0x84);
3180 EXPECT_TRUE(cpu.GetNegativeFlag());
3181 EXPECT_FALSE(cpu.GetZeroFlag());
3185 cpu.SetAccumulatorSize(
true);
3187 std::vector<uint8_t> data = {0x3E, 0x7F, 0xFF};
3188 mock_memory.SetMemoryContents(data);
3189 mock_memory.InsertMemory(0x8001, {0x42});
3191 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3193 cpu.ExecuteInstruction(0x3E);
3194 EXPECT_EQ(mock_memory[0x8001], 0x84);
3195 EXPECT_TRUE(cpu.GetNegativeFlag());
3196 EXPECT_FALSE(cpu.GetZeroFlag());
3202 cpu.SetAccumulatorSize(
true);
3203 std::vector<uint8_t> data = {0x66, 0x80};
3204 mock_memory.SetMemoryContents(data);
3205 mock_memory.InsertMemory(0x0080, {0x42});
3207 cpu.ExecuteInstruction(0x66);
3208 EXPECT_EQ(mock_memory[0x0080], 0x21);
3209 EXPECT_FALSE(cpu.GetNegativeFlag());
3210 EXPECT_FALSE(cpu.GetZeroFlag());
3223 cpu.SetAccumulatorSize(
true);
3224 std::vector<uint8_t> data = {0x6E, 0x7F, 0xFF};
3225 mock_memory.SetMemoryContents(data);
3226 mock_memory.InsertMemory(0x7FFF, {0x42});
3228 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3230 cpu.ExecuteInstruction(0x6E);
3231 EXPECT_EQ(mock_memory[0x7FFF], 0x21);
3232 EXPECT_FALSE(cpu.GetNegativeFlag());
3233 EXPECT_FALSE(cpu.GetZeroFlag());
3237 cpu.SetAccumulatorSize(
true);
3239 std::vector<uint8_t> data = {0x76, 0x80};
3240 mock_memory.SetMemoryContents(data);
3241 mock_memory.InsertMemory(0x0082, {0x42});
3243 cpu.ExecuteInstruction(0x76);
3244 EXPECT_EQ(mock_memory[0x0082], 0x21);
3245 EXPECT_FALSE(cpu.GetNegativeFlag());
3246 EXPECT_FALSE(cpu.GetZeroFlag());
3250 cpu.SetAccumulatorSize(
true);
3252 std::vector<uint8_t> data = {0x7E, 0x7F, 0xFF};
3253 mock_memory.SetMemoryContents(data);
3254 mock_memory.InsertMemory(0x8001, {0x42});
3256 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3258 cpu.ExecuteInstruction(0x7E);
3259 EXPECT_EQ(mock_memory[0x8001], 0x21);
3260 EXPECT_FALSE(cpu.GetNegativeFlag());
3261 EXPECT_FALSE(cpu.GetZeroFlag());
3267 cpu.SetAccumulatorSize(
true);
3269 std::vector<uint8_t> data = {0x40};
3270 mock_memory.SetMemoryContents(data);
3271 mock_memory.InsertMemory(0x0001, {0x7F});
3273 EXPECT_CALL(mock_memory, PopByte()).WillOnce(Return(0x7F));
3275 cpu.ExecuteInstruction(0x40);
3276 EXPECT_EQ(cpu.status, 0x7F);
3282 cpu.SetAccumulatorSize(
true);
3284 std::vector<uint8_t> data = {0x6B};
3285 mock_memory.SetMemoryContents(data);
3286 mock_memory.InsertMemory(0x0001, {0x7F, 0xFF});
3288 EXPECT_CALL(mock_memory, PopWord()).WillOnce(Return(0x7FFF));
3290 cpu.ExecuteInstruction(0x6B);
3291 EXPECT_EQ(cpu.PC, 0x7FFF);
3297 cpu.SetAccumulatorSize(
true);
3299 std::vector<uint8_t> data = {0x60};
3300 mock_memory.SetMemoryContents(data);
3301 mock_memory.InsertMemory(0x0001, {0x7F, 0xFF});
3303 EXPECT_CALL(mock_memory, PopWord()).WillOnce(Return(0x7FFF));
3305 cpu.ExecuteInstruction(0x60);
3306 EXPECT_EQ(cpu.PC, 0x7FFF + 3);
3312 cpu.SetAccumulatorSize(
true);
3317 std::vector<uint8_t> data = {0xE1, 0x3C};
3318 mock_memory.SetMemoryContents(data);
3319 mock_memory.InsertMemory(0x00023E, {0x80});
3320 mock_memory.InsertMemory(0x0080, {0x80});
3322 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3323 EXPECT_CALL(mock_memory, ReadWord(0x00023E)).WillOnce(Return(0x80));
3324 EXPECT_CALL(mock_memory, ReadByte(0x0080)).WillOnce(Return(0x80));
3326 cpu.ExecuteInstruction(0xE1);
3327 EXPECT_EQ(cpu.A, 0x90);
3328 EXPECT_TRUE(cpu.GetNegativeFlag());
3329 EXPECT_FALSE(cpu.GetZeroFlag());
3333 std::vector<uint8_t> data = {0xE3, 0x3C};
3334 mock_memory.SetMemoryContents(data);
3335 cpu.SetAccumulatorSize(
true);
3337 mock_memory.SetSP(0x01FF);
3338 mock_memory.InsertMemory(0x00003E, {0x02});
3339 mock_memory.InsertMemory(0x2002, {0x80});
3341 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
3344 cpu.ExecuteInstruction(0xE3);
3345 EXPECT_EQ(cpu.A, 0x00);
3346 EXPECT_FALSE(cpu.GetNegativeFlag());
3347 EXPECT_TRUE(cpu.GetZeroFlag());
3351 std::vector<uint8_t> data = {0xE5, 0x80};
3352 mock_memory.SetMemoryContents(data);
3355 cpu.SetAccumulatorSize(
true);
3359 mock_memory.InsertMemory(0x0180, {0x01});
3361 cpu.ExecuteInstruction(0xE5);
3362 EXPECT_EQ(cpu.A, 0x41);
3363 EXPECT_FALSE(cpu.GetNegativeFlag());
3364 EXPECT_FALSE(cpu.GetZeroFlag());
3368 cpu.SetAccumulatorSize(
true);
3371 std::vector<uint8_t> data = {0xE7, 0x3C};
3372 mock_memory.SetMemoryContents(data);
3373 mock_memory.InsertMemory(0x00003C, {0x00, 0x10, 0x00});
3374 mock_memory.InsertMemory(0x1000, {0x8F});
3376 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3377 EXPECT_CALL(mock_memory, ReadWordLong(0x00003C)).WillOnce(Return(0x1000));
3379 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x8F));
3381 cpu.ExecuteInstruction(0xE7);
3382 EXPECT_EQ(cpu.A, 0xF1);
3383 EXPECT_TRUE(cpu.GetNegativeFlag());
3384 EXPECT_FALSE(cpu.GetZeroFlag());
3388 cpu.SetAccumulatorSize(
true);
3391 std::vector<uint8_t> data = {0xE9, 0x80};
3392 mock_memory.SetMemoryContents(data);
3394 cpu.ExecuteInstruction(0xE9);
3395 EXPECT_EQ(cpu.A, 0x00);
3396 EXPECT_FALSE(cpu.GetNegativeFlag());
3397 EXPECT_TRUE(cpu.GetZeroFlag());
3401 cpu.SetAccumulatorSize(
true);
3404 std::vector<uint8_t> data = {0xED, 0x7F, 0xFF};
3405 mock_memory.SetMemoryContents(data);
3406 mock_memory.InsertMemory(0x7FFF, {0x80});
3408 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3410 cpu.ExecuteInstruction(0xED);
3411 EXPECT_EQ(cpu.A, 0x7F);
3412 EXPECT_FALSE(cpu.GetNegativeFlag());
3413 EXPECT_FALSE(cpu.GetZeroFlag());
3417 cpu.SetAccumulatorSize(
true);
3420 std::vector<uint8_t> data = {0xEF, 0x7F, 0xFF, 0xFF, 0xFF};
3421 mock_memory.SetMemoryContents(data);
3422 mock_memory.InsertMemory(0x7FFFFF, {0x80});
3424 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x7FFFFF));
3426 cpu.ExecuteInstruction(0xEF);
3427 EXPECT_EQ(cpu.A, 0x7F);
3428 EXPECT_FALSE(cpu.GetNegativeFlag());
3429 EXPECT_FALSE(cpu.GetZeroFlag());
3433 cpu.SetAccumulatorSize(
true);
3437 std::vector<uint8_t> data = {0xF1, 0x3C};
3438 mock_memory.SetMemoryContents(data);
3439 mock_memory.InsertMemory(0x00003E, {0x00, 0x10});
3441 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3442 EXPECT_CALL(mock_memory, ReadWord(0x00003C)).WillOnce(Return(0x1000));
3444 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0x80));
3446 cpu.ExecuteInstruction(0xF1);
3447 EXPECT_EQ(cpu.A, 0x7F);
3448 EXPECT_FALSE(cpu.GetNegativeFlag());
3449 EXPECT_FALSE(cpu.GetZeroFlag());
3453 cpu.SetAccumulatorSize(
true);
3457 std::vector<uint8_t> data = {0xF2, 0x3C};
3458 mock_memory.SetMemoryContents(data);
3459 mock_memory.InsertMemory(0x00023C, {0x00, 0x10});
3460 mock_memory.InsertMemory(0x1000, {0x80});
3462 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3464 EXPECT_CALL(mock_memory, ReadWord(0x00023C)).WillOnce(Return(0x1000));
3466 EXPECT_CALL(mock_memory, ReadByte(0x1000)).WillOnce(Return(0x80));
3468 cpu.ExecuteInstruction(0xF2);
3469 EXPECT_EQ(cpu.A, 0x90);
3470 EXPECT_TRUE(cpu.GetNegativeFlag());
3471 EXPECT_FALSE(cpu.GetZeroFlag());
3475 cpu.SetAccumulatorSize(
true);
3479 mock_memory.SetSP(0x01FF);
3480 std::vector<uint8_t> data = {0xF3, 0x02};
3481 mock_memory.SetMemoryContents(data);
3482 mock_memory.InsertMemory(0x0201, {0x00, 0x30});
3483 mock_memory.InsertMemory(0x3002, {0x80});
3485 EXPECT_CALL(mock_memory, SP()).WillRepeatedly(Return(0x01FF));
3486 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x02));
3487 EXPECT_CALL(mock_memory, ReadWord(0x0201)).WillOnce(Return(0x3000));
3488 EXPECT_CALL(mock_memory, ReadByte(0x3002)).WillOnce(Return(0x80));
3490 cpu.ExecuteInstruction(0xF3);
3491 EXPECT_EQ(cpu.A, 0x7F);
3492 EXPECT_FALSE(cpu.GetNegativeFlag());
3493 EXPECT_FALSE(cpu.GetZeroFlag());
3497 cpu.SetAccumulatorSize(
true);
3500 std::vector<uint8_t> data = {0xF5, 0x80};
3501 mock_memory.SetMemoryContents(data);
3502 mock_memory.InsertMemory(0x0082, {0x01});
3504 cpu.ExecuteInstruction(0xF5);
3505 EXPECT_EQ(cpu.A, 0xFF);
3506 EXPECT_TRUE(cpu.GetNegativeFlag());
3507 EXPECT_FALSE(cpu.GetZeroFlag());
3511 cpu.SetAccumulatorSize(
true);
3515 std::vector<uint8_t> data = {0xF7, 0x3C};
3516 mock_memory.SetMemoryContents(data);
3517 mock_memory.InsertMemory(0x00003C, {0x00, 0x10, 0x00});
3519 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3520 EXPECT_CALL(mock_memory, ReadWordLong(0x00003C)).WillOnce(Return(0x1000));
3522 EXPECT_CALL(mock_memory, ReadByte(0x1002)).WillOnce(Return(0x80));
3524 cpu.ExecuteInstruction(0xF7);
3525 EXPECT_EQ(cpu.A, 0x7F);
3526 EXPECT_FALSE(cpu.GetNegativeFlag());
3527 EXPECT_FALSE(cpu.GetZeroFlag());
3531 cpu.SetAccumulatorSize(
true);
3535 std::vector<uint8_t> data = {0xF9, 0x7F, 0xFF};
3536 mock_memory.SetMemoryContents(data);
3537 mock_memory.InsertMemory(0x8001, {0x80});
3539 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3541 cpu.ExecuteInstruction(0xF9);
3542 EXPECT_EQ(cpu.A, 0x7F);
3543 EXPECT_FALSE(cpu.GetNegativeFlag());
3544 EXPECT_FALSE(cpu.GetZeroFlag());
3548 cpu.SetAccumulatorSize(
true);
3552 std::vector<uint8_t> data = {0xFD, 0x7F, 0xFF};
3553 mock_memory.SetMemoryContents(data);
3554 mock_memory.InsertMemory(0x8001, {0x80});
3556 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3558 cpu.ExecuteInstruction(0xFD);
3559 EXPECT_EQ(cpu.A, 0x7F);
3560 EXPECT_FALSE(cpu.GetNegativeFlag());
3561 EXPECT_FALSE(cpu.GetZeroFlag());
3565 cpu.SetAccumulatorSize(
true);
3569 std::vector<uint8_t> data = {0xFF, 0x7F, 0xFF, 0xFF, 0xFF};
3570 mock_memory.SetMemoryContents(data);
3571 mock_memory.InsertMemory(0x800001, {0x80});
3573 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x7FFFFF));
3575 cpu.ExecuteInstruction(0xFF);
3576 EXPECT_EQ(cpu.A, 0x7F);
3577 EXPECT_FALSE(cpu.GetNegativeFlag());
3578 EXPECT_FALSE(cpu.GetZeroFlag());
3629 cpu.SetAccumulatorSize(
true);
3632 std::vector<uint8_t> data = {0x81, 0x3C};
3633 mock_memory.SetMemoryContents(data);
3634 mock_memory.InsertMemory(0x00003E, {0x00, 0x10});
3636 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3637 EXPECT_CALL(mock_memory, ReadWord(0x00003E)).WillOnce(Return(0x1000));
3639 EXPECT_CALL(mock_memory, WriteByte(0x1000, 0x42));
3641 cpu.ExecuteInstruction(0x81);
3642 EXPECT_EQ(cpu.A, 0x42);
3646 cpu.SetAccumulatorSize(
true);
3648 mock_memory.SetSP(0x01FF);
3649 std::vector<uint8_t> data = {0x83, 0x3C};
3650 mock_memory.SetMemoryContents(data);
3652 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3654 EXPECT_CALL(mock_memory, WriteByte(0x023B, 0x42));
3656 cpu.ExecuteInstruction(0x83);
3660 cpu.SetAccumulatorSize(
true);
3662 std::vector<uint8_t> data = {0x85, 0x80};
3663 mock_memory.SetMemoryContents(data);
3665 EXPECT_CALL(mock_memory, WriteByte(0x0080, 0x42));
3667 cpu.ExecuteInstruction(0x85);
3671 cpu.SetAccumulatorSize(
true);
3673 std::vector<uint8_t> data = {0x87, 0x3C};
3674 mock_memory.SetMemoryContents(data);
3675 mock_memory.InsertMemory(0x00003C, {0x00, 0x10, 0x00});
3677 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3678 EXPECT_CALL(mock_memory, ReadWordLong(0x00003C)).WillOnce(Return(0x1000));
3680 EXPECT_CALL(mock_memory, WriteByte(0x1000, 0x42));
3682 cpu.ExecuteInstruction(0x87);
3686 cpu.SetAccumulatorSize(
true);
3688 std::vector<uint8_t> data = {0x8D, 0xFF, 0x7F};
3689 mock_memory.SetMemoryContents(data);
3691 EXPECT_CALL(mock_memory, WriteByte(0x7FFF, 0x42));
3693 cpu.ExecuteInstruction(0x8D);
3697 cpu.SetAccumulatorSize(
true);
3699 std::vector<uint8_t> data = {0x8F, 0xFF, 0x7F};
3700 mock_memory.SetMemoryContents(data);
3702 EXPECT_CALL(mock_memory, WriteByte(0x7FFF, 0x42));
3704 cpu.ExecuteInstruction(0x8F);
3708 cpu.SetAccumulatorSize(
true);
3711 std::vector<uint8_t> data = {0x91, 0x3C};
3712 mock_memory.SetMemoryContents(data);
3713 mock_memory.InsertMemory(0x00003E, {0x00, 0x10});
3715 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3716 EXPECT_CALL(mock_memory, ReadWord(0x00003C)).WillOnce(Return(0x1000));
3718 EXPECT_CALL(mock_memory, WriteByte(0x1002, 0x42));
3720 cpu.ExecuteInstruction(0x91);
3724 cpu.SetAccumulatorSize(
true);
3727 std::vector<uint8_t> data = {0x92, 0x3C};
3728 mock_memory.SetMemoryContents(data);
3729 mock_memory.InsertMemory(0x00003C, {0x00, 0x10});
3731 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3732 EXPECT_CALL(mock_memory, ReadWord(0x00003C)).WillOnce(Return(0x1000));
3734 EXPECT_CALL(mock_memory, WriteByte(0x1000, 0x42));
3736 cpu.ExecuteInstruction(0x92);
3740 cpu.SetAccumulatorSize(
true);
3743 mock_memory.SetSP(0x01FF);
3744 std::vector<uint8_t> data = {0x93, 0x3C};
3745 mock_memory.SetMemoryContents(data);
3746 mock_memory.InsertMemory(0x00023B, {0x00, 0x10});
3748 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3749 EXPECT_CALL(mock_memory, ReadWord(0x00023B)).WillOnce(Return(0x1000));
3751 EXPECT_CALL(mock_memory, WriteByte(0x1002, 0x42));
3753 cpu.ExecuteInstruction(0x93);
3757 cpu.SetAccumulatorSize(
true);
3760 std::vector<uint8_t> data = {0x95, 0x80};
3761 mock_memory.SetMemoryContents(data);
3763 EXPECT_CALL(mock_memory, WriteByte(0x0082, 0x42));
3765 cpu.ExecuteInstruction(0x95);
3769 cpu.SetAccumulatorSize(
true);
3772 std::vector<uint8_t> data = {0x97, 0x3C};
3773 mock_memory.SetMemoryContents(data);
3774 mock_memory.InsertMemory(0x00003C, {0x00, 0x10, 0x00});
3776 EXPECT_CALL(mock_memory, ReadByte(0x000001)).WillOnce(Return(0x3C));
3777 EXPECT_CALL(mock_memory, ReadWordLong(0x00003C)).WillOnce(Return(0x1000));
3779 EXPECT_CALL(mock_memory, WriteByte(0x1002, 0x42));
3781 cpu.ExecuteInstruction(0x97);
3785 cpu.SetAccumulatorSize(
true);
3788 std::vector<uint8_t> data = {0x99, 0x7F, 0xFF};
3789 mock_memory.SetMemoryContents(data);
3791 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3792 EXPECT_CALL(mock_memory, WriteByte(0x8001, 0x42));
3794 cpu.ExecuteInstruction(0x99);
3798 cpu.SetAccumulatorSize(
true);
3801 std::vector<uint8_t> data = {0x9D, 0x7F, 0xFF};
3802 mock_memory.SetMemoryContents(data);
3804 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3805 EXPECT_CALL(mock_memory, WriteByte(0x8001, 0x42));
3807 cpu.ExecuteInstruction(0x9D);
3811 cpu.SetAccumulatorSize(
true);
3814 std::vector<uint8_t> data = {0x9F, 0xFF, 0xFF, 0x7F};
3815 mock_memory.SetMemoryContents(data);
3817 EXPECT_CALL(mock_memory, ReadWordLong(0x0001)).WillOnce(Return(0x7FFFFF));
3818 EXPECT_CALL(mock_memory, WriteByte(0x800001, 0x42));
3820 cpu.ExecuteInstruction(0x9F);
3833 cpu.SetAccumulatorSize(
true);
3835 std::vector<uint8_t> data = {0x86, 0x80};
3836 mock_memory.SetMemoryContents(data);
3838 EXPECT_CALL(mock_memory, WriteByte(0x0080, 0x42));
3840 cpu.ExecuteInstruction(0x86);
3844 cpu.SetAccumulatorSize(
true);
3846 std::vector<uint8_t> data = {0x8E, 0x7F, 0xFF};
3847 mock_memory.SetMemoryContents(data);
3849 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3850 EXPECT_CALL(mock_memory, WriteByte(0x7FFF, 0x42));
3852 cpu.ExecuteInstruction(0x8E);
3856 cpu.SetAccumulatorSize(
true);
3859 std::vector<uint8_t> data = {0x96, 0x80};
3860 mock_memory.SetMemoryContents(data);
3862 EXPECT_CALL(mock_memory, WriteByte(0x0082, 0x42));
3864 cpu.ExecuteInstruction(0x96);
3870 cpu.SetAccumulatorSize(
true);
3872 std::vector<uint8_t> data = {0x84, 0x80};
3873 mock_memory.SetMemoryContents(data);
3875 EXPECT_CALL(mock_memory, WriteByte(0x0080, 0x42));
3877 cpu.ExecuteInstruction(0x84);
3881 cpu.SetAccumulatorSize(
true);
3883 std::vector<uint8_t> data = {0x8C, 0x7F, 0xFF};
3884 mock_memory.SetMemoryContents(data);
3886 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3887 EXPECT_CALL(mock_memory, WriteByte(0x7FFF, 0x42));
3889 cpu.ExecuteInstruction(0x8C);
3893 cpu.SetAccumulatorSize(
true);
3896 std::vector<uint8_t> data = {0x94, 0x80};
3897 mock_memory.SetMemoryContents(data);
3899 EXPECT_CALL(mock_memory, WriteByte(0x0082, 0x42));
3901 cpu.ExecuteInstruction(0x94);
3907 cpu.SetAccumulatorSize(
true);
3908 std::vector<uint8_t> data = {0x64, 0x80};
3909 mock_memory.SetMemoryContents(data);
3911 EXPECT_CALL(mock_memory, WriteByte(0x0080, 0x00));
3913 cpu.ExecuteInstruction(0x64);
3917 cpu.SetAccumulatorSize(
true);
3919 std::vector<uint8_t> data = {0x74, 0x80};
3920 mock_memory.SetMemoryContents(data);
3922 EXPECT_CALL(mock_memory, WriteByte(0x0082, 0x00));
3924 cpu.ExecuteInstruction(0x74);
3928 cpu.SetAccumulatorSize(
true);
3929 std::vector<uint8_t> data = {0x9C, 0x7F, 0xFF};
3930 mock_memory.SetMemoryContents(data);
3932 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
3933 EXPECT_CALL(mock_memory, WriteByte(0x7FFF, 0x00));
3935 cpu.ExecuteInstruction(0x9C);
3977 cpu.SetAccumulatorSize(
true);
3979 std::vector<uint8_t> data = {0x1B};
3980 mock_memory.SetMemoryContents(data);
3982 EXPECT_CALL(mock_memory, SetSP(0x42));
3984 cpu.ExecuteInstruction(0x1B);
3985 EXPECT_EQ(mock_memory.SP(), 0x42);
4003 cpu.SetAccumulatorSize(
true);
4005 std::vector<uint8_t> data = {0x14, 0x80};
4006 mock_memory.SetMemoryContents(data);
4007 mock_memory.InsertMemory(0x0080, {0x00});
4009 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x0080));
4010 EXPECT_CALL(mock_memory, ReadByte(0x0080)).WillOnce(Return(0x00));
4011 EXPECT_CALL(mock_memory, WriteByte(0x0080, 0x00));
4013 cpu.ExecuteInstruction(0x14);
4017 cpu.SetAccumulatorSize(
true);
4019 std::vector<uint8_t> data = {0x1C, 0xFF, 0x7F};
4020 mock_memory.SetMemoryContents(data);
4021 mock_memory.InsertMemory(0x7FFF, {0x00});
4023 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
4024 EXPECT_CALL(mock_memory, ReadByte(0x7FFF)).WillOnce(Return(0x00));
4025 EXPECT_CALL(mock_memory, WriteByte(0x7FFF, 0x00));
4027 cpu.ExecuteInstruction(0x1C);
4033 cpu.SetAccumulatorSize(
true);
4035 std::vector<uint8_t> data = {0x04, 0x80};
4036 mock_memory.SetMemoryContents(data);
4037 mock_memory.InsertMemory(0x0080, {0x42});
4039 EXPECT_CALL(mock_memory, ReadByte(0x0001)).WillOnce(Return(0x0080));
4040 EXPECT_CALL(mock_memory, ReadByte(0x0080)).WillOnce(Return(0x42));
4041 EXPECT_CALL(mock_memory, WriteByte(0x0080, 0x42));
4043 cpu.ExecuteInstruction(0x04);
4047 cpu.SetAccumulatorSize(
true);
4049 std::vector<uint8_t> data = {0x0C, 0xFF, 0x7F};
4050 mock_memory.SetMemoryContents(data);
4051 mock_memory.InsertMemory(0x7FFF, {0x42});
4053 EXPECT_CALL(mock_memory, ReadWord(0x0001)).WillOnce(Return(0x7FFF));
4054 EXPECT_CALL(mock_memory, ReadByte(0x7FFF)).WillOnce(Return(0x42));
4055 EXPECT_CALL(mock_memory, WriteByte(0x7FFF, 0x42));
4057 cpu.ExecuteInstruction(0x0C);
4188 cpu.ExecuteInstruction(0x18);
4189 cpu.ExecuteInstruction(0xFB);
4190 EXPECT_FALSE(cpu.E);
4192 cpu.ExecuteInstruction(0x38);
4193 cpu.ExecuteInstruction(0xFB);
4196 cpu.ExecuteInstruction(0x18);
4197 cpu.ExecuteInstruction(0xFB);
4198 EXPECT_FALSE(cpu.E);