-- KeysetTest.mesa -- edited by Sweet, 22-Apr-83 12:52:07 DIRECTORY Atom, DLionInputOutput USING [IOPage, processorCommandOffset], Display USING [Black, White], FormSW USING [ AllocateItemDescriptor, ClientItemsProcType, CommandItem, newLine, ProcType], Keys USING [DownUp], TIP, Tool USING [ AddThisSW, Create, MakeFormSW, MakeSWsProc, RegisterSWType, SimpleAdjustProc, SWType], ToolWindow USING [CreateSubwindow], UserTerminal USING [BlinkDisplay], Window USING [Box, Handle, Place, ValidateTree]; KeysetTest: PROGRAM IMPORTS Atom, Display, DLionInputOutput, FormSW, TIP, Tool, ToolWindow, UserTerminal, Window = BEGIN CreateWindow: PROC = BEGIN window _ Tool.Create[ name: "Keyset Test"L, makeSWsProc: MakeSWs]; END; window, formSW, paddleSW: Window.Handle; paddleType: Tool.SWType = Tool.RegisterSWType[]; paddleState: PACKED ARRAY [1..5] OF Keys.DownUp _ ALL[up]; MakeSWs: Tool.MakeSWsProc = BEGIN formSW _ Tool.MakeFormSW[window: window, formProc: MakeForm]; paddleSW _ ToolWindow.CreateSubwindow[parent: window, display: DisplayBars]; Tool.AddThisSW[window: window, sw: paddleSW, swType: paddleType]; TIP.CreateClient[paddleSW, myTip, TIPMe]; END; MakeForm: FormSW.ClientItemsProcType = BEGIN OPEN FormSW; items _ AllocateItemDescriptor[2]; items[0] _ CommandItem[tag: "Turn on"L, place: newLine, proc: TurnOn]; items[1] _ CommandItem[tag: "Turn off"L, proc: TurnOff]; RETURN[items, TRUE] END; ProcessorCommand: TYPE = MACHINE DEPENDENT { busy(100000B), turnOnKeyset(100011B), turnOffKeyset(100012B)}; pProcessorCommand: LONG POINTER TO ProcessorCommand = DLionInputOutput.IOPage + DLionInputOutput.processorCommandOffset; TurnOn: FormSW.ProcType = BEGIN WHILE pProcessorCommand^ >= busy DO NULL ENDLOOP; -- wait for IOP pProcessorCommand^ _ turnOnKeyset; END; TurnOff: FormSW.ProcType = BEGIN WHILE pProcessorCommand^ >= busy DO NULL ENDLOOP; -- wait for IOP pProcessorCommand^ _ turnOffKeyset; END; DisplayBars: PROC [w: Window.Handle ] = BEGIN -- repaint everything Display.Black[paddleSW, [[x: 31, y: 31], [w: 5*32+1, h: 1]]]; Display.Black[paddleSW, [[x: 31, y: 31+128], [w: 5*32+1, h: 1]]]; FOR i: CARDINAL IN [1..6] DO Display.Black[paddleSW, [[x: 32*i-1, y: 31], [w: 1, h: 128]]]; ENDLOOP; FOR i: CARDINAL IN [1..5] DO PaintPaddle[i, paddleState[i]]; ENDLOOP; END; PaintPaddle: PROC [n: CARDINAL, state: Keys.DownUp] = BEGIN proc: PROC [Window.Handle, Window.Box] = IF state = down THEN Display.Black ELSE Display.White; proc [paddleSW, [[x: 32*n, y: 32], [w: 31, h: 126]]]; END; TIPMe: TIP.NotifyProc = BEGIN which: CARDINAL _ 0; FOR input: TIP.Results _ results, input.Rest[] UNTIL input = NIL DO WITH z: input.First[] SELECT FROM atom => SELECT z.a FROM down => IF which IN [1..5] THEN { PaintPaddle[which, down]; paddleState[which] _ down}; up => IF which IN [1..5] THEN { PaintPaddle[which, up]; paddleState[which] _ up}; ENDCASE; int => which _ CARDINAL[z.i]; ENDCASE; ENDLOOP; Window.ValidateTree[paddleSW]; END; myTip: TIP.Table _ NIL; down, up: Atom.ATOM; InitTip: PROCEDURE = { tipContents: STRING _ "-- Keyset.TIP; last edit by -- Sweet 22-Apr-83 11:54:46 SELECT TRIGGER FROM Keyset1 Down => 1, Down; Keyset2 Down => 2, Down; Keyset3 Down => 3, Down; Keyset4 Down => 4, Down; Keyset5 Down => 5, Down; Keyset1 Up => 1, Up; Keyset2 Up => 2, Up; Keyset3 Up => 3, Up; Keyset4 Up => 4, Up; Keyset5 Up => 5, Up; ENDCASE... "L; firstTime: BOOLEAN _ TRUE; down _ Atom.MakeAtom["Down"L]; up _ Atom.MakeAtom["Up"L]; myTip _ TIP.CreateTable[ file: "Keyset.TIP"L, contents: tipContents ! TIP.InvalidTable => IF type = badSyntax THEN { UserTerminal.BlinkDisplay[]; IF firstTime THEN {firstTime _ FALSE; RESUME}}]; TIP.actionToWindow[Keyset1] _ TRUE; TIP.actionToWindow[Keyset2] _ TRUE; TIP.actionToWindow[Keyset3] _ TRUE; TIP.actionToWindow[Keyset4] _ TRUE; TIP.actionToWindow[Keyset5] _ TRUE}; -- main line code InitTip[]; CreateWindow[]; END.