Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. Pseudo-code for the Audio2 module (a service that implements a state machine to play audio for player 2)
  2. Data private to the module: MyPriority (number), CurrentState (state), inARMedMode, inPipeOut, inCelebration, Variables for frequencies of each note, Arrays of frequencies and delays of each tune
  3.  
  4. InitAudio2
  5. Takes a priority number, returns True
  6.  
  7. Initialize the MyPriority variable with the passed in parameter
  8. Initialize the port line to write to speaker 2
  9. Set CurrentState to Waiting2Play
  10. End of InitAudio2 (return True)
  11.  
  12. PostAudio2
  13. Takes an event to post, returns True if event was posted
  14. End of PostAudio2
  15.  
  16. RunAudio2
  17. Implements 2-state state machine for player 2’s audio
  18. The EventType of ThisEvent will be ES_PLAY_TUNE, ES_START_BUTTON_DB_DOWN, ES_PIPE_RECOVERED, ES_TIMEOUT,
  19. ES_GAINED_POINT, or ES_GAMEOVER; the EventParam will be ARMedMode,
  20. StartButton, SuccessWrench, SuccessBucket, FailBucket, PipeOut,
  21. PipeIn, CelebrationMode, FailureMode, PIPE_TIMER, or AUDIO2_TIMER
  22.  
  23.  
  24. Local Variables: NextState (state)
  25. Static Local Variable: TuneFreqs (array)
  26. Static Local Variable: TuneDelays (array)
  27. Static Local Variable: NumberOfNotes (number)
  28. Static Local Variable: CurrentNote (number)
  29.  
  30. Set NextState to CurrentState
  31. Based on the state of the CurrentState variable, choose one of the following blocks of code:
  32. CurrentState is Waiting2Play
  33. If ThisEvent is ES_PLAY_TUNE
  34. Set InARMedMode, inPipeOut, and inCelebration
  35. to zero
  36. Set TuneFreqs to frequency array corresponding
  37. to Event Parameter
  38. Set TuneDelays to delay array corresponding to
  39. Event Parameter
  40. Set NumberOfNotes to the length of TuneFreqs
  41. Play first note of TuneFreqs
  42. Set audio timer for length of first note in
  43. TuneDelays
  44. Set CurrentNote to 1
  45. Set NextState to Playing
  46. Endif
  47. End Waiting2Play block
  48.  
  49. CurrentState is Playing
  50. If (ThisEvent is ES_START_BUTTON_DBDOWN) or (ThisEvent is ES_PIPE_RECOVERED) or (ThisEvent is ES_TIMEOUT and Event Parameter is PIPE_TIMER and inCelebration is 0) or (ThisEvent is ES_GAINED_POINT) or (ThisEvent is ES_GAMEOVER)
  51. Set NextState to Waiting2Play
  52. Play nothing
  53. EndIf
  54. If ThisEvent is ES_TIMEOUT and Event Parameter is
  55. AUDIO2_TIMER
  56. If CurrentNote equals NumberOfNotes
  57. If inArmedMode equals 1
  58. Post event ES_PLAY_TUNE to Audio2
  59. with event parameter ARMedMode
  60. Endif
  61. If inPipeOut equals 1
  62. Post event ES_PLAY_TUNE to Audio2
  63. with event parameter PipeOut
  64. Endif
  65. Play nothing
  66. Set NextState to Waiting2Play
  67. Endif
  68. If CurrentNote < NumberOfNotes
  69. Play note of TuneFreqs with index
  70. CurrentNote
  71. Set audio timer for length of note in
  72. TuneDelays with index CurrentNote
  73. Increment CurrentNote
  74. Endif
  75. Endif
  76. End Playing block
  77.  
  78. Set CurrentState to NextState
  79.  
  80. Return ES_NO_EVENT
  81. End of RunAudio2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement