src/mess/machine/zx8302.c
| r9767 | r9768 | |
| 9 | 9 | |
| 10 | 10 | /* |
| 11 | 11 | |
| 12 | | TODO: |
| 12 | TODO: |
| 13 | 13 | |
| 14 | | - microdrive |
| 15 | | - RTC register write |
| 16 | | - serial data latching? |
| 17 | | - transmit interrupt timing |
| 18 | | - interface interrupt |
| 14 | - set time |
| 15 | - read from microdrive |
| 16 | - write to microdrive |
| 17 | - DTR/CTS handling |
| 18 | - network |
| 19 | 19 | |
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | #include "emu.h" |
| 23 | | #include "zx8302.h" |
| 24 | | #include "devices/microdrv.h" |
| 25 | 23 | #include <time.h> |
| 24 | #include "devices/microdrv.h" |
| 25 | #include "machine/devhelpr.h" |
| 26 | #include "zx8302.h" |
| 26 | 27 | |
| 27 | | /*************************************************************************** |
| 28 | | PARAMETERS |
| 29 | | ***************************************************************************/ |
| 30 | 28 | |
| 29 | |
| 30 | //************************************************************************** |
| 31 | // MACROS / CONSTANTS |
| 32 | //************************************************************************** |
| 33 | |
| 31 | 34 | #define LOG 0 |
| 32 | 35 | |
| 36 | |
| 37 | // IPC serial state |
| 33 | 38 | enum |
| 34 | 39 | { |
| 35 | | ZX8302_IPC_START, |
| 36 | | ZX8302_IPC_DATA, |
| 37 | | ZX8302_IPC_STOP |
| 40 | IPC_START, |
| 41 | IPC_DATA, |
| 42 | IPC_STOP |
| 38 | 43 | }; |
| 39 | 44 | |
| 40 | | #define ZX8302_BAUD_19200 0x00 |
| 41 | | #define ZX8302_BAUD_9600 0x01 |
| 42 | | #define ZX8302_BAUD_4800 0x02 |
| 43 | | #define ZX8302_BAUD_2400 0x03 |
| 44 | | #define ZX8302_BAUD_1200 0x04 |
| 45 | | #define ZX8302_BAUD_600 0x05 |
| 46 | | #define ZX8302_BAUD_300 0x06 |
| 47 | | #define ZX8302_BAUD_75 0x07 |
| 48 | | #define ZX8302_BAUD_MASK 0x07 |
| 49 | 45 | |
| 50 | | #define ZX8302_MODE_SER1 0x00 |
| 51 | | #define ZX8302_MODE_SER2 0x08 |
| 52 | | #define ZX8302_MODE_MDV 0x10 |
| 53 | | #define ZX8302_MODE_NET 0x18 |
| 54 | | #define ZX8302_MODE_MASK 0x18 |
| 46 | // baud rate |
| 47 | static const int BAUD_19200 = 0x00; |
| 48 | static const int BAUD_9600 = 0x01; |
| 49 | static const int BAUD_4800 = 0x02; |
| 50 | static const int BAUD_2400 = 0x03; |
| 51 | static const int BAUD_1200 = 0x04; |
| 52 | static const int BAUD_600 = 0x05; |
| 53 | static const int BAUD_300 = 0x06; |
| 54 | static const int BAUD_75 = 0x07; |
| 55 | static const int BAUD_MASK = 0x07; |
| 55 | 56 | |
| 56 | | #define ZX8302_INT_GAP 0x01 |
| 57 | | #define ZX8302_INT_INTERFACE 0x02 |
| 58 | | #define ZX8302_INT_TRANSMIT 0x04 |
| 59 | | #define ZX8302_INT_FRAME 0x08 |
| 60 | | #define ZX8302_INT_EXTERNAL 0x10 |
| 61 | 57 | |
| 62 | | #define ZX8302_STATUS_NETWORK_PORT 0x01 |
| 63 | | #define ZX8302_STATUS_TX_BUFFER_FULL 0x02 |
| 64 | | #define ZX8302_STATUS_RX_BUFFER_FULL 0x04 |
| 65 | | #define ZX8302_STATUS_MICRODRIVE_GAP 0x08 |
| 58 | // transmit mode |
| 59 | static const int MODE_SER1 = 0x00; |
| 60 | static const int MODE_SER2 = 0x08; |
| 61 | static const int MODE_MDV = 0x10; |
| 62 | static const int MODE_NET = 0x18; |
| 63 | static const int MODE_MASK = 0x18; |
| 66 | 64 | |
| 67 | | #define ZX8302_TXD_START 0 |
| 68 | | #define ZX8302_TXD_STOP 9 |
| 69 | | #define ZX8302_TXD_STOP2 10 |
| 70 | 65 | |
| 71 | | /*************************************************************************** |
| 72 | | TYPE DEFINITIONS |
| 73 | | ***************************************************************************/ |
| 66 | // interrupts |
| 67 | static const int INT_GAP = 0x01; |
| 68 | static const int INT_INTERFACE = 0x02; |
| 69 | static const int INT_TRANSMIT = 0x04; |
| 70 | static const int INT_FRAME = 0x08; |
| 71 | static const int INT_EXTERNAL = 0x10; |
| 74 | 72 | |
| 75 | | typedef struct _zx8302_t zx8302_t; |
| 76 | | struct _zx8302_t |
| 77 | | { |
| 78 | | devcb_resolved_write_line out_ipl1l_func; |
| 79 | | devcb_resolved_write_line out_baudx4_func; |
| 80 | | devcb_resolved_write_line out_comdata_func; |
| 81 | 73 | |
| 82 | | /* registers */ |
| 83 | | UINT8 idr; /* IPC data register */ |
| 84 | | UINT8 tcr; /* transfer control register */ |
| 85 | | UINT8 tdr; /* transfer data register */ |
| 86 | | UINT8 irq; /* interrupt register */ |
| 87 | | UINT32 ctr; /* counter register */ |
| 88 | | UINT8 status; /* status register */ |
| 74 | // status register |
| 75 | static const int STATUS_NETWORK_PORT = 0x01; |
| 76 | static const int STATUS_TX_BUFFER_FULL = 0x02; |
| 77 | static const int STATUS_RX_BUFFER_FULL = 0x04; |
| 78 | static const int STATUS_MICRODRIVE_GAP = 0x08; |
| 89 | 79 | |
| 90 | | /* IPC communication state */ |
| 91 | | int comdata; /* communication data */ |
| 92 | | int comctl; /* communication control */ |
| 93 | | int ipc_state; /* communication state */ |
| 94 | | int ipc_rx; /* receiving data from IPC */ |
| 95 | | int ipc_busy; /* IPC busy */ |
| 96 | | int baudx4; /* IPC baud x4 */ |
| 97 | 80 | |
| 98 | | /* serial transmit state */ |
| 99 | | int tx_bits; /* bits transmitted */ |
| 100 | | int ser1_rxd; /* serial 1 receive */ |
| 101 | | int ser1_cts; /* serial 1 clear to send */ |
| 102 | | int ser2_txd; /* serial 2 transmit */ |
| 103 | | int ser2_dtr; /* serial 2 data terminal ready */ |
| 104 | | int netout; /* ZXNet output */ |
| 105 | | int netin; /* ZXNet input */ |
| 81 | // transmit bits |
| 82 | static const int TXD_START = 0; |
| 83 | static const int TXD_STOP = 9; |
| 84 | static const int TXD_STOP2 = 10; |
| 106 | 85 | |
| 107 | | /* microdrive state */ |
| 108 | | int mdrdw; /* read/write */ |
| 109 | | int mdselck; /* select clock */ |
| 110 | | int mdseld; /* select data */ |
| 111 | | int erase; /* erase head */ |
| 112 | 86 | |
| 113 | | int mdv_motor; /* selected motor */ |
| 114 | | int mdv_offset[8]; /* image offset */ |
| 87 | // Monday 1st January 1979 00:00:00 UTC |
| 88 | static const int RTC_BASE_ADJUST = 283996800; |
| 115 | 89 | |
| 116 | | UINT8 *mdv_image[8]; /* image */ |
| 117 | 90 | |
| 118 | | /* timers */ |
| 119 | | emu_timer *txd_timer; /* transmit timer */ |
| 120 | | emu_timer *ipc_timer; /* baud x4 timer */ |
| 121 | | emu_timer *rtc_timer; /* real time clock timer */ |
| 122 | | emu_timer *gap_timer; /* microdrive gap timer */ |
| 123 | | }; |
| 124 | 91 | |
| 125 | | /*************************************************************************** |
| 126 | | INLINE FUNCTIONS |
| 127 | | ***************************************************************************/ |
| 92 | //************************************************************************** |
| 93 | // DEVICE DEFINITIONS |
| 94 | //************************************************************************** |
| 128 | 95 | |
| 129 | | INLINE zx8302_t *get_safe_token(running_device *device) |
| 130 | | { |
| 131 | | assert(device != NULL); |
| 96 | const device_type ZX8302 = zx8302_device_config::static_alloc_device_config; |
| 132 | 97 | |
| 133 | | return (zx8302_t *)downcast<legacy_device_base *>(device)->token(); |
| 134 | | } |
| 135 | 98 | |
| 136 | | INLINE const zx8302_interface *get_interface(running_device *device) |
| 137 | | { |
| 138 | | assert(device != NULL); |
| 139 | | assert((device->type() == ZX8302)); |
| 140 | | return (const zx8302_interface *) device->baseconfig().static_config(); |
| 141 | | } |
| 142 | 99 | |
| 143 | | /*************************************************************************** |
| 144 | | IMPLEMENTATION |
| 145 | | ***************************************************************************/ |
| 100 | //************************************************************************** |
| 101 | // DEVICE CONFIGURATION |
| 102 | //************************************************************************** |
| 146 | 103 | |
| 147 | | /*------------------------------------------------- |
| 148 | | zx8302_interrupt - interrupt line manager |
| 149 | | -------------------------------------------------*/ |
| 104 | GENERIC_DEVICE_CONFIG_SETUP(zx8302, "Sinclair ZX8302") |
| 150 | 105 | |
| 151 | | static void zx8302_interrupt(running_device *device, UINT8 line) |
| 152 | | { |
| 153 | | zx8302_t *zx8302 = get_safe_token(device); |
| 154 | 106 | |
| 155 | | zx8302->irq |= line; |
| 156 | | devcb_call_write_line(&zx8302->out_ipl1l_func, ASSERT_LINE); |
| 157 | | } |
| 107 | //------------------------------------------------- |
| 108 | // device_config_complete - perform any |
| 109 | // operations now that the configuration is |
| 110 | // complete |
| 111 | //------------------------------------------------- |
| 158 | 112 | |
| 159 | | /*------------------------------------------------- |
| 160 | | zx8302_irq_status_r - interrupt status |
| 161 | | register |
| 162 | | -------------------------------------------------*/ |
| 163 | | |
| 164 | | READ8_DEVICE_HANDLER( zx8302_irq_status_r ) |
| 113 | void zx8302_device_config::device_config_complete() |
| 165 | 114 | { |
| 166 | | zx8302_t *zx8302 = get_safe_token(device); |
| 115 | // inherit a copy of the static data |
| 116 | const zx8302_interface *intf = reinterpret_cast<const zx8302_interface *>(static_config()); |
| 117 | if (intf != NULL) |
| 118 | *static_cast<zx8302_interface *>(this) = *intf; |
| 167 | 119 | |
| 168 | | return zx8302->irq; |
| 120 | // or initialize to defaults if none provided |
| 121 | else |
| 122 | { |
| 123 | memset(&out_ipl1l_func, 0, sizeof(out_ipl1l_func)); |
| 124 | memset(&out_baudx4_func, 0, sizeof(out_baudx4_func)); |
| 125 | memset(&out_comdata_func, 0, sizeof(out_comdata_func)); |
| 126 | memset(&out_txd1_func, 0, sizeof(out_txd1_func)); |
| 127 | memset(&out_txd2_func, 0, sizeof(out_txd2_func)); |
| 128 | memset(&in_dtr1_func, 0, sizeof(in_dtr1_func)); |
| 129 | memset(&in_cts2_func, 0, sizeof(in_cts2_func)); |
| 130 | memset(&out_netout_func, 0, sizeof(out_netout_func)); |
| 131 | memset(&in_netin_func, 0, sizeof(in_netin_func)); |
| 132 | } |
| 169 | 133 | } |
| 170 | 134 | |
| 171 | | /*------------------------------------------------- |
| 172 | | zx8302_irq_acknowledge_w - interrupt |
| 173 | | acknowledge |
| 174 | | -------------------------------------------------*/ |
| 175 | 135 | |
| 176 | | WRITE8_DEVICE_HANDLER( zx8302_irq_acknowledge_w ) |
| 177 | | { |
| 178 | | zx8302_t *zx8302 = get_safe_token(device); |
| 179 | 136 | |
| 180 | | zx8302->irq &= ~data; |
| 137 | //************************************************************************** |
| 138 | // INLINE HELPERS |
| 139 | //************************************************************************** |
| 181 | 140 | |
| 182 | | if (LOG) logerror("ZX8302 Interrupt Acknowledge: %02x\n", data); |
| 141 | //------------------------------------------------- |
| 142 | // trigger_interrupt - |
| 143 | //------------------------------------------------- |
| 183 | 144 | |
| 184 | | if (!zx8302->irq) |
| 185 | | { |
| 186 | | devcb_call_write_line(&zx8302->out_ipl1l_func, CLEAR_LINE); |
| 187 | | } |
| 188 | | } |
| 189 | | |
| 190 | | /*------------------------------------------------- |
| 191 | | TIMER_CALLBACK( zx8302_ipc_tick ) |
| 192 | | -------------------------------------------------*/ |
| 193 | | |
| 194 | | static TIMER_CALLBACK( zx8302_ipc_tick ) |
| 145 | inline void zx8302_device::trigger_interrupt(UINT8 line) |
| 195 | 146 | { |
| 196 | | zx8302_t *zx8302 = get_safe_token((running_device *)ptr); |
| 147 | m_irq |= line; |
| 197 | 148 | |
| 198 | | zx8302->baudx4 = !zx8302->baudx4; |
| 199 | | devcb_call_write_line(&zx8302->out_baudx4_func, zx8302->baudx4); |
| 149 | devcb_call_write_line(&m_out_ipl1l_func, ASSERT_LINE); |
| 200 | 150 | } |
| 201 | 151 | |
| 202 | | /*------------------------------------------------- |
| 203 | | zx8302_ipc_comm_tick - IPC serial transfer |
| 204 | | -------------------------------------------------*/ |
| 205 | 152 | |
| 206 | | static void zx8302_ipc_comm_tick(running_device *device) |
| 153 | //------------------------------------------------- |
| 154 | // transmit_ipc_data - transmit IPC data |
| 155 | //------------------------------------------------- |
| 156 | |
| 157 | inline void zx8302_device::transmit_ipc_data() |
| 207 | 158 | { |
| 208 | 159 | /* |
| 209 | 160 | |
| r9767 | r9768 | |
| 230 | 181 | |
| 231 | 182 | */ |
| 232 | 183 | |
| 233 | | zx8302_t *zx8302 = get_safe_token(device); |
| 234 | | |
| 235 | | switch (zx8302->ipc_state) |
| 184 | switch (m_ipc_state) |
| 236 | 185 | { |
| 237 | | case ZX8302_IPC_START: |
| 238 | | if (LOG) logerror("ZX8302 COMDATA START W: %x\n", 0); |
| 186 | case IPC_START: |
| 187 | if (LOG) logerror("ZX8302 '%s' COMDATA Start Bit\n", tag()); |
| 239 | 188 | |
| 240 | | devcb_call_write_line(&zx8302->out_comdata_func, 0); |
| 241 | | zx8302->ipc_busy = 1; |
| 242 | | zx8302->ipc_state = ZX8302_IPC_DATA; |
| 189 | devcb_call_write_line(&m_out_comdata_func, 0); |
| 190 | m_ipc_busy = 1; |
| 191 | m_ipc_state = IPC_DATA; |
| 243 | 192 | break; |
| 244 | 193 | |
| 245 | | case ZX8302_IPC_DATA: |
| 246 | | if (LOG) logerror("ZX8302 COMDATA W: %x\n", BIT(zx8302->idr, 1)); |
| 194 | case IPC_DATA: |
| 195 | if (LOG) logerror("ZX8302 '%s' COMDATA Data Bit: %x\n", tag(), BIT(m_idr, 1)); |
| 247 | 196 | |
| 248 | | zx8302->comdata = BIT(zx8302->idr, 1); |
| 249 | | devcb_call_write_line(&zx8302->out_comdata_func, zx8302->comdata); |
| 250 | | zx8302->ipc_state = ZX8302_IPC_STOP; |
| 197 | m_comdata = BIT(m_idr, 1); |
| 198 | devcb_call_write_line(&m_out_comdata_func, m_comdata); |
| 199 | m_ipc_state = IPC_STOP; |
| 251 | 200 | break; |
| 252 | 201 | |
| 253 | | case ZX8302_IPC_STOP: |
| 254 | | if (!zx8302->ipc_rx) |
| 202 | case IPC_STOP: |
| 203 | if (!m_ipc_rx) |
| 255 | 204 | { |
| 256 | | if (LOG) logerror("ZX8302 COMDATA STOP W: %x\n", 1); |
| 205 | if (LOG) logerror("ZX8302 '%s' COMDATA Stop Bit\n", tag()); |
| 257 | 206 | |
| 258 | | devcb_call_write_line(&zx8302->out_comdata_func, 1); |
| 259 | | zx8302->ipc_busy = 0; |
| 260 | | zx8302->ipc_state = ZX8302_IPC_START; |
| 207 | devcb_call_write_line(&m_out_comdata_func, 1); |
| 208 | m_ipc_busy = 0; |
| 209 | m_ipc_state = IPC_START; |
| 261 | 210 | } |
| 262 | 211 | break; |
| 263 | 212 | } |
| 264 | 213 | } |
| 265 | 214 | |
| 266 | | /*------------------------------------------------- |
| 267 | | zx8302_comctl_w - IPC COMCTL accessor |
| 268 | | -------------------------------------------------*/ |
| 269 | 215 | |
| 270 | | WRITE_LINE_DEVICE_HANDLER( zx8302_comctl_w ) |
| 271 | | { |
| 272 | | if (LOG) logerror("IPC COMCTL W: %x\n", state); |
| 216 | //------------------------------------------------- |
| 217 | // transmit_bit - transmit serial bit |
| 218 | //------------------------------------------------- |
| 273 | 219 | |
| 274 | | if (state == 1) |
| 275 | | { |
| 276 | | zx8302_ipc_comm_tick(device); |
| 277 | | } |
| 278 | | } |
| 279 | | |
| 280 | | /*------------------------------------------------- |
| 281 | | zx8302_comctl_w - IPC COMDATA accessor |
| 282 | | -------------------------------------------------*/ |
| 283 | | |
| 284 | | WRITE_LINE_DEVICE_HANDLER( zx8302_comdata_w ) |
| 220 | inline void zx8302_device::transmit_bit(int state) |
| 285 | 221 | { |
| 286 | | zx8302_t *zx8302 = get_safe_token(device); |
| 287 | | |
| 288 | | if (LOG) logerror("IPC COMDATA W: %x\n", state); |
| 289 | | |
| 290 | | if (zx8302->ipc_state == ZX8302_IPC_DATA || zx8302->ipc_state == ZX8302_IPC_STOP) |
| 222 | switch (m_tcr & MODE_MASK) |
| 291 | 223 | { |
| 292 | | if (zx8302->ipc_rx) |
| 293 | | { |
| 294 | | zx8302->ipc_rx = 0; |
| 295 | | zx8302->ipc_busy = 0; |
| 296 | | zx8302->ipc_state = ZX8302_IPC_START; |
| 297 | | } |
| 298 | | else |
| 299 | | { |
| 300 | | zx8302->ipc_rx = 1; |
| 301 | | zx8302->comdata = state; |
| 302 | | } |
| 303 | | } |
| 304 | | } |
| 305 | | |
| 306 | | /*------------------------------------------------- |
| 307 | | TIMER_CALLBACK( zx8302_delayed_ipc_command ) |
| 308 | | -------------------------------------------------*/ |
| 309 | | |
| 310 | | static TIMER_CALLBACK( zx8302_delayed_ipc_command ) |
| 311 | | { |
| 312 | | zx8302_t *zx8302 = get_safe_token((running_device *)ptr); |
| 313 | | |
| 314 | | zx8302->idr = param; |
| 315 | | zx8302->ipc_state = ZX8302_IPC_START; |
| 316 | | zx8302->ipc_rx = 0; |
| 317 | | |
| 318 | | zx8302_ipc_comm_tick((running_device *)ptr); |
| 319 | | } |
| 320 | | |
| 321 | | /*------------------------------------------------- |
| 322 | | zx8302_ipc_command_w - IPC command register |
| 323 | | -------------------------------------------------*/ |
| 324 | | |
| 325 | | WRITE8_DEVICE_HANDLER( zx8302_ipc_command_w ) |
| 326 | | { |
| 327 | | if (LOG) logerror("ZX8302 IPC Command: %02x\n", data); |
| 328 | | |
| 329 | | if (data != 0x01) |
| 330 | | { |
| 331 | | timer_set(device->machine,ATTOTIME_IN_NSEC(480), (void *) device, data, zx8302_delayed_ipc_command); |
| 332 | | } |
| 333 | | } |
| 334 | | |
| 335 | | /*------------------------------------------------- |
| 336 | | zx8302_txd - IPC serial transmit |
| 337 | | -------------------------------------------------*/ |
| 338 | | |
| 339 | | static WRITE_LINE_DEVICE_HANDLER( zx8302_txd ) |
| 340 | | { |
| 341 | | zx8302_t *zx8302 = get_safe_token(device); |
| 342 | | |
| 343 | | switch (zx8302->tcr & ZX8302_MODE_MASK) |
| 344 | | { |
| 345 | | case ZX8302_MODE_SER1: |
| 346 | | zx8302->ser1_rxd = state; |
| 224 | case MODE_SER1: |
| 225 | devcb_call_write_line(&m_out_txd1_func, state); |
| 347 | 226 | break; |
| 348 | 227 | |
| 349 | | case ZX8302_MODE_SER2: |
| 350 | | zx8302->ser2_txd = state; |
| 228 | case MODE_SER2: |
| 229 | devcb_call_write_line(&m_out_txd2_func, state); |
| 351 | 230 | break; |
| 352 | 231 | |
| 353 | | case ZX8302_MODE_MDV: |
| 232 | case MODE_MDV: |
| 354 | 233 | // TODO |
| 355 | 234 | break; |
| 356 | 235 | |
| 357 | | case ZX8302_MODE_NET: |
| 358 | | zx8302->netout = state; |
| 236 | case MODE_NET: |
| 237 | devcb_call_write_line(&m_out_netout_func, state); |
| 359 | 238 | break; |
| 360 | 239 | } |
| 361 | 240 | } |
| 362 | 241 | |
| 363 | | /*------------------------------------------------- |
| 364 | | TIMER_CALLBACK( zx8302_txd_tick ) |
| 365 | | -------------------------------------------------*/ |
| 366 | 242 | |
| 367 | | static TIMER_CALLBACK( zx8302_txd_tick ) |
| 368 | | { |
| 369 | | zx8302_t *zx8302 = get_safe_token((running_device *)ptr); |
| 243 | //------------------------------------------------- |
| 244 | // transmit_data - transmit serial data |
| 245 | //------------------------------------------------- |
| 370 | 246 | |
| 371 | | switch (zx8302->tx_bits) |
| 247 | inline void zx8302_device::transmit_serial_data() |
| 248 | { |
| 249 | switch (m_tx_bits) |
| 372 | 250 | { |
| 373 | | case ZX8302_TXD_START: |
| 374 | | if (!(zx8302->irq & ZX8302_INT_TRANSMIT)) |
| 251 | case TXD_START: |
| 252 | if (!(m_irq & INT_TRANSMIT)) |
| 375 | 253 | { |
| 376 | | zx8302_txd((running_device *)ptr, 0); |
| 377 | | zx8302->tx_bits++; |
| 254 | transmit_bit(0); |
| 255 | m_tx_bits++; |
| 378 | 256 | } |
| 379 | 257 | break; |
| 380 | 258 | |
| 381 | 259 | default: |
| 382 | | zx8302_txd((running_device *)ptr, BIT(zx8302->tdr, 0)); |
| 383 | | zx8302->tdr >>= 1; |
| 384 | | zx8302->tx_bits++; |
| 260 | transmit_bit(BIT(m_tdr, 0)); |
| 261 | m_tdr >>= 1; |
| 262 | m_tx_bits++; |
| 385 | 263 | break; |
| 386 | 264 | |
| 387 | | case ZX8302_TXD_STOP: |
| 388 | | zx8302_txd((running_device *)ptr, 1); |
| 389 | | zx8302->tx_bits++; |
| 265 | case TXD_STOP: |
| 266 | transmit_bit(1); |
| 267 | m_tx_bits++; |
| 390 | 268 | break; |
| 391 | 269 | |
| 392 | | case ZX8302_TXD_STOP2: |
| 393 | | zx8302_txd((running_device *)ptr, 1); |
| 394 | | zx8302->tx_bits = ZX8302_TXD_START; |
| 395 | | zx8302->status &= ~ZX8302_STATUS_TX_BUFFER_FULL; |
| 396 | | zx8302_interrupt((running_device *)ptr, ZX8302_INT_TRANSMIT); |
| 270 | case TXD_STOP2: |
| 271 | transmit_bit(1); |
| 272 | m_tx_bits = TXD_START; |
| 273 | m_status &= ~STATUS_TX_BUFFER_FULL; |
| 274 | trigger_interrupt(INT_TRANSMIT); |
| 397 | 275 | break; |
| 398 | 276 | } |
| 399 | 277 | } |
| 400 | 278 | |
| 401 | | /*------------------------------------------------- |
| 402 | | zx8302_data_w - transmit data register |
| 403 | | -------------------------------------------------*/ |
| 404 | 279 | |
| 405 | | WRITE8_DEVICE_HANDLER( zx8302_data_w ) |
| 406 | | { |
| 407 | | zx8302_t *zx8302 = get_safe_token(device); |
| 408 | 280 | |
| 409 | | if (LOG) logerror("ZX8302 Data Register: %02x\n", data); |
| 281 | //************************************************************************** |
| 282 | // LIVE DEVICE |
| 283 | //************************************************************************** |
| 410 | 284 | |
| 411 | | zx8302->tdr = data; |
| 412 | | zx8302->status |= ZX8302_STATUS_TX_BUFFER_FULL; |
| 285 | //------------------------------------------------- |
| 286 | // zx8302_device - constructor |
| 287 | //------------------------------------------------- |
| 288 | |
| 289 | zx8302_device::zx8302_device(running_machine &_machine, const zx8302_device_config &config) |
| 290 | : device_t(_machine, config), |
| 291 | m_idr(1), |
| 292 | m_irq(0), |
| 293 | m_ctr(time(NULL) + RTC_BASE_ADJUST), |
| 294 | m_status(0), |
| 295 | m_comdata(1), |
| 296 | m_comctl(1), |
| 297 | m_ipc_state(0), |
| 298 | m_ipc_rx(0), |
| 299 | m_ipc_busy(0), |
| 300 | m_track(0), |
| 301 | m_config(config) |
| 302 | { |
| 413 | 303 | } |
| 414 | 304 | |
| 415 | | /*------------------------------------------------- |
| 416 | | zx8302_control_w - serial control register |
| 417 | | -------------------------------------------------*/ |
| 418 | 305 | |
| 419 | | WRITE8_DEVICE_HANDLER( zx8302_control_w ) |
| 306 | //------------------------------------------------- |
| 307 | // device_start - device-specific startup |
| 308 | //------------------------------------------------- |
| 309 | |
| 310 | void zx8302_device::device_start() |
| 420 | 311 | { |
| 421 | | zx8302_t *zx8302 = get_safe_token(device); |
| 312 | // resolve callbacks |
| 313 | devcb_resolve_write_line(&m_out_ipl1l_func, &m_config.out_ipl1l_func, this); |
| 314 | devcb_resolve_write_line(&m_out_baudx4_func, &m_config.out_baudx4_func, this); |
| 315 | devcb_resolve_write_line(&m_out_comdata_func, &m_config.out_comdata_func, this); |
| 316 | devcb_resolve_write_line(&m_out_txd1_func, &m_config.out_txd1_func, this); |
| 317 | devcb_resolve_write_line(&m_out_txd2_func, &m_config.out_txd2_func, this); |
| 318 | devcb_resolve_read_line(&m_in_dtr1_func, &m_config.in_dtr1_func, this); |
| 319 | devcb_resolve_read_line(&m_in_cts2_func, &m_config.in_cts2_func, this); |
| 320 | devcb_resolve_write_line(&m_out_netout_func, &m_config.out_netout_func, this); |
| 321 | devcb_resolve_read_line(&m_in_netin_func, &m_config.in_netin_func, this); |
| 422 | 322 | |
| 423 | | int baud = (19200 >> (data & ZX8302_BAUD_MASK)); |
| 424 | | int baudx4 = baud * 4; |
| 323 | // allocate timers |
| 324 | m_txd_timer = device_timer_alloc(*this, TIMER_TXD); |
| 325 | m_baudx4_timer = device_timer_alloc(*this, TIMER_BAUDX4); |
| 326 | m_rtc_timer = device_timer_alloc(*this, TIMER_RTC); |
| 327 | m_gap_timer = device_timer_alloc(*this, TIMER_GAP); |
| 328 | m_ipc_timer = device_timer_alloc(*this, TIMER_IPC); |
| 425 | 329 | |
| 426 | | if (LOG) logerror("ZX8302 Transmit Control Register: %02x\n", data); |
| 330 | timer_adjust_periodic(m_rtc_timer, attotime_zero, 0, ATTOTIME_IN_HZ(m_config.rtc_clock / 32768)); |
| 331 | timer_adjust_periodic(m_gap_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(31)); |
| 427 | 332 | |
| 428 | | zx8302->tcr = data; |
| 429 | | |
| 430 | | timer_adjust_periodic(zx8302->txd_timer, attotime_zero, 0, ATTOTIME_IN_HZ(baud)); |
| 431 | | timer_adjust_periodic(zx8302->ipc_timer, attotime_zero, 0, ATTOTIME_IN_HZ(baudx4)); |
| 333 | // register for state saving |
| 334 | state_save_register_device_item(this, 0, m_idr); |
| 335 | state_save_register_device_item(this, 0, m_tcr); |
| 336 | state_save_register_device_item(this, 0, m_tdr); |
| 337 | state_save_register_device_item(this, 0, m_irq); |
| 338 | state_save_register_device_item(this, 0, m_ctr); |
| 339 | state_save_register_device_item(this, 0, m_status); |
| 340 | state_save_register_device_item(this, 0, m_comdata); |
| 341 | state_save_register_device_item(this, 0, m_comctl); |
| 342 | state_save_register_device_item(this, 0, m_ipc_state); |
| 343 | state_save_register_device_item(this, 0, m_ipc_rx); |
| 344 | state_save_register_device_item(this, 0, m_ipc_busy); |
| 345 | state_save_register_device_item(this, 0, m_baudx4); |
| 346 | state_save_register_device_item(this, 0, m_tx_bits); |
| 347 | state_save_register_device_item(this, 0, m_mdrdw); |
| 348 | state_save_register_device_item(this, 0, m_mdselck); |
| 349 | state_save_register_device_item(this, 0, m_mdseld); |
| 350 | state_save_register_device_item(this, 0, m_erase); |
| 351 | state_save_register_device_item(this, 0, m_mdv_motor); |
| 352 | state_save_register_device_item_array(this, 0, m_mdv_data); |
| 353 | state_save_register_device_item(this, 0, m_track); |
| 432 | 354 | } |
| 433 | 355 | |
| 434 | | /*------------------------------------------------- |
| 435 | | TIMER_CALLBACK( zx8302_rtc_tick ) |
| 436 | | -------------------------------------------------*/ |
| 437 | 356 | |
| 438 | | static TIMER_CALLBACK( zx8302_rtc_tick ) |
| 357 | //------------------------------------------------- |
| 358 | // device_timer - handler timer events |
| 359 | //------------------------------------------------- |
| 360 | |
| 361 | void zx8302_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 439 | 362 | { |
| 440 | | zx8302_t *zx8302 = get_safe_token((running_device *)ptr); |
| 363 | switch (id) |
| 364 | { |
| 365 | case TIMER_TXD: |
| 366 | transmit_serial_data(); |
| 367 | break; |
| 441 | 368 | |
| 442 | | zx8302->ctr++; |
| 369 | case TIMER_BAUDX4: |
| 370 | m_baudx4 = !m_baudx4; |
| 371 | devcb_call_write_line(&m_out_baudx4_func, m_baudx4); |
| 372 | break; |
| 373 | |
| 374 | case TIMER_RTC: |
| 375 | m_ctr++; |
| 376 | break; |
| 377 | |
| 378 | case TIMER_GAP: |
| 379 | if (m_mdv_motor) |
| 380 | { |
| 381 | trigger_interrupt(INT_GAP); |
| 382 | } |
| 383 | break; |
| 384 | |
| 385 | case TIMER_IPC: |
| 386 | m_idr = param; |
| 387 | m_ipc_state = IPC_START; |
| 388 | m_ipc_rx = 0; |
| 389 | |
| 390 | transmit_ipc_data(); |
| 391 | break; |
| 392 | } |
| 443 | 393 | } |
| 444 | 394 | |
| 445 | | /*------------------------------------------------- |
| 446 | | zx8302_rtc_r - clock register read |
| 447 | | -------------------------------------------------*/ |
| 448 | 395 | |
| 449 | | READ8_DEVICE_HANDLER( zx8302_rtc_r ) |
| 396 | //------------------------------------------------- |
| 397 | // rtc_r - real time clock read |
| 398 | //------------------------------------------------- |
| 399 | |
| 400 | READ8_MEMBER( zx8302_device::rtc_r ) |
| 450 | 401 | { |
| 451 | | zx8302_t *zx8302 = get_safe_token(device); |
| 402 | UINT8 data = 0; |
| 452 | 403 | |
| 453 | 404 | switch (offset) |
| 454 | 405 | { |
| 455 | 406 | case 0: |
| 456 | | return (zx8302->ctr >> 24) & 0xff; |
| 407 | data = (m_ctr >> 24) & 0xff; |
| 457 | 408 | case 1: |
| 458 | | return (zx8302->ctr >> 16) & 0xff; |
| 409 | data = (m_ctr >> 16) & 0xff; |
| 459 | 410 | case 2: |
| 460 | | return (zx8302->ctr >> 8) & 0xff; |
| 411 | data = (m_ctr >> 8) & 0xff; |
| 461 | 412 | case 3: |
| 462 | | return zx8302->ctr; |
| 413 | data = m_ctr & 0xff; |
| 463 | 414 | } |
| 464 | 415 | |
| 465 | | return 0; |
| 416 | return data; |
| 466 | 417 | } |
| 467 | 418 | |
| 468 | | /*------------------------------------------------- |
| 469 | | zx8302_rtc_w - clock register write |
| 470 | | -------------------------------------------------*/ |
| 471 | 419 | |
| 472 | | WRITE8_DEVICE_HANDLER( zx8302_rtc_w ) |
| 473 | | { |
| 474 | | // zx8302_t *zx8302 = get_safe_token(device); |
| 420 | //------------------------------------------------- |
| 421 | // rtc_w - real time clock write |
| 422 | //------------------------------------------------- |
| 475 | 423 | |
| 476 | | if (LOG) logerror("ZX8302 Real Time Clock Register: %02x\n", data); |
| 424 | WRITE8_MEMBER( zx8302_device::rtc_w ) |
| 425 | { |
| 426 | if (LOG) logerror("ZX8302 '%s' Set Real Time Clock: %02x\n", tag(), data); |
| 477 | 427 | } |
| 478 | 428 | |
| 479 | | /*------------------------------------------------- |
| 480 | | TIMER_CALLBACK( zx8302_gap_tick ) |
| 481 | | -------------------------------------------------*/ |
| 482 | 429 | |
| 483 | | static TIMER_CALLBACK( zx8302_gap_tick ) |
| 430 | //------------------------------------------------- |
| 431 | // control_w - serial transmit clock |
| 432 | //------------------------------------------------- |
| 433 | |
| 434 | WRITE8_MEMBER( zx8302_device::control_w ) |
| 484 | 435 | { |
| 485 | | zx8302_t *zx8302 = get_safe_token((running_device *)ptr); |
| 436 | if (LOG) logerror("ZX8302 '%s' Transmit Control: %02x\n", tag(), data); |
| 486 | 437 | |
| 487 | | if (zx8302->mdv_motor) |
| 488 | | { |
| 489 | | zx8302_interrupt((running_device *)ptr, ZX8302_INT_GAP); |
| 490 | | } |
| 438 | int baud = (19200 >> (data & BAUD_MASK)); |
| 439 | int baudx4 = baud * 4; |
| 440 | |
| 441 | m_tcr = data; |
| 442 | |
| 443 | timer_adjust_periodic(m_txd_timer, attotime_zero, 0, ATTOTIME_IN_HZ(baud)); |
| 444 | timer_adjust_periodic(m_baudx4_timer, attotime_zero, 0, ATTOTIME_IN_HZ(baudx4)); |
| 491 | 445 | } |
| 492 | 446 | |
| 493 | | /*------------------------------------------------- |
| 494 | | zx8302_get_selected_microdrive - gets the |
| 495 | | index of the selected microdrive |
| 496 | | -------------------------------------------------*/ |
| 497 | 447 | |
| 498 | | static int zx8302_get_selected_microdrive(running_device *device) |
| 448 | //------------------------------------------------- |
| 449 | // mdv_track_r - microdrive track data |
| 450 | //------------------------------------------------- |
| 451 | |
| 452 | READ8_MEMBER( zx8302_device::mdv_track_r ) |
| 499 | 453 | { |
| 500 | | zx8302_t *zx8302 = get_safe_token(device); |
| 454 | if (LOG) logerror("ZX8302 '%s' Microdrive Track %u: %02x\n", tag(), m_track, m_mdv_data[m_track]); |
| 501 | 455 | |
| 502 | | int i; |
| 456 | UINT8 data = m_mdv_data[m_track]; |
| 503 | 457 | |
| 504 | | for (i = 0; i < 8; i++) |
| 505 | | { |
| 506 | | if (BIT(zx8302->mdv_motor, i)) return 7 - i; |
| 507 | | } |
| 458 | m_track = !m_track; |
| 508 | 459 | |
| 509 | | return 0; |
| 460 | return data; |
| 510 | 461 | } |
| 511 | 462 | |
| 512 | | /*------------------------------------------------- |
| 513 | | zx8302_get_microdrive_status - gets the |
| 514 | | status of the selected microdrive |
| 515 | | -------------------------------------------------*/ |
| 516 | 463 | |
| 517 | | static UINT8 zx8302_get_microdrive_status(running_device *device) |
| 464 | //------------------------------------------------- |
| 465 | // status_r - status register |
| 466 | //------------------------------------------------- |
| 467 | |
| 468 | READ8_MEMBER( zx8302_device::status_r ) |
| 518 | 469 | { |
| 519 | | zx8302_t *zx8302 = get_safe_token(device); |
| 470 | /* |
| 520 | 471 | |
| 521 | | int drive = zx8302_get_selected_microdrive(device); |
| 522 | | UINT8 status = 0; |
| 472 | bit description |
| 523 | 473 | |
| 524 | | if (zx8302->mdv_motor) |
| 525 | | { |
| 526 | | switch (zx8302->mdv_offset[drive] % MDV_SECTOR_LENGTH) |
| 527 | | { |
| 528 | | case MDV_OFFSET_HEADER_PREAMBLE: |
| 529 | | zx8302->status &= ~ZX8302_STATUS_MICRODRIVE_GAP; |
| 530 | | zx8302->mdv_offset[drive] += MDV_PREAMBLE_LENGTH; |
| 531 | | break; |
| 474 | 0 Network port |
| 475 | 1 Transmit buffer full |
| 476 | 2 Receive buffer full |
| 477 | 3 Microdrive GAP |
| 478 | 4 SER1 DTR |
| 479 | 5 SER2 CTS |
| 480 | 6 IPC busy |
| 481 | 7 COMDATA |
| 532 | 482 | |
| 533 | | case MDV_OFFSET_HEADER: |
| 534 | | zx8302->status |= ZX8302_STATUS_RX_BUFFER_FULL; |
| 535 | | break; |
| 483 | */ |
| 536 | 484 | |
| 537 | | case MDV_OFFSET_DATA_PREAMBLE: |
| 538 | | zx8302->status &= ~ZX8302_STATUS_RX_BUFFER_FULL; |
| 539 | | zx8302->mdv_offset[drive] += MDV_PREAMBLE_LENGTH; |
| 540 | | break; |
| 485 | UINT8 data = 0; |
| 541 | 486 | |
| 542 | | case MDV_OFFSET_DATA: |
| 543 | | zx8302->status |= ZX8302_STATUS_RX_BUFFER_FULL; |
| 544 | | break; |
| 487 | // TODO network port |
| 545 | 488 | |
| 546 | | case MDV_OFFSET_GAP: |
| 547 | | zx8302->status &= ~ZX8302_STATUS_RX_BUFFER_FULL; |
| 548 | | zx8302->status |= ZX8302_STATUS_MICRODRIVE_GAP; |
| 549 | | zx8302->mdv_offset[drive] += MDV_GAP_LENGTH; |
| 550 | | break; |
| 551 | | } |
| 552 | | } |
| 489 | // serial status |
| 490 | data |= m_status; |
| 553 | 491 | |
| 554 | | return status; |
| 555 | | } |
| 492 | // TODO microdrive GAP |
| 556 | 493 | |
| 557 | | /*------------------------------------------------- |
| 558 | | zx8302_mdv_track_r - microdrive data register |
| 559 | | -------------------------------------------------*/ |
| 494 | // data terminal ready |
| 495 | data |= devcb_call_read_line(&m_in_dtr1_func) << 4; |
| 560 | 496 | |
| 561 | | READ8_DEVICE_HANDLER( zx8302_mdv_track_r ) |
| 562 | | { |
| 563 | | zx8302_t *zx8302 = get_safe_token(device); |
| 497 | // clear to send |
| 498 | data |= devcb_call_read_line(&m_in_cts2_func) << 5; |
| 564 | 499 | |
| 565 | | int drive = zx8302_get_selected_microdrive(device); |
| 566 | | UINT8 data = zx8302->mdv_image[drive][zx8302->mdv_offset[drive]]; |
| 500 | // IPC busy |
| 501 | data |= m_ipc_busy << 6; |
| 567 | 502 | |
| 568 | | zx8302->mdv_offset[drive]++; |
| 503 | // COMDATA |
| 504 | data |= m_comdata << 7; |
| 569 | 505 | |
| 570 | | if (zx8302->mdv_offset[drive] == MDV_IMAGE_LENGTH) |
| 571 | | { |
| 572 | | zx8302->mdv_offset[drive] = 0; |
| 573 | | } |
| 506 | if (LOG) logerror("ZX8302 '%s' Status: %02x\n", tag(), data); |
| 574 | 507 | |
| 575 | 508 | return data; |
| 576 | 509 | } |
| 577 | 510 | |
| 578 | | /*------------------------------------------------- |
| 579 | | zx8302_mdv_control_w - microdrive control |
| 580 | | register |
| 581 | | -------------------------------------------------*/ |
| 582 | 511 | |
| 583 | | WRITE8_DEVICE_HANDLER( zx8302_mdv_control_w ) |
| 512 | //------------------------------------------------- |
| 513 | // ipc_command_w - IPC command |
| 514 | //------------------------------------------------- |
| 515 | |
| 516 | WRITE8_MEMBER( zx8302_device::ipc_command_w ) |
| 584 | 517 | { |
| 585 | | zx8302_t *zx8302 = get_safe_token(device); |
| 518 | if (LOG) logerror("ZX8302 '%s' IPC Command: %02x\n", tag(), data); |
| 586 | 519 | |
| 520 | if (data != 0x01) |
| 521 | { |
| 522 | timer_adjust_oneshot(m_ipc_timer, ATTOTIME_IN_NSEC(480), data); |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | |
| 527 | //------------------------------------------------- |
| 528 | // mdv_control_w - microdrive control |
| 529 | //------------------------------------------------- |
| 530 | |
| 531 | WRITE8_MEMBER( zx8302_device::mdv_control_w ) |
| 532 | { |
| 587 | 533 | /* |
| 588 | 534 | |
| 589 | 535 | bit description |
| r9767 | r9768 | |
| 599 | 545 | |
| 600 | 546 | */ |
| 601 | 547 | |
| 602 | | if (LOG) logerror("ZX8302 Microdrive Control Register: %02x\n", data); |
| 548 | if (LOG) logerror("ZX8302 '%s' Microdrive Control: %02x\n", tag(), data); |
| 603 | 549 | |
| 604 | | zx8302->mdseld = BIT(data, 0); |
| 605 | | zx8302->mdselck = BIT(data, 1); |
| 606 | | zx8302->mdrdw = BIT(data, 2) ? 0 : 1; |
| 607 | | zx8302->erase = BIT(data, 3); |
| 550 | m_mdseld = BIT(data, 0); |
| 551 | m_mdselck = BIT(data, 1); |
| 552 | m_mdrdw = BIT(data, 2) ? 0 : 1; |
| 553 | m_erase = BIT(data, 3); |
| 608 | 554 | |
| 609 | 555 | // Microdrive selection shift register |
| 610 | | |
| 611 | | if (zx8302->mdselck) |
| 556 | if (m_mdselck) |
| 612 | 557 | { |
| 613 | | int drive = 0; |
| 558 | m_mdv_motor >>= 1; |
| 559 | m_mdv_motor |= (m_mdseld << 7); |
| 614 | 560 | |
| 615 | | zx8302->mdv_motor >>= 1; |
| 616 | | zx8302->mdv_motor |= (zx8302->mdseld << 7); |
| 617 | | |
| 618 | | drive = zx8302_get_selected_microdrive(device); |
| 619 | | |
| 620 | | zx8302->mdv_offset[drive] = 0; |
| 621 | | zx8302->status &= ~ZX8302_STATUS_RX_BUFFER_FULL; |
| 561 | m_status &= ~STATUS_RX_BUFFER_FULL; |
| 622 | 562 | } |
| 623 | 563 | } |
| 624 | 564 | |
| 625 | | /*------------------------------------------------- |
| 626 | | zx8302_status_r - status register |
| 627 | | -------------------------------------------------*/ |
| 628 | 565 | |
| 629 | | READ8_DEVICE_HANDLER( zx8302_status_r ) |
| 566 | //------------------------------------------------- |
| 567 | // irq_status_r - interrupt status |
| 568 | //------------------------------------------------- |
| 569 | |
| 570 | READ8_MEMBER( zx8302_device::irq_status_r ) |
| 630 | 571 | { |
| 631 | | zx8302_t *zx8302 = get_safe_token(device); |
| 572 | if (LOG) logerror("ZX8302 '%s' Interrupt Status: %02x\n", tag(), m_irq); |
| 632 | 573 | |
| 633 | | /* |
| 574 | return m_irq; |
| 575 | } |
| 634 | 576 | |
| 635 | | bit description |
| 636 | 577 | |
| 637 | | 0 Network port |
| 638 | | 1 Transmit buffer full |
| 639 | | 2 Receive buffer full |
| 640 | | 3 Microdrive GAP |
| 641 | | 4 SER1 DTR |
| 642 | | 5 SER2 CTS |
| 643 | | 6 IPC busy |
| 644 | | 7 COMDATA |
| 578 | //------------------------------------------------- |
| 579 | // irq_acknowledge_w - interrupt acknowledge |
| 580 | //------------------------------------------------- |
| 645 | 581 | |
| 646 | | */ |
| 582 | WRITE8_MEMBER( zx8302_device::irq_acknowledge_w ) |
| 583 | { |
| 584 | if (LOG) logerror("ZX8302 '%s' Interrupt Acknowledge: %02x\n", tag(), data); |
| 647 | 585 | |
| 648 | | UINT8 data = 0; |
| 586 | m_irq &= ~data; |
| 649 | 587 | |
| 650 | | data |= zx8302->comdata << 7; |
| 651 | | data |= zx8302->ipc_busy << 6; |
| 652 | | data |= zx8302->ser1_cts << 5; |
| 653 | | data |= zx8302->ser2_dtr << 4; |
| 654 | | data |= zx8302_get_microdrive_status(device); |
| 655 | | data |= zx8302->status; |
| 656 | | |
| 657 | | if (LOG) logerror("ZX8302 Status Register: %02x\n", data); |
| 658 | | |
| 659 | | return data; |
| 660 | | } |
| 661 | | |
| 662 | | /*------------------------------------------------- |
| 663 | | zx8302_vsync_w - vertical sync accessor |
| 664 | | -------------------------------------------------*/ |
| 665 | | |
| 666 | | WRITE_LINE_DEVICE_HANDLER( zx8302_vsync_w ) |
| 667 | | { |
| 668 | | if (state) |
| 588 | if (!m_irq) |
| 669 | 589 | { |
| 670 | | zx8302_interrupt(device, ZX8302_INT_FRAME); |
| 671 | | if (LOG) logerror("ZX8302 Frame Interrupt\n"); |
| 590 | devcb_call_write_line(&m_out_ipl1l_func, CLEAR_LINE); |
| 672 | 591 | } |
| 673 | 592 | } |
| 674 | 593 | |
| 675 | | /*------------------------------------------------- |
| 676 | | DEVICE_START( zx8302 ) |
| 677 | | -------------------------------------------------*/ |
| 678 | 594 | |
| 679 | | static DEVICE_START( zx8302 ) |
| 595 | //------------------------------------------------- |
| 596 | // data_w - transmit buffer |
| 597 | //------------------------------------------------- |
| 598 | |
| 599 | WRITE8_MEMBER( zx8302_device::data_w ) |
| 680 | 600 | { |
| 681 | | zx8302_t *zx8302 = get_safe_token(device); |
| 682 | | const zx8302_interface *intf = get_interface(device); |
| 683 | | int i; |
| 601 | if (LOG) logerror("ZX8302 '%s' Data Register: %02x\n", tag(), data); |
| 684 | 602 | |
| 685 | | /* resolve callbacks */ |
| 686 | | devcb_resolve_write_line(&zx8302->out_ipl1l_func, &intf->out_ipl1l_func, device); |
| 687 | | devcb_resolve_write_line(&zx8302->out_baudx4_func, &intf->out_baudx4_func, device); |
| 688 | | devcb_resolve_write_line(&zx8302->out_comdata_func, &intf->out_comdata_func, device); |
| 603 | m_tdr = data; |
| 604 | m_status |= STATUS_TX_BUFFER_FULL; |
| 605 | } |
| 689 | 606 | |
| 690 | | /* set initial values */ |
| 691 | | zx8302->comctl = 1; |
| 692 | | zx8302->comdata = 1; |
| 693 | | zx8302->idr = 1; |
| 694 | 607 | |
| 695 | | zx8302->ctr = time(NULL) + 283996800; |
| 608 | //------------------------------------------------- |
| 609 | // vsync_w - vertical sync |
| 610 | //------------------------------------------------- |
| 696 | 611 | |
| 697 | | /* allocate microdrive images */ |
| 698 | | for (i = 0; i < 8; i++) |
| 612 | WRITE_LINE_MEMBER( zx8302_device::vsync_w ) |
| 613 | { |
| 614 | if (state) |
| 699 | 615 | { |
| 700 | | zx8302->mdv_image[i] = auto_alloc_array(device->machine, UINT8, MDV_IMAGE_LENGTH); |
| 616 | if (LOG) logerror("ZX8302 '%s' Frame Interrupt\n", tag()); |
| 617 | |
| 618 | trigger_interrupt(INT_FRAME); |
| 701 | 619 | } |
| 620 | } |
| 702 | 621 | |
| 703 | | /* create the timers */ |
| 704 | | zx8302->txd_timer = timer_alloc(device->machine, zx8302_txd_tick, (void *)device); |
| 705 | | zx8302->ipc_timer = timer_alloc(device->machine, zx8302_ipc_tick, (void *)device); |
| 706 | | zx8302->rtc_timer = timer_alloc(device->machine, zx8302_rtc_tick, (void *)device); |
| 707 | | zx8302->gap_timer = timer_alloc(device->machine, zx8302_gap_tick, (void *)device); |
| 708 | 622 | |
| 709 | | timer_adjust_periodic(zx8302->rtc_timer, attotime_zero, 0, ATTOTIME_IN_HZ(intf->rtc_clock/32768)); |
| 710 | | timer_adjust_periodic(zx8302->gap_timer, attotime_zero, 0, ATTOTIME_IN_MSEC(31)); |
| 623 | //------------------------------------------------- |
| 624 | // comctl_w - IPC COMCTL |
| 625 | //------------------------------------------------- |
| 711 | 626 | |
| 712 | | /* register for state saving */ |
| 627 | WRITE_LINE_MEMBER( zx8302_device::comctl_w ) |
| 628 | { |
| 629 | if (LOG) logerror("ZX8302 '%s' COMCTL: %x\n", tag(), state); |
| 713 | 630 | |
| 714 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->idr); |
| 715 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->tcr); |
| 716 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->tdr); |
| 717 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->irq); |
| 718 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->ctr); |
| 719 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->status); |
| 720 | | |
| 721 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->comdata); |
| 722 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->comctl); |
| 723 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->ipc_state); |
| 724 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->ipc_rx); |
| 725 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->ipc_busy); |
| 726 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->baudx4); |
| 727 | | |
| 728 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->tx_bits); |
| 729 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->ser1_rxd); |
| 730 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->ser1_cts); |
| 731 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->ser2_txd); |
| 732 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->ser2_dtr); |
| 733 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->netout); |
| 734 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->netin); |
| 735 | | |
| 736 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->mdrdw); |
| 737 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->mdselck); |
| 738 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->mdseld); |
| 739 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->erase); |
| 740 | | |
| 741 | | state_save_register_item(device->machine, "zx8302", device->tag(), 0, zx8302->mdv_motor); |
| 742 | | state_save_register_item_array(device->machine, "zx8302", device->tag(), 0, zx8302->mdv_offset); |
| 631 | if (state) |
| 632 | { |
| 633 | transmit_ipc_data(); |
| 634 | } |
| 743 | 635 | } |
| 744 | 636 | |
| 745 | | /*------------------------------------------------- |
| 746 | | DEVICE_RESET( zx8301 ) |
| 747 | | -------------------------------------------------*/ |
| 748 | 637 | |
| 749 | | static DEVICE_RESET( zx8302 ) |
| 638 | //------------------------------------------------- |
| 639 | // comdata_w - IPC COMDATA |
| 640 | //------------------------------------------------- |
| 641 | |
| 642 | WRITE_LINE_MEMBER( zx8302_device::comdata_w ) |
| 750 | 643 | { |
| 751 | | // zx8302_t *zx8302 = get_safe_token(device); |
| 644 | if (LOG) logerror("ZX8302 '%s' COMDATA: %x\n", tag(), state); |
| 752 | 645 | |
| 646 | if (m_ipc_state == IPC_DATA || m_ipc_state == IPC_STOP) |
| 647 | { |
| 648 | if (m_ipc_rx) |
| 649 | { |
| 650 | m_ipc_rx = 0; |
| 651 | m_ipc_busy = 0; |
| 652 | m_ipc_state = IPC_START; |
| 653 | } |
| 654 | else |
| 655 | { |
| 656 | m_ipc_rx = 1; |
| 657 | m_comdata = state; |
| 658 | } |
| 659 | } |
| 753 | 660 | } |
| 754 | 661 | |
| 755 | | /*------------------------------------------------- |
| 756 | | DEVICE_GET_INFO( zx8301 ) |
| 757 | | -------------------------------------------------*/ |
| 758 | 662 | |
| 759 | | DEVICE_GET_INFO( zx8302 ) |
| 663 | //------------------------------------------------- |
| 664 | // extint_w - external interrupt |
| 665 | //------------------------------------------------- |
| 666 | |
| 667 | WRITE_LINE_MEMBER( zx8302_device::extint_w ) |
| 760 | 668 | { |
| 761 | | switch (state) |
| 762 | | { |
| 763 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 764 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(zx8302_t); break; |
| 765 | | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 669 | if (LOG) logerror("ZX8302 '%s' EXTINT: %x\n", tag(), state); |
| 766 | 670 | |
| 767 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 768 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(zx8302); break; |
| 769 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 770 | | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(zx8302); break; |
| 771 | | |
| 772 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 773 | | case DEVINFO_STR_NAME: strcpy(info->s, "Sinclair ZX8302"); break; |
| 774 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Sinclair QL"); break; |
| 775 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 776 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 777 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright MESS Team"); break; |
| 671 | if (state == ASSERT_LINE) |
| 672 | { |
| 673 | trigger_interrupt(INT_EXTERNAL); |
| 778 | 674 | } |
| 779 | 675 | } |
| 780 | | |
| 781 | | DEFINE_LEGACY_DEVICE(ZX8302, zx8302); |
src/mess/machine/zx8302.h
| r9767 | r9768 | |
| 7 | 7 | |
| 8 | 8 | ********************************************************************** |
| 9 | 9 | _____ _____ |
| 10 | | ERASE 1 |* \_/ | 40 |
| 10 | ERASE 1 |* \_/ | 40 Vdd |
| 11 | 11 | EXTINTL 2 | | 39 DB4 |
| 12 | 12 | MDRDWL 3 | | 38 DB5 |
| 13 | | 4 | | 37 DB0 |
| 13 | NETOUT 4 | | 37 DB0 |
| 14 | 14 | BAUDX4 5 | | 36 DB1 |
| 15 | | NETOUT 6 | | 35 COMDATA |
| 16 | | 7 | | 34 MDSELDH |
| 15 | DTR1L 6 | | 35 COMDATA |
| 16 | CTS2L 7 | | 34 MDSELDH |
| 17 | 17 | DCSML 8 | | 33 MDSELCKH |
| 18 | | 9 | | 32 VSYNCH |
| 18 | ROWL 9 | | 32 VSYNCH |
| 19 | 19 | PCENL 10 | ZX8302 | 31 XTAL2 |
| 20 | | 11 | ULA | 30 XTAL1 |
| 20 | Vdd 11 | ULA | 30 XTAL1 |
| 21 | 21 | DB2 12 | | 29 |
| 22 | | 13 | | 28 RESETOUTL |
| 23 | | 14 | | 27 DB7 |
| 22 | TXD1 13 | | 28 RESETOUTL |
| 23 | TXD2 14 | | 27 DB7 |
| 24 | 24 | A5 15 | | 26 IPL1L |
| 25 | 25 | NETIN 16 | | 25 CLKCPU |
| 26 | 26 | A1 17 | | 24 DB3 |
| 27 | 27 | A0 18 | | 23 DB6 |
| 28 | 28 | RAW2 19 | | 22 COMCTL |
| 29 | | RESETOUTL 20 |_____________| 21 RAW1 |
| 29 | GND 20 |_____________| 21 RAW1 |
| 30 | 30 | |
| 31 | 31 | **********************************************************************/ |
| 32 | 32 | |
| 33 | #pragma once |
| 34 | |
| 33 | 35 | #ifndef __ZX8302__ |
| 34 | 36 | #define __ZX8302__ |
| 35 | 37 | |
| 36 | | #include "devcb.h" |
| 38 | #include "emu.h" |
| 37 | 39 | |
| 38 | | /*************************************************************************** |
| 39 | | MACROS / CONSTANTS |
| 40 | | ***************************************************************************/ |
| 41 | 40 | |
| 42 | | DECLARE_LEGACY_DEVICE(ZX8302, zx8302); |
| 43 | 41 | |
| 44 | | #define MDRV_ZX8302_ADD(_tag, _clock, _config) \ |
| 42 | ///************************************************************************* |
| 43 | // MACROS / CONSTANTS |
| 44 | ///************************************************************************* |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | ///************************************************************************* |
| 50 | // INTERFACE CONFIGURATION MACROS |
| 51 | ///************************************************************************* |
| 52 | |
| 53 | #define MDRV_ZX8302_ADD(_tag, _clock, _intrf) \ |
| 45 | 54 | MDRV_DEVICE_ADD(_tag, ZX8302, _clock) \ |
| 46 | | MDRV_DEVICE_CONFIG(_config) |
| 55 | MDRV_DEVICE_CONFIG(_intrf) |
| 47 | 56 | |
| 48 | 57 | #define ZX8302_INTERFACE(name) \ |
| 49 | | const zx8302_interface(name) = |
| 58 | const zx8302_interface (name)= |
| 50 | 59 | |
| 51 | | /*************************************************************************** |
| 52 | | TYPE DEFINITIONS |
| 53 | | ***************************************************************************/ |
| 54 | 60 | |
| 55 | | typedef struct _zx8302_interface zx8302_interface; |
| 56 | | struct _zx8302_interface |
| 61 | |
| 62 | ///************************************************************************* |
| 63 | // TYPE DEFINITIONS |
| 64 | ///************************************************************************* |
| 65 | |
| 66 | // ======================> zx8302_interface |
| 67 | |
| 68 | struct zx8302_interface |
| 57 | 69 | { |
| 58 | | int rtc_clock; /* the RTC clock (pin 30) of the chip */ |
| 70 | int rtc_clock; // the RTC clock (pin 30) of the chip |
| 59 | 71 | |
| 60 | | const char *mdv1_tag; /* microdrive 1 */ |
| 61 | | const char *mdv2_tag; /* microdrive 2 */ |
| 62 | | |
| 63 | | /* this gets called for every change of the IPL1L pin (pin 26) */ |
| 64 | 72 | devcb_write_line out_ipl1l_func; |
| 65 | | |
| 66 | | /* this gets called for every change of the BAUDX4 pin (pin 5) */ |
| 67 | 73 | devcb_write_line out_baudx4_func; |
| 68 | | |
| 69 | | /* this gets called for every write of the COMDATA pin (pin 35) */ |
| 70 | 74 | devcb_write_line out_comdata_func; |
| 75 | devcb_write_line out_txd1_func; |
| 76 | devcb_write_line out_txd2_func; |
| 77 | devcb_read_line in_dtr1_func; |
| 78 | devcb_read_line in_cts2_func; |
| 79 | devcb_write_line out_netout_func; |
| 80 | devcb_read_line in_netin_func; |
| 71 | 81 | }; |
| 72 | 82 | |
| 73 | | /*************************************************************************** |
| 74 | | PROTOTYPES |
| 75 | | ***************************************************************************/ |
| 76 | | /* real time clock */ |
| 77 | | READ8_DEVICE_HANDLER( zx8302_rtc_r ); |
| 78 | | WRITE8_DEVICE_HANDLER( zx8302_rtc_w ); |
| 79 | 83 | |
| 80 | | /* control */ |
| 81 | | WRITE8_DEVICE_HANDLER( zx8302_control_w ); |
| 84 | // ======================> zx8302_device_config |
| 82 | 85 | |
| 83 | | /* microdrive track data */ |
| 84 | | READ8_DEVICE_HANDLER( zx8302_mdv_track_r ); |
| 86 | class zx8302_device_config : public device_config, |
| 87 | public zx8302_interface |
| 88 | { |
| 89 | friend class zx8302_device; |
| 85 | 90 | |
| 86 | | /* status */ |
| 87 | | READ8_DEVICE_HANDLER( zx8302_status_r ); |
| 91 | // construction/destruction |
| 92 | zx8302_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 88 | 93 | |
| 89 | | /* IPC command */ |
| 90 | | WRITE8_DEVICE_HANDLER( zx8302_ipc_command_w ); |
| 94 | public: |
| 95 | // allocators |
| 96 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 97 | virtual device_t *alloc_device(running_machine &machine) const; |
| 91 | 98 | |
| 92 | | /* microdrive control */ |
| 93 | | WRITE8_DEVICE_HANDLER( zx8302_mdv_control_w ); |
| 99 | protected: |
| 100 | // device_config overrides |
| 101 | virtual void device_config_complete(); |
| 102 | }; |
| 94 | 103 | |
| 95 | | /* interrupt status */ |
| 96 | | READ8_DEVICE_HANDLER( zx8302_irq_status_r ); |
| 97 | 104 | |
| 98 | | /* interrupt acknowledge */ |
| 99 | | WRITE8_DEVICE_HANDLER( zx8302_irq_acknowledge_w ); |
| 105 | // ======================> zx8302_device |
| 100 | 106 | |
| 101 | | /* serial data */ |
| 102 | | WRITE8_DEVICE_HANDLER( zx8302_data_w ); |
| 107 | class zx8302_device : public device_t |
| 108 | { |
| 109 | friend class zx8302_device_config; |
| 103 | 110 | |
| 104 | | /* vertical sync */ |
| 105 | | WRITE_LINE_DEVICE_HANDLER( zx8302_vsync_w ); |
| 111 | // construction/destruction |
| 112 | zx8302_device(running_machine &_machine, const zx8302_device_config &_config); |
| 106 | 113 | |
| 107 | | /* communication control */ |
| 108 | | WRITE_LINE_DEVICE_HANDLER( zx8302_comctl_w ); |
| 114 | public: |
| 115 | DECLARE_READ8_MEMBER( rtc_r ); |
| 116 | DECLARE_WRITE8_MEMBER( rtc_w ); |
| 117 | DECLARE_WRITE8_MEMBER( control_w ); |
| 118 | DECLARE_READ8_MEMBER( mdv_track_r ); |
| 119 | DECLARE_READ8_MEMBER( status_r ); |
| 120 | DECLARE_WRITE8_MEMBER( ipc_command_w ); |
| 121 | DECLARE_WRITE8_MEMBER( mdv_control_w ); |
| 122 | DECLARE_READ8_MEMBER( irq_status_r ); |
| 123 | DECLARE_WRITE8_MEMBER( irq_acknowledge_w ); |
| 124 | DECLARE_WRITE8_MEMBER( data_w ); |
| 125 | DECLARE_WRITE_LINE_MEMBER( vsync_w ); |
| 126 | DECLARE_WRITE_LINE_MEMBER( comctl_w ); |
| 127 | DECLARE_WRITE_LINE_MEMBER( comdata_w ); |
| 128 | DECLARE_WRITE_LINE_MEMBER( extint_w ); |
| 109 | 129 | |
| 110 | | /* communication data */ |
| 111 | | WRITE_LINE_DEVICE_HANDLER( zx8302_comdata_w ); |
| 130 | protected: |
| 131 | // device-level overrides |
| 132 | virtual void device_start(); |
| 133 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 112 | 134 | |
| 135 | inline void trigger_interrupt(UINT8 line); |
| 136 | inline void transmit_ipc_data(); |
| 137 | inline void transmit_bit(int state); |
| 138 | inline void transmit_serial_data(); |
| 139 | |
| 140 | private: |
| 141 | static const device_timer_id TIMER_TXD = 0; |
| 142 | static const device_timer_id TIMER_BAUDX4 = 1; |
| 143 | static const device_timer_id TIMER_RTC = 2; |
| 144 | static const device_timer_id TIMER_GAP = 3; |
| 145 | static const device_timer_id TIMER_IPC = 4; |
| 146 | |
| 147 | devcb_resolved_write_line m_out_ipl1l_func; |
| 148 | devcb_resolved_write_line m_out_baudx4_func; |
| 149 | devcb_resolved_write_line m_out_comdata_func; |
| 150 | devcb_resolved_write_line m_out_txd1_func; |
| 151 | devcb_resolved_write_line m_out_txd2_func; |
| 152 | devcb_resolved_read_line m_in_dtr1_func; |
| 153 | devcb_resolved_read_line m_in_cts2_func; |
| 154 | devcb_resolved_write_line m_out_netout_func; |
| 155 | devcb_resolved_read_line m_in_netin_func; |
| 156 | |
| 157 | // registers |
| 158 | UINT8 m_idr; // IPC data register |
| 159 | UINT8 m_tcr; // transfer control register |
| 160 | UINT8 m_tdr; // transfer data register |
| 161 | UINT8 m_irq; // interrupt register |
| 162 | UINT32 m_ctr; // counter register |
| 163 | UINT8 m_status; // status register |
| 164 | |
| 165 | // IPC communication state |
| 166 | int m_comdata; // communication data |
| 167 | int m_comctl; // communication control |
| 168 | int m_ipc_state; // communication state |
| 169 | int m_ipc_rx; // receiving data from IPC |
| 170 | int m_ipc_busy; // IPC busy |
| 171 | int m_baudx4; // IPC baud x4 |
| 172 | |
| 173 | // serial transmit state |
| 174 | int m_tx_bits; // bits transmitted |
| 175 | |
| 176 | // microdrive state |
| 177 | int m_mdrdw; // read/write |
| 178 | int m_mdselck; // select clock |
| 179 | int m_mdseld; // select data |
| 180 | int m_erase; // erase head |
| 181 | int m_mdv_motor; // selected motor |
| 182 | UINT8 m_mdv_data[2]; // track data register |
| 183 | int m_track; // current track |
| 184 | |
| 185 | // timers |
| 186 | emu_timer *m_txd_timer; // transmit timer |
| 187 | emu_timer *m_baudx4_timer; // baud x4 timer |
| 188 | emu_timer *m_rtc_timer; // real time clock timer |
| 189 | emu_timer *m_gap_timer; // microdrive gap timer |
| 190 | emu_timer *m_ipc_timer; // delayed IPC command timer |
| 191 | |
| 192 | const zx8302_device_config &m_config; |
| 193 | }; |
| 194 | |
| 195 | |
| 196 | // device type definition |
| 197 | extern const device_type ZX8302; |
| 198 | |
| 199 | |
| 200 | |
| 113 | 201 | #endif |