SB BBC @ GBR Oldie hints/tips #112-114 Hints and tips from the archives of Wakefield BBC Micro User Group... 112. Use for EVAL ~~~~~~~~~~~~ People often get confused between VAL and EVAL on the Beeb. VAL simply tries to treat a string as a number, so PRINT VAL("4*3+1") would give the answer 4. The asterisk is a non-numeric character, so it and anything after it are ignored. However, EVAL goes a step further, by attempting to evaluate the string as a valid numeric expression, and would give the answer 13. It is therefore possible to write a program which accepts an equation as a string, thus opening up some interesting possibilities. Anyway, here is a more down-to-earth use for EVAL, for which I claim no originality. If you think about it, there isn't any obvious way to INPUT a number in Hex format; only in Decimal. You can overcome this with the technique below. 10 INPUT"Hex number :&" A$:A=EVAL("&"+A$) You can also use this technique in conjunction with READ and DATA to enable you to put Hex numbers in data statements, without bothering with the ampersands, eg DATA 5B,3C,20,FF instead of DATA &5B,&3C,&20,&FF etc. 113. Altering the RS423 format ~~~~~~~~~~~~~~~~~~~~~~~~~ If you are experimenting with the RS423 serial port, and need to alter the data format, then you can do so with the command *FX156,X,227 . The value of X can be looked up in the table below, where X is 4*n. The default value on the Beeb is n=5, corresponding to *FX156,20,227 . DATA BITS PARITY STOP BITS n X --------- ------ --------- - -- 7 even 2 0 0 7 odd 2 1 4 7 even 1 2 8 7 odd 1 3 12 8 none 2 4 16 8 none 1 5 20 8 even 1 6 24 8 odd 1 7 28 You can read the current value of n using the following function. If you want to read the value of X rather than of n, then change the &400 in line 1020 to &100. Note the comment in tip #111 about X% being LOCAL. 1000 DEF FNstatus:LOCAL A%,X%,Y% 1010 A%=156:Y%=255 1020 =(USR(&FFF4) AND &1C00) DIV &400 114. Another relocate program ~~~~~~~~~~~~~~~~~~~~~~~~ Earlier, I gave a Procedure for tacking onto the end of a Basic program, so that long programs could be run off disc, with a PAGE value down to &E00. This works fine, but there are times when this is not convenient. If you are adapting a very long and complex program from cassette to disc, it may not be safe to go tacking procedures on the end. This is especially true if there is data after the visible Basic part of the program, as any additions are likely to overwrite it. A typical example would be a text adventure game like Castle of Riddles, which is 65 blocks long, over half of which is data. This is too long to even LOAD into memory with PAGE set at &1900. The solution is to make the program a 2-part one, with the relocate routine in the 1st half, thus avoiding any need to tamper with the main program. If the program is short enough to run with PAGE at &1100, then the 1st program need consist only of one line, ie 10 PAGE=&1100:CHAIN "Dragon2" . If the program must run with PAGE lower than that, eg &E00, then the program below will do the trick. It is so fast that it doesn't bother to work out the length of the program, (tricky if you have to allow for any hidden data), but simply relocates all available memory in 1/3 second. In line 10 you specify the new value of PAGE, eg &E00, and the name of the main program. You could of course replace the final term with an INPUT N$ statement, in which case the one relocator will run any named program. PAGE is initially set to &1100 in line 10, in case the main program is too long to even LOAD with PAGE at &1900. This doesn't affect the relocator itself, which churns on merrily, blissfully unaware that PAGE has been altered, but it does define where the main program will LOAD. In many cases, this 1st term in line 10 can be omitted, but it doesn't do any harm to leave it in, (with the Acorn 8271 DFS's at any rate). The program may already have a first part, which just sets up some of the character shapes, and displays a logo on the screen. You could easily add this routine in place of the CHAIN "Dragon2" type of command, followed by END if necessary. Ignore any corruption of the logo; if you're clever enough, you'll know how to preserve it! This program looks rather weird, and it can be hard to spot mistakes. Try missing out the VDU21 in line 60 at first, otherwise useful error messages are suppressed. 10 PAGE=&1100:D%=&E00:N$="Dragon2" 20 !&70=D%:!&72=PAGE:!&74=HIMEM-PAGE 30 P%=&76:[OPT2:LDX&74:LDY#0 40 LDA(&72),Y:STA(&70),Y:INY:BNE&85:INC&71:INC&73 50 DEX:BNE&7A:DEC&75:BNE&7A:RTS:] 60 VDU21:*KEY9LOADN$|M*TAPE|MCALL&76|MPAGE=D%|MNEW|MOLD|MRUN|F|M 70 *FX138,0,137 73 Rick G4BLT @ GB7WRG