SB BBC @ GBR Oldie hints/tips #021-027 Hints and tips from the archives of Wakefield BBC Micro User Group... 21. Press space-bar to continue ~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are various ways of doing this. The first method looks at the keyboard buffer, so if the Space-bar has been pressed just before the message, it will carry straight on. If this is a problem, then either use the second variant with the *FX21,0 buffer clear command, or use the third version. This will still cause a Space to enter the keyboard buffer, so this is cleared with *FX21,0 to avoid problems later. Although written as Procedures, they don't have to be. Call them with PROCspace. 1000 DEFPROCspace:REPEAT UNTIL GET=32:ENDPROC 1000 DEFPROCspace:*FX21,0 1010 REPEAT UNTIL GET=32:ENDPROC 1000 DEFPROCspace:REPEAT UNTIL INKEY(-99):*FX21,0 1010 ENDPROC 22. Time delays ~~~~~~~~~~~ Apart from using a dummy FOR-NEXT loop, there are two main ways to put a time delay in programs. The first is to use the TIME facility, and the other is to use INKEY. The first TIME routine resets the TIME to zero on each occasion. If you wish to avoid this, then the second routine will overcome the problem. The INKEY routine will give a similar delay, except that the delay terminates on pressing any key. The example provides a 2 second delay, (200 centiseconds). Call them with PROCdelay. 1000 DEFPROCdelay:TIME=0:REPEAT UNTIL TIME>=200:ENDPROC 1000 DEFPROCdelay:LOCAL now%:REPEAT UNTIL TIME>=now%+200:ENDPROC 1000 DEFPROCdelay:LOCAL pause%:pause%=INKEY(200):ENDPROC Another way is to call up whatever length delay you want, but still only using one Procedure. You can call up delays with PROCdelay(100), or PROCdelay(200) etc. as follows:- 1000 DEF PROCdelay(wait%):TIME=0:REPEAT UNTIL TIME>=wait%:ENDPROC 1000 DEF PROCdelay(wait%):LOCAL now%:now%=TIME:REPEAT UNTIL TIME>=now%+wait%:ENDPROC 1000 DEF PROCdelay(wait%):LOCAL pause%:pause%=INKEY(wait%):ENDPROC Note the use of Integer variables for accuracy. The variable pause% is a dummy, to satisfy the INKEY syntax. The variable wait% is an implied LOCAL variable, so can be used elsewhere in the program quite independently, without any clash. 23. Printer output only ~~~~~~~~~~~~~~~~~~~ Sometimes it is handy to be able to send text to the printer only, without it appearing on the VDU screen at the same time. This can be done by using VDU2,21 to activate the printer, and VDU6,3 to turn it off again and to restore the VDU drivers. This can cause problems if you try to send anything other than normal text or figures. Control codes or graphic data may be corrupted due to the filtering of the "printer ignore character" specified by *FX6. *FX3,10 and *FX3,0 have a similar effect to these VDU commands. 24. Simulated duff TV ~~~~~~~~~~~~~~~~~ This routine gives the fairly convincing impression that your TV or monitor has gone duff, especially if you turn the brightness up a bit. If you have a Master or Compact, then the ",0;0;0;" bit can be replaced by the single character '|'. Someone suggested hiding it somewhere in a program, as a booby trap for your mates.... 10 VDU23,0,RND(255),RND(255),0;0;0;:GOTO 10 25. Cube roots ~~~~~~~~~~ A reminder for those of us who aren't too hot at Maths. In BBC BASIC, a square root can be obtained with A=SRQ(B), but how to get the cube root? The answer is that SQR is unnecessary, as you could use A=B^(1/2) instead. Thus the cube root is given by A=B^(1/3) etc. 26. Integer variables ~~~~~~~~~~~~~~~~~ Programs can be speeded up by using Integer variables where possible. Try running this program first using X, and then using X% instead. Using NEXT rather than NEXT X or NEXT X% makes it even faster; try it. 10 TIME=0:FOR X=1 TO 5000:NEXT X:PRINT TIME 27. Disc relocate ~~~~~~~~~~~~~ This routine, sometimes referred to rather confusingly as a 'downloader', enables programs to be run which are normally too large for use with a DFS fitted. It switches off the DFS with *TAPE, and shifts the whole program down to &E00 before running it. The screen output is temporarily inhibited with VDU21 during relocation, and reactivated afterwards with |F (VDU6), to give a tidy appearance. For debugging, the VDU21 may be omitted initially, as it also inhibits useful error messages! The routine will relocate BASIC programs, including those containing assembler. If there is also 'hidden' data and/or machine code, then it is easiest to alter the TOP in line 1 to HIMEM, although this makes the routine rather slower. Spaces are shown for clarity only, line 1 is split at a convenient point for the same reason. 0 IF PAGE=&E00 THEN 10 1 VDU21:*KEY9 *TAPE|M FOR I%=0 TO TOP-PAGE STEP 4: I%!&E00=I%!PAGE:NEXT|M PAGE=&E00|M NEW|M OLD|M RUN|F|M 2 *FX138,0,137 3 END : REM Most Important! 10 REM Start of your Program. 73 Rick G4BLT @ GB7WRG