SB BBC @ GBR Oldie hints/tips #179-181 Hints and tips from the archives of Wakefield BBC Micro User Group... 179. Reading/writing registers using OSBYTE ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ There are many Osbyte calls, (*FX calls if you like), which can read from and write to various registers. The format given is a bit daunting to the unitiated:- =( AND Y) EOR X What it means is that the new value you are putting into the register is made up of the original value, after logical ANDing it with the contents of Y, and then Exclusive ORing the result with the contents of X. Why bother with all this complication; why not just stick the new value in and have done? Well, you can, but there's more to it than that. If you want to READ the register without altering the contents, then simply make the appropriate call with X=0 and Y=255, and the current value in the register will usually be in X on exit. The contents will be ANDed with 255, which is 11111111 binary, and will thus be unchanged. Then, they will be Exclusive ORed with 0, which is 00000000 in binary, which also leaves them unchanged. So, nothing is altered. You can do this from BASIC with the command:- 10 A%=156:X%=0:Y%=255:PRINT~(USR&FFF4 AND&FF00)DIV&100 If you want to write a specific value to the register, then you can make Y=0 and X=. Thus, ANDing with 0 clears all the bits, and EORing them with X writes X into the register. Eg:- *FX4,2,0 (the ",0" may be omitted), writes 2 into the register; in this case it affects the action of the cursor keys. Using 4 as the osbyte number in the USR call above should return 0 to 2 depending on what setting of *FX4 is current. It may well be that you want to alter only certain bits in a register, but you don't know exactly what the contents of the other bits will be at the time. For example, with *FX156, bits 5 and 6 affect the status of the RTS line on the RS423 port. I may wish to alter these bits, without knowing the contents of, and without wishing to alter, bits 7 and 0 to 4. This is where the apparent complicated way of doing things comes into its own. The method is:- 1. Set only the bits in Y which you do NOT wish to be affected in any way. 2. Set only the bits in X that you wish to be set to 1 in the register, and leave the rest as 0. 3. Make the appropriate osbyte call. In the example above, if I wished to set bits 5 and 6 to 1, without altering the other bits, then X=&60 and Y=&9F. If I wished to set bit 5 to 0 and bit 6 to 1, then X=&40 and Y=&9F. 180. Printer snag ~~~~~~~~~~~~ Several people have come up against an unexpected snag with some of the newer Epson printers such as the LX80 and LX800, as well as the Citizen 120D when in Epson-compatible mode. After having problems trying to redefine the draft character set, they read the small print in the manuals to find that you are only able to redefine the 6 characters ":;<=>?". Some earlier Epsons, and printers like the Canon PW-1080A and Taxan-Kaga KP810, allow you to redefine ALL the characters if you wish. This seems a curiously retrograde step by Epson, and you should take care when choosing a printer, if this is a facility you particularly need. 181. Friangle ~~~~~~~~ The inspiration for this program came to Bob G3WWF whilst watching a programme on Channel 4. The theme was concerned with how simple rules are able to define quite complex structures, such as a fern leaf. To illustrate this, a simple method of plotting a sort of Fractal Triangle, (hence "Friangle"), was briefly described. In Bob's words:- "Three points of an equilateral triangle are stated, and then a random initial point. A point is then plotted which is half way from the initial point to one of the three triangle tips, chosen at random. From this new point another point is plotted, again halfway to one of the triangle tips at random, and so on. One's first assumption is surely that the points will fill the triangle randomly, but not so!" The program is very simple indeed, and has been further simplified and speeded up by Rick G4BLT. An additional 20% increase in speed can be achieved by using Integer arithmetic; change X to X%, Y to Y% and replace "/" with "DIV". The result is surprising and pleasing; a recursive pattern in fact. A few apparently 'stray' points will sometimes appear; see if you can work out why this happens! 10 MODE0:X=RND(1182)-1:Y=RND(1024)-1:MOVEX,Y 20 REPEAT:ONRND(3)GOSUB100,110,120:PLOT69,X,Y:UNTILFALSE 30 : 100 X=X/2:Y=Y/2:RETURN 110 X=(X+1181)/2:Y=Y/2:RETURN 120 X=(X+590)/2:Y=(Y+1023)/2:RETURN 73 Rick G4BLT @ GB7WRG