aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/instruction.spec.ts26
-rw-r--r--src/instruction.ts7
2 files changed, 29 insertions, 4 deletions
diff --git a/src/instruction.spec.ts b/src/instruction.spec.ts
index 9ea4c0f..8c81a06 100644
--- a/src/instruction.spec.ts
+++ b/src/instruction.spec.ts
@@ -46,10 +46,21 @@ describe('avrInstruction', () => {
expect(cpu.cycles).toEqual(2);
});
+ it('should execute `ST X, r1` instruction', () => {
+ loadProgram('1c92');
+ cpu.data[1] = 0x5a; // r1 <- 0x5a
+ cpu.data[26] = 0x9a; // X <- 0x9a
+ avrInstruction(cpu);
+ expect(cpu.pc).toEqual(1);
+ expect(cpu.cycles).toEqual(1);
+ expect(cpu.data[0x9a]).toEqual(0x5a);
+ expect(cpu.data[26]).toEqual(0x9a); // verify that X was unchanged
+ });
+
it('should execute `ST X+, r1` instruction', () => {
loadProgram('1d92');
- cpu.data[1] = 0x5a; // put the value 5a in r1
- cpu.data[26] = 0x9a; // X <- 0x19
+ cpu.data[1] = 0x5a; // r1 <- 5a
+ cpu.data[26] = 0x9a; // X <- 0x9a
avrInstruction(cpu);
expect(cpu.pc).toEqual(1);
expect(cpu.cycles).toEqual(1);
@@ -57,6 +68,17 @@ describe('avrInstruction', () => {
expect(cpu.data[26]).toEqual(0x9b); // verify that X was incremented
});
+ it('should execute `ST X-, r17` instruction', () => {
+ loadProgram('1e93');
+ cpu.data[17] = 0x88; // r17 <- 0x88
+ cpu.data[26] = 0x99; // X <- 0x99
+ avrInstruction(cpu);
+ expect(cpu.pc).toEqual(1);
+ expect(cpu.cycles).toEqual(2);
+ expect(cpu.data[0x98]).toEqual(0x88);
+ expect(cpu.data[26]).toEqual(0x98); // verify that X was unchanged
+ });
+
it('should execute `CPI r26, 0x9` instruction', () => {
loadProgram('a930');
cpu.data[26] = 0x8;
diff --git a/src/instruction.ts b/src/instruction.ts
index f7789d2..63c4caa 100644
--- a/src/instruction.ts
+++ b/src/instruction.ts
@@ -425,7 +425,7 @@ export function avrInstruction(cpu: ICPU) {
/* STX */
if ((opcode & 0xfe0f) === 0x920c) {
- /* not implemented */
+ cpu.writeData(cpu.dataView.getUint16(26, true), cpu.data[(opcode & 0x1f0) >> 4]);
}
/* STX */
@@ -436,7 +436,10 @@ export function avrInstruction(cpu: ICPU) {
/* STX */
if ((opcode & 0xfe0f) === 0x920e) {
- /* not implemented */
+ const i = cpu.data[(opcode & 0x1f0) >> 4];
+ cpu.dataView.setUint16(26, cpu.dataView.getUint16(26, true) - 1, true);
+ cpu.writeData(cpu.dataView.getUint16(26, true), i);
+ cpu.cycles++;
}
/* STY */
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.