home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / 1997 / 920.ZIP / Psi-on.opl < prev    next >
Encoding:
Text File  |  1997-02-11  |  13.8 KB  |  426 lines

  1. REM PsiOn V1.3.3 by Paul Hargreaves
  2. REM Please do not distribute modified
  3. REM versions of this program
  4. REM ╕1996, ╕1997 Paul Hargreaves
  5.  
  6. REM Changes for 1.3.3
  7. REM If Pause mode was used, next day the
  8. REM    screen showed Pause mode was
  9. REM    running in error
  10. REM If Pause mode was used, and you use
  11. REM    the machine past midnight, Pause
  12. REM    sets itself up for the Next day
  13. REM    instead of today
  14. REM Changed text label for Pause mode
  15.  
  16. REM Changes for 1.3.2
  17. REM Sorted out issue where Agenda just
  18. REM   ignores any events first thing in
  19. REM   the morning.  
  20. REM   (appears that if Agenda isn't in
  21. REM   view, that it ignores key presses)
  22.  
  23. REM New for 1.3
  24. REM Press Psion-A in the screen, and
  25. REM   PsiOn will turn on the password 
  26. REM   and will switch the Psion off - 
  27. REM   just as if the time-out had 
  28. REM   occured.  Useful if you leave your
  29. REM   machine lying around at lunch etc.
  30. REM Press Psion-P in the screen, and
  31. REM   PsiOn will suspend it's auto
  32. REM   re-arm of the password until
  33. REM   04:00 hours the next day rather
  34. REM   than your normal time
  35. REM PsiOn will quit if Psion-Escape is
  36. REM   pressed
  37. REM Agenda control.  If selected, PsiOn
  38. REM   will look for 1 and only 1 running
  39. REM   task called Agenda.  When you next
  40. REM   log in, Agenda will be pushed to
  41. REM   the front, in the view of your
  42. REM   choice
  43. REM Instant response to Events - e.g.
  44. REM   a quit will quit in a couple of
  45. REM   seconds rather than 15
  46. REM Break the program up into different
  47. REM   procedures (slightly)
  48. REM Upgrades that change the psi-on.opd
  49. REM   file will keep your old settings
  50. REM Learned how to spell Siena <g>
  51. REM Low memory mode - removed all the
  52. REM   unneeded displays!  PsiOn uses
  53. REM   9/10k when working rather than 19k
  54. REM Removed Prompt Option, as no-one 
  55. REM   seems to need it - the Auto option
  56. REM   added in 1.2 more than replaces it
  57. REM Removed Beep Option, as it isn't
  58. REM   useful and it's now obvious when 
  59. REM   you log in that PsiOn is runing
  60. REM Removed New Auto-Off time, as PsiOn
  61. REM   /should/ be running all the time
  62. REM   the user will have the value set
  63. REM   in the standard place
  64. REM Changed all dialogs so that no
  65. REM   special dialogs or code are needed
  66. REM   for Siena's.
  67.  
  68. REM Changes for 1.2
  69. REM Auto rearm when password is entered
  70. REM More beep options
  71. REM Rename running program to PsiOn
  72. REM Siena (emulator) compatable!
  73. REM Tidy up the source a little
  74.  
  75. APP PsiOn
  76.    EXT "ODB"
  77.    PATH "\OPD"
  78.    ICON "\OPL\PSI-ON.ICO"
  79.    TYPE $1000
  80. ENDA
  81.  
  82. PROC PsiOn: 
  83.    LOCAL hand%, stat% :REM Handle for TIM:, status flag
  84.    LOCAL nul&         :REM A null value
  85.    LOCAL passwd$(8)   :REM Current unlock password
  86.    LOCAL event%(6)    :REM Checking for system events
  87.    LOCAL oscalls%(6)  :REM For OS calls
  88.    LOCAL wakeagn%     :REM 1 if next login should check time/date, 2 if should display immediately
  89.    LOCAL currday%     :REM Holds the current day
  90.    LOCAL gwidth%      :REM Normal screen width 
  91.    LOCAL gheight%     :REM Normal screen height
  92.    LOCAL title$(30)   :REM For the title of this program
  93.    LOCAL rearmtm&     :REM Time to re-arm   
  94.    LOCAL integer%     :REM General integer   
  95.    LOCAL text$(30)    :REM General text
  96.    LOCAL stattxt$(26) :REM Text "PSION-A To Arm etc."
  97.    LOCAL pause%       :REM 0 for normal, 1 while PsiOn is pausing
  98.    LOCAL pid%         :REM Process ID of agenda
  99.    
  100.    GLOBAL rearm&      :REM Rearm ticks
  101.    GLOBAL agn%        :REM 1 if agenda not controlled, 2 if auto view after 4am, 3 to always show
  102.    GLOBAL view$(1)    :REM Char to send to Agenda (e.g. w for Week view)
  103.  
  104.    REM Rename this process to "PsiOn" for SPY etc to list
  105.    text$="PsiOn"+CHR$(0)
  106.    CALL($0c88,CALL($0088),0,0,0,UADD(ADDR(text$),1))
  107.       
  108.    REM Set a nice font, then display the header
  109.    gheight% = gHEIGHT
  110.    gwidth%  = gWIDTH
  111.    FONT 7,0  
  112.    gFONT 7
  113.    gAT 1,14
  114.    title$="PsiOn V1.3.3 ╕Paul Hargreaves"
  115.    gXPRINT title$,1
  116.    
  117.    REM Disable PSION-ESC to exit program
  118.    ESCAPE OFF
  119.    
  120.    REM Mark program as in-active
  121.    CALL($138b)
  122.       
  123.    REM Set all defaults in-case file cannot be read
  124.    rearm& = 900 :REM Quarter of an hour 15*60
  125.    view$  = "W" :REM Week view
  126.    
  127.    REM Get the user settings from "\opd\psi-on.opd"
  128.    File:(1)
  129.  
  130.    REM Prompt for new settings
  131.    LOCK ON
  132.    DO
  133.       dINIT "PsiOn 1.3.3"
  134.       dXINPUT passwd$,"Power on password"
  135.       dTIME   rearm& ,"Switched off time",3,120,32000 :REM 32000 is over 8 hours
  136.       dCHOICE agn%   ,"Control Agenda","No,Each morning,Every login"
  137.       dEDIT   view$  ,"Agenda view key"
  138.  
  139.       REM Quit if escape pressed
  140.       IF DIALOG = 0
  141.          STOP
  142.       ENDIF      
  143.       
  144.       REM Check password is valid
  145.       integer% = CALL($2f8b, 0, 0, 0, ADDR(passwd$))
  146.       IF integer% <> 0 
  147.          GIPRINT "Wrong password"
  148.       ENDIF
  149.            
  150.    UNTIL integer% = 0 : REM Until dialog is OK.
  151.    LOCK OFF
  152.  
  153.    view$ = UPPER$(view$)
  154.       
  155.    REM Save away new settings if they have changed
  156.    File:(2)
  157.  
  158.    REM Reduce the screen size and save LOTS of memory
  159.    gSETWIN (gWIDTH - 240) / 2, 65, 240, 31
  160.    gCLS
  161.    gAT 1, 14    
  162.    gXPRINT title$, 1
  163.    stattxt$ = CHR$(2) + "A Arm now   " + CHR$(2) + "P Pause mode"
  164.    AT 1, 2
  165.    PRINT stattxt$
  166.  
  167.    WHILE 1 : REM Main loop
  168.          
  169.       REM Trap someone changing the password.  This isn't ideal, but it's a bit silly changing your password while PsiOn is runing anyway!
  170.       IF CALL($2f8b, 0, 0, 0, ADDR(passwd$)) <> 0
  171.          gSETWIN 0, 0, gwidth%, gheight%
  172.          ALERT("PASSWORD HAS BEEN CHANGED!")
  173.          STOP
  174.       ENDIF
  175.             
  176.       REM Turn off the power-on password
  177.       oscalls%(1) = $3000
  178.       REM oscalls%(2,3,4 and 6)=0
  179.       oscalls%(5) = ADDR(passwd$)
  180.       OS($8b, ADDR(oscalls%()))
  181.          
  182.       REM Open the time device
  183.       IF IOOPEN(hand%, "TIM:", 0) < 0
  184.          RAISE -3 :REM Quit - error
  185.       ENDIF
  186.       
  187.       REM Send the program to the background
  188.       CALL($198d, 100, 0)
  189.  
  190.       REM Get current time for first agenda check + start the timer
  191.       rearmtm& = DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND)
  192.       IOC(hand%, 2, stat%, rearmtm&, nul&)
  193.             
  194.       REM Now wait for some action!
  195.       WHILE 1 : REM Waiting Loop
  196.  
  197.          REM Cancel TIM: so we can start new TIM:
  198.          IOCANCEL(hand%)
  199.          IOWAITSTAT stat%
  200.  
  201.          REM Fire TIM: to wake us up if switched off
  202.          IF pause% = 0
  203.             rearmtm& = DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + rearm&
  204.          ENDIF         
  205.          IOC(hand%, 2, stat%, rearmtm&, nul&)
  206.  
  207.          REM Display agenda screen if required
  208.          IF wakeagn% = 2 :REM 2=Display now
  209.             wakeagn% = 0
  210.             text$ = "AGENDA" + CHR$(0)
  211.             oscalls%(1) = $0100
  212.             oscalls%(2) = UADD(ADDR(text$), 1)
  213.             IF (OS($88, ADDR(oscalls%())) AND 1) = 0 AND oscalls%(1) <> 0 :REM Found Agenda?
  214.                pid% = oscalls%(1)
  215.  
  216.                CALL($198d, 0, pid%) :gUPDATE :REM Now view agenda screen 
  217.  
  218.                ToAgn:(32, 4, pid%) :REM Control-Space - Move to today in Day view
  219.                view$ = LOWER$(view$)
  220.                IF view$ <> "" AND view$ <> " " :REM Any other view wanted?
  221.                   ToAgn:(512 + ASC(view$), 10, pid%) :REM Send Key + 512(psion), and flags (Shift+Psion)
  222.                ENDIF
  223.                   
  224.             ENDIF :REM OS = 0
  225.          ENDIF :REM wakeagn% = 2
  226.       
  227.          REM Check if agenda will need attn
  228.          currday% = DAY
  229.          IF HOUR < 4
  230.             wakeagn% = 1 :REM 1=go on alert, and always check time at login
  231.          ENDIF         
  232.          
  233.          REM Wait for 60 seconds or an event
  234.          integer% = 24 :REM 60 seconds
  235.          WHILE integer% > 0 AND stat% = -46 AND NOT TESTEVENT
  236.             integer% = integer% - 1
  237.             PAUSE 50 :REM 2.5 seconds
  238.          ENDWH
  239.                   
  240.          REM Woke up by TIM: ??  If so, break
  241.          IF stat% <> -46
  242.             IOWAITSTAT stat%
  243.             BREAK : REM Waiting loop
  244.          ENDIF
  245.  
  246.          REM Check for any system messages + quit if required
  247.          event%(1) = 0
  248.          WHILE TESTEVENT
  249.             GETEVENT event%()
  250.             IF event%(1) = 609 OR event%(1) = $404 OR event%(1) = 632 OR (event%(1) = 27 AND (event%(2) AND $FF) = 8) :REM Event QUIT or key Psion-X or Psion-Escape, or Psion-A
  251.                IF event%(1) <> 609 :REM Not Psion-A
  252.                   event%(1) = $404
  253.                ENDIF
  254.                BREAK : REM TESTEVENT Loop
  255.             ENDIF
  256.  
  257.             REM Start pause if required, or cancel if not    
  258.             IF event%(1) = 624 :REM Psion-P (512+112)
  259.                IF pause% = 0
  260.                   pause% = 1
  261.                   AT 1, 2
  262.                   PRINT "Paused until next morning" + GEN$(0,-20) :REM The GEN$ is to put spaces after the text
  263.                   REM Work out what 04:00 is on the next day
  264.                   IF HOUR >= 4
  265.                      SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + 86400, event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer%
  266.                   ELSE
  267.                      SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND), event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer%
  268.                   ENDIF
  269.                   
  270.                   rearmtm& = DATETOSECS(event%(1), event%(2), event%(3), 4, 0, 0)               
  271.                   CONTINUE :REM Around the while testevent again
  272.                ENDIF :REM Pause = 0
  273.             ENDIF :REM Event = 624
  274.  
  275.             REM Cancel pause if not required             
  276.             IF pause% = 1 
  277.                IF event%(1) < $400
  278.                   pause% = 0
  279.                   AT 1, 2
  280.                   PRINT stattxt$
  281.                ENDIF :REM Event = key
  282.             ENDIF :REM Pause = 1
  283.             
  284.          ENDWH :REM WHILE TESTEVENT
  285.  
  286.          IF event%(1) = $404 OR event%(1) = 609 :REM Event QUIT or Key Psion-X or Psion-A (Re-arm now)
  287.             IOCANCEL(hand%)
  288.             IOWAITSTAT stat%
  289.             BREAK : REM Waiting Loop
  290.          ENDIF
  291.  
  292.       ENDWH : REM Waiting loop
  293.       
  294.       REM Turn password back on
  295.       oscalls%(1) = $3001
  296.       REM oscalls%(2,3,4 and 6)=0
  297.       oscalls%(5) = ADDR(passwd$)
  298.       OS($8b, ADDR(oscalls%()))
  299.  
  300.       REM Disable pause mode
  301.       pause% = 0
  302.       AT 1, 2
  303.       PRINT stattxt$
  304.       
  305.       REM Close TIM:
  306.       IOCLOSE(hand%)
  307.  
  308.       REM Turn off PSION, when switched on, run again
  309.       IF event%(1) = $404 :REM Event QUIT or Psion-X
  310.          BEEP 5, 300
  311.          STOP
  312.       ENDIF
  313.       CALL($198d, 100, 0) :gUPDATE :REM Make sure PsiOn is in the background
  314.       CALL($198d, 0, 0)   :gUPDATE :REM Now bring PsiOn to the front!
  315.  
  316.       REM Catch the new "To Front" message
  317.       DO   
  318.          GETEVENT event%()
  319.       UNTIL event%(1) = $401 :REM Event TO FRONT
  320.       WHILE TESTEVENT
  321.          GETEVENT event%()
  322.       ENDWH
  323.  
  324.       REM Switch the machine off
  325.       OFF
  326.       
  327.       REM Run again when PsiOn notices that the password is entered
  328.       event%(1) = 0
  329.       WHILE event%(1) <> $401 :REM Event TO FRONT
  330.          
  331.          CALL($198d, 0, 0) :gUPDATE :REM Put PsiOn to the front!
  332.  
  333.          GETEVENT event%()
  334.          IF event%(1) = $404 :REM Event QUIT
  335.             STOP
  336.          ENDIF
  337.       ENDWH :REM Event TO FRONT
  338.      
  339.       REM See if agenda needs looking at
  340.       IF currday% <> DAY
  341.          wakeagn% = 1 :REM 1=check time on turn on
  342.       ENDIF
  343.       IF ((wakeagn% <> 0 AND HOUR >= 4) OR agn% = 3) AND agn% > 1
  344.          wakeagn% = 2 :REM 2=Display agenda
  345.       ENDIF
  346.          
  347.       REM Loop and Re-arm !!
  348.  
  349.    ENDWH : REM Main loop
  350. ENDP 
  351.  
  352. REM Load (1) / Save (2) to settings 
  353. PROC File:(mode%)
  354.    LOCAL fname$(30)
  355.    LOCAL refresh%
  356.    
  357.    fname$="\OPD\PSI-ON.ODB"
  358.  
  359.    REM Read mode
  360.    IF mode% = 1
  361.       REM Try to read a V1.1 or V1.2 file
  362.       TRAP OPENR fname$, A, rearm& :REM V1 + V1.2 file had beep% and autooff&. and V1.2 files have prompt%, but there not used anymore
  363.       IF ERR = 0
  364.          rearm& = A.rearm&
  365.          REM autooff& isn't used
  366.          REM beep% isn't used
  367.          REM prompt% isn't used
  368.       ENDIF
  369.       TRAP CLOSE 
  370.  
  371.       REM Try to read a V1.3.3 file
  372.       TRAP OPENR fname$, A, rearm&, agn%, view$
  373.       IF ERR = 0
  374.          REM rearm& = A.rearm& - this was done by the read 1.1/1.2 section
  375.          agn%  = A.agn%
  376.          view$ = A.view$
  377.       ENDIF
  378.       TRAP CLOSE 
  379.    ENDIF :REM mode = 1 load
  380.    
  381.    REM Save settings
  382.    IF mode% = 2
  383.       REM Open the file for the current version.  If this fails, or any of the contents are different to the screen setting, then recreate the file
  384.       TRAP OPENR fname$, A, rearm&, agn%, view$
  385.       refresh% = ERR :REM Will be 0 if read ok or <> otherwise
  386.       IF ERR = 0
  387.          IF rearm& <> A.rearm& OR agn% <> A.agn% OR view$ <> A.view$
  388.             refresh% = 1
  389.          ENDIF
  390.       ENDIF
  391.       IF refresh% <> 0
  392.          TRAP CLOSE
  393.          TRAP DELETE fname$
  394.          TRAP MKDIR  "\OPD"
  395.          TRAP CREATE fname$, A, rearm&, agn%, view$
  396.          IF ERR = 0
  397.             A.rearm& = rearm&
  398.             A.agn%   = agn%
  399.             A.view$  = view$
  400.             APPEND
  401.          ENDIF
  402.       ENDIF
  403.       TRAP CLOSE
  404.    ENDIF :REM mode = 2 save   
  405. ENDP
  406.  
  407. REM Send a key to the Agenda process
  408. REM sndkey% is the ASCII value of the
  409. REM         key.  If the PSION key is
  410. REM         wanted to, add 512 to the
  411. REM         sndkey% value
  412. REM flags%  +2 for SHIFT, +8 for PSION
  413. REM         (must add 512 to sndkey% if
  414. REM         you send PSION)
  415. REM For example:
  416. REM A             (65,0,pid%)
  417. REM PSION-A       (512+65,8,pid%)
  418. REM PSION-SHIFT-A (512+65,8+2,pid%)
  419. PROC ToAgn:(sndkey%,flags%, pid%)
  420.    LOCAL key%(2)
  421.  
  422.    key%(1) = sndkey%
  423.    key%(2) = flags%
  424.    CALL($0483, pid%, 49, 0, ADDR(key%()))
  425. ENDP
  426.