1 package com.tapina.robe.swi.clib.roslib;
2
3 import com.tapina.robe.swi.clib.Stub;
4 import com.tapina.robe.runtime.Environment;
5 import com.tapina.robe.runtime.Condition;
6 import com.tapina.robe.runtime.UnknownSWIException;
7 import com.tapina.robe.runtime.CPU;
8 import com.tapina.robe.runtime.instruction.SWI;
9
10 /***
11 * This function calls a SWI , whose number is given in a1.
12 * The registers R0-R9 are set to and returned in the values in a2.
13 * If an error occurs it is returned by the function and not reported by the operating system.
14 * Returns: Pointer to an error, or NULL if none.
15 */
16 public class SWIX extends Stub {
17 public final void executeStub(Environment environment) {
18 final CPU cpu = environment.getCpu();
19 final int[] R = cpu.R;
20 final int registerAddress = R[1];
21 final int[] R4to9save = new int[6];
22 final int[] R0to9in = environment.getMemoryMap().getWords(registerAddress, 10);
23 final int[] R0to9out = new int[10];
24 System.arraycopy(R, 4, R4to9save, 0, 6);
25 System.arraycopy(R0to9in, 0, R, 0, 10);
26 try {
27 SWI swi = new SWI(Condition.AL, getSWINumber(R));
28 swi.checkAndExecute(environment);
29 System.arraycopy(R, 0, R0to9out, 0, 10);
30 environment.getMemoryMap().storeWords(registerAddress, R0to9out);
31 if (!cpu.getV()) {
32
33 R[0] = 0;
34 }
35 } catch (UnknownSWIException e) {
36 environment.returnError(e);
37 } finally {
38 System.arraycopy(R4to9save, 0, R, 4, 6);
39 }
40 }
41
42 int getSWINumber(final int[] R) {
43 return R[0] | SWI.X_BIT;
44 }
45 }