trunk/src/emu/video/hd44780.c
| r31226 | r31227 | |
| 124 | 124 | |
| 125 | 125 | void hd44780_device::device_reset() |
| 126 | 126 | { |
| 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 |
| 128 | 128 | memset(m_cgram, 0, sizeof(m_cgram)); |
| 129 | 129 | |
| 130 | 130 | m_ac = 0; |
| r31226 | r31227 | |
| 184 | 184 | m_busy_timer->adjust( attotime::from_usec( usec ) ); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | | void hd44780_device::update_ac(int direction) |
| 187 | void hd44780_device::correct_ac() |
| 188 | 188 | { |
| 189 | 189 | if (m_active_ram == DDRAM) |
| 190 | 190 | { |
| 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); |
| 211 | 199 | } |
| 212 | 200 | else |
| 213 | | { |
| 214 | | m_ac = (m_ac + direction) & 0x3f; |
| 215 | | } |
| 201 | m_ac &= 0x3f; |
| 216 | 202 | } |
| 217 | 203 | |
| 218 | | void hd44780_device::shift_display(int direction) |
| 204 | void hd44780_device::update_ac(int direction) |
| 219 | 205 | { |
| 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; |
| 227 | 208 | 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(); |
| 234 | 212 | } |
| 235 | 213 | |
| 214 | void 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 | |
| 236 | 224 | void hd44780_device::update_nibble(int rs, int rw) |
| 237 | 225 | { |
| 238 | 226 | if (m_rs_state != rs || m_rw_state != rw) |
| r31226 | r31227 | |
| 402 | 390 | // set DDRAM address |
| 403 | 391 | m_active_ram = DDRAM; |
| 404 | 392 | 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(); |
| 413 | 394 | set_busy_flag(37); |
| 414 | 395 | |
| 415 | 396 | if (LOG) logerror("HD44780 '%s': set DDRAM address %x\n", tag(), m_ac); |
| r31226 | r31227 | |
| 437 | 418 | m_char_size = BIT(m_ir, 2) ? 10 : 8; |
| 438 | 419 | m_data_len = BIT(m_ir, 4) ? 8 : 4; |
| 439 | 420 | m_num_line = BIT(m_ir, 3) + 1; |
| 421 | correct_ac(); |
| 440 | 422 | set_busy_flag(37); |
| 441 | 423 | |
| 442 | 424 | 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); |
| r31226 | r31227 | |
| 445 | 427 | else if (BIT(m_ir, 4)) |
| 446 | 428 | { |
| 447 | 429 | // cursor or display shift |
| 448 | | int direct = (BIT(m_ir, 2)) ? +1 : -1; |
| 430 | int direction = (BIT(m_ir, 2)) ? +1 : -1; |
| 449 | 431 | |
| 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); |
| 451 | 433 | |
| 452 | 434 | if (BIT(m_ir, 3)) |
| 453 | | shift_display(direct); |
| 435 | shift_display(direction); |
| 454 | 436 | else |
| 455 | | update_ac(direct); |
| 437 | update_ac(direction); |
| 456 | 438 | |
| 457 | 439 | set_busy_flag(37); |
| 458 | 440 | } |
trunk/src/emu/video/hd44780.h
| r31226 | r31227 | |
| 86 | 86 | private: |
| 87 | 87 | // internal helper |
| 88 | 88 | void set_busy_flag(UINT16 usec); |
| 89 | void correct_ac(); |
| 89 | 90 | void update_ac(int direction); |
| 90 | 91 | void update_nibble(int rs, int rw); |
| 91 | 92 | void shift_display(int direction); |
| r31226 | r31227 | |
| 106 | 107 | UINT8 m_ddram[0x80]; // internal display data RAM |
| 107 | 108 | UINT8 m_cgram[0x40]; // internal chargen RAM |
| 108 | 109 | UINT8 * m_cgrom; // internal chargen ROM |
| 109 | | INT8 m_ac; // address counter |
| 110 | int m_ac; // address counter |
| 110 | 111 | UINT8 m_dr; // data register |
| 111 | 112 | UINT8 m_ir; // instruction register |
| 112 | 113 | UINT8 m_active_ram; // DDRAM or CGRAM |
| r31226 | r31227 | |
| 115 | 116 | bool m_blink_on; // blink on/off |
| 116 | 117 | bool m_shift_on; // shift on/off |
| 117 | 118 | UINT8 m_disp_shift; // display shift |
| 118 | | INT8 m_direction; // auto increment/decrement |
| 119 | int m_direction; // auto increment/decrement (-1 or +1) |
| 119 | 120 | UINT8 m_data_len; // interface data length 4 or 8 bit |
| 120 | 121 | UINT8 m_num_line; // number of lines |
| 121 | 122 | UINT8 m_char_size; // char size 5x8 or 5x10 |
| r31226 | r31227 | |
| 125 | 126 | int m_rw_state; |
| 126 | 127 | bool m_nibble; |
| 127 | 128 | int m_charset_type; |
| 128 | | UINT8 m_render_buf[80*16]; |
| 129 | UINT8 m_render_buf[80 * 16]; |
| 129 | 130 | |
| 130 | 131 | enum { DDRAM, CGRAM }; |
| 131 | 132 | }; |