src/mess/machine/64h156.c
| r11238 | r11239 | |
| 1 | 1 | /********************************************************************** |
| 2 | 2 | |
| 3 | | Commodore 64H165 Gate Array emulation |
| 3 | Commodore 64H156 Gate Array emulation |
| 4 | 4 | |
| 5 | 5 | Copyright MESS Team. |
| 6 | 6 | Visit http://mamedev.org for licensing and usage restrictions. |
| 7 | 7 | |
| 8 | 8 | **********************************************************************/ |
| 9 | 9 | |
| 10 | /* |
| 11 | |
| 12 | TODO: |
| 13 | |
| 14 | - serial IEC protocol handling |
| 15 | - write to disk image |
| 16 | |
| 17 | */ |
| 18 | |
| 10 | 19 | #include "emu.h" |
| 11 | 20 | #include "64h156.h" |
| 12 | 21 | #include "formats/g64_dsk.h" |
| 22 | #include "machine/devhelpr.h" |
| 13 | 23 | |
| 14 | | /*************************************************************************** |
| 15 | | PARAMETERS |
| 16 | | ***************************************************************************/ |
| 17 | 24 | |
| 18 | | /*************************************************************************** |
| 19 | | TYPE DEFINITIONS |
| 20 | | ***************************************************************************/ |
| 21 | 25 | |
| 22 | | typedef struct _c64h156_t c64h156_t; |
| 23 | | struct _c64h156_t |
| 26 | //************************************************************************** |
| 27 | // MACROS / CONSTANTS |
| 28 | //************************************************************************** |
| 29 | |
| 30 | #define SYNC \ |
| 31 | !(m_oe && ((m_data & G64_SYNC_MARK) == G64_SYNC_MARK)) |
| 32 | |
| 33 | #define BYTE \ |
| 34 | !(m_soe & m_byte) |
| 35 | |
| 36 | |
| 37 | |
| 38 | //************************************************************************** |
| 39 | // DEVICE DEFINITIONS |
| 40 | //************************************************************************** |
| 41 | |
| 42 | const device_type C64H156 = c64h156_device_config::static_alloc_device_config; |
| 43 | |
| 44 | |
| 45 | |
| 46 | //************************************************************************** |
| 47 | // DEVICE CONFIGURATION |
| 48 | //************************************************************************** |
| 49 | |
| 50 | GENERIC_DEVICE_CONFIG_SETUP(c64h156, "64H156"); |
| 51 | |
| 52 | |
| 53 | //------------------------------------------------- |
| 54 | // device_config_complete - perform any |
| 55 | // operations now that the configuration is |
| 56 | // complete |
| 57 | //------------------------------------------------- |
| 58 | |
| 59 | void c64h156_device_config::device_config_complete() |
| 24 | 60 | { |
| 25 | | /* motors */ |
| 26 | | int stp; /* stepper motor phase */ |
| 27 | | int mtr; /* spindle motor on */ |
| 61 | // inherit a copy of the static data |
| 62 | const c64h156_interface *intf = reinterpret_cast<const c64h156_interface *>(static_config()); |
| 63 | if (intf != NULL) |
| 64 | *static_cast<c64h156_interface *>(this) = *intf; |
| 28 | 65 | |
| 29 | | /* track */ |
| 30 | | UINT8 track_buffer[G64_BUFFER_SIZE]; /* track data buffer */ |
| 31 | | int track_len; /* track length */ |
| 32 | | int buffer_pos; /* current byte position within track buffer */ |
| 33 | | int bit_pos; /* current bit position within track buffer byte */ |
| 34 | | int bit_count; /* current data byte bit counter */ |
| 35 | | UINT16 data; /* data shift register */ |
| 36 | | UINT8 yb; /* GCR data byte to write */ |
| 66 | // or initialize to defaults if none provided |
| 67 | else |
| 68 | { |
| 69 | memset(&m_out_atn_func, 0, sizeof(m_out_atn_func)); |
| 70 | memset(&m_out_sync_func, 0, sizeof(m_out_sync_func)); |
| 71 | memset(&m_out_byte_func, 0, sizeof(m_out_byte_func)); |
| 72 | } |
| 73 | } |
| 37 | 74 | |
| 38 | | /* signals */ |
| 39 | | int ds; /* density select */ |
| 40 | | int soe; /* s? output enable */ |
| 41 | | int byte; /* byte ready */ |
| 42 | | int mode; /* mode (0 = write, 1 = read) */ |
| 43 | | }; |
| 44 | 75 | |
| 45 | | /*************************************************************************** |
| 46 | | INLINE FUNCTIONS |
| 47 | | ***************************************************************************/ |
| 48 | 76 | |
| 49 | | INLINE c64h156_t *get_safe_token(device_t *device) |
| 77 | //************************************************************************** |
| 78 | // INLINE HELPERS |
| 79 | //************************************************************************** |
| 80 | |
| 81 | //------------------------------------------------- |
| 82 | // set_atn_line - |
| 83 | //------------------------------------------------- |
| 84 | |
| 85 | inline void c64h156_device::set_atn_line() |
| 50 | 86 | { |
| 51 | | assert(device != NULL); |
| 52 | | assert(device->type() == C64H156); |
| 53 | | return (c64h156_t *)downcast<legacy_device_base *>(device)->token(); |
| 87 | m_atn = !m_atni; // TODO m_atna |
| 88 | |
| 89 | devcb_call_write_line(&m_out_atn_func, m_atn); |
| 54 | 90 | } |
| 55 | 91 | |
| 56 | | /*************************************************************************** |
| 57 | | IMPLEMENTATION |
| 58 | | ***************************************************************************/ |
| 59 | 92 | |
| 60 | | READ8_DEVICE_HANDLER( c64h156_yb_r ) |
| 93 | //------------------------------------------------- |
| 94 | // set_sync_line - |
| 95 | //------------------------------------------------- |
| 96 | |
| 97 | inline void c64h156_device::set_sync_line(int state) |
| 61 | 98 | { |
| 62 | | return 0; |
| 99 | m_sync = state; |
| 100 | |
| 101 | devcb_call_write_line(&m_out_sync_func, m_sync); |
| 63 | 102 | } |
| 64 | 103 | |
| 65 | | WRITE8_DEVICE_HANDLER( c64h156_yb_w ) |
| 104 | |
| 105 | //------------------------------------------------- |
| 106 | // set_byte_line - |
| 107 | //------------------------------------------------- |
| 108 | |
| 109 | inline void c64h156_device::set_byte_line(int state) |
| 66 | 110 | { |
| 111 | m_byte = state; |
| 112 | |
| 113 | devcb_call_write_line(&m_out_byte_func, BYTE); |
| 67 | 114 | } |
| 68 | 115 | |
| 69 | | READ_LINE_DEVICE_HANDLER( c64h156_sync_r ) |
| 116 | |
| 117 | //------------------------------------------------- |
| 118 | // read_current_track - |
| 119 | //------------------------------------------------- |
| 120 | |
| 121 | inline void c64h156_device::read_current_track() |
| 70 | 122 | { |
| 71 | | return 0; |
| 123 | int track_length = G64_BUFFER_SIZE; |
| 124 | |
| 125 | // read track data |
| 126 | floppy_drive_read_track_data_info_buffer(m_image, 0, m_track_buffer, &track_length); |
| 127 | |
| 128 | // extract track length |
| 129 | m_track_len = floppy_drive_get_current_track_size(m_image, 0); |
| 130 | |
| 131 | // set bit pointer to track start |
| 132 | m_buffer_pos = 0; |
| 133 | m_bit_pos = 7; |
| 134 | m_bit_count = 0; |
| 72 | 135 | } |
| 73 | 136 | |
| 74 | | READ_LINE_DEVICE_HANDLER( c64h156_byte_r ) |
| 137 | |
| 138 | //------------------------------------------------- |
| 139 | // receive_bit - |
| 140 | //------------------------------------------------- |
| 141 | |
| 142 | inline void c64h156_device::receive_bit() |
| 75 | 143 | { |
| 76 | | return 0; |
| 144 | int byte = 0; |
| 145 | |
| 146 | // shift in data from the read head |
| 147 | m_data <<= 1; |
| 148 | m_data |= BIT(m_track_buffer[m_buffer_pos], m_bit_pos); |
| 149 | m_bit_pos--; |
| 150 | m_bit_count++; |
| 151 | |
| 152 | if (m_bit_pos < 0) |
| 153 | { |
| 154 | m_bit_pos = 7; |
| 155 | m_buffer_pos++; |
| 156 | |
| 157 | if (m_buffer_pos >= m_track_len) |
| 158 | { |
| 159 | // loop to the start of the track |
| 160 | m_buffer_pos = 0; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | set_sync_line(SYNC); |
| 165 | |
| 166 | if (!m_sync) |
| 167 | { |
| 168 | // SYNC detected |
| 169 | m_bit_count = 0; |
| 170 | } |
| 171 | |
| 172 | if (m_bit_count > 7) |
| 173 | { |
| 174 | // byte ready |
| 175 | m_bit_count = 0; |
| 176 | byte = 1; |
| 177 | |
| 178 | m_yb = m_data & 0xff; |
| 179 | |
| 180 | if (!m_yb) |
| 181 | { |
| 182 | // simulate weak bits with randomness |
| 183 | m_yb = m_machine.rand() & 0xff; |
| 184 | } |
| 185 | |
| 186 | set_byte_line(byte); |
| 187 | } |
| 77 | 188 | } |
| 78 | 189 | |
| 79 | | void c64h156_stp_w(device_t *device, int stp) |
| 190 | |
| 191 | |
| 192 | //************************************************************************** |
| 193 | // LIVE DEVICE |
| 194 | //************************************************************************** |
| 195 | |
| 196 | //------------------------------------------------- |
| 197 | // c64h156_device - constructor |
| 198 | //------------------------------------------------- |
| 199 | |
| 200 | c64h156_device::c64h156_device(running_machine &_machine, const c64h156_device_config &_config) |
| 201 | : device_t(_machine, _config), |
| 202 | m_image(*this->owner(), FLOPPY_0), |
| 203 | m_stp(-1), |
| 204 | m_mtr(0), |
| 205 | m_accl(1), |
| 206 | m_ds(-1), |
| 207 | m_soe(0), |
| 208 | m_byte(0), |
| 209 | m_oe(0), |
| 210 | m_sync(1), |
| 211 | m_atn(1), |
| 212 | m_atni(1), |
| 213 | m_atna(1), |
| 214 | m_config(_config) |
| 80 | 215 | { |
| 81 | 216 | } |
| 82 | 217 | |
| 83 | | WRITE_LINE_DEVICE_HANDLER( c64h156_stp1_w ) |
| 218 | |
| 219 | //------------------------------------------------- |
| 220 | // device_start - device-specific startup |
| 221 | //------------------------------------------------- |
| 222 | |
| 223 | void c64h156_device::device_start() |
| 84 | 224 | { |
| 225 | // resolve callbacks |
| 226 | devcb_resolve_write_line(&m_out_atn_func, &m_config.m_out_atn_func, this); |
| 227 | devcb_resolve_write_line(&m_out_sync_func, &m_config.m_out_sync_func, this); |
| 228 | devcb_resolve_write_line(&m_out_byte_func, &m_config.m_out_byte_func, this); |
| 229 | |
| 230 | // allocate timers |
| 231 | m_bit_timer = timer_alloc(); |
| 232 | |
| 233 | // register for state saving |
| 234 | save_item(NAME(m_stp)); |
| 235 | save_item(NAME(m_mtr)); |
| 236 | save_item(NAME(m_track_len)); |
| 237 | save_item(NAME(m_buffer_pos)); |
| 238 | save_item(NAME(m_bit_pos)); |
| 239 | save_item(NAME(m_bit_count)); |
| 240 | save_item(NAME(m_data)); |
| 241 | save_item(NAME(m_yb)); |
| 242 | save_item(NAME(m_accl)); |
| 243 | save_item(NAME(m_ds)); |
| 244 | save_item(NAME(m_soe)); |
| 245 | save_item(NAME(m_byte)); |
| 246 | save_item(NAME(m_oe)); |
| 247 | save_item(NAME(m_sync)); |
| 248 | save_item(NAME(m_atn)); |
| 249 | save_item(NAME(m_atni)); |
| 250 | save_item(NAME(m_atna)); |
| 85 | 251 | } |
| 86 | 252 | |
| 87 | | WRITE_LINE_DEVICE_HANDLER( c64h156_mtr_w ) |
| 253 | |
| 254 | //------------------------------------------------- |
| 255 | // device_timer - handler timer events |
| 256 | //------------------------------------------------- |
| 257 | |
| 258 | void c64h156_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 88 | 259 | { |
| 260 | receive_bit(); |
| 89 | 261 | } |
| 90 | 262 | |
| 91 | | void c64h156_ds_w(device_t *device, int data) |
| 263 | |
| 264 | //------------------------------------------------- |
| 265 | // yb_r - |
| 266 | //------------------------------------------------- |
| 267 | |
| 268 | READ8_MEMBER( c64h156_device::yb_r ) |
| 92 | 269 | { |
| 270 | set_byte_line(0); // TODO remove? |
| 271 | |
| 272 | return m_yb; |
| 93 | 273 | } |
| 94 | 274 | |
| 95 | | WRITE_LINE_DEVICE_HANDLER( c64h156_ted_w ) |
| 275 | |
| 276 | //------------------------------------------------- |
| 277 | // yb_w - |
| 278 | //------------------------------------------------- |
| 279 | |
| 280 | WRITE8_MEMBER( c64h156_device::yb_w ) |
| 96 | 281 | { |
| 282 | m_yb = data; |
| 97 | 283 | } |
| 98 | 284 | |
| 99 | | WRITE_LINE_DEVICE_HANDLER( c64h156_oe_w ) |
| 285 | |
| 286 | //------------------------------------------------- |
| 287 | // test_w - |
| 288 | //------------------------------------------------- |
| 289 | |
| 290 | WRITE_LINE_MEMBER( c64h156_device::test_w ) |
| 100 | 291 | { |
| 101 | 292 | } |
| 102 | 293 | |
| 103 | | WRITE_LINE_DEVICE_HANDLER( c64h156_soe_w ) |
| 294 | |
| 295 | //------------------------------------------------- |
| 296 | // accl_w - |
| 297 | //------------------------------------------------- |
| 298 | |
| 299 | WRITE_LINE_MEMBER( c64h156_device::accl_w ) |
| 104 | 300 | { |
| 301 | m_accl = state; |
| 105 | 302 | } |
| 106 | 303 | |
| 107 | | WRITE_LINE_DEVICE_HANDLER( c64h156_atni_w ) |
| 304 | |
| 305 | //------------------------------------------------- |
| 306 | // sync_r - |
| 307 | //------------------------------------------------- |
| 308 | |
| 309 | READ_LINE_MEMBER( c64h156_device::sync_r ) |
| 108 | 310 | { |
| 311 | return m_sync; |
| 109 | 312 | } |
| 110 | 313 | |
| 111 | | WRITE_LINE_DEVICE_HANDLER( c64h156_atna_w ) |
| 314 | |
| 315 | //------------------------------------------------- |
| 316 | // byte_r - |
| 317 | //------------------------------------------------- |
| 318 | |
| 319 | READ_LINE_MEMBER( c64h156_device::byte_r ) |
| 112 | 320 | { |
| 321 | return BYTE; |
| 113 | 322 | } |
| 114 | 323 | |
| 115 | | /*------------------------------------------------- |
| 116 | | DEVICE_START( c64h156 ) |
| 117 | | -------------------------------------------------*/ |
| 118 | 324 | |
| 119 | | static DEVICE_START( c64h156 ) |
| 325 | //------------------------------------------------- |
| 326 | // stp_w - |
| 327 | //------------------------------------------------- |
| 328 | |
| 329 | WRITE_LINE_MEMBER( c64h156_device::mtr_w ) |
| 120 | 330 | { |
| 121 | | // c64h156_t *c64h156 = get_safe_token(device); |
| 331 | if (m_mtr != state) |
| 332 | { |
| 333 | if (state) |
| 334 | { |
| 335 | // read track data |
| 336 | read_current_track(); |
| 337 | } |
| 122 | 338 | |
| 123 | | /* allocate data timer */ |
| 124 | | // c64h156->bit_timer = device->machine().scheduler().timer_alloc(FUNC(bit_tick), (void *)device); |
| 339 | floppy_mon_w(m_image, !state); |
| 340 | m_bit_timer->enable(state); |
| 125 | 341 | |
| 126 | | /* register for state saving */ |
| 127 | | // device->save_item(NAME(c64h156->)); |
| 342 | m_mtr = state; |
| 343 | } |
| 128 | 344 | } |
| 129 | 345 | |
| 130 | | /*------------------------------------------------- |
| 131 | | DEVICE_GET_INFO( c64h156 ) |
| 132 | | -------------------------------------------------*/ |
| 133 | 346 | |
| 134 | | DEVICE_GET_INFO( c64h156 ) |
| 347 | //------------------------------------------------- |
| 348 | // oe_w - |
| 349 | //------------------------------------------------- |
| 350 | |
| 351 | WRITE_LINE_MEMBER( c64h156_device::oe_w ) |
| 135 | 352 | { |
| 136 | | switch (state) |
| 353 | m_oe = state; |
| 354 | } |
| 355 | |
| 356 | |
| 357 | //------------------------------------------------- |
| 358 | // soe_w - |
| 359 | //------------------------------------------------- |
| 360 | |
| 361 | WRITE_LINE_MEMBER( c64h156_device::soe_w ) |
| 362 | { |
| 363 | m_soe = state; |
| 364 | } |
| 365 | |
| 366 | |
| 367 | //------------------------------------------------- |
| 368 | // atn_r - |
| 369 | //------------------------------------------------- |
| 370 | |
| 371 | READ_LINE_MEMBER( c64h156_device::atn_r ) |
| 372 | { |
| 373 | return m_atn; |
| 374 | } |
| 375 | |
| 376 | |
| 377 | //------------------------------------------------- |
| 378 | // atni_w - |
| 379 | //------------------------------------------------- |
| 380 | |
| 381 | WRITE_LINE_MEMBER( c64h156_device::atni_w ) |
| 382 | { |
| 383 | m_atni = state; |
| 384 | |
| 385 | set_atn_line(); |
| 386 | } |
| 387 | |
| 388 | |
| 389 | //------------------------------------------------- |
| 390 | // atna_w - |
| 391 | //------------------------------------------------- |
| 392 | |
| 393 | WRITE_LINE_MEMBER( c64h156_device::atna_w ) |
| 394 | { |
| 395 | m_atna = state; |
| 396 | |
| 397 | set_atn_line(); |
| 398 | } |
| 399 | |
| 400 | |
| 401 | //------------------------------------------------- |
| 402 | // stp_w - |
| 403 | //------------------------------------------------- |
| 404 | |
| 405 | void c64h156_device::stp_w(int data) |
| 406 | { |
| 407 | if (m_mtr && (m_stp != data)) |
| 137 | 408 | { |
| 138 | | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 139 | | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(c64h156_t); break; |
| 409 | int tracks = 0; |
| 140 | 410 | |
| 141 | | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 142 | | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(c64h156); break; |
| 143 | | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 144 | | case DEVINFO_FCT_RESET: /* Nothing */ break; |
| 411 | switch (m_stp) |
| 412 | { |
| 413 | case 0: if (data == 1) tracks++; else if (data == 3) tracks--; break; |
| 414 | case 1: if (data == 2) tracks++; else if (data == 0) tracks--; break; |
| 415 | case 2: if (data == 3) tracks++; else if (data == 1) tracks--; break; |
| 416 | case 3: if (data == 0) tracks++; else if (data == 2) tracks--; break; |
| 417 | } |
| 145 | 418 | |
| 146 | | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 147 | | case DEVINFO_STR_NAME: strcpy(info->s, "Commodore 64H156"); break; |
| 148 | | case DEVINFO_STR_FAMILY: strcpy(info->s, "Commodore 1541"); break; |
| 149 | | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 150 | | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 151 | | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 419 | if (tracks != 0) |
| 420 | { |
| 421 | // step read/write head |
| 422 | floppy_drive_seek(m_image, tracks); |
| 423 | |
| 424 | // read new track data |
| 425 | read_current_track(); |
| 426 | } |
| 427 | |
| 428 | m_stp = data; |
| 152 | 429 | } |
| 153 | 430 | } |
| 154 | 431 | |
| 155 | | DEFINE_LEGACY_DEVICE(C64H156, c64h156); |
| 432 | |
| 433 | //------------------------------------------------- |
| 434 | // ds_w - density select |
| 435 | //------------------------------------------------- |
| 436 | |
| 437 | void c64h156_device::ds_w(int data) |
| 438 | { |
| 439 | if (m_ds != data) |
| 440 | { |
| 441 | m_bit_timer->adjust(attotime::zero, 0, attotime::from_hz(C2040_BITRATE[data]/4)); |
| 442 | m_ds = data; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | |
| 447 | //------------------------------------------------- |
| 448 | // on_disk_changed - |
| 449 | //------------------------------------------------- |
| 450 | |
| 451 | void c64h156_device::on_disk_changed() |
| 452 | { |
| 453 | read_current_track(); |
| 454 | } |
src/mess/machine/64h156.h
| r11238 | r11239 | |
| 1 | 1 | /********************************************************************** |
| 2 | 2 | |
| 3 | | Commodore 64H165 Gate Array emulation |
| 3 | Commodore 64H156 Gate Array emulation |
| 4 | 4 | |
| 5 | | Used in 1541B/1541C/1541-II/1571 |
| 5 | Used in 1541B/1541C/1541-II/1551/1571 |
| 6 | 6 | |
| 7 | 7 | Copyright MESS Team. |
| 8 | 8 | Visit http://mamedev.org for licensing and usage restrictions. |
| r11238 | r11239 | |
| 55 | 55 | |
| 56 | 56 | **********************************************************************/ |
| 57 | 57 | |
| 58 | | #ifndef __64H156__ |
| 59 | | #define __64H156__ |
| 58 | #pragma once |
| 60 | 59 | |
| 61 | | #include "devcb.h" |
| 60 | #ifndef __C64H156__ |
| 61 | #define __C64H156__ |
| 62 | 62 | |
| 63 | | /*************************************************************************** |
| 64 | | MACROS / CONSTANTS |
| 65 | | ***************************************************************************/ |
| 63 | #define ADDRESS_MAP_MODERN |
| 66 | 64 | |
| 67 | | DECLARE_LEGACY_DEVICE(C64H156, c64h156); |
| 65 | #include "emu.h" |
| 66 | #include "imagedev/flopdrv.h" |
| 67 | #include "formats/d64_dsk.h" |
| 68 | #include "formats/g64_dsk.h" |
| 68 | 69 | |
| 69 | | #define MCFG_64H156_ADD(_tag, _clock, _intrf) \ |
| 70 | |
| 71 | |
| 72 | //************************************************************************** |
| 73 | // INTERFACE CONFIGURATION MACROS |
| 74 | //************************************************************************** |
| 75 | |
| 76 | #define MCFG_64H156_ADD(_tag, _clock, _config) \ |
| 70 | 77 | MCFG_DEVICE_ADD(_tag, C64H156, _clock) \ |
| 71 | | MCFG_DEVICE_CONFIG(_intrf) |
| 78 | MCFG_DEVICE_CONFIG(_config) |
| 72 | 79 | |
| 73 | | #define C64H156_INTERFACE(name) \ |
| 74 | | const c64h156_interface (name)= |
| 80 | #define C64H156_INTERFACE(_name) \ |
| 81 | const c64h156_interface (_name) = |
| 75 | 82 | |
| 76 | | /*************************************************************************** |
| 77 | | TYPE DEFINITIONS |
| 78 | | ***************************************************************************/ |
| 79 | 83 | |
| 80 | | typedef struct _c64h156_interface c64h156_interface; |
| 81 | | struct _c64h156_interface |
| 84 | |
| 85 | //************************************************************************** |
| 86 | // TYPE DEFINITIONS |
| 87 | //************************************************************************** |
| 88 | |
| 89 | // ======================> c64h156_interface |
| 90 | |
| 91 | struct c64h156_interface |
| 82 | 92 | { |
| 83 | | devcb_write_line out_atn_func; |
| 84 | | devcb_write_line out_sync_func; |
| 85 | | devcb_write_line out_byte_func; |
| 93 | devcb_write_line m_out_atn_func; |
| 94 | devcb_write_line m_out_sync_func; |
| 95 | devcb_write_line m_out_byte_func; |
| 86 | 96 | }; |
| 87 | 97 | |
| 88 | | /*************************************************************************** |
| 89 | | PROTOTYPES |
| 90 | | ***************************************************************************/ |
| 91 | 98 | |
| 92 | | /* parallel data */ |
| 93 | | READ8_DEVICE_HANDLER( c64h156_yb_r ); |
| 94 | | WRITE8_DEVICE_HANDLER( c64h156_yb_w ); |
| 99 | // ======================> c64h156_device_config |
| 95 | 100 | |
| 96 | | /* sync mark detected */ |
| 97 | | READ_LINE_DEVICE_HANDLER( c64h156_sync_r ); |
| 101 | class c64h156_device_config : public device_config, |
| 102 | public c64h156_interface |
| 103 | { |
| 104 | friend class c64h156_device; |
| 98 | 105 | |
| 99 | | /* byte ready */ |
| 100 | | READ_LINE_DEVICE_HANDLER( c64h156_byte_r ); |
| 106 | // construction/destruction |
| 107 | c64h156_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 101 | 108 | |
| 102 | | /* stepper driver */ |
| 103 | | void c64h156_stp_w(device_t *device, int data); |
| 109 | public: |
| 110 | // allocators |
| 111 | static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock); |
| 112 | virtual device_t *alloc_device(running_machine &machine) const; |
| 104 | 113 | |
| 105 | | /* stepper motor */ |
| 106 | | WRITE_LINE_DEVICE_HANDLER( c64h156_mtr_w ); |
| 114 | protected: |
| 115 | // device_config overrides |
| 116 | virtual void device_config_complete(); |
| 117 | }; |
| 107 | 118 | |
| 108 | | /* density select */ |
| 109 | | void c64h156_ds_w(device_t *device, int data); |
| 110 | 119 | |
| 111 | | /* */ |
| 112 | | WRITE_LINE_DEVICE_HANDLER( c64h156_ted_w ); |
| 120 | // ======================> c64h156_device |
| 113 | 121 | |
| 114 | | /* mode select */ |
| 115 | | WRITE_LINE_DEVICE_HANDLER( c64h156_oe_w ); |
| 122 | class c64h156_device : public device_t |
| 123 | { |
| 124 | friend class c64h156_device_config; |
| 116 | 125 | |
| 117 | | /* byte input enable */ |
| 118 | | WRITE_LINE_DEVICE_HANDLER( c64h156_soe_w ); |
| 126 | // construction/destruction |
| 127 | c64h156_device(running_machine &_machine, const c64h156_device_config &_config); |
| 119 | 128 | |
| 120 | | /* attention input */ |
| 121 | | WRITE_LINE_DEVICE_HANDLER( c64h156_atni_w ); |
| 129 | public: |
| 130 | DECLARE_READ8_MEMBER( yb_r ); |
| 131 | DECLARE_WRITE8_MEMBER( yb_w ); |
| 132 | DECLARE_WRITE_LINE_MEMBER( test_w ); |
| 133 | DECLARE_WRITE_LINE_MEMBER( accl_w ); |
| 134 | DECLARE_READ_LINE_MEMBER( sync_r ); |
| 135 | DECLARE_READ_LINE_MEMBER( byte_r ); |
| 136 | DECLARE_WRITE_LINE_MEMBER( mtr_w ); |
| 137 | DECLARE_WRITE_LINE_MEMBER( oe_w ); |
| 138 | DECLARE_WRITE_LINE_MEMBER( soe_w ); |
| 139 | DECLARE_READ_LINE_MEMBER( atn_r ); |
| 140 | DECLARE_WRITE_LINE_MEMBER( atni_w ); |
| 141 | DECLARE_WRITE_LINE_MEMBER( atna_w ); |
| 122 | 142 | |
| 123 | | /* attention acknowledge */ |
| 124 | | WRITE_LINE_DEVICE_HANDLER( c64h156_atna_w ); |
| 143 | void stp_w(int data); |
| 144 | void ds_w(int data); |
| 125 | 145 | |
| 146 | void on_disk_changed(); |
| 147 | |
| 148 | protected: |
| 149 | // device-level overrides |
| 150 | virtual void device_start(); |
| 151 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 152 | |
| 153 | inline void set_atn_line(); |
| 154 | inline void set_sync_line(int state); |
| 155 | inline void set_byte_line(int state); |
| 156 | inline void read_current_track(); |
| 157 | inline void spindle_motor(int mtr); |
| 158 | inline void step_motor(int mtr, int stp); |
| 159 | inline void receive_bit(); |
| 160 | |
| 161 | private: |
| 162 | devcb_resolved_write_line m_out_atn_func; |
| 163 | devcb_resolved_write_line m_out_sync_func; |
| 164 | devcb_resolved_write_line m_out_byte_func; |
| 165 | |
| 166 | required_device<device_t> m_image; |
| 167 | |
| 168 | // motors |
| 169 | int m_stp; // stepper motor phase |
| 170 | int m_mtr; // spindle motor on |
| 171 | |
| 172 | // track |
| 173 | UINT8 m_track_buffer[G64_BUFFER_SIZE]; // track data buffer |
| 174 | size_t m_track_len; // track length |
| 175 | offs_t m_buffer_pos; // current byte position within track buffer |
| 176 | int m_bit_pos; // current bit position within track buffer byte |
| 177 | int m_bit_count; // current data byte bit counter |
| 178 | UINT16 m_data; // data shift register |
| 179 | UINT8 m_yb; // GCR data byte |
| 180 | |
| 181 | // signals |
| 182 | int m_accl; // 1/2 MHz select |
| 183 | int m_ds; // density select |
| 184 | int m_soe; // s? output enable |
| 185 | int m_byte; // byte ready |
| 186 | int m_oe; // output enable (0 = write, 1 = read) |
| 187 | int m_sync; // sync character detected |
| 188 | |
| 189 | // IEC |
| 190 | int m_atn; // attention |
| 191 | int m_atni; // attention input |
| 192 | int m_atna; // attention acknowledge |
| 193 | |
| 194 | // timers |
| 195 | emu_timer *m_bit_timer; |
| 196 | |
| 197 | const c64h156_device_config &m_config; |
| 198 | }; |
| 199 | |
| 200 | |
| 201 | |
| 202 | // device type definition |
| 203 | extern const device_type C64H156; |
| 204 | |
| 205 | |
| 206 | |
| 126 | 207 | #endif |
src/mess/machine/c1551.c
| r11238 | r11239 | |
| 29 | 29 | #define M6510T_TAG "u2" |
| 30 | 30 | #define M6523_0_TAG "u3" |
| 31 | 31 | #define M6523_1_TAG "ci_u2" |
| 32 | #define C64H156_TAG "u6" |
| 32 | 33 | |
| 33 | | #define SYNC \ |
| 34 | | !(m_mode && ((m_data & G64_SYNC_MARK) == G64_SYNC_MARK)) |
| 35 | | |
| 36 | 34 | enum |
| 37 | 35 | { |
| 38 | 36 | LED_POWER = 0, |
| r11238 | r11239 | |
| 112 | 110 | |
| 113 | 111 | bit description |
| 114 | 112 | |
| 115 | | P0 STP0A |
| 116 | | P1 STP0B |
| 117 | | P2 MTR0 |
| 118 | | P3 ACT0 |
| 113 | P0 |
| 114 | P1 |
| 115 | P2 |
| 116 | P3 |
| 119 | 117 | P4 WPS |
| 120 | | P5 DS0 |
| 121 | | P6 DS1 |
| 118 | P5 |
| 119 | P6 |
| 122 | 120 | P7 BYTE LTCHED |
| 123 | 121 | |
| 124 | 122 | */ |
| r11238 | r11239 | |
| 126 | 124 | UINT8 data = 0; |
| 127 | 125 | |
| 128 | 126 | // write protect sense |
| 129 | | data |= !floppy_wpt_r(m_image) << 4; |
| 127 | data |= (!floppy_wpt_r(m_image)) << 4; |
| 130 | 128 | |
| 131 | 129 | // byte latched |
| 132 | | data |= (m_soe & m_byte) << 7; |
| 130 | data |= m_ga->atn_r() << 7; |
| 133 | 131 | |
| 134 | 132 | return data; |
| 135 | 133 | } |
| r11238 | r11239 | |
| 145 | 143 | P1 STP0B |
| 146 | 144 | P2 MTR0 |
| 147 | 145 | P3 ACT0 |
| 148 | | P4 WPS |
| 146 | P4 |
| 149 | 147 | P5 DS0 |
| 150 | 148 | P6 DS1 |
| 151 | | P7 BYTE LTCHED |
| 149 | P7 |
| 152 | 150 | |
| 153 | 151 | */ |
| 154 | 152 | |
| 155 | 153 | // spindle motor |
| 156 | | int mtr = BIT(data, 2); |
| 157 | | spindle_motor(mtr); |
| 154 | m_ga->mtr_w(BIT(data, 2)); |
| 158 | 155 | |
| 159 | 156 | // stepper motor |
| 160 | | int stp = data & 0x03; |
| 161 | | step_motor(mtr, stp); |
| 157 | m_ga->stp_w(data & 0x03); |
| 162 | 158 | |
| 163 | 159 | // activity LED |
| 164 | | output_set_led_value(LED_ACT, BIT(data, 6)); |
| 160 | output_set_led_value(LED_ACT, BIT(data, 3)); |
| 165 | 161 | |
| 166 | 162 | // density select |
| 167 | | int ds = (data >> 5) & 0x03; |
| 168 | | |
| 169 | | if (m_ds != ds) |
| 170 | | { |
| 171 | | m_bit_timer->adjust(attotime::zero, 0, attotime::from_hz(C2040_BITRATE[ds]/4)); |
| 172 | | m_ds = ds; |
| 173 | | } |
| 163 | m_ga->ds_w((data >> 5) & 0x03); |
| 174 | 164 | } |
| 175 | 165 | |
| 176 | 166 | |
| r11238 | r11239 | |
| 229 | 219 | } |
| 230 | 220 | |
| 231 | 221 | |
| 232 | | READ8_MEMBER( c1551_device::yb_r ) |
| 233 | | { |
| 234 | | /* |
| 235 | | |
| 236 | | bit description |
| 237 | | |
| 238 | | PB0 YB0 |
| 239 | | PB1 YB1 |
| 240 | | PB2 YB2 |
| 241 | | PB3 YB3 |
| 242 | | PB4 YB4 |
| 243 | | PB5 YB5 |
| 244 | | PB6 YB6 |
| 245 | | PB7 YB7 |
| 246 | | |
| 247 | | */ |
| 248 | | |
| 249 | | m_byte = 0; |
| 250 | | |
| 251 | | return m_yb; |
| 252 | | } |
| 253 | | |
| 254 | | |
| 255 | | WRITE8_MEMBER( c1551_device::yb_w ) |
| 256 | | { |
| 257 | | /* |
| 258 | | |
| 259 | | bit description |
| 260 | | |
| 261 | | PB0 YB0 |
| 262 | | PB1 YB1 |
| 263 | | PB2 YB2 |
| 264 | | PB3 YB3 |
| 265 | | PB4 YB4 |
| 266 | | PB5 YB5 |
| 267 | | PB6 YB6 |
| 268 | | PB7 YB7 |
| 269 | | |
| 270 | | */ |
| 271 | | |
| 272 | | m_yb = data; |
| 273 | | } |
| 274 | | |
| 275 | | |
| 276 | 222 | READ8_MEMBER( c1551_device::tpi0_pc_r ) |
| 277 | 223 | { |
| 278 | 224 | /* |
| r11238 | r11239 | |
| 296 | 242 | data |= m_config.m_address << 5; |
| 297 | 243 | |
| 298 | 244 | // SYNC detect line |
| 299 | | data |= SYNC << 6; |
| 245 | data |= m_ga->sync_r() << 6; |
| 300 | 246 | |
| 301 | 247 | // TCBM data valid |
| 302 | 248 | data |= m_dav << 7; |
| r11238 | r11239 | |
| 331 | 277 | m_ack = BIT(data, 3); |
| 332 | 278 | |
| 333 | 279 | // read/write mode |
| 334 | | m_mode = BIT(data, 4); |
| 280 | m_ga->oe_w(BIT(data, 4)); |
| 335 | 281 | } |
| 336 | 282 | |
| 337 | 283 | |
| r11238 | r11239 | |
| 340 | 286 | DEVCB_NULL, |
| 341 | 287 | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tcbm_data_r), |
| 342 | 288 | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tcbm_data_w), |
| 343 | | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, yb_r), |
| 344 | | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, yb_w), |
| 289 | DEVCB_DEVICE_MEMBER(C64H156_TAG, c64h156_device, yb_r), |
| 290 | DEVCB_DEVICE_MEMBER(C64H156_TAG, c64h156_device, yb_w), |
| 345 | 291 | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi0_pc_r), |
| 346 | 292 | DEVCB_DEVICE_MEMBER(DEVICE_SELF_OWNER, c1551_device, tpi0_pc_w), |
| 347 | 293 | DEVCB_NULL, |
| r11238 | r11239 | |
| 386 | 332 | PC3 |
| 387 | 333 | PC4 |
| 388 | 334 | PC5 |
| 389 | | PC6 TCBM DAV |
| 335 | PC6 |
| 390 | 336 | PC7 TCBM ACK |
| 391 | 337 | |
| 392 | 338 | */ |
| r11238 | r11239 | |
| 413 | 359 | PC4 |
| 414 | 360 | PC5 |
| 415 | 361 | PC6 TCBM DAV |
| 416 | | PC7 TCBM ACK |
| 362 | PC7 |
| 417 | 363 | |
| 418 | 364 | */ |
| 419 | 365 | |
| r11238 | r11239 | |
| 475 | 421 | |
| 476 | 422 | |
| 477 | 423 | //------------------------------------------------- |
| 424 | // C64H156_INTERFACE( ga_intf ) |
| 425 | //------------------------------------------------- |
| 426 | |
| 427 | static C64H156_INTERFACE( ga_intf ) |
| 428 | { |
| 429 | DEVCB_NULL, |
| 430 | DEVCB_NULL, |
| 431 | DEVCB_LINE_MEMBER(c64h156_device, atni_w) |
| 432 | }; |
| 433 | |
| 434 | |
| 435 | //------------------------------------------------- |
| 478 | 436 | // MACHINE_DRIVER( c1551 ) |
| 479 | 437 | //------------------------------------------------- |
| 480 | 438 | |
| r11238 | r11239 | |
| 487 | 445 | MCFG_TPI6525_ADD(M6523_1_TAG, tpi1_intf) |
| 488 | 446 | |
| 489 | 447 | MCFG_FLOPPY_DRIVE_ADD(FLOPPY_0, c1551_floppy_config) |
| 448 | MCFG_64H156_ADD(C64H156_TAG, XTAL_16MHz, ga_intf) |
| 490 | 449 | MACHINE_CONFIG_END |
| 491 | 450 | |
| 492 | 451 | |
| r11238 | r11239 | |
| 503 | 462 | |
| 504 | 463 | |
| 505 | 464 | //************************************************************************** |
| 506 | | // INLINE HELPERS |
| 507 | | //************************************************************************** |
| 508 | | |
| 509 | | //------------------------------------------------- |
| 510 | | // read_current_track - |
| 511 | | //------------------------------------------------- |
| 512 | | |
| 513 | | inline void c1551_device::read_current_track() |
| 514 | | { |
| 515 | | m_track_len = G64_BUFFER_SIZE; |
| 516 | | m_buffer_pos = 0; |
| 517 | | m_bit_pos = 7; |
| 518 | | m_bit_count = 0; |
| 519 | | |
| 520 | | // read track data |
| 521 | | floppy_drive_read_track_data_info_buffer(m_image, 0, m_track_buffer, &m_track_len); |
| 522 | | |
| 523 | | // extract track length |
| 524 | | m_track_len = floppy_drive_get_current_track_size(m_image, 0); |
| 525 | | } |
| 526 | | |
| 527 | | |
| 528 | | //------------------------------------------------- |
| 529 | | // on_disk_change - |
| 530 | | //------------------------------------------------- |
| 531 | | |
| 532 | | void c1551_device::on_disk_change(device_image_interface &image) |
| 533 | | { |
| 534 | | c1551_device *c1551 = static_cast<c1551_device *>(image.device().owner()); |
| 535 | | |
| 536 | | c1551->read_current_track(); |
| 537 | | } |
| 538 | | |
| 539 | | |
| 540 | | //------------------------------------------------- |
| 541 | | // spindle_motor - |
| 542 | | //------------------------------------------------- |
| 543 | | |
| 544 | | inline void c1551_device::spindle_motor(int mtr) |
| 545 | | { |
| 546 | | if (m_mtr != mtr) |
| 547 | | { |
| 548 | | if (mtr) |
| 549 | | { |
| 550 | | // read track data |
| 551 | | read_current_track(); |
| 552 | | } |
| 553 | | |
| 554 | | floppy_mon_w(m_image, !mtr); |
| 555 | | m_bit_timer->enable(mtr); |
| 556 | | |
| 557 | | m_mtr = mtr; |
| 558 | | } |
| 559 | | } |
| 560 | | |
| 561 | | |
| 562 | | //------------------------------------------------- |
| 563 | | // step_motor - |
| 564 | | //------------------------------------------------- |
| 565 | | |
| 566 | | inline void c1551_device::step_motor(int mtr, int stp) |
| 567 | | { |
| 568 | | if (mtr && (m_stp != stp)) |
| 569 | | { |
| 570 | | int tracks = 0; |
| 571 | | |
| 572 | | switch (m_stp) |
| 573 | | { |
| 574 | | case 0: if (stp == 1) tracks++; else if (stp == 3) tracks--; break; |
| 575 | | case 1: if (stp == 2) tracks++; else if (stp == 0) tracks--; break; |
| 576 | | case 2: if (stp == 3) tracks++; else if (stp == 1) tracks--; break; |
| 577 | | case 3: if (stp == 0) tracks++; else if (stp == 2) tracks--; break; |
| 578 | | } |
| 579 | | |
| 580 | | if (tracks != 0) |
| 581 | | { |
| 582 | | // step read/write head |
| 583 | | floppy_drive_seek(m_image, tracks); |
| 584 | | |
| 585 | | // read new track data |
| 586 | | read_current_track(); |
| 587 | | } |
| 588 | | |
| 589 | | m_stp = stp; |
| 590 | | } |
| 591 | | } |
| 592 | | |
| 593 | | |
| 594 | | //------------------------------------------------- |
| 595 | | // receive_bit - |
| 596 | | //------------------------------------------------- |
| 597 | | |
| 598 | | inline void c1551_device::receive_bit() |
| 599 | | { |
| 600 | | int byte = 0; |
| 601 | | |
| 602 | | // shift in data from the read head |
| 603 | | m_data <<= 1; |
| 604 | | m_data |= BIT(m_track_buffer[m_buffer_pos], m_bit_pos); |
| 605 | | m_bit_pos--; |
| 606 | | m_bit_count++; |
| 607 | | |
| 608 | | if (m_bit_pos < 0) |
| 609 | | { |
| 610 | | m_bit_pos = 7; |
| 611 | | m_buffer_pos++; |
| 612 | | |
| 613 | | if (m_buffer_pos >= m_track_len) |
| 614 | | { |
| 615 | | // loop to the start of the track |
| 616 | | m_buffer_pos = 0; |
| 617 | | } |
| 618 | | } |
| 619 | | |
| 620 | | if (!SYNC) |
| 621 | | { |
| 622 | | // SYNC detected |
| 623 | | m_bit_count = 0; |
| 624 | | } |
| 625 | | |
| 626 | | if (m_bit_count > 7) |
| 627 | | { |
| 628 | | // byte ready |
| 629 | | m_bit_count = 0; |
| 630 | | byte = 1; |
| 631 | | |
| 632 | | m_yb = m_data & 0xff; |
| 633 | | |
| 634 | | if (!m_yb) |
| 635 | | { |
| 636 | | // simulate weak bits with randomness |
| 637 | | m_yb = m_machine.rand() & 0xff; |
| 638 | | } |
| 639 | | |
| 640 | | m_byte = byte; |
| 641 | | } |
| 642 | | } |
| 643 | | |
| 644 | | |
| 645 | | //************************************************************************** |
| 646 | 465 | // LIVE DEVICE |
| 647 | 466 | //************************************************************************** |
| 648 | 467 | |
| r11238 | r11239 | |
| 655 | 474 | m_maincpu(*this, M6510T_TAG), |
| 656 | 475 | m_tpi0(*this, M6523_0_TAG), |
| 657 | 476 | m_tpi1(*this, M6523_1_TAG), |
| 477 | m_ga(*this, C64H156_TAG), |
| 658 | 478 | m_image(*this, FLOPPY_0), |
| 659 | 479 | m_tcbm_data(0), |
| 660 | 480 | m_status(0), |
| 661 | 481 | m_dav(0), |
| 662 | 482 | m_ack(0), |
| 663 | | m_stp(0), |
| 664 | | m_mtr(0), |
| 665 | | m_ds(0), |
| 666 | | m_soe(0), |
| 667 | | m_byte(0), |
| 668 | | m_mode(0), |
| 669 | 483 | m_config(_config) |
| 670 | 484 | { |
| 671 | 485 | } |
| r11238 | r11239 | |
| 677 | 491 | |
| 678 | 492 | void c1551_device::device_start() |
| 679 | 493 | { |
| 680 | | // install image callbacks |
| 681 | | floppy_install_unload_proc(m_image, c1551_device::on_disk_change); |
| 682 | | floppy_install_load_proc(m_image, c1551_device::on_disk_change); |
| 683 | | |
| 684 | | // allocate data timer |
| 685 | | m_bit_timer = timer_alloc(TIMER_BIT); |
| 686 | | m_irq_timer = timer_alloc(TIMER_IRQ); |
| 494 | // allocate timers |
| 495 | m_irq_timer = timer_alloc(); |
| 687 | 496 | m_irq_timer->adjust(attotime::from_hz(120), 0, attotime::from_hz(120)); |
| 688 | 497 | |
| 689 | 498 | // map TPI1 to host CPU memory space |
| r11238 | r11239 | |
| 692 | 501 | |
| 693 | 502 | program->install_legacy_readwrite_handler(*m_tpi1, start_address, start_address + 7, FUNC(tpi6525_r), FUNC(tpi6525_w)); |
| 694 | 503 | |
| 504 | // install image callbacks |
| 505 | floppy_install_unload_proc(m_image, c1551_device::on_disk_change); |
| 506 | floppy_install_load_proc(m_image, c1551_device::on_disk_change); |
| 507 | |
| 695 | 508 | // register for state saving |
| 696 | 509 | save_item(NAME(m_tcbm_data)); |
| 697 | 510 | save_item(NAME(m_status)); |
| 698 | 511 | save_item(NAME(m_dav)); |
| 699 | 512 | save_item(NAME(m_ack)); |
| 700 | | save_item(NAME(m_stp)); |
| 701 | | save_item(NAME(m_mtr)); |
| 702 | | save_item(NAME(m_track_len)); |
| 703 | | save_item(NAME(m_buffer_pos)); |
| 704 | | save_item(NAME(m_bit_pos)); |
| 705 | | save_item(NAME(m_bit_count)); |
| 706 | | save_item(NAME(m_data)); |
| 707 | | save_item(NAME(m_yb)); |
| 708 | | save_item(NAME(m_ds)); |
| 709 | | save_item(NAME(m_soe)); |
| 710 | | save_item(NAME(m_byte)); |
| 711 | | save_item(NAME(m_mode)); |
| 712 | 513 | } |
| 713 | 514 | |
| 714 | 515 | |
| r11238 | r11239 | |
| 718 | 519 | |
| 719 | 520 | void c1551_device::device_reset() |
| 720 | 521 | { |
| 721 | | m_soe = 1; |
| 522 | // initialize gate array |
| 523 | m_ga->test_w(1); |
| 524 | m_ga->soe_w(1); |
| 525 | m_ga->accl_w(1); |
| 526 | m_ga->atna_w(1); |
| 722 | 527 | } |
| 723 | 528 | |
| 724 | 529 | |
| r11238 | r11239 | |
| 728 | 533 | |
| 729 | 534 | void c1551_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 730 | 535 | { |
| 731 | | switch (id) |
| 732 | | { |
| 733 | | case TIMER_BIT: |
| 734 | | receive_bit(); |
| 735 | | break; |
| 536 | m_maincpu->set_input_line(M6502_IRQ_LINE, ASSERT_LINE); |
| 537 | m_maincpu->set_input_line(M6502_IRQ_LINE, CLEAR_LINE); |
| 538 | } |
| 736 | 539 | |
| 737 | | case TIMER_IRQ: |
| 738 | | m_maincpu->set_input_line(M6502_IRQ_LINE, ASSERT_LINE); |
| 739 | | m_maincpu->set_input_line(M6502_IRQ_LINE, CLEAR_LINE); |
| 740 | | break; |
| 741 | | } |
| 540 | |
| 541 | //------------------------------------------------- |
| 542 | // on_disk_change - |
| 543 | //------------------------------------------------- |
| 544 | |
| 545 | void c1551_device::on_disk_change(device_image_interface &image) |
| 546 | { |
| 547 | c1551_device *c1551 = static_cast<c1551_device *>(image.device().owner()); |
| 548 | |
| 549 | c1551->m_ga->on_disk_changed(); |
| 742 | 550 | } |
src/mess/machine/c1551.h
| r11238 | r11239 | |
| 19 | 19 | #include "imagedev/flopdrv.h" |
| 20 | 20 | #include "formats/d64_dsk.h" |
| 21 | 21 | #include "formats/g64_dsk.h" |
| 22 | #include "machine/64h156.h" |
| 22 | 23 | #include "machine/6525tpi.h" |
| 23 | 24 | |
| 24 | 25 | |
| r11238 | r11239 | |
| 81 | 82 | // not really public |
| 82 | 83 | static void on_disk_change(device_image_interface &image); |
| 83 | 84 | |
| 84 | | READ8_MEMBER( port_r ); |
| 85 | | WRITE8_MEMBER( port_w ); |
| 86 | | READ8_MEMBER( tcbm_data_r ); |
| 87 | | WRITE8_MEMBER( tcbm_data_w ); |
| 88 | | READ8_MEMBER( yb_r ); |
| 89 | | WRITE8_MEMBER( yb_w ); |
| 90 | | READ8_MEMBER( tpi0_pc_r ); |
| 91 | | WRITE8_MEMBER( tpi0_pc_w ); |
| 92 | | READ8_MEMBER( tpi1_pa_r ); |
| 93 | | WRITE8_MEMBER( tpi1_pa_w ); |
| 94 | | READ8_MEMBER( tpi1_pb_r ); |
| 95 | | READ8_MEMBER( tpi1_pc_r ); |
| 96 | | WRITE8_MEMBER( tpi1_pc_w ); |
| 85 | DECLARE_READ8_MEMBER( port_r ); |
| 86 | DECLARE_WRITE8_MEMBER( port_w ); |
| 87 | DECLARE_READ8_MEMBER( tcbm_data_r ); |
| 88 | DECLARE_WRITE8_MEMBER( tcbm_data_w ); |
| 89 | DECLARE_READ8_MEMBER( yb_r ); |
| 90 | DECLARE_WRITE8_MEMBER( yb_w ); |
| 91 | DECLARE_READ8_MEMBER( tpi0_pc_r ); |
| 92 | DECLARE_WRITE8_MEMBER( tpi0_pc_w ); |
| 93 | DECLARE_READ8_MEMBER( tpi1_pa_r ); |
| 94 | DECLARE_WRITE8_MEMBER( tpi1_pa_w ); |
| 95 | DECLARE_READ8_MEMBER( tpi1_pb_r ); |
| 96 | DECLARE_READ8_MEMBER( tpi1_pc_r ); |
| 97 | DECLARE_WRITE8_MEMBER( tpi1_pc_w ); |
| 97 | 98 | |
| 98 | 99 | protected: |
| 99 | 100 | // device-level overrides |
| r11238 | r11239 | |
| 101 | 102 | virtual void device_reset(); |
| 102 | 103 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 103 | 104 | |
| 104 | | inline void read_current_track(); |
| 105 | | inline void spindle_motor(int mtr); |
| 106 | | inline void step_motor(int mtr, int stp); |
| 107 | | inline void receive_bit(); |
| 108 | | |
| 109 | 105 | private: |
| 110 | | static const device_timer_id TIMER_BIT = 0; |
| 111 | | static const device_timer_id TIMER_IRQ = 1; |
| 112 | | |
| 113 | 106 | required_device<cpu_device> m_maincpu; |
| 114 | 107 | required_device<device_t> m_tpi0; |
| 115 | 108 | required_device<device_t> m_tpi1; |
| 109 | required_device<c64h156_device> m_ga; |
| 116 | 110 | required_device<device_t> m_image; |
| 117 | 111 | |
| 118 | 112 | // TCBM bus |
| r11238 | r11239 | |
| 121 | 115 | int m_dav; // data valid |
| 122 | 116 | int m_ack; // acknowledge |
| 123 | 117 | |
| 124 | | // motors |
| 125 | | int m_stp; // stepper motor phase |
| 126 | | int m_mtr; // spindle motor on |
| 127 | | |
| 128 | | // track |
| 129 | | UINT8 m_track_buffer[G64_BUFFER_SIZE]; // track data buffer |
| 130 | | int m_track_len; // track length |
| 131 | | int m_buffer_pos; // current byte position within track buffer |
| 132 | | int m_bit_pos; // current bit position within track buffer byte |
| 133 | | int m_bit_count; // current data byte bit counter |
| 134 | | UINT16 m_data; // data shift register |
| 135 | | UINT8 m_yb; // GCR data byte |
| 136 | | |
| 137 | | // signals |
| 138 | | int m_ds; // density select |
| 139 | | int m_soe; // s? output enable |
| 140 | | int m_byte; // byte ready |
| 141 | | int m_mode; // mode (0 = write, 1 = read) |
| 142 | | |
| 143 | 118 | // timers |
| 144 | | emu_timer *m_bit_timer; |
| 145 | 119 | emu_timer *m_irq_timer; |
| 146 | 120 | |
| 147 | 121 | const c1551_device_config &m_config; |