Browse Source

DOSBOX opl without interference & WIN95 SC fix

louyihua 8 years ago
parent
commit
b0c92f2aa4
9 changed files with 1238 additions and 1194 deletions
  1. 16 48
      adplug/demuopl.cpp
  2. 6 7
      adplug/demuopl.h
  3. 1179 1110
      adplug/dosbox_opl.cpp
  4. 18 16
      adplug/dosbox_opl.h
  5. 5 1
      adplug/surroundopl.cpp
  6. 2 2
      rixplay.cpp
  7. 6 6
      sdlpal.sln
  8. 1 1
      sdlpal.vcxproj
  9. 5 3
      text.c

+ 16 - 48
adplug/demuopl.cpp

@@ -3,65 +3,33 @@
 //  SDLPal
 //
 //  Created by palxex on 14-7-20.
-//  Copyright (c) 2014 Wei Mingzhi. All rights reserved.
+//  Copyright (c) 2014 Wei Mingzhi. All rights reserved.
 //
 
 #include "demuopl.h"
-#include <math.h>
-#include <stdlib.h> // rand()
 #include <string.h>
 
-int CDemuopl::channels = 0;
-
-struct OPLHandler {
-    virtual void init(int rate) = 0;
-    virtual void getsample(short *buf,int samples) = 0;
-    virtual void write(int reg,int val) = 0;
-};
-
-namespace OPLCore {
-#include "dosbox_opl.cpp"
-	struct DOSBoxOPLHandler : OPLHandler {
-		void init(int rate) {
-			adlib_init(rate);
-		}
-		void getsample(short *buf, int samples) {
-			adlib_getsample(buf, samples);
-		}
-		void write(int reg, int val) {
-			adlib_write(reg, val);
-		}
-	};
+CDemuopl::CDemuopl(int rate, bool bit16, bool usestereo)
+	: use16bit(bit16), stereo(usestereo), rate(rate), chip(adlib_init(rate))
+{
+	currType = TYPE_OPL2;
 }
 
-namespace OPLCore2 {
-#include "dosbox_opl.cpp"
-	struct DOSBoxOPLHandler : OPLHandler {
-		void init(int rate) {
-			adlib_init(rate);
-		}
-		void getsample(short *buf, int samples) {
-			adlib_getsample(buf, samples);
-		}
-		void write(int reg, int val) {
-			adlib_write(reg, val);
-		}
-	};
+CDemuopl::~CDemuopl()
+{
+	adlib_release(chip);
 }
 
-CDemuopl::CDemuopl(int rate, bool bit16, bool usestereo)
-	:use16bit(bit16), stereo(usestereo)
+void CDemuopl::init()
 {
-	if (channels++ == 0)
-		pHandler = new OPLCore::DOSBoxOPLHandler;
-	else
-		pHandler = new OPLCore2::DOSBoxOPLHandler;
-	pHandler->init(rate);
-	currType = TYPE_OPL2;
+	if (chip) adlib_release(chip);
+	chip = adlib_init(rate);
 }
 
 void CDemuopl::update(short *buf, int samples)
 {
+	if (!chip) return;
+
 	short *mixbuf1 = NULL;
 	short *outbuf;
 	if (use16bit) outbuf = buf;
@@ -69,7 +37,7 @@ void CDemuopl::update(short *buf, int samples)
 		mixbuf1 = new short[samples * 2];
 		outbuf = mixbuf1;
 	}
-	pHandler->getsample(outbuf, samples);
+	adlib_getsample(chip, outbuf, samples);
 	if (stereo)
 		for (int i = samples - 1; i >= 0; i--) {
 			outbuf[i * 2] = outbuf[i];
@@ -86,5 +54,5 @@ void CDemuopl::update(short *buf, int samples)
 // template methods
 void CDemuopl::write(int reg, int val)
 {
-    pHandler->write(reg, val);
-};
+	if (chip) adlib_write(chip, reg, val);
+}

+ 6 - 7
adplug/demuopl.h

@@ -28,24 +28,23 @@
 
 #include <assert.h>
 
-struct OPLHandler;
-
 class CDemuopl: public Copl
 {
 public:
     CDemuopl(int rate, bool bit16, bool usestereo);
-    
+	~CDemuopl();
+
     void update(short *buf, int samples);
     
     // template methods
     void write(int reg, int val);
     
-    void init() {};
+    void init();
     
 protected:
-    bool use16bit,stereo;
-    OPLHandler *pHandler;
-    static int channels;
+	opl_chip* chip;
+	int rate;
+	bool use16bit, stereo;
 };
 
 #endif

File diff suppressed because it is too large
+ 1179 - 1110
adplug/dosbox_opl.cpp


+ 18 - 16
adplug/dosbox_opl.h

@@ -164,27 +164,29 @@ typedef struct operator_struct {
 } op_type;
 
 
+typedef struct opl_chip_struct opl_chip;
+
 // enable an operator
-void enable_operator(Bitu regbase, op_type* op_pt);
+void enable_operator(opl_chip* opl, Bitu regbase, op_type* op_pt);
 
 // functions to change parameters of an operator
-void change_frequency(Bitu chanbase, Bitu regbase, op_type* op_pt);
+void change_frequency(opl_chip* opl, Bitu chanbase, Bitu regbase, op_type* op_pt);
 
-void change_attackrate(Bitu regbase, op_type* op_pt);
-void change_decayrate(Bitu regbase, op_type* op_pt);
-void change_releaserate(Bitu regbase, op_type* op_pt);
-void change_sustainlevel(Bitu regbase, op_type* op_pt);
-void change_waveform(Bitu regbase, op_type* op_pt);
-void change_keepsustain(Bitu regbase, op_type* op_pt);
-void change_vibrato(Bitu regbase, op_type* op_pt);
-void change_feedback(Bitu chanbase, op_type* op_pt);
+void change_attackrate(opl_chip* opl, Bitu regbase, op_type* op_pt);
+void change_decayrate(opl_chip* opl, Bitu regbase, op_type* op_pt);
+void change_releaserate(opl_chip* opl, Bitu regbase, op_type* op_pt);
+void change_sustainlevel(opl_chip* opl, Bitu regbase, op_type* op_pt);
+void change_waveform(opl_chip* opl, Bitu regbase, op_type* op_pt);
+void change_keepsustain(opl_chip* opl, Bitu regbase, op_type* op_pt);
+void change_vibrato(opl_chip* opl, Bitu regbase, op_type* op_pt);
+void change_feedback(opl_chip* opl, Bitu chanbase, op_type* op_pt);
 
 // general functions
-void adlib_init(Bit32u samplerate);
-void adlib_write(Bitu idx, Bit8u val);
-void adlib_getsample(Bit16s* sndptr, Bits numsamples);
+opl_chip* adlib_init(Bit32u samplerate);
+void adlib_write(opl_chip* opl, Bitu idx, Bit8u val);
+void adlib_getsample(opl_chip* opl, Bit16s* sndptr, Bits numsamples);
 
-Bitu adlib_reg_read(Bitu port);
-void adlib_write_index(Bitu port, Bit8u val);
+Bitu adlib_reg_read(opl_chip* opl, Bitu port);
+void adlib_write_index(opl_chip* opl, Bitu port, Bit8u val);
 
-static Bit32u generator_add;	// should be a chip parameter
+void adlib_release(opl_chip* opl);

+ 5 - 1
adplug/surroundopl.cpp

@@ -200,4 +200,8 @@ void CSurroundopl::write(int reg, int val)
 
 };
 
-void CSurroundopl::init() {};
+void CSurroundopl::init()
+{
+	a->init();
+	b->init();
+}

+ 2 - 2
rixplay.cpp

@@ -133,8 +133,8 @@ RIX_FillBuffer(
             gpRixPlayer->dwEndFadeTime = t +
                (gpRixPlayer->dwEndFadeTime - gpRixPlayer->dwStartFadeTime);
             gpRixPlayer->dwStartFadeTime = t;
-            gpRixPlayer->rix->rewind(gpRixPlayer->iCurrentMusic);
 			gpRixPlayer->opl->init();
+			gpRixPlayer->rix->rewind(gpRixPlayer->iCurrentMusic);
 			if (gpRixPlayer->resampler[0]) resampler_clear(gpRixPlayer->resampler[0]);
 			if (gpRixPlayer->resampler[1]) resampler_clear(gpRixPlayer->resampler[1]);
             return;
@@ -157,8 +157,8 @@ RIX_FillBuffer(
                gpRixPlayer->dwEndFadeTime = t +
                   (gpRixPlayer->dwEndFadeTime - gpRixPlayer->dwStartFadeTime);
                gpRixPlayer->dwStartFadeTime = t;
-               gpRixPlayer->rix->rewind(gpRixPlayer->iCurrentMusic);
 			   gpRixPlayer->opl->init();
+			   gpRixPlayer->rix->rewind(gpRixPlayer->iCurrentMusic);
 			   if (gpRixPlayer->resampler[0]) resampler_clear(gpRixPlayer->resampler[0]);
 			   if (gpRixPlayer->resampler[1]) resampler_clear(gpRixPlayer->resampler[1]);
 			}

+ 6 - 6
sdlpal.sln

@@ -1,7 +1,7 @@
 
 Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.31101.0
+# Visual Studio 14
+VisualStudioVersion = 14.0.23107.0
 MinimumVisualStudioVersion = 10.0.40219.1
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sdlpal", "sdlpal.vcxproj", "{837BDF47-9375-4C30-866B-07E262E94A01}"
 EndProject
@@ -13,12 +13,12 @@ Global
 		Release|Win32 = Release|Win32
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
-		{837BDF47-9375-4C30-866B-07E262E94A01}.Debug_WIN95|Win32.ActiveCfg = Debug_WIN95|Win32
-		{837BDF47-9375-4C30-866B-07E262E94A01}.Debug_WIN95|Win32.Build.0 = Debug_WIN95|Win32
+		{837BDF47-9375-4C30-866B-07E262E94A01}.Debug_WIN95|Win32.ActiveCfg = Debug|Win32
+		{837BDF47-9375-4C30-866B-07E262E94A01}.Debug_WIN95|Win32.Build.0 = Debug|Win32
 		{837BDF47-9375-4C30-866B-07E262E94A01}.Debug|Win32.ActiveCfg = Debug|Win32
 		{837BDF47-9375-4C30-866B-07E262E94A01}.Debug|Win32.Build.0 = Debug|Win32
-		{837BDF47-9375-4C30-866B-07E262E94A01}.Release_WIN95|Win32.ActiveCfg = Release_WIN95|Win32
-		{837BDF47-9375-4C30-866B-07E262E94A01}.Release_WIN95|Win32.Build.0 = Release_WIN95|Win32
+		{837BDF47-9375-4C30-866B-07E262E94A01}.Release_WIN95|Win32.ActiveCfg = Release|Win32
+		{837BDF47-9375-4C30-866B-07E262E94A01}.Release_WIN95|Win32.Build.0 = Release|Win32
 		{837BDF47-9375-4C30-866B-07E262E94A01}.Release|Win32.ActiveCfg = Release|Win32
 		{837BDF47-9375-4C30-866B-07E262E94A01}.Release|Win32.Build.0 = Release|Win32
 	EndGlobalSection

+ 1 - 1
sdlpal.vcxproj

@@ -61,6 +61,7 @@
       <WarningLevel>Level3</WarningLevel>
       <SuppressStartupBanner>true</SuppressStartupBanner>
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
+      <Optimization>Disabled</Optimization>
     </ClCompile>
     <ResourceCompile>
       <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
@@ -312,7 +313,6 @@
       <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
     </ClCompile>
     <ClCompile Include="adplug\emuopl.cpp">
       <AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>

+ 5 - 3
text.c

@@ -730,9 +730,11 @@ PAL_ShowDialogText(
    {
       int len = wcslen(lpszText);
       if (g_TextLib.nCurrentDialogLine == 0 &&
-         g_TextLib.bDialogPosition != kDialogCenter &&
-		 (lpszText[len - 1] == 0xff1a ||
-		  lpszText[len - 1] == ':'))
+          g_TextLib.bDialogPosition != kDialogCenter &&
+		  (lpszText[len - 1] == 0xff1a ||
+		   lpszText[len - 1] == 0x2236 || // Special case for Pal WIN95 Simplified Chinese version
+		   lpszText[len - 1] == ':')
+		 )
       {
          //
          // name of character