; ; File: ScriptMgrPatch.a (formerly SMgrPatch.a) ; ; Contains: Script Manager trap patches for international scripts and the user interface. ; ; Written by: JDT Joe Ternasky ; MED Mark Davis ; LDC Lee Collins ; PKE Peter Edberg ; ; Copyright: © 1986-1992 by Apple Computer, Inc., all rights reserved. ; ; Change History (most recent first): ; ; <18> 6/12/92 FM Deleted the forRom portion of LwrString since it is in ; ScriptMgrExtensions now. Also This file is now only used in ; system builds. Removed the SMgrPostmunging routine and put in in ; ScriptMgrMisc.a. I removed the less than obvious register ; restoring trick in the GetOSEvent patch. Deleted the ; FixSMgrWorld code since it is no longer called and it is now ; obsolete. Removed the obsolete patch headers for the patches ; that no longer exist. Moved SMgrPostMunging into ; ScriptMgrMisc.a. Moved the PatchTable and PatchTableAUX here ; from ScriptMgrMisc.a ; <17> 5/31/92 FM Remove rom only versions of gestaltScriptMgr and ; gestaltSMgrTable. They are in ScriptMgrExtensions.a now. Still ; many forRom conditionals left unfortunately. ; <16> 4/30/92 FM Get rid of conditionals: SysVers, doScriptMgrGestalt, ; doScriptMgrLwrString2 ScriptMgrKeyboardMenu ; <15> 10/8/91 PKE For Cube-E (and Bruges): Move body LwrString from here to ; ScriptMgrExtTail.a (ptch 27), since we now patch it out ; entirely; leave an RTS stub. Part of fix for bug #1013149. Clean ; up some conditionals; delete code that is conditionalized out. ; <14> 6/12/91 LN removed #include 'HardwareEqu.a' ; <13> 12/14/90 PKE (DC) Remove useless InitApplZone patch in 7.0. Change KeyTrans ; patch so we skip itlk handling if KeyTrans is called with a ; special KCHR (not the one emKeyCache points to). ; <12> 12/10/90 PKE (VL) Change GetOSEvent patch to use smgrKeyScriptResult to ; determine whether or not to strip event from queue. ; <11> 10/30/90 PKE (stb) Change GetOSEvent patch to permit switching keyboards ; within scripts using key combos defined in 'KSWP' resource. ; <10> 7/20/90 PKE For 7.0, move FixSMgrWorld code inside InitScripts in ptch 27. ; <9> 7/5/90 PKE NEEDED FOR SIXPACK: Removed local definition of smgrSixPack ; since it is now defined in ScriptPriv.a. ; <8> 6/11/90 PKE NEEDED FOR SIXPACK: Fix Script Mgr InitResources patch to save ; and restore all regs; only needed for 6.x. Changes are flagged ; with <8>. ; <7> 5/13/90 SMB Removing menu bar script/keyboard toggling (see FilterMouse) in ; GetOSEvent. ; <6> 5/5/90 PKE For 7.0, remove InitWindows and InitResources patches. ; <5> 4/10/90 PKE Used smgrSysVers, smgrROMVers, smgrUseItl2Tables, and other new ; symbols instead of buildLevel. Deleted conditionalized ; definitions of forRom, SysVers, Scripts604. Started organizing ; for ROMification of 7.0 extensions. ; <4> 3/27/90 PKE Use new conditional flags for gestaltScriptMgr and LwrString ; 2-byte extension. ; <3> 3/20/90 EMT Removed unnecessary ROM85 references and oldMacTweek code. ; <2> 1/4/90 PKE Updated conditionals to put SS-6.0.4 changes in 6.0.5 as well as ; 7.0. Updated header to BBS format. ; <1> 12/18/89 CCH Adding for the first time into BBS. Changed include 'inc.sum.a' ; to load 'StandardEqu.d'. Updated file name references. ; BBS versions above: ;___________________________________________________________________________________________________ ; EASE versions below: ; <3.4> 12/8/89 PKE NEEDED FOR Scripts604 AND FOR (6.0.5 <= SysVers < 7.0): Extend ; LwrString to handle 2-byte chars via Transliterate (yuck). For ; 7.0, we do this elsewhere. ; <3.3> 9/17/89 PKE For 7.0, move gestaltScriptMgr function from here to ptch 27 ; (ScriptMgrExtTail.a), so we don't have to duplicate it in PTCH ; files. ; <3.2> 8/28/89 PKE Use LwrString here for ROM builds too, so move it out of the ; System-only section, adjust the conditionals slightly, and ; export LwrString if ForROM. Make SMgrCalcRect and SMgrInitFonts ; entry points available for 7.0., since the body of these patches ; will now be called directly by the routines instead of being ; added as a patch. Also for 7.0, delete trap patch entry points ; xInitMenus, xInitFonts, and xDrawMenuBar (actually, delete ; entire DrawMenuBar patch for 7.0 since SwapIcon will now be ; called directly by the routine). Rearrange the import-export ; section. ; <3.1> 8/26/89 PKE Cleaned up conditionals, changing newItl2Tables to buildLevel >= ; 1. Deleted obsolete itlr stuff (never got built). Removed unused ; InitApplZone, InitResources, SMgrDraw, SMgrFont, SMgrText, ; SMgrEvent labels. Moved TEInit and DrawMenuBar patches into ; System-only code section, since they're only used for the System ; build. Moved all exports to top of file. ; <3.0> 8/25/89 PKE NEEDED FOR 6.0.4 SCRIPTS BUILD: Remove TEInit patch for ; Scripts604, 7.0. ; <2.9> 8/24/89 PKE NEEDED FOR 6.0.4 SCRIPTS BUILD, 6.0.5: Conditionalize (2.7). ; Remove some gratuitous conditionals. NOTE: May have to add back ; load 'nEqu.d' when we roll this over to Fiction for SS-6.0.4 ; Scripts build. ; <2.8> 8/22/89 SES Removed references to nFiles. ; <2.7> 8/21/89 PKE NEEDED FOR 6.0.4 SCRIPTS BUILD, 6.0.5: Change LwrString to save ; IntlForce flag then clear it before IUGetIntl call, restoring it ; afterward. This is so we get the itl2 tables for the correct ; script (instead of the tables for the system script). ; <2.6> 8/7/89 PKE NEEDED FOR 6.0.4: In gestaltScriptMgr function, if gestalt ; selector is undefined, just leave gestalt result alone. ; <2.5> 8/5/89 PKE NEEDED FOR 6.0.4: Provide gestaltFunction for Script Manager. ; <2.4> 7/10/89 PKE Cleaned up conditionals around SMgrCalcRect. ; <2.3> 7/8/89 PKE NEEDED FOR 6.0.4: Fixed error code returned by LwrString if ; 'itl2' not found. ; <2.2> 6/30/89 PKE NEEDED FOR AURORA: For ROM, FixSMgrWorld now dispatches through ; an internal vector. Add xFixSMgrWorld; for RAM version, change ; FixWorld to FixSMgrWorld. Use disabCacheReq constant. ; <2.1> 6/23/89 PKE Skip definition of buildLevel (done in ScriptPriv.a). ; <2.0> 6/5/89 PKE (ROM & 7.0 only) Fix InitFonts patch to handle non-Roman FOND ; IDs on a Roman system; add more error checking in LwrString ; after IUGetIntl call and set error return if necessary. ; <1.9> 4/7/89 PKE Changed lowerNoMarkListOffset to noMarkListOffset (in LwrString) ; <1.8> 3/28/89 PKE Use OS trap bits 9-10 to control function of LwrString (Big Bang ; only); compute smgrRect from icon location in SMgrRecord (ROM & ; Big Bang only). ; <1.7> 3/8/89 PKE Change BSR.S to BSR in 2 places so Big Bang builds. ; <1.6> 3/5/89 PKE Fixed LwrString - was trashing a2. For Big Bang, add & update ; KeyTrans patch (Int'l itlk processing) from KeyHack.a. ; <1.5> 2/28/89 PKE Delete UprString patch for Big Bang. The patch could cause ; UprString to move memory, but it is not documented as a routine ; that can move memory. Instead, this functionality will be added ; to LwrString (which is not presently documented, so we have more ; flexibility). Fixed reference to #MinusOne in GetOSEvent patch. ; <1.4> 2/21/89 PKE Replaced with RomProj version, which already had system and Rom ; sources merged. ;___________________________________________________________________________________________________ ; EASE ROMproj history: ; <1.6> 2/21/89 PKE Get CharType/Transliterate tables from itl2, not itlR; do this ; for all new Systems and ROMs. Get rid of itlR-related ; initializations. Fix up LOADs: always use include ; 'StandardEqu.d'. Fix up SMgrPost- Munging (ROM only) to copy a0 ; to a2. Plus see local comments below. ; 2/21/89 pke Also update to include some of the ROM version improvements in ; Sys $700. Fix up includes: always use include 'inc.sum.a'. ; <1.5> 2/14/89 PKE Updated to use MPW 3.0 final ScriptEqu.a equate names ; <1.4> 2/3/89 PKE Merged with current system sources (CCH's 01/16/1989 merge of ; 6.0.3 and 7.0 sources, done in RES.sys:smgr) ; 2/2/89 pke Merged system sources and ROM sources ; <1.3> 11/14/88 CCH Added semicolons to header so program would assemble. ; <1.2> 11/14/88 PKE Synchronize EASE and Projector; modify SMgrInitFonts to bail if ; SMgr not initialized; put in framework for xKeyTrans patch ; roll-in ; <1.1> 11/11/88 CCH Fixed Header. ; <1.0> 11/9/88 CCH Adding to EASE. ; old EASE ROMproj history: ; <1.7> 10/27/88 LDC Mods by Carl Hewitt and Brian McGhie in the process of putting ; Script Manager in ROM ;___________________________________________________________________________________________________ ; EASE SYSproj history: ; <1.3> 2/14/89 PKE Updated to use MPW 3.0 final ScriptEqu.a equates ; <1.2> 1/17/89 CCH Merged changes from 6.0.3. ; <1.1> 1/16/89 CCH Merged 6.0.3 final sources into 7.0. ; <1.0> 11/16/88 CCH Added to EASE. ;___________________________________________________________________________________________________ ; pre-EASE history ; 9/23/88 ldc added patch for UprString, xUprString ; 6/16/88 ldc Changed xLwrString to get tables via RomanUtil.GetItlr ; 4/26/88 ldc began romification/vectorization ; From here up are changes for ROM or buildLevel >= 2 ; 2/4/88 med Clear pack6 cache in initapplzone patch ; 2/4/88 med Replaced Launch patch with patches to InitApplZone and ; InitResources. ; 2/4/88 med Change InitWindows patch to test smgrEnabled instead of ; bootdrive ; 11/10/87 med Remove oldMac support ; 7/21/87 med Restored Joe's fix of 13Apr87 (not in master) ; 7/8/87 med Catch any InitWindow before launch time, and init the world ; 6/16/87 jdt Use the KeyScript trap in the Launch patch instead of calling ; SwapKybd directly. ; 4/13/87 jdt Copied Mark's fix for the force flag to the InitFonts patch. ; 3/6/87 med Check for substitute Chicago fond ; 3/5/87 med Disable cache request when resetting sys or app fonts with -2 in ; CurFMInput ; 3/4/87 med Fix force flag bug when resetting system fonts ; 1/28/87 MED DonŐt stomp on sysFontFam if it is in the right range. ; 1/19/87 jdt Replaced resource type constants with literals. ; 12/31/86 jdt Removed check on smgrEnabled in DrawMenuBar patch. ; 12/23/86 jdt Removed several checks on ResErr. Only reset application font if ; it is outside the system script's range. Saved space in ; SMgrEvent patch. Eliminated uneccesary register saving in ; several patches. ; 12/9/86 jdt Removed loading of new DSAT during switch-launch. ; 12/8/86 jdt TEInit patch no longer changes the WordRedraw flag. ; 12/5/86 jdt Changed WimpyIcon and WinpyKybd to SwapIcon and SwapKybd. ; Various comments added or modified. Several checks on ResError ; added. We no longer set the system and app font numbers on ROMs. ; Set system bit on RecoverHandle for DSAT at switch-launch. ; 12/3/86 jdt Fixed bug with enabled count in the GetNextEvent patch. ; 11/21/86 jdt Rolled in Tecot's latest changes to the KeyTrans trap. Launch ; patch now uses the SMgr enabled flag as a script count. Draw and ; Event patches bail if script count is less than 2. Removed ; KeyTrans trap patch code. ; 11/20/86 jdt Replaced standard equates load. ; 10/9/86 JDT Copied SMgrTrans patch from Ed Tecot's KeyTrans trap code. ; 10/8/86 JDT Do not toggle the key script if no KSWP resource is present. ; 10/7/86 JDT Played fast and loose with the deep shit alert tables. ; 9/13/86 JDT Broke out patch routines from initialization code. Revised ; _Launch patch and added _TEInit patch. ;___________________________________________________________________________________________________ ; To Do: ; ;___________________________________________________________________________________________________ load 'standardequ.d' ; Private.a, ScriptEqu.a, ... include 'ScriptPriv.a' include 'GestaltEqu.a' ; <08/05/89 pke> include 'HardwarePrivateEqu.a' ; to get hwCbADB <03/05/89 pke> proc blanks on string asis import StdUnlink ; <08/05/89 pke> ;<4/26/88ldc> added vector exports export xKeyTrans ; _KeyTrans <03/05/89 pke> ;os traps export xGetOSEvent ; _GetOSEvent patch. export LwrString ; just a stub now <10> ;------------------------------------------------------------------------------ ; xKeyTrans - Remap the key code and modifiers according to the itlk table. ; ; Introduction: ; This is a special hack to make the various international keyboard ; layouts work on all of the keyboard models. We intercept calls to ; the KeyTrans trap and perform some special mapping of the virtual key ; codes, based on an optional resource that can accompany each KCHR. ; ; If we currently have an international keyboard re-mapping table (itlk resource, ; only present on some international systems), perform any re-mapping and call ; the original KeyTrans routine. The re-mapping table consists of an integer ; count followed by a set of items with the following format: ; ; | old | old | old | care | care | new | new | ; | keyboard | modifiers | key | modifiers | code | modifiers | key | ; | type | | code | | | | code | ; ; This code compares the current keyboard type, key code, and modifiers against ; each entry. If there is a match, it substitutes the new modifiers and key ; code before calling the original KeyTrans routine. Note that the current ; modifiers and key code are masked with the care bits in the entry before the ; comparison is made. When a comparison succeeds, the new modifiers and key ; code are masked with the care bits and the current modifiers and key code ; are masked with the complement of the care bits. The logical or of these ; two products is the final result. This allows for a more compact table when ; several characters on one key are mapped together to a different key. ; ; The keyboard types are: ; $0001 Standard ADB (and Apple II GS) ; $0002 Extended ADB ; $0003 Macintosh Classic (domestic) ; $0103 Macintosh Classic (international) ; $0004 ISO Standard ADB ; $0005? Zoots (European ergonomic) ; $0006? Esprit std ; $0007? Esprit ISO ; $000b Macintosh Plus ; ; The modifier bits are: ; 7 -> (Right Control) ; 6 -> (Right Option) ; 5 -> (Right Shift) ; 4 -> Control (Left Control) ; 3 -> Option (Left Option) ; 2 -> Caps Lock ; 1 -> Shift (Left Shift) ; 0 -> Command ; ; register usage: ; d5 -> loop counter ; d4 -> current keyboard type, key code, and modifiers ; d3 -> masked current keyboard type, key code, and modifiers ; d2 -> new key code and modifiers for re-mapping ; d1 -> care masks for key code and modifiers ; d0 -> old key code and modifiers for comparison ;------------------------------------------------------------------------------ intlEnable equ 10 ; Offset to intlEnable flag ktFrame record {a6link},decr result ds.l 1 ; resulting ascii codes kchrTable ds.l 1 ; KCHR table to use codeMods ds.w 1 ; virtual key code, modifiers deadState ds.l 1 ; dead key state pointer return ds.l 1 ; return address a6link ds.l 1 ; old link pointer ktLocals equ * ; size of locals kchrTableNoLink equ kchrTable-return ; kchrTable offset before link <13> endr xKeyTrans with ktFrame, SMgrRecord ; if we do not have an itlk resource, bail out now GetSMgrCore a0 ; <03/05/89 pke> move.l smgrCurITLK(a0),d0 ; have an itlk currently? <03/05/89 pke> beq.s @noTable ; no -> bail out ; bail if KCHR pointer is not same as in ExpandMem <13> with ExpandMemRec ; <13> move.l ExpandMem,a1 ; <13> move.l emKeyCache(a1),d1 ; Get KCHR pointer in ExpandMem <13> cmp.l kchrTableNoLink(sp),d1 ; same as KCHR pointer param? <13> bne.s @noTable ; if not, skip itlk handling <13> endwith ;ExpandMemRec ; <13> link a6,#ktLocals ; build stack frame movem.l d3-d5,-(sp) ; save the registers move.l d0,a0 ; copy table handle move.l (a0),a0 ; load table pointer ; find the keyboard type and build the comparison key (type, code, modifiers) clr.l d4 ; clear a long move.b kbdType,d4 ; load type move.w HwCfgFlags,d0 ; load hardware configuration btst.l #hwCbADB,d0 ; ADB present? bne.s @knownType ; yes -> skip this cmp.b #$0b,d4 ; Macintosh Plus keyboard? beq.s @knownType ; yes -> skip this move.w #$03,d4 ; old Macintosh keyboard move.l Key1Trans,a1 ; fetch Key1Trans pointer <17jun87 jdt> tst.b intlEnable(a1) ; intlEnable flag on? <17jun87 jdt> beq.s @knownType ; no -> skip this <17jun87 jdt> move.w #$103,d4 ; use special keyboard type <17jun87 jdt> @knownType swap d4 ; put type in high word move.w codeMods(a6),d4 ; load code,mods ; step through the itlk table, looking for a match move.w (a0)+,d5 ; load table length bra.s @stepLoop ; enter loop at bottom @beginLoop move.l (a0)+,d0 ; load old type,code,mods move.w (a0)+,d1 ; load don't care masks move.w (a0)+,d2 ; load new code,mods move.l d4,d3 ; copy current type,code,mods and.w d1,d3 ; mask off don't care bits cmp.l d0,d3 ; same type,code,mods? bne.s @stepLoop ; no -> try next one and.w d1,d2 ; mask off don't care bits not.w d1 ; invert care mask and.w d1,d4 ; mask off care bits or.w d4,d2 ; combine for final code,mods move.w d2,codeMods(a6) ; remap code,mods bra.s @endLoop ; exit search loop @stepLoop dbra d5,@beginLoop ; try next entry @endLoop ; remove the stack frame and jump into the original KeyTrans code movem.l (sp)+,d3-d5 ; restore the registers unlk a6 ; remove stack frame GetSMgrCore a0 ; pointer to SMgr globals <03/05/89 pke> @noTable move.l sVectKeyTrans(a0),a0 ; get old KeyTrans vector <03/05/89 pke> jmp (a0) ; jump to it. endWith ; ---------------------------------------------------------------------------- ; function: SMgrEvent ; input: a0.l Pointer to event record [long]. ; d0.w Event mask [word]. ; output: d0.b 0 = event,-1 = null event [byte]. ; warning: This routine is a trap patch. ; This routine follows OS register conventions. ; ; This routine screens all events and determines when to change the key ; script. If it does change the key script, region symbol in the menu bar ; is redrawn. ; ---------------------------------------------------------------------------- ; Save the registers and the event record pointer. Call the original ; trap vector to get the next event. If it is a null event, return ; without filtering. ; ; a4.l Script Manager globals pointer. ; a3.l Keyboard globals pointer. ; a2.l Event record pointer. with smgrRecord ; import SMgrPostMunging ; now in ScriptMgrExtensions.a xGetOSEvent movem.l a2,-(sp) ; save the registers. GetSMgrCore a2 ; load SMgr globals. <4/26/88ldc> move.l sVectGetOSEvent(a2), a2 ; get old trap <4/26/88ldc> move.l a0,-(sp) ; save a0 EventPtr jsr (a2) ; call old trap routine. move.l (sp)+,a0 ; restore a0 EventPtr tst.b d0 bne.s DoneEvent ; bail on event not available. jsr SMgrPostMunging ; Expects an EventPtr in a0 DoneEvent movem.l (sp)+,a2 ; restore the registers. rts ; return to the caller. endWith ; ; ---------------------------------------------------------------------------- ; routine: LwrString (xLwrString) ; <15> for system builds, just leave stub here; real one is in ScriptMgrExtTail.a ; ---------------------------------------------------------------------------- ; For rom we use the NewLwrString in ScriptMgrExtensions.a LwrString ; <3.2> rts ; ---------------------------------------------------------------------------- endProc ; ----------------------------------------------------------------------------- ; This table contains the entries used for ; patching out the required trap routines. ;<6/7/88ldc> added vector imports ;<6/7/88ldc> changed patch table to add smgr global vectors for rom. ;changed "Old" etc to x+routine name ; Patches removed for System 7: InitResources <10>, InitMenus, TEInit, DrawMenuBar, ; InitFonts, InitWindows <10>, InitApplZone <19>, ScriptUtil <11> PatchTable proc export import PatchStart ; start of patch code with SMgrRecord import xKeyTrans dc.w $01c3,sVectKeyTrans,xKeyTrans-PatchStart ; _KeyTrans <1.6> ; os: add $8000 ; Moved GetOSEvent entry to PatchTableNoAUX <19> import LwrString ; dc.w $8056,sVectLwrString, LwrString-PatchStart ; _LwrString; implement <12/17/87med> endwith ;SMgrRecord ; <19> ; single word termination!!!! <4/27/88ldc> dc.w 0 endProc ; New table for patches to skip if A/UX. <19> ; Moved GetOSEvent entry from above. PatchTableNoAUX proc export import PatchStart ; start of patch code with SMgrRecord ; os: add $8000 import xGetOSEvent dc.w $8031,sVectGetOSEvent, xGetOSEvent-PatchStart ; _GetOSEvent endwith ;SMgrRecord ; <19> ; single word termination dc.w 0 endProc end