src/mess/video/mbee.c
| r9399 | r9400 | |
| 20 | 20 | |
| 21 | 21 | TODO: |
| 22 | 22 | |
| 23 | | 1. Above test 3 doesn't work. EDASM calls Basic to get keys, but |
| 24 | | it just gets stuck (you can see it in the debugger) for no reason |
| 25 | | whatsoever. Yet if you single-step the debugger, supplying values |
| 26 | | as necessary, it works. g a428 to test. |
| 27 | | |
| 28 | | 2. mbeeppc keyboard response is quite slow. You need to hold each |
| 23 | 1. mbeeppc keyboard response is quite slow. You need to hold each |
| 29 | 24 | key until it responds. It works much better if you overclock the cpu. |
| 30 | 25 | |
| 31 | 26 | ****************************************************************************/ |
| r9399 | r9400 | |
| 33 | 28 | #include "emu.h" |
| 34 | 29 | #include "includes/mbee.h" |
| 35 | 30 | |
| 36 | | typedef struct { // CRTC 6545 |
| 37 | | UINT8 horizontal_total; |
| 38 | | UINT8 horizontal_displayed; |
| 39 | | UINT8 horizontal_sync_pos; |
| 40 | | UINT8 horizontal_length; |
| 41 | | UINT8 vertical_total; |
| 42 | | UINT8 vertical_adjust; |
| 43 | | UINT8 vertical_displayed; |
| 44 | | UINT8 vertical_sync_pos; |
| 45 | | UINT8 crt_mode; |
| 46 | | UINT8 scan_lines; |
| 47 | | UINT8 cursor_top; |
| 48 | | UINT8 cursor_bottom; |
| 49 | | UINT8 screen_address_hi; |
| 50 | | UINT8 screen_address_lo; |
| 51 | | UINT8 cursor_address_hi; |
| 52 | | UINT8 cursor_address_lo; |
| 53 | | UINT8 lpen_hi; |
| 54 | | UINT8 lpen_lo; |
| 55 | | UINT8 transp_hi; |
| 56 | | UINT8 transp_lo; |
| 57 | | UINT8 idx; |
| 58 | | UINT8 cursor_visible; |
| 59 | | UINT8 cursor_phase; |
| 60 | | UINT8 lpen_strobe; |
| 61 | | UINT8 update_strobe; |
| 62 | | } CRTC6545; |
| 63 | | |
| 64 | | static CRTC6545 crt; |
| 65 | 31 | static UINT8 framecnt = 0; |
| 66 | | |
| 67 | 32 | static UINT8 *gfxram; |
| 68 | 33 | static UINT8 *colorram; |
| 69 | 34 | static UINT8 *videoram; |
| r9399 | r9400 | |
| 72 | 37 | static UINT8 mbee_0b; |
| 73 | 38 | static UINT8 mbee_1c; |
| 74 | 39 | static UINT8 is_premium; |
| 75 | | static UINT8 mc6845_cursor[16]; // cursor shape |
| 76 | | static void mc6845_cursor_configure(void); |
| 77 | | static void mc6845_screen_configure(running_machine *machine); |
| 40 | static UINT8 sy6545_cursor[16]; |
| 41 | static UINT8 sy6545_status = 0; |
| 42 | static void sy6545_cursor_configure(void); |
| 78 | 43 | static running_device *mc6845; |
| 79 | 44 | static UINT8 speed,flash; |
| 80 | 45 | static UINT16 cursor; |
| 46 | static UINT8 sy6545_reg[20]; /* registers */ |
| 47 | static UINT8 sy6545_ind; /* register index */ |
| 48 | static const UINT8 sy6545_mask[32]={0xff,0xff,0xff,0x0f,0x7f,0x1f,0x7f,0x7f,3,0x1f,0x7f,0x1f,0x3f,0xff,0x3f,0xff,0,0,0x3f,0xff}; |
| 81 | 49 | |
| 82 | 50 | |
| 51 | |
| 83 | 52 | /*********************************************************** |
| 84 | 53 | |
| 85 | 54 | Handlers of video, colour, and attribute RAM |
| r9399 | r9400 | |
| 259 | 228 | |
| 260 | 229 | if( data ) |
| 261 | 230 | { |
| 262 | | crt.lpen_lo = offs; |
| 263 | | crt.lpen_hi = (offs >> 8) & 0x3f; |
| 264 | | crt.lpen_strobe = 1; |
| 231 | sy6545_reg[17] = offs; |
| 232 | sy6545_reg[16] = (offs >> 8) & 0x3f; |
| 233 | sy6545_status |= 0x40; //lpen_strobe |
| 265 | 234 | } |
| 266 | 235 | } |
| 267 | 236 | |
| r9399 | r9400 | |
| 285 | 254 | screen_device *screen = screen_first(*space->machine); |
| 286 | 255 | const rectangle &visarea = screen->visible_area(); |
| 287 | 256 | |
| 288 | | int data = 0, y = space->machine->primary_screen->vpos(); |
| 257 | UINT8 data = sy6545_status; |
| 258 | int y = space->machine->primary_screen->vpos(); |
| 289 | 259 | |
| 290 | | if( y < visarea.min_y || |
| 291 | | y > visarea.max_y ) |
| 260 | if( y < visarea.min_y || y > visarea.max_y ) |
| 292 | 261 | data |= 0x20; /* vertical blanking */ |
| 293 | | if( crt.lpen_strobe ) |
| 294 | | data |= 0x40; /* lpen register full */ |
| 295 | | if( crt.update_strobe ) |
| 296 | | data |= 0x80; /* update strobe has occured */ |
| 297 | 262 | |
| 298 | 263 | return data; |
| 299 | 264 | } |
| r9399 | r9400 | |
| 302 | 267 | { |
| 303 | 268 | int addr, data = 0; |
| 304 | 269 | |
| 305 | | switch( crt.idx ) |
| 270 | switch( sy6545_ind ) |
| 306 | 271 | { |
| 307 | | /* These are write only on a Rockwell 6545 */ |
| 308 | | #if 0 |
| 309 | | case 0: |
| 310 | | return crt.horizontal_total; |
| 311 | | case 1: |
| 312 | | return crt.horizontal_displayed; |
| 313 | | case 2: |
| 314 | | return crt.horizontal_sync_pos; |
| 315 | | case 3: |
| 316 | | return crt.horizontal_length; |
| 317 | | case 4: |
| 318 | | return crt.vertical_total; |
| 319 | | case 5: |
| 320 | | return crt.vertical_adjust; |
| 321 | | case 6: |
| 322 | | return crt.vertical_displayed; |
| 323 | | case 7: |
| 324 | | return crt.vertical_sync_pos; |
| 325 | | case 8: |
| 326 | | return crt.crt_mode; |
| 327 | | case 9: |
| 328 | | return crt.scan_lines; |
| 329 | | case 10: |
| 330 | | return crt.cursor_top; |
| 331 | | case 11: |
| 332 | | return crt.cursor_bottom; |
| 333 | | case 12: |
| 334 | | return crt.screen_address_hi; |
| 335 | | case 13: |
| 336 | | return crt.screen_address_lo; |
| 337 | | #endif |
| 338 | | case 14: |
| 339 | | data = crt.cursor_address_hi; |
| 340 | | break; |
| 341 | | case 15: |
| 342 | | data = crt.cursor_address_lo; |
| 343 | | break; |
| 344 | 272 | case 16: |
| 345 | | crt.lpen_strobe = 0; |
| 346 | | data = crt.lpen_hi; |
| 347 | | break; |
| 348 | 273 | case 17: |
| 349 | | crt.lpen_strobe = 0; |
| 350 | | data = crt.lpen_lo; |
| 274 | sy6545_status &= 0x80; // turn off lpen_strobe |
| 351 | 275 | break; |
| 352 | | case 18: |
| 353 | | data = crt.transp_hi; |
| 354 | | break; |
| 355 | | case 19: |
| 356 | | data = crt.transp_lo; |
| 357 | | break; |
| 358 | 276 | case 31: |
| 359 | 277 | /* This firstly pushes the contents of the transparent registers onto the MA lines, |
| 360 | | then increments the address, then sets strobe on. */ |
| 361 | | addr = (crt.transp_hi << 8) | crt.transp_lo; |
| 278 | then increments the address, then sets update strobe on. */ |
| 279 | addr = (sy6545_reg[18] << 8) | sy6545_reg[19]; |
| 362 | 280 | keyboard_matrix_r(space->machine, addr); |
| 363 | | crt.transp_lo++; |
| 364 | | if (!crt.transp_lo) crt.transp_hi++; |
| 365 | | crt.update_strobe = 1; |
| 281 | sy6545_reg[19]++; |
| 282 | if (!sy6545_reg[19]) sy6545_reg[18]++; |
| 283 | sy6545_status |= 0x80; // update_strobe |
| 366 | 284 | break; |
| 367 | | default: |
| 368 | | logerror("6545 read unmapped port $%X\n", crt.idx); |
| 369 | 285 | } |
| 370 | 286 | return data; |
| 371 | 287 | } |
| 372 | 288 | |
| 373 | 289 | WRITE8_HANDLER ( m6545_index_w ) |
| 374 | 290 | { |
| 375 | | crt.idx = data & 0x1f; |
| 376 | 291 | data &= 0x1f; |
| 377 | | // mc6845_ind = data; |
| 292 | sy6545_ind = data; |
| 378 | 293 | mc6845_address_w( mc6845, 0, data ); |
| 379 | 294 | } |
| 380 | 295 | |
| 381 | 296 | WRITE8_HANDLER ( m6545_data_w ) |
| 382 | 297 | { |
| 383 | | int addr; |
| 298 | int addr = 0; |
| 384 | 299 | |
| 385 | | switch( crt.idx ) |
| 300 | switch( sy6545_ind ) |
| 386 | 301 | { |
| 387 | | case 0: |
| 388 | | if( crt.horizontal_total == data ) |
| 389 | | break; |
| 390 | | crt.horizontal_total = data; |
| 391 | | break; |
| 392 | | case 1: |
| 393 | | crt.horizontal_displayed = data; |
| 394 | | mc6845_screen_configure(space->machine); |
| 395 | | break; |
| 396 | | case 2: |
| 397 | | if( crt.horizontal_sync_pos == data ) |
| 398 | | break; |
| 399 | | crt.horizontal_sync_pos = data; |
| 400 | | break; |
| 401 | | case 3: |
| 402 | | crt.horizontal_length = data; |
| 403 | | break; |
| 404 | | case 4: |
| 405 | | if( crt.vertical_total == data ) |
| 406 | | break; |
| 407 | | crt.vertical_total = data; |
| 408 | | break; |
| 409 | | case 5: |
| 410 | | if( crt.vertical_adjust == data ) |
| 411 | | break; |
| 412 | | crt.vertical_adjust = data; |
| 413 | | break; |
| 414 | | case 6: |
| 415 | | crt.vertical_displayed = data; |
| 416 | | mc6845_screen_configure(space->machine); |
| 417 | | break; |
| 418 | | case 7: |
| 419 | | if( crt.vertical_sync_pos == data ) |
| 420 | | break; |
| 421 | | crt.vertical_sync_pos = data; |
| 422 | | break; |
| 423 | | case 8: |
| 424 | | crt.crt_mode = data; |
| 425 | | |
| 426 | | { |
| 427 | | logerror("6545 mode_w $%02X\n", data); |
| 428 | | logerror(" interlace %d\n", data & 3); |
| 429 | | logerror(" addr mode %d\n", (data >> 2) & 1); |
| 430 | | logerror(" refresh RAM %s\n", ((data >> 3) & 1) ? "transparent" : "shared"); |
| 431 | | logerror(" disp enb, skew %d\n", (data >> 4) & 3); |
| 432 | | logerror(" pin 34 %s\n", ((data >> 6) & 1) ? "update strobe" : "RA4"); |
| 433 | | logerror(" update read mode %s\n", ((data >> 7) & 1) ? "interleaved" : "during h/v-blank"); |
| 434 | | } |
| 435 | | break; |
| 436 | | case 9: |
| 437 | | data &= 15; |
| 438 | | if( crt.scan_lines == data ) |
| 439 | | break; |
| 440 | | crt.scan_lines = data; |
| 441 | | mc6845_screen_configure(space->machine); |
| 442 | | mc6845_cursor_configure(); |
| 443 | | break; |
| 444 | | case 10: |
| 445 | | crt.cursor_top = data; |
| 446 | | mc6845_cursor_configure(); |
| 447 | | break; |
| 448 | | case 11: |
| 449 | | crt.cursor_bottom = data; |
| 450 | | mc6845_cursor_configure(); |
| 451 | | break; |
| 452 | 302 | case 12: |
| 453 | 303 | data &= 0x3f; |
| 454 | | if( crt.screen_address_hi == data ) |
| 455 | | break; |
| 456 | | crt.screen_address_hi = data; |
| 457 | | memcpy(gfxram, memory_region(space->machine, "gfx") + ((data & 32) << 6), 0x800); |
| 304 | if( sy6545_reg[12] != data ) |
| 305 | memcpy(gfxram, memory_region(space->machine, "gfx") + (((data & 0x30) == 0x20) << 11), 0x800); |
| 458 | 306 | break; |
| 459 | | case 13: |
| 460 | | crt.screen_address_lo = data; |
| 461 | | break; |
| 462 | | case 14: |
| 463 | | crt.cursor_address_hi = data & 0x3f; |
| 464 | | break; |
| 465 | | case 15: |
| 466 | | crt.cursor_address_lo = data; |
| 467 | | break; |
| 468 | | case 16: |
| 469 | | /* lpen hi is read only */ |
| 470 | | break; |
| 471 | | case 17: |
| 472 | | /* lpen lo is read only */ |
| 473 | | break; |
| 474 | | case 18: |
| 475 | | data &= 63; |
| 476 | | crt.transp_hi = data; |
| 477 | | break; |
| 478 | | case 19: |
| 479 | | crt.transp_lo = data; |
| 480 | | break; |
| 481 | 307 | case 31: |
| 482 | 308 | /* This firstly pushes the contents of the transparent registers onto the MA lines, |
| 483 | | then increments the address, then sets strobe on. */ |
| 484 | | addr = (crt.transp_hi << 8) | crt.transp_lo; |
| 309 | then increments the address, then sets update strobe on. */ |
| 310 | addr = (sy6545_reg[18] << 8) | sy6545_reg[19]; |
| 485 | 311 | keyboard_matrix_r(space->machine, addr); |
| 486 | | crt.transp_lo++; |
| 487 | | if (!crt.transp_lo) crt.transp_hi++; |
| 488 | | crt.update_strobe = 1; |
| 312 | sy6545_reg[19]++; |
| 313 | if (!sy6545_reg[19]) sy6545_reg[18]++; |
| 314 | sy6545_status |= 0x80; // update_strobe |
| 489 | 315 | break; |
| 490 | | default: |
| 491 | | logerror("6545 write unmapped port $%X <- $%02X\n", crt.idx, data); |
| 492 | 316 | } |
| 493 | | // if (mc6845_ind < 16) mc6845_reg[mc6845_ind] = data & mc6845_mask[mc6845_ind]; /* save data in register */ |
| 494 | | // if ((mc6845_ind == 1) || (mc6845_ind == 6) || (mc6845_ind == 9)) mc6845_screen_configure(space->machine); /* adjust screen size */ |
| 495 | | // if ((mc6845_ind > 8) && (mc6845_ind < 12)) mc6845_cursor_configure(); /* adjust cursor shape - remove when mame fixed */ |
| 317 | sy6545_reg[sy6545_ind] = data & sy6545_mask[sy6545_ind]; /* save data in register */ |
| 496 | 318 | mc6845_register_w( mc6845, 0, data ); |
| 319 | if ((sy6545_ind > 8) && (sy6545_ind < 12)) sy6545_cursor_configure(); /* adjust cursor shape - remove when mame fixed */ |
| 497 | 320 | } |
| 498 | 321 | |
| 499 | 322 | |
| r9399 | r9400 | |
| 507 | 330 | |
| 508 | 331 | ************************************************************/ |
| 509 | 332 | |
| 510 | | static void mc6845_cursor_configure(void) |
| 333 | static void sy6545_cursor_configure(void) |
| 511 | 334 | { |
| 512 | 335 | UINT8 i,curs_type=0,r9,r10,r11; |
| 513 | 336 | |
| r9399 | r9400 | |
| 517 | 340 | 2 = full cursor |
| 518 | 341 | 3 = two-part cursor (has a part at the top and bottom with the middle blank) */ |
| 519 | 342 | |
| 520 | | for ( i = 0; i < ARRAY_LENGTH(mc6845_cursor); i++) mc6845_cursor[i] = 0; // prepare cursor by erasing old one |
| 343 | for ( i = 0; i < ARRAY_LENGTH(sy6545_cursor); i++) sy6545_cursor[i] = 0; // prepare cursor by erasing old one |
| 521 | 344 | |
| 522 | | r9 = crt.scan_lines; // number of scan lines - 1 |
| 523 | | r10 = crt.cursor_top & 0x1f; // cursor start line = last 5 bits |
| 524 | | r11 = crt.cursor_bottom+1; // cursor end line incremented to suit for-loops below |
| 345 | r9 = sy6545_reg[9]; // number of scan lines - 1 |
| 346 | r10 = sy6545_reg[10] & 0x1f; // cursor start line = last 5 bits |
| 347 | r11 = sy6545_reg[11]+1; // cursor end line incremented to suit for-loops below |
| 525 | 348 | |
| 526 | 349 | /* decide the curs_type by examining the registers */ |
| 527 | 350 | if (r10 < r11) curs_type=1; // start less than end, show start to end |
| r9399 | r9400 | |
| 534 | 357 | if (r11 > 16) r11=16; // truncate 5-bit register to fit our 4-bit hardware |
| 535 | 358 | |
| 536 | 359 | /* create the new cursor */ |
| 537 | | if (curs_type > 1) for (i = 0;i < ARRAY_LENGTH(mc6845_cursor);i++) mc6845_cursor[i]=0xff; // turn on full cursor |
| 360 | if (curs_type > 1) for (i = 0;i < ARRAY_LENGTH(sy6545_cursor);i++) sy6545_cursor[i]=0xff; // turn on full cursor |
| 538 | 361 | |
| 539 | | if (curs_type == 1) for (i = r10;i < r11;i++) mc6845_cursor[i]=0xff; // for each line that should show, turn on that scan line |
| 362 | if (curs_type == 1) for (i = r10;i < r11;i++) sy6545_cursor[i]=0xff; // for each line that should show, turn on that scan line |
| 540 | 363 | |
| 541 | | if (curs_type == 3) for (i = r11; i < r10;i++) mc6845_cursor[i]=0; // now take a bite out of the middle |
| 364 | if (curs_type == 3) for (i = r11; i < r10;i++) sy6545_cursor[i]=0; // now take a bite out of the middle |
| 542 | 365 | } |
| 543 | 366 | |
| 544 | 367 | |
| 545 | 368 | |
| 546 | | /*********************************************************** |
| 547 | 369 | |
| 548 | | Resize the screen within the limits of the hardware. |
| 549 | | Expand the image to fill the screen area. |
| 550 | | |
| 551 | | ************************************************************/ |
| 552 | | |
| 553 | | static void mc6845_screen_configure(running_machine *machine) |
| 554 | | { |
| 555 | | rectangle visarea; |
| 556 | | |
| 557 | | UINT16 width = crt.horizontal_displayed*8-1; // width in pixels |
| 558 | | UINT16 height = crt.vertical_displayed*(crt.scan_lines+1)-1; // height in pixels |
| 559 | | UINT16 bytes = crt.horizontal_displayed*crt.vertical_displayed-1; // video ram needed |
| 560 | | |
| 561 | | if (width > 0x27f) width=0x27f; |
| 562 | | if (height > 0x10f) height=0x10f; |
| 563 | | |
| 564 | | /* Resize the screen */ |
| 565 | | visarea.min_x = 0; |
| 566 | | visarea.max_x = width-1; |
| 567 | | visarea.min_y = 0; |
| 568 | | visarea.max_y = height-1; |
| 569 | | if (bytes < 0x800) machine->primary_screen->set_visible_area(0, width, 0, height); |
| 570 | | } |
| 571 | | |
| 572 | | |
| 573 | | |
| 574 | 370 | /*********************************************************** |
| 575 | 371 | |
| 576 | 372 | Video |
| r9399 | r9400 | |
| 607 | 403 | VIDEO_UPDATE( mbee ) |
| 608 | 404 | { |
| 609 | 405 | framecnt++; |
| 610 | | cursor = (crt.cursor_address_hi<<8) | crt.cursor_address_lo; // get cursor position |
| 611 | | speed = crt.cursor_top&0x20, flash = crt.cursor_top&0x40; // cursor modes |
| 406 | speed = sy6545_reg[10]&0x20, flash = sy6545_reg[10]&0x40; // cursor modes |
| 407 | cursor = (sy6545_reg[14]<<8) | sy6545_reg[15]; // get cursor position |
| 612 | 408 | mc6845_update(mc6845, bitmap, cliprect); |
| 613 | 409 | return 0; |
| 614 | 410 | } |
| r9399 | r9400 | |
| 645 | 441 | ((flash) && (speed) && (framecnt & 0x10)) || // (5,6)=(1,1) = cycle per 32 frames |
| 646 | 442 | ((flash) && (!speed) && (framecnt & 8))) && // (5,6)=(0,1) = cycle per 16 frames |
| 647 | 443 | (mem == cursor)) // displaying at cursor position? |
| 648 | | inv ^= mc6845_cursor[ra]; // cursor scan row |
| 444 | inv ^= sy6545_cursor[ra]; // cursor scan row |
| 649 | 445 | |
| 650 | 446 | /* get pattern of pixels for that character scanline */ |
| 651 | 447 | gfx = gfxram[(chr<<4) | ra] ^ inv; |
| r9399 | r9400 | |
| 684 | 480 | ((flash) && (speed) && (framecnt & 0x10)) || // (5,6)=(1,1) = cycle per 32 frames |
| 685 | 481 | ((flash) && (!speed) && (framecnt & 8))) && // (5,6)=(0,1) = cycle per 16 frames |
| 686 | 482 | (mem == cursor)) // displaying at cursor position? |
| 687 | | inv ^= mc6845_cursor[ra]; // cursor scan row |
| 483 | inv ^= sy6545_cursor[ra]; // cursor scan row |
| 688 | 484 | |
| 689 | 485 | /* get pattern of pixels for that character scanline */ |
| 690 | 486 | gfx = gfxram[(chr<<4) | ra] ^ inv; |
| r9399 | r9400 | |
| 739 | 535 | ((flash) && (speed) && (framecnt & 0x10)) || // (5,6)=(1,1) = cycle per 32 frames |
| 740 | 536 | ((flash) && (!speed) && (framecnt & 8))) && // (5,6)=(0,1) = cycle per 16 frames |
| 741 | 537 | (mem == cursor)) // displaying at cursor position? |
| 742 | | inv ^= mc6845_cursor[ra]; // cursor scan row |
| 538 | inv ^= sy6545_cursor[ra]; // cursor scan row |
| 743 | 539 | |
| 744 | 540 | /* get pattern of pixels for that character scanline */ |
| 745 | 541 | gfx = gfxram[(chr<<4) | ra] ^ inv; |