Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

player.cpp

Go to the documentation of this file.
00001 //
00002 // 1997/09/27 21:34:26
00003 //
00004 
00005 #include "player.h"
00006 #include "myendian.h"
00007 #include "6510_.h"
00008 #include "6581_.h"
00009 
00010 //extern ubyte playRamRom;
00011 
00012 // These texts are used to override the sidtune settings.
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 // Table used to check sidtune for usage of PlaySID digis.
00019 static const uword c64addrTable[] =
00020 {
00021         // PlaySID extended SID registers (0xd49d left out).
00022         //0xd41d, 0xd41e, 0xd41f,  // SID is too often written to as 32 bytes !
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         // Do a regular song initialization.
00036         bool ret = sidEmuInitializeSongOld(thisEmuEngine,thisTune,songNumber);
00037         if (ret && (thisEmuEngine.config.digiPlayerScans!=0))
00038         {
00039                 uword replayPC = thisTune.info.playAddr;
00040                 // playRamRom was set by sidEmuInitializeSongOld(..).
00041                 if ( replayPC == 0 )
00042                 {
00043                         thisEmuEngine.playRamRom = thisEmuEngine.iThe6510->c64mem1[1];
00044                         if ((thisEmuEngine.playRamRom & 2) != 0)  // isKernal ?
00045                         {
00046                                 replayPC = readLEword(c64mem1+0x0314);  // IRQ
00047                         }
00048                         else
00049                         {
00050                                 replayPC = readLEword(c64mem1+0xfffe);  // NMI
00051                         }
00052                 }
00053                 
00054                 // Run the music player for a couple of player calls and check for
00055                 // changes in the PlaySID extended SID registers. If no digis are
00056                 // used, apply a higher amplification on each SID voice. First
00057                 // check also covers writings of the player INIT routine.
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                 // Here re-init song, coz it was run.
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                 // ------------------------------------------- Determine clock/speed.
00100                 
00101                 // Get speed/clock setting for song and preselect
00102                 // speed/clock descriptions strings, reg = song init akkumulator.
00103                 ubyte reg = thisTune.selectSong(songNumber) -1;
00104 
00105                 ubyte the_clock, the_speed;
00106                 const char* the_description;
00107 
00108                 // ------------------------------------------------ Force song speed.
00109                 
00110                 if (thisEmuEngine.config.forceSongSpeed)
00111                 {
00112                         if (thisEmuEngine.config.clockSpeed == SIDTUNE_CLOCK_NTSC)
00113                         {
00114                                 // Set clock speed to NTSC.
00115                                 the_clock = SIDTUNE_CLOCK_NTSC;
00116                                 if (thisTune.info.songSpeed == SIDTUNE_SPEED_CIA_1A)  // CIA speed ?
00117                                 {
00118                                         // Set speed mode to CIA. Unless default CIA timer
00119                                         // will be changed, the resulting speed will be 60 Hz.
00120                                         the_speed = SIDTUNE_SPEED_CIA_1A;
00121                                         the_description = text_NTSC_CIA;
00122                                 }
00123                                 else  // fixed speed
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                                                 // Set speed mode to 60 Hz instead of 50|60 Hz.
00131                                                 // This will be same speed as NTSC VBI.
00132                                                 the_speed = SIDTUNE_SPEED_VBI_NTSC;
00133                                                 the_description = text_NTSC_VBI;
00134                                         }
00135                                         else
00136                                         {
00137                                                 // Set speed mode to fixed speed in Hz.
00138                                                 the_speed = thisTune.info.songSpeed;
00139                                                 the_description = text_NTSC_CIA;
00140                                         }
00141                                 }
00142                         }
00143                         else  //if (thisEmuEngine.config.clockSpeed == SIDTUNE_CLOCK_PAL)
00144                         {
00145                                 // Set clock speed to PAL.
00146                                 the_clock = SIDTUNE_CLOCK_PAL;
00147                                 if (thisTune.info.songSpeed == SIDTUNE_SPEED_CIA_1A)  // CIA speed ?
00148                                 {
00149                                         // Set speed mode to CIA. Unless default CIA timer
00150                                         // will be changed, the resulting speed will be 60 Hz.
00151                                         the_speed = SIDTUNE_SPEED_CIA_1A;
00152                                         the_description = text_PAL_CIA;
00153                                 }
00154                                 else  // fixed speed
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                                                 // Set speed mode to 50 Hz instead of 60|50 Hz.
00162                                                 // This will be same speed as PAL VBI.
00163                                                 the_speed = SIDTUNE_SPEED_VBI_PAL;
00164                                                 the_description = text_PAL_VBI;
00165                                         }
00166                                         else
00167                                         {
00168                                                 // Set speed mode to fixed speed in Hz.
00169                                                 the_speed = thisTune.info.songSpeed;
00170                                                 the_description = text_PAL_CIA;
00171                                         }
00172                                 }
00173                         }
00174                 }
00175                 else  // ---------------------------------- Do not force clock speed.
00176                 {
00177                         // Set clock speed (PAL/NTSC) and song speed (VBI/CIA).
00178                         the_clock = thisTune.info.clockSpeed;
00179                         the_speed = thisTune.info.songSpeed;
00180                         // Set speed string according to PAL/NTSC clock speed.
00181                         if (thisTune.info.clockSpeed == SIDTUNE_CLOCK_PAL)
00182                         {
00183                                 if (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI_PAL)  // VBI ?
00184                                 {
00185                                         the_description = text_PAL_VBI;
00186                                 }
00187                                 else  //if (thisTune.info.songSpeed == SIDTUNE_SPEED_CIA_1A)
00188                                 {
00189                                         the_description = text_PAL_CIA;
00190                                 }
00191                         }
00192                         else  //if (thisTune.info.clockSpeed == SIDTUNE_CLOCK_NTSC)
00193                         {
00194                                 if (thisTune.info.songSpeed == SIDTUNE_SPEED_VBI_NTSC)  // VBI ?
00195                                 {
00196                                         the_description = text_NTSC_VBI;
00197                                 }
00198                                 else  //if (thisTune.info.songSpeed == SIDTUNE_SPEED_CIA_1A)
00199                                 {
00200                                         the_description = text_NTSC_CIA;
00201                                 }
00202                         }
00203                 }
00204                 // Here transfer the settings to the emulator engine.
00205                 // From here we do not touch the SID clock speed setting.
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);  // assume fourth voice (digis)
00224                 if ( !thisEmuEngine.reset() )  // currently always returns true
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                 // In PlaySID-mode the interpreter will ignore some of the parameters.
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                 // This code is only used to be able to print out the initial IRQ address.
00239                 if (thisTune.info.playAddr == 0)
00240                 {
00241                         // Get the address of the interrupt handler.
00242                         if ((c64mem1[1] & 2) != 0)  // isKernal ?
00243                         {
00244                                 thisTune.setIRQaddress(readEndian(c64mem1[0x0315],c64mem1[0x0314]));  // IRQ
00245                         }
00246                         else
00247                         {
00248                                 thisTune.setIRQaddress(readEndian(c64mem1[0xffff],c64mem1[0xfffe]));  // NMI
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         }  // top else (all okay)
00262 }
00263 
00264 // EOF - PLAYER.CPP

Generated on Tue Feb 8 04:13:59 2005 for Esidplay by doxygen 1.3.3