src/mess/machine/nes.c
| r6733 | r6734 | |
| 5 | 5 | #include "machine/nes_mmc.h" |
| 6 | 6 | #include "sound/nes_apu.h" |
| 7 | 7 | #include "devices/cartslot.h" |
| 8 | #include "devices/flopdrv.h" |
| 9 | #include "formats/flopimg.h" |
| 8 | 10 | #include "image.h" |
| 9 | 11 | #include "hash.h" |
| 10 | 12 | |
| r6733 | r6734 | |
| 221 | 223 | cputag_reset(machine, "maincpu"); |
| 222 | 224 | } |
| 223 | 225 | |
| 226 | emu_timer *nes_irq_timer; |
| 227 | |
| 228 | static TIMER_CALLBACK( nes_irq_callback ) |
| 229 | { |
| 230 | cputag_set_input_line(machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE); |
| 231 | timer_adjust_oneshot(nes_irq_timer, attotime_never, 0); |
| 232 | } |
| 233 | |
| 224 | 234 | MACHINE_START( nes ) |
| 225 | 235 | { |
| 226 | 236 | init_nes_core(machine); |
| 227 | 237 | add_exit_callback(machine, nes_machine_stop); |
| 238 | |
| 239 | nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL); |
| 228 | 240 | } |
| 229 | 241 | |
| 230 | 242 | static void nes_machine_stop( running_machine *machine ) |
| r6733 | r6734 | |
| 913 | 925 | } |
| 914 | 926 | |
| 915 | 927 | |
| 916 | | DEVICE_START( nes_disk ) |
| 928 | static void nes_load_proc(const device_config *image) |
| 917 | 929 | { |
| 930 | image_fseek(image, 0, SEEK_END); |
| 931 | nes_fds.sides = (image_ftell(image) - 16) / 65500; |
| 932 | nes_fds.data = image_realloc(image, nes_fds.data, nes_fds.sides * 65500); |
| 933 | image_fseek(image, 0x10, SEEK_SET); |
| 934 | image_fread(image, nes_fds.data, 65500 * nes_fds.sides); |
| 935 | return; |
| 936 | } |
| 937 | |
| 938 | static void nes_unload_proc(const device_config *image) |
| 939 | { |
| 940 | /* TODO: should write out changes here as well */ |
| 941 | nes_fds.sides = 0; |
| 942 | nes_fds.data = NULL; |
| 943 | } |
| 944 | |
| 945 | DRIVER_INIT( famicom) |
| 946 | { |
| 947 | nes_fds.sides = 0; |
| 948 | nes_fds.data = NULL; |
| 949 | |
| 950 | floppy_install_load_proc(floppy_get_device(machine,0), nes_load_proc); |
| 951 | floppy_install_unload_proc(floppy_get_device(machine,0), nes_unload_proc); |
| 952 | } |
| 953 | |
| 954 | MACHINE_START( famicom ) |
| 955 | { |
| 918 | 956 | /* clear some of the cart variables we don't use */ |
| 919 | 957 | nes.trainer = 0; |
| 920 | 958 | nes.battery = 0; |
| r6733 | r6734 | |
| 926 | 964 | nes.four_screen_vram = 0; |
| 927 | 965 | nes.hard_mirroring = 0; |
| 928 | 966 | |
| 929 | | nes_fds.sides = 0; |
| 930 | | nes_fds.data = NULL; |
| 967 | nes_fds.sides = 0; |
| 968 | MACHINE_START_CALL( nes ); |
| 931 | 969 | } |
| 932 | | |
| 933 | | |
| 934 | | DEVICE_IMAGE_LOAD( nes_disk ) |
| 935 | | { |
| 936 | | unsigned char magic[4]; |
| 937 | | |
| 938 | | /* See if it has a redundant header on it */ |
| 939 | | image_fread(image, magic, 4); |
| 940 | | if ((magic[0] == 'F') && (magic[1] == 'D') && (magic[2] == 'S')) |
| 941 | | { |
| 942 | | /* Skip past the redundant header */ |
| 943 | | image_fseek(image, 0x10, SEEK_SET); |
| 944 | | } |
| 945 | | else |
| 946 | | /* otherwise, point to the start of the image */ |
| 947 | | image_fseek(image, 0, SEEK_SET); |
| 948 | | |
| 949 | | /* read in all the sides */ |
| 950 | | while (!image_feof(image)) |
| 951 | | { |
| 952 | | nes_fds.sides ++; |
| 953 | | nes_fds.data = image_realloc(image, nes_fds.data, nes_fds.sides * 65500); |
| 954 | | if (!nes_fds.data) |
| 955 | | return INIT_FAIL; |
| 956 | | image_fread(image, nes_fds.data + ((nes_fds.sides - 1) * 65500), 65500); |
| 957 | | } |
| 958 | | |
| 959 | | logerror("Number of sides: %d\n", nes_fds.sides); |
| 960 | | |
| 961 | | return INIT_PASS; |
| 962 | | } |
| 963 | | |
| 964 | | DEVICE_IMAGE_UNLOAD( nes_disk ) |
| 965 | | { |
| 966 | | /* TODO: should write out changes here as well */ |
| 967 | | nes_fds.data = NULL; |
| 968 | | } |
src/mess/machine/nes_mmc.c
| r6733 | r6734 | |
| 263 | 263 | |
| 264 | 264 | static int mapper_warning; |
| 265 | 265 | |
| 266 | | static emu_timer *nes_irq_timer; |
| 267 | 266 | |
| 268 | | |
| 269 | 267 | /************************************************************* |
| 270 | 268 | |
| 271 | 269 | Base emulation (see drivers/nes.c): |
| r6733 | r6734 | |
| 287 | 285 | |
| 288 | 286 | *************************************************************/ |
| 289 | 287 | |
| 290 | | static TIMER_CALLBACK( nes_irq_callback ) |
| 291 | | { |
| 292 | | cputag_set_input_line(machine, "maincpu", M6502_IRQ_LINE, HOLD_LINE); |
| 293 | | timer_adjust_oneshot(nes_irq_timer, attotime_never, 0); |
| 294 | | } |
| 295 | | |
| 296 | 288 | WRITE8_HANDLER( nes_chr_w ) |
| 297 | 289 | { |
| 298 | 290 | int bank = offset >> 10; |
| r6733 | r6734 | |
| 1584 | 1576 | ppu2c0x_set_scanline_callback(state->ppu, mapper ? mapper->mmc_scanline : NULL); |
| 1585 | 1577 | ppu2c0x_set_hblank_callback(state->ppu, mapper ? mapper->mmc_hblank : NULL); |
| 1586 | 1578 | |
| 1587 | | if (!nes_irq_timer) |
| 1588 | | nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL); |
| 1589 | | |
| 1590 | 1579 | mapper_warning = 0; |
| 1591 | 1580 | |
| 1592 | 1581 | nes_mmc5_vram_control = 0; |
| r6733 | r6734 | |
| 1651 | 1640 | ppu2c0x_set_scanline_callback(state->ppu, unif_board ? unif_board->mmc_scanline : NULL); |
| 1652 | 1641 | ppu2c0x_set_hblank_callback(state->ppu, unif_board ? unif_board->mmc_hblank : NULL); |
| 1653 | 1642 | |
| 1654 | | if (!nes_irq_timer) |
| 1655 | | nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL); |
| 1656 | 1643 | |
| 1657 | 1644 | /* Point the WRAM/battery area to the first RAM bank */ |
| 1658 | 1645 | memory_set_bankptr(machine, "bank5", &nes.wram[0x0000]); |
src/mess/formats/nes_dsk.c
| r0 | r6734 | |
| 1 | /********************************************************************* |
| 2 | |
| 3 | formats/nes_dsk.c |
| 4 | |
| 5 | NES disk images |
| 6 | |
| 7 | *********************************************************************/ |
| 8 | |
| 9 | |
| 10 | #include <string.h> |
| 11 | |
| 12 | #include "formats/nes_dsk.h" |
| 13 | #include "formats/basicdsk.h" |
| 14 | |
| 15 | |
| 16 | |
| 17 | /***************************************************************************** |
| 18 | NES floppy core functions |
| 19 | *****************************************************************************/ |
| 20 | |
| 21 | |
| 22 | static FLOPPY_IDENTIFY( nes_dsk_identify ) |
| 23 | { |
| 24 | UINT64 size; |
| 25 | UINT8 header[3]; |
| 26 | |
| 27 | *vote = 100; |
| 28 | |
| 29 | /* get first 3 bytes */ |
| 30 | floppy_image_read(floppy, &header, 0, sizeof(header)); |
| 31 | |
| 32 | /* first check the size of the image */ |
| 33 | size = floppy_image_size(floppy); |
| 34 | |
| 35 | if ((size != 65516) && (size != 131016) && (size != 262016)) |
| 36 | *vote = 0; |
| 37 | |
| 38 | /* then check the first sector for the magic string */ |
| 39 | if (memcmp(header, "FDS", 3)) |
| 40 | *vote = 0; |
| 41 | |
| 42 | return FLOPPY_ERROR_SUCCESS; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | static FLOPPY_CONSTRUCT( nes_dsk_construct ) |
| 47 | { |
| 48 | return FLOPPY_ERROR_SUCCESS; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | /***************************************************************************** |
| 53 | NES floppy options |
| 54 | *****************************************************************************/ |
| 55 | |
| 56 | FLOPPY_OPTIONS_START( nes_only ) |
| 57 | FLOPPY_OPTION( |
| 58 | fds_dsk, |
| 59 | "fds", |
| 60 | "NES floppy disk image", |
| 61 | nes_dsk_identify, |
| 62 | nes_dsk_construct, |
| 63 | NULL |
| 64 | ) |
| 65 | { NULL } |
| 66 | }; |
src/mess/drivers/nes.c
| r6733 | r6734 | |
| 17 | 17 | #include "cpu/m6502/m6502.h" |
| 18 | 18 | #include "devices/cartslot.h" |
| 19 | 19 | #include "sound/nes_apu.h" |
| 20 | #include "devices/flopdrv.h" |
| 21 | #include "formats/nes_dsk.h" |
| 20 | 22 | |
| 21 | 23 | |
| 22 | 24 | static READ8_DEVICE_HANDLER( psg_4015_r ) |
| r6733 | r6734 | |
| 182 | 184 | ppu_nmi |
| 183 | 185 | }; |
| 184 | 186 | |
| 187 | static const floppy_config nes_floppy_config = |
| 188 | { |
| 189 | DEVCB_NULL, |
| 190 | DEVCB_NULL, |
| 191 | DEVCB_NULL, |
| 192 | DEVCB_NULL, |
| 193 | DEVCB_NULL, |
| 194 | FLOPPY_DRIVE_DS_80, |
| 195 | FLOPPY_OPTIONS_NAME(nes_only), |
| 196 | DO_NOT_KEEP_GEOMETRY |
| 197 | }; |
| 185 | 198 | |
| 199 | |
| 186 | 200 | static MACHINE_DRIVER_START( nes ) |
| 187 | 201 | /* basic machine hardware */ |
| 188 | 202 | MDRV_CPU_ADD("maincpu", N2A03, NTSC_CLOCK) |
| r6733 | r6734 | |
| 268 | 282 | |
| 269 | 283 | static MACHINE_DRIVER_START( famicom ) |
| 270 | 284 | MDRV_IMPORT_FROM( nes ) |
| 285 | MDRV_MACHINE_START( famicom ) |
| 271 | 286 | |
| 272 | 287 | MDRV_CARTSLOT_MODIFY("cart") |
| 273 | 288 | MDRV_CARTSLOT_EXTENSION_LIST("nes,unf") |
| 274 | 289 | MDRV_CARTSLOT_NOT_MANDATORY |
| 275 | 290 | MDRV_CARTSLOT_LOAD(nes_cart) |
| 276 | 291 | MDRV_CARTSLOT_PARTIALHASH(nes_partialhash) |
| 292 | |
| 293 | MDRV_FLOPPY_DRIVE_ADD(FLOPPY_0, nes_floppy_config) |
| 277 | 294 | MACHINE_DRIVER_END |
| 278 | 295 | |
| 279 | 296 | |
| r6733 | r6734 | |
| 379 | 396 | ROM_FILL( 0x0000, 0x10000, 0x00 ) |
| 380 | 397 | ROM_END |
| 381 | 398 | |
| 382 | | |
| 383 | | static void famicom_floppy_getinfo(const mess_device_class *devclass, UINT32 state, union devinfo *info) |
| 384 | | { |
| 385 | | /* floppy */ |
| 386 | | switch(state) |
| 387 | | { |
| 388 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 389 | | case MESS_DEVINFO_INT_TYPE: info->i = IO_FLOPPY; break; |
| 390 | | case MESS_DEVINFO_INT_READABLE: info->i = 1; break; |
| 391 | | case MESS_DEVINFO_INT_WRITEABLE: info->i = 0; break; |
| 392 | | case MESS_DEVINFO_INT_CREATABLE: info->i = 0; break; |
| 393 | | case MESS_DEVINFO_INT_COUNT: info->i = 1; break; |
| 394 | | |
| 395 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 396 | | case MESS_DEVINFO_PTR_START: info->start = DEVICE_START_NAME(nes_disk); break; |
| 397 | | case MESS_DEVINFO_PTR_LOAD: info->load = DEVICE_IMAGE_LOAD_NAME(nes_disk); break; |
| 398 | | case MESS_DEVINFO_PTR_UNLOAD: info->unload = DEVICE_IMAGE_UNLOAD_NAME(nes_disk); break; |
| 399 | | |
| 400 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 401 | | case MESS_DEVINFO_STR_FILE_EXTENSIONS: strcpy(info->s = device_temp_str(), "dsk,fds"); break; |
| 402 | | } |
| 403 | | } |
| 404 | | |
| 405 | | static SYSTEM_CONFIG_START(famicom) |
| 406 | | CONFIG_DEVICE(famicom_floppy_getinfo) |
| 407 | | SYSTEM_CONFIG_END |
| 408 | | |
| 409 | 399 | /*************************************************************************** |
| 410 | 400 | |
| 411 | 401 | Game driver(s) |
| r6733 | r6734 | |
| 415 | 405 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT CONFIG COMPANY FULLNAME */ |
| 416 | 406 | CONS( 1985, nes, 0, 0, nes, nes, 0, 0, "Nintendo", "Nintendo Entertainment System / Famicom (NTSC)", GAME_IMPERFECT_GRAPHICS ) |
| 417 | 407 | CONS( 1987, nespal, nes, 0, nespal, nes, 0, 0, "Nintendo", "Nintendo Entertainment System (PAL)", GAME_IMPERFECT_GRAPHICS ) |
| 418 | | CONS( 1983, famicom, nes, 0, famicom, famicom, 0, famicom, "Nintendo", "Famicom Disk System", GAME_IMPERFECT_GRAPHICS ) |
| 419 | | CONS( 1986, famitwin, nes, 0, famicom, famicom, 0, famicom, "Sharp", "Famicom Twin", GAME_IMPERFECT_GRAPHICS ) |
| 408 | CONS( 1983, famicom, nes, 0, famicom, famicom, famicom, 0, "Nintendo", "Famicom Disk System", GAME_IMPERFECT_GRAPHICS ) |
| 409 | CONS( 1986, famitwin, nes, 0, famicom, famicom, famicom, 0, "Sharp", "Famicom Twin", GAME_IMPERFECT_GRAPHICS ) |
| 420 | 410 | CONS( 198?, m82, nes, 0, nes, nes, 0, 0, "Nintendo", "M82 Display Unit", GAME_IMPERFECT_GRAPHICS ) |
| 421 | 411 | CONS( 1996, drpcjr, nes, 0, famicom, nes, 0, 0, "Bung", "Doctor PC Jr", GAME_IMPERFECT_GRAPHICS ) |
| 422 | 412 | CONS( 199?, dendy, nes, 0, dendy, nes, 0, 0, "Steepler", "Dendy Classic", GAME_IMPERFECT_GRAPHICS ) |