import org.xwt.mips.*;
import java.io.*;
+import org.xwt.mips.Runtime;
+
public class MSPack {
private static byte[] image;
private byte[][] data;
public static class MSPackException extends IOException { public MSPackException(String s) { super(s); } }
-
- private static synchronized byte[] getImage() throws IOException {
- if (image == null)
- image = InputStreamToByteArray.convert(Main.builtin.getInputStream("libmspack.mips"));
- return image;
- }
-
- public MSPack(InputStream cabIS) throws IOException {
- byte[] cab = InputStreamToByteArray.convert(cabIS);
- Interpreter vm = new Interpreter(getImage());
-
- int cabAddr = vm.sbrk(cab.length);
- if(cabAddr < 0) throw new MSPackException("sbrk failed");
+ public MSPack(InputStream cabIS) throws IOException {
try {
+ Runtime vm = (Runtime)Class.forName("org.xwt.translators.MIPSApps").newInstance();
+ byte[] cab = InputStreamToByteArray.convert(cabIS);
+ int cabAddr = vm.sbrk(cab.length);
+ if(cabAddr < 0) throw new MSPackException("sbrk failed");
+
vm.copyout(cab,cabAddr,cab.length);
vm.setUserInfo(0,cabAddr);
vm.setUserInfo(1,cab.length);
- int status = vm.run(new String[]{ "mspack.mips"} );
+ int status = vm.run(new String[]{ "mspack"} );
if(status != 0) throw new MSPackException("mspack.mips failed (" + status + ")");
/*static struct {
System.out.println("" + fileNames[i]);
vm.copyin(vm.memRead(addr+4),data[i],length);
}
- } catch(Exception e) {
+ } catch(Runtime.ExecutionException e) {
e.printStackTrace();
throw new MSPackException("mspack.mips crashed");
+ } catch(Exception e) {
+ throw new MSPackException(e.toString());
}
}