src/mess/machine/c64_neoram.c
| r0 | r14935 | |
| 1 | /**********************************************************************
|
| 2 | |
| 3 | NeoRAM cartridge emulation
|
| 4 | |
| 5 | Copyright MESS Team.
|
| 6 | Visit http://mamedev.org for licensing and usage restrictions.
|
| 7 | |
| 8 | **********************************************************************/
|
| 9 | |
| 10 | #include "c64_neoram.h"
|
| 11 | |
| 12 | |
| 13 | |
| 14 | //**************************************************************************
|
| 15 | // DEVICE DEFINITIONS
|
| 16 | //**************************************************************************
|
| 17 | |
| 18 | const device_type C64_NEORAM = &device_creator<c64_neoram_cartridge_device>;
|
| 19 | |
| 20 | |
| 21 | |
| 22 | //**************************************************************************
|
| 23 | // LIVE DEVICE
|
| 24 | //**************************************************************************
|
| 25 | |
| 26 | //-------------------------------------------------
|
| 27 | // c64_neoram_cartridge_device - constructor
|
| 28 | //-------------------------------------------------
|
| 29 | |
| 30 | c64_neoram_cartridge_device::c64_neoram_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
|
| 31 | device_t(mconfig, C64_NEORAM, "C64 NeoRAM cartridge", tag, owner, clock),
|
| 32 | device_c64_expansion_card_interface(mconfig, *this),
|
| 33 | device_nvram_interface(mconfig, *this)
|
| 34 | {
|
| 35 | }
|
| 36 | |
| 37 | |
| 38 | //-------------------------------------------------
|
| 39 | // device_start - device-specific startup
|
| 40 | //-------------------------------------------------
|
| 41 | |
| 42 | void c64_neoram_cartridge_device::device_start()
|
| 43 | {
|
| 44 | // allocate memory
|
| 45 | c64_nvram_pointer(machine(), 0x200000);
|
| 46 | |
| 47 | // state saving
|
| 48 | save_item(NAME(m_bank));
|
| 49 | }
|
| 50 | |
| 51 | |
| 52 | //-------------------------------------------------
|
| 53 | // device_reset - device-specific reset
|
| 54 | //-------------------------------------------------
|
| 55 | |
| 56 | void c64_neoram_cartridge_device::device_reset()
|
| 57 | {
|
| 58 | m_bank = 0;
|
| 59 | }
|
| 60 | |
| 61 | |
| 62 | //-------------------------------------------------
|
| 63 | // c64_cd_r - cartridge data read
|
| 64 | //-------------------------------------------------
|
| 65 | |
| 66 | UINT8 c64_neoram_cartridge_device::c64_cd_r(address_space &space, offs_t offset, int roml, int romh, int io1, int io2)
|
| 67 | {
|
| 68 | UINT8 data = 0;
|
| 69 | |
| 70 | if (!io1)
|
| 71 | {
|
| 72 | offs_t addr = (m_bank << 8) | (offset & 0xff);
|
| 73 | data = m_nvram[addr];
|
| 74 | }
|
| 75 | |
| 76 | return data;
|
| 77 | }
|
| 78 | |
| 79 | |
| 80 | //-------------------------------------------------
|
| 81 | // c64_cd_w - cartridge data write
|
| 82 | //-------------------------------------------------
|
| 83 | |
| 84 | void c64_neoram_cartridge_device::c64_cd_w(address_space &space, offs_t offset, UINT8 data, int roml, int romh, int io1, int io2)
|
| 85 | {
|
| 86 | if (!io1)
|
| 87 | {
|
| 88 | offs_t addr = (m_bank << 8) | (offset & 0xff);
|
| 89 | m_nvram[addr] = data;
|
| 90 | }
|
| 91 | else if (!io2)
|
| 92 | {
|
| 93 | if (BIT(offset, 0))
|
| 94 | {
|
| 95 | m_bank = ((data & 0x7f) << 6) | (m_bank & 0x3f);
|
| 96 | }
|
| 97 | else
|
| 98 | {
|
| 99 | m_bank = (m_bank & 0x1fc0) | (data & 0x3f);
|
| 100 | }
|
| 101 | }
|
| 102 | }
|
src/mess/machine/c64_neoram.h
| r0 | r14935 | |
| 1 | /**********************************************************************
|
| 2 | |
| 3 | NeoRAM cartridge emulation
|
| 4 | |
| 5 | Copyright MESS Team.
|
| 6 | Visit http://mamedev.org for licensing and usage restrictions.
|
| 7 | |
| 8 | **********************************************************************/
|
| 9 | |
| 10 | #pragma once
|
| 11 | |
| 12 | #ifndef __NEORAM__
|
| 13 | #define __NEORAM__
|
| 14 | |
| 15 | |
| 16 | #include "emu.h"
|
| 17 | #include "machine/c64exp.h"
|
| 18 | |
| 19 | |
| 20 | |
| 21 | //**************************************************************************
|
| 22 | // TYPE DEFINITIONS
|
| 23 | //**************************************************************************
|
| 24 | |
| 25 | // ======================> c64_neoram_cartridge_device
|
| 26 | |
| 27 | class c64_neoram_cartridge_device : public device_t,
|
| 28 | public device_c64_expansion_card_interface,
|
| 29 | public device_nvram_interface
|
| 30 | {
|
| 31 | public:
|
| 32 | // construction/destruction
|
| 33 | c64_neoram_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
|
| 34 | |
| 35 | protected:
|
| 36 | // device-level overrides
|
| 37 | virtual void device_start();
|
| 38 | virtual void device_reset();
|
| 39 | virtual void device_config_complete() { m_shortname = "c64_neoram"; }
|
| 40 | |
| 41 | // device_nvram_interface overrides
|
| 42 | virtual void nvram_default() { }
|
| 43 | virtual void nvram_read(emu_file &file) { if (m_nvram != NULL) { file.read(m_nvram, m_nvram_size); } }
|
| 44 | virtual void nvram_write(emu_file &file) { if (m_nvram != NULL) { file.write(m_nvram, m_nvram_size); } }
|
| 45 | |
| 46 | // device_c64_expansion_card_interface overrides
|
| 47 | virtual UINT8 c64_cd_r(address_space &space, offs_t offset, int roml, int romh, int io1, int io2);
|
| 48 | virtual void c64_cd_w(address_space &space, offs_t offset, UINT8 data, int roml, int romh, int io1, int io2);
|
| 49 | |
| 50 | private:
|
| 51 | UINT16 m_bank;
|
| 52 | };
|
| 53 | |
| 54 | |
| 55 | // device type definition
|
| 56 | extern const device_type C64_NEORAM;
|
| 57 | |
| 58 | |
| 59 | #endif
|