File: player.cpp

package info (click to toggle)
sidplay 1.36.28-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,192 kB
  • ctags: 1,674
  • sloc: cpp: 12,514; sh: 1,716; makefile: 223
file content (216 lines) | stat: -rw-r--r-- 5,926 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
//
// /home/ms/source/sidplay/libsidplay/RCS/player.cpp,v
//

#include "player.h"
#include "myendian.h"
#include "6510_.h"

extern ubyte playRamRom;  // MPU bank-switch setting for player call

// These texts are used to override the sidtune settings.
static const char text_PAL_VBI[] = "50 Hz VBI (PAL)";
static const char text_PAL_CIA[] = "CIA 1 Timer A (PAL)";
static const char text_NTSC_VBI[] = "60 Hz VBI (NTSC)";
static const char text_NTSC_CIA[] = "CIA 1 Timer A (NTSC)";

static const int FREQ_VBI_PAL = 50;   // Hz
static const int FREQ_VBI_NTSC = 60;  //

// Table used to check sidtune for usage of PlaySID digis.
static const uword c64addrTable[] =
{
	// PlaySID extended SID registers (0xd49d left out).
	//0xd41d, 0xd41e, 0xd41f,  // SID is too often written to as 32 bytes!
	0xd43d, 0xd43e, 0xd43f,
	0xd45d, 0xd45e, 0xd45f, 0xd47d, 0xd47e, 0xd47f,
	//0xd51d, 0xd51e, 0xd51f,  // SID is too often written to as 32 bytes!
	0xd53d, 0xd53e, 0xd53f,
	0xd55d, 0xd55e, 0xd55f, 0xd57d, 0xd57e, 0xd57f
};
// Number of addresses in c64addrTable[].
static const int numberOfC64addr = sizeof(c64addrTable) / sizeof(uword);
static ubyte oldValues[numberOfC64addr];


bool sidEmuInitializeSong(emuEngine & thisEmuEngine,
						  sidTune & thisTune,
						  uword songNumber)
{
	// Do a regular song initialization.
	bool ret = sidEmuInitializeSongOld(thisEmuEngine,thisTune,songNumber);
	if (ret && (thisEmuEngine.config.digiPlayerScans!=0))
	{
		uword replayPC = thisTune.info.playAddr;
		// playRamRom was set by sidEmuInitializeSongOld(..).
		if ( replayPC == 0 )
		{
			playRamRom = c64mem1[1];
			if ((playRamRom & 2) != 0)  // isKernal?
			{
				replayPC = readLEword(c64mem1+0x0314);  // IRQ
			}
			else
			{
				replayPC = readLEword(c64mem1+0xfffe);  // NMI
			}
		}
		
        // Save the SID registers to allow later comparison.
		for (int i = 0; i < numberOfC64addr; i++)
		{
			oldValues[i] = c64mem2[c64addrTable[i]];
		}
		
		// Run the music player for a couple of player calls and check for
		// changes in the PlaySID extended SID registers. If no digis are
		// used, apply a higher amplification on each SID voice. First
		// check also covers writings of the player INIT routine.
		bool useDigis = false;
		int loops = thisEmuEngine.config.digiPlayerScans;
		while (loops)
		{
			for (int i = 0; i < numberOfC64addr; i++)
			{
				if (oldValues[i] != c64mem2[c64addrTable[i]])
				{
					useDigis = true;
					break;
				}
				oldValues[i] = c64mem2[c64addrTable[i]];
			}
			interpreter(replayPC,playRamRom,0,0,0);
			loops--;
			if (useDigis)
			{
				break;
			}
		};
		thisEmuEngine.amplifyThreeVoiceTunes(!useDigis);
		// Here re-init song to start at beginning.
		ret = sidEmuInitializeSongOld(thisEmuEngine,thisTune,songNumber);
	}
	return ret;
}


bool sidEmuInitializeSongOld(emuEngine & thisEmuEngine,
							 sidTune & thisTune,
							 uword songNumber)
{
	if (!thisEmuEngine.isReady || !thisTune.status )
	{
		return false;
	}
	else
	{
		// ------------------------------------------- Determine clock/speed.
		
		// Get speed/clock setting for song and preselect
		// speed/clock descriptions strings, reg = song init akkumulator.
		ubyte reg = thisTune.selectSong(songNumber) -1;

		const char* the_description;

		ubyte the_clock = thisTune.info.clockSpeed;
		ubyte the_speed = thisTune.info.songSpeed;
		
		if (thisEmuEngine.config.forceSongSpeed)
		{
			the_clock = thisEmuEngine.config.clockSpeed;
		}

		// Select speed description string.
		if (thisEmuEngine.config.clockSpeed == SIDTUNE_CLOCK_PAL)
		{
			if (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI)
			{
				the_description = text_PAL_VBI;
			}
			else  //if (thisTune.info.songSpeed == SIDTUNE_SPEED_CIA_1A)
			{
				the_description = text_PAL_CIA;
			}
		}
		else  //if (thisEmuEngine.config.clockSpeed == SIDTUNE_CLOCK_NTSC)
		{
			if (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI)
			{
				the_description = text_NTSC_VBI;
			}
			else  //if (thisTune.info.songSpeed == SIDTUNE_SPEED_CIA_1A)
			{
				the_description = text_NTSC_CIA;
			}
		}
		
		// Substitute correct VBI frequency.
		if ((the_clock==SIDTUNE_CLOCK_PAL) &&
			(the_speed==SIDTUNE_SPEED_VBI))
		{
			the_speed = FREQ_VBI_PAL;
		}
		
		if ((the_clock==SIDTUNE_CLOCK_NTSC) &&
			(the_speed==SIDTUNE_SPEED_VBI))
		{
			the_speed = FREQ_VBI_NTSC;
		}
			
		// Transfer the speed settings to the emulator engine.
		// From here on we don't touch the SID clock speed setting.
		extern void sidEmuSetReplayingSpeed(int clockMode, uword callsPerSec);  // --> 6581_.cpp
		sidEmuSetReplayingSpeed(the_clock,the_speed);

		thisTune.info.speedString = the_description;
 
		// ------------------------------------------------------------------
		
		thisEmuEngine.MPUreset();
				
		if ( !thisTune.placeSidTuneInC64mem(thisEmuEngine.MPUreturnRAMbase()) )
		{
			return false;
		}

		if (thisTune.info.musPlayer)
		{
			thisTune.MUS_installPlayer(thisEmuEngine.MPUreturnRAMbase());
		}
		
		thisEmuEngine.amplifyThreeVoiceTunes(false);  // assume digis are used
		if ( !thisEmuEngine.reset() )  // currently always returns true
		{
			return false;
		}

		// In PlaySID-mode the interpreter will ignore some of the parameters.
		//bool retcode =
		interpreter(thisTune.info.initAddr,c64memRamRom(thisTune.info.initAddr),reg,reg,reg);
		playRamRom = c64memRamRom(thisTune.info.playAddr);
		
		// This code is only used to be able to print out the initial IRQ address.
		if (thisTune.info.playAddr == 0)
		{
			// Get the address of the interrupt handler.
			if ((c64mem1[1] & 2) != 0)  // isKernal?
			{
				thisTune.setIRQaddress(readEndian(c64mem1[0x0315],c64mem1[0x0314]));  // IRQ
			}
			else
			{
				thisTune.setIRQaddress(readEndian(c64mem1[0xffff],c64mem1[0xfffe]));  // NMI
			}
		}
		else
		{
			thisTune.setIRQaddress(0);
		}

#if defined(SIDEMU_TIME_COUNT)
		thisEmuEngine.resetSecondsThisSong();
#endif
		return true;

	}  // top else (emu&sidtune okay)
}