this repo has no description
at main 1423 lines 28 kB view raw
1/* 2 CONTROLM.h 3 4 Copyright (C) 2007 Paul C. Pratt 5 6 You can redistribute this file and/or modify it under the terms 7 of version 2 of the GNU General Public License as published by 8 the Free Software Foundation. You should have received a copy 9 of the license along with this file; see the file COPYING. 10 11 This file is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 license for more details. 15*/ 16 17/* 18 CONTROL Mode 19*/ 20 21#ifdef CONTROLM_H 22#error "header already included" 23#else 24#define CONTROLM_H 25#endif 26 27enum { 28#if EnableDemoMsg 29 SpclModeDemo, 30#endif 31#if EnableAltKeysMode 32 SpclModeAltKeyText, 33#endif 34#if UseActvCode 35 SpclModeActvCode, 36#endif 37 SpclModeNoRom, 38 SpclModeMessage, 39#if UseControlKeys 40 SpclModeControl, 41#endif 42 43 kNumSpclModes 44}; 45 46LOCALVAR uimr SpecialModes = 0; 47 48LOCALVAR blnr NeedWholeScreenDraw = falseblnr; 49 50#define SpecialModeSet(i) SpecialModes |= (1 << (i)) 51#define SpecialModeClr(i) SpecialModes &= ~ (1 << (i)) 52#define SpecialModeTst(i) (0 != (SpecialModes & (1 << (i)))) 53 54#define MacMsgDisplayed SpecialModeTst(SpclModeMessage) 55 56LOCALVAR ui3p CntrlDisplayBuff = nullpr; 57 58LOCALPROC DrawCell(unsigned int h, unsigned int v, int x) 59{ 60#if 1 61 /* safety check */ 62 if ((h < ((long)vMacScreenWidth / 8 - 2)) 63 && (v < (vMacScreenHeight / 16 - 1))) 64#endif 65 { 66 int i; 67 ui3p p0 = ((ui3p)CellData) + 16 * x; 68 69#if 0 != vMacScreenDepth 70 if (UseColorMode) { 71 ui3p p = CntrlDisplayBuff 72 + ((h + 1) << vMacScreenDepth) 73 + (v * 16 + 11) * vMacScreenByteWidth; 74 75 for (i = 16; --i >= 0; ) { 76#if 1 == vMacScreenDepth 77 int k; 78 ui3b t0 = *p0; 79 ui3p p2 = p; 80 for (k = 2; --k >= 0; ) { 81 *p2++ = (((t0) & 0x80) ? 0xC0 : 0x00) 82 | (((t0) & 0x40) ? 0x30 : 0x00) 83 | (((t0) & 0x20) ? 0x0C : 0x00) 84 | (((t0) & 0x10) ? 0x03 : 0x00); 85 /* black RRGGBBAA, white RRGGBBAA */ 86 t0 <<= 4; 87 } 88#elif 2 == vMacScreenDepth 89 int k; 90 ui3b t0 = *p0; 91 ui3p p2 = p; 92 for (k = 4; --k >= 0; ) { 93 *p2++ = (((t0) & 0x40) ? 0x0F : 0x00) 94 | (((t0) & 0x80) ? 0xF0 : 0x00); 95 /* black RRGGBBAA, white RRGGBBAA */ 96 t0 <<= 2; 97 } 98#elif 3 == vMacScreenDepth 99 int k; 100 ui3b t0 = *p0; 101 ui3p p2 = p; 102 for (k = 8; --k >= 0; ) { 103 *p2++ = ((t0 >> k) & 0x01) ? 0xFF : 0x00; 104 /* black RRGGBBAA, white RRGGBBAA */ 105 } 106#elif 4 == vMacScreenDepth 107 int k; 108 ui4r v; 109 ui3b t0 = *p0; 110 ui3p p2 = p; 111 for (k = 8; --k >= 0; ) { 112 v = ((t0 >> k) & 0x01) ? 0x0000 : 0x7FFF; 113 /* black RRGGBBAA, white RRGGBBAA */ 114 /* *((ui4b *)p2)++ = v; need big endian, so : */ 115 *p2++ = v >> 8; 116 *p2++ = v; 117 } 118#elif 5 == vMacScreenDepth 119 int k; 120 ui5r v; 121 ui3b t0 = *p0; 122 ui3p p2 = p; 123 for (k = 8; --k >= 0; ) { 124 v = ((t0 >> k) & 0x01) ? 0x00000000 : 0x00FFFFFF; 125 /* black RRGGBBAA, white RRGGBBAA */ 126 /* *((ui5b *)p2)++ = v; need big endian, so : */ 127 *p2++ = v >> 24; 128 *p2++ = v >> 16; 129 *p2++ = v >> 8; 130 *p2++ = v; 131 } 132#endif 133 p += vMacScreenByteWidth; 134 p0 ++; 135 } 136 } else 137#endif 138 { 139 ui3p p = CntrlDisplayBuff + (h + 1) 140 + (v * 16 + 11) * vMacScreenMonoByteWidth; 141 142 for (i = 16; --i >= 0; ) { 143 *p = *p0; 144 p += vMacScreenMonoByteWidth; 145 p0 ++; 146 } 147 } 148 } 149} 150 151#define ControlBoxh0 0 152#define ControlBoxw 62 153#define ControlBoxv0 0 154 155#define hLimit (ControlBoxh0 + ControlBoxw - 1) 156#define hStart (ControlBoxh0 + 1) 157 158 159LOCALVAR int CurCellh0; 160LOCALVAR int CurCellv0; 161 162LOCALPROC DrawCellsBeginLine(void) 163{ 164 DrawCell(ControlBoxh0, CurCellv0, kCellMiddleLeft); 165 CurCellh0 = hStart; 166} 167 168LOCALPROC DrawCellsEndLine(void) 169{ 170 int i; 171 172 for (i = CurCellh0; i < hLimit; ++i) { 173 DrawCell(i, CurCellv0, kCellSpace); 174 } 175 DrawCell(hLimit, CurCellv0, kCellMiddleRight); 176 CurCellv0++; 177} 178 179LOCALPROC DrawCellsBottomLine(void) 180{ 181 int i; 182 183 DrawCell(ControlBoxh0 + 0, CurCellv0, kCellLowerLeft); 184 for (i = hStart; i < hLimit; ++i) { 185 DrawCell(i, CurCellv0, kCellLowerMiddle); 186 } 187 DrawCell(hLimit, CurCellv0, kCellLowerRight); 188} 189 190LOCALPROC DrawCellAdvance(int x) 191{ 192 DrawCell(CurCellh0, CurCellv0, x); 193 CurCellh0++; 194} 195 196LOCALPROC DrawCellsBlankLine(void) 197{ 198 DrawCellsBeginLine(); 199 DrawCellsEndLine(); 200} 201 202LOCALPROC DrawCellsFromStr(char *s) 203{ 204 ui3b ps[ClStrMaxLength]; 205 ui3b cs; 206 int L; 207 int i; 208 int j; 209 int w; 210 211 ClStrFromSubstCStr(&L, ps, s); 212 213 i = 0; 214 215 while (i < L) { 216 cs = ps[i]; 217 i++; 218 if (CurCellh0 < hLimit) { 219 DrawCellAdvance(cs); 220 } else { 221 /* line is too wide, wrap */ 222 if (kCellSpace != cs) { 223 --i; /* back up one char, at least */ 224 225 /* now try backing up to beginning of word */ 226 j = i; 227 w = CurCellh0 - hStart; 228 229 while ((w > 0) && (j > 0) 230 && (ps[j - 1] != kCellSpace)) 231 { 232 --j; 233 --w; 234 } 235 if (w != 0) { 236 i = j; 237 CurCellh0 = hStart + w; 238 } 239 /* 240 else if w == 0, then have backed up to 241 beginning of line, so just let the word 242 be split. 243 */ 244 } 245 /* 246 else if cs == kCellSpace, just lose the space. 247 */ 248 DrawCellsEndLine(); 249 /* 250 draw white space over the part of 251 the word that have already drawn 252 */ 253 DrawCellsBeginLine(); 254 } 255 } 256} 257 258LOCALPROC DrawCellsOneLineStr(char *s) 259{ 260 DrawCellsBeginLine(); 261 DrawCellsFromStr(s); 262 DrawCellsEndLine(); 263} 264 265LOCALPROC DrawCellsKeyCommand(char *k, char *s) 266{ 267 DrawCellsBeginLine(); 268 DrawCellsFromStr(" "); 269 DrawCellsFromStr(k); 270 DrawCellsFromStr(" - "); 271 DrawCellsFromStr(s); 272 DrawCellsEndLine(); 273} 274 275typedef void (*SpclModeBody) (void); 276 277LOCALPROC DrawSpclMode0(char *Title, SpclModeBody Body) 278{ 279 int i; 280 int k; 281 282 CurCellv0 = ControlBoxv0 + 0; 283 DrawCell(ControlBoxh0 + 0, CurCellv0, kCellUpperLeft); 284 k = kCellIcon00; 285 for (i = hStart; i < hStart + 4; ++i) { 286 DrawCell(i, CurCellv0, k); 287 k++; 288 } 289 for (i = hStart + 4; i < hLimit; ++i) { 290 DrawCell(i, CurCellv0, kCellUpperMiddle); 291 } 292 DrawCell(hLimit, CurCellv0, kCellUpperRight); 293 ++CurCellv0; 294 295 DrawCellsBeginLine(); 296 for (i = hStart; i < hStart + 4; ++i) { 297 DrawCellAdvance(k); 298 k++; 299 } 300 DrawCellAdvance(kCellSpace); 301 DrawCellsFromStr(Title); 302 DrawCellsEndLine(); 303 304 DrawCellsBeginLine(); 305 for (i = hStart; i < hStart + 4; ++i) { 306 DrawCellAdvance(k); 307 k++; 308 } 309 for (i = hStart + 4; i < hLimit; ++i) { 310 DrawCellAdvance(kCellGraySep); 311 } 312 DrawCellsEndLine(); 313 314 if (nullpr != Body) { 315 Body(); 316 } 317 318 DrawCellsBottomLine(); 319} 320 321#if EnableAltKeysMode 322#include "ALTKEYSM.h" 323#else 324#define Keyboard_UpdateKeyMap1 Keyboard_UpdateKeyMap 325#define DisconnectKeyCodes1 DisconnectKeyCodes 326#endif 327 328#if WantAbnormalReports || UseActvFile 329LOCALPROC ClStrAppendHexNib(int *L0, ui3b *r, ui3r v) 330{ 331 if (v < 10) { 332 ClStrAppendChar(L0, r, kCellDigit0 + v); 333 } else { 334 ClStrAppendChar(L0, r, kCellUpA + (v - 10)); 335 } 336} 337#endif 338 339#if WantAbnormalReports || UseActvFile 340LOCALPROC ClStrAppendHexByte(int *L0, ui3b *r, ui3r v) 341{ 342 ClStrAppendHexNib(L0, r, (v >> 4) & 0x0F); 343 ClStrAppendHexNib(L0, r, v & 0x0F); 344} 345#endif 346 347#if WantAbnormalReports || UseActvFile 348LOCALPROC ClStrAppendHexWord(int *L0, ui3b *r, ui4r v) 349{ 350 ClStrAppendHexByte(L0, r, (v >> 8) & 0xFF); 351 ClStrAppendHexByte(L0, r, v & 0xFF); 352} 353#endif 354 355#if WantAbnormalReports 356LOCALPROC DrawCellsOneLineHexWord(ui4r v) 357{ 358 ui3b ps[ClStrMaxLength]; 359 int L = 0; 360 int i; 361 362 ClStrAppendHexWord(&L, ps, v); 363 364 DrawCellsBeginLine(); 365 for (i = 0; i < L; ++i) { 366 DrawCellAdvance(ps[i]); 367 } 368 DrawCellsEndLine(); 369} 370#endif 371 372LOCALPROC DrawCellsMessageModeBody(void) 373{ 374 DrawCellsOneLineStr(SavedBriefMsg); 375 DrawCellsBlankLine(); 376 DrawCellsOneLineStr(SavedLongMsg); 377#if WantAbnormalReports 378 if (0 != SavedIDMsg) { 379 DrawCellsBlankLine(); 380 DrawCellsOneLineHexWord(SavedIDMsg); 381 } 382#endif 383} 384 385LOCALPROC DrawMessageMode(void) 386{ 387 DrawSpclMode0(kStrModeMessage, DrawCellsMessageModeBody); 388} 389 390LOCALPROC MacMsgDisplayOff(void) 391{ 392 SpecialModeClr(SpclModeMessage); 393 SavedBriefMsg = nullpr; 394#if WantAbnormalReports 395 SavedIDMsg = 0; 396#endif 397 NeedWholeScreenDraw = trueblnr; 398} 399 400LOCALPROC MacMsgDisplayOn(void) 401{ 402 NeedWholeScreenDraw = trueblnr; 403 DisconnectKeyCodes1(kKeepMaskControl | kKeepMaskCapsLock); 404 /* command */ 405 SpecialModeSet(SpclModeMessage); 406} 407 408LOCALPROC DoMessageModeKey(ui3r key) 409{ 410 if (MKC_C == key) { 411 MacMsgDisplayOff(); 412 } 413} 414 415LOCALPROC MacMsgOverride(char *briefMsg, char *longMsg) 416{ 417 if (MacMsgDisplayed) { 418 MacMsgDisplayOff(); 419 SpecialModeSet(SpclModeMessage); 420 } 421 MacMsg(briefMsg, longMsg, falseblnr); 422} 423 424#if dbglog_HAVE 425GLOBALOSGLUPROC MacMsgDebugAlert(char *s) 426{ 427 MacMsgOverride("Debug", s); 428} 429#endif 430 431#if NeedDoMoreCommandsMsg 432LOCALPROC DoMoreCommandsMsg(void) 433{ 434 MacMsgOverride(kStrMoreCommandsTitle, 435 kStrMoreCommandsMessage); 436} 437#endif 438 439#if NeedDoAboutMsg 440LOCALPROC DoAboutMsg(void) 441{ 442 MacMsgOverride(kStrAboutTitle, 443 kStrAboutMessage); 444} 445#endif 446 447LOCALPROC NoRomMsgDisplayOff(void) 448{ 449 SpecialModeClr(SpclModeNoRom); 450 NeedWholeScreenDraw = trueblnr; 451} 452 453LOCALPROC NoRomMsgDisplayOn(void) 454{ 455 NeedWholeScreenDraw = trueblnr; 456 SpecialModeSet(SpclModeNoRom); 457} 458 459LOCALPROC DrawCellsNoRomModeBody(void) 460{ 461 DrawCellsOneLineStr(kStrNoROMMessage); 462} 463 464LOCALPROC DrawNoRomMode(void) 465{ 466 DrawSpclMode0(kStrNoROMTitle, DrawCellsNoRomModeBody); 467} 468 469#if UseControlKeys 470 471LOCALVAR blnr LastControlKey = falseblnr; 472LOCALVAR int CurControlMode = 0; 473LOCALVAR int ControlMessage = 0; 474 475enum { 476 kCntrlModeOff, 477 kCntrlModeBase, 478#if WantEnblCtrlRst 479 kCntrlModeConfirmReset, 480#endif 481#if WantEnblCtrlInt 482 kCntrlModeConfirmInterrupt, 483#endif 484 kCntrlModeConfirmQuit, 485 kCntrlModeSpeedControl, 486 487 kNumCntrlModes 488}; 489 490enum { 491 kCntrlMsgBaseStart, 492#if EnableMagnify 493 kCntrlMsgMagnify, 494#endif 495#if VarFullScreen 496 kCntrlMsgFullScreen, 497#endif 498#if WantEnblCtrlRst 499 kCntrlMsgConfirmResetStart, 500 kCntrlMsgHaveReset, 501 kCntrlMsgResetCancelled, 502#endif 503#if WantEnblCtrlInt 504 kCntrlMsgConfirmInterruptStart, 505 kCntrlMsgHaveInterrupted, 506 kCntrlMsgInterruptCancelled, 507#endif 508 kCntrlMsgConfirmQuitStart, 509 kCntrlMsgQuitCancelled, 510#if WantEnblCtrlKtg 511 kCntrlMsgEmCntrl, 512#endif 513 kCntrlMsgSpeedControlStart, 514 kCntrlMsgNewSpeed, 515 kCntrlMsgNewStopped, 516 kCntrlMsgNewRunInBack, 517#if EnableAutoSlow 518 kCntrlMsgNewAutoSlow, 519#endif 520 kCntrlMsgAbout, 521 kCntrlMsgHelp, 522#if IncludePbufs 523 kCntrlMsgOptionsStrCopied, 524#endif 525#if 0 && (UseActvCode || EnableDemoMsg) 526 kCntrlMsgRegStrCopied, 527#endif 528 529 kNumCntrlMsgs 530}; 531 532LOCALPROC DoEnterControlMode(void) 533{ 534 CurControlMode = kCntrlModeBase; 535 ControlMessage = kCntrlMsgBaseStart; 536 NeedWholeScreenDraw = trueblnr; 537 DisconnectKeyCodes1(kKeepMaskControl | kKeepMaskCapsLock); 538 SpecialModeSet(SpclModeControl); 539} 540 541LOCALPROC DoLeaveControlMode(void) 542{ 543 SpecialModeClr(SpclModeControl); 544 CurControlMode = kCntrlModeOff; 545 NeedWholeScreenDraw = trueblnr; 546} 547 548LOCALPROC Keyboard_UpdateControlKey(blnr down) 549{ 550 if (down != LastControlKey) { 551 LastControlKey = down; 552 if (down) { 553 DoEnterControlMode(); 554 } else { 555 DoLeaveControlMode(); 556 } 557 } 558} 559 560LOCALPROC SetSpeedValue(ui3b i) 561{ 562 SpeedValue = i; 563 CurControlMode = kCntrlModeBase; 564 ControlMessage = kCntrlMsgNewSpeed; 565} 566 567#if VarFullScreen 568FORWARDPROC ToggleWantFullScreen(void); 569#endif 570 571#if IncludeHostTextClipExchange 572LOCALPROC HTCEexportSubstCStr(char *s) 573{ 574 int i; 575 int L; 576 tPbuf j; 577#ifdef PbufHaveLock 578 int n = ClStrSizeSubstCStr(s); 579 580 if (mnvm_noErr == PbufNew(n, &j)) { 581 blnr IsOk = falseblnr; 582 ui3p p = PbufLock(j); 583 584 if (nullpr != p) { 585 L = 0; 586 ClStrAppendSubstCStr(&L, p, s); 587 588 if (L == n) { 589 for (i = 0; i < n; ++i) { 590 p[i] = Cell2MacAsciiMap[p[i]]; 591 } 592 IsOk = trueblnr; 593 } 594 595 PbufUnlock(j); 596 } 597 598 if (IsOk) { 599 HTCEexport(j); 600 } else { 601 PbufDispose(j); 602 } 603 } 604#else 605 ui3b ps[ClStrMaxLength]; 606 607 ClStrFromSubstCStr(&L, ps, s); 608 609 for (i = 0; i < L; ++i) { 610 ps[i] = Cell2MacAsciiMap[ps[i]]; 611 } 612 613 if (mnvm_noErr == PbufNew(L, &j)) { 614 PbufTransfer(ps, j, 0, L, trueblnr); 615 HTCEexport(j); 616 } 617#endif 618} 619#endif 620 621#if IncludeHostTextClipExchange 622LOCALPROC CopyOptionsStr(void) 623{ 624 HTCEexportSubstCStr(kBldOpts); 625} 626#endif 627 628#if 0 629#if UseActvCode 630FORWARDPROC CopyRegistrationStr(void); 631#elif EnableDemoMsg 632LOCALPROC CopyRegistrationStr(void) 633{ 634 HTCEexportSubstCStr("^v"); 635} 636#endif 637#endif 638 639 640LOCALPROC DoControlModeKey(ui3r key) 641{ 642 switch (CurControlMode) { 643 case kCntrlModeBase: 644 switch (key) { 645#if WantEnblCtrlKtg 646 case MKC_K: 647 ControlKeyPressed = ! ControlKeyPressed; 648 ControlMessage = kCntrlMsgEmCntrl; 649 Keyboard_UpdateKeyMap1(MKC_UnMappedKey, 650 ControlKeyPressed); 651 break; 652#endif 653 case MKC_S: 654 CurControlMode = kCntrlModeSpeedControl; 655 ControlMessage = kCntrlMsgSpeedControlStart; 656 break; 657#if WantEnblCtrlInt 658 case MKC_I: 659 CurControlMode = kCntrlModeConfirmInterrupt; 660 ControlMessage = kCntrlMsgConfirmInterruptStart; 661 break; 662#endif 663#if WantEnblCtrlRst 664 case MKC_R: 665 if (! AnyDiskInserted()) { 666 WantMacReset = trueblnr; 667 ControlMessage = kCntrlMsgHaveReset; 668 } else { 669 CurControlMode = kCntrlModeConfirmReset; 670 ControlMessage = kCntrlMsgConfirmResetStart; 671 } 672 break; 673#endif 674 case MKC_Q: 675 if (! AnyDiskInserted()) { 676 ForceMacOff = trueblnr; 677 } else { 678 CurControlMode = kCntrlModeConfirmQuit; 679 ControlMessage = kCntrlMsgConfirmQuitStart; 680 } 681 break; 682 case MKC_A: 683 ControlMessage = kCntrlMsgAbout; 684 break; 685 case MKC_H: 686 ControlMessage = kCntrlMsgHelp; 687 break; 688#if NeedRequestInsertDisk 689 case MKC_O: 690 RequestInsertDisk = trueblnr; 691 break; 692#endif 693#if EnableMagnify 694 case MKC_M: 695 WantMagnify = ! WantMagnify; 696 ControlMessage = kCntrlMsgMagnify; 697 break; 698#endif 699#if VarFullScreen 700 case MKC_F: 701 ToggleWantFullScreen(); 702 ControlMessage = kCntrlMsgFullScreen; 703 break; 704#endif 705#if IncludeHostTextClipExchange 706 case MKC_P: 707 CopyOptionsStr(); 708 ControlMessage = kCntrlMsgOptionsStrCopied; 709 break; 710#endif 711#if 0 && (UseActvCode || EnableDemoMsg) 712 case MKC_P: 713 CopyRegistrationStr(); 714 ControlMessage = kCntrlMsgRegStrCopied; 715 break; 716#endif 717#if NeedRequestIthDisk 718 case MKC_1: 719 RequestIthDisk = 1; 720 break; 721 case MKC_2: 722 RequestIthDisk = 2; 723 break; 724 case MKC_3: 725 RequestIthDisk = 3; 726 break; 727 case MKC_4: 728 RequestIthDisk = 4; 729 break; 730 case MKC_5: 731 RequestIthDisk = 5; 732 break; 733 case MKC_6: 734 RequestIthDisk = 6; 735 break; 736 case MKC_7: 737 RequestIthDisk = 7; 738 break; 739 case MKC_8: 740 RequestIthDisk = 8; 741 break; 742 case MKC_9: 743 RequestIthDisk = 9; 744 break; 745#endif 746 } 747 break; 748#if WantEnblCtrlRst 749 case kCntrlModeConfirmReset: 750 switch (key) { 751 case MKC_Y: 752 WantMacReset = trueblnr; 753 CurControlMode = kCntrlModeBase; 754 ControlMessage = kCntrlMsgHaveReset; 755 break; 756 case MKC_R: 757 /* ignore, in case of repeat */ 758 break; 759 case MKC_N: 760 default: 761 CurControlMode = kCntrlModeBase; 762 ControlMessage = kCntrlMsgResetCancelled; 763 break; 764 } 765 break; 766#endif 767#if WantEnblCtrlInt 768 case kCntrlModeConfirmInterrupt: 769 switch (key) { 770 case MKC_Y: 771 WantMacInterrupt = trueblnr; 772 CurControlMode = kCntrlModeBase; 773 ControlMessage = kCntrlMsgHaveInterrupted; 774 break; 775 case MKC_I: 776 /* ignore, in case of repeat */ 777 break; 778 case MKC_N: 779 default: 780 CurControlMode = kCntrlModeBase; 781 ControlMessage = kCntrlMsgInterruptCancelled; 782 break; 783 } 784 break; 785#endif 786 case kCntrlModeConfirmQuit: 787 switch (key) { 788 case MKC_Y: 789 ForceMacOff = trueblnr; 790 CurControlMode = kCntrlModeBase; 791 ControlMessage = kCntrlMsgBaseStart; 792 /* shouldn't see this message since quitting */ 793 break; 794 case MKC_Q: 795 /* ignore, in case of repeat */ 796 break; 797 case MKC_N: 798 default: 799 CurControlMode = kCntrlModeBase; 800 ControlMessage = kCntrlMsgQuitCancelled; 801 break; 802 } 803 break; 804 case kCntrlModeSpeedControl: 805 switch (key) { 806 case MKC_E: 807 CurControlMode = kCntrlModeBase; 808 ControlMessage = kCntrlMsgBaseStart; 809 break; 810 case MKC_B: 811 RunInBackground = ! RunInBackground; 812 CurControlMode = kCntrlModeBase; 813 ControlMessage = kCntrlMsgNewRunInBack; 814 break; 815 case MKC_D: 816 if (ROM_loaded) { 817 SpeedStopped = ! SpeedStopped; 818 CurControlMode = kCntrlModeBase; 819 ControlMessage = kCntrlMsgNewStopped; 820 } 821 break; 822#if EnableAutoSlow 823 case MKC_W: 824 WantNotAutoSlow = ! WantNotAutoSlow; 825 CurControlMode = kCntrlModeBase; 826 ControlMessage = kCntrlMsgNewAutoSlow; 827 break; 828#endif 829 case MKC_Z: 830 SetSpeedValue(0); 831 break; 832 case MKC_1: 833 SetSpeedValue(1); 834 break; 835 case MKC_2: 836 SetSpeedValue(2); 837 break; 838 case MKC_3: 839 SetSpeedValue(3); 840 break; 841 case MKC_4: 842 SetSpeedValue(4); 843 break; 844 case MKC_5: 845 SetSpeedValue(5); 846 break; 847 case MKC_A: 848 SetSpeedValue((ui3b) -1); 849 break; 850 } 851 break; 852 } 853 NeedWholeScreenDraw = trueblnr; 854} 855 856LOCALFUNC char * ControlMode2TitleStr(void) 857{ 858 char *s; 859 860 switch (CurControlMode) { 861#if WantEnblCtrlRst 862 case kCntrlModeConfirmReset: 863 s = kStrModeConfirmReset; 864 break; 865#endif 866#if WantEnblCtrlInt 867 case kCntrlModeConfirmInterrupt: 868 s = kStrModeConfirmInterrupt; 869 break; 870#endif 871 case kCntrlModeConfirmQuit: 872 s = kStrModeConfirmQuit; 873 break; 874 case kCntrlModeSpeedControl: 875 s = kStrModeSpeedControl; 876 break; 877 case kCntrlModeBase: 878 default: 879 if (kCntrlMsgHelp == ControlMessage) { 880 s = kStrModeControlHelp; 881 } else { 882 s = kStrModeControlBase; 883 } 884 break; 885 } 886 887 return s; 888} 889 890LOCALPROC DrawCellsControlModeBody(void) 891{ 892 switch (ControlMessage) { 893 case kCntrlMsgAbout: 894 DrawCellsOneLineStr(kStrProgramInfo); 895 896 DrawCellsBlankLine(); 897 898 DrawCellsOneLineStr(kStrWorkOfMany); 899 DrawCellsOneLineStr(kMaintainerName); 900 DrawCellsOneLineStr(kStrForMoreInfo); 901 DrawCellsOneLineStr("^w"); 902 903 DrawCellsBlankLine(); 904 905 DrawCellsBeginLine(); 906 DrawCellsFromStr(kStrLicense); 907 DrawCellsFromStr(kStrDisclaimer); 908 DrawCellsEndLine(); 909 910 break; 911 912 case kCntrlMsgHelp: 913 DrawCellsOneLineStr(kStrHowToLeaveControl); 914 DrawCellsOneLineStr(kStrHowToPickACommand); 915 DrawCellsBlankLine(); 916 DrawCellsKeyCommand("A", kStrCmdAbout); 917#if NeedRequestInsertDisk 918 DrawCellsKeyCommand("O", kStrCmdOpenDiskImage); 919#endif 920 DrawCellsKeyCommand("Q", kStrCmdQuit); 921 DrawCellsKeyCommand("S", kStrCmdSpeedControl); 922#if EnableMagnify 923 DrawCellsKeyCommand("M", kStrCmdMagnifyToggle); 924#endif 925#if VarFullScreen 926 DrawCellsKeyCommand("F", kStrCmdFullScrnToggle); 927#endif 928#if WantEnblCtrlKtg 929 DrawCellsKeyCommand("K", kStrCmdCtrlKeyToggle); 930#endif 931#if WantEnblCtrlRst 932 DrawCellsKeyCommand("R", kStrCmdReset); 933#endif 934#if WantEnblCtrlInt 935 DrawCellsKeyCommand("I", kStrCmdInterrupt); 936#endif 937 DrawCellsKeyCommand("P", kStrCmdCopyOptions); 938 DrawCellsKeyCommand("H", kStrCmdHelp); 939 break; 940 case kCntrlMsgSpeedControlStart: 941 DrawCellsOneLineStr(kStrCurrentSpeed); 942 DrawCellsKeyCommand("Z", "1x"); 943 DrawCellsKeyCommand("1", "2x"); 944 DrawCellsKeyCommand("2", "4x"); 945 DrawCellsKeyCommand("3", "8x"); 946 DrawCellsKeyCommand("4", "16x"); 947 DrawCellsKeyCommand("5", "32x"); 948 DrawCellsKeyCommand("A", kStrSpeedAllOut); 949 DrawCellsBlankLine(); 950 DrawCellsKeyCommand("D", kStrSpeedStopped); 951 DrawCellsKeyCommand("B", kStrSpeedBackToggle); 952#if EnableAutoSlow 953 DrawCellsKeyCommand("W", kStrSpeedAutoSlowToggle); 954#endif 955 DrawCellsBlankLine(); 956 DrawCellsKeyCommand("E", kStrSpeedExit); 957 break; 958 case kCntrlMsgNewSpeed: 959 DrawCellsOneLineStr(kStrNewSpeed); 960 break; 961 case kCntrlMsgNewRunInBack: 962 DrawCellsOneLineStr(kStrNewRunInBack); 963 break; 964 case kCntrlMsgNewStopped: 965 DrawCellsOneLineStr(kStrNewStopped); 966 break; 967#if EnableAutoSlow 968 case kCntrlMsgNewAutoSlow: 969 DrawCellsOneLineStr(kStrNewAutoSlow); 970 break; 971#endif 972#if EnableMagnify 973 case kCntrlMsgMagnify: 974 DrawCellsOneLineStr(kStrNewMagnify); 975 break; 976#endif 977#if VarFullScreen 978 case kCntrlMsgFullScreen: 979 DrawCellsOneLineStr(kStrNewFullScreen); 980 break; 981#endif 982#if IncludeHostTextClipExchange 983 case kCntrlMsgOptionsStrCopied: 984 DrawCellsOneLineStr(kStrHaveCopiedOptions); 985 break; 986#endif 987#if 0 988#if UseActvCode 989 case kCntrlMsgRegStrCopied: 990 DrawCellsOneLineStr("Registration String copied."); 991 break; 992#elif EnableDemoMsg 993 case kCntrlMsgRegStrCopied: 994 DrawCellsOneLineStr("Variation name copied."); 995 break; 996#endif 997#endif 998#if WantEnblCtrlRst 999 case kCntrlMsgConfirmResetStart: 1000 DrawCellsOneLineStr(kStrConfirmReset); 1001 DrawCellsBlankLine(); 1002 DrawCellsKeyCommand("Y", kStrResetDo); 1003 DrawCellsKeyCommand("N", kStrResetNo); 1004 break; 1005 case kCntrlMsgHaveReset: 1006 DrawCellsOneLineStr(kStrHaveReset); 1007 break; 1008 case kCntrlMsgResetCancelled: 1009 DrawCellsOneLineStr(kStrCancelledReset); 1010 break; 1011#endif 1012#if WantEnblCtrlInt 1013 case kCntrlMsgConfirmInterruptStart: 1014 DrawCellsOneLineStr(kStrConfirmInterrupt); 1015 DrawCellsBlankLine(); 1016 DrawCellsKeyCommand("Y", kStrInterruptDo); 1017 DrawCellsKeyCommand("N", kStrInterruptNo); 1018 break; 1019 case kCntrlMsgHaveInterrupted: 1020 DrawCellsOneLineStr(kStrHaveInterrupted); 1021 break; 1022 case kCntrlMsgInterruptCancelled: 1023 DrawCellsOneLineStr(kStrCancelledInterrupt); 1024 break; 1025#endif 1026 case kCntrlMsgConfirmQuitStart: 1027 DrawCellsOneLineStr(kStrConfirmQuit); 1028 DrawCellsBlankLine(); 1029 DrawCellsKeyCommand("Y", kStrQuitDo); 1030 DrawCellsKeyCommand("N", kStrQuitNo); 1031 break; 1032 case kCntrlMsgQuitCancelled: 1033 DrawCellsOneLineStr(kStrCancelledQuit); 1034 break; 1035#if WantEnblCtrlKtg 1036 case kCntrlMsgEmCntrl: 1037 DrawCellsOneLineStr(kStrNewCntrlKey); 1038 break; 1039#endif 1040 case kCntrlMsgBaseStart: 1041 default: 1042 DrawCellsOneLineStr(kStrHowToLeaveControl); 1043 break; 1044 } 1045} 1046 1047LOCALPROC DrawControlMode(void) 1048{ 1049 DrawSpclMode0(ControlMode2TitleStr(), DrawCellsControlModeBody); 1050} 1051 1052#endif /* UseControlKeys */ 1053 1054#if EnableDemoMsg 1055 1056LOCALPROC DrawDemoMode(void) 1057{ 1058 CurCellv0 = ControlBoxv0 + ((9 * CurMacDateInSeconds) & 0x0F); 1059 CurCellh0 = ControlBoxh0 + ((15 * CurMacDateInSeconds) & 0x1F); 1060 1061 DrawCellAdvance(kCellDemo0); 1062 DrawCellAdvance(kCellDemo6); 1063 DrawCellAdvance(kCellDemo6); 1064 DrawCellAdvance(kCellDemo7); 1065 DrawCellAdvance(kCellDemo1); 1066 DrawCellAdvance(kCellDemo2); 1067 DrawCellAdvance(kCellDemo3); 1068 DrawCellAdvance(kCellDemo4); 1069 DrawCellAdvance(kCellDemo7); 1070 DrawCellAdvance(kCellDemo6); 1071 DrawCellAdvance(kCellDemo6); 1072 DrawCellAdvance(kCellDemo5); 1073} 1074 1075LOCALPROC DemoModeSecondNotify(void) 1076{ 1077 NeedWholeScreenDraw = trueblnr; 1078 SpecialModeSet(SpclModeDemo); 1079} 1080 1081#endif /* EnableDemoMsg */ 1082 1083#if UseActvCode 1084#include "ACTVCODE.h" 1085#endif 1086 1087LOCALPROC DrawSpclMode(void) 1088{ 1089#if UseControlKeys 1090 if (SpecialModeTst(SpclModeControl)) { 1091 DrawControlMode(); 1092 } else 1093#endif 1094 if (SpecialModeTst(SpclModeMessage)) { 1095 DrawMessageMode(); 1096 } else 1097 if (SpecialModeTst(SpclModeNoRom)) { 1098 DrawNoRomMode(); 1099 } else 1100#if UseActvCode 1101 if (SpecialModeTst(SpclModeActvCode)) { 1102 DrawActvCodeMode(); 1103 } else 1104#endif 1105#if EnableAltKeysMode 1106 if (SpecialModeTst(SpclModeAltKeyText)) { 1107 DrawAltKeyMode(); 1108 } else 1109#endif 1110#if EnableDemoMsg 1111 if (SpecialModeTst(SpclModeDemo)) { 1112 DrawDemoMode(); 1113 } else 1114#endif 1115 { 1116 /* should not get here */ 1117 } 1118} 1119 1120LOCALFUNC ui3p GetCurDrawBuff(void) 1121{ 1122 ui3p p = screencomparebuff; 1123 1124 if (0 != SpecialModes) { 1125 MyMoveBytes((anyp)p, (anyp)CntrlDisplayBuff, 1126#if 0 != vMacScreenDepth 1127 UseColorMode ? vMacScreenNumBytes : 1128#endif 1129 vMacScreenMonoNumBytes 1130 ); 1131 p = CntrlDisplayBuff; 1132 1133 DrawSpclMode(); 1134 } 1135 1136 return p; 1137} 1138 1139#ifdef WantKeyboard_RemapMac 1140LOCALFUNC ui3r Keyboard_RemapMac(ui3r key) 1141{ 1142 switch (key) { 1143#if MKC_formac_Control != MKC_Control 1144 case MKC_Control: 1145 key = MKC_formac_Control; 1146 break; 1147#endif 1148#if MKC_formac_Command != MKC_Command 1149 case MKC_Command: 1150 key = MKC_formac_Command; 1151 break; 1152#endif 1153#if MKC_formac_Option != MKC_Option 1154 case MKC_Option: 1155 key = MKC_formac_Option; 1156 break; 1157#endif 1158#if MKC_formac_Shift != MKC_Shift 1159 case MKC_Shift: 1160 key = MKC_formac_Shift; 1161 break; 1162#endif 1163#if MKC_formac_CapsLock != MKC_CapsLock 1164 case MKC_CapsLock: 1165 key = MKC_formac_CapsLock; 1166 break; 1167#endif 1168#if MKC_formac_F1 != MKC_F1 1169 case MKC_F1: 1170 key = MKC_formac_F1; 1171 break; 1172#endif 1173#if MKC_formac_F2 != MKC_F2 1174 case MKC_F2: 1175 key = MKC_formac_F2; 1176 break; 1177#endif 1178#if MKC_formac_F3 != MKC_F3 1179 case MKC_F3: 1180 key = MKC_formac_F3; 1181 break; 1182#endif 1183#if MKC_formac_F4 != MKC_F4 1184 case MKC_F4: 1185 key = MKC_formac_F4; 1186 break; 1187#endif 1188#if MKC_formac_F5 != MKC_F5 1189 case MKC_F5: 1190 key = MKC_formac_F5; 1191 break; 1192#endif 1193#if MKC_formac_Escape != MKC_Escape 1194 case MKC_Escape: 1195 key = MKC_formac_Escape; 1196 break; 1197#endif 1198#if MKC_formac_BackSlash != MKC_BackSlash 1199 case MKC_BackSlash: 1200 key = MKC_formac_BackSlash; 1201 break; 1202#endif 1203#if MKC_formac_Slash != MKC_Slash 1204 case MKC_Slash: 1205 key = MKC_formac_Slash; 1206 break; 1207#endif 1208#if MKC_formac_Grave != MKC_Grave 1209 case MKC_Grave: 1210 key = MKC_formac_Grave; 1211 break; 1212#endif 1213#if MKC_formac_Enter != MKC_Enter 1214 case MKC_Enter: 1215 key = MKC_formac_Enter; 1216 break; 1217#endif 1218#if MKC_formac_PageUp != MKC_PageUp 1219 case MKC_PageUp: 1220 key = MKC_formac_PageUp; 1221 break; 1222#endif 1223#if MKC_formac_PageDown != MKC_PageDown 1224 case MKC_PageDown: 1225 key = MKC_formac_PageDown; 1226 break; 1227#endif 1228#if MKC_formac_Home != MKC_Home 1229 case MKC_Home: 1230 key = MKC_formac_Home; 1231 break; 1232#endif 1233#if MKC_formac_End != MKC_End 1234 case MKC_End: 1235 key = MKC_formac_End; 1236 break; 1237#endif 1238#if MKC_formac_Help != MKC_Help 1239 case MKC_Help: 1240 key = MKC_formac_Help; 1241 break; 1242#endif 1243#if MKC_formac_ForwardDel != MKC_ForwardDel 1244 case MKC_ForwardDel: 1245 key = MKC_formac_ForwardDel; 1246 break; 1247#endif 1248 default: 1249 break; 1250 } 1251 1252 return key; 1253} 1254#endif /* WantKeyboard_RemapMac */ 1255 1256LOCALPROC Keyboard_UpdateKeyMap2(ui3r key, blnr down) 1257{ 1258#if UseControlKeys 1259 if (MKC_CM == key) { 1260 Keyboard_UpdateControlKey(down); 1261 } else 1262#endif 1263 if ((0 == SpecialModes) 1264#if EnableAltKeysMode || EnableDemoMsg 1265 || (0 == (SpecialModes & ~ ( 1266 0 1267#if EnableAltKeysMode 1268 | (1 << SpclModeAltKeyText) 1269#endif 1270#if EnableDemoMsg 1271 | (1 << SpclModeDemo) 1272#endif 1273 ))) 1274#endif 1275 || (MKC_CapsLock == key) 1276 ) 1277 { 1278 /* pass through */ 1279 Keyboard_UpdateKeyMap1(key, down); 1280 } else { 1281 if (down) { 1282#if UseControlKeys 1283 if (SpecialModeTst(SpclModeControl)) { 1284 DoControlModeKey(key); 1285 } else 1286#endif 1287 if (SpecialModeTst(SpclModeMessage)) { 1288 DoMessageModeKey(key); 1289 } else 1290#if UseActvCode 1291 if (SpecialModeTst(SpclModeActvCode)) { 1292 DoActvCodeModeKey(key); 1293 } else 1294#endif 1295 { 1296 } 1297 } /* else if not down ignore */ 1298 } 1299} 1300 1301LOCALPROC DisconnectKeyCodes2(void) 1302{ 1303 DisconnectKeyCodes1(kKeepMaskControl | kKeepMaskCapsLock); 1304#if UseControlKeys 1305 Keyboard_UpdateControlKey(falseblnr); 1306#endif 1307} 1308 1309#ifndef CheckRomCheckSum 1310#define CheckRomCheckSum 1 1311#endif 1312 1313#if CheckRomCheckSum 1314LOCALFUNC ui5r Calc_Checksum(void) 1315{ 1316 long int i; 1317 ui5b CheckSum = 0; 1318 ui3p p = 4 + ROM; 1319 1320 for (i = (kCheckSumRom_Size - 4) >> 1; --i >= 0; ) { 1321 CheckSum += do_get_mem_word(p); 1322 p += 2; 1323 } 1324 1325 return CheckSum; 1326} 1327#endif 1328 1329#if CheckRomCheckSum && RomStartCheckSum 1330LOCALPROC WarnMsgCorruptedROM(void) 1331{ 1332 MacMsgOverride(kStrCorruptedROMTitle, kStrCorruptedROMMessage); 1333} 1334#endif 1335 1336#if CheckRomCheckSum 1337LOCALPROC WarnMsgUnsupportedROM(void) 1338{ 1339 MacMsgOverride(kStrUnsupportedROMTitle, 1340 kStrUnsupportedROMMessage); 1341} 1342#endif 1343 1344LOCALFUNC tMacErr ROM_IsValid(void) 1345{ 1346#if CheckRomCheckSum 1347 ui5r CheckSum = 1348#if RomStartCheckSum 1349 do_get_mem_long(ROM) 1350#else 1351 Calc_Checksum() 1352#endif 1353 ; 1354 1355#ifdef kRomCheckSum1 1356 if (CheckSum == kRomCheckSum1) { 1357 } else 1358#endif 1359#ifdef kRomCheckSum2 1360 if (CheckSum == kRomCheckSum2) { 1361 } else 1362#endif 1363#ifdef kRomCheckSum3 1364 if (CheckSum == kRomCheckSum3) { 1365 } else 1366#endif 1367 { 1368 WarnMsgUnsupportedROM(); 1369 return mnvm_miscErr; 1370 } 1371 /* 1372 Even if ROM is corrupt or unsupported, go ahead and 1373 try to run anyway. It shouldn't do any harm. 1374 [update: no, don't] 1375 */ 1376 1377#if RomStartCheckSum 1378 { 1379 ui5r CheckSumActual = Calc_Checksum(); 1380 1381 if (CheckSum != CheckSumActual) { 1382 WarnMsgCorruptedROM(); 1383 return mnvm_miscErr; 1384 } 1385 } 1386#endif 1387 1388#endif /* CheckRomCheckSum */ 1389 1390 ROM_loaded = trueblnr; 1391 SpeedStopped = falseblnr; 1392 1393 return mnvm_noErr; 1394} 1395 1396#if NonDiskProtect 1397GLOBALOSGLUPROC WarnMsgUnsupportedDisk(void) 1398{ 1399 MacMsgOverride("Unsupported Disk Image", 1400 "I do not recognize the format of the Disk Image," 1401 " and so will not try to mount it."); 1402} 1403#endif 1404 1405LOCALFUNC blnr WaitForRom(void) 1406{ 1407 if (! ROM_loaded) { 1408 NoRomMsgDisplayOn(); 1409 1410 SpeedStopped = trueblnr; 1411 do { 1412 WaitForNextTick(); 1413 1414 if (ForceMacOff) { 1415 return falseblnr; 1416 } 1417 } while (SpeedStopped); 1418 1419 NoRomMsgDisplayOff(); 1420 } 1421 1422 return trueblnr; 1423}