OSDN Git Service

* public snapshot of sid simulator
[pf3gnuchains/pf3gnuchains3x.git] / sid / component / lcd / T6963C.h
1 // T6963C.h - 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 #ifndef T6963C_DEF_H
8 #define T6963C_DEF_H
9
10 #include <sidtypes.h>
11 #include <sidcomp.h>
12 #include <sidcomputil.h>
13 #include <sidbusutil.h>
14 #include <sidpinutil.h>
15 #include <sidattrutil.h>
16 #include <sidschedutil.h>
17 #include <sidwatchutil.h>
18
19 using namespace sid;
20 using namespace sidutil;
21
22 static const int ROM_SIZE = 128 + 32;
23
24 class T6963C: public virtual component,
25               public fixed_accessor_map_component,
26               public fixed_attribute_map_component,
27               public fixed_bus_map_component,
28               public fixed_pin_map_component,
29               public no_relation_component
30 {
31 private:
32   // registers
33   host_int_1 status;
34   host_int_1 cursor_x, cursor_y;
35   host_int_1 offset;
36   host_int_2 adp;
37
38   host_int_2 graphic_home;
39   host_int_2 text_home;
40   host_int_1 g_cols, t_cols;
41
42   void set_reg_attr();
43
44  /* Commands with arguments are sent as follows:
45   *     check STA0,1 status
46   *     send D1
47   *     check status
48   *     send D2 (optional)
49   *     check status (if D2 sent)
50   *     send command
51   *
52   * dbuf1 and dbuf2 are data buffers to hold D1 and D2, respectively
53   */
54   bool use_first_dbuf;
55   unsigned char dbuf1, dbuf2;
56
57   int mode;                     // mode set
58   bool external_cgen;
59
60   bool cursor_on;               // display mode
61   bool cursor_blink_on;
62   bool text_on;
63   bool graphics_on;
64
65   int num_cursor_lines;
66
67   bool blinking_chars_are_visible;
68
69   // Set if in text attribute mode and at least one char has blink on
70   bool need_continuous_refresh;
71
72   // pins
73
74  /* The real chip uses a bunch of strobes to cycle through the pixels.
75   * Specifically, these are the LP, HSCP, and LSCP pins. I chose to abstract 
76   * these pins into row/col so that we only have to output a pixel if it is on.
77   * Specifically, the row and col are multiplexed into a single word, and the
78   * row_col pin is only driven if that pixel is on.
79   */
80   output_pin row_col;           // row/column selector
81
82  /* The frame pin is set on at the beginning of a refresh and turned off at
83   * the end.
84   */
85   output_pin fr;
86
87   // bus
88   sid::bus *ex_ram;
89
90   friend class callback_byte_bus<T6963C>;
91   callback_byte_bus<T6963C> busif;
92
93  /* The Toshiba specs give the following table for accessing the registers:
94   *
95   * WR! = L, C/D = H: Command Write, C/D = L: Data Write
96   * RD! = L, C/D = H: Status Read,   C/D = L: Data Read
97   *
98   * So there really isn't an address range in a direct sense. To access the
99   * registers, I have assumed that C/D is tied to logical address line A0,
100   * so that the latch buffers are accessed as:
101   *
102   * Logical Address 0: Data buffer
103   * Logical Address 1: Command/Status register
104   */
105   sid::bus::status busRead( host_int_4 laddr, host_int_1& data );
106   sid::bus::status busWrite( host_int_4 laddr, host_int_1 data );
107
108   host_int_1 rom[ROM_SIZE][8];
109
110   void executeCommand( unsigned char cmd );
111
112   void refresh();
113
114   // display geometry
115
116  /* hw_rows and hw_cols are hardwired chip inputs derived from the MDS and
117   * MD0-3 pins. Note that the text area and graphic area commands can over-
118   * ride and refine these settings.
119   */
120   int hw_rows;
121   int hw_cols;
122
123   std::string getDisplayWidth() { return make_attribute( hw_cols ); }
124   component::status setDisplayWidth( const std::string& s );
125
126   std::string getDisplayHeight()        { return make_attribute( hw_rows ); }
127   component::status setDisplayHeight( const std::string& s );
128
129   // The font-size attribute replaces the FS0 and FS1 pins
130   int font_width;
131
132   std::string getFontSize()             { return make_attribute( font_width ); }
133   component::status setFontSize( const std::string& s );
134
135  /* Scheduler stuff. To save on simulation cycles, the screen is only refreshed
136   * if necessary. The two conditions used to determine that a refresh is 
137   * required are: a) there was a write to the chip (data or control), b) either
138   * the cursor or some text is blinking. For (a) we use a one-time refresh,
139   * for (b) we use a continuous periodic refresh. The one-time refresh can
140   * turn into a periodic refresh if it turns out that we wrote something that
141   * enabled blinking.
142   */
143   friend class sidutil::scheduler_event_subscription<T6963C>;
144   sidutil::scheduler_event_subscription<T6963C> refresh_sync;
145
146 public:
147   enum {
148     NO_SCHED,
149     ONE_TIME_SCHED,
150     REGULAR_SCHED
151   };
152
153 private:
154   int current_schedule;         // one of the above
155   host_int_4 refresh_period;    // in milliseconds
156
157   // Triggerpoint manager
158   friend class sidutil::self_watcher<T6963C>;
159   sidutil::self_watcher<T6963C> trigger_mgr;
160
161   // Virtual pin interfaces between self_watcher and fixed_pin_map_component
162   sid::component::status
163   pin_factory( const std::string& n ) { return trigger_mgr.create_virtual_pin(n); }
164
165   void
166   pin_junkyard( const std::string& n ) { trigger_mgr.destroy_virtual_pin( n ); }
167
168   // State save/restore.
169   std::string save_state ();
170   component::status restore_state ( const std::string& state );
171   friend std::ostream& operator << ( std::ostream& op, const T6963C& copy_obj );
172   friend std::istream& operator >> ( std::istream& ip, T6963C& ovwrite_obj );
173
174 public:
175
176   T6963C( bool use_japan_rom );
177
178   void reset();
179
180   ~T6963C() {}
181 };
182
183 #endif // T6963C_DEF_H