' Name : Demo program for SetCom and the others!!!
'
' By   : Gregory A. Kendall
'
' Spefs : Public Domain....  please distribute freely!!!!!
'

' do some set up like setting up menu trapping!!!

DEFINT a-z
ON MENU GOSUB MenuEvaluate : MENU ON

' open up intuition!!!!!

LIBRARY "intuition.library"

' if you got an error here, you need
'  to put the intuition.bmap file in
' the current directory.



' clear basic's menus

FOR t = 1 TO 4
    MENU t,0,0,""
NEXT

' set up some practice menus...

MENU 1,0,1,"Kendall Menu"
    MENU 1,1,1,"Say Hello!!!      " '<---- leave space for command!!!!
    MENU 1,2,1,"Print Hello!!!"
    
' delay for a bit to allow basic time to catch up!!!!

FOR t = 1 TO 1500 : NEXT

' set up a command

CALL SetComm(1,1,"S")    

' print Hello text

PRINT "Hello there!!!!!!  Hit Control-C to end!!!!!"

' show the pointer to the Raster

CALL GetRastPort(WINDOW(7),Rport&)
PRINT "This is the address of the Raster : ",Rport&

' show the screen pointer

CALL GetScreenPointer(WINDOW(7),ScrPointer&)
PRINT "This is the address of the Screen : ",ScrPointer&
PRINT "Actually, this is the workbench screen. heeheehee"

' loop until CTRL-C is sent

WHILE 1
    SLEEP
WEND

' end the program  and begin the sub-programs......

MenuEvaluate:

  menu0 = MENU(0)
  menu1 = MENU(1)
  
  IF menu1 = 1 THEN SAY(TRANSLATE$("Hello there!!!!!"))
  IF menu1 = 2 THEN PRINT "Hello there!!!!"
  
RETURN

'  You need to delay 1 sec after setting the menus
'  through AmigaBasic before calling this routine.
'  Seems that AmigaBasic lags when setting menus!!!!!

SUB SetComm ( MenuNum%, Item%, Comm$ ) STATIC

    CommSeq&    = 4    
    Head&       = PEEKL (WINDOW(7)+28)
    menu1&      = Head&
    IF MenuNum% > 1 THEN
        FOR t = 1 TO MenuNum%-1
            menu1& = PEEKL ( menu1& ) 
        NEXT
    END IF
    menuitem& = PEEKL (menu1&+18) 
    IF Item% > 1 THEN
        FOR t = 1 TO Item%-1
            menuitem& = PEEKL ( menuitem& )
        NEXT
    END IF
    command&    = menuitem& + 26
    flags&      = menuitem& + 12
    POKE  command&,  ASC(Comm$)
    POKEW flags&  ,  PEEKW ( flags& ) OR CommSeq& 
    CALL ClearMenuStrip& ( WINDOW(7) )
    CALL SetMenuStrip& ( WINDOW(7), Head& )

END SUB    
    
    
SUB GetRastPort ( MyWindow&, RastPort& ) STATIC

    RastPort& = PEEKL ( MyWindow&+50 ) 
    
END SUB

SUB GetScreenPtr ( MyWindow&, MyScreen& ) STATIC

    MyScreen& = PEEKL ( MyWindow&+46 )
    
END SUB

