Skip to content

Commit

Permalink
merge Dev (#6)
Browse files Browse the repository at this point in the history
* added opcodes & tests for LDA: 0xA5, 0xB5, 0xAD
* update README.md for opcodes
* iml opcodes: 0xBD, 0xB9, 0xA1, 0xB1
all iml from LDA
  • Loading branch information
kostDev authored Aug 22, 2024
1 parent 7f7b834 commit f15c2e7
Show file tree
Hide file tree
Showing 4 changed files with 518 additions and 53 deletions.
58 changes: 58 additions & 0 deletions js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
### Opcodes progress by Instructions:

<details>
<summary><b>Opcodes for <span style="color: orange">LDA - Load Accumulator with Memory</span></b></summary>

| Dec | Opcode | Instruction | Addressing Mode | Cycles | Implemented |
|:---:|:------:|:----------------:|:---------------:|:------:|:-----------:|
| 169 | 0xA9 | LDA #immediate | Immediate | 2 | ✅️ |
| 165 | 0xA5 | LDA zeropage | Zeropage | 3 | ✅️ |
| 181 | 0xB5 | LDA zeropage,X | Zeropage,X | 4 | ✅️ |
| 173 | 0xAD | LDA absolute | Absolute | 4 ||
| 189 | 0xBD | LDA absolute,X | Absolute,X | 4 (+1) ||
| 185 | 0xB9 | LDA absolute,Y | Absolute,Y | 4 (+1) ||
| 161 | 0xA1 | LDA (indirect,X) | Indirect,X | 6 ||
| 177 | 0xB1 | LDA (indirect),Y | Indirect,Y | 5 (+1) ||

</details>

<details open>
<summary><b>Opcodes for <span style="color: orange">LDX - Load Index Register X From Memory</span></b></summary>

| Decimal | Opcode | Instruction | Addressing Mode | Cycles | Implemented |
|:-------:|:------:|:--------------:|:---------------:|:------:|:-----------:|
| 169 | 0xA2 | LDX #immediate | Immediate | 2 ||
| 181 | 0xA6 | LDX zeropage | Zeropage | 3 | |
| 197 | 0xB6 | LDX zeropage,Y | Zeropage,Y | 4 | |
| 173 | 0xAE | LDX absolute | Absolute | 4 | |
| 189 | 0xBE | LDX absolute,Y | Absolute,Y | 4 (+1) | |

</details>



### Opcodes (23/151)

| Dec | Opcode | Instruction | Status |
|:---:|:------:|:--------------:|:------:|
| 0 | 0x00 | BRK ||
| 9 | 0x09 | ORA #immediate ||
| 29 | 0x29 | AND #immediate ||
| 41 | 0x49 | EOR #immediate ||
| 84 | 0x84 | STY zeropage ||
| 85 | 0x85 | STA zeropage ||
| 86 | 0x86 | STX zeropage ||
| 88 | 0x88 | DEY ||
| 90 | 0x90 | BCC ||
| 98 | 0x98 | TYA ||
| 105 | 0x69 | ADC #immediate ||
| 138 | 0x8A | TXA ||
| 160 | 0xA0 | LDY #immediate ||
| 162 | 0xA2 | LDX #immediate ||
| 168 | 0xA8 | TAY ||
| 170 | 0xAA | TAX ||
| 200 | 0xC8 | INY ||
| 202 | 0xCA | DEX ||
| 232 | 0xE8 | INX ||
| 233 | 0xE9 | SBC #immediate ||
| 234 | 0xEA | NOP ||
115 changes: 108 additions & 7 deletions js/opcodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,21 @@ const OPCODES = {
cpu.zeroFlag = cpu.Y;
}
},
0xA1: "",
0xA1: {
name: "LDA (indirect,X)", // Load Accumulator with Memory (Indirect Indexed Addressing with X)
t: 6, // Cycles required
code: 0xA1,
run: (cpu) => {
const baseAddress = (cpu.fetch() + cpu.X) & 0xFF; // 0x00-0xFF (zeropage)
const lowByte = cpu.memory.readByte(baseAddress);
const highByte = cpu.memory.readByte((baseAddress + 1) & 0xFF); // wrap around in zeropage
const address = (highByte << 8) | lowByte; // 16-bit address

cpu.ACC = cpu.memory.readByte(address);
cpu.negativeFlag = cpu.ACC;
cpu.zeroFlag = cpu.ACC;
},
},
0xA2: {
name: "LDX #immediate", // Load Index X with Memory
t: 2,
Expand All @@ -316,7 +330,17 @@ const OPCODES = {
},
0xA3: "", // lax("(d,x)") // illegal
0xA4: "",
0xA5: "",
0xA5: {
name: "LDA zeropage", // Load Accumulator with Memory from Zeropage
t: 3,
code: 0xA5,
run: (cpu) => {
const address = cpu.fetch();
cpu.ACC = cpu.memory.readByte(address);
cpu.negativeFlag = cpu.ACC;
cpu.zeroFlag = cpu.ACC;
}
},
0xA6: "",
0xA7: "", // illegal
0xA8: {
Expand Down Expand Up @@ -351,23 +375,100 @@ const OPCODES = {
},
0xAB: "", // lax("#i") // illegal
0xAC: "",
0xAD: "",
0xAD: {
name: "LDA absolute", // Load Accumulator Absolute
t: 4,
code: 0xAD,
run: (cpu) => {
const lowByte = cpu.fetch();
const highByte = cpu.fetch();
const address = (highByte << 8) | lowByte;
cpu.ACC = cpu.memory.readByte(address);
cpu.negativeFlag = cpu.ACC;
cpu.zeroFlag = cpu.ACC;
}
},
0xAE: "",
0xAF: "", // lax("a") // illegal
0xB0: "", // bcs("*+d")
0xB1: "", // lda("(d),y")
0xB1: {
name: "LDA (indirect),Y", // Load Accumulator with Memory (Indirect) and Indexed Addressing with Y
t: 5, // 5 (+1)
code: 0xB1,
run: (cpu) => {
const baseAddress = cpu.fetch();
const lowByte = cpu.memory.readByte(baseAddress);
const highByte = cpu.memory.readByte((baseAddress + 1) & 0xFF); // wrap around in zeropage
const address = (highByte << 8) | lowByte + cpu.Y; // 16-bit address

// Check if the address crosses a page boundary
if ((address & 0xFF00) !== ((highByte << 8) & 0xFF00)) {
cpu.cycles += 1; // Add an extra cycle if a page boundary is crossed
}


cpu.ACC = cpu.memory.readByte(address);
cpu.negativeFlag = cpu.ACC;
cpu.zeroFlag = cpu.ACC;
},
},
0xB2: "", // stp_implied() // illegal
0xB3: "", // lax("(d),y") // illegal
0xB4: "",
0xB5: "",
0xB5: {
name: "LDA zeropage,X", // Load Accumulator with X-Indexed Zero Page
t: 4,
code: 0xB5,
run: (cpu) => {
const baseAddress = cpu.fetch();
const address = (baseAddress + cpu.X) & 0xFF;
cpu.ACC = cpu.memory.readByte(address);
cpu.negativeFlag = cpu.ACC;
cpu.zeroFlag = cpu.ACC;
}
},
0xB6: "",
0xB7: "", // lax("d,y") // illegal
0xB8: "", // clv_implied()
0xB9: "", // lda("a,y")
0xB9: {
name: "LDA absolute,Y", // Load Accumulator with Memory (Absolute Addressing with Y offset)
t: 4, // 4 (+1)
code: 0xB9,
run: (cpu) => {
const lowByte = cpu.fetch();
const highByte = cpu.fetch();
const address = ((highByte << 8) | lowByte) + cpu.Y; // Combine bytes and add Y register value
// Check if address crosses a page boundary
if ((address & 0xFF00) !== ((highByte << 8) & 0xFF00)) {
cpu.cycles += 1; // Add an extra cycle if a page boundary is crossed
}

cpu.ACC = cpu.memory.readByte(address);
cpu.negativeFlag = cpu.ACC;
cpu.zeroFlag = cpu.ACC;
}
},
0xBA: "", // tsx_implied()
0xBB: "", // las("a,y") // illegal
0xBC: "", // ldy("a,x")
0xBD: "", // lda("a,x")
0xBD: {
name: "LDA absolute,X", // Load Accumulator with Memory (Absolute Addressing with X offset)
t: 4, // 4 (+1)
code: 0xBD,
run: (cpu) => {
const lowByte = cpu.fetch();
const highByte = cpu.fetch();
const address = ((highByte << 8) | lowByte) + cpu.X; // Combine bytes and add X register value
// Check if address crosses a page boundary
if ((address & 0xFF00) !== ((highByte << 8) & 0xFF00)) {
cpu.cycles += 1; // Add an extra cycle if a page boundary is crossed
}

cpu.ACC = cpu.memory.readByte(address);
cpu.negativeFlag = cpu.ACC;
cpu.zeroFlag = cpu.ACC;
}
},
0xBE: "", // ldx("a,y")
0xBF: "", // lax("a,y") // illegal
0xC0: "", // cpy("#i")
Expand Down
45 changes: 0 additions & 45 deletions js/opcodes.md

This file was deleted.

Loading

0 comments on commit f15c2e7

Please sign in to comment.