2 JPC-RR: A x86 PC Hardware Emulator
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
;
33 import org
.jpc
.emulator
.StatusDumper
;
34 import org
.jpc
.emulator
.SRDumpable
;
35 import org
.jpc
.emulator
.SRDumper
;
36 import org
.jpc
.emulator
.SRLoader
;
38 import java
.nio
.charset
.*;
40 public class OutputChannel
implements SRDumpable
47 public OutputChannel(Output _out
, short chanType
, String chanName
)
56 protected void setChan(short _chan
)
61 protected short getChan()
66 protected String
getName()
71 protected short getType()
76 public void addFrame(OutputFrame newFrame
, boolean sync
)
78 out
.addFrame(this, newFrame
, sync
);
81 public byte[] channelHeader()
83 ByteBuffer _xname
= null;
86 _xname
= Charset
.forName("UTF-8").newEncoder().encode(CharBuffer
.wrap(name
));
87 _name
= new byte[_xname
.remaining()];
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
);
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))
133 output
.println("#" + output
.objectNumber(this) + ": OutputChannel:");
134 dumpStatusPartial(output
);