Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

*************************************************************************************

Psuedo-code for Sound service

InitializeSoundService
Takes a priority number, returns True.

Initialize the MyPriority variable with the passed in parameter.


Set CurrentState to Ready2PlaySound
Post ES_INIT to this service
End of InitializeSoundService

RunSoundService
Set ReturnEvent to ES_NO_EVENT
Set NextState to CurrentState

Based on the state of the CurrentState variable choose one of the following blocks of code:
CurrentState is Ready2PlaySound
If ThisEvent is ES_INIT
Turn off all sound
Initialize deferral queue
EndIf
If ThisEvent is ES_LEAF_INSERTED
Set SOUND_WALL_E bit low
Start SOUND_TRIGGER_TIMER to SOUND_TRIGGER_TIME
Start SOUND_HOLD_TIMER to TIME_WALL_E
Set NextState to PlayingSound
EndIf
If ThisEvent is ES_EVE_TRIGGER
Set EVE_SOUND bit low
Start SOUND_TRIGGER_TIMER to SOUND_TRIGGER_TIME
Set NextState to PlayingSound
EndIf
If ThisEvent is ES_GAME_LOST
Set SOUND_SAD_WALL_E bit low
Start SOUND_TRIGGER_TIMER to SOUND_TRIGGER_TIME
Set NextState to PlayingSound
EndIf
If ThisEvent is ES_GAME_WON
Set SOUND_RECYCLE bit low
Start SOUND_TRIGGER_TIMER to SOUND_TRIGGER_TIME
Set NextState to PlayingSound
EndIf
If ThisEvent is ES_INCORRECT_ANSWER
Set SOUND_INCORRECT_ANSWER bit low
Start SOUND_TRIGGER_TIMER to SOUND_TRIGGER_TIME
Set NextState to PlayingSound
EndIf
If ThisEvent is ES_CORRECT_ANSWER
Set SOUND_CORRECT_ANSWER bit low
Start SOUND_TRIGGER_TIMER to SOUND_TRIGGER_TIME
Set NextState to PlayingSound
EndIf
If ThisEvent is ES_NEED_EVE
Set SOUND_MISSING_EVE bit low
Start SOUND_TRIGGER_TIMER to SOUND_TRIGGER_TIME
Set NextState to PlayingSound
EndIf
If ThisEvent is ES_GAME_STARTED
Set SOUND_START_GAME bit low
Start SOUND_TRIGGER_TIMER to SOUND_TRIGGER_TIME
Set NextState to PlayingSound
EndIf
End Ready2PlaySound block

CurrentState is PlayingSound
If ThisEvent is ES_TIMEOUT
If EventParam is SOUND_TRIGGER_TIMER
Turn all sound bits low
EndIf
If EventParam is SOUND_HOLD_TIMER
Set NextState to Ready2PlaySound
Recall deferred events
EndIf
Else
Defer sound to deferral queue
EndIf
End PlayingSound block
Set CurrentState to NextState
Return ReturnEvent
End RunSoundService

You might also like