src/mess/video/gb.c
| r4575 | r4576 | |
| 139 | 139 | }; |
| 140 | 140 | |
| 141 | 141 | /* Initialise the palettes */ |
| 142 | | PALETTE_INIT( gb ) { |
| 142 | PALETTE_INIT( gb ) |
| 143 | { |
| 143 | 144 | int ii; |
| 144 | | for( ii = 0; ii < 4; ii++) { |
| 145 | for( ii = 0; ii < 4; ii++) |
| 146 | { |
| 145 | 147 | palette_set_color_rgb(machine, ii, palette[ii*3+0], palette[ii*3+1], palette[ii*3+2]); |
| 146 | 148 | } |
| 147 | 149 | } |
| 148 | 150 | |
| 149 | | PALETTE_INIT( gbp ) { |
| 151 | PALETTE_INIT( gbp ) |
| 152 | { |
| 150 | 153 | int ii; |
| 151 | | for( ii = 0; ii < 4; ii++) { |
| 154 | for( ii = 0; ii < 4; ii++) |
| 155 | { |
| 152 | 156 | palette_set_color_rgb(machine, ii, palette[(ii + 4)*3+0], palette[(ii + 4)*3+1], palette[(ii + 4)*3+2]); |
| 153 | 157 | } |
| 154 | 158 | } |
| 155 | 159 | |
| 156 | | PALETTE_INIT( sgb ) { |
| 160 | PALETTE_INIT( sgb ) |
| 161 | { |
| 157 | 162 | int ii, r, g, b; |
| 158 | 163 | |
| 159 | | for( ii = 0; ii < 32768; ii++ ) { |
| 164 | for( ii = 0; ii < 32768; ii++ ) |
| 165 | { |
| 160 | 166 | r = (ii & 0x1F) << 3; |
| 161 | 167 | g = ((ii >> 5) & 0x1F) << 3; |
| 162 | 168 | b = ((ii >> 10) & 0x1F) << 3; |
| r4575 | r4576 | |
| 173 | 179 | sgb_pal[ii] = 0; |
| 174 | 180 | } |
| 175 | 181 | |
| 176 | | PALETTE_INIT( gbc ) { |
| 182 | PALETTE_INIT( gbc ) |
| 183 | { |
| 177 | 184 | int ii, r, g, b; |
| 178 | 185 | |
| 179 | | for( ii = 0; ii < 32768; ii++ ) { |
| 186 | for( ii = 0; ii < 32768; ii++ ) |
| 187 | { |
| 180 | 188 | r = (ii & 0x1F) << 3; |
| 181 | 189 | g = ((ii >> 5) & 0x1F) << 3; |
| 182 | 190 | b = ((ii >> 10) & 0x1F) << 3; |
| r4575 | r4576 | |
| 191 | 199 | cgb_spal[ii] = 0; |
| 192 | 200 | } |
| 193 | 201 | |
| 194 | | PALETTE_INIT( megaduck ) { |
| 202 | PALETTE_INIT( megaduck ) |
| 203 | { |
| 195 | 204 | int ii; |
| 196 | | for( ii = 0; ii < 4; ii++) { |
| 205 | for( ii = 0; ii < 4; ii++) |
| 206 | { |
| 197 | 207 | palette_set_color_rgb(machine, ii, palette_megaduck[ii*3+0], palette_megaduck[ii*3+1], palette_megaduck[ii*3+2]); |
| 198 | 208 | } |
| 199 | 209 | } |
| r4575 | r4576 | |
| 208 | 218 | Select which sprites should be drawn for the current scanline and return the |
| 209 | 219 | number of sprites selected. |
| 210 | 220 | */ |
| 211 | | static void gb_select_sprites( void ) { |
| 221 | static void gb_select_sprites( void ) |
| 222 | { |
| 212 | 223 | int i, /*yindex,*/ line, height; |
| 213 | 224 | UINT8 *oam = gb_oam + 39 * 4; |
| 214 | 225 | |
| 215 | 226 | gb_lcd.sprCount = 0; |
| 216 | 227 | |
| 217 | 228 | /* If video hardware is enabled and sprites are enabled */ |
| 218 | | if ( ( LCDCONT & 0x80 ) && ( LCDCONT & 0x02 ) ) { |
| 229 | if ( ( LCDCONT & 0x80 ) && ( LCDCONT & 0x02 ) ) |
| 230 | { |
| 219 | 231 | /* Check for stretched sprites */ |
| 220 | | if ( LCDCONT & 0x04 ) { |
| 232 | if ( LCDCONT & 0x04 ) |
| 233 | { |
| 221 | 234 | height = 16; |
| 222 | | } else { |
| 235 | } |
| 236 | else |
| 237 | { |
| 223 | 238 | height = 8; |
| 224 | 239 | } |
| 225 | 240 | |
| 226 | 241 | //yindex = gb_lcd.current_line; |
| 227 | 242 | line = gb_lcd.current_line + 16; |
| 228 | 243 | |
| 229 | | for( i = 39; i >= 0; i-- ) { |
| 230 | | if ( line >= oam[0] && line < ( oam[0] + height ) && oam[1] && oam[1] < 168 ) { |
| 244 | for( i = 39; i >= 0; i-- ) |
| 245 | { |
| 246 | if ( line >= oam[0] && line < ( oam[0] + height ) && oam[1] && oam[1] < 168 ) |
| 247 | { |
| 231 | 248 | /* We limit the sprite count to max 10 here; |
| 232 | 249 | proper games should not exceed this... */ |
| 233 | | if ( gb_lcd.sprCount < 10 ) { |
| 250 | if ( gb_lcd.sprCount < 10 ) |
| 251 | { |
| 234 | 252 | gb_lcd.sprite[gb_lcd.sprCount] = i; |
| 235 | 253 | gb_lcd.sprCount++; |
| 236 | 254 | } |
| r4575 | r4576 | |
| 327 | 345 | } |
| 328 | 346 | } |
| 329 | 347 | |
| 330 | | static void gb_update_scanline( running_machine *machine ) { |
| 348 | static void gb_update_scanline( running_machine *machine ) |
| 349 | { |
| 331 | 350 | bitmap_t *bitmap = tmpbitmap; |
| 332 | 351 | |
| 333 | 352 | profiler_mark(PROFILER_VIDEO); |
| 334 | 353 | |
| 335 | 354 | /* Make sure we're in mode 3 */ |
| 336 | | if ( ( LCDSTAT & 0x03 ) == 0x03 ) { |
| 355 | if ( ( LCDSTAT & 0x03 ) == 0x03 ) |
| 356 | { |
| 337 | 357 | /* Calculate number of pixels to render based on time still left on the timer */ |
| 338 | | UINT32 cycles_to_go = cpu_attotime_to_clocks(machine->cpu[0], timer_timeleft( gb_lcd.lcd_timer ) ); |
| 358 | UINT32 cycles_to_go = cputag_attotime_to_clocks(machine, "maincpu", timer_timeleft( gb_lcd.lcd_timer ) ); |
| 339 | 359 | int l = 0; |
| 340 | 360 | |
| 341 | | if ( gb_lcd.start_x < 0 ) { |
| 361 | if ( gb_lcd.start_x < 0 ) |
| 362 | { |
| 342 | 363 | /* Window is enabled if the hardware says so AND the current scanline is |
| 343 | 364 | * within the window AND the window X coordinate is <=166 */ |
| 344 | 365 | gb_lcd.layer[1].enabled = ( ( LCDCONT & 0x20 ) && ( gb_lcd.current_line >= WNDPOSY ) && ( WNDPOSX <= 166 ) ) ? 1 : 0; |
| r4575 | r4576 | |
| 347 | 368 | * AND window's X position is >=7 ) ) */ |
| 348 | 369 | gb_lcd.layer[0].enabled = ( ( LCDCONT & 0x01 ) && ( ( ! gb_lcd.layer[1].enabled ) || ( gb_lcd.layer[1].enabled && ( WNDPOSX >= 7 ) ) ) ) ? 1 : 0; |
| 349 | 370 | |
| 350 | | if ( gb_lcd.layer[0].enabled ) { |
| 371 | if ( gb_lcd.layer[0].enabled ) |
| 372 | { |
| 351 | 373 | gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF; |
| 352 | 374 | gb_lcd.layer[0].bg_map = gb_bgdtab; |
| 353 | 375 | gb_lcd.layer[0].bg_tiles = gb_chrgen; |
| r4575 | r4576 | |
| 357 | 379 | gb_lcd.layer[0].xend = 160; |
| 358 | 380 | } |
| 359 | 381 | |
| 360 | | if ( gb_lcd.layer[1].enabled ) { |
| 382 | if ( gb_lcd.layer[1].enabled ) |
| 383 | { |
| 361 | 384 | int xpos; |
| 362 | 385 | |
| 363 | 386 | xpos = WNDPOSX - 7; /* Window is offset by 7 pixels */ |
| r4575 | r4576 | |
| 376 | 399 | gb_lcd.start_x = 0; |
| 377 | 400 | } |
| 378 | 401 | |
| 379 | | if ( cycles_to_go < 160 ) { |
| 402 | if ( cycles_to_go < 160 ) |
| 403 | { |
| 380 | 404 | gb_lcd.end_x = MIN(160 - cycles_to_go,160); |
| 381 | 405 | /* Draw empty pixels when the background is disabled */ |
| 382 | | if ( ! ( LCDCONT & 0x01 ) ) { |
| 406 | if ( ! ( LCDCONT & 0x01 ) ) |
| 407 | { |
| 383 | 408 | rectangle r; |
| 384 | 409 | r.min_y = r.max_y = gb_lcd.current_line; |
| 385 | 410 | r.min_x = gb_lcd.start_x; |
| 386 | 411 | r.max_x = gb_lcd.end_x - 1; |
| 387 | 412 | bitmap_fill( bitmap, &r , gb_bpal[0]); |
| 388 | 413 | } |
| 389 | | while ( l < 2 ) { |
| 414 | while ( l < 2 ) |
| 415 | { |
| 390 | 416 | UINT8 xindex, *map, *tiles; |
| 391 | 417 | UINT16 data; |
| 392 | 418 | int i, tile_index; |
| 393 | 419 | |
| 394 | | if ( ! gb_lcd.layer[l].enabled ) { |
| 420 | if ( ! gb_lcd.layer[l].enabled ) |
| 421 | { |
| 395 | 422 | l++; |
| 396 | 423 | continue; |
| 397 | 424 | } |
| r4575 | r4576 | |
| 409 | 436 | data = tiles[ tile_index ] | ( tiles[ tile_index+1 ] << 8 ); |
| 410 | 437 | data <<= gb_lcd.layer[l].xshift; |
| 411 | 438 | |
| 412 | | while ( i > 0 ) { |
| 413 | | while ( ( gb_lcd.layer[l].xshift < 8 ) && i ) { |
| 439 | while ( i > 0 ) |
| 440 | { |
| 441 | while ( ( gb_lcd.layer[l].xshift < 8 ) && i ) |
| 442 | { |
| 414 | 443 | register int colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 ); |
| 415 | 444 | gb_plot_pixel( bitmap, xindex, gb_lcd.current_line, gb_bpal[ colour ] ); |
| 416 | 445 | bg_zbuf[ xindex ] = colour; |
| r4575 | r4576 | |
| 419 | 448 | gb_lcd.layer[l].xshift++; |
| 420 | 449 | i--; |
| 421 | 450 | } |
| 422 | | if ( gb_lcd.layer[l].xshift == 8 ) { |
| 451 | if ( gb_lcd.layer[l].xshift == 8 ) |
| 452 | { |
| 423 | 453 | /* Take possible changes to SCROLLY into account */ |
| 424 | | if ( l == 0 ) { |
| 454 | if ( l == 0 ) |
| 455 | { |
| 425 | 456 | gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF; |
| 426 | 457 | map = gb_lcd.layer[l].bg_map + ( ( gb_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 427 | 458 | tiles = gb_lcd.layer[l].bg_tiles + ( ( gb_lcd.layer[l].bgline & 7 ) << 1 ); |
| r4575 | r4576 | |
| 435 | 466 | } |
| 436 | 467 | l++; |
| 437 | 468 | } |
| 438 | | if ( gb_lcd.end_x == 160 && LCDCONT & 0x02 ) { |
| 469 | if ( gb_lcd.end_x == 160 && LCDCONT & 0x02 ) |
| 470 | { |
| 439 | 471 | gb_update_sprites(); |
| 440 | 472 | } |
| 441 | 473 | gb_lcd.start_x = gb_lcd.end_x; |
| 442 | 474 | } |
| 443 | | } else { |
| 444 | | if ( ! ( LCDCONT & 0x80 ) ) { |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | if ( ! ( LCDCONT & 0x80 ) ) |
| 479 | { |
| 445 | 480 | /* Draw an empty line when LCD is disabled */ |
| 446 | | if ( gb_lcd.previous_line != gb_lcd.current_line ) { |
| 447 | | if ( gb_lcd.current_line < 144 ) { |
| 481 | if ( gb_lcd.previous_line != gb_lcd.current_line ) |
| 482 | { |
| 483 | if ( gb_lcd.current_line < 144 ) |
| 484 | { |
| 448 | 485 | const device_config *screen = video_screen_first(machine->config); |
| 449 | 486 | rectangle r = *video_screen_get_visible_area(screen); |
| 450 | 487 | r.min_y = r.max_y = gb_lcd.current_line; |
| r4575 | r4576 | |
| 555 | 592 | } |
| 556 | 593 | } |
| 557 | 594 | |
| 558 | | static void sgb_refresh_border(void) { |
| 595 | static void sgb_refresh_border(void) |
| 596 | { |
| 559 | 597 | UINT16 data, data2; |
| 560 | 598 | UINT16 yidx, xidx, xindex; |
| 561 | 599 | UINT8 *map, *tiles, *tiles2; |
| r4575 | r4576 | |
| 564 | 602 | |
| 565 | 603 | map = sgb_tile_map - 64; |
| 566 | 604 | |
| 567 | | for( yidx = 0; yidx < 224; yidx++ ) { |
| 605 | for( yidx = 0; yidx < 224; yidx++ ) |
| 606 | { |
| 568 | 607 | xindex = 0; |
| 569 | 608 | map += (yidx % 8) ? 0 : 64; |
| 570 | | for( xidx = 0; xidx < 64; xidx+=2 ) { |
| 609 | for( xidx = 0; xidx < 64; xidx+=2 ) |
| 610 | { |
| 571 | 611 | if( map[xidx+1] & 0x80 ) /* Vertical flip */ |
| 572 | 612 | tiles = sgb_tile_data + ( ( 7 - ( yidx % 8 ) ) << 1 ); |
| 573 | 613 | else /* No vertical flip */ |
| r4575 | r4576 | |
| 579 | 619 | pal = 1; |
| 580 | 620 | pal <<= 4; |
| 581 | 621 | |
| 582 | | if( sgb_hack ) { /* A few games do weird stuff */ |
| 622 | if( sgb_hack ) |
| 623 | { /* A few games do weird stuff */ |
| 583 | 624 | UINT8 tileno = map[xidx]; |
| 584 | 625 | if( tileno >= 128 ) tileno = ((64 + tileno) % 128) + 128; |
| 585 | 626 | else tileno = (64 + tileno) % 128; |
| 586 | 627 | data = tiles[ tileno * 32 ] | ( tiles[ ( tileno * 32 ) + 1 ] << 8 ); |
| 587 | 628 | data2 = tiles2[ tileno * 32 ] | ( tiles2[ ( tileno * 32 ) + 1 ] << 8 ); |
| 588 | | } else { |
| 629 | } |
| 630 | else |
| 631 | { |
| 589 | 632 | data = tiles[ map[xidx] * 32 ] | ( tiles[ (map[xidx] * 32 ) + 1 ] << 8 ); |
| 590 | 633 | data2 = tiles2[ map[xidx] * 32 ] | ( tiles2[ (map[xidx] * 32 ) + 1 ] << 8 ); |
| 591 | 634 | } |
| 592 | 635 | |
| 593 | | for( i = 0; i < 8; i++ ) { |
| 636 | for( i = 0; i < 8; i++ ) |
| 637 | { |
| 594 | 638 | register UINT8 colour; |
| 595 | | if( (map[xidx+1] & 0x40) ) { /* Horizontal flip */ |
| 639 | if( (map[xidx+1] & 0x40) ) /* Horizontal flip */ |
| 640 | { |
| 596 | 641 | colour = ((data & 0x0001) ? 1 : 0) | ((data & 0x0100) ? 2 : 0) | |
| 597 | 642 | ((data2 & 0x0001) ? 4 : 0) | ((data2 & 0x0100) ? 8 : 0); |
| 598 | 643 | data >>= 1; |
| 599 | 644 | data2 >>= 1; |
| 600 | | } else { /* No horizontal flip */ |
| 645 | } |
| 646 | else /* No horizontal flip */ |
| 647 | { |
| 601 | 648 | colour = ((data & 0x0080) ? 1 : 0) | ((data & 0x8000) ? 2 : 0) | |
| 602 | 649 | ((data2 & 0x0080) ? 4 : 0) | ((data2 & 0x8000) ? 8 : 0); |
| 603 | 650 | data <<= 1; |
| r4575 | r4576 | |
| 608 | 655 | * scanline, it can obscure the screen even when it shouldn't. |
| 609 | 656 | */ |
| 610 | 657 | if( !((yidx >= SGB_YOFFSET && yidx < SGB_YOFFSET + 144) && |
| 611 | | (xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160)) ) { |
| 658 | (xindex >= SGB_XOFFSET && xindex < SGB_XOFFSET + 160)) ) |
| 659 | { |
| 612 | 660 | gb_plot_pixel(bitmap, xindex, yidx, sgb_pal[pal + colour]); |
| 613 | 661 | } |
| 614 | 662 | xindex++; |
| r4575 | r4576 | |
| 617 | 665 | } |
| 618 | 666 | } |
| 619 | 667 | |
| 620 | | static void sgb_update_scanline( running_machine *machine ) { |
| 668 | static void sgb_update_scanline( running_machine *machine ) |
| 669 | { |
| 621 | 670 | bitmap_t *bitmap = tmpbitmap; |
| 622 | 671 | |
| 623 | 672 | profiler_mark(PROFILER_VIDEO); |
| 624 | 673 | |
| 625 | | if ( ( LCDSTAT & 0x03 ) == 0x03 ) { |
| 674 | if ( ( LCDSTAT & 0x03 ) == 0x03 ) |
| 675 | { |
| 626 | 676 | /* Calcuate number of pixels to render based on time still left on the timer */ |
| 627 | | UINT32 cycles_to_go = cpu_attotime_to_clocks(machine->cpu[0], timer_timeleft( gb_lcd.lcd_timer ) ); |
| 677 | UINT32 cycles_to_go = cputag_attotime_to_clocks(machine, "maincpu", timer_timeleft( gb_lcd.lcd_timer ) ); |
| 628 | 678 | int l = 0; |
| 629 | 679 | |
| 630 | | if ( gb_lcd.start_x < 0 ) { |
| 680 | if ( gb_lcd.start_x < 0 ) |
| 681 | { |
| 631 | 682 | /* Window is enabled if the hardware says so AND the current scanline is |
| 632 | 683 | * within the window AND the window X coordinate is <=166 */ |
| 633 | 684 | gb_lcd.layer[1].enabled = ((LCDCONT & 0x20) && gb_lcd.current_line >= WNDPOSY && WNDPOSX <= 166) ? 1 : 0; |
| r4575 | r4576 | |
| 636 | 687 | * AND window's X position is >=7 ) ) */ |
| 637 | 688 | gb_lcd.layer[0].enabled = ((LCDCONT & 0x01) && ((!gb_lcd.layer[1].enabled) || (gb_lcd.layer[1].enabled && WNDPOSX >= 7))) ? 1 : 0; |
| 638 | 689 | |
| 639 | | if ( gb_lcd.layer[0].enabled ) { |
| 690 | if ( gb_lcd.layer[0].enabled ) |
| 691 | { |
| 640 | 692 | gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF; |
| 641 | 693 | gb_lcd.layer[0].bg_map = gb_bgdtab; |
| 642 | 694 | gb_lcd.layer[0].bg_tiles = gb_chrgen; |
| r4575 | r4576 | |
| 646 | 698 | gb_lcd.layer[0].xend = 160; |
| 647 | 699 | } |
| 648 | 700 | |
| 649 | | if ( gb_lcd.layer[1].enabled ) { |
| 701 | if ( gb_lcd.layer[1].enabled ) |
| 702 | { |
| 650 | 703 | int xpos; |
| 651 | 704 | |
| 652 | 705 | /* Window X position is offset by 7 so we'll need to adjust */ |
| r4575 | r4576 | |
| 666 | 719 | gb_lcd.start_x = 0; |
| 667 | 720 | } |
| 668 | 721 | |
| 669 | | if ( cycles_to_go == 0 ) { |
| 722 | if ( cycles_to_go == 0 ) |
| 723 | { |
| 670 | 724 | |
| 671 | 725 | /* Does this belong here? or should it be moved to the else block */ |
| 672 | 726 | /* Handle SGB mask */ |
| 673 | | switch( sgb_window_mask ) { |
| 727 | switch( sgb_window_mask ) |
| 728 | { |
| 674 | 729 | case 1: /* Freeze screen */ |
| 675 | 730 | return; |
| 676 | 731 | case 2: /* Blank screen (black) */ |
| r4575 | r4576 | |
| 696 | 751 | } |
| 697 | 752 | |
| 698 | 753 | /* Draw the "border" if we're on the first line */ |
| 699 | | if ( gb_lcd.current_line == 0 ) { |
| 754 | if ( gb_lcd.current_line == 0 ) |
| 755 | { |
| 700 | 756 | sgb_refresh_border(); |
| 701 | 757 | } |
| 702 | 758 | } |
| 703 | | if ( cycles_to_go < 160 ) { |
| 759 | if ( cycles_to_go < 160 ) |
| 760 | { |
| 704 | 761 | gb_lcd.end_x = MIN(160 - cycles_to_go,160); |
| 705 | 762 | |
| 706 | 763 | /* if background or screen disabled clear line */ |
| 707 | | if ( ! ( LCDCONT & 0x01 ) ) { |
| 764 | if ( ! ( LCDCONT & 0x01 ) ) |
| 765 | { |
| 708 | 766 | const device_config *screen = video_screen_first(machine->config); |
| 709 | 767 | rectangle r = *video_screen_get_visible_area(screen); |
| 710 | 768 | r.min_x = SGB_XOFFSET; |
| r4575 | r4576 | |
| 712 | 770 | r.min_y = r.max_y = gb_lcd.current_line + SGB_YOFFSET; |
| 713 | 771 | bitmap_fill( bitmap, &r , 0); |
| 714 | 772 | } |
| 715 | | while( l < 2 ) { |
| 773 | while( l < 2 ) |
| 774 | { |
| 716 | 775 | UINT8 xindex, sgb_palette, *map, *tiles; |
| 717 | 776 | UINT16 data; |
| 718 | 777 | int i, tile_index; |
| 719 | 778 | |
| 720 | | if ( ! gb_lcd.layer[l].enabled ) { |
| 779 | if ( ! gb_lcd.layer[l].enabled ) |
| 780 | { |
| 721 | 781 | l++; |
| 722 | 782 | continue; |
| 723 | 783 | } |
| r4575 | r4576 | |
| 738 | 798 | /* Figure out which palette we're using */ |
| 739 | 799 | sgb_palette = sgb_pal_map[ ( gb_lcd.end_x - i ) >> 3 ][ gb_lcd.current_line >> 3 ] << 2; |
| 740 | 800 | |
| 741 | | while( i > 0 ) { |
| 742 | | while( ( gb_lcd.layer[l].xshift < 8 ) && i ) { |
| 801 | while( i > 0 ) |
| 802 | { |
| 803 | while( ( gb_lcd.layer[l].xshift < 8 ) && i ) |
| 804 | { |
| 743 | 805 | register int colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 ); |
| 744 | 806 | gb_plot_pixel( bitmap, xindex + SGB_XOFFSET, gb_lcd.current_line + SGB_YOFFSET, sgb_pal[ sgb_palette + gb_bpal[colour]] ); |
| 745 | 807 | bg_zbuf[xindex] = colour; |
| r4575 | r4576 | |
| 748 | 810 | gb_lcd.layer[l].xshift++; |
| 749 | 811 | i--; |
| 750 | 812 | } |
| 751 | | if ( gb_lcd.layer[l].xshift == 8 ) { |
| 813 | if ( gb_lcd.layer[l].xshift == 8 ) |
| 814 | { |
| 752 | 815 | /* Take possible changes to SCROLLY into account */ |
| 753 | | if ( l == 0 ) { |
| 816 | if ( l == 0 ) |
| 817 | { |
| 754 | 818 | gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF; |
| 755 | 819 | map = gb_lcd.layer[l].bg_map + ( ( gb_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 756 | 820 | tiles = gb_lcd.layer[l].bg_tiles + ( ( gb_lcd.layer[l].bgline & 7 ) << 1 ); |
| r4575 | r4576 | |
| 765 | 829 | } |
| 766 | 830 | l++; |
| 767 | 831 | } |
| 768 | | if ( ( gb_lcd.end_x == 160 ) && ( LCDCONT & 0x02 ) ) { |
| 832 | if ( ( gb_lcd.end_x == 160 ) && ( LCDCONT & 0x02 ) ) |
| 833 | { |
| 769 | 834 | sgb_update_sprites(); |
| 770 | 835 | } |
| 771 | 836 | gb_lcd.start_x = gb_lcd.end_x; |
| 772 | 837 | } |
| 773 | | } else { |
| 774 | | if ( ! ( LCDCONT * 0x80 ) ) { |
| 838 | } |
| 839 | else |
| 840 | { |
| 841 | if ( ! ( LCDCONT * 0x80 ) ) |
| 842 | { |
| 775 | 843 | /* if screen disabled clear line */ |
| 776 | | if ( gb_lcd.previous_line != gb_lcd.current_line ) { |
| 844 | if ( gb_lcd.previous_line != gb_lcd.current_line ) |
| 845 | { |
| 777 | 846 | /* Also refresh border here??? */ |
| 778 | | if ( gb_lcd.current_line < 144 ) { |
| 847 | if ( gb_lcd.current_line < 144 ) |
| 848 | { |
| 779 | 849 | const device_config *screen = video_screen_first(machine->config); |
| 780 | 850 | rectangle r = *video_screen_get_visible_area(screen); |
| 781 | 851 | r.min_x = SGB_XOFFSET; |
| r4575 | r4576 | |
| 793 | 863 | |
| 794 | 864 | /* --- Game Boy Color Specific --- */ |
| 795 | 865 | |
| 796 | | INLINE void cgb_update_sprites ( running_machine *machine ) { |
| 866 | INLINE void cgb_update_sprites ( running_machine *machine ) |
| 867 | { |
| 797 | 868 | bitmap_t *bitmap = tmpbitmap; |
| 798 | 869 | UINT8 height, tilemask, line, *oam; |
| 799 | 870 | int i, xindex, yindex; |
| r4575 | r4576 | |
| 888 | 959 | } |
| 889 | 960 | } |
| 890 | 961 | |
| 891 | | static void cgb_update_scanline ( running_machine *machine ) { |
| 962 | static void cgb_update_scanline ( running_machine *machine ) |
| 963 | { |
| 892 | 964 | bitmap_t *bitmap = tmpbitmap; |
| 893 | 965 | |
| 894 | 966 | profiler_mark(PROFILER_VIDEO); |
| 895 | 967 | |
| 896 | | if ( ( LCDSTAT & 0x03 ) == 0x03 ) { |
| 968 | if ( ( LCDSTAT & 0x03 ) == 0x03 ) |
| 969 | { |
| 897 | 970 | /* Calcuate number of pixels to render based on time still left on the timer */ |
| 898 | | UINT32 cycles_to_go = cpu_attotime_to_clocks(machine->cpu[0], timer_timeleft( gb_lcd.lcd_timer ) ); |
| 971 | UINT32 cycles_to_go = cputag_attotime_to_clocks(machine, "maincpu", timer_timeleft( gb_lcd.lcd_timer ) ); |
| 899 | 972 | int l = 0; |
| 900 | 973 | |
| 901 | | if ( gb_lcd.start_x < 0 ) { |
| 974 | if ( gb_lcd.start_x < 0 ) |
| 975 | { |
| 902 | 976 | /* Window is enabled if the hardware says so AND the current scanline is |
| 903 | 977 | * within the window AND the window X coordinate is <=166 */ |
| 904 | 978 | gb_lcd.layer[1].enabled = ( ( LCDCONT & 0x20 ) && ( gb_lcd.current_line >= WNDPOSY ) && ( WNDPOSX <= 166 ) ) ? 1 : 0; |
| r4575 | r4576 | |
| 907 | 981 | * AND window's X position is >=7 ) ) */ |
| 908 | 982 | gb_lcd.layer[0].enabled = ( ( LCDCONT & 0x01 ) && ( ( ! gb_lcd.layer[1].enabled ) || ( gb_lcd.layer[1].enabled && ( WNDPOSX >= 7 ) ) ) ) ? 1 : 0; |
| 909 | 983 | |
| 910 | | if ( gb_lcd.layer[0].enabled ) { |
| 984 | if ( gb_lcd.layer[0].enabled ) |
| 985 | { |
| 911 | 986 | gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF; |
| 912 | 987 | gb_lcd.layer[0].bg_map = gb_bgdtab; |
| 913 | 988 | gb_lcd.layer[0].gbc_map = gbc_bgdtab; |
| r4575 | r4576 | |
| 917 | 992 | gb_lcd.layer[0].xend = 160; |
| 918 | 993 | } |
| 919 | 994 | |
| 920 | | if ( gb_lcd.layer[1].enabled ) { |
| 995 | if ( gb_lcd.layer[1].enabled ) |
| 996 | { |
| 921 | 997 | int xpos; |
| 922 | 998 | |
| 923 | 999 | /* Window X position is offset by 7 so we'll need to adust */ |
| r4575 | r4576 | |
| 937 | 1013 | gb_lcd.start_x = 0; |
| 938 | 1014 | } |
| 939 | 1015 | |
| 940 | | if ( cycles_to_go < 160 ) { |
| 1016 | if ( cycles_to_go < 160 ) |
| 1017 | { |
| 941 | 1018 | gb_lcd.end_x = MIN(160 - cycles_to_go,160); |
| 942 | 1019 | /* Draw empty line when the background is disabled */ |
| 943 | | if ( ! ( LCDCONT & 0x01 ) ) { |
| 1020 | if ( ! ( LCDCONT & 0x01 ) ) |
| 1021 | { |
| 944 | 1022 | const device_config *screen = video_screen_first(machine->config); |
| 945 | 1023 | rectangle r = *video_screen_get_visible_area(screen); |
| 946 | 1024 | r.min_y = r.max_y = gb_lcd.current_line; |
| r4575 | r4576 | |
| 948 | 1026 | r.max_x = gb_lcd.end_x - 1; |
| 949 | 1027 | bitmap_fill( bitmap, &r , ( gbc_mode == GBC_MODE_MONO ) ? 0 : 32767); |
| 950 | 1028 | } |
| 951 | | while ( l < 2 ) { |
| 1029 | while ( l < 2 ) |
| 1030 | { |
| 952 | 1031 | UINT8 xindex, *map, *tiles, *gbcmap; |
| 953 | 1032 | UINT16 data; |
| 954 | 1033 | int i, tile_index; |
| 955 | 1034 | |
| 956 | | if ( ! gb_lcd.layer[l].enabled ) { |
| 1035 | if ( ! gb_lcd.layer[l].enabled ) |
| 1036 | { |
| 957 | 1037 | l++; |
| 958 | 1038 | continue; |
| 959 | 1039 | } |
| r4575 | r4576 | |
| 962 | 1042 | tiles = ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x08 ) ? gbc_chrgen : gb_chrgen; |
| 963 | 1043 | |
| 964 | 1044 | /* Check for vertical flip */ |
| 965 | | if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x40 ) { |
| 1045 | if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x40 ) |
| 1046 | { |
| 966 | 1047 | tiles += ( ( 7 - ( gb_lcd.layer[l].bgline & 0x07 ) ) << 1 ); |
| 967 | | } else { |
| 1048 | } |
| 1049 | else |
| 1050 | { |
| 968 | 1051 | tiles += ( ( gb_lcd.layer[l].bgline & 0x07 ) << 1 ); |
| 969 | 1052 | } |
| 970 | 1053 | xindex = gb_lcd.start_x; |
| r4575 | r4576 | |
| 978 | 1061 | tile_index = ( map[ gb_lcd.layer[l].xindex ] ^ gb_tile_no_mod ) * 16; |
| 979 | 1062 | data = tiles[ tile_index ] | ( tiles[ tile_index + 1 ] << 8 ); |
| 980 | 1063 | /* Check for horinzontal flip */ |
| 981 | | if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x20 ) { |
| 1064 | if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x20 ) |
| 1065 | { |
| 982 | 1066 | data >>= gb_lcd.layer[l].xshift; |
| 983 | | } else { |
| 1067 | } |
| 1068 | else |
| 1069 | { |
| 984 | 1070 | data <<= gb_lcd.layer[l].xshift; |
| 985 | 1071 | } |
| 986 | 1072 | |
| 987 | | while ( i > 0 ) { |
| 988 | | while ( ( gb_lcd.layer[l].xshift < 8 ) && i ) { |
| 1073 | while ( i > 0 ) |
| 1074 | { |
| 1075 | while ( ( gb_lcd.layer[l].xshift < 8 ) && i ) |
| 1076 | { |
| 989 | 1077 | int colour; |
| 990 | 1078 | /* Check for horinzontal flip */ |
| 991 | | if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x20 ) { |
| 1079 | if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x20 ) |
| 1080 | { |
| 992 | 1081 | colour = ( ( data & 0x0100 ) ? 2 : 0 ) | ( ( data & 0x0001 ) ? 1 : 0 ); |
| 993 | 1082 | data >>= 1; |
| 994 | | } else { |
| 1083 | } |
| 1084 | else |
| 1085 | { |
| 995 | 1086 | colour = ( ( data & 0x8000 ) ? 2 : 0 ) | ( ( data & 0x0080 ) ? 1 : 0 ); |
| 996 | 1087 | data <<= 1; |
| 997 | 1088 | } |
| r4575 | r4576 | |
| 1001 | 1092 | gb_lcd.layer[l].xshift++; |
| 1002 | 1093 | i--; |
| 1003 | 1094 | } |
| 1004 | | if ( gb_lcd.layer[l].xshift == 8 ) { |
| 1095 | if ( gb_lcd.layer[l].xshift == 8 ) |
| 1096 | { |
| 1005 | 1097 | /* Take possible changes to SCROLLY into account */ |
| 1006 | | if ( l == 0 ) { |
| 1098 | if ( l == 0 ) |
| 1099 | { |
| 1007 | 1100 | gb_lcd.layer[0].bgline = ( SCROLLY + gb_lcd.current_line ) & 0xFF; |
| 1008 | 1101 | map = gb_lcd.layer[l].bg_map + ( ( gb_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| 1009 | 1102 | gbcmap = gb_lcd.layer[l].gbc_map + ( ( gb_lcd.layer[l].bgline << 2 ) & 0x3E0 ); |
| r4575 | r4576 | |
| 1014 | 1107 | tiles = ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x08 ) ? gbc_chrgen : gb_chrgen; |
| 1015 | 1108 | |
| 1016 | 1109 | /* Check for vertical flip */ |
| 1017 | | if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x40 ) { |
| 1110 | if ( gbcmap[ gb_lcd.layer[l].xindex ] & 0x40 ) |
| 1111 | { |
| 1018 | 1112 | tiles += ( ( 7 - ( gb_lcd.layer[l].bgline & 0x07 ) ) << 1 ); |
| 1019 | | } else { |
| 1113 | } |
| 1114 | else |
| 1115 | { |
| 1020 | 1116 | tiles += ( ( gb_lcd.layer[l].bgline & 0x07 ) << 1 ); |
| 1021 | 1117 | } |
| 1022 | 1118 | tile_index = ( map[ gb_lcd.layer[l].xindex ] ^ gb_tile_no_mod ) * 16; |
| r4575 | r4576 | |
| 1025 | 1121 | } |
| 1026 | 1122 | l++; |
| 1027 | 1123 | } |
| 1028 | | if ( gb_lcd.end_x == 160 && ( LCDCONT & 0x02 ) ) { |
| 1124 | if ( gb_lcd.end_x == 160 && ( LCDCONT & 0x02 ) ) |
| 1125 | { |
| 1029 | 1126 | cgb_update_sprites( machine ); |
| 1030 | 1127 | } |
| 1031 | 1128 | gb_lcd.start_x = gb_lcd.end_x; |
| 1032 | 1129 | } |
| 1033 | | } else { |
| 1034 | | if ( ! ( LCDCONT & 0x80 ) ) { |
| 1130 | } |
| 1131 | else |
| 1132 | { |
| 1133 | if ( ! ( LCDCONT & 0x80 ) ) |
| 1134 | { |
| 1035 | 1135 | /* Draw an empty line when LCD is disabled */ |
| 1036 | | if ( gb_lcd.previous_line != gb_lcd.current_line ) { |
| 1037 | | if ( gb_lcd.current_line < 144 ) { |
| 1136 | if ( gb_lcd.previous_line != gb_lcd.current_line ) |
| 1137 | { |
| 1138 | if ( gb_lcd.current_line < 144 ) |
| 1139 | { |
| 1038 | 1140 | const device_config *screen = video_screen_first(machine->config); |
| 1039 | 1141 | rectangle r = *video_screen_get_visible_area(screen); |
| 1040 | 1142 | r.min_y = r.max_y = gb_lcd.current_line; |
| r4575 | r4576 | |
| 1157 | 1259 | |
| 1158 | 1260 | static TIMER_CALLBACK( gb_video_init_vbl ) |
| 1159 | 1261 | { |
| 1160 | | cpu_set_input_line( machine->cpu[0], VBL_INT, ASSERT_LINE ); |
| 1262 | cputag_set_input_line( machine, "maincpu", VBL_INT, ASSERT_LINE ); |
| 1161 | 1263 | } |
| 1162 | 1264 | |
| 1163 | | void gb_video_init( running_machine *machine, int mode ) { |
| 1265 | void gb_video_init( running_machine *machine, int mode ) |
| 1266 | { |
| 1164 | 1267 | int i; |
| 1165 | 1268 | int vram_size = 0x2000; |
| 1166 | | const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); |
| 1269 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1167 | 1270 | |
| 1168 | 1271 | if (mode == GB_VIDEO_CGB) vram_size = 0x4000; |
| 1169 | 1272 | |
| r4575 | r4576 | |
| 1178 | 1281 | gb_wndtab = gb_vram + 0x1C00; |
| 1179 | 1282 | |
| 1180 | 1283 | gb_vid_regs[0x06] = 0xFF; |
| 1181 | | for( i = 0x0c; i < _NR_GB_VID_REGS; i++ ) { |
| 1284 | for( i = 0x0c; i < _NR_GB_VID_REGS; i++ ) |
| 1285 | { |
| 1182 | 1286 | gb_vid_regs[i] = 0xFF; |
| 1183 | 1287 | } |
| 1184 | 1288 | |
| r4575 | r4576 | |
| 1190 | 1294 | WNDPOSX = WNDPOSY = 0x00; |
| 1191 | 1295 | |
| 1192 | 1296 | /* Initialize palette arrays */ |
| 1193 | | for( i = 0; i < 4; i++ ) { |
| 1297 | for( i = 0; i < 4; i++ ) |
| 1298 | { |
| 1194 | 1299 | gb_bpal[i] = gb_spal0[i] = gb_spal1[i] = i; |
| 1195 | 1300 | } |
| 1196 | 1301 | |
| 1197 | | switch( mode ) { |
| 1302 | switch( mode ) |
| 1303 | { |
| 1198 | 1304 | case GB_VIDEO_DMG: |
| 1199 | 1305 | gb_lcd.lcd_timer = timer_alloc(machine, gb_lcd_timer_proc , NULL); |
| 1200 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 456), 0); |
| 1306 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 456), 0); |
| 1201 | 1307 | |
| 1202 | 1308 | /* set the scanline update function */ |
| 1203 | 1309 | update_scanline = gb_update_scanline; |
| r4575 | r4576 | |
| 1211 | 1317 | /* set the scanline update function */ |
| 1212 | 1318 | update_scanline = gb_update_scanline; |
| 1213 | 1319 | /* Initialize part of VRAM. This code must be deleted when we have added the bios dump */ |
| 1214 | | for( i = 1; i < 0x0D; i++ ) { |
| 1320 | for( i = 1; i < 0x0D; i++ ) |
| 1321 | { |
| 1215 | 1322 | gb_vram[ 0x1903 + i ] = i; |
| 1216 | 1323 | gb_vram[ 0x1923 + i ] = i + 0x0C; |
| 1217 | 1324 | } |
| r4575 | r4576 | |
| 1221 | 1328 | memcpy( gb_oam, mgb_oam_fingerprint, 0x100 ); |
| 1222 | 1329 | |
| 1223 | 1330 | /* Make sure the VBlank interrupt is set when the first instruction gets executed */ |
| 1224 | | timer_set(machine, cpu_clocks_to_attotime(machine->cpu[0], 1), NULL, 0, gb_video_init_vbl ); |
| 1331 | timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, gb_video_init_vbl ); |
| 1225 | 1332 | |
| 1226 | 1333 | /* Initialize some video registers */ |
| 1227 | 1334 | gb_video_w( space, 0x0, 0x91 ); /* LCDCONT */ |
| r4575 | r4576 | |
| 1232 | 1339 | CURLINE = gb_lcd.current_line = 0; |
| 1233 | 1340 | LCDSTAT = ( LCDSTAT & 0xF8 ) | 0x05; |
| 1234 | 1341 | gb_lcd.mode = 1; |
| 1235 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 60), GB_LCD_STATE_LY00_M0); |
| 1342 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 60), GB_LCD_STATE_LY00_M0); |
| 1236 | 1343 | |
| 1237 | 1344 | break; |
| 1238 | 1345 | case GB_VIDEO_SGB: |
| r4575 | r4576 | |
| 1242 | 1349 | update_scanline = sgb_update_scanline; |
| 1243 | 1350 | |
| 1244 | 1351 | /* Initialize part of VRAM. This code must be deleted when we have added the bios dump */ |
| 1245 | | for( i = 1; i < 0x0D; i++ ) { |
| 1352 | for( i = 1; i < 0x0D; i++ ) |
| 1353 | { |
| 1246 | 1354 | gb_vram[ 0x1903 + i ] = i; |
| 1247 | 1355 | gb_vram[ 0x1923 + i ] = i + 0x0C; |
| 1248 | 1356 | } |
| 1249 | 1357 | gb_vram[ 0x1910 ] = 0x19; |
| 1250 | 1358 | |
| 1251 | 1359 | /* Make sure the VBlank interrupt is set when the first instruction gets executed */ |
| 1252 | | timer_set(machine, cpu_clocks_to_attotime(machine->cpu[0], 1), NULL, 0, gb_video_init_vbl ); |
| 1360 | timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, gb_video_init_vbl ); |
| 1253 | 1361 | |
| 1254 | 1362 | /* Initialize some video registers */ |
| 1255 | 1363 | gb_video_w( space, 0x0, 0x91 ); /* LCDCONT */ |
| r4575 | r4576 | |
| 1260 | 1368 | CURLINE = gb_lcd.current_line = 0; |
| 1261 | 1369 | LCDSTAT = ( LCDSTAT & 0xF8 ) | 0x05; |
| 1262 | 1370 | gb_lcd.mode = 1; |
| 1263 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 60), GB_LCD_STATE_LY00_M0); |
| 1371 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 60), GB_LCD_STATE_LY00_M0); |
| 1264 | 1372 | |
| 1265 | 1373 | break; |
| 1266 | 1374 | case GB_VIDEO_CGB: |
| r4575 | r4576 | |
| 1281 | 1389 | gb_lcd.hdma_possible = 0; |
| 1282 | 1390 | |
| 1283 | 1391 | /* Make sure the VBlank interrupt is set when the first instruction gets executed */ |
| 1284 | | timer_set(machine, cpu_clocks_to_attotime(machine->cpu[0], 1), NULL, 0, gb_video_init_vbl ); |
| 1392 | timer_set(machine, cputag_clocks_to_attotime(machine, "maincpu", 1), NULL, 0, gb_video_init_vbl ); |
| 1285 | 1393 | |
| 1286 | 1394 | /* Initialize some video registers */ |
| 1287 | 1395 | gbc_video_w( space, 0x0, 0x91 ); /* LCDCONT */ |
| r4575 | r4576 | |
| 1292 | 1400 | CURLINE = gb_lcd.current_line = 0x90; |
| 1293 | 1401 | LCDSTAT = ( LCDSTAT & 0xF8 ) | 0x01; |
| 1294 | 1402 | gb_lcd.mode = 1; |
| 1295 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 292), GB_LCD_STATE_LY9X_M1_INC); |
| 1403 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 292), GB_LCD_STATE_LY9X_M1_INC); |
| 1296 | 1404 | gb_lcd.oam_locked = UNLOCKED; |
| 1297 | 1405 | gb_lcd.vram_locked = UNLOCKED; |
| 1298 | 1406 | gb_lcd.pal_locked = UNLOCKED; |
| r4575 | r4576 | |
| 1300 | 1408 | } |
| 1301 | 1409 | } |
| 1302 | 1410 | |
| 1303 | | static void gbc_hdma(running_machine *machine, UINT16 length) { |
| 1411 | static void gbc_hdma(running_machine *machine, UINT16 length) |
| 1412 | { |
| 1304 | 1413 | UINT16 src, dst; |
| 1305 | | const address_space *space = cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM); |
| 1414 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 1306 | 1415 | |
| 1307 | 1416 | src = ((UINT16)HDMA1 << 8) | (HDMA2 & 0xF0); |
| 1308 | 1417 | dst = ((UINT16)(HDMA3 & 0x1F) << 8) | (HDMA4 & 0xF0); |
| 1309 | 1418 | dst |= 0x8000; |
| 1310 | | while( length > 0 ) { |
| 1419 | while( length > 0 ) |
| 1420 | { |
| 1311 | 1421 | memory_write_byte( space, dst++, memory_read_byte( space, src++ ) ); |
| 1312 | 1422 | length--; |
| 1313 | 1423 | } |
| r4575 | r4576 | |
| 1316 | 1426 | HDMA3 = 0x1f & (dst >> 8); |
| 1317 | 1427 | HDMA4 = dst & 0xF0; |
| 1318 | 1428 | HDMA5--; |
| 1319 | | if( (HDMA5 & 0x7f) == 0x7f ) { |
| 1429 | if( (HDMA5 & 0x7f) == 0x7f ) |
| 1430 | { |
| 1320 | 1431 | HDMA5 = 0xff; |
| 1321 | 1432 | gb_lcd.hdma_enabled = 0; |
| 1322 | 1433 | } |
| 1323 | 1434 | } |
| 1324 | 1435 | |
| 1325 | | static void gb_increment_scanline( void ) { |
| 1436 | static void gb_increment_scanline( void ) |
| 1437 | { |
| 1326 | 1438 | gb_lcd.current_line = ( gb_lcd.current_line + 1 ) % 154; |
| 1327 | | if ( LCDCONT & 0x80 ) { |
| 1439 | if ( LCDCONT & 0x80 ) |
| 1440 | { |
| 1328 | 1441 | CURLINE = gb_lcd.current_line; |
| 1329 | 1442 | } |
| 1330 | | if ( gb_lcd.current_line == 0 ) { |
| 1443 | if ( gb_lcd.current_line == 0 ) |
| 1444 | { |
| 1331 | 1445 | gb_lcd.window_lines_drawn = 0; |
| 1332 | 1446 | } |
| 1333 | 1447 | } |
| r4575 | r4576 | |
| 1338 | 1452 | |
| 1339 | 1453 | gb_lcd.state = param; |
| 1340 | 1454 | |
| 1341 | | if ( LCDCONT & 0x80 ) { |
| 1342 | | switch( gb_lcd.state ) { |
| 1455 | if ( LCDCONT & 0x80 ) |
| 1456 | { |
| 1457 | switch( gb_lcd.state ) |
| 1458 | { |
| 1343 | 1459 | case GB_LCD_STATE_LYXX_PRE_M0: /* Just before switching to mode 0 */ |
| 1344 | 1460 | gb_lcd.mode = 0; |
| 1345 | | if ( LCDSTAT & 0x08 ) { |
| 1346 | | if ( ! gb_lcd.mode_irq ) { |
| 1347 | | if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) { |
| 1461 | if ( LCDSTAT & 0x08 ) |
| 1462 | { |
| 1463 | if ( ! gb_lcd.mode_irq ) |
| 1464 | { |
| 1465 | if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) |
| 1466 | { |
| 1348 | 1467 | gb_lcd.mode_irq = 1; |
| 1349 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1468 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1350 | 1469 | } |
| 1351 | | } else { |
| 1470 | } |
| 1471 | else |
| 1472 | { |
| 1352 | 1473 | gb_lcd.mode_irq = 0; |
| 1353 | 1474 | } |
| 1354 | 1475 | } |
| 1355 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0); |
| 1476 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0); |
| 1356 | 1477 | break; |
| 1357 | 1478 | case GB_LCD_STATE_LYXX_M0: /* Switch to mode 0 */ |
| 1358 | 1479 | /* update current scanline */ |
| 1359 | 1480 | update_scanline( machine ); |
| 1360 | 1481 | /* Increment the number of window lines drawn if enabled */ |
| 1361 | | if ( gb_lcd.layer[1].enabled ) { |
| 1482 | if ( gb_lcd.layer[1].enabled ) |
| 1483 | { |
| 1362 | 1484 | gb_lcd.window_lines_drawn++; |
| 1363 | 1485 | } |
| 1364 | 1486 | gb_lcd.previous_line = gb_lcd.current_line; |
| r4575 | r4576 | |
| 1373 | 1495 | than usual. |
| 1374 | 1496 | The SGB probably has the same bug. |
| 1375 | 1497 | */ |
| 1376 | | if ( ( SCROLLX & 0x03 ) == 0x03 ) { |
| 1498 | if ( ( SCROLLX & 0x03 ) == 0x03 ) |
| 1499 | { |
| 1377 | 1500 | gb_lcd.scrollx_adjust += 4; |
| 1378 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_SCX3); |
| 1501 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_SCX3); |
| 1379 | 1502 | break; |
| 1380 | 1503 | } |
| 1381 | 1504 | case GB_LCD_STATE_LYXX_M0_SCX3: |
| 1382 | 1505 | /* Generate lcd interrupt if requested */ |
| 1383 | 1506 | if ( ! gb_lcd.mode_irq && ( LCDSTAT & 0x08 ) && |
| 1384 | | ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) { |
| 1385 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1507 | ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) |
| 1508 | { |
| 1509 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1386 | 1510 | } |
| 1387 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 196 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC); |
| 1511 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 196 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC); |
| 1388 | 1512 | break; |
| 1389 | 1513 | case GB_LCD_STATE_LYXX_M0_PRE_INC: /* Just before incrementing the line counter go to mode 2 internally */ |
| 1390 | | if ( CURLINE < 143 ) { |
| 1514 | if ( CURLINE < 143 ) |
| 1515 | { |
| 1391 | 1516 | gb_lcd.mode = 2; |
| 1392 | 1517 | gb_lcd.triggering_mode_irq = ( LCDSTAT & 0x20 ) ? 1 : 0; |
| 1393 | | if ( gb_lcd.triggering_mode_irq ) { |
| 1394 | | if ( ! gb_lcd.mode_irq ) { |
| 1395 | | if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) { |
| 1518 | if ( gb_lcd.triggering_mode_irq ) |
| 1519 | { |
| 1520 | if ( ! gb_lcd.mode_irq ) |
| 1521 | { |
| 1522 | if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) |
| 1523 | { |
| 1396 | 1524 | gb_lcd.mode_irq = 1; |
| 1397 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1525 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1398 | 1526 | } |
| 1399 | | } else { |
| 1527 | } |
| 1528 | else |
| 1529 | { |
| 1400 | 1530 | gb_lcd.mode_irq = 0; |
| 1401 | 1531 | } |
| 1402 | 1532 | } |
| 1403 | 1533 | } |
| 1404 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_INC); |
| 1534 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_INC); |
| 1405 | 1535 | break; |
| 1406 | 1536 | case GB_LCD_STATE_LYXX_M0_INC: /* Increment LY, stay in M0 for 4 more cycles */ |
| 1407 | 1537 | gb_increment_scanline(); |
| 1408 | 1538 | gb_lcd.delayed_line_irq = gb_lcd.line_irq; |
| 1409 | 1539 | gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1410 | 1540 | gb_lcd.line_irq = 0; |
| 1411 | | if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! gb_lcd.triggering_mode_irq ) { |
| 1541 | if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! gb_lcd.triggering_mode_irq ) |
| 1542 | { |
| 1412 | 1543 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1413 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1544 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1414 | 1545 | } |
| 1415 | 1546 | /* Reset LY==LYC STAT bit */ |
| 1416 | 1547 | LCDSTAT &= 0xFB; |
| 1417 | 1548 | /* Check if we're going into VBlank next */ |
| 1418 | | if ( CURLINE == 144 ) { |
| 1419 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY9X_M1); |
| 1420 | | } else { |
| 1549 | if ( CURLINE == 144 ) |
| 1550 | { |
| 1551 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY9X_M1); |
| 1552 | } |
| 1553 | else |
| 1554 | { |
| 1421 | 1555 | /* Internally switch to mode 2 */ |
| 1422 | 1556 | gb_lcd.mode = 2; |
| 1423 | 1557 | /* Generate lcd interrupt if requested */ |
| 1424 | 1558 | if ( ! gb_lcd.mode_irq && gb_lcd.triggering_mode_irq && |
| 1425 | | ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) { |
| 1559 | ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) |
| 1560 | { |
| 1426 | 1561 | gb_lcd.mode_irq = 1; |
| 1427 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1562 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1428 | 1563 | } |
| 1429 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M2); |
| 1564 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M2); |
| 1430 | 1565 | } |
| 1431 | 1566 | break; |
| 1432 | 1567 | case GB_LCD_STATE_LY00_M2: /* Switch to mode 2 on line #0 */ |
| r4575 | r4576 | |
| 1435 | 1570 | LCDSTAT = ( LCDSTAT & 0xFC ) | 0x02; |
| 1436 | 1571 | gb_lcd.oam_locked = LOCKED; |
| 1437 | 1572 | /* Generate lcd interrupt if requested */ |
| 1438 | | if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) { |
| 1439 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1573 | if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) |
| 1574 | { |
| 1575 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1440 | 1576 | } |
| 1441 | 1577 | /* Check for regular compensation of x-scroll register */ |
| 1442 | 1578 | gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0; |
| 1443 | 1579 | /* Mode 2 lasts approximately 80 clock cycles */ |
| 1444 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3); |
| 1580 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3); |
| 1445 | 1581 | break; |
| 1446 | 1582 | case GB_LCD_STATE_LYXX_M2: /* Switch to mode 2 */ |
| 1447 | 1583 | /* Update STAT register to the correct state */ |
| r4575 | r4576 | |
| 1449 | 1585 | gb_lcd.oam_locked = LOCKED; |
| 1450 | 1586 | /* Generate lcd interrupt if requested */ |
| 1451 | 1587 | if ( ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) || |
| 1452 | | ( ! gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_mode_irq ) ) { |
| 1453 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1588 | ( ! gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_mode_irq ) ) |
| 1589 | { |
| 1590 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1454 | 1591 | } |
| 1455 | 1592 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1456 | 1593 | gb_lcd.triggering_mode_irq = 0; |
| 1457 | 1594 | /* Check if LY==LYC STAT bit should be set */ |
| 1458 | | if ( CURLINE == CMPLINE ) { |
| 1595 | if ( CURLINE == CMPLINE ) |
| 1596 | { |
| 1459 | 1597 | LCDSTAT |= 0x04; |
| 1460 | 1598 | } |
| 1461 | 1599 | /* Check for regular compensation of x-scroll register */ |
| 1462 | 1600 | gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0; |
| 1463 | 1601 | /* Mode 2 last for approximately 80 clock cycles */ |
| 1464 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3); |
| 1602 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3); |
| 1465 | 1603 | break; |
| 1466 | 1604 | case GB_LCD_STATE_LYXX_M3: /* Switch to mode 3 */ |
| 1467 | 1605 | gb_select_sprites(); |
| r4575 | r4576 | |
| 1472 | 1610 | gb_lcd.vram_locked = LOCKED; |
| 1473 | 1611 | /* Check for compensations of x-scroll register */ |
| 1474 | 1612 | /* Mode 3 lasts for approximately 172+cycles needed to handle sprites clock cycles */ |
| 1475 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0); |
| 1613 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0); |
| 1476 | 1614 | gb_lcd.start_x = -1; |
| 1477 | 1615 | break; |
| 1478 | 1616 | case GB_LCD_STATE_LY9X_M1: /* Switch to or stay in mode 1 */ |
| 1479 | | if ( CURLINE == 144 ) { |
| 1617 | if ( CURLINE == 144 ) |
| 1618 | { |
| 1480 | 1619 | /* Trigger VBlank interrupt */ |
| 1481 | | cpu_set_input_line( machine->cpu[0], VBL_INT, HOLD_LINE ); |
| 1620 | cputag_set_input_line( machine, "maincpu", VBL_INT, HOLD_LINE ); |
| 1482 | 1621 | /* Set VBlank lcdstate */ |
| 1483 | 1622 | gb_lcd.mode = 1; |
| 1484 | 1623 | LCDSTAT = (LCDSTAT & 0xFC) | 0x01; |
| 1485 | 1624 | /* Trigger LCD interrupt if requested */ |
| 1486 | | if ( LCDSTAT & 0x10 ) { |
| 1487 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1625 | if ( LCDSTAT & 0x10 ) |
| 1626 | { |
| 1627 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1488 | 1628 | } |
| 1489 | 1629 | } |
| 1490 | 1630 | /* Check if LY==LYC STAT bit should be set */ |
| 1491 | | if ( CURLINE == CMPLINE ) { |
| 1631 | if ( CURLINE == CMPLINE ) |
| 1632 | { |
| 1492 | 1633 | LCDSTAT |= 0x04; |
| 1493 | 1634 | } |
| 1494 | | if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) { |
| 1495 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1635 | if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) |
| 1636 | { |
| 1637 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1496 | 1638 | } |
| 1497 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 452), GB_LCD_STATE_LY9X_M1_INC); |
| 1639 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 452), GB_LCD_STATE_LY9X_M1_INC); |
| 1498 | 1640 | break; |
| 1499 | 1641 | case GB_LCD_STATE_LY9X_M1_INC: /* Increment scanline counter */ |
| 1500 | 1642 | gb_increment_scanline(); |
| 1501 | 1643 | gb_lcd.delayed_line_irq = gb_lcd.line_irq; |
| 1502 | 1644 | gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1503 | 1645 | gb_lcd.line_irq = 0; |
| 1504 | | if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) { |
| 1646 | if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) |
| 1647 | { |
| 1505 | 1648 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1506 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1649 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1507 | 1650 | } |
| 1508 | 1651 | /* Reset LY==LYC STAT bit */ |
| 1509 | 1652 | LCDSTAT &= 0xFB; |
| 1510 | | if ( gb_lcd.current_line == 153 ) { |
| 1511 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1); |
| 1512 | | } else { |
| 1513 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY9X_M1); |
| 1653 | if ( gb_lcd.current_line == 153 ) |
| 1654 | { |
| 1655 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1); |
| 1656 | } |
| 1657 | else |
| 1658 | { |
| 1659 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY9X_M1); |
| 1514 | 1660 | } |
| 1515 | 1661 | break; |
| 1516 | 1662 | case GB_LCD_STATE_LY00_M1: /* we stay in VBlank but current line counter should already be incremented */ |
| 1517 | 1663 | /* Check LY=LYC for line #153 */ |
| 1518 | | if ( gb_lcd.delayed_line_irq ) { |
| 1519 | | if ( gb_lcd.triggering_line_irq ) { |
| 1520 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1664 | if ( gb_lcd.delayed_line_irq ) |
| 1665 | { |
| 1666 | if ( gb_lcd.triggering_line_irq ) |
| 1667 | { |
| 1668 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1521 | 1669 | } |
| 1522 | 1670 | } |
| 1523 | 1671 | gb_lcd.delayed_line_irq = gb_lcd.delayed_line_irq | gb_lcd.line_irq; |
| 1524 | | if ( CURLINE == CMPLINE ) { |
| 1672 | if ( CURLINE == CMPLINE ) |
| 1673 | { |
| 1525 | 1674 | LCDSTAT |= 0x04; |
| 1526 | 1675 | } |
| 1527 | 1676 | gb_increment_scanline(); |
| 1528 | 1677 | gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1529 | 1678 | gb_lcd.line_irq = 0; |
| 1530 | 1679 | LCDSTAT &= 0xFB; |
| 1531 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4/*8*/), GB_LCD_STATE_LY00_M1_1); |
| 1680 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4/*8*/), GB_LCD_STATE_LY00_M1_1); |
| 1532 | 1681 | break; |
| 1533 | 1682 | case GB_LCD_STATE_LY00_M1_1: |
| 1534 | | if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) { |
| 1683 | if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) |
| 1684 | { |
| 1535 | 1685 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1536 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1686 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1537 | 1687 | } |
| 1538 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1_2); |
| 1688 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1_2); |
| 1539 | 1689 | break; |
| 1540 | 1690 | case GB_LCD_STATE_LY00_M1_2: /* Rest of line #0 during VBlank */ |
| 1541 | | if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) { |
| 1691 | if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) |
| 1692 | { |
| 1542 | 1693 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1543 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1694 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1544 | 1695 | } |
| 1545 | | if ( CURLINE == CMPLINE ) { |
| 1696 | if ( CURLINE == CMPLINE ) |
| 1697 | { |
| 1546 | 1698 | LCDSTAT |= 0x04; |
| 1547 | 1699 | } |
| 1548 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 444), GB_LCD_STATE_LY00_M0); |
| 1700 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 444), GB_LCD_STATE_LY00_M0); |
| 1549 | 1701 | break; |
| 1550 | 1702 | case GB_LCD_STATE_LY00_M0: /* The STAT register seems to go to 0 for about 4 cycles */ |
| 1551 | 1703 | /* Set Mode 0 lcdstat */ |
| 1552 | 1704 | gb_lcd.mode = 0; |
| 1553 | 1705 | LCDSTAT = ( LCDSTAT & 0xFC ); |
| 1554 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M2); |
| 1706 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M2); |
| 1555 | 1707 | break; |
| 1556 | 1708 | } |
| 1557 | | } else { |
| 1709 | } |
| 1710 | else |
| 1711 | { |
| 1558 | 1712 | gb_increment_scanline(); |
| 1559 | | if ( gb_lcd.current_line < 144 ) { |
| 1713 | if ( gb_lcd.current_line < 144 ) |
| 1714 | { |
| 1560 | 1715 | update_scanline( machine ); |
| 1561 | 1716 | } |
| 1562 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 456), 0); |
| 1717 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 456), 0); |
| 1563 | 1718 | } |
| 1564 | 1719 | } |
| 1565 | 1720 | |
| r4575 | r4576 | |
| 1569 | 1724 | |
| 1570 | 1725 | gb_lcd.state = param; |
| 1571 | 1726 | |
| 1572 | | if ( LCDCONT & 0x80 ) { |
| 1573 | | switch( gb_lcd.state ) { |
| 1727 | if ( LCDCONT & 0x80 ) |
| 1728 | { |
| 1729 | switch( gb_lcd.state ) |
| 1730 | { |
| 1574 | 1731 | case GB_LCD_STATE_LYXX_PRE_M0: /* Just before switching to mode 0 */ |
| 1575 | 1732 | gb_lcd.mode = 0; |
| 1576 | | if ( LCDSTAT & 0x08 ) { |
| 1577 | | if ( ! gb_lcd.mode_irq ) { |
| 1578 | | if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) { |
| 1733 | if ( LCDSTAT & 0x08 ) |
| 1734 | { |
| 1735 | if ( ! gb_lcd.mode_irq ) |
| 1736 | { |
| 1737 | if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) |
| 1738 | { |
| 1579 | 1739 | gb_lcd.mode_irq = 1; |
| 1580 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1740 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1581 | 1741 | } |
| 1582 | | } else { |
| 1742 | } |
| 1743 | else |
| 1744 | { |
| 1583 | 1745 | gb_lcd.mode_irq = 0; |
| 1584 | 1746 | } |
| 1585 | 1747 | } |
| 1586 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0); |
| 1748 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0); |
| 1587 | 1749 | break; |
| 1588 | 1750 | case GB_LCD_STATE_LYXX_M0: /* Switch to mode 0 */ |
| 1589 | 1751 | /* update current scanline */ |
| 1590 | 1752 | update_scanline( machine ); |
| 1591 | 1753 | /* Increment the number of window lines drawn if enabled */ |
| 1592 | | if ( gb_lcd.layer[1].enabled ) { |
| 1754 | if ( gb_lcd.layer[1].enabled ) |
| 1755 | { |
| 1593 | 1756 | gb_lcd.window_lines_drawn++; |
| 1594 | 1757 | } |
| 1595 | 1758 | gb_lcd.previous_line = gb_lcd.current_line; |
| r4575 | r4576 | |
| 1605 | 1768 | The SGB probably has the same bug. |
| 1606 | 1769 | */ |
| 1607 | 1770 | gb_lcd.triggering_mode_irq = ( LCDSTAT & 0x08 ) ? 1 : 0; |
| 1608 | | if ( ( SCROLLX & 0x03 ) == 0x03 ) { |
| 1771 | if ( ( SCROLLX & 0x03 ) == 0x03 ) |
| 1772 | { |
| 1609 | 1773 | gb_lcd.scrollx_adjust += 4; |
| 1610 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_SCX3); |
| 1774 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_SCX3); |
| 1611 | 1775 | break; |
| 1612 | 1776 | } |
| 1613 | 1777 | case GB_LCD_STATE_LYXX_M0_SCX3: |
| 1614 | 1778 | /* Generate lcd interrupt if requested */ |
| 1615 | 1779 | if ( ! gb_lcd.mode_irq && gb_lcd.triggering_mode_irq && |
| 1616 | | ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) { |
| 1617 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1780 | ( ( ! gb_lcd.line_irq && gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) |
| 1781 | { |
| 1782 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1618 | 1783 | gb_lcd.triggering_mode_irq = 0; |
| 1619 | 1784 | } |
| 1620 | | if ( ( SCROLLX & 0x03 ) == 0x03 ) { |
| 1785 | if ( ( SCROLLX & 0x03 ) == 0x03 ) |
| 1786 | { |
| 1621 | 1787 | gb_lcd.pal_locked = UNLOCKED; |
| 1622 | 1788 | } |
| 1623 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_GBC_PAL); |
| 1789 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_GBC_PAL); |
| 1624 | 1790 | break; |
| 1625 | 1791 | case GB_LCD_STATE_LYXX_M0_GBC_PAL: |
| 1626 | 1792 | gb_lcd.pal_locked = UNLOCKED; |
| 1627 | 1793 | /* Check for HBLANK DMA */ |
| 1628 | | if( gb_lcd.hdma_enabled ) { |
| 1794 | if( gb_lcd.hdma_enabled ) |
| 1795 | { |
| 1629 | 1796 | gbc_hdma(machine, 0x10); |
| 1630 | 1797 | // cpunum_set_reg( 0, LR35902_DMA_CYCLES, 36 ); |
| 1631 | | } else { |
| 1798 | } |
| 1799 | else |
| 1800 | { |
| 1632 | 1801 | gb_lcd.hdma_possible = 1; |
| 1633 | 1802 | } |
| 1634 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 192 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC); |
| 1803 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 192 - gb_lcd.scrollx_adjust - gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_M0_PRE_INC); |
| 1635 | 1804 | break; |
| 1636 | 1805 | case GB_LCD_STATE_LYXX_M0_PRE_INC: /* Just before incrementing the line counter go to mode 2 internally */ |
| 1637 | 1806 | gb_lcd.cmp_line = CMPLINE; |
| 1638 | | if ( CURLINE < 143 ) { |
| 1807 | if ( CURLINE < 143 ) |
| 1808 | { |
| 1639 | 1809 | gb_lcd.mode = 2; |
| 1640 | | if ( LCDSTAT & 0x20 ) { |
| 1641 | | if ( ! gb_lcd.mode_irq ) { |
| 1642 | | if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) { |
| 1810 | if ( LCDSTAT & 0x20 ) |
| 1811 | { |
| 1812 | if ( ! gb_lcd.mode_irq ) |
| 1813 | { |
| 1814 | if ( ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq ) |
| 1815 | { |
| 1643 | 1816 | gb_lcd.mode_irq = 1; |
| 1644 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1817 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1645 | 1818 | } |
| 1646 | | } else { |
| 1819 | } |
| 1820 | else |
| 1821 | { |
| 1647 | 1822 | gb_lcd.mode_irq = 0; |
| 1648 | 1823 | } |
| 1649 | 1824 | } |
| 1650 | 1825 | } |
| 1651 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M0_INC); |
| 1826 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M0_INC); |
| 1652 | 1827 | break; |
| 1653 | 1828 | case GB_LCD_STATE_LYXX_M0_INC: /* Increment LY, stay in M0 for 4 more cycles */ |
| 1654 | 1829 | gb_increment_scanline(); |
| 1655 | 1830 | gb_lcd.delayed_line_irq = gb_lcd.line_irq; |
| 1656 | 1831 | gb_lcd.triggering_line_irq = ( ( gb_lcd.cmp_line == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1657 | 1832 | gb_lcd.line_irq = 0; |
| 1658 | | if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) { |
| 1833 | if ( ! gb_lcd.mode_irq && ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) |
| 1834 | { |
| 1659 | 1835 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1660 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1836 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1661 | 1837 | } |
| 1662 | 1838 | gb_lcd.hdma_possible = 0; |
| 1663 | 1839 | /* Check if we're going into VBlank next */ |
| 1664 | | if ( CURLINE == 144 ) { |
| 1665 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY9X_M1); |
| 1666 | | } else { |
| 1840 | if ( CURLINE == 144 ) |
| 1841 | { |
| 1842 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY9X_M1); |
| 1843 | } |
| 1844 | else |
| 1845 | { |
| 1667 | 1846 | /* Internally switch to mode 2 */ |
| 1668 | 1847 | gb_lcd.mode = 2; |
| 1669 | 1848 | /* Generate lcd interrupt if requested */ |
| 1670 | 1849 | if ( ! gb_lcd.mode_irq && ( LCDSTAT & 0x20 ) && |
| 1671 | | ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) { |
| 1850 | ( ( ! gb_lcd.triggering_line_irq && ! gb_lcd.delayed_line_irq ) || ! ( LCDSTAT & 0x40 ) ) ) |
| 1851 | { |
| 1672 | 1852 | gb_lcd.mode_irq = 1; |
| 1673 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1853 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1674 | 1854 | } |
| 1675 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LYXX_M2); |
| 1855 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LYXX_M2); |
| 1676 | 1856 | } |
| 1677 | 1857 | break; |
| 1678 | 1858 | case GB_LCD_STATE_LY00_M2: /* Switch to mode 2 on line #0 */ |
| r4575 | r4576 | |
| 1681 | 1861 | LCDSTAT = ( LCDSTAT & 0xFC ) | 0x02; |
| 1682 | 1862 | gb_lcd.oam_locked = LOCKED; |
| 1683 | 1863 | /* Generate lcd interrupt if requested */ |
| 1684 | | if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) { |
| 1685 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1864 | if ( ( LCDSTAT & 0x20 ) && ! gb_lcd.line_irq && ! gb_lcd.line_irq ) |
| 1865 | { |
| 1866 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1686 | 1867 | } |
| 1687 | 1868 | /* Check for regular compensation of x-scroll register */ |
| 1688 | 1869 | gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0; |
| 1689 | 1870 | /* Mode 2 lasts approximately 80 clock cycles */ |
| 1690 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3); |
| 1871 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3); |
| 1691 | 1872 | break; |
| 1692 | 1873 | case GB_LCD_STATE_LYXX_M2: /* Switch to mode 2 */ |
| 1693 | 1874 | /* Update STAT register to the correct state */ |
| r4575 | r4576 | |
| 1695 | 1876 | gb_lcd.oam_locked = LOCKED; |
| 1696 | 1877 | /* Generate lcd interrupt if requested */ |
| 1697 | 1878 | if ( ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq && ! ( LCDSTAT & 0x20 ) ) || |
| 1698 | | ( !gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && ( LCDSTAT & 0x20 ) ) ) { |
| 1699 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1879 | ( !gb_lcd.mode_irq && ! gb_lcd.line_irq && ! gb_lcd.delayed_line_irq && ( LCDSTAT & 0x20 ) ) ) |
| 1880 | { |
| 1881 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1700 | 1882 | } |
| 1701 | 1883 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1702 | 1884 | /* Check if LY==LYC STAT bit should be set */ |
| 1703 | | if ( CURLINE == CMPLINE ) { |
| 1885 | if ( CURLINE == CMPLINE ) |
| 1886 | { |
| 1704 | 1887 | LCDSTAT |= 0x04; |
| 1705 | | } else { |
| 1888 | } |
| 1889 | else |
| 1890 | { |
| 1706 | 1891 | LCDSTAT &= ~0x04; |
| 1707 | 1892 | } |
| 1708 | 1893 | /* Check for regular compensation of x-scroll register */ |
| 1709 | 1894 | gb_lcd.scrollx_adjust = ( SCROLLX & 0x04 ) ? 4 : 0; |
| 1710 | 1895 | /* Mode 2 last for approximately 80 clock cycles */ |
| 1711 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3); |
| 1896 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3); |
| 1712 | 1897 | break; |
| 1713 | 1898 | case GB_LCD_STATE_LYXX_M3: /* Switch to mode 3 */ |
| 1714 | 1899 | gb_select_sprites(); |
| r4575 | r4576 | |
| 1720 | 1905 | gb_lcd.pal_locked = LOCKED; |
| 1721 | 1906 | /* Check for compensations of x-scroll register */ |
| 1722 | 1907 | /* Mode 3 lasts for approximately 172+cycles needed to handle sprites clock cycles */ |
| 1723 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0); |
| 1908 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 168 + gb_lcd.scrollx_adjust + gb_lcd.sprite_cycles), GB_LCD_STATE_LYXX_PRE_M0); |
| 1724 | 1909 | gb_lcd.start_x = -1; |
| 1725 | 1910 | break; |
| 1726 | 1911 | case GB_LCD_STATE_LY9X_M1: /* Switch to or stay in mode 1 */ |
| 1727 | | if ( CURLINE == 144 ) { |
| 1912 | if ( CURLINE == 144 ) |
| 1913 | { |
| 1728 | 1914 | /* Trigger VBlank interrupt */ |
| 1729 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1915 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1730 | 1916 | /* Set VBlank lcdstate */ |
| 1731 | 1917 | gb_lcd.mode = 1; |
| 1732 | 1918 | LCDSTAT = (LCDSTAT & 0xFC) | 0x01; |
| 1733 | 1919 | /* Trigger LCD interrupt if requested */ |
| 1734 | | if ( LCDSTAT & 0x10 ) { |
| 1735 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1920 | if ( LCDSTAT & 0x10 ) |
| 1921 | { |
| 1922 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1736 | 1923 | } |
| 1737 | 1924 | } |
| 1738 | 1925 | /* Check if LY==LYC STAT bit should be set */ |
| 1739 | | if ( CURLINE == CMPLINE ) { |
| 1926 | if ( CURLINE == CMPLINE ) |
| 1927 | { |
| 1740 | 1928 | LCDSTAT |= 0x04; |
| 1741 | | } else { |
| 1929 | } |
| 1930 | else |
| 1931 | { |
| 1742 | 1932 | LCDSTAT &= ~0x04; |
| 1743 | 1933 | } |
| 1744 | | if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) { |
| 1745 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1934 | if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) |
| 1935 | { |
| 1936 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1746 | 1937 | } |
| 1747 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 452), GB_LCD_STATE_LY9X_M1_INC); |
| 1938 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 452), GB_LCD_STATE_LY9X_M1_INC); |
| 1748 | 1939 | break; |
| 1749 | 1940 | case GB_LCD_STATE_LY9X_M1_INC: /* Increment scanline counter */ |
| 1750 | 1941 | gb_increment_scanline(); |
| 1751 | 1942 | gb_lcd.delayed_line_irq = gb_lcd.line_irq; |
| 1752 | 1943 | gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1753 | 1944 | gb_lcd.line_irq = 0; |
| 1754 | | if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) { |
| 1945 | if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) |
| 1946 | { |
| 1755 | 1947 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1756 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1948 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1757 | 1949 | } |
| 1758 | | if ( gb_lcd.current_line == 153 ) { |
| 1759 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1); |
| 1760 | | } else { |
| 1761 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY9X_M1); |
| 1950 | if ( gb_lcd.current_line == 153 ) |
| 1951 | { |
| 1952 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1); |
| 1953 | } |
| 1954 | else |
| 1955 | { |
| 1956 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY9X_M1); |
| 1762 | 1957 | } |
| 1763 | 1958 | break; |
| 1764 | 1959 | case GB_LCD_STATE_LY00_M1: /* we stay in VBlank but current line counter should already be incremented */ |
| 1765 | 1960 | /* Check LY=LYC for line #153 */ |
| 1766 | | if ( gb_lcd.delayed_line_irq ) { |
| 1767 | | if ( gb_lcd.triggering_line_irq ) { |
| 1768 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1961 | if ( gb_lcd.delayed_line_irq ) |
| 1962 | { |
| 1963 | if ( gb_lcd.triggering_line_irq ) |
| 1964 | { |
| 1965 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1769 | 1966 | } |
| 1770 | 1967 | } |
| 1771 | 1968 | gb_lcd.delayed_line_irq = gb_lcd.delayed_line_irq | gb_lcd.line_irq; |
| 1772 | | if ( CURLINE == CMPLINE ) { |
| 1969 | if ( CURLINE == CMPLINE ) |
| 1970 | { |
| 1773 | 1971 | LCDSTAT |= 0x04; |
| 1774 | | } else { |
| 1972 | } |
| 1973 | else |
| 1974 | { |
| 1775 | 1975 | LCDSTAT &= ~0x04; |
| 1776 | 1976 | } |
| 1777 | 1977 | gb_increment_scanline(); |
| 1778 | 1978 | gb_lcd.triggering_line_irq = ( ( CMPLINE == CURLINE ) && ( LCDSTAT & 0x40 ) ) ? 1 : 0; |
| 1779 | 1979 | gb_lcd.line_irq = 0; |
| 1780 | 1980 | LCDSTAT &= 0xFB; |
| 1781 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1_1); |
| 1981 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1_1); |
| 1782 | 1982 | break; |
| 1783 | 1983 | case GB_LCD_STATE_LY00_M1_1: |
| 1784 | | if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) { |
| 1984 | if ( ! gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) |
| 1985 | { |
| 1785 | 1986 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1786 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1987 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1787 | 1988 | } |
| 1788 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M1_2); |
| 1989 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M1_2); |
| 1789 | 1990 | break; |
| 1790 | 1991 | case GB_LCD_STATE_LY00_M1_2: /* Rest of line #0 during VBlank */ |
| 1791 | | if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) { |
| 1992 | if ( gb_lcd.delayed_line_irq && gb_lcd.triggering_line_irq ) |
| 1993 | { |
| 1792 | 1994 | gb_lcd.line_irq = gb_lcd.triggering_line_irq; |
| 1793 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 1995 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1794 | 1996 | } |
| 1795 | | if ( CURLINE == CMPLINE ) { |
| 1997 | if ( CURLINE == CMPLINE ) |
| 1998 | { |
| 1796 | 1999 | LCDSTAT |= 0x04; |
| 1797 | | } else { |
| 2000 | } |
| 2001 | else |
| 2002 | { |
| 1798 | 2003 | LCDSTAT &= ~0x04; |
| 1799 | 2004 | } |
| 1800 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 444), GB_LCD_STATE_LY00_M0); |
| 2005 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 444), GB_LCD_STATE_LY00_M0); |
| 1801 | 2006 | break; |
| 1802 | 2007 | case GB_LCD_STATE_LY00_M0: /* The STAT register seems to go to 0 for about 4 cycles */ |
| 1803 | 2008 | /* Set Mode 0 lcdstat */ |
| 1804 | 2009 | gb_lcd.mode = 0; |
| 1805 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 4), GB_LCD_STATE_LY00_M2); |
| 2010 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 4), GB_LCD_STATE_LY00_M2); |
| 1806 | 2011 | break; |
| 1807 | 2012 | } |
| 1808 | | } else { |
| 2013 | } |
| 2014 | else |
| 2015 | { |
| 1809 | 2016 | gb_increment_scanline(); |
| 1810 | | if ( gb_lcd.current_line < 144 ) { |
| 2017 | if ( gb_lcd.current_line < 144 ) |
| 2018 | { |
| 1811 | 2019 | update_scanline( machine ); |
| 1812 | 2020 | } |
| 1813 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 456), 0); |
| 2021 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 456), 0); |
| 1814 | 2022 | } |
| 1815 | 2023 | } |
| 1816 | 2024 | |
| 1817 | | static void gb_lcd_switch_on( running_machine *machine ) { |
| 2025 | static void gb_lcd_switch_on( running_machine *machine ) |
| 2026 | { |
| 1818 | 2027 | gb_lcd.current_line = 0; |
| 1819 | 2028 | gb_lcd.previous_line = 153; |
| 1820 | 2029 | gb_lcd.window_lines_drawn = 0; |
| r4575 | r4576 | |
| 1823 | 2032 | gb_lcd.mode = 0; |
| 1824 | 2033 | gb_lcd.oam_locked = LOCKED; /* TODO: Investigate whether this OAM locking is correct. */ |
| 1825 | 2034 | /* Check for LY=LYC coincidence */ |
| 1826 | | if ( CURLINE == CMPLINE ) { |
| 2035 | if ( CURLINE == CMPLINE ) |
| 2036 | { |
| 1827 | 2037 | LCDSTAT |= 0x04; |
| 1828 | 2038 | /* Generate lcd interrupt if requested */ |
| 1829 | | if ( LCDSTAT & 0x40 ) { |
| 1830 | | cpu_set_input_line( machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 2039 | if ( LCDSTAT & 0x40 ) |
| 2040 | { |
| 2041 | cputag_set_input_line( machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1831 | 2042 | } |
| 1832 | 2043 | } |
| 1833 | 2044 | gb_lcd.state = GB_LCD_STATE_LY00_M2; |
| 1834 | | timer_adjust_oneshot(gb_lcd.lcd_timer, cpu_clocks_to_attotime(machine->cpu[0], 80), GB_LCD_STATE_LYXX_M3); |
| 2045 | timer_adjust_oneshot(gb_lcd.lcd_timer, cputag_clocks_to_attotime(machine, "maincpu", 80), GB_LCD_STATE_LYXX_M3); |
| 1835 | 2046 | } |
| 1836 | 2047 | |
| 1837 | | READ8_HANDLER( gb_video_r ) { |
| 2048 | READ8_HANDLER( gb_video_r ) |
| 2049 | { |
| 1838 | 2050 | return gb_vid_regs[offset]; |
| 1839 | 2051 | } |
| 1840 | 2052 | |
| 1841 | | READ8_HANDLER( gb_vram_r ) { |
| 2053 | READ8_HANDLER( gb_vram_r ) |
| 2054 | { |
| 1842 | 2055 | return ( gb_lcd.vram_locked == LOCKED ) ? 0xFF : gb_vram_ptr[offset]; |
| 1843 | 2056 | } |
| 1844 | 2057 | |
| 1845 | | WRITE8_HANDLER( gb_vram_w ) { |
| 1846 | | if ( gb_lcd.vram_locked == LOCKED ) { |
| 2058 | WRITE8_HANDLER( gb_vram_w ) |
| 2059 | { |
| 2060 | if ( gb_lcd.vram_locked == LOCKED ) |
| 2061 | { |
| 1847 | 2062 | return; |
| 1848 | 2063 | } |
| 1849 | 2064 | gb_vram_ptr[offset] = data; |
| 1850 | 2065 | } |
| 1851 | 2066 | |
| 1852 | | READ8_HANDLER( gb_oam_r ) { |
| 2067 | READ8_HANDLER( gb_oam_r ) |
| 2068 | { |
| 1853 | 2069 | return ( gb_lcd.oam_locked == LOCKED ) ? 0xFF : gb_oam[offset]; |
| 1854 | 2070 | } |
| 1855 | 2071 | |
| 1856 | | WRITE8_HANDLER( gb_oam_w ) { |
| 1857 | | if ( gb_lcd.oam_locked == LOCKED || offset >= 0xa0 ) { |
| 2072 | WRITE8_HANDLER( gb_oam_w ) |
| 2073 | { |
| 2074 | if ( gb_lcd.oam_locked == LOCKED || offset >= 0xa0 ) |
| 2075 | { |
| 1858 | 2076 | return; |
| 1859 | 2077 | } |
| 1860 | 2078 | gb_oam[offset] = data; |
| 1861 | 2079 | } |
| 1862 | 2080 | |
| 1863 | | WRITE8_HANDLER ( gb_video_w ) { |
| 1864 | | switch (offset) { |
| 2081 | WRITE8_HANDLER ( gb_video_w ) |
| 2082 | { |
| 2083 | switch (offset) |
| 2084 | { |
| 1865 | 2085 | case 0x00: /* LCDC - LCD Control */ |
| 1866 | 2086 | gb_chrgen = gb_vram + ((data & 0x10) ? 0x0000 : 0x0800); |
| 1867 | 2087 | gb_tile_no_mod = (data & 0x10) ? 0x00 : 0x80; |
| 1868 | 2088 | gb_bgdtab = gb_vram + ((data & 0x08) ? 0x1C00 : 0x1800 ); |
| 1869 | 2089 | gb_wndtab = gb_vram + ((data & 0x40) ? 0x1C00 : 0x1800 ); |
| 1870 | 2090 | /* if LCD controller is switched off, set STAT and LY to 00 */ |
| 1871 | | if ( ! ( data & 0x80 ) ) { |
| 2091 | if ( ! ( data & 0x80 ) ) |
| 2092 | { |
| 1872 | 2093 | LCDSTAT &= ~0x03; |
| 1873 | 2094 | CURLINE = 0; |
| 1874 | 2095 | gb_lcd.oam_locked = UNLOCKED; |
| 1875 | 2096 | gb_lcd.vram_locked = UNLOCKED; |
| 1876 | 2097 | } |
| 1877 | 2098 | /* If LCD is being switched on */ |
| 1878 | | if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) { |
| 2099 | if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) |
| 2100 | { |
| 1879 | 2101 | gb_lcd_switch_on( space->machine ); |
| 1880 | 2102 | } |
| 1881 | 2103 | break; |
| r4575 | r4576 | |
| 1886 | 2108 | Writing to STAT when the LCD controller is active causes a STAT |
| 1887 | 2109 | interrupt to be triggered. |
| 1888 | 2110 | */ |
| 1889 | | if ( LCDCONT & 0x80 ) { |
| 2111 | if ( LCDCONT & 0x80 ) |
| 2112 | { |
| 1890 | 2113 | /* Triggers seen so far: |
| 1891 | 2114 | - 0x40 -> 0x00 - trigger |
| 1892 | 2115 | - 0x00 -> 0x08 - trigger |
| r4575 | r4576 | |
| 1907 | 2130 | ( ! ( LCDSTAT & 0x48 ) && ( data & 0x08 ) ) || |
| 1908 | 2131 | ( ( LCDSTAT & 0x60 ) == 0x00 && ( data & 0x60 ) == 0x20 ) || |
| 1909 | 2132 | ( ( LCDSTAT & 0x60 ) == 0x20 && ( data & 0x40 ) ) |
| 1910 | | ) ) { |
| 1911 | | cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 2133 | ) ) |
| 2134 | { |
| 2135 | cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1912 | 2136 | } |
| 1913 | 2137 | /* |
| 1914 | 2138 | - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger |
| 1915 | 2139 | - 0x20 -> 0x00/0x10/0x20/0x40 (mode 0, after m2int) - trigger (stat bug) |
| 1916 | 2140 | - 0x00 -> 0xXX (mode 0) - trigger stat bug |
| 1917 | 2141 | */ |
| 1918 | | if ( gb_lcd.mode_irq && gb_lcd.mode == 0 ) { |
| 1919 | | cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 2142 | if ( gb_lcd.mode_irq && gb_lcd.mode == 0 ) |
| 2143 | { |
| 2144 | cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1920 | 2145 | } |
| 1921 | 2146 | } |
| 1922 | 2147 | break; |
| 1923 | 2148 | case 0x04: /* LY - LCD Y-coordinate */ |
| 1924 | 2149 | return; |
| 1925 | 2150 | case 0x05: /* LYC */ |
| 1926 | | if ( CMPLINE != data ) { |
| 1927 | | if ( CURLINE == data ) { |
| 1928 | | if ( gb_lcd.state != GB_LCD_STATE_LYXX_M0_INC && gb_lcd.state != GB_LCD_STATE_LY9X_M1_INC ) { |
| 2151 | if ( CMPLINE != data ) |
| 2152 | { |
| 2153 | if ( CURLINE == data ) |
| 2154 | { |
| 2155 | if ( gb_lcd.state != GB_LCD_STATE_LYXX_M0_INC && gb_lcd.state != GB_LCD_STATE_LY9X_M1_INC ) |
| 2156 | { |
| 1929 | 2157 | LCDSTAT |= 0x04; |
| 1930 | 2158 | /* Generate lcd interrupt if requested */ |
| 1931 | | if ( LCDSTAT & 0x40 ) { |
| 1932 | | cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 2159 | if ( LCDSTAT & 0x40 ) |
| 2160 | { |
| 2161 | cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 1933 | 2162 | } |
| 1934 | 2163 | } |
| 1935 | | } else { |
| 2164 | } |
| 2165 | else |
| 2166 | { |
| 1936 | 2167 | LCDSTAT &= 0xFB; |
| 1937 | 2168 | gb_lcd.triggering_line_irq = 0; |
| 1938 | 2169 | } |
| r4575 | r4576 | |
| 1979 | 2210 | gb_vid_regs[ offset ] = data; |
| 1980 | 2211 | } |
| 1981 | 2212 | |
| 1982 | | READ8_HANDLER( gbc_video_r ) { |
| 1983 | | switch( offset ) { |
| 2213 | READ8_HANDLER( gbc_video_r ) |
| 2214 | { |
| 2215 | switch( offset ) |
| 2216 | { |
| 1984 | 2217 | case 0x11: /* FF51 */ |
| 1985 | 2218 | case 0x12: /* FF52 */ |
| 1986 | 2219 | case 0x13: /* FF53 */ |
| r4575 | r4576 | |
| 1988 | 2221 | return 0xFF; |
| 1989 | 2222 | case 0x29: /* FF69 */ |
| 1990 | 2223 | case 0x2B: /* FF6B */ |
| 1991 | | if ( gb_lcd.pal_locked == LOCKED ) { |
| 2224 | if ( gb_lcd.pal_locked == LOCKED ) |
| 2225 | { |
| 1992 | 2226 | return 0xFF; |
| 1993 | 2227 | } |
| 1994 | 2228 | break; |
| r4575 | r4576 | |
| 1996 | 2230 | return gb_vid_regs[offset]; |
| 1997 | 2231 | } |
| 1998 | 2232 | |
| 1999 | | WRITE8_HANDLER ( gbc_video_w ) { |
| 2233 | WRITE8_HANDLER ( gbc_video_w ) |
| 2234 | { |
| 2000 | 2235 | static const UINT16 gbc_to_gb_pal[4] = {32767, 21140, 10570, 0}; |
| 2001 | 2236 | static UINT16 BP = 0, OP = 0; |
| 2002 | 2237 | |
| 2003 | | switch( offset ) { |
| 2238 | switch( offset ) |
| 2239 | { |
| 2004 | 2240 | case 0x00: /* LCDC - LCD Control */ |
| 2005 | 2241 | gb_chrgen = gb_vram + ((data & 0x10) ? 0x0000 : 0x0800); |
| 2006 | 2242 | gbc_chrgen = gb_vram + ((data & 0x10) ? 0x2000 : 0x2800); |
| r4575 | r4576 | |
| 2010 | 2246 | gb_wndtab = gb_vram + ((data & 0x40) ? 0x1C00 : 0x1800); |
| 2011 | 2247 | gbc_wndtab = gb_vram + ((data & 0x40) ? 0x3C00 : 0x3800); |
| 2012 | 2248 | /* if LCD controller is switched off, set STAT to 00 */ |
| 2013 | | if ( ! ( data & 0x80 ) ) { |
| 2249 | if ( ! ( data & 0x80 ) ) |
| 2250 | { |
| 2014 | 2251 | LCDSTAT &= ~0x03; |
| 2015 | 2252 | CURLINE = 0; |
| 2016 | 2253 | gb_lcd.oam_locked = UNLOCKED; |
| r4575 | r4576 | |
| 2018 | 2255 | gb_lcd.pal_locked = UNLOCKED; |
| 2019 | 2256 | } |
| 2020 | 2257 | /* If LCD is being switched on */ |
| 2021 | | if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) { |
| 2258 | if ( !( LCDCONT & 0x80 ) && ( data & 0x80 ) ) |
| 2259 | { |
| 2022 | 2260 | gb_lcd_switch_on( space->machine ); |
| 2023 | 2261 | } |
| 2024 | 2262 | break; |
| 2025 | 2263 | case 0x01: /* STAT - LCD Status */ |
| 2026 | 2264 | data = 0x80 | (data & 0x78) | (LCDSTAT & 0x07); |
| 2027 | | if ( LCDCONT & 0x80 ) { |
| 2265 | if ( LCDCONT & 0x80 ) |
| 2266 | { |
| 2028 | 2267 | /* |
| 2029 | 2268 | - 0x20 -> 0x08/0x18/0x28/0x48 (mode 0, after m2int) - trigger |
| 2030 | 2269 | */ |
| 2031 | | if ( gb_lcd.mode_irq && gb_lcd.mode == 0 && ( LCDSTAT & 0x28 ) == 0x20 && ( data & 0x08 ) ) { |
| 2032 | | cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 2270 | if ( gb_lcd.mode_irq && gb_lcd.mode == 0 && ( LCDSTAT & 0x28 ) == 0x20 && ( data & 0x08 ) ) |
| 2271 | { |
| 2272 | cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 2033 | 2273 | } |
| 2034 | 2274 | /* Check if line irqs are being disabled */ |
| 2035 | | if ( ! ( data & 0x40 ) ) { |
| 2275 | if ( ! ( data & 0x40 ) ) |
| 2276 | { |
| 2036 | 2277 | gb_lcd.delayed_line_irq = 0; |
| 2037 | 2278 | } |
| 2038 | 2279 | /* Check if line irqs are being enabled */ |
| 2039 | | if ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) ) { |
| 2040 | | if ( CMPLINE == CURLINE ) { |
| 2280 | if ( ! ( LCDSTAT & 0x40 ) && ( data & 0x40 ) ) |
| 2281 | { |
| 2282 | if ( CMPLINE == CURLINE ) |
| 2283 | { |
| 2041 | 2284 | gb_lcd.line_irq = 1; |
| 2042 | | cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 2285 | cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 2043 | 2286 | } |
| 2044 | 2287 | } |
| 2045 | 2288 | } |
| 2046 | 2289 | break; |
| 2047 | 2290 | case 0x05: /* LYC */ |
| 2048 | | if ( CMPLINE != data ) { |
| 2291 | if ( CMPLINE != data ) |
| 2292 | { |
| 2049 | 2293 | if ( ( gb_lcd.state != GB_LCD_STATE_LYXX_M0_PRE_INC && CURLINE == data ) || |
| 2050 | | ( gb_lcd.state == GB_LCD_STATE_LYXX_M0_INC && gb_lcd.triggering_line_irq ) ) { |
| 2294 | ( gb_lcd.state == GB_LCD_STATE_LYXX_M0_INC && gb_lcd.triggering_line_irq ) ) |
| 2295 | { |
| 2051 | 2296 | LCDSTAT |= 0x04; |
| 2052 | 2297 | /* Generate lcd interrupt if requested */ |
| 2053 | | if ( LCDSTAT & 0x40 ) { |
| 2054 | | cpu_set_input_line( space->machine->cpu[0], LCD_INT, HOLD_LINE ); |
| 2298 | if ( LCDSTAT & 0x40 ) |
| 2299 | { |
| 2300 | cputag_set_input_line( space->machine, "maincpu", LCD_INT, HOLD_LINE ); |
| 2055 | 2301 | } |
| 2056 | | } else { |
| 2302 | } |
| 2303 | else |
| 2304 | { |
| 2057 | 2305 | LCDSTAT &= 0xFB; |
| 2058 | 2306 | gb_lcd.triggering_line_irq = 0; |
| 2059 | 2307 | gb_lcd.cmp_line = data; |
| r4575 | r4576 | |
| 2062 | 2310 | break; |
| 2063 | 2311 | case 0x07: /* BGP - GB background palette */ |
| 2064 | 2312 | /* Some GBC games are lazy and still call this */ |
| 2065 | | if( gbc_mode == GBC_MODE_MONO ) { |
| 2313 | if( gbc_mode == GBC_MODE_MONO ) |
| 2314 | { |
| 2066 | 2315 | update_scanline( space->machine ); |
| 2067 | 2316 | cgb_bpal[0] = gbc_to_gb_pal[(data & 0x03)]; |
| 2068 | 2317 | cgb_bpal[1] = gbc_to_gb_pal[(data & 0x0C) >> 2]; |
| r4575 | r4576 | |
| 2126 | 2375 | data &= 0x7f; |
| 2127 | 2376 | gb_vid_regs[offset] = data; |
| 2128 | 2377 | /* Check if HDMA should be immediately performed */ |
| 2129 | | if ( gb_lcd.hdma_possible ) { |
| 2378 | if ( gb_lcd.hdma_possible ) |
| 2379 | { |
| 2130 | 2380 | gbc_hdma( space->machine, 0x10 ); |
| 2131 | 2381 | // cpunum_set_reg( 0, LR35902_DMA_CYCLES, 36 ); |
| 2132 | 2382 | gb_lcd.hdma_possible = 0; |
| r4575 | r4576 | |
| 2136 | 2386 | case 0x28: /* BCPS - Background palette specification */ |
| 2137 | 2387 | break; |
| 2138 | 2388 | case 0x29: /* BCPD - background palette data */ |
| 2139 | | if ( gb_lcd.pal_locked == LOCKED ) { |
| 2389 | if ( gb_lcd.pal_locked == LOCKED ) |
| 2390 | { |
| 2140 | 2391 | return; |
| 2141 | 2392 | } |
| 2142 | 2393 | if( GBCBCPS & 0x1 ) |
| r4575 | r4576 | |
| 2154 | 2405 | case 0x2A: /* OCPS - Object palette specification */ |
| 2155 | 2406 | break; |
| 2156 | 2407 | case 0x2B: /* OCPD - Object palette data */ |
| 2157 | | if ( gb_lcd.pal_locked == LOCKED ) { |
| 2408 | if ( gb_lcd.pal_locked == LOCKED ) |
| 2409 | { |
| 2158 | 2410 | return; |
| 2159 | 2411 | } |
| 2160 | 2412 | if( GBCOCPS & 0x1 ) |
src/mess/machine/gb.c
| r4575 | r4576 | |
| 161 | 161 | /* #define V_BANK*/ /* Display bank switching debug information */ |
| 162 | 162 | #endif |
| 163 | 163 | |
| 164 | | static void gb_init_regs(running_machine *machine) { |
| 164 | static void gb_init_regs(running_machine *machine) |
| 165 | { |
| 165 | 166 | /* Initialize the registers */ |
| 166 | 167 | SIODATA = 0x00; |
| 167 | 168 | SIOCONT = 0x7E; |
| 168 | 169 | |
| 169 | | gb_io_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x05, 0x00 ); /* TIMECNT */ |
| 170 | | gb_io_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x06, 0x00 ); /* TIMEMOD */ |
| 170 | gb_io_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x05, 0x00 ); /* TIMECNT */ |
| 171 | gb_io_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x06, 0x00 ); /* TIMEMOD */ |
| 171 | 172 | } |
| 172 | 173 | |
| 173 | | static void gb_rom16_0000( running_machine *machine, UINT8 *addr ) { |
| 174 | static void gb_rom16_0000( running_machine *machine, UINT8 *addr ) |
| 175 | { |
| 174 | 176 | memory_set_bankptr( machine, 5, addr ); |
| 175 | 177 | memory_set_bankptr( machine, 10, addr + 0x0100 ); |
| 176 | 178 | } |
| 177 | 179 | |
| 178 | | static void gb_rom16_4000( running_machine *machine, UINT8 *addr ) { |
| 180 | static void gb_rom16_4000( running_machine *machine, UINT8 *addr ) |
| 181 | { |
| 179 | 182 | memory_set_bankptr( machine, 1, addr ); |
| 180 | 183 | memory_set_bankptr( machine, 4, addr + 0x2000 ); |
| 181 | 184 | } |
| 182 | 185 | |
| 183 | | static void gb_rom8_4000( running_machine *machine, UINT8 *addr ) { |
| 186 | static void gb_rom8_4000( running_machine *machine, UINT8 *addr ) |
| 187 | { |
| 184 | 188 | memory_set_bankptr( machine, 1, addr ); |
| 185 | 189 | } |
| 186 | 190 | |
| 187 | | static void gb_rom8_6000( running_machine *machine, UINT8 *addr ) { |
| 191 | static void gb_rom8_6000( running_machine *machine, UINT8 *addr ) |
| 192 | { |
| 188 | 193 | memory_set_bankptr( machine, 4, addr ); |
| 189 | 194 | } |
| 190 | 195 | |
| 191 | | static void gb_init(running_machine *machine) { |
| 192 | | const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ); |
| 196 | static void gb_init(running_machine *machine) |
| 197 | { |
| 198 | const address_space *space = cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ); |
| 193 | 199 | |
| 194 | 200 | /* Initialize the memory banks */ |
| 195 | 201 | MBC1Mode = 0; |
| r4575 | r4576 | |
| 379 | 385 | memory_set_bankptr(machine, 10, ROMMap[ROMBank00] ? ROMMap[ROMBank00] + 0x0100 : gb_dummy_rom_bank + 0x0100); |
| 380 | 386 | |
| 381 | 387 | /* Allocate memory for internal ram */ |
| 382 | | for( ii = 0; ii < 8; ii++ ) { |
| 388 | for( ii = 0; ii < 8; ii++ ) |
| 389 | { |
| 383 | 390 | GBC_RAMMap[ii] = mess_ram + CGB_START_RAM_BANKS + ii * 0x1000; |
| 384 | 391 | memset (GBC_RAMMap[ii], 0, 0x1000); |
| 385 | 392 | } |
| 386 | | gbc_io2_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x30, 0x00 ); |
| 393 | gbc_io2_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x30, 0x00 ); |
| 387 | 394 | |
| 388 | 395 | /* Initialise registers */ |
| 389 | | gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x6C, 0xFE ); |
| 390 | | gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x72, 0x00 ); |
| 391 | | gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x73, 0x00 ); |
| 392 | | gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x74, 0x8F ); |
| 393 | | gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x75, 0x00 ); |
| 394 | | gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x76, 0x00 ); |
| 395 | | gb_io_w( cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ), 0x77, 0x00 ); |
| 396 | gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x6C, 0xFE ); |
| 397 | gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x72, 0x00 ); |
| 398 | gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x73, 0x00 ); |
| 399 | gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x74, 0x8F ); |
| 400 | gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x75, 0x00 ); |
| 401 | gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x76, 0x00 ); |
| 402 | gb_io_w( cputag_get_address_space( machine, "maincpu", ADDRESS_SPACE_PROGRAM ), 0x77, 0x00 ); |
| 396 | 403 | |
| 397 | 404 | /* Are we in colour or mono mode? */ |
| 398 | 405 | gbc_mode = GBC_MODE_MONO; |
| r4575 | r4576 | |
| 417 | 424 | image_battery_save(devtag_get_device(machine, "cart"), gb_cart_ram, RAMBanks * 0x2000 ); |
| 418 | 425 | } |
| 419 | 426 | |
| 420 | | static void gb_set_mbc1_banks( running_machine *machine ) { |
| 427 | static void gb_set_mbc1_banks( running_machine *machine ) |
| 428 | { |
| 421 | 429 | gb_rom16_4000( machine, ROMMap[ ROMBank ] ); |
| 422 | 430 | memory_set_bankptr( machine, 2, RAMMap[ MBC1Mode ? ( ROMBank >> 5 ) : 0 ] ); |
| 423 | 431 | } |
| r4575 | r4576 | |
| 468 | 476 | Writing into 3000-3FFF sets the 9th bit |
| 469 | 477 | */ |
| 470 | 478 | logerror( "0x%04X: MBC5 ROM Bank select write 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data ); |
| 471 | | if( offset & 0x1000 ) { |
| 479 | if( offset & 0x1000 ) |
| 480 | { |
| 472 | 481 | ROMBank = (ROMBank & 0xFF ) | ( ( data & 0x01 ) << 8 ); |
| 473 | | } else { |
| 482 | } |
| 483 | else |
| 484 | { |
| 474 | 485 | ROMBank = (ROMBank & 0x100 ) | data; |
| 475 | 486 | } |
| 476 | 487 | /* Switch banks */ |
| 477 | 488 | gb_rom16_4000( space->machine, ROMMap[ROMBank] ); |
| 478 | 489 | } |
| 479 | 490 | |
| 480 | | static WRITE8_HANDLER( gb_ram_bank_select_mbc6 ) { |
| 491 | static WRITE8_HANDLER( gb_ram_bank_select_mbc6 ) |
| 492 | { |
| 481 | 493 | logerror( "0x%04X: write to mbc6 ram enable area: %04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data ); |
| 482 | 494 | } |
| 483 | 495 | |
| 484 | | static WRITE8_HANDLER( gb_rom_bank_select_mbc6_1 ) { |
| 496 | static WRITE8_HANDLER( gb_rom_bank_select_mbc6_1 ) |
| 497 | { |
| 485 | 498 | logerror( "0x%04X: write to mbc6 rom area: 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0x2000 + offset, data ); |
| 486 | | if ( offset & 0x0800 ) { |
| 487 | | if ( data == 0x00 ) { |
| 499 | if ( offset & 0x0800 ) |
| 500 | { |
| 501 | if ( data == 0x00 ) |
| 502 | { |
| 488 | 503 | gb_rom8_4000( space->machine, ROMMap[ROMBank>>1] + ( ( ROMBank & 0x01 ) ? 0x2000 : 0x0000 ) ); |
| 489 | 504 | } |
| 490 | | } else { |
| 505 | } |
| 506 | else |
| 507 | { |
| 491 | 508 | ROMBank = data; |
| 492 | 509 | } |
| 493 | 510 | } |
| 494 | 511 | |
| 495 | | static WRITE8_HANDLER( gb_rom_bank_select_mbc6_2 ) { |
| 512 | static WRITE8_HANDLER( gb_rom_bank_select_mbc6_2 ) |
| 513 | { |
| 496 | 514 | logerror( "0x%04X: write to mbc6 rom area: 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0x3000 + offset, data ); |
| 497 | | if ( offset & 0x0800 ) { |
| 498 | | if ( data == 0x00 ) { |
| 515 | if ( offset & 0x0800 ) |
| 516 | { |
| 517 | if ( data == 0x00 ) |
| 518 | { |
| 499 | 519 | gb_rom8_6000( space->machine, ROMMap[ROMBank00>>1] + ( ( ROMBank00 & 0x01 ) ? 0x2000 : 0x0000 ) ); |
| 500 | 520 | } |
| 501 | | } else { |
| 521 | } |
| 522 | else |
| 523 | { |
| 502 | 524 | ROMBank00 = data; |
| 503 | 525 | } |
| 504 | 526 | } |
| 505 | 527 | |
| 506 | | static WRITE8_HANDLER( gb_rom_bank_select_mbc7 ) { |
| 528 | static WRITE8_HANDLER( gb_rom_bank_select_mbc7 ) |
| 529 | { |
| 507 | 530 | logerror( "0x%04X: write to mbc7 rom select register: 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0x2000 + offset, data ); |
| 508 | 531 | /* Bit 12 must be set for writing to the mbc register */ |
| 509 | | if ( offset & 0x0100 ) { |
| 532 | if ( offset & 0x0100 ) |
| 533 | { |
| 510 | 534 | ROMBank = data; |
| 511 | 535 | gb_rom16_4000( space->machine, ROMMap[ROMBank] ); |
| 512 | 536 | } |
| 513 | 537 | } |
| 514 | 538 | |
| 515 | | static WRITE8_HANDLER( gb_rom_bank_unknown_mbc7 ) { |
| 539 | static WRITE8_HANDLER( gb_rom_bank_unknown_mbc7 ) |
| 540 | { |
| 516 | 541 | logerror( "0x%04X: write to mbc7 rom area: 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0x3000 + offset, data ); |
| 517 | 542 | /* Bit 12 must be set for writing to the mbc register */ |
| 518 | | if ( offset & 0x0100 ) { |
| 519 | | switch( offset & 0x7000 ) { |
| 543 | if ( offset & 0x0100 ) |
| 544 | { |
| 545 | switch( offset & 0x7000 ) |
| 546 | { |
| 520 | 547 | case 0x0000: /* 0x3000-0x3fff */ |
| 521 | 548 | case 0x1000: /* 0x4000-0x4fff */ |
| 522 | 549 | case 0x2000: /* 0x5000-0x5fff */ |
| r4575 | r4576 | |
| 527 | 554 | } |
| 528 | 555 | } |
| 529 | 556 | |
| 530 | | static WRITE8_HANDLER( gb_rom_bank_select_wisdom ) { |
| 557 | static WRITE8_HANDLER( gb_rom_bank_select_wisdom ) |
| 558 | { |
| 531 | 559 | logerror( "0x%04X: wisdom tree mapper write to address 0x%04X\n", cpu_get_pc( space->cpu ), offset ); |
| 532 | 560 | /* The address determines the bank to select */ |
| 533 | 561 | ROMBank = ( offset << 1 ) & 0x1FF; |
| r4575 | r4576 | |
| 550 | 578 | static WRITE8_HANDLER( gb_ram_bank_select_mbc3 ) |
| 551 | 579 | { |
| 552 | 580 | logerror( "0x%04X: write mbc3 ram bank select register 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data ); |
| 553 | | if( data & 0x8 ) { /* RTC banks */ |
| 554 | | if ( CartType & TIMER ) { |
| 581 | if( data & 0x8 ) |
| 582 | { /* RTC banks */ |
| 583 | if ( CartType & TIMER ) |
| 584 | { |
| 555 | 585 | MBC3RTCBank = data & 0x07; |
| 556 | | if ( data < 5 ) { |
| 586 | if ( data < 5 ) |
| 587 | { |
| 557 | 588 | memset( MBC3RTCData, MBC3RTCMap[MBC3RTCBank], 0x2000 ); |
| 558 | 589 | memory_set_bankptr( space->machine, 2, MBC3RTCData ); |
| 559 | 590 | } |
| 560 | 591 | } |
| 561 | | } else { /* RAM banks */ |
| 592 | } |
| 593 | else |
| 594 | { /* RAM banks */ |
| 562 | 595 | RAMBank = data & 0x3; |
| 563 | 596 | MBC3RTCBank = 0xFF; |
| 564 | 597 | /* Switch banks */ |
| r4575 | r4576 | |
| 570 | 603 | { |
| 571 | 604 | logerror( "0x%04X: MBC5 RAM Bank select write 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data ); |
| 572 | 605 | data &= 0x0F; |
| 573 | | if( CartType & RUMBLE ) { |
| 606 | if( CartType & RUMBLE ) |
| 607 | { |
| 574 | 608 | data &= 0x7; |
| 575 | 609 | } |
| 576 | 610 | RAMBank = data; |
| r4575 | r4576 | |
| 594 | 628 | static WRITE8_HANDLER( gb_mem_mode_select_mbc3 ) |
| 595 | 629 | { |
| 596 | 630 | logerror( "0x%04X: Write to mbc3 mem mode select register 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), offset, data ); |
| 597 | | if( CartType & TIMER ) { |
| 631 | if( CartType & TIMER ) |
| 632 | { |
| 598 | 633 | /* FIXME: RTC Latch goes here */ |
| 599 | 634 | MBC3RTCMap[0] = 50; /* Seconds */ |
| 600 | 635 | MBC3RTCMap[1] = 40; /* Minutes */ |
| r4575 | r4576 | |
| 604 | 639 | } |
| 605 | 640 | } |
| 606 | 641 | |
| 607 | | static WRITE8_HANDLER( gb_ram_tama5 ) { |
| 642 | static WRITE8_HANDLER( gb_ram_tama5 ) |
| 643 | { |
| 608 | 644 | logerror( "0x%04X: TAMA5 write 0x%04X <- 0x%02X\n", cpu_get_pc( space->cpu ), 0xA000 + offset, data ); |
| 609 | | switch( offset & 0x0001 ) { |
| 645 | switch( offset & 0x0001 ) |
| 646 | { |
| 610 | 647 | case 0x0000: /* Write to data register */ |
| 611 | | switch( gbLastTama5Command ) { |
| 648 | switch( gbLastTama5Command ) |
| 649 | { |
| 612 | 650 | case 0x00: /* Bits 0-3 for rom bank selection */ |
| 613 | 651 | ROMBank = ( ROMBank & 0xF0 ) | ( data & 0x0F ); |
| 614 | 652 | gb_rom16_4000( space->machine, ROMMap[ROMBank] ); |
| r4575 | r4576 | |
| 630 | 668 | /* This address always seems to written last, so we'll just |
| 631 | 669 | execute the command here */ |
| 632 | 670 | gbTama5Address = ( gbTama5Address & 0xF0 ) | ( data & 0x0F ); |
| 633 | | switch ( gbTama5Address & 0xE0 ) { |
| 671 | switch ( gbTama5Address & 0xE0 ) |
| 672 | { |
| 634 | 673 | case 0x00: /* Write memory */ |
| 635 | 674 | logerror( "Write tama5 memory 0x%02X <- 0x%02X\n", gbTama5Address & 0x1F, gbTama5Byte ); |
| 636 | 675 | gbTama5Memory[ gbTama5Address & 0x1F ] = gbTama5Byte; |
| r4575 | r4576 | |
| 640 | 679 | gbTama5Byte = gbTama5Memory[ gbTama5Address & 0x1F ]; |
| 641 | 680 | break; |
| 642 | 681 | case 0x40: /* Unknown, some kind of read */ |
| 643 | | if ( ( gbTama5Address & 0x1F ) == 0x12 ) { |
| 682 | if ( ( gbTama5Address & 0x1F ) == 0x12 ) |
| 683 | { |
| 644 | 684 | gbTama5Byte = 0xFF; |
| 645 | 685 | } |
| 646 | 686 | case 0x80: /* Unknown, some kind of read (when 07=01)/write (when 07=00/02) */ |
| r4575 | r4576 | |
| 652 | 692 | } |
| 653 | 693 | break; |
| 654 | 694 | case 0x0001: /* Write to control register */ |
| 655 | | switch( data ) { |
| 695 | switch( data ) |
| 696 | { |
| 656 | 697 | case 0x00: /* Bits 0-3 for rom bank selection */ |
| 657 | 698 | case 0x01: /* Bits 4-7 for rom bank selection */ |
| 658 | 699 | case 0x04: /* Data write register lo */ |
| r4575 | r4576 | |
| 686 | 727 | static UINT8 mmm01_bank; |
| 687 | 728 | static UINT8 mmm01_bank_mask; |
| 688 | 729 | |
| 689 | | static WRITE8_HANDLER( gb_rom_bank_mmm01_0000_w ) { |
| 730 | static WRITE8_HANDLER( gb_rom_bank_mmm01_0000_w ) |
| 731 | { |
| 690 | 732 | logerror( "0x%04X: write 0x%02X to 0x%04X\n", cpu_get_pc( space->cpu ), data, offset+0x000 ); |
| 691 | | if ( data & 0x40 ) { |
| 733 | if ( data & 0x40 ) |
| 734 | { |
| 692 | 735 | mmm01_bank_offset = mmm01_reg1; |
| 693 | 736 | memory_set_bankptr( space->machine, 5, ROMMap[ mmm01_bank_offset ] ); |
| 694 | 737 | memory_set_bankptr( space->machine, 10, ROMMap[ mmm01_bank_offset ] + 0x0100 ); |
| r4575 | r4576 | |
| 696 | 739 | } |
| 697 | 740 | } |
| 698 | 741 | |
| 699 | | static WRITE8_HANDLER( gb_rom_bank_mmm01_2000_w ) { |
| 742 | static WRITE8_HANDLER( gb_rom_bank_mmm01_2000_w ) |
| 743 | { |
| 700 | 744 | logerror( "0x%04X: write 0x%02X to 0x%04X\n", cpu_get_pc( space->cpu ), data, offset+0x2000 ); |
| 701 | 745 | |
| 702 | 746 | mmm01_reg1 = data & ROMMask; |
| 703 | 747 | mmm01_bank = mmm01_reg1 & mmm01_bank_mask; |
| 704 | | if ( mmm01_bank == 0 ) { |
| 748 | if ( mmm01_bank == 0 ) |
| 749 | { |
| 705 | 750 | mmm01_bank = 1; |
| 706 | 751 | } |
| 707 | 752 | gb_rom16_4000( space->machine, ROMMap[ mmm01_bank_offset + mmm01_bank ] ); |
| 708 | 753 | } |
| 709 | 754 | |
| 710 | | static WRITE8_HANDLER( gb_rom_bank_mmm01_4000_w ) { |
| 755 | static WRITE8_HANDLER( gb_rom_bank_mmm01_4000_w ) |
| 756 | { |
| 711 | 757 | logerror( "0x%04X: write 0x%02X to 0x%04X\n", cpu_get_pc( space->cpu ), data, offset+0x4000 ); |
| 712 | 758 | } |
| 713 | 759 | |
| 714 | | static WRITE8_HANDLER( gb_rom_bank_mmm01_6000_w ) { |
| 760 | static WRITE8_HANDLER( gb_rom_bank_mmm01_6000_w ) |
| 761 | { |
| 715 | 762 | logerror( "0x%04X: write 0x%02X to 0x%04X\n", cpu_get_pc( space->cpu ), data, offset+0x6000 ); |
| 716 | 763 | /* Not sure if this is correct, Taito Variety Pack sets these values */ |
| 717 | 764 | /* Momotarou Collection 2 writes 01 and 21 here */ |
| 718 | | switch( data ) { |
| 765 | switch( data ) |
| 766 | { |
| 719 | 767 | case 0x30: mmm01_bank_mask = 0x07; break; |
| 720 | 768 | case 0x38: mmm01_bank_mask = 0x03; break; |
| 721 | 769 | default: mmm01_bank_mask = 0xFF; break; |
| r4575 | r4576 | |
| 724 | 772 | |
| 725 | 773 | /* Korean MBC1 variant mapping */ |
| 726 | 774 | |
| 727 | | static void gb_set_mbc1_kor_banks( running_machine *machine ) { |
| 728 | | if ( ROMBank & 0x30 ) { |
| 775 | static void gb_set_mbc1_kor_banks( running_machine *machine ) |
| 776 | { |
| 777 | if ( ROMBank & 0x30 ) |
| 778 | { |
| 729 | 779 | gb_rom16_0000( machine, ROMMap[ ROMBank & 0x30 ] ); |
| 730 | 780 | } |
| 731 | 781 | gb_rom16_4000( machine, ROMMap[ ROMBank ] ); |
| r4575 | r4576 | |
| 777 | 827 | case 0x01: /* SB - Serial transfer data */ |
| 778 | 828 | break; |
| 779 | 829 | case 0x02: /* SC - SIO control */ |
| 780 | | switch( data & 0x81 ) { |
| 830 | switch( data & 0x81 ) |
| 831 | { |
| 781 | 832 | case 0x00: |
| 782 | 833 | case 0x01: |
| 783 | 834 | case 0x80: /* enabled & external clock */ |
| r4575 | r4576 | |
| 786 | 837 | case 0x81: /* enabled & internal clock */ |
| 787 | 838 | SIODATA = 0xFF; |
| 788 | 839 | SIOCount = 8; |
| 789 | | timer_adjust_periodic(gb_serial_timer, cpu_clocks_to_attotime(space->machine->cpu[0], 512), 0, cpu_clocks_to_attotime(space->machine->cpu[0], 512)); |
| 840 | timer_adjust_periodic(gb_serial_timer, cputag_clocks_to_attotime(space->machine, "maincpu", 512), 0, cputag_clocks_to_attotime(space->machine, "maincpu", 512)); |
| 790 | 841 | timer_enable( gb_serial_timer, 1 ); |
| 791 | 842 | break; |
| 792 | 843 | } |
| r4575 | r4576 | |
| 799 | 850 | return; |
| 800 | 851 | case 0x05: /* TIMA - Timer counter */ |
| 801 | 852 | /* Check if the counter is being reloaded in this cycle */ |
| 802 | | if ( gb_timer.reloading && ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) == 4 ) { |
| 853 | if ( gb_timer.reloading && ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) == 4 ) |
| 854 | { |
| 803 | 855 | data = TIMECNT; |
| 804 | 856 | } |
| 805 | 857 | break; |
| 806 | 858 | case 0x06: /* TMA - Timer module */ |
| 807 | 859 | /* Check if the counter is being reloaded in this cycle */ |
| 808 | | if ( gb_timer.reloading && ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) == 4 ) { |
| 860 | if ( gb_timer.reloading && ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) == 4 ) |
| 861 | { |
| 809 | 862 | TIMECNT = data; |
| 810 | 863 | } |
| 811 | 864 | break; |
| 812 | 865 | case 0x07: /* TAC - Timer control */ |
| 813 | 866 | data |= 0xF8; |
| 814 | 867 | /* Check if timer is just disabled or the timer frequency is changing */ |
| 815 | | if ( ( ! ( data & 0x04 ) && ( TIMEFRQ & 0x04 ) ) || ( ( data & 0x04 ) && ( TIMEFRQ & 0x04 ) && ( data & 0x03 ) != ( TIMEFRQ & 0x03 ) ) ) { |
| 868 | if ( ( ! ( data & 0x04 ) && ( TIMEFRQ & 0x04 ) ) || ( ( data & 0x04 ) && ( TIMEFRQ & 0x04 ) && ( data & 0x03 ) != ( TIMEFRQ & 0x03 ) ) ) |
| 869 | { |
| 816 | 870 | /* Check if TIMECNT should be incremented */ |
| 817 | | if ( ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) >= ( gb_timer.shift_cycles >> 1 ) ) { |
| 871 | if ( ( gb_timer.divcount & ( gb_timer.shift_cycles - 1 ) ) >= ( gb_timer.shift_cycles >> 1 ) ) |
| 872 | { |
| 818 | 873 | gb_timer_increment(space->machine); |
| 819 | 874 | } |
| 820 | 875 | } |
| r4575 | r4576 | |
| 823 | 878 | break; |
| 824 | 879 | case 0x0F: /* IF - Interrupt flag */ |
| 825 | 880 | data &= 0x1F; |
| 826 | | cpu_set_reg( space->machine->cpu[0], LR35902_IF, data ); |
| 881 | cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_IF, data ); |
| 827 | 882 | break; |
| 828 | 883 | } |
| 829 | 884 | |
| r4575 | r4576 | |
| 832 | 887 | |
| 833 | 888 | WRITE8_HANDLER ( gb_io2_w ) |
| 834 | 889 | { |
| 835 | | if ( offset == 0x10 ) { |
| 890 | if ( offset == 0x10 ) |
| 891 | { |
| 836 | 892 | /* disable BIOS ROM */ |
| 837 | 893 | memory_set_bankptr(space->machine, 5, ROMMap[ROMBank00]); |
| 838 | | } else { |
| 894 | } |
| 895 | else |
| 896 | { |
| 839 | 897 | gb_video_w( space, offset, data ); |
| 840 | 898 | } |
| 841 | 899 | } |
| r4575 | r4576 | |
| 1363 | 1421 | /* Interrupt Enable register */ |
| 1364 | 1422 | READ8_HANDLER( gb_ie_r ) |
| 1365 | 1423 | { |
| 1366 | | return cpu_get_reg( space->machine->cpu[0], LR35902_IE ); |
| 1424 | return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_IE ); |
| 1367 | 1425 | } |
| 1368 | 1426 | |
| 1369 | 1427 | WRITE8_HANDLER ( gb_ie_w ) |
| 1370 | 1428 | { |
| 1371 | | cpu_set_reg( space->machine->cpu[0], LR35902_IE, data & 0x1F ); |
| 1429 | cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_IE, data & 0x1F ); |
| 1372 | 1430 | } |
| 1373 | 1431 | |
| 1374 | 1432 | /* IO read */ |
| r4575 | r4576 | |
| 1388 | 1446 | return gb_io[offset]; |
| 1389 | 1447 | case 0x0F: |
| 1390 | 1448 | /* Make sure the internal states are up to date */ |
| 1391 | | return 0xE0 | cpu_get_reg( space->machine->cpu[0], LR35902_IF ); |
| 1449 | return 0xE0 | cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_IF ); |
| 1392 | 1450 | default: |
| 1393 | 1451 | /* It seems unsupported registers return 0xFF */ |
| 1394 | 1452 | return 0xFF; |
| r4575 | r4576 | |
| 1405 | 1463 | gb_dummy_ram_bank = auto_malloc( 0x2000 ); |
| 1406 | 1464 | memset( gb_dummy_ram_bank, 0x00, 0x2000 ); |
| 1407 | 1465 | |
| 1408 | | for(I = 0; I < MAX_ROMBANK; I++) { |
| 1466 | for(I = 0; I < MAX_ROMBANK; I++) |
| 1467 | { |
| 1409 | 1468 | ROMMap[I] = gb_dummy_rom_bank; |
| 1410 | 1469 | } |
| 1411 | | for(I = 0; I < MAX_RAMBANK; I++) { |
| 1470 | for(I = 0; I < MAX_RAMBANK; I++) |
| 1471 | { |
| 1412 | 1472 | RAMMap[I] = gb_dummy_ram_bank; |
| 1413 | 1473 | } |
| 1414 | 1474 | ROMBank00 = 0; |
| r4575 | r4576 | |
| 1557 | 1617 | |
| 1558 | 1618 | /* Check for presence of a header, and skip that header */ |
| 1559 | 1619 | J = filesize % 0x4000; |
| 1560 | | if ( J == 512 ) { |
| 1620 | if ( J == 512 ) |
| 1621 | { |
| 1561 | 1622 | logerror( "Rom-header found, skipping\n" ); |
| 1562 | 1623 | image_fseek( image, J, SEEK_SET ); |
| 1563 | 1624 | filesize -= 512; |
| 1564 | 1625 | } |
| 1565 | 1626 | |
| 1566 | 1627 | /* Verify that the file contains 16kb blocks */ |
| 1567 | | if ( ( filesize == 0 ) || ( ( filesize % 0x4000 ) != 0 ) ) { |
| 1628 | if ( ( filesize == 0 ) || ( ( filesize % 0x4000 ) != 0 ) ) |
| 1629 | { |
| 1568 | 1630 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid rom file size" ); |
| 1569 | 1631 | return INIT_FAIL; |
| 1570 | 1632 | } |
| r4575 | r4576 | |
| 1573 | 1635 | gb_cart = auto_malloc( filesize ); |
| 1574 | 1636 | |
| 1575 | 1637 | /* Read cartridge */ |
| 1576 | | if ( image_fread( image, gb_cart, filesize ) != filesize ) { |
| 1638 | if ( image_fread( image, gb_cart, filesize ) != filesize ) |
| 1639 | { |
| 1577 | 1640 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file" ); |
| 1578 | 1641 | return INIT_FAIL; |
| 1579 | 1642 | } |
| r4575 | r4576 | |
| 1582 | 1645 | ROMBank00 = 0; |
| 1583 | 1646 | |
| 1584 | 1647 | /* Check for presence of MMM01 mapper */ |
| 1585 | | if ( filesize >= 0x8000 ) { |
| 1648 | if ( filesize >= 0x8000 ) |
| 1649 | { |
| 1586 | 1650 | static const UINT8 nintendo_logo[0x18] = { |
| 1587 | 1651 | 0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0D, 0x00, 0x0B, |
| 1588 | 1652 | 0x03, 0x73, 0x00, 0x83, 0x00, 0x0C, 0x00, 0x0D, |
| r4575 | r4576 | |
| 1590 | 1654 | }; |
| 1591 | 1655 | int bytes_matched = 0; |
| 1592 | 1656 | gb_header = gb_cart + filesize - 0x8000; |
| 1593 | | for ( I = 0; I < 0x18; I++ ) { |
| 1594 | | if ( gb_header[0x0104 + I] == nintendo_logo[I] ) { |
| 1657 | for ( I = 0; I < 0x18; I++ ) |
| 1658 | { |
| 1659 | if ( gb_header[0x0104 + I] == nintendo_logo[I] ) |
| 1660 | { |
| 1595 | 1661 | bytes_matched++; |
| 1596 | 1662 | } |
| 1597 | 1663 | } |
| 1598 | | if ( bytes_matched == 0x18 && gb_header[0x0147] >= 0x0B && gb_header[0x0147] <= 0x0D ) { |
| 1664 | if ( bytes_matched == 0x18 && gb_header[0x0147] >= 0x0B && gb_header[0x0147] <= 0x0D ) |
| 1665 | { |
| 1599 | 1666 | ROMBank00 = ( filesize / 0x4000 ) - 2; |
| 1600 | 1667 | mmm01_bank_offset = ROMBank00; |
| 1601 | | } else { |
| 1668 | } |
| 1669 | else |
| 1670 | { |
| 1602 | 1671 | gb_header = gb_cart; |
| 1603 | 1672 | } |
| 1604 | 1673 | } |
| 1605 | 1674 | |
| 1606 | 1675 | /* Fill in our cart details */ |
| 1607 | | switch( gb_header[0x0147] ) { |
| 1676 | switch( gb_header[0x0147] ) |
| 1677 | { |
| 1608 | 1678 | case 0x00: MBCType = MBC_NONE; CartType = 0; break; |
| 1609 | 1679 | case 0x01: MBCType = MBC_MBC1; CartType = 0; break; |
| 1610 | 1680 | case 0x02: MBCType = MBC_MBC1; CartType = RAM; break; |
| r4575 | r4576 | |
| 1640 | 1710 | } |
| 1641 | 1711 | |
| 1642 | 1712 | /* Check whether we're dealing with a (possible) Wisdom Tree game here */ |
| 1643 | | if ( gb_header[0x0147] == 0x00 ) { |
| 1713 | if ( gb_header[0x0147] == 0x00 ) |
| 1714 | { |
| 1644 | 1715 | int count = 0; |
| 1645 | | for( I = 0x0134; I <= 0x014C; I++ ) { |
| 1716 | for( I = 0x0134; I <= 0x014C; I++ ) |
| 1717 | { |
| 1646 | 1718 | count += gb_header[I]; |
| 1647 | 1719 | } |
| 1648 | | if ( count == 0 ) { |
| 1720 | if ( count == 0 ) |
| 1721 | { |
| 1649 | 1722 | MBCType = MBC_WISDOM; |
| 1650 | 1723 | } |
| 1651 | 1724 | } |
| 1652 | 1725 | |
| 1653 | 1726 | /* Check if we're dealing with a Korean variant of the MBC1 mapper */ |
| 1654 | | if ( MBCType == MBC_MBC1 ) { |
| 1655 | | if ( gb_header[0x13F] == 0x42 && gb_header[0x140] == 0x32 && gb_header[0x141] == 0x43 && gb_header[0x142] == 0x4B ) { |
| 1727 | if ( MBCType == MBC_MBC1 ) |
| 1728 | { |
| 1729 | if ( gb_header[0x13F] == 0x42 && gb_header[0x140] == 0x32 && gb_header[0x141] == 0x43 && gb_header[0x142] == 0x4B ) |
| 1730 | { |
| 1656 | 1731 | MBCType = MBC_MBC1_KOR; |
| 1657 | 1732 | } |
| 1658 | 1733 | } |
| 1659 | | if ( MBCType == MBC_UNKNOWN ) { |
| 1734 | if ( MBCType == MBC_UNKNOWN ) |
| 1735 | { |
| 1660 | 1736 | image_seterror( image, IMAGE_ERROR_UNSUPPORTED, "Unknown mapper type" ); |
| 1661 | 1737 | return INIT_FAIL; |
| 1662 | 1738 | } |
| 1663 | | if ( MBCType == MBC_MMM01 ) { |
| 1739 | if ( MBCType == MBC_MMM01 ) |
| 1740 | { |
| 1664 | 1741 | // image_seterror( image, IMAGE_ERROR_UNSUPPORTED, "Mapper MMM01 is not supported yet" ); |
| 1665 | 1742 | // return INIT_FAIL; |
| 1666 | 1743 | } |
| 1667 | | if ( MBCType == MBC_MBC4 ) { |
| 1744 | if ( MBCType == MBC_MBC4 ) |
| 1745 | { |
| 1668 | 1746 | image_seterror( image, IMAGE_ERROR_UNSUPPORTED, "Mapper MBC4 is not supported yet" ); |
| 1669 | 1747 | return INIT_FAIL; |
| 1670 | 1748 | } |
| 1671 | 1749 | /* MBC7 support is still work-in-progress, so only enable it for debug builds */ |
| 1672 | 1750 | #ifndef MAME_DEBUG |
| 1673 | | if ( MBCType == MBC_MBC7 ) { |
| 1751 | if ( MBCType == MBC_MBC7 ) |
| 1752 | { |
| 1674 | 1753 | image_seterror( image, IMAGE_ERROR_UNSUPPORTED, "Mapper MBC7 is not supported yet" ); |
| 1675 | 1754 | return INIT_FAIL; |
| 1676 | 1755 | } |
| 1677 | 1756 | #endif |
| 1678 | 1757 | |
| 1679 | 1758 | ROMBanks = filesize / 0x4000; |
| 1680 | | switch( gb_header[0x0148] ) { |
| 1759 | switch( gb_header[0x0148] ) |
| 1760 | { |
| 1681 | 1761 | case 0x52: |
| 1682 | 1762 | reported_rom_banks = 72; |
| 1683 | 1763 | break; |
| r4575 | r4576 | |
| 1696 | 1776 | reported_rom_banks = 256; |
| 1697 | 1777 | break; |
| 1698 | 1778 | } |
| 1699 | | if ( ROMBanks != reported_rom_banks && MBCType != MBC_WISDOM ) { |
| 1779 | if ( ROMBanks != reported_rom_banks && MBCType != MBC_WISDOM ) |
| 1780 | { |
| 1700 | 1781 | logerror( "Warning loading cartridge: Filesize and reported ROM banks don't match.\n" ); |
| 1701 | 1782 | } |
| 1702 | 1783 | |
| r4575 | r4576 | |
| 1728 | 1809 | 96 (1100000) 1011111 (95) |
| 1729 | 1810 | */ |
| 1730 | 1811 | ROMMask = I - 1; |
| 1731 | | if ( ( ROMBanks & ROMMask ) != 0 ) { |
| 1732 | | for( ; I & ROMBanks; I++ ) { |
| 1812 | if ( ( ROMBanks & ROMMask ) != 0 ) |
| 1813 | { |
| 1814 | for( ; I & ROMBanks; I++ ) |
| 1815 | { |
| 1733 | 1816 | ROMMap[ I ] = ROMMap[ I & ROMMask ]; |
| 1734 | 1817 | } |
| 1735 | 1818 | ROMMask = I - 1; |
| 1736 | 1819 | } |
| 1737 | 1820 | |
| 1738 | 1821 | /* Fill out the remaining rom bank pointers, if any. */ |
| 1739 | | for ( ; I < MAX_ROMBANK; I++ ) { |
| 1822 | for ( ; I < MAX_ROMBANK; I++ ) |
| 1823 | { |
| 1740 | 1824 | ROMMap[ I ] = ROMMap[ I & ROMMask ]; |
| 1741 | 1825 | } |
| 1742 | 1826 | |
| r4575 | r4576 | |
| 1775 | 1859 | if( MBCType == MBC_MBC2 ) |
| 1776 | 1860 | RAMBanks = 1; |
| 1777 | 1861 | /* MBC7 has 512 bytes(?) of internal RAM */ |
| 1778 | | if ( MBCType == MBC_MBC7 ) { |
| 1862 | if ( MBCType == MBC_MBC7 ) |
| 1863 | { |
| 1779 | 1864 | RAMBanks = 1; |
| 1780 | 1865 | } |
| 1781 | 1866 | |
| r4575 | r4576 | |
| 1791 | 1876 | |
| 1792 | 1877 | /* Set up rest of the (mirrored) RAM pages */ |
| 1793 | 1878 | RAMMask = I - 1; |
| 1794 | | for ( ; I < MAX_RAMBANK; I++ ) { |
| 1879 | for ( ; I < MAX_RAMBANK; I++ ) |
| 1880 | { |
| 1795 | 1881 | RAMMap[ I ] = RAMMap [ I & RAMMask ]; |
| 1796 | 1882 | } |
| 1797 | | } else { |
| 1883 | } |
| 1884 | else |
| 1885 | { |
| 1798 | 1886 | RAMMask = 0; |
| 1799 | 1887 | } |
| 1800 | 1888 | |
| 1801 | 1889 | /* If there's an RTC claim memory to store the RTC contents */ |
| 1802 | | if ( CartType & TIMER ) { |
| 1890 | if ( CartType & TIMER ) |
| 1891 | { |
| 1803 | 1892 | MBC3RTCData = auto_malloc( 0x2000 ); |
| 1804 | 1893 | } |
| 1805 | 1894 | |
| 1806 | | if ( MBCType == MBC_TAMA5 ) { |
| 1895 | if ( MBCType == MBC_TAMA5 ) |
| 1896 | { |
| 1807 | 1897 | MBC3RTCData = auto_malloc( 0x2000 ); |
| 1808 | 1898 | memset( gbTama5Memory, 0xFF, sizeof(gbTama5Memory) ); |
| 1809 | 1899 | } |
| r4575 | r4576 | |
| 1828 | 1918 | /* Decrement number of handled bits */ |
| 1829 | 1919 | SIOCount--; |
| 1830 | 1920 | /* If all bits done, stop timer and trigger interrupt */ |
| 1831 | | if ( ! SIOCount ) { |
| 1921 | if ( ! SIOCount ) |
| 1922 | { |
| 1832 | 1923 | SIOCONT &= 0x7F; |
| 1833 | 1924 | timer_enable( gb_serial_timer, 0 ); |
| 1834 | | cpu_set_input_line(machine->cpu[0], SIO_INT, HOLD_LINE); |
| 1925 | cputag_set_input_line(machine, "maincpu", SIO_INT, HOLD_LINE); |
| 1835 | 1926 | } |
| 1836 | 1927 | } |
| 1837 | 1928 | |
| 1838 | | INLINE void gb_timer_check_irq( running_machine *machine ) { |
| 1929 | INLINE void gb_timer_check_irq( running_machine *machine ) |
| 1930 | { |
| 1839 | 1931 | gb_timer.reloading = 0; |
| 1840 | | if ( gb_timer.triggering_irq ) { |
| 1932 | if ( gb_timer.triggering_irq ) |
| 1933 | { |
| 1841 | 1934 | gb_timer.triggering_irq = 0; |
| 1842 | | if ( TIMECNT == 0 ) { |
| 1935 | if ( TIMECNT == 0 ) |
| 1936 | { |
| 1843 | 1937 | TIMECNT = TIMEMOD; |
| 1844 | | cpu_set_input_line(machine->cpu[0], TIM_INT, HOLD_LINE ); |
| 1938 | cputag_set_input_line(machine, "maincpu", TIM_INT, HOLD_LINE ); |
| 1845 | 1939 | gb_timer.reloading = 1; |
| 1846 | 1940 | } |
| 1847 | 1941 | } |
| 1848 | 1942 | } |
| 1849 | 1943 | |
| 1850 | | static void gb_timer_increment( running_machine *machine ) { |
| 1944 | static void gb_timer_increment( running_machine *machine ) |
| 1945 | { |
| 1851 | 1946 | gb_timer_check_irq(machine); |
| 1852 | 1947 | |
| 1853 | 1948 | TIMECNT += 1; |
| 1854 | | if ( TIMECNT == 0 ) { |
| 1949 | if ( TIMECNT == 0 ) |
| 1950 | { |
| 1855 | 1951 | gb_timer.triggering_irq = 1; |
| 1856 | 1952 | } |
| 1857 | 1953 | } |
| 1858 | 1954 | |
| 1859 | | void gb_timer_callback(const device_config *device, int cycles) { |
| 1955 | void gb_timer_callback(const device_config *device, int cycles) |
| 1956 | { |
| 1860 | 1957 | UINT16 old_gb_divcount = gb_timer.divcount; |
| 1861 | 1958 | gb_timer.divcount += cycles; |
| 1862 | 1959 | |
| 1863 | 1960 | gb_timer_check_irq(device->machine); |
| 1864 | 1961 | |
| 1865 | | if ( TIMEFRQ & 0x04 ) { |
| 1962 | if ( TIMEFRQ & 0x04 ) |
| 1963 | { |
| 1866 | 1964 | UINT16 old_count = old_gb_divcount >> gb_timer.shift; |
| 1867 | 1965 | UINT16 new_count = gb_timer.divcount >> gb_timer.shift; |
| 1868 | | if ( cycles > gb_timer.shift_cycles ) { |
| 1966 | if ( cycles > gb_timer.shift_cycles ) |
| 1967 | { |
| 1869 | 1968 | gb_timer_increment(device->machine); |
| 1870 | 1969 | old_count++; |
| 1871 | 1970 | } |
| 1872 | | if ( new_count != old_count ) { |
| 1971 | if ( new_count != old_count ) |
| 1972 | { |
| 1873 | 1973 | gb_timer_increment(device->machine); |
| 1874 | 1974 | } |
| 1875 | | if ( new_count << gb_timer.shift < gb_timer.divcount ) { |
| 1975 | if ( new_count << gb_timer.shift < gb_timer.divcount ) |
| 1976 | { |
| 1876 | 1977 | gb_timer_check_irq(device->machine); |
| 1877 | 1978 | } |
| 1878 | 1979 | } |
| r4575 | r4576 | |
| 1880 | 1981 | |
| 1881 | 1982 | WRITE8_HANDLER ( gbc_io2_w ) |
| 1882 | 1983 | { |
| 1883 | | switch( offset ) { |
| 1984 | switch( offset ) |
| 1985 | { |
| 1884 | 1986 | case 0x0D: /* KEY1 - Prepare speed switch */ |
| 1885 | | cpu_set_reg( space->machine->cpu[0], LR35902_SPEED, data ); |
| 1987 | cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_SPEED, data ); |
| 1886 | 1988 | return; |
| 1887 | 1989 | case 0x16: /* RP - Infrared port */ |
| 1888 | 1990 | break; |
| r4575 | r4576 | |
| 1896 | 1998 | gbc_video_w( space, offset, data ); |
| 1897 | 1999 | } |
| 1898 | 2000 | |
| 1899 | | READ8_HANDLER( gbc_io2_r ) { |
| 1900 | | switch( offset ) { |
| 2001 | READ8_HANDLER( gbc_io2_r ) |
| 2002 | { |
| 2003 | switch( offset ) |
| 2004 | { |
| 1901 | 2005 | case 0x0D: /* KEY1 */ |
| 1902 | | return cpu_get_reg( space->machine->cpu[0], LR35902_SPEED ); |
| 2006 | return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), LR35902_SPEED ); |
| 1903 | 2007 | case 0x16: /* RP - Infrared port */ |
| 1904 | 2008 | break; |
| 1905 | 2009 | default: |
| r4575 | r4576 | |
| 1962 | 2066 | { |
| 1963 | 2067 | UINT8 data; |
| 1964 | 2068 | |
| 1965 | | if ( (offset & 0x0C) && ((offset & 0x0C) ^ 0x0C) ) { |
| 2069 | if ( (offset & 0x0C) && ((offset & 0x0C) ^ 0x0C) ) |
| 2070 | { |
| 1966 | 2071 | offset ^= 0x0C; |
| 1967 | 2072 | } |
| 1968 | 2073 | data = gb_video_r( space, offset ); |
| r4575 | r4576 | |
| 1973 | 2078 | |
| 1974 | 2079 | WRITE8_HANDLER ( megaduck_video_w ) |
| 1975 | 2080 | { |
| 1976 | | if ( !offset ) { |
| 2081 | if ( !offset ) |
| 2082 | { |
| 1977 | 2083 | data = BITSWAP8(data,7,3,5,4,2,1,0,6); |
| 1978 | 2084 | } |
| 1979 | | if ( (offset & 0x0C) && ((offset & 0x0C) ^ 0x0C) ) { |
| 2085 | if ( (offset & 0x0C) && ((offset & 0x0C) ^ 0x0C) ) |
| 2086 | { |
| 1980 | 2087 | offset ^= 0x0C; |
| 1981 | 2088 | } |
| 1982 | 2089 | gb_video_w(space, offset, data ); |
| r4575 | r4576 | |
| 1998 | 2105 | |
| 1999 | 2106 | WRITE8_HANDLER( megaduck_sound_w2 ) |
| 2000 | 2107 | { |
| 2001 | | switch(offset) { |
| 2108 | switch(offset) |
| 2109 | { |
| 2002 | 2110 | case 0x00: gb_sound_w(devtag_get_device(space->machine, "custom"), 0x10, data ); break; |
| 2003 | 2111 | case 0x01: gb_sound_w(devtag_get_device(space->machine, "custom"), 0x12, data ); break; |
| 2004 | 2112 | case 0x02: gb_sound_w(devtag_get_device(space->machine, "custom"), 0x11, data ); break; |
| r4575 | r4576 | |
| 2059 | 2167 | filesize = image_length(image); |
| 2060 | 2168 | ROMBanks = filesize / 0x4000; |
| 2061 | 2169 | |
| 2062 | | if ( ( filesize == 0 ) || ( ( filesize % 0x4000 ) != 0 ) ) { |
| 2170 | if ( ( filesize == 0 ) || ( ( filesize % 0x4000 ) != 0 ) ) |
| 2171 | { |
| 2063 | 2172 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Invalid rom file size" ); |
| 2064 | 2173 | return INIT_FAIL; |
| 2065 | 2174 | } |
| r4575 | r4576 | |
| 2068 | 2177 | gb_cart = auto_malloc( filesize ); |
| 2069 | 2178 | |
| 2070 | 2179 | /* Read cartridge */ |
| 2071 | | if (image_fread (image, gb_cart, filesize) != filesize) { |
| 2180 | if (image_fread (image, gb_cart, filesize) != filesize) |
| 2181 | { |
| 2072 | 2182 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file" ); |
| 2073 | 2183 | return INIT_FAIL; |
| 2074 | 2184 | } |
src/mess/machine/gamecom.c
| r4575 | r4576 | |
| 65 | 65 | { |
| 66 | 66 | UINT8 val = ( ( gamecom_internal_registers[SM8521_CLKT] & 0x3F ) + 1 ) & 0x3F; |
| 67 | 67 | gamecom_internal_registers[SM8521_CLKT] = ( gamecom_internal_registers[SM8521_CLKT] & 0xC0 ) | val; |
| 68 | | cpu_set_input_line(machine->cpu[0], CK_INT, HOLD_LINE ); |
| 68 | cputag_set_input_line(machine, "maincpu", CK_INT, HOLD_LINE ); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | MACHINE_RESET( gamecom ) |
| r4575 | r4576 | |
| 90 | 90 | gamecom_dma.enabled = 0; |
| 91 | 91 | |
| 92 | 92 | memset( gamecom_internal_registers, 0x00, sizeof(gamecom_internal_registers) ); |
| 93 | | gamecom_internal_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), SM8521_URTT, 0xFF ); |
| 94 | | gamecom_internal_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), SM8521_URTS, 0x42 ); |
| 95 | | gamecom_internal_w( cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), SM8521_WDTC, 0x38 ); |
| 93 | gamecom_internal_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), SM8521_URTT, 0xFF ); |
| 94 | gamecom_internal_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), SM8521_URTS, 0x42 ); |
| 95 | gamecom_internal_w( cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), SM8521_WDTC, 0x38 ); |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | static void gamecom_set_mmu( running_machine *machine, int mmu, UINT8 data ) |
| r4575 | r4576 | |
| 138 | 138 | |
| 139 | 139 | if ( stylus_x == column ) |
| 140 | 140 | { |
| 141 | | cpu_set_reg( machine->cpu[0], SM8500_P0, row_data[stylus_y] & 0xFF ); |
| 142 | | cpu_set_reg( machine->cpu[0], SM8500_P1, ( cpu_get_reg( machine->cpu[0], SM8500_P1 ) & 0xFC ) | ( ( row_data[stylus_y] >> 8 ) & 0x03 ) ); |
| 141 | cpu_set_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P0, row_data[stylus_y] & 0xFF ); |
| 142 | cpu_set_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P1, ( cpu_get_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P1 ) & 0xFC ) | ( ( row_data[stylus_y] >> 8 ) & 0x03 ) ); |
| 143 | 143 | } |
| 144 | 144 | else |
| 145 | 145 | { |
| 146 | | cpu_set_reg( machine->cpu[0], SM8500_P0, 0xFF ); |
| 147 | | cpu_set_reg( machine->cpu[0], SM8500_P1, ( cpu_get_reg( machine->cpu[0], SM8500_P1 ) & 0xFC ) | 0x03 ); |
| 146 | cpu_set_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P0, 0xFF ); |
| 147 | cpu_set_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P1, ( cpu_get_reg( cputag_get_cpu(machine, "maincpu"), SM8500_P1 ) & 0xFC ) | 0x03 ); |
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | |
| r4575 | r4576 | |
| 158 | 158 | |
| 159 | 159 | switch( offset ) |
| 160 | 160 | { |
| 161 | | case SM8521_IE0: cpu_set_reg( space->machine->cpu[0], SM8500_IE0, data ); return; |
| 162 | | case SM8521_IE1: cpu_set_reg( space->machine->cpu[0], SM8500_IE1, data ); return; |
| 163 | | case SM8521_IR0: cpu_set_reg( space->machine->cpu[0], SM8500_IR0, data ); return; |
| 164 | | case SM8521_IR1: cpu_set_reg( space->machine->cpu[0], SM8500_IR1, data ); return; |
| 165 | | case SM8521_P0: cpu_set_reg( space->machine->cpu[0], SM8500_P0, data ); return; |
| 166 | | case SM8521_P1: cpu_set_reg( space->machine->cpu[0], SM8500_P1, data ); return; |
| 167 | | case SM8521_P2: cpu_set_reg( space->machine->cpu[0], SM8500_P2, data ); |
| 168 | | switch( ( cpu_get_reg( space->machine->cpu[0], SM8500_P1 ) << 8 ) | data ) |
| 161 | case SM8521_IE0: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IE0, data ); return; |
| 162 | case SM8521_IE1: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IE1, data ); return; |
| 163 | case SM8521_IR0: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IR0, data ); return; |
| 164 | case SM8521_IR1: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IR1, data ); return; |
| 165 | case SM8521_P0: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0, data ); return; |
| 166 | case SM8521_P1: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1, data ); return; |
| 167 | case SM8521_P2: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P2, data ); |
| 168 | switch( ( cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1 ) << 8 ) | data ) |
| 169 | 169 | { |
| 170 | 170 | case 0xFBFF: /* column #0 */ |
| 171 | 171 | /* P0 bit 0 cleared => 01 */ |
| r4575 | r4576 | |
| 227 | 227 | /* P0 bit 7 cleared => 8B (button A) */ |
| 228 | 228 | /* P1 bit 0 cleared => 8C (button B) */ |
| 229 | 229 | /* P1 bit 1 cleared => 8D (button C) */ |
| 230 | | cpu_set_reg( space->machine->cpu[0], SM8500_P0, input_port_read(space->machine, "IN0") ); |
| 231 | | cpu_set_reg( space->machine->cpu[0], SM8500_P1, ( cpu_get_reg( space->machine->cpu[0], SM8500_P1 ) & 0xFC ) | ( input_port_read(space->machine, "IN1") & 0x03 ) ); |
| 230 | cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0, input_port_read(space->machine, "IN0") ); |
| 231 | cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1, ( cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1 ) & 0xFC ) | ( input_port_read(space->machine, "IN1") & 0x03 ) ); |
| 232 | 232 | break; |
| 233 | 233 | case 0xFFFF: /* keys #2 */ |
| 234 | 234 | /* P0 bit 0 cleared => 88 (power) */ |
| r4575 | r4576 | |
| 241 | 241 | /* P0 bit 7 cleared => A0 */ |
| 242 | 242 | /* P1 bit 0 cleared => A0 */ |
| 243 | 243 | /* P1 bit 1 cleared => A0 */ |
| 244 | | cpu_set_reg( space->machine->cpu[0], SM8500_P0, ( cpu_get_reg( space->machine->cpu[0], SM8500_P0 ) & 0xFC ) | ( input_port_read(space->machine, "IN2") & 0x03 ) ); |
| 245 | | cpu_set_reg( space->machine->cpu[0], SM8500_P1, 0xFF ); |
| 244 | cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0, ( cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0 ) & 0xFC ) | ( input_port_read(space->machine, "IN2") & 0x03 ) ); |
| 245 | cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1, 0xFF ); |
| 246 | 246 | break; |
| 247 | 247 | } |
| 248 | 248 | return; |
| 249 | 249 | case SM8521_P3: |
| 250 | 250 | /* P3 bit7 clear, bit6 set -> enable cartridge port #0? */ |
| 251 | 251 | /* P3 bit6 clear, bit7 set -> enable cartridge port #1? */ |
| 252 | | cpu_set_reg( space->machine->cpu[0], SM8500_P3, data ); |
| 252 | cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P3, data ); |
| 253 | 253 | switch( data & 0xc0 ) |
| 254 | 254 | { |
| 255 | 255 | case 0x40: cartridge = cartridge1; break; |
| r4575 | r4576 | |
| 262 | 262 | gamecom_set_mmu( space->machine, 3, gamecom_internal_registers[SM8521_MMU3] ); |
| 263 | 263 | gamecom_set_mmu( space->machine, 4, gamecom_internal_registers[SM8521_MMU4] ); |
| 264 | 264 | return; |
| 265 | | case SM8521_SYS: cpu_set_reg( space->machine->cpu[0], SM8500_SYS, data ); return; |
| 266 | | case SM8521_CKC: cpu_set_reg( space->machine->cpu[0], SM8500_CKC, data ); return; |
| 267 | | case SM8521_SPH: cpu_set_reg( space->machine->cpu[0], SM8500_SPH, data ); return; |
| 268 | | case SM8521_SPL: cpu_set_reg( space->machine->cpu[0], SM8500_SPL, data ); return; |
| 269 | | case SM8521_PS0: cpu_set_reg( space->machine->cpu[0], SM8500_PS0, data ); return; |
| 270 | | case SM8521_PS1: cpu_set_reg( space->machine->cpu[0], SM8500_PS1, data ); return; |
| 271 | | case SM8521_P0C: cpu_set_reg( space->machine->cpu[0], SM8500_P0C, data ); return; |
| 272 | | case SM8521_P1C: cpu_set_reg( space->machine->cpu[0], SM8500_P1C, data ); return; |
| 273 | | case SM8521_P2C: cpu_set_reg( space->machine->cpu[0], SM8500_P2C, data ); return; |
| 274 | | case SM8521_P3C: cpu_set_reg( space->machine->cpu[0], SM8500_P3C, data ); return; |
| 265 | case SM8521_SYS: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SYS, data ); return; |
| 266 | case SM8521_CKC: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_CKC, data ); return; |
| 267 | case SM8521_SPH: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SPH, data ); return; |
| 268 | case SM8521_SPL: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SPL, data ); return; |
| 269 | case SM8521_PS0: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_PS0, data ); return; |
| 270 | case SM8521_PS1: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_PS1, data ); return; |
| 271 | case SM8521_P0C: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0C, data ); return; |
| 272 | case SM8521_P1C: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1C, data ); return; |
| 273 | case SM8521_P2C: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P2C, data ); return; |
| 274 | case SM8521_P3C: cpu_set_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P3C, data ); return; |
| 275 | 275 | case SM8521_MMU0: /* disable bootstrap ROM? most likely not written to on game.com */ |
| 276 | 276 | logerror( "Write to MMU0\n" ); |
| 277 | 277 | break; |
| r4575 | r4576 | |
| 397 | 397 | case SM8521_R12: case SM8521_R13: case SM8521_R14: case SM8521_R15: |
| 398 | 398 | return 0; /* NPW 22-Dec-2008 - Not sure what to do here */ |
| 399 | 399 | /*return sm85cpu_mem_readbyte( state, offset );*/ |
| 400 | | case SM8521_IE0: return cpu_get_reg( space->machine->cpu[0], SM8500_IE0 ); |
| 401 | | case SM8521_IE1: return cpu_get_reg( space->machine->cpu[0], SM8500_IE1 ); |
| 402 | | case SM8521_IR0: return cpu_get_reg( space->machine->cpu[0], SM8500_IR0 ); |
| 403 | | case SM8521_IR1: return cpu_get_reg( space->machine->cpu[0], SM8500_IR1 ); |
| 404 | | case SM8521_P0: /* logerror( "%X: Read from P0\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( space->machine->cpu[0], SM8500_P0 ); |
| 405 | | case SM8521_P1: /* logerror( "%X: Read from P1\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( space->machine->cpu[0], SM8500_P1 ); |
| 406 | | case SM8521_P2: /* logerror( "%X: Read from P2\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( space->machine->cpu[0], SM8500_P2 ); |
| 407 | | case SM8521_P3: return cpu_get_reg( space->machine->cpu[0], SM8500_P3 ); |
| 408 | | case SM8521_SYS: return cpu_get_reg( space->machine->cpu[0], SM8500_SYS ); |
| 409 | | case SM8521_CKC: return cpu_get_reg( space->machine->cpu[0], SM8500_CKC ); |
| 410 | | case SM8521_SPH: return cpu_get_reg( space->machine->cpu[0], SM8500_SPH ); |
| 411 | | case SM8521_SPL: return cpu_get_reg( space->machine->cpu[0], SM8500_SPL ); |
| 412 | | case SM8521_PS0: return cpu_get_reg( space->machine->cpu[0], SM8500_PS0 ); |
| 413 | | case SM8521_PS1: return cpu_get_reg( space->machine->cpu[0], SM8500_PS1 ); |
| 414 | | case SM8521_P0C: return cpu_get_reg( space->machine->cpu[0], SM8500_P0C ); |
| 415 | | case SM8521_P1C: return cpu_get_reg( space->machine->cpu[0], SM8500_P1C ); |
| 416 | | case SM8521_P2C: return cpu_get_reg( space->machine->cpu[0], SM8500_P2C ); |
| 417 | | case SM8521_P3C: return cpu_get_reg( space->machine->cpu[0], SM8500_P3C ); |
| 400 | case SM8521_IE0: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IE0 ); |
| 401 | case SM8521_IE1: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IE1 ); |
| 402 | case SM8521_IR0: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IR0 ); |
| 403 | case SM8521_IR1: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_IR1 ); |
| 404 | case SM8521_P0: /* logerror( "%X: Read from P0\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0 ); |
| 405 | case SM8521_P1: /* logerror( "%X: Read from P1\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1 ); |
| 406 | case SM8521_P2: /* logerror( "%X: Read from P2\n", cpu_get_pc(space->cpu) ); */ return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P2 ); |
| 407 | case SM8521_P3: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P3 ); |
| 408 | case SM8521_SYS: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SYS ); |
| 409 | case SM8521_CKC: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_CKC ); |
| 410 | case SM8521_SPH: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SPH ); |
| 411 | case SM8521_SPL: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_SPL ); |
| 412 | case SM8521_PS0: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_PS0 ); |
| 413 | case SM8521_PS1: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_PS1 ); |
| 414 | case SM8521_P0C: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P0C ); |
| 415 | case SM8521_P1C: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P1C ); |
| 416 | case SM8521_P2C: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P2C ); |
| 417 | case SM8521_P3C: return cpu_get_reg( cputag_get_cpu(space->machine, "maincpu"), SM8500_P3C ); |
| 418 | 418 | case SM8521_TM0D: return gamecom_timer[0].counter; |
| 419 | 419 | case SM8521_TM1D: return gamecom_timer[1].counter; |
| 420 | 420 | // case SM8521_CLKT: /* bit 0-5 read only, 6-7 read/write */ |
| r4575 | r4576 | |
| 490 | 490 | case 0x04: |
| 491 | 491 | /* Extend RAM->VRAM */ |
| 492 | 492 | gamecom_dma.source_width = 64; |
| 493 | | gamecom_dma.source_bank = memory_get_read_ptr(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xE000 ); |
| 493 | gamecom_dma.source_bank = memory_get_read_ptr(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xE000 ); |
| 494 | 494 | gamecom_dma.dest_bank = &gamecom_vram[(gamecom_internal_registers[SM8521_DMVP] & 0x02) ? 0x2000 : 0x0000]; |
| 495 | 495 | break; |
| 496 | 496 | case 0x06: |
| 497 | 497 | /* VRAM->Extend RAM */ |
| 498 | 498 | gamecom_dma.source_bank = &gamecom_vram[(gamecom_internal_registers[SM8521_DMVP] & 0x01) ? 0x2000 : 0x0000]; |
| 499 | 499 | gamecom_dma.dest_width = 64; |
| 500 | | gamecom_dma.dest_bank = memory_get_read_ptr(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xE000 ); |
| 500 | gamecom_dma.dest_bank = memory_get_read_ptr(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xE000 ); |
| 501 | 501 | break; |
| 502 | 502 | } |
| 503 | 503 | gamecom_dma.source_current = gamecom_dma.source_width * gamecom_dma.source_y; |
| r4575 | r4576 | |
| 604 | 604 | gamecom_dma.dest_current = gamecom_dma.dest_line; |
| 605 | 605 | } |
| 606 | 606 | gamecom_dma.enabled = 0; |
| 607 | | cpu_set_input_line(device->machine->cpu[0], DMA_INT, HOLD_LINE ); |
| 607 | cputag_set_input_line(device->machine, "maincpu", DMA_INT, HOLD_LINE ); |
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | void gamecom_update_timers( const device_config *device, int cycles ) |
| r4575 | r4576 | |
| 619 | 619 | if ( gamecom_timer[0].counter == gamecom_timer[0].check_value ) |
| 620 | 620 | { |
| 621 | 621 | gamecom_timer[0].counter = 0; |
| 622 | | cpu_set_input_line(device->machine->cpu[0], TIM0_INT, HOLD_LINE ); |
| 622 | cputag_set_input_line(device->machine, "maincpu", TIM0_INT, HOLD_LINE ); |
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | 625 | } |
| r4575 | r4576 | |
| 633 | 633 | if ( gamecom_timer[1].counter == gamecom_timer[1].check_value ) |
| 634 | 634 | { |
| 635 | 635 | gamecom_timer[1].counter = 0; |
| 636 | | cpu_set_input_line(device->machine->cpu[0], TIM1_INT, HOLD_LINE ); |
| 636 | cputag_set_input_line(device->machine, "maincpu", TIM1_INT, HOLD_LINE ); |
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | 639 | } |
| r4575 | r4576 | |
| 651 | 651 | |
| 652 | 652 | DEVICE_START( gamecom_cart ) |
| 653 | 653 | { |
| 654 | | internal_ram = device_get_info_ptr(device->machine->cpu[0], CPUINFO_PTR_SM8500_INTERNAL_RAM); |
| 654 | internal_ram = devtag_get_info_ptr(device->machine, "maincpu", CPUINFO_PTR_SM8500_INTERNAL_RAM); |
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | DEVICE_IMAGE_LOAD( gamecom_cart ) |
src/mess/machine/genesis.c
| r4575 | r4576 | |
| 622 | 622 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000); |
| 623 | 623 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x400000); |
| 624 | 624 | |
| 625 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130ff, 0, 0, genesis_ssf2_bank_w); |
| 625 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130ff, 0, 0, genesis_ssf2_bank_w); |
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | if (cart_type == LIONK3 || cart_type == SKINGKONG) |
| r4575 | r4576 | |
| 630 | 630 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 631 | 631 | memcpy(&ROM[0x200000], &ROM[VIRGIN_COPY_GEN], 0x200000); /* default rom */ |
| 632 | 632 | |
| 633 | | memory_install_readwrite16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw); |
| 634 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w); |
| 633 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw); |
| 634 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w); |
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | if (cart_type == SDK99) |
| r4575 | r4576 | |
| 639 | 639 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x300000); /* default rom */ |
| 640 | 640 | memcpy(&ROM[0x300000], &ROM[VIRGIN_COPY_GEN], 0x100000); /* default rom */ |
| 641 | 641 | |
| 642 | | memory_install_readwrite16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw); |
| 643 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w); |
| 642 | memory_install_readwrite16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_l3alt_prot_r, g_l3alt_protw); |
| 643 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_l3alt_bank_w); |
| 644 | 644 | } |
| 645 | 645 | |
| 646 | 646 | if (cart_type == REDCLIFF) |
| 647 | 647 | { |
| 648 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, redclif_prot2_r); |
| 649 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, redclif_prot_r); |
| 648 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, redclif_prot2_r); |
| 649 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, redclif_prot_r); |
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | if (cart_type == REDCL_EN) |
| r4575 | r4576 | |
| 660 | 660 | |
| 661 | 661 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN + 4], 0x200000); /* default rom */ |
| 662 | 662 | |
| 663 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, redclif_prot2_r); |
| 664 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, redclif_prot_r); |
| 663 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, redclif_prot2_r); |
| 664 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, redclif_prot_r); |
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | if (cart_type == RADICA) |
| r4575 | r4576 | |
| 669 | 669 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000); // keep a copy for later banking.. making use of huge ROM_REGION allocated to genesis driver |
| 670 | 670 | memcpy(&ROM[0x800000], &ROM[VIRGIN_COPY_GEN], 0x400000); // wraparound banking (from hazemd code) |
| 671 | 671 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x400000); |
| 672 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa1307f, 0, 0, radica_bank_select); |
| 672 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa1307f, 0, 0, radica_bank_select); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | if (cart_type == KOF99) |
| 676 | 676 | { |
| 677 | 677 | //memcpy(&ROM[0x000000],&ROM[VIRGIN_COPY_GEN],0x300000); |
| 678 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, kof99_0xA13000_r); |
| 679 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13002, 0xa13003, 0, 0, kof99_0xA13002_r); |
| 680 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa1303e, 0xa1303f, 0, 0, kof99_00A1303E_r); |
| 678 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, kof99_0xA13000_r); |
| 679 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13002, 0xa13003, 0, 0, kof99_0xA13002_r); |
| 680 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa1303e, 0xa1303f, 0, 0, kof99_00A1303E_r); |
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | if (cart_type == SOULBLAD) |
| 684 | 684 | { |
| 685 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, soulb_0x400002_r); |
| 686 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, soulb_0x400004_r); |
| 687 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, soulb_0x400006_r); |
| 685 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, soulb_0x400002_r); |
| 686 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, soulb_0x400004_r); |
| 687 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, soulb_0x400006_r); |
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | if (cart_type == MJLOVER) |
| 691 | 691 | { |
| 692 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, mjlovr_prot_1_r); |
| 693 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x401000, 0x401001, 0, 0, mjlovr_prot_2_r); |
| 692 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, mjlovr_prot_1_r); |
| 693 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x401000, 0x401001, 0, 0, mjlovr_prot_2_r); |
| 694 | 694 | } |
| 695 | 695 | |
| 696 | 696 | if (cart_type == SQUIRRELK) |
| 697 | 697 | { |
| 698 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_r); |
| 699 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_w); |
| 698 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_r); |
| 699 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, squirrel_king_extra_w); |
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | if (cart_type == SMOUSE) |
| 703 | 703 | { |
| 704 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, smous_prot_r); |
| 704 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400007, 0, 0, smous_prot_r); |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | if (cart_type == SMB) |
| 708 | 708 | { |
| 709 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, smbro_prot_r); |
| 709 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, smbro_prot_r); |
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | if (cart_type == SMB2) |
| 713 | 713 | { |
| 714 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, smb2_extra_r); |
| 714 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, smb2_extra_r); |
| 715 | 715 | } |
| 716 | 716 | |
| 717 | 717 | if (cart_type == KAIJU) |
| r4575 | r4576 | |
| 720 | 720 | memcpy(&ROM[0x600000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 721 | 721 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 722 | 722 | |
| 723 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_kaiju_bank_w); |
| 723 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x700000, 0x7fffff, 0, 0, g_kaiju_bank_w); |
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | if (cart_type == CHINFIGHT3) |
| r4575 | r4576 | |
| 729 | 729 | memcpy(&ROM[0x600000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 730 | 730 | memcpy(&ROM[0x000000], &ROM[VIRGIN_COPY_GEN], 0x200000); |
| 731 | 731 | |
| 732 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x4fffff, 0, 0, g_chifi3_prot_r); |
| 733 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_chifi3_bank_w); |
| 732 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x4fffff, 0, 0, g_chifi3_prot_r); |
| 733 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x600000, 0x6fffff, 0, 0, g_chifi3_bank_w); |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | 736 | if (cart_type == LIONK2) |
| 737 | 737 | { |
| 738 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, lion2_prot1_r); |
| 739 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, lion2_prot2_r); |
| 740 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, lion2_prot1_w); |
| 741 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, lion2_prot2_w); |
| 738 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, lion2_prot1_r); |
| 739 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, lion2_prot2_r); |
| 740 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, lion2_prot1_w); |
| 741 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, lion2_prot2_w); |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | if (cart_type == BUGSLIFE) |
| 745 | 745 | { |
| 746 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, bugl_extra_r); |
| 746 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, bugl_extra_r); |
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | if (cart_type == ELFWOR) |
| 750 | 750 | { |
| 751 | 751 | /* It return (0x55 @ 0x400000 OR 0xc9 @ 0x400004) AND (0x0f @ 0x400002 OR 0x18 @ 0x400006). It is probably best to add handlers for all 4 addresses. */ |
| 752 | 752 | |
| 753 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, elfwor_0x400000_r); |
| 754 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, elfwor_0x400002_r); |
| 755 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, elfwor_0x400004_r); |
| 756 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, elfwor_0x400006_r); |
| 753 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, elfwor_0x400000_r); |
| 754 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, elfwor_0x400002_r); |
| 755 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400004, 0x400005, 0, 0, elfwor_0x400004_r); |
| 756 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400006, 0x400007, 0, 0, elfwor_0x400006_r); |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | if (cart_type == ROCKMANX3) |
| 760 | 760 | { |
| 761 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, rx3_extra_r); |
| 761 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13001, 0, 0, rx3_extra_r); |
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | if (cart_type == SBUBBOB) |
| 765 | 765 | { |
| 766 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, sbub_extra1_r); |
| 767 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, sbub_extra2_r); |
| 766 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, sbub_extra1_r); |
| 767 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400002, 0x400003, 0, 0, sbub_extra2_r); |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | if (cart_type == KOF98) |
| 771 | 771 | { |
| 772 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x480000, 0x480001, 0, 0, g_kof98_aa_r); |
| 773 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x4800e0, 0x4800e1, 0, 0, g_kof98_aa_r); |
| 774 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x4824a0, 0x4824a1, 0, 0, g_kof98_aa_r); |
| 775 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x488880, 0x488881, 0, 0, g_kof98_aa_r); |
| 772 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x480000, 0x480001, 0, 0, g_kof98_aa_r); |
| 773 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4800e0, 0x4800e1, 0, 0, g_kof98_aa_r); |
| 774 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4824a0, 0x4824a1, 0, 0, g_kof98_aa_r); |
| 775 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x488880, 0x488881, 0, 0, g_kof98_aa_r); |
| 776 | 776 | |
| 777 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x4a8820, 0x4a8821, 0, 0, g_kof98_0a_r); |
| 778 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x4f8820, 0x4f8821, 0, 0, g_kof98_00_r); |
| 777 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4a8820, 0x4a8821, 0, 0, g_kof98_0a_r); |
| 778 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x4f8820, 0x4f8821, 0, 0, g_kof98_00_r); |
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | if (cart_type == REALTEC) |
| r4575 | r4576 | |
| 790 | 790 | memcpy(ROM + mirroraddr, ROM + relocate + 0x7e000, 0x002000); /* copy last 8kb across the whole rom region */ |
| 791 | 791 | } |
| 792 | 792 | |
| 793 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, realtec_400000_w); |
| 794 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x402000, 0x402001, 0, 0, realtec_402000_w); |
| 795 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0x404000, 0x404001, 0, 0, realtec_404000_w); |
| 793 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x400000, 0x400001, 0, 0, realtec_400000_w); |
| 794 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x402000, 0x402001, 0, 0, realtec_402000_w); |
| 795 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0x404000, 0x404001, 0, 0, realtec_404000_w); |
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | if (cart_type == SUP19IN1) |
| 799 | 799 | { |
| 800 | 800 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x400000); // allow hard reset to menu |
| 801 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13039, 0, 0, s19in1_bank); |
| 801 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13039, 0, 0, s19in1_bank); |
| 802 | 802 | } |
| 803 | 803 | |
| 804 | 804 | if (cart_type == SUP15IN1) |
| 805 | 805 | { |
| 806 | 806 | memcpy(&ROM[0x400000], &ROM[VIRGIN_COPY_GEN], 0x200000); // allow hard reset to menu |
| 807 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13039, 0, 0, s19in1_bank); |
| 807 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa13000, 0xa13039, 0, 0, s19in1_bank); |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | if (has_sram) |
| 811 | 811 | { |
| 812 | | memory_install_read16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), genesis_sram_start & 0x3fffff, genesis_sram_end & 0x3fffff, 0, 0, genesis_sram_read); |
| 813 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), genesis_sram_start & 0x3fffff, genesis_sram_end & 0x3fffff, 0, 0, genesis_sram_write); |
| 814 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle); |
| 812 | memory_install_read16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), genesis_sram_start & 0x3fffff, genesis_sram_end & 0x3fffff, 0, 0, genesis_sram_read); |
| 813 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), genesis_sram_start & 0x3fffff, genesis_sram_end & 0x3fffff, 0, 0, genesis_sram_write); |
| 814 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa130f0, 0xa130f1, 0, 0, genesis_sram_toggle); |
| 815 | 815 | } |
| 816 | 816 | |
| 817 | 817 | |
| 818 | 818 | /* install NOP handler for TMSS */ |
| 819 | | memory_install_write16_handler(cpu_get_address_space(machine->cpu[0], ADDRESS_SPACE_PROGRAM), 0xa14000, 0xa14003, 0, 0, genesis_TMSS_bank_w); |
| 819 | memory_install_write16_handler(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM), 0xa14000, 0xa14003, 0, 0, genesis_TMSS_bank_w); |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | |
src/mess/drivers/gmaster.c
| r4575 | r4576 | |
| 28 | 28 | |
| 29 | 29 | static READ8_HANDLER( gmaster_io_r ) |
| 30 | 30 | { |
| 31 | | UINT8 data=0; |
| 32 | | if (gmaster.ports[2]&1) { |
| 33 | | data=memory_region(space->machine, "maincpu")[0x4000+offset]; |
| 34 | | logerror("%.4x external memory %.4x read %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset,data); |
| 35 | | } else { |
| 36 | | switch (offset) { |
| 37 | | case 1: |
| 38 | | data=gmaster_video.pixels[gmaster_video.y][gmaster_video.x]; |
| 39 | | logerror("%.4x lcd x:%.2x y:%.2x %.4x read %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), gmaster_video.x, gmaster_video.y, 0x4000+offset,data); |
| 40 | | if (!(gmaster_video.mode)&&gmaster_video.delayed) gmaster_video.x++; |
| 41 | | gmaster_video.delayed=TRUE; |
| 42 | | break; |
| 43 | | default: |
| 44 | | logerror("%.4x memory %.4x read %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset,data); |
| 45 | | } |
| 31 | UINT8 data = 0; |
| 32 | if (gmaster.ports[2] & 1) |
| 33 | { |
| 34 | data = memory_region(space->machine, "maincpu")[0x4000 + offset]; |
| 35 | logerror("%.4x external memory %.4x read %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data); |
| 36 | } |
| 37 | else |
| 38 | { |
| 39 | switch (offset) |
| 40 | { |
| 41 | case 1: |
| 42 | data=gmaster_video.pixels[gmaster_video.y][gmaster_video.x]; |
| 43 | logerror("%.4x lcd x:%.2x y:%.2x %.4x read %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), gmaster_video.x, gmaster_video.y, 0x4000 + offset, data); |
| 44 | if (!(gmaster_video.mode) && gmaster_video.delayed) |
| 45 | gmaster_video.x++; |
| 46 | gmaster_video.delayed = TRUE; |
| 47 | break; |
| 48 | default: |
| 49 | logerror("%.4x memory %.4x read %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data); |
| 50 | } |
| 46 | 51 | } |
| 47 | 52 | return data; |
| 48 | 53 | } |
| r4575 | r4576 | |
| 51 | 56 | |
| 52 | 57 | static WRITE8_HANDLER( gmaster_io_w ) |
| 53 | 58 | { |
| 54 | | if (gmaster.ports[2]&1) { |
| 55 | | memory_region(space->machine, "maincpu")[0x4000+offset]=data; |
| 56 | | logerror("%.4x external memory %.4x written %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset, data); |
| 57 | | } else { |
| 58 | | switch (offset) { |
| 59 | | case 0: |
| 60 | | gmaster_video.delayed=FALSE; |
| 61 | | logerror("%.4x lcd %.4x written %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset, data); |
| 62 | | // e2 af a4 a0 a9 falling block init for both halves |
| 63 | | if ((data&0xfc)==0xb8) { |
| 64 | | gmaster_video.index=0; |
| 65 | | gmaster_video.data[gmaster_video.index]=data; |
| 66 | | gmaster_video.y=BLITTER_Y; |
| 67 | | } else if ((data&0xc0)==0) { |
| 68 | | gmaster_video.x=data; |
| 69 | | } else if ((data&0xf0)==0xe0) { |
| 70 | | gmaster_video.mode=(data&0xe)?FALSE:TRUE; |
| 71 | | } |
| 72 | | gmaster_video.data[gmaster_video.index]=data; |
| 73 | | gmaster_video.index=(gmaster_video.index+1)&7; |
| 74 | | break; |
| 75 | | case 1: |
| 76 | | gmaster_video.delayed=FALSE; |
| 77 | | if (gmaster_video.x<ARRAY_LENGTH(gmaster_video.pixels[0])) // continental galaxy flutlicht |
| 78 | | gmaster_video.pixels[gmaster_video.y][gmaster_video.x]=data; |
| 79 | | logerror("%.4x lcd x:%.2x y:%.2x %.4x written %.2x\n", |
| 80 | | (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), gmaster_video.x, gmaster_video.y, 0x4000+offset, data); |
| 81 | | gmaster_video.x++; |
| 59 | if (gmaster.ports[2] & 1) |
| 60 | { |
| 61 | memory_region(space->machine, "maincpu")[0x4000 + offset] = data; |
| 62 | logerror("%.4x external memory %.4x written %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data); |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | switch (offset) |
| 67 | { |
| 68 | case 0: |
| 69 | gmaster_video.delayed=FALSE; |
| 70 | logerror("%.4x lcd %.4x written %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data); |
| 71 | // e2 af a4 a0 a9 falling block init for both halves |
| 72 | if ((data & 0xfc) == 0xb8) |
| 73 | { |
| 74 | gmaster_video.index = 0; |
| 75 | gmaster_video.data[gmaster_video.index] = data; |
| 76 | gmaster_video.y = BLITTER_Y; |
| 77 | } |
| 78 | else if ((data & 0xc0) == 0) |
| 79 | { |
| 80 | gmaster_video.x = data; |
| 81 | } |
| 82 | else if ((data & 0xf0) == 0xe0) |
| 83 | { |
| 84 | gmaster_video.mode = (data & 0xe) ? FALSE : TRUE; |
| 85 | } |
| 86 | gmaster_video.data[gmaster_video.index] = data; |
| 87 | gmaster_video.index = (gmaster_video.index + 1) & 7; |
| 88 | break; |
| 89 | case 1: |
| 90 | gmaster_video.delayed = FALSE; |
| 91 | if (gmaster_video.x < ARRAY_LENGTH(gmaster_video.pixels[0])) // continental galaxy flutlicht |
| 92 | gmaster_video.pixels[gmaster_video.y][gmaster_video.x] = data; |
| 93 | logerror("%.4x lcd x:%.2x y:%.2x %.4x written %.2x\n", |
| 94 | (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), gmaster_video.x, gmaster_video.y, 0x4000 + offset, data); |
| 95 | gmaster_video.x++; |
| 82 | 96 | /* 02 b8 1a |
| 83 | 97 | 02 bb 1a |
| 84 | 98 | 02 bb 22 |
| r4575 | r4576 | |
| 93 | 107 | rr w rr w rr w rr w rr w rr w rr w rr w |
| 94 | 108 | 4000 ee |
| 95 | 109 | */ |
| 96 | | break; |
| 97 | | default: |
| 98 | | logerror("%.4x memory %.4x written %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000+offset, data); |
| 110 | break; |
| 111 | default: |
| 112 | logerror("%.4x memory %.4x written %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), 0x4000 + offset, data); |
| 99 | 113 | } |
| 100 | 114 | } |
| 101 | 115 | } |
| 102 | 116 | |
| 103 | 117 | static READ8_HANDLER( gmaster_port_r ) |
| 104 | 118 | { |
| 105 | | // UINT8 data=gmaster.ports[offset]; |
| 106 | | UINT8 data=0xff; |
| 107 | | switch (offset) { |
| 108 | | case UPD7810_PORTA: |
| 109 | | data=input_port_read(space->machine, "JOY"); |
| 110 | | break; |
| 111 | | default: |
| 112 | | logerror("%.4x port %d read %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC),offset,data); |
| 119 | // UINT8 data = gmaster.ports[offset]; |
| 120 | UINT8 data = 0xff; |
| 121 | switch (offset) |
| 122 | { |
| 123 | case UPD7810_PORTA: |
| 124 | data = input_port_read(space->machine, "JOY"); |
| 125 | break; |
| 126 | default: |
| 127 | logerror("%.4x port %d read %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), offset, data); |
| 113 | 128 | } |
| 114 | 129 | return data; |
| 115 | 130 | } |
| 116 | 131 | |
| 117 | 132 | static WRITE8_HANDLER( gmaster_port_w ) |
| 118 | 133 | { |
| 119 | | gmaster.ports[offset]=data; |
| 120 | | logerror("%.4x port %d written %.2x\n",(int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), offset, data); |
| 121 | | switch (offset) { |
| 122 | | case UPD7810_PORTC: |
| 123 | | gmaster_video.y=BLITTER_Y; |
| 124 | | break; |
| 134 | gmaster.ports[offset] = data; |
| 135 | logerror("%.4x port %d written %.2x\n", (int)cpu_get_reg(space->cpu, CPUINFO_INT_PC), offset, data); |
| 136 | switch (offset) |
| 137 | { |
| 138 | case UPD7810_PORTC: |
| 139 | gmaster_video.y = BLITTER_Y; |
| 140 | break; |
| 125 | 141 | } |
| 126 | 142 | } |
| 127 | 143 | |
| 128 | 144 | static ADDRESS_MAP_START( gmaster_mem, ADDRESS_SPACE_PROGRAM, 8 ) |
| 129 | | AM_RANGE(0x0000, 0x3fff) AM_ROM |
| 130 | | AM_RANGE( 0x4000, 0x7fff) AM_READWRITE(gmaster_io_r, gmaster_io_w) |
| 131 | | AM_RANGE(0x8000, 0xfeff) AM_ROM |
| 132 | | AM_RANGE(0xff00, 0xffff) AM_RAM |
| 145 | AM_RANGE(0x0000, 0x3fff) AM_ROM |
| 146 | AM_RANGE( 0x4000, 0x7fff) AM_READWRITE(gmaster_io_r, gmaster_io_w) |
| 147 | AM_RANGE(0x8000, 0xfeff) AM_ROM |
| 148 | AM_RANGE(0xff00, 0xffff) AM_RAM |
| 133 | 149 | ADDRESS_MAP_END |
| 134 | 150 | |
| 135 | 151 | static ADDRESS_MAP_START(gmaster_io, ADDRESS_SPACE_IO, 8) |
| 136 | | AM_RANGE(UPD7810_PORTA, UPD7810_PORTF) AM_READWRITE(gmaster_port_r, gmaster_port_w ) |
| 152 | AM_RANGE(UPD7810_PORTA, UPD7810_PORTF) AM_READWRITE(gmaster_port_r, gmaster_port_w ) |
| 137 | 153 | ADDRESS_MAP_END |
| 138 | 154 | |
| 139 | 155 | static INPUT_PORTS_START( gmaster ) |
| r4575 | r4576 | |
| 141 | 157 | PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT) |
| 142 | 158 | PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT ) |
| 143 | 159 | PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN ) |
| 144 | | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) |
| 160 | PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP ) |
| 145 | 161 | PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON2) PORT_NAME("B") |
| 146 | 162 | PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON1) PORT_NAME("A") |
| 147 | | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SELECT) PORT_NAME("select") |
| 148 | | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START) PORT_NAME("start") |
| 163 | PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SELECT) PORT_NAME("Select") |
| 164 | PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START) PORT_NAME("Start") |
| 149 | 165 | INPUT_PORTS_END |
| 150 | 166 | |
| 151 | 167 | /* palette in red, green, blue tribles */ |
| r4575 | r4576 | |
| 164 | 180 | { |
| 165 | 181 | int i; |
| 166 | 182 | |
| 167 | | for ( i = 0; i < 2; i++ ) { |
| 183 | for ( i = 0; i < 2; i++ ) |
| 184 | { |
| 168 | 185 | palette_set_color_rgb(machine, i, gmaster_palette[i][0], gmaster_palette[i][1], gmaster_palette[i][2]); |
| 169 | 186 | } |
| 170 | 187 | } |
| r4575 | r4576 | |
| 172 | 189 | static VIDEO_UPDATE( gmaster ) |
| 173 | 190 | { |
| 174 | 191 | int x,y; |
| 175 | | // plot_box(bitmap, 0, 0, 64/*bitmap->width*/, bitmap->height, 0); //xmess rounds up to 64 pixel |
| 176 | | for (y=0;y<ARRAY_LENGTH(gmaster_video.pixels); y++) { |
| 177 | | for (x=0;x<ARRAY_LENGTH(gmaster_video.pixels[0]);x++) { |
| 178 | | UINT8 d=gmaster_video.pixels[y][x]; |
| 179 | | UINT16 *line; |
| 180 | | line=BITMAP_ADDR16(bitmap, (y*8), x); |
| 181 | | line[0]=(d>>0)&1; |
| 182 | | line=BITMAP_ADDR16(bitmap, (y*8+1), x); |
| 183 | | line[0]=(d>>1)&1; |
| 184 | | line=BITMAP_ADDR16(bitmap, (y*8+2), x); |
| 185 | | line[0]=(d>>2)&1; |
| 186 | | line=BITMAP_ADDR16(bitmap, (y*8+3), x); |
| 187 | | line[0]=(d>>3)&1; |
| 188 | | line=BITMAP_ADDR16(bitmap, (y*8+4), x); |
| 189 | | line[0]=(d>>4)&1; |
| 190 | | line=BITMAP_ADDR16(bitmap, (y*8+5), x); |
| 191 | | line[0]=(d>>5)&1; |
| 192 | | line=BITMAP_ADDR16(bitmap, (y*8+6), x); |
| 193 | | line[0]=(d>>6)&1; |
| 194 | | line=BITMAP_ADDR16(bitmap, (y*8+7), x); |
| 195 | | line[0]=(d>>7)&1; |
| 196 | | } |
| 192 | // plot_box(bitmap, 0, 0, 64/*bitmap->width*/, bitmap->height, 0); //xmess rounds up to 64 pixel |
| 193 | for (y = 0; y < ARRAY_LENGTH(gmaster_video.pixels); y++) |
| 194 | { |
| 195 | for (x = 0; x < ARRAY_LENGTH(gmaster_video.pixels[0]); x++) |
| 196 | { |
| 197 | UINT8 d = gmaster_video.pixels[y][x]; |
| 198 | UINT16 *line; |
| 199 | |
| 200 | line = BITMAP_ADDR16(bitmap, (y * 8), x); |
| 201 | line[0] = (d >> 0) & 1; |
| 202 | line = BITMAP_ADDR16(bitmap, (y * 8 + 1), x); |
| 203 | line[0] = (d >> 1) & 1; |
| 204 | line = BITMAP_ADDR16(bitmap, (y * 8 + 2), x); |
| 205 | line[0] = (d >> 2) & 1; |
| 206 | line = BITMAP_ADDR16(bitmap, (y * 8 + 3), x); |
| 207 | line[0] = (d >> 3) & 1; |
| 208 | line = BITMAP_ADDR16(bitmap, (y * 8 + 4), x); |
| 209 | line[0] = (d >> 4) & 1; |
| 210 | line = BITMAP_ADDR16(bitmap, (y * 8 + 5), x); |
| 211 | line[0] = (d >> 5) & 1; |
| 212 | line = BITMAP_ADDR16(bitmap, (y * 8 + 6), x); |
| 213 | line[0] = (d >> 6) & 1; |
| 214 | line = BITMAP_ADDR16(bitmap, (y * 8 + 7), x); |
| 215 | line[0] = (d >> 7) & 1; |
| 216 | } |
| 197 | 217 | } |
| 198 | 218 | return 0; |
| 199 | 219 | } |
| 200 | 220 | |
| 201 | 221 | static INTERRUPT_GEN( gmaster_interrupt ) |
| 202 | 222 | { |
| 203 | | cpu_set_input_line(device->machine->cpu[0], UPD7810_INTFE1, ASSERT_LINE); |
| 223 | cputag_set_input_line(device->machine, "maincpu", UPD7810_INTFE1, ASSERT_LINE); |
| 204 | 224 | } |
| 205 | 225 | |
| 206 | | static const UPD7810_CONFIG config={ |
| 207 | | // TYPE_78C10, // 78c11 in handheld |
| 208 | | TYPE_7801, // temporarily until 7810 core fixes synchronized |
| 209 | | gmaster_io_callback |
| 226 | static const UPD7810_CONFIG config = { |
| 227 | // TYPE_78C10, // 78c11 in handheld |
| 228 | TYPE_7801, // temporarily until 7810 core fixes synchronized |
| 229 | gmaster_io_callback |
| 210 | 230 | }; |
| 211 | 231 | |
| 212 | 232 | static MACHINE_DRIVER_START( gmaster ) |
| r4575 | r4576 | |
| 236 | 256 | |
| 237 | 257 | ROM_START(gmaster) |
| 238 | 258 | ROM_REGION(0x10000,"maincpu", 0) |
| 239 | | ROM_LOAD("gmaster.bin", 0x0000, 0x1000, CRC(05cc45e5) SHA1(05d73638dea9657ccc2791c0202d9074a4782c1e) ) |
| 240 | | // ROM_CART_LOAD(0, "bin", 0x8000, 0x7f00, 0) |
| 241 | | ROM_CART_LOAD("cart", 0x8000, 0x8000, 0) |
| 259 | ROM_LOAD("gmaster.bin", 0x0000, 0x1000, CRC(05cc45e5) SHA1(05d73638dea9657ccc2791c0202d9074a4782c1e) ) |
| 260 | // ROM_CART_LOAD(0, "bin", 0x8000, 0x7f00, 0) |
| 261 | ROM_CART_LOAD("cart", 0x8000, 0x8000, 0) |
| 242 | 262 | ROM_END |
| 243 | 263 | |
| 244 | 264 | static DRIVER_INIT( gmaster ) |
| 245 | 265 | { |
| 246 | | memset(&gmaster_video, 0, sizeof(gmaster_video)); |
| 247 | | |
| 266 | memset(&gmaster_video, 0, sizeof(gmaster_video)); |
| 248 | 267 | } |
| 249 | 268 | |
| 250 | 269 | #if 0 |
| r4575 | r4576 | |
| 266 | 285 | return 1; |
| 267 | 286 | } |
| 268 | 287 | size=osd_fsize(cartfile); |
| 269 | | if (size>0x8000) { |
| 288 | if (size>0x8000) |
| 289 | { |
| 270 | 290 | logerror("%s: size %d not yet supported\n",device_filename(IO_CARTSLOT,id), size); |
| 271 | 291 | return 1; |
| 272 | 292 | } |
| 273 | 293 | |
| 274 | | if (osd_fread(cartfile, rom+0x8000, size)!=size) { |
| 294 | if (osd_fread(cartfile, rom+0x8000, size)!=size) |
| 295 | { |
| 275 | 296 | logerror("%s load error\n",device_filename(IO_CARTSLOT,id)); |
| 276 | 297 | osd_fclose(cartfile); |
| 277 | 298 | return 1; |
| r4575 | r4576 | |
| 285 | 306 | /* YEAR NAME PARENT MACHINE INPUT INIT |
| 286 | 307 | COMPANY FULLNAME */ |
| 287 | 308 | CONS( 1990, gmaster, 0, 0, gmaster, gmaster, gmaster, 0, "Hartung", "Gamemaster", GAME_IMPERFECT_SOUND) |
| 288 | | |