src/mess/machine/64h156.c
| r15882 | r15883 | |
| 11 | 11 | |
| 12 | 12 | TODO: |
| 13 | 13 | |
| 14 | | - serial IEC protocol handling |
| 15 | | - write to disk image |
| 14 | http://staff.washington.edu/rrcc/uwweb/1541early/1540-2.GIF |
| 16 | 15 | |
| 16 | - move bit sync timer code into the execute loop |
| 17 | - analog read circuitry (phantom "weak" bits) |
| 18 | - model disk rotation for proper track alignment |
| 19 | - per-byte bit cell length |
| 20 | - write circuitry |
| 21 | - cycle exact M6502 |
| 22 | - cycle exact VIA |
| 23 | |
| 17 | 24 | */ |
| 18 | 25 | |
| 19 | 26 | #include "emu.h" |
| 20 | 27 | #include "64h156.h" |
| 21 | 28 | #include "formats/g64_dsk.h" |
| 22 | | #include "machine/devhelpr.h" |
| 23 | 29 | |
| 24 | 30 | |
| 25 | 31 | |
| r15882 | r15883 | |
| 29 | 35 | |
| 30 | 36 | #define LOG 0 |
| 31 | 37 | |
| 32 | | #define SYNC \ |
| 33 | | !(m_oe && m_sync) |
| 38 | #define ATN (m_atni ^ m_atna) |
| 34 | 39 | |
| 35 | | #define BYTE \ |
| 36 | | !(m_soe && m_byte) |
| 37 | 40 | |
| 38 | | #define ATN \ |
| 39 | | (m_atni ^ m_atna) |
| 40 | 41 | |
| 41 | | |
| 42 | | |
| 43 | 42 | //************************************************************************** |
| 44 | 43 | // DEVICE DEFINITIONS |
| 45 | 44 | //************************************************************************** |
| r15882 | r15883 | |
| 85 | 84 | |
| 86 | 85 | |
| 87 | 86 | //------------------------------------------------- |
| 88 | | // set_sync_line - |
| 89 | | //------------------------------------------------- |
| 90 | | |
| 91 | | inline void c64h156_device::set_sync_line() |
| 92 | | { |
| 93 | | m_out_sync_func(SYNC); |
| 94 | | } |
| 95 | | |
| 96 | | |
| 97 | | //------------------------------------------------- |
| 98 | | // set_byte_line - |
| 99 | | //------------------------------------------------- |
| 100 | | |
| 101 | | inline void c64h156_device::set_byte_line() |
| 102 | | { |
| 103 | | m_out_byte_func(BYTE); |
| 104 | | } |
| 105 | | |
| 106 | | |
| 107 | | //------------------------------------------------- |
| 108 | 87 | // read_current_track - |
| 109 | 88 | //------------------------------------------------- |
| 110 | 89 | |
| r15882 | r15883 | |
| 122 | 101 | m_buffer_pos = 0; |
| 123 | 102 | m_bit_pos = 7; |
| 124 | 103 | m_bit_count = 0; |
| 125 | | } |
| 126 | 104 | |
| 127 | | |
| 128 | | //------------------------------------------------- |
| 129 | | // receive_bit - |
| 130 | | //------------------------------------------------- |
| 131 | | |
| 132 | | inline void c64h156_device::receive_bit() |
| 133 | | { |
| 134 | | if (m_bit_count == 1) |
| 105 | if (m_track_len) |
| 135 | 106 | { |
| 136 | | m_byte = 0; |
| 137 | | set_byte_line(); |
| 107 | m_speed = m_track_buffer[m_track_len] & 0x03; |
| 108 | m_bit_timer->adjust(attotime::zero, 0, attotime::from_hz(C2040_BITRATE[m_speed] / 4)); |
| 138 | 109 | } |
| 139 | 110 | |
| 140 | | // shift in data from the read head |
| 141 | | m_data <<= 1; |
| 142 | | m_data |= BIT(m_track_buffer[m_buffer_pos], m_bit_pos); |
| 143 | | m_bit_pos--; |
| 144 | | m_bit_count++; |
| 145 | | |
| 146 | | if (m_bit_pos < 0) |
| 147 | | { |
| 148 | | m_bit_pos = 7; |
| 149 | | m_buffer_pos++; |
| 150 | | |
| 151 | | if (m_buffer_pos >= m_track_len) |
| 152 | | { |
| 153 | | // loop to the start of the track |
| 154 | | m_buffer_pos = 0; |
| 155 | | } |
| 156 | | } |
| 157 | | |
| 158 | | m_sync = ((m_data & G64_SYNC_MARK) == G64_SYNC_MARK); |
| 159 | | set_sync_line(); |
| 160 | | |
| 161 | | if (m_sync) |
| 162 | | { |
| 163 | | // SYNC detected |
| 164 | | m_bit_count = 0; |
| 165 | | |
| 166 | | if (LOG) logerror("SYNC\n"); |
| 167 | | } |
| 168 | | |
| 169 | | if (m_bit_count > 7) |
| 170 | | { |
| 171 | | // byte ready |
| 172 | | m_yb = m_data & 0xff; |
| 173 | | m_bit_count = 0; |
| 174 | | |
| 175 | | m_byte = 1; |
| 176 | | set_byte_line(); |
| 177 | | |
| 178 | | if (LOG) logerror("BYTE %02x\n", m_yb); |
| 179 | | |
| 180 | | if (!m_yb) |
| 181 | | { |
| 182 | | // simulate weak bits with randomness |
| 183 | | m_yb = machine().rand() & 0xff; |
| 184 | | } |
| 185 | | } |
| 111 | m_bit_timer->enable(m_mtr && m_track_len); |
| 186 | 112 | } |
| 187 | 113 | |
| 188 | 114 | |
| r15882 | r15883 | |
| 197 | 123 | |
| 198 | 124 | c64h156_device::c64h156_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 199 | 125 | : device_t(mconfig, C64H156, "64H156", tag, owner, clock), |
| 126 | device_execute_interface(mconfig, *this), |
| 127 | m_icount(0), |
| 200 | 128 | m_image(*this->owner(), FLOPPY_0), |
| 201 | 129 | m_stp(-1), |
| 202 | 130 | m_mtr(0), |
| r15882 | r15883 | |
| 208 | 136 | m_accl(1), |
| 209 | 137 | m_ds(-1), |
| 210 | 138 | m_soe(0), |
| 211 | | m_byte(0), |
| 212 | 139 | m_oe(0), |
| 213 | | m_sync(1), |
| 214 | 140 | m_atni(1), |
| 215 | | m_atna(1) |
| 141 | m_atna(1), |
| 142 | m_last_bit_sync(0), |
| 143 | m_bit_sync(0), |
| 144 | m_byte_sync(1), |
| 145 | m_block_sync(1), |
| 146 | m_ue7(0), |
| 147 | m_ue7_tc(0), |
| 148 | m_uf4(0), |
| 149 | m_uf4_qb(0), |
| 150 | m_ud2(0), |
| 151 | m_u4a(0), |
| 152 | m_u4b(0), |
| 153 | m_ue3(0), |
| 154 | m_uc1b(0) |
| 216 | 155 | { |
| 217 | 156 | } |
| 218 | 157 | |
| r15882 | r15883 | |
| 223 | 162 | |
| 224 | 163 | void c64h156_device::device_start() |
| 225 | 164 | { |
| 165 | // set our instruction counter |
| 166 | m_icountptr = &m_icount; |
| 167 | |
| 226 | 168 | // resolve callbacks |
| 227 | 169 | m_out_atn_func.resolve(m_out_atn_cb, *this); |
| 228 | 170 | m_out_sync_func.resolve(m_out_sync_cb, *this); |
| r15882 | r15883 | |
| 239 | 181 | save_item(NAME(m_buffer_pos)); |
| 240 | 182 | save_item(NAME(m_bit_pos)); |
| 241 | 183 | save_item(NAME(m_bit_count)); |
| 242 | | save_item(NAME(m_data)); |
| 243 | | save_item(NAME(m_yb)); |
| 184 | save_item(NAME(m_speed)); |
| 244 | 185 | save_item(NAME(m_accl)); |
| 245 | 186 | save_item(NAME(m_ds)); |
| 246 | 187 | save_item(NAME(m_soe)); |
| 247 | | save_item(NAME(m_byte)); |
| 248 | 188 | save_item(NAME(m_oe)); |
| 249 | | save_item(NAME(m_sync)); |
| 250 | 189 | save_item(NAME(m_atni)); |
| 251 | 190 | save_item(NAME(m_atna)); |
| 191 | save_item(NAME(m_shift)); |
| 192 | save_item(NAME(m_last_bit_sync)); |
| 193 | save_item(NAME(m_bit_sync)); |
| 194 | save_item(NAME(m_byte_sync)); |
| 195 | save_item(NAME(m_block_sync)); |
| 196 | save_item(NAME(m_ue7)); |
| 197 | save_item(NAME(m_ue7_tc)); |
| 198 | save_item(NAME(m_uf4)); |
| 199 | save_item(NAME(m_uf4_qb)); |
| 200 | save_item(NAME(m_ud2)); |
| 201 | save_item(NAME(m_u4a)); |
| 202 | save_item(NAME(m_u4b)); |
| 203 | save_item(NAME(m_ue3)); |
| 204 | save_item(NAME(m_uc1b)); |
| 252 | 205 | } |
| 253 | 206 | |
| 254 | 207 | |
| r15882 | r15883 | |
| 258 | 211 | |
| 259 | 212 | void c64h156_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 260 | 213 | { |
| 261 | | receive_bit(); |
| 214 | m_bit_sync = BIT(m_track_buffer[m_buffer_pos], m_bit_pos); |
| 215 | |
| 216 | if (LOG) logerror("BIT SYNC %u\n", m_bit_sync); |
| 217 | m_shift <<= 1; |
| 218 | m_shift |= m_bit_sync; |
| 219 | |
| 220 | m_bit_pos--; |
| 221 | m_bit_count++; |
| 222 | |
| 223 | if (m_bit_pos < 0) |
| 224 | { |
| 225 | m_bit_pos = 7; |
| 226 | m_buffer_pos++; |
| 227 | |
| 228 | if (m_buffer_pos >= m_track_len) |
| 229 | { |
| 230 | // loop to the start of the track |
| 231 | m_buffer_pos = 0; |
| 232 | } |
| 233 | } |
| 262 | 234 | } |
| 263 | 235 | |
| 264 | 236 | |
| 265 | 237 | //------------------------------------------------- |
| 238 | // execute_run - |
| 239 | //------------------------------------------------- |
| 240 | |
| 241 | void c64h156_device::execute_run() |
| 242 | { |
| 243 | do |
| 244 | { |
| 245 | if (m_mtr) |
| 246 | { |
| 247 | // UE7 |
| 248 | int ue7_tc = 0; |
| 249 | |
| 250 | if (!m_last_bit_sync && m_bit_sync) |
| 251 | { |
| 252 | m_ue7 = m_ds; |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | m_ue7++; |
| 257 | |
| 258 | if (m_ue7 == 16) |
| 259 | { |
| 260 | m_ue7 = m_ds; |
| 261 | ue7_tc = 1; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | if (LOG) logerror("UE7 CTR %01x TC %u, ", m_ue7, ue7_tc); |
| 266 | |
| 267 | // UF4 |
| 268 | if (!m_last_bit_sync && m_bit_sync) |
| 269 | { |
| 270 | m_uf4 = 0; |
| 271 | if (LOG) logerror("--"); |
| 272 | } |
| 273 | else |
| 274 | { |
| 275 | if (!m_ue7_tc && ue7_tc) |
| 276 | { |
| 277 | m_uf4++; |
| 278 | |
| 279 | if (m_uf4 == 16) |
| 280 | { |
| 281 | m_uf4 = 0; |
| 282 | } |
| 283 | |
| 284 | if (LOG) logerror("++"); |
| 285 | } |
| 286 | else if (LOG) logerror(" "); |
| 287 | } |
| 288 | |
| 289 | m_last_bit_sync = m_bit_sync; |
| 290 | m_ue7_tc = ue7_tc; |
| 291 | |
| 292 | int uf4_qa = BIT(m_uf4, 0); |
| 293 | int uf4_qb = BIT(m_uf4, 1); |
| 294 | int uf4_qc = BIT(m_uf4, 2); |
| 295 | int uf4_qd = BIT(m_uf4, 3); |
| 296 | |
| 297 | if (LOG) logerror("UF4 CTR %01x QD %u QC %u QB %u QA %u !QC|QD %u, ", m_uf4, uf4_qd, uf4_qc, uf4_qb, uf4_qa, !(uf4_qc || uf4_qd)); |
| 298 | |
| 299 | if (!m_uf4_qb && uf4_qb) |
| 300 | { |
| 301 | if (LOG) logerror("<<"); |
| 302 | // shift bits thru flip-flops |
| 303 | m_u4b = m_u4a; |
| 304 | m_u4a = BIT(m_ud2, 7); |
| 305 | |
| 306 | // shift in data bit |
| 307 | m_ud2 <<= 1; |
| 308 | m_ud2 |= !(uf4_qc || uf4_qd); |
| 309 | } |
| 310 | else |
| 311 | { |
| 312 | if (LOG) logerror(" "); |
| 313 | } |
| 314 | |
| 315 | if (LOG) logerror("UD2 %u%u%u%u%u%u%u%u%u%u : %02x (%02x), ", m_u4b, m_u4a, BIT(m_ud2, 7), BIT(m_ud2, 6), BIT(m_ud2, 5), BIT(m_ud2, 4), BIT(m_ud2, 3), BIT(m_ud2, 2), BIT(m_ud2, 1), BIT(m_ud2, 0), m_ud2, m_shift & 0xff); |
| 316 | |
| 317 | int block_sync = !(m_oe && (m_ud2 == 0xff) && m_u4a && m_u4b); |
| 318 | |
| 319 | if (LOG) logerror("SYNC %u, ", block_sync); |
| 320 | |
| 321 | if (!block_sync) |
| 322 | { |
| 323 | // load UE3 |
| 324 | m_ue3 = 8; // pin D is floating and TTL inputs float high |
| 325 | if (LOG) logerror("--"); |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | if (m_block_sync && !m_uf4_qb && uf4_qb) |
| 330 | { |
| 331 | // clock UE3 |
| 332 | m_ue3++; |
| 333 | if (LOG) logerror("++"); |
| 334 | |
| 335 | if (m_ue3 == 16) |
| 336 | { |
| 337 | m_ue3 = 0; |
| 338 | } |
| 339 | } |
| 340 | else |
| 341 | { |
| 342 | if (LOG) logerror(" "); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | m_uf4_qb = uf4_qb; |
| 347 | |
| 348 | int ue3_qa = BIT(m_ue3, 0); |
| 349 | int ue3_qb = BIT(m_ue3, 1); |
| 350 | int ue3_qc = BIT(m_ue3, 2); |
| 351 | |
| 352 | int uf3a = !(ue3_qa && ue3_qb && ue3_qc); |
| 353 | int uc1b = !uf3a; // schmitt trigger |
| 354 | |
| 355 | int byte_sync = !(uc1b && m_soe && !uf4_qb); |
| 356 | |
| 357 | if (LOG) logerror("UE3 CTR %01x UF3A %u UC1B %u, ", m_ue3, uf3a, uc1b); |
| 358 | |
| 359 | if (LOG) logerror("BYTE %u SOE %u\n", m_byte_sync, m_soe); |
| 360 | |
| 361 | if (m_block_sync != block_sync) |
| 362 | { |
| 363 | m_block_sync = block_sync; |
| 364 | m_out_sync_func(m_block_sync); |
| 365 | } |
| 366 | |
| 367 | if (m_byte_sync != byte_sync) |
| 368 | { |
| 369 | m_byte_sync = byte_sync; |
| 370 | m_out_byte_func(m_byte_sync); |
| 371 | } |
| 372 | |
| 373 | m_bit_sync = 0; |
| 374 | } |
| 375 | |
| 376 | m_icount--; |
| 377 | } while (m_icount > 0); |
| 378 | } |
| 379 | |
| 380 | |
| 381 | //------------------------------------------------- |
| 266 | 382 | // yb_r - |
| 267 | 383 | //------------------------------------------------- |
| 268 | 384 | |
| r15882 | r15883 | |
| 270 | 386 | { |
| 271 | 387 | UINT8 data = 0; |
| 272 | 388 | |
| 273 | | if (LOG) logerror("YB read %02x\n", m_yb); |
| 274 | | |
| 275 | 389 | if (m_soe) |
| 276 | 390 | { |
| 277 | | data = m_yb; |
| 391 | if (!m_ud2) |
| 392 | { |
| 393 | data = rand() & 0xff; |
| 394 | } |
| 395 | else |
| 396 | { |
| 397 | data = m_ud2; |
| 398 | } |
| 278 | 399 | } |
| 279 | 400 | |
| 401 | if (LOG) logerror("YB read %02x:%02x\n", m_ud2, data); |
| 402 | |
| 280 | 403 | return data; |
| 281 | 404 | } |
| 282 | 405 | |
| r15882 | r15883 | |
| 287 | 410 | |
| 288 | 411 | WRITE8_MEMBER( c64h156_device::yb_w ) |
| 289 | 412 | { |
| 290 | | //m_yb = data; |
| 291 | 413 | } |
| 292 | 414 | |
| 293 | 415 | |
| r15882 | r15883 | |
| 316 | 438 | |
| 317 | 439 | READ_LINE_MEMBER( c64h156_device::sync_r ) |
| 318 | 440 | { |
| 319 | | return SYNC; |
| 441 | return m_block_sync; |
| 320 | 442 | } |
| 321 | 443 | |
| 322 | 444 | |
| r15882 | r15883 | |
| 326 | 448 | |
| 327 | 449 | READ_LINE_MEMBER( c64h156_device::byte_r ) |
| 328 | 450 | { |
| 329 | | return BYTE; |
| 451 | return m_byte_sync; |
| 330 | 452 | } |
| 331 | 453 | |
| 332 | 454 | |
| r15882 | r15883 | |
| 338 | 460 | { |
| 339 | 461 | if (m_mtr != state) |
| 340 | 462 | { |
| 463 | if (LOG) logerror("MTR %u\n", state); |
| 464 | |
| 341 | 465 | if (state) |
| 342 | 466 | { |
| 343 | 467 | // read track data |
| r15882 | r15883 | |
| 345 | 469 | } |
| 346 | 470 | |
| 347 | 471 | floppy_mon_w(m_image, !state); |
| 348 | | m_bit_timer->enable(state); |
| 472 | m_bit_timer->enable(state && m_track_len); |
| 349 | 473 | |
| 350 | 474 | m_mtr = state; |
| 351 | 475 | } |
| r15882 | r15883 | |
| 358 | 482 | |
| 359 | 483 | WRITE_LINE_MEMBER( c64h156_device::oe_w ) |
| 360 | 484 | { |
| 485 | if (LOG) logerror("OE %u\n", state); |
| 486 | |
| 361 | 487 | m_oe = state; |
| 362 | | |
| 363 | | set_sync_line(); |
| 364 | 488 | } |
| 365 | 489 | |
| 366 | 490 | |
| r15882 | r15883 | |
| 373 | 497 | if (LOG) logerror("SOE %u\n", state); |
| 374 | 498 | |
| 375 | 499 | m_soe = state; |
| 376 | | |
| 377 | | set_byte_line(); |
| 378 | 500 | } |
| 379 | 501 | |
| 380 | 502 | |
| r15882 | r15883 | |
| 454 | 576 | |
| 455 | 577 | void c64h156_device::ds_w(int data) |
| 456 | 578 | { |
| 457 | | if (m_ds != data) |
| 458 | | { |
| 459 | | m_bit_timer->adjust(attotime::zero, 0, attotime::from_hz(C2040_BITRATE[data]/4)); |
| 460 | | m_ds = data; |
| 461 | | } |
| 579 | m_ds = data; |
| 462 | 580 | } |
| 463 | 581 | |
| 464 | 582 | |
| r15882 | r15883 | |
| 473 | 591 | |
| 474 | 592 | |
| 475 | 593 | //------------------------------------------------- |
| 476 | | // on_disk_changed - |
| 594 | // set_side - |
| 477 | 595 | //------------------------------------------------- |
| 478 | 596 | |
| 479 | 597 | void c64h156_device::set_side(int side) |
src/mess/machine/64h156.h
| r15882 | r15883 | |
| 97 | 97 | // ======================> c64h156_device |
| 98 | 98 | |
| 99 | 99 | class c64h156_device : public device_t, |
| 100 | public device_execute_interface, |
| 100 | 101 | public c64h156_interface |
| 101 | 102 | { |
| 102 | 103 | public: |
| r15882 | r15883 | |
| 124 | 125 | |
| 125 | 126 | protected: |
| 126 | 127 | // device-level overrides |
| 128 | virtual void device_config_complete(); |
| 127 | 129 | virtual void device_start(); |
| 128 | 130 | virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr); |
| 129 | | virtual void device_config_complete(); |
| 130 | 131 | |
| 132 | // device_execute_interface overrides |
| 133 | virtual void execute_run(); |
| 134 | |
| 135 | int m_icount; |
| 136 | |
| 131 | 137 | inline void set_atn_line(); |
| 132 | | inline void set_sync_line(); |
| 133 | | inline void set_byte_line(); |
| 134 | 138 | inline void read_current_track(); |
| 135 | | inline void receive_bit(); |
| 136 | 139 | |
| 137 | 140 | private: |
| 138 | 141 | devcb_resolved_write_line m_out_atn_func; |
| r15882 | r15883 | |
| 152 | 155 | offs_t m_buffer_pos; // current byte position within track buffer |
| 153 | 156 | int m_bit_pos; // current bit position within track buffer byte |
| 154 | 157 | int m_bit_count; // current data byte bit counter |
| 155 | | UINT16 m_data; // data shift register |
| 156 | | UINT8 m_yb; // GCR data byte |
| 158 | UINT8 m_speed; |
| 157 | 159 | |
| 158 | 160 | // signals |
| 159 | 161 | int m_accl; // 1/2 MHz select |
| 160 | 162 | int m_ds; // density select |
| 161 | 163 | int m_soe; // s? output enable |
| 162 | | int m_byte; // byte ready |
| 163 | 164 | int m_oe; // output enable (0 = write, 1 = read) |
| 164 | | int m_sync; // sync character found |
| 165 | 165 | |
| 166 | 166 | // IEC |
| 167 | 167 | int m_atni; // attention input |
| 168 | 168 | int m_atna; // attention acknowledge |
| 169 | 169 | |
| 170 | // logic |
| 171 | UINT16 m_shift; |
| 172 | int m_last_bit_sync; |
| 173 | int m_bit_sync; |
| 174 | int m_byte_sync; |
| 175 | int m_block_sync; |
| 176 | int m_ue7; |
| 177 | int m_ue7_tc; |
| 178 | int m_uf4; |
| 179 | int m_uf4_qb; |
| 180 | UINT8 m_ud2; |
| 181 | int m_u4a; |
| 182 | int m_u4b; |
| 183 | int m_ue3; |
| 184 | int m_uc1b; |
| 185 | |
| 170 | 186 | // timers |
| 171 | 187 | emu_timer *m_bit_timer; |
| 172 | 188 | |