SMS: add modified Nuked-PSG core

This commit is contained in:
tildearrow 2022-05-26 18:46:20 -05:00
parent 0f203d1abd
commit e3ebe0cb92
10 changed files with 909 additions and 2 deletions

View file

@ -191,6 +191,7 @@ void DivDispatchContainer::init(DivSystem sys, DivEngine* eng, int chanCount, do
break;
case DIV_SYSTEM_SMS:
dispatch=new DivPlatformSMS;
((DivPlatformSMS*)dispatch)->setNuked(eng->getConfInt("snCore",0));
break;
case DIV_SYSTEM_GB:
dispatch=new DivPlatformGB;

View file

@ -21,7 +21,7 @@
#include "../engine.h"
#include <math.h>
#define rWrite(v) {if (!skipRegisterWrites) {sn->write(v); if (dumpWrites) {addWrite(0x200,v);}}}
#define rWrite(v) {if (!skipRegisterWrites) {writes.push(v); if (dumpWrites) {addWrite(0x200,v);}}}
const char* regCheatSheetSN[]={
"DATA", "0",
@ -41,7 +41,47 @@ const char* DivPlatformSMS::getEffectName(unsigned char effect) {
return NULL;
}
void DivPlatformSMS::acquire(short* bufL, short* bufR, size_t start, size_t len) {
void DivPlatformSMS::acquire_nuked(short* bufL, short* bufR, size_t start, size_t len) {
for (size_t h=start; h<start+len; h++) {
if (!writes.empty()) {
unsigned char w=writes.front();
YMPSG_Write(&sn_nuked,w);
writes.pop();
}
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
YMPSG_Clock(&sn_nuked);
bufL[h]=YMPSG_GetOutput(&sn_nuked)*8192.0;
/*
for (int i=0; i<4; i++) {
if (isMuted[i]) {
oscBuf[i]->data[oscBuf[i]->needle++]=0;
} else {
oscBuf[i]->data[oscBuf[i]->needle++]=sn->get_channel_output(i);
}
}*/
}
}
void DivPlatformSMS::acquire_mame(short* bufL, short* bufR, size_t start, size_t len) {
while (!writes.empty()) {
unsigned char w=writes.front();
sn->write(w);
writes.pop();
}
for (size_t h=start; h<start+len; h++) {
sn->sound_stream_update(bufL+h,1);
for (int i=0; i<4; i++) {
@ -54,6 +94,14 @@ void DivPlatformSMS::acquire(short* bufL, short* bufR, size_t start, size_t len)
}
}
void DivPlatformSMS::acquire(short* bufL, short* bufR, size_t start, size_t len) {
if (nuked) {
acquire_nuked(bufL,bufR,start,len);
} else {
acquire_mame(bufL,bufR,start,len);
}
}
int DivPlatformSMS::acquireOne() {
short v;
sn->sound_stream_update(&v,1);
@ -301,6 +349,7 @@ DivDispatchOscBuffer* DivPlatformSMS::getOscBuffer(int ch) {
}
void DivPlatformSMS::reset() {
while (!writes.empty()) writes.pop();
for (int i=0; i<4; i++) {
chan[i]=DivPlatformSMS::Channel();
chan[i].std.setEngine(parent);
@ -309,6 +358,7 @@ void DivPlatformSMS::reset() {
addWrite(0xffffffff,0);
}
sn->device_start();
YMPSG_Init(&sn_nuked);
snNoiseMode=3;
rWrite(0xe7);
updateSNMode=false;
@ -352,6 +402,7 @@ void DivPlatformSMS::setFlags(unsigned int flags) {
chipClock=COLOR_NTSC;
}
resetPhase=!(flags&16);
if (sn!=NULL) delete sn;
switch ((flags>>2)&3) {
case 1: // TI
@ -377,6 +428,10 @@ void DivPlatformSMS::setFlags(unsigned int flags) {
}
}
void DivPlatformSMS::setNuked(bool value) {
nuked=value;
}
int DivPlatformSMS::init(DivEngine* p, int channels, int sugRate, unsigned int flags) {
parent=p;
dumpWrites=false;

View file

@ -23,6 +23,10 @@
#include "../dispatch.h"
#include "../macroInt.h"
#include "sound/sn76496.h"
extern "C" {
#include "../../../extern/Nuked-PSG/ympsg.h"
}
#include <queue>
class DivPlatformSMS: public DivDispatch {
struct Channel {
@ -59,8 +63,14 @@ class DivPlatformSMS: public DivDispatch {
bool updateSNMode;
bool resetPhase;
bool isRealSN;
bool nuked;
sn76496_base_device* sn;
ympsg_t sn_nuked;
std::queue<unsigned char> writes;
friend void putDispatchChan(void*,int,int);
void acquire_nuked(short* bufL, short* bufR, size_t start, size_t len);
void acquire_mame(short* bufL, short* bufR, size_t start, size_t len);
public:
int acquireOne();
void acquire(short* bufL, short* bufR, size_t start, size_t len);
@ -80,6 +90,7 @@ class DivPlatformSMS: public DivDispatch {
void poke(std::vector<DivRegWrite>& wlist);
const char** getRegisterSheet();
const char* getEffectName(unsigned char effect);
void setNuked(bool value);
int init(DivEngine* parent, int channels, int sugRate, unsigned int flags);
void quit();
~DivPlatformSMS();