Skip to content

Commit 606e76e

Browse files
gutomaiabfirsh
authored andcommitted
fix: fixes instructions JSR, PHA, PHP, PLA, RST, RTI, RTS, TSX and TXS
1 parent 2ac9bd1 commit 606e76e

File tree

2 files changed

+7
-22
lines changed

2 files changed

+7
-22
lines changed

src/cpu.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ CPU.prototype = {
982982
// *******
983983

984984
// Transfer stack pointer to index X:
985-
this.REG_X = this.REG_SP - 0x0100;
985+
this.REG_X = this.REG_SP & 0xff;
986986
this.F_SIGN = (this.REG_SP >> 7) & 1;
987987
this.F_ZERO = this.REG_X;
988988
break;
@@ -1004,8 +1004,7 @@ CPU.prototype = {
10041004
// *******
10051005

10061006
// Transfer index X to stack pointer:
1007-
this.REG_SP = this.REG_X + 0x0100;
1008-
this.stackWrap();
1007+
this.REG_SP = this.REG_X & 0xff;
10091008
break;
10101009
}
10111010
case 55: {
@@ -1294,19 +1293,16 @@ CPU.prototype = {
12941293
},
12951294

12961295
push: function (value) {
1297-
this.nes.mmap.write(this.REG_SP, value);
1296+
this.nes.mmap.write(this.REG_SP | 0x100, value);
12981297
this.REG_SP--;
1299-
this.REG_SP = 0x0100 | (this.REG_SP & 0xff);
1300-
},
1301-
1302-
stackWrap: function () {
1303-
this.REG_SP = 0x0100 | (this.REG_SP & 0xff);
1298+
// this.REG_SP = 0x0100 | (this.REG_SP & 0xff);
1299+
this.REG_SP = this.REG_SP & 0xff;
13041300
},
13051301

13061302
pull: function () {
13071303
this.REG_SP++;
1308-
this.REG_SP = 0x0100 | (this.REG_SP & 0xff);
1309-
return this.nes.mmap.load(this.REG_SP);
1304+
this.REG_SP = this.REG_SP & 0xff;
1305+
return this.nes.mmap.load(0x100 | this.REG_SP);
13101306
},
13111307

13121308
pageCrossed: function (addr1, addr2) {

test/cpu.spec.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ describe("CPU", function () {
850850
});
851851

852852
it("tsx", function(done) {
853-
this.skip("TODO");
854853
cpu_set_register("SP", 0xff);
855854
cpu_pc(0x100);
856855
memory_set(0x100, 0xba);
@@ -862,7 +861,6 @@ describe("CPU", function () {
862861
});
863862

864863
it("txs", function(done) {
865-
this.skip("TODO");
866864
cpu_set_register("X", 0xff);
867865
cpu_pc(0x100);
868866
memory_set(0x100, 0x9a);
@@ -874,7 +872,6 @@ describe("CPU", function () {
874872
});
875873

876874
it("pha", function(done) {
877-
this.skip();
878875
cpu_set_register("A", 0xff);
879876
cpu_pc(0x100);
880877
memory_set(0x100, 0x48);
@@ -886,7 +883,6 @@ describe("CPU", function () {
886883
});
887884

888885
it("php", function(done) {
889-
this.skip("TODO:");
890886
cpu_set_register("P", 0xff);
891887
cpu_pc(0x100);
892888
memory_set(0x100, 0x8);
@@ -898,7 +894,6 @@ describe("CPU", function () {
898894
});
899895

900896
it("pla", function(done) {
901-
this.skip();
902897
cpu_pc(0x100);
903898
cpu_push_byte(0xff);
904899
memory_set(0x100, 0x68);
@@ -921,7 +916,6 @@ describe("CPU", function () {
921916
});
922917

923918
it("pla z flag unset", function(done) {
924-
this.skip();
925919
cpu_push_byte(0x1);
926920
cpu_pc(0x100);
927921
memory_set(0x100, 0x68);
@@ -933,7 +927,6 @@ describe("CPU", function () {
933927
});
934928

935929
it("pla n flag set", function(done) {
936-
this.skip();
937930
cpu_push_byte(0x81);
938931
cpu_pc(0x100);
939932
memory_set(0x100, 0x68);
@@ -3478,7 +3471,6 @@ describe("CPU", function () {
34783471
});
34793472

34803473
it("jsr", function(done) {
3481-
this.skip("TODO: check SP register");
34823474
cpu_pc(0x100);
34833475
memory_set(0x100, 0x20);
34843476
memory_set(0x101, 0xff);
@@ -3493,7 +3485,6 @@ describe("CPU", function () {
34933485
});
34943486

34953487
it("jsr stack pointer", function(done) {
3496-
this.skip("TODO:");
34973488
cpu_pc(0x100);
34983489
memory_set(0x100, 0x20);
34993490
memory_set(0x101, 0x84);
@@ -3539,7 +3530,6 @@ describe("CPU", function () {
35393530
});
35403531

35413532
it("rts", function(done) {
3542-
this.skip("TODO");
35433533
cpu_pc(0x100);
35443534
cpu_push_word(0x102);
35453535
memory_set(0x100, 0x60);
@@ -3864,7 +3854,6 @@ describe("CPU", function () {
38643854
});
38653855

38663856
it("rti", function(done) {
3867-
this.skip("TODO");
38683857
cpu_pc(0x100);
38693858
cpu_push_word(0x102);
38703859
cpu_push_byte(0x3);

0 commit comments

Comments
 (0)