src/mess/machine/990_tap.c
| r6748 | r6749 | |
| 33 | 33 | #include "990_tap.h" |
| 34 | 34 | #include "image.h" |
| 35 | 35 | |
| 36 | | static void update_interrupt(running_machine *machine); |
| 36 | static void update_interrupt(const device_config *device); |
| 37 | 37 | |
| 38 | 38 | #define MAX_TAPE_UNIT 4 |
| 39 | 39 | |
| r6748 | r6749 | |
| 45 | 45 | unsigned int wp : 1; /* TRUE if tape is write-protected */ |
| 46 | 46 | } tape_unit_t; |
| 47 | 47 | |
| 48 | | typedef struct tpc_t |
| 48 | typedef struct _tap_990_t tap_990_t; |
| 49 | struct _tap_990_t |
| 49 | 50 | { |
| 50 | 51 | UINT16 w[8]; |
| 51 | 52 | |
| 52 | | void (*interrupt_callback)(running_machine *machine, int state); |
| 53 | | |
| 53 | const ti990_tpc_interface *intf; |
| 54 | |
| 54 | 55 | tape_unit_t t[MAX_TAPE_UNIT]; |
| 55 | | } tpc_t; |
| 56 | }; |
| 56 | 57 | |
| 58 | typedef struct _ti990_tape_t ti990_tape_t; |
| 59 | struct _ti990_tape_t |
| 60 | { |
| 61 | int dummy; |
| 62 | }; |
| 63 | |
| 57 | 64 | enum |
| 58 | 65 | { |
| 59 | 66 | w0_offline = 0x8000, |
| r6748 | r6749 | |
| 103 | 110 | 0xf3ff /* Don't overwrite reserved bits */ |
| 104 | 111 | }; |
| 105 | 112 | |
| 106 | | static tpc_t tpc; |
| 113 | int tape_get_id(const device_config *image) |
| 114 | { |
| 115 | int drive =0; |
| 116 | if (strcmp(image->tag, "tape0") == 0) drive = 0; |
| 117 | if (strcmp(image->tag, "tape1") == 0) drive = 1; |
| 118 | if (strcmp(image->tag, "tape2") == 0) drive = 2; |
| 119 | if (strcmp(image->tag, "tape3") == 0) drive = 3; |
| 120 | return drive; |
| 121 | } |
| 107 | 122 | |
| 123 | /***************************************************************************** |
| 124 | INLINE FUNCTIONS |
| 125 | *****************************************************************************/ |
| 126 | INLINE tap_990_t *get_safe_token(const device_config *device) |
| 127 | { |
| 128 | assert(device != NULL); |
| 129 | assert(device->token != NULL); |
| 108 | 130 | |
| 131 | return (tap_990_t *)device->token; |
| 132 | } |
| 133 | |
| 109 | 134 | DEVICE_START( ti990_tape ) |
| 110 | 135 | { |
| 111 | 136 | tape_unit_t *t; |
| 112 | | int id = image_index_in_device(device); |
| 113 | | |
| 114 | | assert ((id >= 0) && (id < MAX_TAPE_UNIT)); |
| 115 | | |
| 116 | | t = &tpc.t[id]; |
| 137 | tap_990_t *tpc = get_safe_token(device->owner); |
| 138 | int id = tape_get_id(device); |
| 139 | |
| 140 | t = &tpc->t[id]; |
| 117 | 141 | memset(t, 0, sizeof(*t)); |
| 118 | 142 | |
| 119 | 143 | t->img = device; |
| r6748 | r6749 | |
| 122 | 146 | t->eot = 0; |
| 123 | 147 | } |
| 124 | 148 | |
| 125 | | #ifdef UNUSED_FUNCTION |
| 126 | | DEVICE_STOP( ti990_tape ) |
| 127 | | { |
| 128 | | d->img = NULL; |
| 129 | | } |
| 130 | | #endif |
| 131 | | |
| 132 | 149 | /* |
| 133 | 150 | Open a tape image |
| 134 | 151 | */ |
| 135 | 152 | DEVICE_IMAGE_LOAD( ti990_tape ) |
| 136 | 153 | { |
| 137 | 154 | tape_unit_t *t; |
| 138 | | int id = image_index_in_device(image); |
| 139 | | |
| 140 | | |
| 141 | | if ((id < 0) || (id >= MAX_TAPE_UNIT)) |
| 142 | | return INIT_FAIL; |
| 143 | | |
| 144 | | t = &tpc.t[id]; |
| 155 | tap_990_t *tpc = get_safe_token(image->owner); |
| 156 | int id = tape_get_id(image); |
| 157 | |
| 158 | t = &tpc->t[id]; |
| 145 | 159 | memset(t, 0, sizeof(*t)); |
| 146 | 160 | |
| 147 | 161 | /* tell whether the image is writable */ |
| r6748 | r6749 | |
| 158 | 172 | DEVICE_IMAGE_UNLOAD( ti990_tape ) |
| 159 | 173 | { |
| 160 | 174 | tape_unit_t *t; |
| 161 | | int id = image_index_in_device(image); |
| 175 | tap_990_t *tpc = get_safe_token(image->owner); |
| 176 | int id = tape_get_id(image); |
| 162 | 177 | |
| 163 | | if ((id < 0) || (id >= MAX_TAPE_UNIT)) |
| 164 | | return; |
| 165 | | |
| 166 | | t = &tpc.t[id]; |
| 178 | t = &tpc->t[id]; |
| 167 | 179 | t->wp = 1; |
| 168 | 180 | t->bot = 0; |
| 169 | 181 | t->eot = 0; |
| 170 | 182 | } |
| 171 | 183 | |
| 172 | 184 | /* |
| 173 | | Init the tape controller core |
| 174 | | */ |
| 175 | | void ti990_tpc_init(running_machine *machine, void (*interrupt_callback)(running_machine *machine, int state)) |
| 176 | | { |
| 177 | | memset(tpc.w, 0, sizeof(tpc.w)); |
| 178 | | /* The PE bit is always set for the MT3200 (but not MT1600) */ |
| 179 | | /* According to MT3200 manual, w7 bit #4 (reserved) is always set */ |
| 180 | | tpc.w[7] = w7_idle /*| w7_PE_format*/ | 0x0800; |
| 181 | | |
| 182 | | tpc.interrupt_callback = interrupt_callback; |
| 183 | | |
| 184 | | update_interrupt(machine); |
| 185 | | } |
| 186 | | |
| 187 | | /* |
| 188 | 185 | Parse the tape select lines, and return the corresponding tape unit. |
| 189 | 186 | (-1 if none) |
| 190 | 187 | */ |
| 191 | | static int cur_tape_unit(void) |
| 188 | static int cur_tape_unit(const device_config *device) |
| 192 | 189 | { |
| 193 | 190 | int reply; |
| 191 | tap_990_t *tpc = get_safe_token(device); |
| 194 | 192 | |
| 195 | | |
| 196 | | if (tpc.w[6] & w6_unit0_sel) |
| 193 | if (tpc->w[6] & w6_unit0_sel) |
| 197 | 194 | reply = 0; |
| 198 | | else if (tpc.w[6] & w6_unit1_sel) |
| 195 | else if (tpc->w[6] & w6_unit1_sel) |
| 199 | 196 | reply = 1; |
| 200 | | else if (tpc.w[6] & w6_unit2_sel) |
| 197 | else if (tpc->w[6] & w6_unit2_sel) |
| 201 | 198 | reply = 2; |
| 202 | | else if (tpc.w[6] & w6_unit3_sel) |
| 199 | else if (tpc->w[6] & w6_unit3_sel) |
| 203 | 200 | reply = 3; |
| 204 | 201 | else |
| 205 | 202 | reply = -1; |
| r6748 | r6749 | |
| 213 | 210 | /* |
| 214 | 211 | Update interrupt state |
| 215 | 212 | */ |
| 216 | | static void update_interrupt(running_machine *machine) |
| 213 | static void update_interrupt(const device_config *device) |
| 217 | 214 | { |
| 218 | | if (tpc.interrupt_callback) |
| 219 | | (*tpc.interrupt_callback)(machine, (tpc.w[7] & w7_idle) |
| 220 | | && (((tpc.w[7] & w7_int_enable) && (tpc.w[7] & (w7_complete | w7_error))) |
| 221 | | || ((tpc.w[0] & ~(tpc.w[0] >> 4)) & w0_rewind_mask))); |
| 215 | tap_990_t *tpc = get_safe_token(device); |
| 216 | if (tpc->intf->interrupt_callback) |
| 217 | (*tpc->intf->interrupt_callback)(device->machine, (tpc->w[7] & w7_idle) |
| 218 | && (((tpc->w[7] & w7_int_enable) && (tpc->w[7] & (w7_complete | w7_error))) |
| 219 | || ((tpc->w[0] & ~(tpc->w[0] >> 4)) & w0_rewind_mask))); |
| 222 | 220 | } |
| 223 | 221 | |
| 224 | 222 | /* |
| 225 | 223 | Handle the read binary forward command: read the next record on tape. |
| 226 | 224 | */ |
| 227 | | static void cmd_read_binary_forward(running_machine *machine) |
| 225 | static void cmd_read_binary_forward(const device_config *device) |
| 228 | 226 | { |
| 229 | 227 | UINT8 buffer[256]; |
| 230 | 228 | int reclen; |
| r6748 | r6749 | |
| 238 | 236 | int bytes_to_read; |
| 239 | 237 | int bytes_read; |
| 240 | 238 | int i; |
| 239 | tap_990_t *tpc = get_safe_token(device); |
| 240 | int tap_sel = cur_tape_unit(device); |
| 241 | 241 | |
| 242 | | int tap_sel = cur_tape_unit(); |
| 243 | | |
| 244 | 242 | if (tap_sel == -1) |
| 245 | 243 | { |
| 246 | 244 | /* No idea what to report... */ |
| 247 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 248 | | update_interrupt(machine); |
| 245 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 246 | update_interrupt(device); |
| 249 | 247 | return; |
| 250 | 248 | } |
| 251 | | else if (! image_exists(tpc.t[tap_sel].img)) |
| 249 | else if (! image_exists(tpc->t[tap_sel].img)) |
| 252 | 250 | { /* offline */ |
| 253 | | tpc.w[0] |= w0_offline; |
| 254 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 255 | | update_interrupt(machine); |
| 251 | tpc->w[0] |= w0_offline; |
| 252 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 253 | update_interrupt(device); |
| 256 | 254 | return; |
| 257 | 255 | } |
| 258 | 256 | #if 0 |
| 259 | 257 | else if (0) |
| 260 | 258 | { /* rewind in progress */ |
| 261 | | tpc.w[0] |= 0x80 >> tap_sel; |
| 262 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 263 | | update_interrupt(machine); |
| 259 | tpc->w[0] |= 0x80 >> tap_sel; |
| 260 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 261 | update_interrupt(device); |
| 264 | 262 | return; |
| 265 | 263 | } |
| 266 | 264 | #endif |
| 267 | 265 | |
| 268 | | tpc.t[tap_sel].bot = 0; |
| 266 | tpc->t[tap_sel].bot = 0; |
| 269 | 267 | |
| 270 | | dma_address = ((((int) tpc.w[6]) << 16) | tpc.w[5]) & 0x1ffffe; |
| 271 | | char_count = tpc.w[4]; |
| 272 | | read_offset = tpc.w[3]; |
| 268 | dma_address = ((((int) tpc->w[6]) << 16) | tpc->w[5]) & 0x1ffffe; |
| 269 | char_count = tpc->w[4]; |
| 270 | read_offset = tpc->w[3]; |
| 273 | 271 | |
| 274 | | bytes_read = image_fread(tpc.t[tap_sel].img, buffer, 4); |
| 272 | bytes_read = image_fread(tpc->t[tap_sel].img, buffer, 4); |
| 275 | 273 | if (bytes_read != 4) |
| 276 | 274 | { |
| 277 | 275 | if (bytes_read == 0) |
| 278 | 276 | { /* legitimate EOF */ |
| 279 | | tpc.t[tap_sel].eot = 1; |
| 280 | | tpc.w[0] |= w0_EOT; /* or should it be w0_command_timeout? */ |
| 281 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 282 | | update_interrupt(machine); |
| 277 | tpc->t[tap_sel].eot = 1; |
| 278 | tpc->w[0] |= w0_EOT; /* or should it be w0_command_timeout? */ |
| 279 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 280 | update_interrupt(device); |
| 283 | 281 | goto update_registers; |
| 284 | 282 | } |
| 285 | 283 | else |
| r6748 | r6749 | |
| 287 | 285 | /* No idea what to report... */ |
| 288 | 286 | /* eject tape to avoid catastrophes */ |
| 289 | 287 | logerror("Tape error\n"); |
| 290 | | image_unload(tpc.t[tap_sel].img); |
| 291 | | tpc.w[0] |= w0_offline; |
| 292 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 293 | | update_interrupt(machine); |
| 288 | image_unload(tpc->t[tap_sel].img); |
| 289 | tpc->w[0] |= w0_offline; |
| 290 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 291 | update_interrupt(device); |
| 294 | 292 | goto update_registers; |
| 295 | 293 | } |
| 296 | 294 | } |
| r6748 | r6749 | |
| 300 | 298 | logerror("Tape error\n"); |
| 301 | 299 | logerror("Tape format looks gooofy\n"); |
| 302 | 300 | /* eject tape to avoid catastrophes */ |
| 303 | | image_unload(tpc.t[tap_sel].img); |
| 304 | | tpc.w[0] |= w0_offline; |
| 305 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 306 | | update_interrupt(machine); |
| 301 | image_unload(tpc->t[tap_sel].img); |
| 302 | tpc->w[0] |= w0_offline; |
| 303 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 304 | update_interrupt(device); |
| 307 | 305 | goto update_registers; |
| 308 | 306 | } |
| 309 | 307 | |
| r6748 | r6749 | |
| 311 | 309 | if (reclen == 0) |
| 312 | 310 | { |
| 313 | 311 | logerror("read binary forward: found EOF, requested %d\n", char_count); |
| 314 | | tpc.w[0] |= w0_EOF; |
| 315 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 316 | | update_interrupt(machine); |
| 312 | tpc->w[0] |= w0_EOF; |
| 313 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 314 | update_interrupt(device); |
| 317 | 315 | goto update_registers; |
| 318 | 316 | } |
| 319 | 317 | |
| r6748 | r6749 | |
| 324 | 322 | /* skip up to read_offset bytes */ |
| 325 | 323 | chunk_len = (read_offset > rec_count) ? rec_count : read_offset; |
| 326 | 324 | |
| 327 | | if (image_fseek(tpc.t[tap_sel].img, chunk_len, SEEK_CUR)) |
| 325 | if (image_fseek(tpc->t[tap_sel].img, chunk_len, SEEK_CUR)) |
| 328 | 326 | { /* eject tape */ |
| 329 | 327 | logerror("Tape error\n"); |
| 330 | | image_unload(tpc.t[tap_sel].img); |
| 331 | | tpc.w[0] |= w0_offline; |
| 332 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 333 | | update_interrupt(machine); |
| 328 | image_unload(tpc->t[tap_sel].img); |
| 329 | tpc->w[0] |= w0_offline; |
| 330 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 331 | update_interrupt(device); |
| 334 | 332 | goto update_registers; |
| 335 | 333 | } |
| 336 | 334 | |
| r6748 | r6749 | |
| 338 | 336 | read_offset -= chunk_len; |
| 339 | 337 | if (read_offset) |
| 340 | 338 | { |
| 341 | | tpc.w[0] |= w0_EOR; |
| 342 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 343 | | update_interrupt(machine); |
| 339 | tpc->w[0] |= w0_EOR; |
| 340 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 341 | update_interrupt(device); |
| 344 | 342 | goto skip_trailer; |
| 345 | 343 | } |
| 346 | 344 | |
| r6748 | r6749 | |
| 350 | 348 | for (; chunk_len>0; ) |
| 351 | 349 | { |
| 352 | 350 | bytes_to_read = (chunk_len < sizeof(buffer)) ? chunk_len : sizeof(buffer); |
| 353 | | bytes_read = image_fread(tpc.t[tap_sel].img, buffer, bytes_to_read); |
| 351 | bytes_read = image_fread(tpc->t[tap_sel].img, buffer, bytes_to_read); |
| 354 | 352 | |
| 355 | 353 | if (bytes_read & 1) |
| 356 | 354 | { |
| r6748 | r6749 | |
| 360 | 358 | /* DMA */ |
| 361 | 359 | for (i=0; i<bytes_read; i+=2) |
| 362 | 360 | { |
| 363 | | memory_write_word_16be(cputag_get_address_space(machine, "maincpu", ADDRESS_SPACE_PROGRAM),dma_address, (((int) buffer[i]) << 8) | buffer[i+1]); |
| 361 | memory_write_word_16be(cputag_get_address_space(device->machine, "maincpu", ADDRESS_SPACE_PROGRAM),dma_address, (((int) buffer[i]) << 8) | buffer[i+1]); |
| 364 | 362 | dma_address = (dma_address + 2) & 0x1ffffe; |
| 365 | 363 | } |
| 366 | 364 | |
| r6748 | r6749 | |
| 371 | 369 | if (bytes_read != bytes_to_read) |
| 372 | 370 | { /* eject tape */ |
| 373 | 371 | logerror("Tape error\n"); |
| 374 | | image_unload(tpc.t[tap_sel].img); |
| 375 | | tpc.w[0] |= w0_offline; |
| 376 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 377 | | update_interrupt(machine); |
| 372 | image_unload(tpc->t[tap_sel].img); |
| 373 | tpc->w[0] |= w0_offline; |
| 374 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 375 | update_interrupt(device); |
| 378 | 376 | goto update_registers; |
| 379 | 377 | } |
| 380 | 378 | } |
| 381 | 379 | |
| 382 | 380 | if (char_count) |
| 383 | 381 | { |
| 384 | | tpc.w[0] |= w0_EOR; |
| 385 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 386 | | update_interrupt(machine); |
| 382 | tpc->w[0] |= w0_EOR; |
| 383 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 384 | update_interrupt(device); |
| 387 | 385 | goto skip_trailer; |
| 388 | 386 | } |
| 389 | 387 | |
| 390 | 388 | if (rec_count) |
| 391 | 389 | { /* skip end of record */ |
| 392 | | if (image_fseek(tpc.t[tap_sel].img, rec_count, SEEK_CUR)) |
| 390 | if (image_fseek(tpc->t[tap_sel].img, rec_count, SEEK_CUR)) |
| 393 | 391 | { /* eject tape */ |
| 394 | 392 | logerror("Tape error\n"); |
| 395 | | image_unload(tpc.t[tap_sel].img); |
| 396 | | tpc.w[0] |= w0_offline; |
| 397 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 398 | | update_interrupt(machine); |
| 393 | image_unload(tpc->t[tap_sel].img); |
| 394 | tpc->w[0] |= w0_offline; |
| 395 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 396 | update_interrupt(device); |
| 399 | 397 | goto update_registers; |
| 400 | 398 | } |
| 401 | 399 | } |
| 402 | 400 | |
| 403 | 401 | skip_trailer: |
| 404 | | if (image_fread(tpc.t[tap_sel].img, buffer, 4) != 4) |
| 402 | if (image_fread(tpc->t[tap_sel].img, buffer, 4) != 4) |
| 405 | 403 | { /* eject tape */ |
| 406 | 404 | logerror("Tape error\n"); |
| 407 | | image_unload(tpc.t[tap_sel].img); |
| 408 | | tpc.w[0] |= w0_offline; |
| 409 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 410 | | update_interrupt(machine); |
| 405 | image_unload(tpc->t[tap_sel].img); |
| 406 | tpc->w[0] |= w0_offline; |
| 407 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 408 | update_interrupt(device); |
| 411 | 409 | goto update_registers; |
| 412 | 410 | } |
| 413 | 411 | |
| 414 | 412 | if (reclen != ((((int) buffer[1]) << 8) | buffer[0])) |
| 415 | 413 | { /* eject tape */ |
| 416 | 414 | logerror("Tape error\n"); |
| 417 | | image_unload(tpc.t[tap_sel].img); |
| 418 | | tpc.w[0] |= w0_offline; |
| 419 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 420 | | update_interrupt(machine); |
| 415 | image_unload(tpc->t[tap_sel].img); |
| 416 | tpc->w[0] |= w0_offline; |
| 417 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 418 | update_interrupt(device); |
| 421 | 419 | goto update_registers; |
| 422 | 420 | } |
| 423 | 421 | if (buffer[2] || buffer[3]) |
| r6748 | r6749 | |
| 425 | 423 | logerror("Tape error\n"); |
| 426 | 424 | logerror("Tape format looks gooofy\n"); |
| 427 | 425 | /* eject tape to avoid catastrophes */ |
| 428 | | image_unload(tpc.t[tap_sel].img); |
| 429 | | tpc.w[0] |= w0_offline; |
| 430 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 431 | | update_interrupt(machine); |
| 426 | image_unload(tpc->t[tap_sel].img); |
| 427 | tpc->w[0] |= w0_offline; |
| 428 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 429 | update_interrupt(device); |
| 432 | 430 | goto update_registers; |
| 433 | 431 | } |
| 434 | 432 | |
| 435 | | if (! (tpc.w[7] & w7_error)) |
| 433 | if (! (tpc->w[7] & w7_error)) |
| 436 | 434 | { |
| 437 | | tpc.w[7] |= w7_idle | w7_complete; |
| 438 | | update_interrupt(machine); |
| 435 | tpc->w[7] |= w7_idle | w7_complete; |
| 436 | update_interrupt(device); |
| 439 | 437 | } |
| 440 | 438 | |
| 441 | 439 | update_registers: |
| 442 | | tpc.w[1] = rec_count & 0xffff; |
| 443 | | tpc.w[2] = (rec_count >> 8) & 0xff; |
| 444 | | tpc.w[3] = read_offset; |
| 445 | | tpc.w[4] = char_count; |
| 446 | | tpc.w[5] = (dma_address >> 1) & 0xffff; |
| 447 | | tpc.w[6] = (tpc.w[6] & 0xffe0) | ((dma_address >> 17) & 0xf); |
| 440 | tpc->w[1] = rec_count & 0xffff; |
| 441 | tpc->w[2] = (rec_count >> 8) & 0xff; |
| 442 | tpc->w[3] = read_offset; |
| 443 | tpc->w[4] = char_count; |
| 444 | tpc->w[5] = (dma_address >> 1) & 0xffff; |
| 445 | tpc->w[6] = (tpc->w[6] & 0xffe0) | ((dma_address >> 17) & 0xf); |
| 448 | 446 | } |
| 449 | 447 | |
| 450 | 448 | /* |
| 451 | 449 | Handle the record skip forward command: skip a specified number of records. |
| 452 | 450 | */ |
| 453 | | static void cmd_record_skip_forward(running_machine *machine) |
| 451 | static void cmd_record_skip_forward(const device_config *device) |
| 454 | 452 | { |
| 455 | 453 | UINT8 buffer[4]; |
| 456 | 454 | int reclen; |
| 457 | 455 | |
| 458 | 456 | int record_count; |
| 459 | 457 | int bytes_read; |
| 458 | tap_990_t *tpc = get_safe_token(device); |
| 459 | int tap_sel = cur_tape_unit(device); |
| 460 | 460 | |
| 461 | | int tap_sel = cur_tape_unit(); |
| 462 | | |
| 463 | 461 | if (tap_sel == -1) |
| 464 | 462 | { |
| 465 | 463 | /* No idea what to report... */ |
| 466 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 467 | | update_interrupt(machine); |
| 464 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 465 | update_interrupt(device); |
| 468 | 466 | return; |
| 469 | 467 | } |
| 470 | | else if (! image_exists(tpc.t[tap_sel].img)) |
| 468 | else if (! image_exists(tpc->t[tap_sel].img)) |
| 471 | 469 | { /* offline */ |
| 472 | | tpc.w[0] |= w0_offline; |
| 473 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 474 | | update_interrupt(machine); |
| 470 | tpc->w[0] |= w0_offline; |
| 471 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 472 | update_interrupt(device); |
| 475 | 473 | return; |
| 476 | 474 | } |
| 477 | 475 | #if 0 |
| 478 | 476 | else if (0) |
| 479 | 477 | { /* rewind in progress */ |
| 480 | | tpc.w[0] |= 0x80 >> tap_sel; |
| 481 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 482 | | update_interrupt(machine); |
| 478 | tpc->w[0] |= 0x80 >> tap_sel; |
| 479 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 480 | update_interrupt(device); |
| 483 | 481 | return; |
| 484 | 482 | } |
| 485 | 483 | #endif |
| 486 | 484 | |
| 487 | | record_count = tpc.w[4]; |
| 485 | record_count = tpc->w[4]; |
| 488 | 486 | |
| 489 | 487 | if (record_count) |
| 490 | | tpc.t[tap_sel].bot = 0; |
| 488 | tpc->t[tap_sel].bot = 0; |
| 491 | 489 | |
| 492 | 490 | while (record_count > 0) |
| 493 | 491 | { |
| 494 | | bytes_read = image_fread(tpc.t[tap_sel].img, buffer, 4); |
| 492 | bytes_read = image_fread(tpc->t[tap_sel].img, buffer, 4); |
| 495 | 493 | if (bytes_read != 4) |
| 496 | 494 | { |
| 497 | 495 | if (bytes_read == 0) |
| 498 | 496 | { /* legitimate EOF */ |
| 499 | | tpc.t[tap_sel].eot = 1; |
| 500 | | tpc.w[0] |= w0_EOT; /* or should it be w0_command_timeout? */ |
| 501 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 502 | | update_interrupt(machine); |
| 497 | tpc->t[tap_sel].eot = 1; |
| 498 | tpc->w[0] |= w0_EOT; /* or should it be w0_command_timeout? */ |
| 499 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 500 | update_interrupt(device); |
| 503 | 501 | goto update_registers; |
| 504 | 502 | } |
| 505 | 503 | else |
| 506 | 504 | { /* illegitimate EOF */ |
| 507 | 505 | /* No idea what to report... */ |
| 508 | 506 | /* eject tape to avoid catastrophes */ |
| 509 | | image_unload(tpc.t[tap_sel].img); |
| 510 | | tpc.w[0] |= w0_offline; |
| 511 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 512 | | update_interrupt(machine); |
| 507 | image_unload(tpc->t[tap_sel].img); |
| 508 | tpc->w[0] |= w0_offline; |
| 509 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 510 | update_interrupt(device); |
| 513 | 511 | goto update_registers; |
| 514 | 512 | } |
| 515 | 513 | } |
| r6748 | r6749 | |
| 518 | 516 | { /* no idea what these bytes mean */ |
| 519 | 517 | logerror("Tape format looks gooofy\n"); |
| 520 | 518 | /* eject tape to avoid catastrophes */ |
| 521 | | image_unload(tpc.t[tap_sel].img); |
| 522 | | tpc.w[0] |= w0_offline; |
| 523 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 524 | | update_interrupt(machine); |
| 519 | image_unload(tpc->t[tap_sel].img); |
| 520 | tpc->w[0] |= w0_offline; |
| 521 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 522 | update_interrupt(device); |
| 525 | 523 | goto update_registers; |
| 526 | 524 | } |
| 527 | 525 | |
| r6748 | r6749 | |
| 529 | 527 | if (reclen == 0) |
| 530 | 528 | { |
| 531 | 529 | logerror("record skip forward: found EOF\n"); |
| 532 | | tpc.w[0] |= w0_EOF; |
| 533 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 534 | | update_interrupt(machine); |
| 530 | tpc->w[0] |= w0_EOF; |
| 531 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 532 | update_interrupt(device); |
| 535 | 533 | goto update_registers; |
| 536 | 534 | } |
| 537 | 535 | |
| 538 | 536 | /* skip record data */ |
| 539 | | if (image_fseek(tpc.t[tap_sel].img, reclen, SEEK_CUR)) |
| 537 | if (image_fseek(tpc->t[tap_sel].img, reclen, SEEK_CUR)) |
| 540 | 538 | { /* eject tape */ |
| 541 | | image_unload(tpc.t[tap_sel].img); |
| 542 | | tpc.w[0] |= w0_offline; |
| 543 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 544 | | update_interrupt(machine); |
| 539 | image_unload(tpc->t[tap_sel].img); |
| 540 | tpc->w[0] |= w0_offline; |
| 541 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 542 | update_interrupt(device); |
| 545 | 543 | goto update_registers; |
| 546 | 544 | } |
| 547 | 545 | |
| 548 | | if (image_fread(tpc.t[tap_sel].img, buffer, 4) != 4) |
| 546 | if (image_fread(tpc->t[tap_sel].img, buffer, 4) != 4) |
| 549 | 547 | { /* eject tape */ |
| 550 | | image_unload(tpc.t[tap_sel].img); |
| 551 | | tpc.w[0] |= w0_offline; |
| 552 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 553 | | update_interrupt(machine); |
| 548 | image_unload(tpc->t[tap_sel].img); |
| 549 | tpc->w[0] |= w0_offline; |
| 550 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 551 | update_interrupt(device); |
| 554 | 552 | goto update_registers; |
| 555 | 553 | } |
| 556 | 554 | |
| 557 | 555 | if (reclen != ((((int) buffer[1]) << 8) | buffer[0])) |
| 558 | 556 | { /* eject tape */ |
| 559 | | image_unload(tpc.t[tap_sel].img); |
| 560 | | tpc.w[0] |= w0_offline; |
| 561 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 562 | | update_interrupt(machine); |
| 557 | image_unload(tpc->t[tap_sel].img); |
| 558 | tpc->w[0] |= w0_offline; |
| 559 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 560 | update_interrupt(device); |
| 563 | 561 | goto update_registers; |
| 564 | 562 | } |
| 565 | 563 | if (buffer[2] || buffer[3]) |
| 566 | 564 | { /* no idea what these bytes mean */ |
| 567 | 565 | logerror("Tape format looks gooofy\n"); |
| 568 | 566 | /* eject tape to avoid catastrophes */ |
| 569 | | image_unload(tpc.t[tap_sel].img); |
| 570 | | tpc.w[0] |= w0_offline; |
| 571 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 572 | | update_interrupt(machine); |
| 567 | image_unload(tpc->t[tap_sel].img); |
| 568 | tpc->w[0] |= w0_offline; |
| 569 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 570 | update_interrupt(device); |
| 573 | 571 | goto update_registers; |
| 574 | 572 | } |
| 575 | 573 | |
| 576 | 574 | record_count--; |
| 577 | 575 | } |
| 578 | 576 | |
| 579 | | tpc.w[7] |= w7_idle | w7_complete; |
| 580 | | update_interrupt(machine); |
| 577 | tpc->w[7] |= w7_idle | w7_complete; |
| 578 | update_interrupt(device); |
| 581 | 579 | |
| 582 | 580 | update_registers: |
| 583 | | tpc.w[4] = record_count; |
| 581 | tpc->w[4] = record_count; |
| 584 | 582 | } |
| 585 | 583 | |
| 586 | 584 | /* |
| 587 | 585 | Handle the record skip reverse command: skip a specified number of records backwards. |
| 588 | 586 | */ |
| 589 | | static void cmd_record_skip_reverse(running_machine *machine) |
| 587 | static void cmd_record_skip_reverse(const device_config *device) |
| 590 | 588 | { |
| 591 | 589 | UINT8 buffer[4]; |
| 592 | 590 | int reclen; |
| r6748 | r6749 | |
| 594 | 592 | int record_count; |
| 595 | 593 | |
| 596 | 594 | int bytes_read; |
| 595 | tap_990_t *tpc = get_safe_token(device); |
| 596 | int tap_sel = cur_tape_unit(device); |
| 597 | 597 | |
| 598 | | int tap_sel = cur_tape_unit(); |
| 599 | | |
| 600 | 598 | if (tap_sel == -1) |
| 601 | 599 | { |
| 602 | 600 | /* No idea what to report... */ |
| 603 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 604 | | update_interrupt(machine); |
| 601 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 602 | update_interrupt(device); |
| 605 | 603 | return; |
| 606 | 604 | } |
| 607 | | else if (! image_exists(tpc.t[tap_sel].img)) |
| 605 | else if (! image_exists(tpc->t[tap_sel].img)) |
| 608 | 606 | { /* offline */ |
| 609 | | tpc.w[0] |= w0_offline; |
| 610 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 611 | | update_interrupt(machine); |
| 607 | tpc->w[0] |= w0_offline; |
| 608 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 609 | update_interrupt(device); |
| 612 | 610 | return; |
| 613 | 611 | } |
| 614 | 612 | #if 0 |
| 615 | 613 | else if (0) |
| 616 | 614 | { /* rewind in progress */ |
| 617 | | tpc.w[0] |= 0x80 >> tap_sel; |
| 618 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 619 | | update_interrupt(machine); |
| 615 | tpc->w[0] |= 0x80 >> tap_sel; |
| 616 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 617 | update_interrupt(device); |
| 620 | 618 | return; |
| 621 | 619 | } |
| 622 | 620 | #endif |
| 623 | 621 | |
| 624 | | record_count = tpc.w[4]; |
| 622 | record_count = tpc->w[4]; |
| 625 | 623 | |
| 626 | 624 | if (record_count) |
| 627 | | tpc.t[tap_sel].eot = 0; |
| 625 | tpc->t[tap_sel].eot = 0; |
| 628 | 626 | |
| 629 | 627 | while (record_count > 0) |
| 630 | 628 | { |
| 631 | | if (image_ftell(tpc.t[tap_sel].img) == 0) |
| 629 | if (image_ftell(tpc->t[tap_sel].img) == 0) |
| 632 | 630 | { /* bot */ |
| 633 | | tpc.t[tap_sel].bot = 1; |
| 634 | | tpc.w[0] |= w0_BOT; |
| 635 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 636 | | update_interrupt(machine); |
| 631 | tpc->t[tap_sel].bot = 1; |
| 632 | tpc->w[0] |= w0_BOT; |
| 633 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 634 | update_interrupt(device); |
| 637 | 635 | goto update_registers; |
| 638 | 636 | } |
| 639 | | if (image_fseek(tpc.t[tap_sel].img, -4, SEEK_CUR)) |
| 637 | if (image_fseek(tpc->t[tap_sel].img, -4, SEEK_CUR)) |
| 640 | 638 | { /* eject tape */ |
| 641 | | image_unload(tpc.t[tap_sel].img); |
| 642 | | tpc.w[0] |= w0_offline; |
| 643 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 644 | | update_interrupt(machine); |
| 639 | image_unload(tpc->t[tap_sel].img); |
| 640 | tpc->w[0] |= w0_offline; |
| 641 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 642 | update_interrupt(device); |
| 645 | 643 | goto update_registers; |
| 646 | 644 | } |
| 647 | | bytes_read = image_fread(tpc.t[tap_sel].img, buffer, 4); |
| 645 | bytes_read = image_fread(tpc->t[tap_sel].img, buffer, 4); |
| 648 | 646 | if (bytes_read != 4) |
| 649 | 647 | { |
| 650 | 648 | /* illegitimate EOF */ |
| 651 | 649 | /* No idea what to report... */ |
| 652 | 650 | /* eject tape to avoid catastrophes */ |
| 653 | | image_unload(tpc.t[tap_sel].img); |
| 654 | | tpc.w[0] |= w0_offline; |
| 655 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 656 | | update_interrupt(machine); |
| 651 | image_unload(tpc->t[tap_sel].img); |
| 652 | tpc->w[0] |= w0_offline; |
| 653 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 654 | update_interrupt(device); |
| 657 | 655 | goto update_registers; |
| 658 | 656 | } |
| 659 | 657 | reclen = (((int) buffer[1]) << 8) | buffer[0]; |
| r6748 | r6749 | |
| 661 | 659 | { /* no idea what these bytes mean */ |
| 662 | 660 | logerror("Tape format looks gooofy\n"); |
| 663 | 661 | /* eject tape to avoid catastrophes */ |
| 664 | | image_unload(tpc.t[tap_sel].img); |
| 665 | | tpc.w[0] |= w0_offline; |
| 666 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 667 | | update_interrupt(machine); |
| 662 | image_unload(tpc->t[tap_sel].img); |
| 663 | tpc->w[0] |= w0_offline; |
| 664 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 665 | update_interrupt(device); |
| 668 | 666 | goto update_registers; |
| 669 | 667 | } |
| 670 | 668 | |
| r6748 | r6749 | |
| 672 | 670 | if (reclen == 0) |
| 673 | 671 | { |
| 674 | 672 | logerror("record skip reverse: found EOF\n"); |
| 675 | | if (image_fseek(tpc.t[tap_sel].img, -4, SEEK_CUR)) |
| 673 | if (image_fseek(tpc->t[tap_sel].img, -4, SEEK_CUR)) |
| 676 | 674 | { /* eject tape */ |
| 677 | | image_unload(tpc.t[tap_sel].img); |
| 678 | | tpc.w[0] |= w0_offline; |
| 679 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 680 | | update_interrupt(machine); |
| 675 | image_unload(tpc->t[tap_sel].img); |
| 676 | tpc->w[0] |= w0_offline; |
| 677 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 678 | update_interrupt(device); |
| 681 | 679 | goto update_registers; |
| 682 | 680 | } |
| 683 | | tpc.w[0] |= w0_EOF; |
| 684 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 685 | | update_interrupt(machine); |
| 681 | tpc->w[0] |= w0_EOF; |
| 682 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 683 | update_interrupt(device); |
| 686 | 684 | goto update_registers; |
| 687 | 685 | } |
| 688 | 686 | |
| 689 | | if (image_fseek(tpc.t[tap_sel].img, -reclen-8, SEEK_CUR)) |
| 687 | if (image_fseek(tpc->t[tap_sel].img, -reclen-8, SEEK_CUR)) |
| 690 | 688 | { /* eject tape */ |
| 691 | | image_unload(tpc.t[tap_sel].img); |
| 692 | | tpc.w[0] |= w0_offline; |
| 693 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 694 | | update_interrupt(machine); |
| 689 | image_unload(tpc->t[tap_sel].img); |
| 690 | tpc->w[0] |= w0_offline; |
| 691 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 692 | update_interrupt(device); |
| 695 | 693 | goto update_registers; |
| 696 | 694 | } |
| 697 | 695 | |
| 698 | | if (image_fread(tpc.t[tap_sel].img, buffer, 4) != 4) |
| 696 | if (image_fread(tpc->t[tap_sel].img, buffer, 4) != 4) |
| 699 | 697 | { /* eject tape */ |
| 700 | | image_unload(tpc.t[tap_sel].img); |
| 701 | | tpc.w[0] |= w0_offline; |
| 702 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 703 | | update_interrupt(machine); |
| 698 | image_unload(tpc->t[tap_sel].img); |
| 699 | tpc->w[0] |= w0_offline; |
| 700 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 701 | update_interrupt(device); |
| 704 | 702 | goto update_registers; |
| 705 | 703 | } |
| 706 | 704 | if (reclen != ((((int) buffer[1]) << 8) | buffer[0])) |
| 707 | 705 | { /* eject tape */ |
| 708 | | image_unload(tpc.t[tap_sel].img); |
| 709 | | tpc.w[0] |= w0_offline; |
| 710 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 711 | | update_interrupt(machine); |
| 706 | image_unload(tpc->t[tap_sel].img); |
| 707 | tpc->w[0] |= w0_offline; |
| 708 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 709 | update_interrupt(device); |
| 712 | 710 | goto update_registers; |
| 713 | 711 | } |
| 714 | 712 | if (buffer[2] || buffer[3]) |
| 715 | 713 | { /* no idea what these bytes mean */ |
| 716 | 714 | logerror("Tape format looks gooofy\n"); |
| 717 | 715 | /* eject tape to avoid catastrophes */ |
| 718 | | image_unload(tpc.t[tap_sel].img); |
| 719 | | tpc.w[0] |= w0_offline; |
| 720 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 721 | | update_interrupt(machine); |
| 716 | image_unload(tpc->t[tap_sel].img); |
| 717 | tpc->w[0] |= w0_offline; |
| 718 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 719 | update_interrupt(device); |
| 722 | 720 | goto update_registers; |
| 723 | 721 | } |
| 724 | 722 | |
| 725 | | if (image_fseek(tpc.t[tap_sel].img, -4, SEEK_CUR)) |
| 723 | if (image_fseek(tpc->t[tap_sel].img, -4, SEEK_CUR)) |
| 726 | 724 | { /* eject tape */ |
| 727 | | image_unload(tpc.t[tap_sel].img); |
| 728 | | tpc.w[0] |= w0_offline; |
| 729 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 730 | | update_interrupt(machine); |
| 725 | image_unload(tpc->t[tap_sel].img); |
| 726 | tpc->w[0] |= w0_offline; |
| 727 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 728 | update_interrupt(device); |
| 731 | 729 | goto update_registers; |
| 732 | 730 | } |
| 733 | 731 | |
| 734 | 732 | record_count--; |
| 735 | 733 | } |
| 736 | 734 | |
| 737 | | tpc.w[7] |= w7_idle | w7_complete; |
| 738 | | update_interrupt(machine); |
| 735 | tpc->w[7] |= w7_idle | w7_complete; |
| 736 | update_interrupt(device); |
| 739 | 737 | |
| 740 | 738 | update_registers: |
| 741 | | tpc.w[4] = record_count; |
| 739 | tpc->w[4] = record_count; |
| 742 | 740 | } |
| 743 | 741 | |
| 744 | 742 | /* |
| 745 | 743 | Handle the rewind command: rewind to BOT. |
| 746 | 744 | */ |
| 747 | | static void cmd_rewind(running_machine *machine) |
| 745 | static void cmd_rewind(const device_config *device) |
| 748 | 746 | { |
| 749 | | int tap_sel = cur_tape_unit(); |
| 747 | tap_990_t *tpc = get_safe_token(device); |
| 748 | int tap_sel = cur_tape_unit(device); |
| 750 | 749 | |
| 751 | 750 | if (tap_sel == -1) |
| 752 | 751 | { |
| 753 | 752 | /* No idea what to report... */ |
| 754 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 755 | | update_interrupt(machine); |
| 753 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 754 | update_interrupt(device); |
| 756 | 755 | return; |
| 757 | 756 | } |
| 758 | | else if (! image_exists(tpc.t[tap_sel].img)) |
| 757 | else if (! image_exists(tpc->t[tap_sel].img)) |
| 759 | 758 | { /* offline */ |
| 760 | | tpc.w[0] |= w0_offline; |
| 761 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 762 | | update_interrupt(machine); |
| 759 | tpc->w[0] |= w0_offline; |
| 760 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 761 | update_interrupt(device); |
| 763 | 762 | return; |
| 764 | 763 | } |
| 765 | 764 | #if 0 |
| 766 | 765 | else if (0) |
| 767 | 766 | { /* rewind in progress */ |
| 768 | | tpc.w[0] |= 0x80 >> tap_sel; |
| 769 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 770 | | update_interrupt(machine); |
| 767 | tpc->w[0] |= 0x80 >> tap_sel; |
| 768 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 769 | update_interrupt(device); |
| 771 | 770 | return; |
| 772 | 771 | } |
| 773 | 772 | #endif |
| 774 | 773 | |
| 775 | | tpc.t[tap_sel].eot = 0; |
| 774 | tpc->t[tap_sel].eot = 0; |
| 776 | 775 | |
| 777 | | if (image_fseek(tpc.t[tap_sel].img, 0, SEEK_SET)) |
| 776 | if (image_fseek(tpc->t[tap_sel].img, 0, SEEK_SET)) |
| 778 | 777 | { /* eject tape */ |
| 779 | | image_unload(tpc.t[tap_sel].img); |
| 780 | | tpc.w[0] |= w0_offline; |
| 781 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 782 | | update_interrupt(machine); |
| 778 | image_unload(tpc->t[tap_sel].img); |
| 779 | tpc->w[0] |= w0_offline; |
| 780 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 781 | update_interrupt(device); |
| 783 | 782 | return; |
| 784 | 783 | } |
| 785 | | tpc.t[tap_sel].bot = 1; |
| 784 | tpc->t[tap_sel].bot = 1; |
| 786 | 785 | |
| 787 | | tpc.w[7] |= w7_idle | w7_complete; |
| 788 | | update_interrupt(machine); |
| 786 | tpc->w[7] |= w7_idle | w7_complete; |
| 787 | update_interrupt(device); |
| 789 | 788 | } |
| 790 | 789 | |
| 791 | 790 | /* |
| 792 | 791 | Handle the rewind and offline command: disable the tape unit. |
| 793 | 792 | */ |
| 794 | | static void cmd_rewind_and_offline(running_machine *machine) |
| 793 | static void cmd_rewind_and_offline(const device_config *device) |
| 795 | 794 | { |
| 796 | | int tap_sel = cur_tape_unit(); |
| 795 | tap_990_t *tpc = get_safe_token(device); |
| 796 | int tap_sel = cur_tape_unit(device); |
| 797 | 797 | |
| 798 | 798 | if (tap_sel == -1) |
| 799 | 799 | { |
| 800 | 800 | /* No idea what to report... */ |
| 801 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 802 | | update_interrupt(machine); |
| 801 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 802 | update_interrupt(device); |
| 803 | 803 | return; |
| 804 | 804 | } |
| 805 | | else if (! image_exists(tpc.t[tap_sel].img)) |
| 805 | else if (! image_exists(tpc->t[tap_sel].img)) |
| 806 | 806 | { /* offline */ |
| 807 | | tpc.w[0] |= w0_offline; |
| 808 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 809 | | update_interrupt(machine); |
| 807 | tpc->w[0] |= w0_offline; |
| 808 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 809 | update_interrupt(device); |
| 810 | 810 | return; |
| 811 | 811 | } |
| 812 | 812 | #if 0 |
| 813 | 813 | else if (0) |
| 814 | 814 | { /* rewind in progress */ |
| 815 | | tpc.w[0] |= 0x80 >> tap_sel; |
| 816 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 817 | | update_interrupt(machine); |
| 815 | tpc->w[0] |= 0x80 >> tap_sel; |
| 816 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 817 | update_interrupt(device); |
| 818 | 818 | return; |
| 819 | 819 | } |
| 820 | 820 | #endif |
| 821 | 821 | |
| 822 | 822 | /* eject tape */ |
| 823 | | image_unload(tpc.t[tap_sel].img); |
| 823 | image_unload(tpc->t[tap_sel].img); |
| 824 | 824 | |
| 825 | | tpc.w[7] |= w7_idle | w7_complete; |
| 826 | | update_interrupt(machine); |
| 825 | tpc->w[7] |= w7_idle | w7_complete; |
| 826 | update_interrupt(device); |
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | /* |
| 830 | 830 | Handle the read transport status command: return the current tape status. |
| 831 | 831 | */ |
| 832 | | static void read_transport_status(running_machine *machine) |
| 832 | static void read_transport_status(const device_config *device) |
| 833 | 833 | { |
| 834 | | int tap_sel = cur_tape_unit(); |
| 834 | tap_990_t *tpc = get_safe_token(device); |
| 835 | int tap_sel = cur_tape_unit(device); |
| 835 | 836 | |
| 836 | 837 | if (tap_sel == -1) |
| 837 | 838 | { |
| 838 | 839 | /* No idea what to report... */ |
| 839 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 840 | | update_interrupt(machine); |
| 840 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 841 | update_interrupt(device); |
| 841 | 842 | } |
| 842 | | else if (! image_exists(tpc.t[tap_sel].img)) |
| 843 | else if (! image_exists(tpc->t[tap_sel].img)) |
| 843 | 844 | { /* offline */ |
| 844 | | tpc.w[0] |= w0_offline; |
| 845 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 846 | | update_interrupt(machine); |
| 845 | tpc->w[0] |= w0_offline; |
| 846 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 847 | update_interrupt(device); |
| 847 | 848 | } |
| 848 | 849 | #if 0 |
| 849 | 850 | else if (0) |
| 850 | 851 | { /* rewind in progress */ |
| 851 | | tpc.w[0] |= /*...*/; |
| 852 | | tpc.w[7] |= w7_idle | w7_error | w7_tape_error; |
| 853 | | update_interrupt(machine); |
| 852 | tpc->w[0] |= /*...*/; |
| 853 | tpc->w[7] |= w7_idle | w7_error | w7_tape_error; |
| 854 | update_interrupt(device); |
| 854 | 855 | } |
| 855 | 856 | #endif |
| 856 | 857 | else |
| 857 | 858 | { /* no particular error condition */ |
| 858 | | if (tpc.t[tap_sel].bot) |
| 859 | | tpc.w[0] |= w0_BOT; |
| 860 | | if (tpc.t[tap_sel].eot) |
| 861 | | tpc.w[0] |= w0_EOT; |
| 862 | | if (tpc.t[tap_sel].wp) |
| 863 | | tpc.w[0] |= w0_write_ring; |
| 864 | | tpc.w[7] |= w7_idle | w7_complete; |
| 865 | | update_interrupt(machine); |
| 859 | if (tpc->t[tap_sel].bot) |
| 860 | tpc->w[0] |= w0_BOT; |
| 861 | if (tpc->t[tap_sel].eot) |
| 862 | tpc->w[0] |= w0_EOT; |
| 863 | if (tpc->t[tap_sel].wp) |
| 864 | tpc->w[0] |= w0_write_ring; |
| 865 | tpc->w[7] |= w7_idle | w7_complete; |
| 866 | update_interrupt(device); |
| 866 | 867 | } |
| 867 | 868 | } |
| 868 | 869 | |
| 869 | 870 | /* |
| 870 | 871 | Parse command code and execute the command. |
| 871 | 872 | */ |
| 872 | | static void execute_command(running_machine *machine) |
| 873 | static void execute_command(const device_config *device) |
| 873 | 874 | { |
| 874 | 875 | /* hack */ |
| 875 | | tpc.w[0] &= 0xff; |
| 876 | tap_990_t *tpc = get_safe_token(device); |
| 877 | tpc->w[0] &= 0xff; |
| 876 | 878 | |
| 877 | | switch ((tpc.w[6] & w6_command) >> 8) |
| 879 | switch ((tpc->w[6] & w6_command) >> 8) |
| 878 | 880 | { |
| 879 | 881 | case 0x00: |
| 880 | 882 | case 0x0C: |
| 881 | 883 | case 0x0E: |
| 882 | 884 | /* NOP */ |
| 883 | 885 | logerror("NOP\n"); |
| 884 | | tpc.w[7] |= w7_idle | w7_complete; |
| 885 | | update_interrupt(machine); |
| 886 | tpc->w[7] |= w7_idle | w7_complete; |
| 887 | update_interrupt(device); |
| 886 | 888 | break; |
| 887 | 889 | case 0x01: |
| 888 | 890 | /* buffer sync: means nothing under emulation */ |
| 889 | 891 | logerror("buffer sync\n"); |
| 890 | | tpc.w[7] |= w7_idle | w7_complete; |
| 891 | | update_interrupt(machine); |
| 892 | tpc->w[7] |= w7_idle | w7_complete; |
| 893 | update_interrupt(device); |
| 892 | 894 | break; |
| 893 | 895 | case 0x02: |
| 894 | 896 | /* write EOF - not emulated */ |
| 895 | 897 | logerror("write EOF\n"); |
| 896 | 898 | /* ... */ |
| 897 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 898 | | update_interrupt(machine); |
| 899 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 900 | update_interrupt(device); |
| 899 | 901 | break; |
| 900 | 902 | case 0x03: |
| 901 | 903 | /* record skip reverse - not fully tested */ |
| 902 | 904 | logerror("record skip reverse\n"); |
| 903 | | cmd_record_skip_reverse(machine); |
| 905 | cmd_record_skip_reverse(device); |
| 904 | 906 | break; |
| 905 | 907 | case 0x04: |
| 906 | 908 | /* read binary forward */ |
| 907 | 909 | logerror("read binary forward\n"); |
| 908 | | cmd_read_binary_forward(machine); |
| 910 | cmd_read_binary_forward(device); |
| 909 | 911 | break; |
| 910 | 912 | case 0x05: |
| 911 | 913 | /* record skip forward - not tested */ |
| 912 | 914 | logerror("record skip forward\n"); |
| 913 | | cmd_record_skip_forward(machine); |
| 915 | cmd_record_skip_forward(device); |
| 914 | 916 | break; |
| 915 | 917 | case 0x06: |
| 916 | 918 | /* write binary forward - not emulated */ |
| 917 | 919 | logerror("write binary forward\n"); |
| 918 | 920 | /* ... */ |
| 919 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 920 | | update_interrupt(machine); |
| 921 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 922 | update_interrupt(device); |
| 921 | 923 | break; |
| 922 | 924 | case 0x07: |
| 923 | 925 | /* erase - not emulated */ |
| 924 | 926 | logerror("erase\n"); |
| 925 | 927 | /* ... */ |
| 926 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 927 | | update_interrupt(machine); |
| 928 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 929 | update_interrupt(device); |
| 928 | 930 | break; |
| 929 | 931 | case 0x08: |
| 930 | 932 | case 0x09: |
| 931 | 933 | /* read transport status */ |
| 932 | 934 | logerror("read transport status\n"); |
| 933 | | read_transport_status(machine); |
| 935 | read_transport_status(device); |
| 934 | 936 | break; |
| 935 | 937 | case 0x0A: |
| 936 | 938 | /* rewind - not tested */ |
| 937 | 939 | logerror("rewind\n"); |
| 938 | | cmd_rewind(machine); |
| 940 | cmd_rewind(device); |
| 939 | 941 | break; |
| 940 | 942 | case 0x0B: |
| 941 | 943 | /* rewind and offline - not tested */ |
| 942 | 944 | logerror("rewind and offline\n"); |
| 943 | | cmd_rewind_and_offline(machine); |
| 945 | cmd_rewind_and_offline(device); |
| 944 | 946 | break; |
| 945 | 947 | case 0x0F: |
| 946 | 948 | /* extended control and status - not emulated */ |
| 947 | 949 | logerror("extended control and status\n"); |
| 948 | 950 | /* ... */ |
| 949 | | tpc.w[7] |= w7_idle | w7_error | w7_hard_error; |
| 950 | | update_interrupt(machine); |
| 951 | tpc->w[7] |= w7_idle | w7_error | w7_hard_error; |
| 952 | update_interrupt(device); |
| 951 | 953 | break; |
| 952 | 954 | } |
| 953 | 955 | } |
| r6748 | r6749 | |
| 956 | 958 | /* |
| 957 | 959 | Read one register in TPCS space |
| 958 | 960 | */ |
| 959 | | READ16_HANDLER(ti990_tpc_r) |
| 961 | READ16_DEVICE_HANDLER(ti990_tpc_r) |
| 960 | 962 | { |
| 963 | tap_990_t *tpc = get_safe_token(device); |
| 961 | 964 | if ((offset >= 0) && (offset < 8)) |
| 962 | | return tpc.w[offset]; |
| 965 | return tpc->w[offset]; |
| 963 | 966 | else |
| 964 | 967 | return 0; |
| 965 | 968 | } |
| r6748 | r6749 | |
| 967 | 970 | /* |
| 968 | 971 | Write one register in TPCS space. Execute command if w7_idle is cleared. |
| 969 | 972 | */ |
| 970 | | WRITE16_HANDLER(ti990_tpc_w) |
| 973 | WRITE16_DEVICE_HANDLER(ti990_tpc_w) |
| 971 | 974 | { |
| 975 | tap_990_t *tpc = get_safe_token(device); |
| 972 | 976 | if ((offset >= 0) && (offset < 8)) |
| 973 | 977 | { |
| 974 | 978 | /* write protect if a command is in progress */ |
| 975 | | if (tpc.w[7] & w7_idle) |
| 979 | if (tpc->w[7] & w7_idle) |
| 976 | 980 | { |
| 977 | | UINT16 old_data = tpc.w[offset]; |
| 981 | UINT16 old_data = tpc->w[offset]; |
| 978 | 982 | |
| 979 | 983 | /* Only write writable bits AND honor byte accesses (ha!) */ |
| 980 | | tpc.w[offset] = (tpc.w[offset] & ((~w_mask[offset]) | mem_mask)) | (data & w_mask[offset] & ~mem_mask); |
| 984 | tpc->w[offset] = (tpc->w[offset] & ((~w_mask[offset]) | mem_mask)) | (data & w_mask[offset] & ~mem_mask); |
| 981 | 985 | |
| 982 | 986 | if ((offset == 0) || (offset == 7)) |
| 983 | | update_interrupt(space->machine); |
| 987 | update_interrupt(device); |
| 984 | 988 | |
| 985 | 989 | if ((offset == 7) && (old_data & w7_idle) && ! (data & w7_idle)) |
| 986 | 990 | { /* idle has been cleared: start command execution */ |
| 987 | | execute_command(space->machine); |
| 991 | execute_command(device); |
| 988 | 992 | } |
| 989 | 993 | } |
| 990 | 994 | } |
| 991 | 995 | } |
| 996 | |
| 997 | DEVICE_GET_INFO( ti990_tape ) |
| 998 | { |
| 999 | switch (state) |
| 1000 | { |
| 1001 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1002 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 1003 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(ti990_tape_t); break; |
| 1004 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 1005 | case DEVINFO_INT_IMAGE_TYPE: info->i = IO_MAGTAPE; break; |
| 1006 | case DEVINFO_INT_IMAGE_READABLE: info->i = 1; break; |
| 1007 | case DEVINFO_INT_IMAGE_WRITEABLE: info->i = 1; break; |
| 1008 | case DEVINFO_INT_IMAGE_CREATABLE: info->i = 0; break; |
| 1009 | |
| 1010 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1011 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(ti990_tape); break; |
| 1012 | case DEVINFO_FCT_IMAGE_LOAD: info->f = (genf *) DEVICE_IMAGE_LOAD_NAME(ti990_tape); break; |
| 1013 | case DEVINFO_FCT_IMAGE_UNLOAD: info->f = (genf *) DEVICE_IMAGE_UNLOAD_NAME(ti990_tape); break; |
| 1014 | |
| 1015 | case DEVINFO_STR_IMAGE_FILE_EXTENSIONS: strcpy(info->s, "tap"); break; |
| 1016 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1017 | case DEVINFO_STR_NAME: strcpy(info->s, "TI990 Magnetic Tape"); break; |
| 1018 | case DEVINFO_STR_FAMILY: strcpy(info->s, "Magnetic Tape"); break; |
| 1019 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 1020 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1021 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 1022 | } |
| 1023 | } |
| 1024 | #define TI990_TAPE DEVICE_GET_INFO_NAME(ti990_tape) |
| 1025 | |
| 1026 | #define MDRV_TI990_TAPE_ADD(_tag) \ |
| 1027 | MDRV_DEVICE_ADD((_tag), TI990_TAPE, 0) |
| 1028 | |
| 1029 | |
| 1030 | static MACHINE_DRIVER_START( tap_990 ) |
| 1031 | MDRV_TI990_TAPE_ADD("tape0") |
| 1032 | MDRV_TI990_TAPE_ADD("tape1") |
| 1033 | MDRV_TI990_TAPE_ADD("tape2") |
| 1034 | MDRV_TI990_TAPE_ADD("tape3") |
| 1035 | MACHINE_DRIVER_END |
| 1036 | |
| 1037 | /* |
| 1038 | Init the tape controller core |
| 1039 | */ |
| 1040 | DEVICE_START(tap_990) |
| 1041 | { |
| 1042 | tap_990_t *tpc = get_safe_token(device); |
| 1043 | /* verify that we have an interface assigned */ |
| 1044 | assert(device->static_config != NULL); |
| 1045 | |
| 1046 | /* copy interface pointer */ |
| 1047 | tpc->intf = device->static_config; |
| 1048 | |
| 1049 | memset(tpc->w, 0, sizeof(tpc->w)); |
| 1050 | /* The PE bit is always set for the MT3200 (but not MT1600) */ |
| 1051 | /* According to MT3200 manual, w7 bit #4 (reserved) is always set */ |
| 1052 | tpc->w[7] = w7_idle /*| w7_PE_format*/ | 0x0800; |
| 1053 | |
| 1054 | update_interrupt(device); |
| 1055 | } |
| 1056 | |
| 1057 | |
| 1058 | DEVICE_GET_INFO( tap_990 ) |
| 1059 | { |
| 1060 | switch (state) |
| 1061 | { |
| 1062 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 1063 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 1064 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(tap_990_t); break; |
| 1065 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 1066 | |
| 1067 | /* --- the following bits of info are returned as pointers --- */ |
| 1068 | case DEVINFO_PTR_MACHINE_CONFIG: info->machine_config = MACHINE_DRIVER_NAME(tap_990); break; |
| 1069 | |
| 1070 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 1071 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(tap_990); break; |
| 1072 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 1073 | |
| 1074 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 1075 | case DEVINFO_STR_NAME: strcpy(info->s, "Generic TI990 Tape Controller"); break; |
| 1076 | case DEVINFO_STR_FAMILY: strcpy(info->s, "TI990 Tape Controller"); break; |
| 1077 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 1078 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 1079 | case DEVINFO_STR_CREDITS: strcpy(info->s, "Copyright the MESS Team"); break; |
| 1080 | } |
| 1081 | } |
| 1082 | |