1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912
|
/* ui.c: User interface routines, but those which are independent of any UI
Copyright (c) 2002 Philip Kendall
$Id: ui.c 4835 2012-12-31 15:35:45Z zubzero $
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Author contact information:
E-mail: philip-fuse@shadowmagic.org.uk
*/
#include <config.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <libspectrum.h>
#include "fuse.h"
#include "peripherals/if1.h"
#include "peripherals/kempmouse.h"
#include "settings.h"
#include "tape.h"
#include "ui/ui.h"
#include "ui/widget/widget.h"
#define MESSAGE_MAX_LENGTH 256
/* We don't start in a widget */
int ui_widget_level = -1;
static char last_message[ MESSAGE_MAX_LENGTH ] = "";
static size_t frames_since_last_message = 0;
static int
print_error_to_stderr( ui_error_level severity, const char *message );
int
ui_error( ui_error_level severity, const char *format, ... )
{
int error;
va_list ap;
va_start( ap, format );
error = ui_verror( severity, format, ap );
va_end( ap );
return error;
}
int
ui_verror( ui_error_level severity, const char *format, va_list ap )
{
char message[ MESSAGE_MAX_LENGTH ];
vsnprintf( message, MESSAGE_MAX_LENGTH, format, ap );
/* Skip the message if the same message was displayed recently */
if( frames_since_last_message < 50 && !strcmp( message, last_message ) ) {
frames_since_last_message = 0;
return 0;
}
/* And store the 'last message' */
strncpy( last_message, message, MESSAGE_MAX_LENGTH );
#ifndef UI_WIN32
print_error_to_stderr( severity, message );
#endif /* #ifndef UI_WIN32 */
/* Do any UI-specific bits as well */
ui_error_specific( severity, message );
return 0;
}
ui_confirm_save_t
ui_confirm_save( const char *format, ... )
{
va_list ap;
char message[ MESSAGE_MAX_LENGTH ];
ui_confirm_save_t confirm;
va_start( ap, format );
vsnprintf( message, MESSAGE_MAX_LENGTH, format, ap );
confirm = ui_confirm_save_specific( message );
va_end( ap );
return confirm;
}
static int
print_error_to_stderr( ui_error_level severity, const char *message )
{
/* Print the error to stderr if it's more significant than just
informational */
if( severity > UI_ERROR_INFO ) {
/* For the fb and svgalib UIs, we don't want to write to stderr if
it's a terminal, as it's then likely to be what we're currently
using for graphics output, and writing text to it isn't a good
idea. Things are OK if we're exiting though */
#if defined( UI_FB ) || defined( UI_SVGA )
if( isatty( STDERR_FILENO ) && !fuse_exiting ) return 1;
#endif /* #if defined( UI_FB ) || defined( UI_SVGA ) */
fprintf( stderr, "%s: ", fuse_progname );
switch( severity ) {
case UI_ERROR_INFO: break; /* Shouldn't happen */
case UI_ERROR_WARNING: fprintf( stderr, "warning: " ); break;
case UI_ERROR_ERROR: fprintf( stderr, "error: " ); break;
}
fprintf( stderr, "%s\n", message );
}
return 0;
}
libspectrum_error
ui_libspectrum_error( libspectrum_error error GCC_UNUSED, const char *format,
va_list ap )
{
char new_format[ 257 ];
snprintf( new_format, 256, "libspectrum: %s", format );
ui_verror( UI_ERROR_ERROR, new_format, ap );
return LIBSPECTRUM_ERROR_NONE;
}
void
ui_error_frame( void )
{
frames_since_last_message++;
}
int ui_mouse_present = 0;
int ui_mouse_grabbed = 0;
static int mouse_grab_suspended = 0;
void
ui_mouse_button( int button, int down )
{
if( !ui_mouse_grabbed && !mouse_grab_suspended ) button = 2;
int kempston_button = !settings_current.mouse_swap_buttons;
/* Possibly we'll end up handling _more_ than one mouse interface... */
switch( button ) {
case 1:
if( ui_mouse_grabbed ) kempmouse_update( 0, 0, kempston_button, down );
break;
case 3:
if( ui_mouse_grabbed ) kempmouse_update( 0, 0, !kempston_button, down );
break;
case 2:
if( ui_mouse_present && settings_current.kempston_mouse
&& !down && !mouse_grab_suspended )
ui_mouse_grabbed =
ui_mouse_grabbed ? ui_mouse_release( 1 ) : ui_mouse_grab( 0 );
break;
}
}
void
ui_mouse_motion( int x, int y )
{
if( ui_mouse_grabbed ) kempmouse_update( x, y, -1, 0 );
}
void
ui_mouse_suspend( void )
{
mouse_grab_suspended = ui_mouse_grabbed ? 2 : 1;
ui_mouse_grabbed = ui_mouse_release( 1 );
}
void
ui_mouse_resume( void )
{
if( mouse_grab_suspended == 2) ui_mouse_grabbed = ui_mouse_grab( 0 );
mouse_grab_suspended = 0;
}
struct menu_item_entries {
ui_menu_item item;
const char *string1;
const char *string2; int string2_inverted;
const char *string3; int string3_inverted;
const char *string4; int string4_inverted;
const char *string5; int string5_inverted;
const char *string6; int string6_inverted;
const char *string7; int string7_inverted;
};
static const struct menu_item_entries menu_item_lookup[] = {
{ UI_MENU_ITEM_FILE_MOVIE_RECORDING, "/File/Movie/Stop",
"/File/Movie/Pause", 0,
"/File/Movie/Continue", 0,
"/File/Movie/Record...", 1,
"/File/Movie/Record from RZX...", 1
},
{ UI_MENU_ITEM_FILE_MOVIE_PAUSE, "/File/Movie/Pause",
"/File/Movie/Continue", 1,
},
{ UI_MENU_ITEM_MACHINE_PROFILER, "/Machine/Profiler/Stop",
"/Machine/Profiler/Start", 1 },
{ UI_MENU_ITEM_MEDIA_CARTRIDGE, "/Media/Cartridge" },
{ UI_MENU_ITEM_MEDIA_CARTRIDGE_DOCK, "/Media/Cartridge/Timex Dock" },
{ UI_MENU_ITEM_MEDIA_CARTRIDGE_DOCK_EJECT,
"/Media/Cartridge/Timex Dock/Eject" },
{ UI_MENU_ITEM_MEDIA_IF1, "/Media/Interface 1" },
{ UI_MENU_ITEM_MEDIA_IF1_M1_EJECT,
"/Media/Interface 1/Microdrive 1/Eject",
"/Media/Interface 1/Microdrive 1/Save As...", 0,
"/Media/Interface 1/Microdrive 1/Save", 0,
"/Media/Interface 1/Microdrive 1/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_IF1_M1_WP_SET,
"/Media/Interface 1/Microdrive 1/Write protect/Enable",
"/Media/Interface 1/Microdrive 1/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IF1_M2_EJECT,
"/Media/Interface 1/Microdrive 2/Eject",
"/Media/Interface 1/Microdrive 2/Save As...", 0,
"/Media/Interface 1/Microdrive 2/Save", 0,
"/Media/Interface 1/Microdrive 2/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_IF1_M2_WP_SET,
"/Media/Interface 1/Microdrive 2/Write protect/Enable",
"/Media/Interface 1/Microdrive 2/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IF1_M3_EJECT,
"/Media/Interface 1/Microdrive 3/Eject",
"/Media/Interface 1/Microdrive 3/Save As...", 0,
"/Media/Interface 1/Microdrive 3/Save", 0,
"/Media/Interface 1/Microdrive 3/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_IF1_M3_WP_SET,
"/Media/Interface 1/Microdrive 3/Write protect/Enable",
"/Media/Interface 1/Microdrive 3/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IF1_M4_EJECT,
"/Media/Interface 1/Microdrive 4/Eject",
"/Media/Interface 1/Microdrive 4/Save As...", 0,
"/Media/Interface 1/Microdrive 4/Save", 0,
"/Media/Interface 1/Microdrive 4/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_IF1_M4_WP_SET,
"/Media/Interface 1/Microdrive 4/Write protect/Enable",
"/Media/Interface 1/Microdrive 4/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IF1_M5_EJECT,
"/Media/Interface 1/Microdrive 5/Eject",
"/Media/Interface 1/Microdrive 5/Save As...", 0,
"/Media/Interface 1/Microdrive 5/Save", 0,
"/Media/Interface 1/Microdrive 5/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_IF1_M5_WP_SET,
"/Media/Interface 1/Microdrive 5/Write protect/Enable",
"/Media/Interface 1/Microdrive 5/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IF1_M6_EJECT,
"/Media/Interface 1/Microdrive 6/Eject",
"/Media/Interface 1/Microdrive 6/Save As...", 0,
"/Media/Interface 1/Microdrive 6/Save", 0,
"/Media/Interface 1/Microdrive 6/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_IF1_M6_WP_SET,
"/Media/Interface 1/Microdrive 6/Write protect/Enable",
"/Media/Interface 1/Microdrive 6/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IF1_M7_EJECT,
"/Media/Interface 1/Microdrive 7/Eject",
"/Media/Interface 1/Microdrive 7/Save As...", 0,
"/Media/Interface 1/Microdrive 7/Save", 0,
"/Media/Interface 1/Microdrive 7/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_IF1_M7_WP_SET,
"/Media/Interface 1/Microdrive 7/Write protect/Enable",
"/Media/Interface 1/Microdrive 7/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IF1_M8_EJECT,
"/Media/Interface 1/Microdrive 8/Eject",
"/Media/Interface 1/Microdrive 8/Save As...", 0,
"/Media/Interface 1/Microdrive 8/Save", 0,
"/Media/Interface 1/Microdrive 8/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_IF1_M8_WP_SET,
"/Media/Interface 1/Microdrive 8/Write protect/Enable",
"/Media/Interface 1/Microdrive 8/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IF1_RS232_UNPLUG_R,
"/Media/Interface 1/RS232/Unplug RxD" },
{ UI_MENU_ITEM_MEDIA_IF1_RS232_UNPLUG_T,
"/Media/Interface 1/RS232/Unplug TxD" },
{ UI_MENU_ITEM_MEDIA_IF1_SNET_UNPLUG,
"/Media/Interface 1/Sinclair NET/Unplug" },
{ UI_MENU_ITEM_MEDIA_CARTRIDGE_IF2, "/Media/Cartridge/Interface 2" },
{ UI_MENU_ITEM_MEDIA_CARTRIDGE_IF2_EJECT,
"/Media/Cartridge/Interface 2/Eject" },
{ UI_MENU_ITEM_MEDIA_DISK, "/Media/Disk" },
{ UI_MENU_ITEM_MEDIA_DISK_PLUS3, "/Media/Disk/+3" },
{ UI_MENU_ITEM_MEDIA_DISK_PLUS3_A_EJECT,
"/Media/Disk/+3/Drive A:/Eject",
"/Media/Disk/+3/Drive A:/Save As...", 0,
"/Media/Disk/+3/Drive A:/Save", 0,
"/Media/Disk/+3/Drive A:/Flip disk", 0,
"/Media/Disk/+3/Drive A:/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUS3_A_FLIP_SET,
"/Media/Disk/+3/Drive A:/Flip disk/Turn upside down",
"/Media/Disk/+3/Drive A:/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUS3_A_WP_SET,
"/Media/Disk/+3/Drive A:/Write protect/Enable",
"/Media/Disk/+3/Drive A:/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUS3_B, "/Media/Disk/+3/Drive B:" },
{ UI_MENU_ITEM_MEDIA_DISK_PLUS3_B_EJECT,
"/Media/Disk/+3/Drive B:/Eject",
"/Media/Disk/+3/Drive B:/Save As...", 0,
"/Media/Disk/+3/Drive B:/Save", 0,
"/Media/Disk/+3/Drive B:/Flip disk", 0,
"/Media/Disk/+3/Drive B:/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUS3_B_FLIP_SET,
"/Media/Disk/+3/Drive B:/Flip disk/Turn upside down",
"/Media/Disk/+3/Drive B:/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUS3_B_WP_SET,
"/Media/Disk/+3/Drive B:/Write protect/Enable",
"/Media/Disk/+3/Drive B:/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA, "/Media/Disk/Beta" },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_A, "/Media/Disk/Beta/Drive A:" },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_A_EJECT,
"/Media/Disk/Beta/Drive A:/Eject",
"/Media/Disk/Beta/Drive A:/Save As...", 0,
"/Media/Disk/Beta/Drive A:/Save", 0,
"/Media/Disk/Beta/Drive A:/Flip disk", 0,
"/Media/Disk/Beta/Drive A:/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_A_FLIP_SET,
"/Media/Disk/Beta/Drive A:/Flip disk/Turn upside down",
"/Media/Disk/Beta/Drive A:/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_A_WP_SET,
"/Media/Disk/Beta/Drive A:/Write protect/Enable",
"/Media/Disk/Beta/Drive A:/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_B, "/Media/Disk/Beta/Drive B:" },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_B_EJECT,
"/Media/Disk/Beta/Drive B:/Eject",
"/Media/Disk/Beta/Drive B:/Save As...", 0,
"/Media/Disk/Beta/Drive B:/Save", 0,
"/Media/Disk/Beta/Drive B:/Flip disk", 0,
"/Media/Disk/Beta/Drive B:/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_B_FLIP_SET,
"/Media/Disk/Beta/Drive B:/Flip disk/Turn upside down",
"/Media/Disk/Beta/Drive B:/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_B_WP_SET,
"/Media/Disk/Beta/Drive B:/Write protect/Enable",
"/Media/Disk/Beta/Drive B:/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_C, "/Media/Disk/Beta/Drive C:" },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_C_EJECT,
"/Media/Disk/Beta/Drive C:/Eject",
"/Media/Disk/Beta/Drive C:/Save As...", 0,
"/Media/Disk/Beta/Drive C:/Save", 0,
"/Media/Disk/Beta/Drive C:/Flip disk", 0,
"/Media/Disk/Beta/Drive C:/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_C_FLIP_SET,
"/Media/Disk/Beta/Drive C:/Flip disk/Turn upside down",
"/Media/Disk/Beta/Drive C:/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_C_WP_SET,
"/Media/Disk/Beta/Drive C:/Write protect/Enable",
"/Media/Disk/Beta/Drive C:/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_D, "/Media/Disk/Beta/Drive D:" },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_D_EJECT,
"/Media/Disk/Beta/Drive D:/Eject",
"/Media/Disk/Beta/Drive D:/Save As...", 0,
"/Media/Disk/Beta/Drive D:/Save", 0,
"/Media/Disk/Beta/Drive D:/Flip disk", 0,
"/Media/Disk/Beta/Drive D:/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_D_FLIP_SET,
"/Media/Disk/Beta/Drive D:/Flip disk/Turn upside down",
"/Media/Disk/Beta/Drive D:/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_BETA_D_WP_SET,
"/Media/Disk/Beta/Drive D:/Write protect/Enable",
"/Media/Disk/Beta/Drive D:/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD, "/Media/Disk/+D" },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD_1, "/Media/Disk/+D/Drive 1" },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD_1_EJECT,
"/Media/Disk/+D/Drive 1/Eject",
"/Media/Disk/+D/Drive 1/Save As...", 0,
"/Media/Disk/+D/Drive 1/Save", 0,
"/Media/Disk/+D/Drive 1/Flip disk", 0,
"/Media/Disk/+D/Drive 1/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD_1_FLIP_SET,
"/Media/Disk/+D/Drive 1/Flip disk/Turn upside down",
"/Media/Disk/+D/Drive 1/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD_1_WP_SET,
"/Media/Disk/+D/Drive 1/Write protect/Enable",
"/Media/Disk/+D/Drive 1/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD_2, "/Media/Disk/+D/Drive 2" },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD_2_EJECT,
"/Media/Disk/+D/Drive 2/Eject",
"/Media/Disk/+D/Drive 2/Save As...", 0,
"/Media/Disk/+D/Drive 2/Save", 0,
"/Media/Disk/+D/Drive 2/Flip disk", 0,
"/Media/Disk/+D/Drive 2/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD_2_FLIP_SET,
"/Media/Disk/+D/Drive 2/Flip disk/Turn upside down",
"/Media/Disk/+D/Drive 2/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_PLUSD_2_WP_SET,
"/Media/Disk/+D/Drive 2/Write protect/Enable",
"/Media/Disk/+D/Drive 2/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE, "/Media/Disk/DISCiPLE" },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_1, "/Media/Disk/DISCiPLE/Drive 1" },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_1_EJECT,
"/Media/Disk/DISCiPLE/Drive 1/Eject",
"/Media/Disk/DISCiPLE/Drive 1/Save As...", 0,
"/Media/Disk/DISCiPLE/Drive 1/Save", 0,
"/Media/Disk/DISCiPLE/Drive 1/Flip disk", 0,
"/Media/Disk/DISCiPLE/Drive 1/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_1_FLIP_SET,
"/Media/Disk/DISCiPLE/Drive 1/Flip disk/Turn upside down",
"/Media/Disk/DISCiPLE/Drive 1/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_1_WP_SET,
"/Media/Disk/DISCiPLE/Drive 1/Write protect/Enable",
"/Media/Disk/DISCiPLE/Drive 1/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_2, "/Media/Disk/DISCiPLE/Drive 2" },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_2_EJECT,
"/Media/Disk/DISCiPLE/Drive 2/Eject",
"/Media/Disk/DISCiPLE/Drive 2/Save As...", 0,
"/Media/Disk/DISCiPLE/Drive 2/Save", 0,
"/Media/Disk/DISCiPLE/Drive 2/Flip disk", 0,
"/Media/Disk/DISCiPLE/Drive 2/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_2_FLIP_SET,
"/Media/Disk/DISCiPLE/Drive 2/Flip disk/Turn upside down",
"/Media/Disk/DISCiPLE/Drive 2/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_DISCIPLE_2_WP_SET,
"/Media/Disk/DISCiPLE/Drive 2/Write protect/Enable",
"/Media/Disk/DISCiPLE/Drive 2/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS, "/Media/Disk/Opus" },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS_1, "/Media/Disk/Opus/Drive 1" },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS_1_EJECT,
"/Media/Disk/Opus/Drive 1/Eject",
"/Media/Disk/Opus/Drive 1/Save As...", 0,
"/Media/Disk/Opus/Drive 1/Save", 0,
"/Media/Disk/Opus/Drive 1/Flip disk", 0,
"/Media/Disk/Opus/Drive 1/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS_1_FLIP_SET,
"/Media/Disk/Opus/Drive 1/Flip disk/Turn upside down",
"/Media/Disk/Opus/Drive 1/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS_1_WP_SET,
"/Media/Disk/Opus/Drive 1/Write protect/Enable",
"/Media/Disk/Opus/Drive 1/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS_2, "/Media/Disk/Opus/Drive 2" },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS_2_EJECT,
"/Media/Disk/Opus/Drive 2/Eject",
"/Media/Disk/Opus/Drive 2/Save As...", 0,
"/Media/Disk/Opus/Drive 2/Save", 0,
"/Media/Disk/Opus/Drive 2/Flip disk", 0,
"/Media/Disk/Opus/Drive 2/Write protect", 0 },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS_2_FLIP_SET,
"/Media/Disk/Opus/Drive 2/Flip disk/Turn upside down",
"/Media/Disk/Opus/Drive 2/Flip disk/Turn back", 1 },
{ UI_MENU_ITEM_MEDIA_DISK_OPUS_2_WP_SET,
"/Media/Disk/Opus/Drive 2/Write protect/Enable",
"/Media/Disk/Opus/Drive 2/Write protect/Disable", 1 },
{ UI_MENU_ITEM_MEDIA_IDE, "/Media/IDE" },
{ UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT, "/Media/IDE/Simple 8-bit" },
{ UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT_MASTER_EJECT,
"/Media/IDE/Simple 8-bit/Master/Commit",
"/Media/IDE/Simple 8-bit/Master/Eject", 0 },
{ UI_MENU_ITEM_MEDIA_IDE_SIMPLE8BIT_SLAVE_EJECT,
"/Media/IDE/Simple 8-bit/Slave/Commit",
"/Media/IDE/Simple 8-bit/Slave/Eject", 0 },
{ UI_MENU_ITEM_MEDIA_IDE_ZXATASP, "/Media/IDE/ZXATASP" },
{ UI_MENU_ITEM_MEDIA_IDE_ZXATASP_MASTER_EJECT,
"/Media/IDE/ZXATASP/Master/Commit",
"/Media/IDE/ZXATASP/Master/Eject", 0 },
{ UI_MENU_ITEM_MEDIA_IDE_ZXATASP_SLAVE_EJECT,
"/Media/IDE/ZXATASP/Slave/Commit",
"/Media/IDE/ZXATASP/Slave/Eject", 0 },
{ UI_MENU_ITEM_MEDIA_IDE_ZXCF, "/Media/IDE/ZXCF CompactFlash" },
{ UI_MENU_ITEM_MEDIA_IDE_ZXCF_EJECT,
"/Media/IDE/ZXCF CompactFlash/Commit",
"/Media/IDE/ZXCF CompactFlash/Eject", 0 },
{ UI_MENU_ITEM_MEDIA_IDE_DIVIDE, "/Media/IDE/DivIDE" },
{ UI_MENU_ITEM_MEDIA_IDE_DIVIDE_MASTER_EJECT,
"/Media/IDE/DivIDE/Master/Commit",
"/Media/IDE/DivIDE/Master/Eject", 0 },
{ UI_MENU_ITEM_MEDIA_IDE_DIVIDE_SLAVE_EJECT,
"/Media/IDE/DivIDE/Slave/Commit",
"/Media/IDE/DivIDE/Slave/Eject", 0 },
{ UI_MENU_ITEM_RECORDING,
"/File/Recording/Stop",
"/File/Recording/Record...", 1,
"/File/Recording/Record from snapshot...", 1,
"/File/Recording/Play...", 1 },
{ UI_MENU_ITEM_RECORDING_ROLLBACK,
"/File/Recording/Insert snapshot",
"/File/Recording/Rollback", 0,
"/File/Recording/Rollback to...", 0 },
{ UI_MENU_ITEM_AY_LOGGING,
"/File/AY Logging/Stop",
"/File/AY Logging/Record...", 1, },
{ UI_MENU_ITEM_TAPE_RECORDING,
"/Media/Tape/Record Stop",
"/Media/Tape/Record Start", 1,
"/Media/Tape/Open...", 1,
"/Media/Tape/Play", 1,
"/Media/Tape/Rewind", 1,
"/Media/Tape/Clear", 1,
"/Media/Tape/Write...", 1 },
{ UI_MENU_ITEM_TAPE_RECORDING, NULL }, /* End marker */
};
int
ui_menu_activate( ui_menu_item item, int active )
{
const struct menu_item_entries *ptr;
for( ptr = menu_item_lookup; ptr->string1; ptr++ ) {
if( item == ptr->item ) {
ui_menu_item_set_active( ptr->string1, active );
if( ptr->string2 )
ui_menu_item_set_active( ptr->string2,
ptr->string2_inverted ? !active : active );
if( ptr->string3 )
ui_menu_item_set_active( ptr->string3,
ptr->string3_inverted ? !active : active );
if( ptr->string4 )
ui_menu_item_set_active( ptr->string4,
ptr->string4_inverted ? !active : active );
if( ptr->string5 )
ui_menu_item_set_active( ptr->string5,
ptr->string5_inverted ? !active : active );
if( ptr->string6 )
ui_menu_item_set_active( ptr->string6,
ptr->string6_inverted ? !active : active );
if( ptr->string7 )
ui_menu_item_set_active( ptr->string7,
ptr->string7_inverted ? !active : active );
return 0;
}
}
ui_error( UI_ERROR_ERROR, "ui_menu_activate: unknown item %d", item );
return 1;
}
void
ui_menu_disk_update( void )
{
int plus3, beta, plusd, opus, disciple;
int capabilities;
capabilities = machine_current->capabilities;
/* Set the disk menu items and statusbar appropriately */
plus3 = capabilities & LIBSPECTRUM_MACHINE_CAPABILITY_PLUS3_DISK;
beta = beta_available;
opus = opus_available;
plusd = plusd_available;
disciple = disciple_available;
if( plus3 || beta || opus || plusd || disciple ) {
ui_menu_activate( UI_MENU_ITEM_MEDIA_DISK, 1 );
ui_statusbar_update( UI_STATUSBAR_ITEM_DISK, UI_STATUSBAR_STATE_INACTIVE );
} else {
ui_menu_activate( UI_MENU_ITEM_MEDIA_DISK, 0 );
ui_statusbar_update( UI_STATUSBAR_ITEM_DISK,
UI_STATUSBAR_STATE_NOT_AVAILABLE );
}
ui_menu_activate( UI_MENU_ITEM_MEDIA_DISK_PLUS3, plus3 );
ui_menu_activate( UI_MENU_ITEM_MEDIA_DISK_BETA, beta );
ui_menu_activate( UI_MENU_ITEM_MEDIA_DISK_OPUS, opus );
ui_menu_activate( UI_MENU_ITEM_MEDIA_DISK_PLUSD, plusd );
ui_menu_activate( UI_MENU_ITEM_MEDIA_DISK_DISCIPLE, disciple );
}
int
ui_tape_write( void )
{
char *filename;
fuse_emulation_pause();
filename = ui_get_save_filename( "Fuse - Write Tape" );
if( !filename ) { fuse_emulation_unpause(); return 1; }
tape_write( filename );
libspectrum_free( filename );
fuse_emulation_unpause();
return 0;
}
int
ui_plus3_disk_write( specplus3_drive_number which, int saveas )
{
int err;
char drive, *filename = NULL, title[80];
switch( which ) {
case SPECPLUS3_DRIVE_A: drive = 'A'; break;
case SPECPLUS3_DRIVE_B: drive = 'B'; break;
default: drive = '?'; break;
}
fuse_emulation_pause();
snprintf( title, 80, "Fuse - Write +3 Disk %c:", drive );
if( saveas ) {
filename = ui_get_save_filename( title );
if( !filename ) { fuse_emulation_unpause(); return 1; }
}
err = specplus3_disk_write( which, filename );
if( saveas ) libspectrum_free( filename );
fuse_emulation_unpause();
return err;
}
int
ui_beta_disk_write( beta_drive_number which, int saveas )
{
int err;
char drive, *filename = NULL, title[80];
switch( which ) {
case BETA_DRIVE_A: drive = 'A'; break;
case BETA_DRIVE_B: drive = 'B'; break;
case BETA_DRIVE_C: drive = 'C'; break;
case BETA_DRIVE_D: drive = 'D'; break;
default: drive = '?'; break;
}
fuse_emulation_pause();
snprintf( title, 80, "Fuse - Write Beta Disk %c:", drive );
if( saveas ) {
filename = ui_get_save_filename( title );
if( !filename ) { fuse_emulation_unpause(); return 1; }
}
err = beta_disk_write( which, filename );
if( saveas ) libspectrum_free( filename );
fuse_emulation_unpause();
return err;
}
int
ui_opus_disk_write( opus_drive_number which, int saveas )
{
int err;
char drive, *filename = NULL, title[80];
switch( which ) {
case OPUS_DRIVE_1: drive = '1'; break;
case OPUS_DRIVE_2: drive = '2'; break;
default: drive = '?'; break;
}
fuse_emulation_pause();
snprintf( title, 80, "Fuse - Write Opus Disk %c", drive );
if( saveas ) {
filename = ui_get_save_filename( title );
if( !filename ) { fuse_emulation_unpause(); return 1; }
}
err = opus_disk_write( which, filename );
if( saveas ) libspectrum_free( filename );
fuse_emulation_unpause();
return err;
}
int
ui_plusd_disk_write( plusd_drive_number which, int saveas )
{
int err;
char drive, *filename = NULL, title[80];
switch( which ) {
case PLUSD_DRIVE_1: drive = '1'; break;
case PLUSD_DRIVE_2: drive = '2'; break;
default: drive = '?'; break;
}
fuse_emulation_pause();
snprintf( title, 80, "Fuse - Write +D Disk %c", drive );
if( saveas ) {
filename = ui_get_save_filename( title );
if( !filename ) { fuse_emulation_unpause(); return 1; }
}
err = plusd_disk_write( which, filename );
if( saveas ) libspectrum_free( filename );
fuse_emulation_unpause();
return err;
}
int
ui_disciple_disk_write( disciple_drive_number which, int saveas )
{
int err;
char drive, *filename = NULL, title[80];
switch( which ) {
case PLUSD_DRIVE_1: drive = '1'; break;
case PLUSD_DRIVE_2: drive = '2'; break;
default: drive = '?'; break;
}
fuse_emulation_pause();
snprintf( title, 80, "Fuse - Write DISCiPLE Disk %c", drive );
if( saveas ) {
filename = ui_get_save_filename( title );
if( !filename ) { fuse_emulation_unpause(); return 1; }
}
err = disciple_disk_write( which, filename );
if( saveas ) libspectrum_free( filename );
fuse_emulation_unpause();
return err;
}
int
ui_mdr_write( int which, int saveas )
{
int err;
char *filename = NULL, title[80];
fuse_emulation_pause();
snprintf( title, 80, "Fuse - Write Microdrive Cartridge %i", which + 1 );
if( saveas ) {
filename = ui_get_save_filename( title );
if( !filename ) { fuse_emulation_unpause(); return 1; }
}
err = if1_mdr_write( which, filename );
if( saveas ) libspectrum_free( filename );
fuse_emulation_unpause();
return err;
}
#ifdef USE_WIDGET
int
ui_widget_init( void )
{
return widget_init();
}
int
ui_widget_end( void )
{
return widget_end();
}
#else
int
ui_widget_init( void )
{
return 0;
}
int
ui_widget_end( void )
{
return 0;
}
void
ui_popup_menu( int native_key )
{
}
void
ui_widget_keyhandler( int native_key )
{
}
#endif /* #ifndef USE_WIDGET */
|