home *** CD-ROM | disk | FTP | other *** search
/ PDA Software Library / pdasoftwarelib.iso / PSION / 1997 / 947.ZIP / Psi-on.opl < prev    next >
Encoding:
Text File  |  1997-03-07  |  15.3 KB  |  463 lines

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