aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cpu/instruction.spec.ts54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/cpu/instruction.spec.ts b/src/cpu/instruction.spec.ts
index 18ff76b..f257245 100644
--- a/src/cpu/instruction.spec.ts
+++ b/src/cpu/instruction.spec.ts
@@ -80,6 +80,41 @@ describe('avrInstruction', () => {
expect(cpu.data[SREG]).toEqual(SREG_H | SREG_Z | SREG_C);
});
+ it('should execute `ADD r0, r1` instruction when result overflows', () => {
+ loadProgram('ADD r0, r1');
+ cpu.data[r0] = 11;
+ cpu.data[r1] = 245;
+ avrInstruction(cpu);
+ expect(cpu.pc).toEqual(1);
+ expect(cpu.cycles).toEqual(1);
+ expect(cpu.data[r0]).toEqual(0);
+ expect(cpu.data[SREG]).toEqual(SREG_H | SREG_Z | SREG_C);
+ });
+
+ it('should execute `ADD r0, r1` instruction when carry is on', () => {
+ loadProgram('ADD r0, r1');
+ cpu.data[r0] = 11;
+ cpu.data[r1] = 244;
+ cpu.data[SREG] = SREG_C;
+ avrInstruction(cpu);
+ expect(cpu.pc).toEqual(1);
+ expect(cpu.cycles).toEqual(1);
+ expect(cpu.data[r0]).toEqual(255);
+ expect(cpu.data[SREG]).toEqual(SREG_S | SREG_N);
+ });
+
+ it('should execute `ADD r0, r1` instruction when carry is on and the result overflows', () => {
+ loadProgram('ADD r0, r1');
+ cpu.data[r0] = 11;
+ cpu.data[r1] = 245;
+ cpu.data[SREG] = SREG_C;
+ avrInstruction(cpu);
+ expect(cpu.pc).toEqual(1);
+ expect(cpu.cycles).toEqual(1);
+ expect(cpu.data[r0]).toEqual(0);
+ expect(cpu.data[SREG]).toEqual(SREG_H | SREG_Z | SREG_C);
+ });
+
it('should execute `BCLR 2` instruction', () => {
loadProgram('BCLR 2');
cpu.data[SREG] = 0xff;
@@ -991,6 +1026,17 @@ describe('avrInstruction', () => {
expect(cpu.data[Z]).toEqual(0x50); // verify that Z was unchanged
});
+ it('should execute `SUB r0, r1` instruction when result overflows', () => {
+ loadProgram('SUB r0, r1');
+ cpu.data[r0] = 0;
+ cpu.data[r1] = 10;
+ avrInstruction(cpu);
+ expect(cpu.pc).toEqual(1);
+ expect(cpu.cycles).toEqual(1);
+ expect(cpu.data[r0]).toEqual(246);
+ expect(cpu.data[SREG]).toEqual(SREG_S | SREG_N | SREG_C);
+ });
+
it('should execute `SWAP r1` instruction', () => {
loadProgram('SWAP r1');
cpu.data[r1] = 0xa5;
@@ -1000,6 +1046,14 @@ describe('avrInstruction', () => {
expect(cpu.data[r1]).toEqual(0x5a);
});
+ it('should execute `WDR` instruction and call `cpu.onWatchdogReset`', () => {
+ loadProgram('WDR');
+ cpu.onWatchdogReset = jest.fn();
+ expect(cpu.onWatchdogReset).not.toHaveBeenCalled();
+ avrInstruction(cpu);
+ expect(cpu.onWatchdogReset).toHaveBeenCalled();
+ });
+
it('should execute `XCH Z, r21` instruction', () => {
loadProgram('XCH Z, r21');
cpu.data[r21] = 0xa1;
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.