3 import org.xwt.mips.Runtime;
4 import org.xwt.mips.Interpreter;
8 public class CallTest {
9 public static void main(String[] args) throws Exception {
10 int a1 = args.length > 0 ? Integer.parseInt(args[0]) : 0;
11 int a2 = args.length > 1 ? Integer.parseInt(args[1]) : 0;
12 int a3 = args.length > 2 ? Integer.parseInt(args[2]) : 0;
13 int a4 = args.length > 3 ? Integer.parseInt(args[3]) : 0;
14 int a5 = args.length > 4 ? Integer.parseInt(args[4]) : 0;
15 int a6 = args.length > 5 ? Integer.parseInt(args[5]) : 0;
17 System.out.println("Version is: " + System.getProperty("os.version"));
19 if(a1 == 99) // yeah.. this is ugly
20 rt = new Interpreter("build/tests/Test.mips");
23 protected int callJava(int a, int b, int c, int d) {
25 case 1: return strdup("OS: " + System.getProperty("os.name"));
26 case 2: return strdup(System.getProperty("os.version"));
27 case 3: return strdup(new Date().toString());
28 case 4: return allocFDEnt(new OutputStreamFD(new CustomOS()));
30 System.out.println("In callJava() in Java");
31 try { call("backinmips"); } catch(CallException e) { }
32 System.out.println("Back in callJava() in Java");
34 default: return super.callJava(a,b,c,d);
38 System.out.println("Runtime: " + rt);
40 rt.start(new String[]{"Test","calltest"});
43 System.out.println("== Start of CallTest ==");
44 System.out.println("Back in java... calling callme()");
45 int ret = rt.call("callme",a1,a2,a3,a4,a5,a6);
46 System.out.println("callme returned: " + ret);
48 int addr = rt.strdup("Hello, World from java");
49 rt.call("echo",addr,4);
51 System.out.println("== End of CallTest ==");
54 System.exit(rt.exitStatus());
57 private static class CustomOS extends OutputStream {
59 public void write(int b) { byte[] a = new byte[1]; a[0] = (byte)(b&0xff); write(a,0,1); }
60 public void write(byte[] b, int off, int len) {
62 while(b[len2-1]=='\n') len2--;
63 System.out.println("This just in from MIPS: " + new String(b,off,len2));