src/mame/machine/megadriv.c
| r10806 | r10807 | |
| 3943 | 3943 | #define RAM_MODE_2MEG (0) |
| 3944 | 3944 | #define RAM_MODE_1MEG (2) |
| 3945 | 3945 | |
| 3946 | |
| 3947 | |
| 3948 | INLINE void write_pixel(running_machine* machine, UINT8 pix, int pixeloffset ) |
| 3949 | { |
| 3950 | |
| 3951 | int shift = 12-(4*(pixeloffset&0x3)); |
| 3952 | UINT16 datamask = (0x000f) << shift; |
| 3953 | |
| 3954 | int offset = pixeloffset>>3; |
| 3955 | if (pixeloffset&4) offset++; |
| 3956 | |
| 3957 | offset &=0x1ffff; |
| 3958 | |
| 3959 | switch (segacd_memory_priority_mode) |
| 3960 | { |
| 3961 | case 0x00: // normal write, just write the data |
| 3962 | segacd_dataram[offset] = segacd_dataram[offset] &~ datamask; |
| 3963 | segacd_dataram[offset] |= pix << shift; |
| 3964 | break; |
| 3965 | |
| 3966 | case 0x01: // underwrite, only write if the existing data is 0 |
| 3967 | if ((segacd_dataram[offset]&datamask) == 0x0000) |
| 3968 | { |
| 3969 | segacd_dataram[offset] = segacd_dataram[offset] &~ datamask; |
| 3970 | segacd_dataram[offset] |= pix << shift; |
| 3971 | } |
| 3972 | break; |
| 3973 | |
| 3974 | case 0x02: // overwrite, only write non-zero data |
| 3975 | if (pix) |
| 3976 | { |
| 3977 | segacd_dataram[offset] = segacd_dataram[offset] &~ datamask; |
| 3978 | segacd_dataram[offset] |= pix << shift; |
| 3979 | } |
| 3980 | break; |
| 3981 | |
| 3982 | default: |
| 3983 | case 0x03: |
| 3984 | pix = machine->rand() & 0x000f; |
| 3985 | segacd_dataram[offset] = segacd_dataram[offset] &~ datamask; |
| 3986 | segacd_dataram[offset] |= pix << shift; |
| 3987 | break; |
| 3988 | |
| 3989 | } |
| 3990 | } |
| 3991 | |
| 3946 | 3992 | // 1meg / 2meg swap is interleaved swap, not half/half of the ram? |
| 3947 | 3993 | // Wily Beamish and Citizen X appear to rely on this |
| 3948 | 3994 | // however, it breaks the megacdj bios (megacd2j still works!) |
| r10806 | r10807 | |
| 3959 | 4005 | return segacd_dataram[offset]; |
| 3960 | 4006 | } |
| 3961 | 4007 | |
| 3962 | | void segacd_1meg_mode_word_write(int offset, UINT16 data, UINT16 mem_mask, int use_pm) |
| 4008 | |
| 4009 | void segacd_1meg_mode_word_write(running_machine* machine, int offset, UINT16 data, UINT16 mem_mask, int use_pm) |
| 3963 | 4010 | { |
| 3964 | 4011 | offset *= 2; |
| 3965 | 4012 | |
| r10806 | r10807 | |
| 4600 | 4647 | |
| 4601 | 4648 | if (!(scd_rammode & 1)) |
| 4602 | 4649 | { |
| 4603 | | segacd_1meg_mode_word_write((dstoffset+0x20000)/2, data, 0xffff, 0); |
| 4650 | segacd_1meg_mode_word_write(space->machine,(dstoffset+0x20000)/2, data, 0xffff, 0); |
| 4604 | 4651 | } |
| 4605 | 4652 | else |
| 4606 | 4653 | { |
| 4607 | | segacd_1meg_mode_word_write((dstoffset+0x00000)/2, data, 0xffff, 0); |
| 4654 | segacd_1meg_mode_word_write(space->machine,(dstoffset+0x00000)/2, data, 0xffff, 0); |
| 4608 | 4655 | } |
| 4609 | 4656 | } |
| 4610 | 4657 | |
| r10806 | r10807 | |
| 4855 | 4902 | //static void segacd_mark_stampmaps_dirty(void); |
| 4856 | 4903 | |
| 4857 | 4904 | |
| 4905 | |
| 4858 | 4906 | static WRITE16_HANDLER( scd_a12000_halt_reset_w ) |
| 4859 | 4907 | { |
| 4860 | 4908 | space->machine->scheduler().synchronize(); |
| r10806 | r10807 | |
| 4865 | 4913 | { |
| 4866 | 4914 | // reset line |
| 4867 | 4915 | if (a12000_halt_reset_reg&0x0001) |
| 4916 | { |
| 4868 | 4917 | cputag_set_input_line(space->machine, "segacd_68k", INPUT_LINE_RESET, CLEAR_LINE); |
| 4918 | printf("clear reset slave\n"); |
| 4919 | } |
| 4869 | 4920 | else |
| 4921 | { |
| 4870 | 4922 | cputag_set_input_line(space->machine, "segacd_68k", INPUT_LINE_RESET, ASSERT_LINE); |
| 4923 | printf("assert reset slave\n"); |
| 4924 | } |
| 4871 | 4925 | |
| 4872 | 4926 | // request BUS |
| 4873 | 4927 | if (a12000_halt_reset_reg&0x0002) |
| 4928 | { |
| 4874 | 4929 | cputag_set_input_line(space->machine, "segacd_68k", INPUT_LINE_HALT, ASSERT_LINE); |
| 4930 | printf("halt slave\n"); |
| 4931 | } |
| 4875 | 4932 | else |
| 4933 | { |
| 4876 | 4934 | cputag_set_input_line(space->machine, "segacd_68k", INPUT_LINE_HALT, CLEAR_LINE); |
| 4935 | printf("resume slave\n"); |
| 4936 | } |
| 4877 | 4937 | } |
| 4878 | 4938 | |
| 4879 | 4939 | if (ACCESSING_BITS_8_15) |
| r10806 | r10807 | |
| 4886 | 4946 | |
| 4887 | 4947 | if (a12000_halt_reset_reg&0x8000) |
| 4888 | 4948 | { |
| 4889 | | printf("a12000_halt_reset_reg & 0x8000 set\n"); // irq2 mask? |
| 4949 | //printf("a12000_halt_reset_reg & 0x8000 set\n"); // irq2 mask? |
| 4890 | 4950 | } |
| 4891 | 4951 | |
| 4892 | 4952 | |
| r10806 | r10807 | |
| 5347 | 5407 | // ret bit set by sub cpu determines which half of WorkRAM we have access to? |
| 5348 | 5408 | if (scd_rammode&1) |
| 5349 | 5409 | { |
| 5350 | | segacd_1meg_mode_word_write(offset+0x20000/2, data, mem_mask, 0); |
| 5410 | segacd_1meg_mode_word_write(space->machine, offset+0x20000/2, data, mem_mask, 0); |
| 5351 | 5411 | } |
| 5352 | 5412 | else |
| 5353 | 5413 | { |
| 5354 | | segacd_1meg_mode_word_write(offset+0x00000/2, data, mem_mask, 0); |
| 5414 | segacd_1meg_mode_word_write(space->machine, offset+0x00000/2, data, mem_mask, 0); |
| 5355 | 5415 | } |
| 5356 | 5416 | } |
| 5357 | 5417 | else |
| r10806 | r10807 | |
| 6030 | 6090 | stopwatch_timer = machine->device<timer_device>("sw_timer"); |
| 6031 | 6091 | |
| 6032 | 6092 | scd_dma_timer->adjust(attotime::zero); |
| 6093 | |
| 6094 | |
| 6095 | // HACK!!!! timegal, anettfut, roadaven end up with the SubCPU waiting in a loop for *something* |
| 6096 | // overclocking the CPU, even at the point where the game is hung, allows them to continue and boot |
| 6097 | // I'm not sure what the source of this timing problem is, it's not using IRQ3 or StopWatch at the |
| 6098 | // time. Changing the CDHock timer to 50hz from 75hz also stops the hang, but then the video is |
| 6099 | // too slow and has bad sound. -- Investigate! |
| 6100 | |
| 6101 | _segacd_68k_cpu->set_clock_scale(1.5000f); |
| 6102 | |
| 6033 | 6103 | } |
| 6034 | 6104 | |
| 6035 | 6105 | |
| r10806 | r10807 | |
| 6154 | 6224 | |
| 6155 | 6225 | if (scd_rammode&1) |
| 6156 | 6226 | { |
| 6157 | | segacd_1meg_mode_word_write(offset/2+0x00000/2, data , mem_mask, 1); |
| 6227 | segacd_1meg_mode_word_write(space->machine, offset/2+0x00000/2, data , mem_mask, 1); |
| 6158 | 6228 | } |
| 6159 | 6229 | else |
| 6160 | 6230 | { |
| 6161 | | segacd_1meg_mode_word_write(offset/2+0x20000/2, data, mem_mask, 1); |
| 6231 | segacd_1meg_mode_word_write(space->machine, offset/2+0x20000/2, data, mem_mask, 1); |
| 6162 | 6232 | } |
| 6163 | 6233 | |
| 6164 | 6234 | // printf("Unspported: segacd_sub_dataram_part1_w in mode 1 (Word RAM Expander - 1 Byte Per Pixel) %04x\n", data); |
| r10806 | r10807 | |
| 6202 | 6272 | // ret bit set by sub cpu determines which half of WorkRAM we have access to? |
| 6203 | 6273 | if (scd_rammode&1) |
| 6204 | 6274 | { |
| 6205 | | segacd_1meg_mode_word_write(offset+0x00000/2, data, mem_mask, 0); |
| 6275 | segacd_1meg_mode_word_write(space->machine,offset+0x00000/2, data, mem_mask, 0); |
| 6206 | 6276 | } |
| 6207 | 6277 | else |
| 6208 | 6278 | { |
| 6209 | | segacd_1meg_mode_word_write(offset+0x20000/2, data, mem_mask, 0); |
| 6279 | segacd_1meg_mode_word_write(space->machine,offset+0x20000/2, data, mem_mask, 0); |
| 6210 | 6280 | } |
| 6211 | 6281 | |
| 6212 | 6282 | } |
| r10806 | r10807 | |
| 6360 | 6430 | return 0; |
| 6361 | 6431 | } |
| 6362 | 6432 | |
| 6363 | | INLINE void write_pixel_to_imagebuffer( running_machine* machine, UINT32 pix, int line, int xpos ) |
| 6364 | | { |
| 6365 | 6433 | |
| 6366 | | UINT32 bufferstart = (segacd_imagebuffer_start_address&0xfff8)*2; |
| 6367 | | UINT32 bufferend = bufferstart + (((segacd_imagebuffer_vcell_size+1) * (segacd_imagebuffer_hdot_size>>3)*0x20)/2); |
| 6368 | | UINT32 offset; |
| 6369 | 6434 | |
| 6370 | | offset = bufferstart+(((segacd_imagebuffer_vcell_size+1)*0x10)*xpos); |
| 6371 | 6435 | |
| 6372 | | // lines of each output cell |
| 6373 | | offset+= (line*2); |
| 6374 | 6436 | |
| 6375 | | while (offset>=bufferend) |
| 6376 | | offset-= bufferend; |
| 6377 | | |
| 6378 | | |
| 6379 | | switch (segacd_memory_priority_mode) |
| 6380 | | { |
| 6381 | | case 0x00: // normal write, just write the data |
| 6382 | | segacd_dataram[offset] = pix >> 16; |
| 6383 | | segacd_dataram[offset+1] = pix & 0xffff; |
| 6384 | | break; |
| 6385 | | |
| 6386 | | case 0x01: // underwrite, only write if the existing data is 0 |
| 6387 | | if ((segacd_dataram[offset]&0xf000) == 0x0000) segacd_dataram[offset] |= (pix>>16)&0xf000; |
| 6388 | | if ((segacd_dataram[offset]&0x0f00) == 0x0000) segacd_dataram[offset] |= (pix>>16)&0x0f00; |
| 6389 | | if ((segacd_dataram[offset]&0x00f0) == 0x0000) segacd_dataram[offset] |= (pix>>16)&0x00f0; |
| 6390 | | if ((segacd_dataram[offset]&0x000f) == 0x0000) segacd_dataram[offset] |= (pix>>16)&0x000f; |
| 6391 | | if ((segacd_dataram[offset+1]&0xf000) == 0x0000) segacd_dataram[offset+1] |= (pix)&0xf000; |
| 6392 | | if ((segacd_dataram[offset+1]&0x0f00) == 0x0000) segacd_dataram[offset+1] |= (pix)&0x0f00; |
| 6393 | | if ((segacd_dataram[offset+1]&0x00f0) == 0x0000) segacd_dataram[offset+1] |= (pix)&0x00f0; |
| 6394 | | if ((segacd_dataram[offset+1]&0x000f) == 0x0000) segacd_dataram[offset+1] |= (pix)&0x000f; |
| 6395 | | break; |
| 6396 | | |
| 6397 | | case 0x02: // overwrite, only write non-zero data |
| 6398 | | if ((pix>>16)&0xf000) segacd_dataram[offset] = (segacd_dataram[offset] & 0x0fff) | ((pix>>16)&0xf000); |
| 6399 | | if ((pix>>16)&0x0f00) segacd_dataram[offset] = (segacd_dataram[offset] & 0xf0ff) | ((pix>>16)&0x0f00); |
| 6400 | | if ((pix>>16)&0x00f0) segacd_dataram[offset] = (segacd_dataram[offset] & 0xff0f) | ((pix>>16)&0x00f0); |
| 6401 | | if ((pix>>16)&0x000f) segacd_dataram[offset] = (segacd_dataram[offset] & 0xfff0) | ((pix>>16)&0x000f); |
| 6402 | | if ((pix)&0xf000) segacd_dataram[offset+1] = (segacd_dataram[offset+1] & 0x0fff) | ((pix)&0xf000); |
| 6403 | | if ((pix)&0x0f00) segacd_dataram[offset+1] = (segacd_dataram[offset+1] & 0xf0ff) | ((pix)&0x0f00); |
| 6404 | | if ((pix)&0x00f0) segacd_dataram[offset+1] = (segacd_dataram[offset+1] & 0xff0f) | ((pix)&0x00f0); |
| 6405 | | if ((pix)&0x000f) segacd_dataram[offset+1] = (segacd_dataram[offset+1] & 0xfff0) | ((pix)&0x000f); |
| 6406 | | break; |
| 6407 | | |
| 6408 | | default: |
| 6409 | | case 0x03: // invalid? |
| 6410 | | segacd_dataram[offset] = machine->rand(); |
| 6411 | | segacd_dataram[offset+1] = machine->rand(); |
| 6412 | | break; |
| 6413 | | |
| 6414 | | } |
| 6415 | | |
| 6416 | | segacd_mark_tiles_dirty(machine, offset); |
| 6417 | | segacd_mark_tiles_dirty(machine, offset+1); |
| 6418 | | |
| 6419 | | } |
| 6420 | | |
| 6421 | 6437 | // this triggers the conversion operation, which will cause an IRQ1 when finished |
| 6422 | 6438 | WRITE16_HANDLER( segacd_trace_vector_base_address_w ) |
| 6423 | 6439 | { |
| r10806 | r10807 | |
| 6446 | 6462 | int line; |
| 6447 | 6463 | //bitmap_t *srcbitmap = tilemap_get_pixmap(segacd_stampmap[segacd_get_active_stampmap_tilemap()]); |
| 6448 | 6464 | bitmap_t *srcbitmap = 0; |
| 6465 | UINT32 bufferstart = ((segacd_imagebuffer_start_address&0xfff8)*2)<<3; |
| 6449 | 6466 | |
| 6450 | 6467 | for (line=0;line<segacd_imagebuffer_vdot_size;line++) |
| 6451 | 6468 | { |
| r10806 | r10807 | |
| 6466 | 6483 | int ybase = tilemapyoffs * 256; |
| 6467 | 6484 | int count; |
| 6468 | 6485 | |
| 6469 | | for (count=0;count<(segacd_imagebuffer_hdot_size>>3);count++) |
| 6486 | for (count=0;count<(segacd_imagebuffer_hdot_size);count++) |
| 6470 | 6487 | { |
| 6471 | | int i; |
| 6472 | | UINT32 pixblock = 0x00000000; |
| 6473 | | for (i=7*4;i>=0;i-=4) |
| 6474 | | { |
| 6475 | | pixblock |= read_pixel_from_stampmap(space->machine, srcbitmap, xbase>>(3+8), ybase>>(3+8)) << (i); |
| 6488 | //int i; |
| 6489 | UINT8 pix = 0x0; |
| 6476 | 6490 | |
| 6491 | pix = read_pixel_from_stampmap(space->machine, srcbitmap, xbase>>(3+8), ybase>>(3+8)); |
| 6477 | 6492 | |
| 6478 | | xbase += deltax; |
| 6479 | | ybase += deltay; |
| 6493 | xbase += deltax; |
| 6494 | ybase += deltay; |
| 6480 | 6495 | |
| 6481 | | // clamp to 24-bits, seems to be required for all the intro effects to work |
| 6482 | | xbase &= 0xffffff; |
| 6483 | | ybase &= 0xffffff; |
| 6496 | // clamp to 24-bits, seems to be required for all the intro effects to work |
| 6497 | xbase &= 0xffffff; |
| 6498 | ybase &= 0xffffff; |
| 6484 | 6499 | |
| 6500 | int countx = count + (segacd_imagebuffer_offset&0x7); |
| 6485 | 6501 | |
| 6486 | | } |
| 6502 | UINT32 offset; |
| 6487 | 6503 | |
| 6504 | offset = bufferstart+((((segacd_imagebuffer_vcell_size+1)*0x10)*(countx>>3))<<3); |
| 6488 | 6505 | |
| 6506 | offset+= ((line*2)<<3); |
| 6507 | offset+=(segacd_imagebuffer_offset&0x38)<<1; |
| 6489 | 6508 | |
| 6509 | offset+=countx & 0x7; |
| 6490 | 6510 | |
| 6491 | | write_pixel_to_imagebuffer(space->machine, pixblock, line, count); |
| 6511 | write_pixel( space->machine, pix, offset ); |
| 6512 | |
| 6513 | segacd_mark_tiles_dirty(space->machine, (offset>>3)); |
| 6514 | segacd_mark_tiles_dirty(space->machine, (offset>>3)+1); |
| 6515 | |
| 6492 | 6516 | } |
| 6493 | 6517 | |
| 6494 | 6518 | } |
| r10806 | r10807 | |
| 6651 | 6675 | else |
| 6652 | 6676 | cdfader_vol = (cdfader_vol / 1024.0) * 100.0; |
| 6653 | 6677 | |
| 6654 | | printf("%f\n",cdfader_vol); |
| 6678 | //printf("%f\n",cdfader_vol); |
| 6655 | 6679 | |
| 6656 | 6680 | cdda_set_volume(space->machine->device("cdda"), cdfader_vol); |
| 6657 | 6681 | } |
| r10806 | r10807 | |
| 9271 | 9295 | if (genesis_other_hacks) |
| 9272 | 9296 | { |
| 9273 | 9297 | // set_refresh_rate(megadriv_framerate); |
| 9274 | | machine->device("maincpu")->set_clock_scale(0.9950f); /* Fatal Rewind is very fussy... */ |
| 9275 | | // machine->device("maincpu")->set_clock_scale(0.3800f); /* Fatal Rewind is very fussy... */ |
| 9298 | // machine->device("maincpu")->set_clock_scale(0.9950f); /* Fatal Rewind is very fussy... (and doesn't work now anyway, so don't bother with this) */ |
| 9276 | 9299 | |
| 9277 | 9300 | memset(megadrive_ram,0x00,0x10000); |
| 9278 | 9301 | } |