Refactored ESFM timers; removed 16-bit clipping from ESFMu

Co-authored-by: OBattler <oubattler@gmail.com>
This commit is contained in:
Kagamiin~
2024-03-22 11:56:01 -03:00
parent 937537f78e
commit d46e2ef7c8
3 changed files with 40 additions and 65 deletions

View File

@@ -1741,6 +1741,10 @@ ESFM_slot_generate_emu(esfm_slot *slot)
}
/* ------------------------------------------------------------------------- */
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunknown-pragmas"
static void
ESFM_process_feedback(esfm_chip *chip)
{
@@ -2226,7 +2230,7 @@ ESFM_update_write_buffer(esfm_chip *chip)
/* ------------------------------------------------------------------------- */
void
ESFM_generate(esfm_chip *chip, int16_t *buf)
ESFM_generate(esfm_chip *chip, int32_t *buf)
{
int channel_idx;
@@ -2259,8 +2263,8 @@ ESFM_generate(esfm_chip *chip, int16_t *buf)
chip->output_accm[1] += channel->output[1];
}
buf[0] = ESFM_clip_sample(chip->output_accm[0]);
buf[1] = ESFM_clip_sample(chip->output_accm[1]);
buf[0] = chip->output_accm[0];
buf[1] = chip->output_accm[1];
ESFM_update_timers(chip);
ESFM_update_write_buffer(chip);
@@ -2308,10 +2312,13 @@ void
ESFM_generate_stream(esfm_chip *chip, int16_t *sndptr, uint32_t num_samples)
{
uint32_t i;
int32_t buf[2] = { 0 };
for (i = 0; i < num_samples; i++)
{
ESFM_generate(chip, sndptr);
ESFM_generate(chip, buf);
sndptr[0] = ESFM_clip_sample(buf[0]);
sndptr[1] = ESFM_clip_sample(buf[1]);
sndptr += 2;
}
}

View File

@@ -67,7 +67,7 @@ void ESFM_write_reg_buffered_fast (esfm_chip *chip, uint16_t address, uint8_t da
void ESFM_write_port (esfm_chip *chip, uint8_t offset, uint8_t data);
uint8_t ESFM_readback_reg (esfm_chip *chip, uint16_t address);
uint8_t ESFM_read_port (esfm_chip *chip, uint8_t offset);
void ESFM_generate(esfm_chip *chip, int16_t *buf);
void ESFM_generate(esfm_chip *chip, int32_t *buf);
void ESFM_generate_stream(esfm_chip *chip, int16_t *sndptr, uint32_t num_samples);
int16_t ESFM_get_channel_output_native(esfm_chip *chip, int channel_idx);

View File

@@ -99,10 +99,7 @@ esfm_log(const char *fmt, ...)
void
esfm_generate_raw(esfm_drv_t *dev, int32_t *bufp)
{
ESFM_generate(&dev->opl, &dev->samples[0]);
bufp[0] = dev->samples[0];
bufp[1] = dev->samples[1];
ESFM_generate(&dev->opl, bufp);
}
void
@@ -270,75 +267,48 @@ esfm_drv_read(uint16_t port, void *priv)
break;
}
esfm_log("esfm: [%04X:%08X] [R] %04X = %02X\n", CS, cpu_state.pc, port, ret);
return ret;
}
static void
esfm_drv_write_buffered(esfm_drv_t *dev, uint8_t val)
{
uint16_t p = dev->port;
ESFM_write_reg_buffered_fast(&dev->opl, dev->opl.addr_latch, val);
if (dev->opl.native_mode)
{
switch (dev->port & 0x5ff)
{
case 0x402: /* Timer 1 */
dev->timer_count[0] = val;
esfm_log("Timer 0 count now: %i\n", dev->timer_count[0]);
break;
case 0x403: /* Timer 2 */
dev->timer_count[1] = val;
esfm_log("Timer 1 count now: %i\n", dev->timer_count[1]);
break;
case 0x404: /* Timer control */
if (val & CTRL_RESET) {
esfm_log("Resetting timer status...\n");
dev->status &= ~STAT_TMR_OVER;
} else {
dev->timer_ctrl = val;
esfm_timer_control(dev, 0, val & CTRL_TMR1_START);
esfm_timer_control(dev, 1, val & CTRL_TMR2_START);
esfm_log("Status mask now %02X (val = %02X)\n", (val & ~CTRL_TMR_MASK) & CTRL_TMR_MASK, val);
}
break;
default:
break;
}
p -= 0x400;
p &= 0x1ff;
}
else
switch (p)
{
switch (dev->port & 0x1ff)
{
case 0x002: /* Timer 1 */
dev->timer_count[0] = val;
esfm_log("Timer 0 count now: %i\n", dev->timer_count[0]);
break;
case 0x002: /* Timer 1 */
dev->timer_count[0] = val;
esfm_log("Timer 0 count now: %i\n", dev->timer_count[0]);
break;
case 0x003: /* Timer 2 */
dev->timer_count[1] = val;
esfm_log("Timer 1 count now: %i\n", dev->timer_count[1]);
break;
case 0x003: /* Timer 2 */
dev->timer_count[1] = val;
esfm_log("Timer 1 count now: %i\n", dev->timer_count[1]);
break;
case 0x004: /* Timer control */
if (val & CTRL_RESET) {
esfm_log("Resetting timer status...\n");
dev->status &= ~STAT_TMR_OVER;
} else {
dev->timer_ctrl = val;
esfm_timer_control(dev, 0, val & CTRL_TMR1_START);
esfm_timer_control(dev, 1, val & CTRL_TMR2_START);
esfm_log("Status mask now %02X (val = %02X)\n", (val & ~CTRL_TMR_MASK) & CTRL_TMR_MASK, val);
}
break;
case 0x004: /* Timer control */
if (val & CTRL_RESET) {
esfm_log("Resetting timer status...\n");
dev->status &= ~STAT_TMR_OVER;
} else {
dev->timer_ctrl = val;
esfm_timer_control(dev, 0, val & CTRL_TMR1_START);
esfm_timer_control(dev, 1, val & CTRL_TMR2_START);
esfm_log("Status mask now %02X (val = %02X)\n", (val & ~CTRL_TMR_MASK) & CTRL_TMR_MASK, val);
}
break;
default:
break;
}
default:
break;
}
}
@@ -347,8 +317,6 @@ esfm_drv_write(uint16_t port, uint8_t val, void *priv)
{
esfm_drv_t *dev = (esfm_drv_t *) priv;
esfm_log("esfm: [%04X:%08X] [W] %04X = %02X\n", CS, cpu_state.pc, port, val);
if (dev->flags & FLAG_CYCLES)
cycles -= ((int) (isa_timing * 8));