Previous 199869 Revisions Next

r31227 Monday 7th July, 2014 at 23:22:03 UTC by hap
correct ac after function set too
[src/emu/video]hd44780.c hd44780.h

trunk/src/emu/video/hd44780.c
r31226r31227
124124
125125void hd44780_device::device_reset()
126126{
127   memset(m_ddram, 0x20, sizeof(m_ddram)); // can't use 0 here as it would show CGRAM instead of blank space on a soft reset
127   memset(m_ddram, 0x20, sizeof(m_ddram)); // filled with SPACE char
128128   memset(m_cgram, 0, sizeof(m_cgram));
129129
130130   m_ac         = 0;
r31226r31227
184184   m_busy_timer->adjust( attotime::from_usec( usec ) );
185185}
186186
187void hd44780_device::update_ac(int direction)
187void hd44780_device::correct_ac()
188188{
189189   if (m_active_ram == DDRAM)
190190   {
191      if (direction == 1)
192      {
193         if (m_num_line == 2 && m_ac == 0x27)
194            m_ac = 0x40;
195         else if ((m_num_line == 2 && m_ac == 0x67) || (m_num_line == 1 && m_ac == 0x4f))
196            m_ac = 0x00;
197         else
198            m_ac = (m_ac + direction) & 0x7f;
199      }
200      else
201      {
202         if (m_num_line == 2 && m_ac == 0x00)
203            m_ac = 0x67;
204         else if (m_num_line == 1 && m_ac == 0x00)
205            m_ac = 0x4f;
206         else if (m_num_line == 2 && m_ac == 0x40)
207            m_ac = 0x27;
208         else
209            m_ac = (m_ac + direction) & 0x7f;
210      }
191      int max_ac = (m_num_line == 1) ? 0x4f : 0x67;
192     
193      if (m_ac > max_ac)
194         m_ac -= max_ac + 1;
195      else if (m_ac < 0)
196         m_ac = max_ac;
197      else if (m_num_line == 2 && m_ac > 0x27 && m_ac < 0x40)
198         m_ac = 0x40 + (m_ac - 0x28);
211199   }
212200   else
213   {
214      m_ac = (m_ac + direction) & 0x3f;
215   }
201      m_ac &= 0x3f;
216202}
217203
218void hd44780_device::shift_display(int direction)
204void hd44780_device::update_ac(int direction)
219205{
220   if (direction == 1)
221   {
222      if (m_disp_shift == 0x4f)
223         m_disp_shift = 0x00;
224      else
225         m_disp_shift++;
226   }
206   if (m_active_ram == DDRAM && m_num_line == 2 && direction == -1 && m_ac == 0x40)
207      m_ac = 0x27;
227208   else
228   {
229      if (m_disp_shift == 0x00)
230         m_disp_shift = 0x4f;
231      else
232         m_disp_shift--;
233   }
209      m_ac += direction;
210
211   correct_ac();
234212}
235213
214void hd44780_device::shift_display(int direction)
215{
216   m_disp_shift += direction;
217   
218   if (m_disp_shift == 0x50)
219      m_disp_shift = 0;
220   else if (m_disp_shift == -1)
221      m_disp_shift = 0x4f;
222}
223
236224void hd44780_device::update_nibble(int rs, int rw)
237225{
238226   if (m_rs_state != rs || m_rw_state != rw)
r31226r31227
402390      // set DDRAM address
403391      m_active_ram = DDRAM;
404392      m_ac = m_ir & 0x7f;
405
406      if (m_num_line == 2 && m_ac > 0x27 && m_ac < 0x40)
407         m_ac = 0x40 + (m_ac - 0x28);
408      else if (m_num_line == 2 && m_ac > 0x67)
409         m_ac = 0x00 + (m_ac - 0x68);
410      else if (m_num_line == 1 && m_ac > 0x4f)
411         m_ac = 0x00 + (m_ac - 0x50);
412
393      correct_ac();
413394      set_busy_flag(37);
414395
415396      if (LOG) logerror("HD44780 '%s': set DDRAM address %x\n", tag(), m_ac);
r31226r31227
437418      m_char_size = BIT(m_ir, 2) ? 10 : 8;
438419      m_data_len  = BIT(m_ir, 4) ? 8 : 4;
439420      m_num_line  = BIT(m_ir, 3) + 1;
421      correct_ac();
440422      set_busy_flag(37);
441423
442424      if (LOG) logerror("HD44780 '%s': char size 5x%d, data len %d, lines %d\n", tag(), m_char_size, m_data_len, m_num_line);
r31226r31227
445427   else if (BIT(m_ir, 4))
446428   {
447429      // cursor or display shift
448      int direct = (BIT(m_ir, 2)) ? +1 : -1;
430      int direction = (BIT(m_ir, 2)) ? +1 : -1;
449431
450      if (LOG) logerror("HD44780 '%s': %s shift %d\n", tag(), BIT(m_ir, 3) ? "display" : "cursor", direct);
432      if (LOG) logerror("HD44780 '%s': %s shift %d\n", tag(), BIT(m_ir, 3) ? "display" : "cursor", direction);
451433
452434      if (BIT(m_ir, 3))
453         shift_display(direct);
435         shift_display(direction);
454436      else
455         update_ac(direct);
437         update_ac(direction);
456438
457439      set_busy_flag(37);
458440   }
trunk/src/emu/video/hd44780.h
r31226r31227
8686private:
8787   // internal helper
8888   void set_busy_flag(UINT16 usec);
89   void correct_ac();
8990   void update_ac(int direction);
9091   void update_nibble(int rs, int rw);
9192   void shift_display(int direction);
r31226r31227
106107   UINT8       m_ddram[0x80];    // internal display data RAM
107108   UINT8       m_cgram[0x40];    // internal chargen RAM
108109   UINT8 *     m_cgrom;          // internal chargen ROM
109   INT8        m_ac;             // address counter
110   int         m_ac;             // address counter
110111   UINT8       m_dr;             // data register
111112   UINT8       m_ir;             // instruction register
112113   UINT8       m_active_ram;     // DDRAM or CGRAM
r31226r31227
115116   bool        m_blink_on;       // blink on/off
116117   bool        m_shift_on;       // shift on/off
117118   UINT8       m_disp_shift;     // display shift
118   INT8        m_direction;      // auto increment/decrement
119   int        m_direction;      // auto increment/decrement (-1 or +1)
119120   UINT8       m_data_len;       // interface data length 4 or 8 bit
120121   UINT8       m_num_line;       // number of lines
121122   UINT8       m_char_size;      // char size 5x8 or 5x10
r31226r31227
125126   int         m_rw_state;
126127   bool        m_nibble;
127128   int         m_charset_type;
128   UINT8       m_render_buf[80*16];
129   UINT8       m_render_buf[80 * 16];
129130
130131   enum        { DDRAM, CGRAM };
131132};

Previous 199869 Revisions Next


© 1997-2024 The MAME Team