|
@@ -0,0 +1,53 @@
|
|
|
+package de.mcs.tools.sps.holtek;
|
|
|
+
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import de.mcs.tools.sps.EmulatorInput;
|
|
|
+import de.mcs.tools.sps.EmulatorInternals;
|
|
|
+import de.mcs.tools.sps.EmulatorOutput;
|
|
|
+import de.mcs.tools.sps.TOutputCallback;
|
|
|
+import de.mcs.tools.sps.exceptions.WrongProgramSizeException;
|
|
|
+
|
|
|
+class TestHoltekProgram implements TOutputCallback {
|
|
|
+
|
|
|
+ private HoltekEmulator holtekEmulator;
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() throws Exception {
|
|
|
+ holtekEmulator = new HoltekEmulator();
|
|
|
+ holtekEmulator.addCallback(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void test() throws WrongProgramSizeException {
|
|
|
+ byte[] prg = new byte[] { 0x10, 0x1F, 0x10 };
|
|
|
+ holtekEmulator.loadProgram(prg);
|
|
|
+ holtekEmulator.startProgram(true);
|
|
|
+ holtekEmulator.nextStep();
|
|
|
+ holtekEmulator.nextStep();
|
|
|
+ holtekEmulator.nextStep();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onOutput(EmulatorOutput output) {
|
|
|
+ EmulatorInternals internals = holtekEmulator.getEmulatorInternals();
|
|
|
+ EmulatorInput input = holtekEmulator.getEmulatorInput();
|
|
|
+ System.out.printf("adr: 0x%04x, a:0x%02x, b:0x%02x, c:0x%02x, d:0x%02x, page:0x%02x\r\n", internals.getAddress(),
|
|
|
+ internals.getRegister(HoltekEmulatorInternals.REGISTER_A),
|
|
|
+ internals.getRegister(HoltekEmulatorInternals.REGISTER_B),
|
|
|
+ internals.getRegister(HoltekEmulatorInternals.REGISTER_C),
|
|
|
+ internals.getRegister(HoltekEmulatorInternals.REGISTER_D),
|
|
|
+ internals.getRegister(HoltekEmulatorInternals.REGISTER_PAGE));
|
|
|
+ String value = getNibbleString(output.getOutput());
|
|
|
+ System.out.printf("in: %4s, s1: %b, s2: %b, adc1: 0x%02x, adc2: 0x%02x\r\n", value, input.getFeatureAsBool("S1"),
|
|
|
+ input.getFeatureAsBool("S2"), input.getFeature("ADC1"), input.getFeature("ADC2"));
|
|
|
+ System.out.printf("out: %4s, pwm: 0x%02x\r\n", value, output.getFeature("PWM"));
|
|
|
+ System.out.println();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getNibbleString(byte value) {
|
|
|
+ return String.format("%4s", Integer.toBinaryString(value & 0xFF)).replace(' ', '0');
|
|
|
+ }
|
|
|
+
|
|
|
+}
|