src/mess/video/nes.c
| r4506 | r4507 | |
| 13 | 13 | |
| 14 | 14 | int nes_vram_sprite[8]; /* Used only by mmc5 for now */ |
| 15 | 15 | static int last_frame_flip = 0; |
| 16 | static double nes_scanlines_per_frame; |
| 16 | 17 | |
| 17 | | static void ppu_nmi(running_machine *machine, int num, int *ppu_regs) |
| 18 | | { |
| 19 | | cpu_set_input_line(machine->cpu[0], INPUT_LINE_NMI, PULSE_LINE); |
| 20 | | } |
| 21 | | |
| 22 | 18 | static void nes_vh_reset(running_machine *machine) |
| 23 | 19 | { |
| 24 | | ppu2c0x_reset( machine, 0, 1 ); |
| 25 | | } |
| 20 | ppu2c0x_set_vidaccess_callback(devtag_get_device(machine,"ppu"), nes_ppu_vidaccess); |
| 21 | ppu2c0x_set_scanlines_per_frame(devtag_get_device(machine,"ppu"), ceil(nes_scanlines_per_frame)); |
| 26 | 22 | |
| 27 | | static void nes_vh_start(running_machine *machine, ppu_t ppu_type, double scanlines_per_frame) |
| 28 | | { |
| 29 | | ppu2c0x_interface ppu_interface; |
| 30 | | |
| 31 | | last_frame_flip = 0; |
| 32 | | |
| 33 | | memset(&ppu_interface, 0, sizeof(ppu_interface)); |
| 34 | | ppu_interface.type = ppu_type; |
| 35 | | ppu_interface.num = 1; |
| 36 | | ppu_interface.vrom_region[0] = nes.chr_chunks ? "gfx1" : NULL; |
| 37 | | ppu_interface.mirroring[0] = PPU_MIRROR_NONE; |
| 38 | | ppu_interface.nmi_handler[0] = ppu_nmi; |
| 39 | | |
| 40 | | ppu2c0x_init(machine, &ppu_interface); |
| 41 | | ppu2c0x_set_vidaccess_callback(0, nes_ppu_vidaccess); |
| 42 | | ppu2c0x_set_scanlines_per_frame(0, ceil(scanlines_per_frame)); |
| 43 | | |
| 44 | 23 | if (nes.four_screen_vram) |
| 45 | 24 | { |
| 46 | | ppu2c0x_set_mirroring(0, PPU_MIRROR_4SCREEN); |
| 25 | ppu2c0x_set_mirroring(devtag_get_device(machine,"ppu"), PPU_MIRROR_4SCREEN); |
| 47 | 26 | } |
| 48 | 27 | else |
| 49 | 28 | { |
| 50 | 29 | switch(nes.hard_mirroring) |
| 51 | 30 | { |
| 52 | 31 | case 0: |
| 53 | | ppu2c0x_set_mirroring(0, PPU_MIRROR_HORZ); |
| 32 | ppu2c0x_set_mirroring(devtag_get_device(machine,"ppu"), PPU_MIRROR_HORZ); |
| 54 | 33 | break; |
| 55 | 34 | case 1: |
| 56 | | ppu2c0x_set_mirroring(0, PPU_MIRROR_VERT); |
| 35 | ppu2c0x_set_mirroring(devtag_get_device(machine,"ppu"), PPU_MIRROR_VERT); |
| 57 | 36 | break; |
| 37 | default: |
| 38 | ppu2c0x_set_mirroring(devtag_get_device(machine,"ppu"), PPU_MIRROR_NONE ); |
| 39 | break; |
| 58 | 40 | } |
| 59 | 41 | } |
| 42 | } |
| 60 | 43 | |
| 61 | | add_reset_callback(machine, nes_vh_reset); |
| 44 | static void nes_vh_start(running_machine *machine, double scanlines_per_frame) |
| 45 | { |
| 46 | last_frame_flip = 0; |
| 47 | nes_scanlines_per_frame = scanlines_per_frame; |
| 62 | 48 | |
| 63 | | /* Reset the mapper variables. Will also mark the char-gen ram as dirty */ |
| 64 | | mapper_reset(machine, nes.mapper); |
| 49 | add_reset_callback(machine, nes_vh_reset); |
| 65 | 50 | } |
| 66 | 51 | |
| 67 | 52 | |
| 68 | 53 | |
| 69 | 54 | VIDEO_START( nes_ntsc ) |
| 70 | 55 | { |
| 71 | | nes_vh_start(machine, PPU_2C02, PPU_NTSC_SCANLINES_PER_FRAME); |
| 56 | nes_vh_start(machine, PPU_NTSC_SCANLINES_PER_FRAME); |
| 72 | 57 | } |
| 73 | 58 | |
| 74 | 59 | VIDEO_START( nes_pal ) |
| 75 | 60 | { |
| 76 | | nes_vh_start(machine, PPU_2C07, PPU_PAL_SCANLINES_PER_FRAME); |
| 61 | nes_vh_start(machine, PPU_PAL_SCANLINES_PER_FRAME); |
| 77 | 62 | } |
| 78 | 63 | |
| 79 | 64 | PALETTE_INIT( nes ) |
| r4506 | r4507 | |
| 90 | 75 | |
| 91 | 76 | VIDEO_UPDATE( nes ) |
| 92 | 77 | { |
| 78 | nes_state *state = screen->machine->driver_data; |
| 79 | |
| 93 | 80 | /* render the ppu */ |
| 94 | | ppu2c0x_render( 0, bitmap, 0, 0, 0, 0 ); |
| 81 | ppu2c0x_render( state->ppu, bitmap, 0, 0, 0, 0 ); |
| 95 | 82 | |
| 96 | 83 | /* if this is a disk system game, check for the flip-disk key */ |
| 97 | 84 | if (nes.mapper == 20) |
src/mess/messdriv.c
| r4506 | r4507 | |
| 62 | 62 | // DRIVER( falcon40 ) /* Atari Falcon040 (prototype) */ |
| 63 | 63 | |
| 64 | 64 | /* NINTENDO */ |
| 65 | | //0130u4 DRIVER( nes ) /* Nintendo Entertainment System */ |
| 66 | | //0130u4 DRIVER( nespal ) /* Nintendo Entertainment System */ |
| 67 | | //0130u4 DRIVER( famicom ) |
| 68 | | //0130u4 DRIVER( famitwin ) /* Sharp Famicom Twin System */ |
| 69 | | //0130u4 DRIVER( gameboy ) /* Nintendo Game Boy Handheld */ |
| 70 | | //0130u4 DRIVER( supergb ) /* Nintendo Super Game Boy SNES Cartridge */ |
| 71 | | //0130u4 DRIVER( gbpocket ) /* Nintendo Game Boy Pocket Handheld */ |
| 72 | | //0130u4 DRIVER( gbcolor ) /* Nintendo Game Boy Color Handheld */ |
| 73 | | //0130u4 DRIVER( snes ) /* Nintendo Super Nintendo NTSC */ |
| 74 | | //0130u4 DRIVER( snespal ) /* Nintendo Super Nintendo PAL */ |
| 75 | | //0130u4 DRIVER( n64 ) /* Nintendo N64 */ |
| 76 | | //0130u4 DRIVER( pokemini ) /* Nintendo Pokemon Mini */ |
| 65 | DRIVER( nes ) /* Nintendo Entertainment System */ |
| 66 | DRIVER( nespal ) /* Nintendo Entertainment System */ |
| 67 | DRIVER( famicom ) |
| 68 | DRIVER( famitwin ) /* Sharp Famicom Twin System */ |
| 69 | DRIVER( gameboy ) /* Nintendo Game Boy Handheld */ |
| 70 | DRIVER( supergb ) /* Nintendo Super Game Boy SNES Cartridge */ |
| 71 | DRIVER( gbpocket ) /* Nintendo Game Boy Pocket Handheld */ |
| 72 | DRIVER( gbcolor ) /* Nintendo Game Boy Color Handheld */ |
| 73 | DRIVER( snes ) /* Nintendo Super Nintendo NTSC */ |
| 74 | DRIVER( snespal ) /* Nintendo Super Nintendo PAL */ |
| 75 | DRIVER( n64 ) /* Nintendo N64 */ |
| 76 | DRIVER( pokemini ) /* Nintendo Pokemon Mini */ |
| 77 | 77 | |
| 78 | | //0130u4 DRIVER( megaduck ) /* Megaduck */ |
| 78 | DRIVER( megaduck ) /* Megaduck */ |
| 79 | 79 | |
| 80 | 80 | /* SEGA */ |
| 81 | 81 | DRIVER( sg1000 ) /* Sega SG-1000 (Japan) */ |
src/mess/machine/nes.c
| r4506 | r4507 | |
| 72 | 72 | |
| 73 | 73 | static void init_nes_core (running_machine *machine) |
| 74 | 74 | { |
| 75 | | nes_state *state = machine->driver_data; |
| 76 | 75 | const address_space *space = cpu_get_address_space( machine->cpu[0], ADDRESS_SPACE_PROGRAM ); |
| 77 | 76 | |
| 78 | | state->ppu = devtag_get_device(machine, "ppu"); |
| 79 | | state->sound = devtag_get_device(machine, "nessound"); |
| 80 | | state->cart = devtag_get_device(machine, "cart"); |
| 81 | | |
| 82 | 77 | /* We set these here in case they weren't set in the cart loader */ |
| 83 | 78 | nes.rom = memory_region(machine, "maincpu"); |
| 84 | 79 | nes.vrom = memory_region(machine, "gfx1"); |
| r4506 | r4507 | |
| 168 | 163 | memcpy (nes_battery_ram, battery_data, BATTERY_SIZE); |
| 169 | 164 | } |
| 170 | 165 | |
| 171 | | int nes_ppu_vidaccess( running_machine *machine, int num, int address, int data ) |
| 166 | int nes_ppu_vidaccess( const device_config *device, int address, int data ) |
| 172 | 167 | { |
| 173 | 168 | /* TODO: this is a bit of a hack, needed to get Argus, ASO, etc to work */ |
| 174 | 169 | /* but, B-Wings, submath (j) seem to use this location differently... */ |
| r4506 | r4507 | |
| 183 | 178 | |
| 184 | 179 | MACHINE_RESET( nes ) |
| 185 | 180 | { |
| 181 | nes_state *state = machine->driver_data; |
| 182 | |
| 183 | state->ppu = devtag_get_device(machine, "ppu"); |
| 184 | state->sound = devtag_get_device(machine, "nessound"); |
| 185 | state->cart = devtag_get_device(machine, "cart"); |
| 186 | |
| 186 | 187 | /* Some carts have extra RAM and require it on at startup, e.g. Metroid */ |
| 187 | 188 | nes.mid_ram_enable = 1; |
| 188 | 189 | |
| r4506 | r4507 | |
| 192 | 193 | /* Reset the serial input ports */ |
| 193 | 194 | in_0.shift = 0; |
| 194 | 195 | in_1.shift = 0; |
| 196 | |
| 197 | cputag_reset( machine, "maincpu" ); |
| 195 | 198 | } |
| 196 | 199 | |
| 197 | 200 | MACHINE_START( nes ) |
| r4506 | r4507 | |
| 211 | 214 | |
| 212 | 215 | READ8_HANDLER ( nes_IN0_r ) |
| 213 | 216 | { |
| 217 | nes_state *state = space->machine->driver_data; |
| 214 | 218 | int ret; |
| 215 | 219 | |
| 216 | 220 | /* Some games expect bit 6 to be set because the last entry on the data bus shows up */ |
| r4506 | r4507 | |
| 227 | 231 | UINT32 pix, color_base; |
| 228 | 232 | |
| 229 | 233 | /* get the pixel at the gun position */ |
| 230 | | pix = ppu2c0x_get_pixel( 0, x, y ); |
| 234 | pix = ppu2c0x_get_pixel( state->ppu, x, y ); |
| 231 | 235 | |
| 232 | 236 | /* get the color base from the ppu */ |
| 233 | | color_base = ppu2c0x_get_colorbase( 0 ); |
| 237 | color_base = ppu2c0x_get_colorbase( state->ppu ); |
| 234 | 238 | |
| 235 | 239 | /* look at the screen and see if the cursor is over a bright pixel */ |
| 236 | 240 | if ( ( pix == color_base + 0x20 ) || ( pix == color_base + 0x30 ) || |
| r4506 | r4507 | |
| 254 | 258 | |
| 255 | 259 | READ8_HANDLER ( nes_IN1_r ) |
| 256 | 260 | { |
| 261 | nes_state *state = space->machine->driver_data; |
| 257 | 262 | int ret; |
| 258 | 263 | |
| 259 | 264 | /* Some games expect bit 6 to be set because the last entry on the data bus shows up */ |
| r4506 | r4507 | |
| 271 | 276 | UINT32 pix, color_base; |
| 272 | 277 | |
| 273 | 278 | /* get the pixel at the gun position */ |
| 274 | | pix = ppu2c0x_get_pixel( 0, x, y ); |
| 279 | pix = ppu2c0x_get_pixel( state->ppu, x, y ); |
| 275 | 280 | |
| 276 | 281 | /* get the color base from the ppu */ |
| 277 | | color_base = ppu2c0x_get_colorbase( 0 ); |
| 282 | color_base = ppu2c0x_get_colorbase( state->ppu ); |
| 278 | 283 | |
| 279 | 284 | /* look at the screen and see if the cursor is over a bright pixel */ |
| 280 | 285 | if ( ( pix == color_base + 0x20 ) || ( pix == color_base + 0x30 ) || |
src/mess/machine/nes_mmc.c
| r4506 | r4507 | |
| 50 | 50 | write8_space_func mmc_write_mid; |
| 51 | 51 | read8_space_func mmc_read_mid; |
| 52 | 52 | write8_space_func mmc_write; |
| 53 | | /*void (*ppu_latch)(offs_t offset);*/ |
| 54 | 53 | |
| 55 | 54 | static int vrom_bank[16]; |
| 56 | 55 | static int mult1, mult2; |
| r4506 | r4507 | |
| 1390 | 1389 | } |
| 1391 | 1390 | |
| 1392 | 1391 | |
| 1393 | | static void mapper9_latch (running_machine *machine, offs_t offset) |
| 1392 | static void mapper9_latch (const device_config *device, offs_t offset) |
| 1394 | 1393 | { |
| 1395 | 1394 | if ((offset & 0x3ff0) == 0x0fd0) |
| 1396 | 1395 | { |
| 1397 | 1396 | logerror ("mapper9 vrom latch switch (bank 0 low): %02x\n", MMC2_bank0); |
| 1398 | 1397 | MMC2_bank0_latch = 0xfd; |
| 1399 | | chr4_0 (machine, MMC2_bank0); |
| 1398 | chr4_0 (device->machine, MMC2_bank0); |
| 1400 | 1399 | } |
| 1401 | 1400 | else if ((offset & 0x3ff0) == 0x0fe0) |
| 1402 | 1401 | { |
| 1403 | 1402 | logerror ("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_bank0_hi); |
| 1404 | 1403 | MMC2_bank0_latch = 0xfe; |
| 1405 | | chr4_0 (machine, MMC2_bank0_hi); |
| 1404 | chr4_0 (device->machine, MMC2_bank0_hi); |
| 1406 | 1405 | } |
| 1407 | 1406 | else if ((offset & 0x3ff0) == 0x1fd0) |
| 1408 | 1407 | { |
| 1409 | 1408 | logerror ("mapper9 vrom latch switch (bank 1 low): %02x\n", MMC2_bank1); |
| 1410 | 1409 | MMC2_bank1_latch = 0xfd; |
| 1411 | | chr4_4 (machine, MMC2_bank1); |
| 1410 | chr4_4 (device->machine, MMC2_bank1); |
| 1412 | 1411 | } |
| 1413 | 1412 | else if ((offset & 0x3ff0) == 0x1fe0) |
| 1414 | 1413 | { |
| 1415 | 1414 | logerror ("mapper9 vrom latch switch (bank 0 high): %02x\n", MMC2_bank1_hi); |
| 1416 | 1415 | MMC2_bank1_latch = 0xfe; |
| 1417 | | chr4_4 (machine, MMC2_bank1_hi); |
| 1416 | chr4_4 (device->machine, MMC2_bank1_hi); |
| 1418 | 1417 | } |
| 1419 | 1418 | } |
| 1420 | 1419 | |
| r4506 | r4507 | |
| 1465 | 1464 | } |
| 1466 | 1465 | |
| 1467 | 1466 | |
| 1468 | | static void mapper10_latch (running_machine *machine, offs_t offset) |
| 1467 | static void mapper10_latch (const device_config *device, offs_t offset) |
| 1469 | 1468 | { |
| 1470 | 1469 | if ((offset & 0x3ff0) == 0x0fd0) |
| 1471 | 1470 | { |
| 1472 | 1471 | logerror ("mapper10 vrom latch switch (bank 0 low): %02x\n", MMC2_bank0); |
| 1473 | 1472 | MMC2_bank0_latch = 0xfd; |
| 1474 | | chr4_0 (machine, MMC2_bank0); |
| 1473 | chr4_0 (device->machine, MMC2_bank0); |
| 1475 | 1474 | } |
| 1476 | 1475 | else if ((offset & 0x3ff0) == 0x0fe0) |
| 1477 | 1476 | { |
| 1478 | 1477 | logerror ("mapper10 vrom latch switch (bank 0 high): %02x\n", MMC2_bank0_hi); |
| 1479 | 1478 | MMC2_bank0_latch = 0xfe; |
| 1480 | | chr4_0 (machine, MMC2_bank0_hi); |
| 1479 | chr4_0 (device->machine, MMC2_bank0_hi); |
| 1481 | 1480 | } |
| 1482 | 1481 | else if ((offset & 0x3ff0) == 0x1fd0) |
| 1483 | 1482 | { |
| 1484 | 1483 | logerror ("mapper10 vrom latch switch (bank 1 low): %02x\n", MMC2_bank1); |
| 1485 | 1484 | MMC2_bank1_latch = 0xfd; |
| 1486 | | chr4_4 (machine, MMC2_bank1); |
| 1485 | chr4_4 (device->machine, MMC2_bank1); |
| 1487 | 1486 | } |
| 1488 | 1487 | else if ((offset & 0x3ff0) == 0x1fe0) |
| 1489 | 1488 | { |
| 1490 | 1489 | logerror ("mapper10 vrom latch switch (bank 0 high): %02x\n", MMC2_bank1_hi); |
| 1491 | 1490 | MMC2_bank1_latch = 0xfe; |
| 1492 | | chr4_4 (machine, MMC2_bank1_hi); |
| 1491 | chr4_4 (device->machine, MMC2_bank1_hi); |
| 1493 | 1492 | } |
| 1494 | 1493 | } |
| 1495 | 1494 | |
src/mess/drivers/nes.c
| r4506 | r4507 | |
| 36 | 36 | |
| 37 | 37 | static WRITE8_HANDLER(nes_vh_sprite_dma_w) |
| 38 | 38 | { |
| 39 | | ppu2c0x_spriteram_dma(space, 0, data); |
| 39 | nes_state *state = space->machine->driver_data; |
| 40 | ppu2c0x_spriteram_dma(space, state->ppu, data); |
| 40 | 41 | } |
| 41 | 42 | |
| 42 | 43 | static ADDRESS_MAP_START( nes_map, ADDRESS_SPACE_PROGRAM, 8 ) |
| 43 | 44 | AM_RANGE(0x0000, 0x07ff) AM_RAM AM_MIRROR(0x1800) /* RAM */ |
| 44 | | AM_RANGE(0x2000, 0x3fff) AM_READWRITE(ppu2c0x_0_r, ppu2c0x_0_w) /* PPU registers */ |
| 45 | AM_RANGE(0x2000, 0x3fff) AM_DEVREADWRITE("ppu", ppu2c0x_r, ppu2c0x_w) /* PPU registers */ |
| 45 | 46 | AM_RANGE(0x4000, 0x4013) AM_DEVREADWRITE("nessound", nes_psg_r, nes_psg_w) /* PSG primary registers */ |
| 46 | 47 | AM_RANGE(0x4014, 0x4014) AM_WRITE(nes_vh_sprite_dma_w) /* stupid address space hole */ |
| 47 | 48 | AM_RANGE(0x4015, 0x4015) AM_DEVREADWRITE("nessound", psg_4015_r, psg_4015_w) /* PSG status / first control register */ |
| r4506 | r4507 | |
| 213 | 214 | ROM_FILL( 0x0000, 0x10000, 0x00 ) |
| 214 | 215 | ROM_END |
| 215 | 216 | |
| 217 | |
| 218 | static void ppu_nmi(const device_config *device, int *ppu_regs) |
| 219 | { |
| 220 | cpu_set_input_line(device->machine->cpu[0], INPUT_LINE_NMI, PULSE_LINE); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | static ppu2c0x_interface nes_ppu_interface = |
| 225 | { |
| 226 | NULL/*"gfx1"*/, |
| 227 | 0, |
| 228 | 0, |
| 229 | PPU_MIRROR_NONE, |
| 230 | ppu_nmi, |
| 231 | 0 |
| 232 | }; |
| 233 | |
| 234 | |
| 216 | 235 | static MACHINE_DRIVER_START( nes ) |
| 217 | 236 | /* basic machine hardware */ |
| 218 | 237 | MDRV_CPU_ADD("maincpu", N2A03, NTSC_CLOCK) |
| r4506 | r4507 | |
| 225 | 244 | // cycles for the actual vblank period. |
| 226 | 245 | MDRV_SCREEN_VBLANK_TIME(ATTOSECONDS_IN_USEC((113.66/(NTSC_CLOCK/1000000)) * (PPU_VBLANK_LAST_SCANLINE_NTSC-PPU_VBLANK_FIRST_SCANLINE+1+2))) |
| 227 | 246 | |
| 247 | MDRV_DRIVER_DATA( nes_state ) |
| 248 | |
| 228 | 249 | MDRV_MACHINE_START( nes ) |
| 229 | 250 | MDRV_MACHINE_RESET( nes ) |
| 230 | 251 | |
| r4506 | r4507 | |
| 237 | 258 | |
| 238 | 259 | MDRV_PALETTE_LENGTH(4*16*8) |
| 239 | 260 | |
| 261 | MDRV_PPU2C02_ADD( "ppu", nes_ppu_interface ) |
| 262 | |
| 240 | 263 | /* sound hardware */ |
| 241 | 264 | MDRV_SPEAKER_STANDARD_MONO("mono") |
| 242 | 265 | MDRV_SOUND_ADD("nessound", NES, NTSC_CLOCK) |
| r4506 | r4507 | |
| 256 | 279 | /* basic machine hardware */ |
| 257 | 280 | MDRV_CPU_REPLACE("maincpu", N2A03, PAL_CLOCK) |
| 258 | 281 | |
| 282 | MDRV_DEVICE_REMOVE( "ppu" ) |
| 283 | MDRV_PPU2C07_ADD( "ppu", nes_ppu_interface ) |
| 284 | |
| 259 | 285 | /* video hardware */ |
| 260 | 286 | MDRV_SCREEN_MODIFY("screen") |
| 261 | 287 | MDRV_SCREEN_REFRESH_RATE(53.355) |
| r4506 | r4507 | |
| 311 | 337 | ***************************************************************************/ |
| 312 | 338 | |
| 313 | 339 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 314 | | CONS( 1983, famicom, 0, 0, famicom, famicom, 0, famicom, "Nintendo", "Famicom" , 0) |
| 315 | | CONS( 1986, famitwin, famicom, 0, famicom, famicom, 0, famicom, "Sharp", "Famicom Twin" , 0) |
| 316 | | CONS( 1985, nes, 0, 0, nes, nes, 0, 0, "Nintendo", "Nintendo Entertainment System (NTSC)" , 0) |
| 317 | | CONS( 1987, nespal, nes, 0, nespal, nes, 0, 0, "Nintendo", "Nintendo Entertainment System (PAL)" , 0) |
| 340 | CONS( 1983, famicom, 0, 0, famicom, famicom, 0, famicom, "Nintendo", "Famicom" , GAME_NOT_WORKING) |
| 341 | CONS( 1986, famitwin, famicom, 0, famicom, famicom, 0, famicom, "Sharp", "Famicom Twin" , GAME_NOT_WORKING) |
| 342 | CONS( 1985, nes, 0, 0, nes, nes, 0, 0, "Nintendo", "Nintendo Entertainment System (NTSC)" , GAME_NOT_WORKING) |
| 343 | CONS( 1987, nespal, nes, 0, nespal, nes, 0, 0, "Nintendo", "Nintendo Entertainment System (PAL)" , GAME_NOT_WORKING) |