home *** CD-ROM | disk | FTP | other *** search
Wrap
REM PsiOn V1.3.3 by Paul Hargreaves REM Please do not distribute modified REM versions of this program REM ╕1996, ╕1997 Paul Hargreaves REM Changes for 1.3.3 REM If Pause mode was used, next day the REM screen showed Pause mode was REM running in error REM If Pause mode was used, and you use REM the machine past midnight, Pause REM sets itself up for the Next day REM instead of today REM Changed text label for Pause mode REM Changes for 1.3.2 REM Sorted out issue where Agenda just REM ignores any events first thing in REM the morning. REM (appears that if Agenda isn't in REM view, that it ignores key presses) REM New for 1.3 REM Press Psion-A in the screen, and REM PsiOn will turn on the password REM and will switch the Psion off - REM just as if the time-out had REM occured. Useful if you leave your REM machine lying around at lunch etc. REM Press Psion-P in the screen, and REM PsiOn will suspend it's auto REM re-arm of the password until REM 04:00 hours the next day rather REM than your normal time REM PsiOn will quit if Psion-Escape is REM pressed REM Agenda control. If selected, PsiOn REM will look for 1 and only 1 running REM task called Agenda. When you next REM log in, Agenda will be pushed to REM the front, in the view of your REM choice REM Instant response to Events - e.g. REM a quit will quit in a couple of REM seconds rather than 15 REM Break the program up into different REM procedures (slightly) REM Upgrades that change the psi-on.opd REM file will keep your old settings REM Learned how to spell Siena <g> REM Low memory mode - removed all the REM unneeded displays! PsiOn uses REM 9/10k when working rather than 19k REM Removed Prompt Option, as no-one REM seems to need it - the Auto option REM added in 1.2 more than replaces it REM Removed Beep Option, as it isn't REM useful and it's now obvious when REM you log in that PsiOn is runing REM Removed New Auto-Off time, as PsiOn REM /should/ be running all the time REM the user will have the value set REM in the standard place REM Changed all dialogs so that no REM special dialogs or code are needed REM for Siena's. REM Changes for 1.2 REM Auto rearm when password is entered REM More beep options REM Rename running program to PsiOn REM Siena (emulator) compatable! REM Tidy up the source a little APP PsiOn EXT "ODB" PATH "\OPD" ICON "\OPL\PSI-ON.ICO" TYPE $1000 ENDA PROC PsiOn: LOCAL hand%, stat% :REM Handle for TIM:, status flag LOCAL nul& :REM A null value LOCAL passwd$(8) :REM Current unlock password LOCAL event%(6) :REM Checking for system events LOCAL oscalls%(6) :REM For OS calls LOCAL wakeagn% :REM 1 if next login should check time/date, 2 if should display immediately LOCAL currday% :REM Holds the current day LOCAL gwidth% :REM Normal screen width LOCAL gheight% :REM Normal screen height LOCAL title$(30) :REM For the title of this program LOCAL rearmtm& :REM Time to re-arm LOCAL integer% :REM General integer LOCAL text$(30) :REM General text LOCAL stattxt$(26) :REM Text "PSION-A To Arm etc." LOCAL pause% :REM 0 for normal, 1 while PsiOn is pausing LOCAL pid% :REM Process ID of agenda GLOBAL rearm& :REM Rearm ticks GLOBAL agn% :REM 1 if agenda not controlled, 2 if auto view after 4am, 3 to always show GLOBAL view$(1) :REM Char to send to Agenda (e.g. w for Week view) REM Rename this process to "PsiOn" for SPY etc to list text$="PsiOn"+CHR$(0) CALL($0c88,CALL($0088),0,0,0,UADD(ADDR(text$),1)) REM Set a nice font, then display the header gheight% = gHEIGHT gwidth% = gWIDTH FONT 7,0 gFONT 7 gAT 1,14 title$="PsiOn V1.3.3 ╕Paul Hargreaves" gXPRINT title$,1 REM Disable PSION-ESC to exit program ESCAPE OFF REM Mark program as in-active CALL($138b) REM Set all defaults in-case file cannot be read rearm& = 900 :REM Quarter of an hour 15*60 view$ = "W" :REM Week view REM Get the user settings from "\opd\psi-on.opd" File:(1) REM Prompt for new settings LOCK ON DO dINIT "PsiOn 1.3.3" dXINPUT passwd$,"Power on password" dTIME rearm& ,"Switched off time",3,120,32000 :REM 32000 is over 8 hours dCHOICE agn% ,"Control Agenda","No,Each morning,Every login" dEDIT view$ ,"Agenda view key" REM Quit if escape pressed IF DIALOG = 0 STOP ENDIF REM Check password is valid integer% = CALL($2f8b, 0, 0, 0, ADDR(passwd$)) IF integer% <> 0 GIPRINT "Wrong password" ENDIF UNTIL integer% = 0 : REM Until dialog is OK. LOCK OFF view$ = UPPER$(view$) REM Save away new settings if they have changed File:(2) REM Reduce the screen size and save LOTS of memory gSETWIN (gWIDTH - 240) / 2, 65, 240, 31 gCLS gAT 1, 14 gXPRINT title$, 1 stattxt$ = CHR$(2) + "A Arm now " + CHR$(2) + "P Pause mode" AT 1, 2 PRINT stattxt$ WHILE 1 : REM Main loop REM Trap someone changing the password. This isn't ideal, but it's a bit silly changing your password while PsiOn is runing anyway! IF CALL($2f8b, 0, 0, 0, ADDR(passwd$)) <> 0 gSETWIN 0, 0, gwidth%, gheight% ALERT("PASSWORD HAS BEEN CHANGED!") STOP ENDIF REM Turn off the power-on password oscalls%(1) = $3000 REM oscalls%(2,3,4 and 6)=0 oscalls%(5) = ADDR(passwd$) OS($8b, ADDR(oscalls%())) REM Open the time device IF IOOPEN(hand%, "TIM:", 0) < 0 RAISE -3 :REM Quit - error ENDIF REM Send the program to the background CALL($198d, 100, 0) REM Get current time for first agenda check + start the timer rearmtm& = DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) IOC(hand%, 2, stat%, rearmtm&, nul&) REM Now wait for some action! WHILE 1 : REM Waiting Loop REM Cancel TIM: so we can start new TIM: IOCANCEL(hand%) IOWAITSTAT stat% REM Fire TIM: to wake us up if switched off IF pause% = 0 rearmtm& = DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + rearm& ENDIF IOC(hand%, 2, stat%, rearmtm&, nul&) REM Display agenda screen if required IF wakeagn% = 2 :REM 2=Display now wakeagn% = 0 text$ = "AGENDA" + CHR$(0) oscalls%(1) = $0100 oscalls%(2) = UADD(ADDR(text$), 1) IF (OS($88, ADDR(oscalls%())) AND 1) = 0 AND oscalls%(1) <> 0 :REM Found Agenda? pid% = oscalls%(1) CALL($198d, 0, pid%) :gUPDATE :REM Now view agenda screen ToAgn:(32, 4, pid%) :REM Control-Space - Move to today in Day view view$ = LOWER$(view$) IF view$ <> "" AND view$ <> " " :REM Any other view wanted? ToAgn:(512 + ASC(view$), 10, pid%) :REM Send Key + 512(psion), and flags (Shift+Psion) ENDIF ENDIF :REM OS = 0 ENDIF :REM wakeagn% = 2 REM Check if agenda will need attn currday% = DAY IF HOUR < 4 wakeagn% = 1 :REM 1=go on alert, and always check time at login ENDIF REM Wait for 60 seconds or an event integer% = 24 :REM 60 seconds WHILE integer% > 0 AND stat% = -46 AND NOT TESTEVENT integer% = integer% - 1 PAUSE 50 :REM 2.5 seconds ENDWH REM Woke up by TIM: ?? If so, break IF stat% <> -46 IOWAITSTAT stat% BREAK : REM Waiting loop ENDIF REM Check for any system messages + quit if required event%(1) = 0 WHILE TESTEVENT GETEVENT event%() 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 IF event%(1) <> 609 :REM Not Psion-A event%(1) = $404 ENDIF BREAK : REM TESTEVENT Loop ENDIF REM Start pause if required, or cancel if not IF event%(1) = 624 :REM Psion-P (512+112) IF pause% = 0 pause% = 1 AT 1, 2 PRINT "Paused until next morning" + GEN$(0,-20) :REM The GEN$ is to put spaces after the text REM Work out what 04:00 is on the next day IF HOUR >= 4 SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND) + 86400, event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer% ELSE SECSTODATE DATETOSECS(YEAR, MONTH, DAY, HOUR, MINUTE, SECOND), event%(1), event%(2), event%(3), event%(4), event%(5), event%(6), integer% ENDIF rearmtm& = DATETOSECS(event%(1), event%(2), event%(3), 4, 0, 0) CONTINUE :REM Around the while testevent again ENDIF :REM Pause = 0 ENDIF :REM Event = 624 REM Cancel pause if not required IF pause% = 1 IF event%(1) < $400 pause% = 0 AT 1, 2 PRINT stattxt$ ENDIF :REM Event = key ENDIF :REM Pause = 1 ENDWH :REM WHILE TESTEVENT IF event%(1) = $404 OR event%(1) = 609 :REM Event QUIT or Key Psion-X or Psion-A (Re-arm now) IOCANCEL(hand%) IOWAITSTAT stat% BREAK : REM Waiting Loop ENDIF ENDWH : REM Waiting loop REM Turn password back on oscalls%(1) = $3001 REM oscalls%(2,3,4 and 6)=0 oscalls%(5) = ADDR(passwd$) OS($8b, ADDR(oscalls%())) REM Disable pause mode pause% = 0 AT 1, 2 PRINT stattxt$ REM Close TIM: IOCLOSE(hand%) REM Turn off PSION, when switched on, run again IF event%(1) = $404 :REM Event QUIT or Psion-X BEEP 5, 300 STOP ENDIF CALL($198d, 100, 0) :gUPDATE :REM Make sure PsiOn is in the background CALL($198d, 0, 0) :gUPDATE :REM Now bring PsiOn to the front! REM Catch the new "To Front" message DO GETEVENT event%() UNTIL event%(1) = $401 :REM Event TO FRONT WHILE TESTEVENT GETEVENT event%() ENDWH REM Switch the machine off OFF REM Run again when PsiOn notices that the password is entered event%(1) = 0 WHILE event%(1) <> $401 :REM Event TO FRONT CALL($198d, 0, 0) :gUPDATE :REM Put PsiOn to the front! GETEVENT event%() IF event%(1) = $404 :REM Event QUIT STOP ENDIF ENDWH :REM Event TO FRONT REM See if agenda needs looking at IF currday% <> DAY wakeagn% = 1 :REM 1=check time on turn on ENDIF IF ((wakeagn% <> 0 AND HOUR >= 4) OR agn% = 3) AND agn% > 1 wakeagn% = 2 :REM 2=Display agenda ENDIF REM Loop and Re-arm !! ENDWH : REM Main loop ENDP REM Load (1) / Save (2) to settings PROC File:(mode%) LOCAL fname$(30) LOCAL refresh% fname$="\OPD\PSI-ON.ODB" REM Read mode IF mode% = 1 REM Try to read a V1.1 or V1.2 file 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 IF ERR = 0 rearm& = A.rearm& REM autooff& isn't used REM beep% isn't used REM prompt% isn't used ENDIF TRAP CLOSE REM Try to read a V1.3.3 file TRAP OPENR fname$, A, rearm&, agn%, view$ IF ERR = 0 REM rearm& = A.rearm& - this was done by the read 1.1/1.2 section agn% = A.agn% view$ = A.view$ ENDIF TRAP CLOSE ENDIF :REM mode = 1 load REM Save settings IF mode% = 2 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 TRAP OPENR fname$, A, rearm&, agn%, view$ refresh% = ERR :REM Will be 0 if read ok or <> otherwise IF ERR = 0 IF rearm& <> A.rearm& OR agn% <> A.agn% OR view$ <> A.view$ refresh% = 1 ENDIF ENDIF IF refresh% <> 0 TRAP CLOSE TRAP DELETE fname$ TRAP MKDIR "\OPD" TRAP CREATE fname$, A, rearm&, agn%, view$ IF ERR = 0 A.rearm& = rearm& A.agn% = agn% A.view$ = view$ APPEND ENDIF ENDIF TRAP CLOSE ENDIF :REM mode = 2 save ENDP REM Send a key to the Agenda process REM sndkey% is the ASCII value of the REM key. If the PSION key is REM wanted to, add 512 to the REM sndkey% value REM flags% +2 for SHIFT, +8 for PSION REM (must add 512 to sndkey% if REM you send PSION) REM For example: REM A (65,0,pid%) REM PSION-A (512+65,8,pid%) REM PSION-SHIFT-A (512+65,8+2,pid%) PROC ToAgn:(sndkey%,flags%, pid%) LOCAL key%(2) key%(1) = sndkey% key%(2) = flags% CALL($0483, pid%, 49, 0, ADDR(key%())) ENDP