2017-12-28 16:40:15 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Brendan Robert
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
package jace.cpu;
|
|
|
|
|
|
|
|
import jace.Emulator;
|
|
|
|
import jace.apple2e.MOS65C02;
|
2021-11-09 17:20:19 +00:00
|
|
|
import jace.apple2e.RAM128k;
|
2017-12-28 16:40:15 +00:00
|
|
|
import jace.core.Computer;
|
|
|
|
import jace.core.SoundMixer;
|
|
|
|
import jace.core.Utility;
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2023-07-03 20:44:23 +00:00
|
|
|
import static org.junit.Assert.assertArrayEquals;
|
2021-11-09 17:20:19 +00:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertFalse;
|
2023-07-03 20:44:23 +00:00
|
|
|
import static jace.TestUtils.*;
|
2021-11-09 17:20:19 +00:00
|
|
|
|
2017-12-28 16:40:15 +00:00
|
|
|
/**
|
|
|
|
* Basic test functionality to assert correct 6502 decode and execution.
|
|
|
|
*
|
|
|
|
* @author blurry
|
|
|
|
*/
|
|
|
|
public class Basic6502FuncationalityTest {
|
|
|
|
|
|
|
|
static Computer computer;
|
|
|
|
static MOS65C02 cpu;
|
2021-11-09 17:20:19 +00:00
|
|
|
static RAM128k ram;
|
2017-12-28 16:40:15 +00:00
|
|
|
|
|
|
|
@BeforeClass
|
|
|
|
public static void setupClass() {
|
|
|
|
Utility.setHeadlessMode(true);
|
|
|
|
SoundMixer.MUTE = true;
|
2021-11-09 17:20:19 +00:00
|
|
|
computer = Emulator.getComputer();
|
2017-12-28 16:40:15 +00:00
|
|
|
cpu = (MOS65C02) computer.getCpu();
|
2021-11-09 17:20:19 +00:00
|
|
|
ram = (RAM128k) computer.getMemory();
|
2017-12-28 16:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@AfterClass
|
|
|
|
public static void teardownClass() {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setup() {
|
2021-11-09 17:20:19 +00:00
|
|
|
computer.pause();
|
2017-12-28 16:40:15 +00:00
|
|
|
cpu.clearState();
|
|
|
|
}
|
|
|
|
|
2021-11-09 17:20:19 +00:00
|
|
|
@Test
|
|
|
|
public void assertMemoryConfiguredCorrectly() {
|
2023-07-03 20:44:23 +00:00
|
|
|
assertArrayEquals("Active read bank 3 should be main memory page 3",
|
2021-11-09 17:20:19 +00:00
|
|
|
ram.mainMemory.getMemoryPage(3),
|
|
|
|
ram.activeRead.getMemoryPage(3));
|
|
|
|
|
2023-07-03 20:44:23 +00:00
|
|
|
assertArrayEquals("Active write bank 3 should be main memory page 3",
|
2021-11-09 17:20:19 +00:00
|
|
|
ram.mainMemory.getMemoryPage(3),
|
|
|
|
ram.activeWrite.getMemoryPage(3));
|
|
|
|
}
|
|
|
|
|
2017-12-28 16:40:15 +00:00
|
|
|
@Test
|
|
|
|
public void testAdditionNonDecimal() {
|
|
|
|
cpu.A = 0;
|
|
|
|
cpu.D = false;
|
|
|
|
cpu.C = 0;
|
2023-07-03 20:44:23 +00:00
|
|
|
runAssemblyCode("adc #1", 2);
|
2017-12-28 16:40:15 +00:00
|
|
|
assertEquals("0+1 (c=0) = 1", 1, cpu.A);
|
|
|
|
assertFalse("Result is not zero", cpu.Z);
|
2021-11-09 17:20:19 +00:00
|
|
|
assertEquals("Carry is clear", 0, cpu.C);
|
2017-12-28 16:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAdditionNonDecimalWithCarry() {
|
|
|
|
cpu.A = 0;
|
|
|
|
cpu.D = false;
|
|
|
|
cpu.C = 1;
|
2023-07-03 20:44:23 +00:00
|
|
|
runAssemblyCode("adc #1", 2);
|
2017-12-28 16:40:15 +00:00
|
|
|
assertEquals("0+1 (c=1) = 2", 2, cpu.A);
|
|
|
|
assertFalse("Result is not zero", cpu.Z);
|
2021-11-09 17:20:19 +00:00
|
|
|
assertEquals("Carry is clear", 0, cpu.C);
|
2017-12-28 16:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAdditionDecimal() {
|
|
|
|
cpu.A = 9;
|
|
|
|
cpu.D = true;
|
|
|
|
cpu.C = 0;
|
2023-07-03 20:44:23 +00:00
|
|
|
runAssemblyCode("adc #1", 2);
|
2017-12-28 16:40:15 +00:00
|
|
|
assertEquals("9+1 (c=0) = 0x10", 0x10, cpu.A);
|
|
|
|
assertFalse("Result is not zero", cpu.Z);
|
2021-11-09 17:20:19 +00:00
|
|
|
assertEquals("Carry is clear", 0, cpu.C);
|
2017-12-28 16:40:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAdditionDecimalWithCarry() {
|
|
|
|
cpu.A = 9;
|
|
|
|
cpu.D = true;
|
|
|
|
cpu.C = 1;
|
2023-07-03 20:44:23 +00:00
|
|
|
runAssemblyCode("adc #1", 2);
|
2017-12-28 16:40:15 +00:00
|
|
|
assertEquals("9+1 (c=1) = 0x11", 0x11, cpu.A);
|
|
|
|
assertFalse("Result is not zero", cpu.Z);
|
2021-11-09 17:20:19 +00:00
|
|
|
assertEquals("Carry is clear", 0, cpu.C);
|
2017-12-28 16:40:15 +00:00
|
|
|
}
|
|
|
|
}
|