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 import org
.jpc
.emulator
.motherboard
.*;
31 import org
.jpc
.emulator
.*;
32 import org
.jpc
.diskimages
.BlockDevice
;
33 import org
.jpc
.diskimages
.GenericBlockDevice
;
39 * @author Ilari Liusvaara
41 public class SoundTest
extends AbstractHardwareComponent
implements SoundOutputDevice
, TimerResponsive
44 private Timer eventTimer
;
45 private long timeBase
;
46 private SoundDigitalOut out
;
48 public boolean initialised()
50 return (clock
!= null);
58 public void callback()
60 long time
= clock
.getTime();
61 short sampleL
= (short)(32000 * Math
.sin(2 * 3.1415926535897 * time
/ 1000000));
62 short sampleR
= (short)(32000 * Math
.sin(2 * 3.1415926535897 * time
/ 2000000));
63 out
.addSample(time
, sampleL
, sampleR
);
65 //Timer fires in 0.1ms.
66 timeBase
= timeBase
+ 100000;
67 eventTimer
.setExpiry(timeBase
+ 100000);
70 public int getTimerType()
75 public void dumpSRPartial(SRDumper output
) throws IOException
77 super.dumpSRPartial(output
);
78 output
.dumpObject(clock
);
79 output
.dumpObject(eventTimer
);
80 output
.dumpObject(out
);
81 output
.dumpLong(timeBase
);
84 public SoundTest(SRLoader input
) throws IOException
87 clock
= (Clock
)input
.loadObject();
88 eventTimer
= (Timer
)input
.loadObject();
89 out
= (SoundDigitalOut
)input
.loadObject();
90 timeBase
= input
.loadLong();
97 public void dumpStatus(StatusDumper output
)
101 public int requestedSoundChannels()
106 public void soundChannelCallback(SoundDigitalOut _out
)
111 public void acceptComponent(HardwareComponent component
)
113 if ((component
instanceof Clock
) &&
114 component
.initialised()) {
115 clock
= (Clock
)component
;
116 //Timer fires in 1ms.
118 eventTimer
= clock
.newTimer(this);
119 eventTimer
.setExpiry(100000);