summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/libndsfpc/examples/time/timercallback/timercallback.pp
blob: a4f5dd424ffe2bad574d5e56d59ce58b61550c1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
program timercallback;


{$mode objfpc}

uses
  ctypes, nds9;
  
  
procedure waitfor(keys: cint);
begin
  scanKeys();
  while ((keysDown() and keys) = 0) do
  begin
    swiWaitForVBlank();
    scanKeys();
  end;
end;

var
  channel: cuint = 0;
  play: boolean = true;

//this function will be called by the timer.
procedure timerCallBack();
begin
	if (play) then
		soundPause(channel)
	else
		soundResume(channel);

	play := not play;
end;

begin
	soundEnable();
	channel := soundPlayPSG(DutyCycle_50, 10000, 127, 64);

	//calls the timerCallBack function 5 times per second.
	timerStart(0, ClockDivider_1024, TIMER_FREQ_1024(5), @timerCallBack);

	waitfor(KEY_A);

end.