\ This file Copyright 1988 by Warren Block. \ menustuff.f DECIMAL GLOBAL Continue? \ Project Baud Rate Columns \ About 300 40 \ ----- 1200 80 \ Quit 2400 CREATE Project$ 0," Project" CREATE About$ 0," About" CREATE Blank$ 0," " CREATE Quit$ 0," Quit " CREATE Baud$ 0," Baud Rate" CREATE Baud300$ 0," 300" CREATE Baud1200$ 0," 1200" CREATE Baud2400$ 0," 2400" CREATE Column$ 0," Columns" CREATE Column40$ 0," 40" CREATE Column80$ 0," 80" 3 CONSTANT NumMenus 3 CONSTANT NumProjectItems 3 CONSTANT NumBaudItems 2 CONSTANT NumColumnItems GLOBAL MenuBase GLOBAL ProjectITextBase GLOBAL ProjectMItemBase GLOBAL BaudITextBase GLOBAL BaudMItemBase GLOBAL ColumnITextBase GLOBAL ColumnMItemBase VARIABLE ProjectMenu VARIABLE BaudMenu VARIABLE ColumnMenu struct Menu DefaultMenu NULL DefaultMenu +muNextMenu ! 1 DefaultMenu +muLeftEdge W! 0 DefaultMenu +muTopEdge W! 78 DefaultMenu +muWidth W! 10 DefaultMenu +muHeight W! MENUENABLED DefaultMenu +muFlags W! NULL DefaultMenu +muMenuName W! NULL DefaultMenu +muFirstItem ! structend struct IntuiText DefaultIText 0 DefaultIText +itFrontPen C! 1 DefaultIText +itBackPen C! JAM2 DefaultIText +itDrawMode C! 2 DefaultIText +itLeftEdge W! 1 DefaultIText +itTopEdge W! NULL DefaultIText +itITextFont ! NULL DefaultIText +itIText ! NULL DefaultIText +itNextText ! structend struct MenuItem DefaultMItem NULL DefaultMItem +miNextItem ! 2 DefaultMItem +miLeftEdge W! 0 DefaultMItem +miTopEdge W! 20 DefaultMItem +miWidth W! 10 DefaultMItem +miHeight W! ITEMTEXT HIGHCOMP | ITEMENABLED | DefaultMItem +miFlags W! NULL DefaultMItem +miMutualExclude ! NULL DefaultMItem +miItemFill ! NULL DefaultMItem +miSelectFill ! 0 DefaultMItem +miCommand C! NULL DefaultMItem +miSubItem ! 0 DefaultMItem +miNextSelect W! structend : GetMenuMemory ( --- ) \ Allocate RAM for menu stuff. NumProjectItems IntuiText * MEMF_PUBLIC MEMF_CLEAR | AllocMem TO ProjectITextBase NumProjectItems MenuItem * MEMF_PUBLIC MEMF_CLEAR | AllocMem TO ProjectMItemBase NumBaudItems IntuiText * MEMF_PUBLIC MEMF_CLEAR | AllocMem TO BaudITextBase NumBaudItems MenuItem * MEMF_PUBLIC MEMF_CLEAR | AllocMem TO BaudMItemBase NumColumnItems IntuiText * MEMF_PUBLIC MEMF_CLEAR | AllocMem TO ColumnITextBase NumColumnItems MenuItem * MEMF_PUBLIC MEMF_CLEAR | AllocMem TO ColumnMItemBase NumMenus Menu * MEMF_PUBLIC MEMF_CLEAR | AllocMem TO MenuBase MenuBase ProjectMenu ! MenuBase Menu + BaudMenu ! MenuBase Menu 2* + ColumnMenu ! ; : FreeMenuMemory ( --- ) \ Deallocate menu RAM. ProjectITextBase NumProjectItems IntuiText * FreeMem ProjectMItemBase NumProjectItems MenuItem * FreeMem BaudITextBase NumBaudItems IntuiText * FreeMem BaudMItemBase NumBaudItems MenuItem * FreeMem ColumnITextBase NumColumnItems IntuiText * FreeMem ColumnMItemBase NumColumnItems MenuItem * FreeMem MenuBase NumMenus Menu * FreeMem ; : ProjectITexts ( n --- itext ) \ Array of IntuiTexts. ProjectITextBase SWAP IntuiText * + ; : ProjectMItems ( n --- mitem ) \ Array of MenuItems. ProjectMItemBase SWAP MenuItem * + ; : BaudITexts ( n --- itext ) \ Array of IntuiTexts. BaudITextBase SWAP IntuiText * + ; : BaudMItems ( n -- mitem ) \ Array of MenuItems. BaudMItemBase SWAP MenuItem * + ; : ColumnITexts ( n --- itext ) ColumnITextBase SWAP IntuiText * + ; : ColumnMItems ( n --- mitem ) ColumnMItemBase SWAP MenuItem * + ; : InitIText ( addr --- ) \ Copy defaults into an IntuiText. DefaultIText SWAP IntuiText CMOVE ; : InitITexts ( --- ) \ Prepare all the IntuiTexts. NumProjectItems 0 DO I ProjectITexts InitIText LOOP NumBaudItems 0 DO I BaudITexts InitIText LOOP NumColumnItems 0 DO I ColumnITexts InitIText LOOP ; : PointStrings ( --- ) \ Set string pointers for IntuiText structures. About$ 0 ProjectITexts +itIText ! Blank$ 1 ProjectITexts +itIText ! Quit$ 2 ProjectITexts +itIText ! Baud300$ 0 BaudITexts +itIText ! Baud1200$ 1 BaudITexts +itIText ! Baud2400$ 2 BaudITexts +itIText ! Column40$ 0 ColumnITexts +itIText ! Column80$ 1 ColumnITexts +itIText ! ; : InitMItem ( addr --- ) \ Copy defaults into a MenuItem. DefaultMItem SWAP MenuItem CMOVE ; : InitMItems ( --- ) \ Put default values in all the MenuItems. NumProjectItems 0 DO I ProjectMItems InitMItem I ProjectITexts I ProjectMItems +miItemFill ! I 10* I ProjectMItems +miTopEdge W! 91 I ProjectMItems +miWidth W! ITEMTEXT HIGHCOMP | ITEMENABLED | I ProjectMItems +miFlags W! LOOP ITEMTEXT HIGHCOMP | 1 ProjectMItems +miFlags W! \ can't select blank NumBaudItems 0 DO I BaudMItems InitMItem I BaudITexts I BaudMItems +miItemFill ! I 10* I BaudMItems +miTopEdge W! 83 I BaudMItems +miWidth W! ITEMTEXT HIGHCOMP | ITEMENABLED | CHECKIT | I BaudMItems +miFlags W! LOOP ITEMTEXT HIGHCOMP | ITEMENABLED | CHECKIT | CHECKED | 1 BaudMItems +miFlags W! NumColumnItems 0 DO I ColumnMItems InitMItem I ColumnITexts I ColumnMItems +miItemFill ! I 10* I ColumnMItems +miTopEdge W! 67 I ColumnMItems +miWidth W! ITEMTEXT HIGHCOMP | ITEMENABLED | CHECKIT | I ColumnMItems +miFlags W! LOOP ITEMTEXT HIGHCOMP | ITEMENABLED | CHECKIT | CHECKED | 0 ColumnMItems +miFlags W! ; : CreateLinks ( --- ) \ Put everything together. NumProjectItems 1- 0 DO I 1+ ProjectMItems I ProjectMItems +miNextItem ! LOOP NULL NumProjectItems 1- ProjectMItems +miNextItem ! NumBaudItems 1- 0 DO I 1+ BaudMItems I BaudMItems +miNextItem ! LOOP NULL NumBaudItems 1- BaudMItems +miNextItem ! NumColumnItems 1- 0 DO I 1+ ColumnMItems I ColumnMItems +miNextItem ! LOOP NULL NumColumnItems 1- ColumnMItems +miNextItem ! ; : AddExtras ( --- ) \ Extra stuff for MenuItems. 0 ProjectMItems +miFlags W@ COMMSEQ | 0 ProjectMItems +miFlags W! ASCII A 0 ProjectMItems +miCommand C! 65534 0 ProjectMItems +miMutualExclude ! 2 ProjectMItems +miFlags W@ COMMSEQ | 2 ProjectMItems +miFlags W! ASCII Q 2 ProjectMItems +miCommand C! 65533 2 ProjectMItems +miMutualExclude ! 65534 0 BaudMItems +miMutualExclude ! 65533 1 BaudMItems +miMutualExclude ! 65531 2 BaudMItems +miMutualExclude ! 65534 0 ColumnMItems +miMutualExclude ! 65533 1 ColumnMItems +miMutualExclude ! ; : CreateMenus ( --- ) \ Tie everything together. DefaultMenu ProjectMenu @ Menu CMOVE Project$ ProjectMenu @ +muMenuName ! 78 ProjectMenu @ +muWidth W! BaudMenu @ ProjectMenu @ +muNextMenu ! 0 ProjectMItems ProjectMenu @ +muFirstItem ! DefaultMenu BaudMenu @ Menu CMOVE Baud$ BaudMenu @ +muMenuName ! 80 BaudMenu @ +muLeftEdge W! 86 BaudMenu @ +muWidth W! ColumnMenu @ BaudMenu @ +muNextMenu ! 0 BaudMItems BaudMenu @ +muFirstItem ! DefaultMenu ColumnMenu @ Menu CMOVE Column$ ColumnMenu @ +muMenuName ! 168 ColumnMenu @ +muLeftEdge W! 67 ColumnMenu @ +muWidth W! NULL ColumnMenu @ +muNextMenu ! 0 ColumnMItems ColumnMenu @ +muFirstItem ! ; : SetUpMenus ( --- ) \ Create menus. GetMenuMemory InitITexts PointStrings InitMItems CreateLinks AddExtras CreateMenus CurrentWindow @ ProjectMenu @ SetMenuStrip ; : MenuNum ( code -- n ) \ Calculate menu number from message code. 31 AND ; : ItemNum ( code -- n ) \ Calculate item number from message code. -5 SCALE 63 AND ; : HandleMenus ( code --- ) \ Do appropriate menu actions. 1200 LOCALS| pbaud code | code MenuNum CASE 0 OF code ItemNum CASE 0 OF TalkAbout ENDOF { 1 OF ...impossible... ENDOF } 2 OF FALSE TO Continue? ENDOF ENDCASE ENDOF 1 OF ReadMessage @ AbortIO code ItemNum CASE 0 OF 300 TO pbaud ENDOF 1 OF 1200 TO pbaud ENDOF 2 OF 2400 TO pbaud ENDOF ENDCASE pbaud SetSerialParams ReadMessage @ BeginIO ENDOF 2 OF code ItemNum CASE 0 OF ColumnWidth @ 39 = NOT IF 40 ProjectMenu SwitchRes THEN ENDOF 1 OF ColumnWidth @ 79 = NOT IF 80 ProjectMenu SwitchRes THEN ENDOF ENDCASE ENDOF ENDCASE ;