1 // license:BSD-3-Clause 2 // copyright-holders:Brad Oliver,Fabio Priuli 3 /***************************************************************************** 4 5 nes.h 6 7 Nintendo Entertainment System / Famicom 8 9 ****************************************************************************/ 10 11 #ifndef MAME_INCLUDES_NES_H 12 #define MAME_INCLUDES_NES_H 13 14 #pragma once 15 16 17 #include "bus/nes/disksys.h" 18 #include "bus/nes/nes_slot.h" 19 #include "bus/nes/nes_carts.h" 20 #include "bus/nes_ctrl/ctrl.h" 21 #include "video/ppu2c0x.h" 22 #include "screen.h" 23 24 /*************************************************************************** 25 CONSTANTS 26 ***************************************************************************/ 27 28 #define NES_BATTERY_SIZE 0x2000 29 30 /*************************************************************************** 31 TYPE DEFINITIONS 32 ***************************************************************************/ 33 34 /*PPU fast banking constants and structures */ 35 36 #define CHRROM 0 37 #define CHRRAM 1 38 39 40 /*PPU nametable fast banking constants and structures */ 41 42 #define CIRAM 0 43 #define ROM 1 44 #define EXRAM 2 45 #define MMC5FILL 3 46 #define CART_NTRAM 4 47 48 #define NES_BATTERY 0 49 #define NES_WRAM 1 50 51 class nes_base_state : public driver_device 52 { 53 public: nes_base_state(const machine_config & mconfig,device_type type,const char * tag)54 nes_base_state(const machine_config &mconfig, device_type type, const char *tag) : 55 driver_device(mconfig, type, tag), 56 m_maincpu(*this, "maincpu"), 57 m_ctrl1(*this, "ctrl1"), 58 m_ctrl2(*this, "ctrl2") 59 { } 60 61 required_device<cpu_device> m_maincpu; 62 optional_device<nes_control_port_device> m_ctrl1; 63 optional_device<nes_control_port_device> m_ctrl2; 64 65 uint8_t nes_in0_r(); 66 uint8_t nes_in1_r(); 67 void nes_in0_w(uint8_t data); 68 }; 69 70 class nes_state : public nes_base_state 71 { 72 public: nes_state(const machine_config & mconfig,device_type type,const char * tag)73 nes_state(const machine_config &mconfig, device_type type, const char *tag) : 74 nes_base_state(mconfig, type, tag), 75 m_ppu(*this, "ppu"), 76 m_screen(*this, "screen"), 77 m_exp(*this, "exp"), 78 m_cartslot(*this, "nes_slot"), 79 m_disk(*this, "disk") 80 { } 81 82 83 int nes_ppu_vidaccess(int address, int data); 84 85 86 uint8_t fc_in0_r(); 87 uint8_t fc_in1_r(); 88 void fc_in0_w(uint8_t data); 89 void nes_vh_sprite_dma_w(address_space &space, uint8_t data); 90 virtual void machine_start() override; 91 virtual void machine_reset() override; 92 virtual void video_start() override; 93 virtual void video_reset() override; 94 uint32_t screen_update_nes(screen_device &screen, bitmap_rgb32 &bitmap, const rectangle &cliprect); 95 void screen_vblank_nes(int state); 96 97 void init_famicom(); 98 99 // these are needed until we modernize the FDS controller 100 DECLARE_MACHINE_START(fds); 101 DECLARE_MACHINE_START(famitwin); 102 DECLARE_MACHINE_RESET(fds); 103 DECLARE_MACHINE_RESET(famitwin); 104 void setup_disk(nes_disksys_device *slot); 105 106 void suborkbd(machine_config &config); 107 void famipalc(machine_config &config); 108 void famicom(machine_config &config); 109 void famitwin(machine_config &config); 110 void nespal(machine_config &config); 111 void nespalc(machine_config &config); 112 void nes(machine_config &config); 113 void fds(machine_config &config); 114 void nes_map(address_map &map); 115 private: 116 memory_bank *m_prg_bank_mem[5]; 117 118 /* video-related */ 119 int m_last_frame_flip; 120 121 /* misc */ 122 ioport_port *m_io_disksel; 123 124 uint8_t *m_vram; 125 std::unique_ptr<uint8_t[]> m_ciram; //PPU nametable RAM - external to PPU! 126 127 128 required_device<ppu2c0x_device> m_ppu; 129 required_device<screen_device> m_screen; 130 optional_device<nes_control_port_device> m_exp; 131 optional_device<nes_cart_slot_device> m_cartslot; 132 optional_device<nes_disksys_device> m_disk; 133 }; 134 135 #endif // MAME_INCLUDES_NES_H 136