Skip to content

Commit

Permalink
update Nuke.YKT cores to current version
Browse files Browse the repository at this point in the history
  • Loading branch information
ValleyBell committed Dec 26, 2023
1 parent 76a4bbe commit c9bce20
Show file tree
Hide file tree
Showing 8 changed files with 546 additions and 345 deletions.
654 changes: 403 additions & 251 deletions emu/cores/nukedopl3.c

Large diffs are not rendered by default.

50 changes: 40 additions & 10 deletions emu/cores/nukedopl3_int.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// license:LGPL-2.1+
// copyright-holders:Nuke.YKT
/* Nuked OPL3
* Copyright (C) 2013-2020 Nuke.YKT
*
Expand Down Expand Up @@ -31,13 +33,21 @@
*/

// Nuked OPL3 internal structures/functions
#ifndef __NUKEDOPL3_INT_H__
#define __NUKEDOPL3_INT_H__
#ifndef NUKEDOPL3_INT_H
#define NUKEDOPL3_INT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "../../stdtype.h"
#include "../snddef.h"
#include "emutypes.h"

#ifndef OPL_ENABLE_STEREOEXT
#define OPL_ENABLE_STEREOEXT 0
#endif

//#define NOPL_ENABLE_WRITEBUF

#define OPL_WRITEBUF_SIZE 1024
Expand All @@ -54,8 +64,8 @@ struct _opl3_slot {
int16_t fbmod;
const int16_t *mod;
int16_t prout;
int16_t eg_rout;
int16_t eg_out;
uint16_t eg_rout;
uint16_t eg_out;
uint8_t eg_inc;
uint8_t eg_gen;
uint8_t eg_rate;
Expand All @@ -80,10 +90,16 @@ struct _opl3_slot {
};

struct _opl3_channel {
opl3_slot *slots[2];
opl3_slot *slotz[2];/*Don't use "slots" keyword to avoid conflict with Qt applications*/
opl3_channel *pair;
opl3_chip *chip;
const int16_t *out[4];

#if OPL_ENABLE_STEREOEXT
int32_t leftpan;
int32_t rightpan;
#endif

uint8_t chtype;
uint8_t muted;
uint16_t f_num;
Expand All @@ -93,6 +109,7 @@ struct _opl3_channel {
uint8_t alg;
uint8_t ksv;
uint16_t cha, chb;
uint16_t chc, chd;
uint8_t ch_num;
};

Expand Down Expand Up @@ -126,18 +143,23 @@ struct _opl3_chip {
uint8_t tremoloshift;
uint32_t noise;
//int16_t zeromod;
int32_t mixbuff[2];
int32_t mixbuff[4];
uint8_t rm_hh_bit2;
uint8_t rm_hh_bit3;
uint8_t rm_hh_bit7;
uint8_t rm_hh_bit8;
uint8_t rm_tc_bit3;
uint8_t rm_tc_bit5;
//OPL3L

#if OPL_ENABLE_STEREOEXT
uint8_t stereoext;
#endif

/* OPL3L */
int32_t rateratio;
int32_t samplecnt;
int32_t oldsamples[2];
int32_t samples[2];
int32_t oldsamples[4];
int32_t samples[4];

uint32_t muteMask;
int32_t masterVolL; // master volume left (.12 fixed point)
Expand All @@ -159,4 +181,12 @@ void NOPL3_WriteReg(opl3_chip *chip, uint16_t reg, uint8_t v);
void NOPL3_WriteRegBuffered(opl3_chip *chip, uint16_t reg, uint8_t v);
void NOPL3_GenerateStream(opl3_chip *chip, int32_t *sndptr, uint32_t numsamples);

#endif // __NUKEDOPL3_INT_H__
void NOPL3_Generate4Ch(opl3_chip *chip, int32_t *buf4);
void NOPL3_Generate4ChResampled(opl3_chip *chip, int32_t *buf4);
void NOPL3_Generate4ChStream(opl3_chip *chip, int32_t *sndptr1, int32_t *sndptr2, uint32_t numsamples);

#ifdef __cplusplus
}
#endif

#endif // NUKEDOPL3_INT_H
28 changes: 14 additions & 14 deletions emu/cores/nukedopll.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// license:GPL-2.0+
// copyright-holders:Nuke.YKT
/*
* Copyright (C) 2019 Nuke.YKT
* Copyright (C) 2019-2023 Nuke.YKT
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -17,7 +19,7 @@
* siliconpr0n.org(digshadow, John McMaster):
* VRC VII decap and die shot.
*
* version: 1.0.1
* version: 1.0.2
*/

#include <string.h>
Expand Down Expand Up @@ -174,7 +176,7 @@ static const opll_patch_t patch_ds1001[opll_patch_max] = {
{ 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x01, 0x00 },{ 0x00, 0x00 },{ 0x0c, 0x00 },{ 0x08, 0x00 },{ 0x0a, 0x00 },{ 0x07, 0x00 } },
{ 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x05, 0x00 },{ 0x00, 0x00 },{ 0x0f, 0x00 },{ 0x08, 0x00 },{ 0x05, 0x00 },{ 0x09, 0x00 } },
{ 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0f },{ 0x00, 0x08 },{ 0x00, 0x06 },{ 0x00, 0x0d } },
{ 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0d },{ 0x00, 0x08 },{ 0x00, 0x06 },{ 0x00, 0x08 } },
{ 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0d },{ 0x00, 0x08 },{ 0x00, 0x04 },{ 0x00, 0x08 } },
{ 0x00, 0x00, 0x00, 0x00,{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x00 },{ 0x00, 0x01 },{ 0x00, 0x00 },{ 0x00, 0x0a },{ 0x00, 0x0a },{ 0x00, 0x05 },{ 0x00, 0x05 } }
};

Expand Down Expand Up @@ -281,9 +283,8 @@ static void OPLL_DoIO(opll_t *chip) {
}

static void OPLL_DoModeWrite(opll_t *chip) {
uint8_t slot;
if ((chip->write_mode_address & 0x10) && chip->write_d_en) {
slot = chip->write_mode_address & 0x01;
uint8_t slot = chip->write_mode_address & 0x01;
switch (chip->write_mode_address & 0x0f) {
case 0x00:
case 0x01:
Expand Down Expand Up @@ -376,8 +377,6 @@ void NOPLL_Reset(opll_t *chip, uint32_t chip_type, uint32_t rate, uint32_t clock
}

static void OPLL_DoRegWrite(opll_t *chip) {
uint32_t channel;

/* Address */
if (chip->write_a_en) {
if ((chip->write_data & 0xc0) == 0x00) {
Expand All @@ -396,7 +395,7 @@ static void OPLL_DoRegWrite(opll_t *chip) {
/* Update registers */
if (chip->write_fm_data && !chip->write_a_en) {
if ((chip->address & 0x0f) == chip->cycles && chip->cycles < 16) {
channel = chip->cycles % 9;
uint32_t channel = chip->cycles % 9;
switch (chip->address & 0xf0) {
case 0x10:
if (chip->chip_type == opll_type_ym2420)
Expand Down Expand Up @@ -515,8 +514,8 @@ static void OPLL_PreparePatch2(opll_t *chip) {
static void OPLL_PhaseGenerate(opll_t *chip) {
uint32_t ismod;
uint32_t phase;
uint8_t rm_bit;
uint16_t pg_out;
uint8_t rm_bit;

chip->pg_phase[(chip->cycles + 17) % 18] = chip->pg_phase_next + chip->pg_inc;

Expand Down Expand Up @@ -878,11 +877,9 @@ static void OPLL_EnvelopeGenerate(opll_t *chip) {
}

static void OPLL_Channel(opll_t *chip) {
int16_t sign;
int16_t ch_out = chip->ch_out;
uint8_t ismod = (chip->cycles / 3) & 1;
uint8_t mute_m = ismod || ((chip->rm_enable&0x40) && (chip->cycles+15)%18 >= 12);
uint8_t mute_r = 1;
if (chip->chip_type == opll_type_ds1001) {
chip->output_m = ch_out;
if (chip->output_m >= 0) {
Expand All @@ -894,6 +891,7 @@ static void OPLL_Channel(opll_t *chip) {
chip->output_r = 0;
return;
} else {
uint8_t mute_r = 1;
/* TODO: This might be incorrect */
if ((chip->rm_enable & 0x40)) {
switch (chip->cycles) {
Expand Down Expand Up @@ -921,7 +919,7 @@ static void OPLL_Channel(opll_t *chip) {
else
chip->output_r = ch_out;
} else {
sign = ch_out >> 8;
int16_t sign = ch_out >> 8;
if (ch_out >= 0) {
ch_out++;
sign++;
Expand Down Expand Up @@ -1049,6 +1047,9 @@ static void OPLL_Operator(opll_t *chip) {
}
}

if (!(chip->rm_enable & 0x80))
routput = 0;

chip->ch_out = ismod1 ? routput : (output>>3);
}

Expand All @@ -1062,13 +1063,12 @@ static void OPLL_DoRhythm(opll_t *chip) {
}

static void OPLL_DoLFO(opll_t *chip) {
uint8_t vib_step;
uint8_t am_inc = 0;
uint8_t am_bit;

/* Update counter */
if (chip->cycles == 17) {
vib_step = ((chip->lfo_counter & 0x3ff) + 1) >> 10;
uint8_t vib_step = ((chip->lfo_counter & 0x3ff) + 1) >> 10;
chip->lfo_am_step = ((chip->lfo_counter & 0x3f) + 1) >> 6;
vib_step |= (chip->testmode >> 3) & 0x01;
chip->lfo_vib_counter += vib_step;
Expand Down
8 changes: 5 additions & 3 deletions emu/cores/nukedopll_int.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// license:GPL-2.0+
// copyright-holders:Nuke.YKT
/*
* Copyright (C) 2019 Nuke.YKT
*
Expand All @@ -21,8 +23,8 @@
*/

// Nuked OPLL internal structures/functions
#ifndef __NUKEDOPLL_INT_H__
#define __NUKEDOPLL_INT_H__
#ifndef NUKEDOPLL_INT_H
#define NUKEDOPLL_INT_H

#include "../../stdtype.h"
#include "../snddef.h"
Expand Down Expand Up @@ -227,4 +229,4 @@ void NOPLL_Write(opll_t *chip, uint32_t port, uint8_t data);

void NOPLL_WriteBuffered(opll_t*chip, uint32_t port, uint8_t data);

#endif // __NUKEDOPLL_INT_H__
#endif // NUKEDOPLL_INT_H
10 changes: 6 additions & 4 deletions emu/cores/nukedopm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// license:LGPL-2.1+
// copyright-holders:Nuke.YKT
/* Nuked OPM
* Copyright (C) 2020 Nuke.YKT
* Copyright (C) 2022 Nuke.YKT
*
* This file is part of Nuked OPM.
*
Expand All @@ -21,7 +23,7 @@
* siliconpr0n.org(digshadow, John McMaster):
* YM2151 and other FM chip decaps and die shots.
*
* version: 0.9.1 beta
* version: 0.9.3 beta
*/
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -692,7 +694,7 @@ static void OPM_EnvelopePhase4(opm_t *chip)
chip->eg_instantattack = chip->eg_ratemax[1] && (kon || !chip->eg_ratemax[1]);

eg_off = (chip->eg_level[slot] & 0x3f0) == 0x3f0;
slreach = (chip->eg_level[slot] >> 5) == chip->eg_sl[1];
slreach = (chip->eg_level[slot] >> 4) == (chip->eg_sl[1] << 1);
eg_zero = chip->eg_level[slot] == 0;

chip->eg_mute = eg_off && chip->eg_state[slot] != eg_num_attack && !kon;
Expand Down Expand Up @@ -1532,7 +1534,7 @@ static void OPM_DoLFO1(opm_t *chip)

lfo_pm_sign = chip->lfo_wave == 2 ? chip->lfo_trig_sign : chip->lfo_saw_sign;

w[5] = ampm_sel ? chip->lfo_saw_sign : (chip->lfo_wave != 2 || chip->lfo_trig_sign);
w[5] = ampm_sel ? chip->lfo_saw_sign : (chip->lfo_wave != 2 || !chip->lfo_trig_sign);

w[1] = !chip->lfo_clock || chip->lfo_wave == 3 || (chip->cycles & 15) != 15;
w[2] = chip->lfo_wave == 2 && !w[1];
Expand Down
12 changes: 7 additions & 5 deletions emu/cores/nukedopm_int.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// license:LGPL-2.1+
// copyright-holders:Nuke.YKT
/* Nuked OPM
* Copyright (C) 2020 Nuke.YKT
*
Expand All @@ -21,10 +23,10 @@
* siliconpr0n.org(digshadow, John McMaster):
* YM2151 and other FM chip decaps and die shots.
*
* version: 0.9 beta
* version: 0.9.2 beta
*/
#ifndef __NUKEDOPM_INT_H__
#define __NUKEDOPM_INT_H__
#ifndef NUKEDOPM_INT_H
#define NUKEDOPM_INT_H

#include "../../stdtype.h"
#include "../snddef.h"
Expand Down Expand Up @@ -115,7 +117,7 @@ typedef struct {
uint8_t eg_mute;
uint16_t eg_outtemp[2];
uint16_t eg_out[2];
uint8_t eg_am;
uint16_t eg_am;
uint8_t eg_ams[2];
uint8_t eg_timercarry;
uint32_t eg_timer;
Expand Down Expand Up @@ -294,4 +296,4 @@ void NOPM_Reset(opm_t* chip, uint32_t rate, uint32_t clock);
} // extern "C"
#endif

#endif // __NUKEDOPM_INT_H__
#endif // NUKEDOPM_INT_H
Loading

0 comments on commit c9bce20

Please sign in to comment.