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.