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
.diskimages
;
33 import org
.jpc
.emulator
.SRLoader
;
34 import org
.jpc
.emulator
.SRDumper
;
35 import org
.jpc
.emulator
.StatusDumper
;
36 import org
.jpc
.emulator
.SRDumpable
;
39 public class GenericBlockDevice
implements BlockDevice
, SRDumpable
41 private DiskImage image
;
42 private boolean isLocked
;
43 private BlockDevice
.Type diskType
;
45 public void dumpStatusPartial(StatusDumper output
)
47 output
.println("\tdiskType " + diskType
+ " isLocked " + isLocked
);
48 output
.println("\timage <object #" + output
.objectNumber(image
) + ">"); if(image
!= null) image
.dumpStatus(output
);
51 public void dumpStatus(StatusDumper output
)
53 if(output
.dumped(this))
56 output
.println("#" + output
.objectNumber(this) + ": GenericBlockDevice:");
57 dumpStatusPartial(output
);
61 public void dumpSRPartial(SRDumper output
) throws IOException
63 output
.dumpObject(image
);
64 output
.dumpBoolean(isLocked
);
67 output
.dumpByte((byte)0);
70 output
.dumpByte((byte)1);
73 output
.dumpByte((byte)2);
78 public GenericBlockDevice(SRLoader input
) throws IOException
80 input
.objectCreated(this);
81 image
= (DiskImage
)(input
.loadObject());
82 isLocked
= input
.loadBoolean();
83 byte tmpDiskType
= input
.loadByte();
86 diskType
= BlockDevice
.Type
.FLOPPY
;
89 diskType
= BlockDevice
.Type
.HARDDRIVE
;
92 diskType
= BlockDevice
.Type
.CDROM
;
95 throw new IOException("Invalid disk type in GenericBlockDevice.");
99 public GenericBlockDevice(BlockDevice
.Type driveType
)
101 diskType
= driveType
;
106 public GenericBlockDevice(DiskImage _image
) throws IOException
108 diskType
= _image
.getType();
114 public GenericBlockDevice(DiskImage _image
, BlockDevice
.Type expectedType
) throws IOException
116 if(_image
!= null && _image
.getType() != expectedType
)
117 throw new IOException("Disk is of wrong type.");
118 diskType
= expectedType
;
125 public byte[] getImageID()
128 return image
.getImageID();
139 public int read(long sectorNumber
, byte[] buffer
, int size
)
142 return image
.read(sectorNumber
, buffer
, size
);
147 public int write(long sectorNumber
, byte[] buffer
, int size
)
150 return image
.write(sectorNumber
, buffer
, size
);
155 public boolean isInserted()
157 return (image
!= null);
160 public boolean isLocked()
165 public boolean isReadOnly()
168 return image
.isReadOnly();
173 public void setLock(boolean locked
)
178 public long getTotalSectors()
181 return image
.getTotalSectors();
186 public int getCylinders()
189 return image
.getCylinders();
194 public int getHeads()
197 return image
.getHeads();
202 public int getSectors()
205 return image
.getSectors();
210 public BlockDevice
.Type
getType()
215 public String
getImageFileName()
218 return image
.getImageFileName();
223 public void configure(String spec
) throws IOException
225 //Just implement this, as its required by interface.
226 DiskImage dImage
= new DiskImage(spec
, false);
230 public void configure(DiskImage spec
) throws IOException
232 if(spec
!= null && spec
.getType() != diskType
)
233 throw new IOException("Trying to put disk of wrong type to drive.");
235 throw new IOException("Can not change disk in locked drive.");
243 public DiskImage
getImage()