OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / lcd / testsuite / t6963c-japan.cxx
1 // t6963c-japan.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 "t6963c-japan.h"
8
9 #include <sidso.h>
10 #include <stdio.h>
11 #include <unistd.h>
12
13 #define NROWS   8
14 #define NCOLS   8
15
16 enum {
17   SET_CURSOR    = 0x21,
18   SET_OFFSET    = 0x22,
19   SET_ADP       = 0x24,
20   SET_TXT_HOME  = 0x40,
21   SET_TXT_AREA  = 0x41,
22   SET_GRX_HOME  = 0x42,
23   SET_GRX_AREA  = 0x43,
24   SET_AWRITE    = 0xb0,
25   SET_AREAD     = 0xb1,
26   CLR_AUTO_RW   = 0xb2,
27   DWRITE_INC    = 0xc0,
28   DREAD_INC     = 0xc1,
29   DWRITE_DEC    = 0xc2,
30   DREAD_DEC     = 0xc3,
31   DWRITE        = 0xc4,
32   DREAD         = 0xc5
33 };
34
35 enum {          // status byte
36   STA0  = 0x1,  // set if ready to take next command
37   STA1  = 0x2,  // set if memory ready
38   STA2  = 0x4,  // set if auto read
39   STA3  = 0x8,  // set if auto write
40   STA6  = 0x40, // set if peek/poke error
41   STA7  = 0x80, // set if display on
42 };
43
44 enum {
45   DATA_REG      = 0xa0000,
46   CMD_REG       = 0xa0004,
47   STATUS_REG    = 0xa0004
48 };
49
50 T6963C_tester :: T6963C_tester() : run_ipin( this, &T6963C_tester::run ) {
51   add_pin( "run", &run_ipin, &run_opin );
52   add_accessor( "bus", &bus );
53
54   lcd = 0;
55   add_uni_relation( "lcd", &lcd );
56
57   lcd = 0;
58   add_uni_relation( "ddram", &dram );
59
60   state = INIT;
61   fail_count = 0;
62 }
63
64 bool 
65 T6963C_tester :: check_status( uchar what ) {
66   big_int_1 val;
67   uchar byte;
68
69   if( bus->read( STATUS_REG, val ) != sid::bus::ok ) {
70     ++fail_count;
71     printf( "check_status: read failed\n" );
72     return false;
73   }
74
75   byte = val;
76   if( (byte & what) != what ) {
77     ++fail_count;
78     printf( "check_status: bad status - got %02x != %02x\n", byte, what );
79     return false;
80   }
81
82   return true;
83 }
84
85 bool 
86 T6963C_tester :: send_cmd( uchar cmd ) {
87   big_int_1 val = cmd;
88
89   if( !check_status( STA1 | STA0 ) )
90     return false;
91
92   if( bus->write( CMD_REG, val ) != sid::bus::ok ) {
93     ++fail_count;
94     printf( "send_cmd: bad write\n" );
95     return false;
96   }
97   
98   return true;
99 }
100   
101 bool 
102 T6963C_tester :: reset_auto( uchar mode ) {
103   big_int_1 val = CLR_AUTO_RW;
104
105   if( !check_status( mode ) )
106     return false;
107
108   if( bus->write( CMD_REG, val ) != sid::bus::ok ) {
109     ++fail_count;
110     printf( "reset_auto: bad write\n" );
111     return false;
112   }
113   
114   return true;
115 }
116   
117 bool 
118 T6963C_tester :: send_data( uchar data ) {
119   big_int_1 val = data;
120
121   if( !check_status( STA1 | STA0 ) )
122     return false;
123
124   if( bus->write( DATA_REG, val ) != sid::bus::ok ) {
125     ++fail_count;
126     printf( "send_data: bad write\n" );
127     return false;
128   }
129   
130   return true;
131 }
132   
133 bool 
134 T6963C_tester :: get_data( uchar& data ) {
135   big_int_1 val;
136
137   if( !check_status( STA1 | STA0 ) )
138     return false;
139
140   if( bus->read( DATA_REG, val ) != sid::bus::ok ) {
141     ++fail_count;
142     printf( "get_data: read failed\n" );
143     return false;
144   }
145
146   data = val;
147   return true;
148 }
149
150 bool 
151 T6963C_tester :: write_mem( uchar cmd, uchar val ) {
152   if( !send_data( val ) )
153     return false;
154
155   if( !send_cmd( cmd ) )
156     return false;
157
158   return true;
159 }
160
161 bool 
162 T6963C_tester :: read_mem( uchar cmd, uchar& val ) {
163   if( !send_cmd( cmd ) )
164     return false;
165
166   return get_data( val );
167 }
168
169 bool 
170 T6963C_tester :: auto_write( uchar data ) {
171   big_int_1 val = data;
172
173   if( !check_status( STA3 ) )
174     return false;
175
176   if( bus->write( DATA_REG, val ) != sid::bus::ok ) {
177     ++fail_count;
178     printf( "auto_write failed\n" );
179     return false;
180   }
181   
182   return true;
183 }
184
185 bool 
186 T6963C_tester :: auto_read( uchar& data ) {
187   big_int_1 val;
188
189   if( !check_status( STA2 ) )
190     return false;
191
192   if( bus->read( DATA_REG, val ) != sid::bus::ok ) {
193     ++fail_count;
194     printf( "auto_read failed\n" );
195     return false;
196   }
197
198   data = val;
199   return true;
200 }
201
202 bool 
203 T6963C_tester :: set_word_reg( uchar cmd, uchar lo, uchar hi ) {
204   if( !send_data( lo ) )
205     return false;
206
207   if( !send_data( hi ) )
208     return false;
209
210   if( !send_cmd( cmd ) )
211     return false;
212
213   return true;
214 }
215
216 void
217 T6963C_tester :: mem_set( uchar val, unsigned addr, int len ) {
218   set_word_reg( SET_ADP, addr & 0xff, addr >> 8 );
219   send_cmd( SET_AWRITE );
220  
221  for( int i=0; i<len; i++ )
222     auto_write( val );
223
224   reset_auto( 8 );
225 }
226
227 void
228 T6963C_tester :: init() {
229   int i;
230   uchar val;
231
232   cout << "starting T6963C LCD tests" << endl;
233
234   //intialize the display
235   set_word_reg( SET_TXT_HOME, 0x00, 0x00 );
236   set_word_reg( SET_TXT_AREA, NCOLS, 0 );
237   set_word_reg( SET_GRX_HOME, 0x00, 0x02 );
238   set_word_reg( SET_GRX_AREA, NCOLS, 0 );
239  
240   // mode set: OR mode, internal cgen
241   send_cmd( 0x80 );                     
242
243   mem_set( 0, 0, NCOLS*NROWS );                 // clear display
244
245   // write a text string
246   set_word_reg( SET_ADP, 2*NCOLS+1, 0x00 );     // row 2, col 1
247   send_cmd( SET_AWRITE );
248
249   char *test_str = "CYGNUS";
250   int len = strlen( test_str );
251
252   for( i=0; i<len; i++ ) 
253     auto_write( test_str[i] - ' ' );
254   reset_auto( 8 );
255
256   set_word_reg( SET_ADP, 4*NCOLS+1, 0x00 );     // row 4, col 1
257   send_cmd( SET_AWRITE );
258
259   test_str = "REDHAT";
260   len = strlen( test_str );
261
262   for( i=0; i<len; i++ ) 
263     auto_write( test_str[i] - ' ' );
264   reset_auto( 8 );
265
266   set_word_reg( SET_ADP, 3*NCOLS+4, 0x00 );     // row 3, col 4
267   write_mem( DWRITE, '+' - ' ' );
268   set_word_reg( SET_ADP, 5*NCOLS+4, 0x00 );     // row 5, col 4
269   write_mem( DWRITE, '=' - ' ' );
270   set_word_reg( SET_ADP, 6*NCOLS+3, 0x00 );     // row 6, col 3
271   write_mem( DWRITE_INC, '$' - ' ' );
272   write_mem( DWRITE_INC, 0 );
273   write_mem( DWRITE_INC, '?' - ' ' );
274
275   set_word_reg( SET_CURSOR, 3, 6 );             // cursor at [x,y] = 5,6
276   send_cmd( 0xa8 );                             // 8-line cursor
277
278   // display: text on, graphics off, blinking cursor
279   send_cmd( 0x97 );
280
281   cout << "should see 'CYGNUS + REDHAT = $?'" << endl;
282 }
283
284 void
285 T6963C_tester :: dump_rom() {
286   int i;
287
288   mem_set( 0, 0, NROWS*NCOLS );                 // clear text mem
289
290   set_word_reg( SET_ADP, 0, 0 );
291   send_cmd( SET_AWRITE );
292   for( i=0x40; i<0x80; i++ )
293     auto_write( i );
294   reset_auto( 8 );
295
296   set_word_reg( SET_CURSOR, NCOLS/2, NROWS/2 );
297   send_cmd( 0xa0 );                             // 1-line cursor
298
299   send_cmd( 0x94 );                             // text only, no cursor
300
301   cout << "should Japanese character set" << endl;
302 }
303
304 void
305 T6963C_tester :: yield( int to_state, unsigned long count ) {
306   if( state == WAITING ) {
307     if( curr_count < wait_count ) {
308       ++curr_count;
309
310 #if 0
311       if( (curr_count % 1000) == 0 )
312         cerr << ".";
313 #endif
314       return;
315     }
316
317     state = next_state;
318   }
319   else {
320     next_state = to_state;
321     state = WAITING;
322     curr_count = 0;
323     wait_count = count;
324   }
325 }
326
327 void
328 T6963C_tester :: run( host_int_4 ) {
329   switch( state ) {
330   case INIT:
331     init();
332     yield( DISABLE_DISPLAY, 1000000 );
333     return;
334
335   case DISABLE_DISPLAY:
336     if( !lcd || !dram ) {
337       cout << "missing relation to lcd and/or dram" << endl;
338       ++fail_count;
339     }
340     else {
341       snap_shot = lcd->attribute_value( "state-snapshot" );
342       dram_state = dram->attribute_value( "state-snapshot" );
343       cout << "Took a state snapshot" << endl;
344     }
345
346     send_cmd( 0x90 );   // disable display
347     cout << "Display should now be disabled" << endl;
348     yield( ENABLE_DISPLAY, 100000 );
349     return;
350
351   case ENABLE_DISPLAY:
352     send_cmd( 0x94 );
353     cout << "Re-enabled display" << endl;
354     yield( DUMP_ROM, 0 );
355     return;
356
357   case DUMP_ROM:
358     dump_rom();
359     yield( RESTORE, 1000000 );
360     return;
361
362   case RESTORE:
363     {
364       component::status rc;
365
366       rc = lcd->set_attribute_value( "state-snapshot", snap_shot );
367       if( rc != component::ok ) {
368         cout << "lcd restore state failed" << endl;
369         ++fail_count;
370       }
371       rc = dram->set_attribute_value( "state-snapshot", dram_state );
372       if( rc != component::ok ) {
373         cout << "dram restore state failed" << endl;
374         ++fail_count;
375       }
376
377       cout << "state should be restored to snap-shot" << endl;
378       yield( DONE, 200000 );
379     }
380     return;
381
382   case WAITING:
383     yield( next_state, 0 );
384     return;
385
386   default:
387     break;
388   }
389
390   cout << "all tests complete: fail count " << fail_count << endl;
391
392   run_opin.drive( 0 );
393 }
394
395 static vector<string>
396 T6963CTesterListTypes() {
397   vector<string> types;
398   types.push_back(string("t6963c-tester"));
399   return types;
400 }
401
402 static component*
403 T6963CTesterCreate( const string& typeName ) {
404   if(typeName == "t6963c-tester")
405     return new T6963C_tester();
406   else
407     return 0;
408 }
409
410 static void
411 T6963CTesterDelete( component* c ) {
412   delete dynamic_cast<T6963C_tester*>(c);
413 }
414
415
416 // static object
417 extern const component_library t6963c_tester_component_library;
418
419 const component_library t6963c_tester_component_library DLLEXPORT = 
420 {
421   COMPONENT_LIBRARY_MAGIC,
422   & T6963CTesterListTypes, 
423   & T6963CTesterCreate,
424   & T6963CTesterDelete
425 };
426