Files
TempleOS-Rijn/LT/Demo/MultiCore.CPZ
T
2018-09-08 21:45:20 +02:00

95 lines
1.5 KiB
Plaintext

/*
This demo uses some memory which is
uncached and can be accessed by
both CPU's.
See $LK,"Memory","HI:Memory"$
*/
class XferCtrl
{
BoolU4 done;
I1 buf[512];
I8 cnt;
TssStruct *song_tsk;
};
XferCtrl *xc;
void SongEndTsk()
{
Sound(0);
Exit;
}
void SongTsk()
{
Fs->end_task_cb=&SongEndTsk;
ResetMusicSettings;
while (TRUE) {
Play("3qG2G3DBsDCDCqRCG");
Play("G2G3DBsDCDCqRCG");
Play("EeGFqBBDA2eGGqR");
Play("3EeGFqBBDA2eGGqR");
}
}
void CPU1Tsk1()
{
Preempt(ON);
xc->song_tsk=Spawn(&SongTsk,"MultiCore Song");
while (!xc->done) {
SPrintF(xc->buf,"Hi %d",xc->cnt);
SPrintF(xc->buf,"Low %d",xc->cnt);
xc->cnt++;
}
xc->done=FALSE;
}
void CPU1Tsk2()
{
Preempt(ON);
Kill(xc->song_tsk);
while (!xc->done) {
SPrintF(xc->buf,"Up %d",xc->cnt);
SPrintF(xc->buf,"Down%d",xc->cnt);
xc->cnt--;
}
xc->done=FALSE;
}
void CPU0Tsk()
{
//$FG,2$Allocate off of the write-through heap$FG$
xc=MAllocHC(sizeof(XferCtrl),mp_heap);
WbInvd; //$FG,2$Flush xc out of Cache.$FG$
xc->cnt=0;
xc->done=FALSE;
*xc->buf=0;
MPQueueJob(&CPU1Tsk1);
while (!ScanKey) {
coutln xc->cnt,":",xc->buf;
SwapInNext;
}
xc->done=TRUE;
while (xc->done)
SwapInNext;
MPQueueJob(&CPU1Tsk2);
while (!ScanKey) {
coutln xc->cnt,":",xc->buf;
SwapInNext;
}
xc->done=TRUE;
while (xc->done)
SwapInNext;
FreeHC(xc,mp_heap);
}
CPU0Tsk;