Change FPU initialization method
[jpcrr.git] / SoundTest.java
blob4f7ebacff8c00e5ddc66cc30cbae151cb1462369
1 /*
2 JPC-RR: A x86 PC Hardware Emulator
3 Release 1
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;
35 import java.io.*;
37 /**
39 * @author Ilari Liusvaara
41 public class SoundTest extends AbstractHardwareComponent implements SoundOutputDevice, TimerResponsive
43 private Clock clock;
44 private Timer eventTimer;
45 private long timeBase;
46 private SoundDigitalOut out;
48 public boolean initialised()
50 return (clock != null);
53 public void reset()
55 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()
72 return 76;
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
86 super(input);
87 clock = (Clock)input.loadObject();
88 eventTimer = (Timer)input.loadObject();
89 out = (SoundDigitalOut)input.loadObject();
90 timeBase = input.loadLong();
93 public SoundTest()
97 public void dumpStatus(StatusDumper output)
101 public int requestedSoundChannels()
103 return 1;
106 public void soundChannelCallback(SoundDigitalOut _out)
108 out = _out;
111 public void acceptComponent(HardwareComponent component)
113 if ((component instanceof Clock) &&
114 component.initialised()) {
115 clock = (Clock)component;
116 //Timer fires in 1ms.
117 timeBase = 0;
118 eventTimer = clock.newTimer(this);
119 eventTimer.setExpiry(100000);