src/mess/devices/mflopimg.c
| r1473 | r1474 | |
| 60 | 60 | { FLOPPY_ERROR_INVALIDIMAGE, IMAGE_ERROR_INVALIDIMAGE } |
| 61 | 61 | }; |
| 62 | 62 | |
| 63 | | static int flopimg_keep_geometry; /* hack for TI-99 - please fix when possible */ |
| 64 | | |
| 65 | | |
| 66 | | |
| 67 | 63 | /*************************************************************************** |
| 68 | 64 | IMPLEMENTATION |
| 69 | 65 | ***************************************************************************/ |
| r1473 | r1474 | |
| 263 | 259 | |
| 264 | 260 | static int device_init_floppy(mess_image *image) |
| 265 | 261 | { |
| 266 | | flopimg_keep_geometry = FALSE; |
| 267 | 262 | if (!image_alloctag(image, FLOPPY_TAG, sizeof(mess_flopimg))) |
| 268 | 263 | return INIT_FAIL; |
| 269 | 264 | return floppy_drive_init(image, &mess_floppy_interface); |
| r1473 | r1474 | |
| 279 | 274 | const struct FloppyFormat *floppy_options; |
| 280 | 275 | int floppy_flags, i; |
| 281 | 276 | const char *extension; |
| 277 | int keep_geometry = 0; |
| 282 | 278 | |
| 283 | 279 | /* look up instance data */ |
| 284 | 280 | flopimg = get_flopimg(image); |
| r1473 | r1474 | |
| 304 | 300 | if (err) |
| 305 | 301 | goto error; |
| 306 | 302 | } |
| 303 | |
| 304 | /* if we can get head and track counts, then set the geometry accordingly |
| 305 | However, at least the ti99 system family requires that medium track |
| 306 | count and drive track count be handled separately. |
| 307 | It is possible to insert a 40 track medium in an 80 track drive; the |
| 308 | TI controllers read the track count from sector 0 and automatically |
| 309 | apply double steps. Setting the track count of the drive to the |
| 310 | medium track count will then lead to unreachable tracks. |
| 311 | */ |
| 312 | keep_geometry = (int)device_get_info_int(&image_device(image)->devclass, DEVINFO_INT_KEEP_DRIVE_GEOMETRY); |
| 307 | 313 | |
| 308 | | /* if we can get head and track counts, then set the geometry accordingly */ |
| 309 | | if (!flopimg_keep_geometry |
| 314 | if (!keep_geometry |
| 310 | 315 | && floppy_callbacks(flopimg->floppy)->get_heads_per_disk |
| 311 | 316 | && floppy_callbacks(flopimg->floppy)->get_tracks_per_disk) |
| 312 | 317 | { |
| r1473 | r1474 | |
| 378 | 383 | flopimg->tracktranslate_proc = proc; |
| 379 | 384 | } |
| 380 | 385 | |
| 381 | | |
| 382 | | /************ |
| 383 | | * Another hack for ti99: Drive track count may differ from medium track count. |
| 384 | | * It is possible to insert a 40 track medium in an 80 track drive; the TI |
| 385 | | * controllers read the track count from sector 0 and automatically |
| 386 | | * apply double steps. Setting the track count of the drive to the medium |
| 387 | | * track count will lead to unreachable tracks. |
| 388 | | * This function is called from 99_dsk.c to switch off the lines in |
| 389 | | * internal_floppy_device_load which set the drive geometry to the medium |
| 390 | | * geometry. |
| 391 | | *************/ |
| 392 | | void floppy_keep_drive_geometry(void) |
| 393 | | { |
| 394 | | assert_always(mame_get_phase(Machine) == MAME_PHASE_INIT, "Can only call floppy_keep_drive_geometry at init time!"); |
| 395 | | flopimg_keep_geometry = TRUE; |
| 396 | | } |
| 397 | | |
| 398 | | |
| 399 | | |
| 400 | 386 | /************************************* |
| 401 | 387 | * |
| 402 | 388 | * Device specification function |
| r1473 | r1474 | |
| 428 | 414 | info->i = count; |
| 429 | 415 | break; |
| 430 | 416 | |
| 417 | case DEVINFO_INT_KEEP_DRIVE_GEOMETRY: |
| 418 | info->i = 0; |
| 419 | break; |
| 420 | |
| 431 | 421 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 432 | 422 | case DEVINFO_STR_FILE_EXTENSIONS: |
| 433 | 423 | /* retrieve the floppy options */ |
src/mess/machine/99_dsk.c
| r1473 | r1474 | |
| 34 | 34 | #include "devices/mflopimg.h" |
| 35 | 35 | |
| 36 | 36 | #define MAX_FLOPPIES 4 |
| 37 | #define TI99DSK_TAG "ti99dsktag" |
| 37 | 38 | |
| 38 | 39 | static int use_80_track_drives; |
| 39 | 40 | |
| 41 | /* defines for DRQ_IRQ_status */ |
| 42 | enum |
| 43 | { |
| 44 | fdc_IRQ = 1, |
| 45 | fdc_DRQ = 2 |
| 46 | }; |
| 47 | |
| 48 | /* current state of the DRQ and IRQ lines */ |
| 49 | static int DRQ_IRQ_status; |
| 50 | |
| 51 | /* when TRUE the CPU is halted while DRQ/IRQ are true */ |
| 52 | static int DSKhold; |
| 53 | /* disk selection bits */ |
| 54 | static int DSEL; |
| 55 | /* currently selected disk unit */ |
| 56 | static int DSKnum; |
| 57 | /* current side */ |
| 58 | static int DSKside; |
| 59 | /* 1 if motor is on */ |
| 60 | static int DVENA; |
| 61 | /* on rising edge, sets DVENA for 4.23 seconds on rising edge */ |
| 62 | static int motor_on; |
| 63 | /* count 4.23s from rising edge of motor_on */ |
| 64 | void *motor_on_timer; |
| 65 | |
| 66 | /* |
| 67 | call this when the state of DSKhold or DRQ/IRQ or DVENA change |
| 68 | |
| 69 | Emulation is faulty because the CPU is actually stopped in the midst of |
| 70 | instruction, at the end of the memory access |
| 71 | */ |
| 72 | static void fdc_handle_hold(void) |
| 73 | { |
| 74 | if (DSKhold && (!DRQ_IRQ_status) && DVENA) |
| 75 | cpunum_set_input_line(0, INPUT_LINE_HALT, ASSERT_LINE); |
| 76 | else |
| 77 | cpunum_set_input_line(0, INPUT_LINE_HALT, CLEAR_LINE); |
| 78 | } |
| 79 | |
| 80 | /* |
| 81 | callback called at the end of DVENA pulse |
| 82 | */ |
| 83 | static TIMER_CALLBACK(motor_on_timer_callback) |
| 84 | { |
| 85 | DVENA = 0; |
| 86 | fdc_handle_hold(); |
| 87 | } |
| 88 | |
| 40 | 89 | typedef struct ti99_geometry |
| 41 | 90 | { |
| 42 | 91 | UINT8 sides; |
| r1473 | r1474 | |
| 45 | 94 | UINT8 density; |
| 46 | 95 | } ti99_geometry; |
| 47 | 96 | |
| 97 | static void hfdc_int_callback(int which, int state); |
| 98 | static int hfdc_select_callback(int which, select_mode_t select_mode, int select_line, int gpos); |
| 99 | static UINT8 hfdc_dma_read_callback(int which, offs_t offset); |
| 100 | static void hfdc_dma_write_callback(int which, offs_t offset, UINT8 data); |
| 48 | 101 | |
| 49 | | #define TI99DSK_TAG "ti99dsktag" |
| 102 | static const smc92x4_intf hfdc_intf = |
| 103 | { |
| 104 | hfdc_select_callback, |
| 105 | hfdc_dma_read_callback, |
| 106 | hfdc_dma_write_callback, |
| 107 | hfdc_int_callback |
| 108 | }; |
| 50 | 109 | |
| 51 | 110 | /* |
| 52 | 111 | Convert physical sector address to sector offset in disk image |
| r1473 | r1474 | |
| 76 | 135 | static int ti99_tracktranslate(mess_image *image, floppy_image *floppy, int physical_track) |
| 77 | 136 | { |
| 78 | 137 | struct ti99_geometry *geometry; |
| 79 | | |
| 80 | 138 | geometry = floppy_tag(floppy, TI99DSK_TAG); |
| 81 | 139 | |
| 82 | 140 | if (use_80_track_drives && (geometry->tracksperside <= 40)) |
| r1473 | r1474 | |
| 267 | 325 | int success; |
| 268 | 326 | floperr_t err; |
| 269 | 327 | |
| 270 | | /* Prevents internal_floppy_device_load (mflopimg) to set the drive |
| 271 | | geometry to the medium geometry. TI disk controllers determine the |
| 272 | | number of tracks from a field in sector 0, and if the medium has |
| 273 | | 40 tracks but the drive has 80, the DSR ROM automatically |
| 274 | | double-steps the tracks. |
| 275 | | */ |
| 276 | | floppy_keep_drive_geometry(); |
| 277 | | |
| 278 | 328 | geometry1 = floppy_create_tag(floppy, TI99DSK_TAG, sizeof(*geometry1)); |
| 279 | 329 | |
| 280 | 330 | ti99_guess_geometry(floppy, geometry1, NULL, &success); |
| r1473 | r1474 | |
| 312 | 362 | } |
| 313 | 363 | } |
| 314 | 364 | |
| 365 | /* |
| 366 | callback called whenever DRQ/IRQ state change |
| 367 | */ |
| 368 | static void fdc_callback(wd17xx_state_t event, void *param) |
| 369 | { |
| 370 | switch (event) |
| 371 | { |
| 372 | case WD17XX_IRQ_CLR: |
| 373 | DRQ_IRQ_status &= ~fdc_IRQ; |
| 374 | ti99_peb_set_ilb_bit(intb_fdc_bit, 0); |
| 375 | break; |
| 376 | case WD17XX_IRQ_SET: |
| 377 | DRQ_IRQ_status |= fdc_IRQ; |
| 378 | ti99_peb_set_ilb_bit(intb_fdc_bit, 1); |
| 379 | break; |
| 380 | case WD17XX_DRQ_CLR: |
| 381 | DRQ_IRQ_status &= ~fdc_DRQ; |
| 382 | break; |
| 383 | case WD17XX_DRQ_SET: |
| 384 | DRQ_IRQ_status |= fdc_DRQ; |
| 385 | break; |
| 386 | } |
| 315 | 387 | |
| 388 | fdc_handle_hold(); |
| 389 | } |
| 390 | |
| 391 | /* |
| 392 | Initializes all available controllers. This routine is only used in the |
| 393 | init state of the emulator. During the normal operation, only the |
| 394 | reset routines are used. |
| 395 | */ |
| 396 | void ti99_floppy_controllers_init_all(void) |
| 397 | { |
| 398 | /* initialize the controller chip for TI FDC, CC, BwG */ |
| 399 | wd17xx_init(WD_TYPE_179X, fdc_callback, NULL); |
| 400 | |
| 401 | /* initialize the controller chip for HFDC */ |
| 402 | smc92x4_init(0, & hfdc_intf); |
| 403 | |
| 404 | ti99_install_tracktranslate_procs(); |
| 405 | |
| 406 | motor_on_timer = timer_alloc(motor_on_timer_callback, NULL); |
| 407 | |
| 408 | /* initialize the RTC for BwG and HFDC */ |
| 409 | mm58274c_init(1, 1); |
| 410 | } |
| 411 | |
| 316 | 412 | /*===========================================================================*/ |
| 317 | 413 | /* |
| 318 | 414 | TI99/4(a) Floppy disk controller card emulation |
| r1473 | r1474 | |
| 329 | 425 | /* pointer to the fdc ROM data */ |
| 330 | 426 | static UINT8 *ti99_disk_DSR; |
| 331 | 427 | |
| 332 | | /* when TRUE the CPU is halted while DRQ/IRQ are true */ |
| 333 | | static int DSKhold; |
| 334 | | |
| 335 | | /* defines for DRQ_IRQ_status */ |
| 336 | | enum |
| 337 | | { |
| 338 | | fdc_IRQ = 1, |
| 339 | | fdc_DRQ = 2 |
| 340 | | }; |
| 341 | | |
| 342 | | /* current state of the DRQ and IRQ lines */ |
| 343 | | static int DRQ_IRQ_status; |
| 344 | | |
| 345 | | /* disk selection bits */ |
| 346 | | static int DSEL; |
| 347 | | /* currently selected disk unit */ |
| 348 | | static int DSKnum; |
| 349 | | /* current side */ |
| 350 | | static int DSKside; |
| 351 | | |
| 352 | | /* 1 if motor is on */ |
| 353 | | static int DVENA; |
| 354 | | /* on rising edge, sets DVENA for 4.23 seconds on rising edge */ |
| 355 | | static int motor_on; |
| 356 | | /* count 4.23s from rising edge of motor_on */ |
| 357 | | static void *motor_on_timer; |
| 358 | | |
| 359 | 428 | static const ti99_peb_card_handlers_t fdc_handlers = |
| 360 | 429 | { |
| 361 | 430 | fdc_cru_r, |
| r1473 | r1474 | |
| 364 | 433 | fdc_mem_w |
| 365 | 434 | }; |
| 366 | 435 | |
| 367 | | |
| 368 | 436 | /* |
| 369 | 437 | Reset fdc card, set up handlers |
| 370 | 438 | */ |
| 371 | | void ti99_fdc_init(void) |
| 372 | | { |
| 373 | | wd17xx_init(WD_TYPE_179X, fdc_callback, NULL); /* initialize the floppy disk controller */ |
| 374 | | ti99_install_tracktranslate_procs(); |
| 375 | | motor_on_timer = timer_alloc(motor_on_timer_callback, NULL); |
| 376 | | use_80_track_drives = FALSE; |
| 377 | | } |
| 378 | | |
| 379 | | /* |
| 380 | | Reset fdc card, set up handlers |
| 381 | | */ |
| 382 | 439 | void ti99_fdc_reset(void) |
| 383 | 440 | { |
| 384 | 441 | ti99_disk_DSR = memory_region(region_dsr) + offset_fdc_dsr; |
| r1473 | r1474 | |
| 388 | 445 | |
| 389 | 446 | DVENA = 0; |
| 390 | 447 | motor_on = 0; |
| 448 | |
| 449 | use_80_track_drives = FALSE; |
| 450 | |
| 391 | 451 | ti99_peb_set_card_handlers(0x1100, & fdc_handlers); |
| 392 | 452 | wd17xx_reset(); /* resets the fdc */ |
| 393 | 453 | wd17xx_set_density(DEN_FM_LO); |
| 394 | 454 | } |
| 395 | 455 | |
| 396 | | |
| 397 | 456 | /* |
| 398 | | call this when the state of DSKhold or DRQ/IRQ or DVENA change |
| 399 | | |
| 400 | | Emulation is faulty because the CPU is actually stopped in the midst of instruction, at |
| 401 | | the end of the memory access |
| 402 | | */ |
| 403 | | static void fdc_handle_hold(void) |
| 404 | | { |
| 405 | | if (DSKhold && (!DRQ_IRQ_status) && DVENA) |
| 406 | | cpunum_set_input_line(0, INPUT_LINE_HALT, ASSERT_LINE); |
| 407 | | else |
| 408 | | cpunum_set_input_line(0, INPUT_LINE_HALT, CLEAR_LINE); |
| 409 | | } |
| 410 | | |
| 411 | | /* |
| 412 | | callback called whenever DRQ/IRQ state change |
| 413 | | */ |
| 414 | | static void fdc_callback(wd17xx_state_t event, void *param) |
| 415 | | { |
| 416 | | switch (event) |
| 417 | | { |
| 418 | | case WD17XX_IRQ_CLR: |
| 419 | | DRQ_IRQ_status &= ~fdc_IRQ; |
| 420 | | ti99_peb_set_ilb_bit(intb_fdc_bit, 0); |
| 421 | | break; |
| 422 | | case WD17XX_IRQ_SET: |
| 423 | | DRQ_IRQ_status |= fdc_IRQ; |
| 424 | | ti99_peb_set_ilb_bit(intb_fdc_bit, 1); |
| 425 | | break; |
| 426 | | case WD17XX_DRQ_CLR: |
| 427 | | DRQ_IRQ_status &= ~fdc_DRQ; |
| 428 | | break; |
| 429 | | case WD17XX_DRQ_SET: |
| 430 | | DRQ_IRQ_status |= fdc_DRQ; |
| 431 | | break; |
| 432 | | } |
| 433 | | |
| 434 | | fdc_handle_hold(); |
| 435 | | } |
| 436 | | |
| 437 | | /* |
| 438 | | callback called at the end of DVENA pulse |
| 439 | | */ |
| 440 | | static TIMER_CALLBACK(motor_on_timer_callback) |
| 441 | | { |
| 442 | | DVENA = 0; |
| 443 | | fdc_handle_hold(); |
| 444 | | } |
| 445 | | |
| 446 | | /* |
| 447 | 457 | Read disk CRU interface |
| 448 | 458 | |
| 449 | 459 | bit 0: HLD pin |
| r1473 | r1474 | |
| 632 | 642 | ccfdc_mem_w |
| 633 | 643 | }; |
| 634 | 644 | |
| 635 | | |
| 636 | | /* |
| 637 | | Reset fdc card, set up handlers |
| 638 | | */ |
| 639 | | void ti99_ccfdc_init(void) |
| 640 | | { |
| 641 | | wd17xx_init(WD_TYPE_179X, fdc_callback, NULL); /* initialize the floppy disk controller */ |
| 642 | | motor_on_timer = timer_alloc(motor_on_timer_callback, NULL); |
| 643 | | ti99_install_tracktranslate_procs(); |
| 644 | | use_80_track_drives = FALSE; |
| 645 | | } |
| 646 | | |
| 647 | 645 | void ti99_ccfdc_reset(void) |
| 648 | 646 | { |
| 649 | 647 | ti99_disk_DSR = memory_region(region_dsr) + offset_ccfdc_dsr; |
| r1473 | r1474 | |
| 654 | 652 | DVENA = 0; |
| 655 | 653 | motor_on = 0; |
| 656 | 654 | |
| 655 | use_80_track_drives = FALSE; |
| 656 | |
| 657 | 657 | ti99_peb_set_card_handlers(0x1100, & ccfdc_handlers); |
| 658 | 658 | |
| 659 | 659 | wd17xx_reset(); /* initialize the floppy disk controller */ |
| r1473 | r1474 | |
| 853 | 853 | /* |
| 854 | 854 | Reset fdc card, set up handlers |
| 855 | 855 | */ |
| 856 | | void ti99_bwg_init(void) |
| 857 | | { |
| 858 | | wd17xx_init(WD_TYPE_179X, fdc_callback, NULL); /* initialize the floppy disk controller */ |
| 859 | | mm58274c_init(1, 1); /* initialize the RTC */ |
| 860 | | motor_on_timer = timer_alloc(motor_on_timer_callback, NULL); |
| 861 | | ti99_install_tracktranslate_procs(); |
| 862 | | use_80_track_drives = FALSE; |
| 863 | | } |
| 864 | | |
| 865 | 856 | void ti99_bwg_reset(void) |
| 866 | 857 | { |
| 867 | 858 | ti99_disk_DSR = memory_region(region_dsr) + offset_bwg_dsr; |
| r1473 | r1474 | |
| 876 | 867 | |
| 877 | 868 | DVENA = 0; |
| 878 | 869 | motor_on = 0; |
| 870 | |
| 871 | use_80_track_drives = FALSE; |
| 872 | |
| 879 | 873 | ti99_peb_set_card_handlers(0x1100, & bwg_handlers); |
| 880 | 874 | |
| 881 | 875 | wd17xx_reset(); /* initialize the floppy disk controller */ |
| r1473 | r1474 | |
| 1066 | 1060 | break; |
| 1067 | 1061 | } |
| 1068 | 1062 | } |
| 1069 | | |
| 1070 | 1063 | return reply; |
| 1071 | 1064 | } |
| 1072 | 1065 | |
| r1473 | r1474 | |
| 1150 | 1143 | static UINT8 *hfdc_ram; |
| 1151 | 1144 | static int hfdc_irq_state; |
| 1152 | 1145 | |
| 1153 | | |
| 1154 | | static int hfdc_select_callback(int which, select_mode_t select_mode, int select_line, int gpos); |
| 1155 | | static UINT8 hfdc_dma_read_callback(int which, offs_t offset); |
| 1156 | | static void hfdc_dma_write_callback(int which, offs_t offset, UINT8 data); |
| 1157 | | static void hfdc_int_callback(int which, int state); |
| 1158 | | |
| 1159 | | static const smc92x4_intf hfdc_intf = |
| 1160 | | { |
| 1161 | | hfdc_select_callback, |
| 1162 | | hfdc_dma_read_callback, |
| 1163 | | hfdc_dma_write_callback, |
| 1164 | | hfdc_int_callback |
| 1165 | | }; |
| 1166 | | |
| 1167 | 1146 | /* |
| 1168 | 1147 | Select the correct HFDC disk units. |
| 1169 | 1148 | floppy disks are selected by the 4 gpos instead of the select lines. |
| r1473 | r1474 | |
| 1246 | 1225 | /* |
| 1247 | 1226 | Reset fdc card, set up handlers |
| 1248 | 1227 | */ |
| 1249 | | void ti99_hfdc_init(void) |
| 1250 | | { |
| 1251 | | /* initialize the floppy disk controller */ |
| 1252 | | smc92x4_init(0, & hfdc_intf); |
| 1253 | | mm58274c_init(1, 1); /* initialize the RTC */ |
| 1254 | | motor_on_timer = timer_alloc(motor_on_timer_callback, NULL); |
| 1255 | | ti99_install_tracktranslate_procs(); |
| 1256 | | use_80_track_drives = TRUE; |
| 1257 | | } |
| 1258 | | |
| 1259 | | |
| 1260 | 1228 | void ti99_hfdc_reset(void) |
| 1261 | 1229 | { |
| 1262 | 1230 | ti99_disk_DSR = memory_region(region_dsr) + offset_hfdc_dsr; |
| r1473 | r1474 | |
| 1274 | 1242 | |
| 1275 | 1243 | ti99_peb_set_card_handlers(0x1100, & hfdc_handlers); |
| 1276 | 1244 | |
| 1245 | use_80_track_drives = TRUE; |
| 1246 | |
| 1277 | 1247 | smc92x4_reset(0); |
| 1278 | 1248 | } |
| 1279 | 1249 | |