timercallback.pp 672 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. program timercallback;
  2. {$mode objfpc}
  3. uses
  4. ctypes, nds9;
  5. procedure waitfor(keys: cint);
  6. begin
  7. scanKeys();
  8. while ((keysDown() and keys) = 0) do
  9. begin
  10. swiWaitForVBlank();
  11. scanKeys();
  12. end;
  13. end;
  14. var
  15. channel: cuint = 0;
  16. play: boolean = true;
  17. //this function will be called by the timer.
  18. procedure timerCallBack();
  19. begin
  20. if (play) then
  21. soundPause(channel)
  22. else
  23. soundResume(channel);
  24. play := not play;
  25. end;
  26. begin
  27. soundEnable();
  28. channel := soundPlayPSG(DutyCycle_50, 10000, 127, 64);
  29. //calls the timerCallBack function 5 times per second.
  30. timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(5), @timerCallBack);
  31. waitfor(KEY_A);
  32. end.