filename | src/display.c |
changeset | 329:4b453d68e9ae |
prev | 327:00d55a462af3 |
next | 352:f0df7a6d4703 |
author | nkeynes |
date | Wed Jan 31 11:02:50 2007 +0000 (17 years ago) |
permissions | -rw-r--r-- |
last change | Load textures into the right region Allow setting the backplane control word from the test data |
view | annotate | diff | log | raw |
1 /**
2 * $Id: display.c,v 1.5 2007-01-25 13:03:23 nkeynes Exp $
3 *
4 * Generic support for keyboard and other input sources. The active display
5 * driver is expected to deliver events here, where they're translated and
6 * passed to the appropriate dreamcast controllers (if any).
7 *
8 * Copyright (c) 2005 Nathan Keynes.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
21 #include <stdint.h>
22 #include <assert.h>
23 #include "dream.h"
24 #include "display.h"
26 typedef struct keymap_entry {
27 uint16_t keycode;
28 input_key_callback_t callback;
29 void *data;
30 uint32_t value;
31 } *keymap_entry_t;
33 /**
34 * Colour format information
35 */
36 struct colour_format colour_formats[] = {
37 { GL_UNSIGNED_SHORT_1_5_5_5_REV, GL_BGRA, GL_RGB5_A1, 2 },
38 { GL_UNSIGNED_SHORT_5_6_5, GL_RGB, GL_RGB5, 2 },
39 { GL_UNSIGNED_SHORT_4_4_4_4_REV, GL_BGRA, GL_RGBA4, 2 },
40 { GL_UNSIGNED_INT_8_8_8_8_REV, GL_BGRA, GL_RGBA8, 4 }, /* YUV decoded to ARGB8888 */
41 { GL_UNSIGNED_BYTE, GL_BGR, GL_RGB, 3 },
42 { GL_UNSIGNED_INT_8_8_8_8_REV, GL_BGRA, GL_RGBA8, 4 }
43 };
45 /**
46 * FIXME: make this more memory efficient
47 */
48 struct keymap_entry *keymap[65536];
51 static struct keymap_entry *input_create_key( uint16_t keycode )
52 {
53 struct keymap_entry *key = keymap[ keycode ];
54 if( key == NULL ) {
55 key = malloc( sizeof( struct keymap_entry ) );
56 assert( key != NULL );
57 keymap[ keycode ] = key;
58 key->keycode = keycode;
59 }
60 return key;
61 }
63 static void input_delete_key( uint16_t keycode )
64 {
65 struct keymap_entry *key = keymap[keycode];
66 if( key != NULL ) {
67 free( key );
68 keymap[keycode] = NULL;
69 }
70 }
72 static struct keymap_entry *input_get_key( uint16_t keycode )
73 {
74 return keymap[ keycode ];
75 }
77 gboolean input_register_key( const gchar *keysym, input_key_callback_t callback,
78 void *data, uint32_t value )
79 {
80 int i;
81 if( display_driver == NULL || keysym == NULL )
82 return FALSE; /* No display driver */
83 gchar **strv = g_strsplit(keysym, ",", 16);
84 gchar **s = strv;
85 while( *s != NULL ) {
86 uint16_t keycode = display_driver->resolve_keysym(g_strstrip(*s));
87 if( keycode == 0 )
88 return FALSE; /* Invalid keysym */
90 struct keymap_entry *key = input_create_key( keycode );
91 key->callback = callback;
92 key->data = data;
93 key->value = value;
94 s++;
95 }
96 g_strfreev(strv);
97 return TRUE;
98 }
100 void input_unregister_key( const gchar *keysym )
101 {
102 if( display_driver == NULL || keysym == NULL )
103 return;
104 uint16_t keycode = display_driver->resolve_keysym(keysym);
105 if( keycode == 0 )
106 return;
107 input_delete_key( keycode );
108 }
111 gboolean input_is_key_valid( const gchar *keysym )
112 {
113 if( display_driver == NULL )
114 return FALSE; /* No display driver */
115 return display_driver->resolve_keysym(keysym) != 0;
116 }
118 gboolean input_is_key_registered( const gchar *keysym )
119 {
120 if( display_driver == NULL )
121 return FALSE;
122 uint16_t keycode = display_driver->resolve_keysym(keysym);
123 if( keycode == 0 )
124 return FALSE;
125 return input_get_key( keycode ) != NULL;
126 }
128 void input_event_keydown( uint16_t keycode )
129 {
130 struct keymap_entry *key = input_get_key(keycode);
131 if( key != NULL ) {
132 key->callback( key->data, key->value, TRUE );
133 }
134 }
136 void input_event_keyup( uint16_t keycode )
137 {
138 struct keymap_entry *key = input_get_key(keycode);
139 if( key != NULL ) {
140 key->callback( key->data, key->value, FALSE );
141 }
142 }
146 void display_set_driver( display_driver_t driver )
147 {
148 if( display_driver != NULL && display_driver->shutdown_driver != NULL )
149 display_driver->shutdown_driver();
151 display_driver = driver;
152 if( driver->init_driver != NULL )
153 driver->init_driver();
154 driver->set_display_format( 640, 480, COLFMT_ARGB8888 );
155 driver->set_render_format( 640, 480, COLFMT_ARGB8888, FALSE );
156 texcache_gl_init();
157 }
.