Search
lxdream.org :: lxdream/src/display.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/display.c
changeset 144:7f0714e89aaa
next166:8aa70cf503a2
author nkeynes
date Mon May 15 08:28:52 2006 +0000 (13 years ago)
permissions -rw-r--r--
last change Rename video_driver to display_driver
Add input source to display
Implement configuration file support
Hook controllers up to configuration
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/display.c Mon May 15 08:28:52 2006 +0000
1.3 @@ -0,0 +1,139 @@
1.4 +/**
1.5 + * $Id: display.c,v 1.1 2006-05-15 08:28:48 nkeynes Exp $
1.6 + *
1.7 + * Generic support for keyboard and other input sources. The active display
1.8 + * driver is expected to deliver events here, where they're translated and
1.9 + * passed to the appropriate dreamcast controllers (if any).
1.10 + *
1.11 + * Copyright (c) 2005 Nathan Keynes.
1.12 + *
1.13 + * This program is free software; you can redistribute it and/or modify
1.14 + * it under the terms of the GNU General Public License as published by
1.15 + * the Free Software Foundation; either version 2 of the License, or
1.16 + * (at your option) any later version.
1.17 + *
1.18 + * This program is distributed in the hope that it will be useful,
1.19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.21 + * GNU General Public License for more details.
1.22 + */
1.23 +
1.24 +#include <stdint.h>
1.25 +#include <assert.h>
1.26 +#include "dream.h"
1.27 +#include "display.h"
1.28 +
1.29 +typedef struct keymap_entry {
1.30 + uint16_t keycode;
1.31 + input_key_callback_t callback;
1.32 + void *data;
1.33 + uint32_t value;
1.34 +} *keymap_entry_t;
1.35 +
1.36 +/**
1.37 + * FIXME: make this more memory efficient
1.38 + */
1.39 +struct keymap_entry *keymap[65536];
1.40 +
1.41 +
1.42 +static struct keymap_entry *input_create_key( uint16_t keycode )
1.43 +{
1.44 + struct keymap_entry *key = keymap[ keycode ];
1.45 + if( key == NULL ) {
1.46 + key = malloc( sizeof( struct keymap_entry ) );
1.47 + assert( key != NULL );
1.48 + keymap[ keycode ] = key;
1.49 + key->keycode = keycode;
1.50 + }
1.51 + return key;
1.52 +}
1.53 +
1.54 +static void input_delete_key( uint16_t keycode )
1.55 +{
1.56 + struct keymap_entry *key = keymap[keycode];
1.57 + if( key != NULL ) {
1.58 + free( key );
1.59 + keymap[keycode] = NULL;
1.60 + }
1.61 +}
1.62 +
1.63 +static struct keymap_entry *input_get_key( uint16_t keycode )
1.64 +{
1.65 + return keymap[ keycode ];
1.66 +}
1.67 +
1.68 +gboolean input_register_key( const gchar *keysym, input_key_callback_t callback,
1.69 + void *data, uint32_t value )
1.70 +{
1.71 + if( display_driver == NULL || keysym == NULL )
1.72 + return FALSE; /* No display driver */
1.73 + uint16_t keycode = display_driver->resolve_keysym(keysym);
1.74 + if( keycode == 0 )
1.75 + return FALSE; /* Invalid keysym */
1.76 +
1.77 + struct keymap_entry *key = input_create_key( keycode );
1.78 + key->callback = callback;
1.79 + key->data = data;
1.80 + key->value = value;
1.81 + INFO( "Registered key '%s' (%4x)", keysym, keycode );
1.82 + return TRUE;
1.83 +}
1.84 +
1.85 +void input_unregister_key( const gchar *keysym )
1.86 +{
1.87 + if( display_driver == NULL || keysym == NULL )
1.88 + return;
1.89 + uint16_t keycode = display_driver->resolve_keysym(keysym);
1.90 + if( keycode == 0 )
1.91 + return;
1.92 + input_delete_key( keycode );
1.93 +}
1.94 +
1.95 +
1.96 +gboolean input_is_key_valid( const gchar *keysym )
1.97 +{
1.98 + if( display_driver == NULL )
1.99 + return FALSE; /* No display driver */
1.100 + return display_driver->resolve_keysym(keysym) != 0;
1.101 +}
1.102 +
1.103 +gboolean input_is_key_registered( const gchar *keysym )
1.104 +{
1.105 + if( display_driver == NULL )
1.106 + return FALSE;
1.107 + uint16_t keycode = display_driver->resolve_keysym(keysym);
1.108 + if( keycode == 0 )
1.109 + return FALSE;
1.110 + return input_get_key( keycode ) != NULL;
1.111 +}
1.112 +
1.113 +void input_event_keydown( uint16_t keycode )
1.114 +{
1.115 + struct keymap_entry *key = input_get_key(keycode);
1.116 + if( key != NULL ) {
1.117 + key->callback( key->data, key->value, TRUE );
1.118 + }
1.119 +}
1.120 +
1.121 +void input_event_keyup( uint16_t keycode )
1.122 +{
1.123 + struct keymap_entry *key = input_get_key(keycode);
1.124 + if( key != NULL ) {
1.125 + key->callback( key->data, key->value, FALSE );
1.126 + }
1.127 +}
1.128 +
1.129 +
1.130 +
1.131 +void display_set_driver( display_driver_t driver )
1.132 +{
1.133 + if( display_driver != NULL && display_driver->shutdown_driver != NULL )
1.134 + display_driver->shutdown_driver();
1.135 +
1.136 + display_driver = driver;
1.137 + if( driver->init_driver != NULL )
1.138 + driver->init_driver();
1.139 + driver->set_display_format( 640, 480, COLFMT_ARGB8888 );
1.140 + driver->set_render_format( 640, 480, COLFMT_ARGB8888, FALSE );
1.141 + texcache_gl_init();
1.142 +}
.