summaryrefslogtreecommitdiffstats
path: root/clock.c
blob: 754fd156c9f580594821e8093504d58f3e454104 (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
45
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>

#include "z80.h"
#include "screen.h"

/*
 * Trig a non maskable interrupt in the Z80 on the clock signal.
 */
static Uint32 clock_handler(Uint32 interval, void *param)
{
    (void)param;
    z80_state.nminterrupt = 1;
    return interval;
}


/*
 * Set up signal handler and schedule a signal every 20 ms.
 */
void
clock_init(void)
{
    SDL_AddTimer(20, clock_handler, NULL);
}

/* Standard callback routine to post a periodic user event */
/* (int)param is the event code */
Uint32 post_periodic(Uint32 interval, void *param)
{
  SDL_Event event;
  event.type = SDL_USEREVENT;
  event.user.code  = 0;
  event.user.data1 = param;
  event.user.data2 = 0;

  if ( event_pending < 32 )
    SDL_PushEvent(&event);

  event_pending++;

  return interval;
}