Skip to content

Commit ce12c92

Browse files
committed
Fixed CPU instructions
1 parent 6755f88 commit ce12c92

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/CPU.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class CPU {
2121

2222
public int additionalCycles = 0;
2323

24-
public Instruction[] lookup = new Instruction[0xFF];
24+
public Instruction[] lookup = new Instruction[0x100];
2525

2626
public CPU() {
2727
reset();
@@ -95,14 +95,14 @@ public CPU() {
9595
lookup[0xE4] = new Instruction("CPX","ZPP",3);
9696
lookup[0xEC] = new Instruction("CPX","ABS",4);
9797

98-
lookup[0xC0] = new Instruction("CPX","IMM",2);
99-
lookup[0xC4] = new Instruction("CPX","ZPP",3);
100-
lookup[0xCC] = new Instruction("CPX","ABS",4);
98+
lookup[0xC0] = new Instruction("CPY","IMM",2);
99+
lookup[0xC4] = new Instruction("CPY","ZPP",3);
100+
lookup[0xCC] = new Instruction("CPY","ABS",4);
101101

102-
lookup[0xC6] = new Instruction("CPX","ZPP",5);
103-
lookup[0xD6] = new Instruction("CPX","ZPX",6);
104-
lookup[0xCE] = new Instruction("CPX","ABS",6);
105-
lookup[0xDE] = new Instruction("CPX","ABX",7);
102+
lookup[0xC6] = new Instruction("DEC","ZPP",5);
103+
lookup[0xD6] = new Instruction("DEC","ZPX",6);
104+
lookup[0xCE] = new Instruction("DEC","ABS",6);
105+
lookup[0xDE] = new Instruction("DEC","ABX",7);
106106

107107
lookup[0xCA] = new Instruction("DEX","IMP",2);
108108

@@ -345,6 +345,8 @@ void reset() {
345345
cycles = 8;
346346

347347
startTime = System.currentTimeMillis();
348+
349+
opcode = Bus.read(programCounter);
348350
}
349351

350352
void irq() {
@@ -702,7 +704,7 @@ public void CPY() {
702704

703705
public void DEC() {
704706
fetch();
705-
short temp = (short)(fetched-1);
707+
int temp = (Byte.toUnsignedInt(fetched)-1);
706708
Bus.write(addressAbsolute, (byte)(temp&0x00FF));
707709
setFlag('Z',(temp&0x00FF)==0x0000);
708710
setFlag('N',(temp&0x0080)==0x0080);

0 commit comments

Comments
 (0)