NHMLFixup v10
[jpcrr.git] / org / jpc / output / OutputChannel.java
blob8229b096f489eaa1598d2f7156662fab2754c56e
1 /*
2 JPC-RR: A x86 PC Hardware Emulator
3 Release 1
5 Copyright (C) 2007-2009 Isis Innovation Limited
6 Copyright (C) 2009-2010 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.output;
32 import java.io.*;
33 import org.jpc.emulator.StatusDumper;
34 import org.jpc.emulator.SRDumpable;
35 import org.jpc.emulator.SRDumper;
36 import org.jpc.emulator.SRLoader;
37 import java.nio.*;
38 import java.nio.charset.*;
40 public class OutputChannel implements SRDumpable
42 private short type;
43 private String name;
44 private short chan;
45 private Output out;
47 public OutputChannel(Output _out, short chanType, String chanName)
49 type = chanType;
50 name = chanName;
51 chan = -1;
52 out = _out;
53 out.newChannel(this);
56 protected void setChan(short _chan)
58 chan = _chan;
61 protected short getChan()
63 return chan;
66 protected String getName()
68 return name;
71 protected short getType()
73 return type;
76 public void addFrame(OutputFrame newFrame, boolean sync)
78 out.addFrame(this, newFrame, sync);
81 public byte[] channelHeader()
83 ByteBuffer _xname = null;
84 byte[] _name = null;
85 try {
86 _xname = Charset.forName("UTF-8").newEncoder().encode(CharBuffer.wrap(name));
87 _name = new byte[_xname.remaining()];
88 _xname.get(_name);
89 } catch(Exception e) {
90 _name = new byte[]{0x33}; //WTF?
92 int len = 6 + _name.length;
93 byte[] buf = new byte[len];
94 buf[0] = (byte)((chan >> 8) & 0xFF);
95 buf[1] = (byte)(chan & 0xFF);
96 buf[2] = (byte)((type >> 8) & 0xFF);
97 buf[3] = (byte)(type & 0xFF);
98 buf[4] = (byte)((_name.length >> 8) & 0xFF);
99 buf[5] = (byte)(_name.length & 0xFF);
100 System.arraycopy(_name, 0, buf, 6, _name.length);
101 return buf;
104 public void dumpSRPartial(SRDumper output) throws IOException
106 output.dumpShort(type);
107 output.dumpShort(chan);
108 output.dumpString(name);
109 output.dumpObject(out);
112 public void dumpStatusPartial(StatusDumper output)
114 output.println("\ttype " + type + " chan " + chan);
115 output.println("\tname " + name);
116 output.println("\tout <object #" + output.objectNumber(out) + ">"); if(out != null) out.dumpStatus(output);
119 public OutputChannel(SRLoader input) throws IOException
121 input.objectCreated(this);
122 type = input.loadShort();
123 chan = input.loadShort();
124 name = input.loadString();
125 out = (Output)input.loadObject();
128 public void dumpStatus(StatusDumper output)
130 if(output.dumped(this))
131 return;
133 output.println("#" + output.objectNumber(this) + ": OutputChannel:");
134 dumpStatusPartial(output);
135 output.endObject();