1 /* event.h: Routines needed for dealing with the event list
2 Copyright (c) 2000-2004 Philip Kendall
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 Author contact information:
19
20 E-mail: philip-fuse@shadowmagic.org.uk
21
22 */
23
24 #ifndef FUSE_EVENT_H
25 #define FUSE_EVENT_H
26
27 #ifdef HAVE_LIB_GLIB
28 #include <glib.h>
29 #endif /* #ifdef HAVE_LIB_GLIB */
30
31 #include <libspectrum.h>
32
33 /* Information about an event */
34 typedef struct event_t {
35 libspectrum_dword tstates;
36 int type;
37 void *user_data;
38 } event_t;
39
40 /* A null event type */
41 extern int event_type_null;
42
43 /* The function to be called when an event occurs */
44 typedef void (*event_fn_t)( libspectrum_dword tstates, int type, void *user_data );
45
46 /* When will the next event happen? */
47 extern libspectrum_dword event_next_event;
48
49 /* Register a new event type */
50 int event_register( event_fn_t fn, const char *description );
51
52 /* Add an event at the correct place in the event list */
53 void event_add_with_data( libspectrum_dword event_time, int type,
54 void *user_data );
55
56 static inline void
event_add(libspectrum_dword event_time,int type)57 event_add( libspectrum_dword event_time, int type )
58 {
59 event_add_with_data( event_time, type, NULL );
60 }
61
62 /* Do all events which have passed */
63 int event_do_events(void);
64
65 /* Called at end of frame to reduce T-state count of all entries */
66 void event_frame( libspectrum_dword tstates_per_frame );
67
68 /* Force all events between now and the next interrupt to happen */
69 void event_force_events( void );
70
71 /* Remove all events of a specific type from the stack */
72 void event_remove_type( int type );
73
74 /* Remove all events of a specific type and user data from the stack */
75 void event_remove_type_user_data( int type, gpointer user_data );
76
77 /* Clear the event stack */
78 void event_reset( void );
79
80 /* Call a user-supplied function for every event in the current list */
81 void event_foreach( GFunc function, gpointer user_data );
82
83 /* A textual representation of each event type */
84 const char *event_name( int type );
85
86 /* Register the init and end functions */
87 void event_register_startup( void );
88
89 #endif /* #ifndef FUSE_EVENT_H */
90