allow playing KidVid without tapes

This commit is contained in:
Thomas Jentzsch 2022-09-01 17:47:19 +02:00
parent 601287f8c7
commit 3789843b39
2 changed files with 50 additions and 52 deletions

View File

@ -42,7 +42,22 @@ KidVid::~KidVid()
closeSampleFile();
}
#include "System.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KidVid::write(DigitalPin pin, bool value)
{
// Change the pin state based on value
switch(pin)
{
// Pin 1: Signal tape running or stopped
case DigitalPin::One:
setPin(DigitalPin::One, value);
break;
default:
break;
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KidVid::update()
@ -92,26 +107,10 @@ void KidVid::update()
openSampleFile();
}
// Convert separate pin states into a 'register'
uInt8 IOPortA = 0b11110000;
if(getPin(DigitalPin::One)) IOPortA |= 0b0001;
if(getPin(DigitalPin::Two)) IOPortA |= 0b0010;
if(getPin(DigitalPin::Three)) IOPortA |= 0b0100;
if(getPin(DigitalPin::Four)) IOPortA |= 0b1000;
// Is the tape running?
if((myTape != 0) && ((IOPortA & 0b0001) == 0b0001) && !myTapeBusy)
if(myTape != 0 && getPin(DigitalPin::One) && !myTapeBusy)
{
IOPortA = (IOPortA & 0b11110111) | (((ourKVData[myIdx >> 3] << (myIdx & 0x07)) & 0x80) >> 4);
//cerr << endl << std::dec << IOPortA << " ";
// Now convert the register back into separate boolean values
//setPin(DigitalPin::One, IOPortA & 0b0001);
//setPin(DigitalPin::Two, IOPortA & 0b0010);
//setPin(DigitalPin::Three, IOPortA & 0b0100);
//if(IOPortA != 0xff)
// int i = 0;
setPin(DigitalPin::Four, IOPortA & 0b1000);
setPin(DigitalPin::Four, (ourKVData[myIdx >> 3] << (myIdx & 0x07)) & 0x80);
// increase to next bit
++myIdx;
@ -131,7 +130,7 @@ void KidVid::update()
else
{
myIdx = 36 * 8;//KVPause-KVData=36
cerr << endl << "Auto ";
//cerr << endl << "Auto ";
setNextSong();
}
}
@ -150,26 +149,10 @@ void KidVid::update()
myBlockIdx = KVBLOCKBITS;
}
}
#ifdef KID_TAPE
else
myTapeBusy = false;
//if(myFileOpened && ((IOPortA & 0b1000) == 0b1000) || myTapeBusy)
//{
// for(int i = 0; i < 266 * 2; ++i)
// getNextSampleByte();
// cerr << mySongCounter << " ";
//}
////else
//{
// if((myTape != 0) && ((IOPortA & 0b1000) == 0b0000) && myTapeBusy)
// {
// //while(myBeep && myTapeBusy && ((IOPortA & 0b0001) == 0b0001)) // mySongCounter; ++i)
// for(int i = mySongCounter / 8; i >= 0; --i)
// getNextSampleByte();
// cerr << mySongCounter << " ";
// }
//}
#endif
// emulate playing the songs (but MUCH faster!)
// TODO: this has to be done by an Audio class
for(int i = mySongCounter / 8; i >= 0; --i)
getNextSampleByte();
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -235,6 +218,7 @@ void KidVid::closeSampleFile()
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KidVid::setNextSong()
{
#ifdef KID_TAPE
if(myFileOpened)
{
cerr << endl << std::dec << mySongCounter << ", " << myFilePointer << endl;
@ -244,33 +228,34 @@ void KidVid::setNextSong()
mySharedData = (temp < 10);
mySongCounter = ourSongStart[temp+1] - ourSongStart[temp];
#ifdef KID_TAPE
if(mySharedData)
fseek(mySharedSampleFile, ourSongStart[temp], SEEK_SET);
else
fseek(mySampleFile, ourSongStart[temp], SEEK_SET);
#endif
++myFilePointer;
myTapeBusy = true;
}
else
#endif
{
myBeep = true;
myTapeBusy = true;
mySongCounter = 80*262; /* delay needed for Harmony without tape */
mySongCounter = 10 * 80*262; /* delay needed for Harmony without tape */
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void KidVid::getNextSampleByte()
{
#ifdef KID_TAPE
static int oddeven = 0;
#endif
if(mySongCounter == 0)
mySampleByte = 0x80;
{
#ifdef KID_TAPE
mySampleByte = 0x80;
#endif
}
else
{
oddeven = oddeven^1;
@ -279,6 +264,7 @@ void KidVid::getNextSampleByte()
mySongCounter--;
myTapeBusy = (mySongCounter > 262 * 48) || !myBeep;
#ifdef KID_TAPE
if(myFileOpened)
{
if(mySharedData)
@ -288,12 +274,12 @@ void KidVid::getNextSampleByte()
}
else
mySampleByte = 0x80;
#endif
if(!myBeep && (mySongCounter == 0))
setNextSong();
}
}
#endif
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

View File

@ -54,6 +54,16 @@ class KidVid : public Controller
~KidVid() override;
public:
/**
Write the given value to the specified digital pin for this
controller. Writing is only allowed to the pins associated
with the PIA. Therefore you cannot write to pin six.
@param pin The pin of the controller jack to write to
@param value The value to write to the pin
*/
void write(DigitalPin pin, bool value) override;
/**
Update the entire digital and analog pin state according to the
events currently set.
@ -95,17 +105,19 @@ class KidVid : public Controller
#ifdef KID_TAPE
// The file handles for the WAV files
FILE *mySampleFile{nullptr}, *mySharedSampleFile{nullptr};
#endif
// Indicates if sample files have been successfully opened
bool myFileOpened{false};
uInt32 myFilePointer{0};
bool mySharedData{false};
uInt8 mySampleByte{0};
#endif
// Is the tape currently 'busy' / in use?
bool myTapeBusy{false};
uInt32 myFilePointer{0}, mySongCounter{0};
bool myBeep{false}, mySharedData{false};
uInt8 mySampleByte{0};
uInt32 mySongCounter{0};
bool myBeep{false};
uInt32 myGame{0}, myTape{0};
uInt32 myIdx{0}, myBlock{0}, myBlockIdx{0};