View Javadoc

1   /***
2    * Created by IntelliJ IDEA.
3    * User: gareth
4    * Date: Sep 11, 2003
5    * Time: 6:43:19 PM
6    */
7   package com.tapina.robe.swi;
8   
9   import com.tapina.robe.runtime.Environment;
10  import com.tapina.robe.runtime.FilenameUtils;
11  
12  import java.io.IOException;
13  import java.lang.reflect.Method;
14  
15  public final class DDEUtils extends SWIHandler {
16      private static DDEUtils ourInstance;
17  
18      public synchronized static DDEUtils getInstance() {
19          if (ourInstance == null) {
20              ourInstance = new DDEUtils();
21          }
22          return ourInstance;
23      }
24  
25      private DDEUtils() {
26      }
27  
28      public static int getBase() {
29          return 0x42580;
30      }
31  
32      private static final String[] methodNames = new String[] {
33          "Prefix", "SetCLSize", "SetCL", "GetCLSize", "GetCl", "ThrowbackRegister", "ThrowbackUnRegister", "ThrowbackStart", // 0x42580
34          "ThrowbackSend", "ThrowbackEnd", "ReadPrefix", "", "", "", "", "", // 0x42588
35          "", "", "", "", "", "", "", "", // 0x42590
36          "", "", "", "", "", "", "", "", // 0x42598
37          "", "", "", "", "", "", "", "", // 0x425a0
38          "", "", "", "", "", "", "", "", // 0x425a8
39          "", "", "", "", "", "", "", "", // 0x425b0
40          "", "", "", "", "", "", "", "" // 0x425b8
41      };
42  
43      public static Method getMethod(Integer offset) throws NoSuchMethodException {
44          return getMethod(methodNames[offset.intValue()]);
45      }
46  
47      private static final Method getMethod(String name) throws NoSuchMethodException {
48          return DDEUtils.class.getMethod(name, METHOD_PARAMETERS);
49      }
50  
51      /***
52       * This SWI is used to set the current directory for this context, relative to the global curent directory.
53       * R0 = pointer to directory name, or 0 to clear
54       */
55      public final void Prefix(Environment env) {
56          prefix(env.getMemoryMap().getString0(env.getCpu().R[0]));
57      }
58  
59      public void prefix(String dirName) {
60          try {
61              final String nativeDirName = FilenameUtils.acornToNative(dirName);
62              Runtime.getRuntime().exec(new String[] { "cd", nativeDirName });
63          } catch (IOException e) {
64              log.warning("Error during prefix(\"" + dirName + "\") - " + e.getMessage());
65              throw new SWIError(0, e);
66          }
67      }
68  
69  
70      public final void GetCLSize(Environment env) {
71          env.getCpu().R[0] = OS.getInstance().getEnv().getCommandLine().length() + 1;
72      }
73  
74      public final void GetCl(Environment env) {
75          env.getMemoryMap().storeString0(env.getCpu().R[0], OS.getInstance().getEnv().getCommandLine());
76      }
77  
78  }
79