src/mess/video/mbee.c
| r2298 | r2299 | |
| 39 | 39 | } CRTC6545; |
| 40 | 40 | |
| 41 | 41 | static CRTC6545 crt; |
| 42 | | static int off_x = 0; |
| 43 | | static int off_y = 0; |
| 44 | 42 | static int framecnt = 0; |
| 45 | 43 | static int m6545_color_bank = 0; |
| 46 | 44 | static int m6545_video_bank = 0; |
| 47 | 45 | static int mbee_pcg_color_latch = 0; |
| 48 | 46 | |
| 49 | 47 | int mbee_frame_counter; |
| 50 | | |
| 51 | | |
| 52 | 48 | UINT8 *pcgram; |
| 53 | 49 | |
| 50 | static UINT8 mc6845_cursor[16]; // cursor shape |
| 51 | static void mc6845_cursor_configure(void); |
| 52 | static void mc6845_screen_configure(running_machine *machine); |
| 54 | 53 | |
| 55 | 54 | WRITE8_HANDLER ( mbee_pcg_color_latch_w ) |
| 56 | 55 | { |
| r2298 | r2299 | |
| 158 | 157 | return data; |
| 159 | 158 | } |
| 160 | 159 | |
| 161 | | static void m6545_offset_xy(void) |
| 162 | | { |
| 163 | | if( crt.horizontal_sync_pos ) |
| 164 | | off_x = crt.horizontal_total - crt.horizontal_sync_pos - 23; |
| 165 | | else |
| 166 | | off_x = -24; |
| 167 | | |
| 168 | | off_y = (crt.vertical_total - crt.vertical_sync_pos) * |
| 169 | | (crt.scan_lines + 1) + crt.vertical_adjust; |
| 170 | | |
| 171 | | if( off_y < 0 ) |
| 172 | | off_y = 0; |
| 173 | | |
| 174 | | if( off_y > 128 ) |
| 175 | | off_y = 128; |
| 176 | | } |
| 177 | | |
| 178 | 160 | READ8_HANDLER ( mbee_color_bank_r ) |
| 179 | 161 | { |
| 180 | 162 | return m6545_color_bank; |
| r2298 | r2299 | |
| 312 | 294 | if( crt.horizontal_total == data ) |
| 313 | 295 | break; |
| 314 | 296 | crt.horizontal_total = data; |
| 315 | | m6545_offset_xy(); |
| 316 | 297 | break; |
| 317 | 298 | case 1: |
| 318 | 299 | crt.horizontal_displayed = data; |
| 300 | mc6845_screen_configure(machine); |
| 319 | 301 | break; |
| 320 | 302 | case 2: |
| 321 | 303 | if( crt.horizontal_sync_pos == data ) |
| 322 | 304 | break; |
| 323 | 305 | crt.horizontal_sync_pos = data; |
| 324 | | m6545_offset_xy(); |
| 325 | 306 | break; |
| 326 | 307 | case 3: |
| 327 | 308 | crt.horizontal_length = data; |
| r2298 | r2299 | |
| 330 | 311 | if( crt.vertical_total == data ) |
| 331 | 312 | break; |
| 332 | 313 | crt.vertical_total = data; |
| 333 | | m6545_offset_xy(); |
| 334 | 314 | break; |
| 335 | 315 | case 5: |
| 336 | 316 | if( crt.vertical_adjust == data ) |
| 337 | 317 | break; |
| 338 | 318 | crt.vertical_adjust = data; |
| 339 | | m6545_offset_xy(); |
| 340 | 319 | break; |
| 341 | 320 | case 6: |
| 342 | 321 | crt.vertical_displayed = data; |
| 322 | mc6845_screen_configure(machine); |
| 343 | 323 | break; |
| 344 | 324 | case 7: |
| 345 | 325 | if( crt.vertical_sync_pos == data ) |
| 346 | 326 | break; |
| 347 | 327 | crt.vertical_sync_pos = data; |
| 348 | | m6545_offset_xy(); |
| 349 | 328 | break; |
| 350 | 329 | case 8: |
| 351 | 330 | crt.crt_mode = data; |
| r2298 | r2299 | |
| 365 | 344 | if( crt.scan_lines == data ) |
| 366 | 345 | break; |
| 367 | 346 | crt.scan_lines = data; |
| 368 | | m6545_offset_xy(); |
| 347 | mc6845_screen_configure(machine); |
| 348 | mc6845_cursor_configure(); |
| 369 | 349 | break; |
| 370 | 350 | case 10: |
| 371 | 351 | crt.cursor_top = data; |
| 352 | mc6845_cursor_configure(); |
| 372 | 353 | break; |
| 373 | 354 | case 11: |
| 374 | 355 | crt.cursor_bottom = data; |
| 356 | mc6845_cursor_configure(); |
| 375 | 357 | break; |
| 376 | 358 | case 12: |
| 377 | 359 | data &= 0x3f; |
| r2298 | r2299 | |
| 418 | 400 | } |
| 419 | 401 | } |
| 420 | 402 | |
| 403 | /* The 6845 can produce a variety of cursor shapes - all are emulated here */ |
| 404 | static void mc6845_cursor_configure(void) |
| 405 | { |
| 406 | UINT8 i,curs_type=0,r9,r10,r11; |
| 407 | |
| 408 | /* curs_type holds the general cursor shape to be created |
| 409 | 0 = no cursor |
| 410 | 1 = partial cursor (only shows on a block of scan lines) |
| 411 | 2 = full cursor |
| 412 | 3 = two-part cursor (has a part at the top and bottom with the middle blank) */ |
| 413 | |
| 414 | for ( i = 0; i < ARRAY_LENGTH(mc6845_cursor); i++) mc6845_cursor[i] = 0; // prepare cursor by erasing old one |
| 415 | |
| 416 | r9 = crt.scan_lines; // number of scan lines - 1 |
| 417 | r10 = crt.cursor_top & 0x1f; // cursor start line = last 5 bits |
| 418 | r11 = crt.cursor_bottom+1; // cursor end line incremented to suit for-loops below |
| 419 | |
| 420 | /* decide the curs_type by examining the registers */ |
| 421 | if (r10 < r11) curs_type=1; // start less than end, show start to end |
| 422 | else |
| 423 | if (r10 == r11) curs_type=2; // if equal, show full cursor |
| 424 | else curs_type=3; // if start greater than end, it's a two-part cursor |
| 425 | |
| 426 | if ((r11 - 1) > r9) curs_type=2; // if end greater than scan-lines, show full cursor |
| 427 | if (r10 > r9) curs_type=0; // if start greater than scan-lines, then no cursor |
| 428 | if (r11 > 16) r11=16; // truncate 5-bit register to fit our 4-bit hardware |
| 429 | |
| 430 | /* create the new cursor */ |
| 431 | if (curs_type > 1) for (i = 0;i < ARRAY_LENGTH(mc6845_cursor);i++) mc6845_cursor[i]=0xff; // turn on full cursor |
| 432 | |
| 433 | 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 |
| 434 | |
| 435 | if (curs_type == 3) for (i = r11; i < r10;i++) mc6845_cursor[i]=0; // now take a bite out of the middle |
| 436 | } |
| 437 | |
| 438 | /* Resize the screen within the limits of the hardware. Expand the image to fill the screen area */ |
| 439 | static void mc6845_screen_configure(running_machine *machine) |
| 440 | { |
| 441 | rectangle visarea; |
| 442 | |
| 443 | UINT16 width = crt.horizontal_displayed*8-1; // width in pixels |
| 444 | UINT16 height = crt.vertical_displayed*(crt.scan_lines+1)-1; // height in pixels |
| 445 | UINT16 bytes = crt.horizontal_displayed*crt.vertical_displayed-1; // video ram needed -1 |
| 446 | |
| 447 | /* Resize the screen */ |
| 448 | visarea.min_x = 0; |
| 449 | visarea.max_x = width-1; |
| 450 | visarea.min_y = 0; |
| 451 | visarea.max_y = height-1; |
| 452 | if ((width < 610) && (height < 460) && (bytes < 0x800)) /* bounds checking to prevent an assert or violation */ |
| 453 | video_screen_set_visarea(machine->primary_screen, 0, width, 0, height); |
| 454 | } |
| 455 | |
| 421 | 456 | VIDEO_START( mbee ) |
| 422 | 457 | { |
| 423 | 458 | videoram = auto_malloc(0x800); |
| r2298 | r2299 | |
| 433 | 468 | |
| 434 | 469 | VIDEO_UPDATE( mbee ) |
| 435 | 470 | { |
| 436 | | int offs, cursor, screen_; |
| 471 | UINT16 i, bytes = crt.horizontal_displayed*crt.vertical_displayed; |
| 472 | UINT8 speed = crt.cursor_top&0x20, flash = crt.cursor_top&0x40; // cursor modes |
| 473 | UINT16 cursor = (crt.cursor_address_hi<<8) | crt.cursor_address_lo; // get cursor position |
| 474 | UINT16 screen_home = (crt.screen_address_hi<<8) | crt.screen_address_lo; // screen home offset (usually zero) |
| 437 | 475 | |
| 438 | | for( offs = 0x000; offs < 0x380; offs += 0x10 ) |
| 439 | | keyboard_matrix_r(offs); |
| 476 | for( i = 0; i < 0x380; i += 0x10 ) keyboard_matrix_r(i); |
| 440 | 477 | |
| 441 | 478 | framecnt++; |
| 442 | 479 | |
| 443 | | cursor = (crt.cursor_address_hi << 8) | crt.cursor_address_lo; |
| 444 | | screen_ = (crt.screen_address_hi << 8) | crt.screen_address_lo; |
| 480 | /* Get the graphics of the character under the cursor, xor with the visible cursor scan lines, |
| 481 | and store as character number 256. If inverse mode, drop bit 7 of character before xoring */ |
| 482 | for ( i = 0; i < ARRAY_LENGTH(mc6845_cursor); i++) |
| 483 | pcgram[0x1000+i] = pcgram[(videoram[cursor]<<4) + i] ^ mc6845_cursor[i]; |
| 445 | 484 | |
| 446 | | for (offs = 0; offs < crt.horizontal_displayed * crt.vertical_displayed; offs++) |
| 485 | decodechar(screen->machine->gfx[0],256, pcgram); // and into machine graphics |
| 486 | |
| 487 | for( i = 0; i < bytes; i++ ) |
| 447 | 488 | { |
| 448 | | int mem = ((offs + screen_) & 0x7ff); |
| 449 | | int sy = off_y - 9 + (offs / crt.horizontal_displayed) * (crt.scan_lines + 1); |
| 450 | | int sx = (off_x + 3 + (offs % crt.horizontal_displayed)) << 3; |
| 451 | | int code = videoram[mem]; |
| 452 | | drawgfx( bitmap, screen->machine->gfx[0],code,0,0,0,sx,sy, |
| 453 | | NULL,TRANSPARENCY_NONE,0); |
| 489 | int mem = ((i + screen_home) & 0x7ff); |
| 490 | int sy = (i / crt.horizontal_displayed) * (crt.scan_lines + 1); |
| 491 | int sx = (i % crt.horizontal_displayed) << 3; |
| 492 | int chr = videoram[mem]; |
| 454 | 493 | |
| 455 | | if( mem == cursor && (crt.cursor_top & 0x60) != 0x20 ) |
| 456 | | { |
| 457 | | if( (crt.cursor_top & 0x60) == 0x60 || (framecnt & 16) == 0 ) |
| 458 | | { |
| 459 | | int x, y; |
| 460 | | for( y = (crt.cursor_top & 31); y <= (crt.cursor_bottom & 31); y++ ) |
| 461 | | { |
| 462 | | if( y > crt.scan_lines ) |
| 463 | | break; |
| 464 | | for( x = 0; x < 8; x++ ) |
| 465 | | *BITMAP_ADDR16(bitmap, sy+y, sx+x) = 1; |
| 466 | | } |
| 467 | | } |
| 468 | | } |
| 494 | /* if cursor is on and we are at cursor position, show it */ |
| 495 | /* NOTE: flash rates obtained from real hardware */ |
| 496 | |
| 497 | if ((((!flash) && (!speed)) || // (5,6)=(0,0) = cursor on always |
| 498 | ((flash) && (speed) && (framecnt & 0x10)) || // (5,6)=(1,1) = cycle per 32 frames |
| 499 | ((flash) && (!speed) && (framecnt & 8))) && // (5,6)=(0,1) = cycle per 16 frames |
| 500 | (mem == cursor)) // displaying at cursor position? |
| 501 | chr = 256; // 256 = cursor character |
| 502 | |
| 503 | drawgfx( bitmap, screen->machine->gfx[0],chr,0,0,0,sx,sy, |
| 504 | cliprect,TRANSPARENCY_NONE,0); // put character on the screen |
| 469 | 505 | } |
| 470 | 506 | |
| 471 | 507 | return 0; |
| r2298 | r2299 | |
| 473 | 509 | |
| 474 | 510 | VIDEO_UPDATE( mbeeic ) |
| 475 | 511 | { |
| 476 | | int offs, cursor, screen_; |
| 512 | UINT16 i, bytes = crt.horizontal_displayed*crt.vertical_displayed; |
| 513 | UINT8 speed = crt.cursor_top&0x20, flash = crt.cursor_top&0x40; // cursor modes |
| 514 | UINT16 cursor = (crt.cursor_address_hi<<8) | crt.cursor_address_lo; // get cursor position |
| 515 | UINT16 screen_home = (crt.screen_address_hi<<8) | crt.screen_address_lo; // screen home offset (usually zero) |
| 477 | 516 | UINT16 colourm = (mbee_pcg_color_latch & 0x0e) << 7; |
| 478 | 517 | |
| 479 | | for( offs = 0x000; offs < 0x380; offs += 0x10 ) |
| 480 | | keyboard_matrix_r(offs); |
| 518 | for( i = 0; i < 0x380; i += 0x10 ) keyboard_matrix_r(i); |
| 481 | 519 | |
| 482 | 520 | framecnt++; |
| 483 | 521 | |
| 484 | | cursor = (crt.cursor_address_hi << 8) | crt.cursor_address_lo; |
| 485 | | screen_ = (crt.screen_address_hi << 8) | crt.screen_address_lo; |
| 522 | /* Get the graphics of the character under the cursor, xor with the visible cursor scan lines, |
| 523 | and store as character number 256. If inverse mode, drop bit 7 of character before xoring */ |
| 524 | for ( i = 0; i < ARRAY_LENGTH(mc6845_cursor); i++) |
| 525 | pcgram[0x1000+i] = pcgram[(videoram[cursor]<<4) + i] ^ mc6845_cursor[i]; |
| 486 | 526 | |
| 487 | | for (offs = 0; offs < crt.horizontal_displayed * crt.vertical_displayed; offs++) |
| 527 | decodechar(screen->machine->gfx[0],256, pcgram); // and into machine graphics |
| 528 | |
| 529 | for( i = 0; i < bytes; i++ ) |
| 488 | 530 | { |
| 489 | | int mem = ((offs + screen_) & 0x7ff); |
| 490 | | int sy = off_y + (offs / crt.horizontal_displayed) * (crt.scan_lines + 1); |
| 491 | | int sx = (off_x + (offs % crt.horizontal_displayed)) << 3; |
| 492 | | int code = videoram[mem]; |
| 493 | | int color = colorram[mem] | colourm; |
| 494 | | drawgfx( bitmap, screen->machine->gfx[0],code,color,0,0,sx,sy, |
| 495 | | NULL, TRANSPARENCY_NONE, 0); |
| 531 | int mem = ((i + screen_home) & 0x7ff); |
| 532 | int sy = (i / crt.horizontal_displayed) * (crt.scan_lines + 1); |
| 533 | int sx = (i % crt.horizontal_displayed) << 3; |
| 534 | int chr = videoram[mem]; |
| 535 | int col = colorram[mem] | colourm; // read a byte of colour |
| 496 | 536 | |
| 497 | | if( mem == cursor && (crt.cursor_top & 0x60) != 0x20 ) |
| 498 | | { |
| 499 | | if( (crt.cursor_top & 0x60) == 0x60 || (framecnt & 16) == 0 ) |
| 500 | | { |
| 501 | | int x, y; |
| 502 | | for( y = (crt.cursor_top & 31); y <= (crt.cursor_bottom & 31); y++ ) |
| 503 | | { |
| 504 | | if( y > crt.scan_lines ) |
| 505 | | break; |
| 506 | | for( x = 0; x < 8; x++ ) |
| 507 | | *BITMAP_ADDR16(bitmap, sy+y, sx+x) = ((color<<1)+1); /* convert to palette entry number */ |
| 508 | | } |
| 509 | | } |
| 510 | | } |
| 537 | /* if cursor is on and we are at cursor position, show it */ |
| 538 | /* NOTE: flash rates obtained from real hardware */ |
| 539 | |
| 540 | if ((((!flash) && (!speed)) || // (5,6)=(0,0) = cursor on always |
| 541 | ((flash) && (speed) && (framecnt & 0x10)) || // (5,6)=(1,1) = cycle per 32 frames |
| 542 | ((flash) && (!speed) && (framecnt & 8))) && // (5,6)=(0,1) = cycle per 16 frames |
| 543 | (mem == cursor)) // displaying at cursor position? |
| 544 | chr = 256; // 256 = cursor character |
| 545 | |
| 546 | drawgfx( bitmap, screen->machine->gfx[0],chr,col,0,0,sx,sy, |
| 547 | cliprect,TRANSPARENCY_NONE,0); // put character on the screen |
| 548 | |
| 511 | 549 | } |
| 550 | |
| 512 | 551 | return 0; |
| 513 | 552 | } |