1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-06-18 00:29:30 +00:00

65816: Emulator bugfixes

This commit is contained in:
Karol Stasiak 2020-09-22 17:58:34 +02:00
parent 030531161e
commit c9f602b049
4 changed files with 54 additions and 31 deletions

1
.gitignore vendored
View File

@ -6,6 +6,7 @@ project/project/target/
stuff
releases
src/test/scala/experiments/
src/test/java/experiments/
# doesn't work yet
examples/lunix/
# older copies

View File

@ -1621,13 +1621,14 @@ var EOR_const = {
if(cpu.p.e||cpu.p.m) {
cpu.r.a ^= bytes[0];
cpu.p.n = cpu.r.a >> 7;
cpu_lib.r.p.check_z(cpu, cpu.r.a & 0xff);
} else {
cpu.cycle_count++;
cpu.r.a ^= (bytes[1]<<8)|bytes[0];
cpu.p.n = cpu.r.a >> 15;
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
};
@ -1690,14 +1691,14 @@ var ORA_const= {
if(cpu.p.e||cpu.p.m) {
cpu.r.a |= bytes[0];
cpu.p.n = cpu.r.a >> 7;
cpu_lib.r.p.check_z(cpu, cpu.r.a & 0xff);
} else {
cpu.cycle_count++;
cpu.r.a |= (bytes[1]<<8)|bytes[0];
cpu.p.n = cpu.r.a >> 15;
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
};
@ -1758,16 +1759,16 @@ var AND_const= {
cpu.cycle_count+=2;
if(cpu.p.e||cpu.p.m) {
cpu.r.a &= bytes[0];
cpu.r.a = cpu.r.a & 0xff00 | cpu.r.a & 0xff & bytes[0];
cpu.p.n = cpu.r.a >> 7;
cpu_lib.r.p.check_z(cpu, cpu.r.a & 0xff);
} else {
cpu.cycle_count++;
cpu.r.a &= (bytes[1]<<8)|bytes[0];
cpu.p.n = cpu.r.a >> 15;
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
};
@ -1829,7 +1830,7 @@ var CPX_const= {
var result;
if(cpu.p.e||cpu.p.x) {
result = cpu.r.x - bytes[0];
result = (cpu.r.x & 0xff) - bytes[0];
if(result<0) {
cpu.p.c = 0;
result = 0x100 + result;
@ -1878,7 +1879,7 @@ var CPY_const= {
var result;
if(cpu.p.e||cpu.p.x) {
result = cpu.r.y - bytes[0];
result = (cpu.r.y & 0xff) - bytes[0];
if(result<0) {
cpu.p.c = 0;
result = 0x100 + result;
@ -1926,7 +1927,7 @@ var CMP_const= {
var result;
if(cpu.p.e||cpu.p.m) {
result = cpu.r.a - bytes[0];
result = (cpu.r.a & 0xff) - bytes[0];
if(result<0) {
cpu.p.c = 0;
result = 0x100 + result;
@ -2433,21 +2434,16 @@ var TYA = {
execute:function(cpu) {
cpu.cycle_count+=2;
if(cpu.p.e||cpu.p.m) {
if(cpu.p.e||cpu.p.x) {
// 8-bit index register to 8-bit accumulator.
cpu.r.a = cpu.r.y;
} else {
// 16-bit index register to 8-bit accumulator.
cpu.r.a = cpu.r.y & 0x00ff;
}
// 8-bit accumulator.
cpu.r.a = cpu.r.a & 0xff00 | cpu.r.y & 0x00ff;
cpu.p.n = cpu.r.a >> 7;
cpu_lib.r.p.check_z(cpu, cpu.r.a & 0xff);
} else {
// 8-bit index register to 16-bit accumulator.
// 16-bit index register to 16-bit accumulator.
// 16-bit accumulator.
cpu.r.a = cpu.r.y;
cpu.p.n = cpu.r.a >> 15;
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
cpu_lib.r.p.check_z(cpu, cpu.r.a);
cpu.instruction_history += " TYA";
cpu.instruction_details += "<br />Transfer Y Register to Accumulator";
}
@ -2496,21 +2492,16 @@ var TXA = {
execute:function(cpu) {
cpu.cycle_count+=2;
if(cpu.p.e||cpu.p.m) {
if(cpu.p.e||cpu.p.x) {
// 8-bit index register to 8-bit accumulator.
cpu.r.a = cpu.r.x;
} else {
// 16-bit index register to 8-bit accumulator.
cpu.r.a = cpu.r.x & 0x00ff;
}
// 8-bit accumulator.
cpu.r.a = cpu.r.a & 0xff00 | cpu.r.x & 0x00ff;
cpu.p.n = cpu.r.a >> 7;
cpu_lib.r.p.check_z(cpu, cpu.r.a & 0xff);
} else {
// 8-bit index register to 16-bit accumulator.
// 16-bit index register to 16-bit accumulator.
// 16-bit accumulator.
cpu.r.a = cpu.r.x;
cpu.p.n = cpu.r.a >> 15;
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
cpu_lib.r.p.check_z(cpu, cpu.r.a);
cpu.instruction_history += " TXA";
cpu.instruction_details += "<br />Transfer X Register to Accumulator";
}
@ -3336,15 +3327,16 @@ var LDA_const= {
cpu.cycle_count+=2;
if(cpu.p.e||cpu.p.m) {
cpu.r.a = bytes[0];
cpu.r.a = cpu.r.a & 0xff00 | bytes[0];
cpu.p.n = cpu.r.a >> 7;
cpu_lib.r.p.check_z(cpu, cpu.r.a & 0xff);
} else {
cpu.cycle_count++;
cpu.r.a = (bytes[1]<<8)|bytes[0];
cpu.p.n = cpu.r.a >> 15;
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
cpu_lib.r.p.check_z(cpu, cpu.r.a);
}
};

View File

@ -561,6 +561,8 @@ class ComparisonSuite extends FunSuite with Matchers with AppendedClues {
| noinline word id(word x) = x
|""".stripMargin
EmuCrossPlatformBenchmarkRun(Cpu.Mos, Cpu.Sixteen, Cpu.Z80, Cpu.Intel8080, Cpu.Sharp, Cpu.Motorola6809)(code) {m =>
// TODO: for some reason this still fails on 65816
// the main suspect is a bug in the emulator
m.readByte(0xc000) should equal (code.count(_ == '↑'))
}
}

View File

@ -0,0 +1,28 @@
package millfork.test
import millfork.test.emu.EmuUnoptimizedNative65816Run
import org.scalatest.{AppendedClues, FunSuite, Matchers}
/**
* @author Karol Stasiak
*/
class EmulatorCorrectnessSuite extends FunSuite with Matchers with AppendedClues {
test("TXA should not clobber AH") {
val m = EmuUnoptimizedNative65816Run(
"""
|
|asm void main() {
| SEP #$30
| LDA #1
| XBA
| LDX #3
| TXA
| REP #$30
| STA $700
| RTS
|}
|""".stripMargin)
m.readWord(0x700) should equal(0x103)
}
}