initial FDS bring-up
This commit is contained in:
parent
9ef50bbda7
commit
ac3772c024
14 changed files with 870 additions and 1 deletions
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include "apu.h"
|
||||
#include "fds.h"
|
||||
|
||||
#define mod_cycles_op(op, vl) cpu.cycles op vl
|
||||
#define r2006_during_rendering()\
|
||||
|
|
@ -314,4 +315,83 @@ INLINE static void apu_wr_reg(struct NESAPU* a, WORD address, BYTE value) {
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
INLINE static BYTE fds_wr_mem(struct _fds* fds, WORD address, BYTE value) {
|
||||
if (address == 0x4023) {
|
||||
fds->enabled_snd_reg=value&0x02;
|
||||
}
|
||||
if ((address >= 0x4040) && (address <= 0x408A)) {
|
||||
if (fds->enabled_snd_reg) {
|
||||
if ((address >= 0x4040) && (address <= 0x407F)) {
|
||||
fds->snd.wave.data[address & 0x003F] = value & 0x3F;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4080) {
|
||||
fds->snd.volume.speed = value & 0x3F;
|
||||
fds->snd.volume.increase = value & 0x40;
|
||||
fds->snd.volume.mode = value & 0x80;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4082) {
|
||||
fds->snd.main.frequency = (fds->snd.main.frequency & 0xFF00) | value;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4083) {
|
||||
fds->snd.main.frequency = ((value & 0x0F) << 8) | (fds->snd.main.frequency & 0x00FF);
|
||||
fds->snd.envelope.disabled = value & 0x40;
|
||||
fds->snd.main.silence = value & 0x80;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4084) {
|
||||
fds->snd.sweep.speed = value & 0x3F;
|
||||
fds->snd.sweep.increase = value & 0x40;
|
||||
fds->snd.sweep.mode = value & 0x80;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4085) {
|
||||
fds->snd.sweep.bias = ((SBYTE) (value << 1)) / 2;
|
||||
fds->snd.modulation.index = 0;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4086) {
|
||||
fds->snd.modulation.frequency = (fds->snd.modulation.frequency & 0xFF00) | value;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4087) {
|
||||
fds->snd.modulation.frequency = ((value & 0x0F) << 8)
|
||||
| (fds->snd.modulation.frequency & 0x00FF);
|
||||
fds->snd.modulation.disabled = value & 0x80;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4088) {
|
||||
BYTE i;
|
||||
|
||||
// 0,2,4,6,-8,-6,-4,-2
|
||||
for (i = 0; i < 32; i++) {
|
||||
BYTE a = i << 1;
|
||||
|
||||
if (i < 31) {
|
||||
fds->snd.modulation.data[a] = fds->snd.modulation.data[a + 2];
|
||||
} else {
|
||||
BYTE tmp = ((value & 0x03) | (0x3F * (value & 0x04)));
|
||||
fds->snd.modulation.data[a] = (SBYTE) tmp;
|
||||
}
|
||||
fds->snd.modulation.data[a + 1] = fds->snd.modulation.data[a];
|
||||
}
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x4089) {
|
||||
fds->snd.wave.writable = value & 0x80;
|
||||
fds->snd.wave.volume = value & 0x03;
|
||||
return (TRUE);
|
||||
}
|
||||
if (address == 0x408A) {
|
||||
fds->snd.envelope.speed = value;
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (FALSE);
|
||||
}
|
||||
#endif /* CPU_INLINE_H_ */
|
||||
|
|
|
|||
138
src/engine/platform/sound/nes/fds.c
Normal file
138
src/engine/platform/sound/nes/fds.c
Normal file
|
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "fds.h"
|
||||
|
||||
enum { TRANSFERED_8BIT = 0x02, END_OF_HEAD = 0x40 };
|
||||
|
||||
static const BYTE volume_wave[4] = { 39, 26, 19, 15 };
|
||||
|
||||
void fds_reset(struct _fds* fds) {
|
||||
memset(fds,0,sizeof(struct _fds));
|
||||
}
|
||||
|
||||
void extcl_apu_tick_FDS(struct _fds* fds) {
|
||||
SWORD freq;
|
||||
|
||||
/* volume unit */
|
||||
if (fds->snd.volume.mode) {
|
||||
fds->snd.volume.gain = fds->snd.volume.speed;
|
||||
} else if (!fds->snd.envelope.disabled && fds->snd.envelope.speed) {
|
||||
if (fds->snd.volume.counter) {
|
||||
fds->snd.volume.counter--;
|
||||
} else {
|
||||
fds->snd.volume.counter = (fds->snd.envelope.speed << 3) * (fds->snd.volume.speed + 1);
|
||||
if (fds->snd.volume.increase) {
|
||||
if (fds->snd.volume.gain < 32) {
|
||||
fds->snd.volume.gain++;
|
||||
}
|
||||
} else if (fds->snd.volume.gain) {
|
||||
fds->snd.volume.gain--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* sweep unit */
|
||||
if (fds->snd.sweep.mode) {
|
||||
fds->snd.sweep.gain = fds->snd.sweep.speed;
|
||||
} else if (!fds->snd.envelope.disabled && fds->snd.envelope.speed) {
|
||||
if (fds->snd.sweep.counter) {
|
||||
fds->snd.sweep.counter--;
|
||||
} else {
|
||||
fds->snd.sweep.counter = (fds->snd.envelope.speed << 3) * (fds->snd.sweep.speed + 1);
|
||||
if (fds->snd.sweep.increase) {
|
||||
if (fds->snd.sweep.gain < 32) {
|
||||
fds->snd.sweep.gain++;
|
||||
}
|
||||
} else if (fds->snd.sweep.gain) {
|
||||
fds->snd.sweep.gain--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* modulation unit */
|
||||
freq = fds->snd.main.frequency;
|
||||
|
||||
if (!fds->snd.modulation.disabled && fds->snd.modulation.frequency) {
|
||||
if ((fds->snd.modulation.counter -= fds->snd.modulation.frequency) < 0) {
|
||||
SWORD temp, temp2, a, d;
|
||||
SBYTE adj = fds->snd.modulation.data[fds->snd.modulation.index];
|
||||
|
||||
fds->snd.modulation.counter += 65536;
|
||||
|
||||
if (++fds->snd.modulation.index == 64) {
|
||||
fds->snd.modulation.index = 0;
|
||||
}
|
||||
|
||||
if (adj == -4) {
|
||||
fds->snd.sweep.bias = 0;
|
||||
} else {
|
||||
fds->snd.sweep.bias += adj;
|
||||
}
|
||||
|
||||
temp = fds->snd.sweep.bias * ((fds->snd.sweep.gain < 32) ? fds->snd.sweep.gain : 32);
|
||||
|
||||
a = 64;
|
||||
d = 0;
|
||||
|
||||
if (temp <= 0) {
|
||||
d = 15;
|
||||
} else if (temp < 3040) { //95 * 32
|
||||
a = 66;
|
||||
d = -31;
|
||||
}
|
||||
|
||||
temp2 = a + (SBYTE) ((temp - d) / 16 - a);
|
||||
|
||||
fds->snd.modulation.mod = freq * temp2 / 64;
|
||||
}
|
||||
|
||||
if (freq) {
|
||||
freq += fds->snd.modulation.mod;
|
||||
}
|
||||
}
|
||||
|
||||
/* main unit */
|
||||
if (fds->snd.main.silence) {
|
||||
fds->snd.main.output = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (freq && !fds->snd.wave.writable) {
|
||||
if ((fds->snd.wave.counter -= freq) < 0) {
|
||||
WORD level;
|
||||
|
||||
fds->snd.wave.counter += 65536;
|
||||
|
||||
level = (fds->snd.volume.gain < 32 ? fds->snd.volume.gain : 32)
|
||||
* volume_wave[fds->snd.wave.volume];
|
||||
|
||||
/* valore massimo dell'output (63 * (39 * 32)) = 78624 */
|
||||
/*fds->snd.main.output = (fds->snd.wave.data[fds->snd.wave.index] * level) >> 4;*/
|
||||
fds->snd.main.output = (fds->snd.wave.data[fds->snd.wave.index] * level) >> 3;
|
||||
|
||||
if (++fds->snd.wave.index == 64) {
|
||||
fds->snd.wave.index = 0;
|
||||
}
|
||||
|
||||
fds->snd.wave.clocked = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
94
src/engine/platform/sound/nes/fds.h
Normal file
94
src/engine/platform/sound/nes/fds.h
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#ifndef FDS_H_
|
||||
#define FDS_H_
|
||||
|
||||
#include "common.h"
|
||||
|
||||
enum fds_operations { FDS_OP_NONE, FDS_OP_READ, FDS_OP_WRITE };
|
||||
|
||||
#if defined (__cplusplus)
|
||||
#define EXTERNC extern "C"
|
||||
#else
|
||||
#define EXTERNC
|
||||
#endif
|
||||
|
||||
EXTERNC struct _fds {
|
||||
// snd
|
||||
BYTE enabled_snd_reg;
|
||||
struct _fds_snd {
|
||||
struct _fds_snd_wave {
|
||||
BYTE data[64];
|
||||
BYTE writable;
|
||||
BYTE volume;
|
||||
|
||||
BYTE index;
|
||||
int32_t counter;
|
||||
|
||||
/* ------------------------------------------------------- */
|
||||
/* questi valori non e' necessario salvarli nei savestates */
|
||||
/* ------------------------------------------------------- */
|
||||
/* */ BYTE clocked; /* */
|
||||
/* ------------------------------------------------------- */
|
||||
} wave;
|
||||
struct _fds_snd_envelope {
|
||||
BYTE speed;
|
||||
BYTE disabled;
|
||||
} envelope;
|
||||
struct _fds_snd_main {
|
||||
BYTE silence;
|
||||
WORD frequency;
|
||||
|
||||
SWORD output;
|
||||
} main;
|
||||
struct _fds_snd_volume {
|
||||
BYTE speed;
|
||||
BYTE mode;
|
||||
BYTE increase;
|
||||
|
||||
BYTE gain;
|
||||
uint32_t counter;
|
||||
} volume;
|
||||
struct _fds_snd_sweep {
|
||||
SBYTE bias;
|
||||
BYTE mode;
|
||||
BYTE increase;
|
||||
BYTE speed;
|
||||
|
||||
BYTE gain;
|
||||
uint32_t counter;
|
||||
} sweep;
|
||||
struct _fds_snd_modulation {
|
||||
SBYTE data[64];
|
||||
WORD frequency;
|
||||
BYTE disabled;
|
||||
|
||||
BYTE index;
|
||||
int32_t counter;
|
||||
SWORD mod;
|
||||
} modulation;
|
||||
} snd;
|
||||
};
|
||||
|
||||
EXTERNC void extcl_apu_tick_FDS(struct _fds* fds);
|
||||
EXTERNC void fds_reset(struct _fds* fds);
|
||||
|
||||
#undef EXTERNC
|
||||
|
||||
#endif /* FDS_H_ */
|
||||
Loading…
Add table
Add a link
Reference in a new issue