event.c
  1  /*
  2  ** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)
  3  **
  4  **
  5  ** This program is free software; you can redistribute it and/or
  6  ** modify it under the terms of version 2 of the GNU Library General 
  7  ** Public License as published by the Free Software Foundation.
  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 GNU 
 12  ** Library General Public License for more details.  To obtain a 
 13  ** copy of the GNU Library General Public License, write to the Free 
 14  ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 15  **
 16  ** Any permitted reproduction of these routines, in whole or in part,
 17  ** must bear this legend.
 18  **
 19  **
 20  ** event.c
 21  **
 22  ** OS-independent event handling
 23  ** $Id: event.c,v 1.3 2001/04/27 14:37:11 neil Exp $
 24  */
 25  
 26  #include <stdlib.h>
 27  #include "noftypes.h"
 28  #include "event.h"
 29  #include "nesinput.h"
 30  
 31  
 32  
 33  /* pointer to our current system's event handler table */
 34  static event_t *system_events = NULL;
 35  
 36  /* standard keyboard input */
 37  static nesinput_t kb_input = { INP_JOYPAD0, 0 };
 38  static nesinput_t kb_alt_input = { INP_JOYPAD1, 0 };
 39  
 40  
 41  
 42  static void func_event_joypad1_a(int code)
 43  {
 44     input_event(&kb_input, code, INP_PAD_A);
 45  }
 46  
 47  static void func_event_joypad1_b(int code)
 48  {
 49     input_event(&kb_input, code, INP_PAD_B);
 50  }
 51  
 52  static void func_event_joypad1_start(int code)
 53  {
 54     input_event(&kb_input, code, INP_PAD_START);
 55  }
 56  
 57  static void func_event_joypad1_select(int code)
 58  {
 59     input_event(&kb_input, code, INP_PAD_SELECT);
 60  }
 61  
 62  static void func_event_joypad1_up(int code)
 63  {
 64     input_event(&kb_input, code, INP_PAD_UP);
 65  }
 66  
 67  static void func_event_joypad1_down(int code)
 68  {
 69     input_event(&kb_input, code, INP_PAD_DOWN);
 70  }
 71  
 72  static void func_event_joypad1_left(int code)
 73  {
 74     input_event(&kb_input, code, INP_PAD_LEFT);
 75  }
 76  
 77  static void func_event_joypad1_right(int code)
 78  {
 79     input_event(&kb_input, code, INP_PAD_RIGHT);
 80  }
 81  
 82  static void func_event_joypad2_a(int code)
 83  {
 84     input_event(&kb_alt_input, code, INP_PAD_A);
 85  }
 86  
 87  static void func_event_joypad2_b(int code)
 88  {
 89     input_event(&kb_alt_input, code, INP_PAD_B);
 90  }
 91  
 92  static void func_event_joypad2_start(int code)
 93  {
 94     input_event(&kb_alt_input, code, INP_PAD_START);
 95  }
 96  
 97  static void func_event_joypad2_select(int code)
 98  {
 99     input_event(&kb_alt_input, code, INP_PAD_SELECT);
100  }
101  
102  static void func_event_joypad2_up(int code)
103  {
104     input_event(&kb_alt_input, code, INP_PAD_UP);
105  }
106  
107  static void func_event_joypad2_down(int code)
108  {
109     input_event(&kb_alt_input, code, INP_PAD_DOWN);
110  }
111  
112  static void func_event_joypad2_left(int code)
113  {
114     input_event(&kb_alt_input, code, INP_PAD_LEFT);
115  }
116  
117  static void func_event_joypad2_right(int code)
118  {
119     input_event(&kb_alt_input, code, INP_PAD_RIGHT);
120  }
121  
122  
123  
124  /* NES events */
125  static const event_t nes_events[] =
126  {
127     NULL, /* 0 */
128     NULL,
129     NULL,
130     NULL,
131     NULL,
132     NULL,
133     NULL,
134     NULL,
135     NULL,
136     /* saves */
137     NULL,
138     NULL, /* 10 */
139     NULL,
140     NULL,
141     NULL,
142     NULL,
143     NULL,
144     NULL,
145     NULL,
146     NULL,
147     NULL,
148     NULL, /* 20 */
149     /* GUI */
150     NULL,
151     NULL,
152     NULL,
153     NULL,
154     NULL,
155     NULL,
156     NULL,
157     NULL,
158     /* sound */
159     NULL,
160     NULL, /* 30 */
161     NULL,
162     NULL,
163     NULL,
164     NULL,
165     NULL,
166     NULL,
167     NULL,
168     /* picture */
169     NULL,
170     NULL,
171     NULL,
172     NULL, /* 40 */
173     NULL,
174     NULL,
175     NULL,
176     /* joypad 1 */
177     func_event_joypad1_a,
178     func_event_joypad1_b, 
179     func_event_joypad1_start,
180     func_event_joypad1_select,
181     func_event_joypad1_up,
182     func_event_joypad1_down,
183     func_event_joypad1_left, /* 50 */
184     func_event_joypad1_right,
185     /* joypad 2 */
186     func_event_joypad2_a,
187     func_event_joypad2_b,
188     func_event_joypad2_start,
189     func_event_joypad2_select,
190     func_event_joypad2_up,
191     func_event_joypad2_down,
192     func_event_joypad2_left,
193     func_event_joypad2_right,
194     /* NSF control */
195     NULL, /* 60 */
196     NULL,
197     NULL,
198     /* OS-specific */
199     NULL,
200     NULL,
201     NULL,
202     NULL,
203     NULL,
204     NULL,
205     NULL,
206     NULL, /* 70 */
207     NULL,
208     /* last */
209     NULL
210  };
211  static event_t *event_system_table[NUM_SUPPORTED_SYSTEMS] =
212  {
213     NULL, /* unknown */
214     NULL, /* autodetect */
215     nes_events, /* nes */
216  };
217  
218  
219  
220  void event_init(void)
221  {
222     input_register(&kb_input);
223     input_register(&kb_alt_input);
224  }
225  
226  /* set up the event system for a certain console/system type */
227  void event_set_system(system_t type)
228  {
229     ASSERT(type < NUM_SUPPORTED_SYSTEMS);
230  
231     system_events = event_system_table[type];
232  }
233  
234  void event_set(int index, event_t handler)
235  {
236     /* now, event_set is used to set osd-specific events.  We should assume
237     ** (for now, at least) that these events should be used across all
238     ** emulated systems, so let's loop through all system event handler
239     ** tables and add this event...
240     */
241     int i;
242  
243     for (i = 0; i < NUM_SUPPORTED_SYSTEMS; i++)
244     {
245        if(event_system_table[i])
246        {
247           event_system_table[i][index] = handler;
248        }
249     }
250  }
251  
252  
253  event_t event_get(int index)
254  {
255     return system_events[index];
256  }
257  
258  
259  /*
260  ** $Log: event.c,v $
261  ** Revision 1.3  2001/04/27 14:37:11  neil
262  ** wheeee
263  **
264  ** Revision 1.2  2001/04/27 11:10:08  neil
265  ** compile
266  **
267  ** Revision 1.1.1.1  2001/04/27 07:03:54  neil
268  ** initial
269  **
270  ** Revision 1.18  2000/11/25 20:26:05  matt
271  ** removed fds "system"
272  **
273  ** Revision 1.17  2000/11/09 14:05:42  matt
274  ** state load fixed, state save mostly fixed
275  **
276  ** Revision 1.16  2000/11/05 16:37:18  matt
277  ** rolled rgb.h into bitmap.h
278  **
279  ** Revision 1.15  2000/11/01 17:33:26  neil
280  ** little crash bugs fixed
281  **
282  ** Revision 1.14  2000/11/01 14:15:35  matt
283  ** multi-system event system, or whatever
284  **
285  ** Revision 1.13  2000/10/27 12:59:48  matt
286  ** api change for ppu palette functions
287  **
288  ** Revision 1.12  2000/10/26 22:48:05  matt
289  ** no need for extern
290  **
291  ** Revision 1.11  2000/10/25 00:23:16  matt
292  ** makefiles updated for new directory structure
293  **
294  ** Revision 1.10  2000/10/23 17:50:46  matt
295  ** adding fds support
296  **
297  ** Revision 1.9  2000/10/23 15:52:04  matt
298  ** better system handling
299  **
300  ** Revision 1.8  2000/10/22 15:01:51  matt
301  ** prevented palette changing in VS unisystem games
302  **
303  ** Revision 1.7  2000/10/10 13:03:54  matt
304  ** Mr. Clean makes a guest appearance
305  **
306  ** Revision 1.6  2000/08/16 02:58:34  matt
307  ** random cleanups
308  **
309  ** Revision 1.5  2000/07/27 01:15:33  matt
310  ** name changes
311  **
312  ** Revision 1.4  2000/07/26 21:36:13  neil
313  ** Big honkin' change -- see the mailing list
314  **
315  ** Revision 1.3  2000/07/23 15:17:19  matt
316  ** non-osd calls moved from osd.c to gui.c
317  **
318  ** Revision 1.2  2000/07/21 12:07:40  neil
319  ** added room in event_array for all osd events
320  **
321  ** Revision 1.1  2000/07/21 04:26:38  matt
322  ** initial revision
323  **
324  */