Previous 199869 Revisions Next

r19140 Sunday 25th November, 2012 at 14:40:31 UTC by Nathan Woods
[NES MESS] Minor cleanups
[src/mess/drivers]nes.c
[src/mess/includes]nes.h
[src/mess/machine]nes.c nes_mmc.c

trunk/src/mess/machine/nes_mmc.c
r19139r19140
237237
238238void nes_carts_state::wram_bank(int bank, int source)
239239{
240   nes_state *state = machine().driver_data<nes_state>();
241
240242   assert(m_battery || m_prg_ram);
241243   if (source == NES_BATTERY)
242244   {
r19139r19140
248250      bank &= (m_wram_size / 0x2000) - 1;
249251      m_prg_bank[4] = m_prgram_bank5_start + bank;
250252   }
251   membank("bank5")->set_entry(m_prg_bank[4]);
253   state->update_prg_banks(4, 4);
252254}
253255
254256INLINE void prg_bank_refresh( running_machine &machine )
255257{
256258   nes_state *state = machine.driver_data<nes_state>();
257   state->membank("bank1")->set_entry(state->m_prg_bank[0]);
258   state->membank("bank2")->set_entry(state->m_prg_bank[1]);
259   state->membank("bank3")->set_entry(state->m_prg_bank[2]);
260   state->membank("bank4")->set_entry(state->m_prg_bank[3]);
259   state->update_prg_banks(0, 3);
261260}
262261
263262/* PRG ROM in 8K, 16K or 32K blocks */
trunk/src/mess/machine/nes.c
r19139r19140
1/*****************************************************************************
2
3   nes.c
4
5   Nintendo Entertainment System (Famicom)
6
7 ****************************************************************************/
8
19#include "emu.h"
210#include "crsshair.h"
311#include "cpu/m6502/m6502.h"
r19139r19140
2331    FUNCTION PROTOTYPES
2432***************************************************************************/
2533
26static void nes_machine_stop(running_machine &machine);
2734
28
2935static void fds_irq(device_t *device, int scanline, int vblank, int blanked);
3036
3137/***************************************************************************
r19139r19140
284290   machine.save().register_postload(save_prepost_delegate(FUNC(nes_banks_restore), state));
285291}
286292
293
294//-------------------------------------------------
295//  machine_start
296//-------------------------------------------------
297
287298void nes_state::machine_start()
288299{
300   m_ppu = machine().device<ppu2c0x_device>("ppu");
289301
290   m_ppu = machine().device<ppu2c0x_device>("ppu");
291302   init_nes_core();
292   machine().add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(nes_machine_stop),&machine()));
293303
294   m_maincpu = machine().device<cpu_device>("maincpu");
295   m_sound = machine().device("nessound");
296   m_cart = machine().device("cart");
304   m_maincpu         = machine().device<cpu_device>("maincpu");
305   m_sound            = machine().device("nessound");
306   m_cart            = machine().device("cart");
307   m_io_ctrlsel      = ioport("CTRLSEL");
308   m_prg_bank_mem[0]   = membank("bank1");
309   m_prg_bank_mem[1]   = membank("bank2");
310   m_prg_bank_mem[2]   = membank("bank3");
311   m_prg_bank_mem[3]   = membank("bank4");
312   m_prg_bank_mem[4]   = membank("bank5");
297313
298314   // If we're starting famicom with no disk inserted, we still haven't initialized the VRAM needed for
299315   // video emulation, so we need to take care of it now
r19139r19140
312328   nes_state_register(machine());
313329}
314330
315static void nes_machine_stop( running_machine &machine )
331
332//-------------------------------------------------
333//  machine_stop
334//-------------------------------------------------
335
336void nes_state::machine_stop()
316337{
317   nes_state *state = machine.driver_data<nes_state>();
318   device_image_interface *image = dynamic_cast<device_image_interface *>(state->m_cart);
338   device_image_interface *image = dynamic_cast<device_image_interface *>(m_cart);
319339   /* Write out the battery file if necessary */
320   if (state->m_battery)
321      image->battery_save(state->m_battery_ram, state->m_battery_size);
340   if (m_battery)
341      image->battery_save(m_battery_ram, m_battery_size);
322342
323   if (state->m_mapper_bram_size)
324      image->battery_save(state->m_mapper_bram, state->m_mapper_bram_size);
343   if (m_mapper_bram_size)
344      image->battery_save(m_mapper_bram, m_mapper_bram_size);
325345}
326346
327347
328348
349//-------------------------------------------------
350//  update_prg_banks
351//-------------------------------------------------
352
353void nes_state::update_prg_banks(int prg_bank_start, int prg_bank_end)
354{
355   for (int prg_bank = prg_bank_start; prg_bank <= prg_bank_end; prg_bank++)
356   {
357      assert(prg_bank >= 0);
358      assert(prg_bank < ARRAY_LENGTH(m_prg_bank));
359      assert(prg_bank < ARRAY_LENGTH(m_prg_bank_mem));
360
361      m_prg_bank_mem[prg_bank]->set_entry(m_prg_bank[prg_bank]);
362   }
363}
364
365
366
329367READ8_MEMBER(nes_state::nes_IN0_r)
330368{
331   int cfg = ioport("CTRLSEL")->read();
369   int cfg = m_io_ctrlsel->read();
332370   int ret;
333371
334372   if ((cfg & 0x000f) >= 0x08)   // for now we treat the FC keyboard separately from other inputs!
r19139r19140
397435
398436READ8_MEMBER(nes_state::nes_IN1_r)
399437{
400   int cfg = ioport("CTRLSEL")->read();
438   int cfg = m_io_ctrlsel->read();
401439   int ret;
402440
403441   if ((cfg & 0x000f) == 0x08)   // for now we treat the FC keyboard separately from other inputs!
r19139r19140
525563
526564TIMER_CALLBACK_MEMBER(nes_state::lightgun_tick)
527565{
528   if ((machine().root_device().ioport("CTRLSEL")->read() & 0x000f) == 0x0002)
566   if ((m_io_ctrlsel->read() & 0x000f) == 0x0002)
529567   {
530568      /* enable lightpen crosshair */
531569      crosshair_set_screen(machine(), 0, CROSSHAIR_SCREEN_ALL);
r19139r19140
536574      crosshair_set_screen(machine(), 0, CROSSHAIR_SCREEN_NONE);
537575   }
538576
539   if ((machine().root_device().ioport("CTRLSEL")->read() & 0x00f0) == 0x0030)
577   if ((m_io_ctrlsel->read() & 0x00f0) == 0x0030)
540578   {
541579      /* enable lightpen crosshair */
542580      crosshair_set_screen(machine(), 1, CROSSHAIR_SCREEN_ALL);
r19139r19140
550588
551589WRITE8_MEMBER(nes_state::nes_IN0_w)
552590{
553   int cfg = ioport("CTRLSEL")->read();
591   int cfg = m_io_ctrlsel->read();
554592
555593   /* Check if lightgun has been chosen as input: if so, enable crosshair */
556594   machine().scheduler().timer_set(attotime::zero, timer_expired_delegate(FUNC(nes_state::lightgun_tick),this));
trunk/src/mess/includes/nes.h
r19139r19140
11/*****************************************************************************
2 *
3 * includes/nes.h
4 *
5 * Nintendo Entertainment System (Famicom)
6 *
2
3   nes.h
4
5   Nintendo Entertainment System (Famicom)
6
77 ****************************************************************************/
88
99#ifndef NES_H_
r19139r19140
6868   void pcb_handlers_setup();
6969   int pcb_initialize(int idx);
7070   int nes_pcb_reset();
71   void update_prg_banks(int prg_bank_start, int prg_bank_end);
7172
7273   DECLARE_WRITE8_MEMBER(nes_chr_w);
7374   DECLARE_READ8_MEMBER(nes_chr_r);
r19139r19140
8485   read8_delegate    m_mmc_read_mid;
8586   read8_delegate    m_mmc_read;
8687
87   /* devices */
88//  cpu_device        *m_maincpu;
89//  ppu2c0x_device    *m_ppu;
90//  device_t          *m_sound;
91   device_t          *m_cart;
92//  emu_timer         *m_irq_timer;
93
9488   /***** FDS-floppy related *****/
9589
9690   int     m_disk_expansion;
r19139r19140
120114   DECLARE_WRITE8_MEMBER(nes_vh_sprite_dma_w);
121115   DECLARE_DRIVER_INIT(famicom);
122116   virtual void machine_start();
117   virtual void machine_stop();
123118   virtual void machine_reset();
124119   virtual void video_start();
125120   virtual void palette_init();
r19139r19140
129124   DECLARE_READ8_MEMBER(psg_4015_r);
130125   DECLARE_WRITE8_MEMBER(psg_4015_w);
131126   DECLARE_WRITE8_MEMBER(psg_4017_w);
127
128private:
129   /* devices */
130//  cpu_device        *m_maincpu;
131//  ppu2c0x_device    *m_ppu;
132//  device_t          *m_sound;
133   device_t          *m_cart;
134//  emu_timer         *m_irq_timer;
135   ioport_port       *m_io_ctrlsel;
136   memory_bank       *m_prg_bank_mem[5];
132137};
133138
134139/*----------- defined in machine/nes.c -----------*/
trunk/src/mess/drivers/nes.c
r19139r19140
406406INPUT_PORTS_END
407407
408408
409#ifdef UNUSED_FUNCTION
410/* This layout is not changed at runtime */
411gfx_layout nes_vram_charlayout =
412{
413    8,8,    /* 8*8 characters */
414    512,    /* 512 characters */
415    2,  /* 2 bits per pixel */
416    { 8*8, 0 }, /* the two bitplanes are separated */
417    { 0, 1, 2, 3, 4, 5, 6, 7 },
418    { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8 },
419    16*8    /* every char takes 16 consecutive bytes */
420};
421#endif
422
423409static const nes_interface nes_apu_interface =
424410{
425411   "maincpu"

Previous 199869 Revisions Next


© 1997-2024 The MAME Team