src/emu/video/mc6845.c
| r1812 | r1813 | |
| 26 | 26 | #include "mc6845.h" |
| 27 | 27 | |
| 28 | 28 | |
| 29 | | #define LOG (0) |
| 29 | #define LOG (1) |
| 30 | 30 | |
| 31 | 31 | |
| 32 | /* device types */ |
| 33 | enum |
| 34 | { |
| 35 | TYPE_MC6845, |
| 36 | TYPE_R6545 |
| 37 | }; |
| 38 | |
| 39 | |
| 32 | 40 | struct _mc6845_t |
| 33 | 41 | { |
| 42 | int device_type; |
| 34 | 43 | running_machine *machine; |
| 35 | 44 | const mc6845_interface *intf; |
| 36 | 45 | |
| 37 | 46 | /* internal registers */ |
| 38 | 47 | UINT8 address_latch; |
| 39 | | UINT8 horiz_total; |
| 48 | UINT8 horiz_char_total; |
| 40 | 49 | UINT8 horiz_disp; |
| 41 | 50 | UINT8 horiz_sync_pos; |
| 42 | | UINT8 horiz_sync_width; |
| 43 | | UINT8 vert_total; |
| 51 | UINT8 sync_width; |
| 52 | UINT8 vert_char_total; |
| 44 | 53 | UINT8 vert_total_adj; |
| 45 | 54 | UINT8 vert_disp; |
| 46 | 55 | UINT8 vert_sync_pos; |
| r1812 | r1813 | |
| 52 | 61 | UINT16 cursor_addr; |
| 53 | 62 | UINT16 light_pen_addr; |
| 54 | 63 | |
| 64 | /* other internal state */ |
| 65 | UINT8 cursor_state; /* 0 = off, 1 = on */ |
| 66 | UINT8 cursor_blink_count; |
| 67 | |
| 68 | /* timers */ |
| 55 | 69 | emu_timer *de_changed_timer; |
| 56 | 70 | emu_timer *hsync_on_timer; |
| 57 | 71 | emu_timer *hsync_off_timer; |
| 58 | 72 | emu_timer *vsync_on_timer; |
| 59 | 73 | emu_timer *vsync_off_timer; |
| 60 | | UINT8 cursor_state; /* 0 = off, 1 = on */ |
| 61 | | UINT8 cursor_blink_count; |
| 74 | emu_timer *light_pen_latch_timer; |
| 62 | 75 | |
| 63 | | /* saved screen parameters so we don't call |
| 64 | | video_screen_configure() unneccessarily. |
| 65 | | Do NOT state save these! */ |
| 66 | | UINT16 last_horiz_total; |
| 67 | | UINT16 last_vert_total; |
| 68 | | UINT16 last_max_x; |
| 69 | | UINT16 last_max_y; |
| 70 | | UINT16 last_hsync_on_pos; |
| 71 | | UINT16 last_hsync_off_pos; |
| 72 | | UINT16 last_vsync_on_pos; |
| 73 | | UINT16 last_vsync_off_pos; |
| 76 | /* computed values - do NOT state save these! */ |
| 77 | UINT16 horiz_pix_total; |
| 78 | UINT16 vert_pix_total; |
| 79 | UINT16 max_visible_x; |
| 80 | UINT16 max_visible_y; |
| 81 | UINT16 hsync_on_pos; |
| 82 | UINT16 hsync_off_pos; |
| 83 | UINT16 vsync_on_pos; |
| 84 | UINT16 vsync_off_pos; |
| 74 | 85 | UINT16 current_ma; /* the MA address currently drawn */ |
| 75 | 86 | int has_valid_parameters; |
| 76 | 87 | }; |
| r1812 | r1813 | |
| 81 | 92 | static void update_de_changed_timer(mc6845_t *mc6845); |
| 82 | 93 | static void update_hsync_changed_timers(mc6845_t *mc6845); |
| 83 | 94 | static void update_vsync_changed_timers(mc6845_t *mc6845); |
| 84 | | static TIMER_CALLBACK( de_changed_timer_cb ); |
| 85 | | static TIMER_CALLBACK( vsync_on_timer_cb ); |
| 86 | | static TIMER_CALLBACK( vsync_off_timer_cb ); |
| 87 | | static TIMER_CALLBACK( hsync_on_timer_cb ); |
| 88 | | static TIMER_CALLBACK( hsync_off_timer_cb ); |
| 89 | 95 | |
| 90 | 96 | |
| 91 | 97 | static void mc6845_state_save_postload(void *param) |
| 92 | 98 | { |
| 93 | | mc6845_t *mc6845 = (mc6845_t *)param; |
| 94 | | |
| 95 | | configure_screen(mc6845, TRUE); |
| 99 | configure_screen(param, TRUE); |
| 96 | 100 | } |
| 97 | 101 | |
| 98 | 102 | |
| r1812 | r1813 | |
| 136 | 140 | |
| 137 | 141 | switch (mc6845->address_latch) |
| 138 | 142 | { |
| 139 | | case 0x00: mc6845->horiz_total = data & 0xff; break; |
| 143 | case 0x00: mc6845->horiz_char_total = data & 0xff; break; |
| 140 | 144 | case 0x01: mc6845->horiz_disp = data & 0xff; break; |
| 141 | 145 | case 0x02: mc6845->horiz_sync_pos = data & 0xff; break; |
| 142 | | case 0x03: mc6845->horiz_sync_width = data & 0x0f; break; |
| 143 | | case 0x04: mc6845->vert_total = data & 0x7f; break; |
| 146 | case 0x03: mc6845->sync_width = data & 0xff; break; |
| 147 | case 0x04: mc6845->vert_char_total = data & 0x7f; break; |
| 144 | 148 | case 0x05: mc6845->vert_total_adj = data & 0x1f; break; |
| 145 | 149 | case 0x06: mc6845->vert_disp = data & 0x7f; break; |
| 146 | 150 | case 0x07: mc6845->vert_sync_pos = data & 0x7f; break; |
| r1812 | r1813 | |
| 165 | 169 | { |
| 166 | 170 | if (mc6845->intf) |
| 167 | 171 | { |
| 172 | UINT16 hsync_on_pos, hsync_off_pos, vsync_on_pos, vsync_off_pos; |
| 173 | |
| 168 | 174 | /* compute the screen sizes */ |
| 169 | | UINT16 horiz_total = (mc6845->horiz_total + 1) * mc6845->intf->hpixels_per_column; |
| 170 | | UINT16 vert_total = (mc6845->vert_total + 1) * (mc6845->max_ras_addr + 1) + mc6845->vert_total_adj; |
| 175 | UINT16 horiz_pix_total = (mc6845->horiz_char_total + 1) * mc6845->intf->hpixels_per_column; |
| 176 | UINT16 vert_pix_total = (mc6845->vert_char_total + 1) * (mc6845->max_ras_addr + 1) + mc6845->vert_total_adj; |
| 171 | 177 | |
| 172 | 178 | /* determine the visible area, avoid division by 0 */ |
| 173 | | UINT16 max_x = mc6845->horiz_disp * mc6845->intf->hpixels_per_column - 1; |
| 174 | | UINT16 max_y = mc6845->vert_disp * (mc6845->max_ras_addr + 1) - 1; |
| 179 | UINT16 max_visible_x = mc6845->horiz_disp * mc6845->intf->hpixels_per_column - 1; |
| 180 | UINT16 max_visible_y = mc6845->vert_disp * (mc6845->max_ras_addr + 1) - 1; |
| 175 | 181 | |
| 176 | 182 | /* determine the syncing positions */ |
| 177 | | UINT16 hsync_on_pos = mc6845->horiz_sync_pos * mc6845->intf->hpixels_per_column; |
| 178 | | UINT16 hsync_off_pos = hsync_on_pos + (mc6845->horiz_sync_width * mc6845->intf->hpixels_per_column); |
| 179 | | UINT16 vsync_on_pos = mc6845->vert_sync_pos * (mc6845->max_ras_addr + 1); |
| 180 | | UINT16 vsync_off_pos = vsync_on_pos + 0x10; /* this is a constant -- non-programmable */ |
| 183 | UINT8 horiz_sync_char_width = mc6845->sync_width & 0x0f; |
| 184 | UINT8 vert_sync_pix_height = (mc6845->device_type == TYPE_MC6845) ? 0x10 : (mc6845->sync_width >> 4) & 0x0f; |
| 181 | 185 | |
| 186 | if (horiz_sync_char_width == 0) |
| 187 | horiz_sync_char_width = 0x10; |
| 188 | |
| 189 | if (vert_sync_pix_height == 0) |
| 190 | vert_sync_pix_height = 0x10; |
| 191 | |
| 192 | hsync_on_pos = mc6845->horiz_sync_pos * mc6845->intf->hpixels_per_column; |
| 193 | hsync_off_pos = hsync_on_pos + (horiz_sync_char_width * mc6845->intf->hpixels_per_column); |
| 194 | vsync_on_pos = mc6845->vert_sync_pos * (mc6845->max_ras_addr + 1); |
| 195 | vsync_off_pos = vsync_on_pos + vert_sync_pix_height; |
| 196 | |
| 197 | /* the Commodore 40xx series computers program a horizontal synch pulse that extends |
| 198 | past the scanline width. I am assume that the real device will clamp it */ |
| 199 | if (hsync_off_pos > horiz_pix_total) |
| 200 | hsync_off_pos = horiz_pix_total; |
| 201 | |
| 202 | if (vsync_off_pos > vert_pix_total) |
| 203 | vsync_off_pos = vert_pix_total; |
| 204 | |
| 182 | 205 | /* update only if screen parameters changed, unless we are coming here after loading the saved state */ |
| 183 | 206 | if (postload || |
| 184 | | (horiz_total != mc6845->last_horiz_total) || (vert_total != mc6845->last_vert_total) || |
| 185 | | (max_x != mc6845->last_max_x) || (max_y != mc6845->last_max_y) || |
| 186 | | (hsync_on_pos != mc6845->last_hsync_on_pos) || (vsync_on_pos != mc6845->last_vsync_on_pos) || |
| 187 | | (hsync_off_pos != mc6845->last_hsync_off_pos) || (vsync_off_pos != mc6845->last_vsync_off_pos)) |
| 207 | (horiz_pix_total != mc6845->horiz_pix_total) || (vert_pix_total != mc6845->vert_pix_total) || |
| 208 | (max_visible_x != mc6845->max_visible_x) || (max_visible_y != mc6845->max_visible_y) || |
| 209 | (hsync_on_pos != mc6845->hsync_on_pos) || (vsync_on_pos != mc6845->vsync_on_pos) || |
| 210 | (hsync_off_pos != mc6845->hsync_off_pos) || (vsync_off_pos != mc6845->vsync_off_pos)) |
| 188 | 211 | { |
| 189 | 212 | /* update the screen if we have valid data */ |
| 190 | | if ((horiz_total > 0) && (max_x < horiz_total) && |
| 191 | | (vert_total > 0) && (max_y < vert_total) && |
| 192 | | (hsync_off_pos <= horiz_total) && (vsync_off_pos <= vert_total) && |
| 213 | if ((horiz_pix_total > 0) && (max_visible_x < horiz_pix_total) && |
| 214 | (vert_pix_total > 0) && (max_visible_y < vert_pix_total) && |
| 215 | (hsync_on_pos <= horiz_pix_total) && (vsync_on_pos <= vert_pix_total) && |
| 193 | 216 | (hsync_on_pos != hsync_off_pos)) |
| 194 | 217 | { |
| 195 | 218 | rectangle visarea; |
| 196 | 219 | |
| 197 | | attoseconds_t refresh = HZ_TO_ATTOSECONDS(mc6845->intf->clock) * (mc6845->horiz_total + 1) * vert_total; |
| 220 | attoseconds_t refresh = HZ_TO_ATTOSECONDS(mc6845->intf->clock) * (mc6845->horiz_char_total + 1) * vert_pix_total; |
| 198 | 221 | |
| 199 | 222 | visarea.min_x = 0; |
| 200 | 223 | visarea.min_y = 0; |
| 201 | | visarea.max_x = max_x; |
| 202 | | visarea.max_y = max_y; |
| 224 | visarea.max_x = max_visible_x; |
| 225 | visarea.max_y = max_visible_y; |
| 203 | 226 | |
| 204 | 227 | 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", |
| 205 | | horiz_total, vert_total, max_x, max_y, hsync_on_pos, hsync_off_pos - 1, vsync_on_pos, vsync_off_pos - 1, 1 / ATTOSECONDS_TO_DOUBLE(refresh)); |
| 228 | 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)); |
| 206 | 229 | |
| 207 | | video_screen_configure(mc6845->intf->scrnum, horiz_total, vert_total, &visarea, refresh); |
| 230 | video_screen_configure(mc6845->intf->scrnum, horiz_pix_total, vert_pix_total, &visarea, refresh); |
| 208 | 231 | |
| 209 | 232 | mc6845->has_valid_parameters = TRUE; |
| 210 | 233 | } |
| 211 | 234 | else |
| 212 | 235 | mc6845->has_valid_parameters = FALSE; |
| 213 | 236 | |
| 214 | | mc6845->last_horiz_total = horiz_total; |
| 215 | | mc6845->last_vert_total = vert_total; |
| 216 | | mc6845->last_max_x = max_x; |
| 217 | | mc6845->last_max_y = max_y; |
| 218 | | mc6845->last_hsync_on_pos = hsync_on_pos; |
| 219 | | mc6845->last_hsync_off_pos = hsync_off_pos; |
| 220 | | mc6845->last_vsync_on_pos = vsync_on_pos; |
| 221 | | mc6845->last_vsync_off_pos = vsync_off_pos; |
| 237 | mc6845->horiz_pix_total = horiz_pix_total; |
| 238 | mc6845->vert_pix_total = vert_pix_total; |
| 239 | mc6845->max_visible_x = max_visible_x; |
| 240 | mc6845->max_visible_y = max_visible_y; |
| 241 | mc6845->hsync_on_pos = hsync_on_pos; |
| 242 | mc6845->hsync_off_pos = hsync_off_pos; |
| 243 | mc6845->vsync_on_pos = vsync_on_pos; |
| 244 | mc6845->vsync_off_pos = vsync_off_pos; |
| 222 | 245 | |
| 223 | 246 | update_de_changed_timer(mc6845); |
| 224 | 247 | update_hsync_changed_timers(mc6845); |
| r1812 | r1813 | |
| 233 | 256 | UINT16 y = video_screen_get_vpos(mc6845->intf->scrnum); |
| 234 | 257 | UINT16 x = video_screen_get_hpos(mc6845->intf->scrnum); |
| 235 | 258 | |
| 236 | | return (y <= mc6845->last_max_y) && (x <= mc6845->last_max_x); |
| 259 | return (y <= mc6845->max_visible_y) && (x <= mc6845->max_visible_x); |
| 237 | 260 | } |
| 238 | 261 | |
| 239 | 262 | |
| r1812 | r1813 | |
| 250 | 273 | { |
| 251 | 274 | /* normally, it's at end the current raster line */ |
| 252 | 275 | next_y = video_screen_get_vpos(mc6845->intf->scrnum); |
| 253 | | next_x = mc6845->last_max_x + 1; |
| 276 | next_x = mc6845->max_visible_x + 1; |
| 254 | 277 | |
| 255 | | /* but if visible width = horiz_total, then we need |
| 278 | /* but if visible width = horiz_pix_total, then we need |
| 256 | 279 | to go to the beginning of VBLANK */ |
| 257 | | if (next_x == mc6845->last_horiz_total) |
| 280 | if (next_x == mc6845->horiz_pix_total) |
| 258 | 281 | { |
| 259 | | next_y = mc6845->last_max_y + 1; |
| 282 | next_y = mc6845->max_visible_y + 1; |
| 260 | 283 | next_x = 0; |
| 261 | 284 | |
| 262 | 285 | /* abnormal case, no vertical blanking, either */ |
| 263 | | if (next_y == mc6845->last_vert_total) |
| 286 | if (next_y == mc6845->vert_pix_total) |
| 264 | 287 | next_y = -1; |
| 265 | 288 | } |
| 266 | 289 | } |
| r1812 | r1813 | |
| 269 | 292 | else |
| 270 | 293 | { |
| 271 | 294 | next_x = 0; |
| 272 | | next_y = (video_screen_get_vpos(mc6845->intf->scrnum) + 1) % mc6845->last_vert_total; |
| 295 | next_y = (video_screen_get_vpos(mc6845->intf->scrnum) + 1) % mc6845->vert_pix_total; |
| 273 | 296 | |
| 274 | 297 | /* if we would now fall in the vertical blanking, we need |
| 275 | 298 | to go to the top of the screen */ |
| 276 | | if (next_y > mc6845->last_max_y) |
| 299 | if (next_y > mc6845->max_visible_y) |
| 277 | 300 | next_y = 0; |
| 278 | 301 | } |
| 279 | 302 | |
| r1812 | r1813 | |
| 294 | 317 | UINT16 next_y; |
| 295 | 318 | |
| 296 | 319 | /* we are before the HSYNC position, we trigger on the current line */ |
| 297 | | if (video_screen_get_hpos(mc6845->intf->scrnum) < mc6845->last_hsync_on_pos) |
| 320 | if (video_screen_get_hpos(mc6845->intf->scrnum) < mc6845->hsync_on_pos) |
| 298 | 321 | next_y = video_screen_get_vpos(mc6845->intf->scrnum); |
| 299 | 322 | |
| 300 | 323 | /* trigger on the next line */ |
| 301 | 324 | else |
| 302 | | next_y = (video_screen_get_vpos(mc6845->intf->scrnum) + 1) % mc6845->last_vert_total; |
| 325 | next_y = (video_screen_get_vpos(mc6845->intf->scrnum) + 1) % mc6845->vert_pix_total; |
| 303 | 326 | |
| 304 | 327 | /* if the next line is not in the visible region, go to the beginning of the screen */ |
| 305 | | if (next_y > mc6845->last_max_y) |
| 328 | if (next_y > mc6845->max_visible_y) |
| 306 | 329 | next_y = 0; |
| 307 | 330 | |
| 308 | | timer_adjust_oneshot(mc6845->hsync_on_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, next_y, mc6845->last_hsync_on_pos) , 0); |
| 309 | | timer_adjust_oneshot(mc6845->hsync_off_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, next_y, mc6845->last_hsync_off_pos), 0); |
| 331 | timer_adjust_oneshot(mc6845->hsync_on_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, next_y, mc6845->hsync_on_pos) , 0); |
| 332 | timer_adjust_oneshot(mc6845->hsync_off_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, next_y, mc6845->hsync_off_pos), 0); |
| 310 | 333 | } |
| 311 | 334 | } |
| 312 | 335 | |
| r1812 | r1813 | |
| 315 | 338 | { |
| 316 | 339 | if (mc6845->has_valid_parameters && (mc6845->vsync_on_timer != NULL)) |
| 317 | 340 | { |
| 318 | | timer_adjust_oneshot(mc6845->vsync_on_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, mc6845->last_vsync_on_pos, 0), 0); |
| 319 | | timer_adjust_oneshot(mc6845->vsync_off_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, mc6845->last_vsync_off_pos, 0), 0); |
| 341 | timer_adjust_oneshot(mc6845->vsync_on_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, mc6845->vsync_on_pos, 0), 0); |
| 342 | timer_adjust_oneshot(mc6845->vsync_off_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, mc6845->vsync_off_pos, 0), 0); |
| 320 | 343 | } |
| 321 | 344 | } |
| 322 | 345 | |
| r1812 | r1813 | |
| 373 | 396 | |
| 374 | 397 | |
| 375 | 398 | |
| 376 | | static UINT16 get_ma_for_yx(mc6845_t *mc6845, int y, int x) |
| 399 | UINT16 mc6845_get_ma(mc6845_t *mc6845) |
| 377 | 400 | { |
| 378 | 401 | UINT16 ret; |
| 379 | 402 | |
| 403 | assert(mc6845 != NULL); |
| 404 | |
| 380 | 405 | if (mc6845->has_valid_parameters) |
| 381 | 406 | { |
| 382 | 407 | /* clamp Y/X to the visible region */ |
| 408 | int y = video_screen_get_vpos(mc6845->intf->scrnum); |
| 409 | int x = video_screen_get_hpos(mc6845->intf->scrnum); |
| 383 | 410 | |
| 384 | 411 | /* since the MA counter stops in the blanking regions, if we are in a |
| 385 | 412 | VBLANK, both X and Y are at their max */ |
| 386 | | if ((y > mc6845->last_max_y) || (x > mc6845->last_max_x)) |
| 387 | | x = mc6845->last_max_x; |
| 413 | if ((y > mc6845->max_visible_y) || (x > mc6845->max_visible_x)) |
| 414 | x = mc6845->max_visible_x; |
| 388 | 415 | |
| 389 | | if (y > mc6845->last_max_y) |
| 390 | | y = mc6845->last_max_y; |
| 416 | if (y > mc6845->max_visible_y) |
| 417 | y = mc6845->max_visible_y; |
| 391 | 418 | |
| 392 | 419 | ret = (mc6845->start_addr + |
| 393 | 420 | (y / (mc6845->max_ras_addr + 1)) * mc6845->horiz_disp + |
| r1812 | r1813 | |
| 400 | 427 | } |
| 401 | 428 | |
| 402 | 429 | |
| 403 | | UINT16 mc6845_get_ma(mc6845_t *mc6845) |
| 404 | | { |
| 405 | | UINT16 ret; |
| 406 | | |
| 407 | | assert(mc6845 != NULL); |
| 408 | | |
| 409 | | if (mc6845->has_valid_parameters) |
| 410 | | { |
| 411 | | int y = video_screen_get_vpos(mc6845->intf->scrnum); |
| 412 | | int x = video_screen_get_hpos(mc6845->intf->scrnum); |
| 413 | | |
| 414 | | ret = get_ma_for_yx(mc6845, y, x); |
| 415 | | } |
| 416 | | else |
| 417 | | ret = 0; |
| 418 | | |
| 419 | | return ret; |
| 420 | | } |
| 421 | | |
| 422 | | |
| 423 | 430 | UINT8 mc6845_get_ra(mc6845_t *mc6845) |
| 424 | 431 | { |
| 425 | 432 | UINT8 ret; |
| r1812 | r1813 | |
| 431 | 438 | /* get the current vertical raster position and clamp it to the visible region */ |
| 432 | 439 | int y = video_screen_get_vpos(mc6845->intf->scrnum); |
| 433 | 440 | |
| 434 | | if (y > mc6845->last_max_y) |
| 435 | | y = mc6845->last_max_y; |
| 441 | if (y > mc6845->max_visible_y) |
| 442 | y = mc6845->max_visible_y; |
| 436 | 443 | |
| 437 | 444 | ret = y % (mc6845->max_ras_addr + 1); |
| 438 | 445 | } |
| r1812 | r1813 | |
| 443 | 450 | } |
| 444 | 451 | |
| 445 | 452 | |
| 453 | static TIMER_CALLBACK( light_pen_latch_timer_cb ) |
| 454 | { |
| 455 | mc6845_t *mc6845 = ptr; |
| 456 | |
| 457 | mc6845->light_pen_addr = mc6845_get_ma(mc6845); |
| 458 | } |
| 459 | |
| 460 | |
| 446 | 461 | void mc6845_assert_light_pen_input(mc6845_t *mc6845) |
| 447 | 462 | { |
| 448 | 463 | int y, x; |
| 464 | int char_x; |
| 449 | 465 | |
| 450 | 466 | assert(mc6845 != NULL); |
| 451 | 467 | |
| 452 | | /* the light pen address register gets latched on the NEXT display address change */ |
| 453 | | y = video_screen_get_vpos(mc6845->intf->scrnum); |
| 454 | | x = video_screen_get_hpos(mc6845->intf->scrnum) + mc6845->intf->hpixels_per_column; |
| 468 | if (mc6845->has_valid_parameters) |
| 469 | { |
| 470 | /* get the current pixel coordinates */ |
| 471 | y = video_screen_get_vpos(mc6845->intf->scrnum); |
| 472 | x = video_screen_get_hpos(mc6845->intf->scrnum); |
| 455 | 473 | |
| 456 | | mc6845->light_pen_addr = get_ma_for_yx(mc6845, y, x); |
| 474 | /* compute the pixel coordinate of the NEXT character -- this is when the light pen latches */ |
| 475 | char_x = x / mc6845->intf->hpixels_per_column; |
| 476 | x = (char_x + 1) * mc6845->intf->hpixels_per_column; |
| 477 | |
| 478 | /* adjust if we are passed the boundaries of the screen */ |
| 479 | if (x == mc6845->horiz_pix_total) |
| 480 | { |
| 481 | y = y + 1; |
| 482 | x = 0; |
| 483 | |
| 484 | if (y == mc6845->vert_pix_total) |
| 485 | y = 0; |
| 486 | } |
| 487 | |
| 488 | /* set the timer that will latch the display address into the light pen registers */ |
| 489 | timer_adjust_oneshot(mc6845->light_pen_latch_timer, video_screen_get_time_until_pos(mc6845->intf->scrnum, y, x), 0); |
| 490 | } |
| 457 | 491 | } |
| 458 | 492 | |
| 459 | 493 | |
| r1812 | r1813 | |
| 488 | 522 | } |
| 489 | 523 | |
| 490 | 524 | |
| 491 | | void mc6845_update(mc6845_t *mc6845, mame_bitmap *bitmap, const rectangle *cliprect) |
| 525 | void mc6845_update(mc6845_t *mc6845, bitmap_t *bitmap, const rectangle *cliprect) |
| 492 | 526 | { |
| 527 | assert(mc6845 != NULL); |
| 528 | assert(bitmap != NULL); |
| 529 | assert(cliprect != NULL); |
| 530 | |
| 493 | 531 | if (mc6845->has_valid_parameters) |
| 494 | 532 | { |
| 495 | 533 | UINT16 y; |
| 496 | 534 | |
| 497 | | /* call the set up function if any */ |
| 498 | 535 | void *param = NULL; |
| 499 | 536 | |
| 500 | | if (mc6845->intf->begin_update) |
| 537 | assert(mc6845->intf != NULL); |
| 538 | assert(mc6845->intf->update_row != NULL); |
| 539 | |
| 540 | /* call the set up function if any */ |
| 541 | if (mc6845->intf->begin_update != NULL) |
| 501 | 542 | param = mc6845->intf->begin_update(mc6845->machine, mc6845, bitmap, cliprect); |
| 502 | 543 | |
| 503 | 544 | if (cliprect->min_y == 0) |
| r1812 | r1813 | |
| 534 | 575 | } |
| 535 | 576 | |
| 536 | 577 | /* call the tear down function if any */ |
| 537 | | if (mc6845->intf->end_update) |
| 578 | if (mc6845->intf->end_update != NULL) |
| 538 | 579 | mc6845->intf->end_update(mc6845->machine, mc6845, bitmap, cliprect, param); |
| 539 | 580 | |
| 540 | 581 | popmessage(NULL); |
| 541 | 582 | } |
| 542 | 583 | else |
| 543 | | popmessage("Invalid MC6845 screen parameters - display disabed!!!"); |
| 584 | popmessage("Invalid MC6845 screen parameters - display disabled!!!"); |
| 544 | 585 | } |
| 545 | 586 | |
| 546 | 587 | |
| 547 | 588 | /* device interface */ |
| 548 | | static void *mc6845_start(running_machine *machine, const char *tag, const void *static_config, const void *inline_config) |
| 589 | static void *common_start(running_machine *machine, const char *tag, const void *static_config, const void *inline_config, int device_type) |
| 549 | 590 | { |
| 550 | 591 | mc6845_t *mc6845; |
| 551 | 592 | char unique_tag[30]; |
| r1812 | r1813 | |
| 559 | 600 | mc6845 = auto_malloc(sizeof(*mc6845)); |
| 560 | 601 | memset(mc6845, 0, sizeof(*mc6845)); |
| 561 | 602 | |
| 603 | mc6845->device_type = device_type; |
| 562 | 604 | mc6845->machine = machine; |
| 563 | 605 | mc6845->intf = static_config; |
| 564 | 606 | |
| 565 | 607 | /* create the timers for the various pin notifications */ |
| 566 | | if (mc6845->intf) |
| 608 | if (mc6845->intf != NULL) |
| 567 | 609 | { |
| 568 | | if (mc6845->intf->on_de_changed) |
| 610 | if (mc6845->intf->on_de_changed != NULL) |
| 569 | 611 | mc6845->de_changed_timer = timer_alloc(de_changed_timer_cb, mc6845); |
| 570 | 612 | |
| 571 | | if (mc6845->intf->on_hsync_changed) |
| 613 | if (mc6845->intf->on_hsync_changed != NULL) |
| 572 | 614 | { |
| 573 | 615 | mc6845->hsync_on_timer = timer_alloc(hsync_on_timer_cb, mc6845); |
| 574 | 616 | mc6845->hsync_off_timer = timer_alloc(hsync_off_timer_cb, mc6845); |
| 575 | 617 | } |
| 576 | 618 | |
| 577 | | if (mc6845->intf->on_vsync_changed) |
| 619 | if (mc6845->intf->on_vsync_changed != NULL) |
| 578 | 620 | { |
| 579 | 621 | mc6845->vsync_on_timer = timer_alloc(vsync_on_timer_cb, mc6845); |
| 580 | 622 | mc6845->vsync_off_timer = timer_alloc(vsync_off_timer_cb, mc6845); |
| 581 | 623 | } |
| 582 | 624 | } |
| 583 | 625 | |
| 626 | mc6845->light_pen_latch_timer = timer_alloc(light_pen_latch_timer_cb, mc6845); |
| 627 | |
| 584 | 628 | /* register for state saving */ |
| 585 | | state_save_combine_module_and_tag(unique_tag, "mc6845", tag); |
| 629 | switch (device_type) |
| 630 | { |
| 631 | case TYPE_MC6845: |
| 632 | default: |
| 633 | state_save_combine_module_and_tag(unique_tag, "mc6845", tag); |
| 634 | break; |
| 586 | 635 | |
| 636 | case TYPE_R6545: |
| 637 | state_save_combine_module_and_tag(unique_tag, "r6545", tag); |
| 638 | break; |
| 639 | } |
| 640 | |
| 587 | 641 | state_save_register_func_postload_ptr(mc6845_state_save_postload, mc6845); |
| 588 | 642 | |
| 589 | 643 | state_save_register_item(unique_tag, 0, mc6845->address_latch); |
| 590 | | state_save_register_item(unique_tag, 0, mc6845->horiz_total); |
| 644 | state_save_register_item(unique_tag, 0, mc6845->horiz_char_total); |
| 591 | 645 | state_save_register_item(unique_tag, 0, mc6845->horiz_disp); |
| 592 | 646 | state_save_register_item(unique_tag, 0, mc6845->horiz_sync_pos); |
| 593 | | state_save_register_item(unique_tag, 0, mc6845->horiz_sync_width); |
| 594 | | state_save_register_item(unique_tag, 0, mc6845->vert_total); |
| 647 | state_save_register_item(unique_tag, 0, mc6845->sync_width); |
| 648 | state_save_register_item(unique_tag, 0, mc6845->vert_char_total); |
| 595 | 649 | state_save_register_item(unique_tag, 0, mc6845->vert_total_adj); |
| 596 | 650 | state_save_register_item(unique_tag, 0, mc6845->vert_disp); |
| 597 | 651 | state_save_register_item(unique_tag, 0, mc6845->vert_sync_pos); |
| r1812 | r1813 | |
| 608 | 662 | return mc6845; |
| 609 | 663 | } |
| 610 | 664 | |
| 665 | static void *mc6845_start(running_machine *machine, const char *tag, const void *static_config, const void *inline_config) |
| 666 | { |
| 667 | return common_start(machine, tag, static_config, inline_config, TYPE_MC6845); |
| 668 | } |
| 611 | 669 | |
| 670 | static void *r6545_start(running_machine *machine, const char *tag, const void *static_config, const void *inline_config) |
| 671 | { |
| 672 | return common_start(machine, tag, static_config, inline_config, TYPE_R6545); |
| 673 | } |
| 674 | |
| 675 | |
| 676 | static void mc6845_reset(running_machine *machine, void *token) |
| 677 | { |
| 678 | mc6845_t *mc6845 = token; |
| 679 | |
| 680 | /* internal registers remain unchanged, all outputs go low */ |
| 681 | if (mc6845->intf != NULL) |
| 682 | { |
| 683 | if (mc6845->intf->on_de_changed != NULL) |
| 684 | mc6845->intf->on_de_changed(machine, mc6845, FALSE); |
| 685 | |
| 686 | if (mc6845->intf->on_hsync_changed != NULL) |
| 687 | mc6845->intf->on_hsync_changed(machine, mc6845, FALSE); |
| 688 | |
| 689 | if (mc6845->intf->on_vsync_changed != NULL) |
| 690 | mc6845->intf->on_vsync_changed(machine, mc6845, FALSE); |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | |
| 612 | 695 | static void mc6845_set_info(running_machine *machine, void *token, UINT32 state, const deviceinfo *info) |
| 613 | 696 | { |
| 614 | 697 | switch (state) |
| r1812 | r1813 | |
| 629 | 712 | case DEVINFO_FCT_SET_INFO: info->set_info = mc6845_set_info; break; |
| 630 | 713 | case DEVINFO_FCT_START: info->start = mc6845_start; break; |
| 631 | 714 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 632 | | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 715 | case DEVINFO_FCT_RESET: info->reset = mc6845_reset; break; |
| 633 | 716 | |
| 634 | 717 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 635 | 718 | case DEVINFO_STR_NAME: info->s = "MC6845"; break; |
| 636 | 719 | case DEVINFO_STR_FAMILY: info->s = "MC6845 CRTC"; break; |
| 637 | | case DEVINFO_STR_VERSION: info->s = "1.5"; break; |
| 720 | case DEVINFO_STR_VERSION: info->s = "1.6"; break; |
| 638 | 721 | case DEVINFO_STR_SOURCE_FILE: info->s = __FILE__; break; |
| 639 | 722 | case DEVINFO_STR_CREDITS: info->s = "Copyright Nicola Salmoria and the MAME Team"; break; |
| 640 | 723 | } |
| r1812 | r1813 | |
| 647 | 730 | { |
| 648 | 731 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 649 | 732 | case DEVINFO_STR_NAME: info->s = "R6545"; break; |
| 733 | |
| 734 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 735 | case DEVINFO_FCT_START: info->start = r6545_start; break; |
| 736 | |
| 650 | 737 | default: mc6845_get_info(machine, token, state, info); break; |
| 651 | 738 | } |
| 652 | 739 | } |