src/mess/machine/ncr5390.c
| r14142 | r14143 | |
| 1 | #define ADDRESS_MAP_MODERN |
| 2 | |
| 3 | #include "emu.h" |
| 4 | #include "ncr5390.h" |
| 5 | |
| 6 | const device_type NCR5390 = &device_creator<ncr5390_device>; |
| 7 | |
| 8 | DEVICE_ADDRESS_MAP_START(map, 8, ncr5390_device) |
| 9 | AM_RANGE(0x0, 0x0) AM_READWRITE(tcount_lo_r, tcount_lo_w) |
| 10 | AM_RANGE(0x1, 0x1) AM_READWRITE(tcount_hi_r, tcount_hi_w) |
| 11 | AM_RANGE(0x2, 0x2) AM_READWRITE(fifo_r, fifo_w) |
| 12 | AM_RANGE(0x3, 0x3) AM_READWRITE(command_r, command_w) |
| 13 | AM_RANGE(0x4, 0x4) AM_READWRITE(status_r, bus_id_w) |
| 14 | AM_RANGE(0x5, 0x5) AM_READWRITE(istatus_r, timeout_w) |
| 15 | AM_RANGE(0x6, 0x6) AM_READWRITE(seq_step_r, sync_period_w) |
| 16 | AM_RANGE(0x7, 0x7) AM_READWRITE(fifo_flags_r, sync_offset_w) |
| 17 | AM_RANGE(0x8, 0x8) AM_READWRITE(conf_r, conf_w) |
| 18 | AM_RANGE(0x9, 0x9) AM_WRITE(clock_w) |
| 19 | ADDRESS_MAP_END |
| 20 | |
| 21 | ncr5390_device::ncr5390_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 22 | : device_t(mconfig, NCR5390, "5390 SCSI", tag, owner, clock) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | void ncr5390_device::device_start() |
| 27 | { |
| 28 | save_item(NAME(command)); |
| 29 | save_item(NAME(config)); |
| 30 | save_item(NAME(status)); |
| 31 | save_item(NAME(istatus)); |
| 32 | save_item(NAME(fifo_pos)); |
| 33 | save_item(NAME(fifo)); |
| 34 | save_item(NAME(tcount)); |
| 35 | save_item(NAME(mode)); |
| 36 | save_item(NAME(command_pos)); |
| 37 | save_item(NAME(irq)); |
| 38 | save_item(NAME(drq)); |
| 39 | save_item(NAME(clock_conv)); |
| 40 | |
| 41 | tcount = 0; |
| 42 | config = 0; |
| 43 | status = 0; |
| 44 | bus_id = 0; |
| 45 | select_timeout = 0; |
| 46 | tm = timer_alloc(0); |
| 47 | memset(devices, 0, sizeof(devices)); |
| 48 | for(int i=0; i != slots->devs_present; i++) |
| 49 | SCSIAllocInstance(machine(), |
| 50 | slots->devices[i].scsiClass, |
| 51 | devices+i, |
| 52 | slots->devices[i].diskregion); |
| 53 | } |
| 54 | |
| 55 | void ncr5390_device::device_reset() |
| 56 | { |
| 57 | fifo_pos = 0; |
| 58 | memset(fifo, 0, sizeof(fifo)); |
| 59 | |
| 60 | clock_conv = 2; |
| 61 | sync_period = 5; |
| 62 | sync_offset = 0; |
| 63 | config &= 7; |
| 64 | status &= 0x97; |
| 65 | istatus = 0; |
| 66 | irq = false; |
| 67 | if(!irq_cb.isnull()) |
| 68 | irq_cb(irq); |
| 69 | reset_soft(); |
| 70 | } |
| 71 | |
| 72 | void ncr5390_device::reset_soft() |
| 73 | { |
| 74 | status &= 0xef; |
| 75 | drq = false; |
| 76 | if(!drq_cb.isnull()) |
| 77 | drq_cb(drq); |
| 78 | reset_disconnect(); |
| 79 | } |
| 80 | |
| 81 | void ncr5390_device::reset_disconnect() |
| 82 | { |
| 83 | command_pos = 0; |
| 84 | memset(command, 0, sizeof(command)); |
| 85 | mode = MODE_D; |
| 86 | } |
| 87 | |
| 88 | void ncr5390_device::set_cb(line_cb_t _irq_cb, line_cb_t _drq_cb) |
| 89 | { |
| 90 | irq_cb = _irq_cb; |
| 91 | drq_cb = _drq_cb; |
| 92 | } |
| 93 | |
| 94 | void ncr5390_device::set_slots(const SCSIConfigTable &_slots) |
| 95 | { |
| 96 | slots = &_slots; |
| 97 | } |
| 98 | |
| 99 | void ncr5390_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 100 | { |
| 101 | switch(param) { |
| 102 | case T_SELECT_TIMEOUT: |
| 103 | logerror("ncr5390: select timeout\n"); |
| 104 | istatus |= I_DISCONNECT; |
| 105 | check_irq(); |
| 106 | break; |
| 107 | |
| 108 | default: |
| 109 | logerror("ncr5390: device_timer unexpected param %d\n", param); |
| 110 | exit(0); |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | void ncr5390_device::delay(int cycles, int param) |
| 115 | { |
| 116 | if(!clock_conv) |
| 117 | return; |
| 118 | cycles *= clock_conv; |
| 119 | tm->adjust(clocks_to_attotime(cycles), param); |
| 120 | } |
| 121 | |
| 122 | READ8_MEMBER(ncr5390_device::tcount_lo_r) |
| 123 | { |
| 124 | fprintf(stderr, "ncr5390: tcount_lo_r (%08x)\n", cpu_get_pc(&space.device())); |
| 125 | return tcount; |
| 126 | } |
| 127 | |
| 128 | WRITE8_MEMBER(ncr5390_device::tcount_lo_w) |
| 129 | { |
| 130 | tcount = (tcount & 0xff00) | data; |
| 131 | fprintf(stderr, "ncr5390: tcount_lo_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 132 | } |
| 133 | |
| 134 | READ8_MEMBER(ncr5390_device::tcount_hi_r) |
| 135 | { |
| 136 | fprintf(stderr, "ncr5390: tcount_hi_r (%08x)\n", cpu_get_pc(&space.device())); |
| 137 | return tcount >> 8; |
| 138 | } |
| 139 | |
| 140 | WRITE8_MEMBER(ncr5390_device::tcount_hi_w) |
| 141 | { |
| 142 | tcount = (tcount & 0x00ff) | (data << 8); |
| 143 | fprintf(stderr, "ncr5390: tcount_hi_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 144 | } |
| 145 | |
| 146 | READ8_MEMBER(ncr5390_device::fifo_r) |
| 147 | { |
| 148 | UINT8 r; |
| 149 | if(fifo_pos) { |
| 150 | r = fifo[0]; |
| 151 | fifo_pos--; |
| 152 | memmove(fifo, fifo+1, fifo_pos); |
| 153 | } else |
| 154 | r = 0; |
| 155 | fprintf(stderr, "ncr5390: fifo_r %02x (%08x)\n", r, cpu_get_pc(&space.device())); |
| 156 | return r; |
| 157 | } |
| 158 | |
| 159 | WRITE8_MEMBER(ncr5390_device::fifo_w) |
| 160 | { |
| 161 | fprintf(stderr, "ncr5390: fifo_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 162 | if(fifo_pos != 16) |
| 163 | fifo[fifo_pos++] = data; |
| 164 | } |
| 165 | |
| 166 | READ8_MEMBER(ncr5390_device::command_r) |
| 167 | { |
| 168 | fprintf(stderr, "ncr5390: command_r (%08x)\n", cpu_get_pc(&space.device())); |
| 169 | return command[0]; |
| 170 | } |
| 171 | |
| 172 | WRITE8_MEMBER(ncr5390_device::command_w) |
| 173 | { |
| 174 | fprintf(stderr, "ncr5390: command_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 175 | if(command_pos == 2) { |
| 176 | status |= S_GROSS_ERROR; |
| 177 | check_irq(); |
| 178 | return; |
| 179 | } |
| 180 | command[command_pos++] = data; |
| 181 | if(command_pos == 1) |
| 182 | start_command(); |
| 183 | } |
| 184 | |
| 185 | void ncr5390_device::command_pop_and_chain() |
| 186 | { |
| 187 | if(command_pos) { |
| 188 | command_pos--; |
| 189 | if(command_pos) { |
| 190 | command[0] = command[1]; |
| 191 | start_command(); |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void ncr5390_device::start_command() |
| 197 | { |
| 198 | if(!check_valid_command(command[0] & 0x7f)) { |
| 199 | logerror("ncr5390: invalid command %02x\n", command[0]); |
| 200 | istatus |= I_ILLEGAL; |
| 201 | check_irq(); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | bool msg; |
| 206 | int extra; |
| 207 | int total_len; |
| 208 | command_params_size(msg, extra); |
| 209 | if(fifo_pos < extra) { |
| 210 | logerror("ncr5390: cmd without extra bytes (fp=%d, extra=%d)\n", fifo_pos, extra); |
| 211 | exit(0); |
| 212 | } |
| 213 | if(msg) { |
| 214 | if(fifo_pos < extra+1) { |
| 215 | logerror("ncr5390: cmd without msg header (fp=%d, extra=%d)\n", fifo_pos, extra); |
| 216 | exit(0); |
| 217 | } |
| 218 | int len = derive_msg_size(fifo[extra]); |
| 219 | if(fifo_pos < extra+len) { |
| 220 | logerror("ncr5390: cmd without complete msg (fp=%d, extra=%d, len=%d)\n", fifo_pos, extra, len); |
| 221 | exit(0); |
| 222 | } |
| 223 | total_len = len+extra; |
| 224 | } else |
| 225 | total_len = extra; |
| 226 | |
| 227 | logerror("ncr5390: fifo_pos = %d, total_len = %d\n", fifo_pos, total_len); |
| 228 | |
| 229 | switch((command[0] >> 4) & 7) { |
| 230 | case 0: start_command_misc(); break; |
| 231 | case 4: start_command_disconnected(); break; |
| 232 | case 2: start_command_target(); break; |
| 233 | case 1: start_command_initiator(); break; |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | bool ncr5390_device::check_valid_command(UINT8 cmd) |
| 238 | { |
| 239 | int subcmd = cmd & 15; |
| 240 | switch((cmd >> 4) & 7) { |
| 241 | case 0: return subcmd <= 3; |
| 242 | case 4: return mode == MODE_D && subcmd <= 5; |
| 243 | case 2: return mode == MODE_T && subcmd <= 13 && subcmd != 6; |
| 244 | case 1: return mode == MODE_I && (subcmd <= 2 || subcmd == 8 || subcmd == 10); |
| 245 | } |
| 246 | return false; |
| 247 | } |
| 248 | |
| 249 | void ncr5390_device::command_params_size(bool &msg, int &extra) |
| 250 | { |
| 251 | msg = false; |
| 252 | extra = 0; |
| 253 | int subcmd = command[0] & 15; |
| 254 | switch((command[0] >> 4) & 7) { |
| 255 | case 0: |
| 256 | break; |
| 257 | |
| 258 | case 4: |
| 259 | extra = subcmd == 0 || subcmd == 2 || subcmd == 3 ? 1 : 0; |
| 260 | msg = subcmd == 1 || subcmd == 2; |
| 261 | break; |
| 262 | |
| 263 | case 2: |
| 264 | extra = subcmd >= 3 && subcmd <= 5 ? 2 : 0; |
| 265 | msg = subcmd <= 2; |
| 266 | break; |
| 267 | |
| 268 | case 1: |
| 269 | break; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | int ncr5390_device::derive_msg_size(UINT8 msg_id) |
| 274 | { |
| 275 | const static int sizes[8] = { 6, 10, 6, 6, 6, 12, 6, 10 }; |
| 276 | return sizes[msg_id >> 5]; |
| 277 | } |
| 278 | |
| 279 | void ncr5390_device::start_command_misc() |
| 280 | { |
| 281 | UINT8 subcmd = command[0] & 15; |
| 282 | switch(subcmd) { |
| 283 | case 0: // Nop |
| 284 | command_pop_and_chain(); |
| 285 | break; |
| 286 | |
| 287 | case 1: // Fifo flush |
| 288 | fifo_pos = 0; |
| 289 | command_pop_and_chain(); |
| 290 | break; |
| 291 | |
| 292 | case 2: // Device reset |
| 293 | device_reset(); |
| 294 | break; |
| 295 | |
| 296 | case 3: // SCSI bus reset |
| 297 | reset_soft(); |
| 298 | break; |
| 299 | |
| 300 | default: |
| 301 | logerror("ncr5390: start unimplemented misc(%d)\n", subcmd); |
| 302 | exit(0); |
| 303 | } |
| 304 | } |
| 305 | |
| 306 | void ncr5390_device::start_command_disconnected() |
| 307 | { |
| 308 | UINT8 subcmd = command[0] & 15; |
| 309 | switch(subcmd) { |
| 310 | case 2: |
| 311 | delay(8192*select_timeout, T_SELECT_TIMEOUT); |
| 312 | break; |
| 313 | |
| 314 | default: |
| 315 | logerror("ncr5390: start unimplemented disconnected(%d)\n", subcmd); |
| 316 | device_reset(); |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | void ncr5390_device::start_command_target() |
| 322 | { |
| 323 | UINT8 subcmd = command[0] & 15; |
| 324 | switch(subcmd) { |
| 325 | default: |
| 326 | logerror("ncr5390: start unimplemented target(%d)\n", subcmd); |
| 327 | exit(0); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | void ncr5390_device::start_command_initiator() |
| 332 | { |
| 333 | UINT8 subcmd = command[0] & 15; |
| 334 | switch(subcmd) { |
| 335 | default: |
| 336 | logerror("ncr5390: start unimplemented initiator(%d)\n", subcmd); |
| 337 | exit(0); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | void ncr5390_device::check_irq() |
| 342 | { |
| 343 | bool oldirq = irq; |
| 344 | irq = istatus != 0; |
| 345 | if(irq != oldirq && !irq_cb.isnull()) |
| 346 | irq_cb(irq); |
| 347 | |
| 348 | } |
| 349 | |
| 350 | READ8_MEMBER(ncr5390_device::status_r) |
| 351 | { |
| 352 | fprintf(stderr, "ncr5390: status_r (%08x)\n", cpu_get_pc(&space.device())); |
| 353 | return status; |
| 354 | } |
| 355 | |
| 356 | WRITE8_MEMBER(ncr5390_device::bus_id_w) |
| 357 | { |
| 358 | bus_id = data & 7; |
| 359 | } |
| 360 | |
| 361 | READ8_MEMBER(ncr5390_device::istatus_r) |
| 362 | { |
| 363 | UINT8 res = istatus; |
| 364 | status = istatus = 0; |
| 365 | check_irq(); |
| 366 | if(res) |
| 367 | command_pop_and_chain(); |
| 368 | |
| 369 | fprintf(stderr, "ncr5390: istatus_r (%08x)\n", cpu_get_pc(&space.device())); |
| 370 | return res; |
| 371 | } |
| 372 | |
| 373 | WRITE8_MEMBER(ncr5390_device::timeout_w) |
| 374 | { |
| 375 | select_timeout = data; |
| 376 | } |
| 377 | |
| 378 | READ8_MEMBER(ncr5390_device::seq_step_r) |
| 379 | { |
| 380 | fprintf(stderr, "ncr5390: seq_step_r (%08x)\n", cpu_get_pc(&space.device())); |
| 381 | return 0x00; |
| 382 | } |
| 383 | |
| 384 | WRITE8_MEMBER(ncr5390_device::sync_period_w) |
| 385 | { |
| 386 | sync_period = data & 0x1f; |
| 387 | } |
| 388 | |
| 389 | READ8_MEMBER(ncr5390_device::fifo_flags_r) |
| 390 | { |
| 391 | return fifo_pos; |
| 392 | } |
| 393 | |
| 394 | WRITE8_MEMBER(ncr5390_device::sync_offset_w) |
| 395 | { |
| 396 | sync_offset = data & 0x0f; |
| 397 | } |
| 398 | |
| 399 | READ8_MEMBER(ncr5390_device::conf_r) |
| 400 | { |
| 401 | return config; |
| 402 | } |
| 403 | |
| 404 | WRITE8_MEMBER(ncr5390_device::conf_w) |
| 405 | { |
| 406 | config = data; |
| 407 | } |
| 408 | |
| 409 | WRITE8_MEMBER(ncr5390_device::clock_w) |
| 410 | { |
| 411 | clock_conv = data & 0x07; |
| 412 | } |
| 413 | |
src/mess/machine/n82077aa.c
| r14142 | r14143 | |
| 6 | 6 | |
| 7 | 7 | DEVICE_ADDRESS_MAP_START(amap, 8, n82077aa_device) |
| 8 | 8 | AM_RANGE(0x0, 0x0) AM_READ(sra_r) |
| 9 | | AM_RANGE(0x1, 0x1) AM_READ(sra_r) |
| 9 | AM_RANGE(0x1, 0x1) AM_READ(srb_r) |
| 10 | 10 | AM_RANGE(0x2, 0x2) AM_READWRITE(dor_r, dor_w) |
| 11 | 11 | AM_RANGE(0x3, 0x3) AM_READWRITE(tdr_r, tdr_w) |
| 12 | 12 | AM_RANGE(0x4, 0x4) AM_READWRITE(msr_r, dsr_w) |
| r14142 | r14143 | |
| 14 | 14 | AM_RANGE(0x7, 0x7) AM_READWRITE(dir_r, ccr_w) |
| 15 | 15 | ADDRESS_MAP_END |
| 16 | 16 | |
| 17 | int n82077aa_device::rates[4] = { 500000, 300000, 250000, 1000000 }; |
| 18 | |
| 17 | 19 | n82077aa_device::n82077aa_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) : device_t(mconfig, N82077AA, "N82077AA", tag, owner, clock) |
| 18 | 20 | { |
| 19 | 21 | } |
| r14142 | r14143 | |
| 23 | 25 | mode = _mode; |
| 24 | 26 | } |
| 25 | 27 | |
| 28 | void n82077aa_device::setup_intrq_cb(line_cb cb) |
| 29 | { |
| 30 | intrq_cb = cb; |
| 31 | } |
| 32 | |
| 33 | void n82077aa_device::setup_drq_cb(line_cb cb) |
| 34 | { |
| 35 | drq_cb = cb; |
| 36 | } |
| 37 | |
| 26 | 38 | void n82077aa_device::device_start() |
| 27 | 39 | { |
| 40 | static const char *names[] = { "fd0", "fd1", "fd2", "fd3" }; |
| 41 | for(int i=0; i != 4; i++) { |
| 42 | flopi[i].tm = timer_alloc(i); |
| 43 | flopi[i].id = i; |
| 44 | floppy_connector *con = machine().device<floppy_connector>(names[i]); |
| 45 | if(con) { |
| 46 | flopi[i].dev = con->get_device(); |
| 47 | flopi[i].dev->setup_index_pulse_cb(floppy_image_device::index_pulse_cb(FUNC(n82077aa_device::index_callback), this)); |
| 48 | } else |
| 49 | flopi[i].dev = 0; |
| 50 | } |
| 28 | 51 | } |
| 29 | 52 | |
| 30 | 53 | void n82077aa_device::device_reset() |
| 31 | 54 | { |
| 55 | main_phase = PHASE_CMD; |
| 56 | for(int i=0; i<4; i++) { |
| 57 | flopi[i].main_state = IDLE; |
| 58 | flopi[i].sub_state = IDLE; |
| 59 | flopi[i].irq = false; |
| 60 | flopi[i].live = false; |
| 61 | } |
| 62 | dor = 0x00; |
| 63 | fifo_pos = 0; |
| 64 | command_pos = 0; |
| 65 | result_pos = 0; |
| 66 | fifocfg = 0x10; |
| 67 | cur_live.fi = 0; |
| 68 | cur_irq = false; |
| 69 | drq = false; |
| 70 | live_abort(); |
| 32 | 71 | } |
| 33 | 72 | |
| 34 | 73 | READ8_MEMBER(n82077aa_device::sra_r) |
| 35 | 74 | { |
| 36 | | fprintf(stderr, "sra_r (%08x)\n", cpu_get_pc(&space.device())); |
| 37 | | return 0; |
| 75 | UINT8 sra = 0; |
| 76 | int fid = dor & 3; |
| 77 | floppy_info &fi = flopi[fid]; |
| 78 | if(fi.dir) |
| 79 | sra |= 0x01; |
| 80 | if(fi.index) |
| 81 | sra |= 0x04; |
| 82 | if((dsr & 3) == 0 || (dsr & 3) == 3) |
| 83 | sra |= 0x08; |
| 84 | if(fi.dev && fi.dev->trk00_r()) |
| 85 | sra |= 0x10; |
| 86 | if(fi.main_state == SEEK_WAIT_STEP_SIGNAL_TIME) |
| 87 | sra |= 0x20; |
| 88 | sra |= 0x40; |
| 89 | if(cur_irq) |
| 90 | sra |= 0x80; |
| 91 | if(mode == MODE_M30) |
| 92 | sra ^= 0x1f; |
| 93 | fprintf(stderr, "sra_r %02x (%08x)\n", sra, cpu_get_pc(&space.device())); |
| 94 | return sra; |
| 38 | 95 | } |
| 39 | 96 | |
| 40 | 97 | READ8_MEMBER(n82077aa_device::srb_r) |
| 41 | 98 | { |
| 42 | | fprintf(stderr, "sra_r (%08x)\n", cpu_get_pc(&space.device())); |
| 99 | fprintf(stderr, "srb_r (%08x)\n", cpu_get_pc(&space.device())); |
| 43 | 100 | return 0; |
| 44 | 101 | } |
| 45 | 102 | |
| 46 | 103 | READ8_MEMBER(n82077aa_device::dor_r) |
| 47 | 104 | { |
| 48 | | fprintf(stderr, "dor_r (%08x)\n", cpu_get_pc(&space.device())); |
| 105 | fprintf(stderr, "dor_r %02x (%08x)\n", dor, cpu_get_pc(&space.device())); |
| 49 | 106 | return dor; |
| 50 | 107 | } |
| 51 | 108 | |
| r14142 | r14143 | |
| 54 | 111 | UINT8 diff = dor ^ data; |
| 55 | 112 | dor = data; |
| 56 | 113 | fprintf(stderr, "dor_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 57 | | if(diff & 4) |
| 114 | if((diff & 4) && !(data & 4)) |
| 58 | 115 | device_reset(); |
| 116 | else |
| 117 | for(int i=0; i<4; i++) { |
| 118 | floppy_info &fi = flopi[i]; |
| 119 | if(fi.dev && (diff & (0x10 << i))) |
| 120 | fi.dev->mon_w(!(dor & (0x10 << i))); |
| 121 | } |
| 122 | |
| 59 | 123 | } |
| 60 | 124 | |
| 61 | 125 | READ8_MEMBER(n82077aa_device::tdr_r) |
| r14142 | r14143 | |
| 71 | 135 | |
| 72 | 136 | READ8_MEMBER(n82077aa_device::msr_r) |
| 73 | 137 | { |
| 74 | | if(cpu_get_pc(&space.device()) != 0x10111fa) |
| 75 | | fprintf(stderr, "msr_r (%08x)\n", cpu_get_pc(&space.device())); |
| 76 | | return 0; |
| 138 | UINT32 msr = 0; |
| 139 | switch(main_phase) { |
| 140 | case PHASE_CMD: |
| 141 | msr |= 0x80; |
| 142 | if(command_pos) |
| 143 | msr |= 0x10; |
| 144 | break; |
| 145 | case PHASE_EXEC: |
| 146 | msr |= 0x10; |
| 147 | break; |
| 148 | |
| 149 | case PHASE_RESULT: |
| 150 | msr |= 0xd0; |
| 151 | break; |
| 152 | } |
| 153 | for(int i=0; i<4; i++) |
| 154 | if(flopi[i].main_state == RECALIBRATE) |
| 155 | msr |= 1<<i; |
| 156 | |
| 157 | // fprintf(stderr, "msr_r %02x (%08x)\n", msr, cpu_get_pc(&space.device())); |
| 158 | return msr; |
| 77 | 159 | } |
| 78 | 160 | |
| 79 | 161 | WRITE8_MEMBER(n82077aa_device::dsr_w) |
| r14142 | r14143 | |
| 84 | 166 | |
| 85 | 167 | READ8_MEMBER(n82077aa_device::fifo_r) |
| 86 | 168 | { |
| 87 | | fprintf(stderr, "fifo_r (%08x)\n", cpu_get_pc(&space.device())); |
| 88 | | return 0; |
| 169 | UINT8 r = 0; |
| 170 | switch(main_phase) { |
| 171 | case PHASE_RESULT: |
| 172 | r = result[0]; |
| 173 | result_pos--; |
| 174 | memmove(result, result+1, result_pos); |
| 175 | if(!result_pos) |
| 176 | main_phase = PHASE_CMD; |
| 177 | break; |
| 178 | default: |
| 179 | fprintf(stderr, "fifo_r in phase %d\n", main_phase); |
| 180 | // exit(1); |
| 181 | } |
| 182 | |
| 183 | fprintf(stderr, "fifo_r %02x (%08x)\n", r, cpu_get_pc(&space.device())); |
| 184 | return r; |
| 89 | 185 | } |
| 90 | 186 | |
| 91 | 187 | WRITE8_MEMBER(n82077aa_device::fifo_w) |
| 92 | 188 | { |
| 93 | 189 | fprintf(stderr, "fifo_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 190 | switch(main_phase) { |
| 191 | case PHASE_CMD: { |
| 192 | command[command_pos++] = data; |
| 193 | int cmd = check_command(); |
| 194 | if(cmd == C_INCOMPLETE) |
| 195 | break; |
| 196 | if(cmd == C_INVALID) { |
| 197 | fprintf(stderr, "Invalid on %02x\n", command[0]); |
| 198 | // exit(1); |
| 199 | command_pos = 0; |
| 200 | return; |
| 201 | } |
| 202 | start_command(cmd); |
| 203 | break; |
| 204 | } |
| 205 | default: |
| 206 | fprintf(stderr, "fifo_w in phase %d\n", main_phase); |
| 207 | exit(1); |
| 208 | } |
| 94 | 209 | } |
| 95 | 210 | |
| 96 | 211 | READ8_MEMBER(n82077aa_device::dir_r) |
| r14142 | r14143 | |
| 102 | 217 | WRITE8_MEMBER(n82077aa_device::ccr_w) |
| 103 | 218 | { |
| 104 | 219 | fprintf(stderr, "ccr_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 105 | | ccr = data; |
| 220 | dsr = (dsr & 0xfc) | (data & 3); |
| 106 | 221 | } |
| 222 | |
| 223 | void n82077aa_device::set_drq(bool state) |
| 224 | { |
| 225 | if(state != drq) { |
| 226 | drq = state; |
| 227 | if(!drq_cb.isnull()) |
| 228 | drq_cb(drq); |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | bool n82077aa_device::get_drq() const |
| 233 | { |
| 234 | return drq; |
| 235 | } |
| 236 | |
| 237 | void n82077aa_device::fifo_push(UINT8 data) |
| 238 | { |
| 239 | if(fifo_pos == 16) { |
| 240 | fprintf(stderr, "Overflow\n"); |
| 241 | return; |
| 242 | } |
| 243 | fifo[fifo_pos++] = data; |
| 244 | fifo_expected--; |
| 245 | if(!drq) { |
| 246 | int thr = (fifocfg & 15)+1; |
| 247 | if(!fifo_expected || fifo_pos >= thr || (fifocfg & 0x20)) |
| 248 | set_drq(true); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | void n82077aa_device::fifo_expect(int size, bool write) |
| 253 | { |
| 254 | fifo_expected = size; |
| 255 | fifo_write = write; |
| 256 | } |
| 257 | |
| 258 | UINT8 n82077aa_device::dma_r() |
| 259 | { |
| 260 | if(!fifo_pos) |
| 261 | return 0; |
| 262 | UINT8 r = fifo[0]; |
| 263 | fifo_pos--; |
| 264 | memmove(fifo, fifo+1, fifo_pos); |
| 265 | if(!fifo_pos) |
| 266 | set_drq(false); |
| 267 | return r; |
| 268 | } |
| 269 | |
| 270 | void n82077aa_device::live_start(floppy_info &fi, int state) |
| 271 | { |
| 272 | cur_live.tm = machine().time(); |
| 273 | cur_live.state = state; |
| 274 | cur_live.next_state = -1; |
| 275 | cur_live.fi = &fi; |
| 276 | cur_live.shift_reg = 0; |
| 277 | cur_live.crc = 0xffff; |
| 278 | cur_live.bit_counter = 0; |
| 279 | cur_live.data_separator_phase = false; |
| 280 | cur_live.data_reg = 0; |
| 281 | cur_live.previous_type = live_info::PT_NONE; |
| 282 | cur_live.data_bit_context = false; |
| 283 | cur_live.byte_counter = 0; |
| 284 | cur_live.pll.reset(cur_live.tm); |
| 285 | // cur_live.pll.set_clock(attotime::from_hz(rates[dsr & 3]*2)); |
| 286 | cur_live.pll.set_clock(attotime::from_hz(rates[dsr & 3])); |
| 287 | checkpoint_live = cur_live; |
| 288 | fi.live = true; |
| 289 | |
| 290 | live_run(); |
| 291 | } |
| 292 | |
| 293 | void n82077aa_device::checkpoint() |
| 294 | { |
| 295 | if(cur_live.fi) |
| 296 | cur_live.pll.commit(cur_live.fi->dev, cur_live.tm); |
| 297 | checkpoint_live = cur_live; |
| 298 | } |
| 299 | |
| 300 | void n82077aa_device::rollback() |
| 301 | { |
| 302 | cur_live = checkpoint_live; |
| 303 | } |
| 304 | |
| 305 | void n82077aa_device::live_delay(int state) |
| 306 | { |
| 307 | cur_live.next_state = state; |
| 308 | if(cur_live.tm != machine().time()) |
| 309 | cur_live.fi->tm->adjust(cur_live.tm - machine().time()); |
| 310 | } |
| 311 | |
| 312 | void n82077aa_device::live_sync() |
| 313 | { |
| 314 | if(!cur_live.tm.is_never()) { |
| 315 | if(cur_live.tm > machine().time()) { |
| 316 | rollback(); |
| 317 | live_run(machine().time()); |
| 318 | cur_live.pll.commit(cur_live.fi->dev, cur_live.tm); |
| 319 | } |
| 320 | if(cur_live.tm == machine().time()) { |
| 321 | cur_live.pll.commit(cur_live.fi->dev, cur_live.tm); |
| 322 | if(cur_live.next_state != -1) { |
| 323 | cur_live.state = cur_live.next_state; |
| 324 | cur_live.next_state = -1; |
| 325 | } |
| 326 | if(cur_live.state == IDLE) { |
| 327 | cur_live.tm = attotime::never; |
| 328 | cur_live.fi->live = false; |
| 329 | cur_live.fi = 0; |
| 330 | } |
| 331 | } |
| 332 | cur_live.next_state = -1; |
| 333 | checkpoint(); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | void n82077aa_device::live_abort() |
| 338 | { |
| 339 | |
| 340 | if(!cur_live.tm.is_never() && cur_live.tm > machine().time()) { |
| 341 | rollback(); |
| 342 | live_run(machine().time()); |
| 343 | } |
| 344 | |
| 345 | if(cur_live.fi) { |
| 346 | cur_live.pll.stop_writing(cur_live.fi->dev, cur_live.tm); |
| 347 | cur_live.fi->live = false; |
| 348 | cur_live.fi = 0; |
| 349 | } |
| 350 | |
| 351 | cur_live.tm = attotime::never; |
| 352 | cur_live.state = IDLE; |
| 353 | cur_live.next_state = -1; |
| 354 | } |
| 355 | |
| 356 | void n82077aa_device::live_run(attotime limit) |
| 357 | { |
| 358 | if(cur_live.state == IDLE || cur_live.next_state != -1) |
| 359 | return; |
| 360 | |
| 361 | if(limit == attotime::never) { |
| 362 | if(cur_live.fi->dev) |
| 363 | limit = cur_live.fi->dev->time_next_index(); |
| 364 | if(limit == attotime::never) { |
| 365 | // Happens when there's no disk or if the fdc is not |
| 366 | // connected to a drive, hence no index pulse. Force a |
| 367 | // sync from time to time in that case, so that the main |
| 368 | // cpu timeout isn't too painful. Avoids looping into |
| 369 | // infinity looking for data too. |
| 370 | |
| 371 | limit = machine().time() + attotime::from_msec(1); |
| 372 | cur_live.fi->tm->adjust(attotime::from_msec(1)); |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | for(;;) { |
| 377 | switch(cur_live.state) { |
| 378 | case SEARCH_ADDRESS_MARK_HEADER: |
| 379 | if(read_one_bit(limit)) |
| 380 | return; |
| 381 | #if 0 |
| 382 | fprintf(stderr, "%s: shift = %04x data=%02x c=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg, |
| 383 | (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) | |
| 384 | (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) | |
| 385 | (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) | |
| 386 | (cur_live.shift_reg & 0x0100 ? 0x10 : 0x00) | |
| 387 | (cur_live.shift_reg & 0x0040 ? 0x08 : 0x00) | |
| 388 | (cur_live.shift_reg & 0x0010 ? 0x04 : 0x00) | |
| 389 | (cur_live.shift_reg & 0x0004 ? 0x02 : 0x00) | |
| 390 | (cur_live.shift_reg & 0x0001 ? 0x01 : 0x00), |
| 391 | cur_live.bit_counter); |
| 392 | #endif |
| 393 | |
| 394 | if(cur_live.shift_reg == 0x4489) { |
| 395 | cur_live.crc = 0x443b; |
| 396 | cur_live.data_separator_phase = false; |
| 397 | cur_live.bit_counter = 0; |
| 398 | cur_live.state = READ_HEADER_BLOCK_HEADER; |
| 399 | } |
| 400 | break; |
| 401 | |
| 402 | case READ_HEADER_BLOCK_HEADER: { |
| 403 | if(read_one_bit(limit)) |
| 404 | return; |
| 405 | #if 0 |
| 406 | fprintf(stderr, "%s: shift = %04x data=%02x counter=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg, |
| 407 | (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) | |
| 408 | (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) | |
| 409 | (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) | |
| 410 | (cur_live.shift_reg & 0x0100 ? 0x10 : 0x00) | |
| 411 | (cur_live.shift_reg & 0x0040 ? 0x08 : 0x00) | |
| 412 | (cur_live.shift_reg & 0x0010 ? 0x04 : 0x00) | |
| 413 | (cur_live.shift_reg & 0x0004 ? 0x02 : 0x00) | |
| 414 | (cur_live.shift_reg & 0x0001 ? 0x01 : 0x00), |
| 415 | cur_live.bit_counter); |
| 416 | #endif |
| 417 | if(cur_live.bit_counter & 15) |
| 418 | break; |
| 419 | |
| 420 | int slot = cur_live.bit_counter >> 4; |
| 421 | |
| 422 | if(slot < 3) { |
| 423 | if(cur_live.shift_reg != 0x4489) |
| 424 | cur_live.state = SEARCH_ADDRESS_MARK_HEADER; |
| 425 | break; |
| 426 | } |
| 427 | if(cur_live.data_reg != 0xfe) { |
| 428 | cur_live.state = SEARCH_ADDRESS_MARK_HEADER; |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | cur_live.bit_counter = 0; |
| 433 | cur_live.state = READ_ID_BLOCK_TO_LOCAL; |
| 434 | |
| 435 | break; |
| 436 | } |
| 437 | |
| 438 | case READ_ID_BLOCK_TO_LOCAL: { |
| 439 | if(read_one_bit(limit)) |
| 440 | return; |
| 441 | if(cur_live.bit_counter & 15) |
| 442 | break; |
| 443 | int slot = (cur_live.bit_counter >> 4)-1; |
| 444 | cur_live.idbuf[slot] = cur_live.data_reg; |
| 445 | if(slot == 5) { |
| 446 | live_delay(IDLE); |
| 447 | return; |
| 448 | } |
| 449 | break; |
| 450 | } |
| 451 | |
| 452 | case SEARCH_ADDRESS_MARK_DATA: |
| 453 | if(read_one_bit(limit)) |
| 454 | return; |
| 455 | #if 0 |
| 456 | fprintf(stderr, "%s: shift = %04x data=%02x c=%d.%x\n", tts(cur_live.tm).cstr(), cur_live.shift_reg, |
| 457 | (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) | |
| 458 | (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) | |
| 459 | (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) | |
| 460 | (cur_live.shift_reg & 0x0100 ? 0x10 : 0x00) | |
| 461 | (cur_live.shift_reg & 0x0040 ? 0x08 : 0x00) | |
| 462 | (cur_live.shift_reg & 0x0010 ? 0x04 : 0x00) | |
| 463 | (cur_live.shift_reg & 0x0004 ? 0x02 : 0x00) | |
| 464 | (cur_live.shift_reg & 0x0001 ? 0x01 : 0x00), |
| 465 | cur_live.bit_counter >> 4, cur_live.bit_counter & 15); |
| 466 | #endif |
| 467 | if(cur_live.bit_counter > 43*16) { |
| 468 | live_delay(SEARCH_ADDRESS_MARK_DATA_FAILED); |
| 469 | return; |
| 470 | } |
| 471 | |
| 472 | if(cur_live.bit_counter >= 28*16 && cur_live.shift_reg == 0x4489) { |
| 473 | cur_live.crc = 0x443b; |
| 474 | cur_live.data_separator_phase = false; |
| 475 | cur_live.bit_counter = 0; |
| 476 | cur_live.state = READ_DATA_BLOCK_HEADER; |
| 477 | } |
| 478 | break; |
| 479 | |
| 480 | case READ_DATA_BLOCK_HEADER: { |
| 481 | if(read_one_bit(limit)) |
| 482 | return; |
| 483 | #if 0 |
| 484 | fprintf(stderr, "%s: shift = %04x data=%02x counter=%d\n", tts(cur_live.tm).cstr(), cur_live.shift_reg, |
| 485 | (cur_live.shift_reg & 0x4000 ? 0x80 : 0x00) | |
| 486 | (cur_live.shift_reg & 0x1000 ? 0x40 : 0x00) | |
| 487 | (cur_live.shift_reg & 0x0400 ? 0x20 : 0x00) | |
| 488 | (cur_live.shift_reg & 0x0100 ? 0x10 : 0x00) | |
| 489 | (cur_live.shift_reg & 0x0040 ? 0x08 : 0x00) | |
| 490 | (cur_live.shift_reg & 0x0010 ? 0x04 : 0x00) | |
| 491 | (cur_live.shift_reg & 0x0004 ? 0x02 : 0x00) | |
| 492 | (cur_live.shift_reg & 0x0001 ? 0x01 : 0x00), |
| 493 | cur_live.bit_counter); |
| 494 | #endif |
| 495 | if(cur_live.bit_counter & 15) |
| 496 | break; |
| 497 | |
| 498 | int slot = cur_live.bit_counter >> 4; |
| 499 | |
| 500 | if(slot < 3) { |
| 501 | if(cur_live.shift_reg != 0x4489) { |
| 502 | live_delay(SEARCH_ADDRESS_MARK_DATA_FAILED); |
| 503 | return; |
| 504 | } |
| 505 | break; |
| 506 | } |
| 507 | if(cur_live.data_reg != 0xfb && cur_live.data_reg != 0xfd) { |
| 508 | live_delay(SEARCH_ADDRESS_MARK_DATA_FAILED); |
| 509 | return; |
| 510 | } |
| 511 | |
| 512 | cur_live.bit_counter = 0; |
| 513 | cur_live.state = READ_SECTOR_DATA; |
| 514 | break; |
| 515 | } |
| 516 | |
| 517 | case SEARCH_ADDRESS_MARK_DATA_FAILED: |
| 518 | // status |= S_RNF; |
| 519 | cur_live.state = IDLE; |
| 520 | return; |
| 521 | |
| 522 | case READ_SECTOR_DATA: { |
| 523 | if(read_one_bit(limit)) |
| 524 | return; |
| 525 | if(cur_live.bit_counter & 15) |
| 526 | break; |
| 527 | int slot = (cur_live.bit_counter >> 4)-1; |
| 528 | if(slot < sector_size) { |
| 529 | // Sector data |
| 530 | live_delay(READ_SECTOR_DATA_BYTE); |
| 531 | return; |
| 532 | |
| 533 | } else if(slot < sector_size+2) { |
| 534 | // CRC |
| 535 | if(slot == sector_size+1) { |
| 536 | live_delay(IDLE); |
| 537 | return; |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | break; |
| 542 | } |
| 543 | |
| 544 | case READ_SECTOR_DATA_BYTE: |
| 545 | // fprintf(stderr, "databyte = %02x\n", cur_live.data_reg); |
| 546 | fifo_push(cur_live.data_reg); |
| 547 | cur_live.state = READ_SECTOR_DATA; |
| 548 | checkpoint(); |
| 549 | break; |
| 550 | |
| 551 | default: |
| 552 | logerror("%s: Unknown live state %d\n", tts(cur_live.tm).cstr(), cur_live.state); |
| 553 | return; |
| 554 | } |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | int n82077aa_device::check_command() |
| 559 | { |
| 560 | // 0.000010 read track |
| 561 | // 00000011 specify |
| 562 | // 00000100 sense drive status |
| 563 | // ..000101 write data |
| 564 | // ...00110 read data |
| 565 | // 00000111 recalibrate |
| 566 | // 00001000 sense interrupt status |
| 567 | // ..001001 write deleted data |
| 568 | // 0.001010 read id |
| 569 | // ...01100 read deleted data |
| 570 | // 0.001101 format track |
| 571 | // 00001110 dumpreg |
| 572 | // 00001111 seek |
| 573 | // 00010000 version |
| 574 | // ...10001 scan equal |
| 575 | // 00010010 perpendicular mode |
| 576 | // 00010011 configure |
| 577 | // .0010100 lock |
| 578 | // ...10110 verify |
| 579 | // ...11001 scan low or equal |
| 580 | // ...11101 scan high or equal |
| 581 | // 1.001111 relative seek |
| 582 | |
| 583 | switch(command[0]) { |
| 584 | case 0x03: |
| 585 | return command_pos == 3 ? C_SPECIFY : C_INCOMPLETE; |
| 586 | |
| 587 | case 0x06: case 0x26: case 0x46: case 0x66: case 0x86: case 0xa6: case 0xc6: case 0xe6: |
| 588 | return command_pos == 9 ? C_READ_DATA : C_INCOMPLETE; |
| 589 | |
| 590 | case 0x07: |
| 591 | return command_pos == 2 ? C_RECALIBRATE : C_INCOMPLETE; |
| 592 | |
| 593 | case 0x08: |
| 594 | return C_SENSE_INTERRUPT_STATUS; |
| 595 | |
| 596 | case 0x0f: |
| 597 | |
| 598 | case 0x12: |
| 599 | return command_pos == 2 ? C_PERPENDICULAR : C_INCOMPLETE; |
| 600 | |
| 601 | case 0x13: |
| 602 | return command_pos == 4 ? C_CONFIGURE : C_INCOMPLETE; |
| 603 | |
| 604 | default: |
| 605 | return C_INVALID; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | void n82077aa_device::start_command(int cmd) |
| 610 | { |
| 611 | command_pos = 0; |
| 612 | result_pos = 0; |
| 613 | main_phase = PHASE_EXEC; |
| 614 | switch(cmd) { |
| 615 | case C_CONFIGURE: |
| 616 | fprintf(stderr, "Configure %02x %02x %02x\n", |
| 617 | command[1], command[2], command[3]); |
| 618 | // byte 1 is ignored, byte 3 is precompensation-related |
| 619 | fifocfg = command[2]; |
| 620 | main_phase = PHASE_CMD; |
| 621 | break; |
| 622 | |
| 623 | case C_PERPENDICULAR: |
| 624 | main_phase = PHASE_CMD; |
| 625 | break; |
| 626 | |
| 627 | case C_READ_DATA: |
| 628 | read_data_start(flopi[command[1] & 3]); |
| 629 | break; |
| 630 | |
| 631 | case C_RECALIBRATE: |
| 632 | recalibrate_start(flopi[command[1] & 3]); |
| 633 | main_phase = PHASE_CMD; |
| 634 | break; |
| 635 | |
| 636 | case C_SENSE_INTERRUPT_STATUS: { |
| 637 | main_phase = PHASE_RESULT; |
| 638 | |
| 639 | int fid; |
| 640 | for(fid=0; fid<4 && !flopi[fid].irq; fid++); |
| 641 | if(fid == 4) { |
| 642 | result[0] = 0x80; |
| 643 | result_pos = 1; |
| 644 | break; |
| 645 | } |
| 646 | floppy_info &fi = flopi[fid]; |
| 647 | fi.irq = false; |
| 648 | result[0] = (fi.status << 6) | 0x20 | fid; |
| 649 | result[1] = fi.pcn; |
| 650 | result_pos = 2; |
| 651 | check_irq(); |
| 652 | break; |
| 653 | } |
| 654 | |
| 655 | case C_SPECIFY: |
| 656 | fprintf(stderr, "Specify %02x %02x\n", |
| 657 | command[1], command[2]); |
| 658 | spec = (command[1] << 8) | command[2]; |
| 659 | main_phase = PHASE_CMD; |
| 660 | break; |
| 661 | |
| 662 | default: |
| 663 | fprintf(stderr, "start command %d\n", cmd); |
| 664 | exit(1); |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | void n82077aa_device::command_end(floppy_info &fi, int status) |
| 669 | { |
| 670 | fi.main_state = fi.sub_state = IDLE; |
| 671 | fi.irq = true; |
| 672 | fi.status = status; |
| 673 | check_irq(); |
| 674 | } |
| 675 | |
| 676 | void n82077aa_device::recalibrate_start(floppy_info &fi) |
| 677 | { |
| 678 | fi.main_state = RECALIBRATE; |
| 679 | fi.sub_state = SEEK_WAIT_STEP_TIME_DONE; |
| 680 | fi.dir = 1; |
| 681 | seek_continue(fi); |
| 682 | } |
| 683 | |
| 684 | void n82077aa_device::delay_cycles(emu_timer *tm, int cycles) |
| 685 | { |
| 686 | tm->adjust(attotime::from_double(double(cycles)/rates[dsr & 3])); |
| 687 | } |
| 688 | |
| 689 | void n82077aa_device::seek_continue(floppy_info &fi) |
| 690 | { |
| 691 | for(;;) { |
| 692 | switch(fi.sub_state) { |
| 693 | case SEEK_MOVE: |
| 694 | if(fi.dev) { |
| 695 | fi.dev->dir_w(fi.dir); |
| 696 | fi.dev->stp_w(0); |
| 697 | } |
| 698 | fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME; |
| 699 | fi.tm->adjust(attotime::from_nsec(2500)); |
| 700 | return; |
| 701 | |
| 702 | case SEEK_WAIT_STEP_SIGNAL_TIME: |
| 703 | return; |
| 704 | |
| 705 | case SEEK_WAIT_STEP_SIGNAL_TIME_DONE: |
| 706 | if(fi.dev) |
| 707 | fi.dev->stp_w(1); |
| 708 | |
| 709 | fi.sub_state = SEEK_WAIT_STEP_TIME; |
| 710 | delay_cycles(fi.tm, 500*(16-(spec >> 12))); |
| 711 | return; |
| 712 | |
| 713 | case SEEK_WAIT_STEP_TIME: |
| 714 | return; |
| 715 | |
| 716 | case SEEK_WAIT_STEP_TIME_DONE: { |
| 717 | bool done = false; |
| 718 | switch(fi.main_state) { |
| 719 | case RECALIBRATE: |
| 720 | done = !fi.dev || !fi.dev->trk00_r(); |
| 721 | if(done) |
| 722 | fi.pcn = 0; |
| 723 | break; |
| 724 | } |
| 725 | if(done) { |
| 726 | fprintf(stderr, "Seek done\n"); |
| 727 | command_end(fi, 0); |
| 728 | return; |
| 729 | } |
| 730 | fi.sub_state = SEEK_MOVE; |
| 731 | break; |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | void n82077aa_device::read_data_start(floppy_info &fi) |
| 738 | { |
| 739 | fi.main_state = READ_DATA; |
| 740 | fi.sub_state = HEAD_LOAD_DONE; |
| 741 | |
| 742 | fprintf(stderr, "Read data%s%s%s\n", |
| 743 | command[0] & 0x80 ? " mt" : "", |
| 744 | command[0] & 0x40 ? " mfm" : "", |
| 745 | command[0] & 0x20 ? " sk" : ""); |
| 746 | fprintf(stderr, " cmd=%02x sel=%x chrn=(%d, %d, %d, %d) eot=%02x gpl=%02x dtl=%02x\n", |
| 747 | command[0], |
| 748 | command[1], |
| 749 | command[2], |
| 750 | command[3], |
| 751 | command[4], |
| 752 | 128 << (command[5] & 7), |
| 753 | command[6], |
| 754 | command[7], |
| 755 | command[8]); |
| 756 | fprintf(stderr, " rate=%d\n", rates[dsr & 3]); |
| 757 | if(fi.dev) |
| 758 | fi.dev->ss_w(command[1] & 8); |
| 759 | read_data_continue(fi); |
| 760 | } |
| 761 | |
| 762 | void n82077aa_device::read_data_continue(floppy_info &fi) |
| 763 | { |
| 764 | for(;;) { |
| 765 | switch(fi.sub_state) { |
| 766 | case HEAD_LOAD_DONE: |
| 767 | counter = 0; |
| 768 | fi.sub_state = SCAN_ID; |
| 769 | live_start(fi, SEARCH_ADDRESS_MARK_HEADER); |
| 770 | return; |
| 771 | |
| 772 | case SCAN_ID: |
| 773 | if(!sector_matches()) { |
| 774 | live_start(fi, SEARCH_ADDRESS_MARK_HEADER); |
| 775 | return; |
| 776 | } |
| 777 | if(cur_live.crc) { |
| 778 | fprintf(stderr, "Header CRC error\n"); |
| 779 | live_start(fi, SEARCH_ADDRESS_MARK_HEADER); |
| 780 | return; |
| 781 | } |
| 782 | sector_size = 128 << (cur_live.idbuf[3] & 3); |
| 783 | fifo_expect(sector_size, false); |
| 784 | fi.sub_state = SECTOR_READ; |
| 785 | live_start(fi, SEARCH_ADDRESS_MARK_DATA); |
| 786 | return; |
| 787 | |
| 788 | case SCAN_ID_FAILED: |
| 789 | fprintf(stderr, "RNF\n"); |
| 790 | command_end(fi, 1); |
| 791 | return; |
| 792 | |
| 793 | case SECTOR_READ: |
| 794 | if(cur_live.crc) { |
| 795 | fprintf(stderr, "CRC error\n"); |
| 796 | } |
| 797 | command[4]++; |
| 798 | command[6]--; |
| 799 | fprintf(stderr, "One sector done -> %d.\n", command[6]); |
| 800 | if(command[6]) { |
| 801 | fi.sub_state = HEAD_LOAD_DONE; |
| 802 | break; |
| 803 | } |
| 804 | main_phase = PHASE_RESULT; |
| 805 | result[0] = 0; |
| 806 | result[1] = 0; |
| 807 | result[2] = 0; |
| 808 | result[3] = command[2]; |
| 809 | result[4] = command[3]; |
| 810 | result[5] = command[4]; |
| 811 | result[6] = command[5]; |
| 812 | result_pos = 7; |
| 813 | command_end(fi, 0); |
| 814 | return; |
| 815 | |
| 816 | default: |
| 817 | logerror("%s: read sector unknown sub-state %d\n", ttsn().cstr(), fi.sub_state); |
| 818 | return; |
| 819 | } |
| 820 | } |
| 821 | } |
| 822 | |
| 823 | void n82077aa_device::check_irq() |
| 824 | { |
| 825 | bool old_irq = cur_irq; |
| 826 | cur_irq = false; |
| 827 | for(int i=0; i<4; i++) |
| 828 | cur_irq = cur_irq || flopi[i].irq; |
| 829 | if(cur_irq != old_irq && !intrq_cb.isnull()) |
| 830 | intrq_cb(cur_irq); |
| 831 | } |
| 832 | |
| 833 | astring n82077aa_device::tts(attotime t) |
| 834 | { |
| 835 | char buf[256]; |
| 836 | int nsec = t.attoseconds / ATTOSECONDS_PER_NANOSECOND; |
| 837 | sprintf(buf, "%4d.%03d,%03d,%03d", int(t.seconds), nsec/1000000, (nsec/1000)%1000, nsec % 1000); |
| 838 | return buf; |
| 839 | } |
| 840 | |
| 841 | astring n82077aa_device::ttsn() |
| 842 | { |
| 843 | return tts(machine().time()); |
| 844 | } |
| 845 | |
| 846 | void n82077aa_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 847 | { |
| 848 | live_sync(); |
| 849 | |
| 850 | floppy_info &fi = flopi[id]; |
| 851 | switch(fi.sub_state) { |
| 852 | case SEEK_WAIT_STEP_SIGNAL_TIME: |
| 853 | fi.sub_state = SEEK_WAIT_STEP_SIGNAL_TIME_DONE; |
| 854 | break; |
| 855 | case SEEK_WAIT_STEP_TIME: |
| 856 | fi.sub_state = SEEK_WAIT_STEP_TIME_DONE; |
| 857 | break; |
| 858 | } |
| 859 | |
| 860 | general_continue(fi); |
| 861 | } |
| 862 | |
| 863 | void n82077aa_device::index_callback(floppy_image_device *floppy, int state) |
| 864 | { |
| 865 | int fid; |
| 866 | for(fid=0; fid<4; fid++) |
| 867 | if(flopi[fid].dev == floppy) |
| 868 | break; |
| 869 | |
| 870 | assert(fid != 4); |
| 871 | floppy_info &fi = flopi[fid]; |
| 872 | |
| 873 | live_sync(); |
| 874 | fi.index = state; |
| 875 | |
| 876 | if(!state) { |
| 877 | general_continue(fi); |
| 878 | return; |
| 879 | } |
| 880 | |
| 881 | switch(fi.sub_state) { |
| 882 | case IDLE: |
| 883 | break; |
| 884 | |
| 885 | case SCAN_ID: |
| 886 | counter++; |
| 887 | if(counter == 2) |
| 888 | fi.sub_state = SCAN_ID_FAILED; |
| 889 | break; |
| 890 | |
| 891 | default: |
| 892 | logerror("%s: Index pulse on unknown sub-state %d\n", ttsn().cstr(), fi.sub_state); |
| 893 | break; |
| 894 | } |
| 895 | |
| 896 | general_continue(fi); |
| 897 | } |
| 898 | |
| 899 | |
| 900 | void n82077aa_device::general_continue(floppy_info &fi) |
| 901 | { |
| 902 | if(fi.live && cur_live.state != IDLE) { |
| 903 | live_run(); |
| 904 | if(cur_live.state != IDLE) |
| 905 | return; |
| 906 | } |
| 907 | |
| 908 | switch(fi.main_state) { |
| 909 | case IDLE: |
| 910 | break; |
| 911 | |
| 912 | case RECALIBRATE: |
| 913 | seek_continue(fi); |
| 914 | break; |
| 915 | |
| 916 | case READ_DATA: |
| 917 | read_data_continue(fi); |
| 918 | break; |
| 919 | |
| 920 | default: |
| 921 | logerror("%s: general_continue on unknown main-state %d\n", ttsn().cstr(), fi.main_state); |
| 922 | break; |
| 923 | } |
| 924 | } |
| 925 | |
| 926 | bool n82077aa_device::read_one_bit(attotime limit) |
| 927 | { |
| 928 | int bit = cur_live.pll.get_next_bit(cur_live.tm, cur_live.fi->dev, limit); |
| 929 | if(bit < 0) |
| 930 | return true; |
| 931 | cur_live.shift_reg = (cur_live.shift_reg << 1) | bit; |
| 932 | cur_live.bit_counter++; |
| 933 | if(cur_live.data_separator_phase) { |
| 934 | cur_live.data_reg = (cur_live.data_reg << 1) | bit; |
| 935 | if((cur_live.crc ^ (bit ? 0x8000 : 0x0000)) & 0x8000) |
| 936 | cur_live.crc = (cur_live.crc << 1) ^ 0x1021; |
| 937 | else |
| 938 | cur_live.crc = cur_live.crc << 1; |
| 939 | } |
| 940 | cur_live.data_separator_phase = !cur_live.data_separator_phase; |
| 941 | return false; |
| 942 | } |
| 943 | |
| 944 | bool n82077aa_device::write_one_bit(attotime limit) |
| 945 | { |
| 946 | bool bit = cur_live.shift_reg & 0x8000; |
| 947 | if(cur_live.pll.write_next_bit(bit, cur_live.tm, cur_live.fi->dev, limit)) |
| 948 | return true; |
| 949 | if(cur_live.bit_counter & 1) { |
| 950 | if((cur_live.crc ^ (bit ? 0x8000 : 0x0000)) & 0x8000) |
| 951 | cur_live.crc = (cur_live.crc << 1) ^ 0x1021; |
| 952 | else |
| 953 | cur_live.crc = cur_live.crc << 1; |
| 954 | } |
| 955 | cur_live.shift_reg = cur_live.shift_reg << 1; |
| 956 | cur_live.bit_counter--; |
| 957 | return false; |
| 958 | } |
| 959 | |
| 960 | bool n82077aa_device::sector_matches() const |
| 961 | { |
| 962 | if(1) |
| 963 | fprintf(stderr, "match %d %d %d %d - %d %d %d %d\n", |
| 964 | cur_live.idbuf[0], cur_live.idbuf[1], cur_live.idbuf[2], cur_live.idbuf[3], |
| 965 | command[2], command[3], command[4], command[5]); |
| 966 | return |
| 967 | cur_live.idbuf[0] == command[2] && |
| 968 | cur_live.idbuf[1] == command[3] && |
| 969 | cur_live.idbuf[2] == command[4] && |
| 970 | cur_live.idbuf[3] == command[5]; |
| 971 | } |
| 972 | |
| 973 | void n82077aa_device::pll_t::set_clock(attotime _period) |
| 974 | { |
| 975 | period = _period; |
| 976 | period_adjust_base = period * 0.05; |
| 977 | min_period = period * 0.75; |
| 978 | max_period = period * 1.25; |
| 979 | } |
| 980 | |
| 981 | void n82077aa_device::pll_t::reset(attotime when) |
| 982 | { |
| 983 | ctime = when; |
| 984 | phase_adjust = attotime::zero; |
| 985 | freq_hist = 0; |
| 986 | write_position = 0; |
| 987 | write_start_time = attotime::never; |
| 988 | } |
| 989 | |
| 990 | void n82077aa_device::pll_t::start_writing(attotime tm) |
| 991 | { |
| 992 | write_start_time = tm; |
| 993 | write_position = 0; |
| 994 | } |
| 995 | |
| 996 | void n82077aa_device::pll_t::stop_writing(floppy_image_device *floppy, attotime tm) |
| 997 | { |
| 998 | commit(floppy, tm); |
| 999 | write_start_time = attotime::never; |
| 1000 | } |
| 1001 | |
| 1002 | void n82077aa_device::pll_t::commit(floppy_image_device *floppy, attotime tm) |
| 1003 | { |
| 1004 | if(write_start_time.is_never() || tm == write_start_time) |
| 1005 | return; |
| 1006 | |
| 1007 | if(floppy) |
| 1008 | floppy->write_flux(write_start_time, tm, write_position, write_buffer); |
| 1009 | write_start_time = tm; |
| 1010 | write_position = 0; |
| 1011 | } |
| 1012 | |
| 1013 | int n82077aa_device::pll_t::get_next_bit(attotime &tm, floppy_image_device *floppy, attotime limit) |
| 1014 | { |
| 1015 | attotime edge = floppy ? floppy->get_next_transition(ctime) : attotime::never; |
| 1016 | |
| 1017 | attotime next = ctime + period + phase_adjust; |
| 1018 | |
| 1019 | #if 0 |
| 1020 | if(!edge.is_never()) |
| 1021 | fprintf(stderr, "transition_time=%s, next=%s\n", tts(edge).cstr(), tts(next).cstr()); |
| 1022 | #endif |
| 1023 | |
| 1024 | if(next > limit) |
| 1025 | return -1; |
| 1026 | |
| 1027 | ctime = next; |
| 1028 | |
| 1029 | if(edge.is_never() || edge >= next) { |
| 1030 | // No transition in the window means 0 and pll in free run mode |
| 1031 | phase_adjust = attotime::zero; |
| 1032 | tm = next; |
| 1033 | return 0; |
| 1034 | } |
| 1035 | |
| 1036 | // Transition in the window means 1, and the pll is adjusted |
| 1037 | |
| 1038 | attotime delta = edge - (next - period/2); |
| 1039 | |
| 1040 | phase_adjust = 0.65*delta; |
| 1041 | |
| 1042 | if(delta < attotime::zero) { |
| 1043 | if(freq_hist < 0) |
| 1044 | freq_hist--; |
| 1045 | else |
| 1046 | freq_hist = -1; |
| 1047 | } else if(delta > attotime::zero) { |
| 1048 | if(freq_hist > 0) |
| 1049 | freq_hist++; |
| 1050 | else |
| 1051 | freq_hist = 1; |
| 1052 | } else |
| 1053 | freq_hist = 0; |
| 1054 | |
| 1055 | if(freq_hist) { |
| 1056 | int afh = freq_hist < 0 ? -freq_hist : freq_hist; |
| 1057 | if(afh > 1) { |
| 1058 | attotime aper = attotime::from_double(period_adjust_base.as_double()*delta.as_double()/period.as_double()); |
| 1059 | period += aper; |
| 1060 | |
| 1061 | if(period < min_period) |
| 1062 | period = min_period; |
| 1063 | else if(period > max_period) |
| 1064 | period = max_period; |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | return 1; |
| 1069 | } |
| 1070 | |
| 1071 | bool n82077aa_device::pll_t::write_next_bit(bool bit, attotime &tm, floppy_image_device *floppy, attotime limit) |
| 1072 | { |
| 1073 | if(write_start_time.is_never()) { |
| 1074 | write_start_time = ctime; |
| 1075 | write_position = 0; |
| 1076 | } |
| 1077 | |
| 1078 | attotime etime = ctime + period; |
| 1079 | if(etime > limit) |
| 1080 | return true; |
| 1081 | |
| 1082 | if(write_position < ARRAY_LENGTH(write_buffer)) |
| 1083 | write_buffer[write_position++] = ctime + period/2; |
| 1084 | |
| 1085 | tm = etime; |
| 1086 | ctime = etime; |
| 1087 | return false; |
| 1088 | } |
src/mess/machine/nextmo.c
| r14142 | r14143 | |
| 1 | #define ADDRESS_MAP_MODERN |
| 2 | |
| 3 | #include "emu.h" |
| 4 | #include "nextmo.h" |
| 5 | |
| 6 | const device_type NEXTMO = &device_creator<nextmo_device>; |
| 7 | |
| 8 | DEVICE_ADDRESS_MAP_START(map, 8, nextmo_device) |
| 9 | AM_RANGE(0x04, 0x04) AM_READWRITE(r4_r, r4_w) |
| 10 | AM_RANGE(0x05, 0x05) AM_READWRITE(r5_r, r5_w) |
| 11 | AM_RANGE(0x06, 0x06) AM_READWRITE(r6_r, r6_w) |
| 12 | AM_RANGE(0x07, 0x07) AM_READWRITE(r7_r, r7_w) |
| 13 | AM_RANGE(0x08, 0x08) AM_READWRITE(r8_r, r8_w) |
| 14 | AM_RANGE(0x09, 0x09) AM_READWRITE(r9_r, r9_w) |
| 15 | AM_RANGE(0x0a, 0x0a) AM_READWRITE(ra_r, ra_w) |
| 16 | AM_RANGE(0x0b, 0x0b) AM_READWRITE(rb_r, rb_w) |
| 17 | AM_RANGE(0x10, 0x17) AM_READWRITE(r10_r, r10_w) |
| 18 | ADDRESS_MAP_END |
| 19 | |
| 20 | nextmo_device::nextmo_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 21 | : device_t(mconfig, NEXTMO, "NeXT Magneto-optical drive", tag, owner, clock) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | void nextmo_device::set_cb(cb_t _irq_cb, cb_t _drq_cb) |
| 26 | { |
| 27 | irq_cb = _irq_cb; |
| 28 | drq_cb = _drq_cb; |
| 29 | } |
| 30 | |
| 31 | void nextmo_device::device_start() |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | void nextmo_device::device_reset() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | READ8_MEMBER(nextmo_device::r4_r) |
| 40 | { |
| 41 | fprintf(stderr, "nextmo: r4_r %02x (%08x)\n", r4, cpu_get_pc(&space.device())); |
| 42 | return r4; |
| 43 | } |
| 44 | |
| 45 | WRITE8_MEMBER(nextmo_device::r4_w) |
| 46 | { |
| 47 | if(r4 & 1) |
| 48 | device_reset(); |
| 49 | r4 = (r4 & (~data & 0xfc)) | (data & 3); |
| 50 | fprintf(stderr, "nextmo: r4_w %02x (%08x)\n", r4, cpu_get_pc(&space.device())); |
| 51 | } |
| 52 | |
| 53 | READ8_MEMBER(nextmo_device::r5_r) |
| 54 | { |
| 55 | fprintf(stderr, "nextmo: r5_r %02x (%08x)\n", r5, cpu_get_pc(&space.device())); |
| 56 | return r5; |
| 57 | } |
| 58 | |
| 59 | WRITE8_MEMBER(nextmo_device::r5_w) |
| 60 | { |
| 61 | r5 = data; |
| 62 | fprintf(stderr, "nextmo: r5_w %02x (%08x)\n", r5, cpu_get_pc(&space.device())); |
| 63 | } |
| 64 | |
| 65 | READ8_MEMBER(nextmo_device::r6_r) |
| 66 | { |
| 67 | fprintf(stderr, "nextmo: r6_r %02x (%08x)\n", r6, cpu_get_pc(&space.device())); |
| 68 | return r6; |
| 69 | } |
| 70 | |
| 71 | WRITE8_MEMBER(nextmo_device::r6_w) |
| 72 | { |
| 73 | r6 = data; |
| 74 | fprintf(stderr, "nextmo: r6_w %02x (%08x)\n", r6, cpu_get_pc(&space.device())); |
| 75 | } |
| 76 | |
| 77 | READ8_MEMBER(nextmo_device::r7_r) |
| 78 | { |
| 79 | fprintf(stderr, "nextmo: r7_r %02x (%08x)\n", r7, cpu_get_pc(&space.device())); |
| 80 | return r7; |
| 81 | } |
| 82 | |
| 83 | WRITE8_MEMBER(nextmo_device::r7_w) |
| 84 | { |
| 85 | r7 = data; |
| 86 | fprintf(stderr, "nextmo: r7_w %02x (%08x)\n", r7, cpu_get_pc(&space.device())); |
| 87 | if(r7 & 0xc0) { |
| 88 | fprintf(stderr, "nextmo: start dma %02x %02x\n", r6, r7); |
| 89 | sector_pos = 0; |
| 90 | if(!drq_cb.isnull()) |
| 91 | drq_cb(true); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | UINT8 nextmo_device::dma_r() |
| 96 | { |
| 97 | UINT8 r = 0; |
| 98 | if(r7 & 0x80) |
| 99 | r = sector[sector_pos++]; |
| 100 | check_dma_end(); |
| 101 | return r; |
| 102 | } |
| 103 | |
| 104 | void nextmo_device::dma_w(UINT8 data) |
| 105 | { |
| 106 | if(r7 & 0x40) |
| 107 | sector[sector_pos++] = data; |
| 108 | check_dma_end(); |
| 109 | } |
| 110 | |
| 111 | void nextmo_device::check_dma_end() |
| 112 | { |
| 113 | int limit; |
| 114 | if(r7 & 0x40) |
| 115 | limit = r6 & 0x20 ? 0x510 : 0x400; |
| 116 | else |
| 117 | limit = r6 & 0x20 ? 0x400 : 0x510; |
| 118 | if(sector_pos == limit) { |
| 119 | if(!drq_cb.isnull()) |
| 120 | drq_cb(false); |
| 121 | if(r7 & 0x40) { |
| 122 | if(r6 & 0x20) |
| 123 | check_ecc(); |
| 124 | else |
| 125 | compute_ecc(); |
| 126 | } |
| 127 | r7 &= 0x3f; |
| 128 | r4 |= 0x08; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | READ8_MEMBER(nextmo_device::r8_r) |
| 133 | { |
| 134 | fprintf(stderr, "nextmo: r8_r (%08x)\n", cpu_get_pc(&space.device())); |
| 135 | return 0x00; |
| 136 | } |
| 137 | |
| 138 | WRITE8_MEMBER(nextmo_device::r8_w) |
| 139 | { |
| 140 | fprintf(stderr, "nextmo: r8_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 141 | } |
| 142 | |
| 143 | READ8_MEMBER(nextmo_device::r9_r) |
| 144 | { |
| 145 | fprintf(stderr, "nextmo: r9_r (%08x)\n", cpu_get_pc(&space.device())); |
| 146 | return 0x00; |
| 147 | } |
| 148 | |
| 149 | WRITE8_MEMBER(nextmo_device::r9_w) |
| 150 | { |
| 151 | fprintf(stderr, "nextmo: r9_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 152 | } |
| 153 | |
| 154 | READ8_MEMBER(nextmo_device::ra_r) |
| 155 | { |
| 156 | fprintf(stderr, "nextmo: ra_r (%08x)\n", cpu_get_pc(&space.device())); |
| 157 | return 0x00; |
| 158 | } |
| 159 | |
| 160 | WRITE8_MEMBER(nextmo_device::ra_w) |
| 161 | { |
| 162 | fprintf(stderr, "nextmo: ra_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 163 | } |
| 164 | |
| 165 | READ8_MEMBER(nextmo_device::rb_r) |
| 166 | { |
| 167 | fprintf(stderr, "nextmo: rb_r (%08x)\n", cpu_get_pc(&space.device())); |
| 168 | return 0x24; |
| 169 | } |
| 170 | |
| 171 | WRITE8_MEMBER(nextmo_device::rb_w) |
| 172 | { |
| 173 | fprintf(stderr, "nextmo: rb_w %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 174 | } |
| 175 | |
| 176 | READ8_MEMBER(nextmo_device::r10_r) |
| 177 | { |
| 178 | fprintf(stderr, "nextmo: r10_r %d (%08x)\n", offset, cpu_get_pc(&space.device())); |
| 179 | return 0x00; |
| 180 | } |
| 181 | |
| 182 | WRITE8_MEMBER(nextmo_device::r10_w) |
| 183 | { |
| 184 | fprintf(stderr, "nextmo: r10_w %d, %02x (%08x)\n", offset, data, cpu_get_pc(&space.device())); |
| 185 | } |
| 186 | |
| 187 | void nextmo_device::check_ecc() |
| 188 | { |
| 189 | fprintf(stderr, "nextmo: check_ecc\n"); |
| 190 | for(int i=0; i<0x400; i++) |
| 191 | sector[i] = i; |
| 192 | } |
| 193 | |
| 194 | void nextmo_device::compute_ecc() |
| 195 | { |
| 196 | fprintf(stderr, "nextmo: compute_ecc\n"); |
| 197 | memset(sector+0x400, 0, 0x110); |
| 198 | } |
src/mess/machine/mb8795.c
| r14142 | r14143 | |
| 1 | #define ADDRESS_MAP_MODERN |
| 2 | |
| 3 | #include "emu.h" |
| 4 | #include "mb8795.h" |
| 5 | |
| 6 | const device_type MB8795 = &device_creator<mb8795_device>; |
| 7 | |
| 8 | DEVICE_ADDRESS_MAP_START(map, 8, mb8795_device) |
| 9 | AM_RANGE(0x0, 0x0) AM_READWRITE(txstat_r, txstat_w) |
| 10 | AM_RANGE(0x1, 0x1) AM_READWRITE(txmask_r, txmask_w) |
| 11 | AM_RANGE(0x2, 0x2) AM_READWRITE(rxstat_r, rxstat_w) |
| 12 | AM_RANGE(0x3, 0x3) AM_READWRITE(rxmask_r, rxmask_w) |
| 13 | AM_RANGE(0x4, 0x4) AM_READWRITE(txmode_r, txmode_w) |
| 14 | AM_RANGE(0x5, 0x5) AM_READWRITE(rxmode_r, rxmode_w) |
| 15 | AM_RANGE(0x6, 0x6) AM_WRITE(reset_w) |
| 16 | AM_RANGE(0x7, 0x7) AM_READ(tdc_lsb_r) |
| 17 | AM_RANGE(0x8, 0xf) AM_READWRITE(mac_r, mac_w) // Mapping limitation, real is up to 0xd |
| 18 | ADDRESS_MAP_END |
| 19 | |
| 20 | mb8795_device::mb8795_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) |
| 21 | : device_t(mconfig, MB8795, "Fujitsu MB8795", tag, owner, clock), |
| 22 | device_network_interface(mconfig, *this, 10) |
| 23 | { |
| 24 | } |
| 25 | |
| 26 | void mb8795_device::set_irq_cb(line_cb_t tx, line_cb_t rx) |
| 27 | { |
| 28 | irq_tx_cb = tx; |
| 29 | irq_rx_cb = rx; |
| 30 | } |
| 31 | |
| 32 | void mb8795_device::set_drq_cb(line_cb_t tx, line_cb_t rx) |
| 33 | { |
| 34 | drq_tx_cb = tx; |
| 35 | drq_rx_cb = rx; |
| 36 | } |
| 37 | |
| 38 | void mb8795_device::check_irq() |
| 39 | { |
| 40 | bool old_irq_tx = irq_tx; |
| 41 | bool old_irq_rx = irq_rx; |
| 42 | irq_tx = txstat & txmask; |
| 43 | irq_rx = rxstat & rxmask; |
| 44 | if(irq_tx != old_irq_tx && !irq_tx_cb.isnull()) |
| 45 | irq_tx_cb(irq_tx); |
| 46 | if(irq_rx != old_irq_rx && !irq_rx_cb.isnull()) |
| 47 | irq_rx_cb(irq_rx); |
| 48 | } |
| 49 | |
| 50 | void mb8795_device::device_start() |
| 51 | { |
| 52 | memset(mac, 0, 6); |
| 53 | timer_tx = timer_alloc(TIMER_TX); |
| 54 | timer_rx = timer_alloc(TIMER_RX); |
| 55 | } |
| 56 | |
| 57 | void mb8795_device::device_reset() |
| 58 | { |
| 59 | txstat = EN_TXS_READY; |
| 60 | txmask = 0x00; |
| 61 | rxstat = 0x00; |
| 62 | rxmask = 0x00; |
| 63 | txmode = 0x00; |
| 64 | rxmode = 0x00; |
| 65 | |
| 66 | drq_tx = drq_rx = false; |
| 67 | irq_tx = irq_rx = false; |
| 68 | |
| 69 | txlen = rxlen = txcount = 0; |
| 70 | |
| 71 | set_promisc(true); |
| 72 | |
| 73 | start_send(); |
| 74 | } |
| 75 | |
| 76 | void mb8795_device::recv_cb(UINT8 *buf, int len) |
| 77 | { |
| 78 | memcpy(rxbuf, buf, len); |
| 79 | rxlen = len; |
| 80 | receive(); |
| 81 | } |
| 82 | |
| 83 | bool mb8795_device::mcast_chk(const UINT8 *buf, int len) |
| 84 | { |
| 85 | return true; |
| 86 | } |
| 87 | |
| 88 | READ8_MEMBER(mb8795_device::txstat_r) |
| 89 | { |
| 90 | // fprintf(stderr, "mb8795: txstat_r %02x (%08x)\n", txstat, cpu_get_pc(&space.device())); |
| 91 | return txstat; |
| 92 | } |
| 93 | |
| 94 | WRITE8_MEMBER(mb8795_device::txstat_w) |
| 95 | { |
| 96 | txstat = txstat & (0xf0 | ~data); |
| 97 | check_irq(); |
| 98 | fprintf(stderr, "mb8795: txstat_w %02x (%08x)\n", txstat, cpu_get_pc(&space.device())); |
| 99 | } |
| 100 | |
| 101 | READ8_MEMBER(mb8795_device::txmask_r) |
| 102 | { |
| 103 | fprintf(stderr, "mb8795: txmask_r %02x (%08x)\n", txmask, cpu_get_pc(&space.device())); |
| 104 | return txmask; |
| 105 | } |
| 106 | |
| 107 | WRITE8_MEMBER(mb8795_device::txmask_w) |
| 108 | { |
| 109 | txmask = data & 0xaf; |
| 110 | check_irq(); |
| 111 | fprintf(stderr, "mb8795: txmask_w %02x (%08x)\n", txmask, cpu_get_pc(&space.device())); |
| 112 | } |
| 113 | |
| 114 | READ8_MEMBER(mb8795_device::rxstat_r) |
| 115 | { |
| 116 | fprintf(stderr, "mb8795: rxstat_r %02x (%08x)\n", rxstat, cpu_get_pc(&space.device())); |
| 117 | return rxstat; |
| 118 | } |
| 119 | |
| 120 | WRITE8_MEMBER(mb8795_device::rxstat_w) |
| 121 | { |
| 122 | rxstat = rxstat & (0x70 | ~data); |
| 123 | check_irq(); |
| 124 | fprintf(stderr, "mb8795: rxstat_w %02x (%08x)\n", rxstat, cpu_get_pc(&space.device())); |
| 125 | } |
| 126 | |
| 127 | READ8_MEMBER(mb8795_device::rxmask_r) |
| 128 | { |
| 129 | fprintf(stderr, "mb8795: rxmask_r %02x (%08x)\n", rxmask, cpu_get_pc(&space.device())); |
| 130 | return rxmask; |
| 131 | } |
| 132 | |
| 133 | WRITE8_MEMBER(mb8795_device::rxmask_w) |
| 134 | { |
| 135 | rxmask = data & 0x9f; |
| 136 | check_irq(); |
| 137 | fprintf(stderr, "mb8795: rxmask_w %02x (%08x)\n", rxmask, cpu_get_pc(&space.device())); |
| 138 | } |
| 139 | |
| 140 | READ8_MEMBER(mb8795_device::txmode_r) |
| 141 | { |
| 142 | fprintf(stderr, "mb8795: txmode_r %02x (%08x)\n", txmode, cpu_get_pc(&space.device())); |
| 143 | return txmode; |
| 144 | } |
| 145 | |
| 146 | WRITE8_MEMBER(mb8795_device::txmode_w) |
| 147 | { |
| 148 | txmode = data; |
| 149 | fprintf(stderr, "mb8795: txmode_w %02x (%08x)\n", txmode, cpu_get_pc(&space.device())); |
| 150 | } |
| 151 | |
| 152 | READ8_MEMBER(mb8795_device::rxmode_r) |
| 153 | { |
| 154 | fprintf(stderr, "mb8795: rxmode_r %02x (%08x)\n", rxmode, cpu_get_pc(&space.device())); |
| 155 | return rxmode; |
| 156 | } |
| 157 | |
| 158 | WRITE8_MEMBER(mb8795_device::rxmode_w) |
| 159 | { |
| 160 | rxmode = data; |
| 161 | fprintf(stderr, "mb8795: rxmode_w %02x (%08x)\n", rxmode, cpu_get_pc(&space.device())); |
| 162 | } |
| 163 | |
| 164 | WRITE8_MEMBER(mb8795_device::reset_w) |
| 165 | { |
| 166 | if(data & EN_RST_RESET) |
| 167 | device_reset(); |
| 168 | } |
| 169 | |
| 170 | READ8_MEMBER(mb8795_device::tdc_lsb_r) |
| 171 | { |
| 172 | fprintf(stderr, "mb8795: tdc_lsb_r %02x (%08x)\n", txcount & 0xff, cpu_get_pc(&space.device())); |
| 173 | return txcount; |
| 174 | } |
| 175 | |
| 176 | READ8_MEMBER(mb8795_device::mac_r) |
| 177 | { |
| 178 | if(offset < 6) |
| 179 | return mac[offset]; |
| 180 | if(offset == 7) { |
| 181 | fprintf(stderr, "mb8795: tdc_msb_r %02x (%08x)\n", txcount >> 8, cpu_get_pc(&space.device())); |
| 182 | return (txcount >> 8) & 0x3f; |
| 183 | } |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | WRITE8_MEMBER(mb8795_device::mac_w) |
| 188 | { |
| 189 | if(offset < 6) { |
| 190 | mac[offset] = data; |
| 191 | set_mac((const char *)mac); |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | void mb8795_device::start_send() |
| 196 | { |
| 197 | timer_tx->adjust(attotime::zero); |
| 198 | } |
| 199 | |
| 200 | void mb8795_device::tx_dma_w(UINT8 data, bool eof) |
| 201 | { |
| 202 | txbuf[txlen++] = data; |
| 203 | if(txstat & EN_TXS_READY) { |
| 204 | txstat &= ~EN_TXS_READY; |
| 205 | check_irq(); |
| 206 | } |
| 207 | |
| 208 | drq_tx = false; |
| 209 | if(!drq_tx_cb.isnull()) |
| 210 | drq_tx_cb(drq_tx); |
| 211 | |
| 212 | if(eof) { |
| 213 | fprintf(stderr, "mb8795: send packet, dest=%02x.%02x.%02x.%02x.%02x.%02x len=%04x\n", |
| 214 | txbuf[0], txbuf[1], txbuf[2], txbuf[3], txbuf[4], txbuf[5], |
| 215 | txlen); |
| 216 | if(!(txmode & EN_TMD_LB_DISABLE)) |
| 217 | fprintf(stderr, " -> loopback active\n"); |
| 218 | |
| 219 | if(!(txmode & EN_TMD_LB_DISABLE)) { |
| 220 | memcpy(rxbuf, txbuf, txlen); |
| 221 | rxlen = txlen; |
| 222 | receive(); |
| 223 | } |
| 224 | send(txbuf, txlen); |
| 225 | txlen = 0; |
| 226 | txstat |= EN_TXS_READY; |
| 227 | txcount++; |
| 228 | start_send(); |
| 229 | } else |
| 230 | timer_tx->adjust(attotime::from_nsec(800)); |
| 231 | } |
| 232 | |
| 233 | void mb8795_device::rx_dma_r(UINT8 &data, bool &eof) |
| 234 | { |
| 235 | drq_rx = false; |
| 236 | if(!drq_rx_cb.isnull()) |
| 237 | drq_rx_cb(drq_rx); |
| 238 | |
| 239 | if(rxlen) { |
| 240 | data = rxbuf[0]; |
| 241 | rxlen--; |
| 242 | memmove(rxbuf, rxbuf+1, rxlen); |
| 243 | } else |
| 244 | data = 0; |
| 245 | |
| 246 | if(rxlen) { |
| 247 | timer_rx->adjust(attotime::from_nsec(800)); |
| 248 | eof = false; |
| 249 | } else |
| 250 | eof = true; |
| 251 | } |
| 252 | |
| 253 | void mb8795_device::receive() |
| 254 | { |
| 255 | fprintf(stderr, "mb8975: received packet for %02x.%02x.%02x.%02x.%02x.%02x len=%04x, mode=%d\n", |
| 256 | rxbuf[0], rxbuf[1], rxbuf[2], rxbuf[3], rxbuf[4], rxbuf[5], |
| 257 | rxlen, rxmode & 3); |
| 258 | bool keep; |
| 259 | switch(rxmode & EN_RMD_WHATRECV) { |
| 260 | case EN_RMD_RECV_NONE: |
| 261 | keep = false; |
| 262 | break; |
| 263 | case EN_RMD_RECV_NORMAL: |
| 264 | keep = recv_is_broadcast() || recv_is_me() || recv_is_local_multicast(); |
| 265 | break; |
| 266 | case EN_RMD_RECV_MULTI: |
| 267 | keep = recv_is_broadcast() || recv_is_me() || recv_is_multicast(); |
| 268 | break; |
| 269 | case EN_RMD_RECV_PROMISC: |
| 270 | keep = true; |
| 271 | break; |
| 272 | } |
| 273 | fprintf(stderr, " -> %s\n", keep ? "kept" : "dropped"); |
| 274 | if(!keep) |
| 275 | rxlen = false; |
| 276 | else { |
| 277 | rxstat |= EN_RXS_OK; |
| 278 | check_irq(); |
| 279 | timer_rx->adjust(attotime::zero); |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | bool mb8795_device::recv_is_broadcast() |
| 284 | { |
| 285 | return |
| 286 | rxbuf[0] == 0xff && |
| 287 | rxbuf[1] == 0xff && |
| 288 | rxbuf[2] == 0xff && |
| 289 | rxbuf[3] == 0xff && |
| 290 | rxbuf[4] == 0xff && |
| 291 | rxbuf[5] == 0xff; |
| 292 | } |
| 293 | |
| 294 | bool mb8795_device::recv_is_me() |
| 295 | { |
| 296 | return |
| 297 | rxbuf[0] == mac[0] && |
| 298 | rxbuf[1] == mac[1] && |
| 299 | rxbuf[2] == mac[2] && |
| 300 | rxbuf[3] == mac[3] && |
| 301 | rxbuf[4] == mac[4] && |
| 302 | ((rxmode & EN_RMD_ADDRSIZE) || rxbuf[5] == mac[5]); |
| 303 | } |
| 304 | |
| 305 | bool mb8795_device::recv_is_local_multicast() |
| 306 | { |
| 307 | return |
| 308 | (rxbuf[0] & 0x01) && |
| 309 | (rxbuf[0] & 0xfe) == mac[0] && |
| 310 | rxbuf[1] == mac[1] && |
| 311 | rxbuf[2] == mac[2]; |
| 312 | } |
| 313 | |
| 314 | bool mb8795_device::recv_is_multicast() |
| 315 | { |
| 316 | return rxbuf[0] & 0x01; |
| 317 | } |
| 318 | |
| 319 | void mb8795_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 320 | { |
| 321 | if(id == TIMER_TX) { |
| 322 | drq_tx = true; |
| 323 | if(!drq_tx_cb.isnull()) |
| 324 | drq_tx_cb(drq_tx); |
| 325 | } |
| 326 | |
| 327 | if(id == TIMER_RX && rxlen) { |
| 328 | drq_rx = true; |
| 329 | if(!drq_rx_cb.isnull()) |
| 330 | drq_rx_cb(drq_rx); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | |
src/mess/drivers/next.c
| r14142 | r14143 | |
| 19 | 19 | #define ADDRESS_MAP_MODERN |
| 20 | 20 | |
| 21 | 21 | #include "includes/next.h" |
| 22 | | #include "machine/pc_fdc.h" |
| 22 | #include "formats/pc_dsk.h" |
| 23 | #include "formats/mfi_dsk.h" |
| 23 | 24 | |
| 24 | 25 | UINT32 next_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) |
| 25 | 26 | { |
| r14142 | r14143 | |
| 141 | 142 | return 0x00012002; // TODO |
| 142 | 143 | } |
| 143 | 144 | |
| 144 | | READ32_MEMBER( next_state::irq_status_r ) |
| 145 | // Interrupt subsystem |
| 146 | // source bit level |
| 147 | // nmi 31 7 |
| 148 | // pfail 30 7 |
| 149 | // timer 29 6 |
| 150 | // enetxdma 28 6 |
| 151 | // enetrdma 27 6 |
| 152 | // scsidma 26 6 |
| 153 | // diskdma 25 6 |
| 154 | // prndma 24 6 |
| 155 | // sndoutdma 23 6 |
| 156 | // sndindma 22 6 |
| 157 | // sccdma 21 6 |
| 158 | // dspdma 20 6 |
| 159 | // m2rdma 19 6 |
| 160 | // r2mdma 18 6 |
| 161 | // scc 17 5 |
| 162 | // remote 16 5 |
| 163 | // bus 15 5 |
| 164 | // dsp4 14 4 |
| 165 | // disk 13 3 |
| 166 | // scsi 12 3 |
| 167 | // printer 11 3 |
| 168 | // enetx 10 3 |
| 169 | // enetr 9 3 |
| 170 | // soundovr 8 3 |
| 171 | // phone 7 3 -- floppy |
| 172 | // dsp3 6 3 |
| 173 | // video 5 3 |
| 174 | // monitor 4 3 |
| 175 | // kbdmouse 3 3 |
| 176 | // power 2 3 |
| 177 | // softint1 1 2 |
| 178 | // softint0 0 1 |
| 179 | |
| 180 | void next_state::irq_set(int id, bool raise) |
| 145 | 181 | { |
| 146 | | return irq_status; |
| 182 | UINT32 mask = 1U << id; |
| 183 | if(raise) |
| 184 | irq_status |= mask; |
| 185 | else |
| 186 | irq_status &= ~mask; |
| 187 | irq_check(); |
| 147 | 188 | } |
| 148 | 189 | |
| 149 | | WRITE32_MEMBER( next_state::irq_status_w ) |
| 190 | |
| 191 | READ32_MEMBER( next_state::irq_status_r ) |
| 150 | 192 | { |
| 151 | | COMBINE_DATA(&irq_status); |
| 193 | return irq_status; |
| 152 | 194 | } |
| 153 | 195 | |
| 154 | 196 | READ32_MEMBER( next_state::irq_mask_r ) |
| r14142 | r14143 | |
| 159 | 201 | WRITE32_MEMBER( next_state::irq_mask_w ) |
| 160 | 202 | { |
| 161 | 203 | COMBINE_DATA(&irq_mask); |
| 204 | irq_check(); |
| 162 | 205 | } |
| 163 | 206 | |
| 164 | | READ32_MEMBER( next_state::modisk_r) |
| 207 | void next_state::irq_check() |
| 165 | 208 | { |
| 166 | | return 0; // return 0 atm |
| 209 | UINT32 act = irq_status & irq_mask; |
| 210 | int bit; |
| 211 | for(bit=31; bit >= 0 && !(act & (1U << bit)); bit--); |
| 212 | |
| 213 | int level; |
| 214 | if (bit < 0) level = 0; |
| 215 | else if(bit < 1) level = 1; |
| 216 | else if(bit < 2) level = 2; |
| 217 | else if(bit < 14) level = 3; |
| 218 | else if(bit < 15) level = 4; |
| 219 | else if(bit < 18) level = 5; |
| 220 | else if(bit < 30) level = 6; |
| 221 | else level = 7; |
| 222 | |
| 223 | fprintf(stderr, "IRQ info %08x/%08x - %d\n", irq_status, irq_mask, level); |
| 224 | |
| 225 | if(level != irq_level) { |
| 226 | maincpu->set_input_line(irq_level, CLEAR_LINE); |
| 227 | maincpu->set_input_line_and_vector(level, ASSERT_LINE, M68K_INT_ACK_AUTOVECTOR); |
| 228 | irq_level = level; |
| 229 | } |
| 167 | 230 | } |
| 168 | 231 | |
| 232 | const char *next_state::dma_targets[0x20] = { |
| 233 | 0, "scsi", 0, 0, "soundout", "disk", 0, 0, |
| 234 | "soundin", "printer", 0, 0, "scc", "dsp", 0, 0, |
| 235 | "s-enetx", "enetx", 0, 0, "s-enetr", "enetr", 0, 0, |
| 236 | "video", 0, 0, 0, "r2m", "m2r", 0, 0 |
| 237 | }; |
| 238 | |
| 239 | const int next_state::dma_irqs[0x20] = { |
| 240 | -1, 26, -1, -1, 23, 25, -1, -1, 22, 24, -1, -1, 21, 20, -1, -1, |
| 241 | -1, 28, -1, -1, -1, 27, -1, -1, -2, -1, -1, -1, 18, 19, -1, -1 |
| 242 | }; |
| 243 | |
| 244 | const char *next_state::dma_name(int slot) |
| 245 | { |
| 246 | static char buf[32]; |
| 247 | if(dma_targets[slot]) |
| 248 | return dma_targets[slot]; |
| 249 | sprintf(buf, "<%02x>", slot); |
| 250 | return buf; |
| 251 | } |
| 252 | |
| 253 | void next_state::dma_drq_w(int slot, bool state) |
| 254 | { |
| 255 | // fprintf(stderr, "DMA drq_w %d, %d\n", slot, state); |
| 256 | dma_slot &ds = dma_slots[slot]; |
| 257 | ds.drq = state; |
| 258 | if(state && (ds.state & DMA_ENABLE)) { |
| 259 | address_space *space = maincpu->memory().space(AS_PROGRAM); |
| 260 | if(ds.state & DMA_READ) { |
| 261 | while(ds.drq) { |
| 262 | UINT8 val; |
| 263 | bool eof; |
| 264 | bool err; |
| 265 | dma_read(slot, val, eof, err); |
| 266 | if(err) { |
| 267 | ds.state = (ds.state & ~DMA_ENABLE) | DMA_BUSEXC; |
| 268 | fprintf(stderr, "DMA: bus error on read slot %d\n", slot); |
| 269 | return; |
| 270 | } |
| 271 | if(0) |
| 272 | fprintf(stderr, "DMA [%08x] = %02x\n", ds.current, val); |
| 273 | space->write_byte(ds.current++, val); |
| 274 | dma_check_end(slot, eof); |
| 275 | if(!(ds.state & DMA_ENABLE)) |
| 276 | return; |
| 277 | } |
| 278 | } else { |
| 279 | while(ds.drq) { |
| 280 | UINT8 val = space->read_byte(ds.current++); |
| 281 | bool eof = ds.current == (ds.limit & 0x7fffffff) && (ds.limit & 0x80000000); |
| 282 | bool err; |
| 283 | dma_write(slot, val, eof, err); |
| 284 | if(err) { |
| 285 | ds.state = (ds.state & ~DMA_ENABLE) | DMA_BUSEXC; |
| 286 | fprintf(stderr, "DMA: bus error on write slot %d\n", slot); |
| 287 | return; |
| 288 | } |
| 289 | dma_check_end(slot, false); |
| 290 | if(!(ds.state & DMA_ENABLE)) |
| 291 | return; |
| 292 | } |
| 293 | } |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | void next_state::dma_read(int slot, UINT8 &val, bool &eof, bool &err) |
| 298 | { |
| 299 | err = false; |
| 300 | eof = false; |
| 301 | switch(slot) { |
| 302 | case 1: |
| 303 | val = fdc->dma_r(); |
| 304 | break; |
| 305 | |
| 306 | case 5: |
| 307 | val = mo->dma_r(); |
| 308 | break; |
| 309 | |
| 310 | case 21: |
| 311 | net->rx_dma_r(val, eof); |
| 312 | break; |
| 313 | |
| 314 | default: |
| 315 | err = true; |
| 316 | val = 0; |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | void next_state::dma_write(int slot, UINT8 data, bool eof, bool &err) |
| 322 | { |
| 323 | err = false; |
| 324 | switch(slot) { |
| 325 | case 4: |
| 326 | break; |
| 327 | |
| 328 | case 5: |
| 329 | mo->dma_w(data); |
| 330 | break; |
| 331 | |
| 332 | case 17: |
| 333 | net->tx_dma_w(data, eof); |
| 334 | break; |
| 335 | |
| 336 | default: |
| 337 | err = true; |
| 338 | break; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | void next_state::dma_end(int slot) |
| 343 | { |
| 344 | dma_slot &ds = dma_slots[slot]; |
| 345 | if(ds.supdate) { |
| 346 | dma_slot &ds1 = dma_slots[(slot-1) & 31]; |
| 347 | ds1.start = ds.start; |
| 348 | ds1.limit = ds.current; |
| 349 | ds.start = ds.chain_start; |
| 350 | ds.limit = ds.chain_limit; |
| 351 | ds.current = ds.start; |
| 352 | ds.supdate = false; |
| 353 | } else |
| 354 | ds.state &= ~DMA_ENABLE; |
| 355 | ds.state |= DMA_COMPLETE; |
| 356 | if(dma_irqs[slot] >= 0) |
| 357 | irq_set(dma_irqs[slot], true); |
| 358 | } |
| 359 | |
| 360 | void next_state::dma_check_end(int slot, bool eof) |
| 361 | { |
| 362 | dma_slot &ds = dma_slots[slot]; |
| 363 | if(eof || ds.current == (ds.limit & 0x7fffffff)) |
| 364 | dma_end(slot); |
| 365 | } |
| 366 | |
| 367 | READ32_MEMBER( next_state::dma_regs_r) |
| 368 | { |
| 369 | int slot = offset >> 2; |
| 370 | int reg = offset & 3; |
| 371 | |
| 372 | const char *name = dma_name(slot); |
| 373 | |
| 374 | fprintf(stderr, "dma_regs_r %s:%d (%08x)\n", name, reg, cpu_get_pc(&space.device())); |
| 375 | switch(reg) { |
| 376 | case 0: |
| 377 | return dma_slots[slot].start; |
| 378 | case 1: |
| 379 | return dma_slots[slot].limit; |
| 380 | case 2: |
| 381 | return dma_slots[slot].chain_start; |
| 382 | case 3: default: |
| 383 | return dma_slots[slot].chain_limit; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | WRITE32_MEMBER( next_state::dma_regs_w) |
| 388 | { |
| 389 | int slot = offset >> 2; |
| 390 | int reg = offset & 3; |
| 391 | |
| 392 | const char *name = dma_name(slot); |
| 393 | |
| 394 | fprintf(stderr, "dma_regs_w %s:%d %08x (%08x)\n", name, reg, data, cpu_get_pc(&space.device())); |
| 395 | switch(reg) { |
| 396 | case 0: |
| 397 | dma_slots[slot].start = data; |
| 398 | dma_slots[slot].current = data; |
| 399 | break; |
| 400 | case 1: |
| 401 | dma_slots[slot].limit = data; |
| 402 | break; |
| 403 | case 2: |
| 404 | dma_slots[slot].chain_start = data; |
| 405 | break; |
| 406 | case 3: |
| 407 | dma_slots[slot].chain_limit = data; |
| 408 | break; |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | READ32_MEMBER( next_state::dma_ctrl_r) |
| 413 | { |
| 414 | int slot = offset >> 2; |
| 415 | int reg = offset & 3; |
| 416 | |
| 417 | const char *name = dma_name(slot); |
| 418 | |
| 419 | fprintf(stderr, "dma_ctrl_r %s:%d %02x (%08x)\n", name, reg, dma_slots[slot].state, cpu_get_pc(&space.device())); |
| 420 | |
| 421 | return reg ? 0 : dma_slots[slot].state << 24; |
| 422 | } |
| 423 | |
| 424 | WRITE32_MEMBER( next_state::dma_ctrl_w) |
| 425 | { |
| 426 | int slot = offset >> 2; |
| 427 | int reg = offset & 3; |
| 428 | const char *name = dma_name(slot); |
| 429 | fprintf(stderr, "dma_ctrl_w %s:%d %08x @ %08x (%08x)\n", name, reg, data, mem_mask, cpu_get_pc(&space.device())); |
| 430 | if(!reg) { |
| 431 | if(ACCESSING_BITS_16_23) |
| 432 | dma_do_ctrl_w(slot, data >> 16); |
| 433 | else if(ACCESSING_BITS_24_31) |
| 434 | dma_do_ctrl_w(slot, data >> 24); |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | WRITE32_MEMBER( next_state::dma_040_ctrl_w) |
| 439 | { |
| 440 | int slot = offset >> 2; |
| 441 | int reg = offset & 3; |
| 442 | if(!reg && ACCESSING_BITS_16_23) |
| 443 | dma_do_ctrl_w(slot, data >> 16); |
| 444 | } |
| 445 | |
| 446 | void next_state::dma_do_ctrl_w(int slot, UINT8 data) |
| 447 | { |
| 448 | const char *name = dma_name(slot); |
| 449 | #if 0 |
| 450 | fprintf(stderr, "dma_ctrl_w %s %02x (%08x)\n", name, data, cpu_get_pc(maincpu)); |
| 451 | |
| 452 | fprintf(stderr, " ->%s%s%s%s%s%s%s\n", |
| 453 | data & DMA_SETENABLE ? " enable" : "", |
| 454 | data & DMA_SETSUPDATE ? " supdate" : "", |
| 455 | data & DMA_SETREAD ? " read" : "", |
| 456 | data & DMA_CLRCOMPLETE ? " complete" : "", |
| 457 | data & DMA_RESET ? " reset" : "", |
| 458 | data & DMA_INITBUF ? " initbuf" : "", |
| 459 | data & DMA_INITBUFTURBO ? " initbufturbo" : ""); |
| 460 | #endif |
| 461 | if(data & DMA_SETENABLE) |
| 462 | fprintf(stderr, "dma enable %s %s %08x (%08x)\n", name, data & DMA_SETREAD ? "read" : "write", (dma_slots[slot].limit-dma_slots[slot].start) & 0x7fffffff, cpu_get_pc(maincpu)); |
| 463 | |
| 464 | dma_slot &ds = dma_slots[slot]; |
| 465 | if(data & (DMA_RESET|DMA_INITBUF|DMA_INITBUFTURBO)) { |
| 466 | ds.state = 0; |
| 467 | if(dma_irqs[slot] >= 0) |
| 468 | irq_set(dma_irqs[slot], false); |
| 469 | } |
| 470 | if(data & DMA_SETSUPDATE) { |
| 471 | ds.state |= DMA_SUPDATE; |
| 472 | ds.supdate = true; |
| 473 | } |
| 474 | if(data & DMA_SETREAD) |
| 475 | ds.state |= DMA_READ; |
| 476 | if(data & DMA_CLRCOMPLETE) { |
| 477 | ds.state &= ~DMA_COMPLETE; |
| 478 | if(dma_irqs[slot] >= 0) |
| 479 | irq_set(dma_irqs[slot], false); |
| 480 | } |
| 481 | if(data & DMA_SETENABLE) { |
| 482 | ds.state |= DMA_ENABLE; |
| 483 | // fprintf(stderr, "dma slot %d drq=%s\n", slot, ds.drq ? "on" : "off"); |
| 484 | if(ds.drq) |
| 485 | dma_drq_w(slot, ds.drq); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | const int next_state::scsi_clocks[4] = { 10000000, 12000000, 20000000, 16000000 }; |
| 490 | |
| 491 | READ32_MEMBER( next_state::scsictrl_r ) |
| 492 | { |
| 493 | fprintf(stderr, "read %08x\n", cpu_get_pc(&space.device())); |
| 494 | return (scsictrl << 24) | (scsistat << 16); |
| 495 | } |
| 496 | |
| 497 | WRITE32_MEMBER( next_state::scsictrl_w ) |
| 498 | { |
| 499 | if(ACCESSING_BITS_24_31) { |
| 500 | scsictrl = data >> 24; |
| 501 | if(scsictrl & 0x02) |
| 502 | scsi->reset(); |
| 503 | device_t::static_set_clock(*scsi, scsi_clocks[scsictrl >> 6]); |
| 504 | |
| 505 | fprintf(stderr, "SCSIctrl %dMHz int=%s dma=%s dmadir=%s%s%s dest=%s (%08x)\n", |
| 506 | scsi_clocks[scsictrl >> 6]/1000000, |
| 507 | scsictrl & 0x20 ? "on" : "off", |
| 508 | scsictrl & 0x10 ? "on" : "off", |
| 509 | scsictrl & 0x08 ? "read" : "write", |
| 510 | scsictrl & 0x04 ? " flush" : "", |
| 511 | scsictrl & 0x02 ? " reset" : "", |
| 512 | scsictrl & 0x01 ? "wd3392" : "ncr5390", |
| 513 | cpu_get_pc(&space.device())); |
| 514 | } |
| 515 | if(ACCESSING_BITS_16_23) { |
| 516 | scsistat = data >> 16; |
| 517 | fprintf(stderr, "SCSIstat %02x (%08x)\n", data, cpu_get_pc(&space.device())); |
| 518 | } |
| 519 | } |
| 520 | |
| 169 | 521 | READ32_MEMBER( next_state::event_counter_r) |
| 170 | 522 | { |
| 171 | 523 | // Event counters, around that time, are usually fixed-frequency counters. |
| r14142 | r14143 | |
| 173 | 525 | |
| 174 | 526 | // The nexttrb rom seems pretty convinced that it's 20 bits only. |
| 175 | 527 | |
| 176 | | return machine().time().as_ticks(1000000) & 0xfffff; |
| 528 | if(ACCESSING_BITS_24_31) |
| 529 | eventc_latch = machine().time().as_ticks(1000000) & 0xfffff; |
| 530 | return eventc_latch; |
| 177 | 531 | } |
| 178 | 532 | |
| 179 | | READ32_MEMBER( next_state::network_r) |
| 533 | READ32_MEMBER( next_state::dsp_r) |
| 180 | 534 | { |
| 181 | | return 0xffffffff; |
| 535 | return 0x7fffffff; |
| 182 | 536 | } |
| 183 | 537 | |
| 184 | | READ32_MEMBER( next_state::dsp_r) |
| 538 | WRITE32_MEMBER( next_state::fdc_control_w ) |
| 185 | 539 | { |
| 186 | | return 0xffffffff; |
| 540 | fprintf(stderr, "FDC write %02x (%08x)\n", data >> 24, cpu_get_pc(&space.device())); |
| 187 | 541 | } |
| 188 | 542 | |
| 189 | | void next_state::scc_int() |
| 543 | READ32_MEMBER( next_state::fdc_control_r ) |
| 190 | 544 | { |
| 545 | // Type of floppy present? |
| 546 | // Seems to behave identically as long as b24-25 is non-zero |
| 547 | // Zero means no floppy |
| 548 | |
| 549 | fprintf(stderr, "FDC read (%08x)\n", cpu_get_pc(&space.device())); |
| 550 | return 0 << 24; |
| 191 | 551 | } |
| 192 | 552 | |
| 193 | | void next_state::keyboard_int() |
| 553 | READ32_MEMBER( next_state::phy_r ) |
| 194 | 554 | { |
| 555 | logerror("phy_r %d %08x (%08x)\n", offset, phy[offset], cpu_get_pc(&space.device())); |
| 556 | return phy[offset] | (0 << 24); |
| 195 | 557 | } |
| 196 | 558 | |
| 559 | WRITE32_MEMBER( next_state::phy_w ) |
| 560 | { |
| 561 | COMBINE_DATA(phy+offset); |
| 562 | logerror("phy_w %d %08x (%08x)\n", offset, phy[offset], cpu_get_pc(&space.device())); |
| 563 | } |
| 564 | |
| 565 | void next_state::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) |
| 566 | { |
| 567 | irq_set(29, true); |
| 568 | } |
| 569 | |
| 570 | READ32_MEMBER( next_state::timer_data_r ) |
| 571 | { |
| 572 | if(timer_ctrl & 0x80000000) |
| 573 | timer_update(); |
| 574 | return timer_data; |
| 575 | } |
| 576 | |
| 577 | WRITE32_MEMBER( next_state::timer_data_w ) |
| 578 | { |
| 579 | if(timer_ctrl & 0x80000000) |
| 580 | timer_update(); |
| 581 | COMBINE_DATA(&timer_data); |
| 582 | timer_data &= 0xffff0000; |
| 583 | if(timer_ctrl & 0x80000000) |
| 584 | timer_start(); |
| 585 | } |
| 586 | |
| 587 | READ32_MEMBER( next_state::timer_ctrl_r ) |
| 588 | { |
| 589 | irq_set(29, false); |
| 590 | return timer_ctrl; |
| 591 | } |
| 592 | |
| 593 | WRITE32_MEMBER( next_state::timer_ctrl_w ) |
| 594 | { |
| 595 | bool oldact = timer_ctrl & 0x80000000; |
| 596 | COMBINE_DATA(&timer_ctrl); |
| 597 | bool newact = timer_ctrl & 0x80000000; |
| 598 | if(oldact != newact) { |
| 599 | if(oldact) { |
| 600 | timer_update(); |
| 601 | irq_set(29, false); |
| 602 | } else |
| 603 | timer_start(); |
| 604 | } |
| 605 | } |
| 606 | |
| 607 | void next_state::timer_update() |
| 608 | { |
| 609 | int delta = timer_vbase - (machine().time() - timer_tbase).as_ticks(1000000); |
| 610 | if(delta < 0) |
| 611 | delta = 0; |
| 612 | timer_data = delta << 16; |
| 613 | } |
| 614 | |
| 615 | void next_state::timer_start() |
| 616 | { |
| 617 | timer_tbase = machine().time(); |
| 618 | timer_vbase = timer_data >> 16; |
| 619 | timer_tm->adjust(attotime::from_usec(timer_vbase)); |
| 620 | } |
| 621 | |
| 622 | void next_state::scc_irq(int state) |
| 623 | { |
| 624 | irq_set(17, state); |
| 625 | } |
| 626 | |
| 627 | void next_state::keyboard_irq(bool state) |
| 628 | { |
| 629 | irq_set(3, state); |
| 630 | } |
| 631 | |
| 632 | void next_state::fdc_irq(bool state) |
| 633 | { |
| 634 | irq_set(7, state); |
| 635 | } |
| 636 | |
| 637 | void next_state::fdc_drq(bool state) |
| 638 | { |
| 639 | dma_drq_w(1, state); |
| 640 | } |
| 641 | |
| 642 | void next_state::net_tx_irq(bool state) |
| 643 | { |
| 644 | irq_set(10, state); |
| 645 | } |
| 646 | |
| 647 | void next_state::net_rx_irq(bool state) |
| 648 | { |
| 649 | irq_set(9, state); |
| 650 | } |
| 651 | |
| 652 | void next_state::net_tx_drq(bool state) |
| 653 | { |
| 654 | dma_drq_w(17, state); |
| 655 | } |
| 656 | |
| 657 | void next_state::net_rx_drq(bool state) |
| 658 | { |
| 659 | dma_drq_w(21, state); |
| 660 | } |
| 661 | |
| 662 | void next_state::mo_irq(bool state) |
| 663 | { |
| 664 | irq_set(13, state); |
| 665 | } |
| 666 | |
| 667 | void next_state::mo_drq(bool state) |
| 668 | { |
| 669 | dma_drq_w(5, state); |
| 670 | } |
| 671 | |
| 672 | void next_state::scsi_irq(bool state) |
| 673 | { |
| 674 | irq_set(12, state); |
| 675 | } |
| 676 | |
| 677 | void next_state::scsi_drq(bool state) |
| 678 | { |
| 679 | dma_drq_w(26, state); |
| 680 | } |
| 681 | |
| 197 | 682 | void next_state::machine_start() |
| 198 | 683 | { |
| 199 | 684 | save_item(NAME(scr2)); |
| 200 | 685 | save_item(NAME(irq_status)); |
| 201 | 686 | save_item(NAME(irq_mask)); |
| 687 | save_item(NAME(irq_level)); |
| 688 | save_item(NAME(phy)); |
| 689 | save_item(NAME(scsictrl)); |
| 690 | save_item(NAME(timer_tbase)); |
| 691 | save_item(NAME(timer_vbase)); |
| 692 | save_item(NAME(timer_data)); |
| 693 | save_item(NAME(timer_ctrl)); |
| 694 | save_item(NAME(eventc_latch)); |
| 695 | |
| 696 | timer_tm = timer_alloc(0); |
| 697 | |
| 698 | if(fdc) { |
| 699 | fdc->setup_intrq_cb(n82077aa_device::line_cb(FUNC(next_state::fdc_irq), this)); |
| 700 | fdc->setup_drq_cb(n82077aa_device::line_cb(FUNC(next_state::fdc_drq), this)); |
| 701 | } |
| 202 | 702 | } |
| 203 | 703 | |
| 204 | 704 | void next_state::machine_reset() |
| r14142 | r14143 | |
| 206 | 706 | scr2 = 0; |
| 207 | 707 | irq_status = 0; |
| 208 | 708 | irq_mask = 0; |
| 709 | irq_level = 0; |
| 710 | esp = 0; |
| 711 | scsictrl = 0; |
| 712 | phy[0] = phy[1] = 0; |
| 713 | eventc_latch = 0; |
| 714 | timer_vbase = 0; |
| 715 | timer_data = 0; |
| 716 | timer_ctrl = 0; |
| 717 | dma_drq_w(4, true); // soundout |
| 209 | 718 | } |
| 210 | 719 | |
| 211 | 720 | static ADDRESS_MAP_START( next_mem, AS_PROGRAM, 32, next_state ) |
| 212 | 721 | AM_RANGE(0x00000000, 0x0001ffff) AM_ROM AM_REGION("user1", 0) |
| 213 | 722 | AM_RANGE(0x01000000, 0x0101ffff) AM_ROM AM_REGION("user1", 0) |
| 214 | | // AM_RANGE(0x02000010, 0x02000010) AM_MIRROR(0x300000) SCSI DMA CSR |
| 215 | | // AM_RANGE(0x02000040, 0x02000040) AM_MIRROR(0x300000) SOUNDOUT DMA CSR |
| 216 | | // AM_RANGE(0x02000050, 0x02000050) AM_MIRROR(0x300000) DISK DMA CSR |
| 217 | | // AM_RANGE(0x02000080, 0x02000080) AM_MIRROR(0x300000) SOUNDIN DMA CSR |
| 218 | | // AM_RANGE(0x02000090, 0x02000090) AM_MIRROR(0x300000) PRINTER DMA CSR |
| 219 | | // AM_RANGE(0x020000c0, 0x020000c0) AM_MIRROR(0x300000) SCC DMA CSR |
| 220 | | // AM_RANGE(0x020000d0, 0x020000d0) AM_MIRROR(0x300000) DSP DMA CSR |
| 221 | | // AM_RANGE(0x02000110, 0x02000110) AM_MIRROR(0x300000) ENETX DMA CSR |
| 222 | | // AM_RANGE(0x02000150, 0x02000150) AM_MIRROR(0x300000) ENETR DMA CSR |
| 223 | | // AM_RANGE(0x02000180, 0x02000180) AM_MIRROR(0x300000) VIDEO DMA CSR |
| 224 | | // AM_RANGE(0x020001c0, 0x020001c0) AM_MIRROR(0x300000) R2M DMA CSR |
| 225 | | // AM_RANGE(0x020001d0, 0x020001d0) AM_MIRROR(0x300000) M2R DMA CSR |
| 226 | | AM_RANGE(0x02006000, 0x02006003) AM_MIRROR(0x300000) AM_READ(network_r) // ethernet |
| 723 | AM_RANGE(0x02000000, 0x020001ff) AM_MIRROR(0x300200) AM_READWRITE(dma_ctrl_r, dma_ctrl_w) |
| 724 | AM_RANGE(0x02004000, 0x020041ff) AM_MIRROR(0x300200) AM_READWRITE(dma_regs_r, dma_regs_w) |
| 725 | AM_RANGE(0x02006000, 0x0200600f) AM_MIRROR(0x300000) AM_DEVICE8("net", mb8795_device, map, 0xffffffff) |
| 227 | 726 | // AM_RANGE(0x02006010, 0x02006013) AM_MIRROR(0x300000) memory timing |
| 228 | | AM_RANGE(0x02007000, 0x02007003) AM_MIRROR(0x300000) AM_READWRITE(irq_status_r,irq_status_w) |
| 727 | AM_RANGE(0x02007000, 0x02007003) AM_MIRROR(0x300000) AM_READ(irq_status_r) |
| 229 | 728 | AM_RANGE(0x02007800, 0x02007803) AM_MIRROR(0x300000) AM_READWRITE(irq_mask_r,irq_mask_w) |
| 230 | 729 | AM_RANGE(0x02008000, 0x02008003) AM_MIRROR(0x300000) AM_READ(dsp_r) |
| 231 | 730 | AM_RANGE(0x0200c000, 0x0200c003) AM_MIRROR(0x300000) AM_READ(scr1_r) |
| r14142 | r14143 | |
| 235 | 734 | AM_RANGE(0x0200e000, 0x0200e00b) AM_MIRROR(0x300000) AM_DEVICE("keyboard", nextkbd_device, amap) |
| 236 | 735 | // AM_RANGE(0x0200f000, 0x0200f003) AM_MIRROR(0x300000) printer |
| 237 | 736 | // AM_RANGE(0x02010000, 0x02010003) AM_MIRROR(0x300000) brightness |
| 238 | | AM_RANGE(0x02012004, 0x02012007) AM_MIRROR(0x300000) AM_READ(modisk_r) |
| 239 | | // AM_RANGE(0x02014000, 0x02014003) AM_MIRROR(0x300000) SCSI |
| 240 | | AM_RANGE(0x02014100, 0x02014107) AM_MIRROR(0x300000) AM_DEVICE8("fdc", n82077aa_device, amap, 0xffffffff) |
| 241 | | // AM_RANGE(0x02016000, 0x02016003) AM_MIRROR(0x300000) timer |
| 242 | | // AM_RANGE(0x02016004, 0x02016007) AM_MIRROR(0x300000) timer CSR |
| 243 | | AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", am8530h_device, ca_r, ca_w, 0xff000000) |
| 244 | | AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", am8530h_device, cb_r, cb_w, 0x00ff0000) |
| 245 | | AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", am8530h_device, da_r, da_w, 0x0000ff00) |
| 246 | | AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", am8530h_device, db_r, db_w, 0x000000ff) |
| 737 | AM_RANGE(0x02012000, 0x0201201f) AM_MIRROR(0x300000) AM_DEVICE8("mo", nextmo_device, map, 0xffffffff) |
| 738 | AM_RANGE(0x02014000, 0x0201400f) AM_MIRROR(0x300000) AM_DEVICE8("scsi", ncr5390_device, map, 0xffffffff) |
| 739 | AM_RANGE(0x02114020, 0x02114023) AM_MIRROR(0x300000) AM_READWRITE(scsictrl_r, scsictrl_w) |
| 740 | AM_RANGE(0x02016000, 0x02016003) AM_MIRROR(0x300000) AM_READWRITE(timer_data_r, timer_data_w) |
| 741 | AM_RANGE(0x02016004, 0x02016007) AM_MIRROR(0x300000) AM_READWRITE(timer_ctrl_r, timer_ctrl_w) |
| 742 | AM_RANGE(0x02018000, 0x02018003) AM_MIRROR(0x300000) AM_DEVREADWRITE8("scc", scc8530_t, reg_r, reg_w, 0xffffffff) |
| 247 | 743 | // AM_RANGE(0x02018004, 0x02018007) AM_MIRROR(0x300000) SCC CLK |
| 248 | 744 | // AM_RANGE(0x02018100, 0x02018103) AM_MIRROR(0x300000) Color RAMDAC |
| 249 | 745 | // AM_RANGE(0x02018104, 0x02018107) AM_MIRROR(0x300000) Color CSR |
| r14142 | r14143 | |
| 251 | 747 | // AM_RANGE(0x02018198, 0x0201819f) AM_MIRROR(0x300000) warp 9c VRAM timing |
| 252 | 748 | AM_RANGE(0x0201a000, 0x0201a003) AM_MIRROR(0x300000) AM_READ(event_counter_r) // EVENTC |
| 253 | 749 | // AM_RANGE(0x020c0000, 0x020c0004) AM_MIRROR(0x300000) BMAP |
| 750 | AM_RANGE(0x020c0030, 0x020c0037) AM_MIRROR(0x300000) AM_READWRITE(phy_r, phy_w) |
| 254 | 751 | // AM_RANGE(0x02000000, 0x0201ffff) AM_MIRROR(0x300000) AM_READWRITE8(io_r,io_w,0xffffffff) //intentional fall-through |
| 255 | 752 | AM_RANGE(0x04000000, 0x07ffffff) AM_RAM //work ram |
| 256 | 753 | AM_RANGE(0x0b000000, 0x0b03ffff) AM_RAM AM_BASE(vram) //vram |
| r14142 | r14143 | |
| 265 | 762 | // AM_RANGE(0x2c000000, 0x2c1fffff) Color VRAM |
| 266 | 763 | ADDRESS_MAP_END |
| 267 | 764 | |
| 765 | static ADDRESS_MAP_START( next_040_mem, AS_PROGRAM, 32, next_state ) |
| 766 | AM_RANGE(0x02000000, 0x020001ff) AM_MIRROR(0x300000) AM_READWRITE(dma_ctrl_r, dma_040_ctrl_w) |
| 767 | AM_RANGE(0x02014100, 0x02014107) AM_MIRROR(0x300000) AM_DEVICE8("fdc", n82077aa_device, amap, 0xffffffff) |
| 768 | AM_RANGE(0x02014108, 0x0201410b) AM_MIRROR(0x300000) AM_READWRITE(fdc_control_r, fdc_control_w) |
| 769 | |
| 770 | AM_IMPORT_FROM(next_mem) |
| 771 | ADDRESS_MAP_END |
| 772 | |
| 268 | 773 | /* Input ports */ |
| 269 | 774 | static INPUT_PORTS_START( next ) |
| 270 | 775 | INPUT_PORTS_END |
| r14142 | r14143 | |
| 278 | 783 | palette_set_color(machine, 3,MAKE_RGB(0xff,0xff,0xff)); |
| 279 | 784 | } |
| 280 | 785 | |
| 281 | | static MCCS1850_INTERFACE( rtc_intf ) |
| 282 | | { |
| 283 | | DEVCB_NULL, // RTCINT |
| 284 | | DEVCB_NULL, |
| 285 | | DEVCB_NULL |
| 786 | const floppy_format_type next_state::floppy_formats[] = { |
| 787 | FLOPPY_PC_FORMAT, |
| 788 | FLOPPY_MFI_FORMAT, |
| 789 | NULL |
| 286 | 790 | }; |
| 287 | 791 | |
| 288 | | static const floppy_interface next_floppy_interface = |
| 289 | | { |
| 290 | | DEVCB_NULL, |
| 291 | | DEVCB_NULL, |
| 292 | | DEVCB_NULL, |
| 293 | | DEVCB_NULL, |
| 294 | | DEVCB_NULL, |
| 295 | | FLOPPY_STANDARD_3_5_DSED, |
| 296 | | LEGACY_FLOPPY_OPTIONS_NAME(default), |
| 297 | | "floppy_3_5", |
| 298 | | NULL |
| 792 | static SLOT_INTERFACE_START( next_floppies ) |
| 793 | SLOT_INTERFACE( "35hd", FLOPPY_35_HD ) |
| 794 | SLOT_INTERFACE_END |
| 795 | |
| 796 | const SCSIConfigTable next_state::scsi_devices = { |
| 797 | 2, |
| 798 | { |
| 799 | { SCSI_ID_0, "harddisk0", SCSI_DEVICE_HARDDISK }, |
| 800 | { SCSI_ID_1, "cdrom", SCSI_DEVICE_CDROM } |
| 801 | } |
| 299 | 802 | }; |
| 300 | 803 | |
| 804 | const cdrom_interface next_state::cdrom_intf = { NULL, NULL }; |
| 805 | const harddisk_interface next_state::harddisk_intf = { NULL, NULL, "next_hdd", NULL }; |
| 806 | |
| 301 | 807 | static MACHINE_CONFIG_START( next, next_state ) |
| 302 | 808 | /* basic machine hardware */ |
| 303 | 809 | MCFG_CPU_ADD("maincpu",M68030, XTAL_25MHz) |
| r14142 | r14143 | |
| 315 | 821 | MCFG_PALETTE_INIT(next) |
| 316 | 822 | |
| 317 | 823 | // devices |
| 318 | | MCFG_MCCS1850_ADD("rtc", XTAL_32_768kHz, rtc_intf) |
| 319 | | MCFG_LEGACY_FLOPPY_DRIVE_ADD(FLOPPY_0, next_floppy_interface) |
| 320 | | MCFG_AM8530H_ADD("scc", am8530h_device::int_cb_t(FUNC(next_state::scc_int), static_cast<next_state *>(owner))) |
| 321 | | MCFG_NEXTKBD_ADD("keyboard", nextkbd_device::int_cb_t(FUNC(next_state::keyboard_int), static_cast<next_state *>(owner))) |
| 322 | | MCFG_N82077AA_ADD("fdc", n82077aa_device::MODE_PS2) |
| 824 | MCFG_MCCS1850_ADD("rtc", XTAL_32_768kHz, |
| 825 | mccs1850_device::cb_t(), mccs1850_device::cb_t(), mccs1850_device::cb_t()) |
| 826 | MCFG_SCC8530_ADD("scc", XTAL_25MHz, scc8530_t::intrq_cb_t(FUNC(next_state::scc_irq), static_cast<next_state *>(owner))) |
| 827 | MCFG_NEXTKBD_ADD("keyboard", nextkbd_device::int_cb_t(FUNC(next_state::keyboard_irq), static_cast<next_state *>(owner))) |
| 828 | MCFG_NCR5390_ADD("scsi", 10000000, |
| 829 | line_cb_t(FUNC(next_state::scsi_irq), static_cast<next_state *>(owner)), |
| 830 | line_cb_t(FUNC(next_state::scsi_drq), static_cast<next_state *>(owner)), |
| 831 | next_state::scsi_devices) |
| 832 | MCFG_MB8795_ADD("net", |
| 833 | line_cb_t(FUNC(next_state::net_tx_irq), static_cast<next_state *>(owner)), |
| 834 | line_cb_t(FUNC(next_state::net_rx_irq), static_cast<next_state *>(owner)), |
| 835 | line_cb_t(FUNC(next_state::net_tx_drq), static_cast<next_state *>(owner)), |
| 836 | line_cb_t(FUNC(next_state::net_rx_drq), static_cast<next_state *>(owner))) |
| 837 | MCFG_NEXTMO_ADD("mo", |
| 838 | nextmo_device::cb_t(FUNC(next_state::mo_irq), static_cast<next_state *>(owner)), |
| 839 | nextmo_device::cb_t(FUNC(next_state::mo_drq), static_cast<next_state *>(owner))) |
| 323 | 840 | |
| 841 | MCFG_CDROM_ADD("cdrom", next_state::cdrom_intf) |
| 842 | MCFG_HARDDISK_CONFIG_ADD("harddisk0", next_state::harddisk_intf) |
| 843 | |
| 324 | 844 | // software list |
| 325 | 845 | MCFG_SOFTWARE_LIST_ADD("flop_list", "next") |
| 326 | 846 | MACHINE_CONFIG_END |
| 327 | 847 | |
| 328 | 848 | static MACHINE_CONFIG_DERIVED( next040, next ) |
| 329 | | MCFG_CPU_REPLACE("maincpu", M68040, XTAL_33MHz) |
| 330 | | MCFG_CPU_PROGRAM_MAP(next_mem) |
| 849 | MCFG_CPU_REPLACE("maincpu", M68040, XTAL_25MHz) |
| 850 | MCFG_CPU_PROGRAM_MAP(next_040_mem) |
| 851 | |
| 852 | MCFG_N82077AA_ADD("fdc", n82077aa_device::MODE_PS2) |
| 853 | MCFG_FLOPPY_DRIVE_ADD("fd0", next_floppies, "35hd", 0, next_state::floppy_formats) |
| 331 | 854 | MACHINE_CONFIG_END |
| 332 | 855 | |
| 333 | 856 | /* ROM definition */ |
| r14142 | r14143 | |
| 341 | 864 | ROMX_LOAD( "rev_1.0_proto.bin", 0x0000, 0x10000, CRC(F44974F9) SHA1(09EAF9F5D47E379CFA0E4DC377758A97D2869DDC), ROM_BIOS(3)) /* Label: "(C) 1989 NeXT, Inc. // All Rights Reserved. // Release 1.0 // 1142.00", no underlabel */ |
| 342 | 865 | |
| 343 | 866 | ROM_REGION( 0x20, "rtc", 0 ) |
| 344 | | ROM_LOAD( "nvram.bin", 0x00, 0x20, BAD_DUMP CRC(7cb74196) SHA1(faa2177c2a08a6b76a6242761a9c0a8b64c4da6e) ) |
| 867 | ROM_LOAD( "nvram.bin", 0x00, 0x20, CRC(52162469) SHA1(f49888af63d2d2658db4f41b3345cae153f42884) ) |
| 345 | 868 | ROM_END |
| 346 | 869 | |
| 347 | 870 | ROM_START( nextnt ) // 68040 non-turbo |
| r14142 | r14143 | |
| 374 | 897 | ROM_LOAD( "nvram-trb.bin", 0x00, 0x20, CRC(2516dd08) SHA1(b20afe82efee5b625fb8afda14a1d14aabc8e07e) ) |
| 375 | 898 | ROM_END |
| 376 | 899 | |
| 900 | static DRIVER_INIT(nexttrb) |
| 901 | { |
| 902 | UINT32 *rom = (UINT32 *)(machine.region("user1")->base()); |
| 903 | rom[0x329c/4] = 0x70004e71; // memory test funcall |
| 904 | rom[0x32a0/4] = 0x4e712400; |
| 905 | rom[0x03f8/4] = 0x001a4e71; // rom checksum |
| 906 | rom[0x03fc/4] = 0x4e714e71; |
| 907 | } |
| 908 | |
| 909 | static DRIVER_INIT(next) |
| 910 | { |
| 911 | UINT32 *rom = (UINT32 *)(machine.region("user1")->base()); |
| 912 | rom[0x3f48/4] = 0x2f017000; // memory test funcall |
| 913 | rom[0x3f4c/4] = 0x4e712400; |
| 914 | rom[0x00b8/4] = 0x001a4e71; // rom checksum |
| 915 | rom[0x00bc/4] = 0x4e714e71; |
| 916 | } |
| 917 | |
| 377 | 918 | /* Driver */ |
| 378 | 919 | |
| 379 | 920 | /* YEAR NAME PARENT COMPAT MACHINE INPUT INIT COMPANY FULLNAME FLAGS */ |
| 380 | | COMP( 1987, next, 0, 0, next, next, 0, "Next Software Inc", "NeXT Computer", GAME_NOT_WORKING | GAME_NO_SOUND) |
| 921 | COMP( 1987, next, 0, 0, next, next, next, "Next Software Inc", "NeXT Computer", GAME_NOT_WORKING | GAME_NO_SOUND) |
| 381 | 922 | COMP( 1990, nextnt, next, 0, next040, next, 0, "Next Software Inc", "NeXT (Non Turbo)", GAME_NOT_WORKING | GAME_NO_SOUND) |
| 382 | | COMP( 1992, nexttrb,next, 0, next040, next, 0, "Next Software Inc", "NeXT (Turbo)", GAME_NOT_WORKING | GAME_NO_SOUND) |
| 923 | COMP( 1992, nexttrb,next, 0, next040, next, nexttrb, "Next Software Inc", "NeXT (Turbo)", GAME_NOT_WORKING | GAME_NO_SOUND) |