revision 144:7f0714e89aaa
summary |
tree |
shortlog |
changelog |
graph |
changeset |
raw | bz2 | zip | gz changeset | 144:7f0714e89aaa |
parent | 143:9446fb6df0c5 |
child | 145:8f1af16b0665 |
author | nkeynes |
date | Mon May 15 08:28:52 2006 +0000 (17 years ago) |
Rename video_driver to display_driver
Add input source to display
Implement configuration file support
Hook controllers up to configuration
Add input source to display
Implement configuration file support
Hook controllers up to configuration
1.1 --- a/src/Makefile.am Wed May 03 12:52:38 2006 +00001.2 +++ b/src/Makefile.am Mon May 15 08:28:52 2006 +00001.3 @@ -32,6 +32,7 @@1.4 gui/gui.c gui/gui.h gui/mmr_win.c \1.5 gui/debug_win.c gui/dump_win.c \1.6 loader.c bootstrap.c util.c \1.7 + display.c display.h \1.8 drivers/audio_null.c drivers/audio_esd.c \1.9 drivers/video_null.c drivers/video_gtk.c drivers/video_gtk.h \1.10 drivers/video_x11.c drivers/video_x11.h
2.1 --- a/src/Makefile.in Wed May 03 12:52:38 2006 +00002.2 +++ b/src/Makefile.in Mon May 15 08:28:52 2006 +00002.3 @@ -159,6 +159,7 @@2.4 gui/gui.c gui/gui.h gui/mmr_win.c \2.5 gui/debug_win.c gui/dump_win.c \2.6 loader.c bootstrap.c util.c \2.7 + display.c display.h \2.8 drivers/audio_null.c drivers/audio_esd.c \2.9 drivers/video_null.c drivers/video_gtk.c drivers/video_gtk.h \2.10 drivers/video_x11.c drivers/video_x11.h2.11 @@ -187,9 +188,9 @@2.12 controller.$(OBJEXT) support.$(OBJEXT) interface.$(OBJEXT) \2.13 callbacks.$(OBJEXT) gui.$(OBJEXT) mmr_win.$(OBJEXT) \2.14 debug_win.$(OBJEXT) dump_win.$(OBJEXT) loader.$(OBJEXT) \2.15 - bootstrap.$(OBJEXT) util.$(OBJEXT) audio_null.$(OBJEXT) \2.16 - audio_esd.$(OBJEXT) video_null.$(OBJEXT) video_gtk.$(OBJEXT) \2.17 - video_x11.$(OBJEXT)2.18 + bootstrap.$(OBJEXT) util.$(OBJEXT) display.$(OBJEXT) \2.19 + audio_null.$(OBJEXT) audio_esd.$(OBJEXT) video_null.$(OBJEXT) \2.20 + video_gtk.$(OBJEXT) video_x11.$(OBJEXT)2.21 dream_OBJECTS = $(am_dream_OBJECTS)2.22 dream_DEPENDENCIES =2.23 dream_LDFLAGS =2.24 @@ -204,22 +205,22 @@2.25 @AMDEP_TRUE@ ./$(DEPDIR)/bios.Po ./$(DEPDIR)/bootstrap.Po \2.26 @AMDEP_TRUE@ ./$(DEPDIR)/callbacks.Po ./$(DEPDIR)/controller.Po \2.27 @AMDEP_TRUE@ ./$(DEPDIR)/dcload.Po ./$(DEPDIR)/debug_win.Po \2.28 -@AMDEP_TRUE@ ./$(DEPDIR)/dmac.Po ./$(DEPDIR)/dreamcast.Po \2.29 -@AMDEP_TRUE@ ./$(DEPDIR)/dump_win.Po ./$(DEPDIR)/gdrom.Po \2.30 -@AMDEP_TRUE@ ./$(DEPDIR)/gui.Po ./$(DEPDIR)/ide.Po \2.31 -@AMDEP_TRUE@ ./$(DEPDIR)/intc.Po ./$(DEPDIR)/interface.Po \2.32 -@AMDEP_TRUE@ ./$(DEPDIR)/loader.Po ./$(DEPDIR)/main.Po \2.33 -@AMDEP_TRUE@ ./$(DEPDIR)/maple.Po ./$(DEPDIR)/mem.Po \2.34 -@AMDEP_TRUE@ ./$(DEPDIR)/mmr_win.Po ./$(DEPDIR)/nrg.Po \2.35 -@AMDEP_TRUE@ ./$(DEPDIR)/pvr2.Po ./$(DEPDIR)/render.Po \2.36 -@AMDEP_TRUE@ ./$(DEPDIR)/scif.Po ./$(DEPDIR)/sh4core.Po \2.37 -@AMDEP_TRUE@ ./$(DEPDIR)/sh4dasm.Po ./$(DEPDIR)/sh4mem.Po \2.38 -@AMDEP_TRUE@ ./$(DEPDIR)/sh4mmio.Po ./$(DEPDIR)/support.Po \2.39 -@AMDEP_TRUE@ ./$(DEPDIR)/syscall.Po ./$(DEPDIR)/ta.Po \2.40 -@AMDEP_TRUE@ ./$(DEPDIR)/texcache.Po ./$(DEPDIR)/timer.Po \2.41 -@AMDEP_TRUE@ ./$(DEPDIR)/util.Po ./$(DEPDIR)/video_gtk.Po \2.42 -@AMDEP_TRUE@ ./$(DEPDIR)/video_null.Po ./$(DEPDIR)/video_x11.Po \2.43 -@AMDEP_TRUE@ ./$(DEPDIR)/watch.Po2.44 +@AMDEP_TRUE@ ./$(DEPDIR)/display.Po ./$(DEPDIR)/dmac.Po \2.45 +@AMDEP_TRUE@ ./$(DEPDIR)/dreamcast.Po ./$(DEPDIR)/dump_win.Po \2.46 +@AMDEP_TRUE@ ./$(DEPDIR)/gdrom.Po ./$(DEPDIR)/gui.Po \2.47 +@AMDEP_TRUE@ ./$(DEPDIR)/ide.Po ./$(DEPDIR)/intc.Po \2.48 +@AMDEP_TRUE@ ./$(DEPDIR)/interface.Po ./$(DEPDIR)/loader.Po \2.49 +@AMDEP_TRUE@ ./$(DEPDIR)/main.Po ./$(DEPDIR)/maple.Po \2.50 +@AMDEP_TRUE@ ./$(DEPDIR)/mem.Po ./$(DEPDIR)/mmr_win.Po \2.51 +@AMDEP_TRUE@ ./$(DEPDIR)/nrg.Po ./$(DEPDIR)/pvr2.Po \2.52 +@AMDEP_TRUE@ ./$(DEPDIR)/render.Po ./$(DEPDIR)/scif.Po \2.53 +@AMDEP_TRUE@ ./$(DEPDIR)/sh4core.Po ./$(DEPDIR)/sh4dasm.Po \2.54 +@AMDEP_TRUE@ ./$(DEPDIR)/sh4mem.Po ./$(DEPDIR)/sh4mmio.Po \2.55 +@AMDEP_TRUE@ ./$(DEPDIR)/support.Po ./$(DEPDIR)/syscall.Po \2.56 +@AMDEP_TRUE@ ./$(DEPDIR)/ta.Po ./$(DEPDIR)/texcache.Po \2.57 +@AMDEP_TRUE@ ./$(DEPDIR)/timer.Po ./$(DEPDIR)/util.Po \2.58 +@AMDEP_TRUE@ ./$(DEPDIR)/video_gtk.Po ./$(DEPDIR)/video_null.Po \2.59 +@AMDEP_TRUE@ ./$(DEPDIR)/video_x11.Po ./$(DEPDIR)/watch.Po2.60 COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \2.61 $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)2.62 CCLD = $(CC)2.63 @@ -285,6 +286,7 @@2.64 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/controller.Po@am__quote@2.65 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dcload.Po@am__quote@2.66 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/debug_win.Po@am__quote@2.67 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/display.Po@am__quote@2.68 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dmac.Po@am__quote@2.69 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dreamcast.Po@am__quote@2.70 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dump_win.Po@am__quote@
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00003.2 +++ b/src/display.c Mon May 15 08:28:52 2006 +00003.3 @@ -0,0 +1,139 @@3.4 +/**3.5 + * $Id: display.c,v 1.1 2006-05-15 08:28:48 nkeynes Exp $3.6 + *3.7 + * Generic support for keyboard and other input sources. The active display3.8 + * driver is expected to deliver events here, where they're translated and3.9 + * passed to the appropriate dreamcast controllers (if any).3.10 + *3.11 + * Copyright (c) 2005 Nathan Keynes.3.12 + *3.13 + * This program is free software; you can redistribute it and/or modify3.14 + * it under the terms of the GNU General Public License as published by3.15 + * the Free Software Foundation; either version 2 of the License, or3.16 + * (at your option) any later version.3.17 + *3.18 + * This program is distributed in the hope that it will be useful,3.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of3.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the3.21 + * GNU General Public License for more details.3.22 + */3.23 +3.24 +#include <stdint.h>3.25 +#include <assert.h>3.26 +#include "dream.h"3.27 +#include "display.h"3.28 +3.29 +typedef struct keymap_entry {3.30 + uint16_t keycode;3.31 + input_key_callback_t callback;3.32 + void *data;3.33 + uint32_t value;3.34 +} *keymap_entry_t;3.35 +3.36 +/**3.37 + * FIXME: make this more memory efficient3.38 + */3.39 +struct keymap_entry *keymap[65536];3.40 +3.41 +3.42 +static struct keymap_entry *input_create_key( uint16_t keycode )3.43 +{3.44 + struct keymap_entry *key = keymap[ keycode ];3.45 + if( key == NULL ) {3.46 + key = malloc( sizeof( struct keymap_entry ) );3.47 + assert( key != NULL );3.48 + keymap[ keycode ] = key;3.49 + key->keycode = keycode;3.50 + }3.51 + return key;3.52 +}3.53 +3.54 +static void input_delete_key( uint16_t keycode )3.55 +{3.56 + struct keymap_entry *key = keymap[keycode];3.57 + if( key != NULL ) {3.58 + free( key );3.59 + keymap[keycode] = NULL;3.60 + }3.61 +}3.62 +3.63 +static struct keymap_entry *input_get_key( uint16_t keycode )3.64 +{3.65 + return keymap[ keycode ];3.66 +}3.67 +3.68 +gboolean input_register_key( const gchar *keysym, input_key_callback_t callback,3.69 + void *data, uint32_t value )3.70 +{3.71 + if( display_driver == NULL || keysym == NULL )3.72 + return FALSE; /* No display driver */3.73 + uint16_t keycode = display_driver->resolve_keysym(keysym);3.74 + if( keycode == 0 )3.75 + return FALSE; /* Invalid keysym */3.76 +3.77 + struct keymap_entry *key = input_create_key( keycode );3.78 + key->callback = callback;3.79 + key->data = data;3.80 + key->value = value;3.81 + INFO( "Registered key '%s' (%4x)", keysym, keycode );3.82 + return TRUE;3.83 +}3.84 +3.85 +void input_unregister_key( const gchar *keysym )3.86 +{3.87 + if( display_driver == NULL || keysym == NULL )3.88 + return;3.89 + uint16_t keycode = display_driver->resolve_keysym(keysym);3.90 + if( keycode == 0 )3.91 + return;3.92 + input_delete_key( keycode );3.93 +}3.94 +3.95 +3.96 +gboolean input_is_key_valid( const gchar *keysym )3.97 +{3.98 + if( display_driver == NULL )3.99 + return FALSE; /* No display driver */3.100 + return display_driver->resolve_keysym(keysym) != 0;3.101 +}3.102 +3.103 +gboolean input_is_key_registered( const gchar *keysym )3.104 +{3.105 + if( display_driver == NULL )3.106 + return FALSE;3.107 + uint16_t keycode = display_driver->resolve_keysym(keysym);3.108 + if( keycode == 0 )3.109 + return FALSE;3.110 + return input_get_key( keycode ) != NULL;3.111 +}3.112 +3.113 +void input_event_keydown( uint16_t keycode )3.114 +{3.115 + struct keymap_entry *key = input_get_key(keycode);3.116 + if( key != NULL ) {3.117 + key->callback( key->data, key->value, TRUE );3.118 + }3.119 +}3.120 +3.121 +void input_event_keyup( uint16_t keycode )3.122 +{3.123 + struct keymap_entry *key = input_get_key(keycode);3.124 + if( key != NULL ) {3.125 + key->callback( key->data, key->value, FALSE );3.126 + }3.127 +}3.128 +3.129 +3.130 +3.131 +void display_set_driver( display_driver_t driver )3.132 +{3.133 + if( display_driver != NULL && display_driver->shutdown_driver != NULL )3.134 + display_driver->shutdown_driver();3.135 +3.136 + display_driver = driver;3.137 + if( driver->init_driver != NULL )3.138 + driver->init_driver();3.139 + driver->set_display_format( 640, 480, COLFMT_ARGB8888 );3.140 + driver->set_render_format( 640, 480, COLFMT_ARGB8888, FALSE );3.141 + texcache_gl_init();3.142 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00004.2 +++ b/src/display.h Mon May 15 08:28:52 2006 +00004.3 @@ -0,0 +1,155 @@4.4 +/**4.5 + * $Id: display.h,v 1.1 2006-05-15 08:28:48 nkeynes Exp $4.6 + *4.7 + * The PC side of the video support (responsible for actually displaying /4.8 + * rendering frames)4.9 + *4.10 + * Copyright (c) 2005 Nathan Keynes.4.11 + *4.12 + * This program is free software; you can redistribute it and/or modify4.13 + * it under the terms of the GNU General Public License as published by4.14 + * the Free Software Foundation; either version 2 of the License, or4.15 + * (at your option) any later version.4.16 + *4.17 + * This program is distributed in the hope that it will be useful,4.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of4.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the4.20 + * GNU General Public License for more details.4.21 + */4.22 +4.23 +#ifndef dream_video_H4.24 +#define dream_video_H4.25 +4.26 +#include <stdint.h>4.27 +#include <glib.h>4.28 +4.29 +#ifdef __cplusplus4.30 +extern "C" {4.31 +#endif4.32 +4.33 +/**4.34 + * Supported colour formats. Note that ARGB4444 is only ever used for texture4.35 + * rendering (it's not valid for display purposes).4.36 + */4.37 +#define COLFMT_RGB565 14.38 +#define COLFMT_RGB888 44.39 +#define COLFMT_ARGB1555 04.40 +#define COLFMT_ARGB8888 54.41 +#define COLFMT_ARGB4444 24.42 +#define COLFMT_YUV422 3 /* 8-bit YUV (texture source only) */4.43 +#define COLFMT_INDEX4 6 /* 4 bit indexed colour (texture source only) */4.44 +#define COLFMT_INDEX8 7 /* 8-bit indexed colour (texture source only) */4.45 +4.46 +typedef struct video_buffer {4.47 + uint32_t hres;4.48 + uint32_t vres;4.49 + uint32_t rowstride;4.50 + int colour_format;4.51 + char *data;4.52 +} *video_buffer_t;4.53 +4.54 +/**4.55 + * Core video driver - expected to directly support an OpenGL context4.56 + */4.57 +typedef struct display_driver {4.58 + char *name;4.59 + /**4.60 + * Initialize the driver. This is called only once at startup time, and4.61 + * is guaranteed to be called before any other methods.4.62 + * @return TRUE if the driver was successfully initialized, otherwise4.63 + * FALSE.4.64 + */4.65 + gboolean (*init_driver)(void);4.66 +4.67 + /**4.68 + * Cleanly shutdown the driver. Normally only called at system shutdown4.69 + * time.4.70 + */4.71 + void (*shutdown_driver)(void);4.72 +4.73 + /**4.74 + * Given a particular keysym, return the keycode associated with it.4.75 + * @param keysym The keysym to be resolved, ie "Tab"4.76 + * @return the display-specific keycode, or 0 if the keysym cannot4.77 + * be resolved.4.78 + */4.79 + uint16_t (*resolve_keysym)( const gchar *keysym );4.80 +4.81 + /**4.82 + * Set the current display format to the specified values. This is4.83 + * called immediately prior to any display frame call where the4.84 + * parameters have changed from the previous frame4.85 + */4.86 + gboolean (*set_display_format)( uint32_t hres, uint32_t vres,4.87 + int colour_fmt );4.88 +4.89 + /**4.90 + * Set the current rendering format to the specified values. This is4.91 + * called immediately prior to starting rendering of a frame where the4.92 + * parameters have changed from the previous frame. Note that the driver4.93 + * is not required to precisely support the requested colour format.4.94 + *4.95 + * This method is also responsible for setting up an appropriate GL4.96 + * context for the main engine to render into.4.97 + *4.98 + * @param hres The horizontal resolution (ie 640)4.99 + * @param vres The vertical resolution (ie 480)4.100 + * @param colour_fmt The colour format of the buffer (ie COLFMT_ARGB4444)4.101 + * @param texture Flag indicating that the frame being rendered is a4.102 + * texture, rather than a display frame.4.103 + */4.104 + gboolean (*set_render_format)( uint32_t hres, uint32_t vres,4.105 + int colour_fmt, gboolean texture );4.106 + /**4.107 + * Display a single frame using the supplied pixmap data. Is assumed to4.108 + * invalidate the current GL front buffer (but not the back buffer).4.109 + */4.110 + gboolean (*display_frame)( video_buffer_t buffer );4.111 +4.112 + /**4.113 + * Display a single blanked frame using a fixed colour for the4.114 + * entire frame (specified in RGB888 format). Is assumed to invalidate4.115 + * the current GL front buffer (but not the back buffer).4.116 + */4.117 + gboolean (*display_blank_frame)( uint32_t rgb );4.118 +4.119 + /**4.120 + * Promote the current render back buffer to the front buffer4.121 + */4.122 + void (*display_back_buffer)( void );4.123 +} *display_driver_t;4.124 +4.125 +void video_open( void );4.126 +void video_update_frame( void );4.127 +void video_update_size( int, int, int );4.128 +4.129 +extern uint32_t pvr2_frame_counter;4.130 +4.131 +extern display_driver_t display_driver;4.132 +4.133 +extern struct display_driver display_gtk_driver;4.134 +extern struct display_driver display_null_driver;4.135 +4.136 +/****************** Input methods **********************/4.137 +4.138 +typedef void (*input_key_callback_t)( void *data, uint32_t value, gboolean isKeyDown );4.139 +4.140 +gboolean input_register_key( const gchar *keysym, input_key_callback_t callback,4.141 + void *data, uint32_t value );4.142 +4.143 +void input_unregister_key( const gchar *keysym );4.144 +4.145 +gboolean input_is_key_valid( const gchar *keysym );4.146 +4.147 +gboolean input_is_key_registered( const gchar *keysym );4.148 +4.149 +void input_event_keydown( uint16_t keycode );4.150 +4.151 +void input_event_keyup( uint16_t keycode );4.152 +4.153 +4.154 +4.155 +#ifdef __cplusplus4.156 +}4.157 +#endif4.158 +#endif
5.1 --- a/src/dreamcast.c Wed May 03 12:52:38 2006 +00005.2 +++ b/src/dreamcast.c Mon May 15 08:28:52 2006 +00005.3 @@ -1,5 +1,5 @@5.4 /**5.5 - * $Id: dreamcast.c,v 1.14 2006-01-22 22:42:05 nkeynes Exp $5.6 + * $Id: dreamcast.c,v 1.15 2006-05-15 08:28:48 nkeynes Exp $5.7 * Central switchboard for the system. This pulls all the individual modules5.8 * together into some kind of coherent structure. This is also where you'd5.9 * add Naomi support, if I ever get a board to play with...5.10 @@ -18,6 +18,7 @@5.11 */5.13 #include <errno.h>5.14 +#include <glib/gstrfuncs.h>5.15 #include "dream.h"5.16 #include "mem.h"5.17 #include "aica/aica.h"5.18 @@ -77,10 +78,12 @@5.19 dreamcast_register_module( &ide_module );5.21 /* Attach any default maple devices, ie a pair of controllers */5.22 - maple_device_t controller1 = controller_new();5.23 - maple_device_t controller2 = controller_new();5.24 + /*5.25 + maple_device_t controller1 = maple_new_device("Sega Controller");5.26 + maple_device_t controller2 = maple_new_device("Sega Controller");5.27 maple_attach_device( controller1, 0, 0 );5.28 maple_attach_device( controller2, 1, 0 );5.29 + */5.30 }5.32 /**5.33 @@ -159,16 +162,193 @@5.35 /***************************** User Configuration **************************/5.37 -void dreamcast_load_config( const gchar *filename )5.38 +static struct dreamcast_config_entry global_config[] =5.39 + {{ "bios", CONFIG_TYPE_FILE, "dcboot.rom" },5.40 + { "flash", CONFIG_TYPE_FILE, "dcflash.rom" },5.41 + { "default path", CONFIG_TYPE_PATH, "." },5.42 + { "save path", CONFIG_TYPE_PATH, "save" },5.43 + { "bootstrap", CONFIG_TYPE_FILE, "IP.BIN" },5.44 + { NULL, CONFIG_TYPE_NONE }};5.45 +5.46 +static struct dreamcast_config_entry serial_config[] =5.47 + {{ "device", CONFIG_TYPE_FILE, "/dev/ttyS1" },5.48 + { NULL, CONFIG_TYPE_NONE }};5.49 +5.50 +struct dreamcast_config_group dreamcast_config_root[] =5.51 + {{ "global", global_config },5.52 + { "controllers", NULL },5.53 + { "serial", serial_config },5.54 + { NULL, CONFIG_TYPE_NONE }};5.55 +5.56 +void dreamcast_set_default_config( )5.57 +{5.58 + struct dreamcast_config_group *group = dreamcast_config_root;5.59 + while( group->key != NULL ) {5.60 + struct dreamcast_config_entry *param = group->params;5.61 + if( param != NULL ) {5.62 + while( param->key != NULL ) {5.63 + if( param->value != param->default_value ) {5.64 + if( param->value != NULL )5.65 + free( param->value );5.66 + param->value = (gchar *)param->default_value;5.67 + }5.68 + param++;5.69 + }5.70 + }5.71 + group++;5.72 + }5.73 + maple_detach_all();5.74 +}5.75 +5.76 +gboolean dreamcast_load_config( const gchar *filename )5.77 +{5.78 + FILE *f = fopen(filename, "ro");5.79 + gboolean result;5.80 +5.81 + if( f == NULL ) {5.82 + ERROR( "Unable to open '%s': %s", filename, strerror(errno) );5.83 + return FALSE;5.84 + }5.85 +5.86 + result = dreamcast_load_config_stream( f );5.87 + fclose(f);5.88 + return result;5.89 +}5.90 +5.91 +gboolean dreamcast_load_config_stream( FILE *f )5.92 {5.94 + char buf[512], *p;5.95 + int maple_device = -1, maple_subdevice = -1;5.96 + struct dreamcast_config_group devgroup;5.97 + struct dreamcast_config_group *group = NULL;5.98 + maple_device_t device = NULL;5.99 + dreamcast_set_default_config();5.101 + while( fgets( buf, sizeof(buf), f ) != NULL ) {5.102 + g_strstrip(buf);5.103 + if( buf[0] == '#' )5.104 + continue;5.105 + if( *buf == '[' ) {5.106 + char *p = strchr(buf, ']');5.107 + if( p != NULL ) {5.108 + struct dreamcast_config_group *tmp_group;5.109 + maple_device = maple_subdevice = -1;5.110 + *p = '\0';5.111 + g_strstrip(buf+1);5.112 + tmp_group = &dreamcast_config_root[0];5.113 + while( tmp_group->key != NULL ) {5.114 + if( strcasecmp(tmp_group->key, buf+1) == 0 ) {5.115 + group = tmp_group;5.116 + break;5.117 + }5.118 + tmp_group++;5.119 + }5.120 + }5.121 + } else if( group != NULL ) {5.122 + char *value = strchr( buf, '=' );5.123 + if( value != NULL ) {5.124 + struct dreamcast_config_entry *param = group->params;5.125 + *value = '\0';5.126 + value++;5.127 + g_strstrip(buf);5.128 + g_strstrip(value);5.129 + if( strcmp(group->key,"controllers") == 0 ) {5.130 + if( g_strncasecmp( buf, "device ", 7 ) == 0 ) {5.131 + maple_device = strtoul( buf+7, NULL, 0 );5.132 + if( maple_device < 0 || maple_device > 3 ) {5.133 + ERROR( "Device number must be between 0..3 (not '%s')", buf+7);5.134 + continue;5.135 + }5.136 + maple_subdevice = 0;5.137 + device = maple_new_device( value );5.138 + if( device == NULL ) {5.139 + ERROR( "Unrecognized device '%s'", value );5.140 + } else {5.141 + devgroup.key = "controllers";5.142 + devgroup.params = maple_get_device_config(device);5.143 + maple_attach_device( device, maple_device, maple_subdevice );5.144 + group = &devgroup;5.145 + }5.146 + continue;5.147 + } else if( g_strncasecmp( buf, "subdevice ", 10 ) == 0 ) {5.148 + maple_subdevice = strtoul( buf+10, NULL, 0 );5.149 + if( maple_device == -1 ) {5.150 + ERROR( "Subdevice not allowed without primary device" );5.151 + } else if( maple_subdevice < 1 || maple_subdevice > 5 ) {5.152 + ERROR( "Subdevice must be between 1..5 (not '%s')", buf+10 );5.153 + } else if( (device = maple_new_device(value)) == NULL ) {5.154 + ERROR( "Unrecognized subdevice '%s'", value );5.155 + } else {5.156 + devgroup.key = "controllers";5.157 + devgroup.params = maple_get_device_config(device);5.158 + maple_attach_device( device, maple_device, maple_subdevice );5.159 + group = &devgroup;5.160 + }5.161 + continue;5.162 + }5.163 + }5.164 + while( param->key != NULL ) {5.165 + if( strcasecmp( param->key, buf ) == 0 ) {5.166 + param->value = g_strdup(value);5.167 + break;5.168 + }5.169 + param++;5.170 + }5.171 + }5.172 + }5.173 + }5.174 + return TRUE;5.175 }5.177 -void dreamcast_save_config( const gchar *filename )5.178 +gboolean dreamcast_save_config( const gchar *filename )5.179 {5.180 + FILE *f = fopen(filename, "wo");5.181 + gboolean result;5.182 + if( f == NULL ) {5.183 + ERROR( "Unable to open '%s': %s", filename, strerror(errno) );5.184 + return FALSE;5.185 + }5.186 + result = dreamcast_save_config_stream(f);5.187 + fclose(f);5.188 +}5.190 -5.191 +gboolean dreamcast_save_config_stream( FILE *f )5.192 +{5.193 + struct dreamcast_config_group *group = &dreamcast_config_root[0];5.194 +5.195 + while( group->key != NULL ) {5.196 + struct dreamcast_config_entry *entry = group->params;5.197 + fprintf( f, "[%s]\n", group->key );5.198 +5.199 + if( entry != NULL ) {5.200 + while( entry->key != NULL ) {5.201 + fprintf( f, "%s = %s\n", entry->key, entry->value );5.202 + entry++;5.203 + }5.204 + } else if( strcmp(group->key, "controllers") == 0 ) {5.205 + int i,j;5.206 + for( i=0; i<4; i++ ) {5.207 + for( j=0; j<6; j++ ) {5.208 + maple_device_t dev = maple_get_device( i, j );5.209 + if( dev != NULL ) {5.210 + if( j == 0 )5.211 + fprintf( f, "Device %d = %s\n", i, dev->device_class->name );5.212 + else5.213 + fprintf( f, "Subdevice %d = %s\n", j, dev->device_class->name );5.214 + entry = dev->get_config(dev);5.215 + while( entry->key != NULL ) {5.216 + fprintf( f, "%*c%s = %s\n", j==0?4:8, ' ',entry->key, entry->value );5.217 + entry++;5.218 + }5.219 + }5.220 + }5.221 + }5.222 + }5.223 + fprintf( f, "\n" );5.224 + group++;5.225 + }5.226 + return TRUE;5.227 }5.229 /********************************* Save States *****************************/
6.1 --- a/src/dreamcast.h Wed May 03 12:52:38 2006 +00006.2 +++ b/src/dreamcast.h Mon May 15 08:28:52 2006 +00006.3 @@ -1,5 +1,5 @@6.4 /**6.5 - * $Id: dreamcast.h,v 1.8 2005-12-25 05:56:55 nkeynes Exp $6.6 + * $Id: dreamcast.h,v 1.9 2006-05-15 08:28:48 nkeynes Exp $6.7 *6.8 * Public interface for dreamcast.c -6.9 * Central switchboard for the system. This pulls all the individual modules6.10 @@ -30,18 +30,39 @@6.11 #endif6.13 #define DEFAULT_TIMESLICE_LENGTH 1000000 /* nanoseconds */6.14 +#define CONFIG_TYPE_NONE 06.15 +#define CONFIG_TYPE_FILE 16.16 +#define CONFIG_TYPE_PATH 26.17 +#define CONFIG_TYPE_KEY 36.18 +6.19 +#define DEFAULT_CONFIG_FILENAME "dream.conf"6.20 +6.21 +typedef struct dreamcast_config_entry {6.22 + const gchar *key;6.23 + const int type;6.24 + const gchar *default_value;6.25 + gchar *value;6.26 +} *dreamcast_config_entry_t;6.27 +6.28 +typedef struct dreamcast_config_group {6.29 + const gchar *key;6.30 + struct dreamcast_config_entry *params;6.31 +} *dreamcast_config_group_t;6.32 +6.34 void dreamcast_init(void);6.35 void dreamcast_reset(void);6.36 void dreamcast_run(void);6.37 void dreamcast_stop(void);6.39 -void dreamcast_load_config( const gchar *filename );6.40 -void dreamcast_save_config( const gchar *filename );6.41 +gboolean dreamcast_load_config( const gchar *filename );6.42 +gboolean dreamcast_save_config( const gchar *filename );6.44 int dreamcast_save_state( const gchar *filename );6.45 int dreamcast_load_state( const gchar *filename );6.47 +extern struct dreamcast_config_group dreamcast_config_root[];6.48 +6.49 #ifdef __cplusplus6.50 }6.51 #endif
7.1 --- a/src/drivers/video_gtk.c Wed May 03 12:52:38 2006 +00007.2 +++ b/src/drivers/video_gtk.c Mon May 15 08:28:52 2006 +00007.3 @@ -1,5 +1,5 @@7.4 /**7.5 - * $Id: video_gtk.c,v 1.5 2006-03-16 12:42:28 nkeynes Exp $7.6 + * $Id: video_gtk.c,v 1.6 2006-05-15 08:28:52 nkeynes Exp $7.7 *7.8 * The PC side of the video support (responsible for actually displaying /7.9 * rendering frames)7.10 @@ -20,7 +20,7 @@7.11 #include <gnome.h>7.12 #include <gdk/gdkx.h>7.13 #include <stdint.h>7.14 -#include "video.h"7.15 +#include "display.h"7.16 #include "drivers/video_x11.h"7.18 GdkImage *video_img = NULL;7.19 @@ -30,21 +30,45 @@7.20 uint32_t video_height = 480;7.21 uint32_t video_frame_count = 0;7.23 +uint16_t video_gtk_resolve_keysym( const gchar *keysym );7.24 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,7.25 int colour_format );7.26 gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,7.27 - int colour_format );7.28 + int colour_format, gboolean texture );7.29 gboolean video_gtk_display_frame( video_buffer_t frame );7.30 gboolean video_gtk_blank( uint32_t rgb );7.32 -struct video_driver video_gtk_driver = { "gtk",7.33 - NULL,7.34 - NULL,7.35 - video_gtk_set_output_format,7.36 - video_gtk_set_render_format,7.37 - video_gtk_display_frame,7.38 - video_gtk_blank,7.39 - video_glx_swap_buffers };7.40 +struct display_driver display_gtk_driver = { "gtk",7.41 + NULL,7.42 + NULL,7.43 + video_gtk_resolve_keysym,7.44 + video_gtk_set_output_format,7.45 + video_gtk_set_render_format,7.46 + video_gtk_display_frame,7.47 + video_gtk_blank,7.48 + video_glx_swap_buffers };7.49 +7.50 +gboolean video_gtk_keydown_callback(GtkWidget *widget,7.51 + GdkEventKey *event,7.52 + gpointer user_data)7.53 +{7.54 + input_event_keydown( event->keyval );7.55 +}7.56 +7.57 +uint16_t video_gtk_resolve_keysym( const gchar *keysym )7.58 +{7.59 + int val = gdk_keyval_from_name( keysym );7.60 + if( val == GDK_VoidSymbol )7.61 + return 0;7.62 + return (uint16_t)val;7.63 +}7.64 +7.65 +gboolean video_gtk_keyup_callback(GtkWidget *widget,7.66 + GdkEventKey *event,7.67 + gpointer user_data)7.68 +{7.69 + input_event_keyup( event->keyval );7.70 +}7.72 gboolean video_gtk_set_output_format( uint32_t width, uint32_t height,7.73 int colour_format )7.74 @@ -57,6 +81,13 @@7.75 gtk_window_set_policy( video_win, FALSE, FALSE, FALSE );7.76 gtk_window_set_default_size( video_win, width, height );7.78 + g_signal_connect( video_win, "key_press_event",7.79 + G_CALLBACK(video_gtk_keydown_callback), NULL );7.80 + g_signal_connect( video_win, "key_release_event",7.81 + G_CALLBACK(video_gtk_keyup_callback), NULL );7.82 + gtk_widget_add_events( GTK_WIDGET(video_win),7.83 + GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK |7.84 + GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK );7.85 video_area = gtk_image_new();7.86 gtk_widget_show( GTK_WIDGET(video_area) );7.87 gtk_container_add( GTK_CONTAINER(video_win), GTK_WIDGET(video_area) );7.88 @@ -156,7 +187,7 @@7.89 }7.91 gboolean video_gtk_set_render_format( uint32_t width, uint32_t height,7.92 - int colour_format )7.93 + int colour_format, gboolean texture )7.94 {7.95 return video_glx_set_render_format( 0, 0, width, height );7.96 }
8.1 --- a/src/drivers/video_null.c Wed May 03 12:52:38 2006 +00008.2 +++ b/src/drivers/video_null.c Mon May 15 08:28:52 2006 +00008.3 @@ -1,5 +1,5 @@8.4 /**8.5 - * $Id: video_null.c,v 1.1 2006-03-14 12:45:53 nkeynes Exp $8.6 + * $Id: video_null.c,v 1.2 2006-05-15 08:28:52 nkeynes Exp $8.7 *8.8 * Null video output driver (ie no video output whatsoever)8.9 *8.10 @@ -16,7 +16,7 @@8.11 * GNU General Public License for more details.8.12 */8.14 -#include "video.h"8.15 +#include "display.h"8.17 gboolean video_null_set_output_format( uint32_t hres, uint32_t vres,8.18 int colour_format )8.19 @@ -45,7 +45,7 @@8.20 }8.23 -struct video_driver video_null_driver = { "null",8.24 +struct display_driver display_null_driver = { "null",8.25 NULL,8.26 NULL,8.27 video_null_set_output_format,
9.1 --- a/src/drivers/video_x11.c Wed May 03 12:52:38 2006 +00009.2 +++ b/src/drivers/video_x11.c Mon May 15 08:28:52 2006 +00009.3 @@ -1,5 +1,5 @@9.4 /**9.5 - * $Id: video_x11.c,v 1.4 2006-03-16 12:42:28 nkeynes Exp $9.6 + * $Id: video_x11.c,v 1.5 2006-05-15 08:28:52 nkeynes Exp $9.7 *9.8 * Shared functions for all X11-based display drivers.9.9 *9.10 @@ -19,7 +19,6 @@9.11 #include <X11/Xlib.h>9.12 #include <GL/glx.h>9.13 #include "dream.h"9.14 -#include "video.h"9.15 #include "drivers/video_x11.h"9.17 /**
10.1 --- a/src/drivers/video_x11.h Wed May 03 12:52:38 2006 +000010.2 +++ b/src/drivers/video_x11.h Mon May 15 08:28:52 2006 +000010.3 @@ -1,5 +1,5 @@10.4 /**10.5 - * $Id: video_x11.h,v 1.2 2006-03-15 13:16:46 nkeynes Exp $10.6 + * $Id: video_x11.h,v 1.3 2006-05-15 08:28:52 nkeynes Exp $10.7 *10.8 * Parent for all X11 display drivers.10.9 *10.10 @@ -20,7 +20,7 @@10.11 #define video_x11_driver_H10.13 #include "X11/Xlib.h"10.14 -#include "video.h"10.15 +#include "display.h"10.17 void video_x11_set_display( Display *display, Screen *screen, Window window );
11.1 --- a/src/gui/debug_win.c Wed May 03 12:52:38 2006 +000011.2 +++ b/src/gui/debug_win.c Mon May 15 08:28:52 2006 +000011.3 @@ -1,5 +1,5 @@11.4 /**11.5 - * $Id: debug_win.c,v 1.18 2006-03-30 11:31:05 nkeynes Exp $11.6 + * $Id: debug_win.c,v 1.19 2006-05-15 08:28:52 nkeynes Exp $11.7 * This file is responsible for the main debugger gui frame.11.8 *11.9 * Copyright (c) 2005 Nathan Keynes.11.10 @@ -22,7 +22,7 @@11.11 #include "gui/gui.h"11.12 #include "mem.h"11.13 #include "cpu.h"11.14 -#include "video.h"11.15 +#include "display.h"11.17 GdkColor *msg_colors[] = { &clrError, &clrError, &clrWarn, &clrNormal,11.18 &clrDebug, &clrTrace };
12.1 --- a/src/main.c Wed May 03 12:52:38 2006 +000012.2 +++ b/src/main.c Mon May 15 08:28:52 2006 +000012.3 @@ -1,5 +1,5 @@12.4 /**12.5 - * $Id: main.c,v 1.16 2006-03-16 12:41:59 nkeynes Exp $12.6 + * $Id: main.c,v 1.17 2006-05-15 08:28:48 nkeynes Exp $12.7 *12.8 * Main program, initializes dreamcast and gui, then passes control off to12.9 * the gtk main loop (currently).12.10 @@ -30,16 +30,19 @@12.11 #include "syscall.h"12.12 #include "dreamcast.h"12.13 #include "aica/audio.h"12.14 -#include "video.h"12.15 +#include "display.h"12.16 +#include "maple/maple.h"12.18 #define S3M_PLAYER "s3mplay.bin"12.20 -char *option_list = "a:s:A:V:phb";12.21 +char *option_list = "a:s:A:V:phbd:c:";12.22 struct option longopts[1] = { { NULL, 0, 0, 0 } };12.23 char *aica_program = NULL;12.24 char *s3m_file = NULL;12.25 -char *video_driver_name = "gtk";12.26 +char *disc_file = NULL;12.27 +char *display_driver_name = "gtk";12.28 char *audio_driver_name = "esd";12.29 +char *config_file = DEFAULT_CONFIG_FILENAME;12.30 gboolean start_immediately = FALSE;12.31 gboolean headless = FALSE;12.32 gboolean without_bios = FALSE;12.33 @@ -48,9 +51,9 @@12.34 &audio_esd_driver,12.35 NULL };12.37 -video_driver_t video_driver_list[] = { &video_null_driver,12.38 - &video_gtk_driver,12.39 - NULL };12.40 +display_driver_t display_driver_list[] = { &display_null_driver,12.41 + &display_gtk_driver,12.42 + NULL };12.44 int main (int argc, char *argv[])12.45 {12.46 @@ -65,6 +68,12 @@12.47 case 'a': /* AICA only mode - argument is an AICA program */12.48 aica_program = optarg;12.49 break;12.50 + case 'c': /* Config file */12.51 + config_file = optarg;12.52 + break;12.53 + case 'd': /* Mount disc */12.54 + disc_file = optarg;12.55 + break;12.56 case 's': /* AICA-only w/ S3M player */12.57 aica_program = S3M_PLAYER;12.58 s3m_file = optarg;12.59 @@ -73,7 +82,7 @@12.60 audio_driver_name = optarg;12.61 break;12.62 case 'V': /* Video driver */12.63 - video_driver_name = optarg;12.64 + display_driver_name = optarg;12.65 break;12.66 case 'p': /* Start immediately */12.67 start_immediately = TRUE;12.68 @@ -87,6 +96,8 @@12.69 }12.70 }12.72 + dreamcast_load_config( config_file );12.73 +12.74 if( aica_program == NULL ) {12.75 if( !headless ) {12.76 gnome_init ("dreamon", VERSION, argc, argv);12.77 @@ -129,25 +140,30 @@12.78 }12.80 if( headless ) {12.81 - video_set_driver( &video_null_driver );12.82 + display_set_driver( &display_null_driver );12.83 } else {12.84 - for( i=0; video_driver_list[i] != NULL; i++ ) {12.85 - if( strcasecmp( video_driver_list[i]->name, video_driver_name ) == 0 ) {12.86 - video_set_driver( video_driver_list[i] );12.87 + for( i=0; display_driver_list[i] != NULL; i++ ) {12.88 + if( strcasecmp( display_driver_list[i]->name, display_driver_name ) == 0 ) {12.89 + display_set_driver( display_driver_list[i] );12.90 break;12.91 }12.92 }12.93 - if( video_driver_list[i] == NULL ) {12.94 - ERROR( "Video driver '%s' not found, using null driver", video_driver_name );12.95 - video_set_driver( &video_null_driver );12.96 + if( display_driver_list[i] == NULL ) {12.97 + ERROR( "Video driver '%s' not found, using null driver", display_driver_name );12.98 + display_set_driver( &display_null_driver );12.99 }12.100 }12.102 + maple_reattach_all();12.103 INFO( "DreamOn! ready..." );12.104 if( optind < argc ) {12.105 file_load_magic( argv[optind] );12.106 }12.108 + if( disc_file != NULL ) {12.109 + gdrom_mount_image( disc_file );12.110 + }12.111 +12.112 if( start_immediately )12.113 dreamcast_run();12.114 if( !headless ) {
13.1 --- a/src/maple/controller.c Wed May 03 12:52:38 2006 +000013.2 +++ b/src/maple/controller.c Mon May 15 08:28:52 2006 +000013.3 @@ -1,5 +1,5 @@13.4 /**13.5 - * $Id: controller.c,v 1.2 2005-12-25 08:24:11 nkeynes Exp $13.6 + * $Id: controller.c,v 1.3 2006-05-15 08:28:52 nkeynes Exp $13.7 *13.8 * Implements the standard dreamcast controller13.9 *13.10 @@ -18,25 +18,51 @@13.12 #include <stdlib.h>13.13 #include "dream.h"13.14 +#include "dreamcast.h"13.15 #include "maple.h"13.16 #include "maple/controller.h"13.18 +#define CONTROLLER_CONFIG_ENTRIES 1613.19 +13.20 void controller_attach( maple_device_t dev );13.21 void controller_detach( maple_device_t dev );13.22 +void controller_destroy( maple_device_t dev );13.23 +maple_device_t controller_new();13.24 +dreamcast_config_entry_t controller_get_config( maple_device_t dev );13.25 int controller_get_cond( maple_device_t dev, int function, char *outbuf,13.26 int *outlen );13.28 -static struct maple_device base_controller = {13.29 - MAPLE_DEVICE_TAG, CONTROLLER_IDENT, CONTROLLER_VERSION, NULL, NULL,13.30 - controller_get_cond, NULL, NULL, NULL,13.31 - controller_attach, controller_detach };13.32 -13.33 typedef struct controller_device {13.34 struct maple_device dev;13.35 uint32_t condition[2];13.36 + struct dreamcast_config_entry config[CONTROLLER_CONFIG_ENTRIES];13.37 } *controller_device_t;13.39 +struct maple_device_class controller_class = { "Sega Controller", controller_new };13.41 +static struct controller_device base_controller = {13.42 + { MAPLE_DEVICE_TAG, &controller_class, CONTROLLER_IDENT, CONTROLLER_VERSION,13.43 + controller_get_config, controller_attach, controller_detach, controller_destroy,13.44 + NULL, NULL, controller_get_cond, NULL, NULL, NULL },13.45 + {0x0000FFFF, 0},13.46 + {{ "dpad left", CONFIG_TYPE_KEY },13.47 + { "dpad right", CONFIG_TYPE_KEY },13.48 + { "dpad up", CONFIG_TYPE_KEY },13.49 + { "dpad down", CONFIG_TYPE_KEY },13.50 + { "analog left", CONFIG_TYPE_KEY },13.51 + { "analog right", CONFIG_TYPE_KEY },13.52 + { "analog up", CONFIG_TYPE_KEY },13.53 + { "analog down", CONFIG_TYPE_KEY },13.54 + { "button X", CONFIG_TYPE_KEY },13.55 + { "button Y", CONFIG_TYPE_KEY },13.56 + { "button A", CONFIG_TYPE_KEY },13.57 + { "button B", CONFIG_TYPE_KEY },13.58 + { "trigger left", CONFIG_TYPE_KEY },13.59 + { "trigger right", CONFIG_TYPE_KEY },13.60 + { "start", CONFIG_TYPE_KEY },13.61 + { NULL, CONFIG_TYPE_NONE }} };13.62 +13.63 +#define CONTROLLER(x) ((controller_device_t)(x))13.65 maple_device_t controller_new( )13.66 {13.67 @@ -47,10 +73,54 @@13.68 return MAPLE_DEVICE(dev);13.69 }13.71 +/**13.72 + * Input callback13.73 + */13.74 +void controller_key_callback( void *mdev, uint32_t value, gboolean isKeyDown )13.75 +{13.76 + controller_device_t dev = (controller_device_t)mdev;13.77 + if( isKeyDown ) {13.78 + dev->condition[0] |= value;13.79 + fprintf( stderr, "Key %08X DOWN\n", value );13.80 + } else {13.81 + dev->condition[0] &= ~value;13.82 + fprintf( stderr, "Key %08X UP\n", value );13.83 + }13.84 +}13.86 -void controller_attach( maple_device_t dev )13.87 +dreamcast_config_entry_t controller_get_config( maple_device_t mdev )13.88 {13.89 + controller_device_t dev = (controller_device_t)mdev;13.90 + return dev->config;13.91 +}13.93 +void controller_destroy( maple_device_t mdev )13.94 +{13.95 + free( mdev );13.96 +}13.97 +13.98 +/**13.99 + * Device is being attached to the bus. Go through the config and reserve the13.100 + * keys we need.13.101 + */13.102 +void controller_attach( maple_device_t mdev )13.103 +{13.104 + controller_device_t dev = (controller_device_t)mdev;13.105 + input_register_key( dev->config[0].value, controller_key_callback, dev, BUTTON_DPAD_LEFT );13.106 + input_register_key( dev->config[1].value, controller_key_callback, dev, BUTTON_DPAD_RIGHT );13.107 + input_register_key( dev->config[2].value, controller_key_callback, dev, BUTTON_DPAD_UP );13.108 + input_register_key( dev->config[3].value, controller_key_callback, dev, BUTTON_DPAD_DOWN );13.109 + input_register_key( dev->config[4].value, controller_key_callback, dev, 0 );13.110 + input_register_key( dev->config[5].value, controller_key_callback, dev, 0 );13.111 + input_register_key( dev->config[6].value, controller_key_callback, dev, 0 );13.112 + input_register_key( dev->config[7].value, controller_key_callback, dev, 0 );13.113 + input_register_key( dev->config[8].value, controller_key_callback, dev, BUTTON_X );13.114 + input_register_key( dev->config[9].value, controller_key_callback, dev, BUTTON_Y );13.115 + input_register_key( dev->config[10].value, controller_key_callback, dev, BUTTON_A );13.116 + input_register_key( dev->config[11].value, controller_key_callback, dev, BUTTON_B );13.117 + input_register_key( dev->config[12].value, controller_key_callback, dev, BUTTON_LEFT_TRIGGER );13.118 + input_register_key( dev->config[13].value, controller_key_callback, dev, BUTTON_RIGHT_TRIGGER );13.119 + input_register_key( dev->config[14].value, controller_key_callback, dev, BUTTON_START );13.120 }13.122 void controller_detach( maple_device_t dev )
14.1 --- a/src/maple/maple.c Wed May 03 12:52:38 2006 +000014.2 +++ b/src/maple/maple.c Mon May 15 08:28:52 2006 +000014.3 @@ -1,5 +1,5 @@14.4 /**14.5 - * $Id: maple.c,v 1.7 2006-03-20 12:00:15 nkeynes Exp $14.6 + * $Id: maple.c,v 1.8 2006-05-15 08:28:52 nkeynes Exp $14.7 *14.8 * Implements the core Maple bus, including DMA transfers to and from the bus.14.9 *14.10 @@ -28,11 +28,30 @@14.11 struct dreamcast_module maple_module = { "Maple", maple_init, NULL, NULL, NULL,14.12 NULL, NULL, NULL };14.14 +struct maple_device_class *maple_device_classes[] = { &controller_class, NULL };14.15 +14.16 void maple_init( void )14.17 {14.19 }14.21 +maple_device_t maple_new_device( const gchar *name )14.22 +{14.23 + int i;14.24 + for( i=0; maple_device_classes[i] != NULL; i++ ) {14.25 + if( g_strcasecmp(maple_device_classes[i]->name, name ) == 0 )14.26 + return maple_device_classes[i]->new_device();14.27 + }14.28 + return NULL;14.29 +}14.30 +14.31 +dreamcast_config_entry_t maple_get_device_config( maple_device_t dev )14.32 +{14.33 + if( dev->get_config == NULL )14.34 + return NULL;14.35 + return dev->get_config(dev);14.36 +}14.37 +14.38 /**14.39 * Input data looks like this:14.40 * 0: transfer control word14.41 @@ -60,6 +79,14 @@14.42 #define PUTBYTE(n,x) (buf[n] = (char)x)14.43 #define PUTWORD(n,x) (*((uint32_t *)(return_buf+(n))) = (x))14.45 +maple_device_t maple_get_device( unsigned int port, unsigned int periph ) {14.46 + if( port >= 4 )14.47 + return NULL;14.48 + if( periph >= 6 )14.49 + return NULL;14.50 + return maple_devices[port][periph];14.51 +}14.52 +14.53 void maple_handle_buffer( uint32_t address ) {14.54 unsigned char *buf = (unsigned char *)mem_get_region(address);14.55 if( buf == NULL ) {14.56 @@ -242,5 +269,34 @@14.57 } else {14.58 maple_periph_mask[port] &= (~(1<<(periph-1)));14.59 }14.60 -14.61 +14.62 }14.63 +14.64 +void maple_detach_all() {14.65 + int i, j;14.66 + for( i=0; i<4; i++ ) {14.67 + for( j=0; j<6; j++ ) {14.68 + if( maple_devices[i][j] != NULL ) {14.69 + maple_device_t dev = maple_devices[i][j];14.70 + if( dev->detach != NULL )14.71 + dev->detach(dev);14.72 + if( dev->destroy != NULL )14.73 + dev->destroy(dev);14.74 + }14.75 + }14.76 + maple_periph_mask[i] = 0;14.77 + }14.78 +}14.79 +14.80 +void maple_reattach_all() {14.81 + int i, j;14.82 + for( i=0; i<4; i++ ) {14.83 + for( j=0; j<6; j++ ) {14.84 + if( maple_devices[i][j] != NULL ) {14.85 + maple_device_t dev = maple_devices[i][j];14.86 + if( dev->attach != NULL )14.87 + dev->attach(dev);14.88 + }14.89 + }14.90 + }14.91 +}
15.1 --- a/src/maple/maple.h Wed May 03 12:52:38 2006 +000015.2 +++ b/src/maple/maple.h Mon May 15 08:28:52 2006 +000015.3 @@ -1,5 +1,5 @@15.4 /**15.5 - * $Id: maple.h,v 1.4 2005-12-25 08:24:11 nkeynes Exp $15.6 + * $Id: maple.h,v 1.5 2006-05-15 08:28:52 nkeynes Exp $15.7 *15.8 * Maple bus definitions15.9 *15.10 @@ -19,6 +19,8 @@15.11 #ifndef dream_maple_H15.12 #define dream_maple_H 115.14 +#include "dreamcast.h"15.15 +15.16 #define MAPLE_CMD_INFO 1 /* Request device information */15.17 #define MAPLE_CMD_EXT_INFO 2 /* Request extended information */15.18 #define MAPLE_CMD_RESET 3 /* Reset device */15.19 @@ -52,13 +54,27 @@15.20 #define MAPLE_DEVICE_TAG 0x4D41504C15.21 #define MAPLE_DEVICE(x) ((maple_device_t)x)15.23 +typedef struct maple_device_class *maple_device_class_t;15.24 +typedef struct maple_device *maple_device_t;15.25 +15.26 +struct maple_device_class {15.27 + const char *name;15.28 + maple_device_t (*new_device)();15.29 +};15.30 +15.31 /**15.32 * Table of functions to be implemented by any maple device.15.33 */15.34 -typedef struct maple_device {15.35 +struct maple_device {15.36 uint32_t _tag;15.37 + maple_device_class_t device_class;15.38 unsigned char ident[112];15.39 unsigned char version[80];15.40 + dreamcast_config_entry_t (*get_config)(struct maple_device *dev);15.41 + void (*attach)(struct maple_device *dev);15.42 + void (*detach)(struct maple_device *dev);15.43 + void (*destroy)(struct maple_device *dev);15.44 +15.45 int (*reset)(struct maple_device *dev);15.46 int (*shutdown)(struct maple_device *dev);15.47 int (*get_condition)(struct maple_device *dev,15.48 @@ -69,14 +85,18 @@15.49 int function, uint32_t block, unsigned char *outbuf, int *buflen);15.50 int (*write_block)(struct maple_device *dev,15.51 int function, uint32_t block, unsigned char *inbuf, int buflen);15.52 - void (*attach)(struct maple_device *dev);15.53 - void (*detach)(struct maple_device *dev);15.54 -} *maple_device_t;15.55 +};15.57 -maple_device_t controller_new(void);15.58 +extern struct maple_device_class controller_class;15.59 +15.60 +maple_device_t maple_new_device( const char *name );15.61 +maple_device_t maple_get_device( unsigned int port, unsigned int periph );15.62 +dreamcast_config_entry_t maple_get_device_config( maple_device_t dev );15.64 void maple_handle_buffer( uint32_t buffer );15.65 void maple_attach_device( maple_device_t dev, unsigned int port, unsigned int periph );15.66 void maple_detach_device( unsigned int port, unsigned int periph );15.67 +void maple_detach_all( );15.68 +void maple_reattach_all( );15.70 #endif /* !dream_maple_H */
16.1 --- a/src/pvr2/pvr2.c Wed May 03 12:52:38 2006 +000016.2 +++ b/src/pvr2/pvr2.c Mon May 15 08:28:52 2006 +000016.3 @@ -1,5 +1,5 @@16.4 /**16.5 - * $Id: pvr2.c,v 1.22 2006-03-30 11:30:59 nkeynes Exp $16.6 + * $Id: pvr2.c,v 1.23 2006-05-15 08:28:52 nkeynes Exp $16.7 *16.8 * PVR2 (Video) Core module implementation and MMIO registers.16.9 *16.10 @@ -18,7 +18,7 @@16.11 #define MODULE pvr2_module16.13 #include "dream.h"16.14 -#include "video.h"16.15 +#include "display.h"16.16 #include "mem.h"16.17 #include "asic.h"16.18 #include "pvr2/pvr2.h"16.19 @@ -41,7 +41,7 @@16.20 pvr2_save_state, pvr2_load_state };16.23 -video_driver_t video_driver = NULL;16.24 +display_driver_t display_driver = NULL;16.26 struct video_timing {16.27 int fields_per_second;16.28 @@ -136,19 +136,6 @@16.29 return pvr2_state.frame_count;16.30 }16.32 -void video_set_driver( video_driver_t driver )16.33 -{16.34 - if( video_driver != NULL && video_driver->shutdown_driver != NULL )16.35 - video_driver->shutdown_driver();16.36 -16.37 - video_driver = driver;16.38 - if( driver->init_driver != NULL )16.39 - driver->init_driver();16.40 - driver->set_display_format( 640, 480, COLFMT_RGB32 );16.41 - driver->set_render_format( 640, 480, COLFMT_RGB32, FALSE );16.42 - texcache_gl_init();16.43 -}16.44 -16.45 /**16.46 * Display the next frame, copying the current contents of video ram to16.47 * the window. If the video configuration has changed, first recompute the16.48 @@ -193,18 +180,18 @@16.49 break;16.50 }16.52 - if( video_driver != NULL ) {16.53 + if( display_driver != NULL ) {16.54 if( buffer->hres != last->hres ||16.55 buffer->vres != last->vres ||16.56 buffer->colour_format != last->colour_format) {16.57 - video_driver->set_display_format( buffer->hres, buffer->vres,16.58 + display_driver->set_display_format( buffer->hres, buffer->vres,16.59 buffer->colour_format );16.60 }16.61 if( MMIO_READ( PVR2, DISPCFG2 ) & 0x08 ) { /* Blanked */16.62 uint32_t colour = MMIO_READ( PVR2, DISPBORDER );16.63 - video_driver->display_blank_frame( colour );16.64 + display_driver->display_blank_frame( colour );16.65 } else if( !pvr2_render_display_frame( PVR2_RAM_BASE + display_addr ) ) {16.66 - video_driver->display_frame( buffer );16.67 + display_driver->display_frame( buffer );16.68 }16.69 }16.70 } else {
17.1 --- a/src/pvr2/pvr2.h Wed May 03 12:52:38 2006 +000017.2 +++ b/src/pvr2/pvr2.h Mon May 15 08:28:52 2006 +000017.3 @@ -1,5 +1,5 @@17.4 /**17.5 - * $Id: pvr2.h,v 1.12 2006-03-30 11:30:59 nkeynes Exp $17.6 + * $Id: pvr2.h,v 1.13 2006-05-15 08:28:52 nkeynes Exp $17.7 *17.8 * PVR2 (video chip) functions and macros.17.9 *17.10 @@ -18,7 +18,7 @@17.12 #include "dream.h"17.13 #include "mem.h"17.14 -#include "video.h"17.15 +#include "display.h"17.16 #include "pvr2/pvr2mmio.h"17.17 #include <GL/gl.h>17.19 @@ -98,8 +98,6 @@17.20 #define PVR2_TEX_IS_COMPRESSED(x) ( (x) & PVR2_TEX_COMPRESSED )17.21 #define PVR2_TEX_IS_TWIDDLED(x) (((x) & PVR2_TEX_UNTWIDDLED) == 0)17.23 -extern video_driver_t video_driver;17.24 -17.25 /****************************** Frame Buffer *****************************/17.27 /**
18.1 --- a/src/pvr2/render.c Wed May 03 12:52:38 2006 +000018.2 +++ b/src/pvr2/render.c Mon May 15 08:28:52 2006 +000018.3 @@ -1,5 +1,5 @@18.4 /**18.5 - * $Id: render.c,v 1.7 2006-03-30 11:29:54 nkeynes Exp $18.6 + * $Id: render.c,v 1.8 2006-05-15 08:28:52 nkeynes Exp $18.7 *18.8 * PVR2 Renderer support. This is where the real work happens.18.9 *18.10 @@ -192,7 +192,7 @@18.11 /* The more useful case - back buffer is to be displayed. Swap18.12 * the buffers18.13 */18.14 - video_driver->display_back_buffer();18.15 + display_driver->display_back_buffer();18.16 front_buffer = back_buffer;18.17 back_buffer.render_addr = -1;18.18 return TRUE;18.19 @@ -210,7 +210,7 @@18.20 gboolean texture_target )18.21 {18.22 /* Select and initialize the render context */18.23 - video_driver->set_render_format( width, height, colour_format, texture_target );18.24 + display_driver->set_render_format( width, height, colour_format, texture_target );18.26 if( pvr2_render_font_list == -1 ) {18.27 pvr2_render_font_list = video_glx_load_font( "-*-helvetica-*-r-normal--16-*-*-*-p-*-iso8859-1");
.