Skip to content

Commit

Permalink
4.4.0.0 Added RPC server feture. Your application can be integrated w…
Browse files Browse the repository at this point in the history
…ith the MAmidiMEmo. See the manual for details.
  • Loading branch information
110-kenichi committed Nov 7, 2022
1 parent 48faba3 commit 19c8f53
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MAmidiMEmo 4.3.10.1 Itoken (c)2019, 2020, 2021, 2022 / GPL-2.0
MAmidiMEmo 4.4.0.0 Itoken (c)2019, 2020, 2021, 2022 / GPL-2.0

*** What is the MAmidiMEmo? ***

Expand Down Expand Up @@ -268,6 +268,7 @@ e.g.) YM2151 has 8ch FM sounds, so you can play 8 chords on MIDI 1ch or sharing
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SNQ9JE3JAQMNQ)

*** Changes ***
4.4.0.0 Added RPC server feture. Your application can be integrated with the MAmidiMEmo. See the manual for details.
4.3.10.1 Added "FILT.Auto" property value for SID chips.
4.3.9.0 Added MIDI Delay Test tool. You can open the tool from [Tool] menu.
4.3.8.2 Improved MONO mode for playing legato.
Expand Down
Binary file modified docs/MAmidiMEmo/Manual.pdf
Binary file not shown.
Binary file modified docs/MAmidiMEmo/Manual.pptx
Binary file not shown.
24 changes: 20 additions & 4 deletions src/emu/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ void LoadData(unsigned char* data, int length);
int SaveData(void** saveBuf);
void SendMidiEvent(unsigned char data1, unsigned char data2, unsigned char data3);
void SendMidiSysEvent(unsigned char* data, int length);
void DirectAccessToChip(unsigned char device_id, unsigned char unit, unsigned int address, unsigned int data);

void running_machine::mami_timer_callback(void* ptr, s32 param)
{
Expand All @@ -320,11 +321,11 @@ void running_machine::mami_timer_callback(void* ptr, s32 param)

void SetVSTiMode();

rpc::client* m_rpcClient;
rpc::server* m_rpcSrv;
rpc::client* m_rpcClient = NULL;
rpc::server* m_rpcSrv = NULL;

CHAR* m_cpSharedMemory;
HANDLE m_hSharedMemory;
CHAR* m_cpSharedMemory = NULL;
HANDLE m_hSharedMemory = NULL;

bool createSharedMemory(int m_mami_sample_rate, USHORT m_vstPort)
{
Expand Down Expand Up @@ -542,6 +543,11 @@ int running_machine::run(bool quiet)
SendMidiSysEvent(&buffer[0], length);
});

m_rpcSrv->bind("DirectAccessToChip", [&](unsigned char device_id, unsigned char unit, unsigned int address, unsigned int data)
{
DirectAccessToChip(device_id, unit, address, data);
});

m_rpcSrv->async_run();

m_rpcClient->call("MAmiMainStarted");
Expand All @@ -555,6 +561,16 @@ int running_machine::run(bool quiet)
dynamic_cast<device_sound_interface*>(this->device((std::string("rspeaker")).c_str()));
sdr->set_stream_update_callback(StreamUpdatedR);
}
else {
m_rpcSrv = new rpc::server(30000);

m_rpcSrv->bind("DirectAccessToChip", [&](unsigned char device_id, unsigned char unit, unsigned int address, unsigned int data)
{
DirectAccessToChip(device_id, unit, address, data);
});

m_rpcSrv->async_run();
}

// run the CPUs until a reset or exit
while ((!m_hard_reset_pending && !m_exit_pending) || m_saveload_schedule != saveload_schedule::NONE)
Expand Down
12 changes: 11 additions & 1 deletion src/emu/mamidimemo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef int(CALLBACK* CloseApplicationProc)();
typedef void(CALLBACK* LoadDataProc)(unsigned char* data, int length);
typedef int(CALLBACK* SaveDataProc)(void** saveBuf);
typedef void(CALLBACK* SoundTimerCallbackProc)();
typedef void(CALLBACK* DirectAccessToChipProc)(unsigned char device_id, unsigned char index, unsigned int address, unsigned int data);

InitializeDotNetProc initializeDotNet = 0;
HasExitedProc hasExited = 0;
Expand All @@ -35,6 +36,7 @@ CloseApplicationProc closeApplication = 0;
LoadDataProc loadData = 0;
SaveDataProc saveData = 0;
SoundTimerCallbackProc soundTimerCallback = 0;
DirectAccessToChipProc directAccessToChip = 0;

DWORD WINAPI StartMAmidiMEmoMainThread(LPVOID lpParam)
{
Expand Down Expand Up @@ -114,6 +116,9 @@ void StartMAmidiMEmoMain()
proc = GetProcAddress(hModule, "SoundTimerCallback");
if (proc != NULL)
soundTimerCallback = reinterpret_cast<SoundTimerCallbackProc>(proc);
proc = GetProcAddress(hModule, "DirectAccessToChip");
if (proc != NULL)
directAccessToChip = reinterpret_cast<DirectAccessToChipProc>(proc);

// Launch MAmi
proc = GetProcAddress(hModule, "MainWarpper");
Expand Down Expand Up @@ -220,4 +225,9 @@ void SoundTimerCallback()
{
if(soundTimerCallback != 0)
soundTimerCallback();
}
}

void DirectAccessToChip(unsigned char device_id, unsigned char unit, unsigned int address, unsigned int data)
{
directAccessToChip(device_id, unit, address, data);
}
2 changes: 1 addition & 1 deletion src/mamidimemo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class Program
/// <summary>
///
/// </summary>
public const string FILE_VERSION = "4.3.10.1";
public const string FILE_VERSION = "4.4.0.0";

public const string FILE_COPYRIGHT = @"Virtual chiptune sound MIDI module ""MAmidiMEmo"" Version {0}
Copyright(C) 2019, 2022 Itoken.All rights reserved.";
Expand Down
23 changes: 22 additions & 1 deletion src/mamidimemo/instruments/Chips/AY8910.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,27 @@ private static delegate_ay8910_address_data_w ay8910_address_data_w
set;
}

/// <summary>
///
/// </summary>
/// <param name="address"></param>
/// <param name="data"></param>
internal override void DirectAccessToChip(uint address, uint data)
{
if(address < 14)
{
if (address == 7)
data &= 0x3f;
Ay8910WriteData(UnitNumber, (byte)address, (byte)data, !(address == 13));
}
}

/// <summary>
///
/// </summary>
/// <param name="unitNumber"></param>
/// <param name="offset"></param>
/// <param name="data"></param>
private void Ay8910WriteData(uint unitNumber, uint offset, byte data)
{
Ay8910WriteData(unitNumber, offset, data, true);
Expand Down Expand Up @@ -835,7 +856,7 @@ internal override void ProcessAllSoundOff()
var me = new ControlChangeEvent((SevenBitNumber)120, (SevenBitNumber)0);
ProcessControlChange(me);

parentModule.Ay8910WriteData(parentModule.UnitNumber, 7, 0xff);
parentModule.Ay8910WriteData(parentModule.UnitNumber, 7, 0x3f);
}

}
Expand Down
95 changes: 94 additions & 1 deletion src/mamidimemo/instruments/Chips/SCC1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using zanac.MAmidiMEmo.Mame;
using zanac.MAmidiMEmo.Midi;
using zanac.MAmidiMEmo.VSIF;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TaskbarClock;

//http://bifi.msxnet.org/msxnet/tech/scc.html

Expand Down Expand Up @@ -234,7 +235,7 @@ private void enableScc(SCCType type, SCCSlotNo slot, bool clearCache)
vsifClient.WriteData(3, (byte)(type), (byte)slot, f_ftdiClkWidth);
}
}
if(clearCache)
if (clearCache)
ClearWrittenDataCache();
}

Expand Down Expand Up @@ -313,6 +314,98 @@ public override void RestoreFrom(string serializeData)

private static delegate_SCC1_r SCC1_keyonoff_r;

/// <summary>
///
/// </summary>
/// <param name="address"></param>
/// <param name="data"></param>
internal override void DirectAccessToChip(uint address, uint data)
{
byte type = 0;
lock (sndEnginePtrLock)
{
switch (CurrentSoundEngine)
{
case SoundEngineType.VSIF_MSX_FTDI:
switch (SCCChipType)
{
case SCCType.SCC1:
type = 4;
break;
case SCCType.SCC1_Compat:
case SCCType.SCC:
type = 5;
break;
}
break;
}
}
WriteData(address, data, true, new Action(() =>
{
lock (sndEnginePtrLock)
{
if (CurrentSoundEngine == SoundEngineType.VSIF_MSX_FTDI)
{
enableScc(SCCChipType, ExtSCCSlot);
vsifClient.WriteData(type, (byte)(address & 0xff), (byte)data, f_ftdiClkWidth);
}
}
if (address < 0x100)
{
//SCC
if (address < 0x80)
{
// 0x00..0x7F : write wave form 1..4
DeferredWriteData(SCC1_waveform_w, UnitNumber, (uint)address, new sbyte[] { (sbyte)data }, 1);
}
else if (address < 0x8a)
{
// 0x80..0x9F : freq volume block
DeferredWriteData(SCC1_frequency_w, UnitNumber, (uint)(address - 0x80), (byte)data);
}
else if (address < 0x8f)
{
DeferredWriteData(SCC1_volume_w, UnitNumber, (uint)(address - 0x8a), (byte)data);
}
else if (address == 0x8f)
{
DeferredWriteData(SCC1_keyonoff_w, UnitNumber, (uint)0, (byte)data);
}
else
{
// 0xA0..0xDF : no function
// 0xE0..0xFF : deformation register
}
}
else
{
//SCC+
address = address & 0xff;
if (address < 0xa0)
{
DeferredWriteData(SCC1_waveform_w, UnitNumber, (uint)address, new sbyte[] { (sbyte)data }, 1);
}
else if (address < 0xaa)
{
DeferredWriteData(SCC1_frequency_w, UnitNumber, (uint)(address - 0xa0), (byte)data);
}
else if (address < 0xaf)
{
DeferredWriteData(SCC1_volume_w, UnitNumber, (uint)(address - 0xaa), (byte)data);
}
else if (address == 0xaf)
{
DeferredWriteData(SCC1_keyonoff_w, UnitNumber, (uint)0, (byte)data);
}
else
{
// 0xA0..0xDF : no function
// 0xE0..0xFF : deformation register
}
}
}));
}

/// <summary>
///
/// </summary>
Expand Down
12 changes: 11 additions & 1 deletion src/mamidimemo/instruments/Chips/YM2413.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,16 @@ private static delegate_YM2413_read YM2413_read

private static byte[] addressTable = new byte[] { 0x00, 0x01, 0x02, 0x08, 0x09, 0x0a, 0x10, 0x11, 0x12 };

/// <summary>
///
/// </summary>
/// <param name="address"></param>
/// <param name="data"></param>
internal override void DirectAccessToChip(uint address, uint data)
{
YM2413WriteData(UnitNumber, (byte)address, 0, (byte)data, !(0x20 <= address && address <= 0x28));
}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -1439,7 +1449,7 @@ public override void OnPitchUpdated()
byte kon = IsKeyOff ? (byte)0 : (byte)0x10;
lastFreqData = (byte)(timbre.SUS << 5 | kon | octave | ((freq >> 8) & 1));

parentModule.YM2413WriteData(parentModule.UnitNumber, (byte)(0x10 + Slot), 0, (byte)(0xff & freq), false);
parentModule.YM2413WriteData(parentModule.UnitNumber, (byte)(0x10 + Slot), 0, (byte)(0xff & freq));
parentModule.YM2413WriteData(parentModule.UnitNumber, (byte)(0x20 + Slot), 0, lastFreqData, false);
}
break;
Expand Down
9 changes: 9 additions & 0 deletions src/mamidimemo/instruments/InstrumentBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2147,6 +2147,8 @@ protected virtual void Dispose(bool disposing)
// このコードは、破棄可能なパターンを正しく実装できるように追加されました。
public virtual void Dispose()
{
AllSoundOff();

Program.SoundUpdating();

// このコードを変更しないでください。クリーンアップ コードを上の Dispose(bool disposing) に記述します。
Expand Down Expand Up @@ -2235,6 +2237,11 @@ protected void WriteData(uint address, uint data, bool useCache, Action wtiteAct
}
}

internal virtual void DirectAccessToChip(uint address, uint data)
{

}

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -2271,6 +2278,8 @@ void act()
{
foreach (var (d, a) in deferredWriteData)
{
if (Program.HasExited() != 0)
break;
try
{
invokeFunction(d, a);
Expand Down
18 changes: 18 additions & 0 deletions src/mamidimemo/instruments/InstrumentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,5 +1105,23 @@ public static void Reset()
}
}
}

/// <summary>
///
/// </summary>
unsafe public static void DirectAccessToChip(byte device_id, byte unit, uint address, uint data)
{
try
{
InstrumentManager.InstExclusiveLockObject.EnterReadLock();

if(unit < instruments[(int)device_id - 1].Count)
instruments[(int)device_id - 1][unit].DirectAccessToChip(address, data);
}
finally
{
InstrumentManager.InstExclusiveLockObject.ExitReadLock();
}
}
}
}
Binary file modified src/wrapper/wrapper.cpp
Binary file not shown.
1 change: 1 addition & 0 deletions src/wrapper/wrapper.def
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ EXPORTS
SendMidiEvent
LoadData
SaveData
DirectAccessToChip
SoundTimerCallback
MainWarpper @4

0 comments on commit 19c8f53

Please sign in to comment.