Previous 15994 Revisions Next

r6734 Thursday 24th December, 2009 at 15:16:17 UTC by Miodrag Milanović
NES Famicom floppy moved to MAME device, note that it works only if mount during after driver boot for now.
[src/mess]mess.mak
[src/mess/drivers]nes.c
[src/mess/formats]nes_dsk.c* nes_dsk.h*
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_ines.c nes_mmc.c

src/mess/includes/nes.h
r6733r6734
9696MACHINE_START( nes );
9797MACHINE_RESET( nes );
9898
99MACHINE_START( famicom );
100DRIVER_INIT( famicom );
101
99102READ8_HANDLER( nes_IN0_r );
100103READ8_HANDLER( nes_IN1_r );
101104
src/mess/machine/nes.c
r6733r6734
55#include "machine/nes_mmc.h"
66#include "sound/nes_apu.h"
77#include "devices/cartslot.h"
8#include "devices/flopdrv.h"
9#include "formats/flopimg.h"
810#include "image.h"
911#include "hash.h"
1012
r6733r6734
221223   cputag_reset(machine, "maincpu");
222224}
223225
226emu_timer   *nes_irq_timer;
227
228static 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
224234MACHINE_START( nes )
225235{
226236   init_nes_core(machine);
227237   add_exit_callback(machine, nes_machine_stop);
238   
239   nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL);
228240}
229241
230242static void nes_machine_stop( running_machine *machine )
r6733r6734
913925}
914926
915927
916DEVICE_START( nes_disk )
928static void nes_load_proc(const device_config *image)
917929{
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
938static 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
945DRIVER_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
954MACHINE_START( famicom )
955{   
918956   /* clear some of the cart variables we don't use */
919957   nes.trainer = 0;
920958   nes.battery = 0;
r6733r6734
926964   nes.four_screen_vram = 0;
927965   nes.hard_mirroring = 0;
928966
929   nes_fds.sides = 0;
930   nes_fds.data = NULL;
967   nes_fds.sides = 0;   
968   MACHINE_START_CALL( nes );
931969}
932
933
934DEVICE_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
964DEVICE_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
r6733r6734
263263
264264static int mapper_warning;
265265
266static emu_timer   *nes_irq_timer;
267266
268
269267/*************************************************************
270268
271269    Base emulation (see drivers/nes.c):
r6733r6734
287285
288286*************************************************************/
289287
290static 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
296288WRITE8_HANDLER( nes_chr_w )
297289{
298290   int bank = offset >> 10;
r6733r6734
15841576   ppu2c0x_set_scanline_callback(state->ppu, mapper ? mapper->mmc_scanline : NULL);
15851577   ppu2c0x_set_hblank_callback(state->ppu, mapper ? mapper->mmc_hblank : NULL);
15861578
1587   if (!nes_irq_timer)
1588      nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL);
1589
15901579   mapper_warning = 0;
15911580
15921581   nes_mmc5_vram_control = 0;
r6733r6734
16511640   ppu2c0x_set_scanline_callback(state->ppu, unif_board ? unif_board->mmc_scanline : NULL);
16521641   ppu2c0x_set_hblank_callback(state->ppu, unif_board ? unif_board->mmc_hblank : NULL);
16531642
1654   if (!nes_irq_timer)
1655      nes_irq_timer = timer_alloc(machine, nes_irq_callback, NULL);
16561643
16571644   /* Point the WRAM/battery area to the first RAM bank */
16581645   memory_set_bankptr(machine, "bank5", &nes.wram[0x0000]);
src/mess/machine/nes_ines.c
r6733r6734
28292829
28302830*************************************************************/
28312831
2832extern emu_timer   *nes_irq_timer;
2833
28322834static WRITE8_HANDLER( mapper42_w )
28332835{
28342836   LOG_MMC(("mapper42_w, offset: %04x, data: %02x\n", offset, data));
src/mess/formats/nes_dsk.c
r0r6734
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
22static 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
46static FLOPPY_CONSTRUCT( nes_dsk_construct )
47{
48   return FLOPPY_ERROR_SUCCESS;
49}
50
51
52/*****************************************************************************
53 NES floppy options
54*****************************************************************************/
55
56FLOPPY_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/formats/nes_dsk.h
r0r6734
1/*********************************************************************
2
3    formats/nes_dsk.h
4
5    NES disk images
6
7*********************************************************************/
8
9#ifndef NES_DSK_H_
10#define NES_DSK_H_
11
12#include "formats/flopimg.h"
13
14FLOPPY_OPTIONS_EXTERN(nes_only);
15
16#endif /*NES_DSK_H_*/
src/mess/mess.mak
r6733r6734
10711071   $(MESS_MACHINE)/nes_mmc.o   \
10721072   $(MAME_VIDEO)/ppu2c0x.o      \
10731073   $(MESS_VIDEO)/nes.o         \
1074   $(MESS_FORMATS)/nes_dsk.o   \
10741075   $(MESS_MACHINE)/nes.o      \
10751076   $(MESS_DRIVERS)/nes.o      \
10761077   $(MAME_AUDIO)/snes.o      \
src/mess/drivers/nes.c
r6733r6734
1717#include "cpu/m6502/m6502.h"
1818#include "devices/cartslot.h"
1919#include "sound/nes_apu.h"
20#include "devices/flopdrv.h"
21#include "formats/nes_dsk.h"
2022
2123
2224static READ8_DEVICE_HANDLER( psg_4015_r )
r6733r6734
182184   ppu_nmi
183185};
184186
187static 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};
185198
199
186200static MACHINE_DRIVER_START( nes )
187201   /* basic machine hardware */
188202   MDRV_CPU_ADD("maincpu", N2A03, NTSC_CLOCK)
r6733r6734
268282
269283static MACHINE_DRIVER_START( famicom )
270284   MDRV_IMPORT_FROM( nes )
285   MDRV_MACHINE_START( famicom )
271286
272287   MDRV_CARTSLOT_MODIFY("cart")
273288   MDRV_CARTSLOT_EXTENSION_LIST("nes,unf")
274289   MDRV_CARTSLOT_NOT_MANDATORY
275290   MDRV_CARTSLOT_LOAD(nes_cart)
276291   MDRV_CARTSLOT_PARTIALHASH(nes_partialhash)
292   
293   MDRV_FLOPPY_DRIVE_ADD(FLOPPY_0, nes_floppy_config)
277294MACHINE_DRIVER_END
278295
279296
r6733r6734
379396   ROM_FILL( 0x0000, 0x10000, 0x00 )
380397ROM_END
381398
382
383static 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
405static SYSTEM_CONFIG_START(famicom)
406   CONFIG_DEVICE(famicom_floppy_getinfo)
407SYSTEM_CONFIG_END
408
409399/***************************************************************************
410400
411401  Game driver(s)
r6733r6734
415405/*     YEAR  NAME      PARENT  COMPAT MACHINE   INPUT    INIT   CONFIG   COMPANY       FULLNAME */
416406CONS( 1985, nes,       0,      0,     nes,      nes,     0,     0,       "Nintendo",  "Nintendo Entertainment System / Famicom (NTSC)", GAME_IMPERFECT_GRAPHICS )
417407CONS( 1987, nespal,    nes,    0,     nespal,   nes,     0,     0,       "Nintendo",  "Nintendo Entertainment System (PAL)", GAME_IMPERFECT_GRAPHICS )
418CONS( 1983, famicom,   nes,    0,     famicom,  famicom, 0,     famicom, "Nintendo",  "Famicom Disk System", GAME_IMPERFECT_GRAPHICS )
419CONS( 1986, famitwin,  nes,    0,     famicom,  famicom, 0,     famicom, "Sharp",     "Famicom Twin", GAME_IMPERFECT_GRAPHICS )
408CONS( 1983, famicom,   nes,    0,     famicom,  famicom, famicom,    0,        "Nintendo",  "Famicom Disk System", GAME_IMPERFECT_GRAPHICS )
409CONS( 1986, famitwin,  nes,    0,     famicom,  famicom, famicom,    0,        "Sharp",     "Famicom Twin", GAME_IMPERFECT_GRAPHICS )
420410CONS( 198?, m82,       nes,    0,     nes,      nes,     0,     0,       "Nintendo",  "M82 Display Unit", GAME_IMPERFECT_GRAPHICS )
421411CONS( 1996, drpcjr,    nes,    0,     famicom,  nes,     0,     0,       "Bung",      "Doctor PC Jr", GAME_IMPERFECT_GRAPHICS )
422412CONS( 199?, dendy,     nes,    0,     dendy,    nes,     0,     0,       "Steepler",  "Dendy Classic", GAME_IMPERFECT_GRAPHICS )

Previous 15994 Revisions Next


© 1998-2018 The MESS Team