home *** CD-ROM | disk | FTP | other *** search
- PBASMLIB Assembly Language Routines for PB3C
- Version 1.0
- Miscellaneous Routines Module
- (C) Copyright 1994 by Tim Gerchmez
- All Rights Reserved.
-
- This module contains miscellaneous routines. It will be immediately
- accessible to your programs by adding the statements $INCLUDE "PBASMLIB.INC"
- and $LINK "PBASMLIB.PBL" at the top of your programs. It's recommended
- that you use these routines only in a standalone .EXE file, since they
- include several interrupt-driven routines which should not be repeatedly
- stopped and restarted with IDE compiles. There is a possibility of
- interrupt vectors being corrupted if these routines are used in the
- PowerBASIC IDE environment.
-
- ================================================================================
- function countflag
-
- Used in conjunction with the PBASMLIB COUNTDOWN timer to check
- when countdown is finished. COUNTFLAG will return -1 when countdown
- is complete, or 0 if COUNTDOWN is still progressing. Countflag will
- not be reset to zero until COUNTDOWN is started again.
-
- Example: print countflag
-
- ================================================================================
- function countval
-
- Returns the time remaining for the countdown timer COUNTDOWN.
- It will return the number of timer ticks left (18.2 per second)
- until the countdown timer completes its countdown.
-
- Example: print countval
-
- ================================================================================
- sub countdown(t??)
-
- Sets and activates a "countdown timer" that can be checked
- with COUNTFLAG or used in conjunction with ON UEVENT to branch
- to a subroutine when the countdown completes. When the countdown
- completes, the "countdown timer" will have to be reset with this
- routine again if another countdown needs to be done. A countdown can
- also be interrupted in the middle and restarted using any value desired
- by simply issuing this command again. Note: Unlike some of the other
- routines in PBASMLIB's MISC module, countdown WILL work in the IDE just fine.
-
- t??: Set to number of "timer ticks." Each timer tick is 1/18.2 of
- a second. When the countdown completes, a flag will be set that
- you can check with COUNTFLAG, or you can use UEVENT to automatically
- interrupt your program (see example below, and the PB manuals).
-
- Example: on uevent gosub counted 'UEVENT is a PowerBASIC command
- uevent on 'Turn UEVENT checking on.
- countdown 18.2*5 'Set countdown timer for 5 seconds
- do:loop 'Go into an endless (actually 5-second) loop
- counted:
- print "UEVENT HAPPENED!":end
-
- Example: countdown 36.4 '2-second countdown
- do
- loop until countflag 'Use COUNTFLAG function
- print "countdown complete."
-
- ================================================================================
- function alarmcheck
-
- Checks the status of the CMOS alarm set with ALARMSET.
- Returns zero if alarm has not gone off, or -1 if alarm has
- gone off. The ALARMCHECK flag will stay at -1 after the alarm
- has gone off, until alarm is reset with the ALARMSET procedure,
- or turned off with ALARMCLEAR. You can use ON UEVENT instead of
- alarmcheck to cause your program to branch to a subroutine when the
- alarm goes off.
-
- Example: if alarmcheck then print "Alarm went off."
-
- ================================================================================
- sub alarmclear
-
- Clears any pending alarm request on the CMOS time/date chip
- (see ALARMSET). Use to cancel ALARMSET at the end of your
- PowerBASIC program, if the alarm hasn't gone off by the time
- your program ends (if it has, calling this routine won't do any
- harm). Note that the alarm is cleared or turned off automatically
- when it "rings" - you must call ALARMSET again to restart it after
- it has gone off.
-
- Example: call alarmclear
-
- ================================================================================
- sub alarmset(hr%,mn%,sc%)
-
- Sets an interrupt-level alarm clock in the CMOS time/date chip that
- can be checked at any time during the program with ALARMCHECK, or can
- be trapped with ON UEVENT. Only one alarm may be active at any given time.
- When the alarm goes off, a flag will be set which you can check with ALARMCHECK.
- You can also use ON UEVENT GOSUB and UEVENT ON to make your program branch to a
- particular place when the alarm goes off (see example below). Be sure to use
- ALARMCLEAR at the end of your program to turn off the alarm if the program ends
- before the alarm goes off, or a system crash will occur after the program exits
- to DOS and the alarm finally goes off. ALARMCLEAR is called automatically when
- the alarm goes off, so you'll have to call this routine again to reactivate the alarm.
-
- Note: I've found that for some reason this routine will
- not work in the PB IDE. An alarm can only be set
- and activated from a standalone .EXE program.
-
- hr%: Set to hour (0-23) - Military (24-Hr.) time
- mn%: Set to minutes (0-59)
- sc%: Set to seconds (0-59)
-
- Example: alarmset 0,0,0 'Set to midnight exactly
- do
- if alarmcheck then
- print "Midnight!":beep 'See ALARMCHECK
- end
- end if
- loop 'Waits til midnight
-
- Example: on uevent gosub alarmrang 'GOSUB to alarmrang when alarm goes off
- uevent on 'Turn on UEVENT trapping
- alarmset 0,0,0 'Set to midnight
- 'Continue your program here, the subroutine you
- 'specified in ON UEVENT will be called at alarm time.
-
-
- ================================================================================
- function checkbreak
-
- Works in conjunction with the FAILSAFE command to return a flag
- indicating whether the user attempted to break out of a program.
- Returns 0 if not, 1 if user pressed CTRL-BREAK, or 2 if user pressed
- CTRL-ALT-DEL. Using CHECKBREAK sets the flag to zero, so assign CHECKBREAK
- to a variable if you need to save the status of the flag.
-
- Example: cb% = checkbreak
-
- ================================================================================
- sub coldboot
-
- Calling this routine will perform a cold boot, resetting
- the computer. This routine is optimized to reboot the computer
- in just about all situations, including multitasking and protected
- mode environments like Desqview or Windows. Use with caution, and
- make sure all files are closed and data is flushed before calling this
- routine, or data loss may occur (Caution: data loss may occur when using
- this routine with delayed writeback disk cache programs). You use this
- routine entirely at your own risk and the risk of the users of your programs.
-
- Example: call coldboot
-
- ================================================================================
- sub failsafe(ed%)
-
- Executes a routine that traps the CTRL-C, CTRL-BREAK and
- CTRL-ALT-DEL key combinations. This makes your program
- "failsafe" in that it can't be terminated by any of these keys,
- or rebooted by the user at the wrong time. It also prevents the
- infamous PB3 "CTRL-BREAK" problem, where sometimes a PowerBASIC
- program will exit to DOS after CTRL-BREAK is pressed without resetting
- interrupt vectors - a sure guarantee of a system crash. Note: BE SURE
- TO TURN FAILSAFE OFF WITH FAILSAFE 0 BEFORE ENDING YOUR PROGRAM, OR A
- SYSTEM CRASH WILL OCCUR WHEN THE USER EXITS TO DOS!! Also, FAILSAFE has
- no effect while in the PB IDE, and works only in a standalone .EXE file.
-
- ed%: Set to 1 or 0. A one turns failsafe mode on, and a zero
- turns failsafe mode off. Turning failsafe mode on also activates
- the CHECKBREAK function to check if the user attempted to break out of
- the program (see CHECKBREAK).
-
- Example: failsafe 1 'Make your program "failsafe"
-
- ================================================================================
- sub micropause(us&)
-
- Pauses for a specified number of microseconds (one
- millionth of a second). This routine isn't perfectly
- accurate, as it takes a few microseconds for BASIC to call
- the routine, but it does allow a finer resolution than MILLIPAUSE.
-
- us&: Set to number of microseconds to pause (1 million = 1 second).
- Max. value that can be passed in a long int is a little over two
- million, or about two seconds max delay with this routine.
-
- Example: micropause 10 'Pause 10 microseconds (more or less)
-
- ================================================================================
- sub millipause(ms%)
-
- Pauses for the specified number of milliseconds (1/1000 of
- a second. For finer resolution, use micropause, which pauses for
- multiples of 1/1,000,000 of a second.
-
- ms%: Set to milliseconds to pause
-
- Example: millipause 250 'Pause 250 ms, or 1/4 of a second
-
- ================================================================================
- sub pbasound(p%,d%)
-
- Similar to PowerBASIC's SOUND statement, but does not pull in the
- floating point library (which can add 17-20K to your programs if needed
- only for the SOUND statement), and has a higher delay resolution than the
- SOUND statement (milliseconds). Also, PBASOUND will not allow your program
- to continue until the tone is finished sounding (unlike PB's SOUND statement).
- To cancel a tone that is "stuck" on after pressing CTRL-BREAK, execute a
- PBASOUND statement with a duration or frequency of zero.
-
- p%: Set to frequency value in hertz (37-32767)
- d%: Set to milliseconds to delay (a millisecond is 1/1000 of a second).
- The maximum length of time you can sound a tone with PBASOUND is 32767
- milliseconds, or about 32 seconds. To sound longer tones, execute multiple
- PBASOUND statements.
-
- Example: pbasound 250,500 '250 hz. tone 1/2 second long
-
- ================================================================================
- sub softlockup
-
- Locks up the processor, creating a temporary condition that
- can be reset with CTRL-ALT-DEL. This routine is mostly harmless and does
- not affect background processes (to my knowledge) such as disk caches,
- etc. Use with caution, however, as there won't be too many situations
- where you'll want to intentionally cause a lockup. For a "hard" lockup,
- see HARDLOCKUP.
-
- Example: call softlockup
-
- ================================================================================
- sub hardlockup
-
- Locks up the processor, creating a permanent condition that
- can only be overcome by powering down/back up or pressing the reset
- button. CTRL-ALT-DEL will have no effect. Use this routine with
- extreme caution, as it halts the processor and can affect background
- processes such as lazy-write disk caches, etc. Data loss may occur
- if the CPU is locked up while files are still open, etc. This routine
- will have an unpredictable effect in a multitasking environment.
-
- Example: call hardlockup
-
- ================================================================================
- sub keyboardlock(l%)
-
- Allows you to lock (disable) and unlock access to the
- keyboard. Keypresses will be "stored up" in the keyboard
- controller while the keyboard is locked, and released when
- unlocked (including CTRL-ALT-DEL, etc). You can clear the
- keyboard buffer after unlocking the keyboard, if desired.
-
- l%: Set to 1 to lock the keyboard, or 0 to unlock the keyboard
-
- Example: keyboardlock 1 'Keyboard is "locked up" until called again with 0
-
- ================================================================================
- sub warmboot
-
- Performs a warm reboot, resetting your computer like CTRL-ALT-DEL had
- been pressed (skips the power-up memory test). Use COLDBOOT to perform a
- cold reboot instead if desired (similar to pressing the reset button or
- powering off/back on). This routine is optimized to reboot the computer
- in just about all situations, including in multitasking environments. Use
- with extreme caution, making sure all data is flushed to disk and files are
- closed. You use this routine entirely at your own (and your program's user's)
- risk.
-
- Example: call warmboot
-
-