00001
00002
00003
00004
00005 #include "player.h"
00006 #include "myendian.h"
00007 #include "6510_.h"
00008 #include "6581_.h"
00009
00010
00011
00012
00013 static const char text_PAL_VBI[] = "50 Hz VBI (PAL)";
00014 static const char text_PAL_CIA[] = "CIA 1 Timer A (PAL)";
00015 static const char text_NTSC_VBI[] = "60 Hz VBI (NTSC)";
00016 static const char text_NTSC_CIA[] = "CIA 1 Timer A (NTSC)";
00017
00018
00019 static const uword c64addrTable[] =
00020 {
00021
00022
00023 0xd43d, 0xd43e, 0xd43f,
00024 0xd45d, 0xd45e, 0xd45f, 0xd47d, 0xd47e, 0xd47f
00025 };
00026
00027
00028 EXPORT_C bool sidEmuInitializeSong(emuEngine & thisEmuEngine,
00029 sidTune & thisTune,
00030 uword songNumber)
00031 {
00032 ubyte* c64mem1 = thisEmuEngine.iThe6510->c64mem1;
00033 ubyte* c64mem2 = thisEmuEngine.iThe6510->c64mem2;
00034
00035
00036 bool ret = sidEmuInitializeSongOld(thisEmuEngine,thisTune,songNumber);
00037 if (ret && (thisEmuEngine.config.digiPlayerScans!=0))
00038 {
00039 uword replayPC = thisTune.info.playAddr;
00040
00041 if ( replayPC == 0 )
00042 {
00043 thisEmuEngine.playRamRom = thisEmuEngine.iThe6510->c64mem1[1];
00044 if ((thisEmuEngine.playRamRom & 2) != 0)
00045 {
00046 replayPC = readLEword(c64mem1+0x0314);
00047 }
00048 else
00049 {
00050 replayPC = readLEword(c64mem1+0xfffe);
00051 }
00052 }
00053
00054
00055
00056
00057
00058 bool useDigis = false;
00059 int loops = thisEmuEngine.config.digiPlayerScans;
00060 while (loops)
00061 {
00062 for (int i = 0; i < numberOfC64addr; i++)
00063 {
00064 if (thisEmuEngine.oldValues[i] != c64mem2[c64addrTable[i]])
00065 {
00066 useDigis = true;
00067 break;
00068 }
00069 thisEmuEngine.oldValues[i] = c64mem2[c64addrTable[i]];
00070 }
00071 thisEmuEngine.iThe6510->interpreter(replayPC, thisEmuEngine.playRamRom,0,0,0);
00072 loops--;
00073 if (useDigis)
00074 {
00075 break;
00076 }
00077 };
00078 thisEmuEngine.amplifyThreeVoiceTunes(!useDigis);
00079
00080 ret = sidEmuInitializeSongOld(thisEmuEngine,thisTune,songNumber);
00081 }
00082 return ret;
00083 }
00084
00085
00086 bool sidEmuInitializeSongOld(emuEngine & thisEmuEngine,
00087 sidTune & thisTune,
00088 uword songNumber)
00089 {
00090 ubyte* c64mem1 = thisEmuEngine.iThe6510->c64mem1;
00091 ubyte* c64mem2 = thisEmuEngine.iThe6510->c64mem2;
00092
00093 if (!thisEmuEngine.isReady || !thisTune.status )
00094 {
00095 return false;
00096 }
00097 else
00098 {
00099
00100
00101
00102
00103 ubyte reg = thisTune.selectSong(songNumber) -1;
00104
00105 ubyte the_clock, the_speed;
00106 const char* the_description;
00107
00108
00109
00110 if (thisEmuEngine.config.forceSongSpeed)
00111 {
00112 if (thisEmuEngine.config.clockSpeed == SIDTUNE_CLOCK_NTSC)
00113 {
00114
00115 the_clock = SIDTUNE_CLOCK_NTSC;
00116 if (thisTune.info.songSpeed == SIDTUNE_SPEED_CIA_1A)
00117 {
00118
00119
00120 the_speed = SIDTUNE_SPEED_CIA_1A;
00121 the_description = text_NTSC_CIA;
00122 }
00123 else
00124 {
00125 if ( ((thisTune.info.clockSpeed == SIDTUNE_CLOCK_PAL)
00126 && (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI_PAL))
00127 || ((thisTune.info.clockSpeed == SIDTUNE_CLOCK_NTSC)
00128 && (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI_NTSC)) )
00129 {
00130
00131
00132 the_speed = SIDTUNE_SPEED_VBI_NTSC;
00133 the_description = text_NTSC_VBI;
00134 }
00135 else
00136 {
00137
00138 the_speed = thisTune.info.songSpeed;
00139 the_description = text_NTSC_CIA;
00140 }
00141 }
00142 }
00143 else
00144 {
00145
00146 the_clock = SIDTUNE_CLOCK_PAL;
00147 if (thisTune.info.songSpeed == SIDTUNE_SPEED_CIA_1A)
00148 {
00149
00150
00151 the_speed = SIDTUNE_SPEED_CIA_1A;
00152 the_description = text_PAL_CIA;
00153 }
00154 else
00155 {
00156 if ( ((thisTune.info.clockSpeed == SIDTUNE_CLOCK_NTSC)
00157 && (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI_NTSC))
00158 || ((thisTune.info.clockSpeed == SIDTUNE_CLOCK_PAL)
00159 && (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI_PAL)) )
00160 {
00161
00162
00163 the_speed = SIDTUNE_SPEED_VBI_PAL;
00164 the_description = text_PAL_VBI;
00165 }
00166 else
00167 {
00168
00169 the_speed = thisTune.info.songSpeed;
00170 the_description = text_PAL_CIA;
00171 }
00172 }
00173 }
00174 }
00175 else
00176 {
00177
00178 the_clock = thisTune.info.clockSpeed;
00179 the_speed = thisTune.info.songSpeed;
00180
00181 if (thisTune.info.clockSpeed == SIDTUNE_CLOCK_PAL)
00182 {
00183 if (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI_PAL)
00184 {
00185 the_description = text_PAL_VBI;
00186 }
00187 else
00188 {
00189 the_description = text_PAL_CIA;
00190 }
00191 }
00192 else
00193 {
00194 if (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI_NTSC)
00195 {
00196 the_description = text_NTSC_VBI;
00197 }
00198 else
00199 {
00200 the_description = text_NTSC_CIA;
00201 }
00202 }
00203 }
00204
00205
00206 thisEmuEngine.iTheSidEmu->sidEmuSetReplayingSpeed(the_clock,the_speed);
00207 thisTune.info.speedString = the_description;
00208
00209
00210
00211 thisEmuEngine.MPUreset();
00212
00213 if ( !thisTune.placeSidTuneInC64mem(thisEmuEngine.MPUreturnRAMbase()) )
00214 {
00215 return false;
00216 }
00217
00218 if (thisTune.info.musPlayer)
00219 {
00220 thisTune.MUS_installPlayer(thisEmuEngine.MPUreturnRAMbase());
00221 }
00222
00223 thisEmuEngine.amplifyThreeVoiceTunes(false);
00224 if ( !thisEmuEngine.reset() )
00225 {
00226 return false;
00227 }
00228
00229 for (int i = 0; i < numberOfC64addr; i++)
00230 {
00231 thisEmuEngine.oldValues[i] = c64mem2[c64addrTable[i]];
00232 }
00233
00234
00235 thisEmuEngine.iThe6510->interpreter(thisTune.info.initAddr, thisEmuEngine.iThe6510->c64memRamRom(thisTune.info.initAddr),reg,reg,reg);
00236 thisEmuEngine.playRamRom = thisEmuEngine.iThe6510->c64memRamRom(thisTune.info.playAddr);
00237
00238
00239 if (thisTune.info.playAddr == 0)
00240 {
00241
00242 if ((c64mem1[1] & 2) != 0)
00243 {
00244 thisTune.setIRQaddress(readEndian(c64mem1[0x0315],c64mem1[0x0314]));
00245 }
00246 else
00247 {
00248 thisTune.setIRQaddress(readEndian(c64mem1[0xffff],c64mem1[0xfffe]));
00249 }
00250 }
00251 else
00252 {
00253 thisTune.setIRQaddress(0);
00254 }
00255
00256 #if defined(SIDEMU_TIME_COUNT)
00257 thisEmuEngine.resetSecondsThisSong();
00258 #endif
00259 return true;
00260
00261 }
00262 }
00263
00264