forked from Apple-2-Tools/jace
Whitespace reformat and moving around init code in hopes of getting U5 to playback correctly on the first try every boot
This commit is contained in:
parent
2f9b38e570
commit
55b3693466
@ -44,30 +44,30 @@ import javax.sound.sampled.SourceDataLine;
|
|||||||
* 6522 chips to communicate to two respective AY PSG sound chips. This class
|
* 6522 chips to communicate to two respective AY PSG sound chips. This class
|
||||||
* manages the I/O access as well as the sound playback thread.
|
* manages the I/O access as well as the sound playback thread.
|
||||||
*
|
*
|
||||||
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
|
* @author Brendan Robert (BLuRry) brendan.robert@gmail.com
|
||||||
*/
|
*/
|
||||||
@Name("Mockingboard")
|
@Name("Mockingboard")
|
||||||
public class CardMockingboard extends Card implements Runnable {
|
public class CardMockingboard extends Card implements Runnable {
|
||||||
// If true, emulation will cover 4 AY chips. Otherwise, only 2 AY chips
|
// If true, emulation will cover 4 AY chips. Otherwise, only 2 AY chips
|
||||||
|
|
||||||
@ConfigurableField(name = "Volume", shortName = "vol",
|
@ConfigurableField(name = "Volume", shortName = "vol",
|
||||||
category = "Sound",
|
category = "Sound",
|
||||||
description = "Mockingboard volume, 100=max, 0=silent")
|
description = "Mockingboard volume, 100=max, 0=silent")
|
||||||
public int volume = 100;
|
public int volume = 100;
|
||||||
static public int MAX_AMPLITUDE = 0x007fff;
|
static public int MAX_AMPLITUDE = 0x007fff;
|
||||||
@ConfigurableField(name = "Phasor mode",
|
@ConfigurableField(name = "Phasor mode",
|
||||||
category = "Sound",
|
category = "Sound",
|
||||||
description = "If enabled, card will have 4 sound chips instead of 2")
|
description = "If enabled, card will have 4 sound chips instead of 2")
|
||||||
public boolean phasorMode = false;
|
public boolean phasorMode = false;
|
||||||
@ConfigurableField(name = "Clock Rate (hz)",
|
@ConfigurableField(name = "Clock Rate (hz)",
|
||||||
category = "Sound",
|
category = "Sound",
|
||||||
defaultValue = "1020484",
|
defaultValue = "1020484",
|
||||||
description = "Clock rate of AY oscillators")
|
description = "Clock rate of AY oscillators")
|
||||||
public int CLOCK_SPEED = 1020484;
|
public int CLOCK_SPEED = 1020484;
|
||||||
public int SAMPLE_RATE = 48000;
|
public int SAMPLE_RATE = 48000;
|
||||||
@ConfigurableField(name = "Buffer size",
|
@ConfigurableField(name = "Buffer size",
|
||||||
category = "Sound",
|
category = "Sound",
|
||||||
description = "Number of samples to generate on each pass")
|
description = "Number of samples to generate on each pass")
|
||||||
public int BUFFER_LENGTH = 2;
|
public int BUFFER_LENGTH = 2;
|
||||||
// The array of configured AY chips
|
// The array of configured AY chips
|
||||||
public PSG[] chips;
|
public PSG[] chips;
|
||||||
@ -93,12 +93,12 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
final int j = i;
|
final int j = i;
|
||||||
controllers[i] = new R6522(computer) {
|
controllers[i] = new R6522(computer) {
|
||||||
int controller = j;
|
int controller = j;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendOutputA(int value) {
|
public void sendOutputA(int value) {
|
||||||
chips[j].setBus(value);
|
chips[j].setBus(value);
|
||||||
if (phasorMode) {
|
if (phasorMode) {
|
||||||
chips[j+2].setBus(value);
|
chips[j + 2].setBus(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,8 +108,8 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
if ((chips[j].mask & value) != 0) {
|
if ((chips[j].mask & value) != 0) {
|
||||||
chips[j].setControl(value & 0x07);
|
chips[j].setControl(value & 0x07);
|
||||||
}
|
}
|
||||||
if ((chips[j+2].mask & value) != 0) {
|
if ((chips[j + 2].mask & value) != 0) {
|
||||||
chips[j+2].setControl(value & 0x07);
|
chips[j + 2].setControl(value & 0x07);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
chips[j].setControl(value & 0x07);
|
chips[j].setControl(value & 0x07);
|
||||||
@ -142,7 +142,6 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void handleFirmwareAccess(int register, TYPE type, int value, RAMEvent e) {
|
protected void handleFirmwareAccess(int register, TYPE type, int value, RAMEvent e) {
|
||||||
// System.out.println(e.getType().toString() + " event to mockingboard register "+Integer.toHexString(register)+", value "+e.getNewValue());
|
|
||||||
resume();
|
resume();
|
||||||
int chip = 0;
|
int chip = 0;
|
||||||
for (PSG psg : chips) {
|
for (PSG psg : chips) {
|
||||||
@ -159,7 +158,6 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
R6522 controller = controllers[chip & 1];
|
R6522 controller = controllers[chip & 1];
|
||||||
if (e.getType().isRead()) {
|
if (e.getType().isRead()) {
|
||||||
int val = controller.readRegister(register & 0x0f);
|
int val = controller.readRegister(register & 0x0f);
|
||||||
// System.out.println("Register returns "+Integer.toHexString(val));
|
|
||||||
e.setNewValue(val);
|
e.setNewValue(val);
|
||||||
} else {
|
} else {
|
||||||
controller.writeRegister(register & 0x0f, e.getNewValue());
|
controller.writeRegister(register & 0x0f, e.getNewValue());
|
||||||
@ -209,7 +207,7 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
boolean restart = suspend();
|
boolean restart = suspend();
|
||||||
initPSG();
|
initPSG();
|
||||||
for (PSG chip : chips) {
|
for (PSG chip : chips) {
|
||||||
chip.setRate(phasorMode ? CLOCK_SPEED*2 : CLOCK_SPEED, SAMPLE_RATE);
|
chip.setRate(phasorMode ? CLOCK_SPEED * 2 : CLOCK_SPEED, SAMPLE_RATE);
|
||||||
chip.reset();
|
chip.reset();
|
||||||
}
|
}
|
||||||
super.reconfigure();
|
super.reconfigure();
|
||||||
@ -217,8 +215,7 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
resume();
|
resume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////
|
||||||
public static int[] VolTable;
|
public static int[] VolTable;
|
||||||
int[][] buffers;
|
int[][] buffers;
|
||||||
@ -249,6 +246,7 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
VolTable[i] = (int) Math.round(out); /* round to nearest */ // [TC: unsigned int cast]
|
VolTable[i] = (int) Math.round(out); /* round to nearest */ // [TC: unsigned int cast]
|
||||||
// out /= 1.188502227; /* = 10 ^ (1.5/20) = 1.5dB */
|
// out /= 1.188502227; /* = 10 ^ (1.5/20) = 1.5dB */
|
||||||
// out /= 1.15; /* = 10 ^ (3/20) = 3dB */
|
// out /= 1.15; /* = 10 ^ (3/20) = 3dB */
|
||||||
|
|
||||||
delta += 0.0225;
|
delta += 0.0225;
|
||||||
out /= delta; // As per applewin's source, the levels don't scale as documented.
|
out /= delta; // As per applewin's source, the levels don't scale as documented.
|
||||||
}
|
}
|
||||||
@ -256,13 +254,17 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
}
|
}
|
||||||
Thread playbackThread = null;
|
Thread playbackThread = null;
|
||||||
boolean pause = false;
|
boolean pause = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resume() {
|
public void resume() {
|
||||||
pause = false;
|
pause = false;
|
||||||
if (!isRunning()) {
|
if (!isRunning()) {
|
||||||
if (chips == null) {
|
if (chips == null) {
|
||||||
initPSG();
|
initPSG();
|
||||||
|
for (PSG psg : chips) {
|
||||||
|
psg.setRate(phasorMode ? CLOCK_SPEED * 2 : CLOCK_SPEED, SAMPLE_RATE);
|
||||||
|
psg.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (R6522 controller : controllers) {
|
for (R6522 controller : controllers) {
|
||||||
controller.attach();
|
controller.attach();
|
||||||
@ -283,12 +285,6 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
controller.suspend();
|
controller.suspend();
|
||||||
controller.detach();
|
controller.detach();
|
||||||
}
|
}
|
||||||
// Reset PSG registers
|
|
||||||
if (chips != null) {
|
|
||||||
for (PSG psg : chips) {
|
|
||||||
psg.reset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (playbackThread == null || !playbackThread.isAlive()) {
|
if (playbackThread == null || !playbackThread.isAlive()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -395,14 +391,14 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
private void initPSG() {
|
private void initPSG() {
|
||||||
if (phasorMode) {
|
if (phasorMode) {
|
||||||
chips = new PSG[4];
|
chips = new PSG[4];
|
||||||
chips[0] = new PSG(0x10, CLOCK_SPEED*2, SAMPLE_RATE, "AY1", 8);
|
chips[0] = new PSG(0x10, CLOCK_SPEED * 2, SAMPLE_RATE, "AY1", 8);
|
||||||
chips[1] = new PSG(0x80, CLOCK_SPEED*2, SAMPLE_RATE, "AY2", 8);
|
chips[1] = new PSG(0x80, CLOCK_SPEED * 2, SAMPLE_RATE, "AY2", 8);
|
||||||
chips[2] = new PSG(0x10, CLOCK_SPEED*2, SAMPLE_RATE, "AY3", 16);
|
chips[2] = new PSG(0x10, CLOCK_SPEED * 2, SAMPLE_RATE, "AY3", 16);
|
||||||
chips[3] = new PSG(0x80, CLOCK_SPEED*2, SAMPLE_RATE, "AY4", 16);
|
chips[3] = new PSG(0x80, CLOCK_SPEED * 2, SAMPLE_RATE, "AY4", 16);
|
||||||
} else {
|
} else {
|
||||||
chips = new PSG[2];
|
chips = new PSG[2];
|
||||||
chips[0] = new PSG(0, CLOCK_SPEED, SAMPLE_RATE, "AY1", 255);
|
chips[0] = new PSG(0, CLOCK_SPEED, SAMPLE_RATE, "AY1", 255);
|
||||||
chips[1] = new PSG(0x80, CLOCK_SPEED, SAMPLE_RATE, "AY2", 255);
|
chips[1] = new PSG(0x80, CLOCK_SPEED, SAMPLE_RATE, "AY2", 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,4 +412,4 @@ public class CardMockingboard extends Card implements Runnable {
|
|||||||
public boolean suspendWithCPU() {
|
public boolean suspendWithCPU() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user