OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / lcd / testsuite / hd-two-line.cxx
1 // hd-two-line.cxx - description.  -*- C++ -*-
2
3 // Copyright (C) 1999, 2000 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.
6
7 #include "hd-two-line.h"
8 #include <sidso.h>
9
10 void
11 hd_two_line :: init() {
12   put( LCD_IR, 0x38 );          // 2-lines, 5x8 font
13   put( LCD_IR, 1 );             // clear display
14   put( LCD_IR, 0x3 );           // return home
15   put( LCD_IR, 0xc );           // enable display
16 }
17
18 static char logo[] = { 0x3, 0x4, 0x9, 0xa, 0xa, 
19                 0xa, 0xa, 0x9, 0x4, 0x3, 0x0, 0x0, 0x0, 
20                 0x0, 0x0, 0x0, 0x18, 0x4, 0x13, 0x0b, 0x0, 
21                 0x0, 0xa, 0x13, 0x4, 0x18 };
22
23 void
24 hd_two_line :: draw_logo() {
25   int i;
26
27   put( LCD_IR, 0x43 );          // set AC to CGRAM char 0 line 3
28
29   for( i=0; i<26; i++ )         // create logo         
30     put( LCD_DR, logo[i] );
31
32   put( LCD_IR, 0x80 );          // select DDRAM address 0
33
34   put( LCD_DR, 0 );             // write first line
35   put( LCD_DR, 2 );
36
37   char *str = "cygnus";
38   char *p = str;
39
40   while( *p )
41     put( LCD_DR, *p++ );
42
43   put( LCD_IR, 0xc0 );          // select start of second line
44
45   put( LCD_DR, 1 );             // write second line
46   put( LCD_DR, 3 );
47
48   str = "rules!";
49   p = str;
50
51   while( *p )
52     put( LCD_DR, *p++ );
53
54   cout << "should see \"Cygnus rules!\" " << endl; 
55
56   // This is for later, when the display is shifted
57   put( LCD_IR, 0x88 );          // select DDRAM address 8
58
59   put( LCD_DR, 0xf3 );          // infinity
60   put( LCD_DR, 0xfc );          // house?
61
62   put( LCD_IR, 0xa6 );          // select DDRAM address 0x26
63
64   put( LCD_DR, 0xec );          // cent
65   put( LCD_DR, 0xed );          // pound
66
67   put( LCD_IR, 0xc8 );          // select DDRAM address 0x48
68
69   put( LCD_DR, 0x5c );          // yen
70   put( LCD_DR, 0xf2 );          // theta
71
72   put( LCD_IR, 0xe6 );          // select DDRAM address 0x66
73
74   put( LCD_DR, 0xe8 );          // sqrt
75   put( LCD_DR, 0xf7 );          // pi
76 }
77
78 void 
79 hd_two_line :: enable_cursor() {
80   put( LCD_IR, 0x82 );          // set DDRAM address to pos 2
81   put( LCD_IR, 0x0e );          // enable cursor display
82
83   cout << "cursor should be visible in line 1 pos 2" << endl;
84 }
85
86 void 
87 hd_two_line :: move_cursor() {
88   put( LCD_IR, 0xc7 );          // set DDRAM address to pos 1
89   put( LCD_IR, 0x0f );          // enable cursor display
90
91   cout << "cursor and char should be blinking in line 2 pos 7" << endl;
92 }
93
94 void 
95 hd_two_line :: shift_cursor_left() {
96   put( LCD_IR, 0x10 );          // shift cursor left
97
98   cout << "cursor and char should be blinking in line 2 pos 6" << endl;
99 }
100
101 void 
102 hd_two_line :: shift_cursor_right() {
103   put( LCD_IR, 0x0d );          // disable cursor (leave blinking on)
104   put( LCD_IR, 0x14 );          // shift cursor right
105
106   cout << "char should be blinking in line 2 pos 7" << endl;
107 }
108
109
110 void 
111 hd_two_line :: shift_display_left() {
112   put( LCD_IR, 0x18 );          // shift display left
113
114   cout << "display should be shifted left by one" << endl;
115 }
116
117 void 
118 hd_two_line :: shift_display_right() {
119   put( LCD_IR, 0x1c );          // shift display right
120
121   cout << "display should be shifted right by one" << endl;
122 }
123
124 void
125 hd_two_line :: disable_display() {
126   put( LCD_IR, 0x08 );
127
128   cout << "display should be disabled " << endl;
129 }
130
131 void
132 hd_two_line :: enable_display() {
133   put( LCD_IR, 0x0c );          // leaves blink and cursor off
134
135   cout << "display is now enabled " << endl;
136 }
137
138 void
139 hd_two_line :: run( host_int_4 ) {
140   switch( curr_state() ) {
141   case INIT:
142     init();
143     yield( DRAW_LOGO, 0 );
144     return;
145
146   case DRAW_LOGO:
147     draw_logo();
148     yield( NO_DISPLAY, 200000 );
149     return;
150
151   case NO_DISPLAY:
152     disable_display();
153     yield( SET_CURSOR, 100000 );
154     return;
155
156   case SET_CURSOR:
157     enable_display();
158     enable_cursor();
159     yield( MOVE_CURSOR, 200000 );
160     return;
161
162   case MOVE_CURSOR:
163     move_cursor();
164     yield( SHIFT_CURSOR_LEFT, 500000 );
165     return;
166
167   case SHIFT_CURSOR_LEFT:
168     shift_cursor_left();
169     yield( SHIFT_CURSOR_RIGHT, 500000 );
170     return;
171
172   case SHIFT_CURSOR_RIGHT:
173     shift_cursor_right();
174     yield( SHIFT_DISPLAY_LEFT, 500000 );
175     shift_count = 0;
176     return;
177
178   case SHIFT_DISPLAY_LEFT:
179     shift_display_left();
180     ++shift_count;
181     if( shift_count == 2 ) {
182       yield( SHIFT_DISPLAY_RIGHT, 200000 );
183       shift_count = 0;
184     }
185     else
186       yield( SHIFT_DISPLAY_LEFT, 200000 );
187     return;
188
189   case SHIFT_DISPLAY_RIGHT:
190     shift_display_right();
191     ++shift_count;
192     if( shift_count == 4 )
193       yield( DONE, 200000 );
194     else
195       yield( SHIFT_DISPLAY_RIGHT, 200000 );
196     return;
197
198   case WAITING:
199     yield();
200     return;
201
202   default:
203     break;
204   }
205
206   cout << "all tests complete: fail count " << fail_count << endl;
207
208   run_opin.drive( 0 );
209 }
210
211 static vector<string>
212 HD44780UTesterListTypes() {
213   vector<string> types;
214   types.push_back(string("hd44780u-tester"));
215   return types;
216 }
217
218 static component*
219 HD44780UTesterCreate( const string& typeName ) {
220   if(typeName == "hd44780u-tester")
221     return new hd_two_line();
222   else
223     return 0;
224 }
225
226 static void
227 HD44780UTesterDelete( component* c ) {
228   delete dynamic_cast<hd_two_line*>(c);
229 }
230
231
232 // static object
233 extern const component_library hd2l_tester_component_library;
234
235 const component_library hd2l_tester_component_library DLLEXPORT = 
236 {
237   COMPONENT_LIBRARY_MAGIC,
238   & HD44780UTesterListTypes, 
239   & HD44780UTesterCreate,
240   & HD44780UTesterDelete
241 };
242