2 JPC-RR: A x86 PC Hardware Emulator
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009 H. Ilari Liusvaara
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as published by
10 the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 Based on JPC x86 PC Hardware emulator,
22 A project from the Physics Dept, The University of Oxford
24 Details about original JPC can be found at:
26 www-jpc.physics.ox.ac.uk
30 package org
.jpc
.luaextensions
;
36 import java
.util
.zip
.*;
37 import java
.lang
.reflect
.*;
39 import org
.jpc
.plugins
.LuaPlugin
;
40 import org
.jpc
.jrsr
.*;
41 import static org
.jpc
.Misc
.parseStringToComponents
;
42 import static org
.jpc
.Misc
.errorDialog
;
43 import static org
.jpc
.Misc
.tempname
;
44 import static org
.jpc
.Misc
.nextParseLine
;
45 import static org
.jpc
.Misc
.parseString
;
46 import static org
.jpc
.Misc
.encodeLine
;
48 //Locking this class is used for preventing termination and when terminating.
49 public class BinaryOutFile
extends LuaPlugin
.LuaResource
53 BinaryOutFile(LuaPlugin plugin
, OutputStream os
) throws IOException
59 public void destroy() throws IOException
65 public int luaCB_four_to_five(Lua l
, LuaPlugin plugin
)
68 plugin
.generateLuaClass(l
, new BinaryOutFile(plugin
, new FourToFiveEncoder(object
)));
69 } catch(IOException e
) {
71 l
.pushString("IOException: " + e
.getMessage());
73 } catch(IllegalArgumentException e
) {
75 l
.pushString("Illegal argument: " + e
.getMessage());
81 public int luaCB_deflate(Lua l
, LuaPlugin plugin
)
84 plugin
.generateLuaClass(l
, new BinaryOutFile(plugin
, new DeflaterOutputStream(object
)));
85 } catch(IOException e
) {
87 l
.pushString("IOException: " + e
.getMessage());
89 } catch(IllegalArgumentException e
) {
91 l
.pushString("Illegal argument: " + e
.getMessage());
97 public int luaCB_text(Lua l
, LuaPlugin plugin
)
100 plugin
.generateLuaClass(l
, new TextOutFile(plugin
, object
));
101 } catch(IOException e
) {
103 l
.pushString("IOException: " + e
.getMessage());
105 } catch(IllegalArgumentException e
) {
107 l
.pushString("Illegal argument: " + e
.getMessage());
113 public int luaCB_write(Lua l
, LuaPlugin plugin
)
117 String towrite
= l
.checkString(2);
122 byte[] tmp
= new byte[towrite
.length()];
123 for(int i
= 0; i
< towrite
.length(); i
++)
124 tmp
[i
] = (byte)towrite
.charAt(i
);
127 } catch(IOException e
) {
128 l
.pushBoolean(false);
129 l
.pushString("IOException: " + e
.getMessage());
135 public int luaCB_close(Lua l
, LuaPlugin plugin
)
138 plugin
.destroyLuaObject(l
);
140 } catch(IOException e
) {
141 l
.pushBoolean(false);
142 l
.pushString("IOException: " + e
.getMessage());
148 public static int luaCB_open(Lua l
, LuaPlugin plugin
)
151 String name
= l
.checkString(1);
153 plugin
.generateLuaClass(l
, new BinaryOutFile(plugin
, new FileOutputStream(name
)));
154 } catch(IOException e
) {
156 l
.pushString("IOException: " + e
.getMessage());
158 } catch(IllegalArgumentException e
) {
160 l
.pushString("Illegal argument: " + e
.getMessage());