File: module.c

package info (click to toggle)
fuse-emulator 1.6.0%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 9,228 kB
  • sloc: ansic: 93,856; sh: 4,334; perl: 3,921; makefile: 998; yacc: 245; lex: 139
file content (124 lines) | stat: -rw-r--r-- 2,833 bytes parent folder | download | duplicates (4)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* module.c: API for Fuse modules
   Copyright (c) 2007 Philip Kendall

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

   Author contact information:

   E-mail: philip-fuse@shadowmagic.org.uk

*/

#include <config.h>

#ifdef HAVE_LIB_GLIB
#include <glib.h>
#endif				/* #ifdef HAVE_LIB_GLIB */

#include <libspectrum.h>

#include "compat.h"
#include "module.h"

static GSList *registered_modules = NULL;

int
module_register( module_info_t *module )
{
  registered_modules = g_slist_append( registered_modules, module );

  return 0;
}

void
module_end( void )
{
  g_slist_free( registered_modules );
  registered_modules = NULL;
}

static void
reset( gpointer data, gpointer user_data )
{
  const module_info_t *module = data;
  int hard_reset = GPOINTER_TO_INT( user_data );

  if( module->reset ) module->reset( hard_reset );
}

void
module_reset( int hard_reset )
{
  g_slist_foreach( registered_modules, reset, GINT_TO_POINTER( hard_reset ) );
}

static void
romcs( gpointer data, gpointer user_data GCC_UNUSED )
{
  const module_info_t *module = data;

  if( module->romcs ) module->romcs();
}

void
module_romcs( void )
{
  g_slist_foreach( registered_modules, romcs, NULL );
}

static void
snapshot_enabled( gpointer data, gpointer user_data )
{
  const module_info_t *module = data;
  libspectrum_snap *snap = user_data;

  if( module->snapshot_enabled ) module->snapshot_enabled( snap );
}

void
module_snapshot_enabled( libspectrum_snap *snap )
{
  g_slist_foreach( registered_modules, snapshot_enabled, snap );
}

static void
snapshot_from( gpointer data, gpointer user_data )
{
  const module_info_t *module = data;
  libspectrum_snap *snap = user_data;

  if( module->snapshot_from ) module->snapshot_from( snap );
}

void
module_snapshot_from( libspectrum_snap *snap )
{
  g_slist_foreach( registered_modules, snapshot_from, snap );
}

static void
snapshot_to( gpointer data, gpointer user_data )
{
  const module_info_t *module = data;
  libspectrum_snap *snap = user_data;

  if( module->snapshot_to ) module->snapshot_to( snap );
}

void
module_snapshot_to( libspectrum_snap *snap )
{
  g_slist_foreach( registered_modules, snapshot_to, snap );
}