# BBC BASIC Programmers' Reference

### Site Tools

simplifying_20arithmetic_20using_20strings

# Differences

This shows you the differences between two versions of the page.

 simplifying_20arithmetic_20using_20strings [2018/03/31 13:19]127.0.0.1 external edit simplifying_20arithmetic_20using_20strings [2018/04/17 18:47]tbest3112 Added syntax highlighting 2018/04/17 18:47 tbest3112 Added syntax highlighting2018/03/31 13:19 external edit 2018/04/17 18:47 tbest3112 Added syntax highlighting2018/03/31 13:19 external edit Line 9: Line 9: | 11\\ | text top line\\ | 32\\ | text top line\\ | | 11\\ | text top line\\ | 32\\ | text top line\\ | \\  I didn't want to go through the whole program changing every reference, it was easier and safer to build a veneer function to convert Acorn VDU offsets into BBFW VDU offsets.\\ \\  If you subtract two from the Acorn offset and then multiply by four you get the same range of BBFW offsets, but in a different order. The difficulty was trying to build a formula to get them in the right order.\\ \\  Looking at the bottom two bits, it needs to convert 0, 1, 2, 3 to 0, 3, 1, 2. I found the easiest way to do that was as follows:​\\ ​ \\  I didn't want to go through the whole program changing every reference, it was easier and safer to build a veneer function to convert Acorn VDU offsets into BBFW VDU offsets.\\ \\  If you subtract two from the Acorn offset and then multiply by four you get the same range of BBFW offsets, but in a different order. The difficulty was trying to build a formula to get them in the right order.\\ \\  Looking at the bottom two bits, it needs to convert 0, 1, 2, 3 to 0, 3, 1, 2. I found the easiest way to do that was as follows:​\\ ​ + m=24+4*VALMID\$("​0312",​(n AND 3)+1,1) m=24+4*VALMID\$("​0312",​(n AND 3)+1,1) + ​ This changes 8, 9, 10, 11 to 24, 36, 28, 32. Taking account of @vdu% values being in pixels, not characters, this allowed me to write the following veneer function:​\\ ​ This changes 8, 9, 10, 11 to 24, 36, 28, 32. Taking account of @vdu% values being in pixels, not characters, this allowed me to write the following veneer function:​\\ ​ + DEF FNvdu(n) DEF FNvdu(n) IF (bbfw) THEN IF (bbfw) THEN Line 16: Line 19: ENDIF ENDIF =VDU n =VDU n + ​ where bbfw is a variable in the program that indicates that it is running on BBC BASIC for Windows.\\ \\ //Richard Russell, May 2009//​\\ ​ The above routine works correctly only in MODEs in which a character cell is 8 pixels wide by 16 pixels high. The alternative code listed below works in all MODEs, and is (arguably) easier to understand:​\\ \\ where bbfw is a variable in the program that indicates that it is running on BBC BASIC for Windows.\\ \\ //Richard Russell, May 2009//​\\ ​ The above routine works correctly only in MODEs in which a character cell is 8 pixels wide by 16 pixels high. The alternative code listed below works in all MODEs, and is (arguably) easier to understand:​\\ \\ + DEF FNvdu(n) DEF FNvdu(n) CASE bbfw AND n OF CASE bbfw AND n OF Line 25: Line 30: ENDCASE ENDCASE = VDU n = VDU n + ​ This code relies on **bbfw** being a Boolean (i.e. having the value 0 or -1).\\ \\ This code relies on **bbfw** being a Boolean (i.e. having the value 0 or -1).\\ \\ ===== See also ===== ===== See also ===== [[/​Data%20without%20DATA|Data without DATA]] [[/​Data%20without%20DATA|Data without DATA]]