diff --git a/.gitmodules b/.gitmodules index 83f383989..5f0e538d1 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,7 +4,6 @@ [submodule "extern/SDL"] path = extern/SDL url = https://github.com/libsdl-org/SDL.git - branch = 2.0.22 [submodule "extern/libsndfile"] path = extern/libsndfile url = https://github.com/libsndfile/libsndfile.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e20b9577..8ade1ede1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -526,6 +526,7 @@ src/engine/platform/zxbeeper.cpp src/engine/platform/bubsyswsg.cpp src/engine/platform/n163.cpp src/engine/platform/pet.cpp +src/engine/platform/pokemini.cpp src/engine/platform/pong.cpp src/engine/platform/vic20.cpp src/engine/platform/vrc6.cpp @@ -534,6 +535,7 @@ src/engine/platform/ymz280b.cpp src/engine/platform/namcowsg.cpp src/engine/platform/rf5c68.cpp src/engine/platform/snes.cpp +src/engine/platform/k007232.cpp src/engine/platform/pcmdac.cpp src/engine/platform/dummy.cpp ) diff --git a/TODO.md b/TODO.md index 89a31eecf..a5f800629 100644 --- a/TODO.md +++ b/TODO.md @@ -2,7 +2,9 @@ - POKEY - Pokémon Mini + - register layout + - confirm emulation - (maybe) YM2612 CSM (no DualPCM) -- port presets to new format +- port op macro code to all other OPN chips - bug fixes - (maybe) advanced linear arpeggio? (run arp+slide simultaneously) diff --git a/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java b/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java index 802c7254e..cf3c9267f 100644 --- a/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java +++ b/android/app/src/main/java/org/libsdl/app/HIDDeviceManager.java @@ -248,7 +248,9 @@ public class HIDDeviceManager { 0x1689, // Razer Onza 0x1949, // Lab126, Inc. 0x1bad, // Harmonix + 0x20d6, // PowerA 0x24c6, // PowerA + 0x2c22, // Qanba }; if (usbInterface.getInterfaceClass() == UsbConstants.USB_CLASS_VENDOR_SPEC && @@ -274,7 +276,9 @@ public class HIDDeviceManager { 0x0e6f, // PDP 0x0f0d, // Hori 0x1532, // Razer Wildcat + 0x20d6, // PowerA 0x24c6, // PowerA + 0x2dc8, /* 8BitDo */ 0x2e24, // Hyperkin }; diff --git a/android/app/src/main/java/org/libsdl/app/SDLActivity.java b/android/app/src/main/java/org/libsdl/app/SDLActivity.java index 3da072091..55b961a47 100644 --- a/android/app/src/main/java/org/libsdl/app/SDLActivity.java +++ b/android/app/src/main/java/org/libsdl/app/SDLActivity.java @@ -27,7 +27,9 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.Message; +import android.text.Editable; import android.text.InputType; +import android.text.Selection; import android.util.DisplayMetrics; import android.util.Log; import android.util.SparseArray; @@ -63,6 +65,112 @@ import java.util.Locale; */ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityChangeListener { private static final String TAG = "SDL"; +/* + // Display InputType.SOURCE/CLASS of events and devices + // + // SDLActivity.debugSource(device.getSources(), "device[" + device.getName() + "]"); + // SDLActivity.debugSource(event.getSource(), "event"); + public static void debugSource(int sources, String prefix) { + int s = sources; + int s_copy = sources; + String cls = ""; + String src = ""; + int tst = 0; + int FLAG_TAINTED = 0x80000000; + + if ((s & InputDevice.SOURCE_CLASS_BUTTON) != 0) cls += " BUTTON"; + if ((s & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) cls += " JOYSTICK"; + if ((s & InputDevice.SOURCE_CLASS_POINTER) != 0) cls += " POINTER"; + if ((s & InputDevice.SOURCE_CLASS_POSITION) != 0) cls += " POSITION"; + if ((s & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) cls += " TRACKBALL"; + + + int s2 = s_copy & ~InputDevice.SOURCE_ANY; // keep class bits + s2 &= ~( InputDevice.SOURCE_CLASS_BUTTON + | InputDevice.SOURCE_CLASS_JOYSTICK + | InputDevice.SOURCE_CLASS_POINTER + | InputDevice.SOURCE_CLASS_POSITION + | InputDevice.SOURCE_CLASS_TRACKBALL); + + if (s2 != 0) cls += "Some_Unkown"; + + s2 = s_copy & InputDevice.SOURCE_ANY; // keep source only, no class; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + tst = InputDevice.SOURCE_BLUETOOTH_STYLUS; + if ((s & tst) == tst) src += " BLUETOOTH_STYLUS"; + s2 &= ~tst; + } + + tst = InputDevice.SOURCE_DPAD; + if ((s & tst) == tst) src += " DPAD"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_GAMEPAD; + if ((s & tst) == tst) src += " GAMEPAD"; + s2 &= ~tst; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + tst = InputDevice.SOURCE_HDMI; + if ((s & tst) == tst) src += " HDMI"; + s2 &= ~tst; + } + + tst = InputDevice.SOURCE_JOYSTICK; + if ((s & tst) == tst) src += " JOYSTICK"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_KEYBOARD; + if ((s & tst) == tst) src += " KEYBOARD"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_MOUSE; + if ((s & tst) == tst) src += " MOUSE"; + s2 &= ~tst; + + if (Build.VERSION.SDK_INT >= 26) { + tst = InputDevice.SOURCE_MOUSE_RELATIVE; + if ((s & tst) == tst) src += " MOUSE_RELATIVE"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_ROTARY_ENCODER; + if ((s & tst) == tst) src += " ROTARY_ENCODER"; + s2 &= ~tst; + } + tst = InputDevice.SOURCE_STYLUS; + if ((s & tst) == tst) src += " STYLUS"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_TOUCHPAD; + if ((s & tst) == tst) src += " TOUCHPAD"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_TOUCHSCREEN; + if ((s & tst) == tst) src += " TOUCHSCREEN"; + s2 &= ~tst; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { + tst = InputDevice.SOURCE_TOUCH_NAVIGATION; + if ((s & tst) == tst) src += " TOUCH_NAVIGATION"; + s2 &= ~tst; + } + + tst = InputDevice.SOURCE_TRACKBALL; + if ((s & tst) == tst) src += " TRACKBALL"; + s2 &= ~tst; + + tst = InputDevice.SOURCE_ANY; + if ((s & tst) == tst) src += " ANY"; + s2 &= ~tst; + + if (s == FLAG_TAINTED) src += " FLAG_TAINTED"; + s2 &= ~FLAG_TAINTED; + + if (s2 != 0) src += " Some_Unkown"; + + Log.v(TAG, prefix + "int=" + s_copy + " CLASS={" + cls + " } source(s):" + src); + } +*/ public static boolean mIsResumedCalled, mHasFocus; public static final boolean mHasMultiWindow = (Build.VERSION.SDK_INT >= 24); @@ -1204,8 +1312,21 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh for (int id : ids) { InputDevice device = InputDevice.getDevice(id); - if (device != null && (device.getSources() & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) { - nativeAddTouch(device.getId(), device.getName()); + /* Allow SOURCE_TOUCHSCREEN and also Virtual InputDevices because they can send TOUCHSCREEN events */ + if (device != null && ((device.getSources() & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN + || device.isVirtual())) { + + int touchDevId = device.getId(); + /* + * Prevent id to be -1, since it's used in SDL internal for synthetic events + * Appears when using Android emulator, eg: + * adb shell input mouse tap 100 100 + * adb shell input touchscreen tap 100 100 + */ + if (touchDevId < 0) { + touchDevId -= 1; + } + nativeAddTouch(touchDevId, device.getName()); } } } @@ -1895,7 +2016,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, } } - if ((source & InputDevice.SOURCE_KEYBOARD) != 0) { + if ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD) { if (event.getAction() == KeyEvent.ACTION_DOWN) { if (SDLActivity.isTextInputEvent(event)) { SDLInputConnection.nativeCommitText(String.valueOf((char) event.getUnicodeChar()), 1); @@ -1908,7 +2029,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback, } } - if ((source & InputDevice.SOURCE_MOUSE) != 0) { + if ((source & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE) { // on some devices key events are sent for mouse BUTTON_BACK/FORWARD presses // they are ignored here because sending them as mouse input to SDL is messy if ((keyCode == KeyEvent.KEYCODE_BACK) || (keyCode == KeyEvent.KEYCODE_FORWARD)) { @@ -2195,7 +2316,7 @@ class DummyEdit extends View implements View.OnKeyListener { public InputConnection onCreateInputConnection(EditorInfo outAttrs) { ic = new SDLInputConnection(this, true); - outAttrs.inputType = InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD; + outAttrs.inputType = InputType.TYPE_CLASS_TEXT; outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN /* API 11 */; @@ -2237,6 +2358,29 @@ class SDLInputConnection extends BaseInputConnection { @Override public boolean commitText(CharSequence text, int newCursorPosition) { + /* Generate backspaces for the text we're going to replace */ + final Editable content = getEditable(); + if (content != null) { + int a = getComposingSpanStart(content); + int b = getComposingSpanEnd(content); + if (a == -1 || b == -1) { + a = Selection.getSelectionStart(content); + b = Selection.getSelectionEnd(content); + } + if (a < 0) a = 0; + if (b < 0) b = 0; + if (b < a) { + int tmp = a; + a = b; + b = tmp; + } + int backspaces = (b - a); + + for (int i = 0; i < backspaces; i++) { + nativeGenerateScancodeForUnichar('\b'); + } + } + for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); if (c == '\n') { @@ -2271,14 +2415,11 @@ class SDLInputConnection extends BaseInputConnection { // Workaround to capture backspace key. Ref: http://stackoverflow.com/questions/14560344/android-backspace-in-webview-baseinputconnection // and https://bugzilla.libsdl.org/show_bug.cgi?id=2265 if (beforeLength > 0 && afterLength == 0) { - boolean ret = true; // backspace(s) while (beforeLength-- > 0) { - boolean ret_key = sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL)) - && sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)); - ret = ret && ret_key; + nativeGenerateScancodeForUnichar('\b'); } - return ret; + return true; } return super.deleteSurroundingText(beforeLength, afterLength); diff --git a/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java b/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java index 1fa32ef39..82373d9d6 100644 --- a/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java +++ b/android/app/src/main/java/org/libsdl/app/SDLControllerManager.java @@ -255,23 +255,21 @@ class SDLJoystickHandler_API16 extends SDLJoystickHandler { @Override public boolean handleMotionEvent(MotionEvent event) { - if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) { - int actionPointerIndex = event.getActionIndex(); - int action = event.getActionMasked(); - if (action == MotionEvent.ACTION_MOVE) { - SDLJoystick joystick = getJoystick(event.getDeviceId()); - if (joystick != null) { - for (int i = 0; i < joystick.axes.size(); i++) { - InputDevice.MotionRange range = joystick.axes.get(i); - /* Normalize the value to -1...1 */ - float value = (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin()) / range.getRange() * 2.0f - 1.0f; - SDLControllerManager.onNativeJoy(joystick.device_id, i, value); - } - for (int i = 0; i < joystick.hats.size() / 2; i++) { - int hatX = Math.round(event.getAxisValue(joystick.hats.get(2 * i).getAxis(), actionPointerIndex)); - int hatY = Math.round(event.getAxisValue(joystick.hats.get(2 * i + 1).getAxis(), actionPointerIndex)); - SDLControllerManager.onNativeHat(joystick.device_id, i, hatX, hatY); - } + int actionPointerIndex = event.getActionIndex(); + int action = event.getActionMasked(); + if (action == MotionEvent.ACTION_MOVE) { + SDLJoystick joystick = getJoystick(event.getDeviceId()); + if (joystick != null) { + for (int i = 0; i < joystick.axes.size(); i++) { + InputDevice.MotionRange range = joystick.axes.get(i); + /* Normalize the value to -1...1 */ + float value = (event.getAxisValue(range.getAxis(), actionPointerIndex) - range.getMin()) / range.getRange() * 2.0f - 1.0f; + SDLControllerManager.onNativeJoy(joystick.device_id, i, value); + } + for (int i = 0; i < joystick.hats.size() / 2; i++) { + int hatX = Math.round(event.getAxisValue(joystick.hats.get(2 * i).getAxis(), actionPointerIndex)); + int hatY = Math.round(event.getAxisValue(joystick.hats.get(2 * i + 1).getAxis(), actionPointerIndex)); + SDLControllerManager.onNativeHat(joystick.device_id, i, hatX, hatY); } } } @@ -562,8 +560,6 @@ class SDLGenericMotionListener_API12 implements View.OnGenericMotionListener { switch ( event.getSource() ) { case InputDevice.SOURCE_JOYSTICK: - case InputDevice.SOURCE_GAMEPAD: - case InputDevice.SOURCE_DPAD: return SDLControllerManager.handleJoystickMotionEvent(event); case InputDevice.SOURCE_MOUSE: @@ -693,8 +689,6 @@ class SDLGenericMotionListener_API26 extends SDLGenericMotionListener_API24 { switch ( event.getSource() ) { case InputDevice.SOURCE_JOYSTICK: - case InputDevice.SOURCE_GAMEPAD: - case InputDevice.SOURCE_DPAD: return SDLControllerManager.handleJoystickMotionEvent(event); case InputDevice.SOURCE_MOUSE: diff --git a/demos/README.md b/demos/README.md index 49d5cb37d..eb2fced30 100644 --- a/demos/README.md +++ b/demos/README.md @@ -12,6 +12,8 @@ contact me or send a pull request if you want your song to be added to this coll - big label music covers also are discouraged - low effort compositions/covers may not be accepted at all. +make sure to put your demo song under the respective category. + tildearrow also accepts demo songs in the .dmf format as well as the .fur format. thank you for contributing! diff --git a/demos/Coconut_Mall.fur b/demos/a2600/Coconut_Mall.fur similarity index 100% rename from demos/Coconut_Mall.fur rename to demos/a2600/Coconut_Mall.fur diff --git a/demos/atari breakbeat.fur b/demos/a2600/atari breakbeat.fur similarity index 100% rename from demos/atari breakbeat.fur rename to demos/a2600/atari breakbeat.fur diff --git a/demos/the_erfngjt.fur b/demos/a2600/the_erfngjt.fur similarity index 100% rename from demos/the_erfngjt.fur rename to demos/a2600/the_erfngjt.fur diff --git a/demos/bruno_time.fur b/demos/amiga/bruno_time.fur similarity index 100% rename from demos/bruno_time.fur rename to demos/amiga/bruno_time.fur diff --git a/demos/m7 vibe.fur b/demos/amiga/m7 vibe.fur similarity index 100% rename from demos/m7 vibe.fur rename to demos/amiga/m7 vibe.fur diff --git a/demos/AY-3-8910_Jam.fur b/demos/ay8910/AY-3-8910_Jam.fur similarity index 100% rename from demos/AY-3-8910_Jam.fur rename to demos/ay8910/AY-3-8910_Jam.fur diff --git a/demos/demoscenetypebeat.fur b/demos/ay8910/demoscenetypebeat.fur similarity index 100% rename from demos/demoscenetypebeat.fur rename to demos/ay8910/demoscenetypebeat.fur diff --git a/demos/Red_Planet.fur b/demos/ay8930/Red_Planet.fur similarity index 100% rename from demos/Red_Planet.fur rename to demos/ay8930/Red_Planet.fur diff --git a/demos/duty fun.fur b/demos/ay8930/duty fun.fur similarity index 100% rename from demos/duty fun.fur rename to demos/ay8930/duty fun.fur diff --git a/demos/C64 junk.fur b/demos/c64/C64 junk.fur similarity index 100% rename from demos/C64 junk.fur rename to demos/c64/C64 junk.fur diff --git a/demos/ChaosTune.fur b/demos/c64/ChaosTune.fur similarity index 100% rename from demos/ChaosTune.fur rename to demos/c64/ChaosTune.fur diff --git a/demos/DOOM_E1M1.fur b/demos/c64/DOOM_E1M1.fur similarity index 100% rename from demos/DOOM_E1M1.fur rename to demos/c64/DOOM_E1M1.fur diff --git a/demos/DOOM_E1M3.fur b/demos/c64/DOOM_E1M3.fur similarity index 100% rename from demos/DOOM_E1M3.fur rename to demos/c64/DOOM_E1M3.fur diff --git a/demos/The_Snippet.fur b/demos/c64/The_Snippet.fur similarity index 100% rename from demos/The_Snippet.fur rename to demos/c64/The_Snippet.fur diff --git a/demos/You're_Doing_Well!_GB.fur b/demos/gameboy/You're_Doing_Well!.fur similarity index 100% rename from demos/You're_Doing_Well!_GB.fur rename to demos/gameboy/You're_Doing_Well!.fur diff --git a/demos/puggs_in_space.fur b/demos/gameboy/puggs_in_space.fur similarity index 100% rename from demos/puggs_in_space.fur rename to demos/gameboy/puggs_in_space.fur diff --git a/demos/snowdin.fur b/demos/gameboy/snowdin.fur old mode 100755 new mode 100644 similarity index 100% rename from demos/snowdin.fur rename to demos/gameboy/snowdin.fur diff --git a/demos/Another_winter.fur b/demos/genesis/Another_winter.fur similarity index 100% rename from demos/Another_winter.fur rename to demos/genesis/Another_winter.fur diff --git a/demos/Carnage.fur b/demos/genesis/Carnage.fur similarity index 100% rename from demos/Carnage.fur rename to demos/genesis/Carnage.fur diff --git a/demos/Checknobankh.fur b/demos/genesis/Checknobankh.fur similarity index 100% rename from demos/Checknobankh.fur rename to demos/genesis/Checknobankh.fur diff --git a/demos/CorridorsOfTimeRMX.fur b/demos/genesis/CorridorsOfTimeRMX.fur similarity index 100% rename from demos/CorridorsOfTimeRMX.fur rename to demos/genesis/CorridorsOfTimeRMX.fur diff --git a/demos/GEN Equinox Intro.fur b/demos/genesis/Equinox Intro.fur similarity index 100% rename from demos/GEN Equinox Intro.fur rename to demos/genesis/Equinox Intro.fur diff --git a/demos/Solar_Man_Genesis.fur b/demos/genesis/Solar_Man.fur similarity index 100% rename from demos/Solar_Man_Genesis.fur rename to demos/genesis/Solar_Man.fur diff --git a/demos/Stereotactics_Rewritten.fur b/demos/genesis/Stereotactics_Rewritten.fur similarity index 100% rename from demos/Stereotactics_Rewritten.fur rename to demos/genesis/Stereotactics_Rewritten.fur diff --git a/demos/Swaggin_Dragon.dmf b/demos/genesis/Swaggin_Dragon.dmf similarity index 100% rename from demos/Swaggin_Dragon.dmf rename to demos/genesis/Swaggin_Dragon.dmf diff --git a/demos/darkstar.dmf b/demos/genesis/darkstar.dmf similarity index 100% rename from demos/darkstar.dmf rename to demos/genesis/darkstar.dmf diff --git a/demos/the_serenity_of_lonliness.fur b/demos/genesis/the_serenity_of_lonliness.fur similarity index 100% rename from demos/the_serenity_of_lonliness.fur rename to demos/genesis/the_serenity_of_lonliness.fur diff --git a/demos/yky.fur b/demos/genesis/yky.fur similarity index 100% rename from demos/yky.fur rename to demos/genesis/yky.fur diff --git a/demos/LedStorm.fur b/demos/lynx/LedStorm.fur similarity index 100% rename from demos/LedStorm.fur rename to demos/lynx/LedStorm.fur diff --git a/demos/Road_Rash_Grass_Valley_Lynx_01d.fur b/demos/lynx/Road_Rash_Grass_Valley.fur similarity index 100% rename from demos/Road_Rash_Grass_Valley_Lynx_01d.fur rename to demos/lynx/Road_Rash_Grass_Valley.fur diff --git a/demos/Tyrian-Camanis.fur b/demos/lynx/Tyrian-Camanis.fur similarity index 100% rename from demos/Tyrian-Camanis.fur rename to demos/lynx/Tyrian-Camanis.fur diff --git a/demos/chippylotus.fur b/demos/lynx/chippylotus.fur similarity index 100% rename from demos/chippylotus.fur rename to demos/lynx/chippylotus.fur diff --git a/demos/insert_title_lynx.fur b/demos/lynx/insert_title_here.fur similarity index 100% rename from demos/insert_title_lynx.fur rename to demos/lynx/insert_title_here.fur diff --git a/demos/misc/Dreamliner_FMTowns.fur b/demos/misc/Dreamliner_FMTowns.fur new file mode 100644 index 000000000..d7120416c Binary files /dev/null and b/demos/misc/Dreamliner_FMTowns.fur differ diff --git a/demos/Eternal_Forest_Taito_Arcade.fur b/demos/misc/Eternal_Forest_Taito_Arcade.fur similarity index 100% rename from demos/Eternal_Forest_Taito_Arcade.fur rename to demos/misc/Eternal_Forest_Taito_Arcade.fur diff --git a/demos/Neo_Seaside_Volley_Court.fur b/demos/misc/Neo_Seaside_Volley_Court_NeoGeo.fur similarity index 100% rename from demos/Neo_Seaside_Volley_Court.fur rename to demos/misc/Neo_Seaside_Volley_Court_NeoGeo.fur diff --git a/demos/UT99_Run_Taito_Arcade.fur b/demos/misc/UT99_Run_Taito_Arcade.fur similarity index 100% rename from demos/UT99_Run_Taito_Arcade.fur rename to demos/misc/UT99_Run_Taito_Arcade.fur diff --git a/demos/Utter Determination YM2610B.fur b/demos/misc/Utter Determination YM2610B.fur similarity index 100% rename from demos/Utter Determination YM2610B.fur rename to demos/misc/Utter Determination YM2610B.fur diff --git a/demos/beeper_torture.fur b/demos/misc/beeper_torture.fur similarity index 100% rename from demos/beeper_torture.fur rename to demos/misc/beeper_torture.fur diff --git a/demos/fursuits_for_the_suspiciously_rich.fur b/demos/misc/fursuits_for_the_suspiciously_rich_MSM5232.fur similarity index 100% rename from demos/fursuits_for_the_suspiciously_rich.fur rename to demos/misc/fursuits_for_the_suspiciously_rich_MSM5232.fur diff --git a/demos/hope_for_the_dream.fur b/demos/misc/hope_for_the_dream_opm.fur similarity index 100% rename from demos/hope_for_the_dream.fur rename to demos/misc/hope_for_the_dream_opm.fur diff --git a/demos/massive_x_opz.fur b/demos/misc/massive_x_opz.fur similarity index 100% rename from demos/massive_x_opz.fur rename to demos/misc/massive_x_opz.fur diff --git a/demos/pseudogba_pwaa_godot.fur b/demos/misc/pseudogba_pwaa_godot.fur similarity index 100% rename from demos/pseudogba_pwaa_godot.fur rename to demos/misc/pseudogba_pwaa_godot.fur diff --git a/demos/rule2.fur b/demos/misc/rule2_zx.fur similarity index 100% rename from demos/rule2.fur rename to demos/misc/rule2_zx.fur diff --git a/demos/the_king_of_crisp.fur b/demos/misc/the_king_of_crisp_opm.fur similarity index 100% rename from demos/the_king_of_crisp.fur rename to demos/misc/the_king_of_crisp_opm.fur diff --git a/demos/L’ambreSong.fur b/demos/msx/Il_ambreSong.fur similarity index 100% rename from demos/L’ambreSong.fur rename to demos/msx/Il_ambreSong.fur diff --git a/demos/Lagrange_Point.fur b/demos/msx/Lagrange_Point.fur similarity index 100% rename from demos/Lagrange_Point.fur rename to demos/msx/Lagrange_Point.fur diff --git a/demos/Princess_of_the_Dead.fur b/demos/msx/Princess_of_the_Dead.fur similarity index 100% rename from demos/Princess_of_the_Dead.fur rename to demos/msx/Princess_of_the_Dead.fur diff --git a/demos/opll-fashioned_drums.fur b/demos/msx/opll-fashioned_drums.fur similarity index 100% rename from demos/opll-fashioned_drums.fur rename to demos/msx/opll-fashioned_drums.fur diff --git a/demos/AgentX.fur b/demos/multichip/AgentX.fur similarity index 100% rename from demos/AgentX.fur rename to demos/multichip/AgentX.fur diff --git a/demos/BONUS. Sonic 2 Boss.fur b/demos/multichip/BONUS. Sonic 2 Boss.fur similarity index 100% rename from demos/BONUS. Sonic 2 Boss.fur rename to demos/multichip/BONUS. Sonic 2 Boss.fur diff --git a/demos/Between_the_Circuits.fur b/demos/multichip/Between_the_Circuits.fur similarity index 100% rename from demos/Between_the_Circuits.fur rename to demos/multichip/Between_the_Circuits.fur diff --git a/demos/ComicPartytrack20.fur b/demos/multichip/ComicPartytrack20.fur similarity index 100% rename from demos/ComicPartytrack20.fur rename to demos/multichip/ComicPartytrack20.fur diff --git a/demos/Fiorella YM2610B+YM2203.fur b/demos/multichip/Fiorella YM2610B+YM2203.fur similarity index 100% rename from demos/Fiorella YM2610B+YM2203.fur rename to demos/multichip/Fiorella YM2610B+YM2203.fur diff --git a/demos/Fusion.fur b/demos/multichip/Fusion.fur similarity index 100% rename from demos/Fusion.fur rename to demos/multichip/Fusion.fur diff --git a/demos/HoldOn.fur b/demos/multichip/HoldOn.fur similarity index 100% rename from demos/HoldOn.fur rename to demos/multichip/HoldOn.fur diff --git a/demos/Ice_Wind_OPMSPCM.fur b/demos/multichip/Ice_Wind_OPMSPCM.fur similarity index 100% rename from demos/Ice_Wind_OPMSPCM.fur rename to demos/multichip/Ice_Wind_OPMSPCM.fur diff --git a/demos/Jet_Pack_Adventure_GBAesque.fur b/demos/multichip/Jet_Pack_Adventure_GBAesque.fur similarity index 100% rename from demos/Jet_Pack_Adventure_GBAesque.fur rename to demos/multichip/Jet_Pack_Adventure_GBAesque.fur diff --git a/demos/MetalSlug_BaseCamp_SMS_TIA.fur b/demos/multichip/MetalSlug_BaseCamp_SMS_TIA.fur similarity index 100% rename from demos/MetalSlug_BaseCamp_SMS_TIA.fur rename to demos/multichip/MetalSlug_BaseCamp_SMS_TIA.fur diff --git a/demos/The_Good_Times_Arcade.fur b/demos/multichip/The_Good_Times_Arcade.fur similarity index 100% rename from demos/The_Good_Times_Arcade.fur rename to demos/multichip/The_Good_Times_Arcade.fur diff --git a/demos/Tubelectric_Fictional_Arcade.fur b/demos/multichip/Tubelectric_Fictional_Arcade.fur similarity index 100% rename from demos/Tubelectric_Fictional_Arcade.fur rename to demos/multichip/Tubelectric_Fictional_Arcade.fur diff --git a/demos/cueball.fur b/demos/multichip/cueball.fur similarity index 100% rename from demos/cueball.fur rename to demos/multichip/cueball.fur diff --git a/demos/double-dragon-stage1.fur b/demos/multichip/double-dragon-stage1.fur similarity index 100% rename from demos/double-dragon-stage1.fur rename to demos/multichip/double-dragon-stage1.fur diff --git a/demos/government funding breakcore-ish remix.fur b/demos/multichip/government funding breakcore-ish remix.fur similarity index 100% rename from demos/government funding breakcore-ish remix.fur rename to demos/multichip/government funding breakcore-ish remix.fur diff --git a/demos/iji_tor.fur b/demos/multichip/iji_tor.fur similarity index 100% rename from demos/iji_tor.fur rename to demos/multichip/iji_tor.fur diff --git a/demos/meteor_shower.fur b/demos/multichip/meteor_shower.fur similarity index 100% rename from demos/meteor_shower.fur rename to demos/multichip/meteor_shower.fur diff --git a/demos/genesis thing.fur b/demos/multichip/not genesis thing.fur similarity index 100% rename from demos/genesis thing.fur rename to demos/multichip/not genesis thing.fur diff --git a/demos/overdrive.fur b/demos/multichip/overdrive.fur similarity index 100% rename from demos/overdrive.fur rename to demos/multichip/overdrive.fur diff --git a/demos/ridiculous_game.fur b/demos/multichip/ridiculous_game.fur similarity index 100% rename from demos/ridiculous_game.fur rename to demos/multichip/ridiculous_game.fur diff --git a/demos/silverlining.fur b/demos/multichip/silverlining.fur similarity index 100% rename from demos/silverlining.fur rename to demos/multichip/silverlining.fur diff --git a/demos/skate_or_die.fur b/demos/multichip/skate_or_die.fur similarity index 100% rename from demos/skate_or_die.fur rename to demos/multichip/skate_or_die.fur diff --git a/demos/splashingwater.fur b/demos/multichip/splashingwater.fur similarity index 100% rename from demos/splashingwater.fur rename to demos/multichip/splashingwater.fur diff --git a/demos/super_fantasy_zone_mango.fur b/demos/multichip/super_fantasy_zone_mango.fur similarity index 100% rename from demos/super_fantasy_zone_mango.fur rename to demos/multichip/super_fantasy_zone_mango.fur diff --git a/demos/the_machines_are_socialising.fur b/demos/multichip/the_machines_are_socialising.fur similarity index 100% rename from demos/the_machines_are_socialising.fur rename to demos/multichip/the_machines_are_socialising.fur diff --git a/demos/Mars_Bar_On_Mars.fur b/demos/namco/Mars_Bar_On_Mars.fur similarity index 100% rename from demos/Mars_Bar_On_Mars.fur rename to demos/namco/Mars_Bar_On_Mars.fur diff --git a/demos/Phoenix_cover.fur b/demos/namco/Phoenix_cover.fur similarity index 100% rename from demos/Phoenix_cover.fur rename to demos/namco/Phoenix_cover.fur diff --git a/demos/ice-cap-nc30.fur b/demos/namco/ice-cap-nc30.fur similarity index 100% rename from demos/ice-cap-nc30.fur rename to demos/namco/ice-cap-nc30.fur diff --git a/demos/FDS TEST.fur b/demos/nes/FDS TEST.fur similarity index 100% rename from demos/FDS TEST.fur rename to demos/nes/FDS TEST.fur diff --git a/demos/Rise_against_the_ashes_to_the_new_dawn.fur b/demos/nes/Rise_against_the_ashes_to_the_new_dawn.fur similarity index 100% rename from demos/Rise_against_the_ashes_to_the_new_dawn.fur rename to demos/nes/Rise_against_the_ashes_to_the_new_dawn.fur diff --git a/demos/Samsung SGH-x830 - Ringtone 8.fur b/demos/nes/Samsung SGH-x830 - Ringtone 8.fur similarity index 100% rename from demos/Samsung SGH-x830 - Ringtone 8.fur rename to demos/nes/Samsung SGH-x830 - Ringtone 8.fur diff --git a/demos/The Cheetahmen.fur b/demos/nes/The Cheetahmen.fur similarity index 100% rename from demos/The Cheetahmen.fur rename to demos/nes/The Cheetahmen.fur diff --git a/demos/carve_your_own_path.fur b/demos/nes/carve_your_own_path.fur similarity index 100% rename from demos/carve_your_own_path.fur rename to demos/nes/carve_your_own_path.fur diff --git a/demos/going_up_a_step_at_time.fur b/demos/nes/going_up_a_step_at_time.fur similarity index 100% rename from demos/going_up_a_step_at_time.fur rename to demos/nes/going_up_a_step_at_time.fur diff --git a/demos/oby1_ingame.fur b/demos/nes/oby1_ingame.fur similarity index 100% rename from demos/oby1_ingame.fur rename to demos/nes/oby1_ingame.fur diff --git a/demos/spamton.fur b/demos/nes/spamton.fur similarity index 100% rename from demos/spamton.fur rename to demos/nes/spamton.fur diff --git a/demos/Contraduct Design OPL3 Cover.fur b/demos/opl/Contraduct Design OPL3 Cover.fur similarity index 100% rename from demos/Contraduct Design OPL3 Cover.fur rename to demos/opl/Contraduct Design OPL3 Cover.fur diff --git a/demos/E1M4OPL2.fur b/demos/opl/E1M4OPL2.fur similarity index 100% rename from demos/E1M4OPL2.fur rename to demos/opl/E1M4OPL2.fur diff --git a/demos/Egyptian_Rule.fur b/demos/opl/Egyptian_Rule.fur similarity index 100% rename from demos/Egyptian_Rule.fur rename to demos/opl/Egyptian_Rule.fur diff --git a/demos/Funky_Bubbles_OPL3.fur b/demos/opl/Funky_Bubbles_OPL3.fur similarity index 100% rename from demos/Funky_Bubbles_OPL3.fur rename to demos/opl/Funky_Bubbles_OPL3.fur diff --git a/demos/Midnight_Dog_Orchestra.fur b/demos/opl/Midnight_Dog_Orchestra.fur similarity index 100% rename from demos/Midnight_Dog_Orchestra.fur rename to demos/opl/Midnight_Dog_Orchestra.fur diff --git a/demos/Moon.fur b/demos/opl/Moon.fur similarity index 100% rename from demos/Moon.fur rename to demos/opl/Moon.fur diff --git a/demos/OPL3_SegaPCM_Xeno_Crisis_-_Facility_Area_2.fur b/demos/opl/OPL3_SegaPCM_Xeno_Crisis_-_Facility_Area_2.fur similarity index 100% rename from demos/OPL3_SegaPCM_Xeno_Crisis_-_Facility_Area_2.fur rename to demos/opl/OPL3_SegaPCM_Xeno_Crisis_-_Facility_Area_2.fur diff --git a/demos/Oh no, more sine waves.fur b/demos/opl/Oh no, more sine waves.fur similarity index 100% rename from demos/Oh no, more sine waves.fur rename to demos/opl/Oh no, more sine waves.fur diff --git a/demos/Waterworld_-_Map.fur b/demos/opl/Waterworld_-_Map.fur similarity index 100% rename from demos/Waterworld_-_Map.fur rename to demos/opl/Waterworld_-_Map.fur diff --git a/demos/fight and flight.fur b/demos/opl/fight and flight.fur similarity index 100% rename from demos/fight and flight.fur rename to demos/opl/fight and flight.fur diff --git a/demos/green_biker_dude_opl.fur b/demos/opl/green_biker_dude_opl.fur similarity index 100% rename from demos/green_biker_dude_opl.fur rename to demos/opl/green_biker_dude_opl.fur diff --git a/demos/home_wfl_opl3.fur b/demos/opl/home_wfl_opl3.fur similarity index 100% rename from demos/home_wfl_opl3.fur rename to demos/opl/home_wfl_opl3.fur diff --git a/demos/MMXStageClear.fur b/demos/pc98/MMXStageClear.fur similarity index 100% rename from demos/MMXStageClear.fur rename to demos/pc98/MMXStageClear.fur diff --git a/demos/Fake Gameboy.fur b/demos/pce/Fake Gameboy.fur similarity index 100% rename from demos/Fake Gameboy.fur rename to demos/pce/Fake Gameboy.fur diff --git a/demos/pce/Ma-Da-Ra.fur b/demos/pce/Ma-Da-Ra.fur new file mode 100644 index 000000000..98139ed76 Binary files /dev/null and b/demos/pce/Ma-Da-Ra.fur differ diff --git a/demos/doorintosummer.fur b/demos/sms/doorintosummer.fur similarity index 100% rename from demos/doorintosummer.fur rename to demos/sms/doorintosummer.fur diff --git a/demos/snes/MM8_Frost_Man.fur b/demos/snes/MM8_Frost_Man.fur new file mode 100644 index 000000000..bad1ceeef Binary files /dev/null and b/demos/snes/MM8_Frost_Man.fur differ diff --git a/demos/very chill snes.fur b/demos/snes/very chill snes.fur similarity index 100% rename from demos/very chill snes.fur rename to demos/snes/very chill snes.fur diff --git a/demos/Silver Surfer - Stage Music 1.fur b/demos/specs2/Silver Surfer - Stage Music 1.fur similarity index 100% rename from demos/Silver Surfer - Stage Music 1.fur rename to demos/specs2/Silver Surfer - Stage Music 1.fur diff --git a/demos/atmosphere.fur b/demos/specs2/atmosphere.fur similarity index 100% rename from demos/atmosphere.fur rename to demos/specs2/atmosphere.fur diff --git a/demos/su_memory.fur b/demos/specs2/su_memory.fur similarity index 100% rename from demos/su_memory.fur rename to demos/specs2/su_memory.fur diff --git a/demos/thick bass test.fur b/demos/specs2/thick bass test.fur similarity index 100% rename from demos/thick bass test.fur rename to demos/specs2/thick bass test.fur diff --git a/demos/vaportrail_staffroll.fur b/demos/specs2/vaportrail_staffroll.fur similarity index 100% rename from demos/vaportrail_staffroll.fur rename to demos/specs2/vaportrail_staffroll.fur diff --git a/demos/Rave_Dancetune_VSU-VUE.fur b/demos/virtualboy/Rave_Dancetune.fur similarity index 100% rename from demos/Rave_Dancetune_VSU-VUE.fur rename to demos/virtualboy/Rave_Dancetune.fur diff --git a/demos/SeeingRed.fur b/demos/virtualboy/SeeingRed.fur similarity index 100% rename from demos/SeeingRed.fur rename to demos/virtualboy/SeeingRed.fur diff --git a/demos/Bullet_Hell.fur b/demos/wonderswan/Bullet_Hell.fur similarity index 100% rename from demos/Bullet_Hell.fur rename to demos/wonderswan/Bullet_Hell.fur diff --git a/demos/Rusty_-_Queen_in_the_Dark_Night.fur b/demos/wonderswan/Rusty_-_Queen_in_the_Dark_Night.fur similarity index 100% rename from demos/Rusty_-_Queen_in_the_Dark_Night.fur rename to demos/wonderswan/Rusty_-_Queen_in_the_Dark_Night.fur diff --git a/demos/TimeTrial.fur b/demos/wonderswan/TimeTrial.fur similarity index 100% rename from demos/TimeTrial.fur rename to demos/wonderswan/TimeTrial.fur diff --git a/demos/sijofsjfsoeife.fur b/demos/wonderswan/sijofsjfsoeife.fur similarity index 100% rename from demos/sijofsjfsoeife.fur rename to demos/wonderswan/sijofsjfsoeife.fur diff --git a/demos/Cafe - 010 Editor 2.0crk.fur b/demos/x16/Cafe - 010 Editor 2.0crk.fur similarity index 100% rename from demos/Cafe - 010 Editor 2.0crk.fur rename to demos/x16/Cafe - 010 Editor 2.0crk.fur diff --git a/demos/Identity_Believer_VERA.fur b/demos/x16/Identity_Believer.fur similarity index 100% rename from demos/Identity_Believer_VERA.fur rename to demos/x16/Identity_Believer.fur diff --git a/demos/her11_veraedit.fur b/demos/x16/her11.fur similarity index 100% rename from demos/her11_veraedit.fur rename to demos/x16/her11.fur diff --git a/demos/lunacommdemo.fur b/demos/x16/lunacommdemo.fur similarity index 100% rename from demos/lunacommdemo.fur rename to demos/x16/lunacommdemo.fur diff --git a/demos/watching_paint_dry.fur b/demos/x16/watching_paint_dry.fur similarity index 100% rename from demos/watching_paint_dry.fur rename to demos/x16/watching_paint_dry.fur diff --git a/extern/SDL b/extern/SDL index f8e14ad25..55b03c749 160000 --- a/extern/SDL +++ b/extern/SDL @@ -1 +1 @@ -Subproject commit f8e14ad25aa6f0b4bbed411583a9863c855ad9e6 +Subproject commit 55b03c7493a7abed33cf803d1380a40fa8af903f diff --git a/extern/opm/opm.c b/extern/opm/opm.c index aafce483d..d2878f541 100644 --- a/extern/opm/opm.c +++ b/extern/opm/opm.c @@ -1892,9 +1892,9 @@ void OPM_Clock(opm_t *chip, int32_t *output, uint8_t *sh1, uint8_t *sh2, uint8_t OPM_PhaseCalcIncrement(chip); OPM_PhaseCalcFNumBlock(chip); - /*OPM_DoTimerIRQ(chip); + OPM_DoTimerIRQ(chip); OPM_DoTimerA(chip); - OPM_DoTimerB(chip);*/ + OPM_DoTimerB(chip); OPM_DoLFOMult(chip); OPM_DoLFO1(chip); OPM_Noise(chip); @@ -1904,10 +1904,10 @@ void OPM_Clock(opm_t *chip, int32_t *output, uint8_t *sh1, uint8_t *sh2, uint8_t OPM_NoiseTimer(chip); OPM_KeyOn1(chip); OPM_DoIO(chip); - /*OPM_DoTimerA2(chip); - OPM_DoTimerB2(chip);*/ + OPM_DoTimerA2(chip); + OPM_DoTimerB2(chip); OPM_DoLFO2(chip); - //OPM_CSM(chip); + OPM_CSM(chip); OPM_NoiseChannel(chip); OPM_Output(chip); OPM_DAC(chip); diff --git a/papers/doc/6-sample/README.md b/papers/doc/6-sample/README.md index 4fbb6c914..ec6f230a6 100644 --- a/papers/doc/6-sample/README.md +++ b/papers/doc/6-sample/README.md @@ -25,6 +25,7 @@ as of Furnace 0.6, the following sound chips have sample support: - tildearrow Sound Unit - VERA (last channel only) - Y8950 (last channel only) +- Konami K007232 - a few more that I've forgotten to mention ## compatible sample mode diff --git a/papers/doc/7-systems/README.md b/papers/doc/7-systems/README.md index 1ec5aa305..29c08c2ee 100644 --- a/papers/doc/7-systems/README.md +++ b/papers/doc/7-systems/README.md @@ -12,6 +12,7 @@ this is a list of sound chips that Furnace supports, including effects. - [Generic PCM DAC](dac.md) - [Famicom Disk System](fds.md) - [Game Boy](game-boy.md) +- [Konami K007232](k007232.md) - [Konami SCC](scc.md) - [Konami VRC6](vrc6.md) - [Atari Lynx](lynx.md) diff --git a/papers/doc/7-systems/k007232.md b/papers/doc/7-systems/k007232.md new file mode 100644 index 000000000..adf7d95fb --- /dev/null +++ b/papers/doc/7-systems/k007232.md @@ -0,0 +1,11 @@ +# Konami K007232 + +a 2-channel PCM sound chip from Konami which was used in some of their 1986-1990 arcade boards. + +Its sample format is unique; the topmost bit is the end marker, and the low 7 bits are used for generating sound (unsigned format). + +It has 7 bit digital output per each channel and no volume register on chip, so it needs external logic to control channel volume. + +# effects + +- Nothing for now diff --git a/papers/format.md b/papers/format.md index 685e1aefd..d30c48b52 100644 --- a/papers/format.md +++ b/papers/format.md @@ -271,6 +271,8 @@ size | description | - 0xc3: OPN CSM - 10 channels | - 0xc4: PC-98 CSM - 20 channels | - 0xc5: YM2610B CSM - 20 channels + | - 0xc6: K007232 - 2 channels + | - 0xc7: GA20 - 4 channels | - 0xde: YM2610B extended - 19 channels | - 0xe0: QSound - 19 channels | - 0xfc: Pong - 1 channel diff --git a/papers/newIns.md b/papers/newIns.md index dbc1e4f2d..548edbdeb 100644 --- a/papers/newIns.md +++ b/papers/newIns.md @@ -65,6 +65,57 @@ size | description ??? | data... ``` +the following instrument types are available: + +- 0: SN76489 +- 1: FM (OPN) +- 2: Game Boy +- 3: C64 +- 4: Amiga/sample +- 5: PC Engine +- 6: AY-3-8910 +- 7: AY8930 +- 8: TIA +- 9: SAA1099 +- 10: VIC +- 11: PET +- 12: VRC6 +- 13: OPLL +- 14: OPL +- 15: FDS +- 16: Virtual Boy +- 17: Namco 163 +- 18: SCC +- 19: OPZ +- 20: POKEY +- 21: PC Speaker +- 22: WonderSwan +- 23: Lynx +- 24: VERA +- 25: X1-010 +- 26: VRC6 (saw) +- 27: ES5506 +- 28: MultiPCM +- 29: SNES +- 30: Sound Unit +- 31: Namco WSG +- 32: OPL (drums) +- 33: FM (OPM) +- 34: NES +- 35: MSM6258 +- 36: MSM6295 +- 37: ADPCM-A +- 38: ADPCM-B +- 39: SegaPCM +- 40: QSound +- 41: YMZ280B +- 42: RF5C68 +- 43: MSM5232 +- 44: T6W28 +- 45: K007232 +- 46: GA20 +- 47: Pokémon Mini + the following feature codes are recognized: - `NA`: instrument name diff --git a/src/engine/chipUtils.h b/src/engine/chipUtils.h new file mode 100644 index 000000000..814935e61 --- /dev/null +++ b/src/engine/chipUtils.h @@ -0,0 +1,59 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _CHIP_UTILS_H +#define _CHIP_UTILS_H + +#include "macroInt.h" + +// custom clock limits +#define MIN_CUSTOM_CLOCK 100000 +#define MAX_CUSTOM_CLOCK 40000000 + +// common shared channel struct +template struct SharedChannel { + int freq, baseFreq, pitch, pitch2; + int ins, note; + bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta; + T vol, outVol; + DivMacroInt std; + void macroInit(DivInstrument* which) { + std.init(which); + pitch2=0; + } + SharedChannel(T initVol): + freq(0), + baseFreq(0), + pitch(0), + pitch2(0), + ins(-1), + note(0), + active(false), + insChanged(true), + freqChanged(false), + keyOn(false), + keyOff(false), + portaPause(false), + inPorta(false), + vol(initVol), + outVol(initVol), + std() {} +}; + +#endif diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index 4574ebb97..6a13689c2 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -24,6 +24,7 @@ #include #include #include "config.h" +#include "chipUtils.h" #define ONE_SEMITONE 2200 @@ -453,6 +454,18 @@ class DivDispatch { */ virtual bool getWantPreNote(); + /** + * get minimum chip clock. + * @return clock in Hz, or 0 if custom clocks are not supported. + */ + virtual int getClockRangeMin(); + + /** + * get maximum chip clock. + * @return clock in Hz, or 0 if custom clocks are not supported. + */ + virtual int getClockRangeMax(); + /** * set the chip flags. * @param flags a DivConfig containing chip flags. @@ -582,9 +595,9 @@ class DivDispatch { // custom chip clock helper define. put in setFlags, but before rate is set. #define CHECK_CUSTOM_CLOCK \ if (flags.getInt("customClock",0)>0) { \ - chipClock=flags.getInt("customClock",1000000); \ - if (chipClock>20000000) chipClock=20000000; \ - if (chipClock<100000) chipClock=100000; \ + chipClock=flags.getInt("customClock",getClockRangeMin()); \ + if (chipClock>getClockRangeMax()) chipClock=getClockRangeMax(); \ + if (chipClock -#include "../macroInt.h" #include "../waveSynth.h" class DivPlatformAmiga: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2; + struct Channel: public SharedChannel { unsigned int audLoc; unsigned short audLen; unsigned int audPos; int audSub; signed char audDat; int sample, wave; - int ins; int busClock; - int note; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, useWave, setPos, useV, useP; - signed char vol, outVol; - DivMacroInt std; + bool useWave, setPos, useV, useP; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(64), audLoc(0), audLen(0), audPos(0), @@ -57,21 +44,11 @@ class DivPlatformAmiga: public DivDispatch { audDat(0), sample(-1), wave(-1), - ins(-1), busClock(0), - note(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), useWave(false), setPos(false), useV(false), - useP(false), - vol(64), - outVol(64) {} + useP(false) {} }; Channel chan[4]; DivDispatchOscBuffer* oscBuf[4]; diff --git a/src/engine/platform/arcade.h b/src/engine/platform/arcade.h index eee273df3..f8c66aca1 100644 --- a/src/engine/platform/arcade.h +++ b/src/engine/platform/arcade.h @@ -20,8 +20,6 @@ #ifndef _ARCADE_H #define _ARCADE_H #include "fmshared_OPM.h" -#include "../macroInt.h" -#include "../instrument.h" #include #include "../../../extern/opm/opm.h" #include "sound/ymfm/ymfm_opm.h" @@ -36,44 +34,12 @@ class DivPlatformArcade: public DivPlatformOPM { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; - struct Channel { - DivInstrumentFM state; - DivMacroInt std; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, note; - int ins; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, portaPause, furnacePCM, hardReset, opMaskChanged; - int vol, outVol; - unsigned char chVolL, chVolR, opMask; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + struct Channel: public FMChannel { + unsigned char chVolL, chVolR; Channel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - portaPause(false), - furnacePCM(false), - hardReset(false), - opMaskChanged(false), - vol(0), - outVol(0), - chVolL(127), - chVolR(127), - opMask(15) {} + FMChannel(), + chVolL(1), + chVolR(1) {} }; Channel chan[8]; DivDispatchOscBuffer* oscBuf[8]; @@ -94,10 +60,9 @@ class DivPlatformArcade: public DivPlatformOPM { void acquire_nuked(short* bufL, short* bufR, size_t start, size_t len); void acquire_ymfm(short* bufL, short* bufR, size_t start, size_t len); - - friend void putDispatchChip(void*,int); + friend void putDispatchChan(void*,int,int); - + friend void putDispatchChip(void*,int); public: void acquire(short* bufL, short* bufR, size_t start, size_t len); int dispatch(DivCommand c); diff --git a/src/engine/platform/ay.h b/src/engine/platform/ay.h index d28eac1bf..430d5631c 100644 --- a/src/engine/platform/ay.h +++ b/src/engine/platform/ay.h @@ -20,7 +20,6 @@ #ifndef _AY_H #define _AY_H #include "../dispatch.h" -#include "../macroInt.h" #include #include "sound/ay8910.h" @@ -30,7 +29,7 @@ class DivPlatformAY8910: public DivDispatch { 0,4,1,5,2,6,9,8,11,12,13,3,7,10,14,15 }; inline unsigned char regRemap(unsigned char reg) { return intellivision?AY8914RegRemap[reg&0x0f]:reg&0x0f; } - struct Channel { + struct Channel: public SharedChannel { struct PSGMode { union { struct { @@ -73,38 +72,15 @@ class DivPlatformAY8910: public DivDispatch { furnaceDAC(0) {} } dac; - int freq, baseFreq, note, pitch, pitch2; - int ins; unsigned char autoEnvNum, autoEnvDen; signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta; - int vol, outVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): + SharedChannel(15), curPSGMode(PSGMode(0)), nextPSGMode(PSGMode(1)), dac(DAC()), - freq(0), - baseFreq(0), - note(0), - pitch(0), - pitch2(0), - ins(-1), autoEnvNum(0), - autoEnvDen(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - vol(0), - outVol(15) {} + autoEnvDen(0) {} }; Channel chan[3]; bool isMuted[3]; diff --git a/src/engine/platform/ay8930.h b/src/engine/platform/ay8930.h index 3663ee99b..d51ebf0de 100644 --- a/src/engine/platform/ay8930.h +++ b/src/engine/platform/ay8930.h @@ -20,13 +20,12 @@ #ifndef _AY8930_H #define _AY8930_H #include "../dispatch.h" -#include "../macroInt.h" #include #include "sound/ay8910.h" class DivPlatformAY8930: public DivDispatch { protected: - struct Channel { + struct Channel: public SharedChannel { struct Envelope { unsigned char mode; unsigned short period; @@ -81,40 +80,17 @@ class DivPlatformAY8930: public DivDispatch { furnaceDAC(0) {} } dac; - int freq, baseFreq, note, pitch, pitch2; - int ins; unsigned char autoEnvNum, autoEnvDen, duty; signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta; - int vol, outVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): + SharedChannel(31), envelope(Envelope()), curPSGMode(PSGMode(0)), nextPSGMode(PSGMode(1)), dac(DAC()), - freq(0), - baseFreq(0), - note(0), - pitch(0), - pitch2(0), - ins(-1), autoEnvNum(0), autoEnvDen(0), - duty(4), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - vol(0), - outVol(31) {} + duty(4) {} }; Channel chan[3]; bool isMuted[3]; diff --git a/src/engine/platform/bubsyswsg.h b/src/engine/platform/bubsyswsg.h index 0d7e3fd58..92c64d898 100644 --- a/src/engine/platform/bubsyswsg.h +++ b/src/engine/platform/bubsyswsg.h @@ -22,37 +22,16 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "../waveSynth.h" #include "vgsound_emu/src/k005289/k005289.hpp" class DivPlatformBubSysWSG: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta; - signed char vol, outVol, wave; + struct Channel: public SharedChannel { + signed short wave; signed char waveROM[32] = {0}; // 4 bit PROM per channel on bubble system - DivMacroInt std; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - vol(15), - outVol(15), + SharedChannel(15), wave(-1) {} }; Channel chan[2]; diff --git a/src/engine/platform/c64.h b/src/engine/platform/c64.h index 4fe68f4e6..9bdabbe45 100644 --- a/src/engine/platform/c64.h +++ b/src/engine/platform/c64.h @@ -22,32 +22,20 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "sound/c64/sid.h" #include "sound/c64_fp/SID.h" class DivPlatformC64: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, prevFreq, testWhen, note, ins; + struct Channel: public SharedChannel { + int prevFreq, testWhen; unsigned char sweep, wave, attack, decay, sustain, release; short duty; - bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, filter; + bool sweepChanged, filter; bool resetMask, resetFilter, resetDuty, ring, sync, test; - signed char vol, outVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(15), prevFreq(65535), testWhen(0), - note(0), - ins(-1), sweep(0), wave(0), attack(0), @@ -55,21 +43,14 @@ class DivPlatformC64: public DivDispatch { sustain(0), release(0), duty(0), - active(false), - insChanged(true), - freqChanged(false), sweepChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), filter(false), resetMask(false), resetFilter(false), resetDuty(false), ring(false), sync(false), - test(false), - vol(15) {} + test(false) {} }; Channel chan[3]; DivDispatchOscBuffer* oscBuf[3]; diff --git a/src/engine/platform/fds.h b/src/engine/platform/fds.h index 7a54aa52d..beabb6417 100644 --- a/src/engine/platform/fds.h +++ b/src/engine/platform/fds.h @@ -21,46 +21,27 @@ #define _FDS_H #include "../dispatch.h" -#include "../macroInt.h" #include "../waveSynth.h" #include "sound/nes_nsfplay/nes_fds.h" class DivPlatformFDS: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, prevFreq, note, modFreq, ins; + struct Channel: public SharedChannel { + int prevFreq, modFreq; unsigned char duty, sweep, modDepth, modPos; - bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, modOn; - signed char vol, outVol, wave; + bool sweepChanged, modOn; + signed short wave; signed char modTable[32]; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(32), prevFreq(65535), - note(0), modFreq(0), - ins(-1), duty(0), sweep(8), modDepth(0), modPos(0), - active(false), - insChanged(true), - freqChanged(false), sweepChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), modOn(false), - vol(32), - outVol(32), wave(-1) { memset(modTable,0,32); } diff --git a/src/engine/platform/fmshared_OPN.h b/src/engine/platform/fmshared_OPN.h index a6eb7185e..19eec0aab 100644 --- a/src/engine/platform/fmshared_OPN.h +++ b/src/engine/platform/fmshared_OPN.h @@ -101,6 +101,48 @@ class DivPlatformOPN: public DivPlatformFMBase { 0x00, 0x04, 0x08, 0x0c }; + struct OPNChannel: public FMChannel { + unsigned char psgMode, autoEnvNum, autoEnvDen; + bool furnacePCM; + int sample, macroVolMul; + + OPNChannel(): + FMChannel(), + psgMode(1), + autoEnvNum(0), + autoEnvDen(0), + furnacePCM(false), + sample(-1), + macroVolMul(255) {} + }; + + struct OPNChannelStereo: public OPNChannel { + unsigned char pan; + OPNChannelStereo(): + OPNChannel(), + pan(3) {} + }; + + struct OPNOpChannel: public SharedChannel { + unsigned char freqH, freqL; + int portaPauseFreq; + signed char konCycles; + bool mask; + OPNOpChannel(): + SharedChannel(0), + freqH(0), + freqL(0), + portaPauseFreq(0), + mask(true) {} + }; + + struct OPNOpChannelStereo: public OPNOpChannel { + unsigned char pan; + OPNOpChannelStereo(): + OPNOpChannel(), + pan(3) {} + }; + double fmFreqBase; unsigned int fmDivBase; unsigned int ayDiv; @@ -108,6 +150,8 @@ class DivPlatformOPN: public DivPlatformFMBase { DivConfig ayFlags; + friend void putDispatchChip(void*,int); + friend void putDispatchChan(void*,int,int); DivPlatformOPN(double f=9440540.0, unsigned int d=72, unsigned int a=32, bool isExtSys=false): DivPlatformFMBase(), fmFreqBase(f), diff --git a/src/engine/platform/fmsharedbase.h b/src/engine/platform/fmsharedbase.h index 15baacefa..0c09b64a0 100644 --- a/src/engine/platform/fmsharedbase.h +++ b/src/engine/platform/fmsharedbase.h @@ -21,6 +21,7 @@ #define _FMSHARED_BASE_H #include "../dispatch.h" +#include "../instrument.h" #include #define KVS(x,y) ((chan[x].state.op[y].kvs==2 && isOutput[chan[x].state.alg][y]) || chan[x].state.op[y].kvs==1) @@ -46,6 +47,32 @@ class DivPlatformFMBase: public DivDispatch { 0,2,1,3 }; + struct FMChannel: public SharedChannel { + DivInstrumentFM state; + unsigned char freqH, freqL; + int portaPauseFreq; + unsigned char opMask; + signed char konCycles; + bool hardReset, opMaskChanged; + + FMChannel(): + SharedChannel(0), + freqH(0), + freqL(0), + portaPauseFreq(0), + opMask(15), + konCycles(0), + hardReset(false), + opMaskChanged(false) {} + }; + + struct FMChannelStereo: public FMChannel { + unsigned char pan; + FMChannelStereo(): + FMChannel(), + pan(3) {} + }; + struct QueuedWrite { unsigned short addr; unsigned char val; @@ -89,8 +116,9 @@ class DivPlatformFMBase: public DivDispatch { } } - DivPlatformFMBase(): - DivDispatch(), + friend void putDispatchChan(void*,int,int); + + DivPlatformFMBase():DivDispatch(), lastBusy(0), delay(0) {} }; diff --git a/src/engine/platform/gb.h b/src/engine/platform/gb.h index 17a17da16..581962999 100644 --- a/src/engine/platform/gb.h +++ b/src/engine/platform/gb.h @@ -21,48 +21,29 @@ #define _GB_H #include "../dispatch.h" -#include "../macroInt.h" #include "../waveSynth.h" #include "sound/gb/gb.h" #include class DivPlatformGB: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; + struct Channel: public SharedChannel { unsigned char duty, sweep; - bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, released, softEnv, killIt; + bool sweepChanged, released, softEnv, killIt; bool soManyHacksToMakeItDefleCompatible; - signed char vol, outVol, wave, lastKill; + signed short wave; + signed char lastKill; unsigned char envVol, envDir, envLen, soundLen; unsigned short hwSeqPos; short hwSeqDelay; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), + SharedChannel(15), duty(0), sweep(0), - active(false), - insChanged(true), - freqChanged(false), sweepChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), released(false), softEnv(false), killIt(false), soManyHacksToMakeItDefleCompatible(false), - vol(15), - outVol(15), wave(-1), lastKill(0), envVol(0), diff --git a/src/engine/platform/genesis.cpp b/src/engine/platform/genesis.cpp index adfdf2583..9dd3699c7 100644 --- a/src/engine/platform/genesis.cpp +++ b/src/engine/platform/genesis.cpp @@ -19,6 +19,7 @@ #include "genesis.h" #include "../engine.h" +#include "../../ta-log.h" #include #include @@ -27,6 +28,22 @@ #define IS_REALLY_MUTED(x) (isMuted[x] && (x<5 || !softPCM || (isMuted[5] && isMuted[6]))) +void DivYM2612Interface::ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks) { + if (tnum==1) { + countB=duration_in_clocks; + } else if (tnum==0) { + countA=duration_in_clocks; + } + logV("ymfm_set_timer(%d,%d)",tnum,duration_in_clocks); +} + +void DivYM2612Interface::clock() { + if (countA>=0) { + countA-=144; + if (countA<0) m_engine->engine_timer_expired(0); + } +} + void DivPlatformGenesis::processDAC(int iRate) { if (softPCM) { softPCMTimer+=chipClock/576; @@ -197,6 +214,7 @@ void DivPlatformGenesis::acquire_ymfm(short* bufL, short* bufR, size_t start, si } else { ((ymfm::ym3438*)fm_ymfm)->generate(&out_ymfm); } + iface.clock(); os[0]=out_ymfm.data[0]; os[1]=out_ymfm.data[1]; //OPN2_Write(&fm,0,0); diff --git a/src/engine/platform/genesis.h b/src/engine/platform/genesis.h index 999e3687e..bd5d9afff 100644 --- a/src/engine/platform/genesis.h +++ b/src/engine/platform/genesis.h @@ -19,14 +19,22 @@ #ifndef _GENESIS_H #define _GENESIS_H + #include "fmshared_OPN.h" -#include "../macroInt.h" #include "../../../extern/Nuked-OPN2/ym3438.h" #include "sound/ymfm/ymfm_opn.h" class DivYM2612Interface: public ymfm::ymfm_interface { + int countA, countB; + public: + void clock(); + void ymfm_set_timer(uint32_t tnum, int32_t duration_in_clocks); + DivYM2612Interface(): + ymfm::ymfm_interface(), + countA(-1), + countB(-1) {} }; class DivPlatformGenesis: public DivPlatformOPN { @@ -39,16 +47,8 @@ class DivPlatformGenesis: public DivPlatformOPN { 0, 1, 2, 4, 5, 6 }; - struct Channel { - DivInstrumentFM state; - DivMacroInt std; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, note; - int ins; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, furnaceDac, inPorta, hardReset, opMaskChanged; - int vol, outVol; - unsigned char pan, opMask; - + struct Channel: public FMChannelStereo { + bool furnaceDac; bool dacMode; int dacPeriod; int dacRate; @@ -59,34 +59,9 @@ class DivPlatformGenesis: public DivPlatformOPN { bool dacDirection; unsigned char sampleBank; signed char dacOutput; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), + FMChannelStereo(), furnaceDac(false), - inPorta(false), - hardReset(false), - opMaskChanged(false), - vol(0), - outVol(0), - pan(3), - opMask(15), dacMode(false), dacPeriod(0), dacRate(0), @@ -123,6 +98,8 @@ class DivPlatformGenesis: public DivPlatformOPN { void acquire_nuked(short* bufL, short* bufR, size_t start, size_t len); void acquire_ymfm(short* bufL, short* bufR, size_t start, size_t len); + friend void putDispatchChip(void*,int); + friend void putDispatchChan(void*,int,int); public: void acquire(short* bufL, short* bufR, size_t start, size_t len); void fillStream(std::vector& stream, int sRate, size_t len); diff --git a/src/engine/platform/genesisext.cpp b/src/engine/platform/genesisext.cpp index 45a8898db..5395b32c1 100644 --- a/src/engine/platform/genesisext.cpp +++ b/src/engine/platform/genesisext.cpp @@ -709,7 +709,7 @@ void DivPlatformGenesisExt::reset() { DivPlatformGenesis::reset(); for (int i=0; i<4; i++) { - opChan[i]=DivPlatformGenesisExt::OpChannel(); + opChan[i]=DivPlatformOPN::OPNOpChannelStereo(); opChan[i].std.setEngine(parent); opChan[i].vol=127; opChan[i].outVol=127; diff --git a/src/engine/platform/genesisext.h b/src/engine/platform/genesisext.h index fb68ecfff..eec093a8e 100644 --- a/src/engine/platform/genesisext.h +++ b/src/engine/platform/genesisext.h @@ -17,46 +17,15 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef _GENESISEXT_H +#define _GENESISEXT_H + #include "../dispatch.h" #include "genesis.h" class DivPlatformGenesisExt: public DivPlatformGenesis { - struct OpChannel { - DivMacroInt std; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, ins, note; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, mask; - int vol, outVol; - unsigned char pan; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } - OpChannel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - ins(-1), - note(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - mask(true), - vol(0), - outVol(0), - pan(3) {} - }; - OpChannel opChan[4]; + OPNOpChannelStereo opChan[4]; bool isOpMuted[4]; friend void putDispatchChip(void*,int); friend void putDispatchChan(void*,int,int); @@ -77,3 +46,5 @@ class DivPlatformGenesisExt: public DivPlatformGenesis { void quit(); ~DivPlatformGenesisExt(); }; + +#endif diff --git a/src/engine/platform/k007232.cpp b/src/engine/platform/k007232.cpp new file mode 100644 index 000000000..e174a277a --- /dev/null +++ b/src/engine/platform/k007232.cpp @@ -0,0 +1,569 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "k007232.h" +#include "../engine.h" +#include "../../ta-log.h" +#include + +#define rWrite(a,v) {if(!skipRegisterWrites) {writes.emplace(a,v); if(dumpWrites) addWrite(a,v);}} + +#define CHIP_DIVIDER 64 + +const char* regCheatSheetK007232[]={ + // on-chip + "CHX_FreqL", "X*6+0", + "CHX_FreqH", "X*6+1", + "CHX_StartL", "X*6+2", + "CHX_StartM", "X*6+3", + "CHX_StartH", "X*6+4", + "CHX_Keyon", "X*6+5", + "SLEV", "C", // external IO + "Loop", "D", + // off-chip + "CHX_Volume", "X*2+10", + "CHX_Bank", "X*2+12", + NULL +}; + +const char** DivPlatformK007232::getRegisterSheet() { + return regCheatSheetK007232; +} + +inline void DivPlatformK007232::chWrite(unsigned char ch, unsigned int addr, unsigned char val) { + if (!skipRegisterWrites) { + if ((ch<2) && (addr<6)) { + rWrite((ch*6)+(addr&7),val); + } + } +} + +void DivPlatformK007232::acquire(short* bufL, short* bufR, size_t start, size_t len) { + for (size_t h=start; h>4)&0xf)),(k007232.output(1)*((vol2>>4)&0xf))}; + bufL[h]=(lout[0]+lout[1])<<4; + bufR[h]=(rout[0]+rout[1])<<4; + for (int i=0; i<2; i++) { + oscBuf[i]->data[oscBuf[i]->needle++]=(lout[i]+rout[i])<<4; + } + } else { + const unsigned char vol=regPool[0xc]; + const signed int out[2]={(k007232.output(0)*(vol&0xf)),(k007232.output(1)*((vol>>4)&0xf))}; + bufL[h]=bufR[h]=(out[0]+out[1])<<4; + for (int i=0; i<2; i++) { + oscBuf[i]->data[oscBuf[i]->needle++]=out[i]<<5; + } + } + } +} + +u8 DivPlatformK007232::read_sample(u8 ne, u32 address) { + if ((sampleMem!=NULL) && (addresscalcArp(chan[i].note,chan[i].std.arp.val)); + } + chan[i].freqChanged=true; + } + if (chan[i].std.pitch.had) { + if (chan[i].std.pitch.mode) { + chan[i].pitch2+=chan[i].std.pitch.val; + CLAMP_VAR(chan[i].pitch2,-32768,32767); + } else { + chan[i].pitch2=chan[i].std.pitch.val; + } + chan[i].freqChanged=true; + } + // volume and panning registers are off-chip + if (chan[i].std.panL.had) { + chan[i].panning&=0xf0; + chan[i].panning|=chan[i].std.panL.val&15; + if ((!isMuted[i]) && stereo) { + chan[i].volumeChanged=true; + } + } + if (chan[i].std.panR.had) { + chan[i].panning&=0x0f; + chan[i].panning|=(chan[i].std.panR.val&15)<<4; + if ((!isMuted[i]) && stereo) { + chan[i].volumeChanged=true; + } + } + if (chan[i].std.phaseReset.had) { + if (chan[i].std.phaseReset.val==1 && chan[i].active) { + chan[i].audPos=0; + chan[i].setPos=true; + } + } + if (chan[i].volumeChanged) { + chan[i].resVol=isMuted[i]?0:chan[i].outVol&0xf; + if (stereo) { + chan[i].lvol=((chan[i].resVol&0xf)*((chan[i].panning>>0)&0xf))/15; + chan[i].rvol=((chan[i].resVol&0xf)*((chan[i].panning>>4)&0xf))/15; + const int newPan=(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4); + if (chan[i].prevPan!=newPan) { + rWrite(0x10+i,(chan[i].lvol&0xf)|((chan[i].rvol&0xf)<<4)); + chan[i].prevPan=newPan; + } + } + else { + const unsigned char prevVolume=lastVolume; + lastVolume=(lastVolume&~(0xf<<(i<<2)))|((chan[i].resVol&0xf)<<(i<<2)); + if (prevVolume!=lastVolume) { + rWrite(0xc,lastVolume); + } + } + chan[i].volumeChanged=false; + } + if (chan[i].setPos) { + // force keyon + chan[i].keyOn=true; + chan[i].setPos=false; + } else { + chan[i].audPos=0; + } + if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { + double off=1.0; + int sample=chan[i].sample; + if (sample>=0 && samplesong.sampleLen) { + DivSample* s=parent->getSample(sample); + if (s->centerRate<1) { + off=1.0; + } else { + off=8363.0/s->centerRate; + } + } + DivSample* s=parent->getSample(chan[i].sample); + chan[i].freq=0x1000-(int)(off*parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true,0,chan[i].pitch2,chipClock,CHIP_DIVIDER)); + if (chan[i].freq>4095) chan[i].freq=4095; + if (chan[i].freq<0) chan[i].freq=0; + if (chan[i].keyOn) { + unsigned int bank=0; + unsigned int start=0; + unsigned int loop=0; + if (chan[i].sample>=0 && chan[i].samplesong.sampleLen) { + bank=sampleOffK007232[chan[i].sample]>>17; + start=sampleOffK007232[chan[i].sample]&0x1ffff; + loop=start+s->length8; + } + if (chan[i].audPos>0) { + start=start+MIN(chan[i].audPos,MIN(131072-1,s->length8)); + } + start=MIN(start,MIN(getSampleMemCapacity(),131072)-1); + loop=MIN(loop,MIN(getSampleMemCapacity(),131072)-1); + // force keyoff first + chWrite(i,2,0xff); + chWrite(i,3,0xff); + chWrite(i,4,0x1); + chWrite(i,5,0); + // keyon + const unsigned char prevLoop=lastLoop; + if (s->isLoopable()) { + loop=start+s->loopStart; + lastLoop|=(1<>8)&0xf); + chan[i].prevFreq=chan[i].freq; + } + chWrite(i,2,start&0xff); + chWrite(i,3,start>>8); + chWrite(i,4,start>>16); + chWrite(i,5,0); + if (s->isLoopable() && start!=loop) { + chWrite(i,2,loop&0xff); + chWrite(i,3,loop>>8); + chWrite(i,4,loop>>16); + } + if (!chan[i].std.vol.had) { + chan[i].outVol=chan[i].vol; + if (!isMuted[i]) { + chan[i].volumeChanged=true; + } + } + chan[i].keyOn=false; + } + if (chan[i].keyOff) { + chWrite(i,2,0xff); + chWrite(i,3,0xff); + chWrite(i,4,0x1); + chWrite(i,5,0); + const unsigned char prevLoop=lastLoop; + lastLoop&=~(1<>8)&0xf); + chan[i].prevFreq=chan[i].freq; + } + chan[i].freqChanged=false; + } + } + } +} + +int DivPlatformK007232::dispatch(DivCommand c) { + switch (c.cmd) { + case DIV_CMD_NOTE_ON: { + DivInstrument* ins=parent->getIns(chan[c.chan].ins,DIV_INS_AMIGA); + chan[c.chan].macroVolMul=ins->type==DIV_INS_AMIGA?64:15; + chan[c.chan].sample=ins->amiga.getSample(c.value); + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].baseFreq=NOTE_PERIODIC(c.value); + } + if (chan[c.chan].sample<0 || chan[c.chan].sample>=parent->song.sampleLen) { + chan[c.chan].sample=-1; + } + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].freqChanged=true; + chan[c.chan].note=c.value; + } + chan[c.chan].active=true; + chan[c.chan].keyOn=true; + chan[c.chan].macroInit(ins); + if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { + chan[c.chan].outVol=chan[c.chan].vol; + if (!isMuted[c.chan]) { + chan[c.chan].volumeChanged=true; + } + } + break; + } + case DIV_CMD_NOTE_OFF: + chan[c.chan].sample=-1; + chan[c.chan].active=false; + chan[c.chan].keyOff=true; + chan[c.chan].macroInit(NULL); + break; + case DIV_CMD_NOTE_OFF_ENV: + case DIV_CMD_ENV_RELEASE: + chan[c.chan].std.release(); + break; + case DIV_CMD_INSTRUMENT: + if (chan[c.chan].ins!=c.value || c.value2==1) { + chan[c.chan].ins=c.value; + } + break; + case DIV_CMD_VOLUME: + if (chan[c.chan].vol!=c.value) { + chan[c.chan].vol=c.value; + if (!chan[c.chan].std.vol.has) { + chan[c.chan].outVol=c.value; + if (!isMuted[c.chan]) { + chan[c.chan].volumeChanged=true; + } + } + } + break; + case DIV_CMD_GET_VOLUME: + if (chan[c.chan].std.vol.has) { + return chan[c.chan].vol; + } + return chan[c.chan].outVol; + break; + case DIV_CMD_PANNING: + chan[c.chan].panning=(c.value>>4)|(c.value2&0xf0); + if (!isMuted[c.chan] && stereo) { + chan[c.chan].volumeChanged=true; + } + break; + case DIV_CMD_PITCH: + chan[c.chan].pitch=c.value; + chan[c.chan].freqChanged=true; + break; + case DIV_CMD_NOTE_PORTA: { + const int destFreq=NOTE_PERIODIC(c.value2); + bool return2=false; + if (destFreq>chan[c.chan].baseFreq) { + chan[c.chan].baseFreq+=c.value; + if (chan[c.chan].baseFreq>=destFreq) { + chan[c.chan].baseFreq=destFreq; + return2=true; + } + } else { + chan[c.chan].baseFreq-=c.value; + if (chan[c.chan].baseFreq<=destFreq) { + chan[c.chan].baseFreq=destFreq; + return2=true; + } + } + chan[c.chan].freqChanged=true; + if (return2) { + chan[c.chan].inPorta=false; + return 2; + } + break; + } + case DIV_CMD_LEGATO: { + chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+((chan[c.chan].std.arp.will && !chan[c.chan].std.arp.mode)?(chan[c.chan].std.arp.val-12):(0))); + chan[c.chan].freqChanged=true; + chan[c.chan].note=c.value; + break; + } + case DIV_CMD_PRE_PORTA: + if (chan[c.chan].active && c.value2) { + if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_AMIGA)); + } + if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will) chan[c.chan].baseFreq=NOTE_PERIODIC(chan[c.chan].note); + chan[c.chan].inPorta=c.value; + break; + case DIV_CMD_SAMPLE_POS: + chan[c.chan].audPos=c.value; + chan[c.chan].setPos=true; + break; + case DIV_CMD_GET_VOLMAX: + return 15; + break; + case DIV_ALWAYS_SET_VOLUME: + return 1; + break; + default: + break; + } + return 1; +} + +void DivPlatformK007232::muteChannel(int ch, bool mute) { + isMuted[ch]=mute; + chan[ch].volumeChanged=true; +} + +void DivPlatformK007232::forceIns() { + while (!writes.empty()) writes.pop(); + for (int i=0; i<2; i++) { + chan[i].insChanged=true; + chan[i].freqChanged=true; + chan[i].sample=-1; + } +} + +void* DivPlatformK007232::getChanState(int ch) { + return &chan[ch]; +} + +DivMacroInt* DivPlatformK007232::getChanMacroInt(int ch) { + return &chan[ch].std; +} + +DivDispatchOscBuffer* DivPlatformK007232::getOscBuffer(int ch) { + return oscBuf[ch]; +} + +void DivPlatformK007232::reset() { + while (!writes.empty()) { + writes.pop(); + } + memset(regPool,0,20); + k007232.reset(); + lastLoop=0; + lastVolume=0; + for (int i=0; i<2; i++) { + chan[i]=DivPlatformK007232::Channel(); + chan[i].std.setEngine(parent); + // keyoff all channels + chWrite(i,0,0); + chWrite(i,1,0); + chWrite(i,2,0xff); + chWrite(i,3,0xff); + chWrite(i,4,1); + chWrite(i,5,0); + } +} + +bool DivPlatformK007232::isStereo() { + return stereo; +} + +void DivPlatformK007232::notifyInsChange(int ins) { + for (int i=0; i<2; i++) { + if (chan[i].ins==ins) { + chan[i].insChanged=true; + } + } +} + +void DivPlatformK007232::notifyWaveChange(int wave) { + // TODO when wavetables are added + // TODO they probably won't be added unless the samples reside in RAM +} + +void DivPlatformK007232::notifyInsDeletion(void* ins) { + for (int i=0; i<2; i++) { + chan[i].std.notifyInsDeletion((DivInstrument*)ins); + } +} + +void DivPlatformK007232::setFlags(const DivConfig& flags) { + chipClock=COLOR_NTSC; + CHECK_CUSTOM_CLOCK; + rate=chipClock/4; + stereo=flags.getBool("stereo",false); + for (int i=0; i<2; i++) { + oscBuf[i]->rate=rate; + } +} + +void DivPlatformK007232::poke(unsigned int addr, unsigned short val) { + rWrite(addr&0x1f,val); +} + +void DivPlatformK007232::poke(std::vector& wlist) { + for (DivRegWrite& i: wlist) rWrite(i.addr&0x1f,i.val); +} + +unsigned char* DivPlatformK007232::getRegisterPool() { + return regPool; +} + +int DivPlatformK007232::getRegisterPoolSize() { + return 20; +} + +const void* DivPlatformK007232::getSampleMem(int index) { + return index == 0 ? sampleMem : NULL; +} + +size_t DivPlatformK007232::getSampleMemCapacity(int index) { + return index == 0 ? 16777216 : 0; +} + +size_t DivPlatformK007232::getSampleMemUsage(int index) { + return index == 0 ? sampleMemLen : 0; +} + +bool DivPlatformK007232::isSampleLoaded(int index, int sample) { + if (index!=0) return false; + if (sample<0 || sample>255) return false; + return sampleLoaded[sample]; +} + +void DivPlatformK007232::renderSamples(int sysID) { + memset(sampleMem,0xc0,getSampleMemCapacity()); + memset(sampleOffK007232,0,256*sizeof(unsigned int)); + memset(sampleLoaded,0,256*sizeof(bool)); + + size_t memPos=0; + for (int i=0; isong.sampleLen; i++) { + DivSample* s=parent->song.sample[i]; + if (!s->renderOn[0][sysID]) { + sampleOffK007232[i]=0; + continue; + } + + const int length=s->getLoopEndPosition(DIV_SAMPLE_DEPTH_8BIT); + int actualLength=MIN((int)(getSampleMemCapacity()-memPos)-1,length); + if (actualLength>0) { + if (actualLength>131072-1) { + actualLength=131072-1; + } + if ((memPos&0xfe0000)!=((memPos+actualLength+1)&0xfe0000)) { + memPos=(memPos+0x1ffff)&0xfe0000; + } + sampleOffK007232[i]=memPos; + for (int j=0; jdata8[j])^0x80; + sampleMem[memPos++]=(val>>1)&0x7f; + } + // write end of sample marker + memset(&sampleMem[memPos],0xc0,1); + memPos+=1; + } + if ((memPos+MAX(actualLength,0))>=(getSampleMemCapacity()-1)) { + logW("out of K007232 PCM memory for sample %d!",i); + break; + } else { + sampleLoaded[i]=true; + } + } + sampleMemLen=memPos; +} + +int DivPlatformK007232::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { + parent=p; + dumpWrites=false; + skipRegisterWrites=false; + + for (int i=0; i<2; i++) { + isMuted[i]=false; + oscBuf[i]=new DivDispatchOscBuffer; + } + sampleMem=new unsigned char[getSampleMemCapacity()]; + sampleMemLen=0; + setFlags(flags); + reset(); + + return 2; +} + +void DivPlatformK007232::quit() { + delete[] sampleMem; + for (int i=0; i<2; i++) { + delete oscBuf[i]; + } +} diff --git a/src/engine/platform/k007232.h b/src/engine/platform/k007232.h new file mode 100644 index 000000000..04e6e73f0 --- /dev/null +++ b/src/engine/platform/k007232.h @@ -0,0 +1,115 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _K007232_H +#define _K007232_H + +#include "../dispatch.h" +#include +#include "../macroInt.h" +#include "vgsound_emu/src/k007232/k007232.hpp" + +class DivPlatformK007232: public DivDispatch, public k007232_intf { + struct Channel: public SharedChannel { + int prevFreq; + unsigned int audPos; + int prevBank; + int sample; + int panning, prevPan; + bool volumeChanged, setPos; + int resVol, lvol, rvol; + int macroVolMul; + Channel(): + SharedChannel(15), + prevFreq(-1), + audPos(0), + prevBank(-1), + sample(-1), + panning(255), + prevPan(-1), + volumeChanged(false), + setPos(false), + resVol(15), + lvol(15), + rvol(15), + macroVolMul(64) {} + }; + Channel chan[2]; + DivDispatchOscBuffer* oscBuf[2]; + bool isMuted[2]; + struct QueuedWrite { + unsigned short addr; + unsigned char val; + unsigned short delay; + QueuedWrite(unsigned short a, unsigned char v, unsigned short d=1): + addr(a), + val(v), + delay(d) {} + }; + std::queue writes; + unsigned int sampleOffK007232[256]; + bool sampleLoaded[256]; + + int delay; + unsigned char lastLoop, lastVolume; + bool stereo; + + unsigned char* sampleMem; + size_t sampleMemLen; + k007232_core k007232; + unsigned char regPool[20]; + friend void putDispatchChip(void*,int); + friend void putDispatchChan(void*,int,int); + + void chWrite(unsigned char ch, unsigned int addr, unsigned char val); + public: + u8 read_sample(u8 ne, u32 address); + void acquire(short* bufL, short* bufR, size_t start, size_t len); + int dispatch(DivCommand c); + void* getChanState(int chan); + DivMacroInt* getChanMacroInt(int ch); + DivDispatchOscBuffer* getOscBuffer(int chan); + unsigned char* getRegisterPool(); + int getRegisterPoolSize(); + void reset(); + void forceIns(); + void tick(bool sysTick=true); + void muteChannel(int ch, bool mute); + bool isStereo(); + void notifyInsChange(int ins); + void notifyWaveChange(int wave); + void notifyInsDeletion(void* ins); + void setFlags(const DivConfig& flags); + void poke(unsigned int addr, unsigned short val); + void poke(std::vector& wlist); + const char** getRegisterSheet(); + const void* getSampleMem(int index = 0); + size_t getSampleMemCapacity(int index = 0); + size_t getSampleMemUsage(int index = 0); + bool isSampleLoaded(int index, int sample); + void renderSamples(int chipID); + int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); + void quit(); + DivPlatformK007232(): + DivDispatch(), + k007232_intf(), + k007232(*this) {} +}; + +#endif diff --git a/src/engine/platform/lynx.h b/src/engine/platform/lynx.h index c03402e24..463aad3d0 100644 --- a/src/engine/platform/lynx.h +++ b/src/engine/platform/lynx.h @@ -21,64 +21,44 @@ #define _LYNX_H #include "../dispatch.h" -#include "../macroInt.h" #include "sound/lynx/Mikey.hpp" class DivPlatformLynx: public DivDispatch { struct MikeyFreqDiv { - uint8_t clockDivider; - uint8_t backup; + unsigned char clockDivider; + unsigned char backup; MikeyFreqDiv(int frequency); }; struct MikeyDuty { - uint8_t int_feedback7; - uint8_t feedback; + unsigned char int_feedback7; + unsigned char feedback; MikeyDuty(int duty); }; - struct Channel { - DivMacroInt std; + struct Channel: public SharedChannel { MikeyFreqDiv fd; MikeyDuty duty; - int baseFreq, pitch, pitch2, note, actualNote, lfsr, ins, sample, samplePos, sampleAccum, sampleBaseFreq, sampleFreq; + int actualNote, lfsr, sample, samplePos, sampleAccum, sampleBaseFreq, sampleFreq; unsigned char pan; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, pcm; - signed char vol, outVol; + bool pcm; int macroVolMul; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - std(), + SharedChannel(127), fd(0), duty(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), actualNote(0), lfsr(-1), - ins(-1), sample(-1), samplePos(0), sampleAccum(0), sampleBaseFreq(0), sampleFreq(0), pan(0xff), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), pcm(false), - vol(127), - outVol(127), macroVolMul(127) {} }; Channel chan[4]; diff --git a/src/engine/platform/mmc5.h b/src/engine/platform/mmc5.h index ddad9ec2d..a3ab90538 100644 --- a/src/engine/platform/mmc5.h +++ b/src/engine/platform/mmc5.h @@ -21,40 +21,19 @@ #define _MMC5_H #include "../dispatch.h" -#include "../macroInt.h" class DivPlatformMMC5: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, prevFreq, note, ins; + struct Channel: public SharedChannel { + int prevFreq; unsigned char duty, sweep; - bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac; - signed char vol, outVol, wave; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + bool sweepChanged, furnaceDac; Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(15), prevFreq(65535), - note(0), - ins(-1), duty(0), sweep(8), - active(false), - insChanged(true), - freqChanged(false), sweepChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - furnaceDac(false), - vol(15), - outVol(15), - wave(-1) {} + furnaceDac(false) {} }; Channel chan[5]; DivDispatchOscBuffer* oscBuf[3]; diff --git a/src/engine/platform/msm5232.h b/src/engine/platform/msm5232.h index 3e2bf71a4..2d4b9705e 100644 --- a/src/engine/platform/msm5232.h +++ b/src/engine/platform/msm5232.h @@ -22,36 +22,14 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "sound/oki/msm5232.h" class DivPlatformMSM5232: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note; - int ins; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, noise; - signed char vol, outVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + struct Channel: public SharedChannel { + bool noise; Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - noise(false), - vol(127), - outVol(127) {} + SharedChannel(127), + noise(false) {} }; Channel chan[8]; DivDispatchOscBuffer* oscBuf[8]; diff --git a/src/engine/platform/msm6258.cpp b/src/engine/platform/msm6258.cpp index ef11c7174..1c594982a 100644 --- a/src/engine/platform/msm6258.cpp +++ b/src/engine/platform/msm6258.cpp @@ -156,7 +156,6 @@ int DivPlatformMSM6258::dispatch(DivCommand c) { //DivSample* s=parent->getSample(chan[c.chan].sample); if (c.value!=DIV_NOTE_NULL) { chan[c.chan].note=c.value; - chan[c.chan].freqChanged=true; } chan[c.chan].active=true; chan[c.chan].keyOn=true; diff --git a/src/engine/platform/msm6258.h b/src/engine/platform/msm6258.h index 9a5cd7d76..28f04f92f 100644 --- a/src/engine/platform/msm6258.h +++ b/src/engine/platform/msm6258.h @@ -19,51 +19,20 @@ #ifndef _MSM6258_H #define _MSM6258_H + #include "../dispatch.h" -#include "../macroInt.h" #include #include "sound/oki/okim6258.h" class DivPlatformMSM6258: public DivDispatch { protected: - struct Channel { - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, note, ins; - unsigned char psgMode, autoEnvNum, autoEnvDen; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, furnacePCM, hardReset; - int vol, outVol; + struct Channel: public SharedChannel { + bool furnacePCM; int sample; unsigned char pan; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - note(0), - ins(-1), - psgMode(1), - autoEnvNum(0), - autoEnvDen(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), + SharedChannel(8), furnacePCM(false), - hardReset(false), - vol(0), - outVol(15), sample(-1), pan(3) {} }; diff --git a/src/engine/platform/msm6295.cpp b/src/engine/platform/msm6295.cpp index 3bf0b8eb4..33321bb6a 100644 --- a/src/engine/platform/msm6295.cpp +++ b/src/engine/platform/msm6295.cpp @@ -144,7 +144,6 @@ int DivPlatformMSM6295::dispatch(DivCommand c) { //DivSample* s=parent->getSample(chan[c.chan].sample); if (c.value!=DIV_NOTE_NULL) { chan[c.chan].note=c.value; - chan[c.chan].freqChanged=true; } chan[c.chan].active=true; chan[c.chan].keyOn=true; diff --git a/src/engine/platform/msm6295.h b/src/engine/platform/msm6295.h index 9d47824a6..e3339df31 100644 --- a/src/engine/platform/msm6295.h +++ b/src/engine/platform/msm6295.h @@ -19,35 +19,19 @@ #ifndef _MSM6295_H #define _MSM6295_H + #include "../dispatch.h" -#include "../macroInt.h" #include #include "vgsound_emu/src/msm6295/msm6295.hpp" class DivPlatformMSM6295: public DivDispatch, public vgsound_emu_mem_intf { protected: - struct Channel { - int note, ins; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, furnacePCM, hardReset; - int vol, outVol; + struct Channel: public SharedChannel { + bool furnacePCM; int sample; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - } Channel(): - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), + SharedChannel(8), furnacePCM(false), - hardReset(false), - vol(8), - outVol(8), sample(-1) {} }; Channel chan[4]; diff --git a/src/engine/platform/n163.h b/src/engine/platform/n163.h index 2f8e5ef98..872c622bf 100644 --- a/src/engine/platform/n163.h +++ b/src/engine/platform/n163.h @@ -22,32 +22,22 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "../waveSynth.h" #include "vgsound_emu/src/n163/n163.hpp" class DivPlatformN163: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note; - short ins, wave, wavePos, waveLen; + struct Channel: public SharedChannel { + signed char resVol; + short wave, wavePos, waveLen; unsigned char waveMode; short loadWave, loadPos, loadLen; unsigned char loadMode; - bool active, insChanged, freqChanged, volumeChanged, waveChanged, waveUpdated, keyOn, keyOff, inPorta; - signed char vol, outVol, resVol; - DivMacroInt std; + bool volumeChanged; + bool waveChanged, waveUpdated; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), + SharedChannel(15), + resVol(15), wave(-1), wavePos(0), waveLen(0), @@ -56,18 +46,9 @@ class DivPlatformN163: public DivDispatch { loadPos(0), loadLen(0), loadMode(0), - active(false), - insChanged(true), - freqChanged(false), volumeChanged(false), waveChanged(false), - waveUpdated(false), - keyOn(false), - keyOff(false), - inPorta(false), - vol(15), - outVol(15), - resVol(15) {} + waveUpdated(false) {} }; Channel chan[8]; DivDispatchOscBuffer* oscBuf[8]; diff --git a/src/engine/platform/namcowsg.h b/src/engine/platform/namcowsg.h index fdc863467..127f84aa4 100644 --- a/src/engine/platform/namcowsg.h +++ b/src/engine/platform/namcowsg.h @@ -22,40 +22,19 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "../waveSynth.h" #include "sound/namco.h" class DivPlatformNamcoWSG: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note; - int ins; + struct Channel: public SharedChannel { unsigned char pan; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, noise; - signed char vol, outVol, wave; - DivMacroInt std; + bool noise; + signed short wave; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), + SharedChannel(15), pan(255), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), noise(false), - vol(15), - outVol(15), wave(-1) {} }; Channel chan[8]; diff --git a/src/engine/platform/nes.h b/src/engine/platform/nes.h index 4dbfcec37..d9f43e915 100644 --- a/src/engine/platform/nes.h +++ b/src/engine/platform/nes.h @@ -21,44 +21,23 @@ #define _NES_H #include "../dispatch.h" -#include "../macroInt.h" #include "sound/nes_nsfplay/nes_apu.h" class DivPlatformNES: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, prevFreq, note, ins; + struct Channel: public SharedChannel { + int prevFreq; unsigned char duty, sweep, envMode, len; - bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac; - signed char vol, outVol, wave; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + bool sweepChanged, furnaceDac; Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(15), prevFreq(65535), - note(0), - ins(-1), duty(0), sweep(8), envMode(3), len(0x1f), - active(false), - insChanged(true), - freqChanged(false), sweepChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - furnaceDac(false), - vol(15), - outVol(15), - wave(-1) {} + furnaceDac(false) {} }; Channel chan[5]; DivDispatchOscBuffer* oscBuf[5]; diff --git a/src/engine/platform/opl.h b/src/engine/platform/opl.h index b8dee3945..f4a6788cb 100644 --- a/src/engine/platform/opl.h +++ b/src/engine/platform/opl.h @@ -19,8 +19,8 @@ #ifndef _OPL_H #define _OPL_H + #include "../dispatch.h" -#include "../macroInt.h" #include #include "../../../extern/opl/opl3.h" #include "sound/ymfm/ymfm_adpcm.h" @@ -36,41 +36,22 @@ class DivOPLAInterface: public ymfm::ymfm_interface { class DivPlatformOPL: public DivDispatch { protected: - struct Channel { + struct Channel: public SharedChannel { DivInstrumentFM state; - DivMacroInt std; unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, note, ins, sample, fixedFreq; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, furnacePCM, inPorta, fourOp, hardReset; - int vol, outVol; + int sample, fixedFreq; + bool furnacePCM, fourOp, hardReset; unsigned char pan; int macroVolMul; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): + SharedChannel(0), freqH(0), freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), sample(-1), fixedFreq(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), furnacePCM(false), - inPorta(false), fourOp(false), hardReset(false), - vol(0), pan(3), macroVolMul(64) { state.ops=2; diff --git a/src/engine/platform/opll.h b/src/engine/platform/opll.h index 8dd8743de..a1eb70048 100644 --- a/src/engine/platform/opll.h +++ b/src/engine/platform/opll.h @@ -19,8 +19,8 @@ #ifndef _OPLL_H #define _OPLL_H + #include "../dispatch.h" -#include "../macroInt.h" #include extern "C" { @@ -29,37 +29,18 @@ extern "C" { class DivPlatformOPLL: public DivDispatch { protected: - struct Channel { + struct Channel: public SharedChannel { DivInstrumentFM state; - DivMacroInt std; unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, note, ins, fixedFreq; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, furnaceDac, inPorta; - int vol, outVol; + int fixedFreq; + bool furnaceDac; unsigned char pan; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): + SharedChannel(0), freqH(0), freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), fixedFreq(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), furnaceDac(false), - inPorta(false), - vol(0), pan(3) {} }; Channel chan[11]; diff --git a/src/engine/platform/pce.h b/src/engine/platform/pce.h index 5645586be..7a417a2a2 100644 --- a/src/engine/platform/pce.h +++ b/src/engine/platform/pce.h @@ -22,32 +22,22 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "../waveSynth.h" #include "sound/pce_psg.h" class DivPlatformPCE: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, antiClickPeriodCount, antiClickWavePos; + struct Channel: public SharedChannel { + int antiClickPeriodCount, antiClickWavePos; int dacPeriod, dacRate, dacOut; unsigned int dacPos; - int dacSample, ins; + int dacSample; unsigned char pan; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, noise, pcm, furnaceDac, deferredWaveUpdate; - signed char vol, outVol, wave; + bool noise, pcm, furnaceDac, deferredWaveUpdate; + signed short wave; int macroVolMul; - DivMacroInt std; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), + SharedChannel(31), antiClickPeriodCount(0), antiClickWavePos(0), dacPeriod(0), @@ -55,20 +45,11 @@ class DivPlatformPCE: public DivDispatch { dacOut(0), dacPos(0), dacSample(-1), - ins(-1), pan(255), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), noise(false), pcm(false), furnaceDac(false), deferredWaveUpdate(false), - vol(31), - outVol(31), wave(-1), macroVolMul(31) {} }; diff --git a/src/engine/platform/pcmdac.h b/src/engine/platform/pcmdac.h index 46b9e2247..7a16ec547 100644 --- a/src/engine/platform/pcmdac.h +++ b/src/engine/platform/pcmdac.h @@ -22,33 +22,22 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "../waveSynth.h" class DivPlatformPCMDAC: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2; + struct Channel: public SharedChannel { bool audDir; unsigned int audLoc; unsigned short audLen; int audPos; int audSub; - int sample, wave, ins; - int note; + int sample, wave; int panL, panR; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, useWave, setPos; - int vol, envVol; - DivMacroInt std; + bool useWave, setPos; + int envVol; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(255), audDir(false), audLoc(0), audLen(0), @@ -56,19 +45,10 @@ class DivPlatformPCMDAC: public DivDispatch { audSub(0), sample(-1), wave(-1), - ins(-1), - note(0), panL(255), panR(255), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), useWave(false), setPos(false), - vol(255), envVol(64) {} }; Channel chan; diff --git a/src/engine/platform/pcspkr.h b/src/engine/platform/pcspkr.h index 9d84c2104..b3028d784 100644 --- a/src/engine/platform/pcspkr.h +++ b/src/engine/platform/pcspkr.h @@ -21,43 +21,15 @@ #define _PCSPKR_H #include "../dispatch.h" -#include "../macroInt.h" #include #include #include #include class DivPlatformPCSpeaker: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; - unsigned char duty, sweep; - bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac; - signed char vol, outVol, wave; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + struct Channel: public SharedChannel { Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - duty(0), - sweep(8), - active(false), - insChanged(true), - freqChanged(false), - sweepChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - furnaceDac(false), - vol(15), - outVol(15), - wave(-1) {} + SharedChannel(15) {} }; Channel chan[1]; DivDispatchOscBuffer* oscBuf; diff --git a/src/engine/platform/pet.h b/src/engine/platform/pet.h index 17c0686f5..46c565562 100644 --- a/src/engine/platform/pet.h +++ b/src/engine/platform/pet.h @@ -21,37 +21,17 @@ #define _PET_H #include "../dispatch.h" -#include "../macroInt.h" class DivPlatformPET: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, enable; - int vol, outVol, wave; + struct Channel: public SharedChannel { + bool enable; + int wave; unsigned char sreg; int cnt; short out; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), + SharedChannel(1), enable(false), - vol(1), - outVol(1), wave(0b00001111), sreg(0), cnt(0), diff --git a/src/engine/platform/pokemini.cpp b/src/engine/platform/pokemini.cpp new file mode 100644 index 000000000..bcbe73bb9 --- /dev/null +++ b/src/engine/platform/pokemini.cpp @@ -0,0 +1,315 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "pokemini.h" +#include "../engine.h" +#include "../../ta-log.h" +#include + +#define PCSPKR_DIVIDER 16 +#define CHIP_DIVIDER 1 + +const char* regCheatSheetPokeMini[]={ + "Period", "0", + NULL +}; + +const short volTable[4]={ + 0, 16384, 16384, 32767 +}; + +const short scaleTable[8]={ + 1, 7, 31, 63, 127, 255, 1023, 4095 +}; + +const char** DivPlatformPokeMini::getRegisterSheet() { + return regCheatSheetPokeMini; +} + +void DivPlatformPokeMini::acquire(short* bufL, short* bufR, size_t start, size_t len) { + int out=0; + for (size_t i=start; i=pivot && !isMuted[0])?volTable[vol&3]:0; + bufL[i]=out; + oscBuf->data[oscBuf->needle++]=out; + } else { + bufL[i]=0; + oscBuf->data[oscBuf->needle++]=0; + } + } +} + +void DivPlatformPokeMini::tick(bool sysTick) { + for (int i=0; i<1; i++) { + chan[i].std.next(); + if (chan[i].std.vol.had) { + chan[i].outVol=VOL_SCALE_LINEAR(chan[i].vol,chan[i].std.vol.val,3); + vol=(chan[i].outVol==2)?3:chan[i].outVol; + } + if (chan[i].std.arp.had) { + if (!chan[i].inPorta) { + chan[i].baseFreq=NOTE_PERIODIC(parent->calcArp(chan[i].note,chan[i].std.arp.val)); + } + chan[i].freqChanged=true; + } + if (chan[i].std.duty.had) { + chan[i].duty=chan[i].std.duty.val; + chan[i].freqChanged=true; + } + if (chan[i].std.pitch.had) { + if (chan[i].std.pitch.mode) { + chan[i].pitch2+=chan[i].std.pitch.val; + CLAMP_VAR(chan[i].pitch2,-32768,32767); + } else { + chan[i].pitch2=chan[i].std.pitch.val; + } + chan[i].freqChanged=true; + } + if (chan[i].freqChanged || chan[i].keyOn || chan[i].keyOff) { + chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true,0,chan[i].pitch2,chipClock,CHIP_DIVIDER)-1; + if (chan[i].freq<0) chan[i].freq=0; + if (chan[i].freq>65535) chan[i].freq=65535; + if (chan[i].keyOn) { + on=true; + } + if (chan[i].keyOff) { + on=false; + } + preset=chan[i].freq; + pivot=(chan[i].duty*preset)>>8; + if (chan[i].keyOn) chan[i].keyOn=false; + if (chan[i].keyOff) chan[i].keyOff=false; + chan[i].freqChanged=false; + } + } +} + +int DivPlatformPokeMini::dispatch(DivCommand c) { + switch (c.cmd) { + case DIV_CMD_NOTE_ON: + if (c.value!=DIV_NOTE_NULL) { + chan[c.chan].baseFreq=NOTE_PERIODIC(c.value); + chan[c.chan].freqChanged=true; + chan[c.chan].note=c.value; + } + vol=(chan[c.chan].outVol==2)?3:chan[c.chan].outVol; + chan[c.chan].active=true; + chan[c.chan].keyOn=true; + chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_BEEPER)); + if (!parent->song.brokenOutVol && !chan[c.chan].std.vol.will) { + chan[c.chan].outVol=chan[c.chan].vol; + } + break; + case DIV_CMD_NOTE_OFF: + chan[c.chan].active=false; + chan[c.chan].keyOff=true; + chan[c.chan].macroInit(NULL); + break; + case DIV_CMD_NOTE_OFF_ENV: + case DIV_CMD_ENV_RELEASE: + chan[c.chan].std.release(); + break; + case DIV_CMD_INSTRUMENT: + if (chan[c.chan].ins!=c.value || c.value2==1) { + chan[c.chan].ins=c.value; + } + break; + case DIV_CMD_VOLUME: + if (chan[c.chan].vol!=c.value) { + chan[c.chan].vol=c.value; + if (!chan[c.chan].std.vol.has) { + chan[c.chan].outVol=c.value; + } + if (chan[c.chan].active) { + on=chan[c.chan].vol; + } + } + break; + case DIV_CMD_GET_VOLUME: + return chan[c.chan].vol; + break; + case DIV_CMD_PITCH: + chan[c.chan].pitch=c.value; + chan[c.chan].freqChanged=true; + break; + case DIV_CMD_NOTE_PORTA: { + int destFreq=NOTE_PERIODIC(c.value2); + bool return2=false; + if (destFreq>chan[c.chan].baseFreq) { + chan[c.chan].baseFreq+=c.value; + if (chan[c.chan].baseFreq>=destFreq) { + chan[c.chan].baseFreq=destFreq; + return2=true; + } + } else { + chan[c.chan].baseFreq-=c.value; + if (chan[c.chan].baseFreq<=destFreq) { + chan[c.chan].baseFreq=destFreq; + return2=true; + } + } + chan[c.chan].freqChanged=true; + if (return2) { + chan[c.chan].inPorta=false; + return 2; + } + break; + } + case DIV_CMD_LEGATO: + if (c.chan==3) break; + chan[c.chan].baseFreq=NOTE_PERIODIC(c.value+((chan[c.chan].std.arp.will && !chan[c.chan].std.arp.mode)?(chan[c.chan].std.arp.val):(0))); + chan[c.chan].freqChanged=true; + chan[c.chan].note=c.value; + break; + case DIV_CMD_PRE_PORTA: + if (chan[c.chan].active && c.value2) { + if (parent->song.resetMacroOnPorta) chan[c.chan].macroInit(parent->getIns(chan[c.chan].ins,DIV_INS_BEEPER)); + } + if (!chan[c.chan].inPorta && c.value && !parent->song.brokenPortaArp && chan[c.chan].std.arp.will) chan[c.chan].baseFreq=NOTE_PERIODIC(chan[c.chan].note); + chan[c.chan].inPorta=c.value; + break; + case DIV_CMD_GET_VOLMAX: + return 2; + break; + case DIV_ALWAYS_SET_VOLUME: + return 1; + break; + default: + break; + } + return 1; +} + +void DivPlatformPokeMini::muteChannel(int ch, bool mute) { + isMuted[ch]=mute; +} + +void DivPlatformPokeMini::forceIns() { + for (int i=0; i<1; i++) { + chan[i].insChanged=true; + } +} + +void* DivPlatformPokeMini::getChanState(int ch) { + return &chan[ch]; +} + +DivMacroInt* DivPlatformPokeMini::getChanMacroInt(int ch) { + return &chan[ch].std; +} + +DivDispatchOscBuffer* DivPlatformPokeMini::getOscBuffer(int ch) { + return oscBuf; +} + +unsigned char* DivPlatformPokeMini::getRegisterPool() { + if (on) { + regPool[0]=preset; + regPool[1]=preset>>8; + } else { + regPool[0]=0; + regPool[1]=0; + } + return regPool; +} + +int DivPlatformPokeMini::getRegisterPoolSize() { + return 2; +} + +void DivPlatformPokeMini::reset() { + for (int i=0; i<1; i++) { + chan[i]=DivPlatformPokeMini::Channel(); + chan[i].std.setEngine(parent); + } + if (dumpWrites) { + addWrite(0xffffffff,0); + } + + on=false; + preset=0; + pivot=0; + pos=0; + timerScale=0; + vol=0; + preset=0; + pivot=0; + elapsedMain=0; + + memset(regPool,0,2); +} + +bool DivPlatformPokeMini::keyOffAffectsArp(int ch) { + return true; +} + +void DivPlatformPokeMini::setFlags(const DivConfig& flags) { + chipClock=4000000; + CHECK_CUSTOM_CLOCK; + + rate=chipClock/PCSPKR_DIVIDER; + oscBuf->rate=rate; +} + +void DivPlatformPokeMini::notifyInsDeletion(void* ins) { + for (int i=0; i<1; i++) { + chan[i].std.notifyInsDeletion((DivInstrument*)ins); + } +} + +void DivPlatformPokeMini::poke(unsigned int addr, unsigned short val) { + // ??? +} + +void DivPlatformPokeMini::poke(std::vector& wlist) { + // ??? +} + +int DivPlatformPokeMini::init(DivEngine* p, int channels, int sugRate, const DivConfig& flags) { + parent=p; + dumpWrites=false; + skipRegisterWrites=false; + for (int i=0; i<1; i++) { + isMuted[i]=false; + } + oscBuf=new DivDispatchOscBuffer; + setFlags(flags); + + reset(); + return 5; +} + +void DivPlatformPokeMini::quit() { + delete oscBuf; +} + +DivPlatformPokeMini::~DivPlatformPokeMini() { +} diff --git a/src/engine/platform/pokemini.h b/src/engine/platform/pokemini.h new file mode 100644 index 000000000..b310de739 --- /dev/null +++ b/src/engine/platform/pokemini.h @@ -0,0 +1,69 @@ +/** + * Furnace Tracker - multi-system chiptune tracker + * Copyright (C) 2021-2022 tildearrow and contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef _POKEMINI_H +#define _POKEMINI_H + +#include "../dispatch.h" +#include "../macroInt.h" + +class DivPlatformPokeMini: public DivDispatch { + struct Channel: public SharedChannel { + unsigned char duty; + Channel(): + SharedChannel(2), + duty(128) {} + }; + Channel chan[1]; + DivDispatchOscBuffer* oscBuf; + bool isMuted[1]; + bool on; + int pos; + unsigned char timerScale, vol; + unsigned short preset, pivot; + unsigned char regPool[2]; + unsigned short elapsedMain; + + friend void putDispatchChip(void*,int); + friend void putDispatchChan(void*,int,int); + + public: + void acquire(short* bufL, short* bufR, size_t start, size_t len); + int dispatch(DivCommand c); + void* getChanState(int chan); + DivMacroInt* getChanMacroInt(int ch); + DivDispatchOscBuffer* getOscBuffer(int chan); + unsigned char* getRegisterPool(); + int getRegisterPoolSize(); + void reset(); + void forceIns(); + void tick(bool sysTick=true); + void muteChannel(int ch, bool mute); + bool keyOffAffectsArp(int ch); + void setFlags(const DivConfig& flags); + void notifyInsDeletion(void* ins); + void poke(unsigned int addr, unsigned short val); + void poke(std::vector& wlist); + const char** getRegisterSheet(); + int init(DivEngine* parent, int channels, int sugRate, const DivConfig& flags); + void quit(); + ~DivPlatformPokeMini(); +}; + +#endif diff --git a/src/engine/platform/pong.h b/src/engine/platform/pong.h index afce74506..835809f5c 100644 --- a/src/engine/platform/pong.h +++ b/src/engine/platform/pong.h @@ -21,39 +21,11 @@ #define _PONG_H #include "../dispatch.h" -#include "../macroInt.h" class DivPlatformPong: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; - unsigned char duty, sweep; - bool active, insChanged, freqChanged, sweepChanged, keyOn, keyOff, inPorta, furnaceDac; - signed char vol, outVol, wave; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + struct Channel: public SharedChannel { Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - duty(0), - sweep(8), - active(false), - insChanged(true), - freqChanged(false), - sweepChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - furnaceDac(false), - vol(1), - outVol(1), - wave(-1) {} + SharedChannel(1) {} }; Channel chan[1]; DivDispatchOscBuffer* oscBuf; diff --git a/src/engine/platform/qsound.h b/src/engine/platform/qsound.h index d141d5911..18eb886b4 100644 --- a/src/engine/platform/qsound.h +++ b/src/engine/platform/qsound.h @@ -22,45 +22,24 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "sound/qsound.h" class DivPlatformQSound: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2; - int sample, wave, ins; - int note; + struct Channel: public SharedChannel { + int resVol; + int sample, wave; int panning; int echo; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, useWave, surround, isNewQSound; - int vol, outVol, resVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + bool useWave, surround, isNewQSound; Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(255), + resVol(4095), sample(-1), - ins(-1), - note(0), panning(0x10), echo(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), useWave(false), surround(true), - isNewQSound(false), - vol(255), - outVol(255), - resVol(4096) {} + isNewQSound(false) {} }; Channel chan[19]; DivDispatchOscBuffer* oscBuf[19]; diff --git a/src/engine/platform/rf5c68.h b/src/engine/platform/rf5c68.h index 5af36c035..c22688c3b 100644 --- a/src/engine/platform/rf5c68.h +++ b/src/engine/platform/rf5c68.h @@ -22,43 +22,21 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "sound/rf5c68.h" class DivPlatformRF5C68: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2; + struct Channel: public SharedChannel { unsigned int audPos; - int sample, wave, ins; - int note; + int sample, wave; int panning; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, setPos; - int vol, outVol; + bool setPos; int macroVolMul; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(255), audPos(0), sample(-1), - ins(-1), - note(0), panning(255), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), setPos(false), - vol(255), - outVol(255), macroVolMul(64) {} }; Channel chan[8]; diff --git a/src/engine/platform/saa.h b/src/engine/platform/saa.h index 6bae715ed..055a0979f 100644 --- a/src/engine/platform/saa.h +++ b/src/engine/platform/saa.h @@ -19,27 +19,23 @@ #ifndef _SAA_H #define _SAA_H + #include "../dispatch.h" -#include "../macroInt.h" #include #include "../../../extern/SAASound/src/SAASound.h" class DivPlatformSAA1099: public DivDispatch { protected: - struct Channel { + struct Channel: public SharedChannel { unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, note, ins; unsigned char psgMode; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta; - int vol, outVol; unsigned char pan; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } - Channel(): freqH(0), freqL(0), freq(0), baseFreq(0), pitch(0), pitch2(0), note(0), ins(-1), psgMode(1), active(false), insChanged(true), freqChanged(false), keyOn(false), keyOff(false), portaPause(false), inPorta(false), vol(0), outVol(15), pan(255) {} + Channel(): + SharedChannel(15), + freqH(0), + freqL(0), + psgMode(1), + pan(255) {} }; Channel chan[6]; DivDispatchOscBuffer* oscBuf[6]; diff --git a/src/engine/platform/scc.h b/src/engine/platform/scc.h index ed8865476..5c4db4e28 100644 --- a/src/engine/platform/scc.h +++ b/src/engine/platform/scc.h @@ -22,36 +22,18 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "../waveSynth.h" #include "vgsound_emu/src/scc/scc.hpp" class DivPlatformSCC: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; - bool active, insChanged, freqChanged, freqInit, inPorta; - signed char vol, outVol, wave; - signed char waveROM[32] = {0}; // 4 bit PROM per channel on bubble system - DivMacroInt std; + struct Channel: public SharedChannel { + bool freqInit; + signed short wave; + signed char waveROM[32] = {0}; // 8 bit signed waveform DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), + SharedChannel(15), freqInit(false), - inPorta(false), - vol(15), - outVol(15), wave(-1) {} }; Channel chan[5]; diff --git a/src/engine/platform/segapcm.h b/src/engine/platform/segapcm.h index 2ed15eae8..0c99a20ca 100644 --- a/src/engine/platform/segapcm.h +++ b/src/engine/platform/segapcm.h @@ -19,18 +19,15 @@ #ifndef _SEGAPCM_H #define _SEGAPCM_H + #include "../dispatch.h" #include "../instrument.h" #include -#include "../macroInt.h" class DivPlatformSegaPCM: public DivDispatch { protected: - struct Channel { - DivMacroInt std; - int freq, baseFreq, pitch, pitch2, note, ins; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, portaPause, furnacePCM, isNewSegaPCM; - int vol, outVol; + struct Channel: public SharedChannel { + bool furnacePCM, isNewSegaPCM; unsigned char chVolL, chVolR; unsigned char chPanL, chPanR; int macroVolMul; @@ -42,28 +39,10 @@ class DivPlatformSegaPCM: public DivDispatch { unsigned char freq; PCMChannel(): sample(-1), pos(0), len(0), freq(0) {} } pcm; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - portaPause(false), + SharedChannel(127), furnacePCM(false), isNewSegaPCM(false), - vol(0), - outVol(0), chVolL(127), chVolR(127), chPanL(127), diff --git a/src/engine/platform/sms.h b/src/engine/platform/sms.h index 41f0efe48..7bb3b1b16 100644 --- a/src/engine/platform/sms.h +++ b/src/engine/platform/sms.h @@ -21,7 +21,6 @@ #define _SMS_H #include "../dispatch.h" -#include "../macroInt.h" #include "sound/sn76496.h" extern "C" { #include "../../../extern/Nuked-PSG/ympsg.h" @@ -29,32 +28,13 @@ extern "C" { #include class DivPlatformSMS: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, actualNote, ins; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, writeVol; - signed char vol, outVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + struct Channel: public SharedChannel { + int actualNote; + bool writeVol; Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), + SharedChannel(15), actualNote(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - writeVol(false), - vol(15), - outVol(15) {} + writeVol(false) {} }; Channel chan[4]; DivDispatchOscBuffer* oscBuf[4]; diff --git a/src/engine/platform/snes.h b/src/engine/platform/snes.h index ed8bfbf32..8d5e25311 100644 --- a/src/engine/platform/snes.h +++ b/src/engine/platform/snes.h @@ -21,46 +21,26 @@ #define _SNES_H #include "../dispatch.h" -#include "../macroInt.h" #include "../waveSynth.h" #include #include "sound/snes/SPC_DSP.h" class DivPlatformSNES: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2; + struct Channel: public SharedChannel { unsigned int audPos; - int sample, wave, ins; - int note; + int sample, wave; int panL, panR; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, useWave, setPos, noise, echo, pitchMod, invertL, invertR, shallWriteVol, shallWriteEnv; - int vol, outVol; + bool useWave, setPos, noise, echo, pitchMod, invertL, invertR, shallWriteVol, shallWriteEnv; int wtLen; DivInstrumentSNES state; - DivMacroInt std; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(127), audPos(0), sample(-1), wave(-1), - ins(-1), - note(0), panL(127), panR(127), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), useWave(false), setPos(false), noise(false), @@ -70,8 +50,6 @@ class DivPlatformSNES: public DivDispatch { invertR(false), shallWriteVol(false), shallWriteEnv(false), - vol(127), - outVol(127), wtLen(16) {} }; Channel chan[8]; diff --git a/src/engine/platform/sound/ymfm/README.md b/src/engine/platform/sound/ymfm/README.md index 788b99015..40e64f19e 100644 --- a/src/engine/platform/sound/ymfm/README.md +++ b/src/engine/platform/sound/ymfm/README.md @@ -4,7 +4,7 @@ # modified version -this is a modified version of ymfm with a small bug fix. +this is a modified version which contains many fixes. ## Supported environments diff --git a/src/engine/platform/sound/ymfm/ymfm.h b/src/engine/platform/sound/ymfm/ymfm.h index 7b98f8499..47ff90072 100644 --- a/src/engine/platform/sound/ymfm/ymfm.h +++ b/src/engine/platform/sound/ymfm/ymfm.h @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -325,6 +326,86 @@ struct ymfm_output }; +// ======================> ymfm_wavfile + +// this class is a debugging helper that accumulates data and writes it to wav files +template +class ymfm_wavfile +{ +public: + // construction + ymfm_wavfile(uint32_t samplerate = 44100) : + m_samplerate(samplerate) + { + } + + // configuration + ymfm_wavfile &set_index(uint32_t index) { m_index = index; return *this; } + ymfm_wavfile &set_samplerate(uint32_t samplerate) { m_samplerate = samplerate; return *this; } + + // destruction + ~ymfm_wavfile() + { + if (!m_buffer.empty()) + { + // create file + char name[20]; + sprintf(name, "wavlog-%02d.wav", m_index); + FILE *out = fopen(name, "wb"); + + // make the wav file header + uint8_t header[44]; + memcpy(&header[0], "RIFF", 4); + *(uint32_t *)&header[4] = m_buffer.size() * 2 + 44 - 8; + memcpy(&header[8], "WAVE", 4); + memcpy(&header[12], "fmt ", 4); + *(uint32_t *)&header[16] = 16; + *(uint16_t *)&header[20] = 1; + *(uint16_t *)&header[22] = Channels; + *(uint32_t *)&header[24] = m_samplerate; + *(uint32_t *)&header[28] = m_samplerate * 2 * Channels; + *(uint16_t *)&header[32] = 2 * Channels; + *(uint16_t *)&header[34] = 16; + memcpy(&header[36], "data", 4); + *(uint32_t *)&header[40] = m_buffer.size() * 2 + 44 - 44; + + // write header then data + fwrite(&header[0], 1, sizeof(header), out); + fwrite(&m_buffer[0], 2, m_buffer.size(), out); + fclose(out); + } + } + + // add data to the file + template + void add(ymfm_output output) + { + int16_t sum[Channels] = { 0 }; + for (int index = 0; index < Outputs; index++) + sum[index % Channels] += output.data[index]; + for (int index = 0; index < Channels; index++) + m_buffer.push_back(sum[index]); + } + + // add data to the file, using a reference + template + void add(ymfm_output output, ymfm_output const &ref) + { + int16_t sum[Channels] = { 0 }; + for (int index = 0; index < Outputs; index++) + sum[index % Channels] += output.data[index] - ref.data[index]; + for (int index = 0; index < Channels; index++) + m_buffer.push_back(sum[index]); + } + +private: + // internal state + uint32_t m_index; + uint32_t m_samplerate; + std::vector m_buffer; +}; + + // ======================> ymfm_saved_state // this class contains a managed vector of bytes that is used to save and diff --git a/src/engine/platform/sound/ymfm/ymfm_adpcm.cpp b/src/engine/platform/sound/ymfm/ymfm_adpcm.cpp index 76839e787..6d7eb710c 100644 --- a/src/engine/platform/sound/ymfm/ymfm_adpcm.cpp +++ b/src/engine/platform/sound/ymfm/ymfm_adpcm.cpp @@ -465,48 +465,60 @@ void adpcm_b_channel::clock() if (position < 0x10000) return; - // if playing from RAM/ROM, check the end address and process - if (m_regs.external()) + // if we're about to process nibble 0, fetch sample + if (m_curnibble == 0) { - // wrap at the limit address - if (at_limit()) - m_curaddress = 0; - - // handle the sample end, either repeating or stopping - if (at_end()) - { - // if repeating, go back to the start - if (m_regs.repeat()) - load_start(); - - // otherwise, done; set the EOS bit and return - else - { - m_accumulator = 0; - m_prev_accum = 0; - m_status = (m_status & ~STATUS_PLAYING) | STATUS_EOS; - debug::log_keyon("%s\n", "ADPCM EOS"); - return; - } - } - - // if we're about to process nibble 0, fetch and increment - if (m_curnibble == 0) - { - m_curbyte = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_B, m_curaddress++); - m_curaddress &= 0xffffff; - } + // playing from RAM/ROM + if (m_regs.external()) + m_curbyte = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_B, m_curaddress); } // extract the nibble from our current byte uint8_t data = uint8_t(m_curbyte << (4 * m_curnibble)) >> 4; m_curnibble ^= 1; - // if CPU-driven and we just processed the last nibble, copy the next byte and request more - if (m_curnibble == 0 && !m_regs.external()) + // we just processed the last nibble + if (m_curnibble == 0) { - m_curbyte = m_regs.cpudata(); - m_status |= STATUS_BRDY; + // if playing from RAM/ROM, check the end/limit address or advance + if (m_regs.external()) + { + // handle the sample end, either repeating or stopping + if (at_end()) + { + // if repeating, go back to the start + if (m_regs.repeat()) + load_start(); + + // otherwise, done; set the EOS bit + else + { + m_accumulator = 0; + m_prev_accum = 0; + m_status = (m_status & ~STATUS_PLAYING) | STATUS_EOS; + debug::log_keyon("%s\n", "ADPCM EOS"); + return; + } + } + + // wrap at the limit address + else if (at_limit()) + m_curaddress = 0; + + // otherwise, advance the current address + else + { + m_curaddress++; + m_curaddress &= 0xffffff; + } + } + + // if CPU-driven, copy the next byte and request more + else + { + m_curbyte = m_regs.cpudata(); + m_status |= STATUS_BRDY; + } } // remember previous value for interpolation @@ -574,18 +586,27 @@ uint8_t adpcm_b_channel::read(uint32_t regnum) m_dummy_read--; } - // did we hit the end? if so, signal EOS - if (at_end()) - { - m_status = STATUS_EOS | STATUS_BRDY; - debug::log_keyon("%s\n", "ADPCM EOS"); - } - - // otherwise, write the data and signal ready + // read the data else { + // read from outside of the chip result = m_owner.intf().ymfm_external_read(ACCESS_ADPCM_B, m_curaddress++); - m_status = STATUS_BRDY; + + // did we hit the end? if so, signal EOS + if (at_end()) + { + m_status = STATUS_EOS | STATUS_BRDY; + debug::log_keyon("%s\n", "ADPCM EOS"); + } + else + { + // signal ready + m_status = STATUS_BRDY; + } + + // wrap at the limit address + if (at_limit()) + m_curaddress = 0; } } return result; diff --git a/src/engine/platform/sound/ymfm/ymfm_adpcm.h b/src/engine/platform/sound/ymfm/ymfm_adpcm.h index 58bee8a22..f80e6ab9e 100644 --- a/src/engine/platform/sound/ymfm/ymfm_adpcm.h +++ b/src/engine/platform/sound/ymfm/ymfm_adpcm.h @@ -351,11 +351,11 @@ private: // load the start address void load_start(); - // limit checker - bool at_limit() const { return (m_curaddress >> address_shift()) >= m_regs.limit(); } + // limit checker; stops at the last byte of the chunk described by address_shift() + bool at_limit() const { return (m_curaddress == (((m_regs.limit() + 1) << address_shift()) - 1)); } - // end checker - bool at_end() const { return (m_curaddress >> address_shift()) > m_regs.end(); } + // end checker; stops at the last byte of the chunk described by address_shift() + bool at_end() const { return (m_curaddress == (((m_regs.end() + 1) << address_shift()) - 1)); } // internal state uint32_t const m_address_shift; // address bits shift-left diff --git a/src/engine/platform/sound/ymfm/ymfm_fm.h b/src/engine/platform/sound/ymfm/ymfm_fm.h index 352ac9464..df3b486af 100644 --- a/src/engine/platform/sound/ymfm/ymfm_fm.h +++ b/src/engine/platform/sound/ymfm/ymfm_fm.h @@ -33,6 +33,8 @@ #pragma once +#define YMFM_DEBUG_LOG_WAVFILES (0) + namespace ymfm { @@ -162,8 +164,8 @@ template class fm_engine_base; template class fm_operator { - // "quiet" value, used to optimize when we can skip doing working - static constexpr uint32_t EG_QUIET = 0x200; + // "quiet" value, used to optimize when we can skip doing work + static constexpr uint32_t EG_QUIET = 0x380; public: // constructor @@ -206,6 +208,7 @@ public: // simple getters for debugging envelope_state debug_eg_state() const { return m_env_state; } uint16_t debug_eg_attenuation() const { return m_env_attenuation; } + uint8_t debug_ssg_inverted() const { return m_ssg_inverted; } opdata_cache &debug_cache() { return m_cache; } private: @@ -406,7 +409,14 @@ public: void set_clock_prescale(uint32_t prescale) { m_clock_prescale = prescale; } // compute sample rate - uint32_t sample_rate(uint32_t baseclock) const { return baseclock / (m_clock_prescale * OPERATORS); } + uint32_t sample_rate(uint32_t baseclock) const + { +#if (YMFM_DEBUG_LOG_WAVFILES) + for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) + m_wavfile[chnum].set_samplerate(baseclock / (m_clock_prescale * OPERATORS)); +#endif + return baseclock / (m_clock_prescale * OPERATORS); + } // return the owning device ymfm_interface &intf() const { return m_intf; } @@ -453,6 +463,9 @@ protected: RegisterType m_regs; // register accessor std::unique_ptr> m_channel[CHANNELS]; // channel pointers std::unique_ptr> m_operator[OPERATORS]; // operator pointers +#if (YMFM_DEBUG_LOG_WAVFILES) + mutable ymfm_wavfile<1> m_wavfile[CHANNELS]; // for debugging +#endif }; } diff --git a/src/engine/platform/sound/ymfm/ymfm_fm.ipp b/src/engine/platform/sound/ymfm/ymfm_fm.ipp index d532d7b2e..4fdff8a38 100644 --- a/src/engine/platform/sound/ymfm/ymfm_fm.ipp +++ b/src/engine/platform/sound/ymfm/ymfm_fm.ipp @@ -448,6 +448,8 @@ void fm_operator::clock(uint32_t env_counter, int32_t lfo_raw_pm) // clock the SSG-EG state (OPN/OPNA) if (m_regs.op_ssg_eg_enable(m_opoffs)) clock_ssg_eg_state(); + else + m_ssg_inverted = false; // clock the envelope if on an envelope cycle; env_counter is a x.2 value if (bitfield(env_counter, 0, 2) == 0) @@ -470,15 +472,6 @@ int32_t fm_operator::compute_volume(uint32_t phase, uint32_t am_of // the low 10 bits of phase represents a full 2*PI period over // the full sin wave -#if 0 -// temporary envelope logging -if (m_choffs == 0) -{ - printf(" %c@%02X:%03X", "PADSRV"[m_env_state], m_cache.eg_rate[m_env_state], envelope_attenuation(am_offset)); - if (m_opoffs == 0x18) printf("\n"); -} -#endif - // early out if the envelope is effectively off if (m_env_attenuation > EG_QUIET && m_cache.eg_shift == 0) return 0; @@ -896,6 +889,23 @@ void fm_channel::clock(uint32_t env_counter, int32_t lfo_raw_pm) for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++) if (m_op[opnum] != nullptr) m_op[opnum]->clock(env_counter, lfo_raw_pm); + +/* +useful temporary code for envelope debugging +if (m_choffs == 0x101) +{ + for (uint32_t opnum = 0; opnum < array_size(m_op); opnum++) + { + auto &op = *m_op[((opnum & 1) << 1) | ((opnum >> 1) & 1)]; + printf(" %c%03X%c%c ", + "PADSRV"[op.debug_eg_state()], + op.debug_eg_attenuation(), + op.debug_ssg_inverted() ? '-' : '+', + m_regs.op_ssg_eg_enable(op.opoffs()) ? '0' + m_regs.op_ssg_eg_mode(op.opoffs()) : ' '); + } +printf(" -- "); +} +*/ } @@ -943,7 +953,8 @@ void fm_channel::output_2op(output_data &output, uint32_t rshift, } else { - result = op1value + (m_op[1]->compute_volume(m_op[1]->phase(), am_offset) >> rshift); + result = (RegisterType::MODULATOR_DELAY ? m_feedback[1] : op1value) >> rshift; + result += m_op[1]->compute_volume(m_op[1]->phase(), am_offset) >> rshift; int32_t clipmin = -clipmax - 1; result = clamp(result, clipmin, clipmax); } @@ -1180,6 +1191,7 @@ fm_engine_base::fm_engine_base(ymfm_interface &intf) : m_irq_mask(STATUS_TIMERA | STATUS_TIMERB), m_irq_state(0), m_timer_running{0,0}, + m_total_clocks(0), m_active_channels(ALL_CHANNELS), m_modified_channels(ALL_CHANNELS), m_prepare_count(0) @@ -1195,6 +1207,11 @@ fm_engine_base::fm_engine_base(ymfm_interface &intf) : for (uint32_t opnum = 0; opnum < OPERATORS; opnum++) m_operator[opnum] = std::make_unique>(*this, RegisterType::operator_offset(opnum)); +#if (YMFM_DEBUG_LOG_WAVFILES) + for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) + m_wavfile[chnum].set_index(chnum); +#endif + // do the initial operator assignment assign_operators(); } @@ -1305,24 +1322,6 @@ uint32_t fm_engine_base::clock(uint32_t chanmask) if (bitfield(chanmask, chnum)) m_channel[chnum]->clock(m_env_counter, lfo_raw_pm); -#if 0 -//Temporary debugging... -static double curtime = 0; -//for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) -uint32_t chnum = 4; -{ - printf("t=%.4f ch%d: ", curtime, chnum); - for (uint32_t opnum = 0; opnum < 4; opnum++) - { - auto op = debug_channel(chnum)->debug_operator(opnum); - auto eg_state = op->debug_eg_state(); - printf(" %c%03X[%02X]%c ", "PADSRV"[eg_state], op.debug_eg_attenuation(), op.debug_cache().eg_rate[eg_state], m_regs.op_ssg_eg_enable(op.opoffs()) ? '*' : ' '); - } - printf(" -- "); -} -curtime += 1.0 / double(sample_rate(7670454)); -#endif - // return the envelope counter as it is used to clock ADPCM-A return m_env_counter; } @@ -1340,7 +1339,8 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, chanmask &= debug::GLOBAL_FM_CHANNEL_MASK; // mask out inactive channels - chanmask &= m_active_channels; + if (!YMFM_DEBUG_LOG_WAVFILES) + chanmask &= m_active_channels; // handle the rhythm case, where some of the operators are dedicated // to percussion (this is an OPL-specific feature) @@ -1358,6 +1358,9 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(chanmask, chnum)) { +#if (YMFM_DEBUG_LOG_WAVFILES) + auto reference = output; +#endif if (chnum == 6) m_channel[chnum]->output_rhythm_ch6(output, rshift, clipmax); else if (chnum == 7) @@ -1368,6 +1371,9 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, m_channel[chnum]->output_4op(output, rshift, clipmax); else m_channel[chnum]->output_2op(output, rshift, clipmax); +#if (YMFM_DEBUG_LOG_WAVFILES) + m_wavfile[chnum].add(output, reference); +#endif } } else @@ -1376,10 +1382,16 @@ void fm_engine_base::output(output_data &output, uint32_t rshift, for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(chanmask, chnum)) { +#if (YMFM_DEBUG_LOG_WAVFILES) + auto reference = output; +#endif if (m_channel[chnum]->is4op()) m_channel[chnum]->output_4op(output, rshift, clipmax); else m_channel[chnum]->output_2op(output, rshift, clipmax); +#if (YMFM_DEBUG_LOG_WAVFILES) + m_wavfile[chnum].add(output, reference); +#endif } } } @@ -1508,7 +1520,10 @@ void fm_engine_base::engine_timer_expired(uint32_t tnum) if (tnum == 0 && m_regs.csm()) for (uint32_t chnum = 0; chnum < CHANNELS; chnum++) if (bitfield(RegisterType::CSM_TRIGGER_MASK, chnum)) - m_channel[chnum]->keyonoff(1, KEYON_CSM, chnum); + { + m_channel[chnum]->keyonoff(0xf, KEYON_CSM, chnum); + m_modified_channels |= 1 << chnum; + } // reset m_timer_running[tnum] = false; diff --git a/src/engine/platform/sound/ymfm/ymfm_opn.cpp b/src/engine/platform/sound/ymfm/ymfm_opn.cpp index 00ac2cf63..053ad9770 100644 --- a/src/engine/platform/sound/ymfm/ymfm_opn.cpp +++ b/src/engine/platform/sound/ymfm/ymfm_opn.cpp @@ -146,7 +146,10 @@ bool opn_registers_base::write(uint16_t index, uint8_t data, uint32_t &c // borrow unused registers 0xb8-bf/0x1b8-bf as temporary holding locations if ((index & 0xf0) == 0xa0) { - uint32_t latchindex = 0xb8 | (bitfield(index, 3) << 2) | bitfield(index, 0, 2); + if (bitfield(index, 0, 2) == 3) + return false; + + uint32_t latchindex = 0xb8 | bitfield(index, 3); if (IsOpnA) latchindex |= index & 0x100; @@ -157,9 +160,16 @@ bool opn_registers_base::write(uint16_t index, uint8_t data, uint32_t &c // writes to the lower half only commit if the latch is there else if (bitfield(m_regdata[latchindex], 7)) { + m_regdata[index] = data; m_regdata[index | 4] = m_regdata[latchindex] & 0x3f; m_regdata[latchindex] = 0; } + return false; + } + else if ((index & 0xf8) == 0xb8) + { + // registers 0xb8-0xbf are used internally + return false; } // everything else is normal @@ -195,7 +205,12 @@ int32_t opn_registers_base::clock_noise_and_lfo() if (!IsOpnA || !lfo_enable()) { m_lfo_counter = 0; - m_lfo_am = 0; + + // special case: if LFO is disabled on OPNA, it basically just keeps the counter + // at 0; since position 0 gives an AM value of 0x3f, it is important to reflect + // that here; for example, MegaDrive Venom plays some notes with LFO globally + // disabled but enabling LFO on the operators, and it expects this added attenutation + m_lfo_am = IsOpnA ? 0x3f : 0x00; return 0; } @@ -417,10 +432,10 @@ std::string opn_registers_base::log_keyon(uint32_t choffs, uint32_t opof ch_output_1(choffs) ? 'R' : '-'); if (op_ssg_eg_enable(opoffs)) end += sprintf(end, " ssg=%X", op_ssg_eg_mode(opoffs)); - bool am = (lfo_enable() && op_lfo_am_enable(opoffs) && ch_lfo_am_sens(choffs) != 0); + bool am = (op_lfo_am_enable(opoffs) && ch_lfo_am_sens(choffs) != 0); if (am) end += sprintf(end, " am=%u", ch_lfo_am_sens(choffs)); - bool pm = (lfo_enable() && ch_lfo_pm_sens(choffs) != 0); + bool pm = (ch_lfo_pm_sens(choffs) != 0); if (pm) end += sprintf(end, " pm=%u", ch_lfo_pm_sens(choffs)); if (am || pm) @@ -1094,7 +1109,7 @@ uint8_t ym2608::read_status_hi() uint8_t ym2608::read_data_hi() { uint8_t result = 0; - if (m_address < 0x10) + if ((m_address & 0xff) < 0x10) { // 00-0F: Read from ADPCM-B result = m_adpcm_b.read(m_address & 0x0f); diff --git a/src/engine/platform/sound/ymfm/ymfm_opn.h b/src/engine/platform/sound/ymfm/ymfm_opn.h index 00fd61adf..2a9b92d5d 100644 --- a/src/engine/platform/sound/ymfm/ymfm_opn.h +++ b/src/engine/platform/sound/ymfm/ymfm_opn.h @@ -784,7 +784,7 @@ public: protected: // simulate the DAC discontinuity - int32_t dac_discontinuity(int32_t value) const { return (value < 0) ? (value - 2) : (value + 3); } + int32_t dac_discontinuity(int32_t value) const { return (value < 0) ? (value - 3) : (value + 4); } // internal state uint16_t m_address; // address register diff --git a/src/engine/platform/sound/ymfm/ymfm_ssg.cpp b/src/engine/platform/sound/ymfm/ymfm_ssg.cpp index 5a9a9d43e..77a62563b 100644 --- a/src/engine/platform/sound/ymfm/ymfm_ssg.cpp +++ b/src/engine/platform/sound/ymfm/ymfm_ssg.cpp @@ -201,19 +201,14 @@ void ssg_engine::output(output_data &output) for (int chan = 0; chan < 3; chan++) { // noise depends on the noise state, which is the LSB of m_noise_state - uint32_t noise_on = m_regs.ch_noise_enable(chan) & m_noise_state; + uint32_t noise_on = m_regs.ch_noise_enable_n(chan) | m_noise_state; // tone depends on the current tone state - uint32_t tone_on = m_regs.ch_tone_enable(chan) & m_tone_state[chan]; + uint32_t tone_on = m_regs.ch_tone_enable_n(chan) | m_tone_state[chan]; - // if envelope is enabled but tone and noise aren't, use the envelope - // volume + // if neither tone nor noise enabled, return 0 uint32_t volume; - if (m_regs.ch_envelope_enable(chan) && !m_regs.ch_noise_enable(chan) && !m_regs.ch_tone_enable(chan)) - volume = envelope_volume; - - // if neither tone nor noise enabled, return 0 - else if ((noise_on | tone_on) == 0) + if ((noise_on & tone_on) == 0) volume = 0; // if the envelope is enabled, use its amplitude diff --git a/src/engine/platform/sound/ymfm/ymfm_ssg.h b/src/engine/platform/sound/ymfm/ymfm_ssg.h index 55e748d6b..df974fe43 100644 --- a/src/engine/platform/sound/ymfm/ymfm_ssg.h +++ b/src/engine/platform/sound/ymfm/ymfm_ssg.h @@ -130,8 +130,8 @@ public: uint32_t io_b_data() const { return m_regdata[0x0f]; } // per-channel registers - uint32_t ch_noise_enable(uint32_t choffs) const { return bitfield(~m_regdata[0x07], 3 + choffs); } - uint32_t ch_tone_enable(uint32_t choffs) const { return bitfield(~m_regdata[0x07], 0 + choffs); } + uint32_t ch_noise_enable_n(uint32_t choffs) const { return bitfield(m_regdata[0x07], 3 + choffs); } + uint32_t ch_tone_enable_n(uint32_t choffs) const { return bitfield(m_regdata[0x07], 0 + choffs); } uint32_t ch_tone_period(uint32_t choffs) const { return m_regdata[0x00 + 2 * choffs] | (bitfield(m_regdata[0x01 + 2 * choffs], 0, 4) << 8); } uint32_t ch_envelope_enable(uint32_t choffs) const { return bitfield(m_regdata[0x08 + choffs], 4); } uint32_t ch_amplitude(uint32_t choffs) const { return bitfield(m_regdata[0x08 + choffs], 0, 4); } diff --git a/src/engine/platform/su.h b/src/engine/platform/su.h index bacdbc013..ebaa911b9 100644 --- a/src/engine/platform/su.h +++ b/src/engine/platform/su.h @@ -22,34 +22,22 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "sound/su.h" class DivPlatformSoundUnit: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note; - int ins, cutoff, baseCutoff, res, control, hasOffset; + struct Channel: public SharedChannel { + int cutoff, baseCutoff, res, control, hasOffset; signed char pan; unsigned char duty; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, noise, pcm, phaseReset, filterPhaseReset, switchRoles; + bool noise, pcm, phaseReset, filterPhaseReset, switchRoles; bool pcmLoop, timerSync, freqSweep, volSweep, cutSweep; unsigned short freqSweepP, volSweepP, cutSweepP; unsigned char freqSweepB, volSweepB, cutSweepB; unsigned char freqSweepV, volSweepV, cutSweepV; unsigned short syncTimer; - signed char vol, outVol, wave; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + signed short wave; Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), + SharedChannel(127), cutoff(16383), baseCutoff(16380), res(0), @@ -57,12 +45,6 @@ class DivPlatformSoundUnit: public DivDispatch { hasOffset(0), pan(0), duty(63), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), noise(false), pcm(false), phaseReset(false), @@ -83,8 +65,6 @@ class DivPlatformSoundUnit: public DivDispatch { volSweepV(0), cutSweepV(0), syncTimer(0), - vol(127), - outVol(127), wave(0) {} }; Channel chan[8]; diff --git a/src/engine/platform/swan.h b/src/engine/platform/swan.h index 8261e634a..b93f0859d 100644 --- a/src/engine/platform/swan.h +++ b/src/engine/platform/swan.h @@ -21,39 +21,18 @@ #define _SWAN_H #include "../dispatch.h" -#include "../macroInt.h" #include "../waveSynth.h" #include "sound/swan.h" #include class DivPlatformSwan: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; + struct Channel: public SharedChannel { unsigned char pan; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta; - int vol, outVol, wave; - DivMacroInt std; + int wave; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), + SharedChannel(15), pan(255), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - vol(15), - outVol(15), wave(-1) {} }; Channel chan[4]; diff --git a/src/engine/platform/t6w28.h b/src/engine/platform/t6w28.h index 2cd66f9fd..c526fd5d8 100644 --- a/src/engine/platform/t6w28.h +++ b/src/engine/platform/t6w28.h @@ -22,39 +22,16 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "sound/t6w28/T6W28_Apu.h" class DivPlatformT6W28: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note; - int ins; + struct Channel: public SharedChannel { unsigned char panL, panR, duty; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta; - signed char vol, outVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), + SharedChannel(15), panL(15), panR(15), - duty(7), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - vol(15), - outVol(15) {} + duty(7) {} }; Channel chan[4]; DivDispatchOscBuffer* oscBuf[4]; diff --git a/src/engine/platform/tia.h b/src/engine/platform/tia.h index 85bfcabe3..d60d41656 100644 --- a/src/engine/platform/tia.h +++ b/src/engine/platform/tia.h @@ -19,25 +19,18 @@ #ifndef _TIA_H #define _TIA_H + #include "../dispatch.h" -#include "../macroInt.h" #include #include "sound/tia/Audio.h" class DivPlatformTIA: public DivDispatch { protected: - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; + struct Channel: public SharedChannel { unsigned char shape; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta; - int vol, outVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } - Channel(): freq(0), baseFreq(0), pitch(0), pitch2(0), note(0), ins(-1), shape(4), active(false), insChanged(true), freqChanged(false), keyOn(false), keyOff(false), portaPause(false), inPorta(false), vol(0), outVol(15) {} + Channel(): + SharedChannel(15), + shape(4) {} }; Channel chan[2]; DivDispatchOscBuffer* oscBuf[2]; diff --git a/src/engine/platform/tx81z.h b/src/engine/platform/tx81z.h index 5b4b9f240..b180f28c5 100644 --- a/src/engine/platform/tx81z.h +++ b/src/engine/platform/tx81z.h @@ -19,9 +19,8 @@ #ifndef _TX81Z_H #define _TX81Z_H + #include "fmshared_OPM.h" -#include "../macroInt.h" -#include "../instrument.h" #include #include "sound/ymfm/ymfm_opz.h" @@ -35,41 +34,12 @@ class DivPlatformTX81Z: public DivPlatformOPM { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }; - struct Channel { - DivInstrumentFM state; - DivMacroInt std; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, note, ins; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, portaPause, furnacePCM, hardReset; - int vol, outVol; + struct Channel: public FMChannel { unsigned char chVolL, chVolR; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - portaPause(false), - furnacePCM(false), - hardReset(false), - vol(0), - outVol(0), - chVolL(127), - chVolR(127) {} + FMChannel(), + chVolL(1), + chVolR(1) {} }; Channel chan[8]; DivDispatchOscBuffer* oscBuf[8]; @@ -87,10 +57,8 @@ class DivPlatformTX81Z: public DivPlatformOPM { int octave(int freq); int toFreq(int freq); - + friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); - public: void acquire(short* bufL, short* bufR, size_t start, size_t len); int dispatch(DivCommand c); diff --git a/src/engine/platform/vb.h b/src/engine/platform/vb.h index baefc03f3..bcce42fee 100644 --- a/src/engine/platform/vb.h +++ b/src/engine/platform/vb.h @@ -22,43 +22,22 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "../waveSynth.h" #include "sound/vsu.h" class DivPlatformVB: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note; - int ins; + struct Channel: public SharedChannel { unsigned char pan, envLow, envHigh; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, noise, deferredWaveUpdate; - signed char vol, outVol, wave; - DivMacroInt std; + bool noise, deferredWaveUpdate; + signed short wave; DivWaveSynth ws; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), + SharedChannel(15), pan(255), envLow(0), envHigh(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), noise(false), deferredWaveUpdate(false), - vol(15), - outVol(15), wave(-1) {} }; Channel chan[6]; diff --git a/src/engine/platform/vera.h b/src/engine/platform/vera.h index fec113fc7..57be5dc9a 100644 --- a/src/engine/platform/vera.h +++ b/src/engine/platform/vera.h @@ -19,23 +19,19 @@ #ifndef _VERA_H #define _VERA_H + #include "../dispatch.h" #include "../instrument.h" -#include "../macroInt.h" struct VERA_PSG; struct VERA_PCM; class DivPlatformVERA: public DivDispatch { protected: - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; + struct Channel: public SharedChannel { unsigned char pan; - bool active, freqChanged, inPorta; - int vol, outVol; unsigned accum; int noiseval; - DivMacroInt std; struct PCMChannel { int sample; @@ -45,12 +41,12 @@ class DivPlatformVERA: public DivDispatch { bool depth16; PCMChannel(): sample(-1), pos(0), len(0), freq(0), depth16(false) {} } pcm; - // somebody please split this into multiple lines! - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } - Channel(): freq(0), baseFreq(0), pitch(0), pitch2(0), note(0), ins(-1), pan(0), active(false), freqChanged(false), inPorta(false), vol(0), outVol(0), accum(0), noiseval(0) {} + Channel(): + SharedChannel(0), + pan(0), + accum(0), + noiseval(0), + pcm(PCMChannel()) {} }; Channel chan[17]; DivDispatchOscBuffer* oscBuf[17]; diff --git a/src/engine/platform/vic20.h b/src/engine/platform/vic20.h index 21669c27a..a2628872e 100644 --- a/src/engine/platform/vic20.h +++ b/src/engine/platform/vic20.h @@ -21,37 +21,14 @@ #define _VIC20_H #include "../dispatch.h" -#include "../macroInt.h" #include "sound/vic20sound.h" #include class DivPlatformVIC20: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note, ins; - unsigned char pan; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta; - int vol, outVol, wave, waveWriteCycle; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + struct Channel: public SharedChannel { + int wave, waveWriteCycle; Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - pan(255), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - vol(15), - outVol(15), + SharedChannel(15), wave(0), waveWriteCycle(-1) {} }; diff --git a/src/engine/platform/vrc6.h b/src/engine/platform/vrc6.h index 839c089b9..3cb02c415 100644 --- a/src/engine/platform/vrc6.h +++ b/src/engine/platform/vrc6.h @@ -22,47 +22,26 @@ #include #include "../dispatch.h" -#include "../macroInt.h" #include "vgsound_emu/src/vrcvi/vrcvi.hpp" class DivPlatformVRC6: public DivDispatch, public vrcvi_intf { - struct Channel { - int freq, baseFreq, pitch, pitch2, note; + struct Channel: public SharedChannel { int dacPeriod, dacRate, dacOut; unsigned int dacPos; - int dacSample, ins; + int dacSample; unsigned char duty; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, pcm, furnaceDac; - signed char vol, outVol; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } + bool pcm, furnaceDac; Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), + SharedChannel(15), dacPeriod(0), dacRate(0), dacOut(0), dacPos(0), dacSample(-1), - ins(-1), duty(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), pcm(false), - furnaceDac(false), - vol(15), - outVol(15) {} + furnaceDac(false) {} }; Channel chan[3]; DivDispatchOscBuffer* oscBuf[3]; diff --git a/src/engine/platform/x1_010.h b/src/engine/platform/x1_010.h index d588d9446..28b180eb4 100644 --- a/src/engine/platform/x1_010.h +++ b/src/engine/platform/x1_010.h @@ -22,12 +22,11 @@ #include "../dispatch.h" #include "../engine.h" -#include "../macroInt.h" #include "../waveSynth.h" #include "vgsound_emu/src/x1_010/x1_010.hpp" class DivPlatformX1_010: public DivDispatch, public vgsound_emu_mem_intf { - struct Channel { + struct Channel: public SharedChannel { struct Envelope { struct EnvFlag { unsigned char envEnable : 1; @@ -68,38 +67,40 @@ class DivPlatformX1_010: public DivDispatch, public vgsound_emu_mem_intf { slide(0), slidefrac(0) {} }; - int freq, baseFreq, fixedFreq, pitch, pitch2, note; - int wave, sample, ins; + int fixedFreq; + int wave, sample; unsigned char pan, autoEnvNum, autoEnvDen; - bool active, insChanged, envChanged, freqChanged, keyOn, keyOff, inPorta, furnacePCM, pcm; - int vol, outVol, lvol, rvol; + bool envChanged, furnacePCM, pcm; + int lvol, rvol; int macroVolMul; unsigned char waveBank; unsigned int bankSlot; Envelope env; - DivMacroInt std; DivWaveSynth ws; void reset() { - freq = baseFreq = pitch = pitch2 = note = 0; - wave = sample = ins = -1; - pan = 255; - autoEnvNum = autoEnvDen = 0; - active = false; - insChanged = envChanged = freqChanged = true; - keyOn = keyOff = inPorta = furnacePCM = pcm = false; - vol = outVol = lvol = rvol = 15; - waveBank = 0; - } - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; + freq=baseFreq=pitch=pitch2=note=0; + wave=sample=ins=-1; + pan=255; + autoEnvNum=autoEnvDen=0; + active=false; + insChanged=envChanged=freqChanged=true; + keyOn=keyOff=inPorta=furnacePCM=pcm=false; + vol=outVol=lvol=rvol=15; + waveBank=0; } Channel(): - freq(0), baseFreq(0), fixedFreq(0), pitch(0), pitch2(0), note(0), - wave(-1), sample(-1), ins(-1), - pan(255), autoEnvNum(0), autoEnvDen(0), - active(false), insChanged(true), envChanged(true), freqChanged(false), keyOn(false), keyOff(false), inPorta(false), furnacePCM(false), pcm(false), - vol(15), outVol(15), lvol(15), rvol(15), + SharedChannel(15), + fixedFreq(0), + wave(-1), + sample(-1), + pan(255), + autoEnvNum(0), + autoEnvDen(0), + envChanged(true), + furnacePCM(false), + pcm(false), + lvol(15), + rvol(15), macroVolMul(15), waveBank(0), bankSlot(0) {} diff --git a/src/engine/platform/ym2203.cpp b/src/engine/platform/ym2203.cpp index 3d6eaa8a6..558e164b3 100644 --- a/src/engine/platform/ym2203.cpp +++ b/src/engine/platform/ym2203.cpp @@ -851,7 +851,7 @@ void DivPlatformYM2203::reset() { } fm->reset(); for (int i=0; i<6; i++) { - chan[i]=DivPlatformYM2203::Channel(); + chan[i]=DivPlatformOPN::OPNChannel(); chan[i].std.setEngine(parent); } for (int i=0; i<3; i++) { diff --git a/src/engine/platform/ym2203.h b/src/engine/platform/ym2203.h index b93e45ddb..2a3f292f2 100644 --- a/src/engine/platform/ym2203.h +++ b/src/engine/platform/ym2203.h @@ -19,8 +19,8 @@ #ifndef _YM2203_H #define _YM2203_H + #include "fmshared_OPN.h" -#include "../macroInt.h" #include "sound/ymfm/ymfm_opn.h" #include "ay.h" @@ -39,49 +39,7 @@ class DivPlatformYM2203: public DivPlatformOPN { 0, 1, 2 }; - struct Channel { - DivInstrumentFM state; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, note, ins; - unsigned char psgMode, autoEnvNum, autoEnvDen, opMask; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, furnacePCM, hardReset, opMaskChanged; - int vol, outVol; - int sample; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } - Channel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - note(0), - ins(-1), - psgMode(1), - autoEnvNum(0), - autoEnvDen(0), - opMask(15), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - furnacePCM(false), - hardReset(false), - opMaskChanged(false), - vol(0), - outVol(15), - sample(-1) {} - }; - Channel chan[6]; + OPNChannel chan[6]; DivDispatchOscBuffer* oscBuf[6]; bool isMuted[6]; ymfm::ym2203* fm; @@ -93,10 +51,8 @@ class DivPlatformYM2203: public DivPlatformOPN { bool extMode, noExtMacros; unsigned char prescale; - + friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); - public: void acquire(short* bufL, short* bufR, size_t start, size_t len); int dispatch(DivCommand c); diff --git a/src/engine/platform/ym2203ext.cpp b/src/engine/platform/ym2203ext.cpp index 21465da77..ace50bee2 100644 --- a/src/engine/platform/ym2203ext.cpp +++ b/src/engine/platform/ym2203ext.cpp @@ -483,7 +483,7 @@ void DivPlatformYM2203Ext::reset() { DivPlatformYM2203::reset(); for (int i=0; i<4; i++) { - opChan[i]=DivPlatformYM2203Ext::OpChannel(); + opChan[i]=DivPlatformOPN::OPNOpChannel(); opChan[i].vol=127; } diff --git a/src/engine/platform/ym2203ext.h b/src/engine/platform/ym2203ext.h index 5cf664296..14535e2d1 100644 --- a/src/engine/platform/ym2203ext.h +++ b/src/engine/platform/ym2203ext.h @@ -17,42 +17,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef _YM2203EXT_H +#define _YM2203EXT_H + #include "../dispatch.h" #include "ym2203.h" class DivPlatformYM2203Ext: public DivPlatformYM2203 { - struct OpChannel { - DivMacroInt std; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, ins; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, mask; - int vol; - // UGLY - OpChannel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - mask(true), - vol(0) {} - }; - OpChannel opChan[4]; + OPNOpChannel opChan[4]; bool isOpMuted[4]; friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); public: int dispatch(DivCommand c); void* getChanState(int chan); @@ -68,3 +43,5 @@ class DivPlatformYM2203Ext: public DivPlatformYM2203 { void quit(); ~DivPlatformYM2203Ext(); }; + +#endif diff --git a/src/engine/platform/ym2608.cpp b/src/engine/platform/ym2608.cpp index e15bf6b42..65537f4ee 100644 --- a/src/engine/platform/ym2608.cpp +++ b/src/engine/platform/ym2608.cpp @@ -1245,7 +1245,7 @@ void DivPlatformYM2608::reset() { } fm->reset(); for (int i=0; i<16; i++) { - chan[i]=DivPlatformYM2608::Channel(); + chan[i]=DivPlatformOPN::OPNChannelStereo(); chan[i].std.setEngine(parent); } for (int i=0; i<6; i++) { diff --git a/src/engine/platform/ym2608.h b/src/engine/platform/ym2608.h index ef63fe634..f6dfc21ab 100644 --- a/src/engine/platform/ym2608.h +++ b/src/engine/platform/ym2608.h @@ -19,8 +19,8 @@ #ifndef _YM2608_H #define _YM2608_H + #include "fmshared_OPN.h" -#include "../macroInt.h" #include "sound/ymfm/ymfm_opn.h" #include "ay.h" @@ -44,53 +44,7 @@ class DivPlatformYM2608: public DivPlatformOPN { 0, 1, 2, 4, 5, 6 }; - struct Channel { - DivInstrumentFM state; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, note, ins; - unsigned char psgMode, autoEnvNum, autoEnvDen, opMask; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, furnacePCM, hardReset, opMaskChanged; - int vol, outVol; - int sample; - unsigned char pan; - int macroVolMul; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } - Channel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - note(0), - ins(-1), - psgMode(1), - autoEnvNum(0), - autoEnvDen(0), - opMask(15), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - furnacePCM(false), - hardReset(false), - opMaskChanged(false), - vol(0), - outVol(15), - sample(-1), - pan(3), - macroVolMul(255) {} - }; - Channel chan[16]; + OPNChannelStereo chan[16]; DivDispatchOscBuffer* oscBuf[16]; bool isMuted[16]; ymfm::ym2608* fm; @@ -112,9 +66,8 @@ class DivPlatformYM2608: public DivPlatformOPN { double NOTE_OPNB(int ch, int note); double NOTE_ADPCMB(int note); + friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); - public: void acquire(short* bufL, short* bufR, size_t start, size_t len); int dispatch(DivCommand c); diff --git a/src/engine/platform/ym2608ext.cpp b/src/engine/platform/ym2608ext.cpp index 331f3887c..7a244e4db 100644 --- a/src/engine/platform/ym2608ext.cpp +++ b/src/engine/platform/ym2608ext.cpp @@ -519,7 +519,7 @@ void DivPlatformYM2608Ext::reset() { DivPlatformYM2608::reset(); for (int i=0; i<4; i++) { - opChan[i]=DivPlatformYM2608Ext::OpChannel(); + opChan[i]=DivPlatformOPN::OPNOpChannelStereo(); opChan[i].vol=127; } diff --git a/src/engine/platform/ym2608ext.h b/src/engine/platform/ym2608ext.h index fc734097f..01afb3617 100644 --- a/src/engine/platform/ym2608ext.h +++ b/src/engine/platform/ym2608ext.h @@ -17,44 +17,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef _YM2608EXT_H +#define _YM2608EXT_H + #include "../dispatch.h" #include "ym2608.h" class DivPlatformYM2608Ext: public DivPlatformYM2608 { - struct OpChannel { - DivMacroInt std; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, ins; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, mask; - int vol; - unsigned char pan; - // UGLY - OpChannel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - mask(true), - vol(0), - pan(3) {} - }; - OpChannel opChan[4]; + OPNOpChannelStereo opChan[4]; bool isOpMuted[4]; friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); public: int dispatch(DivCommand c); void* getChanState(int chan); @@ -70,3 +43,5 @@ class DivPlatformYM2608Ext: public DivPlatformYM2608 { void quit(); ~DivPlatformYM2608Ext(); }; + +#endif diff --git a/src/engine/platform/ym2610.cpp b/src/engine/platform/ym2610.cpp index 12434b06c..16bb0922a 100644 --- a/src/engine/platform/ym2610.cpp +++ b/src/engine/platform/ym2610.cpp @@ -1213,7 +1213,7 @@ void DivPlatformYM2610::reset() { } fm->reset(); for (int i=0; i<14; i++) { - chan[i]=DivPlatformYM2610::Channel(); + chan[i]=DivPlatformOPN::OPNChannelStereo(); chan[i].std.setEngine(parent); } for (int i=0; i { @@ -36,8 +37,6 @@ class DivPlatformYM2610: public DivPlatformYM2610Base<14> { }; friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); - public: void acquire(short* bufL, short* bufR, size_t start, size_t len); int dispatch(DivCommand c); diff --git a/src/engine/platform/ym2610b.cpp b/src/engine/platform/ym2610b.cpp index e005131ca..18b99cf87 100644 --- a/src/engine/platform/ym2610b.cpp +++ b/src/engine/platform/ym2610b.cpp @@ -1276,7 +1276,7 @@ void DivPlatformYM2610B::reset() { } fm->reset(); for (int i=0; i<16; i++) { - chan[i]=DivPlatformYM2610B::Channel(); + chan[i]=DivPlatformOPN::OPNChannelStereo(); chan[i].std.setEngine(parent); } for (int i=0; i { @@ -32,8 +33,6 @@ class DivPlatformYM2610B: public DivPlatformYM2610Base<16> { }; friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); - public: void acquire(short* bufL, short* bufR, size_t start, size_t len); int dispatch(DivCommand c); diff --git a/src/engine/platform/ym2610bext.cpp b/src/engine/platform/ym2610bext.cpp index 0f9b38195..80298dcb0 100644 --- a/src/engine/platform/ym2610bext.cpp +++ b/src/engine/platform/ym2610bext.cpp @@ -510,7 +510,7 @@ void DivPlatformYM2610BExt::reset() { DivPlatformYM2610B::reset(); for (int i=0; i<4; i++) { - opChan[i]=DivPlatformYM2610BExt::OpChannel(); + opChan[i]=DivPlatformOPN::OPNOpChannelStereo(); opChan[i].vol=127; } diff --git a/src/engine/platform/ym2610bext.h b/src/engine/platform/ym2610bext.h index accd7eeeb..c77649597 100644 --- a/src/engine/platform/ym2610bext.h +++ b/src/engine/platform/ym2610bext.h @@ -17,15 +17,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef _YM2610BEXT_H +#define _YM2610BEXT_H + #include "../dispatch.h" #include "ym2610b.h" class DivPlatformYM2610BExt: public DivPlatformYM2610B { - DivPlatformYM2610Base::OpChannel opChan[4]; + OPNOpChannelStereo opChan[4]; bool isOpMuted[4]; friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); public: int dispatch(DivCommand c); void* getChanState(int chan); @@ -41,3 +43,5 @@ class DivPlatformYM2610BExt: public DivPlatformYM2610B { void quit(); ~DivPlatformYM2610BExt(); }; + +#endif diff --git a/src/engine/platform/ym2610ext.cpp b/src/engine/platform/ym2610ext.cpp index 2a428b6d6..52af18545 100644 --- a/src/engine/platform/ym2610ext.cpp +++ b/src/engine/platform/ym2610ext.cpp @@ -510,7 +510,7 @@ void DivPlatformYM2610Ext::reset() { DivPlatformYM2610::reset(); for (int i=0; i<4; i++) { - opChan[i]=DivPlatformYM2610Ext::OpChannel(); + opChan[i]=DivPlatformOPN::OPNOpChannelStereo(); opChan[i].vol=127; } diff --git a/src/engine/platform/ym2610ext.h b/src/engine/platform/ym2610ext.h index 97ce9c1cc..5e78c53f4 100644 --- a/src/engine/platform/ym2610ext.h +++ b/src/engine/platform/ym2610ext.h @@ -17,15 +17,17 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef _YM2610EXT_H +#define _YM2610EXT_H + #include "../dispatch.h" #include "ym2610.h" class DivPlatformYM2610Ext: public DivPlatformYM2610 { - DivPlatformYM2610Base::OpChannel opChan[4]; + OPNOpChannelStereo opChan[4]; bool isOpMuted[4]; friend void putDispatchChip(void*,int); - friend void putDispatchChan(void*,int,int); public: int dispatch(DivCommand c); void* getChanState(int chan); @@ -41,3 +43,5 @@ class DivPlatformYM2610Ext: public DivPlatformYM2610 { void quit(); ~DivPlatformYM2610Ext(); }; + +#endif diff --git a/src/engine/platform/ym2610shared.h b/src/engine/platform/ym2610shared.h index c2dce8aa5..487412d54 100644 --- a/src/engine/platform/ym2610shared.h +++ b/src/engine/platform/ym2610shared.h @@ -19,8 +19,8 @@ #ifndef _YM2610SHARED_H #define _YM2610SHARED_H + #include "fmshared_OPN.h" -#include "../macroInt.h" #include "../engine.h" #include "../../ta-log.h" #include "ay.h" @@ -46,83 +46,7 @@ class DivYM2610Interface: public ymfm::ymfm_interface { template class DivPlatformYM2610Base: public DivPlatformOPN { protected: - struct Channel { - DivInstrumentFM state; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, note, ins; - unsigned char psgMode, autoEnvNum, autoEnvDen; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, furnacePCM, hardReset, opMaskChanged; - int vol, outVol; - int sample; - unsigned char pan, opMask; - int macroVolMul; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } - Channel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - note(0), - ins(-1), - psgMode(1), - autoEnvNum(0), - autoEnvDen(0), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - furnacePCM(false), - hardReset(false), - opMaskChanged(false), - vol(0), - outVol(15), - sample(-1), - pan(3), - opMask(15), - macroVolMul(255) {} - }; - - struct OpChannel { - DivMacroInt std; - unsigned char freqH, freqL; - int freq, baseFreq, pitch, pitch2, portaPauseFreq, ins; - signed char konCycles; - bool active, insChanged, freqChanged, keyOn, keyOff, portaPause, inPorta, mask; - int vol; - unsigned char pan; - // UGLY - OpChannel(): - freqH(0), - freqL(0), - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - portaPauseFreq(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - portaPause(false), - inPorta(false), - mask(true), - vol(0), - pan(3) {} - }; - Channel chan[ChanNum]; + OPNChannelStereo chan[ChanNum]; DivDispatchOscBuffer* oscBuf[ChanNum]; bool isMuted[ChanNum]; diff --git a/src/engine/platform/ymz280b.h b/src/engine/platform/ymz280b.h index 9477d003d..d2f2f1bbd 100644 --- a/src/engine/platform/ymz280b.h +++ b/src/engine/platform/ymz280b.h @@ -22,44 +22,22 @@ #include "../dispatch.h" #include -#include "../macroInt.h" #include "sound/ymz280b.h" class DivPlatformYMZ280B: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2; + struct Channel: public SharedChannel { unsigned int audPos; - int sample, wave, ins; - int note; + int sample, wave; int panning; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta, setPos, isNewYMZ; - int vol, outVol; + bool setPos, isNewYMZ; int macroVolMul; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), + SharedChannel(255), audPos(0), sample(-1), - ins(-1), - note(0), panning(8), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), setPos(false), isNewYMZ(false), - vol(255), - outVol(255), macroVolMul(64) {} }; Channel chan[8]; diff --git a/src/engine/platform/zxbeeper.h b/src/engine/platform/zxbeeper.h index ed82caeeb..19c3e6ed9 100644 --- a/src/engine/platform/zxbeeper.h +++ b/src/engine/platform/zxbeeper.h @@ -22,36 +22,13 @@ #include "../dispatch.h" #include -#include "../macroInt.h" class DivPlatformZXBeeper: public DivDispatch { - struct Channel { - int freq, baseFreq, pitch, pitch2, note; - int ins; - bool active, insChanged, freqChanged, keyOn, keyOff, inPorta; - signed char vol, outVol; + struct Channel: public SharedChannel { unsigned short sPosition; unsigned char duty; - DivMacroInt std; - void macroInit(DivInstrument* which) { - std.init(which); - pitch2=0; - } Channel(): - freq(0), - baseFreq(0), - pitch(0), - pitch2(0), - note(0), - ins(-1), - active(false), - insChanged(true), - freqChanged(false), - keyOn(false), - keyOff(false), - inPorta(false), - vol(1), - outVol(1), + SharedChannel(1), sPosition(0), duty(64) {} }; diff --git a/src/engine/song.h b/src/engine/song.h index 33e319b1d..e1a1607db 100644 --- a/src/engine/song.h +++ b/src/engine/song.h @@ -115,6 +115,8 @@ enum DivSystem { DIV_SYSTEM_YM2612_FRAC_EXT, DIV_SYSTEM_MSM5232, DIV_SYSTEM_T6W28, + DIV_SYSTEM_K007232, + DIV_SYSTEM_GA20, DIV_SYSTEM_PCM_DAC, DIV_SYSTEM_PONG, DIV_SYSTEM_DUMMY diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 9cd0b33ff..0cec489d6 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1171,10 +1171,10 @@ void DivEngine::registerSystems() { sysDefs[DIV_SYSTEM_POKEMINI]=new DivSysDef( "Pokémon Mini", NULL, 0x99, 0, 1, false, true, 0, false, 0, "this one is like PC Speaker but has duty cycles.", - {"Square"}, - {"SQ"}, + {"Pulse"}, + {"P"}, {DIV_CH_PULSE}, - {DIV_INS_BEEPER} + {DIV_INS_POKEMINI} ); sysDefs[DIV_SYSTEM_SEGAPCM]=new DivSysDef( @@ -1693,6 +1693,26 @@ void DivEngine::registerSystems() { {DIV_INS_AMIGA} ); + sysDefs[DIV_SYSTEM_K007232]=new DivSysDef( + "Konami K007232", NULL, 0xc6, 0, 2, false, true, 0, false, 1U<nuked?colorOn:colorOff,">> Nuked"); -#define GENESIS_CHAN_DEBUG \ - DivPlatformGenesis::Channel* ch=(DivPlatformGenesis::Channel*)data; \ - ImGui::Text("> YM2612"); \ - ImGui::Text("- freqHL: %.2x%.2x",ch->freqH,ch->freqL); \ +#define COMMON_CHAN_DEBUG \ ImGui::Text("* freq: %d",ch->freq); \ ImGui::Text(" - base: %d",ch->baseFreq); \ ImGui::Text(" - pitch: %d",ch->pitch); \ ImGui::Text(" - pitch2: %d",ch->pitch2); \ + ImGui::Text("- note: %d",ch->note); \ + ImGui::Text("- ins: %d",ch->ins); \ + ImGui::Text("- vol: %.2x",ch->vol); \ + ImGui::Text("- outVol: %.2x",ch->outVol); + +#define COMMON_CHAN_DEBUG_BOOL \ + ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); \ + ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); \ + ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); \ + ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); \ + ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); \ + ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); \ + ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + +#define GENESIS_CHAN_DEBUG \ + DivPlatformGenesis::Channel* ch=(DivPlatformGenesis::Channel*)data; \ + ImGui::Text("> YM2612"); \ + ImGui::Text("- freqHL: %.2x%.2x",ch->freqH,ch->freqL); \ + COMMON_CHAN_DEBUG; \ ImGui::Text("- portaPauseFreq: %d",ch->portaPauseFreq); \ ImGui::Text("* DAC:"); \ ImGui::Text(" - period: %d",ch->dacPeriod); \ @@ -138,21 +156,11 @@ ImGui::Text(" - sample: %d",ch->dacSample); \ ImGui::Text(" - delay: %d",ch->dacDelay); \ ImGui::Text(" - output: %d",ch->dacOutput); \ - ImGui::Text("- note: %d",ch->note); \ - ImGui::Text("- ins: %d",ch->ins); \ - ImGui::Text("- vol: %.2x",ch->vol); \ - ImGui::Text("- outVol: %.2x",ch->outVol); \ ImGui::Text("- pan: %x",ch->pan); \ ImGui::Text("- opMask: %x",ch->opMask); \ ImGui::Text("- sampleBank: %d",ch->sampleBank); \ - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); \ - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); \ - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); \ - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); \ - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); \ - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); \ + COMMON_CHAN_DEBUG_BOOL; \ ImGui::TextColored(ch->furnaceDac?colorOn:colorOff,">> FurnaceDAC"); \ - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); \ ImGui::TextColored(ch->hardReset?colorOn:colorOff,">> hardReset"); \ ImGui::TextColored(ch->opMaskChanged?colorOn:colorOff,">> opMaskChanged"); \ ImGui::TextColored(ch->dacMode?colorOn:colorOff,">> DACMode"); \ @@ -160,140 +168,70 @@ ImGui::TextColored(ch->dacDirection?colorOn:colorOff,">> DACDirection"); #define GENESIS_OPCHAN_DEBUG \ - DivPlatformGenesisExt::OpChannel* ch=(DivPlatformGenesisExt::OpChannel*)data; \ + DivPlatformOPN::OPNOpChannelStereo* ch=(DivPlatformOPN::OPNOpChannelStereo*)data; \ ImGui::Text("> YM2612 (per operator)"); \ ImGui::Text("- freqHL: %.2x%.2x",ch->freqH,ch->freqL); \ - ImGui::Text("* freq: %d",ch->freq); \ - ImGui::Text(" - base: %d",ch->baseFreq); \ - ImGui::Text(" - pitch: %d",ch->pitch); \ - ImGui::Text(" - pitch2: %d",ch->pitch2); \ + COMMON_CHAN_DEBUG; \ ImGui::Text("- portaPauseFreq: %d",ch->portaPauseFreq); \ - ImGui::Text("- ins: %d",ch->ins); \ - ImGui::Text("- vol: %.2x",ch->vol); \ ImGui::Text("- pan: %x",ch->pan); \ - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); \ - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); \ - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); \ - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); \ - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); \ - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); \ - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); \ + COMMON_CHAN_DEBUG_BOOL; \ ImGui::TextColored(ch->mask?colorOn:colorOff,">> Mask"); #define SMS_CHAN_DEBUG \ DivPlatformSMS::Channel* ch=(DivPlatformSMS::Channel*)data; \ ImGui::Text("> SMS"); \ - ImGui::Text("* freq: %d",ch->freq); \ - ImGui::Text(" - base: %d",ch->baseFreq); \ - ImGui::Text(" - pitch: %d",ch->pitch); \ - ImGui::Text(" - pitch2: %d",ch->pitch2); \ - ImGui::Text("- note: %d",ch->note); \ - ImGui::Text("- ins: %d",ch->ins); \ - ImGui::Text("- vol: %.2x",ch->vol); \ - ImGui::Text("- outVol: %.2x",ch->outVol); \ - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); \ - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); \ - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); \ - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); \ - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); + COMMON_CHAN_DEBUG; \ + COMMON_CHAN_DEBUG_BOOL; #define OPN_CHAN_DEBUG \ - DivPlatformYM2203::Channel* ch=(DivPlatformYM2203::Channel*)data; \ + DivPlatformOPN::OPNChannel* ch=(DivPlatformOPN::OPNChannel*)data; \ ImGui::Text("> YM2203"); \ ImGui::Text("- freqHL: %.2x%.2x",ch->freqH,ch->freqL); \ - ImGui::Text("* freq: %d",ch->freq); \ - ImGui::Text(" - base: %d",ch->baseFreq); \ - ImGui::Text(" - pitch: %d",ch->pitch); \ - ImGui::Text(" - pitch2: %d",ch->pitch2); \ + COMMON_CHAN_DEBUG; \ ImGui::Text("- portaPauseFreq: %d",ch->portaPauseFreq); \ ImGui::Text("* PSG:"); \ ImGui::Text(" - psgMode: %d",ch->psgMode); \ ImGui::Text(" - autoEnvNum: %d",ch->autoEnvNum); \ ImGui::Text(" - autoEnvDen: %d",ch->autoEnvDen); \ ImGui::Text("- sample: %d",ch->sample); \ - ImGui::Text("- note: %d",ch->note); \ - ImGui::Text("- ins: %d",ch->ins); \ - ImGui::Text("- vol: %.2x",ch->vol); \ - ImGui::Text("- outVol: %.2x",ch->outVol); \ ImGui::Text("- opMask: %x",ch->opMask); \ - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); \ - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); \ - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); \ - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); \ - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); \ - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); \ - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); \ + COMMON_CHAN_DEBUG_BOOL; \ ImGui::TextColored(ch->hardReset?colorOn:colorOff,">> hardReset"); \ ImGui::TextColored(ch->opMaskChanged?colorOn:colorOff,">> opMaskChanged"); \ ImGui::TextColored(ch->furnacePCM?colorOn:colorOff,">> FurnacePCM"); #define OPN_OPCHAN_DEBUG \ - DivPlatformYM2203Ext::OpChannel* ch=(DivPlatformYM2203Ext::OpChannel*)data; \ + DivPlatformOPN::OPNOpChannel* ch=(DivPlatformOPN::OPNOpChannel*)data; \ ImGui::Text("> YM2203 (per operator)"); \ ImGui::Text("- freqHL: %.2x%.2x",ch->freqH,ch->freqL); \ - ImGui::Text("* freq: %d",ch->freq); \ - ImGui::Text(" - base: %d",ch->baseFreq); \ - ImGui::Text(" - pitch: %d",ch->pitch); \ - ImGui::Text(" - pitch2: %d",ch->pitch2); \ + COMMON_CHAN_DEBUG; \ ImGui::Text("- portaPauseFreq: %d",ch->portaPauseFreq); \ - ImGui::Text("- ins: %d",ch->ins); \ - ImGui::Text("- vol: %.2x",ch->vol); \ - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); \ - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); \ - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); \ - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); \ - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); \ - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); \ - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); \ + COMMON_CHAN_DEBUG_BOOL; \ ImGui::TextColored(ch->mask?colorOn:colorOff,">> Mask"); #define OPNB_CHAN_DEBUG \ ImGui::Text("- freqHL: %.2x%.2x",ch->freqH,ch->freqL); \ - ImGui::Text("* freq: %d",ch->freq); \ - ImGui::Text(" - base: %d",ch->baseFreq); \ - ImGui::Text(" - pitch: %d",ch->pitch); \ - ImGui::Text(" - pitch2: %d",ch->pitch2); \ + COMMON_CHAN_DEBUG; \ ImGui::Text("- portaPauseFreq: %d",ch->portaPauseFreq); \ ImGui::Text("* PSG:"); \ ImGui::Text(" - psgMode: %d",ch->psgMode); \ ImGui::Text(" - autoEnvNum: %d",ch->autoEnvNum); \ ImGui::Text(" - autoEnvDen: %d",ch->autoEnvDen); \ ImGui::Text("- sample: %d",ch->sample); \ - ImGui::Text("- note: %d",ch->note); \ - ImGui::Text("- ins: %d",ch->ins); \ - ImGui::Text("- vol: %.2x",ch->vol); \ - ImGui::Text("- outVol: %.2x",ch->outVol); \ ImGui::Text("- pan: %x",ch->pan); \ ImGui::Text("- opMask: %x",ch->opMask); \ ImGui::Text("- macroVolMul: %x",ch->macroVolMul); \ - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); \ - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); \ - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); \ - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); \ - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); \ - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); \ - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); \ + COMMON_CHAN_DEBUG_BOOL; \ ImGui::TextColored(ch->hardReset?colorOn:colorOff,">> hardReset"); \ ImGui::TextColored(ch->opMaskChanged?colorOn:colorOff,">> opMaskChanged"); \ ImGui::TextColored(ch->furnacePCM?colorOn:colorOff,">> FurnacePCM"); #define OPNB_OPCHAN_DEBUG \ ImGui::Text("- freqHL: %.2x%.2x",ch->freqH,ch->freqL); \ - ImGui::Text("* freq: %d",ch->freq); \ - ImGui::Text(" - base: %d",ch->baseFreq); \ - ImGui::Text(" - pitch: %d",ch->pitch); \ - ImGui::Text(" - pitch2: %d",ch->pitch2); \ + COMMON_CHAN_DEBUG; \ ImGui::Text("- portaPauseFreq: %d",ch->portaPauseFreq); \ - ImGui::Text("- ins: %d",ch->ins); \ - ImGui::Text("- vol: %.2x",ch->vol); \ ImGui::Text("- pan: %x",ch->pan); \ - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); \ - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); \ - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); \ - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); \ - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); \ - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); \ - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); \ + COMMON_CHAN_DEBUG_BOOL; \ ImGui::TextColored(ch->mask?colorOn:colorOff,">> Mask"); void putDispatchChip(void* data, int type) { @@ -553,6 +491,17 @@ void putDispatchChip(void* data, int type) { ImGui::TextColored(ch->outStereo?colorOn:colorOff,">> OutStereo"); break; } + case DIV_SYSTEM_K007232: { + DivPlatformK007232* ch=(DivPlatformK007232*)data; + ImGui::Text("> K007232"); + COMMON_CHIP_DEBUG; + ImGui::Text("- delay: %.2x",ch->delay); + ImGui::Text("- lastLoop: %.2x",ch->lastLoop); + ImGui::Text("- lastVolume: %.2x",ch->lastVolume); + COMMON_CHIP_DEBUG_BOOL; + ImGui::TextColored(ch->stereo?colorOn:colorOff,">> Stereo"); + break; + } default: ImGui::Text("Unimplemented chip! Help!"); break; @@ -574,7 +523,9 @@ void putDispatchChan(void* data, int chanNum, int type) { if (chanNum>8) { SMS_CHAN_DEBUG; } else if (chanNum>=2 && chanNum<=5) { - GENESIS_OPCHAN_DEBUG + DivPlatformOPN::OPNOpChannelStereo* ch=(DivPlatformOPN::OPNOpChannelStereo*)data; + ImGui::Text("> YM2612 (per operator)"); + OPNB_OPCHAN_DEBUG; } else { GENESIS_CHAN_DEBUG; } @@ -588,7 +539,9 @@ void putDispatchChan(void* data, int chanNum, int type) { case DIV_SYSTEM_YM2612_EXT: case DIV_SYSTEM_YM2612_FRAC_EXT: { if (chanNum>=2 && chanNum<=5) { - GENESIS_OPCHAN_DEBUG + DivPlatformOPN::OPNOpChannelStereo* ch=(DivPlatformOPN::OPNOpChannelStereo*)data; + ImGui::Text("> YM2612 (per operator)"); + OPNB_OPCHAN_DEBUG; } else { GENESIS_CHAN_DEBUG; } @@ -611,18 +564,18 @@ void putDispatchChan(void* data, int chanNum, int type) { break; } case DIV_SYSTEM_PC98: { - DivPlatformYM2608::Channel* ch=(DivPlatformYM2608::Channel*)data; + DivPlatformOPN::OPNChannelStereo* ch=(DivPlatformOPN::OPNChannelStereo*)data; ImGui::Text("> YM2608"); OPNB_CHAN_DEBUG; break; } case DIV_SYSTEM_PC98_EXT: { if (chanNum>=2 && chanNum<=5) { - DivPlatformYM2608Ext::OpChannel* ch=(DivPlatformYM2608Ext::OpChannel*)data; + DivPlatformOPN::OPNOpChannelStereo* ch=(DivPlatformOPN::OPNOpChannelStereo*)data; ImGui::Text("> YM2608 (per operator)"); OPNB_OPCHAN_DEBUG; } else { - DivPlatformYM2608Ext::Channel* ch=(DivPlatformYM2608Ext::Channel*)data; + DivPlatformOPN::OPNChannelStereo* ch=(DivPlatformOPN::OPNChannelStereo*)data; ImGui::Text("> YM2608"); OPNB_CHAN_DEBUG; } @@ -630,13 +583,13 @@ void putDispatchChan(void* data, int chanNum, int type) { } case DIV_SYSTEM_YM2610: case DIV_SYSTEM_YM2610_FULL: { - DivPlatformYM2610::Channel* ch=(DivPlatformYM2610::Channel*)data; + DivPlatformOPN::OPNChannelStereo* ch=(DivPlatformOPN::OPNChannelStereo*)data; ImGui::Text("> YM2610"); OPNB_CHAN_DEBUG; break; } case DIV_SYSTEM_YM2610B: { - DivPlatformYM2610B::Channel* ch=(DivPlatformYM2610B::Channel*)data; + DivPlatformOPN::OPNChannelStereo* ch=(DivPlatformOPN::OPNChannelStereo*)data; ImGui::Text("> YM2610B"); OPNB_CHAN_DEBUG; break; @@ -644,11 +597,11 @@ void putDispatchChan(void* data, int chanNum, int type) { case DIV_SYSTEM_YM2610_EXT: case DIV_SYSTEM_YM2610_FULL_EXT: { if (chanNum>=1 && chanNum<=4) { - DivPlatformYM2610Ext::OpChannel* ch=(DivPlatformYM2610Ext::OpChannel*)data; + DivPlatformOPN::OPNOpChannelStereo* ch=(DivPlatformOPN::OPNOpChannelStereo*)data; ImGui::Text("> YM2610 (per operator)"); OPNB_OPCHAN_DEBUG; } else { - DivPlatformYM2610Ext::Channel* ch=(DivPlatformYM2610Ext::Channel*)data; + DivPlatformOPN::OPNChannelStereo* ch=(DivPlatformOPN::OPNChannelStereo*)data; ImGui::Text("> YM2610"); OPNB_CHAN_DEBUG; } @@ -656,11 +609,11 @@ void putDispatchChan(void* data, int chanNum, int type) { } case DIV_SYSTEM_YM2610B_EXT: { if (chanNum>=2 && chanNum<=5) { - DivPlatformYM2610BExt::OpChannel* ch=(DivPlatformYM2610BExt::OpChannel*)data; + DivPlatformOPN::OPNOpChannelStereo* ch=(DivPlatformOPN::OPNOpChannelStereo*)data; ImGui::Text("> YM2610B (per operator)"); OPNB_OPCHAN_DEBUG; } else { - DivPlatformYM2610BExt::Channel* ch=(DivPlatformYM2610BExt::Channel*)data; + DivPlatformOPN::OPNChannelStereo* ch=(DivPlatformOPN::OPNChannelStereo*)data; ImGui::Text("> YM2610B"); OPNB_CHAN_DEBUG; } @@ -669,52 +622,28 @@ void putDispatchChan(void* data, int chanNum, int type) { case DIV_SYSTEM_GB: { DivPlatformGB::Channel* ch=(DivPlatformGB::Channel*)data; ImGui::Text("> GameBoy"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); - ImGui::Text("- ins: %d",ch->ins); + COMMON_CHAN_DEBUG; ImGui::Text("- duty: %d",ch->duty); ImGui::Text("- sweep: %.2x",ch->sweep); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- wave: %d",ch->wave); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->sweepChanged?colorOn:colorOff,">> SweepChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); break; } case DIV_SYSTEM_PCE: { DivPlatformPCE::Channel* ch=(DivPlatformPCE::Channel*)data; ImGui::Text("> PCEngine"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); + COMMON_CHAN_DEBUG; ImGui::Text("* DAC:"); ImGui::Text(" - period: %d",ch->dacPeriod); ImGui::Text(" - rate: %d",ch->dacRate); ImGui::Text(" - pos: %d",ch->dacPos); ImGui::Text(" - out: %d",ch->dacOut); ImGui::Text(" - sample: %d",ch->dacSample); - ImGui::Text("- ins: %d",ch->ins); ImGui::Text("- pan: %.2x",ch->pan); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- wave: %d",ch->wave); ImGui::Text("- macroVolMul: %d",ch->macroVolMul); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->noise?colorOn:colorOff,">> Noise"); ImGui::TextColored(ch->pcm?colorOn:colorOff,">> DAC"); ImGui::TextColored(ch->furnaceDac?colorOn:colorOff,">> FurnaceDAC"); @@ -723,52 +652,27 @@ void putDispatchChan(void* data, int chanNum, int type) { case DIV_SYSTEM_NES: { DivPlatformNES::Channel* ch=(DivPlatformNES::Channel*)data; ImGui::Text("> NES"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); + COMMON_CHAN_DEBUG; ImGui::Text(" - prev: %d",ch->prevFreq); - ImGui::Text("- note: %d",ch->note); - ImGui::Text("- ins: %d",ch->ins); ImGui::Text("- duty: %d",ch->duty); ImGui::Text("- sweep: %.2x",ch->sweep); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); - ImGui::Text("- wave: %d",ch->wave); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->sweepChanged?colorOn:colorOff,">> SweepChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); ImGui::TextColored(ch->furnaceDac?colorOn:colorOff,">> FurnaceDAC"); break; } case DIV_SYSTEM_C64_6581: case DIV_SYSTEM_C64_8580: { DivPlatformC64::Channel* ch=(DivPlatformC64::Channel*)data; ImGui::Text("> C64"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text(" - prev: %d",ch->prevFreq); + COMMON_CHAN_DEBUG; + ImGui::Text("- prevFreq: %d",ch->prevFreq); ImGui::Text("- testWhen: %d",ch->testWhen); - ImGui::Text("- note: %d",ch->note); - ImGui::Text("- ins: %d",ch->ins); ImGui::Text("- duty: %d",ch->duty); ImGui::Text("- sweep: %.2x",ch->sweep); ImGui::Text("- wave: %.1x",ch->wave); ImGui::Text("- ADSR: %.1x %.1x %.1x %.1x",ch->attack,ch->decay,ch->sustain,ch->release); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->sweepChanged?colorOn:colorOff,">> SweepChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); ImGui::TextColored(ch->filter?colorOn:colorOff,">> Filter"); ImGui::TextColored(ch->resetMask?colorOn:colorOff,">> ResetMask"); ImGui::TextColored(ch->resetFilter?colorOn:colorOff,">> ResetFilter"); @@ -782,68 +686,37 @@ void putDispatchChan(void* data, int chanNum, int type) { DivPlatformArcade::Channel* ch=(DivPlatformArcade::Channel*)data; ImGui::Text("> YM2151"); ImGui::Text("- freqHL: %.2x%.2x",ch->freqH,ch->freqL); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); - ImGui::Text("- ins: %d",ch->ins); + COMMON_CHAN_DEBUG; ImGui::Text("- KOnCycles: %d",ch->konCycles); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- chVolL: %.2x",ch->chVolL); ImGui::Text("- chVolR: %.2x",ch->chVolR); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + COMMON_CHAN_DEBUG_BOOL; break; } case DIV_SYSTEM_SEGAPCM: case DIV_SYSTEM_SEGAPCM_COMPAT: { DivPlatformSegaPCM::Channel* ch=(DivPlatformSegaPCM::Channel*)data; ImGui::Text("> SegaPCM"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); - ImGui::Text("- ins: %d",ch->ins); + COMMON_CHAN_DEBUG; ImGui::Text("* PCM:"); ImGui::Text(" - sample: %d",ch->pcm.sample); ImGui::Text(" - pos: %d",ch->pcm.pos); ImGui::Text(" - len: %d",ch->pcm.len); ImGui::Text(" - freq: %d",ch->pcm.freq); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- chVolL: %.2x",ch->chVolL); ImGui::Text("- chVolR: %.2x",ch->chVolR); ImGui::Text("- chPanL: %.2x",ch->chPanL); ImGui::Text("- chPanR: %.2x",ch->chPanR); ImGui::Text("- macroVolMul: %.2x",ch->macroVolMul); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->furnacePCM?colorOn:colorOff,">> FurnacePCM"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); ImGui::TextColored(ch->isNewSegaPCM?colorOn:colorOff,">> IsNewSegaPCM"); break; } case DIV_SYSTEM_AY8910: { DivPlatformAY8910::Channel* ch=(DivPlatformAY8910::Channel*)data; ImGui::Text("> AY-3-8910"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); - ImGui::Text("- ins: %d",ch->ins); + COMMON_CHAN_DEBUG; ImGui::Text("* psgMode:"); ImGui::Text(" * curr:"); ImGui::Text(" - tone: %d",ch->curPSGMode.tone); @@ -863,27 +736,14 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text(" - out: %d",ch->dac.out); ImGui::Text("- autoEnvNum: %.2x",ch->autoEnvNum); ImGui::Text("- autoEnvDen: %.2x",ch->autoEnvDen); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->dac.furnaceDAC?colorOn:colorOff,">> furnaceDAC"); break; } case DIV_SYSTEM_AY8930: { DivPlatformAY8930::Channel* ch=(DivPlatformAY8930::Channel*)data; ImGui::Text("> AY8930"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); - ImGui::Text("- ins: %d",ch->ins); + COMMON_CHAN_DEBUG; ImGui::Text("- duty: %d",ch->duty); ImGui::Text("* envelope:"); ImGui::Text(" - mode: %d",ch->envelope.mode); @@ -909,39 +769,19 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text(" - out: %d",ch->dac.out); ImGui::Text("- autoEnvNum: %.2x",ch->autoEnvNum); ImGui::Text("- autoEnvDen: %.2x",ch->autoEnvDen); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->portaPause?colorOn:colorOff,">> PortaPause"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->dac.furnaceDAC?colorOn:colorOff,">> furnaceDAC"); break; } case DIV_SYSTEM_QSOUND: { DivPlatformQSound::Channel* ch=(DivPlatformQSound::Channel*)data; ImGui::Text("> QSound"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); - ImGui::Text("- ins: %d",ch->ins); + COMMON_CHAN_DEBUG; ImGui::Text("- sample: %d",ch->sample); ImGui::Text("- echo: %d",ch->echo); ImGui::Text("- panning: %d",ch->panning); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- resVol: %.2x",ch->resVol); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->useWave?colorOn:colorOff,">> UseWave"); ImGui::TextColored(ch->surround?colorOn:colorOff,">> Surround"); ImGui::TextColored(ch->isNewQSound?colorOn:colorOff,">> IsNewQSound"); @@ -950,14 +790,9 @@ void putDispatchChan(void* data, int chanNum, int type) { case DIV_SYSTEM_X1_010: { DivPlatformX1_010::Channel* ch=(DivPlatformX1_010::Channel*)data; ImGui::Text("> X1-010"); - ImGui::Text("* freq: %.4x",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); + COMMON_CHAN_DEBUG; ImGui::Text("- wave: %d",ch->wave); ImGui::Text("- sample: %d",ch->sample); - ImGui::Text("- ins: %d",ch->ins); ImGui::Text("- pan: %d",ch->pan); ImGui::Text("* envelope:"); ImGui::Text(" - shape: %d",ch->env.shape); @@ -968,17 +803,10 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text(" - autoEnvDen: %.2x",ch->autoEnvDen); ImGui::Text("- WaveBank: %d",ch->waveBank); ImGui::Text("- bankSlot: %d",ch->bankSlot); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- Lvol: %.2x",ch->lvol); ImGui::Text("- Rvol: %.2x",ch->rvol); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->envChanged?colorOn:colorOff,">> EnvChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); ImGui::TextColored(ch->furnacePCM?colorOn:colorOff,">> FurnacePCM"); ImGui::TextColored(ch->pcm?colorOn:colorOff,">> PCM"); ImGui::TextColored(ch->env.flag.envEnable?colorOn:colorOff,">> EnvEnable"); @@ -993,11 +821,7 @@ void putDispatchChan(void* data, int chanNum, int type) { case DIV_SYSTEM_N163: { DivPlatformN163::Channel* ch=(DivPlatformN163::Channel*)data; ImGui::Text("> N163"); - ImGui::Text("* freq: %.4x",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); + COMMON_CHAN_DEBUG; ImGui::Text("- wave: %d",ch->wave); ImGui::Text("- wavepos: %d",ch->wavePos); ImGui::Text("- wavelen: %d",ch->waveLen); @@ -1006,45 +830,25 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text("- loadpos: %d",ch->loadPos); ImGui::Text("- loadlen: %d",ch->loadLen); ImGui::Text("- loadmode: %d",ch->loadMode); - ImGui::Text("- ins: %d",ch->ins); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- resVol: %.2x",ch->resVol); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->volumeChanged?colorOn:colorOff,">> VolumeChanged"); ImGui::TextColored(ch->waveChanged?colorOn:colorOff,">> WaveChanged"); ImGui::TextColored(ch->waveUpdated?colorOn:colorOff,">> WaveUpdated"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); break; } case DIV_SYSTEM_VRC6: { DivPlatformVRC6::Channel* ch=(DivPlatformVRC6::Channel*)data; ImGui::Text("> VRC6"); - ImGui::Text("* freq: %d",ch->freq); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("- note: %d",ch->note); + COMMON_CHAN_DEBUG; ImGui::Text("* DAC:"); ImGui::Text(" - period: %d",ch->dacPeriod); ImGui::Text(" - rate: %d",ch->dacRate); ImGui::Text(" - out: %d",ch->dacOut); ImGui::Text(" - pos: %d",ch->dacPos); ImGui::Text(" - sample: %d",ch->dacSample); - ImGui::Text("- ins: %d",ch->ins); ImGui::Text("- duty: %d",ch->duty); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->pcm?colorOn:colorOff,">> DAC"); ImGui::TextColored(ch->furnaceDac?colorOn:colorOff,">> FurnaceDAC"); break; @@ -1052,46 +856,30 @@ void putDispatchChan(void* data, int chanNum, int type) { case DIV_SYSTEM_LYNX: { DivPlatformLynx::Channel* ch=(DivPlatformLynx::Channel*)data; ImGui::Text("> Lynx"); - ImGui::Text("* freq:"); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); + COMMON_CHAN_DEBUG; ImGui::Text("* FreqDiv:"); ImGui::Text(" - clockDivider: %d",ch->fd.clockDivider); ImGui::Text(" - backup: %d",ch->fd.backup); - ImGui::Text("* note: %d",ch->note); - ImGui::Text(" - actualNote: %d",ch->actualNote); + ImGui::Text("- actualNote: %d",ch->actualNote); ImGui::Text("* Sample:"); ImGui::Text(" - sample: %d",ch->sample); ImGui::Text(" - pos: %d",ch->samplePos); ImGui::Text(" - accum: %d",ch->sampleAccum); ImGui::Text(" * freq: %d",ch->sampleFreq); ImGui::Text(" - base: %d",ch->sampleBaseFreq); - ImGui::Text("- ins: %d",ch->ins); ImGui::Text("* duty:"); ImGui::Text(" - int_feedback7: %d",ch->duty.int_feedback7); ImGui::Text(" - feedback: %d",ch->duty.feedback); ImGui::Text("- pan: %.2x",ch->pan); - ImGui::Text("- vol: %.2x",ch->vol); - ImGui::Text("- outVol: %.2x",ch->outVol); ImGui::Text("- macroVolMul: %.2x",ch->macroVolMul); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->pcm?colorOn:colorOff,">> DAC"); break; } case DIV_SYSTEM_PCM_DAC: { DivPlatformPCMDAC::Channel* ch=(DivPlatformPCMDAC::Channel*)data; ImGui::Text("> PCM DAC"); - ImGui::Text("* freq:"); - ImGui::Text(" - base: %d",ch->baseFreq); - ImGui::Text(" - pitch: %d",ch->pitch); - ImGui::Text(" - pitch2: %d",ch->pitch2); - ImGui::Text("* note: %d",ch->note); + COMMON_CHAN_DEBUG; ImGui::Text("* Sample: %d",ch->sample); ImGui::Text(" - dir: %d",ch->audDir); ImGui::Text(" - loc: %d",ch->audLoc); @@ -1099,21 +887,33 @@ void putDispatchChan(void* data, int chanNum, int type) { ImGui::Text(" * pos: %d",ch->audPos); ImGui::Text(" - sub: %d",ch->audSub); ImGui::Text("- wave: %d",ch->wave); - ImGui::Text("- ins: %d",ch->ins); ImGui::Text("- panL: %.2x",ch->panL); ImGui::Text("- panR: %.2x",ch->panR); - ImGui::Text("- vol: %.2x",ch->vol); ImGui::Text("- envVol: %.2x",ch->envVol); - ImGui::TextColored(ch->active?colorOn:colorOff,">> Active"); - ImGui::TextColored(ch->insChanged?colorOn:colorOff,">> InsChanged"); - ImGui::TextColored(ch->freqChanged?colorOn:colorOff,">> FreqChanged"); - ImGui::TextColored(ch->keyOn?colorOn:colorOff,">> KeyOn"); - ImGui::TextColored(ch->keyOff?colorOn:colorOff,">> KeyOff"); - ImGui::TextColored(ch->inPorta?colorOn:colorOff,">> InPorta"); + COMMON_CHAN_DEBUG_BOOL; ImGui::TextColored(ch->useWave?colorOn:colorOff,">> UseWave"); ImGui::TextColored(ch->setPos?colorOn:colorOff,">> SetPos"); break; } + case DIV_SYSTEM_K007232: { + DivPlatformK007232::Channel* ch=(DivPlatformK007232::Channel*)data; + ImGui::Text("> K007232"); + COMMON_CHAN_DEBUG; + ImGui::Text("- prevFreq: %d",ch->prevFreq); + ImGui::Text("* Sample: %d",ch->sample); + ImGui::Text(" - pos: %d",ch->audPos); + ImGui::Text(" - prevBank: %d",ch->prevBank); + ImGui::Text("* panning: %d",ch->panning); + ImGui::Text(" - prev: %d",ch->prevPan); + ImGui::Text("- resVol: %.2x",ch->resVol); + ImGui::Text("- lvol: %.2x",ch->lvol); + ImGui::Text("- rvol: %.2x",ch->rvol); + ImGui::Text("- macroVolMul: %.2x",ch->macroVolMul); + COMMON_CHAN_DEBUG_BOOL; + ImGui::TextColored(ch->volumeChanged?colorOn:colorOff,">> VolumeChanged"); + ImGui::TextColored(ch->setPos?colorOn:colorOff,">> SetPos"); + break; + } default: ImGui::Text("Unimplemented chip! Help!"); break; diff --git a/src/gui/doAction.cpp b/src/gui/doAction.cpp index 89c615645..362762da3 100644 --- a/src/gui/doAction.cpp +++ b/src/gui/doAction.cpp @@ -1324,7 +1324,8 @@ void FurnaceGUI::doAction(int what) { i==DIV_INS_VRC6 || i==DIV_INS_SU || i==DIV_INS_SNES || - i==DIV_INS_ES5506) { + i==DIV_INS_ES5506 || + i==DIV_INS_K007232) { makeInsTypeList.push_back(i); } } diff --git a/src/gui/editControls.cpp b/src/gui/editControls.cpp index b10c85ea3..f019f766b 100644 --- a/src/gui/editControls.cpp +++ b/src/gui/editControls.cpp @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _USE_MATH_DEFINES #include "gui.h" #include "IconsFontAwesome4.h" #include diff --git a/src/gui/gui.h b/src/gui/gui.h index ec8f8b7f5..aa0ff29a9 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -185,6 +185,9 @@ enum FurnaceGUIColors { GUI_COLOR_INSTR_RF5C68, GUI_COLOR_INSTR_MSM5232, GUI_COLOR_INSTR_T6W28, + GUI_COLOR_INSTR_K007232, + GUI_COLOR_INSTR_GA20, + GUI_COLOR_INSTR_POKEMINI, GUI_COLOR_INSTR_UNKNOWN, GUI_COLOR_CHANNEL_BG, diff --git a/src/gui/guiConst.cpp b/src/gui/guiConst.cpp index 906f207c1..9f0ad23be 100644 --- a/src/gui/guiConst.cpp +++ b/src/gui/guiConst.cpp @@ -125,6 +125,9 @@ const char* insTypes[DIV_INS_MAX+1]={ "RF5C68", "MSM5232", "T6W28", + "K007232", + "GA20", + "Pokémon Mini", NULL }; @@ -808,6 +811,9 @@ const FurnaceGUIColorDef guiColors[GUI_COLOR_MAX]={ D(GUI_COLOR_INSTR_RF5C68,"",ImVec4(1.0f,0.3f,0.3f,1.0f)), D(GUI_COLOR_INSTR_MSM5232,"",ImVec4(0.5f,0.9f,1.0f,1.0f)), D(GUI_COLOR_INSTR_T6W28,"",ImVec4(1.0f,0.8f,0.1f,1.0f)), + D(GUI_COLOR_INSTR_K007232,"",ImVec4(1.0f,0.8f,0.1f,1.0f)), + D(GUI_COLOR_INSTR_GA20,"",ImVec4(0.1f,1.0f,0.4f,1.0f)), + D(GUI_COLOR_INSTR_POKEMINI,"",ImVec4(1.0f,1.0f,0.3f,1.0f)), D(GUI_COLOR_INSTR_UNKNOWN,"",ImVec4(0.3f,0.3f,0.3f,1.0f)), D(GUI_COLOR_CHANNEL_BG,"",ImVec4(0.4f,0.6f,0.8f,1.0f)), @@ -928,6 +934,7 @@ const int availableSystems[]={ DIV_SYSTEM_AY8910, DIV_SYSTEM_AMIGA, DIV_SYSTEM_PCSPKR, + DIV_SYSTEM_POKEMINI, DIV_SYSTEM_SFX_BEEPER, DIV_SYSTEM_YMU759, DIV_SYSTEM_DUMMY, @@ -975,6 +982,7 @@ const int availableSystems[]={ DIV_SYSTEM_RF5C68, DIV_SYSTEM_SNES, DIV_SYSTEM_MSM5232, + DIV_SYSTEM_K007232, DIV_SYSTEM_PCM_DAC, DIV_SYSTEM_PONG, 0 // don't remove this last one! @@ -1018,6 +1026,7 @@ const int chipsSquare[]={ DIV_SYSTEM_SMS, DIV_SYSTEM_AY8910, DIV_SYSTEM_PCSPKR, + DIV_SYSTEM_POKEMINI, DIV_SYSTEM_SAA1099, DIV_SYSTEM_VIC20, DIV_SYSTEM_MSM5232, @@ -1073,6 +1082,7 @@ const int chipsSample[]={ DIV_SYSTEM_MSM6295, DIV_SYSTEM_RF5C68, DIV_SYSTEM_SNES, + DIV_SYSTEM_K007232, DIV_SYSTEM_PCM_DAC, 0 // don't remove this last one! }; diff --git a/src/gui/insEdit.cpp b/src/gui/insEdit.cpp index 7e48b2460..97f3a80d4 100644 --- a/src/gui/insEdit.cpp +++ b/src/gui/insEdit.cpp @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#define _USE_MATH_DEFINES #include "gui.h" #include "imgui_internal.h" #include "../engine/macroInt.h" @@ -4251,7 +4252,8 @@ void FurnaceGUI::drawInsEdit() { ins->type==DIV_INS_VRC6 || ins->type==DIV_INS_SU || ins->type==DIV_INS_SNES || - ins->type==DIV_INS_ES5506) { + ins->type==DIV_INS_ES5506 || + ins->type==DIV_INS_K007232) { if (ImGui::BeginTabItem((ins->type==DIV_INS_SU)?"Sound Unit":"Sample")) { String sName; if (ins->amiga.initSample<0 || ins->amiga.initSample>=e->song.sampleLen) { @@ -4947,6 +4949,9 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_QSOUND) { volMax=16383; } + if (ins->type==DIV_INS_POKEMINI) { + volMax=2; + } const char* dutyLabel="Duty/Noise"; int dutyMin=0; @@ -4980,7 +4985,7 @@ void FurnaceGUI::drawInsEdit() { dutyLabel="Group Ctrl"; dutyMax=5; } - if (ins->type==DIV_INS_BEEPER) { + if (ins->type==DIV_INS_BEEPER || ins->type==DIV_INS_POKEMINI) { dutyLabel="Pulse Width"; dutyMax=255; } @@ -4993,7 +4998,7 @@ void FurnaceGUI::drawInsEdit() { } if (ins->type==DIV_INS_TIA || ins->type==DIV_INS_AMIGA || ins->type==DIV_INS_SCC || ins->type==DIV_INS_PET || ins->type==DIV_INS_VIC || ins->type==DIV_INS_SEGAPCM || - ins->type==DIV_INS_FM) { + ins->type==DIV_INS_FM || ins->type==DIV_INS_K007232) { dutyMax=0; } if (ins->type==DIV_INS_VBOY) { @@ -5076,6 +5081,8 @@ void FurnaceGUI::drawInsEdit() { if (ins->type==DIV_INS_MSM6258) waveMax=0; if (ins->type==DIV_INS_MSM6295) waveMax=0; if (ins->type==DIV_INS_SEGAPCM) waveMax=0; + if (ins->type==DIV_INS_K007232) waveMax=0; + if (ins->type==DIV_INS_POKEMINI) waveMax=0; if (ins->type==DIV_INS_SU) waveMax=7; if (ins->type==DIV_INS_PET) { waveMax=8; @@ -5165,7 +5172,7 @@ void FurnaceGUI::drawInsEdit() { } if (ins->type==DIV_INS_X1_010 || ins->type==DIV_INS_PCE || ins->type==DIV_INS_MIKEY || ins->type==DIV_INS_SAA1099 || ins->type==DIV_INS_NAMCO || ins->type==DIV_INS_RF5C68 || - ins->type==DIV_INS_VBOY || ins->type==DIV_INS_T6W28) { + ins->type==DIV_INS_VBOY || ins->type==DIV_INS_T6W28 || ins->type==DIV_INS_K007232) { panMax=15; } if (ins->type==DIV_INS_SEGAPCM) { @@ -5274,7 +5281,8 @@ void FurnaceGUI::drawInsEdit() { ins->type==DIV_INS_ES5506 || ins->type==DIV_INS_T6W28 || ins->type==DIV_INS_VBOY || - (ins->type==DIV_INS_X1_010 && ins->amiga.useSample)) { + (ins->type==DIV_INS_X1_010 && ins->amiga.useSample) || + ins->type==DIV_INS_K007232) { macroList.push_back(FurnaceGUIMacroDesc("Phase Reset",&ins->std.phaseResetMacro,0,1,32,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true)); } if (ex1Max>0) { diff --git a/src/gui/pattern.cpp b/src/gui/pattern.cpp index 2c611d46d..d14902eef 100644 --- a/src/gui/pattern.cpp +++ b/src/gui/pattern.cpp @@ -18,7 +18,6 @@ */ // for suck's fake Clang extension! -#include #define _USE_MATH_DEFINES #include "gui.h" #include "../ta-log.h" diff --git a/src/gui/presets.cpp b/src/gui/presets.cpp index 6072570ee..66e6c6e9a 100644 --- a/src/gui/presets.cpp +++ b/src/gui/presets.cpp @@ -216,6 +216,11 @@ void FurnaceGUI::initSystemPresets() { ) } ); + ENTRY( + "Pokémon Mini", { + CH(DIV_SYSTEM_POKEMINI, 32, 0, "") + } + ); CATEGORY_END; CATEGORY_BEGIN("Computers","let's get to work on chiptune today."); @@ -1079,6 +1084,11 @@ void FurnaceGUI::initSystemPresets() { CH(DIV_SYSTEM_PCSPKR, 32, 0, "") } ); + ENTRY( + "Pokémon Mini", { + CH(DIV_SYSTEM_POKEMINI, 32, 0, "") + } + ); ENTRY( "Commodore VIC", { CH(DIV_SYSTEM_VIC20, 64, 0, "clockSel=1") @@ -1143,6 +1153,11 @@ void FurnaceGUI::initSystemPresets() { CH(DIV_SYSTEM_SNES, 64, 0, "") } ); + ENTRY( + "Konami K007232", { + CH(DIV_SYSTEM_K007232, 64, 0, "") + } + ); ENTRY( "Generic PCM DAC", { CH(DIV_SYSTEM_PCM_DAC, 64, 0, "") @@ -1326,6 +1341,12 @@ void FurnaceGUI::initSystemPresets() { // VLM5030 exists but not used for music at all } ); + ENTRY( + "Konami MX5000", { + CH(DIV_SYSTEM_YM2151, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); ENTRY( "Konami Battlantis", { CH(DIV_SYSTEM_OPL2, 64, 0, "clockSel=3"), // 3MHz @@ -1350,6 +1371,54 @@ void FurnaceGUI::initSystemPresets() { CH(DIV_SYSTEM_OPL2_DRUMS, 64, 0, "clockSel=3") // "" } ); + ENTRY( + "Konami Fast Lane", { + CH(DIV_SYSTEM_K007232, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami Chequered Flag", { + CH(DIV_SYSTEM_YM2151, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, "stereo=true"), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami Haunted Castle", { + CH(DIV_SYSTEM_OPL2, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_SCC, 64, 0, ""), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami Haunted Castle (drums mode)", { + CH(DIV_SYSTEM_OPL2_DRUMS, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_SCC, 64, 0, ""), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami Hot Chase", { + CH(DIV_SYSTEM_K007232, 64, 0, "stereo=true"), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, "stereo=true"), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "stereo=true") // "" + } + ); + ENTRY( + "Konami S.P.Y.", { + CH(DIV_SYSTEM_OPL2, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, ""), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); + ENTRY( + "Konami S.P.Y. (drums mode)", { + CH(DIV_SYSTEM_OPL2_DRUMS, 64, 0, ""), // 3.58MHz + CH(DIV_SYSTEM_K007232, 64, 0, ""), // "" + CH(DIV_SYSTEM_K007232, 64, 0, "") // "" + } + ); ENTRY( "Konami Hexion", { CH(DIV_SYSTEM_SCC, 64, 0, "clockSel=2"), // 1.5MHz (3MHz input) diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index beca31025..2f80a04f8 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -16,6 +16,8 @@ * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ + +#define _USE_MATH_DEFINES #include "gui.h" #include #include diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index 1c8cebb5b..d40e4dac7 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -1787,6 +1787,10 @@ void FurnaceGUI::drawSettings() { UI_COLOR_CONFIG(GUI_COLOR_INSTR_QSOUND,"QSound"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_YMZ280B,"YMZ280B"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_RF5C68,"RF5C68"); + UI_COLOR_CONFIG(GUI_COLOR_INSTR_MSM5232,"MSM5232"); + UI_COLOR_CONFIG(GUI_COLOR_INSTR_K007232,"K007232"); + UI_COLOR_CONFIG(GUI_COLOR_INSTR_GA20,"GA20"); + UI_COLOR_CONFIG(GUI_COLOR_INSTR_POKEMINI,"Pokémon Mini"); UI_COLOR_CONFIG(GUI_COLOR_INSTR_UNKNOWN,"Other/Unknown"); ImGui::TreePop(); } @@ -2594,6 +2598,15 @@ void FurnaceGUI::commitSettings() { settings.tg100Path!=e->getConfString("tg100Path","") || settings.mu5Path!=e->getConfString("mu5Path",""); + bool coresChanged=( + settings.arcadeCore!=e->getConfInt("arcadeCore",0) || + settings.ym2612Core!=e->getConfInt("ym2612Core",0) || + settings.snCore!=e->getConfInt("snCore",0) || + settings.nesCore!=e->getConfInt("nesCore",0) || + settings.fdsCore!=e->getConfInt("fdsCore",0) || + settings.c64Core!=e->getConfInt("c64Core",1) + ); + e->setConf("mainFontSize",settings.mainFontSize); e->setConf("patFontSize",settings.patFontSize); e->setConf("iconSize",settings.iconSize); @@ -2754,7 +2767,7 @@ void FurnaceGUI::commitSettings() { } } - if (!e->switchMaster()) { + if (!e->switchMaster(coresChanged)) { showError("could not initialize audio!"); } diff --git a/src/gui/sysConf.cpp b/src/gui/sysConf.cpp index 170e2d8bd..6702f6cb3 100644 --- a/src/gui/sysConf.cpp +++ b/src/gui/sysConf.cpp @@ -17,6 +17,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#include "../engine/chipUtils.h" #include "gui.h" #include "misc/cpp/imgui_stdlib.h" #include @@ -1546,6 +1547,20 @@ bool FurnaceGUI::drawSysConf(int chan, DivSystem type, DivConfig& flags, bool mo } break; } + case DIV_SYSTEM_K007232: { + bool stereo=flags.getBool("stereo",false); + + if (ImGui::Checkbox("Stereo",&stereo)) { + altered=true; + } + + if (altered) { + e->lockSave([&]() { + flags.set("stereo",stereo); + }); + } + break; + } case DIV_SYSTEM_SWAN: case DIV_SYSTEM_BUBSYS_WSG: case DIV_SYSTEM_PET: @@ -1575,19 +1590,19 @@ bool FurnaceGUI::drawSysConf(int chan, DivSystem type, DivConfig& flags, bool mo if (supportsCustomRate) { ImGui::Separator(); int customClock=flags.getInt("customClock",0); - bool usingCustomClock=customClock>=100000; + bool usingCustomClock=customClock>=MIN_CUSTOM_CLOCK; if (ImGui::Checkbox("Custom clock rate",&usingCustomClock)) { if (usingCustomClock) { - customClock=1000000; + customClock=MIN_CUSTOM_CLOCK; } else { customClock=0; } altered=true; } if (ImGui::InputInt("Hz",&customClock)) { - if (customClock<100000) customClock=0; - if (customClock>20000000) customClock=20000000; + if (customClockMAX_CUSTOM_CLOCK) customClock=MAX_CUSTOM_CLOCK; altered=true; }