[PATCH] Fix: MIDI IRQ needs to be re-enabled on re-init

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Midi_UnInit() removes the IRQ, but Midi_Init() does not set it,
only Midi_Reset() does.

Add few TODOs for other thing that probably should also be reset on
MIDI device change.
---
 src/change.c  |  6 ++++++
 src/control.c | 12 +++++++-----
 src/midi.c    |  3 +++
 3 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/src/change.c b/src/change.c
index a834e007..418f87f7 100644
--- a/src/change.c
+++ b/src/change.c
@@ -484,6 +484,12 @@ void Change_CopyChangedParamsToConfiguration(CNF_PARAMS *current, CNF_PARAMS *ch
 	{
 		Dprintf("- midi<\n");
 		Midi_Init();
+		if (!NeedReset)
+		{
+			// does extra things, but needs to be called
+			// to restart MIDI IRQ stopped on Midi_UnInit()
+			Midi_Reset();
+		}
 	}
 
 	/* Force things associated with screen change */
diff --git a/src/control.c b/src/control.c
index 3ef34391..580f2213 100644
--- a/src/control.c
+++ b/src/control.c
@@ -176,11 +176,12 @@ static bool Control_DeviceAction(const char *name, action_t action)
 		bool *pvalue;
 		void(*init)(void);
 		void(*uninit)(void);
+		const char *init_note;
 	} item[] = {
-		{ "printer", &ConfigureParams.Printer.bEnablePrinting, Printer_Init, Printer_UnInit },
-		{ "rs232",   &ConfigureParams.RS232.bEnableRS232, RS232_Init, RS232_UnInit },
-		{ "sccb",    &ConfigureParams.RS232.bEnableSccB, SCC_Init, SCC_UnInit },
-		{ "midi",    &ConfigureParams.Midi.bEnableMidi, Midi_Init, Midi_UnInit },
+		{ "printer", &ConfigureParams.Printer.bEnablePrinting, Printer_Init, Printer_UnInit, "" },
+		{ "rs232",   &ConfigureParams.RS232.bEnableRS232, RS232_Init, RS232_UnInit, "" },
+		{ "sccb",    &ConfigureParams.RS232.bEnableSccB, SCC_Init, SCC_UnInit, "" },
+		{ "midi",    &ConfigureParams.Midi.bEnableMidi, Midi_Init, Midi_UnInit, "(reset emulation after re-init!)" },
 		{ NULL, NULL, NULL, NULL }
 	};
 	int i;
@@ -204,10 +205,11 @@ static bool Control_DeviceAction(const char *name, action_t action)
 			*(item[i].pvalue) = value;
 			if (value) {
 				item[i].init();
+				fprintf(stderr, "%s: ON %s\n", name, item[i].init_note);
 			} else {
 				item[i].uninit();
+				fprintf(stderr, "%s: OFF\n", name);
 			}
-			fprintf(stderr, "%s: %s\n", name, value?"ON":"OFF");
 			return true;
 		}
 	}
diff --git a/src/midi.c b/src/midi.c
index ceb2335c..2f8ef8b6 100644
--- a/src/midi.c
+++ b/src/midi.c
@@ -563,6 +563,7 @@ static int Midi_Host_ReadByte(void)
 		return fgetc(pMidiFhIn);
 	else return EOF;
 #else
+	// TODO: should these be reset with Midi_Init()?
 	static Uint8 msg[4];
 	static Uint8 ibyte = 0;
 	static int bytesAvailable = 0;
@@ -664,6 +665,7 @@ static int Midi_GetDataLength(Uint8 status)
 static PmEvent* Midi_BuildEvent(Uint8 byte)
 {
 	static const Uint8 shifts[] = { 0,8,16,24 };
+	// TODO: should these be reset with Midi_Init()?
 	static PmEvent midiEvent = { 0,0 };
 	static Uint32 midimsg;
 	static Uint8 runningStatus = 0;
@@ -771,6 +773,7 @@ static PmEvent* Midi_BuildEvent(Uint8 byte)
  */
 static int Midi_SplitEvent(PmEvent* midiEvent, Uint8* msg)
 {
+	// TODO: should be reset with Midi_Init()?
 	static bool processingSysex = false;
 	PmMessage midiMessage = midiEvent->message;
 	int i, bytesAvailable = 0;
-- 
2.30.2


--------------F1971866F5590457B84C96A9--



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/