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
;
38 public class DiskImageSet
implements SRDumpable
40 private DiskImage
[] disks
;
41 private int diskCount
;
42 private int lowestGap
;
46 disks
= new DiskImage
[5];
51 public int addDisk(DiskImage image
)
56 if(diskCount
== disks
.length
) {
57 DiskImage
[] newDisks
= new DiskImage
[2 * disks
.length
];
58 System
.arraycopy(disks
, 0, newDisks
, 0, disks
.length
);
62 for(int i
= base
; i
< disks
.length
; i
++) {
63 if(disks
[i
] == null) {
71 return -1; //Can't come here.
74 public void addDisk(int id
, DiskImage image
)
76 while(id
>= disks
.length
) {
77 DiskImage
[] newDisks
= new DiskImage
[2 * disks
.length
];
78 System
.arraycopy(disks
, 0, newDisks
, 0, disks
.length
);
81 if(disks
[id
] == null && image
!= null)
83 if(lowestGap
== id
&& image
!= null)
85 else if(lowestGap
> id
&& image
== null)
91 public DiskImage
lookupDisk(int index
)
97 } catch(Exception e
) {
102 public int[] diskIndicesByType(BlockDevice
.Type type
)
104 int images
= 0, j
= 0;
105 for(int i
= 0; i
< disks
.length
; i
++)
106 if(disks
[i
] != null && disks
[i
].getType() == type
)
108 int[] diskIDs
= new int[images
];
109 for(int i
= 0; i
< disks
.length
; i
++)
110 if(disks
[i
] != null && disks
[i
].getType() == type
)
115 public int getDiskCount()
120 public int highestDiskIndex()
122 return disks
.length
- 1;
125 public void dumpStatusPartial(StatusDumper output
)
127 output
.println("\tdiskCount " + diskCount
+ " lowestGap " + lowestGap
);
128 for(int i
=0; i
< disks
.length
; i
++) {
129 output
.println("\tdisks[" + i
+ "] <object #" + output
.objectNumber(disks
[i
]) + ">");
130 if(disks
[i
] != null) disks
[i
].dumpStatus(output
);
134 public void dumpStatus(StatusDumper output
)
136 if(output
.dumped(this))
139 output
.println("#" + output
.objectNumber(this) + ": DiskImageSet:");
140 dumpStatusPartial(output
);
144 public void dumpSRPartial(SRDumper output
) throws IOException
146 output
.dumpInt(diskCount
);
147 output
.dumpInt(lowestGap
);
148 output
.dumpInt(disks
.length
);
149 for(int i
= 0; i
< disks
.length
; i
++)
150 output
.dumpObject(disks
[i
]);
153 public DiskImageSet(SRLoader input
) throws IOException
155 input
.objectCreated(this);
156 diskCount
= input
.loadInt();
157 lowestGap
= input
.loadInt();
158 disks
= new DiskImage
[input
.loadInt()];
159 for(int i
= 0; i
< disks
.length
; i
++)
160 disks
[i
] = (DiskImage
)(input
.loadObject());