trunk/src/mess/machine/c64_turbo232.c
| r0 | r20776 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | CMD Turbo232 RS-232 cartridge emulation |
| 4 | |
| 5 | Copyright MESS Team. |
| 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | |
| 8 | **********************************************************************/ |
| 9 | |
| 10 | /* |
| 11 | |
| 12 | http://ar.c64.org/wiki/Turbo232_Programming.txt |
| 13 | |
| 14 | */ |
| 15 | |
| 16 | #include "c64_turbo232.h" |
| 17 | |
| 18 | |
| 19 | |
| 20 | //************************************************************************** |
| 21 | // MACROS/CONSTANTS |
| 22 | //************************************************************************** |
| 23 | |
| 24 | #define MOS6551_TAG "mos6551" |
| 25 | |
| 26 | |
| 27 | |
| 28 | //************************************************************************** |
| 29 | // DEVICE DEFINITIONS |
| 30 | //************************************************************************** |
| 31 | |
| 32 | const device_type C64_TURBO232 = &device_creator<c64_turbo232_cartridge_device>; |
| 33 | |
| 34 | |
| 35 | //------------------------------------------------- |
| 36 | // MACHINE_CONFIG_FRAGMENT( c64_turbo232 ) |
| 37 | //------------------------------------------------- |
| 38 | |
| 39 | static MACHINE_CONFIG_FRAGMENT( c64_turbo232 ) |
| 40 | MCFG_MOS6551_ADD(MOS6551_TAG, XTAL_3_6864MHz, DEVWRITELINE(DEVICE_SELF, c64_turbo232_cartridge_device, acia_irq_w)) |
| 41 | MACHINE_CONFIG_END |
| 42 | |
| 43 | |
| 44 | //------------------------------------------------- |
| 45 | // machine_config_additions - device-specific |
| 46 | // machine configurations |
| 47 | //------------------------------------------------- |
| 48 | |
| 49 | machine_config_constructor c64_turbo232_cartridge_device::device_mconfig_additions() const |
| 50 | { |
| 51 | return MACHINE_CONFIG_NAME( c64_turbo232 ); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | //------------------------------------------------- |
| 56 | // INPUT_PORTS( c64_turbo232 ) |
| 57 | //------------------------------------------------- |
| 58 | |
| 59 | static INPUT_PORTS_START( c64_turbo232 ) |
| 60 | PORT_START("CS") |
| 61 | PORT_DIPNAME( 0x03, 0x01, "Base Address" ) |
| 62 | PORT_DIPSETTING( 0x00, "$D700 (C128)" ) |
| 63 | PORT_DIPSETTING( 0x01, "$DE00" ) |
| 64 | PORT_DIPSETTING( 0x02, "$DF00" ) |
| 65 | |
| 66 | PORT_START("IRQ") |
| 67 | PORT_DIPNAME( 0x01, 0x01, "Interrupt" ) |
| 68 | PORT_DIPSETTING( 0x00, "IRQ (C128)" ) |
| 69 | PORT_DIPSETTING( 0x01, "NMI" ) |
| 70 | INPUT_PORTS_END |
| 71 | |
| 72 | |
| 73 | //------------------------------------------------- |
| 74 | // input_ports - device-specific input ports |
| 75 | //------------------------------------------------- |
| 76 | |
| 77 | ioport_constructor c64_turbo232_cartridge_device::device_input_ports() const |
| 78 | { |
| 79 | return INPUT_PORTS_NAME( c64_turbo232 ); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | |
| 84 | //************************************************************************** |
| 85 | // LIVE DEVICE |
| 86 | //************************************************************************** |
| 87 | |
| 88 | //------------------------------------------------- |
| 89 | // c64_turbo232_cartridge_device - constructor |
| 90 | //------------------------------------------------- |
| 91 | |
| 92 | c64_turbo232_cartridge_device::c64_turbo232_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : |
| 93 | device_t(mconfig, C64_TURBO232, "C64 Turbo232 cartridge", tag, owner, clock), |
| 94 | device_c64_expansion_card_interface(mconfig, *this), |
| 95 | m_acia(*this, MOS6551_TAG), |
| 96 | m_io_cs(*this, "CS"), |
| 97 | m_io_irq(*this, "IRQ") |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | |
| 102 | //------------------------------------------------- |
| 103 | // device_start - device-specific startup |
| 104 | //------------------------------------------------- |
| 105 | |
| 106 | void c64_turbo232_cartridge_device::device_start() |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | |
| 111 | //------------------------------------------------- |
| 112 | // device_reset - device-specific reset |
| 113 | //------------------------------------------------- |
| 114 | |
| 115 | void c64_turbo232_cartridge_device::device_reset() |
| 116 | { |
| 117 | m_acia->reset(); |
| 118 | |
| 119 | m_cs = m_io_cs->read(); |
| 120 | m_irq = m_io_irq->read(); |
| 121 | |
| 122 | m_es = 0; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | //------------------------------------------------- |
| 127 | // c64_cd_r - cartridge data read |
| 128 | //------------------------------------------------- |
| 129 | |
| 130 | UINT8 c64_turbo232_cartridge_device::c64_cd_r(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2) |
| 131 | { |
| 132 | if (((m_cs == DE00) && !io1) || ((m_cs == DF00) && !io2) || |
| 133 | ((m_cs == D700) && ((offset & 0xff00) == 0xd700))) |
| 134 | { |
| 135 | if (!(offset & 0xe0)) |
| 136 | { |
| 137 | switch (offset & 0x07) |
| 138 | { |
| 139 | case 0: case 1: case 2: case 3: |
| 140 | data = m_acia->read(space, offset & 0x03); |
| 141 | break; |
| 142 | |
| 143 | case 7: |
| 144 | data = m_es; |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | return data; |
| 150 | } |
| 151 | |
| 152 | |
| 153 | //------------------------------------------------- |
| 154 | // c64_cd_w - cartridge data write |
| 155 | //------------------------------------------------- |
| 156 | |
| 157 | void c64_turbo232_cartridge_device::c64_cd_w(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2) |
| 158 | { |
| 159 | if (((m_cs == DE00) && !io1) || ((m_cs == DF00) && !io2) || |
| 160 | ((m_cs == D700) && ((offset & 0xff00) == 0xd700))) |
| 161 | { |
| 162 | if (!(offset & 0xe0)) |
| 163 | { |
| 164 | switch (offset & 0x07) |
| 165 | { |
| 166 | case 0: case 1: case 2: |
| 167 | m_acia->write(space, offset & 0x03, data); |
| 168 | break; |
| 169 | |
| 170 | case 3: |
| 171 | m_acia->write(space, offset & 0x03, data); |
| 172 | |
| 173 | if (data & 0x0f) |
| 174 | m_es &= ~ES_M; |
| 175 | else |
| 176 | m_es |= ES_M; |
| 177 | break; |
| 178 | |
| 179 | case 7: |
| 180 | if (m_es & ES_M) |
| 181 | { |
| 182 | data = m_es; |
| 183 | |
| 184 | switch (m_es & ES_S_MASK) |
| 185 | { |
| 186 | case ES_S_230400: m_acia->set_rxc(230400*16); break; |
| 187 | case ES_S_115200: m_acia->set_rxc(115200*16); break; |
| 188 | case ES_S_57600: m_acia->set_rxc(57600*16); break; |
| 189 | case ES_S_UNDEFINED: m_acia->set_rxc(0); break; |
| 190 | } |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | |
| 198 | //------------------------------------------------- |
| 199 | // acia_irq_w - |
| 200 | //------------------------------------------------- |
| 201 | |
| 202 | WRITE_LINE_MEMBER( c64_turbo232_cartridge_device::acia_irq_w ) |
| 203 | { |
| 204 | switch (m_irq) |
| 205 | { |
| 206 | case IRQ: m_slot->irq_w(state); break; |
| 207 | case NMI: m_slot->nmi_w(state); break; |
| 208 | } |
| 209 | } |
trunk/src/mess/machine/c64_turbo232.h
| r0 | r20776 | |
| 1 | /********************************************************************** |
| 2 | |
| 3 | CMD Turbo232 RS-232 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 __TURBO232__ |
| 13 | #define __TURBO232__ |
| 14 | |
| 15 | |
| 16 | #include "emu.h" |
| 17 | #include "machine/c64exp.h" |
| 18 | #include "machine/mos6551.h" |
| 19 | |
| 20 | |
| 21 | |
| 22 | //************************************************************************** |
| 23 | // TYPE DEFINITIONS |
| 24 | //************************************************************************** |
| 25 | |
| 26 | // ======================> c64_turbo232_cartridge_device |
| 27 | |
| 28 | class c64_turbo232_cartridge_device : public device_t, |
| 29 | public device_c64_expansion_card_interface |
| 30 | { |
| 31 | public: |
| 32 | // construction/destruction |
| 33 | c64_turbo232_cartridge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock); |
| 34 | |
| 35 | // optional information overrides |
| 36 | virtual machine_config_constructor device_mconfig_additions() const; |
| 37 | virtual ioport_constructor device_input_ports() const; |
| 38 | |
| 39 | DECLARE_WRITE_LINE_MEMBER( acia_irq_w ); |
| 40 | |
| 41 | protected: |
| 42 | // device-level overrides |
| 43 | virtual void device_config_complete() { m_shortname = "c64_turbo232"; } |
| 44 | virtual void device_start(); |
| 45 | virtual void device_reset(); |
| 46 | |
| 47 | // device_c64_expansion_card_interface overrides |
| 48 | virtual UINT8 c64_cd_r(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2); |
| 49 | virtual void c64_cd_w(address_space &space, offs_t offset, UINT8 data, int sphi2, int ba, int roml, int romh, int io1, int io2); |
| 50 | |
| 51 | private: |
| 52 | required_device<mos6551_device> m_acia; |
| 53 | required_ioport m_io_cs; |
| 54 | required_ioport m_io_irq; |
| 55 | |
| 56 | enum |
| 57 | { |
| 58 | D700 = 0, |
| 59 | DE00, |
| 60 | DF00 |
| 61 | }; |
| 62 | |
| 63 | enum |
| 64 | { |
| 65 | IRQ = 0, |
| 66 | NMI |
| 67 | }; |
| 68 | |
| 69 | enum |
| 70 | { |
| 71 | ES_S_230400 = 0x00, |
| 72 | ES_S_115200 = 0x01, |
| 73 | ES_S_57600 = 0x02, |
| 74 | ES_S_UNDEFINED = 0x03, |
| 75 | ES_S_MASK = 0x03, |
| 76 | ES_M = 0x04 |
| 77 | }; |
| 78 | |
| 79 | int m_cs; |
| 80 | int m_irq; |
| 81 | |
| 82 | UINT8 m_es; |
| 83 | }; |
| 84 | |
| 85 | |
| 86 | // device type definition |
| 87 | extern const device_type C64_TURBO232; |
| 88 | |
| 89 | |
| 90 | #endif |