Publish VCC Plus OSS source distribution for 3.6.2 build 60
This commit is contained in:
commit
c652a5276d
1192 files changed
+272368
No files matched your search
@@ -0,0 +1,116 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "Cartridge.h"
|
||||
//#include <vcc/util/winapi.h>
|
||||
#include <vcc/util/logger.h>
|
||||
|
||||
namespace detail
|
||||
{
|
||||
void NullAssetCartridgeLine(slot_id_type, bool) {}
|
||||
}
|
||||
|
||||
|
||||
Cartridge* Cartridge::m_Singleton(nullptr);
|
||||
|
||||
|
||||
Cartridge::Cartridge()
|
||||
{
|
||||
if (m_Singleton)
|
||||
{
|
||||
// throw std::runtime_error("Cartridge instance already created.");
|
||||
}
|
||||
|
||||
m_Singleton = this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Cartridge::~Cartridge()
|
||||
{
|
||||
m_Singleton = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void Cartridge::LoadConfiguration(const std::string& /*filename*/)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//void Cartridge::LoadMenuItems()
|
||||
//{
|
||||
//}
|
||||
|
||||
|
||||
void Cartridge::SetSlotId(slot_id_type SlotId)
|
||||
{
|
||||
m_SlotId = SlotId;
|
||||
}
|
||||
|
||||
|
||||
void Cartridge::SetCartLineAssertCallback(PakAssertCartridgeLineHostCallback callback)
|
||||
{
|
||||
AssetCartridgeLinePtr = callback;
|
||||
}
|
||||
|
||||
|
||||
void Cartridge::SetConfigurationPath(std::string path)
|
||||
{
|
||||
m_ConfigurationPath = move(path);
|
||||
LoadConfiguration(m_ConfigurationPath);
|
||||
// LoadMenuItems();
|
||||
}
|
||||
|
||||
std::string Cartridge::GetStatusMessage() const
|
||||
{
|
||||
return std::string();
|
||||
}
|
||||
|
||||
void Cartridge::OnMenuItemSelected(unsigned char /*menuId*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Cartridge::OnReset()
|
||||
{}
|
||||
|
||||
unsigned short Cartridge::UpdateAudio()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Cartridge::GetMenuItem(menu_item_entry* /*item*/, size_t /*index*/)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned char Cartridge::OnReadMemory(unsigned short /*address*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Cartridge::OnWritePort(unsigned char /*port*/, unsigned char /*data*/)
|
||||
{}
|
||||
|
||||
|
||||
unsigned char Cartridge::OnReadPort(unsigned char /*port*/) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#pragma once
|
||||
#include "CartridgeTrampolines.h"
|
||||
#include <string>
|
||||
|
||||
namespace detail
|
||||
{
|
||||
void NullAssetCartridgeLine(slot_id_type, bool);
|
||||
}
|
||||
|
||||
class Cartridge
|
||||
{
|
||||
protected:
|
||||
|
||||
Cartridge();
|
||||
|
||||
|
||||
public:
|
||||
|
||||
virtual ~Cartridge();
|
||||
|
||||
|
||||
virtual void SetSlotId(slot_id_type SlotId);
|
||||
virtual void SetCartLineAssertCallback(PakAssertCartridgeLineHostCallback callback);
|
||||
virtual void SetConfigurationPath(std::string path);
|
||||
|
||||
virtual std::string GetStatusMessage() const;
|
||||
virtual void OnMenuItemSelected(unsigned char menuId);
|
||||
|
||||
virtual void OnReset();
|
||||
virtual unsigned short UpdateAudio();
|
||||
virtual unsigned char OnReadMemory(unsigned short address) const;
|
||||
virtual void OnWritePort(unsigned char port, unsigned char data);
|
||||
virtual unsigned char OnReadPort(unsigned char port) const;
|
||||
virtual bool GetMenuItem(menu_item_entry* item, size_t index);
|
||||
|
||||
protected:
|
||||
|
||||
void AssetCartridgeLine(bool state) const
|
||||
{
|
||||
AssetCartridgeLinePtr(m_SlotId, state);
|
||||
}
|
||||
|
||||
virtual void LoadConfiguration(const std::string& filename);
|
||||
// virtual void LoadMenuItems();
|
||||
|
||||
private:
|
||||
|
||||
friend const char* PakGetName();
|
||||
friend const char* PakGetCatalogId();
|
||||
friend void PakInitialize(
|
||||
slot_id_type SlotId,
|
||||
const char* const configuration_path,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks* const callbacks);
|
||||
friend void PakGetStatus(char* text_buffer, size_t buffer_size);
|
||||
friend void PakMenuItemClicked(unsigned char menuId);
|
||||
friend void PakReset();
|
||||
friend unsigned char PakReadMemoryByte(unsigned short address);
|
||||
friend void PakWritePort(unsigned char port, unsigned char data);
|
||||
friend unsigned char PakReadPort(unsigned char port);
|
||||
friend unsigned short PakSampleAudio();
|
||||
friend bool PakGetMenuItem(menu_item_entry* item, size_t index);
|
||||
|
||||
private:
|
||||
|
||||
static Cartridge* m_Singleton;
|
||||
|
||||
slot_id_type m_SlotId {};
|
||||
std::string m_Name;
|
||||
std::string m_CatalogId;
|
||||
std::string m_ConfigurationPath;
|
||||
PakAssertCartridgeLineHostCallback AssetCartridgeLinePtr = detail::NullAssetCartridgeLine;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
#include "CartridgeTrampolines.h"
|
||||
#include "Cartridge.h"
|
||||
#include "resource.h"
|
||||
#include <vcc/util/limits.h>
|
||||
#include <vcc/util/logger.h>
|
||||
|
||||
//#define USE_LOGGING
|
||||
|
||||
GMC_EXPORT const char* PakGetName()
|
||||
{
|
||||
static char string_buffer[MAX_LOADSTRING];
|
||||
|
||||
LoadString(gModuleInstance, IDS_MODULE_NAME, string_buffer, MAX_LOADSTRING);
|
||||
|
||||
return string_buffer;
|
||||
}
|
||||
|
||||
GMC_EXPORT const char* PakGetCatalogId()
|
||||
{
|
||||
static char string_buffer[MAX_LOADSTRING];
|
||||
|
||||
LoadString(gModuleInstance, IDS_CATNUMBER, string_buffer, MAX_LOADSTRING);
|
||||
|
||||
return string_buffer;
|
||||
}
|
||||
|
||||
GMC_EXPORT const char* PakGetDescription()
|
||||
{
|
||||
static char string_buffer[MAX_LOADSTRING];
|
||||
|
||||
LoadString(gModuleInstance, IDS_DESCRIPTION, string_buffer, MAX_LOADSTRING);
|
||||
|
||||
return string_buffer;
|
||||
}
|
||||
|
||||
HWND gVccWnd;
|
||||
GMC_EXPORT void PakInitialize(
|
||||
slot_id_type SlotId,
|
||||
const char* const configuration_path,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks* const callbacks)
|
||||
{
|
||||
gVccWnd = hVccWnd;
|
||||
|
||||
DLOG_C("GMC %p %p %p %p\n",
|
||||
callbacks->assert_interrupt,
|
||||
callbacks->assert_cartridge_line,
|
||||
callbacks->write_memory_byte,
|
||||
callbacks->read_memory_byte);
|
||||
|
||||
Cartridge::m_Singleton->SetSlotId(SlotId);
|
||||
Cartridge::m_Singleton->SetCartLineAssertCallback(callbacks->assert_cartridge_line);
|
||||
Cartridge::m_Singleton->SetConfigurationPath(configuration_path);
|
||||
}
|
||||
|
||||
|
||||
GMC_EXPORT void PakMenuItemClicked(unsigned char menuId)
|
||||
{
|
||||
Cartridge::m_Singleton->OnMenuItemSelected(menuId);
|
||||
}
|
||||
|
||||
|
||||
GMC_EXPORT void PakReset()
|
||||
{
|
||||
Cartridge::m_Singleton->OnReset();
|
||||
}
|
||||
|
||||
|
||||
GMC_EXPORT void PakGetStatus(char* text_buffer, size_t buffer_size)
|
||||
{
|
||||
auto message(Cartridge::m_Singleton->GetStatusMessage());
|
||||
if (message.size() > 63)
|
||||
{
|
||||
message.resize(63);
|
||||
}
|
||||
|
||||
strcpy(text_buffer, message.c_str());
|
||||
}
|
||||
|
||||
|
||||
GMC_EXPORT unsigned char PakReadMemoryByte(unsigned short address)
|
||||
{
|
||||
return Cartridge::m_Singleton->OnReadMemory(address);
|
||||
}
|
||||
|
||||
GMC_EXPORT void PakWritePort(unsigned char port, unsigned char data)
|
||||
{
|
||||
Cartridge::m_Singleton->OnWritePort(port, data);
|
||||
}
|
||||
|
||||
|
||||
GMC_EXPORT unsigned char PakReadPort(unsigned char port)
|
||||
{
|
||||
return Cartridge::m_Singleton->OnReadPort(port);
|
||||
}
|
||||
|
||||
|
||||
// This gets called at the end of every scan line 262 Lines * 60 Frames = 15780 Hz 15720
|
||||
GMC_EXPORT unsigned short PakSampleAudio()
|
||||
{
|
||||
return Cartridge::m_Singleton->UpdateAudio();
|
||||
}
|
||||
|
||||
// Return menu
|
||||
GMC_EXPORT bool PakGetMenuItem(menu_item_entry* item, size_t index)
|
||||
{
|
||||
return Cartridge::m_Singleton->GetMenuItem(item, index);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include "GMC.h"
|
||||
|
||||
GMC_EXPORT const char* PakGetName();
|
||||
GMC_EXPORT const char* PakGetCatalogId();
|
||||
GMC_EXPORT void PakInitialize(
|
||||
slot_id_type SlotId,
|
||||
const char* const configuration_path,
|
||||
HWND hVccWnd,
|
||||
const cpak_callbacks* const callbacks);
|
||||
|
||||
GMC_EXPORT void PakGetStatus(char* text_buffer, size_t buffer_size);
|
||||
GMC_EXPORT void PakMenuItemClicked(unsigned char /*menuId*/);
|
||||
GMC_EXPORT void PakReset();
|
||||
GMC_EXPORT unsigned char PakReadMemoryByte(unsigned short address);
|
||||
GMC_EXPORT void PakWritePort(unsigned char port, unsigned char data);
|
||||
GMC_EXPORT unsigned char PakReadPort(unsigned char port);
|
||||
GMC_EXPORT unsigned short PakSampleAudio();
|
||||
GMC_EXPORT bool PakGetMenuItem(menu_item_entry* item, size_t index);
|
||||
@@ -0,0 +1,41 @@
|
||||
#include "Configuration.h"
|
||||
#include <io.h>
|
||||
#include <Windows.h>
|
||||
#include <vcc/util/settings.h>
|
||||
|
||||
using settings = ::VCC::Util::settings;
|
||||
|
||||
Configuration::Configuration(std::string filename)
|
||||
: m_Filename(move(filename))
|
||||
{
|
||||
m_ActiveROM = settings(m_Filename).read("GMC-SN74689","ROM");
|
||||
|
||||
//Chet had plans for an MRU list. maybe someday...
|
||||
// MRUListType mruROMList;
|
||||
// for (auto i(0U); ; ++i)
|
||||
// {
|
||||
// const auto keyName("ROM" + std::to_string(i));
|
||||
// if (!GetPrivateProfileStringA(moduleName, keyName.c_str(), "",
|
||||
// pathBuffer, MAX_PATH, m_Filename.c_str()))
|
||||
// break;
|
||||
// mruROMList.emplace_back(pathBuffer);
|
||||
// }
|
||||
// m_MRURoms = move(mruROMList);
|
||||
}
|
||||
|
||||
std::string Configuration::GetActiveRom() const
|
||||
{
|
||||
return m_ActiveROM;
|
||||
}
|
||||
|
||||
void Configuration::SetActiveRom(std::string filename)
|
||||
{
|
||||
m_ActiveROM = filename;
|
||||
settings(m_Filename).write("GMC-SN74689","ROM",filename);
|
||||
|
||||
// m_MRURoms.emplace_back(m_ActiveROM);
|
||||
// m_ActiveROM = filename;
|
||||
// static const auto moduleName = "GMC-SN74689";
|
||||
// WritePrivateProfileStringA(moduleName, "ROM", filename.data(), m_Filename.c_str());
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
class Configuration
|
||||
{
|
||||
public:
|
||||
|
||||
Configuration() = default;
|
||||
explicit Configuration(std::string filename);
|
||||
virtual ~Configuration() = default;
|
||||
|
||||
std::string GetActiveRom() const;
|
||||
void SetActiveRom(std::string filename);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
using MRUListType = std::vector<std::string>;
|
||||
|
||||
std::string m_Filename;
|
||||
MRUListType m_MRURoms;
|
||||
std::string m_ActiveROM;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vcc/bus/cpak_cartridge_definitions.h>
|
||||
#include <vcc/bus/cartridge_menuitem.h>
|
||||
|
||||
#ifdef GMC_EXPORTS
|
||||
#define GMC_EXPORT extern "C" __declspec(dllexport)
|
||||
#else
|
||||
#define GMC_EXPORT
|
||||
#endif
|
||||
|
||||
extern HINSTANCE gModuleInstance;
|
||||
std::string SelectROMFile();
|
||||
std::string ExtractFilename(std::string path);
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "winres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (United States) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""winres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 2,1,8,1
|
||||
PRODUCTVERSION 2,1,8,1
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x21L
|
||||
#else
|
||||
FILEFLAGS 0x20L
|
||||
#endif
|
||||
FILEOS 0x40004L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "040904b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "Game Master Cartridge (SN76489)"
|
||||
VALUE "FileDescription", "GMC"
|
||||
VALUE "FileVersion", "2.1.8.1"
|
||||
VALUE "InternalName", "orch90"
|
||||
VALUE "LegalCopyright", "Copyright � 2019"
|
||||
VALUE "OriginalFilename", "gmc.dll"
|
||||
VALUE "ProductName", "Game Master Cartridge (SN76489)"
|
||||
VALUE "ProductVersion", "26-XXXX"
|
||||
VALUE "SpecialBuild", "Game Master Cartridge (SN76489)"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x409, 1200
|
||||
END
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// String Table
|
||||
//
|
||||
|
||||
STRINGTABLE
|
||||
BEGIN
|
||||
IDS_MODULE_NAME "Game Master Catridge"
|
||||
IDS_CATNUMBER "26-XXXX"
|
||||
IDS_DESCRIPTION "Emulates John Linville's Game Master Cart. This cartridge provides a dedicated sound chip (SN76489) and more memory, allowing for enhanced graphics and audio in games. GMC ROMS usually assume that the Game Master Cart is loaded in MMI slot 1"
|
||||
IDS_VERSION "1.0"
|
||||
END
|
||||
|
||||
#endif // English (United States) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
#include "GMCCartridge.h"
|
||||
#include <Windows.h>
|
||||
#include <vcc/util/logger.h>
|
||||
#include <vcc/bus/cartridge_menu.h>
|
||||
#include <vcc/bus/cartridge_messages.h>
|
||||
|
||||
static VCC::Bus::cartridge_menu GMCMenu {};
|
||||
|
||||
void GMCCartridge::LoadConfiguration(const std::string& filename)
|
||||
{
|
||||
Cartridge::LoadConfiguration(filename);
|
||||
m_Configuration = Configuration(filename);
|
||||
}
|
||||
|
||||
bool GMCCartridge::GetMenuItem(menu_item_entry* item, size_t index)
|
||||
{
|
||||
if (!item) return false;
|
||||
// request zero rebuilds the menu list but does it ever change?
|
||||
// leave it incase we want to show the loaded rom in the menu
|
||||
if (index == 0) {
|
||||
GMCMenu.clear();
|
||||
GMCMenu.add("", 0, MIT_Seperator);
|
||||
GMCMenu.add("Select GMC ROM", ControlId(MenuItems::SelectRom), MIT_StandAlone);
|
||||
}
|
||||
// return requested list item or false
|
||||
return GMCMenu.copy_item(*item, index);
|
||||
}
|
||||
|
||||
std::string GMCCartridge::GetStatusMessage() const
|
||||
{
|
||||
std::string message("GMC Active");
|
||||
|
||||
const auto activeRom(ExtractFilename(m_ROMImage.GetFilename()));
|
||||
if (m_ROMImage.HasImage())
|
||||
{
|
||||
message += " (" + activeRom + " Loaded)";
|
||||
}
|
||||
else
|
||||
{
|
||||
message += activeRom.empty() ? " (No ROM Selected)" : "(Unable to load `" + activeRom + "`)";
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
void GMCCartridge::OnMenuItemSelected(unsigned char menuId)
|
||||
{
|
||||
if (menuId == MenuItems::SelectRom)
|
||||
{
|
||||
const auto selectedFile(SelectROMFile());
|
||||
m_Configuration.SetActiveRom(selectedFile);
|
||||
|
||||
extern HWND gVccWnd;
|
||||
SendMessage(gVccWnd, WM_VCC_CPU_RESET, (WPARAM)0, (LPARAM)0);
|
||||
|
||||
AssetCartridgeLine(false);
|
||||
AssetCartridgeLine(true);
|
||||
}
|
||||
}
|
||||
|
||||
void GMCCartridge::OnReset()
|
||||
{
|
||||
m_PSG.device_start();
|
||||
|
||||
if (m_ROMImage.Load(m_Configuration.GetActiveRom()))
|
||||
{
|
||||
AssetCartridgeLine(false);
|
||||
AssetCartridgeLine(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ROMImage.Unload();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned short GMCCartridge::UpdateAudio()
|
||||
{
|
||||
SN76489Device::stream_sample_t lbuffer, rbuffer;
|
||||
|
||||
return m_PSG.sound_stream_update(lbuffer, rbuffer);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
unsigned char GMCCartridge::OnReadMemory(unsigned short address) const
|
||||
{
|
||||
return m_ROMImage.Read(address);
|
||||
}
|
||||
|
||||
|
||||
void GMCCartridge::OnWritePort(unsigned char port, unsigned char data)
|
||||
{
|
||||
if (port < 0x40 && port > 0x5f) return;
|
||||
|
||||
switch (port&1)
|
||||
{
|
||||
case Ports::BankSelect:
|
||||
m_ROMImage.SetBank(data);
|
||||
break;
|
||||
|
||||
case Ports::PSG:
|
||||
m_PSG.write(data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned char GMCCartridge::OnReadPort(unsigned char port) const
|
||||
{
|
||||
if (port < 0x40 && port > 0x5f) return 0;
|
||||
|
||||
if ((port&1) == Ports::BankSelect)
|
||||
{
|
||||
return m_ROMImage.GetBank();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
#include "Cartridge.h"
|
||||
#include "ROM.h"
|
||||
#include "sn76496.h"
|
||||
#include "Configuration.h"
|
||||
|
||||
|
||||
class GMCCartridge : public Cartridge
|
||||
{
|
||||
public:
|
||||
|
||||
void LoadConfiguration(const std::string& filename) override;
|
||||
|
||||
std::string GetStatusMessage() const override;
|
||||
void OnMenuItemSelected(unsigned char menuId) override;
|
||||
void OnReset() override;
|
||||
unsigned short UpdateAudio() override;
|
||||
unsigned char OnReadMemory(unsigned short address) const override;
|
||||
void OnWritePort(unsigned char port, unsigned char data) override;
|
||||
unsigned char OnReadPort(unsigned char port) const override;
|
||||
bool GetMenuItem(menu_item_entry* item, size_t index) override;
|
||||
|
||||
private:
|
||||
|
||||
struct MenuItems
|
||||
{
|
||||
static const unsigned int SelectRom = 10;
|
||||
};
|
||||
|
||||
struct Ports
|
||||
{
|
||||
static const unsigned char BankSelect = 0;
|
||||
static const unsigned char PSG = 1;
|
||||
};
|
||||
|
||||
ROM m_ROMImage;
|
||||
SN76489Device m_PSG;
|
||||
Configuration m_Configuration;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#include "ROM.h"
|
||||
#include <fstream>
|
||||
#include <Windows.h>
|
||||
using namespace std;
|
||||
|
||||
bool ROM::Load(std::string filename)
|
||||
{
|
||||
ifstream input(filename,ios::binary);
|
||||
if (!input.is_open())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
std::streamoff begin = input.tellg();
|
||||
input.seekg(0,ios::end);
|
||||
std::streamoff end = input.tellg();
|
||||
std::streamoff fileLength = end - begin;
|
||||
input.seekg(0,ios::beg);
|
||||
|
||||
std::vector<unsigned char> fileData(static_cast<size_t>(fileLength));
|
||||
input.read(reinterpret_cast<char*>(&fileData[0]), fileData.size());
|
||||
|
||||
if (fileLength != fileData.size())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
m_Filename = move(filename);
|
||||
m_Data = move(fileData);
|
||||
m_BankOffset = 0;
|
||||
m_Bank = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ROM::Unload()
|
||||
{
|
||||
m_Data.clear();
|
||||
m_BankOffset = 0;
|
||||
m_Bank = 0;
|
||||
}
|
||||
|
||||
|
||||
void ROM::Reset()
|
||||
{
|
||||
SetBank(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void ROM::SetBank(unsigned char blockId)
|
||||
{
|
||||
if (!m_Data.empty())
|
||||
{
|
||||
m_Bank = blockId;
|
||||
m_BankOffset = blockId * BankSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned char ROM::GetBank() const
|
||||
{
|
||||
return m_Bank;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ROM::value_type ROM::Read(size_type readOffset) const
|
||||
{
|
||||
if (m_Data.empty())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return m_Data[(m_BankOffset + readOffset) % m_Data.size()];
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class ROM
|
||||
{
|
||||
public:
|
||||
|
||||
using container_type = std::vector<unsigned char>;
|
||||
using value_type = container_type::value_type;
|
||||
using size_type = container_type::size_type;
|
||||
|
||||
static const unsigned BankSize = 16384; // 8k banks
|
||||
|
||||
virtual ~ROM() = default;
|
||||
|
||||
bool HasImage() const
|
||||
{
|
||||
return !m_Data.empty();
|
||||
}
|
||||
|
||||
std::string GetFilename() const
|
||||
{
|
||||
return m_Filename;
|
||||
}
|
||||
|
||||
virtual bool Load(std::string filename);
|
||||
virtual void Unload();
|
||||
virtual void Reset();
|
||||
|
||||
virtual void SetBank(unsigned char blockId);
|
||||
virtual unsigned char GetBank() const;
|
||||
virtual value_type Read(size_type offset) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::string m_Filename;
|
||||
unsigned char m_Bank = 0;
|
||||
size_type m_BankOffset = 0;
|
||||
container_type m_Data;
|
||||
};
|
||||
@@ -0,0 +1,122 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Legacy|Win32">
|
||||
<Configuration>Legacy</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<SccProjectName />
|
||||
<SccLocalPath />
|
||||
<ProjectGuid>{BD7CA587-71D0-43D6-A730-582126B1C1F4}</ProjectGuid>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\vcc-base.props" />
|
||||
<Import Project="..\vcc-legacy.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\vcc-base.props" />
|
||||
<Import Project="..\vcc-release.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\vcc-base.props" />
|
||||
<Import Project="..\vcc-debug.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
|
||||
<LibraryPath>C:\Program Files %28x86%29\Windows Kits\8.1\Lib\winv6.3\um\x86;$(LibraryPath)</LibraryPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;GMC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<ResourceCompile />
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_USRDLL;GMC_EXPORTS;_LEGACY_VCC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/arch:SSE</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<ResourceCompile>
|
||||
<Culture>0x0409</Culture>
|
||||
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ResourceCompile>
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;GMC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/arch:SSE</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<ResourceCompile />
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Cartridge.cpp" />
|
||||
<ClCompile Include="CartridgeTrampolines.cpp" />
|
||||
<ClCompile Include="Configuration.cpp" />
|
||||
<ClCompile Include="GMCCartridge.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="ROM.cpp" />
|
||||
<ClCompile Include="sn76496.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="CartridgeTrampolines.h" />
|
||||
<ClInclude Include="Configuration.h" />
|
||||
<ClInclude Include="GMC.h" />
|
||||
<ClInclude Include="Cartridge.h" />
|
||||
<ClInclude Include="GMCCartridge.h" />
|
||||
<ClInclude Include="resource.h" />
|
||||
<ClInclude Include="ROM.h" />
|
||||
<ClInclude Include="sn76496.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="GMC.rc" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\libcommon\libcommon.vcxproj">
|
||||
<Project>{e0aa25bd-5527-475f-8d8b-b549a6311b0c}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Cartridge.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="CartridgeTrampolines.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Configuration.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="GMCCartridge.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ROM.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="sn76496.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Cartridge.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="CartridgeTrampolines.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Configuration.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GMC.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="GMCCartridge.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ROM.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="sn76496.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="resource.h">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{91041c29-a58e-47d1-be3c-2181e226240f}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{1bc76e3c-f021-4d3d-9abc-d398f3daab81}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{c2b09bad-8285-4ea1-9cde-aaaa010a2925}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="GMC.rc">
|
||||
<Filter>Resource Files</Filter>
|
||||
</ResourceCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,68 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright 2015 by Joseph Forgione
|
||||
// This file is part of VCC (Virtual Color Computer).
|
||||
//
|
||||
// VCC (Virtual Color Computer) is free software: you can redistribute itand/or
|
||||
// modify it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or (at your
|
||||
// option) any later version.
|
||||
//
|
||||
// VCC (Virtual Color Computer) 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.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License along with
|
||||
// VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include <Windows.h>
|
||||
#include "GMCCartridge.h"
|
||||
#include <vcc/util/DialogOps.h>
|
||||
|
||||
HINSTANCE gModuleInstance = nullptr;
|
||||
GMCCartridge theCart;
|
||||
|
||||
std::string ExtractFilename(std::string path)
|
||||
{
|
||||
char filename[MAX_PATH];
|
||||
char ext[MAX_PATH];
|
||||
|
||||
_splitpath(path.c_str(), nullptr, nullptr, filename, ext);
|
||||
path = filename;
|
||||
if (ext[0])
|
||||
{
|
||||
path += ext;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
std::string SelectROMFile()
|
||||
{
|
||||
std::string selectedPath;
|
||||
|
||||
FileDialog dlg;
|
||||
dlg.setFilter("ROM Files\0*.ROM\0\0");
|
||||
dlg.setDefExt("rom");
|
||||
dlg.setTitle("Select GMC Rom file");
|
||||
if (dlg.show()) {
|
||||
selectedPath = dlg.path();
|
||||
} else {
|
||||
selectedPath.clear();
|
||||
}
|
||||
return selectedPath;
|
||||
}
|
||||
|
||||
|
||||
BOOL APIENTRY DllMain(HINSTANCE hinst, DWORD reason, LPVOID foo)
|
||||
{
|
||||
if (reason == DLL_PROCESS_ATTACH) {
|
||||
gModuleInstance = hinst;
|
||||
} else if (reason == DLL_PROCESS_DETACH) {
|
||||
//Clean up here.
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by GMC.rc
|
||||
//
|
||||
#define IDS_MODULE_NAME 1
|
||||
#define IDS_CATNUMBER 2
|
||||
#define IDS_DESCRIPTION 3
|
||||
#define IDS_VERSION 4
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 102
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
@@ -0,0 +1,380 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Nicola Salmoria
|
||||
/***************************************************************************
|
||||
|
||||
sn76496.c
|
||||
by Nicola Salmoria
|
||||
with contributions by others
|
||||
|
||||
Routines to emulate the:
|
||||
Texas Instruments SN76489, SN76489A, SN76494/SN76496
|
||||
( Also known as, or at least compatible with, the TMS9919 and SN94624.)
|
||||
and the Sega 'PSG' used on the Master System, Game Gear, and Megadrive/Genesis
|
||||
This chip is known as the Programmable Sound Generator, or PSG, and is a 4
|
||||
channel sound generator, with three squarewave channels and a noise/arbitrary
|
||||
duty cycle channel.
|
||||
|
||||
Noise emulation for all verified chips should be accurate:
|
||||
|
||||
** SN76489 uses a 15-bit shift register with taps on bits D and E, output on E,
|
||||
XOR function.
|
||||
It uses a 15-bit ring buffer for periodic noise/arbitrary duty cycle.
|
||||
Its output is inverted.
|
||||
** SN94624 is the same as SN76489 but lacks the /8 divider on its clock input.
|
||||
** SN76489A uses a 15-bit shift register with taps on bits D and E, output on F,
|
||||
XOR function.
|
||||
It uses a 15-bit ring buffer for periodic noise/arbitrary duty cycle.
|
||||
Its output is not inverted.
|
||||
** SN76494 is the same as SN76489A but lacks the /8 divider on its clock input.
|
||||
** SN76496 is identical in operation to the SN76489A, but the audio input on pin 9 is
|
||||
documented.
|
||||
All the TI-made PSG chips have an audio input line which is mixed with the 4 channels
|
||||
of output. (It is undocumented and may not function properly on the sn76489, 76489a
|
||||
and 76494; the sn76489a input is mentioned in datasheets for the tms5200)
|
||||
All the TI-made PSG chips act as if the frequency was set to 0x400 if 0 is
|
||||
written to the frequency register.
|
||||
** Sega Master System III/MD/Genesis PSG uses a 16-bit shift register with taps
|
||||
on bits C and F, output on F
|
||||
It uses a 16-bit ring buffer for periodic noise/arbitrary duty cycle.
|
||||
(whether it uses an XOR or XNOR needs to be verified, assumed XOR)
|
||||
(whether output is inverted or not needs to be verified, assumed to be inverted)
|
||||
** Sega Game Gear PSG is identical to the SMS3/MD/Genesis one except it has an
|
||||
extra register for mapping which channels go to which speaker.
|
||||
The register, connected to a z80 port, means:
|
||||
for bits 7 6 5 4 3 2 1 0
|
||||
L3 L2 L1 L0 R3 R2 R1 R0
|
||||
Noise is an XOR function, and audio output is negated before being output.
|
||||
All the Sega-made PSG chips act as if the frequency was set to 0 if 0 is written
|
||||
to the frequency register.
|
||||
** NCR8496 (as used on the Tandy 1000TX) is similar to the SN76489 but with a
|
||||
different noise LFSR pattern: taps on bits A and E, output on E, XNOR function
|
||||
It uses a 15-bit ring buffer for periodic noise/arbitrary duty cycle.
|
||||
Its output is inverted.
|
||||
** PSSJ-3 (as used on the later Tandy 1000 series computers) is the same as the
|
||||
NCR8496 with the exception that its output is not inverted.
|
||||
|
||||
1/1/2019: Chet Simpson
|
||||
Refactored for use with VCC Color Computer 3 Emulator
|
||||
|
||||
28/03/2005 : Sebastien Chevalier
|
||||
Update th SN76496Write func, according to SN76489 doc found on SMSPower.
|
||||
- On write with 0x80 set to 0, when LastRegister is other then TONE,
|
||||
the function is similar than update with 0x80 set to 1
|
||||
|
||||
23/04/2007 : Lord Nightmare
|
||||
Major update, implement all three different noise generation algorithms and a
|
||||
set_variant call to discern among them.
|
||||
|
||||
28/04/2009 : Lord Nightmare
|
||||
Add READY line readback; cleaned up struct a bit. Cleaned up comments.
|
||||
Add more TODOs. Fixed some unsaved savestate related stuff.
|
||||
|
||||
04/11/2009 : Lord Nightmare
|
||||
Changed the way that the invert works (it now selects between XOR and XNOR
|
||||
for the taps), and added R->OldNoise to simulate the extra 0 that is always
|
||||
output before the noise LFSR contents are after an LFSR reset.
|
||||
This fixes SN76489/A to match chips. Added SN94624.
|
||||
|
||||
14/11/2009 : Lord Nightmare
|
||||
Removed STEP mess, vastly simplifying the code. Made output bipolar rather
|
||||
than always above the 0 line, but disabled that code due to pending issues.
|
||||
|
||||
16/11/2009 : Lord Nightmare
|
||||
Fix screeching in regulus: When summing together four equal channels, the
|
||||
size of the max amplitude per channel should be 1/4 of the max range, not
|
||||
1/3. Added NCR8496.
|
||||
|
||||
18/11/2009 : Lord Nightmare
|
||||
Modify Init functions to support negating the audio output. The gamegear
|
||||
psg does this. Change gamegear and sega psgs to use XOR rather than XNOR
|
||||
based on testing. Got rid of R->OldNoise and fixed taps accordingly.
|
||||
Added stereo support for game gear.
|
||||
|
||||
15/01/2010 : Lord Nightmare
|
||||
Fix an issue with SN76489 and SN76489A having the wrong periodic noise periods.
|
||||
Note that properly emulating the noise cycle bit timing accurately may require
|
||||
extensive rewriting.
|
||||
|
||||
24/01/2010: Lord Nightmare
|
||||
Implement periodic noise as forcing one of the XNOR or XOR taps to 1 or 0 respectively.
|
||||
Thanks to PlgDavid for providing samples which helped immensely here.
|
||||
Added true clock divider emulation, so sn94624 and sn76494 run 8x faster than
|
||||
the others, as in real life.
|
||||
|
||||
15/02/2010: Lord Nightmare & Michael Zapf (additional testing by PlgDavid)
|
||||
Fix noise period when set to mirror channel 3 and channel 3 period is set to 0 (tested on hardware for noise, wave needs tests) - MZ
|
||||
Fix phase of noise on sn94624 and sn76489; all chips use a standard XOR, the only inversion is the output itself - LN, Plgdavid
|
||||
Thanks to PlgDavid and Michael Zapf for providing samples which helped immensely here.
|
||||
|
||||
23/02/2011: Lord Nightmare & Enik
|
||||
Made it so the Sega PSG chips have a frequency of 0 if 0 is written to the
|
||||
frequency register, while the others have 0x400 as before. Should fix a bug
|
||||
or two on sega games, particularly Vigilante on Sega Master System. Verified
|
||||
on SMS hardware.
|
||||
|
||||
27/06/2012: Michael Zapf
|
||||
Converted to modern device, legacy devices were gradually removed afterwards.
|
||||
|
||||
16/09/2015: Lord Nightmare
|
||||
Fix PSG chips to have volume reg inited on reset to 0x0 based on tests by
|
||||
ValleyBell. Made Sega PSG chips start up with register 0x3 selected (volume
|
||||
for channel 2) based on hardware tests by Nemesis.
|
||||
|
||||
03/09/2018: Lord Nightmare, Qbix, ValleyBell, NewRisingSun
|
||||
* renamed the NCR8496 to its correct name, based on chip pictures on VGMPF
|
||||
* fixed NCR8496's noise LFSR behavior so it is only reset if the mode bit in
|
||||
register 6 is changed.
|
||||
* NCR8496's LFSR feedback function is an XNOR, which is now supported.
|
||||
* add PSSJ-3 support for the later Tandy 1000 series computers.
|
||||
* NCR8496's output is inverted, PSSJ-3's output is not.
|
||||
|
||||
16/10/2026: Craig Allsop
|
||||
* fix integration with vcc and return the expected format.
|
||||
|
||||
TODO: * Implement the TMS9919 - any difference to sn94624?
|
||||
* Implement the T6W28; has registers in a weird order, needs writes
|
||||
to be 'sanitized' first. Also is stereo, similar to game gear.
|
||||
* Factor out common code so that the SAA1099 can share some code.
|
||||
* verify NCR8496/PSSJ-3 behavior on write to mirrored registers; unlike the
|
||||
other variants, the NCR-derived variants are implied to ignore writes to
|
||||
regs 1,3,5,6,7 if 0x80 is not set. This needs to be verified on real hardware.
|
||||
|
||||
***************************************************************************/
|
||||
#include "sn76496.h"
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
|
||||
// was: #define MAX_OUTPUT 0x7fff
|
||||
// changed to use the full range since output is always positive atm, each
|
||||
// channel is given MAX_OUTPUT/4, this is rounded to integer so there is
|
||||
// already loss. See: https://www.smspower.org/Development/SN76489 actual
|
||||
// output is 0/1 (before filtering). If this is changed to +-0.5 then this
|
||||
// should be updated of course.
|
||||
#define MAX_OUTPUT 0xffff
|
||||
|
||||
|
||||
void SN76489Device::device_start()
|
||||
{
|
||||
for (int i = 0; i < 8; i += 2)
|
||||
{
|
||||
m_register[i] = 0;
|
||||
m_register[i + 1] = 0; // volume = 0x0 (max volume) on reset; this needs testing on chips other than SN76489A and Sega VDP PSG
|
||||
}
|
||||
m_last_register = m_sega_style_psg ? 3 : 0; // Sega VDP PSG defaults to selected period reg for 2nd channel
|
||||
|
||||
for (int i = 0; i < 4; i++)
|
||||
{
|
||||
m_period[i] = 0;
|
||||
m_volume[i] = 0;
|
||||
m_count[i] = 0;
|
||||
m_output[i] = 0;
|
||||
}
|
||||
|
||||
m_RNG = m_feedback_mask;
|
||||
m_output[3] = m_RNG & 1;
|
||||
|
||||
m_cycles_to_ready = 1; // assume ready is not active immediately on init. is this correct?
|
||||
m_stereo_mask = 0xFF; // all channels enabled
|
||||
|
||||
|
||||
// build volume table (2dB per step)
|
||||
double out = MAX_OUTPUT / 4; // four channels, each gets 1/4 of the total range
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
// limit volume to avoid clipping
|
||||
if (out > MAX_OUTPUT / 4)
|
||||
{
|
||||
m_vol_table[i] = MAX_OUTPUT / 4;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vol_table[i] = static_cast<int32_t>(out);
|
||||
}
|
||||
|
||||
out /= 1.258925412; /* = 10 ^ (2/20) = 2dB */
|
||||
}
|
||||
m_vol_table[15] = 0;
|
||||
|
||||
m_ready_state = true;
|
||||
}
|
||||
|
||||
|
||||
void SN76489Device::write(uint8_t data)
|
||||
{
|
||||
int n, r, c;
|
||||
|
||||
// set number of cycles until READY is active; this is always one
|
||||
// 'sample', i.e. it equals the clock divider exactly
|
||||
m_cycles_to_ready = 1;
|
||||
|
||||
if (data & 0x80)
|
||||
{
|
||||
r = (data & 0x70) >> 4;
|
||||
m_last_register = r;
|
||||
if ((m_ncr_style_psg && (r == 6)) && ((data & 0x04) != (m_register[6] & 0x04)))
|
||||
{
|
||||
m_RNG = m_feedback_mask; // NCR-style PSG resets the LFSR only on a mode write which actually changes the state of bit 2 of register 6
|
||||
}
|
||||
m_register[r] = (m_register[r] & 0x3f0) | (data & 0x0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
r = m_last_register;
|
||||
//if ((m_ncr_style_psg) && ((r & 1) || (r == 6))) return; // NCR-style PSG ignores writes to regs 1, 3, 5, 6 and 7 with bit 7 clear; this behavior is not verified on hardware yet, uncomment it once verified.
|
||||
}
|
||||
|
||||
c = r >> 1;
|
||||
switch (r)
|
||||
{
|
||||
case 0: // tone 0: frequency
|
||||
case 2: // tone 1: frequency
|
||||
case 4: // tone 2: frequency
|
||||
if ((data & 0x80) == 0)
|
||||
{
|
||||
m_register[r] = (m_register[r] & 0x0f) | ((data & 0x3f) << 4);
|
||||
}
|
||||
|
||||
if (m_register[r] != 0 || !m_sega_style_psg)
|
||||
{
|
||||
m_period[c] = m_register[r];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_period[c] = 0x400;
|
||||
}
|
||||
|
||||
if (r == 4)
|
||||
{
|
||||
// update noise shift frequency
|
||||
if ((m_register[6] & 0x03) == 0x03)
|
||||
{
|
||||
m_period[3] = m_period[2] << 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 1: // tone 0: volume
|
||||
case 3: // tone 1: volume
|
||||
case 5: // tone 2: volume
|
||||
case 7: // noise: volume
|
||||
m_volume[c] = m_vol_table[data & 0x0f];
|
||||
if ((data & 0x80) == 0)
|
||||
{
|
||||
m_register[r] = (m_register[r] & 0x3f0) | (data & 0x0f);
|
||||
}
|
||||
break;
|
||||
|
||||
case 6: // noise: frequency, mode
|
||||
//if ((data & 0x80) == 0) logerror("SN76489Device: write to reg 6 with bit 7 clear; data was %03x, new write is %02x! report this to LN!\n", m_register[6], data);
|
||||
if ((data & 0x80) == 0)
|
||||
{
|
||||
m_register[r] = (m_register[r] & 0x3f0) | (data & 0x0f);
|
||||
}
|
||||
n = m_register[6];
|
||||
// N/512,N/1024,N/2048,Tone #3 output
|
||||
m_period[3] = ((n & 3) == 3) ? (m_period[2] << 1) : (1 << (5 + (n & 3)));
|
||||
if (!m_ncr_style_psg)
|
||||
{
|
||||
m_RNG = m_feedback_mask;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool SN76489Device::in_noise_mode() const
|
||||
{
|
||||
return ((m_register[6] & 4) != 0);
|
||||
}
|
||||
|
||||
void SN76489Device::countdown_cycles()
|
||||
{
|
||||
if (m_cycles_to_ready > 0)
|
||||
{
|
||||
m_cycles_to_ready--;
|
||||
//if (m_ready_state==true) m_ready_handler(CLEAR_LINE);
|
||||
m_ready_state = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//if (m_ready_state==false) m_ready_handler(ASSERT_LINE);
|
||||
m_ready_state = true;
|
||||
}
|
||||
}
|
||||
|
||||
SN76489Device::stream_sample_t SN76489Device::sound_stream_update(stream_sample_t& lbuffer, stream_sample_t& rbuffer)
|
||||
{
|
||||
// decrement Cycles to READY by one
|
||||
countdown_cycles();
|
||||
|
||||
// handle channels 0,1,2
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
m_count[i]--;
|
||||
if (m_count[i] <= 0)
|
||||
{
|
||||
m_output[i] ^= 1;
|
||||
m_count[i] = static_cast<int32_t>(static_cast<float>(m_period[i]) / m_period_divider);
|
||||
}
|
||||
}
|
||||
|
||||
// handle channel 3
|
||||
m_count[3]--;
|
||||
if (m_count[3] <= 0)
|
||||
{
|
||||
// if noisemode is 1, both taps are enabled
|
||||
// if noisemode is 0, the lower tap, whitenoisetap2, is held at 0
|
||||
// The != was a bit-XOR (^) before
|
||||
if (((m_RNG & m_whitenoise_tap1)!=0) != (((static_cast<int32_t>(m_RNG) & m_whitenoise_tap2)!=(m_ncr_style_psg?m_whitenoise_tap2:0)) && in_noise_mode()))
|
||||
{
|
||||
m_RNG >>= 1;
|
||||
m_RNG |= m_feedback_mask;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_RNG >>= 1;
|
||||
}
|
||||
m_output[3] = m_RNG & 1;
|
||||
|
||||
m_count[3] = static_cast<int32_t>(static_cast<float>(m_period[3]) / m_period_divider);
|
||||
}
|
||||
|
||||
int out;
|
||||
int out2 = 0;
|
||||
|
||||
if (m_stereo)
|
||||
{
|
||||
out = ((((m_stereo_mask & 0x10)!=0) && (m_output[0]!=0))? m_volume[0] : 0)
|
||||
+ ((((m_stereo_mask & 0x20)!=0) && (m_output[1]!=0))? m_volume[1] : 0)
|
||||
+ ((((m_stereo_mask & 0x40)!=0) && (m_output[2]!=0))? m_volume[2] : 0)
|
||||
+ ((((m_stereo_mask & 0x80)!=0) && (m_output[3]!=0))? m_volume[3] : 0);
|
||||
|
||||
out2= ((((m_stereo_mask & 0x1)!=0) && (m_output[0]!=0))? m_volume[0] : 0)
|
||||
+ ((((m_stereo_mask & 0x2)!=0) && (m_output[1]!=0))? m_volume[1] : 0)
|
||||
+ ((((m_stereo_mask & 0x4)!=0) && (m_output[2]!=0))? m_volume[2] : 0)
|
||||
+ ((((m_stereo_mask & 0x8)!=0) && (m_output[3]!=0))? m_volume[3] : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
out= ((m_output[0]!=0)? m_volume[0]:0)
|
||||
+((m_output[1]!=0)? m_volume[1]:0)
|
||||
+((m_output[2]!=0)? m_volume[2]:0)
|
||||
+((m_output[3]!=0)? m_volume[3]:0);
|
||||
|
||||
// output mono to both channels
|
||||
out2 = out;
|
||||
}
|
||||
|
||||
lbuffer = static_cast<stream_sample_t>(out);
|
||||
rbuffer = static_cast<stream_sample_t>(out2);
|
||||
|
||||
// assumed positive
|
||||
assert(lbuffer >= 0 && lbuffer <= MAX_OUTPUT);
|
||||
assert(rbuffer >= 0 && lbuffer <= MAX_OUTPUT);
|
||||
|
||||
// vcc expects unsigned short as 0xLLRR, as lrbuffer is
|
||||
// never negative just convert to unsigned byte.
|
||||
uint8_t left = std::clamp(lbuffer >> 8, 0, 255);
|
||||
uint8_t right = std::clamp(rbuffer >> 8, 0, 255);
|
||||
return (left << 8) | right;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
// license:BSD-3-Clause
|
||||
// copyright-holders:Nicola Salmoria
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
class SN76489Device
|
||||
{
|
||||
public:
|
||||
|
||||
using stream_sample_t = unsigned short;
|
||||
|
||||
SN76489Device() = default;
|
||||
virtual ~SN76489Device() = default;
|
||||
|
||||
virtual void device_start();
|
||||
virtual void write(uint8_t data);
|
||||
virtual stream_sample_t sound_stream_update(stream_sample_t &lbuffer, stream_sample_t &rbuffer);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
|
||||
private:
|
||||
|
||||
inline bool in_noise_mode() const;
|
||||
void countdown_cycles();
|
||||
|
||||
|
||||
const int32_t m_feedback_mask = 0x4000; // mask for feedback
|
||||
const int32_t m_whitenoise_tap1 = 0x01; // mask for white noise tap 1 (higher one, usually bit 14)
|
||||
const int32_t m_whitenoise_tap2 = 0x02; // mask for white noise tap 2 (lower one, usually bit 13)
|
||||
const bool m_stereo = false; // whether we're dealing with stereo or not
|
||||
const float m_period_divider = 6.11f; // period divider
|
||||
const bool m_ncr_style_psg = false; // flag to ignore writes to regs 1,3,5,6,7 with bit 7 low
|
||||
const bool m_sega_style_psg = true; // flag to make frequency zero acts as if it is one more than max (0x3ff+1) or if it acts like 0; the initial register is pointing to 0x3 instead of 0x0; the volume reg is preloaded with 0xF instead of 0x0
|
||||
|
||||
int32_t m_vol_table[16] = { 0 }; // volume table (for 4-bit to db conversion)
|
||||
|
||||
bool m_ready_state = false;
|
||||
int32_t m_cycles_to_ready = 0; // number of cycles until the READY line goes active
|
||||
int32_t m_register[8] = { 0 }; // registers
|
||||
int32_t m_last_register = 0; // last register written
|
||||
uint32_t m_RNG = 0; // noise generator LFSR
|
||||
int32_t m_stereo_mask = 0; // the stereo output mask
|
||||
int32_t m_period[4] = { 0 }; // Length of 1/2 of waveform
|
||||
int32_t m_volume[4] = { 0 }; // db volume of voice 0-2 and noise
|
||||
int32_t m_count[4] = { 0 }; // Position within the waveform
|
||||
int32_t m_output[4] = { 0 }; // 1-bit output of each channel, pre-volume
|
||||
};
|
||||
Reference in new issue
Block a user