View Javadoc

1   package com.tapina.robe.swi;
2   
3   import com.tapina.robe.runtime.Environment;
4   
5   import java.lang.reflect.Method;
6   
7   public final class OSExt3 extends SWIHandler {
8       private static OSExt3 ourInstance;
9   
10      public synchronized static OSExt3 getInstance() {
11          if (ourInstance == null) {
12              ourInstance = new OSExt3();
13          }
14          return ourInstance;
15      }
16  
17      private OSExt3() {
18      }
19  
20      public static int getBase() {
21          return 0xC0;
22      }
23  
24      private static final String[] methodNames = new String[]{
25          "", "", "", "", "", "", "", "", // 0xC0
26          "", "", "", "", "", "", "", "", // 0xC8
27          "", "", "ConvertHex4", "", "", "", "", "", // 0xD0
28          "ConvertCardinal4", "", "", "", "", "", "", "", // 0xD8
29          "", "", "", "", "", "", "", "", // 0xE0
30          "", "", "", "", "", "", "", "", // 0xE8
31          "", "", "", "", "", "", "", "", // 0xF0
32          "", "", "", "", "", "", "", ""  // 0xF8
33      };
34  
35      public static Method getMethod(Integer offset) throws NoSuchMethodException {
36          return getMethod(methodNames[offset.intValue()]);
37      }
38  
39      private static final Method getMethod(String name) throws NoSuchMethodException {
40          return OSExt3.class.getMethod(name, METHOD_PARAMETERS);
41      }
42  
43      public final void ConvertHex4(Environment env) {
44          storeConvertResult(env, convertHex(env.getCpu().R[0], 4));
45      }
46  
47      private void storeConvertResult(Environment env, String s) {
48          final int[] R = env.getCpu().R;
49          if (s.length() > R[2]) {
50              s = s.substring(0, R[2]);
51          }
52          env.getMemoryMap().storeString0(R[1], s);
53          R[0] = R[1];
54          R[1] += s.length();
55          R[2] -= s.length();
56      }
57  
58      public final String convertHex(int value, int digits) {
59          String s = "0000000" + Integer.toHexString(value).toUpperCase();
60          return s.substring(s.length() - digits, s.length());
61      }
62  
63      public final void ConvertCardinal4(Environment env) {
64          storeConvertResult(env, convertCardinal(env.getCpu().R[0], 4));
65      }
66  
67      public final String convertCardinal(int value, int bytes) {
68          long mask = (1L << (bytes * 8)) - 1;
69          return Long.toString(((long) value) & mask);
70      }
71  }