src/mess/drivers/vii.c
| r7548 | r7549 | |
| 33 | 33 | D - SPG243 - The Batman |
| 34 | 34 | D - SPG243 - Wall-E |
| 35 | 35 | D - SPG243 - Chintendo / KenSingTon / Siatronics / Jungle Soft Vii |
| 36 | Partial D - SPG200 - V-Tech V-Smile |
| 36 | 37 | ND - Likely many more |
| 37 | 38 | |
| 38 | 39 | *******************************************************************************/ |
| r7548 | r7549 | |
| 77 | 78 | } |
| 78 | 79 | screen[320*240]; |
| 79 | 80 | |
| 80 | | UINT16 io_regs[0x100]; |
| 81 | UINT16 io_regs[0x200]; |
| 81 | 82 | UINT16 uart_rx_count; |
| 82 | 83 | UINT8 controller_input[8]; |
| 83 | 84 | UINT32 spg243_mode; |
| r7548 | r7549 | |
| 87 | 88 | { |
| 88 | 89 | SPG243_VII = 0, |
| 89 | 90 | SPG243_BATMAN, |
| 91 | SPG243_VSMILE, |
| 90 | 92 | |
| 91 | 93 | SPG243_MODEL_COUNT, |
| 92 | 94 | }; |
| r7548 | r7549 | |
| 153 | 155 | state->screen[offset].b = expand_rgb5_to_rgb8(rgb); |
| 154 | 156 | } |
| 155 | 157 | |
| 156 | | static void vii_blit(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT32 xoff, UINT32 yoff, UINT32 flags, UINT32 bitmap_addr, UINT16 tile) |
| 158 | static void vii_blit(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, UINT32 xoff, UINT32 yoff, UINT32 attr, UINT32 ctrl, UINT32 bitmap_addr, UINT16 tile) |
| 157 | 159 | { |
| 158 | 160 | vii_state *state = (vii_state *)machine->driver_data; |
| 159 | 161 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 160 | 162 | |
| 161 | | UINT32 h = 8 << ((flags & PAGE_TILE_HEIGHT_MASK) >> PAGE_TILE_HEIGHT_SHIFT); |
| 162 | | UINT32 w = 8 << ((flags & PAGE_TILE_WIDTH_MASK) >> PAGE_TILE_WIDTH_SHIFT); |
| 163 | UINT32 h = 8 << ((attr & PAGE_TILE_HEIGHT_MASK) >> PAGE_TILE_HEIGHT_SHIFT); |
| 164 | UINT32 w = 8 << ((attr & PAGE_TILE_WIDTH_MASK) >> PAGE_TILE_WIDTH_SHIFT); |
| 163 | 165 | |
| 164 | | UINT32 yflipmask = flags & TILE_Y_FLIP ? h - 1 : 0; |
| 165 | | UINT32 xflipmask = flags & TILE_X_FLIP ? w - 1 : 0; |
| 166 | UINT32 yflipmask = attr & TILE_Y_FLIP ? h - 1 : 0; |
| 167 | UINT32 xflipmask = attr & TILE_X_FLIP ? w - 1 : 0; |
| 166 | 168 | |
| 167 | | UINT32 nc = ((flags & 0x0003) + 1) << 1; |
| 169 | UINT32 nc = ((attr & 0x0003) + 1) << 1; |
| 168 | 170 | |
| 169 | | UINT32 palette_offset = (flags & 0x0f00) >> 4; |
| 171 | UINT32 palette_offset = (attr & 0x0f00) >> 4; |
| 172 | palette_offset >>= nc; |
| 173 | palette_offset <<= nc; |
| 170 | 174 | |
| 171 | 175 | UINT32 m = bitmap_addr + nc*w*h/16*tile; |
| 172 | 176 | UINT32 bits = 0; |
| r7548 | r7549 | |
| 193 | 197 | } |
| 194 | 198 | nbits -= nc; |
| 195 | 199 | |
| 196 | | pal = palette_offset + (bits >> 16); |
| 200 | pal = palette_offset | (bits >> 16); |
| 197 | 201 | bits &= 0xffff; |
| 198 | 202 | |
| 199 | | if((flags & 0x00100000) && yy < 240) |
| 203 | if((ctrl & 0x0010) && yy < 240) |
| 200 | 204 | { |
| 201 | 205 | xx = (xx - (INT16)state->rowscroll[yy]) & 0x01ff; |
| 202 | 206 | } |
| r7548 | r7549 | |
| 206 | 210 | UINT16 rgb = state->palette[pal]; |
| 207 | 211 | if(!(rgb & 0x8000)) |
| 208 | 212 | { |
| 209 | | if (flags & 0x4000) |
| 213 | if (attr & 0x4000) |
| 210 | 214 | { |
| 211 | 215 | vii_mix_pixel(state, xx + 320*yy, rgb); |
| 212 | 216 | } |
| r7548 | r7549 | |
| 225 | 229 | UINT32 x0, y0; |
| 226 | 230 | UINT32 xscroll = regs[0]; |
| 227 | 231 | UINT32 yscroll = regs[1]; |
| 228 | | UINT32 flags = regs[2]; |
| 229 | | UINT32 flags2 = regs[3]; |
| 232 | UINT32 attr = regs[2]; |
| 233 | UINT32 ctrl = regs[3]; |
| 230 | 234 | UINT32 tilemap = regs[4]; |
| 231 | 235 | UINT32 palette_map = regs[5]; |
| 232 | 236 | UINT32 h, w, hn, wn; |
| 233 | 237 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 234 | 238 | |
| 235 | | if(!(flags2 & PAGE_ENABLE_MASK)) |
| 239 | if(!(ctrl & PAGE_ENABLE_MASK)) |
| 236 | 240 | { |
| 237 | 241 | return; |
| 238 | 242 | } |
| 239 | 243 | |
| 240 | | if(((flags & PAGE_DEPTH_FLAG_MASK) >> PAGE_DEPTH_FLAG_SHIFT) != depth) |
| 244 | if(((attr & PAGE_DEPTH_FLAG_MASK) >> PAGE_DEPTH_FLAG_SHIFT) != depth) |
| 241 | 245 | { |
| 242 | 246 | return; |
| 243 | 247 | } |
| 244 | 248 | |
| 245 | | h = 8 << ((flags & PAGE_TILE_HEIGHT_MASK) >> PAGE_TILE_HEIGHT_SHIFT); |
| 246 | | w = 8 << ((flags & PAGE_TILE_WIDTH_MASK) >> PAGE_TILE_WIDTH_SHIFT); |
| 249 | h = 8 << ((attr & PAGE_TILE_HEIGHT_MASK) >> PAGE_TILE_HEIGHT_SHIFT); |
| 250 | w = 8 << ((attr & PAGE_TILE_WIDTH_MASK) >> PAGE_TILE_WIDTH_SHIFT); |
| 247 | 251 | |
| 248 | 252 | hn = 256 / h; |
| 249 | 253 | wn = 512 / w; |
| r7548 | r7549 | |
| 254 | 258 | { |
| 255 | 259 | UINT16 tile = memory_read_word_16le(space, (tilemap + x0 + wn * y0) << 1); |
| 256 | 260 | UINT16 palette = 0; |
| 257 | | UINT32 tileflags = 0; |
| 258 | 261 | UINT32 xx, yy; |
| 259 | 262 | |
| 260 | 263 | if(!tile) |
| r7548 | r7549 | |
| 268 | 271 | palette >>= 8; |
| 269 | 272 | } |
| 270 | 273 | |
| 271 | | if(palette & 0x10) // X flip |
| 272 | | { |
| 273 | | tileflags |= 4; |
| 274 | UINT32 tileattr = attr; |
| 275 | UINT32 tilectrl = ctrl; |
| 276 | if ((ctrl & 2) == 0) |
| 277 | { // -(1) bld(1) flip(2) pal(4) |
| 278 | tileattr &= ~0x000c; |
| 279 | tileattr |= (palette >> 2) & 0x000c; // flip |
| 280 | |
| 281 | tileattr &= ~0x0f00; |
| 282 | tileattr |= (palette << 8) & 0x0f00; // palette |
| 283 | |
| 284 | tileattr &= ~0x0100; |
| 285 | tileattr |= (palette << 2) & 0x0100; // blend |
| 274 | 286 | } |
| 275 | | tileflags |= (palette & 0x0f) << 8; |
| 276 | 287 | |
| 277 | 288 | yy = ((h*y0 - yscroll + 0x10) & 0xff) - 0x10; |
| 278 | 289 | xx = (w*x0 - xscroll) & 0x1ff; |
| 279 | 290 | |
| 280 | | vii_blit(machine, bitmap, cliprect, xx, yy, (flags2 << 16) | flags | tileflags, bitmap_addr, tile); |
| 291 | vii_blit(machine, bitmap, cliprect, xx, yy, tileattr, tilectrl, bitmap_addr, tile); |
| 281 | 292 | } |
| 282 | 293 | } |
| 283 | 294 | } |
| r7548 | r7549 | |
| 286 | 297 | { |
| 287 | 298 | vii_state *state = (vii_state *)machine->driver_data; |
| 288 | 299 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 289 | | UINT16 tile, flags; |
| 300 | UINT16 tile, attr; |
| 290 | 301 | INT16 x, y; |
| 291 | 302 | UINT32 h, w; |
| 292 | 303 | UINT32 bitmap_addr = 0x40 * state->video_regs[0x22]; |
| r7548 | r7549 | |
| 294 | 305 | tile = memory_read_word_16le(space, (base_addr + 0) << 1); |
| 295 | 306 | x = memory_read_word_16le(space, (base_addr + 1) << 1); |
| 296 | 307 | y = memory_read_word_16le(space, (base_addr + 2) << 1); |
| 297 | | flags = memory_read_word_16le(space, (base_addr + 3) << 1); |
| 308 | attr = memory_read_word_16le(space, (base_addr + 3) << 1); |
| 298 | 309 | |
| 299 | | if(((flags & PAGE_DEPTH_FLAG_MASK) >> PAGE_DEPTH_FLAG_SHIFT) != depth) |
| 310 | if(!tile) |
| 300 | 311 | { |
| 301 | 312 | return; |
| 302 | 313 | } |
| 303 | 314 | |
| 315 | if(((attr & PAGE_DEPTH_FLAG_MASK) >> PAGE_DEPTH_FLAG_SHIFT) != depth) |
| 316 | { |
| 317 | return; |
| 318 | } |
| 319 | |
| 304 | 320 | if(state->centered_coordinates) |
| 305 | 321 | { |
| 306 | 322 | x = 160 + x; |
| 307 | 323 | y = 120 - y; |
| 308 | 324 | |
| 309 | | h = 8 << ((flags & PAGE_TILE_HEIGHT_MASK) >> PAGE_TILE_HEIGHT_SHIFT); |
| 310 | | w = 8 << ((flags & PAGE_TILE_WIDTH_MASK) >> PAGE_TILE_WIDTH_SHIFT); |
| 325 | h = 8 << ((attr & PAGE_TILE_HEIGHT_MASK) >> PAGE_TILE_HEIGHT_SHIFT); |
| 326 | w = 8 << ((attr & PAGE_TILE_WIDTH_MASK) >> PAGE_TILE_WIDTH_SHIFT); |
| 311 | 327 | |
| 312 | 328 | x -= (w/2); |
| 313 | 329 | y -= (h/2) - 8; |
| r7548 | r7549 | |
| 316 | 332 | x &= 0x01ff; |
| 317 | 333 | y &= 0x01ff; |
| 318 | 334 | |
| 319 | | vii_blit(machine, bitmap, cliprect, x, y, flags, bitmap_addr, tile); |
| 335 | vii_blit(machine, bitmap, cliprect, x, y, attr, 0, bitmap_addr, tile); |
| 320 | 336 | } |
| 321 | 337 | |
| 322 | 338 | static void vii_blit_sprites(running_machine *machine, bitmap_t *bitmap, const rectangle *cliprect, int depth) |
| 323 | 339 | { |
| 324 | | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 340 | vii_state *state = (vii_state *)machine->driver_data; |
| 325 | 341 | UINT32 n; |
| 342 | |
| 343 | if (!(state->video_regs[0x42] & 1)) |
| 344 | { |
| 345 | return; |
| 346 | } |
| 347 | |
| 326 | 348 | for(n = 0; n < 256; n++) |
| 327 | 349 | { |
| 328 | | if(memory_read_word_16le(space, (0x2c00 + 4*n) << 1)) |
| 350 | //if(memory_read_word_16le(space, (0x2c00 + 4*n) << 1)) |
| 329 | 351 | { |
| 330 | 352 | vii_blit_sprite(machine, bitmap, cliprect, depth, 0x2c00 + 4*n); |
| 331 | 353 | } |
| r7548 | r7549 | |
| 485 | 507 | UINT16 buffer = state->io_regs[5*index + 2]; |
| 486 | 508 | UINT16 dir = state->io_regs[5*index + 3]; |
| 487 | 509 | UINT16 attr = state->io_regs[5*index + 4]; |
| 510 | UINT16 special= state->io_regs[5*index + 5]; |
| 488 | 511 | |
| 489 | 512 | UINT16 push = dir; |
| 490 | 513 | UINT16 pull = (~dir) & (~attr); |
| 491 | | UINT16 what = (buffer & (push | pull)) ^ (dir &~ attr); |
| 514 | UINT16 what = (buffer & (push | pull)); |
| 515 | what ^= (dir & ~attr); |
| 516 | what &= ~special; |
| 492 | 517 | |
| 493 | 518 | if(state->spg243_mode == SPG243_VII) |
| 494 | 519 | { |
| r7548 | r7549 | |
| 525 | 550 | { |
| 526 | 551 | } |
| 527 | 552 | |
| 553 | static void spg_do_dma(running_machine *machine, UINT32 len) |
| 554 | { |
| 555 | vii_state *state = (vii_state *)machine->driver_data; |
| 556 | const address_space *space = cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM); |
| 557 | |
| 558 | UINT32 src = ((state->io_regs[0x101] & 0x3f) << 16) | state->io_regs[0x100]; |
| 559 | UINT32 dst = state->io_regs[0x103] & 0x3fff; |
| 560 | UINT32 j; |
| 561 | |
| 562 | for(j = 0; j < len; j++) |
| 563 | { |
| 564 | memory_write_word_16le(space, (dst+j) << 1, memory_read_word_16le(space, (src+j) << 1)); |
| 565 | } |
| 566 | |
| 567 | state->io_regs[0x102] = 0; |
| 568 | } |
| 569 | |
| 528 | 570 | static READ16_HANDLER( vii_io_r ) |
| 529 | 571 | { |
| 530 | 572 | static const char *gpioregs[] = { "GPIO Data Port", "GPIO Buffer Port", "GPIO Direction Port", "GPIO Attribute Port", "GPIO IRQ/Latch Port" }; |
| r7548 | r7549 | |
| 654 | 696 | COMBINE_DATA(&state->io_regs[offset]); |
| 655 | 697 | break; |
| 656 | 698 | |
| 699 | case 0x32: // UART Reset |
| 700 | verboselog(space->machine, 3, "vii_io_r: UART Reset\n"); |
| 701 | break; |
| 702 | |
| 657 | 703 | case 0x33: // UART Baud Rate |
| 658 | | verboselog(space->machine, 3, "vii_io_w: UART Baud Rate = %04x (%04x)\n", data, mem_mask); |
| 704 | verboselog(space->machine, 3, "vii_io_w: UART Baud Rate = %u\n", 27000000 / 16 / (0x10000 - (state->io_regs[0x34] << 8) - data)); |
| 659 | 705 | COMBINE_DATA(&state->io_regs[offset]); |
| 660 | 706 | break; |
| 661 | 707 | |
| 662 | 708 | case 0x35: // UART TX Data |
| 663 | | verboselog(space->machine, 3, "vii_io_w: UART TX Data = %04x (%04x)\n", data, mem_mask); |
| 709 | verboselog(space->machine, 3, "vii_io_w: UART Baud Rate = %u\n", 27000000 / 16 / (0x10000 - (data << 8) - state->io_regs[0x33])); |
| 664 | 710 | COMBINE_DATA(&state->io_regs[offset]); |
| 665 | 711 | break; |
| 666 | 712 | |
| r7548 | r7549 | |
| 705 | 751 | state->io_regs[offset] &= ~data; |
| 706 | 752 | break; |
| 707 | 753 | |
| 754 | case 0x100: // DMA Source (L) |
| 755 | case 0x101: // DMA Source (H) |
| 756 | case 0x103: // DMA Destination |
| 757 | COMBINE_DATA(&state->io_regs[offset]); |
| 758 | break; |
| 759 | |
| 760 | case 0x102: // DMA Length |
| 761 | spg_do_dma(space->machine, data); |
| 762 | break; |
| 763 | |
| 708 | 764 | default: |
| 709 | 765 | verboselog(space->machine, 3, "vii_io_w: Unknown register %04x = %04x (%04x)\n", 0x3800 + offset, data, mem_mask); |
| 710 | 766 | COMBINE_DATA(&state->io_regs[offset]); |
| r7548 | r7549 | |
| 769 | 825 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("X Button") |
| 770 | 826 | INPUT_PORTS_END |
| 771 | 827 | |
| 828 | static INPUT_PORTS_START( vsmile ) |
| 829 | PORT_START("P1") |
| 830 | PORT_BIT( 0x01, IP_ACTIVE_HIGH, IPT_JOYSTICK_UP ) PORT_PLAYER(1) PORT_NAME("Joypad Up") |
| 831 | PORT_BIT( 0x02, IP_ACTIVE_HIGH, IPT_JOYSTICK_DOWN ) PORT_PLAYER(1) PORT_NAME("Joypad Down") |
| 832 | PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_JOYSTICK_LEFT ) PORT_PLAYER(1) PORT_NAME("Joypad Left") |
| 833 | PORT_BIT( 0x08, IP_ACTIVE_HIGH, IPT_JOYSTICK_RIGHT ) PORT_PLAYER(1) PORT_NAME("Joypad Right") |
| 834 | PORT_BIT( 0x10, IP_ACTIVE_HIGH, IPT_BUTTON1 ) PORT_PLAYER(1) PORT_NAME("A Button") |
| 835 | PORT_BIT( 0x20, IP_ACTIVE_HIGH, IPT_BUTTON2 ) PORT_PLAYER(1) PORT_NAME("Menu") |
| 836 | PORT_BIT( 0x40, IP_ACTIVE_HIGH, IPT_BUTTON3 ) PORT_PLAYER(1) PORT_NAME("B Button") |
| 837 | PORT_BIT( 0x80, IP_ACTIVE_HIGH, IPT_BUTTON4 ) PORT_PLAYER(1) PORT_NAME("X Button") |
| 838 | INPUT_PORTS_END |
| 839 | |
| 772 | 840 | static DEVICE_IMAGE_LOAD( vii_cart ) |
| 773 | 841 | { |
| 774 | 842 | vii_state *state = (vii_state *)image->machine->driver_data; |
| r7548 | r7549 | |
| 797 | 865 | return INIT_PASS; |
| 798 | 866 | } |
| 799 | 867 | |
| 868 | static DEVICE_IMAGE_LOAD( vsmile_cart ) |
| 869 | { |
| 870 | vii_state *state = (vii_state *)image->machine->driver_data; |
| 871 | UINT8 *cart = memory_region( image->machine, "cart" ); |
| 872 | int size = image_length( image ); |
| 873 | |
| 874 | if( image_fread( image, cart, size ) != size ) |
| 875 | { |
| 876 | image_seterror( image, IMAGE_ERROR_UNSPECIFIED, "Unable to fully read from file" ); |
| 877 | return INIT_FAIL; |
| 878 | } |
| 879 | |
| 880 | memcpy(state->cart, cart + 0x4000*2, (0x400000 - 0x4000) * 2); |
| 881 | |
| 882 | return INIT_PASS; |
| 883 | } |
| 884 | |
| 800 | 885 | static MACHINE_START( vii ) |
| 801 | 886 | { |
| 802 | 887 | vii_state *state = (vii_state *)machine->driver_data; |
| r7548 | r7549 | |
| 878 | 963 | MDRV_VIDEO_UPDATE( vii ) |
| 879 | 964 | MACHINE_DRIVER_END |
| 880 | 965 | |
| 966 | static MACHINE_DRIVER_START( vsmile ) |
| 967 | |
| 968 | MDRV_DRIVER_DATA( vii_state ) |
| 969 | |
| 970 | MDRV_CPU_ADD( "maincpu", UNSP, XTAL_27MHz) |
| 971 | MDRV_CPU_PROGRAM_MAP( vii_mem ) |
| 972 | MDRV_CPU_VBLANK_INT("screen", vii_vblank) |
| 973 | |
| 974 | MDRV_MACHINE_START( vii ) |
| 975 | MDRV_MACHINE_RESET( vii ) |
| 976 | |
| 977 | MDRV_SCREEN_ADD( "screen", RASTER ) |
| 978 | MDRV_SCREEN_REFRESH_RATE(60) |
| 979 | MDRV_SCREEN_FORMAT(BITMAP_FORMAT_RGB32) |
| 980 | MDRV_SCREEN_SIZE(320, 240) |
| 981 | MDRV_SCREEN_VISIBLE_AREA(0, 320-1, 0, 240-1) |
| 982 | |
| 983 | MDRV_PALETTE_LENGTH(32768) |
| 984 | |
| 985 | MDRV_CARTSLOT_ADD( "cart" ) |
| 986 | MDRV_CARTSLOT_EXTENSION_LIST( "bin" ) |
| 987 | MDRV_CARTSLOT_MANDATORY |
| 988 | MDRV_CARTSLOT_LOAD( vsmile_cart ) |
| 989 | |
| 990 | MDRV_VIDEO_START( vii ) |
| 991 | MDRV_VIDEO_UPDATE( vii ) |
| 992 | MACHINE_DRIVER_END |
| 993 | |
| 881 | 994 | static MACHINE_DRIVER_START( batman ) |
| 882 | 995 | |
| 883 | 996 | MDRV_DRIVER_DATA( vii_state ) |
| r7548 | r7549 | |
| 920 | 1033 | i2cmem_init(machine, 0, I2CMEM_SLAVE_ADDRESS, 0, 0x200, NULL); |
| 921 | 1034 | } |
| 922 | 1035 | |
| 1036 | static DRIVER_INIT( vsmile ) |
| 1037 | { |
| 1038 | vii_state *state = (vii_state *)machine->driver_data; |
| 1039 | |
| 1040 | state->spg243_mode = SPG243_VSMILE; |
| 1041 | state->centered_coordinates = 1; |
| 1042 | } |
| 1043 | |
| 923 | 1044 | ROM_START( vii ) |
| 924 | 1045 | ROM_REGION( 0x800000, "maincpu", ROMREGION_ERASEFF ) /* dummy region for u'nSP */ |
| 925 | 1046 | |
| r7548 | r7549 | |
| 931 | 1052 | ROM_LOAD16_WORD_SWAP( "batman.bin", 0x000000, 0x400000, CRC(46f848e5) SHA1(5875d57bb3fe0cac5d20e626e4f82a0e5f9bb94c) ) |
| 932 | 1053 | ROM_END |
| 933 | 1054 | |
| 1055 | ROM_START( vsmile ) |
| 1056 | ROM_REGION( 0x800000, "maincpu", ROMREGION_ERASEFF ) /* dummy region for u'nSP */ |
| 1057 | |
| 1058 | ROM_REGION( 0x2000000, "cart", ROMREGION_ERASE00 ) |
| 1059 | ROM_END |
| 1060 | |
| 934 | 1061 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME FLAGS */ |
| 935 | 1062 | CONS( 2004, batman, 0, 0, batman, batman, batman, "JAKKS Pacific, Inc. / HotGen, Ltd.", "The Batman", GAME_NO_SOUND ) |
| 936 | | CONS( 2007, vii, 0, 0, vii, vii, vii, "Jungle Soft / KenSingTon / Chintendo / Siatronics", "Vii", GAME_NOT_WORKING | GAME_NO_SOUND) |
| 1063 | CONS( 2005, vsmile, 0, 0, vsmile, vsmile, vsmile, "V-Tech", "V-Smile", GAME_NO_SOUND | GAME_NOT_WORKING ) |
| 1064 | CONS( 2007, vii, 0, 0, vii, vii, vii, "Jungle Soft / KenSingTon / Chintendo / Siatronics", "Vii", GAME_NO_SOUND ) |
src/mess/drivers/craft.c
| r7548 | r7549 | |
| 1 | | /* |
| 2 | | Linus Akesson's "Craft" |
| 1 | /*\ |
| 2 | * * Linus Akesson's "Craft" |
| 3 | * * |
| 4 | * * Skeleton driver by MooglyGuy |
| 5 | * * Partial rewrite by Harmony |
| 6 | \*/ |
| 3 | 7 | |
| 4 | | Skeleton driver by MooglyGuy |
| 5 | | */ |
| 6 | | |
| 7 | 8 | #include "emu.h" |
| 8 | 9 | #include "cpu/avr8/avr8.h" |
| 10 | #include "machine/avr8.h" |
| 9 | 11 | #include "sound/dac.h" |
| 10 | 12 | |
| 13 | #define VERBOSE_LEVEL (0) |
| 14 | |
| 15 | #define ENABLE_VERBOSE_LOG (0) |
| 16 | |
| 17 | #if ENABLE_VERBOSE_LOG |
| 18 | INLINE void verboselog(running_machine *machine, int n_level, const char *s_fmt, ...) |
| 19 | { |
| 20 | if( VERBOSE_LEVEL >= n_level ) |
| 21 | { |
| 22 | va_list v; |
| 23 | char buf[ 32768 ]; |
| 24 | va_start( v, s_fmt ); |
| 25 | vsprintf( buf, s_fmt, v ); |
| 26 | va_end( v ); |
| 27 | logerror( "%08x: %s", cpu_get_pc(devtag_get_device(machine, "maincpu")), buf ); |
| 28 | } |
| 29 | } |
| 30 | #else |
| 31 | #define verboselog(x,y,z,...) |
| 32 | #endif |
| 33 | |
| 11 | 34 | #define MASTER_CLOCK 20000000 |
| 12 | 35 | |
| 13 | 36 | /****************************************************\ |
| 14 | 37 | * I/O devices * |
| 15 | 38 | \****************************************************/ |
| 16 | 39 | |
| 17 | | typedef struct |
| 18 | | { |
| 19 | | UINT8 r[0x20]; |
| 20 | | |
| 21 | | UINT8 res0[3]; |
| 22 | | |
| 23 | | UINT8 pinb; |
| 24 | | UINT8 ddrb; |
| 25 | | UINT8 portb; |
| 26 | | UINT8 pinc; |
| 27 | | UINT8 ddrc; |
| 28 | | UINT8 portc; |
| 29 | | UINT8 pind; |
| 30 | | UINT8 ddrd; |
| 31 | | UINT8 portd; |
| 32 | | |
| 33 | | UINT8 res1[9]; |
| 34 | | |
| 35 | | UINT8 tifr0; |
| 36 | | UINT8 tifr1; |
| 37 | | UINT8 tifr2; |
| 38 | | |
| 39 | | UINT8 res2[3]; |
| 40 | | |
| 41 | | UINT8 pcifr; |
| 42 | | UINT8 eifr; |
| 43 | | UINT8 eimsk; |
| 44 | | UINT8 gpior0; |
| 45 | | UINT8 eecr; |
| 46 | | UINT8 eedr; |
| 47 | | UINT8 eearl; |
| 48 | | UINT8 eearh; |
| 49 | | UINT8 gtccr; |
| 50 | | UINT8 tccr0a; |
| 51 | | UINT8 tccr0b; |
| 52 | | UINT8 tcnt0; |
| 53 | | UINT8 ocr0a; |
| 54 | | UINT8 ocr0b; |
| 55 | | |
| 56 | | UINT8 res3; |
| 57 | | |
| 58 | | UINT8 gpior1; |
| 59 | | UINT8 gpior2; |
| 60 | | UINT8 spcr; |
| 61 | | UINT8 spsr; |
| 62 | | UINT8 spdr; |
| 63 | | |
| 64 | | UINT8 res4; |
| 65 | | |
| 66 | | UINT8 acsr; |
| 67 | | |
| 68 | | UINT8 res5[2]; |
| 69 | | |
| 70 | | UINT8 smcr; |
| 71 | | UINT8 mcusr; |
| 72 | | UINT8 mcucr; |
| 73 | | |
| 74 | | UINT8 res6; |
| 75 | | |
| 76 | | UINT8 spmcsr; |
| 77 | | |
| 78 | | UINT8 res7[5]; |
| 79 | | |
| 80 | | UINT16 sp; |
| 81 | | UINT8 sreg; |
| 82 | | |
| 83 | | UINT8 wdtcsr; |
| 84 | | UINT8 clkpr; |
| 85 | | |
| 86 | | UINT8 res8[2]; |
| 87 | | |
| 88 | | UINT8 prr; |
| 89 | | |
| 90 | | UINT8 res9; |
| 91 | | |
| 92 | | UINT8 osccal; |
| 93 | | |
| 94 | | UINT8 res10; |
| 95 | | |
| 96 | | UINT8 pcicr; |
| 97 | | UINT8 eicra; |
| 98 | | |
| 99 | | UINT8 res11; |
| 100 | | |
| 101 | | UINT8 pcmsk0; |
| 102 | | UINT8 pcmsk1; |
| 103 | | UINT8 pcmsk2; |
| 104 | | UINT8 timsk0; |
| 105 | | UINT8 timsk1; |
| 106 | | UINT8 timsk2; |
| 107 | | |
| 108 | | UINT8 res12[7]; |
| 109 | | |
| 110 | | UINT8 adcl; |
| 111 | | UINT8 adch; |
| 112 | | UINT8 adcsra; |
| 113 | | UINT8 adcsrb; |
| 114 | | UINT8 admux; |
| 115 | | |
| 116 | | UINT8 res13; |
| 117 | | |
| 118 | | UINT8 didr0; |
| 119 | | UINT8 didr1; |
| 120 | | UINT8 tccr1a; |
| 121 | | UINT8 tccr1b; |
| 122 | | UINT8 tccr1c; |
| 123 | | |
| 124 | | UINT8 res14; |
| 125 | | |
| 126 | | UINT16 tcnt1; |
| 127 | | UINT16 icr1; |
| 128 | | UINT16 ocr1a; |
| 129 | | UINT16 ocr1b; |
| 130 | | |
| 131 | | UINT8 res15[36]; |
| 132 | | |
| 133 | | UINT8 tccr2a; |
| 134 | | UINT8 tccr2b; |
| 135 | | UINT8 tcnt2; |
| 136 | | UINT8 ocr2a; |
| 137 | | UINT8 ocr2b; |
| 138 | | |
| 139 | | UINT8 res16; |
| 140 | | |
| 141 | | UINT8 assr; |
| 142 | | |
| 143 | | UINT8 res17; |
| 144 | | |
| 145 | | UINT8 twbr; |
| 146 | | UINT8 twsr; |
| 147 | | UINT8 twar; |
| 148 | | UINT8 twdr; |
| 149 | | UINT8 twcr; |
| 150 | | UINT8 twamr; |
| 151 | | |
| 152 | | UINT8 res18[2]; |
| 153 | | |
| 154 | | UINT8 ucsr0a; |
| 155 | | UINT8 ucsr0b; |
| 156 | | UINT8 ucsr0c; |
| 157 | | |
| 158 | | UINT8 res19; |
| 159 | | |
| 160 | | UINT8 ubrr0l; |
| 161 | | UINT8 ubrr0h; |
| 162 | | UINT8 udr0; |
| 163 | | |
| 164 | | UINT8 res20[57]; |
| 165 | | |
| 166 | | UINT8 hidden_high; |
| 167 | | |
| 168 | | INT64 last_tcnt1_cycle; |
| 169 | | |
| 170 | | emu_timer *ocr1a_timer; |
| 171 | | emu_timer *ocr1b_timer; |
| 172 | | } avr8_regs; |
| 173 | | |
| 174 | | |
| 175 | 40 | class craft_state |
| 176 | 41 | { |
| 177 | 42 | public: |
| r7548 | r7549 | |
| 179 | 44 | |
| 180 | 45 | craft_state(running_machine &machine) { } |
| 181 | 46 | |
| 182 | | avr8_regs regs; |
| 183 | | int blah; |
| 47 | UINT8 regs[0x100]; |
| 48 | INT32 tcnt1_direction; |
| 49 | |
| 50 | emu_timer* ocr1a_timer; |
| 51 | emu_timer* ocr1b_timer; |
| 184 | 52 | }; |
| 185 | 53 | |
| 186 | | #define AVR8_TIMSK1_OCIE1A 0x02 |
| 187 | | #define AVR8_TIMSK1_OCIE1B 0x04 |
| 188 | | |
| 189 | | static UINT64 avr8_get_timer_1_frequency(avr8_regs *device) |
| 54 | #if 0 |
| 55 | static UINT64 avr8_get_timer_1_frequency(craft_state *state) |
| 190 | 56 | { |
| 191 | 57 | UINT64 frequency = 0; |
| 192 | | switch(device->tccr1b & 0x07) |
| 58 | switch(AVR8_TCCR1B & 0x07) |
| 193 | 59 | { |
| 194 | 60 | case 0: // No clock source (Timer/Counter stopped). |
| 195 | 61 | case 6: // External clock source on T1 pin. Clock on falling edge. |
| r7548 | r7549 | |
| 218 | 84 | break; |
| 219 | 85 | |
| 220 | 86 | default: |
| 221 | | frequency = 0; |
| 222 | | printf( "device->tccr1b & 0x07 returned a value not in the range of 0 to 7. This is\n" ); |
| 223 | | printf( "impossible. Please ensure that your walls are not bleeding and your bathroom\n" ); |
| 224 | | printf( "has not turned into a psychokinetic vortex.\n" ); |
| 87 | frequency = 0; |
| 88 | fatalerror( "&state->tccr1b & 0x07 returned a value not in the range of 0 to 7.\n" ); |
| 225 | 89 | break; |
| 226 | 90 | } |
| 227 | 91 | |
| 228 | 92 | return frequency; |
| 229 | 93 | } |
| 230 | 94 | |
| 231 | | static void avr8_maybe_start_timer_1(avr8_regs *device) |
| 95 | static UINT16 avr8_get_tc1_top(craft_state *state) |
| 232 | 96 | { |
| 233 | | UINT64 frequency = avr8_get_timer_1_frequency(device); |
| 97 | switch(AVR8_WGM1) |
| 98 | { |
| 99 | case AVR8_WGM1_NORMAL: |
| 100 | return 0xffff; |
| 101 | |
| 102 | case AVR8_WGM1_PWM_8_PC: |
| 103 | case AVR8_WGM1_FAST_PWM_8: |
| 104 | return 0x00ff; |
| 105 | |
| 106 | case AVR8_WGM1_PWM_9_PC: |
| 107 | case AVR8_WGM1_FAST_PWM_9: |
| 108 | return 0x01ff; |
| 109 | |
| 110 | case AVR8_WGM1_PWM_10_PC: |
| 111 | case AVR8_WGM1_FAST_PWM_10: |
| 112 | return 0x03ff; |
| 113 | |
| 114 | case AVR8_WGM1_CTC_ICR: |
| 115 | case AVR8_WGM1_PWM_PFC_ICR: |
| 116 | case AVR8_WGM1_PWM_PC_ICR: |
| 117 | case AVR8_WGM1_FAST_PWM_ICR: |
| 118 | return AVR8_ICR1; |
| 119 | |
| 120 | case AVR8_WGM1_CTC_OCR: |
| 121 | case AVR8_WGM1_PWM_PFC_OCR: |
| 122 | case AVR8_WGM1_PWM_PC_OCR: |
| 123 | case AVR8_WGM1_FAST_PWM_OCR: |
| 124 | return AVR8_OCR1A; |
| 125 | |
| 126 | case AVR8_WGM1_RESERVED: |
| 127 | logerror("Attempting to retrieve TOP for a reserved waveform generation mode\n"); |
| 128 | return 0xffff; |
| 129 | } |
| 130 | return 0xffff; |
| 131 | } |
| 132 | |
| 133 | enum |
| 134 | { |
| 135 | AVR8_REG_A = 0, |
| 136 | AVR8_REG_B, |
| 137 | }; |
| 138 | |
| 139 | static UINT16 avr8_get_tc1_distance(craft_state *state, INT32 reg) |
| 140 | { |
| 141 | UINT16 top = avr8_get_tc1_top(state); |
| 142 | UINT16 ocr = (reg == AVR8_REG_A) ? AVR8_OCR1A : AVR8_OCR1B; |
| 143 | if(AVR8_TCNT1_DIR > 0) |
| 144 | { |
| 145 | if(AVR8_TCNT1 < ocr) |
| 146 | { |
| 147 | return ocr - AVR8_TCNT1; |
| 148 | } |
| 149 | else |
| 150 | { |
| 151 | return top - AVR8_TCNT1; |
| 152 | } |
| 153 | } |
| 154 | else |
| 155 | { |
| 156 | if(AVR8_TCNT1 > ocr) |
| 157 | { |
| 158 | return AVR8_TCNT1 - ocr; |
| 159 | } |
| 160 | else |
| 161 | { |
| 162 | return ocr; |
| 163 | } |
| 164 | } |
| 165 | return 0xffff; |
| 166 | } |
| 167 | |
| 168 | static void avr8_maybe_start_timer_1(craft_state *state) |
| 169 | { |
| 170 | UINT64 frequency = avr8_get_timer_1_frequency(state); |
| 234 | 171 | if(frequency == 0) |
| 235 | 172 | { |
| 236 | | timer_adjust_oneshot(device->ocr1a_timer, attotime_never, 0); |
| 237 | | timer_adjust_oneshot(device->ocr1b_timer, attotime_never, 0); |
| 173 | timer_adjust_oneshot(state->ocr1a_timer, attotime_never, 0); |
| 174 | timer_adjust_oneshot(state->ocr1b_timer, attotime_never, 0); |
| 238 | 175 | } |
| 239 | 176 | else |
| 240 | 177 | { |
| 241 | | UINT16 wrap_count_a = (UINT16)(((UINT32)device->ocr1a - (UINT32)device->tcnt1) & 0x0000ffff); |
| 242 | | UINT16 wrap_count_b = (UINT16)(((UINT32)device->ocr1b - (UINT32)device->tcnt1) & 0x0000ffff); |
| 243 | | attotime period_a = attotime_mul(ATTOTIME_IN_HZ(frequency), wrap_count_a); |
| 244 | | attotime period_b = attotime_mul(ATTOTIME_IN_HZ(frequency), wrap_count_b); |
| 245 | | if(device->timsk1 & AVR8_TIMSK1_OCIE1A) |
| 246 | | { |
| 247 | | timer_adjust_oneshot(device->ocr1a_timer, period_a, 0); |
| 248 | | } |
| 249 | | if(device->timsk1 & AVR8_TIMSK1_OCIE1B) |
| 250 | | { |
| 251 | | timer_adjust_oneshot(device->ocr1b_timer, period_b, 0); |
| 252 | | } |
| 178 | attotime period_a = attotime_mul(ATTOTIME_IN_HZ(frequency), avr8_get_tc1_distance(state, AVR8_REG_A)); |
| 179 | attotime period_b = attotime_mul(ATTOTIME_IN_HZ(frequency), avr8_get_tc1_distance(state, AVR8_REG_B)); |
| 180 | timer_adjust_oneshot(state->ocr1a_timer, period_a, 0); |
| 181 | timer_adjust_oneshot(state->ocr1b_timer, period_b, 0); |
| 253 | 182 | } |
| 254 | 183 | } |
| 184 | #endif |
| 255 | 185 | |
| 256 | 186 | static TIMER_CALLBACK( ocr1a_timer_compare ) |
| 257 | 187 | { |
| 258 | | craft_state *state = (craft_state *)machine->driver_data; |
| 259 | | avr8_regs *regs = &state->regs; |
| 188 | //craft_state *state = (craft_state *)machine->driver_data; |
| 189 | //avr8_regs *regs = &state->regs; |
| 260 | 190 | |
| 261 | | printf( "ocr1a_timer_compare %d\n", state->blah++ ); |
| 262 | | avr8_maybe_start_timer_1(regs); |
| 191 | // TODO |
| 263 | 192 | |
| 264 | | // Inaccurate |
| 265 | | cpu_set_input_line(devtag_get_device(machine, "maincpu"), AVR8_INT_T1COMPA, ASSERT_LINE); |
| 193 | //avr8_maybe_start_timer_1(regs); |
| 194 | //cpu_set_input_line(devtag_get_device(machine, "maincpu"), AVR8_INT_T1COMPA, ASSERT_LINE); |
| 266 | 195 | } |
| 267 | 196 | |
| 268 | 197 | static TIMER_CALLBACK( ocr1b_timer_compare ) |
| 269 | 198 | { |
| 270 | | craft_state *state = (craft_state *)machine->driver_data; |
| 271 | | avr8_regs *regs = &state->regs; |
| 199 | //craft_state *state = (craft_state *)machine->driver_data; |
| 200 | //avr8_regs *regs = &state->regs; |
| 272 | 201 | |
| 273 | | printf( "ocr1b_timer_compare\n" ); |
| 274 | | avr8_maybe_start_timer_1(regs); |
| 202 | // TODO |
| 275 | 203 | |
| 276 | | // Inaccurate |
| 277 | | cpu_set_input_line(devtag_get_device(machine, "maincpu"), AVR8_INT_T1COMPB, ASSERT_LINE); |
| 204 | //avr8_maybe_start_timer_1(regs); |
| 205 | //cpu_set_input_line(devtag_get_device(machine, "maincpu"), AVR8_INT_T1COMPB, ASSERT_LINE); |
| 278 | 206 | } |
| 279 | 207 | |
| 280 | 208 | static READ8_HANDLER( avr8_read ) |
| 281 | 209 | { |
| 282 | 210 | craft_state *state = (craft_state *)space->machine->driver_data; |
| 283 | | avr8_regs *regs = &state->regs; |
| 284 | 211 | |
| 212 | if(offset <= AVR8_REG_R31) |
| 213 | { |
| 214 | return state->regs[offset]; |
| 215 | } |
| 216 | |
| 285 | 217 | switch( offset ) |
| 286 | 218 | { |
| 287 | | case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: |
| 288 | | case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 289 | | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: |
| 290 | | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 291 | | return regs->r[offset]; |
| 292 | | case 0x24: |
| 293 | | printf( "AVR8: R: regs->ddrb (%02x)\n", regs->ddrb ); |
| 294 | | return regs->ddrb; |
| 295 | | case 0x25: |
| 296 | | printf( "AVR8: R: regs->portb (%02x)\n", regs->portb ); |
| 297 | | return regs->portb; |
| 298 | | case 0x27: |
| 299 | | printf( "AVR8: R: regs->ddrc (%02x)\n", regs->ddrc ); |
| 300 | | return regs->ddrc; |
| 301 | | case 0x2a: |
| 302 | | printf( "AVR8: R: regs->ddrd (%02x)\n", regs->ddrd ); |
| 303 | | return regs->ddrd; |
| 304 | | case 0x4c: |
| 305 | | printf( "AVR8: R: regs->spcr (%02x)\n", regs->spcr ); |
| 306 | | return regs->spcr; |
| 307 | | case 0x4d: |
| 308 | | printf( "AVR8: R: regs->spsr (%02x)\n", regs->spsr ); |
| 309 | | return regs->spsr; |
| 310 | | case 0x5d: |
| 311 | | //printf( "AVR8: R: regs->spl (%02x)\n", regs->spl ); |
| 312 | | return regs->sp & 0x00ff; |
| 313 | | case 0x5e: |
| 314 | | //printf( "AVR8: R: regs->sph (%02x)\n", regs->sph ); |
| 315 | | return (regs->sp >> 8) & 0x00ff; |
| 316 | | case 0x5f: |
| 317 | | return regs->sreg; |
| 318 | | case 0x6f: |
| 319 | | printf( "AVR8: R: regs->timsk1 (%02x)\n", regs->timsk1 ); |
| 320 | | return regs->timsk1; |
| 321 | | case 0x80: |
| 322 | | printf( "AVR8: R: regs->tccr1a (%02x)\n", regs->tccr1a ); |
| 323 | | return regs->tccr1a; |
| 324 | | case 0x81: |
| 325 | | printf( "AVR8: R: regs->tccr1b (%02x)\n", regs->tccr1b ); |
| 326 | | return regs->tccr1b; |
| 327 | | case 0x84: |
| 328 | | { |
| 329 | | //INT64 divisor = 1; |
| 330 | | #if 0 |
| 331 | | INT64 update = (INT64)(cpu_get_total_cycles(space->cpu)) - last_tcnt1_cycle; |
| 332 | | switch(device->tccr1b & 0x07) |
| 333 | | { |
| 334 | | case 0: // No clock source (Timer/Counter stopped). |
| 335 | | case 1: // clk / 1 (No prescaling) |
| 336 | | case 6: // External clock source on T1 pin. Clock on falling edge. |
| 337 | | case 7: // External clock source on T1 pin. Clock on rising edge. |
| 338 | | divisor = 1; |
| 339 | | break; |
| 340 | | |
| 341 | | case 2: // clk / 8 (From prescaler) |
| 342 | | divisor = 8; |
| 343 | | break; |
| 344 | | |
| 345 | | case 3: // clk / 64 (From prescaler) |
| 346 | | divisor = 64; |
| 347 | | break; |
| 348 | | |
| 349 | | case 4: // clk / 256 (From prescaler) |
| 350 | | divisor = 256; |
| 351 | | break; |
| 352 | | |
| 353 | | case 5: // clk / 1024 (From prescaler) |
| 354 | | divisor = 1024; |
| 355 | | break; |
| 356 | | |
| 357 | | default: |
| 358 | | divisor = 1; |
| 359 | | printf( "device->tccr1b & 0x07 returned a value not in the range of 0 to 7. This is\n" ); |
| 360 | | printf( "impossible. Please ensure that your walls are not bleeding and your bathroom\n" ); |
| 361 | | printf( "has not turned into a psychokinetic vortex.\n" ); |
| 362 | | break; |
| 363 | | } |
| 364 | | diff /= divisor; |
| 365 | | diff %= regs->ocr1a; |
| 366 | | printf( "AVR8: R: regs->tcnt1l read: %04x\n", ); |
| 367 | | #endif |
| 368 | | break; |
| 369 | | } |
| 370 | | |
| 371 | | case 0x85: |
| 372 | | printf( "AVR8: R: regs->tcnt1h\n" ); |
| 373 | | break; |
| 374 | | case 0x88: |
| 375 | | printf( "AVR8: R: regs->ocr1al (%02x)\n", regs->ocr1a & 0x00ff ); |
| 376 | | return regs->ocr1a & 0x00ff; |
| 377 | | case 0x89: |
| 378 | | printf( "AVR8: R: regs->ocr1ah (%02x)\n", (regs->ocr1a >> 8) & 0x00ff ); |
| 379 | | return (regs->ocr1a >> 8) & 0x00ff; |
| 380 | | case 0x8a: |
| 381 | | printf( "AVR8: R: regs->ocr1bl (%02x)\n", regs->ocr1b & 0x00ff ); |
| 382 | | return regs->ocr1b & 0x00ff; |
| 383 | | case 0x8b: |
| 384 | | printf( "AVR8: R: regs->ocr1bh (%02x)\n", (regs->ocr1b >> 8) & 0x00ff ); |
| 385 | | return (regs->ocr1b >> 8) & 0x00ff; |
| 386 | | case 0xb0: |
| 387 | | printf( "AVR8: R: regs->tccr2a (%02x)\n", regs->tccr2a ); |
| 388 | | return regs->tccr2a; |
| 389 | | case 0xb1: |
| 390 | | printf( "AVR8: R: regs->tccr2b (%02x)\n", regs->tccr2b ); |
| 391 | | return regs->tccr2b; |
| 392 | 219 | default: |
| 393 | | printf( "AVR8: Unrecognized register read: %02x\n", offset ); |
| 220 | verboselog(space->machine, 0, "AVR8: Unrecognized register read: %02x\n", offset ); |
| 394 | 221 | } |
| 222 | |
| 395 | 223 | return 0; |
| 396 | 224 | } |
| 397 | 225 | |
| 398 | 226 | static WRITE8_HANDLER( avr8_write ) |
| 399 | 227 | { |
| 400 | 228 | craft_state *state = (craft_state *)space->machine->driver_data; |
| 401 | | avr8_regs *regs = &state->regs; |
| 402 | 229 | |
| 230 | if(offset <= AVR8_REG_R31) |
| 231 | { |
| 232 | state->regs[offset] = data; |
| 233 | } |
| 234 | |
| 403 | 235 | switch( offset ) |
| 404 | 236 | { |
| 405 | | case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07: |
| 406 | | case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f: |
| 407 | | case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17: |
| 408 | | case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f: |
| 409 | | regs->r[offset] = data; |
| 410 | | break; |
| 411 | | case 0x24: |
| 412 | | printf( "AVR8: W: regs->ddrb = %02x\n", data ); |
| 413 | | regs->ddrb = data; |
| 414 | | break; |
| 415 | | case 0x25: |
| 416 | | printf( "AVR8: W: regs->portb = %02x\n", data ); |
| 417 | | regs->portb = data; |
| 418 | | break; |
| 419 | | case 0x27: |
| 420 | | printf( "AVR8: W: regs->ddrc = %02x\n", data ); |
| 421 | | regs->ddrc = data; |
| 422 | | break; |
| 423 | | case 0x2a: |
| 424 | | printf( "AVR8: W: regs->ddrd = %02x\n", data ); |
| 425 | | regs->ddrd = data; |
| 426 | | break; |
| 427 | | case 0x2b: |
| 428 | | dac_data_w(devtag_get_device(space->machine, "dac"), data); |
| 429 | | break; |
| 430 | | case 0x4c: |
| 431 | | printf( "AVR8: W: regs->spcr = %02x\n", data ); |
| 432 | | regs->spcr = data; |
| 433 | | break; |
| 434 | | case 0x4d: |
| 435 | | printf( "AVR8: W: regs->spsr = %02x\n", data ); |
| 436 | | regs->spsr = data; |
| 437 | | break; |
| 438 | | case 0x5d: |
| 439 | | //printf( "AVR8: W: regs->sp(L) = %02x\n", data ); |
| 440 | | regs->sp = (regs->hidden_high << 8) | data; |
| 441 | | break; |
| 442 | | case 0x5e: |
| 443 | | //printf( "AVR8: W: regs->sp(H) = %02x\n", data ); |
| 444 | | regs->hidden_high = data & 0x07; |
| 445 | | break; |
| 446 | | case 0x5f: |
| 447 | | regs->sreg = data; |
| 448 | | break; |
| 449 | | case 0x6f: |
| 450 | | printf( "AVR8: W: regs->timsk1 = %02x\n", data ); |
| 451 | | regs->timsk1 = data; |
| 452 | | avr8_maybe_start_timer_1(regs); |
| 453 | | break; |
| 454 | | case 0x80: |
| 455 | | printf( "AVR8: W: regs->tccr1a = %02x\n", data ); |
| 456 | | regs->tccr1a = data; |
| 457 | | break; |
| 458 | | case 0x81: |
| 459 | | printf( "AVR8: W: regs->tccr1b = %02x\n", data ); |
| 460 | | regs->tccr1b = data; |
| 461 | | break; |
| 462 | | case 0x88: |
| 463 | | printf( "AVR8: W: regs->ocr1a(L) = %02x\n", data ); |
| 464 | | regs->ocr1a = (regs->hidden_high << 8) | data; |
| 465 | | avr8_maybe_start_timer_1(regs); |
| 466 | | break; |
| 467 | | case 0x89: |
| 468 | | printf( "AVR8: W: regs->ocr1a(H) = %02x\n", data ); |
| 469 | | regs->hidden_high = data; |
| 470 | | break; |
| 471 | | case 0x8a: |
| 472 | | printf( "AVR8: W: regs->ocr1b(L) = %02x\n", data ); |
| 473 | | regs->ocr1b = (regs->hidden_high << 8) | data; |
| 474 | | avr8_maybe_start_timer_1(regs); |
| 475 | | break; |
| 476 | | case 0x8b: |
| 477 | | printf( "AVR8: W: regs->ocr1b(H) = %02x\n", data ); |
| 478 | | regs->hidden_high = data; |
| 479 | | break; |
| 480 | | case 0xb0: |
| 481 | | printf( "AVR8: W: regs->tccr2a = %02x\n", data ); |
| 482 | | regs->tccr2a = data; |
| 483 | | break; |
| 484 | | case 0xb1: |
| 485 | | printf( "AVR8: W: regs->tccr2b = %02x\n", data ); |
| 486 | | regs->tccr2b = data; |
| 487 | | break; |
| 488 | 237 | default: |
| 489 | | printf( "AVR8: Unrecognized register write: %02x = %02x\n", offset, data ); |
| 238 | verboselog(space->machine, 0, "AVR8: Unrecognized register write: %02x = %02x\n", offset, data ); |
| 490 | 239 | } |
| 491 | 240 | } |
| 492 | 241 | |
| r7548 | r7549 | |
| 528 | 277 | static DRIVER_INIT( craft ) |
| 529 | 278 | { |
| 530 | 279 | craft_state *state = (craft_state *)machine->driver_data; |
| 531 | | avr8_regs *regs = &state->regs; |
| 532 | 280 | |
| 533 | | regs->ocr1a_timer = timer_alloc(machine, ocr1a_timer_compare, 0); |
| 534 | | regs->ocr1b_timer = timer_alloc(machine, ocr1b_timer_compare, 0); |
| 281 | state->ocr1a_timer = timer_alloc(machine, ocr1a_timer_compare, 0); |
| 282 | state->ocr1b_timer = timer_alloc(machine, ocr1b_timer_compare, 0); |
| 535 | 283 | } |
| 536 | 284 | |
| 537 | 285 | static MACHINE_RESET( craft ) |
| 538 | 286 | { |
| 539 | 287 | craft_state *state = (craft_state *)machine->driver_data; |
| 540 | | avr8_regs *regs = &state->regs; |
| 541 | 288 | |
| 542 | | regs->timsk1 = 0; |
| 543 | | regs->tcnt1 = 0; |
| 544 | | regs->ocr1a = 0; |
| 545 | | regs->ocr1b = 0; |
| 546 | | regs->icr1 = 0; |
| 547 | | regs->last_tcnt1_cycle = 0; |
| 289 | AVR8_TIMSK1 = 0; |
| 290 | AVR8_OCR1AH = 0; |
| 291 | AVR8_OCR1AL = 0; |
| 292 | AVR8_OCR1BH = 0; |
| 293 | AVR8_OCR1BL = 0; |
| 294 | AVR8_ICR1H = 0; |
| 295 | AVR8_ICR1L = 0; |
| 296 | AVR8_TCNT1H = 0; |
| 297 | AVR8_TCNT1L = 0; |
| 548 | 298 | |
| 549 | 299 | dac_data_w(devtag_get_device(machine, "dac"), 0x00); |
| 550 | 300 | } |
| r7548 | r7549 | |
| 587 | 337 | ROM_END |
| 588 | 338 | |
| 589 | 339 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME */ |
| 590 | | CONS(2008, craft, 0, 0, craft, craft, craft, "Linus Akesson", "Craft", GAME_NO_SOUND | GAME_NOT_WORKING) |
| 340 | CONS(2008, craft, 0, 0, craft, craft, craft, "Linus Akesson", "Craft", GAME_NO_SOUND | GAME_NOT_WORKING) |
| | No newline at end of file |