mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-22 12:35:11 +00:00
no more global variables!
This commit is contained in:
parent
5599ee327b
commit
f415e4c9a1
8 changed files with 236 additions and 229 deletions
|
@ -3,98 +3,60 @@
|
|||
|
||||
#include "supervision.h"
|
||||
|
||||
enum {FALSE, TRUE};
|
||||
|
||||
#include <string.h>
|
||||
|
||||
uint32 UNSCALED_CLOCK = 4000000;
|
||||
#define SV_SAMPLE_RATE ((UNSCALED_CLOCK)/64)
|
||||
#define SV_SAMPLE_RATE ((svision->UNSCALED_CLOCK)/64)
|
||||
#define SV_DEC_TICK ((SV_SAMPLE_RATE)/60)
|
||||
|
||||
uint32 decrement_tick = 0;
|
||||
|
||||
uint8 supervision_dma_mem[65536];
|
||||
|
||||
void supervision_sound_set_clock(uint32 clock) {
|
||||
UNSCALED_CLOCK = clock;
|
||||
void supervision_sound_set_clock(struct svision_t *svision, uint32 clock) {
|
||||
svision->UNSCALED_CLOCK = clock;
|
||||
}
|
||||
|
||||
void supervision_memorymap_registers_write(uint32 Addr, uint8 Value)
|
||||
void supervision_memorymap_registers_write(struct svision_t *svision, uint32 Addr, uint8 Value)
|
||||
{
|
||||
switch (Addr & 0x1fff) {
|
||||
case 0x10: case 0x11: case 0x12: case 0x13:
|
||||
case 0x14: case 0x15: case 0x16: case 0x17:
|
||||
supervision_sound_wave_write(((Addr & 0x4) >> 2), Addr & 3, Value);
|
||||
supervision_sound_wave_write(svision, ((Addr & 0x4) >> 2), Addr & 3, Value);
|
||||
break;
|
||||
case 0x18:
|
||||
case 0x19:
|
||||
case 0x1a:
|
||||
case 0x1b:
|
||||
case 0x1c:
|
||||
supervision_sound_dma_write(Addr & 0x07, Value);
|
||||
supervision_sound_dma_write(svision, Addr & 0x07, Value);
|
||||
break;
|
||||
case 0x28:
|
||||
case 0x29:
|
||||
case 0x2a:
|
||||
supervision_sound_noise_write(Addr & 0x07, Value);
|
||||
supervision_sound_noise_write(svision, Addr & 0x07, Value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 ch_mask = 15;
|
||||
uint32 flags = 0b00000001;
|
||||
|
||||
void supervision_set_mute_mask(uint32 mask) {
|
||||
ch_mask = mask;
|
||||
void supervision_set_mute_mask(struct svision_t *svision, uint8 mask) {
|
||||
svision->ch_mask = mask;
|
||||
}
|
||||
|
||||
void supervision_sound_set_flags(uint32 flags_set)
|
||||
void supervision_sound_set_flags(struct svision_t *svision, uint8 flags_set)
|
||||
{
|
||||
flags = flags_set;
|
||||
svision->flags = flags_set;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
uint8 reg[4];
|
||||
int on;
|
||||
uint8 waveform, volume;
|
||||
uint16 pos, size;
|
||||
uint16 count;
|
||||
} SVISION_CHANNEL;
|
||||
SVISION_CHANNEL m_channel[2];
|
||||
// For clear sound (no grating), sync with m_channel
|
||||
SVISION_CHANNEL ch[2];
|
||||
|
||||
typedef struct {
|
||||
uint8 reg[3];
|
||||
int on, right, left, play;
|
||||
uint8 type; // 6 - 7-Bit, 14 - 15-Bit
|
||||
uint16 state;
|
||||
uint8 value, volume;
|
||||
uint16 count;
|
||||
real pos, step;
|
||||
} SVISION_NOISE;
|
||||
SVISION_NOISE m_noise;
|
||||
|
||||
typedef struct {
|
||||
uint8 reg[5];
|
||||
int on, right, left;
|
||||
uint32 ca14to16;
|
||||
uint16 start;
|
||||
uint16 size;
|
||||
real pos, step;
|
||||
} SVISION_DMA;
|
||||
SVISION_DMA m_dma;
|
||||
|
||||
void supervision_sound_reset(void)
|
||||
void supervision_sound_reset(struct svision_t *svision)
|
||||
{
|
||||
memset(m_channel, 0, sizeof(m_channel));
|
||||
memset(&m_noise, 0, sizeof(m_noise) );
|
||||
memset(&m_dma, 0, sizeof(m_dma) );
|
||||
memset(svision->m_channel, 0, sizeof(svision->m_channel));
|
||||
memset(&svision->m_noise, 0, sizeof(svision->m_noise) );
|
||||
memset(&svision->m_dma, 0, sizeof(svision->m_dma) );
|
||||
|
||||
memset(ch, 0, sizeof(ch) );
|
||||
decrement_tick = 0;
|
||||
ch_mask = 15;
|
||||
memset(svision->ch, 0, sizeof(svision->ch) );
|
||||
svision->decrement_tick = 0;
|
||||
svision->ch_mask = 15;
|
||||
}
|
||||
|
||||
void supervision_sound_stream_update(uint8 *stream, uint32 len)
|
||||
void supervision_sound_stream_update(struct svision_t *svision, uint8 *stream, uint32 len)
|
||||
{
|
||||
size_t i, j;
|
||||
SVISION_CHANNEL *channel;
|
||||
|
@ -105,29 +67,29 @@ void supervision_sound_stream_update(uint8 *stream, uint32 len)
|
|||
|
||||
for (i = 0; i < len >> 1; i++, left += 2, right += 2) {
|
||||
*left = *right = 0;
|
||||
for (channel = m_channel, j = 0; j < 2; j++, channel++) {
|
||||
for (channel = svision->m_channel, j = 0; j < 2; j++, channel++) {
|
||||
chout[j] = 0;
|
||||
if (ch[j].size != 0) {
|
||||
if (ch[j].on || channel->count != 0) {
|
||||
if (svision->ch[j].size != 0) {
|
||||
if (svision->ch[j].on || channel->count != 0) {
|
||||
BOOL on = FALSE;
|
||||
switch (ch[j].waveform) {
|
||||
switch (svision->ch[j].waveform) {
|
||||
case 0: // 12.5%
|
||||
on = ch[j].pos < (28 * ch[j].size) >> 5;
|
||||
on = svision->ch[j].pos < (28 * svision->ch[j].size) >> 5;
|
||||
break;
|
||||
case 1: // 25%
|
||||
on = ch[j].pos < (24 * ch[j].size) >> 5;
|
||||
on = svision->ch[j].pos < (24 * svision->ch[j].size) >> 5;
|
||||
break;
|
||||
case 2: // 50%
|
||||
on = ch[j].pos < ch[j].size / 2;
|
||||
on = svision->ch[j].pos < svision->ch[j].size / 2;
|
||||
break;
|
||||
case 3: // 75%
|
||||
on = ch[j].pos < ch[j].size / 4;
|
||||
// MESS/MAME: <= (9 * ch[j].size) >> 5;
|
||||
on = svision->ch[j].pos < svision->ch[j].size / 4;
|
||||
// MESS/MAME: <= (9 * svision->ch[j].size) >> 5;
|
||||
break;
|
||||
}
|
||||
s = on ? (ch[j].volume)<<2 : 0;
|
||||
s = ((ch_mask>>(3-j))&1)?s:0;
|
||||
if (flags&1) {
|
||||
s = on ? (svision->ch[j].volume)<<2 : 0;
|
||||
s = ((svision->ch_mask>>(3-j))&1)?s:0;
|
||||
if (svision->flags&1) {
|
||||
if (j == 0)
|
||||
*right += s;
|
||||
else
|
||||
|
@ -138,91 +100,91 @@ void supervision_sound_stream_update(uint8 *stream, uint32 len)
|
|||
}
|
||||
chout[j] = s;
|
||||
}
|
||||
ch[j].pos++;
|
||||
if (ch[j].pos >= ch[j].size) {
|
||||
ch[j].pos = 0;
|
||||
svision->ch[j].pos++;
|
||||
if (svision->ch[j].pos >= svision->ch[j].size) {
|
||||
svision->ch[j].pos = 0;
|
||||
// Transition from off to on
|
||||
if (channel->on) {
|
||||
memcpy(&ch[j], channel, sizeof(ch[j]));
|
||||
memcpy(&svision->ch[j], channel, sizeof(svision->ch[j]));
|
||||
channel->on = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_noise.on && (m_noise.play || m_noise.count != 0)) {
|
||||
s = (m_noise.value * m_noise.volume) << 2;
|
||||
s = ch_mask&1?s:0;
|
||||
if (svision->m_noise.on && (svision->m_noise.play || svision->m_noise.count != 0)) {
|
||||
s = (svision->m_noise.value * svision->m_noise.volume) << 2;
|
||||
s = svision->ch_mask&1?s:0;
|
||||
chout[3] = 0;
|
||||
if (m_noise.left) {
|
||||
if (svision->m_noise.left) {
|
||||
*left += s;
|
||||
chout[3] = s;
|
||||
}
|
||||
if (m_noise.right) {
|
||||
if (svision->m_noise.right) {
|
||||
*right += s;
|
||||
chout[3] = s;
|
||||
}
|
||||
m_noise.pos += m_noise.step;
|
||||
while (m_noise.pos >= 1.0) { // if/while difference - Pacific Battle
|
||||
svision->m_noise.pos += svision->m_noise.step;
|
||||
while (svision->m_noise.pos >= 1.0) { // if/while difference - Pacific Battle
|
||||
// LFSR: x^2 + x + 1
|
||||
uint16 feedback;
|
||||
m_noise.value = m_noise.state & 1;
|
||||
feedback = ((m_noise.state >> 1) ^ m_noise.state) & 0x0001;
|
||||
feedback <<= m_noise.type;
|
||||
m_noise.state = (m_noise.state >> 1) | feedback;
|
||||
m_noise.pos -= 1.0;
|
||||
svision->m_noise.value = svision->m_noise.state & 1;
|
||||
feedback = ((svision->m_noise.state >> 1) ^ svision->m_noise.state) & 0x0001;
|
||||
feedback <<= svision->m_noise.type;
|
||||
svision->m_noise.state = (svision->m_noise.state >> 1) | feedback;
|
||||
svision->m_noise.pos -= 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
chout[2] = 0;
|
||||
if (m_dma.on) {
|
||||
if (svision->m_dma.on) {
|
||||
uint8 sample;
|
||||
uint16 addr = m_dma.start + (uint16)m_dma.pos / 2;
|
||||
uint16 addr = svision->m_dma.start + (uint16)svision->m_dma.pos / 2;
|
||||
if (addr >= 0x8000 && addr < 0xc000) {
|
||||
sample = supervision_dma_mem[(addr & 0x3fff) | m_dma.ca14to16];
|
||||
sample = svision->supervision_dma_mem[(addr & 0x3fff) | svision->m_dma.ca14to16];
|
||||
}
|
||||
if (((uint16)m_dma.pos) & 1)
|
||||
if (((uint16)svision->m_dma.pos) & 1)
|
||||
s = (sample & 0xf);
|
||||
else
|
||||
s = (sample & 0xf0) >> 4;
|
||||
s <<= 2;
|
||||
s = ((ch_mask>>1)&1)?s:0;
|
||||
s = ((svision->ch_mask>>1)&1)?s:0;
|
||||
chout[2] = 0;
|
||||
if (m_dma.left) {
|
||||
if (svision->m_dma.left) {
|
||||
*left += s;
|
||||
chout[2] = s;
|
||||
}
|
||||
if (m_dma.right) {
|
||||
if (svision->m_dma.right) {
|
||||
*right += s;
|
||||
chout[2] = s;
|
||||
}
|
||||
m_dma.pos += m_dma.step;
|
||||
if (m_dma.pos >= m_dma.size) {
|
||||
m_dma.on = FALSE;
|
||||
svision->m_dma.pos += svision->m_dma.step;
|
||||
if (svision->m_dma.pos >= svision->m_dma.size) {
|
||||
svision->m_dma.on = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (decrement_tick > SV_DEC_TICK) {
|
||||
decrement_tick = 0;
|
||||
supervision_sound_decrement();
|
||||
if (svision->decrement_tick > SV_DEC_TICK) {
|
||||
svision->decrement_tick = 0;
|
||||
supervision_sound_decrement(svision);
|
||||
}
|
||||
decrement_tick++;
|
||||
svision->decrement_tick++;
|
||||
}
|
||||
}
|
||||
|
||||
void supervision_sound_decrement(void)
|
||||
void supervision_sound_decrement(struct svision_t *svision)
|
||||
{
|
||||
if (m_channel[0].count > 0)
|
||||
m_channel[0].count--;
|
||||
if (m_channel[1].count > 0)
|
||||
m_channel[1].count--;
|
||||
if (m_noise.count > 0)
|
||||
m_noise.count--;
|
||||
if (svision->m_channel[0].count > 0)
|
||||
svision->m_channel[0].count--;
|
||||
if (svision->m_channel[1].count > 0)
|
||||
svision->m_channel[1].count--;
|
||||
if (svision->m_noise.count > 0)
|
||||
svision->m_noise.count--;
|
||||
}
|
||||
|
||||
void supervision_sound_wave_write(int which, int offset, uint8 data)
|
||||
void supervision_sound_wave_write(struct svision_t *svision, int which, int offset, uint8 data)
|
||||
{
|
||||
SVISION_CHANNEL *channel = &m_channel[which];
|
||||
SVISION_CHANNEL *channel = &svision->m_channel[which];
|
||||
|
||||
channel->reg[offset] = data;
|
||||
switch (offset) {
|
||||
|
@ -232,15 +194,15 @@ void supervision_sound_wave_write(int which, int offset, uint8 data)
|
|||
size = channel->reg[0] | ((channel->reg[1] & 7) << 8);
|
||||
// if size == 0 then channel->size == 0
|
||||
if (size)
|
||||
channel->size = (uint16)(((real)SV_SAMPLE_RATE) * ((real)((size + 1) << 5)) / ((real)UNSCALED_CLOCK));
|
||||
channel->size = (uint16)(((real)SV_SAMPLE_RATE) * ((real)((size + 1) << 5)) / ((real)svision->UNSCALED_CLOCK));
|
||||
else
|
||||
channel->size = 0;
|
||||
channel->pos = 0;
|
||||
// Popo Team
|
||||
if (channel->count != 0 || ch[which].size == 0 || channel->size == 0) {
|
||||
ch[which].size = channel->size;
|
||||
if (channel->count != 0 || svision->ch[which].size == 0 || channel->size == 0) {
|
||||
svision->ch[which].size = channel->size;
|
||||
if (channel->count == 0)
|
||||
ch[which].pos = 0;
|
||||
svision->ch[which].pos = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -248,75 +210,75 @@ void supervision_sound_wave_write(int which, int offset, uint8 data)
|
|||
channel->on = data & 0x40;
|
||||
channel->waveform = (data & 0x30) >> 4;
|
||||
channel->volume = data & 0x0f;
|
||||
if (!channel->on || ch[which].size == 0 || channel->size == 0) {
|
||||
uint16 pos = ch[which].pos;
|
||||
memcpy(&ch[which], channel, sizeof(ch[which]));
|
||||
if (!channel->on || svision->ch[which].size == 0 || channel->size == 0) {
|
||||
uint16 pos = svision->ch[which].pos;
|
||||
memcpy(&svision->ch[which], channel, sizeof(svision->ch[which]));
|
||||
if (channel->count != 0) // Journey to the West
|
||||
ch[which].pos = pos;
|
||||
svision->ch[which].pos = pos;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
channel->count = data + 1;
|
||||
ch[which].size = channel->size; // Sonny Xpress!
|
||||
svision->ch[which].size = channel->size; // Sonny Xpress!
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void supervision_sound_dma_write(int offset, uint8 data)
|
||||
void supervision_sound_dma_write(struct svision_t *svision, int offset, uint8 data)
|
||||
{
|
||||
m_dma.reg[offset] = data;
|
||||
svision->m_dma.reg[offset] = data;
|
||||
switch (offset) {
|
||||
case 0:
|
||||
case 1:
|
||||
m_dma.start = (m_dma.reg[0] | (m_dma.reg[1] << 8));
|
||||
svision->m_dma.start = (svision->m_dma.reg[0] | (svision->m_dma.reg[1] << 8));
|
||||
break;
|
||||
case 2:
|
||||
m_dma.size = (data ? data : 0x100) * 32; // Number of 4-bit samples
|
||||
svision->m_dma.size = (data ? data : 0x100) * 32; // Number of 4-bit samples
|
||||
break;
|
||||
case 3:
|
||||
// Test games: Classic Casino, SSSnake
|
||||
m_dma.step = ((real)UNSCALED_CLOCK) / ((real)SV_SAMPLE_RATE * (256 << (data & 3)));
|
||||
svision->m_dma.step = ((real)svision->UNSCALED_CLOCK) / ((real)SV_SAMPLE_RATE * (256 << (data & 3)));
|
||||
// MESS/MAME. Wrong
|
||||
//m_dma.step = UNSCALED_CLOCK / (256.0 * SV_SAMPLE_RATE * (1 + (data & 3)));
|
||||
m_dma.right = data & 4;
|
||||
m_dma.left = data & 8;
|
||||
m_dma.ca14to16 = ((data & 0x70) >> 4) << 14;
|
||||
//svision->m_dma.step = svision->UNSCALED_CLOCK / (256.0 * SV_SAMPLE_RATE * (1 + (data & 3)));
|
||||
svision->m_dma.right = data & 4;
|
||||
svision->m_dma.left = data & 8;
|
||||
svision->m_dma.ca14to16 = ((data & 0x70) >> 4) << 14;
|
||||
break;
|
||||
case 4:
|
||||
m_dma.on = data & 0x80;
|
||||
if (m_dma.on) {
|
||||
m_dma.pos = 0.0;
|
||||
svision->m_dma.on = data & 0x80;
|
||||
if (svision->m_dma.on) {
|
||||
svision->m_dma.pos = 0.0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void supervision_sound_noise_write(int offset, uint8 data)
|
||||
void supervision_sound_noise_write(struct svision_t *svision, int offset, uint8 data)
|
||||
{
|
||||
m_noise.reg[offset] = data;
|
||||
svision->m_noise.reg[offset] = data;
|
||||
switch (offset) {
|
||||
case 0: {
|
||||
uint32 divisor = 8 << (data >> 4);
|
||||
if (divisor)
|
||||
m_noise.step = ((real)UNSCALED_CLOCK) / ((real)SV_SAMPLE_RATE * divisor);
|
||||
svision->m_noise.step = ((real)svision->UNSCALED_CLOCK) / ((real)SV_SAMPLE_RATE * divisor);
|
||||
else
|
||||
m_noise.step = 0;
|
||||
svision->m_noise.step = 0;
|
||||
|
||||
m_noise.step = ((real)UNSCALED_CLOCK) / ((real)SV_SAMPLE_RATE * divisor);
|
||||
m_noise.volume = data & 0xf;
|
||||
svision->m_noise.step = ((real)svision->UNSCALED_CLOCK) / ((real)SV_SAMPLE_RATE * divisor);
|
||||
svision->m_noise.volume = data & 0xf;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
m_noise.count = data + 1;
|
||||
svision->m_noise.count = data + 1;
|
||||
break;
|
||||
case 2:
|
||||
m_noise.type = (data & 1) ? 14 : 6;
|
||||
m_noise.play = data & 2;
|
||||
m_noise.right = data & 4;
|
||||
m_noise.left = data & 8;
|
||||
m_noise.on = data & 0x10; /* honey bee start */
|
||||
m_noise.state = 1;
|
||||
svision->m_noise.type = (data & 1) ? 14 : 6;
|
||||
svision->m_noise.play = data & 2;
|
||||
svision->m_noise.right = data & 4;
|
||||
svision->m_noise.left = data & 8;
|
||||
svision->m_noise.on = data & 0x10; /* honey bee start */
|
||||
svision->m_noise.state = 1;
|
||||
break;
|
||||
}
|
||||
m_noise.pos = 0.0;
|
||||
svision->m_noise.pos = 0.0;
|
||||
}
|
||||
|
|
|
@ -13,22 +13,60 @@ typedef uint16_t uint16;
|
|||
typedef uint32_t uint32;
|
||||
typedef float real;
|
||||
typedef uint8_t BOOL;
|
||||
enum {FALSE, TRUE};
|
||||
|
||||
void supervision_sound_reset(void);
|
||||
void supervision_sound_set_clock(uint32 clock);
|
||||
void supervision_sound_stream_update(uint8 *stream, uint32 len);
|
||||
void supervision_sound_decrement(void);
|
||||
void supervision_sound_wave_write(int which, int offset, uint8 data);
|
||||
void supervision_sound_dma_write(int offset, uint8 data);
|
||||
void supervision_sound_noise_write(int offset, uint8 data);
|
||||
void supervision_sound_noise_write(int offset, uint8 data);
|
||||
void supervision_memorymap_registers_write(uint32 Addr, uint8 Value);
|
||||
|
||||
typedef struct {
|
||||
uint8 reg[4];
|
||||
int on;
|
||||
uint8 waveform, volume;
|
||||
uint16 pos, size;
|
||||
uint16 count;
|
||||
} SVISION_CHANNEL;
|
||||
|
||||
typedef struct {
|
||||
uint8 reg[3];
|
||||
int on, right, left, play;
|
||||
uint8 type; // 6 - 7-Bit, 14 - 15-Bit
|
||||
uint16 state;
|
||||
uint8 value, volume;
|
||||
uint16 count;
|
||||
real pos, step;
|
||||
} SVISION_NOISE;
|
||||
|
||||
typedef struct {
|
||||
uint8 reg[5];
|
||||
int on, right, left;
|
||||
uint32 ca14to16;
|
||||
uint16 start;
|
||||
uint16 size;
|
||||
real pos, step;
|
||||
} SVISION_DMA;
|
||||
|
||||
struct svision_t {
|
||||
SVISION_CHANNEL m_channel[2];
|
||||
// For clear sound (no grating), sync with m_channel
|
||||
SVISION_CHANNEL ch[2];
|
||||
SVISION_NOISE m_noise;
|
||||
SVISION_DMA m_dma;
|
||||
uint8 supervision_dma_mem[65536];
|
||||
uint32 decrement_tick;
|
||||
uint32 UNSCALED_CLOCK;
|
||||
uint8 ch_mask, flags;
|
||||
};
|
||||
|
||||
void supervision_sound_reset(struct svision_t *svision);
|
||||
void supervision_sound_set_clock(struct svision_t *svision, uint32 clock);
|
||||
void supervision_sound_stream_update(struct svision_t *svision, uint8 *stream, uint32 len);
|
||||
void supervision_sound_decrement(struct svision_t *svision);
|
||||
void supervision_sound_wave_write(struct svision_t *svision, int which, int offset, uint8 data);
|
||||
void supervision_sound_dma_write(struct svision_t *svision,int offset, uint8 data);
|
||||
void supervision_sound_noise_write(struct svision_t *svision, int offset, uint8 data);
|
||||
void supervision_sound_noise_write(struct svision_t *svision, int offset, uint8 data);
|
||||
void supervision_memorymap_registers_write(struct svision_t *svision, uint32 Addr, uint8 Value);
|
||||
// 12SN
|
||||
void supervision_set_mute_mask(uint32 mask);
|
||||
void supervision_sound_set_flags(uint32 flags_set);
|
||||
void supervision_set_mute_mask(struct svision_t *svision, uint8 mask);
|
||||
void supervision_sound_set_flags(struct svision_t *svision, uint8 flags_set);
|
||||
|
||||
extern uint8 supervision_dma_mem[65536];
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
|
|
@ -216,89 +216,79 @@ const unsigned char noise_tbl[8][256] = {
|
|||
|
||||
};
|
||||
|
||||
uint8_t upd1771c_packets[16];
|
||||
uint8_t upd1771c_mode;
|
||||
uint32_t upd1771c_pos;
|
||||
uint8_t upd1771c_off;
|
||||
uint8_t upd1771c_posc;
|
||||
uint8_t upd1771c_wave;
|
||||
uint8_t upd1771c_vol;
|
||||
uint8_t upd1771c_period;
|
||||
uint8_t upd1771c_npos;
|
||||
void upd1771c_reset() {
|
||||
memset(upd1771c_packets,0,16);
|
||||
upd1771c_mode = 0;
|
||||
upd1771c_pos = 0;
|
||||
upd1771c_posc = 0;
|
||||
upd1771c_wave = 0;
|
||||
upd1771c_vol = 0;
|
||||
upd1771c_period = 0;
|
||||
upd1771c_off = 0;
|
||||
upd1771c_npos = 0;
|
||||
void upd1771c_reset(struct upd1771c_t *scv) {
|
||||
memset(scv->upd1771c_packets,0,16);
|
||||
scv->upd1771c_mode = 0;
|
||||
scv->upd1771c_pos = 0;
|
||||
scv->upd1771c_posc = 0;
|
||||
scv->upd1771c_wave = 0;
|
||||
scv->upd1771c_vol = 0;
|
||||
scv->upd1771c_period = 0;
|
||||
scv->upd1771c_off = 0;
|
||||
scv->upd1771c_npos = 0;
|
||||
//scv->upd1771c_repsamp = 0;
|
||||
}
|
||||
|
||||
void upd1771c_write_packet(uint8_t ind, uint8_t val) {
|
||||
upd1771c_packets[ind&15] = val;
|
||||
switch (upd1771c_packets[0]) {
|
||||
void upd1771c_write_packet(struct upd1771c_t *scv, uint8_t ind, uint8_t val) {
|
||||
scv->upd1771c_packets[ind&15] = val;
|
||||
switch (scv->upd1771c_packets[0]) {
|
||||
case 1:
|
||||
if (ind == 3) {
|
||||
upd1771c_mode = 1;
|
||||
upd1771c_wave = (upd1771c_packets[1]&0xe0)>>5;
|
||||
upd1771c_off = 0; //?
|
||||
upd1771c_period = upd1771c_packets[2];
|
||||
upd1771c_vol = upd1771c_packets[3]&0x1f;
|
||||
scv->upd1771c_mode = 1;
|
||||
scv->upd1771c_wave = (scv->upd1771c_packets[1]&0xe0)>>5;
|
||||
scv->upd1771c_off = 0; //?
|
||||
scv->upd1771c_period = scv->upd1771c_packets[2];
|
||||
scv->upd1771c_vol = scv->upd1771c_packets[3]&0x1f;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
if (ind == 3) {
|
||||
upd1771c_mode = 2;
|
||||
upd1771c_wave = (upd1771c_packets[1]&0xe0)>>5;
|
||||
upd1771c_off = upd1771c_packets[1]&0x1f;
|
||||
upd1771c_period = upd1771c_packets[2]<0x20?0x20:upd1771c_packets[2];
|
||||
upd1771c_vol = upd1771c_packets[3]&0x1f;
|
||||
scv->upd1771c_mode = 2;
|
||||
scv->upd1771c_wave = (scv->upd1771c_packets[1]&0xe0)>>5;
|
||||
scv->upd1771c_off = scv->upd1771c_packets[1]&0x1f;
|
||||
scv->upd1771c_period = scv->upd1771c_packets[2]<0x20?0x20:scv->upd1771c_packets[2];
|
||||
scv->upd1771c_vol = scv->upd1771c_packets[3]&0x1f;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
case 0:
|
||||
upd1771c_mode = 0;
|
||||
scv->upd1771c_mode = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int upd1771c_repsamp = 0;
|
||||
|
||||
void upd1771c_sound_set_clock(unsigned int clock, unsigned int divi) {
|
||||
upd1771c_repsamp = divi;
|
||||
void upd1771c_sound_set_clock(struct upd1771c_t *scv, unsigned int clock, unsigned int divi) {
|
||||
scv->upd1771c_repsamp = divi;
|
||||
}
|
||||
|
||||
int16_t upd1771c_sound_stream_update() {
|
||||
int16_t upd1771c_sound_stream_update(struct upd1771c_t *scv) {
|
||||
int16_t s = 0;
|
||||
for (int i = 0; i < upd1771c_repsamp; i++) {
|
||||
for (int i = 0; i < scv->upd1771c_repsamp; i++) {
|
||||
s = 0;
|
||||
switch (upd1771c_mode) {
|
||||
switch (scv->upd1771c_mode) {
|
||||
case 2:
|
||||
s = ((int16_t)WAVEFORMS[upd1771c_wave][upd1771c_posc])*upd1771c_vol;
|
||||
upd1771c_pos++;
|
||||
if (upd1771c_pos >= upd1771c_period) {
|
||||
upd1771c_pos=0;
|
||||
upd1771c_posc++;
|
||||
if (upd1771c_posc == 32)
|
||||
upd1771c_posc = upd1771c_off;
|
||||
s = ((int16_t)WAVEFORMS[scv->upd1771c_wave][scv->upd1771c_posc])*scv->upd1771c_vol;
|
||||
scv->upd1771c_pos++;
|
||||
if (scv->upd1771c_pos >= scv->upd1771c_period) {
|
||||
scv->upd1771c_pos=0;
|
||||
scv->upd1771c_posc++;
|
||||
if (scv->upd1771c_posc == 32)
|
||||
scv->upd1771c_posc = scv->upd1771c_off;
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
upd1771c_pos++;
|
||||
if (upd1771c_pos >= ((((uint32_t)upd1771c_period) + 1)*128)) {
|
||||
upd1771c_pos=0;
|
||||
upd1771c_posc++;
|
||||
if (upd1771c_posc == NOISE_SIZE)
|
||||
upd1771c_posc = 0;
|
||||
scv->upd1771c_pos++;
|
||||
if (scv->upd1771c_pos >= ((((uint32_t)scv->upd1771c_period) + 1)*128)) {
|
||||
scv->upd1771c_pos=0;
|
||||
scv->upd1771c_posc++;
|
||||
if (scv->upd1771c_posc == NOISE_SIZE)
|
||||
scv->upd1771c_posc = 0;
|
||||
}
|
||||
uint16_t p = upd1771c_posc;
|
||||
uint16_t p = scv->upd1771c_posc;
|
||||
p = p>=254?253:p;
|
||||
s = ((int16_t)(noise_tbl[upd1771c_wave][p])-127)*upd1771c_vol;
|
||||
s = ((int16_t)(noise_tbl[scv->upd1771c_wave][p])-127)*scv->upd1771c_vol;
|
||||
// inaccurate noise mixing :/
|
||||
// s |= (upd1771c_npos&128)?127*upd1771c_vol:0;
|
||||
// s |= (scv->upd1771c_npos&128)?127*scv->upd1771c_vol:0;
|
||||
break;
|
||||
case 0:
|
||||
default:
|
||||
|
|
|
@ -8,10 +8,23 @@ extern "C"
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
void upd1771c_reset(void);
|
||||
void upd1771c_write_packet(uint8_t ind, uint8_t val);
|
||||
int16_t upd1771c_sound_stream_update(void);
|
||||
void upd1771c_sound_set_clock(unsigned int clock, unsigned int divi);
|
||||
struct upd1771c_t {
|
||||
uint8_t upd1771c_packets[16];
|
||||
uint8_t upd1771c_mode;
|
||||
uint32_t upd1771c_pos;
|
||||
uint8_t upd1771c_off;
|
||||
uint8_t upd1771c_posc;
|
||||
uint8_t upd1771c_wave;
|
||||
uint8_t upd1771c_vol;
|
||||
uint8_t upd1771c_period;
|
||||
uint8_t upd1771c_npos;
|
||||
int upd1771c_repsamp;
|
||||
};
|
||||
|
||||
void upd1771c_reset(struct upd1771c_t *scv);
|
||||
void upd1771c_write_packet(struct upd1771c_t *scv, uint8_t ind, uint8_t val);
|
||||
int16_t upd1771c_sound_stream_update(struct upd1771c_t *scv);
|
||||
void upd1771c_sound_set_clock(struct upd1771c_t *scv, unsigned int clock, unsigned int divi);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
|
|
@ -61,17 +61,17 @@ void DivPlatformSupervision::acquire(short** buf, size_t len) {
|
|||
int mask_bits=0;
|
||||
for (int i=0; i<4; i++)
|
||||
mask_bits |= isMuted[i]?0:8>>i;
|
||||
supervision_set_mute_mask(mask_bits);
|
||||
supervision_set_mute_mask(&svision,mask_bits);
|
||||
|
||||
while (!writes.empty()) {
|
||||
QueuedWrite w=writes.front();
|
||||
supervision_memorymap_registers_write(w.addr|0x2000,w.val);
|
||||
supervision_memorymap_registers_write(&svision,w.addr|0x2000,w.val);
|
||||
regPool[w.addr&0x3f]=w.val;
|
||||
writes.pop();
|
||||
}
|
||||
|
||||
unsigned char s[6];
|
||||
supervision_sound_stream_update(s,2);
|
||||
supervision_sound_stream_update(&svision,s,2);
|
||||
tempL[0]=(((int)s[0])-128)*256;
|
||||
tempR[0]=(((int)s[1])-128)*256;
|
||||
|
||||
|
@ -441,7 +441,7 @@ void DivPlatformSupervision::reset() {
|
|||
if (dumpWrites) {
|
||||
addWrite(0xffffffff,0);
|
||||
}
|
||||
supervision_sound_reset();
|
||||
supervision_sound_reset(&svision);
|
||||
memset(tempL,0,32*sizeof(int));
|
||||
memset(tempR,0,32*sizeof(int));
|
||||
memset(noiseReg,0,3*sizeof(unsigned char));
|
||||
|
@ -481,8 +481,8 @@ void DivPlatformSupervision::setFlags(const DivConfig& flags) {
|
|||
for (int i=0; i<4; i++) {
|
||||
oscBuf[i]->rate=rate;
|
||||
}
|
||||
supervision_sound_set_clock((unsigned int)chipClock);
|
||||
supervision_sound_set_flags((unsigned int)otherFlags);
|
||||
supervision_sound_set_clock(&svision,(unsigned int)chipClock);
|
||||
supervision_sound_set_flags(&svision,(unsigned int)otherFlags);
|
||||
}
|
||||
|
||||
void DivPlatformSupervision::poke(unsigned int addr, unsigned short val) {
|
||||
|
@ -574,12 +574,14 @@ int DivPlatformSupervision::init(DivEngine* p, int channels, int sugRate, const
|
|||
isMuted[i]=false;
|
||||
oscBuf[i]=new DivDispatchOscBuffer;
|
||||
}
|
||||
sampleMem=supervision_dma_mem;
|
||||
sampleMem=svision.supervision_dma_mem;
|
||||
dutySwap=0;
|
||||
otherFlags=0;
|
||||
sampleOffset=0;
|
||||
sampleMemLen=0;
|
||||
memset(sampleMem,0,65536);
|
||||
svision.ch_mask=15;
|
||||
svision.flags=1;
|
||||
setFlags(flags);
|
||||
reset();
|
||||
return 4;
|
||||
|
|
|
@ -66,6 +66,7 @@ class DivPlatformSupervision: public DivDispatch {
|
|||
unsigned char noiseReg[3];
|
||||
unsigned char kon[4];
|
||||
unsigned char initWrite[4];
|
||||
struct svision_t svision;
|
||||
|
||||
friend void putDispatchChip(void*,int);
|
||||
friend void putDispatchChan(void*,int,int);
|
||||
|
|
|
@ -47,12 +47,12 @@ void DivPlatformUPD1771c::acquire(short** buf, size_t len) {
|
|||
|
||||
while (!writes.empty()) {
|
||||
QueuedWrite w=writes.front();
|
||||
upd1771c_write_packet(w.addr&15,w.val);
|
||||
upd1771c_write_packet(&scv,w.addr&15,w.val);
|
||||
regPool[w.addr&0xf]=w.val;
|
||||
writes.pop();
|
||||
}
|
||||
|
||||
signed short s = upd1771c_sound_stream_update()<<3;
|
||||
signed short s = (upd1771c_sound_stream_update(&scv)<<3)*((isMuted[0]&1)^1);
|
||||
|
||||
for (int i=0; i<1; i++) {
|
||||
oscBuf[i]->data[oscBuf[i]->needle++]=s;
|
||||
|
@ -314,7 +314,7 @@ void DivPlatformUPD1771c::reset() {
|
|||
if (dumpWrites) {
|
||||
addWrite(0xffffffff,0);
|
||||
}
|
||||
//upd1771c_sound_reset();
|
||||
upd1771c_reset(&scv);
|
||||
memset(tempL,0,32*sizeof(int));
|
||||
memset(tempR,0,32*sizeof(int));
|
||||
memset(kon,0,1*sizeof(unsigned char));
|
||||
|
@ -342,7 +342,7 @@ void DivPlatformUPD1771c::setFlags(const DivConfig& flags) {
|
|||
for (int i=0; i<1; i++) {
|
||||
oscBuf[i]->rate=rate;
|
||||
}
|
||||
upd1771c_sound_set_clock((unsigned int)chipClock,8);
|
||||
upd1771c_sound_set_clock(&scv,(unsigned int)chipClock,8);
|
||||
}
|
||||
|
||||
void DivPlatformUPD1771c::poke(unsigned int addr, unsigned short val) {
|
||||
|
|
|
@ -53,6 +53,7 @@ class DivPlatformUPD1771c: public DivDispatch {
|
|||
// I may add the 3 square waves in noise mode later...
|
||||
unsigned char kon[1];
|
||||
unsigned char initWrite[1];
|
||||
struct upd1771c_t scv;
|
||||
|
||||
|
||||
friend void putDispatchChip(void*,int);
|
||||
|
|
Loading…
Reference in a new issue