1 // lcd-char-display.cxx - description. -*- C++ -*-
3 // Copyright (C) 1999, 2000, 2001, 2002 Red Hat.
4 // This file is part of SID and is licensed under the GPL.
5 // See the file COPYING.SID for conditions for redistribution.
11 #include <sidpinutil.h>
12 #include <sidattrutil.h>
13 #include <sidcomputil.h>
14 #include <sidattrutil.h>
15 #include <sidwatchutil.h>
17 #ifdef HAVE__USR_INCLUDE_CURSES_H
18 // The following macro definition prevents curses.h from providing a typedef
19 // for bool on Solaris.
21 #include "/usr/include/curses.h"
33 using sid::host_int_2;
34 using sid::host_int_4;
35 using sid::component_library;
36 using sid::COMPONENT_LIBRARY_MAGIC;
38 using namespace sidutil;
40 class lcd_char_display : public virtual component,
41 public fixed_pin_map_component,
42 public fixed_attribute_map_component,
43 public no_bus_component,
44 public no_accessor_component,
45 public no_relation_component
49 friend class callback_pin<lcd_char_display>;
50 callback_pin<lcd_char_display> row_col_pin;
51 callback_pin<lcd_char_display> frame_pin;
52 callback_pin<lcd_char_display> init_pin;
54 host_int_2 width, height;
56 void set_pixel( host_int_4 row_col );
58 void new_frame( host_int_4 val );
59 void init( host_int_4 );
61 #if HAVE_CURSES_H && HAVE_CURSES_LIBRARY
65 // Triggerpoint manager
66 friend class self_watcher<lcd_char_display>;
67 self_watcher<lcd_char_display> trigger_mgr;
69 // Virtual pin interfaces between self_watcher and fixed_pin_map_component
70 sid::component::status
71 pin_factory( const string& n ) { return trigger_mgr.create_virtual_pin(n); }
74 pin_junkyard( const string& n ) { trigger_mgr.destroy_virtual_pin( n ); }
79 ~lcd_char_display() throw ();
81 // Save & restore state
83 component::status restore_state (const string& state);
86 lcd_char_display :: lcd_char_display() :
87 row_col_pin( this, &lcd_char_display::set_pixel ),
88 frame_pin( this, &lcd_char_display::new_frame ),
89 init_pin( this, &lcd_char_display::init ),
92 add_pin( "row-col", &row_col_pin );
93 add_attribute( "row-col", &row_col_pin, "pin" );
94 trigger_mgr.add_watchable_attribute( "row-col" );
95 categorize( "row-col", "watchable" );
97 add_pin( "FR", &frame_pin );
98 add_attribute( "FR", &frame_pin, "pin" );
99 trigger_mgr.add_watchable_attribute( "FR" );
100 categorize( "FR", "watchable" );
102 add_pin( "init", &init_pin );
103 add_attribute( "init", &init_pin, "pin" );
104 trigger_mgr.add_watchable_attribute( "init" );
105 categorize( "init", "watchable" );
109 add_attribute( "width", &width, "setting" );
110 add_attribute( "height", &height, "setting" );
112 add_attribute_virtual ("state-snapshot", this,
113 & lcd_char_display::save_state,
114 & lcd_char_display::restore_state);
116 #if HAVE_CURSES_H && HAVE_CURSES_LIBRARY
122 lcd_char_display :: ~lcd_char_display() throw () {
123 #if HAVE_CURSES_H && HAVE_CURSES_LIBRARY
129 lcd_char_display :: init( host_int_4 ) {
130 #if HAVE_CURSES_H && HAVE_CURSES_LIBRARY
132 w = newwin( height, width, 0, 0 );
137 trigger_mgr.check_and_dispatch();
141 lcd_char_display::set_pixel (host_int_4 val)
146 int col = i & 0x0ffff;
148 #if HAVE_CURSES_H && HAVE_CURSES_LIBRARY
151 mvwaddch( w, row, col, '*' );
153 std::cout << '[' << row << ',' << col << ']';
154 #endif // HAVE_CURSES_H
156 trigger_mgr.check_and_dispatch();
160 lcd_char_display::new_frame (host_int_4 val)
162 #if HAVE_CURSES_H && HAVE_CURSES_LIBRARY
171 std::cout << std::endl;
174 trigger_mgr.check_and_dispatch();
178 lcd_char_display::save_state ( )
180 return string ("lcd-char");
184 lcd_char_display::restore_state(const string& state)
186 if (state == "lcd-char")
187 return component::ok;
188 return component::bad_value;
191 static vector<string>
194 vector<string> types;
196 types.push_back( string( "hw-lcd-char-display" ) );
202 DevicesCreate(const string& typeName)
204 if( typeName == "hw-lcd-char-display" )
205 return new lcd_char_display();
211 DevicesDelete(component* c)
213 delete dynamic_cast<lcd_char_display*>(c);
217 DLLEXPORT extern const component_library lcd_char_display_component_library;
219 const component_library lcd_char_display_component_library =
221 COMPONENT_LIBRARY_MAGIC,