src/mess/video/nes.c
| r7953 | r7954 | |
| 11 | 11 | #include "includes/nes.h" |
| 12 | 12 | #include "machine/nes_mmc.h" |
| 13 | 13 | |
| 14 | | int nes_vram_sprite[8]; /* Used only by mmc5 for now */ |
| 15 | | static int last_frame_flip = 0; |
| 16 | | static double nes_scanlines_per_frame; |
| 17 | | |
| 18 | 14 | static void nes_vh_reset( running_machine *machine ) |
| 19 | 15 | { |
| 20 | 16 | nes_state *state = (nes_state *)machine->driver_data; |
| 21 | 17 | ppu2c0x_set_vidaccess_callback(devtag_get_device(machine,"ppu"), nes_ppu_vidaccess); |
| 22 | | ppu2c0x_set_scanlines_per_frame(devtag_get_device(machine,"ppu"), ceil(nes_scanlines_per_frame)); |
| 18 | ppu2c0x_set_scanlines_per_frame(devtag_get_device(machine,"ppu"), ceil(state->scanlines_per_frame)); |
| 23 | 19 | |
| 24 | 20 | if (state->four_screen_vram) |
| 25 | 21 | set_nt_mirroring(machine, PPU_MIRROR_4SCREEN); |
| r7953 | r7954 | |
| 42 | 38 | |
| 43 | 39 | static void nes_vh_start(running_machine *machine, double scanlines_per_frame) |
| 44 | 40 | { |
| 45 | | last_frame_flip = 0; |
| 46 | | nes_scanlines_per_frame = scanlines_per_frame; |
| 41 | nes_state *state = (nes_state *)machine->driver_data; |
| 47 | 42 | |
| 43 | state->last_frame_flip = 0; |
| 44 | state->scanlines_per_frame = scanlines_per_frame; |
| 45 | |
| 48 | 46 | add_reset_callback(machine, nes_vh_reset); |
| 49 | 47 | } |
| 50 | 48 | |
| 51 | | |
| 52 | | |
| 53 | 49 | VIDEO_START( nes_ntsc ) |
| 54 | 50 | { |
| 55 | 51 | nes_vh_start(machine, PPU_NTSC_SCANLINES_PER_FRAME); |
| r7953 | r7954 | |
| 83 | 79 | if (state->mapper == 20) |
| 84 | 80 | { |
| 85 | 81 | // latch this input so it doesn't go at warp speed |
| 86 | | if ((input_port_read(screen->machine, "FLIPDISK") & 0x01) && (!last_frame_flip)) |
| 82 | if ((input_port_read(screen->machine, "FLIPDISK") & 0x01) && (!state->last_frame_flip)) |
| 87 | 83 | { |
| 88 | | last_frame_flip = 1; |
| 84 | state->last_frame_flip = 1; |
| 89 | 85 | state->fds_current_side++; |
| 90 | 86 | if (state->fds_current_side > state->fds_sides) |
| 91 | 87 | state->fds_current_side = 0; |
| r7953 | r7954 | |
| 97 | 93 | } |
| 98 | 94 | |
| 99 | 95 | if (!(input_port_read(screen->machine, "FLIPDISK") & 0x01)) |
| 100 | | last_frame_flip = 0; |
| 96 | state->last_frame_flip = 0; |
| 101 | 97 | } |
| 102 | 98 | return 0; |
| 103 | 99 | } |
src/mess/machine/nes.c
| r7953 | r7954 | |
| 23 | 23 | #define SPLIT_PRG 0 |
| 24 | 24 | #define SPLIT_CHR 0 |
| 25 | 25 | |
| 26 | | #define BATTERY_SIZE 0x2000 |
| 27 | | |
| 28 | 26 | /*************************************************************************** |
| 29 | | TYPE DEFINITIONS |
| 30 | | ***************************************************************************/ |
| 31 | | |
| 32 | | typedef struct _nes_input nes_input; |
| 33 | | struct _nes_input |
| 34 | | { |
| 35 | | UINT32 shift; |
| 36 | | UINT32 i0, i1, i2; |
| 37 | | }; |
| 38 | | |
| 39 | | /*************************************************************************** |
| 40 | | GLOBAL VARIABLES |
| 41 | | ***************************************************************************/ |
| 42 | | |
| 43 | | unsigned char *nes_battery_ram; |
| 44 | | static UINT8 battery_data[BATTERY_SIZE]; |
| 45 | | |
| 46 | | static nes_input in_0; |
| 47 | | static nes_input in_1; |
| 48 | | |
| 49 | | /*************************************************************************** |
| 50 | 27 | FUNCTION PROTOTYPES |
| 51 | 28 | ***************************************************************************/ |
| 52 | 29 | |
| r7953 | r7954 | |
| 77 | 54 | |
| 78 | 55 | memory_set_bankptr(machine, "bank10", state->rom); |
| 79 | 56 | |
| 80 | | nes_battery_ram = state->wram; |
| 57 | state->battery_ram = state->wram; |
| 81 | 58 | |
| 82 | 59 | /* Set up the memory handlers for the mapper */ |
| 83 | 60 | switch (state->mapper) |
| r7953 | r7954 | |
| 174 | 151 | /* memory subsystem is set up. When this routine is called */ |
| 175 | 152 | /* everything is ready, so we can just copy over the data */ |
| 176 | 153 | /* we loaded before. */ |
| 177 | | memcpy(nes_battery_ram, battery_data, BATTERY_SIZE); |
| 154 | memcpy(state->battery_ram, state->battery_data, NES_BATTERY_SIZE); |
| 178 | 155 | } |
| 179 | 156 | |
| 180 | 157 | int nes_ppu_vidaccess( running_device *device, int address, int data ) |
| r7953 | r7954 | |
| 211 | 188 | nes_unif_reset(machine, state->board); |
| 212 | 189 | |
| 213 | 190 | /* Reset the serial input ports */ |
| 214 | | in_0.shift = 0; |
| 215 | | in_1.shift = 0; |
| 191 | state->in_0.shift = 0; |
| 192 | state->in_1.shift = 0; |
| 216 | 193 | |
| 217 | 194 | devtag_get_device(machine, "maincpu")->reset(); |
| 218 | 195 | } |
| r7953 | r7954 | |
| 239 | 216 | |
| 240 | 217 | /* Write out the battery file if necessary */ |
| 241 | 218 | if (state->battery) |
| 242 | | image_battery_save(state->cart, nes_battery_ram, BATTERY_SIZE); |
| 219 | image_battery_save(state->cart, state->battery_ram, NES_BATTERY_SIZE); |
| 243 | 220 | } |
| 244 | 221 | |
| 245 | 222 | |
| r7953 | r7954 | |
| 253 | 230 | /* in the unused upper 3 bits, so typically a read from $4016 leaves 0x40 there. */ |
| 254 | 231 | ret = 0x40; |
| 255 | 232 | |
| 256 | | ret |= ((in_0.i0 >> in_0.shift) & 0x01); |
| 233 | ret |= ((state->in_0.i0 >> state->in_0.shift) & 0x01); |
| 257 | 234 | |
| 258 | 235 | /* zapper */ |
| 259 | 236 | if ((input_port_read(space->machine, "CTRLSEL") & 0x000f) == 0x0002) |
| 260 | 237 | { |
| 261 | | int x = in_0.i1; /* read Zapper x-position */ |
| 262 | | int y = in_0.i2; /* read Zapper y-position */ |
| 238 | int x = state->in_0.i1; /* read Zapper x-position */ |
| 239 | int y = state->in_0.i2; /* read Zapper y-position */ |
| 263 | 240 | UINT32 pix, color_base; |
| 264 | 241 | |
| 265 | 242 | /* get the pixel at the gun position */ |
| r7953 | r7954 | |
| 278 | 255 | ret |= 0x08; /* no sprite hit */ |
| 279 | 256 | |
| 280 | 257 | /* If button 1 is pressed, indicate the light gun trigger is pressed */ |
| 281 | | ret |= ((in_0.i0 & 0x01) << 4); |
| 258 | ret |= ((state->in_0.i0 & 0x01) << 4); |
| 282 | 259 | } |
| 283 | 260 | |
| 284 | 261 | if (LOG_JOY) |
| 285 | | logerror("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), in_0.shift, in_0.i0); |
| 262 | logerror("joy 0 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), state->in_0.shift, state->in_0.i0); |
| 286 | 263 | |
| 287 | | in_0.shift++; |
| 264 | state->in_0.shift++; |
| 288 | 265 | return ret; |
| 289 | 266 | } |
| 290 | 267 | |
| r7953 | r7954 | |
| 298 | 275 | ret = 0x40; |
| 299 | 276 | |
| 300 | 277 | /* Handle data line 0's serial output */ |
| 301 | | ret |= ((in_1.i0 >> in_1.shift) & 0x01); |
| 278 | ret |= ((state->in_1.i0 >> state->in_1.shift) & 0x01); |
| 302 | 279 | |
| 303 | 280 | /* zapper */ |
| 304 | 281 | if ((input_port_read(space->machine, "CTRLSEL") & 0x00f0) == 0x0030) |
| 305 | 282 | { |
| 306 | | int x = in_1.i1; /* read Zapper x-position */ |
| 307 | | int y = in_1.i2; /* read Zapper y-position */ |
| 283 | int x = state->in_1.i1; /* read Zapper x-position */ |
| 284 | int y = state->in_1.i2; /* read Zapper y-position */ |
| 308 | 285 | UINT32 pix, color_base; |
| 309 | 286 | |
| 310 | 287 | /* get the pixel at the gun position */ |
| r7953 | r7954 | |
| 323 | 300 | ret |= 0x08; /* no sprite hit */ |
| 324 | 301 | |
| 325 | 302 | /* If button 1 is pressed, indicate the light gun trigger is pressed */ |
| 326 | | ret |= ((in_1.i0 & 0x01) << 4); |
| 303 | ret |= ((state->in_1.i0 & 0x01) << 4); |
| 327 | 304 | } |
| 328 | 305 | |
| 329 | 306 | /* arkanoid dial */ |
| 330 | 307 | else if ((input_port_read(space->machine, "CTRLSEL") & 0x00f0) == 0x0040) |
| 331 | 308 | { |
| 332 | 309 | /* Handle data line 2's serial output */ |
| 333 | | ret |= ((in_1.i2 >> in_1.shift) & 0x01) << 3; |
| 310 | ret |= ((state->in_1.i2 >> state->in_1.shift) & 0x01) << 3; |
| 334 | 311 | |
| 335 | 312 | /* Handle data line 3's serial output - bits are reversed */ |
| 336 | 313 | /* NPW 27-Nov-2007 - there is no third subscript! commenting out */ |
| 337 | | /* ret |= ((in_1[3] >> in_1.shift) & 0x01) << 4; */ |
| 338 | | /* ret |= ((in_1[3] << in_1.shift) & 0x80) >> 3; */ |
| 314 | /* ret |= ((state->in_1[3] >> state->in_1.shift) & 0x01) << 4; */ |
| 315 | /* ret |= ((state->in_1[3] << state->in_1.shift) & 0x80) >> 3; */ |
| 339 | 316 | } |
| 340 | 317 | |
| 341 | 318 | if (LOG_JOY) |
| 342 | | logerror("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), in_1.shift, in_1.i0); |
| 319 | logerror("joy 1 read, val: %02x, pc: %04x, bits read: %d, chan0: %08x\n", ret, cpu_get_pc(space->cpu), state->in_1.shift, state->in_1.i0); |
| 343 | 320 | |
| 344 | | in_1.shift++; |
| 321 | state->in_1.shift++; |
| 345 | 322 | return ret; |
| 346 | 323 | } |
| 347 | 324 | |
| r7953 | r7954 | |
| 415 | 392 | |
| 416 | 393 | WRITE8_HANDLER( nes_IN0_w ) |
| 417 | 394 | { |
| 395 | nes_state *state = (nes_state *)space->machine->driver_data; |
| 418 | 396 | int cfg; |
| 419 | | nes_input in_2; |
| 420 | | nes_input in_3; |
| 421 | 397 | |
| 422 | 398 | if (data & 0x01) |
| 423 | 399 | return; |
| 424 | 400 | |
| 425 | 401 | if (LOG_JOY) |
| 426 | | logerror("joy 0 bits read: %d\n", in_0.shift); |
| 402 | logerror("joy 0 bits read: %d\n", state->in_0.shift); |
| 427 | 403 | |
| 428 | 404 | /* Toggling bit 0 high then low resets both controllers */ |
| 429 | | in_0.shift = 0; |
| 430 | | in_1.shift = 0; |
| 405 | state->in_0.shift = 0; |
| 406 | state->in_1.shift = 0; |
| 431 | 407 | |
| 432 | 408 | /* Check if lightgun has been chosen as input: if so, enable crosshair */ |
| 433 | 409 | timer_set(space->machine, attotime_zero, NULL, 0, lightgun_tick); |
| r7953 | r7954 | |
| 436 | 412 | cfg = input_port_read(space->machine, "CTRLSEL"); |
| 437 | 413 | |
| 438 | 414 | /* Read the input devices */ |
| 439 | | nes_read_input_device(space->machine, cfg >> 0, &in_0, 0, TRUE, -1); |
| 440 | | nes_read_input_device(space->machine, cfg >> 4, &in_1, 1, TRUE, 1); |
| 441 | | nes_read_input_device(space->machine, cfg >> 8, &in_2, 2, FALSE, -1); |
| 442 | | nes_read_input_device(space->machine, cfg >> 12, &in_3, 3, FALSE, -1); |
| 415 | nes_read_input_device(space->machine, cfg >> 0, &state->in_0, 0, TRUE, -1); |
| 416 | nes_read_input_device(space->machine, cfg >> 4, &state->in_1, 1, TRUE, 1); |
| 417 | nes_read_input_device(space->machine, cfg >> 8, &state->in_2, 2, FALSE, -1); |
| 418 | nes_read_input_device(space->machine, cfg >> 12, &state->in_3, 3, FALSE, -1); |
| 443 | 419 | |
| 444 | 420 | if (cfg & 0x0f00) |
| 445 | | in_0.i0 |= (in_2.i0 << 8) | (0x08 << 16); |
| 421 | state->in_0.i0 |= (state->in_2.i0 << 8) | (0x08 << 16); |
| 446 | 422 | if (cfg & 0xf000) |
| 447 | | in_1.i0 |= (in_3.i0 << 8) | (0x04 << 16); |
| 423 | state->in_1.i0 |= (state->in_3.i0 << 8) | (0x04 << 16); |
| 448 | 424 | } |
| 449 | 425 | |
| 450 | 426 | |
| r7953 | r7954 | |
| 638 | 614 | /* Attempt to load a battery file for this ROM. If successful, we */ |
| 639 | 615 | /* must wait until later to move it to the system memory. */ |
| 640 | 616 | if (state->battery) |
| 641 | | image_battery_load(image, battery_data, BATTERY_SIZE, 0x00); |
| 617 | image_battery_load(image, state->battery_data, NES_BATTERY_SIZE, 0x00); |
| 642 | 618 | |
| 643 | 619 | } |
| 644 | 620 | else if ((magic[0] == 'U') && (magic[1] == 'N') && (magic[2] == 'I') && (magic[3] == 'F')) /* If header starts with 'UNIF' it is UNIF */ |
src/mess/machine/nes_ines.c
| r7953 | r7954 | |
| 507 | 507 | LOG_MMC(("MMC5 mid RAM bank select: %02x\n", data & 0x07)); |
| 508 | 508 | memory_set_bankptr(space->machine, "bank5", &state->wram[data * 0x2000]); |
| 509 | 509 | /* The & 4 is a hack that'll tide us over for now */ |
| 510 | | nes_battery_ram = &state->wram[(data & 4) * 0x2000]; |
| 510 | state->battery_ram = &state->wram[(data & 4) * 0x2000]; |
| 511 | 511 | break; |
| 512 | 512 | |
| 513 | 513 | case 0x1014: /* $5114 */ |
| r7953 | r7954 | |
| 623 | 623 | vrom_bank[0] = data; |
| 624 | 624 | // mapper5_sync_vrom(0); |
| 625 | 625 | chr1_0(space->machine, vrom_bank[0], CHRROM); |
| 626 | | // nes_vram_sprite[0] = vrom_bank[0] * 64; |
| 626 | // state->nes_vram_sprite[0] = vrom_bank[0] * 64; |
| 627 | 627 | // vrom_next[0] = 4; |
| 628 | 628 | // vrom_page_a = 1; |
| 629 | 629 | // vrom_page_b = 0; |
| r7953 | r7954 | |
| 643 | 643 | vrom_bank[1] = data; |
| 644 | 644 | // mapper5_sync_vrom(0); |
| 645 | 645 | chr1_1(space->machine, vrom_bank[1], CHRROM); |
| 646 | | // nes_vram_sprite[1] = vrom_bank[0] * 64; |
| 646 | // state->nes_vram_sprite[1] = vrom_bank[0] * 64; |
| 647 | 647 | // vrom_next[1] = 5; |
| 648 | 648 | // vrom_page_a = 1; |
| 649 | 649 | // vrom_page_b = 0; |
| r7953 | r7954 | |
| 659 | 659 | vrom_bank[2] = data; |
| 660 | 660 | // mapper5_sync_vrom(0); |
| 661 | 661 | chr1_2(space->machine, vrom_bank[2], CHRROM); |
| 662 | | // nes_vram_sprite[2] = vrom_bank[0] * 64; |
| 662 | // state->nes_vram_sprite[2] = vrom_bank[0] * 64; |
| 663 | 663 | // vrom_next[2] = 6; |
| 664 | 664 | // vrom_page_a = 1; |
| 665 | 665 | // vrom_page_b = 0; |
| r7953 | r7954 | |
| 682 | 682 | vrom_bank[3] = data; |
| 683 | 683 | // mapper5_sync_vrom(0); |
| 684 | 684 | chr1_3(space->machine, vrom_bank[3], CHRROM); |
| 685 | | // nes_vram_sprite[3] = vrom_bank[0] * 64; |
| 685 | // state->nes_vram_sprite[3] = vrom_bank[0] * 64; |
| 686 | 686 | // vrom_next[3] = 7; |
| 687 | 687 | // vrom_page_a = 1; |
| 688 | 688 | // vrom_page_b = 0; |
| r7953 | r7954 | |
| 698 | 698 | vrom_bank[4] = data; |
| 699 | 699 | // mapper5_sync_vrom(0); |
| 700 | 700 | chr1_4(space->machine, vrom_bank[4], CHRROM); |
| 701 | | // nes_vram_sprite[4] = vrom_bank[0] * 64; |
| 701 | // state->nes_vram_sprite[4] = vrom_bank[0] * 64; |
| 702 | 702 | // vrom_next[0] = 0; |
| 703 | 703 | // vrom_page_a = 0; |
| 704 | 704 | // vrom_page_b = 0; |
| r7953 | r7954 | |
| 718 | 718 | vrom_bank[5] = data; |
| 719 | 719 | // mapper5_sync_vrom(0); |
| 720 | 720 | chr1_5(space->machine, vrom_bank[5], CHRROM); |
| 721 | | // nes_vram_sprite[5] = vrom_bank[0] * 64; |
| 721 | // state->nes_vram_sprite[5] = vrom_bank[0] * 64; |
| 722 | 722 | // vrom_next[1] = 1; |
| 723 | 723 | // vrom_page_a = 0; |
| 724 | 724 | // vrom_page_b = 0; |
| r7953 | r7954 | |
| 734 | 734 | vrom_bank[6] = data; |
| 735 | 735 | // mapper5_sync_vrom(0); |
| 736 | 736 | chr1_6(space->machine, vrom_bank[6], CHRROM); |
| 737 | | // nes_vram_sprite[6] = vrom_bank[0] * 64; |
| 737 | // state->nes_vram_sprite[6] = vrom_bank[0] * 64; |
| 738 | 738 | // vrom_next[2] = 2; |
| 739 | 739 | // vrom_page_a = 0; |
| 740 | 740 | // vrom_page_b = 0; |
| r7953 | r7954 | |
| 762 | 762 | vrom_bank[7] = data; |
| 763 | 763 | // mapper5_sync_vrom(0); |
| 764 | 764 | chr1_7(space->machine, vrom_bank[7], CHRROM); |
| 765 | | // nes_vram_sprite[7] = vrom_bank[0] * 64; |
| 765 | // state->nes_vram_sprite[7] = vrom_bank[0] * 64; |
| 766 | 766 | // vrom_next[3] = 3; |
| 767 | 767 | // vrom_page_a = 0; |
| 768 | 768 | // vrom_page_b = 0; |