1
0
Fork 0

Add Nuked OPL3 emulator v1.8

Set oplemu to nuked in config file. Also set oplrate and mixer rate
to 49716 for best sound quality.

Changelog for v1.8:

- New envelope generator.
- Rhythm mode emulation is 100% correct now.

Vogons thread: https://www.vogons.org/viewtopic.php?f=9&t=37782

Imported-from: https://www.vogons.org/viewtopic.php?p=661417#p661417
This commit is contained in:
Alexey Khokholov 2018-03-30 11:41:00 +02:00 committed by Patryk Obara
parent eaf6970dbd
commit 64b90ab930
5 changed files with 1558 additions and 5 deletions

View file

@ -604,7 +604,7 @@ void DOSBOX_Init(void) {
Pstring->Set_values(oplmodes);
Pstring->Set_help("Type of OPL emulation. On 'auto' the mode is determined by sblaster type. All OPL modes are Adlib-compatible, except for 'cms'.");
const char* oplemus[]={ "default", "compat", "fast", "mame", 0};
const char* oplemus[]={ "default", "compat", "fast", "mame", "nuked", 0};
Pstring = secprop->Add_string("oplemu",Property::Changeable::WhenIdle,"default");
Pstring->Set_values(oplemus);
Pstring->Set_help("Provider for the OPL emulation. compat might provide better quality (see oplrate as well).");

View file

@ -2,7 +2,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include
SUBDIRS = serialport mame
EXTRA_DIST = opl.cpp opl.h adlib.h dbopl.h pci_devices.h
EXTRA_DIST = opl.cpp opl.h adlib.h dbopl.h pci_devices.h nukedopl.h
noinst_LIBRARIES = libhardware.a
@ -10,6 +10,4 @@ libhardware_a_SOURCES = adlib.cpp dma.cpp gameblaster.cpp hardware.cpp iohandler
memory.cpp mixer.cpp pcspeaker.cpp pci_bus.cpp pic.cpp sblaster.cpp tandy_sound.cpp timer.cpp \
vga.cpp vga_attr.cpp vga_crtc.cpp vga_dac.cpp vga_draw.cpp vga_gfx.cpp vga_other.cpp \
vga_memory.cpp vga_misc.cpp vga_seq.cpp vga_xga.cpp vga_s3.cpp vga_tseng.cpp vga_paradise.cpp \
cmos.cpp disney.cpp gus.cpp mpu401.cpp ipx.cpp ipxserver.cpp dbopl.cpp
cmos.cpp disney.cpp gus.cpp mpu401.cpp ipx.cpp ipxserver.cpp dbopl.cpp nukedopl.cpp

View file

@ -27,6 +27,7 @@
#include "mapper.h"
#include "mem.h"
#include "dbopl.h"
#include "nukedopl.h"
#include "mame/emu.h"
#include "mame/fmopl.h"
@ -164,6 +165,42 @@ struct Handler : public Adlib::Handler {
}
namespace NukedOPL {
struct Handler : public Adlib::Handler {
opl3_chip chip;
Bit8u newm;
virtual void WriteReg( Bit32u reg, Bit8u val ) {
OPL3_WriteRegBuffered(&chip, (Bit16u)reg, val);
if (reg == 0x105)
newm = reg & 0x01;
}
virtual Bit32u WriteAddr( Bit32u port, Bit8u val ) {
Bit16u addr;
addr = val;
if ((port & 2) && (addr == 0x05 || newm)) {
addr |= 0x100;
}
return addr;
}
virtual void Generate( MixerChannel* chan, Bitu samples ) {
Bit16s buf[1024*2];
while( samples > 0 ) {
Bitu todo = samples > 1024 ? 1024 : samples;
samples -= todo;
OPL3_GenerateStream(&chip, buf, todo);
chan->AddSamples_s16( todo, buf );
}
}
virtual void Init( Bitu rate ) {
newm = 0;
OPL3_Reset(&chip, rate);
}
~Handler() {
}
};
}
#define RAW_SIZE 1024
@ -806,6 +843,9 @@ Module::Module(Section *configuration)
else {
handler = new MAMEOPL3::Handler();
}
}
else if (oplemu == "nuked") {
handler = new NukedOPL::Handler();
} else {
handler = new DBOPL::Handler();
}

1377
src/hardware/nukedopl.cpp Normal file

File diff suppressed because it is too large Load diff

138
src/hardware/nukedopl.h Normal file
View file

@ -0,0 +1,138 @@
//
// Copyright (C) 2013-2018 Alexey Khokholov (Nuke.YKT)
//
// 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.
//
//
// Nuked OPL3 emulator.
// Thanks:
// MAME Development Team(Jarek Burczynski, Tatsuyuki Satoh):
// Feedback and Rhythm part calculation information.
// forums.submarine.org.uk(carbon14, opl3):
// Tremolo and phase generator calculation information.
// OPLx decapsulated(Matthew Gambrell, Olli Niemitalo):
// OPL2 ROMs.
// siliconpr0n.org(John McMaster, digshadow):
// YMF262 and VRC VII decaps and die shots.
//
// version: 1.8
//
#ifndef OPL_OPL3_H
#define OPL_OPL3_H
#define OPL_WRITEBUF_SIZE 1024
#define OPL_WRITEBUF_DELAY 1
#include "dosbox.h"
typedef struct _opl3_slot opl3_slot;
typedef struct _opl3_channel opl3_channel;
typedef struct _opl3_chip opl3_chip;
struct _opl3_slot {
opl3_channel *channel;
opl3_chip *chip;
Bit16s out;
Bit16s fbmod;
Bit16s *mod;
Bit16s prout;
Bit16s eg_rout;
Bit16s eg_out;
Bit8u eg_inc;
Bit8u eg_gen;
Bit8u eg_rate;
Bit8u eg_ksl;
Bit8u *trem;
Bit8u reg_vib;
Bit8u reg_type;
Bit8u reg_ksr;
Bit8u reg_mult;
Bit8u reg_ksl;
Bit8u reg_tl;
Bit8u reg_ar;
Bit8u reg_dr;
Bit8u reg_sl;
Bit8u reg_rr;
Bit8u reg_wf;
Bit8u key;
Bit32u pg_reset;
Bit32u pg_phase;
Bit16u pg_phase_out;
Bit8u slot_num;
};
struct _opl3_channel {
opl3_slot *slots[2];
opl3_channel *pair;
opl3_chip *chip;
Bit16s *out[4];
Bit8u chtype;
Bit16u f_num;
Bit8u block;
Bit8u fb;
Bit8u con;
Bit8u alg;
Bit8u ksv;
Bit16u cha, chb;
Bit8u ch_num;
};
typedef struct _opl3_writebuf {
Bit64u time;
Bit16u reg;
Bit8u data;
} opl3_writebuf;
struct _opl3_chip {
opl3_channel channel[18];
opl3_slot slot[36];
Bit16u timer;
Bit64u eg_timer;
Bit8u eg_timerrem;
Bit8u eg_state;
Bit8u eg_add;
Bit8u newm;
Bit8u nts;
Bit8u rhy;
Bit8u vibpos;
Bit8u vibshift;
Bit8u tremolo;
Bit8u tremolopos;
Bit8u tremoloshift;
Bit32u noise;
Bit16s zeromod;
Bit32s mixbuff[2];
Bit8u rm_hh_bit2;
Bit8u rm_hh_bit3;
Bit8u rm_hh_bit7;
Bit8u rm_hh_bit8;
Bit8u rm_tc_bit3;
Bit8u rm_tc_bit5;
//OPL3L
Bit32s rateratio;
Bit32s samplecnt;
Bit16s oldsamples[2];
Bit16s samples[2];
Bit64u writebuf_samplecnt;
Bit32u writebuf_cur;
Bit32u writebuf_last;
Bit64u writebuf_lasttime;
opl3_writebuf writebuf[OPL_WRITEBUF_SIZE];
};
void OPL3_Generate(opl3_chip *chip, Bit16s *buf);
void OPL3_GenerateResampled(opl3_chip *chip, Bit16s *buf);
void OPL3_Reset(opl3_chip *chip, Bit32u samplerate);
void OPL3_WriteReg(opl3_chip *chip, Bit16u reg, Bit8u v);
void OPL3_WriteRegBuffered(opl3_chip *chip, Bit16u reg, Bit8u v);
void OPL3_GenerateStream(opl3_chip *chip, Bit16s *sndptr, Bit32u numsamples);
#endif