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,111 @@
|
||||
<?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>{850B6887-187F-4553-BAEA-B0E19C91EA30}</ProjectGuid>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
<ProjectName>ssc</ProjectName>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>DynamicLibrary</ConfigurationType>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
<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;SSC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Legacy|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_USRDLL;SSC_EXPORTS;_LEGACY_VCC;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/arch:SSE</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;SSC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalOptions>/arch:SSE</AdditionalOptions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<LinkDLL>true</LinkDLL>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ssc_dll.cpp" />
|
||||
<ClCompile Include="..\..\..\src\devices\ssc\ssc_core.cpp" />
|
||||
<ClCompile Include="..\..\..\src\devices\ssc\tms7000.cpp" />
|
||||
<ClCompile Include="..\..\..\src\devices\ssc\sp0256.cpp" />
|
||||
<ClCompile Include="..\..\..\src\devices\ssc\ay8913.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\src\devices\ssc\ssc_core.h" />
|
||||
<ClInclude Include="..\..\..\src\devices\ssc\tms7000.h" />
|
||||
<ClInclude Include="..\..\..\src\devices\ssc\sp0256.h" />
|
||||
<ClInclude Include="..\..\..\src\devices\ssc\ay8913.h" />
|
||||
</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,208 @@
|
||||
// ssc_dll.cpp
|
||||
//
|
||||
// VCC "cpak" DLL cartridge entry points for the Tandy Speech/Sound
|
||||
// Cartridge emulation. This file is the thin, Windows/VCC-specific
|
||||
// adapter; all of the actual chip emulation lives in ssc_core.* /
|
||||
// tms7000.* / sp0256.* / ay8913.*, which are plain portable C++ with no
|
||||
// VCC or Windows dependency and can be (and are, see test/) unit tested
|
||||
// standalone.
|
||||
//
|
||||
// Build layout: this file is designed to live in a folder (e.g. "SSC/")
|
||||
// dropped in as a sibling of VCC's own orch90/, FD502/, GMC/ folders
|
||||
// inside a checkout of https://github.com/VCCE/VCC -- see README.md.
|
||||
// That gives it the same libcommon include path and project-reference
|
||||
// setup every other pak in the tree already uses.
|
||||
//
|
||||
// ROM files: the SSC's two internal ROMs (the PIC7040 firmware and the
|
||||
// SP0256-AL2 speech mask ROM) are NOT included with this source -- they
|
||||
// are copyrighted dumps of the real cartridge's chips, same as how VCC
|
||||
// itself expects the user to supply their own CoCo BASIC ROM, and how
|
||||
// orch90.dll expects ORCH90.ROM to already exist. At startup this DLL
|
||||
// looks for two files next to SSC.DLL itself:
|
||||
// pic-7040-510.bin (4096 bytes)
|
||||
// sp0256-al2.bin (2048 bytes)
|
||||
// using the same filenames MAME's coco_ssc.cpp ROM_LOAD lines use, so a
|
||||
// ROM set already collected for MAME can be copied over unmodified. See
|
||||
// README.md for where these are documented/archived.
|
||||
|
||||
#include <windows.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <vcc/bus/cpak_cartridge_definitions.h>
|
||||
|
||||
#include "../../../src/devices/ssc/ssc_core.h"
|
||||
|
||||
namespace {
|
||||
|
||||
HINSTANCE gModuleInstance = nullptr;
|
||||
slot_id_type gSlotId {};
|
||||
PakAssertCartridgeLineHostCallback gAssertCartLine = nullptr;
|
||||
ssc::SscCore gSsc;
|
||||
bool gRomsOk = false;
|
||||
char gRomDir[MAX_PATH] = "";
|
||||
|
||||
// Directory containing this DLL (not the host EXE's CWD -- see the
|
||||
// header comment above for why that matters).
|
||||
void ComputeRomDir()
|
||||
{
|
||||
char path[MAX_PATH] = "";
|
||||
GetModuleFileNameA(gModuleInstance, path, MAX_PATH);
|
||||
|
||||
char* slash = strrchr(path, '\\');
|
||||
if (!slash) slash = strrchr(path, '/');
|
||||
if (slash) {
|
||||
*(slash + 1) = '\0';
|
||||
std::snprintf(gRomDir, sizeof(gRomDir), "%s", path);
|
||||
} else {
|
||||
gRomDir[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
bool ReadWholeFile(const char* filename, uint8_t* buf, size_t expected_len)
|
||||
{
|
||||
char full[MAX_PATH * 2];
|
||||
std::snprintf(full, sizeof(full), "%s%s", gRomDir, filename);
|
||||
|
||||
FILE* f = std::fopen(full, "rb");
|
||||
if (!f) return false;
|
||||
|
||||
size_t got = std::fread(buf, 1, expected_len, f);
|
||||
std::fclose(f);
|
||||
return got == expected_len;
|
||||
}
|
||||
|
||||
bool LoadRoms()
|
||||
{
|
||||
static uint8_t pic_rom[4096];
|
||||
static uint8_t spo_rom[0x800];
|
||||
|
||||
bool pic_ok = ReadWholeFile("pic-7040-510.bin", pic_rom, sizeof(pic_rom));
|
||||
bool spo_ok = ReadWholeFile("sp0256-al2.bin", spo_rom, sizeof(spo_rom));
|
||||
|
||||
if (pic_ok) gSsc.LoadPicRom(pic_rom, sizeof(pic_rom));
|
||||
if (spo_ok) gSsc.LoadSpeechRom(spo_rom, sizeof(spo_rom));
|
||||
|
||||
return pic_ok && spo_ok;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C"
|
||||
{
|
||||
__declspec(dllexport) const char* PakGetName()
|
||||
{
|
||||
return "Tandy Speech/Sound Cartridge";
|
||||
}
|
||||
|
||||
__declspec(dllexport) const char* PakGetCatalogId()
|
||||
{
|
||||
return "26-3144";
|
||||
}
|
||||
|
||||
__declspec(dllexport) const char* PakGetDescription()
|
||||
{
|
||||
return gRomsOk
|
||||
? "Tandy Speech/Sound Cartridge (SSC): PIC7040 + AY-3-8913 + SP0256-AL2 emulation"
|
||||
: "Tandy Speech/Sound Cartridge (SSC): ROMs not found -- see README.md";
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakInitialize(
|
||||
slot_id_type SlotId,
|
||||
const char* const /*configuration_path*/,
|
||||
HWND /*hVccWnd*/,
|
||||
const cpak_callbacks* const callbacks)
|
||||
{
|
||||
gSlotId = SlotId;
|
||||
gAssertCartLine = callbacks->assert_cartridge_line;
|
||||
|
||||
// This "cpak" ABI generation ticks us from PakProcessHorizontalSync
|
||||
// (a real per-scanline callback) rather than from the audio-sample
|
||||
// export itself -- a genuinely different cadence than the classic
|
||||
// ModuleAudioSample-driven ABI in ssc_dll_legacy.cpp, which SscCore
|
||||
// defaults to (44100Hz). Per an embedded comment in VCCE/VCC's own
|
||||
// current orch90.cpp ("called every scan line 262 Lines * 60
|
||||
// Frames = 15780 Hz 15720"), PakProcessHorizontalSync really does
|
||||
// fire at the classic ~15720Hz CoCo scanline rate, so tell SscCore
|
||||
// to interpret each Tick() call accordingly.
|
||||
gSsc.SetTickRateHz(15720.0);
|
||||
|
||||
ComputeRomDir();
|
||||
gRomsOk = LoadRoms();
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakReset()
|
||||
{
|
||||
gSsc.Reset();
|
||||
if (gAssertCartLine) gAssertCartLine(gSlotId, gRomsOk ? 1 : 0);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakWritePort(unsigned char Port, unsigned char Data)
|
||||
{
|
||||
gSsc.WritePort(Port, Data);
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned char PakReadPort(unsigned char Port)
|
||||
{
|
||||
return gSsc.ReadPort(Port);
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned char PakReadMemoryByte(unsigned short /*Address*/)
|
||||
{
|
||||
// The real S/SC has no cartridge ROM of its own (its only ROMs
|
||||
// are the PIC7040's internal program memory and the SP0256's
|
||||
// mask ROM, neither of which is CPU-addressable from the CoCo
|
||||
// side) -- see the service manual excerpt in README.md.
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakProcessHorizontalSync()
|
||||
{
|
||||
// Called once per scanline (~15720Hz on NTSC), matching the
|
||||
// same cadence orch90.cpp documents for PakSampleAudio(). This
|
||||
// is where we advance the PIC7040/AY/SP0256 emulation and latch
|
||||
// the next output sample.
|
||||
gSsc.Tick();
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned short PakSampleAudio()
|
||||
{
|
||||
unsigned char s = gSsc.LatchedSample();
|
||||
return (static_cast<unsigned short>(s) << 8) | s; // mono -> both channels
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakGetStatus(char* text_buffer, size_t buffer_size)
|
||||
{
|
||||
if (!gRomsOk) {
|
||||
std::snprintf(text_buffer, buffer_size, "S/SC: ROMs MISSING (see README.md)");
|
||||
return;
|
||||
}
|
||||
// Live diagnostics -- reopen VCC's cartridge menu (or whatever
|
||||
// shows this status string) while a program is driving the SSC
|
||||
// to see whether the firmware is actually receiving I/O:
|
||||
// pc = TMS7040 program counter (should move around within
|
||||
// $F000-$FFFF; if it's frozen at one address for a
|
||||
// long time, or leaves that range, something's wrong)
|
||||
// ay/ald = cumulative counts of AY register writes and SP0256
|
||||
// allophone-load strobes since reset (both should
|
||||
// keep climbing while a test program is actively
|
||||
// using sound/speech; if they're stuck at whatever
|
||||
// they were after the boot-time AY init, the host
|
||||
// program's writes to $FF7D/$FF7E aren't reaching
|
||||
// the firmware, or the firmware isn't acting on them)
|
||||
// illeg = illegal-opcode fetch count (should always be 0;
|
||||
// nonzero means the CPU core has derailed)
|
||||
// busy = current $FF7E busy handshake state
|
||||
std::snprintf(text_buffer, buffer_size,
|
||||
"S/SC: PC=$%04X cmd=%u spk=%u ALD=%u illeg=%u busy=%s",
|
||||
gSsc.CpuPc(), gSsc.CommandCount(), gSsc.AldSpeechCount(), gSsc.AldCount(),
|
||||
gSsc.CpuIllegalCount(), gSsc.Busy() ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
if (fdwReason == DLL_PROCESS_ATTACH)
|
||||
gModuleInstance = hinstDLL;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
// ssc_dll_legacy.cpp
|
||||
//
|
||||
// VCC cartridge DLL adapter targeting the CLASSIC (pre-refactor) VCC pak
|
||||
// ABI used by VCC releases up through at least 2.1.9.1 (Dec 2024) --
|
||||
// this is a DIFFERENT, older interface than the "Pak*"-named cpak ABI
|
||||
// in ssc_dll.cpp (which targets the newer VCCE/VCC GitHub main-branch
|
||||
// libcommon refactor). Use THIS file if your VCC's own orch90.dll
|
||||
// exports ModuleName/PackPortRead/PackPortWrite/ModuleReset/SetCart/
|
||||
// PakMemRead8/ModuleAudioSample (check with a PE export viewer, or
|
||||
// just try this build if ssc_dll.cpp's build gives you a "Not a valid
|
||||
// Module" error or silently won't show as inserted in an MPI slot).
|
||||
//
|
||||
// Confirmed against VCCE/VCC tag vcc-2.1.9.1 (pakinterface.c / mpi.cpp
|
||||
// at that tag): the loader requires the DLL to export "ModuleName" --
|
||||
// GetProcAddress(handle, "ModuleName") == NULL is the exact condition
|
||||
// that produces the literal MessageBox "Not a valid Module". Every
|
||||
// other export below is optional (bound if present, harmless if not),
|
||||
// but all are implemented here for a fully-featured cartridge:
|
||||
//
|
||||
// ModuleName(ModName, CatNumber, MenuCallback) -- REQUIRED. Called
|
||||
// once at insert time to populate the cartridge menu label.
|
||||
// PackPortWrite(Port, Data) / PackPortRead(Port) -- host I/O ports,
|
||||
// broadcast to every MPI slot on every access (not SCS-gated in
|
||||
// this VCC generation), matching $FF7D/$FF7E exactly like the
|
||||
// new-ABI build.
|
||||
// ModuleReset(void) -- called once right after insert (and again on
|
||||
// any VCC reset). This is where ROM loading + chip reset happens
|
||||
// (there's no separate "Initialize" call in this ABI generation).
|
||||
// SetCart(HostCallback) -- called once by the host right after insert
|
||||
// to hand the DLL a callback for asserting the cartridge line;
|
||||
// we store it and invoke it from ModuleReset() once ROMs load.
|
||||
// PakMemRead8(Address) -- CPU-side ROM byte read; always 0xFF, same
|
||||
// reasoning as the new-ABI build (S/SC has no CoCo-addressable
|
||||
// ROM of its own).
|
||||
// ModuleAudioSample(void) -- called once per AUDIO SAMPLE, at a real,
|
||||
// wall-clock-accurate 44100Hz (confirmed directly against VCC's
|
||||
// own source for this exact tag: audio.cpp's AudioOut()/
|
||||
// GetDACSample() pulls PackAudioSample() -> this export every
|
||||
// SoundInterupt = NANOSECOND/44100 nanoseconds, with no batching
|
||||
// or resampling in between -- NOT the ~15720Hz video scanline
|
||||
// rate an earlier version of this file assumed). This is ALSO
|
||||
// where we advance the emulated PIC7040/AY/SP0256 by one tick
|
||||
// (there's no separate horizontal-sync callback in this ABI --
|
||||
// real orch90.dll from this era does the same thing: all of its
|
||||
// periodic work happens inside this one function).
|
||||
// ModuleStatus(StatusLine) -- fills a 256-byte buffer (SystemState::
|
||||
// StatusLine in this VCC generation) with the same live PC/AY/ALD/
|
||||
// busy diagnostics as the new-ABI build's PakGetStatus.
|
||||
//
|
||||
// Everything else (ROM loading, chip cores, SscCore glue) is shared
|
||||
// unchanged with ssc_dll.cpp via ssc_core.h -- this file differs from
|
||||
// it only in which Windows-facing export names/signatures it presents.
|
||||
|
||||
#include <windows.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "../../../src/devices/ssc/ssc_core.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using DynamicMenuCallback = void (*)(char*, int, int);
|
||||
using SetCartCallback = void (*)(unsigned char);
|
||||
|
||||
HINSTANCE gModuleInstance = nullptr;
|
||||
SetCartCallback gHostSetCart = nullptr;
|
||||
ssc::SscCore gSsc;
|
||||
bool gRomsOk = false;
|
||||
char gRomDir[MAX_PATH] = "";
|
||||
|
||||
// Directory containing this DLL (not the host EXE's CWD).
|
||||
void ComputeRomDir()
|
||||
{
|
||||
char path[MAX_PATH] = "";
|
||||
GetModuleFileNameA(gModuleInstance, path, MAX_PATH);
|
||||
|
||||
char* slash = strrchr(path, '\\');
|
||||
if (!slash) slash = strrchr(path, '/');
|
||||
if (slash) {
|
||||
*(slash + 1) = '\0';
|
||||
std::snprintf(gRomDir, sizeof(gRomDir), "%s", path);
|
||||
} else {
|
||||
gRomDir[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
bool ReadWholeFile(const char* filename, uint8_t* buf, size_t expected_len)
|
||||
{
|
||||
char full[MAX_PATH * 2];
|
||||
std::snprintf(full, sizeof(full), "%s%s", gRomDir, filename);
|
||||
|
||||
FILE* f = std::fopen(full, "rb");
|
||||
if (!f) return false;
|
||||
|
||||
size_t got = std::fread(buf, 1, expected_len, f);
|
||||
std::fclose(f);
|
||||
return got == expected_len;
|
||||
}
|
||||
|
||||
bool LoadRoms()
|
||||
{
|
||||
static uint8_t pic_rom[4096];
|
||||
static uint8_t spo_rom[0x800];
|
||||
|
||||
bool pic_ok = ReadWholeFile("pic-7040-510.bin", pic_rom, sizeof(pic_rom));
|
||||
bool spo_ok = ReadWholeFile("sp0256-al2.bin", spo_rom, sizeof(spo_rom));
|
||||
|
||||
if (pic_ok) gSsc.LoadPicRom(pic_rom, sizeof(pic_rom));
|
||||
if (spo_ok) gSsc.LoadSpeechRom(spo_rom, sizeof(spo_rom));
|
||||
|
||||
return pic_ok && spo_ok;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C"
|
||||
{
|
||||
__declspec(dllexport) void ModuleName(char* ModName, char* CatNumber, DynamicMenuCallback /*Temp*/)
|
||||
{
|
||||
// MAX_LOADSTRING in this VCC generation is 100 -- both strings
|
||||
// below are well under that.
|
||||
std::strcpy(ModName, "Tandy Speech/Sound Cartridge");
|
||||
std::strcpy(CatNumber, "26-3144");
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PackPortWrite(unsigned char Port, unsigned char Data)
|
||||
{
|
||||
gSsc.WritePort(Port, Data);
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned char PackPortRead(unsigned char Port)
|
||||
{
|
||||
return gSsc.ReadPort(Port);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void ModuleReset(void)
|
||||
{
|
||||
ComputeRomDir();
|
||||
gRomsOk = LoadRoms();
|
||||
gSsc.Reset();
|
||||
if (gHostSetCart) gHostSetCart(gRomsOk ? 1 : 0);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void SetCart(SetCartCallback Pointer)
|
||||
{
|
||||
gHostSetCart = Pointer;
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned char PakMemRead8(unsigned short /*Address*/)
|
||||
{
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned short ModuleAudioSample(void)
|
||||
{
|
||||
// No separate heartbeat export in this ABI generation -- advance
|
||||
// the emulated chips once per call, same as real orch90.dll does
|
||||
// in its own ModuleAudioSample for this same VCC generation.
|
||||
gSsc.Tick();
|
||||
unsigned char s = gSsc.LatchedSample();
|
||||
return (static_cast<unsigned short>(s) << 8) | s; // mono -> both channels
|
||||
}
|
||||
|
||||
__declspec(dllexport) void ModuleStatus(char* StatusLine)
|
||||
{
|
||||
// StatusLine points at SystemState::StatusLine, a 256-byte
|
||||
// buffer in this VCC generation.
|
||||
if (!gRomsOk) {
|
||||
std::snprintf(StatusLine, 256, "S/SC: ROMs MISSING (see README.md)");
|
||||
return;
|
||||
}
|
||||
std::snprintf(StatusLine, 256,
|
||||
"S/SC: PC=$%04X cmd=%u spk=%u ALD=%u illeg=%u busy=%s",
|
||||
gSsc.CpuPc(), gSsc.CommandCount(), gSsc.AldSpeechCount(), gSsc.AldCount(),
|
||||
gSsc.CpuIllegalCount(), gSsc.Busy() ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
if (fdwReason == DLL_PROCESS_ATTACH)
|
||||
gModuleInstance = hinstDLL;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
// ssc_dll_universal.cpp
|
||||
//
|
||||
// A single SSC.DLL that exports BOTH VCC pak ABI generations at once,
|
||||
// so one file works whichever loader the host VCC build actually has:
|
||||
//
|
||||
// - the classic/legacy ABI (ModuleName, PackPortRead, PackPortWrite,
|
||||
// ModuleReset, SetCart, PakMemRead8, ModuleAudioSample, ModuleStatus)
|
||||
// used by VCC's own pakinterface.c through at least tag vcc-2.1.9.2,
|
||||
// - the newer "cpak" ABI (PakInitialize, PakGetName, PakGetCatalogId,
|
||||
// PakGetDescription, PakReset, PakWritePort, PakReadPort,
|
||||
// PakReadMemoryByte, PakProcessHorizontalSync, PakSampleAudio,
|
||||
// PakGetStatus) used by VCC's libcommon/cartridge_loader.cpp
|
||||
// starting at tag vcc-2.1.9.3.
|
||||
//
|
||||
// This works safely because of how each VCC generation actually probes
|
||||
// a cartridge DLL (confirmed directly against VCC's own source for both
|
||||
// generations, not guessed):
|
||||
//
|
||||
// - pakinterface.c (<= 2.1.9.2) does GetProcAddress(handle,
|
||||
// "ModuleName"); if that's present it uses ONLY the legacy-named
|
||||
// exports above and never looks for anything named "Pak*".
|
||||
// - libcommon/src/bus/cartridge_loader.cpp (>= 2.1.9.3) does
|
||||
// GetProcAddress(handle, "PakInitialize"); if that's present it
|
||||
// uses ONLY the cpak-named exports above and never looks for
|
||||
// "ModuleName" et al.
|
||||
//
|
||||
// Neither loader is confused by the *other* ABI's exports also being
|
||||
// present in the same DLL -- they only ever look up the handful of
|
||||
// names they know about. The two export name sets don't collide (one
|
||||
// side is "ModuleName"/"PackPort*"/etc., the other is all "Pak*" but
|
||||
// with different names -- e.g. PakMemRead8 vs PakReadMemoryByte), so
|
||||
// there's nothing to resolve at build time either. This file is just
|
||||
// ssc_dll.cpp and ssc_dll_legacy.cpp's exports combined into one
|
||||
// translation unit, sharing one SscCore instance and one DllMain
|
||||
// (each of those files has its own copy of both, which is what a
|
||||
// naive concatenation would collide on).
|
||||
//
|
||||
// Whichever entry point the host actually calls first (PakInitialize
|
||||
// vs ModuleReset) is the one that ends up computing the ROM directory
|
||||
// and setting SscCore's tick rate -- see the comment on SetTickRateHz
|
||||
// below. Since only one loader generation is ever driving a given
|
||||
// process, the other entry point is simply never called, so sharing
|
||||
// state between the two ABIs is safe.
|
||||
|
||||
#include <windows.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include <vcc/bus/cpak_cartridge_definitions.h>
|
||||
|
||||
#include "../../../src/devices/ssc/ssc_core.h"
|
||||
|
||||
namespace {
|
||||
|
||||
using DynamicMenuCallback = void (*)(char*, int, int);
|
||||
using SetCartCallback = void (*)(unsigned char);
|
||||
|
||||
HINSTANCE gModuleInstance = nullptr;
|
||||
ssc::SscCore gSsc;
|
||||
bool gRomsOk = false;
|
||||
char gRomDir[MAX_PATH] = "";
|
||||
|
||||
// cpak-ABI-specific state
|
||||
slot_id_type gSlotId {};
|
||||
PakAssertCartridgeLineHostCallback gAssertCartLine = nullptr;
|
||||
|
||||
// legacy-ABI-specific state
|
||||
SetCartCallback gHostSetCart = nullptr;
|
||||
|
||||
// Directory containing this DLL (not the host EXE's CWD).
|
||||
void ComputeRomDir()
|
||||
{
|
||||
char path[MAX_PATH] = "";
|
||||
GetModuleFileNameA(gModuleInstance, path, MAX_PATH);
|
||||
|
||||
char* slash = strrchr(path, '\\');
|
||||
if (!slash) slash = strrchr(path, '/');
|
||||
if (slash) {
|
||||
*(slash + 1) = '\0';
|
||||
std::snprintf(gRomDir, sizeof(gRomDir), "%s", path);
|
||||
} else {
|
||||
gRomDir[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
bool ReadWholeFile(const char* filename, uint8_t* buf, size_t expected_len)
|
||||
{
|
||||
char full[MAX_PATH * 2];
|
||||
std::snprintf(full, sizeof(full), "%s%s", gRomDir, filename);
|
||||
|
||||
FILE* f = std::fopen(full, "rb");
|
||||
if (!f) return false;
|
||||
|
||||
size_t got = std::fread(buf, 1, expected_len, f);
|
||||
std::fclose(f);
|
||||
return got == expected_len;
|
||||
}
|
||||
|
||||
bool LoadRoms()
|
||||
{
|
||||
static uint8_t pic_rom[4096];
|
||||
static uint8_t spo_rom[0x800];
|
||||
|
||||
bool pic_ok = ReadWholeFile("pic-7040-510.bin", pic_rom, sizeof(pic_rom));
|
||||
bool spo_ok = ReadWholeFile("sp0256-al2.bin", spo_rom, sizeof(spo_rom));
|
||||
|
||||
if (pic_ok) gSsc.LoadPicRom(pic_rom, sizeof(pic_rom));
|
||||
if (spo_ok) gSsc.LoadSpeechRom(spo_rom, sizeof(spo_rom));
|
||||
|
||||
return pic_ok && spo_ok;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
extern "C"
|
||||
{
|
||||
// ---------------------------------------------------------------
|
||||
// cpak ABI (VCC >= vcc-2.1.9.3) -- required export: PakInitialize
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
__declspec(dllexport) const char* PakGetName()
|
||||
{
|
||||
return "Tandy Speech/Sound Cartridge";
|
||||
}
|
||||
|
||||
__declspec(dllexport) const char* PakGetCatalogId()
|
||||
{
|
||||
return "26-3144";
|
||||
}
|
||||
|
||||
__declspec(dllexport) const char* PakGetDescription()
|
||||
{
|
||||
return gRomsOk
|
||||
? "Tandy Speech/Sound Cartridge (SSC): PIC7040 + AY-3-8913 + SP0256-AL2 emulation"
|
||||
: "Tandy Speech/Sound Cartridge (SSC): ROMs not found -- see README.md";
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakInitialize(
|
||||
slot_id_type SlotId,
|
||||
const char* const /*configuration_path*/,
|
||||
HWND /*hVccWnd*/,
|
||||
const cpak_callbacks* const callbacks)
|
||||
{
|
||||
gSlotId = SlotId;
|
||||
gAssertCartLine = callbacks->assert_cartridge_line;
|
||||
|
||||
// PakProcessHorizontalSync fires at the real ~15720Hz CoCo
|
||||
// scanline rate in this ABI generation (confirmed against
|
||||
// VCC's own orch90.cpp) -- a different cadence than the
|
||||
// classic ABI's ModuleAudioSample (44100Hz, SscCore's
|
||||
// default, set below under "legacy ABI").
|
||||
gSsc.SetTickRateHz(15720.0);
|
||||
|
||||
ComputeRomDir();
|
||||
gRomsOk = LoadRoms();
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakReset()
|
||||
{
|
||||
gSsc.Reset();
|
||||
if (gAssertCartLine) gAssertCartLine(gSlotId, gRomsOk ? 1 : 0);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakWritePort(unsigned char Port, unsigned char Data)
|
||||
{
|
||||
gSsc.WritePort(Port, Data);
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned char PakReadPort(unsigned char Port)
|
||||
{
|
||||
return gSsc.ReadPort(Port);
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned char PakReadMemoryByte(unsigned short /*Address*/)
|
||||
{
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakProcessHorizontalSync()
|
||||
{
|
||||
gSsc.Tick();
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned short PakSampleAudio()
|
||||
{
|
||||
unsigned char s = gSsc.LatchedSample();
|
||||
return (static_cast<unsigned short>(s) << 8) | s;
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PakGetStatus(char* text_buffer, size_t buffer_size)
|
||||
{
|
||||
if (!gRomsOk) {
|
||||
std::snprintf(text_buffer, buffer_size, "S/SC: ROMs MISSING (see README.md)");
|
||||
return;
|
||||
}
|
||||
std::snprintf(text_buffer, buffer_size,
|
||||
"S/SC: PC=$%04X cmd=%u spk=%u ALD=%u illeg=%u busy=%s",
|
||||
gSsc.CpuPc(), gSsc.CommandCount(), gSsc.AldSpeechCount(), gSsc.AldCount(),
|
||||
gSsc.CpuIllegalCount(), gSsc.Busy() ? "1" : "0");
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
// legacy ABI (VCC <= vcc-2.1.9.2) -- required export: ModuleName
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
__declspec(dllexport) void ModuleName(char* ModName, char* CatNumber, DynamicMenuCallback /*Temp*/)
|
||||
{
|
||||
std::strcpy(ModName, "Tandy Speech/Sound Cartridge");
|
||||
std::strcpy(CatNumber, "26-3144");
|
||||
}
|
||||
|
||||
__declspec(dllexport) void PackPortWrite(unsigned char Port, unsigned char Data)
|
||||
{
|
||||
gSsc.WritePort(Port, Data);
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned char PackPortRead(unsigned char Port)
|
||||
{
|
||||
return gSsc.ReadPort(Port);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void ModuleReset(void)
|
||||
{
|
||||
ComputeRomDir();
|
||||
gRomsOk = LoadRoms();
|
||||
gSsc.Reset();
|
||||
if (gHostSetCart) gHostSetCart(gRomsOk ? 1 : 0);
|
||||
}
|
||||
|
||||
__declspec(dllexport) void SetCart(SetCartCallback Pointer)
|
||||
{
|
||||
gHostSetCart = Pointer;
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned char PakMemRead8(unsigned short /*Address*/)
|
||||
{
|
||||
return 0xff;
|
||||
}
|
||||
|
||||
__declspec(dllexport) unsigned short ModuleAudioSample(void)
|
||||
{
|
||||
// No separate heartbeat export in this ABI generation --
|
||||
// SscCore's default tick rate (44100Hz) is correct here and is
|
||||
// never overridden (contrast PakInitialize above, which sets
|
||||
// 15720Hz for the *other* ABI's different callback cadence).
|
||||
gSsc.Tick();
|
||||
unsigned char s = gSsc.LatchedSample();
|
||||
return (static_cast<unsigned short>(s) << 8) | s;
|
||||
}
|
||||
|
||||
__declspec(dllexport) void ModuleStatus(char* StatusLine)
|
||||
{
|
||||
if (!gRomsOk) {
|
||||
std::snprintf(StatusLine, 256, "S/SC: ROMs MISSING (see README.md)");
|
||||
return;
|
||||
}
|
||||
std::snprintf(StatusLine, 256,
|
||||
"S/SC: PC=$%04X cmd=%u spk=%u ALD=%u illeg=%u busy=%s",
|
||||
gSsc.CpuPc(), gSsc.CommandCount(), gSsc.AldSpeechCount(), gSsc.AldCount(),
|
||||
gSsc.CpuIllegalCount(), gSsc.Busy() ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID /*lpReserved*/)
|
||||
{
|
||||
if (fdwReason == DLL_PROCESS_ATTACH)
|
||||
gModuleInstance = hinstDLL;
|
||||
return TRUE;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
*.cpp text eol=lf
|
||||
*.sh text eol=lf
|
||||
Binary file not shown.
@@ -0,0 +1,184 @@
|
||||
// real_rom_test.cpp
|
||||
//
|
||||
// Validation harness that runs the ACTUAL S/SC ROM dumps (pic-7040-510.bin,
|
||||
// sp0256-al2.bin) through the full SscCore glue layer -- as opposed to the
|
||||
// other smoke_*.cpp tests, which only exercise the cores with synthetic
|
||||
// (non-real) data to check for crashes/hangs. This is the strongest check
|
||||
// possible without a real CoCo/VCC: does the *real* TMS7040 firmware boot
|
||||
// on this CPU core and drive the AY/SP0256 the way coco_ssc.cpp's wiring
|
||||
// expects, with no illegal-opcode fetches (which would mean the CPU core
|
||||
// has a decode bug or has run off into data)?
|
||||
//
|
||||
// Usage: real_rom_test <pic-7040-510.bin> <sp0256-al2.bin>
|
||||
//
|
||||
// Not part of run_tests.sh, since it requires ROM files this project
|
||||
// cannot ship. Exits nonzero and prints a diagnosis on any anomaly.
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
#include "../../../../src/devices/ssc/ssc_core.h"
|
||||
|
||||
namespace {
|
||||
|
||||
std::vector<uint8_t> ReadFile(const char* path)
|
||||
{
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
if (!f) { std::fprintf(stderr, "error: can't open %s\n", path); std::exit(2); }
|
||||
return std::vector<uint8_t>(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>());
|
||||
}
|
||||
|
||||
void RunScanlines(ssc::SscCore& core, int n, std::vector<uint8_t>* samples = nullptr)
|
||||
{
|
||||
for (int i = 0; i < n; i++) {
|
||||
core.Tick();
|
||||
if (samples) samples->push_back(core.LatchedSample());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 3) {
|
||||
std::fprintf(stderr, "usage: %s <pic-7040-510.bin> <sp0256-al2.bin>\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
|
||||
auto pic_rom = ReadFile(argv[1]);
|
||||
auto spo_rom = ReadFile(argv[2]);
|
||||
std::printf("pic ROM: %zu bytes, speech ROM: %zu bytes\n", pic_rom.size(), spo_rom.size());
|
||||
|
||||
int failures = 0;
|
||||
|
||||
ssc::SscCore core;
|
||||
bool pic_ok = core.LoadPicRom(pic_rom.data(), pic_rom.size());
|
||||
bool spo_ok = core.LoadSpeechRom(spo_rom.data(), spo_rom.size());
|
||||
std::printf("LoadPicRom -> %s, LoadSpeechRom -> %s\n", pic_ok ? "ok" : "WRONG SIZE", spo_ok ? "ok" : "WRONG SIZE");
|
||||
if (!pic_ok || !spo_ok) { std::printf("FAIL: ROM size mismatch\n"); return 1; }
|
||||
|
||||
core.Reset();
|
||||
|
||||
// ---- 1. Real host reset sequence -----------------------------------
|
||||
// Mirrors what a CoCo driver does on $FF7D: strobe bit0 low then high
|
||||
// (see ssc_core.cpp WritePort's 0x7d case -- the falling edge resets
|
||||
// the TMS7040+AY, the rising edge resets the SP0256).
|
||||
core.WritePort(0x7d, 0x00);
|
||||
core.WritePort(0x7d, 0x01);
|
||||
|
||||
// ---- 2. Let the firmware run its power-on init for ~0.5s of scanlines ----
|
||||
// Real firmware should: initialize its stack/RAM, program the AY to a
|
||||
// known state, and settle into an idle/poll loop waiting for a command
|
||||
// -- all without ever fetching an undefined opcode.
|
||||
const double kTickHz = core.TickRateHz(); // real Hz one Tick() call represents (44100 by default)
|
||||
const int kSettleScanlines = int(kTickHz * 0.5); // ~0.5s worth of Tick() calls
|
||||
RunScanlines(core, kSettleScanlines);
|
||||
|
||||
std::printf("\nAfter %d scanlines of boot/idle:\n", kSettleScanlines);
|
||||
std::printf(" CPU PC = $%04X\n", core.CpuPc());
|
||||
std::printf(" illegal-opcode fetches = %u\n", core.CpuIllegalCount());
|
||||
std::printf(" AY register writes so far = %u\n", core.AyWriteCount());
|
||||
std::printf(" ALD (speech) strobes so far = %u\n", core.AldCount());
|
||||
std::printf(" busy flag = %s\n", core.Busy() ? "true" : "false");
|
||||
|
||||
if (core.CpuIllegalCount() > 0) {
|
||||
std::printf(" FAIL: illegal opcodes were fetched -- CPU core has run off firmware code.\n");
|
||||
failures++;
|
||||
}
|
||||
if (core.CpuPc() < 0xF000) {
|
||||
std::printf(" FAIL: PC is outside the internal ROM ($F000-$FFFF) -- firmware jumped to unmapped/RAM space.\n");
|
||||
failures++;
|
||||
}
|
||||
if (core.AyWriteCount() == 0) {
|
||||
std::printf(" FAIL: firmware never wrote to the AY-3-8913 during its init sequence (expected -- real S/SC firmware programs the AY at boot).\n");
|
||||
failures++;
|
||||
}
|
||||
if (!failures) std::printf(" OK: firmware appears to have booted and initialized the AY cleanly.\n");
|
||||
|
||||
// ---- 3. Send a command byte and see if the firmware responds -------
|
||||
// We don't have the documented command protocol on hand, so this
|
||||
// isn't a claim that command 0x00 does anything specific -- it's a
|
||||
// check that sending *a* command byte doesn't crash the CPU core and
|
||||
// that the busy handshake (host write -> INT3 -> firmware services it
|
||||
// -> BSY release) moves at all, which only happens if real code path
|
||||
// in the firmware's INT3 handler runs.
|
||||
uint32_t pre_illegal = core.CpuIllegalCount();
|
||||
core.WritePort(0x7e, 0x00);
|
||||
std::printf("\nAfter sending command byte 0x00 to $FF7E, busy=%s\n", core.Busy() ? "true" : "false");
|
||||
RunScanlines(core, kSettleScanlines);
|
||||
std::printf("After %d more scanlines:\n", kSettleScanlines);
|
||||
std::printf(" CPU PC = $%04X\n", core.CpuPc());
|
||||
std::printf(" illegal-opcode fetches (delta) = %u\n", core.CpuIllegalCount() - pre_illegal);
|
||||
std::printf(" busy flag = %s\n", core.Busy() ? "true" : "false");
|
||||
std::printf(" AY register writes (total) = %u\n", core.AyWriteCount());
|
||||
std::printf(" ALD (speech) strobes (total) = %u\n", core.AldCount());
|
||||
|
||||
if (core.CpuIllegalCount() > pre_illegal) {
|
||||
std::printf(" FAIL: command byte triggered illegal opcode fetches.\n");
|
||||
failures++;
|
||||
}
|
||||
if (core.Busy()) {
|
||||
std::printf(" NOTE: still busy after %.2fs -- either this command byte blocks waiting for more\n", kSettleScanlines / kTickHz);
|
||||
std::printf(" data (plausible -- many real commands are multi-byte), or the firmware is stuck.\n");
|
||||
std::printf(" Not counted as a failure by itself; see PC below for a stuck-loop check.\n");
|
||||
} else {
|
||||
std::printf(" OK: busy handshake completed -- firmware serviced the command and released BSY.\n");
|
||||
}
|
||||
|
||||
// ---- 4. Render a longer stretch to WAV for manual/spectral inspection ----
|
||||
std::vector<uint8_t> samples;
|
||||
core.WritePort(0x7d, 0x00);
|
||||
core.WritePort(0x7d, 0x01); // fresh reset
|
||||
RunScanlines(core, int(kTickHz * 2), &samples); // 2 seconds, capturing every sample
|
||||
|
||||
// basic amplitude stats
|
||||
int minv = 255, maxv = 0;
|
||||
double sum = 0, sumsq = 0;
|
||||
for (uint8_t s : samples) {
|
||||
minv = std::min(minv, int(s));
|
||||
maxv = std::max(maxv, int(s));
|
||||
sum += s;
|
||||
sumsq += double(s) * s;
|
||||
}
|
||||
double mean = sum / samples.size();
|
||||
double var = sumsq / samples.size() - mean * mean;
|
||||
std::printf("\n2-second post-reset audio capture (%zu samples):\n", samples.size());
|
||||
std::printf(" min=%d max=%d mean=%.1f stddev=%.2f\n", minv, maxv, mean, std::sqrt(std::max(0.0, var)));
|
||||
if (minv == maxv) {
|
||||
std::printf(" NOTE: dead flat output -- silence is plausible for an idle cartridge (matches real hardware:\n");
|
||||
std::printf(" it's silent until told to speak/play), not necessarily a bug.\n");
|
||||
}
|
||||
|
||||
// Write a WAV so a human can actually listen to it.
|
||||
{
|
||||
std::ofstream wav("real_rom_capture.wav", std::ios::binary);
|
||||
uint32_t sr = uint32_t(kTickHz), data_bytes = uint32_t(samples.size());
|
||||
uint32_t riff_size = 36 + data_bytes;
|
||||
uint16_t channels = 1, bits = 8;
|
||||
uint32_t byte_rate = sr * channels * bits / 8;
|
||||
uint16_t block_align = channels * bits / 8;
|
||||
wav.write("RIFF", 4);
|
||||
wav.write(reinterpret_cast<char*>(&riff_size), 4);
|
||||
wav.write("WAVE", 4);
|
||||
wav.write("fmt ", 4);
|
||||
uint32_t fmt_size = 16; wav.write(reinterpret_cast<char*>(&fmt_size), 4);
|
||||
uint16_t fmt_tag = 1; wav.write(reinterpret_cast<char*>(&fmt_tag), 2);
|
||||
wav.write(reinterpret_cast<char*>(&channels), 2);
|
||||
wav.write(reinterpret_cast<char*>(&sr), 4);
|
||||
wav.write(reinterpret_cast<char*>(&byte_rate), 4);
|
||||
wav.write(reinterpret_cast<char*>(&block_align), 2);
|
||||
wav.write(reinterpret_cast<char*>(&bits), 2);
|
||||
wav.write("data", 4);
|
||||
wav.write(reinterpret_cast<char*>(&data_bytes), 4);
|
||||
wav.write(reinterpret_cast<const char*>(samples.data()), std::streamsize(samples.size()));
|
||||
std::printf(" wrote real_rom_capture.wav (%u bytes payload)\n", data_bytes);
|
||||
}
|
||||
|
||||
std::printf("\n%s (%d failure(s))\n", failures ? "FAIL" : "PASS", failures);
|
||||
return failures ? 1 : 0;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,131 @@
|
||||
// real_sp0256_speech_test.cpp
|
||||
//
|
||||
// Focused validation of the SP0256 core against the REAL sp0256-al2.bin
|
||||
// ROM, feeding it actual non-pause allophone codes directly (bypassing
|
||||
// the TMS7040 firmware entirely) to check whether the core can produce
|
||||
// non-silent audio at all. This isolates the SP0256 chip-level emulation
|
||||
// from the still-unknown TMS7040 firmware command protocol -- if this
|
||||
// test shows real audio for ordinary allophones, the SP0256 core itself
|
||||
// is not the problem, and whatever's silencing the real cartridge in
|
||||
// VCC is either the AY/SP0256 mix downstream or something specific to
|
||||
// how the real firmware drives ALD in its speech routine.
|
||||
//
|
||||
// Usage: real_sp0256_speech_test <sp0256-al2.bin>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
|
||||
#include "../../../../src/devices/ssc/sp0256.h"
|
||||
|
||||
namespace {
|
||||
std::vector<uint8_t> ReadFile(const char* path)
|
||||
{
|
||||
std::ifstream f(path, std::ios::binary);
|
||||
if (!f) { std::fprintf(stderr, "error: can't open %s\n", path); std::exit(2); }
|
||||
return std::vector<uint8_t>(std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>());
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
std::fprintf(stderr, "usage: %s <sp0256-al2.bin>\n", argv[0]);
|
||||
return 2;
|
||||
}
|
||||
auto rom = ReadFile(argv[1]);
|
||||
std::printf("speech ROM: %zu bytes\n", rom.size());
|
||||
|
||||
ssc::Sp0256 spo;
|
||||
spo.LoadRom(rom.data(), rom.size());
|
||||
spo.Reset();
|
||||
|
||||
// SP0256-AL2 standard allophone table: 0 = PA1 (pause, legitimately
|
||||
// silent), 1-63 are real phonemes (/AA/, /IY/, /EY/, /S/, etc.). We
|
||||
// drive codes 1 through 20 back-to-back -- a representative sample,
|
||||
// not the full 63 -- and measure whether real audio energy comes out
|
||||
// for each one.
|
||||
std::vector<int16_t> all_samples;
|
||||
int failures = 0;
|
||||
int16_t global_min = 0, global_max = 0;
|
||||
|
||||
const int kNumCodes = 63;
|
||||
for (int code = 1; code <= kNumCodes; code++) {
|
||||
if (!spo.Standby()) {
|
||||
// shouldn't happen between codes, but drain just in case
|
||||
for (int i = 0; i < 20000 && !spo.Standby(); i++) {
|
||||
int16_t s;
|
||||
spo.GenerateSamples(&s, 1);
|
||||
}
|
||||
}
|
||||
spo.Ald(uint8_t(code));
|
||||
|
||||
std::vector<int16_t> samples;
|
||||
samples.reserve(20000);
|
||||
int guard = 0;
|
||||
while (!spo.Standby() && guard < 30000) {
|
||||
int16_t s;
|
||||
spo.GenerateSamples(&s, 1);
|
||||
samples.push_back(s);
|
||||
guard++;
|
||||
}
|
||||
|
||||
int16_t minv = 0, maxv = 0;
|
||||
double sumsq = 0;
|
||||
for (int16_t s : samples) {
|
||||
minv = std::min(minv, s);
|
||||
maxv = std::max(maxv, s);
|
||||
sumsq += double(s) * s;
|
||||
}
|
||||
double rms = samples.empty() ? 0.0 : std::sqrt(sumsq / samples.size());
|
||||
|
||||
std::printf("allophone %2d: %5zu samples, min=%6d max=%6d rms=%8.1f %s\n",
|
||||
code, samples.size(), minv, maxv, rms,
|
||||
rms > 50.0 ? "OK (audible)" : "SILENT/near-silent");
|
||||
|
||||
if (rms <= 50.0) failures++;
|
||||
global_min = std::min(global_min, minv);
|
||||
global_max = std::max(global_max, maxv);
|
||||
|
||||
all_samples.insert(all_samples.end(), samples.begin(), samples.end());
|
||||
}
|
||||
|
||||
std::printf("\nGLOBAL peak across all %d allophones: min=%d max=%d (int16 full scale is +/-32767)\n",
|
||||
kNumCodes, global_min, global_max);
|
||||
|
||||
// Write a WAV of the whole run (10kHz mono, matching the SP0256's
|
||||
// native sample rate at the SSC's 3.12MHz clock) so it can actually
|
||||
// be listened to.
|
||||
{
|
||||
std::ofstream wav("real_sp0256_speech.wav", std::ios::binary);
|
||||
uint32_t sr = 10000, data_bytes = uint32_t(all_samples.size() * 2);
|
||||
uint32_t riff_size = 36 + data_bytes;
|
||||
uint16_t channels = 1, bits = 16;
|
||||
uint32_t byte_rate = sr * channels * bits / 8;
|
||||
uint16_t block_align = channels * bits / 8;
|
||||
wav.write("RIFF", 4);
|
||||
wav.write(reinterpret_cast<char*>(&riff_size), 4);
|
||||
wav.write("WAVE", 4);
|
||||
wav.write("fmt ", 4);
|
||||
uint32_t fmt_size = 16; wav.write(reinterpret_cast<char*>(&fmt_size), 4);
|
||||
uint16_t fmt_tag = 1; wav.write(reinterpret_cast<char*>(&fmt_tag), 2);
|
||||
wav.write(reinterpret_cast<char*>(&channels), 2);
|
||||
wav.write(reinterpret_cast<char*>(&sr), 4);
|
||||
wav.write(reinterpret_cast<char*>(&byte_rate), 4);
|
||||
wav.write(reinterpret_cast<char*>(&block_align), 2);
|
||||
wav.write(reinterpret_cast<char*>(&bits), 2);
|
||||
wav.write("data", 4);
|
||||
wav.write(reinterpret_cast<char*>(&data_bytes), 4);
|
||||
wav.write(reinterpret_cast<const char*>(all_samples.data()), std::streamsize(data_bytes));
|
||||
std::printf("\nwrote real_sp0256_speech.wav (%u bytes payload, %d allophones concatenated)\n",
|
||||
data_bytes, kNumCodes);
|
||||
}
|
||||
|
||||
std::printf("\n%s (%d of %d allophones came out silent/near-silent)\n",
|
||||
failures == 0 ? "PASS" : (failures < kNumCodes ? "PARTIAL" : "FAIL"), failures, kNumCodes);
|
||||
return failures == kNumCodes ? 1 : 0;
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
# Builds and runs the standalone unit tests for the portable chip cores
|
||||
# (no VCC or Windows needed -- these are plain C++17). Run from anywhere;
|
||||
# the script cd's to its own directory first.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
CXX=${CXX:-g++}
|
||||
FLAGS="-std=c++17 -Wall -Wextra -O2"
|
||||
|
||||
echo "== TMS7000 core =="
|
||||
$CXX $FLAGS -o /tmp/ssc_test_cpu smoke_cpu.cpp ../tms7000.cpp
|
||||
/tmp/ssc_test_cpu
|
||||
|
||||
echo
|
||||
echo "== SP0256 speech core =="
|
||||
$CXX $FLAGS -o /tmp/ssc_test_sp0256 smoke_sp0256.cpp ../sp0256.cpp
|
||||
/tmp/ssc_test_sp0256
|
||||
|
||||
echo
|
||||
echo "== AY-3-8913 PSG core =="
|
||||
$CXX $FLAGS -o /tmp/ssc_test_ay8913 smoke_ay8913.cpp ../ay8913.cpp
|
||||
/tmp/ssc_test_ay8913
|
||||
|
||||
echo
|
||||
echo "== Full SSC glue (ports, timing, mixing) =="
|
||||
$CXX $FLAGS -o /tmp/ssc_test_core smoke_ssc_core.cpp ../ssc_core.cpp ../tms7000.cpp ../sp0256.cpp ../ay8913.cpp
|
||||
/tmp/ssc_test_core
|
||||
|
||||
echo
|
||||
echo "All tests passed."
|
||||
echo
|
||||
echo "Optional: to also validate against the REAL S/SC ROM dumps (not"
|
||||
echo "included here -- see README.md), build and run:"
|
||||
echo " g++ -std=c++17 -O2 -o /tmp/real_rom_test real_rom_test.cpp ../ssc_core.cpp ../tms7000.cpp ../sp0256.cpp ../ay8913.cpp"
|
||||
echo " /tmp/real_rom_test <path-to-pic-7040-510.bin> <path-to-sp0256-al2.bin>"
|
||||
echo " g++ -std=c++17 -O2 -o /tmp/real_sp0256_speech_test real_sp0256_speech_test.cpp ../sp0256.cpp"
|
||||
echo " /tmp/real_sp0256_speech_test <path-to-sp0256-al2.bin>"
|
||||
echo "real_rom_capture.wav and real_sp0256_speech.wav in this folder are"
|
||||
echo "captured output from prior runs of those two, kept as reference."
|
||||
Reference in new issue
Block a user