Skip to content

Commit 053ab68

Browse files
committed
Add BRA, P(H|L)(X|Y), and STZ commands to CPU.java
1 parent 0488e01 commit 053ab68

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

src/CPU.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public CPU() {
7777
lookup[0xD0] = new Instruction("BNE","REL",2);
7878

7979
lookup[0x10] = new Instruction("BPL","REL",2);
80+
81+
lookup[0x80] = new Instruction("BRA","REL",2);
8082

8183
lookup[0x00] = new Instruction("BRK","IMP",2);
8284

@@ -182,10 +184,18 @@ public CPU() {
182184
lookup[0x48] = new Instruction("PHA","IMP",3);
183185

184186
lookup[0x08] = new Instruction("PHP","IMP",3);
187+
188+
lookup[0xDA] = new Instruction("PHX","IMP",3);
189+
190+
lookup[0x5A] = new Instruction("PHY","IMP",3);
185191

186192
lookup[0x68] = new Instruction("PLA","IMP",4);
187193

188194
lookup[0x28] = new Instruction("PLP","IMP",4);
195+
196+
lookup[0xFA] = new Instruction("PLX", "IMP",4);
197+
198+
lookup[0x7A] = new Instruction("PLY","IMP",4);
189199

190200
lookup[0x2A] = new Instruction("ROL","IMP",2);
191201
lookup[0x26] = new Instruction("ROL","ZPP",5);
@@ -233,6 +243,11 @@ public CPU() {
233243
lookup[0x84] = new Instruction("STY","ZPP",3);
234244
lookup[0x94] = new Instruction("STY","ZPX",4);
235245
lookup[0x8C] = new Instruction("STY","ABS",4);
246+
247+
lookup[0x64] = new Instruction("STZ","ZPP",3);
248+
lookup[0x74] = new Instruction("STZ","ZPX",4);
249+
lookup[0x9C] = new Instruction("STZ","ABS",4);
250+
lookup[0x9E] = new Instruction("STZ","ABX",4);
236251

237252
lookup[0xAA] = new Instruction("TAX","IMP",2);
238253

@@ -444,6 +459,9 @@ void executeOpcodeFunction(String opcode) {
444459
case "BPL":
445460
BPL();
446461
break;
462+
case "BRA":
463+
BRA();
464+
break;
447465
case "BRK":
448466
BRK();
449467
break;
@@ -525,12 +543,24 @@ void executeOpcodeFunction(String opcode) {
525543
case "PHP":
526544
PHP();
527545
break;
546+
case "PHX":
547+
PHX();
548+
break;
549+
case "PHY":
550+
PHY();
551+
break;
528552
case "PLA":
529553
PLA();
530554
break;
531555
case "PLP":
532556
PLP();
533557
break;
558+
case "PLX":
559+
PLX();
560+
break;
561+
case "PLY":
562+
PLY();
563+
break;
534564
case "ROL":
535565
ROL();
536566
break;
@@ -564,6 +594,9 @@ void executeOpcodeFunction(String opcode) {
564594
case "STY":
565595
STY();
566596
break;
597+
case "STZ":
598+
STZ();
599+
break;
567600
case "TAX":
568601
TAX();
569602
break;
@@ -887,6 +920,16 @@ public void BPL() {
887920
}
888921
}
889922

923+
public void BRA() {
924+
cycles++;
925+
addressAbsolute = (short)(programCounter+addressRelative);
926+
927+
if ((addressAbsolute&0xFF00) != (programCounter & 0xFF00))
928+
cycles++;
929+
930+
programCounter = addressAbsolute;
931+
}
932+
890933
public void BRK() {
891934
programCounter++;
892935

@@ -1098,6 +1141,16 @@ public void PHP() {
10981141
setFlag('U',false);
10991142
stackPointer--;
11001143
}
1144+
1145+
public void PHX() {
1146+
Bus.write((short)(0x0100+Byte.toUnsignedInt(stackPointer)), x);
1147+
stackPointer--;
1148+
}
1149+
1150+
public void PHY() {
1151+
Bus.write((short)(0x0100+Byte.toUnsignedInt(stackPointer)), y);
1152+
stackPointer--;
1153+
}
11011154

11021155
public void PLA() {
11031156
stackPointer++;
@@ -1112,6 +1165,20 @@ public void PLP() {
11121165
setFlag('U', true);
11131166
}
11141167

1168+
public void PLX() {
1169+
stackPointer++;
1170+
x = Bus.read((short)(0x0100+Byte.toUnsignedInt(stackPointer)));
1171+
setFlag('Z', x == 0);
1172+
setFlag('N', (x & 0x80) == 0x80);
1173+
}
1174+
1175+
public void PLY() {
1176+
stackPointer++;
1177+
y = Bus.read((short)(0x0100+Byte.toUnsignedInt(stackPointer)));
1178+
setFlag('Z', y == 0);
1179+
setFlag('N', (y & 0x80) == 0x80);
1180+
}
1181+
11151182
public void ROL() {
11161183
fetch();
11171184
short temp = (short)((fetched<<1) | (getFlag('C') ? 1 : 0));
@@ -1196,6 +1263,10 @@ public void STX() {
11961263
public void STY() {
11971264
Bus.write(addressAbsolute, y);
11981265
}
1266+
1267+
public void STZ() {
1268+
Bus.write(addressAbsolute, (byte)0);
1269+
}
11991270

12001271
public void TAX() {
12011272
x = a;

0 commit comments

Comments
 (0)