src/emu/video/mc6845.c
| r11542 | r11543 | |
| 24 | 24 | |
| 25 | 25 | #include "emu.h" |
| 26 | 26 | #include "mc6845.h" |
| 27 | #include "machine/devhelpr.h" |
| 27 | 28 | |
| 28 | 29 | |
| 29 | 30 | #define LOG (0) |
| 30 | 31 | |
| 31 | 32 | |
| 32 | | /* device types */ |
| 33 | | enum |
| 34 | | { |
| 35 | | TYPE_MC6845 = 0, |
| 36 | | TYPE_MC6845_1, |
| 37 | | TYPE_C6545_1, |
| 38 | | TYPE_R6545_1, |
| 39 | | TYPE_H46505, |
| 40 | | TYPE_HD6845, |
| 41 | | TYPE_SY6545_1, |
| 42 | | TYPE_SY6845E, |
| 33 | const device_type MC6845 = &device_creator<mc6845_device>; |
| 34 | const device_type MC6845_1 = &device_creator<mc6845_1_device>; |
| 35 | const device_type R6545_1 = &device_creator<r6545_1_device>; |
| 36 | const device_type C6545_1 = &device_creator<c6545_1_device>; |
| 37 | const device_type H46505 = &device_creator<h46505_device>; |
| 38 | const device_type HD6845 = &device_creator<hd6845_device>; |
| 39 | const device_type SY6545_1 = &device_creator<sy6545_1_device>; |
| 40 | const device_type SY6845E = &device_creator<sy6845e_device>; |
| 43 | 41 | |
| 44 | | NUM_TYPES |
| 45 | | }; |
| 46 | 42 | |
| 47 | 43 | /* mode macros */ |
| 48 | | #define MODE_TRANSPARENT(d) (((d)->mode_control & 0x08) != 0) |
| 49 | | #define MODE_TRANSPARENT_PHI2(d) (((d)->mode_control & 0x88) == 0x88) |
| 44 | #define MODE_TRANSPARENT ((m_mode_control & 0x08) != 0) |
| 45 | #define MODE_TRANSPARENT_PHI2 ((m_mode_control & 0x88) == 0x88) |
| 50 | 46 | /* FIXME: not supported yet */ |
| 51 | | #define MODE_TRANSPARENT_BLANK(d) (((d)->mode_control & 0x88) == 0x08) |
| 52 | | #define MODE_UPDATE_STROBE(d) (((d)->mode_control & 0x40) != 0) |
| 53 | | #define MODE_CURSOR_SKEW(d) (((d)->mode_control & 0x20) != 0) |
| 54 | | #define MODE_DISPLAY_ENABLE_SKEW(d) (((d)->mode_control & 0x10) != 0) |
| 55 | | #define MODE_ROW_COLUMN_ADDRESSING(d) (((d)->mode_control & 0x04) != 0) |
| 47 | #define MODE_TRANSPARENT_BLANK ((m_mode_control & 0x88) == 0x08) |
| 48 | #define MODE_UPDATE_STROBE ((m_mode_control & 0x40) != 0) |
| 49 | #define MODE_CURSOR_SKEW ((m_mode_control & 0x20) != 0) |
| 50 | #define MODE_DISPLAY_ENABLE_SKEW ((m_mode_control & 0x10) != 0) |
| 51 | #define MODE_ROW_COLUMN_ADDRESSING ((m_mode_control & 0x04) != 0) |
| 56 | 52 | |
| 57 | | /* capabilities */ /* MC6845 MC6845-1 C6545-1 R6545-1 H46505 HD6845 SY6545-1 SY6845E */ |
| 58 | | static const int supports_disp_start_addr_r[NUM_TYPES] = { TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE }; |
| 59 | | static const int supports_vert_sync_width[NUM_TYPES] = { FALSE, TRUE, TRUE, TRUE, FALSE, TRUE, TRUE, TRUE }; |
| 60 | | static const int supports_status_reg_d5[NUM_TYPES] = { FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE }; |
| 61 | | static const int supports_status_reg_d6[NUM_TYPES] = { FALSE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, TRUE }; |
| 62 | 53 | |
| 63 | | /* FIXME: check other variants */ |
| 64 | | static const int supports_status_reg_d7[NUM_TYPES] = { FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE }; |
| 65 | | |
| 66 | | /* FIXME: check other variants */ |
| 67 | | static const int supports_transparent[NUM_TYPES] = { FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, TRUE, TRUE }; |
| 68 | | |
| 69 | | |
| 70 | | typedef struct _mc6845_t mc6845_t; |
| 71 | | struct _mc6845_t |
| 54 | void mc6845_device::device_config_complete() |
| 72 | 55 | { |
| 73 | | devcb_resolved_write_line out_de_func; |
| 74 | | devcb_resolved_write_line out_cur_func; |
| 75 | | devcb_resolved_write_line out_hsync_func; |
| 76 | | devcb_resolved_write_line out_vsync_func; |
| 56 | const mc6845_interface *intf = reinterpret_cast<const mc6845_interface *>(static_config()); |
| 77 | 57 | |
| 78 | | int device_type; |
| 79 | | const mc6845_interface *intf; |
| 80 | | screen_device *screen; |
| 58 | if ( intf != NULL ) |
| 59 | { |
| 60 | *static_cast<mc6845_interface *>(this) = *intf; |
| 61 | } |
| 62 | else |
| 63 | { |
| 64 | m_screen_tag = NULL; |
| 65 | m_hpixels_per_column = 0; |
| 66 | m_begin_update = NULL; |
| 67 | m_update_row = NULL; |
| 68 | m_end_update = NULL; |
| 69 | m_on_update_addr_changed = NULL; |
| 70 | memset(&m_out_de_func, 0, sizeof(m_out_de_func)); |
| 71 | memset(&m_out_cur_func, 0, sizeof(m_out_cur_func)); |
| 72 | memset(&m_out_hsync_func, 0, sizeof(m_out_hsync_func)); |
| 73 | memset(&m_out_vsync_func, 0, sizeof(m_out_vsync_func)); |
| 74 | } |
| 75 | } |
| 81 | 76 | |
| 82 | | /* register file */ |
| 83 | | UINT8 horiz_char_total; /* 0x00 */ |
| 84 | | UINT8 horiz_disp; /* 0x01 */ |
| 85 | | UINT8 horiz_sync_pos; /* 0x02 */ |
| 86 | | UINT8 sync_width; /* 0x03 */ |
| 87 | | UINT8 vert_char_total; /* 0x04 */ |
| 88 | | UINT8 vert_total_adj; /* 0x05 */ |
| 89 | | UINT8 vert_disp; /* 0x06 */ |
| 90 | | UINT8 vert_sync_pos; /* 0x07 */ |
| 91 | | UINT8 mode_control; /* 0x08 */ |
| 92 | | UINT8 max_ras_addr; /* 0x09 */ |
| 93 | | UINT8 cursor_start_ras; /* 0x0a */ |
| 94 | | UINT8 cursor_end_ras; /* 0x0b */ |
| 95 | | UINT16 disp_start_addr; /* 0x0c/0x0d */ |
| 96 | | UINT16 cursor_addr; /* 0x0e/0x0f */ |
| 97 | | UINT16 light_pen_addr; /* 0x10/0x11 */ |
| 98 | | UINT16 update_addr; /* 0x12/0x13 */ |
| 99 | 77 | |
| 100 | | /* other internal state */ |
| 101 | | UINT64 clock; |
| 102 | | UINT8 register_address_latch; |
| 103 | | UINT8 hpixels_per_column; |
| 104 | | UINT8 cursor_state; /* 0 = off, 1 = on */ |
| 105 | | UINT8 cursor_blink_count; |
| 106 | | UINT8 update_ready_bit; |
| 107 | | /* output signals */ |
| 108 | | int cur; |
| 109 | | int hsync; |
| 110 | | int vsync; |
| 111 | | int de; |
| 112 | | |
| 113 | | /* internal counters */ |
| 114 | | UINT8 character_counter; /* Not used yet */ |
| 115 | | UINT8 hsync_width_counter; /* Not used yet */ |
| 116 | | UINT8 line_counter; |
| 117 | | UINT8 raster_counter; |
| 118 | | UINT8 adjust_counter; |
| 119 | | UINT8 vsync_width_counter; |
| 120 | | |
| 121 | | UINT8 line_enable_ff; /* Internal flip flop which is set when the line_counter is reset and reset when vert_disp is reached */ |
| 122 | | UINT8 vsync_ff; |
| 123 | | UINT8 adjust_active; |
| 124 | | UINT16 line_address; |
| 125 | | INT16 cursor_x; |
| 126 | | |
| 127 | | /* timers */ |
| 128 | | emu_timer *line_timer; |
| 129 | | emu_timer *de_off_timer; |
| 130 | | emu_timer *cur_on_timer; |
| 131 | | emu_timer *cur_off_timer; |
| 132 | | emu_timer *hsync_on_timer; |
| 133 | | emu_timer *hsync_off_timer; |
| 134 | | emu_timer *light_pen_latch_timer; |
| 135 | | emu_timer *upd_adr_timer; |
| 136 | | |
| 137 | | /* computed values - do NOT state save these! */ |
| 138 | | /* These computed are used to define the screen parameters for a driver */ |
| 139 | | UINT16 horiz_pix_total; |
| 140 | | UINT16 vert_pix_total; |
| 141 | | UINT16 max_visible_x; |
| 142 | | UINT16 max_visible_y; |
| 143 | | UINT16 hsync_on_pos; |
| 144 | | UINT16 hsync_off_pos; |
| 145 | | UINT16 vsync_on_pos; |
| 146 | | UINT16 vsync_off_pos; |
| 147 | | int has_valid_parameters; |
| 148 | | |
| 149 | | UINT16 current_disp_addr; /* the display address currently drawn (used only in mc6845_update) */ |
| 150 | | |
| 151 | | UINT8 light_pen_latched; |
| 152 | | attotime upd_time; |
| 153 | | }; |
| 154 | | |
| 155 | | |
| 156 | | static void mc6845_state_save_postload(mc6845_t *mc6845); |
| 157 | | static void recompute_parameters(mc6845_t *mc6845, int postload); |
| 158 | | static void update_upd_adr_timer(mc6845_t *mc6845); |
| 159 | | static void update_cursor_state(mc6845_t *mc6845); |
| 160 | | |
| 161 | | |
| 162 | | const mc6845_interface mc6845_null_interface = { 0 }; |
| 163 | | |
| 164 | | |
| 165 | | /* makes sure that the passed in device is the right type */ |
| 166 | | INLINE mc6845_t *get_safe_token(device_t *device) |
| 78 | mc6845_device::mc6845_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) |
| 79 | : device_t(mconfig, type, name, tag, owner, clock) |
| 167 | 80 | { |
| 168 | | assert(device != NULL); |
| 169 | | assert((device->type() == MC6845) || |
| 170 | | (device->type() == MC6845_1) || |
| 171 | | (device->type() == C6545_1) || |
| 172 | | (device->type() == R6545_1) || |
| 173 | | (device->type() == H46505) || |
| 174 | | (device->type() == HD6845) || |
| 175 | | (device->type() == SY6545_1) || |
| 176 | | (device->type() == SY6845E)); |
| 177 | | |
| 178 | | return (mc6845_t *)downcast<legacy_device_base *>(device)->token(); |
| 179 | 81 | } |
| 180 | 82 | |
| 181 | | |
| 182 | | static void mc6845_state_save_postload(mc6845_t *mc6845) |
| 83 | mc6845_device::mc6845_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 84 | : device_t(mconfig, MC6845, "mc6845", tag, owner, clock) |
| 183 | 85 | { |
| 184 | | recompute_parameters(mc6845, TRUE); |
| 185 | 86 | } |
| 186 | 87 | |
| 187 | 88 | |
| 188 | | static TIMER_CALLBACK( on_update_address_cb ) |
| 89 | void mc6845_device::device_post_load() |
| 189 | 90 | { |
| 190 | | device_t *device = (device_t *)ptr; |
| 191 | | mc6845_t *mc6845 = get_safe_token(device); |
| 192 | | int addr = (param >> 8); |
| 193 | | int strobe = (param & 0xff); |
| 194 | | |
| 195 | | /* call the callback function -- we know it exists */ |
| 196 | | mc6845->intf->on_update_addr_changed(device, addr, strobe); |
| 197 | | |
| 198 | | if(!mc6845->update_ready_bit && MODE_TRANSPARENT_BLANK(mc6845)) |
| 199 | | { |
| 200 | | mc6845->update_addr++; |
| 201 | | mc6845->update_addr &= 0x3fff; |
| 202 | | mc6845->update_ready_bit = 1; |
| 203 | | } |
| 91 | recompute_parameters(true); |
| 204 | 92 | } |
| 205 | 93 | |
| 206 | | INLINE void call_on_update_address(device_t *device, int strobe) |
| 207 | | { |
| 208 | | mc6845_t *mc6845 = get_safe_token(device); |
| 209 | 94 | |
| 210 | | if (mc6845->intf->on_update_addr_changed) |
| 211 | | device->machine().scheduler().timer_set(attotime::zero, FUNC(on_update_address_cb), (mc6845->update_addr << 8) | strobe, (void *) device); |
| 95 | void mc6845_device::call_on_update_address(int strobe) |
| 96 | { |
| 97 | if (m_on_update_addr_changed) |
| 98 | m_upd_trans_timer->adjust(attotime::zero, (m_update_addr << 8) | strobe); |
| 212 | 99 | else |
| 213 | 100 | fatalerror("M6845: transparent memory mode without handler\n"); |
| 214 | 101 | } |
| 215 | 102 | |
| 216 | 103 | |
| 217 | | WRITE8_DEVICE_HANDLER( mc6845_address_w ) |
| 104 | void mc6845_device::address_w(UINT8 data) |
| 218 | 105 | { |
| 219 | | mc6845_t *mc6845 = get_safe_token(device); |
| 220 | | |
| 221 | | mc6845->register_address_latch = data & 0x1f; |
| 106 | m_register_address_latch = data & 0x1f; |
| 222 | 107 | } |
| 223 | 108 | |
| 224 | 109 | |
| 225 | | READ8_DEVICE_HANDLER( mc6845_status_r ) |
| 110 | UINT8 mc6845_device::status_r() |
| 226 | 111 | { |
| 227 | | mc6845_t *mc6845 = get_safe_token(device); |
| 228 | 112 | UINT8 ret = 0; |
| 229 | 113 | |
| 230 | 114 | /* VBLANK bit */ |
| 231 | | if (supports_status_reg_d5[mc6845->device_type] && ( mc6845->line_enable_ff == 0 )) |
| 115 | if (m_supports_status_reg_d5 && !m_line_enable_ff) |
| 232 | 116 | ret = ret | 0x20; |
| 233 | 117 | |
| 234 | 118 | /* light pen latched */ |
| 235 | | if (supports_status_reg_d6[mc6845->device_type] && mc6845->light_pen_latched) |
| 119 | if (m_supports_status_reg_d6 && m_light_pen_latched) |
| 236 | 120 | ret = ret | 0x40; |
| 237 | 121 | |
| 238 | 122 | /* UPDATE ready */ |
| 239 | | if (supports_status_reg_d7[mc6845->device_type] && mc6845->update_ready_bit) |
| 123 | if (m_supports_status_reg_d7 && m_update_ready_bit) |
| 240 | 124 | ret = ret | 0x80; |
| 241 | 125 | |
| 242 | 126 | return ret; |
| 243 | 127 | } |
| 244 | 128 | |
| 245 | 129 | |
| 246 | | READ8_DEVICE_HANDLER( mc6845_register_r ) |
| 130 | UINT8 mc6845_device::register_r() |
| 247 | 131 | { |
| 248 | | mc6845_t *mc6845 = get_safe_token(device); |
| 249 | 132 | UINT8 ret = 0; |
| 250 | 133 | |
| 251 | | switch (mc6845->register_address_latch) |
| 134 | switch (m_register_address_latch) |
| 252 | 135 | { |
| 253 | | case 0x0c: ret = supports_disp_start_addr_r[mc6845->device_type] ? (mc6845->disp_start_addr >> 8) & 0xff : 0; break; |
| 254 | | case 0x0d: ret = supports_disp_start_addr_r[mc6845->device_type] ? (mc6845->disp_start_addr >> 0) & 0xff : 0; break; |
| 255 | | case 0x0e: ret = (mc6845->cursor_addr >> 8) & 0xff; break; |
| 256 | | case 0x0f: ret = (mc6845->cursor_addr >> 0) & 0xff; break; |
| 257 | | case 0x10: ret = (mc6845->light_pen_addr >> 8) & 0xff; mc6845->light_pen_latched = FALSE; break; |
| 258 | | case 0x11: ret = (mc6845->light_pen_addr >> 0) & 0xff; mc6845->light_pen_latched = FALSE; break; |
| 136 | case 0x0c: ret = m_supports_disp_start_addr_r ? (m_disp_start_addr >> 8) & 0xff : 0; break; |
| 137 | case 0x0d: ret = m_supports_disp_start_addr_r ? (m_disp_start_addr >> 0) & 0xff : 0; break; |
| 138 | case 0x0e: ret = (m_cursor_addr >> 8) & 0xff; break; |
| 139 | case 0x0f: ret = (m_cursor_addr >> 0) & 0xff; break; |
| 140 | case 0x10: ret = (m_light_pen_addr >> 8) & 0xff; m_light_pen_latched = false; break; |
| 141 | case 0x11: ret = (m_light_pen_addr >> 0) & 0xff; m_light_pen_latched = false; break; |
| 259 | 142 | case 0x1f: |
| 260 | | if (supports_transparent[mc6845->device_type] && MODE_TRANSPARENT(mc6845)) |
| 143 | if (m_supports_transparent && MODE_TRANSPARENT) |
| 261 | 144 | { |
| 262 | | if(MODE_TRANSPARENT_PHI2(mc6845)) |
| 145 | if(MODE_TRANSPARENT_PHI2) |
| 263 | 146 | { |
| 264 | | mc6845->update_addr++; |
| 265 | | mc6845->update_addr &= 0x3fff; |
| 266 | | call_on_update_address(device, 0); |
| 147 | m_update_addr++; |
| 148 | m_update_addr &= 0x3fff; |
| 149 | call_on_update_address(0); |
| 267 | 150 | } |
| 268 | 151 | else |
| 269 | 152 | { |
| 270 | 153 | /* MODE_TRANSPARENT_BLANK */ |
| 271 | | if(mc6845->update_ready_bit) |
| 154 | if(m_update_ready_bit) |
| 272 | 155 | { |
| 273 | | mc6845->update_ready_bit = 0; |
| 274 | | update_upd_adr_timer(mc6845); |
| 156 | m_update_ready_bit = false; |
| 157 | update_upd_adr_timer(); |
| 275 | 158 | } |
| 276 | 159 | } |
| 277 | 160 | } |
| r11542 | r11543 | |
| 285 | 168 | } |
| 286 | 169 | |
| 287 | 170 | |
| 288 | | WRITE8_DEVICE_HANDLER( mc6845_register_w ) |
| 171 | void mc6845_device::register_w(UINT8 data) |
| 289 | 172 | { |
| 290 | | mc6845_t *mc6845 = get_safe_token(device); |
| 173 | if (LOG) logerror("%s:M6845 reg 0x%02x = 0x%02x\n", machine().describe_context(), m_register_address_latch, data); |
| 291 | 174 | |
| 292 | | if (LOG) logerror("%s:M6845 reg 0x%02x = 0x%02x\n", device->machine().describe_context(), mc6845->register_address_latch, data); |
| 293 | | |
| 294 | | switch (mc6845->register_address_latch) |
| 175 | switch (m_register_address_latch) |
| 295 | 176 | { |
| 296 | | case 0x00: mc6845->horiz_char_total = data & 0xff; break; |
| 297 | | case 0x01: mc6845->horiz_disp = data & 0xff; break; |
| 298 | | case 0x02: mc6845->horiz_sync_pos = data & 0xff; break; |
| 299 | | case 0x03: mc6845->sync_width = data & 0xff; break; |
| 300 | | case 0x04: mc6845->vert_char_total = data & 0x7f; break; |
| 301 | | case 0x05: mc6845->vert_total_adj = data & 0x1f; break; |
| 302 | | case 0x06: mc6845->vert_disp = data & 0x7f; break; |
| 303 | | case 0x07: mc6845->vert_sync_pos = data & 0x7f; break; |
| 304 | | case 0x08: mc6845->mode_control = data & 0xff; break; |
| 305 | | case 0x09: mc6845->max_ras_addr = data & 0x1f; break; |
| 306 | | case 0x0a: mc6845->cursor_start_ras = data & 0x7f; break; |
| 307 | | case 0x0b: mc6845->cursor_end_ras = data & 0x1f; break; |
| 308 | | case 0x0c: mc6845->disp_start_addr = ((data & 0x3f) << 8) | (mc6845->disp_start_addr & 0x00ff); break; |
| 309 | | case 0x0d: mc6845->disp_start_addr = ((data & 0xff) << 0) | (mc6845->disp_start_addr & 0xff00); break; |
| 310 | | case 0x0e: mc6845->cursor_addr = ((data & 0x3f) << 8) | (mc6845->cursor_addr & 0x00ff); break; |
| 311 | | case 0x0f: mc6845->cursor_addr = ((data & 0xff) << 0) | (mc6845->cursor_addr & 0xff00); break; |
| 177 | case 0x00: m_horiz_char_total = data & 0xff; break; |
| 178 | case 0x01: m_horiz_disp = data & 0xff; break; |
| 179 | case 0x02: m_horiz_sync_pos = data & 0xff; break; |
| 180 | case 0x03: m_sync_width = data & 0xff; break; |
| 181 | case 0x04: m_vert_char_total = data & 0x7f; break; |
| 182 | case 0x05: m_vert_total_adj = data & 0x1f; break; |
| 183 | case 0x06: m_vert_disp = data & 0x7f; break; |
| 184 | case 0x07: m_vert_sync_pos = data & 0x7f; break; |
| 185 | case 0x08: m_mode_control = data & 0xff; break; |
| 186 | case 0x09: m_max_ras_addr = data & 0x1f; break; |
| 187 | case 0x0a: m_cursor_start_ras = data & 0x7f; break; |
| 188 | case 0x0b: m_cursor_end_ras = data & 0x1f; break; |
| 189 | case 0x0c: m_disp_start_addr = ((data & 0x3f) << 8) | (m_disp_start_addr & 0x00ff); break; |
| 190 | case 0x0d: m_disp_start_addr = ((data & 0xff) << 0) | (m_disp_start_addr & 0xff00); break; |
| 191 | case 0x0e: m_cursor_addr = ((data & 0x3f) << 8) | (m_cursor_addr & 0x00ff); break; |
| 192 | case 0x0f: m_cursor_addr = ((data & 0xff) << 0) | (m_cursor_addr & 0xff00); break; |
| 312 | 193 | case 0x10: /* read-only */ break; |
| 313 | 194 | case 0x11: /* read-only */ break; |
| 314 | 195 | case 0x12: |
| 315 | | if (supports_transparent[mc6845->device_type]) |
| 196 | if (m_supports_transparent) |
| 316 | 197 | { |
| 317 | | mc6845->update_addr = ((data & 0x3f) << 8) | (mc6845->update_addr & 0x00ff); |
| 318 | | if(MODE_TRANSPARENT_PHI2(mc6845)) |
| 319 | | call_on_update_address(device, 0); |
| 198 | m_update_addr = ((data & 0x3f) << 8) | (m_update_addr & 0x00ff); |
| 199 | if(MODE_TRANSPARENT_PHI2) |
| 200 | call_on_update_address(0); |
| 320 | 201 | } |
| 321 | 202 | break; |
| 322 | 203 | case 0x13: |
| 323 | | if (supports_transparent[mc6845->device_type]) |
| 204 | if (m_supports_transparent) |
| 324 | 205 | { |
| 325 | | mc6845->update_addr = ((data & 0xff) << 0) | (mc6845->update_addr & 0xff00); |
| 326 | | if(MODE_TRANSPARENT_PHI2(mc6845)) |
| 327 | | call_on_update_address(device, 0); |
| 206 | m_update_addr = ((data & 0xff) << 0) | (m_update_addr & 0xff00); |
| 207 | if(MODE_TRANSPARENT_PHI2) |
| 208 | call_on_update_address(0); |
| 328 | 209 | } |
| 329 | 210 | break; |
| 330 | 211 | case 0x1f: |
| 331 | | if (supports_transparent[mc6845->device_type] && MODE_TRANSPARENT(mc6845)) |
| 212 | if (m_supports_transparent && MODE_TRANSPARENT) |
| 332 | 213 | { |
| 333 | | if(MODE_TRANSPARENT_PHI2(mc6845)) |
| 214 | if(MODE_TRANSPARENT_PHI2) |
| 334 | 215 | { |
| 335 | | mc6845->update_addr++; |
| 336 | | mc6845->update_addr &= 0x3fff; |
| 337 | | call_on_update_address(device, 0); |
| 216 | m_update_addr++; |
| 217 | m_update_addr &= 0x3fff; |
| 218 | call_on_update_address(0); |
| 338 | 219 | } |
| 339 | 220 | else |
| 340 | 221 | { |
| 341 | 222 | /* MODE_TRANSPARENT_BLANK */ |
| 342 | | if(mc6845->update_ready_bit) |
| 223 | if(m_update_ready_bit) |
| 343 | 224 | { |
| 344 | | mc6845->update_ready_bit = 0; |
| 345 | | update_upd_adr_timer(mc6845); |
| 225 | m_update_ready_bit = false; |
| 226 | update_upd_adr_timer(); |
| 346 | 227 | } |
| 347 | 228 | } |
| 348 | 229 | } |
| r11542 | r11543 | |
| 351 | 232 | } |
| 352 | 233 | |
| 353 | 234 | /* display message if the Mode Control register is not zero */ |
| 354 | | if ((mc6845->register_address_latch == 0x08) && (mc6845->mode_control != 0)) |
| 355 | | if (!supports_transparent[mc6845->device_type]) |
| 356 | | popmessage("Mode Control %02X is not supported!!!", mc6845->mode_control); |
| 235 | if ((m_register_address_latch == 0x08) && (m_mode_control != 0)) |
| 236 | if (!m_supports_transparent) |
| 237 | popmessage("Mode Control %02X is not supported!!!", m_mode_control); |
| 357 | 238 | |
| 358 | | recompute_parameters(mc6845, FALSE); |
| 239 | recompute_parameters(false); |
| 359 | 240 | } |
| 360 | 241 | |
| 361 | 242 | |
| 362 | | static void recompute_parameters(mc6845_t *mc6845, int postload) |
| 243 | void mc6845_device::recompute_parameters(bool postload) |
| 363 | 244 | { |
| 364 | | if (mc6845->intf != NULL) |
| 365 | | { |
| 366 | | UINT16 hsync_on_pos, hsync_off_pos, vsync_on_pos, vsync_off_pos; |
| 245 | UINT16 hsync_on_pos, hsync_off_pos, vsync_on_pos, vsync_off_pos; |
| 367 | 246 | |
| 368 | | /* compute the screen sizes */ |
| 369 | | UINT16 horiz_pix_total = (mc6845->horiz_char_total + 1) * mc6845->hpixels_per_column; |
| 370 | | UINT16 vert_pix_total = (mc6845->vert_char_total + 1) * (mc6845->max_ras_addr + 1) + mc6845->vert_total_adj; |
| 247 | /* compute the screen sizes */ |
| 248 | UINT16 horiz_pix_total = (m_horiz_char_total + 1) * m_hpixels_per_column; |
| 249 | UINT16 vert_pix_total = (m_vert_char_total + 1) * (m_max_ras_addr + 1) + m_vert_total_adj; |
| 371 | 250 | |
| 372 | | /* determine the visible area, avoid division by 0 */ |
| 373 | | UINT16 max_visible_x = mc6845->horiz_disp * mc6845->hpixels_per_column - 1; |
| 374 | | UINT16 max_visible_y = mc6845->vert_disp * (mc6845->max_ras_addr + 1) - 1; |
| 251 | /* determine the visible area, avoid division by 0 */ |
| 252 | UINT16 max_visible_x = m_horiz_disp * m_hpixels_per_column - 1; |
| 253 | UINT16 max_visible_y = m_vert_disp * (m_max_ras_addr + 1) - 1; |
| 375 | 254 | |
| 376 | | /* determine the syncing positions */ |
| 377 | | UINT8 horiz_sync_char_width = mc6845->sync_width & 0x0f; |
| 378 | | UINT8 vert_sync_pix_width = supports_vert_sync_width[mc6845->device_type] ? (mc6845->sync_width >> 4) & 0x0f : 0x10; |
| 255 | /* determine the syncing positions */ |
| 256 | UINT8 horiz_sync_char_width = m_sync_width & 0x0f; |
| 257 | UINT8 vert_sync_pix_width = m_supports_vert_sync_width ? (m_sync_width >> 4) & 0x0f : 0x10; |
| 379 | 258 | |
| 380 | | if (horiz_sync_char_width == 0) |
| 381 | | horiz_sync_char_width = 0x10; |
| 259 | if (horiz_sync_char_width == 0) |
| 260 | horiz_sync_char_width = 0x10; |
| 382 | 261 | |
| 383 | | if (vert_sync_pix_width == 0) |
| 384 | | vert_sync_pix_width = 0x10; |
| 262 | if (vert_sync_pix_width == 0) |
| 263 | vert_sync_pix_width = 0x10; |
| 385 | 264 | |
| 386 | | /* determine the transparent update cycle time, 1 update every 4 character clocks */ |
| 387 | | mc6845->upd_time = attotime::from_hz(mc6845->clock) * (4 * mc6845->hpixels_per_column); |
| 265 | /* determine the transparent update cycle time, 1 update every 4 character clocks */ |
| 266 | m_upd_time = attotime::from_hz(m_clock) * (4 * m_hpixels_per_column); |
| 388 | 267 | |
| 389 | | hsync_on_pos = mc6845->horiz_sync_pos * mc6845->hpixels_per_column; |
| 390 | | hsync_off_pos = hsync_on_pos + (horiz_sync_char_width * mc6845->hpixels_per_column); |
| 391 | | vsync_on_pos = mc6845->vert_sync_pos * (mc6845->max_ras_addr + 1); |
| 392 | | vsync_off_pos = vsync_on_pos + vert_sync_pix_width; |
| 268 | hsync_on_pos = m_horiz_sync_pos * m_hpixels_per_column; |
| 269 | hsync_off_pos = hsync_on_pos + (horiz_sync_char_width * m_hpixels_per_column); |
| 270 | vsync_on_pos = m_vert_sync_pos * (m_max_ras_addr + 1); |
| 271 | vsync_off_pos = vsync_on_pos + vert_sync_pix_width; |
| 393 | 272 | |
| 394 | | /* the Commodore PET computers program a horizontal synch pulse that extends |
| 395 | | past the scanline width. I assume that the real device will clamp it */ |
| 396 | | if (hsync_off_pos > horiz_pix_total) |
| 397 | | hsync_off_pos = horiz_pix_total; |
| 273 | /* the Commodore PET computers program a horizontal synch pulse that extends |
| 274 | past the scanline width. I assume that the real device will clamp it */ |
| 275 | if (hsync_off_pos > horiz_pix_total) |
| 276 | hsync_off_pos = horiz_pix_total; |
| 398 | 277 | |
| 399 | | if (vsync_off_pos > vert_pix_total) |
| 400 | | vsync_off_pos = vert_pix_total; |
| 278 | if (vsync_off_pos > vert_pix_total) |
| 279 | vsync_off_pos = vert_pix_total; |
| 401 | 280 | |
| 402 | | /* update only if screen parameters changed, unless we are coming here after loading the saved state */ |
| 403 | | if (postload || |
| 404 | | (horiz_pix_total != mc6845->horiz_pix_total) || (vert_pix_total != mc6845->vert_pix_total) || |
| 405 | | (max_visible_x != mc6845->max_visible_x) || (max_visible_y != mc6845->max_visible_y) || |
| 406 | | (hsync_on_pos != mc6845->hsync_on_pos) || (vsync_on_pos != mc6845->vsync_on_pos) || |
| 407 | | (hsync_off_pos != mc6845->hsync_off_pos) || (vsync_off_pos != mc6845->vsync_off_pos)) |
| 281 | /* update only if screen parameters changed, unless we are coming here after loading the saved state */ |
| 282 | if (postload || |
| 283 | (horiz_pix_total != m_horiz_pix_total) || (vert_pix_total != m_vert_pix_total) || |
| 284 | (max_visible_x != m_max_visible_x) || (max_visible_y != m_max_visible_y) || |
| 285 | (hsync_on_pos != m_hsync_on_pos) || (vsync_on_pos != m_vsync_on_pos) || |
| 286 | (hsync_off_pos != m_hsync_off_pos) || (vsync_off_pos != m_vsync_off_pos)) |
| 287 | { |
| 288 | /* update the screen if we have valid data */ |
| 289 | if ((horiz_pix_total > 0) && (max_visible_x < horiz_pix_total) && |
| 290 | (vert_pix_total > 0) && (max_visible_y < vert_pix_total) && |
| 291 | (hsync_on_pos <= horiz_pix_total) && (vsync_on_pos <= vert_pix_total) && |
| 292 | (hsync_on_pos != hsync_off_pos)) |
| 408 | 293 | { |
| 409 | | /* update the screen if we have valid data */ |
| 410 | | if ((horiz_pix_total > 0) && (max_visible_x < horiz_pix_total) && |
| 411 | | (vert_pix_total > 0) && (max_visible_y < vert_pix_total) && |
| 412 | | (hsync_on_pos <= horiz_pix_total) && (vsync_on_pos <= vert_pix_total) && |
| 413 | | (hsync_on_pos != hsync_off_pos)) |
| 414 | | { |
| 415 | | rectangle visarea; |
| 294 | rectangle visarea; |
| 416 | 295 | |
| 417 | | attoseconds_t refresh = HZ_TO_ATTOSECONDS(mc6845->clock) * (mc6845->horiz_char_total + 1) * vert_pix_total; |
| 296 | attoseconds_t refresh = HZ_TO_ATTOSECONDS(m_clock) * (m_horiz_char_total + 1) * vert_pix_total; |
| 418 | 297 | |
| 419 | | visarea.min_x = 0; |
| 420 | | visarea.min_y = 0; |
| 421 | | visarea.max_x = max_visible_x; |
| 422 | | visarea.max_y = max_visible_y; |
| 298 | visarea.min_x = 0; |
| 299 | visarea.min_y = 0; |
| 300 | visarea.max_x = max_visible_x; |
| 301 | visarea.max_y = max_visible_y; |
| 423 | 302 | |
| 424 | | if (LOG) logerror("M6845 config screen: HTOTAL: 0x%x VTOTAL: 0x%x MAX_X: 0x%x MAX_Y: 0x%x HSYNC: 0x%x-0x%x VSYNC: 0x%x-0x%x Freq: %ffps\n", |
| 425 | | horiz_pix_total, vert_pix_total, max_visible_x, max_visible_y, hsync_on_pos, hsync_off_pos - 1, vsync_on_pos, vsync_off_pos - 1, 1 / ATTOSECONDS_TO_DOUBLE(refresh)); |
| 303 | if (LOG) logerror("M6845 config screen: HTOTAL: 0x%x VTOTAL: 0x%x MAX_X: 0x%x MAX_Y: 0x%x HSYNC: 0x%x-0x%x VSYNC: 0x%x-0x%x Freq: %ffps\n", |
| 304 | horiz_pix_total, vert_pix_total, max_visible_x, max_visible_y, hsync_on_pos, hsync_off_pos - 1, vsync_on_pos, vsync_off_pos - 1, 1 / ATTOSECONDS_TO_DOUBLE(refresh)); |
| 426 | 305 | |
| 427 | | if ( mc6845->screen != NULL ) |
| 428 | | mc6845->screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh); |
| 306 | if ( m_screen != NULL ) |
| 307 | m_screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh); |
| 429 | 308 | |
| 430 | | mc6845->has_valid_parameters = TRUE; |
| 431 | | } |
| 432 | | else |
| 433 | | mc6845->has_valid_parameters = FALSE; |
| 434 | | |
| 435 | | mc6845->horiz_pix_total = horiz_pix_total; |
| 436 | | mc6845->vert_pix_total = vert_pix_total; |
| 437 | | mc6845->max_visible_x = max_visible_x; |
| 438 | | mc6845->max_visible_y = max_visible_y; |
| 439 | | mc6845->hsync_on_pos = hsync_on_pos; |
| 440 | | mc6845->hsync_off_pos = hsync_off_pos; |
| 441 | | mc6845->vsync_on_pos = vsync_on_pos; |
| 442 | | mc6845->vsync_off_pos = vsync_off_pos; |
| 309 | m_has_valid_parameters = true; |
| 443 | 310 | } |
| 311 | else |
| 312 | m_has_valid_parameters = false; |
| 313 | |
| 314 | m_horiz_pix_total = horiz_pix_total; |
| 315 | m_vert_pix_total = vert_pix_total; |
| 316 | m_max_visible_x = max_visible_x; |
| 317 | m_max_visible_y = max_visible_y; |
| 318 | m_hsync_on_pos = hsync_on_pos; |
| 319 | m_hsync_off_pos = hsync_off_pos; |
| 320 | m_vsync_on_pos = vsync_on_pos; |
| 321 | m_vsync_off_pos = vsync_off_pos; |
| 444 | 322 | } |
| 445 | 323 | } |
| 446 | 324 | |
| 447 | 325 | |
| 448 | | INLINE void mc6845_update_counters(mc6845_t *mc6845) |
| 326 | void mc6845_device::update_counters() |
| 449 | 327 | { |
| 450 | | mc6845->character_counter = mc6845->line_timer ->elapsed( ).as_ticks( mc6845->clock ); |
| 328 | m_character_counter = m_line_timer->elapsed( ).as_ticks( m_clock ); |
| 451 | 329 | |
| 452 | | if ( mc6845->hsync_off_timer ->enabled( ) ) |
| 330 | if ( m_hsync_off_timer ->enabled( ) ) |
| 453 | 331 | { |
| 454 | | mc6845->hsync_width_counter = mc6845->hsync_off_timer ->elapsed( ).as_ticks( mc6845->clock ); |
| 332 | m_hsync_width_counter = m_hsync_off_timer ->elapsed( ).as_ticks( m_clock ); |
| 455 | 333 | } |
| 456 | 334 | } |
| 457 | 335 | |
| 458 | 336 | |
| 459 | | INLINE void mc6845_set_de(mc6845_t *mc6845, int state) |
| 337 | void mc6845_device::set_de(int state) |
| 460 | 338 | { |
| 461 | | if ( mc6845->de != state ) |
| 339 | if ( m_de != state ) |
| 462 | 340 | { |
| 463 | | mc6845->de = state; |
| 341 | m_de = state; |
| 464 | 342 | |
| 465 | | if ( mc6845->de ) |
| 343 | if ( m_de ) |
| 466 | 344 | { |
| 467 | 345 | /* If the upd_adr_timer was running, cancel it */ |
| 468 | | mc6845->upd_adr_timer->adjust(attotime::never); |
| 346 | m_upd_adr_timer->adjust(attotime::never); |
| 469 | 347 | } |
| 470 | 348 | else |
| 471 | 349 | { |
| 472 | 350 | /* if transparent update was requested fire the update timer */ |
| 473 | | if(!mc6845->update_ready_bit) |
| 474 | | update_upd_adr_timer(mc6845); |
| 351 | if(!m_update_ready_bit) |
| 352 | update_upd_adr_timer(); |
| 475 | 353 | } |
| 476 | 354 | |
| 477 | | if ( !mc6845->out_de_func.isnull() ) |
| 478 | | mc6845->out_de_func(mc6845->de ); |
| 355 | if ( !m_res_out_de_func.isnull() ) |
| 356 | m_res_out_de_func( m_de ); |
| 479 | 357 | } |
| 480 | 358 | } |
| 481 | 359 | |
| 482 | 360 | |
| 483 | | INLINE void mc6845_set_hsync(mc6845_t *mc6845, int state) |
| 361 | void mc6845_device::set_hsync(int state) |
| 484 | 362 | { |
| 485 | | if ( mc6845->hsync != state ) |
| 363 | if ( m_hsync != state ) |
| 486 | 364 | { |
| 487 | | mc6845->hsync = state; |
| 365 | m_hsync = state; |
| 488 | 366 | |
| 489 | | if ( !mc6845->out_hsync_func.isnull() ) |
| 490 | | mc6845->out_hsync_func(mc6845->hsync ); |
| 367 | if ( !m_res_out_hsync_func.isnull() ) |
| 368 | m_res_out_hsync_func( m_hsync ); |
| 491 | 369 | } |
| 492 | 370 | } |
| 493 | 371 | |
| 494 | 372 | |
| 495 | | INLINE void mc6845_set_vsync(mc6845_t *mc6845, int state) |
| 373 | void mc6845_device::set_vsync(int state) |
| 496 | 374 | { |
| 497 | | if ( mc6845->vsync != state ) |
| 375 | if ( m_vsync != state ) |
| 498 | 376 | { |
| 499 | | mc6845->vsync = state; |
| 377 | m_vsync = state; |
| 500 | 378 | |
| 501 | | if ( !mc6845->out_vsync_func.isnull() ) |
| 502 | | mc6845->out_vsync_func(mc6845->vsync ); |
| 379 | if ( !m_res_out_vsync_func.isnull() ) |
| 380 | m_res_out_vsync_func( m_vsync ); |
| 503 | 381 | } |
| 504 | 382 | } |
| 505 | 383 | |
| 506 | 384 | |
| 507 | | INLINE void mc6845_set_cur(mc6845_t *mc6845, int state) |
| 385 | void mc6845_device::set_cur(int state) |
| 508 | 386 | { |
| 509 | | if ( mc6845->cur != state ) |
| 387 | if ( m_cur != state ) |
| 510 | 388 | { |
| 511 | | mc6845->cur = state; |
| 389 | m_cur = state; |
| 512 | 390 | |
| 513 | | if ( !mc6845->out_cur_func.isnull() ) |
| 514 | | mc6845->out_cur_func(mc6845->cur ); |
| 391 | if ( !m_res_out_cur_func.isnull() ) |
| 392 | m_res_out_cur_func( m_cur ); |
| 515 | 393 | } |
| 516 | 394 | } |
| 517 | 395 | |
| 518 | 396 | |
| 519 | | static void update_upd_adr_timer(mc6845_t *mc6845) |
| 397 | void mc6845_device::update_upd_adr_timer() |
| 520 | 398 | { |
| 521 | | if (! mc6845->de && supports_transparent[mc6845->device_type]) |
| 522 | | mc6845->upd_adr_timer->adjust(mc6845->upd_time); |
| 399 | if (! m_de && m_supports_transparent) |
| 400 | m_upd_adr_timer->adjust(m_upd_time); |
| 523 | 401 | } |
| 524 | 402 | |
| 525 | 403 | |
| 526 | | static TIMER_CALLBACK( upd_adr_timer_cb ) |
| 404 | void mc6845_device::handle_line_timer() |
| 527 | 405 | { |
| 528 | | device_t *device = (device_t *)ptr; |
| 406 | int new_vsync = m_vsync; |
| 529 | 407 | |
| 530 | | /* fire a update address strobe */ |
| 531 | | call_on_update_address(device, 0); |
| 532 | | } |
| 408 | m_character_counter = 0; |
| 409 | m_cursor_x = -1; |
| 533 | 410 | |
| 534 | | |
| 535 | | static TIMER_CALLBACK( de_off_timer_cb ) |
| 536 | | { |
| 537 | | device_t *device = (device_t *)ptr; |
| 538 | | mc6845_t *mc6845 = get_safe_token(device); |
| 539 | | |
| 540 | | mc6845_set_de( mc6845, FALSE ); |
| 541 | | } |
| 542 | | |
| 543 | | |
| 544 | | static TIMER_CALLBACK( cur_on_timer_cb ) |
| 545 | | { |
| 546 | | device_t *device = (device_t *)ptr; |
| 547 | | mc6845_t *mc6845 = get_safe_token(device); |
| 548 | | |
| 549 | | mc6845_set_cur( mc6845, TRUE ); |
| 550 | | |
| 551 | | /* Schedule CURSOR off signal */ |
| 552 | | mc6845->cur_off_timer->adjust( attotime::from_ticks( 1, mc6845->clock ) ); |
| 553 | | } |
| 554 | | |
| 555 | | |
| 556 | | static TIMER_CALLBACK( cur_off_timer_cb ) |
| 557 | | { |
| 558 | | device_t *device = (device_t *)ptr; |
| 559 | | mc6845_t *mc6845 = get_safe_token(device); |
| 560 | | |
| 561 | | mc6845_set_cur( mc6845, FALSE ); |
| 562 | | } |
| 563 | | |
| 564 | | |
| 565 | | static TIMER_CALLBACK( hsync_on_timer_cb ) |
| 566 | | { |
| 567 | | device_t *device = (device_t *)ptr; |
| 568 | | mc6845_t *mc6845 = get_safe_token(device); |
| 569 | | UINT8 hsync_width = ( mc6845->sync_width & 0x0f ) ? ( mc6845->sync_width & 0x0f ) : 0x10; |
| 570 | | |
| 571 | | mc6845->hsync_width_counter = 0; |
| 572 | | mc6845_set_hsync( mc6845, TRUE ); |
| 573 | | |
| 574 | | /* Schedule HSYNC off signal */ |
| 575 | | mc6845->hsync_off_timer->adjust( attotime::from_ticks( hsync_width, mc6845->clock ) ); |
| 576 | | } |
| 577 | | |
| 578 | | |
| 579 | | static TIMER_CALLBACK( hsync_off_timer_cb ) |
| 580 | | { |
| 581 | | device_t *device = (device_t *)ptr; |
| 582 | | mc6845_t *mc6845 = get_safe_token(device); |
| 583 | | |
| 584 | | mc6845_set_hsync( mc6845, FALSE ); |
| 585 | | } |
| 586 | | |
| 587 | | |
| 588 | | static TIMER_CALLBACK( line_timer_cb ) |
| 589 | | { |
| 590 | | device_t *device = (device_t *)ptr; |
| 591 | | mc6845_t *mc6845 = get_safe_token(device); |
| 592 | | int new_vsync = mc6845->vsync; |
| 593 | | |
| 594 | | mc6845->character_counter = 0; |
| 595 | | mc6845->cursor_x = -1; |
| 596 | | |
| 597 | 411 | /* Check if VSYNC is active */ |
| 598 | | if ( mc6845->vsync_ff ) |
| 412 | if ( m_vsync_ff ) |
| 599 | 413 | { |
| 600 | | UINT8 vsync_width = supports_vert_sync_width[mc6845->device_type] ? (mc6845->sync_width >> 4) & 0x0f : 0; |
| 414 | UINT8 vsync_width = m_supports_vert_sync_width ? (m_sync_width >> 4) & 0x0f : 0; |
| 601 | 415 | |
| 602 | | mc6845->vsync_width_counter = ( mc6845->vsync_width_counter + 1 ) & 0x0F; |
| 416 | m_vsync_width_counter = ( m_vsync_width_counter + 1 ) & 0x0F; |
| 603 | 417 | |
| 604 | 418 | /* Check if we've reached end of VSYNC */ |
| 605 | | if ( mc6845->vsync_width_counter == vsync_width ) |
| 419 | if ( m_vsync_width_counter == vsync_width ) |
| 606 | 420 | { |
| 607 | | mc6845->vsync_ff = 0; |
| 421 | m_vsync_ff = 0; |
| 608 | 422 | |
| 609 | 423 | new_vsync = FALSE; |
| 610 | 424 | } |
| 611 | 425 | } |
| 612 | 426 | |
| 613 | | if ( mc6845->raster_counter == mc6845->max_ras_addr ) |
| 427 | if ( m_raster_counter == m_max_ras_addr ) |
| 614 | 428 | { |
| 615 | 429 | /* Check if we have reached the end of the vertical area */ |
| 616 | | if ( mc6845->line_counter == mc6845->vert_char_total ) |
| 430 | if ( m_line_counter == m_vert_char_total ) |
| 617 | 431 | { |
| 618 | | mc6845->adjust_counter = 0; |
| 619 | | mc6845->adjust_active = 1; |
| 432 | m_adjust_counter = 0; |
| 433 | m_adjust_active = 1; |
| 620 | 434 | } |
| 621 | 435 | |
| 622 | | mc6845->raster_counter = 0; |
| 623 | | mc6845->line_counter = ( mc6845->line_counter + 1 ) & 0x7F; |
| 624 | | mc6845->line_address = ( mc6845->line_address + mc6845->horiz_disp ) & 0x3fff; |
| 436 | m_raster_counter = 0; |
| 437 | m_line_counter = ( m_line_counter + 1 ) & 0x7F; |
| 438 | m_line_address = ( m_line_address + m_horiz_disp ) & 0x3fff; |
| 625 | 439 | |
| 626 | 440 | /* Check if we've reached the end of active display */ |
| 627 | | if ( mc6845->line_counter == mc6845->vert_disp ) |
| 441 | if ( m_line_counter == m_vert_disp ) |
| 628 | 442 | { |
| 629 | | mc6845->line_enable_ff = 0; |
| 443 | m_line_enable_ff = false; |
| 630 | 444 | } |
| 631 | 445 | |
| 632 | 446 | /* Check if VSYNC should be enabled */ |
| 633 | | if ( mc6845->line_counter == mc6845->vert_sync_pos ) |
| 447 | if ( m_line_counter == m_vert_sync_pos ) |
| 634 | 448 | { |
| 635 | | mc6845->vsync_width_counter = 0; |
| 636 | | mc6845->vsync_ff = 1; |
| 449 | m_vsync_width_counter = 0; |
| 450 | m_vsync_ff = 1; |
| 637 | 451 | |
| 638 | 452 | new_vsync = TRUE; |
| 639 | 453 | } |
| 640 | 454 | } |
| 641 | 455 | else |
| 642 | 456 | { |
| 643 | | mc6845->raster_counter = ( mc6845->raster_counter + 1 ) & 0x1F; |
| 457 | m_raster_counter = ( m_raster_counter + 1 ) & 0x1F; |
| 644 | 458 | } |
| 645 | 459 | |
| 646 | | if ( mc6845->adjust_active ) |
| 460 | if ( m_adjust_active ) |
| 647 | 461 | { |
| 648 | 462 | /* Check if we have reached the end of a full cycle */ |
| 649 | | if ( mc6845->adjust_counter == mc6845->vert_total_adj ) |
| 463 | if ( m_adjust_counter == m_vert_total_adj ) |
| 650 | 464 | { |
| 651 | | mc6845->adjust_active = 0; |
| 652 | | mc6845->raster_counter = 0; |
| 653 | | mc6845->line_counter = 0; |
| 654 | | mc6845->line_address = mc6845->disp_start_addr; |
| 655 | | mc6845->line_enable_ff = 1; |
| 465 | m_adjust_active = 0; |
| 466 | m_raster_counter = 0; |
| 467 | m_line_counter = 0; |
| 468 | m_line_address = m_disp_start_addr; |
| 469 | m_line_enable_ff = true; |
| 656 | 470 | /* also update the cursor state now */ |
| 657 | | update_cursor_state(mc6845); |
| 471 | update_cursor_state(); |
| 658 | 472 | |
| 659 | | if (mc6845->screen != NULL) |
| 660 | | mc6845->screen->reset_origin(); |
| 473 | if (m_screen != NULL) |
| 474 | m_screen->reset_origin(); |
| 661 | 475 | } |
| 662 | 476 | else |
| 663 | 477 | { |
| 664 | | mc6845->adjust_counter = ( mc6845->adjust_counter + 1 ) & 0x1F; |
| 478 | m_adjust_counter = ( m_adjust_counter + 1 ) & 0x1F; |
| 665 | 479 | } |
| 666 | 480 | } |
| 667 | 481 | |
| 668 | | if ( mc6845->line_enable_ff ) |
| 482 | if ( m_line_enable_ff ) |
| 669 | 483 | { |
| 670 | 484 | /* Schedule DE off signal change */ |
| 671 | | mc6845->de_off_timer->adjust(attotime::from_ticks( mc6845->horiz_disp, mc6845->clock )); |
| 485 | m_de_off_timer->adjust(attotime::from_ticks( m_horiz_disp, m_clock )); |
| 672 | 486 | |
| 673 | 487 | /* Is cursor visible on this line? */ |
| 674 | | if ( mc6845->cursor_state && |
| 675 | | (mc6845->raster_counter >= (mc6845->cursor_start_ras & 0x1f)) && |
| 676 | | (mc6845->raster_counter <= mc6845->cursor_end_ras) && |
| 677 | | (mc6845->cursor_addr >= mc6845->line_address) && |
| 678 | | (mc6845->cursor_addr < (mc6845->line_address + mc6845->horiz_disp)) ) |
| 488 | if ( m_cursor_state && |
| 489 | (m_raster_counter >= (m_cursor_start_ras & 0x1f)) && |
| 490 | (m_raster_counter <= m_cursor_end_ras) && |
| 491 | (m_cursor_addr >= m_line_address) && |
| 492 | (m_cursor_addr < (m_line_address + m_horiz_disp)) ) |
| 679 | 493 | { |
| 680 | | mc6845->cursor_x = mc6845->cursor_addr - mc6845->line_address; |
| 494 | m_cursor_x = m_cursor_addr - m_line_address; |
| 681 | 495 | |
| 682 | 496 | /* Schedule CURSOR ON signal */ |
| 683 | | mc6845->cur_on_timer->adjust( attotime::from_ticks( mc6845->cursor_x, mc6845->clock ) ); |
| 497 | m_cur_on_timer->adjust( attotime::from_ticks( m_cursor_x, m_clock ) ); |
| 684 | 498 | } |
| 685 | 499 | } |
| 686 | 500 | |
| 687 | 501 | /* Schedule HSYNC on signal */ |
| 688 | | mc6845->hsync_on_timer->adjust( attotime::from_ticks( mc6845->horiz_sync_pos, mc6845->clock ) ); |
| 502 | m_hsync_on_timer->adjust( attotime::from_ticks( m_horiz_sync_pos, m_clock ) ); |
| 689 | 503 | |
| 690 | 504 | /* Schedule our next callback */ |
| 691 | | mc6845->line_timer->adjust( attotime::from_ticks( mc6845->horiz_char_total + 1, mc6845->clock ) ); |
| 505 | m_line_timer->adjust( attotime::from_ticks( m_horiz_char_total + 1, m_clock ) ); |
| 692 | 506 | |
| 693 | 507 | /* Set VSYNC and DE signals */ |
| 694 | | mc6845_set_vsync( mc6845, new_vsync ); |
| 695 | | mc6845_set_de( mc6845, mc6845->line_enable_ff ? TRUE : FALSE ); |
| 508 | set_vsync( new_vsync ); |
| 509 | set_de( m_line_enable_ff ? TRUE : FALSE ); |
| 696 | 510 | } |
| 697 | 511 | |
| 698 | 512 | |
| 699 | | UINT16 mc6845_get_ma(device_t *device) |
| 513 | void mc6845_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 700 | 514 | { |
| 701 | | mc6845_t *mc6845 = get_safe_token(device); |
| 515 | switch (id) |
| 516 | { |
| 517 | case TIMER_LINE: |
| 518 | handle_line_timer(); |
| 519 | break; |
| 702 | 520 | |
| 703 | | mc6845_update_counters( mc6845 ); |
| 521 | case TIMER_DE_OFF: |
| 522 | set_de( FALSE ); |
| 523 | break; |
| 704 | 524 | |
| 705 | | return ( mc6845->line_address + mc6845->character_counter ) & 0x3fff; |
| 706 | | } |
| 525 | case TIMER_CUR_ON: |
| 526 | set_cur( TRUE ); |
| 707 | 527 | |
| 528 | /* Schedule CURSOR off signal */ |
| 529 | m_cur_off_timer->adjust( attotime::from_ticks( 1, m_clock ) ); |
| 530 | break; |
| 708 | 531 | |
| 709 | | UINT8 mc6845_get_ra(device_t *device) |
| 710 | | { |
| 711 | | mc6845_t *mc6845 = get_safe_token(device); |
| 532 | case TIMER_CUR_OFF: |
| 533 | set_cur( FALSE ); |
| 534 | break; |
| 712 | 535 | |
| 713 | | return mc6845->raster_counter; |
| 536 | case TIMER_HSYNC_ON: |
| 537 | { |
| 538 | UINT8 hsync_width = ( m_sync_width & 0x0f ) ? ( m_sync_width & 0x0f ) : 0x10; |
| 539 | |
| 540 | m_hsync_width_counter = 0; |
| 541 | set_hsync( TRUE ); |
| 542 | |
| 543 | /* Schedule HSYNC off signal */ |
| 544 | m_hsync_off_timer->adjust( attotime::from_ticks( hsync_width, m_clock ) ); |
| 545 | } |
| 546 | break; |
| 547 | |
| 548 | case TIMER_HSYNC_OFF: |
| 549 | set_hsync( FALSE ); |
| 550 | break; |
| 551 | |
| 552 | case TIMER_LIGHT_PEN_LATCH: |
| 553 | m_light_pen_addr = get_ma(); |
| 554 | m_light_pen_latched = true; |
| 555 | break; |
| 556 | |
| 557 | case TIMER_UPD_ADR: |
| 558 | /* fire a update address strobe */ |
| 559 | call_on_update_address(0); |
| 560 | break; |
| 561 | |
| 562 | case TIMER_UPD_TRANS: |
| 563 | { |
| 564 | int addr = (param >> 8); |
| 565 | int strobe = (param & 0xff); |
| 566 | |
| 567 | /* call the callback function -- we know it exists */ |
| 568 | m_on_update_addr_changed(this, addr, strobe); |
| 569 | |
| 570 | if(!m_update_ready_bit && MODE_TRANSPARENT_BLANK) |
| 571 | { |
| 572 | m_update_addr++; |
| 573 | m_update_addr &= 0x3fff; |
| 574 | m_update_ready_bit = true; |
| 575 | } |
| 576 | } |
| 577 | break; |
| 578 | |
| 579 | } |
| 714 | 580 | } |
| 715 | 581 | |
| 716 | 582 | |
| 717 | | static TIMER_CALLBACK( light_pen_latch_timer_cb ) |
| 583 | UINT16 mc6845_device::get_ma() |
| 718 | 584 | { |
| 719 | | device_t *device = (device_t *)ptr; |
| 720 | | mc6845_t *mc6845 = get_safe_token(device); |
| 585 | update_counters(); |
| 721 | 586 | |
| 722 | | mc6845->light_pen_addr = mc6845_get_ma(device); |
| 723 | | mc6845->light_pen_latched = TRUE; |
| 587 | return ( m_line_address + m_character_counter ) & 0x3fff; |
| 724 | 588 | } |
| 725 | 589 | |
| 726 | 590 | |
| 727 | | void mc6845_assert_light_pen_input(device_t *device) |
| 591 | UINT8 mc6845_device::get_ra() |
| 728 | 592 | { |
| 729 | | mc6845_t *mc6845 = get_safe_token(device); |
| 593 | return m_raster_counter; |
| 594 | } |
| 730 | 595 | |
| 596 | |
| 597 | void mc6845_device::assert_light_pen_input() |
| 598 | { |
| 731 | 599 | /* compute the pixel coordinate of the NEXT character -- this is when the light pen latches */ |
| 732 | 600 | /* set the timer that will latch the display address into the light pen registers */ |
| 733 | | mc6845->light_pen_latch_timer->adjust(attotime::from_ticks( 1, mc6845->clock )); |
| 601 | m_light_pen_latch_timer->adjust(attotime::from_ticks( 1, m_clock )); |
| 734 | 602 | } |
| 735 | 603 | |
| 736 | 604 | |
| 737 | | void mc6845_set_clock(device_t *device, int clock) |
| 605 | void mc6845_device::set_clock(int clock) |
| 738 | 606 | { |
| 739 | | mc6845_t *mc6845 = get_safe_token(device); |
| 740 | | |
| 741 | 607 | /* validate arguments */ |
| 742 | 608 | assert(clock > 0); |
| 743 | 609 | |
| 744 | | if (clock != mc6845->clock) |
| 610 | if (clock != m_clock) |
| 745 | 611 | { |
| 746 | | mc6845->clock = clock; |
| 747 | | recompute_parameters(mc6845, TRUE); |
| 612 | m_clock = clock; |
| 613 | recompute_parameters(true); |
| 748 | 614 | } |
| 749 | 615 | } |
| 750 | 616 | |
| 751 | 617 | |
| 752 | | void mc6845_set_hpixels_per_column(device_t *device, int hpixels_per_column) |
| 618 | void mc6845_device::set_hpixels_per_column(int hpixels_per_column) |
| 753 | 619 | { |
| 754 | | mc6845_t *mc6845 = get_safe_token(device); |
| 755 | | |
| 756 | 620 | /* validate arguments */ |
| 757 | 621 | assert(hpixels_per_column > 0); |
| 758 | 622 | |
| 759 | | if (hpixels_per_column != mc6845->hpixels_per_column) |
| 623 | if (hpixels_per_column != m_hpixels_per_column) |
| 760 | 624 | { |
| 761 | | mc6845->hpixels_per_column = hpixels_per_column; |
| 762 | | recompute_parameters(mc6845, FALSE); |
| 625 | m_hpixels_per_column = hpixels_per_column; |
| 626 | recompute_parameters(false); |
| 763 | 627 | } |
| 764 | 628 | } |
| 765 | 629 | |
| 766 | 630 | |
| 767 | | static void update_cursor_state(mc6845_t *mc6845) |
| 631 | void mc6845_device::update_cursor_state() |
| 768 | 632 | { |
| 769 | 633 | /* save and increment cursor counter */ |
| 770 | | UINT8 last_cursor_blink_count = mc6845->cursor_blink_count; |
| 771 | | mc6845->cursor_blink_count = mc6845->cursor_blink_count + 1; |
| 634 | UINT8 last_cursor_blink_count = m_cursor_blink_count; |
| 635 | m_cursor_blink_count = m_cursor_blink_count + 1; |
| 772 | 636 | |
| 773 | 637 | /* switch on cursor blinking mode */ |
| 774 | | switch (mc6845->cursor_start_ras & 0x60) |
| 638 | switch (m_cursor_start_ras & 0x60) |
| 775 | 639 | { |
| 776 | 640 | /* always on */ |
| 777 | | case 0x00: mc6845->cursor_state = TRUE; break; |
| 641 | case 0x00: m_cursor_state = true; break; |
| 778 | 642 | |
| 779 | 643 | /* always off */ |
| 780 | 644 | default: |
| 781 | | case 0x20: mc6845->cursor_state = FALSE; break; |
| 645 | case 0x20: m_cursor_state = false; break; |
| 782 | 646 | |
| 783 | 647 | /* fast blink */ |
| 784 | 648 | case 0x40: |
| 785 | | if ((last_cursor_blink_count & 0x10) != (mc6845->cursor_blink_count & 0x10)) |
| 786 | | mc6845->cursor_state = !mc6845->cursor_state; |
| 649 | if ((last_cursor_blink_count & 0x10) != (m_cursor_blink_count & 0x10)) |
| 650 | m_cursor_state = !m_cursor_state; |
| 787 | 651 | break; |
| 788 | 652 | |
| 789 | 653 | /* slow blink */ |
| 790 | 654 | case 0x60: |
| 791 | | if ((last_cursor_blink_count & 0x20) != (mc6845->cursor_blink_count & 0x20)) |
| 792 | | mc6845->cursor_state = !mc6845->cursor_state; |
| 655 | if ((last_cursor_blink_count & 0x20) != (m_cursor_blink_count & 0x20)) |
| 656 | m_cursor_state = !m_cursor_state; |
| 793 | 657 | break; |
| 794 | 658 | } |
| 795 | 659 | } |
| 796 | 660 | |
| 797 | 661 | |
| 798 | | void mc6845_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 662 | void mc6845_device::update(bitmap_t *bitmap, const rectangle *cliprect) |
| 799 | 663 | { |
| 800 | | mc6845_t *mc6845 = get_safe_token(device); |
| 801 | 664 | assert(bitmap != NULL); |
| 802 | 665 | assert(cliprect != NULL); |
| 803 | 666 | |
| 804 | | if (mc6845->has_valid_parameters) |
| 667 | if (m_has_valid_parameters) |
| 805 | 668 | { |
| 806 | 669 | UINT16 y; |
| 807 | 670 | |
| 808 | 671 | void *param = NULL; |
| 809 | 672 | |
| 810 | | assert(mc6845->intf != NULL); |
| 811 | | assert(mc6845->intf->update_row != NULL); |
| 673 | assert(m_update_row != NULL); |
| 812 | 674 | |
| 813 | 675 | /* call the set up function if any */ |
| 814 | | if (mc6845->intf->begin_update != NULL) |
| 815 | | param = mc6845->intf->begin_update(device, bitmap, cliprect); |
| 676 | if (m_begin_update != NULL) |
| 677 | param = m_begin_update(this, bitmap, cliprect); |
| 816 | 678 | |
| 817 | 679 | if (cliprect->min_y == 0) |
| 818 | 680 | { |
| 819 | 681 | /* read the start address at the beginning of the frame */ |
| 820 | | mc6845->current_disp_addr = mc6845->disp_start_addr; |
| 682 | m_current_disp_addr = m_disp_start_addr; |
| 821 | 683 | } |
| 822 | 684 | |
| 823 | 685 | /* for each row in the visible region */ |
| 824 | 686 | for (y = cliprect->min_y; y <= cliprect->max_y; y++) |
| 825 | 687 | { |
| 826 | 688 | /* compute the current raster line */ |
| 827 | | UINT8 ra = y % (mc6845->max_ras_addr + 1); |
| 689 | UINT8 ra = y % (m_max_ras_addr + 1); |
| 828 | 690 | |
| 829 | 691 | /* check if the cursor is visible and is on this scanline */ |
| 830 | | int cursor_visible = mc6845->cursor_state && |
| 831 | | (ra >= (mc6845->cursor_start_ras & 0x1f)) && |
| 832 | | (ra <= mc6845->cursor_end_ras) && |
| 833 | | (mc6845->cursor_addr >= mc6845->current_disp_addr) && |
| 834 | | (mc6845->cursor_addr < (mc6845->current_disp_addr + mc6845->horiz_disp)); |
| 692 | int cursor_visible = m_cursor_state && |
| 693 | (ra >= (m_cursor_start_ras & 0x1f)) && |
| 694 | (ra <= m_cursor_end_ras) && |
| 695 | (m_cursor_addr >= m_current_disp_addr) && |
| 696 | (m_cursor_addr < (m_current_disp_addr + m_horiz_disp)); |
| 835 | 697 | |
| 836 | 698 | /* compute the cursor X position, or -1 if not visible */ |
| 837 | | INT8 cursor_x = cursor_visible ? (mc6845->cursor_addr - mc6845->current_disp_addr) : -1; |
| 699 | INT8 cursor_x = cursor_visible ? (m_cursor_addr - m_current_disp_addr) : -1; |
| 838 | 700 | |
| 839 | 701 | /* call the external system to draw it */ |
| 840 | | if (MODE_ROW_COLUMN_ADDRESSING(mc6845)) |
| 702 | if (MODE_ROW_COLUMN_ADDRESSING) |
| 841 | 703 | { |
| 842 | 704 | UINT8 cc = 0; |
| 843 | | UINT8 cr = y / (mc6845->max_ras_addr + 1); |
| 705 | UINT8 cr = y / (m_max_ras_addr + 1); |
| 844 | 706 | UINT16 ma = (cr << 8) | cc; |
| 845 | 707 | |
| 846 | | mc6845->intf->update_row(device, bitmap, cliprect, ma, ra, y, mc6845->horiz_disp, cursor_x, param); |
| 708 | m_update_row(this, bitmap, cliprect, ma, ra, y, m_horiz_disp, cursor_x, param); |
| 847 | 709 | } |
| 848 | 710 | else |
| 849 | 711 | { |
| 850 | | mc6845->intf->update_row(device, bitmap, cliprect, mc6845->current_disp_addr, ra, y, mc6845->horiz_disp, cursor_x, param); |
| 712 | m_update_row(this, bitmap, cliprect, m_current_disp_addr, ra, y, m_horiz_disp, cursor_x, param); |
| 851 | 713 | } |
| 852 | 714 | |
| 853 | 715 | /* update MA if the last raster address */ |
| 854 | | if (ra == mc6845->max_ras_addr) |
| 855 | | mc6845->current_disp_addr = (mc6845->current_disp_addr + mc6845->horiz_disp) & 0x3fff; |
| 716 | if (ra == m_max_ras_addr) |
| 717 | m_current_disp_addr = (m_current_disp_addr + m_horiz_disp) & 0x3fff; |
| 856 | 718 | } |
| 857 | 719 | |
| 858 | 720 | /* call the tear down function if any */ |
| 859 | | if (mc6845->intf->end_update != NULL) |
| 860 | | mc6845->intf->end_update(device, bitmap, cliprect, param); |
| 721 | if (m_end_update != NULL) |
| 722 | m_end_update(this, bitmap, cliprect, param); |
| 861 | 723 | } |
| 862 | 724 | else |
| 863 | 725 | popmessage("Invalid MC6845 screen parameters - display disabled!!!"); |
| 864 | 726 | } |
| 865 | 727 | |
| 866 | 728 | |
| 867 | | /* device interface */ |
| 868 | | static void common_start(device_t *device, int device_type) |
| 729 | void mc6845_device::device_start() |
| 869 | 730 | { |
| 870 | | mc6845_t *mc6845 = get_safe_token(device); |
| 731 | assert(m_clock > 0); |
| 732 | assert(m_hpixels_per_column > 0); |
| 871 | 733 | |
| 872 | | /* validate arguments */ |
| 873 | | assert(device != NULL); |
| 734 | /* resolve callbacks */ |
| 735 | m_res_out_de_func.resolve(m_out_de_func, *this); |
| 736 | m_res_out_cur_func.resolve(m_out_cur_func, *this); |
| 737 | m_res_out_hsync_func.resolve(m_out_hsync_func, *this); |
| 738 | m_res_out_vsync_func.resolve(m_out_vsync_func, *this); |
| 874 | 739 | |
| 875 | | mc6845->intf = (const mc6845_interface *)device->static_config(); |
| 876 | | mc6845->device_type = device_type; |
| 877 | | |
| 878 | | if (mc6845->intf != NULL) |
| 740 | /* get the screen device */ |
| 741 | if ( m_screen_tag != NULL ) |
| 879 | 742 | { |
| 880 | | assert(device->clock() > 0); |
| 881 | | assert(mc6845->intf->hpixels_per_column > 0); |
| 882 | | |
| 883 | | /* resolve callbacks */ |
| 884 | | mc6845->out_de_func.resolve(mc6845->intf->out_de_func, *device); |
| 885 | | mc6845->out_cur_func.resolve(mc6845->intf->out_cur_func, *device); |
| 886 | | mc6845->out_hsync_func.resolve(mc6845->intf->out_hsync_func, *device); |
| 887 | | mc6845->out_vsync_func.resolve(mc6845->intf->out_vsync_func, *device); |
| 888 | | |
| 889 | | /* copy the initial parameters */ |
| 890 | | mc6845->clock = device->clock(); |
| 891 | | mc6845->hpixels_per_column = mc6845->intf->hpixels_per_column; |
| 892 | | |
| 893 | | /* get the screen device */ |
| 894 | | if ( mc6845->intf->screen_tag != NULL ) |
| 895 | | { |
| 896 | | mc6845->screen = downcast<screen_device *>(device->machine().device(mc6845->intf->screen_tag)); |
| 897 | | if (mc6845->screen == NULL) { |
| 898 | | astring tempstring; |
| 899 | | mc6845->screen = downcast<screen_device *>(device->machine().device(device->owner()->subtag(tempstring,mc6845->intf->screen_tag))); |
| 900 | | } |
| 901 | | assert(mc6845->screen != NULL); |
| 743 | m_screen = downcast<screen_device *>(machine().device(m_screen_tag)); |
| 744 | if (m_screen == NULL) { |
| 745 | astring tempstring; |
| 746 | m_screen = downcast<screen_device *>(machine().device(owner()->subtag(tempstring,m_screen_tag))); |
| 902 | 747 | } |
| 903 | | else |
| 904 | | mc6845->screen = NULL; |
| 905 | | |
| 906 | | /* create the timers */ |
| 907 | | mc6845->line_timer = device->machine().scheduler().timer_alloc(FUNC(line_timer_cb), (void *)device); |
| 908 | | |
| 909 | | mc6845->de_off_timer = device->machine().scheduler().timer_alloc(FUNC(de_off_timer_cb), (void *)device); |
| 910 | | mc6845->upd_adr_timer = device->machine().scheduler().timer_alloc(FUNC(upd_adr_timer_cb), (void *)device); |
| 911 | | |
| 912 | | mc6845->cur_on_timer = device->machine().scheduler().timer_alloc(FUNC(cur_on_timer_cb), (void *)device); |
| 913 | | mc6845->cur_off_timer = device->machine().scheduler().timer_alloc(FUNC(cur_off_timer_cb), (void *)device); |
| 914 | | |
| 915 | | mc6845->hsync_on_timer = device->machine().scheduler().timer_alloc(FUNC(hsync_on_timer_cb), (void *)device); |
| 916 | | mc6845->hsync_off_timer = device->machine().scheduler().timer_alloc(FUNC(hsync_off_timer_cb), (void *)device); |
| 748 | assert(m_screen != NULL); |
| 917 | 749 | } |
| 750 | else |
| 751 | m_screen = NULL; |
| 918 | 752 | |
| 919 | | mc6845->light_pen_latch_timer = device->machine().scheduler().timer_alloc(FUNC(light_pen_latch_timer_cb), (void *)device); |
| 753 | /* create the timers */ |
| 754 | m_line_timer = timer_alloc(TIMER_LINE); |
| 755 | m_de_off_timer = timer_alloc(TIMER_DE_OFF); |
| 756 | m_cur_on_timer = timer_alloc(TIMER_CUR_ON); |
| 757 | m_cur_off_timer = timer_alloc(TIMER_CUR_OFF); |
| 758 | m_hsync_on_timer = timer_alloc(TIMER_HSYNC_ON); |
| 759 | m_hsync_off_timer = timer_alloc(TIMER_HSYNC_OFF); |
| 760 | m_light_pen_latch_timer = timer_alloc(TIMER_LIGHT_PEN_LATCH); |
| 761 | m_upd_adr_timer = timer_alloc(TIMER_UPD_ADR); |
| 762 | m_upd_trans_timer = timer_alloc(TIMER_UPD_TRANS); |
| 920 | 763 | |
| 921 | 764 | /* Use some large startup values */ |
| 922 | | mc6845->horiz_char_total = 0xff; |
| 923 | | mc6845->max_ras_addr = 0x1f; |
| 924 | | mc6845->vert_char_total = 0x7f; |
| 765 | m_horiz_char_total = 0xff; |
| 766 | m_max_ras_addr = 0x1f; |
| 767 | m_vert_char_total = 0x7f; |
| 925 | 768 | |
| 926 | | /* register for state saving */ |
| 927 | | device->machine().save().register_postload(save_prepost_delegate(FUNC(mc6845_state_save_postload), mc6845)); |
| 928 | | |
| 929 | | device->save_item(NAME(mc6845->clock)); |
| 930 | | device->save_item(NAME(mc6845->hpixels_per_column)); |
| 931 | | device->save_item(NAME(mc6845->register_address_latch)); |
| 932 | | device->save_item(NAME(mc6845->horiz_char_total)); |
| 933 | | device->save_item(NAME(mc6845->horiz_disp)); |
| 934 | | device->save_item(NAME(mc6845->horiz_sync_pos)); |
| 935 | | device->save_item(NAME(mc6845->sync_width)); |
| 936 | | device->save_item(NAME(mc6845->vert_char_total)); |
| 937 | | device->save_item(NAME(mc6845->vert_total_adj)); |
| 938 | | device->save_item(NAME(mc6845->vert_disp)); |
| 939 | | device->save_item(NAME(mc6845->vert_sync_pos)); |
| 940 | | device->save_item(NAME(mc6845->mode_control)); |
| 941 | | device->save_item(NAME(mc6845->max_ras_addr)); |
| 942 | | device->save_item(NAME(mc6845->cursor_start_ras)); |
| 943 | | device->save_item(NAME(mc6845->cursor_end_ras)); |
| 944 | | device->save_item(NAME(mc6845->disp_start_addr)); |
| 945 | | device->save_item(NAME(mc6845->cursor_addr)); |
| 946 | | device->save_item(NAME(mc6845->light_pen_addr)); |
| 947 | | device->save_item(NAME(mc6845->light_pen_latched)); |
| 948 | | device->save_item(NAME(mc6845->cursor_state)); |
| 949 | | device->save_item(NAME(mc6845->cursor_blink_count)); |
| 950 | | device->save_item(NAME(mc6845->update_addr)); |
| 951 | | device->save_item(NAME(mc6845->update_ready_bit)); |
| 952 | | device->save_item(NAME(mc6845->cur)); |
| 953 | | device->save_item(NAME(mc6845->hsync)); |
| 954 | | device->save_item(NAME(mc6845->vsync)); |
| 955 | | device->save_item(NAME(mc6845->de)); |
| 956 | | device->save_item(NAME(mc6845->character_counter)); |
| 957 | | device->save_item(NAME(mc6845->hsync_width_counter)); |
| 958 | | device->save_item(NAME(mc6845->line_counter)); |
| 959 | | device->save_item(NAME(mc6845->raster_counter)); |
| 960 | | device->save_item(NAME(mc6845->adjust_counter)); |
| 961 | | device->save_item(NAME(mc6845->vsync_width_counter)); |
| 962 | | device->save_item(NAME(mc6845->line_enable_ff)); |
| 963 | | device->save_item(NAME(mc6845->vsync_ff)); |
| 964 | | device->save_item(NAME(mc6845->adjust_active)); |
| 965 | | device->save_item(NAME(mc6845->line_address)); |
| 966 | | device->save_item(NAME(mc6845->cursor_x)); |
| 769 | m_supports_disp_start_addr_r = true; |
| 770 | m_supports_vert_sync_width = false; |
| 771 | m_supports_status_reg_d5 = false; |
| 772 | m_supports_status_reg_d6 = false; |
| 773 | m_supports_status_reg_d7 = false; |
| 774 | m_supports_transparent = false; |
| 775 | |
| 776 | save_item(NAME(m_hpixels_per_column)); |
| 777 | save_item(NAME(m_register_address_latch)); |
| 778 | save_item(NAME(m_horiz_char_total)); |
| 779 | save_item(NAME(m_horiz_disp)); |
| 780 | save_item(NAME(m_horiz_sync_pos)); |
| 781 | save_item(NAME(m_sync_width)); |
| 782 | save_item(NAME(m_vert_char_total)); |
| 783 | save_item(NAME(m_vert_total_adj)); |
| 784 | save_item(NAME(m_vert_disp)); |
| 785 | save_item(NAME(m_vert_sync_pos)); |
| 786 | save_item(NAME(m_mode_control)); |
| 787 | save_item(NAME(m_max_ras_addr)); |
| 788 | save_item(NAME(m_cursor_start_ras)); |
| 789 | save_item(NAME(m_cursor_end_ras)); |
| 790 | save_item(NAME(m_disp_start_addr)); |
| 791 | save_item(NAME(m_cursor_addr)); |
| 792 | save_item(NAME(m_light_pen_addr)); |
| 793 | save_item(NAME(m_light_pen_latched)); |
| 794 | save_item(NAME(m_cursor_state)); |
| 795 | save_item(NAME(m_cursor_blink_count)); |
| 796 | save_item(NAME(m_update_addr)); |
| 797 | save_item(NAME(m_update_ready_bit)); |
| 798 | save_item(NAME(m_cur)); |
| 799 | save_item(NAME(m_hsync)); |
| 800 | save_item(NAME(m_vsync)); |
| 801 | save_item(NAME(m_de)); |
| 802 | save_item(NAME(m_character_counter)); |
| 803 | save_item(NAME(m_hsync_width_counter)); |
| 804 | save_item(NAME(m_line_counter)); |
| 805 | save_item(NAME(m_raster_counter)); |
| 806 | save_item(NAME(m_adjust_counter)); |
| 807 | save_item(NAME(m_vsync_width_counter)); |
| 808 | save_item(NAME(m_line_enable_ff)); |
| 809 | save_item(NAME(m_vsync_ff)); |
| 810 | save_item(NAME(m_adjust_active)); |
| 811 | save_item(NAME(m_line_address)); |
| 812 | save_item(NAME(m_cursor_x)); |
| 967 | 813 | } |
| 968 | 814 | |
| 969 | | static DEVICE_START( mc6845 ) |
| 970 | | { |
| 971 | | common_start(device, TYPE_MC6845); |
| 972 | | } |
| 973 | 815 | |
| 974 | | static DEVICE_START( mc6845_1 ) |
| 816 | void mc6845_1_device::device_start() |
| 975 | 817 | { |
| 976 | | common_start(device, TYPE_MC6845_1); |
| 818 | mc6845_device::device_start(); |
| 819 | |
| 820 | m_supports_disp_start_addr_r = true; |
| 821 | m_supports_vert_sync_width = true; |
| 822 | m_supports_status_reg_d5 = false; |
| 823 | m_supports_status_reg_d6 = false; |
| 824 | m_supports_status_reg_d7 = false; |
| 825 | m_supports_transparent = false; |
| 977 | 826 | } |
| 978 | 827 | |
| 979 | | static DEVICE_START( c6545_1 ) |
| 828 | |
| 829 | void c6545_1_device::device_start() |
| 980 | 830 | { |
| 981 | | common_start(device, TYPE_C6545_1); |
| 831 | mc6845_device::device_start(); |
| 832 | |
| 833 | m_supports_disp_start_addr_r = false; |
| 834 | m_supports_vert_sync_width = true; |
| 835 | m_supports_status_reg_d5 = true; |
| 836 | m_supports_status_reg_d6 = true; |
| 837 | m_supports_status_reg_d7 = false; |
| 838 | m_supports_transparent = false; |
| 982 | 839 | } |
| 983 | 840 | |
| 984 | | static DEVICE_START( r6545_1 ) |
| 841 | |
| 842 | void r6545_1_device::device_start() |
| 985 | 843 | { |
| 986 | | common_start(device, TYPE_R6545_1); |
| 844 | mc6845_device::device_start(); |
| 845 | |
| 846 | m_supports_disp_start_addr_r = false; |
| 847 | m_supports_vert_sync_width = true; |
| 848 | m_supports_status_reg_d5 = true; |
| 849 | m_supports_status_reg_d6 = true; |
| 850 | m_supports_status_reg_d7 = true; |
| 851 | m_supports_transparent = true; |
| 987 | 852 | } |
| 988 | 853 | |
| 989 | | static DEVICE_START( h46505 ) |
| 854 | |
| 855 | void h46505_device::device_start() |
| 990 | 856 | { |
| 991 | | common_start(device, TYPE_H46505); |
| 857 | mc6845_device::device_start(); |
| 858 | |
| 859 | m_supports_disp_start_addr_r = false; |
| 860 | m_supports_vert_sync_width = false; |
| 861 | m_supports_status_reg_d5 = false; |
| 862 | m_supports_status_reg_d6 = false; |
| 863 | m_supports_status_reg_d7 = false; |
| 864 | m_supports_transparent = false; |
| 992 | 865 | } |
| 993 | 866 | |
| 994 | | static DEVICE_START( hd6845 ) |
| 867 | |
| 868 | void hd6845_device::device_start() |
| 995 | 869 | { |
| 996 | | common_start(device, TYPE_HD6845); |
| 870 | mc6845_device::device_start(); |
| 871 | |
| 872 | m_supports_disp_start_addr_r = false; |
| 873 | m_supports_vert_sync_width = true; |
| 874 | m_supports_status_reg_d5 = false; |
| 875 | m_supports_status_reg_d6 = false; |
| 876 | m_supports_status_reg_d7 = false; |
| 877 | m_supports_transparent = false; |
| 997 | 878 | } |
| 998 | 879 | |
| 999 | | static DEVICE_START( sy6545_1 ) |
| 880 | |
| 881 | void sy6545_1_device::device_start() |
| 1000 | 882 | { |
| 1001 | | common_start(device, TYPE_SY6545_1); |
| 883 | mc6845_device::device_start(); |
| 884 | |
| 885 | m_supports_disp_start_addr_r = false; |
| 886 | m_supports_vert_sync_width = true; |
| 887 | m_supports_status_reg_d5 = true; |
| 888 | m_supports_status_reg_d6 = true; |
| 889 | m_supports_status_reg_d7 = true; |
| 890 | m_supports_transparent = true; |
| 1002 | 891 | } |
| 1003 | 892 | |
| 1004 | | static DEVICE_START( sy6845e ) |
| 893 | |
| 894 | void sy6845e_device::device_start() |
| 1005 | 895 | { |
| 1006 | | common_start(device, TYPE_SY6845E); |
| 896 | mc6845_device::device_start(); |
| 897 | |
| 898 | m_supports_disp_start_addr_r = false; |
| 899 | m_supports_vert_sync_width = true; |
| 900 | m_supports_status_reg_d5 = true; |
| 901 | m_supports_status_reg_d6 = true; |
| 902 | m_supports_status_reg_d7 = true; |
| 903 | m_supports_transparent = true; |
| 1007 | 904 | } |
| 1008 | 905 | |
| 1009 | 906 | |
| 1010 | | static DEVICE_RESET( mc6845 ) |
| 907 | void mc6845_device::device_reset() |
| 1011 | 908 | { |
| 1012 | | mc6845_t *mc6845 = get_safe_token(device); |
| 1013 | | |
| 1014 | 909 | /* internal registers other than status remain unchanged, all outputs go low */ |
| 1015 | | if (mc6845->intf != NULL) |
| 1016 | | { |
| 1017 | | if (!mc6845->out_de_func.isnull()) |
| 1018 | | mc6845->out_de_func(FALSE); |
| 910 | if ( !m_res_out_de_func.isnull() ) |
| 911 | m_res_out_de_func( FALSE ); |
| 1019 | 912 | |
| 1020 | | if (!mc6845->out_hsync_func.isnull()) |
| 1021 | | mc6845->out_hsync_func(FALSE); |
| 913 | if ( !m_res_out_hsync_func.isnull() ) |
| 914 | m_res_out_hsync_func( FALSE ); |
| 1022 | 915 | |
| 1023 | | if (!mc6845->out_vsync_func.isnull()) |
| 1024 | | mc6845->out_vsync_func(FALSE); |
| 1025 | | } |
| 916 | if ( !m_res_out_vsync_func.isnull() ) |
| 917 | m_res_out_vsync_func( FALSE ); |
| 1026 | 918 | |
| 1027 | | if ( ! mc6845->line_timer ->enabled( ) ) |
| 919 | if ( ! m_line_timer->enabled( ) ) |
| 1028 | 920 | { |
| 1029 | | mc6845->line_timer->adjust( attotime::from_ticks( mc6845->horiz_char_total + 1, mc6845->clock ) ); |
| 921 | m_line_timer->adjust( attotime::from_ticks( m_horiz_char_total + 1, m_clock ) ); |
| 1030 | 922 | } |
| 1031 | 923 | |
| 1032 | | mc6845->light_pen_latched = FALSE; |
| 924 | m_light_pen_latched = false; |
| 1033 | 925 | } |
| 1034 | 926 | |
| 1035 | | #if 0 |
| 1036 | | static DEVICE_VALIDITY_CHECK( mc6845 ) |
| 1037 | | { |
| 1038 | | int error = FALSE; |
| 1039 | | const mc6845_interface *intf = (const mc6845_interface *) device->static_config(); |
| 1040 | 927 | |
| 1041 | | if (intf != NULL && intf->screen_tag != NULL) |
| 1042 | | { |
| 1043 | | if (device->clock() <= 0) |
| 1044 | | { |
| 1045 | | mame_printf_error("%s: %s has an mc6845 with an invalid clock\n", driver->source_file, driver->name); |
| 1046 | | error = TRUE; |
| 1047 | | } |
| 928 | void r6545_1_device::device_reset() { mc6845_device::device_reset(); } |
| 929 | void h46505_device::device_reset() { mc6845_device::device_reset(); } |
| 930 | void mc6845_1_device::device_reset() { mc6845_device::device_reset(); } |
| 931 | void hd6845_device::device_reset() { mc6845_device::device_reset(); } |
| 932 | void c6545_1_device::device_reset() { mc6845_device::device_reset(); } |
| 933 | void sy6545_1_device::device_reset() { mc6845_device::device_reset(); } |
| 934 | void sy6845e_device::device_reset() { mc6845_device::device_reset(); } |
| 1048 | 935 | |
| 1049 | | if (intf->hpixels_per_column <= 0) |
| 1050 | | { |
| 1051 | | mame_printf_error("%s: %s has an mc6845 with an invalid hpixels_per_column\n", driver->source_file, driver->name); |
| 1052 | | error = TRUE; |
| 1053 | | } |
| 1054 | | } |
| 1055 | 936 | |
| 1056 | | return error; |
| 937 | r6545_1_device::r6545_1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 938 | : mc6845_device(mconfig, R6545_1, "r6545_1", tag, owner, clock) |
| 939 | { |
| 1057 | 940 | } |
| 1058 | | #endif |
| 1059 | 941 | |
| 1060 | | DEVICE_GET_INFO( mc6845 ) |
| 942 | |
| 943 | h46505_device::h46505_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 944 | : mc6845_device(mconfig, H46505, "h46505", tag, owner, clock) |
| 1061 | 945 | { |
| 1062 | | switch (state) |
| 1063 | | { |
| 1064 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1065 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(mc6845_t); break; |
| 1066 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 946 | } |
| 1067 | 947 | |
| 1068 | | /* --- the following bits of info are returned as pointers to functions --- */ |
| 1069 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(mc6845); break; |
| 1070 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1071 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(mc6845); break; |
| 1072 | | // case DEVINFO_FCT_VALIDITY_CHECK: info->validity_check = DEVICE_VALIDITY_CHECK_NAME(mc6845); break; |
| 1073 | 948 | |
| 1074 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1075 | | case DEVINFO_STR_NAME: strcpy(info->s, "Motorola 6845"); break; |
| 1076 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "MC6845 CRTC"); break; |
| 1077 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.61"); break; |
| 1078 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1079 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright Nicola Salmoria and the MAME Team"); break; |
| 1080 | | } |
| 949 | mc6845_1_device::mc6845_1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 950 | : mc6845_device(mconfig, MC6845_1, "mc6845_1", tag, owner, clock) |
| 951 | { |
| 1081 | 952 | } |
| 1082 | 953 | |
| 1083 | 954 | |
| 1084 | | DEVICE_GET_INFO( mc6845_1 ) |
| 955 | hd6845_device::hd6845_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 956 | : mc6845_device(mconfig, HD6845, "hd6845", tag, owner, clock) |
| 1085 | 957 | { |
| 1086 | | switch (state) |
| 1087 | | { |
| 1088 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1089 | | case DEVINFO_STR_NAME: strcpy(info->s, "Motorola 6845-1"); break; |
| 958 | } |
| 1090 | 959 | |
| 1091 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1092 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(mc6845_1); break; |
| 1093 | 960 | |
| 1094 | | default: DEVICE_GET_INFO_CALL(mc6845); break; |
| 1095 | | } |
| 961 | c6545_1_device::c6545_1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 962 | : mc6845_device(mconfig, C6545_1, "c6545_1", tag, owner, clock) |
| 963 | { |
| 1096 | 964 | } |
| 1097 | 965 | |
| 1098 | 966 | |
| 1099 | | DEVICE_GET_INFO( c6545_1 ) |
| 967 | sy6545_1_device::sy6545_1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 968 | : mc6845_device(mconfig, SY6545_1, "sy6545_1", tag, owner, clock) |
| 1100 | 969 | { |
| 1101 | | switch (state) |
| 1102 | | { |
| 1103 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1104 | | case DEVINFO_STR_NAME: strcpy(info->s, "MOS Technology 6545-1"); break; |
| 970 | } |
| 1105 | 971 | |
| 1106 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1107 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(c6545_1); break; |
| 1108 | 972 | |
| 1109 | | default: DEVICE_GET_INFO_CALL(mc6845); break; |
| 1110 | | } |
| 973 | sy6845e_device::sy6845e_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 974 | : mc6845_device(mconfig, SY6845E, "sy6845e", tag, owner, clock) |
| 975 | { |
| 1111 | 976 | } |
| 1112 | 977 | |
| 1113 | 978 | |
| 1114 | | DEVICE_GET_INFO( r6545_1 ) |
| 979 | /***************************************** |
| 980 | * TRAMPOLINES |
| 981 | *****************************************/ |
| 982 | |
| 983 | WRITE8_DEVICE_HANDLER( mc6845_address_w ) |
| 1115 | 984 | { |
| 1116 | | switch (state) |
| 1117 | | { |
| 1118 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1119 | | case DEVINFO_STR_NAME: strcpy(info->s, "Rockwell 6545-1"); break; |
| 985 | downcast<mc6845_device *>(device)->address_w( data ); |
| 986 | } |
| 1120 | 987 | |
| 1121 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1122 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(r6545_1); break; |
| 1123 | | |
| 1124 | | default: DEVICE_GET_INFO_CALL(mc6845); break; |
| 1125 | | } |
| 988 | READ8_DEVICE_HANDLER( mc6845_status_r ) |
| 989 | { |
| 990 | return downcast<mc6845_device *>(device)->status_r(); |
| 1126 | 991 | } |
| 1127 | 992 | |
| 1128 | | |
| 1129 | | DEVICE_GET_INFO( h46505 ) |
| 993 | READ8_DEVICE_HANDLER( mc6845_register_r ) |
| 1130 | 994 | { |
| 1131 | | switch (state) |
| 1132 | | { |
| 1133 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1134 | | case DEVINFO_STR_NAME: strcpy(info->s, "Hitachi 46505"); break; |
| 995 | return downcast<mc6845_device *>(device)->register_r(); |
| 996 | } |
| 1135 | 997 | |
| 1136 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1137 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(h46505); break; |
| 1138 | | |
| 1139 | | default: DEVICE_GET_INFO_CALL(mc6845); break; |
| 1140 | | } |
| 998 | WRITE8_DEVICE_HANDLER( mc6845_register_w ) |
| 999 | { |
| 1000 | downcast<mc6845_device *>(device)->register_w( data ); |
| 1141 | 1001 | } |
| 1142 | 1002 | |
| 1143 | | |
| 1144 | | DEVICE_GET_INFO( hd6845 ) |
| 1003 | UINT16 mc6845_get_ma(device_t *device) |
| 1145 | 1004 | { |
| 1146 | | switch (state) |
| 1147 | | { |
| 1148 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1149 | | case DEVINFO_STR_NAME: strcpy(info->s, "Hitachi 6845"); break; |
| 1005 | return downcast<mc6845_device *>(device)->get_ma(); |
| 1006 | } |
| 1150 | 1007 | |
| 1151 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1152 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(hd6845); break; |
| 1153 | | |
| 1154 | | default: DEVICE_GET_INFO_CALL(mc6845); break; |
| 1155 | | } |
| 1008 | UINT8 mc6845_get_ra(device_t *device) |
| 1009 | { |
| 1010 | return downcast<mc6845_device *>(device)->get_ra(); |
| 1156 | 1011 | } |
| 1157 | 1012 | |
| 1158 | | |
| 1159 | | DEVICE_GET_INFO( sy6545_1 ) |
| 1013 | void mc6845_assert_light_pen_input(device_t *device) |
| 1160 | 1014 | { |
| 1161 | | switch (state) |
| 1162 | | { |
| 1163 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1164 | | case DEVINFO_STR_NAME: strcpy(info->s, "Synertek 6545-1"); break; |
| 1015 | downcast<mc6845_device *>(device)->assert_light_pen_input(); |
| 1016 | } |
| 1165 | 1017 | |
| 1166 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1167 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(sy6545_1); break; |
| 1168 | | |
| 1169 | | default: DEVICE_GET_INFO_CALL(mc6845); break; |
| 1170 | | } |
| 1018 | void mc6845_set_clock(device_t *device, int clock) |
| 1019 | { |
| 1020 | downcast<mc6845_device *>(device)->set_clock( clock ); |
| 1171 | 1021 | } |
| 1172 | 1022 | |
| 1173 | | |
| 1174 | | DEVICE_GET_INFO( sy6845e ) |
| 1023 | void mc6845_set_hpixels_per_column(device_t *device, int hpixels_per_column) |
| 1175 | 1024 | { |
| 1176 | | switch (state) |
| 1177 | | { |
| 1178 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1179 | | case DEVINFO_STR_NAME: strcpy(info->s, "Synertek 6845E"); break; |
| 1025 | downcast<mc6845_device *>(device)->set_hpixels_per_column( hpixels_per_column ); |
| 1026 | } |
| 1180 | 1027 | |
| 1181 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1182 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(sy6845e); break; |
| 1183 | | |
| 1184 | | default: DEVICE_GET_INFO_CALL(mc6845); break; |
| 1185 | | } |
| 1028 | void mc6845_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 1029 | { |
| 1030 | downcast<mc6845_device *>(device)->update( bitmap, cliprect ); |
| 1186 | 1031 | } |
| 1187 | 1032 | |
| 1188 | | DEFINE_LEGACY_DEVICE(MC6845, mc6845); |
| 1189 | | DEFINE_LEGACY_DEVICE(MC6845_1, mc6845_1); |
| 1190 | | DEFINE_LEGACY_DEVICE(R6545_1, r6545_1); |
| 1191 | | DEFINE_LEGACY_DEVICE(C6545_1, c6545_1); |
| 1192 | | DEFINE_LEGACY_DEVICE(H46505, h46505); |
| 1193 | | DEFINE_LEGACY_DEVICE(HD6845, hd6845); |
| 1194 | | DEFINE_LEGACY_DEVICE(SY6545_1, sy6545_1); |
| 1195 | | DEFINE_LEGACY_DEVICE(SY6845E, sy6845e); |
| 1033 | |
src/emu/video/mc6845.h
| r11542 | r11543 | |
| 10 | 10 | #ifndef __MC6845__ |
| 11 | 11 | #define __MC6845__ |
| 12 | 12 | |
| 13 | | #include "devlegcy.h" |
| 13 | #include "emu.h" |
| 14 | #include "machine/devhelpr.h" |
| 14 | 15 | |
| 15 | | DECLARE_LEGACY_DEVICE(MC6845, mc6845); |
| 16 | | DECLARE_LEGACY_DEVICE(MC6845_1, mc6845_1); |
| 17 | | DECLARE_LEGACY_DEVICE(R6545_1, r6545_1); |
| 18 | | DECLARE_LEGACY_DEVICE(C6545_1, c6545_1); |
| 19 | | DECLARE_LEGACY_DEVICE(H46505, h46505); |
| 20 | | DECLARE_LEGACY_DEVICE(HD6845, hd6845); |
| 21 | | DECLARE_LEGACY_DEVICE(SY6545_1, sy6545_1); |
| 22 | | DECLARE_LEGACY_DEVICE(SY6845E, sy6845e); |
| 23 | 16 | |
| 17 | #define MC6845_INTERFACE(name) \ |
| 18 | const mc6845_interface (name) = |
| 24 | 19 | |
| 25 | 20 | #define MCFG_MC6845_ADD(_tag, _variant, _clock, _config) \ |
| 26 | 21 | MCFG_DEVICE_ADD(_tag, _variant, _clock) \ |
| 27 | 22 | MCFG_DEVICE_CONFIG(_config) |
| 28 | 23 | |
| 29 | 24 | |
| 25 | class mc6845_device; |
| 26 | |
| 30 | 27 | /* callback definitions */ |
| 31 | | typedef void * (*mc6845_begin_update_func)(device_t *device, bitmap_t *bitmap, const rectangle *cliprect); |
| 32 | | #define MC6845_BEGIN_UPDATE(name) void *name(device_t *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 28 | typedef void * (*mc6845_begin_update_func)(mc6845_device *device, bitmap_t *bitmap, const rectangle *cliprect); |
| 29 | #define MC6845_BEGIN_UPDATE(name) void *name(mc6845_device *device, bitmap_t *bitmap, const rectangle *cliprect) |
| 33 | 30 | |
| 34 | | typedef void (*mc6845_update_row_func)(device_t *device, bitmap_t *bitmap, |
| 31 | |
| 32 | typedef void (*mc6845_update_row_func)(mc6845_device *device, bitmap_t *bitmap, |
| 35 | 33 | const rectangle *cliprect, UINT16 ma, UINT8 ra, |
| 36 | 34 | UINT16 y, UINT8 x_count, INT8 cursor_x, void *param); |
| 37 | | #define MC6845_UPDATE_ROW(name) void name(device_t *device, bitmap_t *bitmap, \ |
| 35 | |
| 36 | |
| 37 | #define MC6845_UPDATE_ROW(name) void name(mc6845_device *device, bitmap_t *bitmap, \ |
| 38 | 38 | const rectangle *cliprect, UINT16 ma, UINT8 ra, \ |
| 39 | 39 | UINT16 y, UINT8 x_count, INT8 cursor_x, void *param) |
| 40 | 40 | |
| 41 | | typedef void (*mc6845_end_update_func)(device_t *device, bitmap_t *bitmap, const rectangle *cliprect, void *param); |
| 42 | | #define MC6845_END_UPDATE(name) void name(device_t *device, bitmap_t *bitmap, const rectangle *cliprect, void *param) |
| 43 | 41 | |
| 44 | | typedef void (*mc6845_on_update_addr_changed_func)(device_t *device, int address, int strobe); |
| 45 | | #define MC6845_ON_UPDATE_ADDR_CHANGED(name) void name(device_t *device, int address, int strobe) |
| 42 | typedef void (*mc6845_end_update_func)(mc6845_device *device, bitmap_t *bitmap, const rectangle *cliprect, void *param); |
| 43 | #define MC6845_END_UPDATE(name) void name(mc6845_device *device, bitmap_t *bitmap, const rectangle *cliprect, void *param) |
| 46 | 44 | |
| 45 | |
| 46 | typedef void (*mc6845_on_update_addr_changed_func)(mc6845_device *device, int address, int strobe); |
| 47 | #define MC6845_ON_UPDATE_ADDR_CHANGED(name) void name(mc6845_device *device, int address, int strobe) |
| 48 | |
| 49 | |
| 47 | 50 | /* interface */ |
| 48 | 51 | typedef struct _mc6845_interface mc6845_interface; |
| 49 | 52 | struct _mc6845_interface |
| 50 | 53 | { |
| 51 | | const char *screen_tag; /* screen we are acting on */ |
| 52 | | int hpixels_per_column; /* number of pixels per video memory address */ |
| 54 | const char *m_screen_tag; /* screen we are acting on */ |
| 55 | int m_hpixels_per_column; /* number of pixels per video memory address */ |
| 53 | 56 | |
| 54 | 57 | /* if specified, this gets called before any pixel update, |
| 55 | 58 | optionally return a pointer that will be passed to the |
| 56 | 59 | update and tear down callbacks */ |
| 57 | | mc6845_begin_update_func begin_update; |
| 60 | mc6845_begin_update_func m_begin_update; |
| 58 | 61 | |
| 59 | 62 | /* this gets called for every row, the driver must output |
| 60 | 63 | x_count * hpixels_per_column pixels. |
| 61 | 64 | cursor_x indicates the character position where the cursor is, or -1 |
| 62 | 65 | if there is no cursor on this row */ |
| 63 | | mc6845_update_row_func update_row; |
| 66 | mc6845_update_row_func m_update_row; |
| 64 | 67 | |
| 65 | 68 | /* if specified, this gets called after all row updating is complete */ |
| 66 | | mc6845_end_update_func end_update; |
| 69 | mc6845_end_update_func m_end_update; |
| 67 | 70 | |
| 68 | 71 | /* if specified, this gets called for every change of the disply enable pin (pin 18) */ |
| 69 | | devcb_write_line out_de_func; |
| 72 | devcb_write_line m_out_de_func; |
| 70 | 73 | |
| 71 | 74 | /* if specified, this gets called for every change of the cursor pin (pin 19) */ |
| 72 | | devcb_write_line out_cur_func; |
| 75 | devcb_write_line m_out_cur_func; |
| 73 | 76 | |
| 74 | 77 | /* if specified, this gets called for every change of the HSYNC pin (pin 39) */ |
| 75 | | devcb_write_line out_hsync_func; |
| 78 | devcb_write_line m_out_hsync_func; |
| 76 | 79 | |
| 77 | 80 | /* if specified, this gets called for every change of the VSYNC pin (pin 40) */ |
| 78 | | devcb_write_line out_vsync_func; |
| 81 | devcb_write_line m_out_vsync_func; |
| 79 | 82 | |
| 80 | 83 | /* Called whenenever the update address changes |
| 81 | 84 | * For vblank/hblank timing strobe indicates the physical update. |
| 82 | 85 | * vblank/hblank timing not supported yet! */ |
| 83 | 86 | |
| 84 | | mc6845_on_update_addr_changed_func on_update_addr_changed; |
| 87 | mc6845_on_update_addr_changed_func m_on_update_addr_changed; |
| 85 | 88 | }; |
| 86 | 89 | |
| 87 | | extern const mc6845_interface mc6845_null_interface; |
| 88 | 90 | |
| 91 | class mc6845_device : public device_t, |
| 92 | public mc6845_interface |
| 93 | { |
| 94 | friend class mc6845_1_device; |
| 95 | friend class r6545_1_device; |
| 96 | friend class c6545_1_device; |
| 97 | friend class h46505_device; |
| 98 | friend class hd6845_device; |
| 99 | friend class sy6545_1_device; |
| 100 | friend class sy6845e_device; |
| 89 | 101 | |
| 90 | | /* select one of the registers for reading or writing */ |
| 102 | |
| 103 | public: |
| 104 | // construction/destruction |
| 105 | mc6845_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 106 | mc6845_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock); |
| 107 | |
| 108 | /* select one of the registers for reading or writing */ |
| 109 | void address_w(UINT8 data); |
| 110 | |
| 111 | /* read from the status register */ |
| 112 | UINT8 status_r(); |
| 113 | |
| 114 | /* read from the currently selected register */ |
| 115 | UINT8 register_r(); |
| 116 | |
| 117 | /* write to the currently selected register */ |
| 118 | void register_w(UINT8 data); |
| 119 | |
| 120 | /* return the current value on the MA0-MA13 pins */ |
| 121 | UINT16 get_ma(); |
| 122 | |
| 123 | /* return the current value on the RA0-RA4 pins */ |
| 124 | UINT8 get_ra(); |
| 125 | |
| 126 | /* simulates the LO->HI clocking of the light pen pin (pin 3) */ |
| 127 | void assert_light_pen_input(); |
| 128 | |
| 129 | /* set the clock (pin 21) of the chip */ |
| 130 | void set_clock(int clock); |
| 131 | |
| 132 | /* set number of pixels per video memory address */ |
| 133 | void set_hpixels_per_column(int hpixels_per_column); |
| 134 | |
| 135 | /* updates the screen -- this will call begin_update(), |
| 136 | followed by update_row() reapeatedly and after all row |
| 137 | updating is complete, end_update() */ |
| 138 | void update(bitmap_t *bitmap, const rectangle *cliprect); |
| 139 | |
| 140 | protected: |
| 141 | // device-level overrides |
| 142 | virtual void device_config_complete(); |
| 143 | virtual void device_start(); |
| 144 | virtual void device_reset(); |
| 145 | virtual void device_post_load(); |
| 146 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 147 | |
| 148 | private: |
| 149 | bool m_supports_disp_start_addr_r; |
| 150 | bool m_supports_vert_sync_width; |
| 151 | bool m_supports_status_reg_d5; |
| 152 | bool m_supports_status_reg_d6; |
| 153 | bool m_supports_status_reg_d7; |
| 154 | bool m_supports_transparent; |
| 155 | |
| 156 | devcb_resolved_write_line m_res_out_de_func; |
| 157 | devcb_resolved_write_line m_res_out_cur_func; |
| 158 | devcb_resolved_write_line m_res_out_hsync_func; |
| 159 | devcb_resolved_write_line m_res_out_vsync_func; |
| 160 | |
| 161 | int m_device_type; |
| 162 | screen_device *m_screen; |
| 163 | |
| 164 | /* register file */ |
| 165 | UINT8 m_horiz_char_total; /* 0x00 */ |
| 166 | UINT8 m_horiz_disp; /* 0x01 */ |
| 167 | UINT8 m_horiz_sync_pos; /* 0x02 */ |
| 168 | UINT8 m_sync_width; /* 0x03 */ |
| 169 | UINT8 m_vert_char_total; /* 0x04 */ |
| 170 | UINT8 m_vert_total_adj; /* 0x05 */ |
| 171 | UINT8 m_vert_disp; /* 0x06 */ |
| 172 | UINT8 m_vert_sync_pos; /* 0x07 */ |
| 173 | UINT8 m_mode_control; /* 0x08 */ |
| 174 | UINT8 m_max_ras_addr; /* 0x09 */ |
| 175 | UINT8 m_cursor_start_ras; /* 0x0a */ |
| 176 | UINT8 m_cursor_end_ras; /* 0x0b */ |
| 177 | UINT16 m_disp_start_addr; /* 0x0c/0x0d */ |
| 178 | UINT16 m_cursor_addr; /* 0x0e/0x0f */ |
| 179 | UINT16 m_light_pen_addr; /* 0x10/0x11 */ |
| 180 | UINT16 m_update_addr; /* 0x12/0x13 */ |
| 181 | |
| 182 | /* other internal state */ |
| 183 | UINT8 m_register_address_latch; |
| 184 | bool m_cursor_state; |
| 185 | UINT8 m_cursor_blink_count; |
| 186 | bool m_update_ready_bit; |
| 187 | /* output signals */ |
| 188 | int m_cur; |
| 189 | int m_hsync; |
| 190 | int m_vsync; |
| 191 | int m_de; |
| 192 | |
| 193 | /* internal counters */ |
| 194 | UINT8 m_character_counter; /* Not used yet */ |
| 195 | UINT8 m_hsync_width_counter; /* Not used yet */ |
| 196 | UINT8 m_line_counter; |
| 197 | UINT8 m_raster_counter; |
| 198 | UINT8 m_adjust_counter; |
| 199 | UINT8 m_vsync_width_counter; |
| 200 | |
| 201 | bool m_line_enable_ff; /* Internal flip flop which is set when the line_counter is reset and reset when vert_disp is reached */ |
| 202 | UINT8 m_vsync_ff; |
| 203 | UINT8 m_adjust_active; |
| 204 | UINT16 m_line_address; |
| 205 | INT16 m_cursor_x; |
| 206 | |
| 207 | /* timers */ |
| 208 | static const device_timer_id TIMER_LINE = 0; |
| 209 | static const device_timer_id TIMER_DE_OFF = 1; |
| 210 | static const device_timer_id TIMER_CUR_ON = 2; |
| 211 | static const device_timer_id TIMER_CUR_OFF = 3; |
| 212 | static const device_timer_id TIMER_HSYNC_ON = 4; |
| 213 | static const device_timer_id TIMER_HSYNC_OFF = 5; |
| 214 | static const device_timer_id TIMER_LIGHT_PEN_LATCH = 6; |
| 215 | static const device_timer_id TIMER_UPD_ADR = 7; |
| 216 | static const device_timer_id TIMER_UPD_TRANS = 8; |
| 217 | |
| 218 | emu_timer *m_line_timer; |
| 219 | emu_timer *m_de_off_timer; |
| 220 | emu_timer *m_cur_on_timer; |
| 221 | emu_timer *m_cur_off_timer; |
| 222 | emu_timer *m_hsync_on_timer; |
| 223 | emu_timer *m_hsync_off_timer; |
| 224 | emu_timer *m_light_pen_latch_timer; |
| 225 | emu_timer *m_upd_adr_timer; |
| 226 | emu_timer *m_upd_trans_timer; |
| 227 | |
| 228 | /* computed values - do NOT state save these! */ |
| 229 | /* These computed are used to define the screen parameters for a driver */ |
| 230 | UINT16 m_horiz_pix_total; |
| 231 | UINT16 m_vert_pix_total; |
| 232 | UINT16 m_max_visible_x; |
| 233 | UINT16 m_max_visible_y; |
| 234 | UINT16 m_hsync_on_pos; |
| 235 | UINT16 m_hsync_off_pos; |
| 236 | UINT16 m_vsync_on_pos; |
| 237 | UINT16 m_vsync_off_pos; |
| 238 | bool m_has_valid_parameters; |
| 239 | |
| 240 | UINT16 m_current_disp_addr; /* the display address currently drawn (used only in mc6845_update) */ |
| 241 | |
| 242 | bool m_light_pen_latched; |
| 243 | attotime m_upd_time; |
| 244 | |
| 245 | void update_upd_adr_timer(); |
| 246 | void call_on_update_address(int strobe); |
| 247 | void recompute_parameters(bool postload); |
| 248 | void update_counters(); |
| 249 | void set_de(int state); |
| 250 | void set_hsync(int state); |
| 251 | void set_vsync(int state); |
| 252 | void set_cur(int state); |
| 253 | void handle_line_timer(); |
| 254 | void update_cursor_state(); |
| 255 | }; |
| 256 | |
| 257 | |
| 258 | class mc6845_1_device : public mc6845_device |
| 259 | { |
| 260 | public: |
| 261 | mc6845_1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 262 | |
| 263 | protected: |
| 264 | virtual void device_start(); |
| 265 | virtual void device_reset(); |
| 266 | }; |
| 267 | |
| 268 | class r6545_1_device : public mc6845_device |
| 269 | { |
| 270 | public: |
| 271 | r6545_1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 272 | |
| 273 | protected: |
| 274 | virtual void device_start(); |
| 275 | virtual void device_reset(); |
| 276 | }; |
| 277 | |
| 278 | class c6545_1_device : public mc6845_device |
| 279 | { |
| 280 | public: |
| 281 | c6545_1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 282 | |
| 283 | protected: |
| 284 | virtual void device_start(); |
| 285 | virtual void device_reset(); |
| 286 | }; |
| 287 | |
| 288 | class h46505_device : public mc6845_device |
| 289 | { |
| 290 | public: |
| 291 | h46505_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 292 | |
| 293 | protected: |
| 294 | virtual void device_start(); |
| 295 | virtual void device_reset(); |
| 296 | }; |
| 297 | |
| 298 | class hd6845_device : public mc6845_device |
| 299 | { |
| 300 | public: |
| 301 | hd6845_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 302 | |
| 303 | protected: |
| 304 | virtual void device_start(); |
| 305 | virtual void device_reset(); |
| 306 | }; |
| 307 | |
| 308 | class sy6545_1_device : public mc6845_device |
| 309 | { |
| 310 | public: |
| 311 | sy6545_1_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 312 | |
| 313 | protected: |
| 314 | virtual void device_start(); |
| 315 | virtual void device_reset(); |
| 316 | }; |
| 317 | |
| 318 | class sy6845e_device : public mc6845_device |
| 319 | { |
| 320 | public: |
| 321 | sy6845e_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 322 | |
| 323 | protected: |
| 324 | virtual void device_start(); |
| 325 | virtual void device_reset(); |
| 326 | }; |
| 327 | |
| 328 | |
| 329 | extern const device_type MC6845; |
| 330 | extern const device_type MC6845_1; |
| 331 | extern const device_type R6545_1; |
| 332 | extern const device_type C6545_1; |
| 333 | extern const device_type H46505; |
| 334 | extern const device_type HD6845; |
| 335 | extern const device_type SY6545_1; |
| 336 | extern const device_type SY6845E; |
| 337 | |
| 338 | |
| 91 | 339 | WRITE8_DEVICE_HANDLER( mc6845_address_w ); |
| 92 | | |
| 93 | | /* read from the status register */ |
| 94 | 340 | READ8_DEVICE_HANDLER( mc6845_status_r ); |
| 95 | | |
| 96 | | /* read from the currently selected register */ |
| 97 | 341 | READ8_DEVICE_HANDLER( mc6845_register_r ); |
| 98 | | |
| 99 | | /* write to the currently selected register */ |
| 100 | 342 | WRITE8_DEVICE_HANDLER( mc6845_register_w ); |
| 101 | | |
| 102 | | /* return the current value on the MA0-MA13 pins */ |
| 103 | 343 | UINT16 mc6845_get_ma(device_t *device); |
| 104 | | |
| 105 | | /* return the current value on the RA0-RA4 pins */ |
| 106 | 344 | UINT8 mc6845_get_ra(device_t *device); |
| 107 | | |
| 108 | | /* simulates the LO->HI clocking of the light pen pin (pin 3) */ |
| 109 | 345 | void mc6845_assert_light_pen_input(device_t *device); |
| 110 | | |
| 111 | | /* set the clock (pin 21) of the chip */ |
| 112 | 346 | void mc6845_set_clock(device_t *device, int clock); |
| 113 | | |
| 114 | | /* set number of pixels per video memory address */ |
| 115 | 347 | void mc6845_set_hpixels_per_column(device_t *device, int hpixels_per_column); |
| 116 | | |
| 117 | | /* updates the screen -- this will call begin_update(), |
| 118 | | followed by update_row() reapeatedly and after all row |
| 119 | | updating is complete, end_update() */ |
| 120 | 348 | void mc6845_update(device_t *device, bitmap_t *bitmap, const rectangle *cliprect); |
| 121 | 349 | |
| 122 | 350 | #endif |