Loading+BFont+files

8x8 bitmap character definitions (called BFonts) are defined with **VDU 23** and read with OSWORD 10. They can be saved as BFont files ([|such as these]) as the sequences of eight bytes that define each character.

These BFont files can be loaded to define characters, and code using VDU similar to the following is often used: code REM file loaded to mem% FOR C%=start% TO end% VDU 23,C% FOR B%=0 TO 7 VDU ?(mem%+C%*8+B%) NEXT B%   NEXT C% code

A more efficient way to do this is to notice that the **VDU 23,C%** can be done within the loop just before every eighth byte: code FOR A%=0 TO len%-1 IF (A% AND 7)=0 THEN VDU 23,(A% DIV 8)+start% VDU mem%?A% NEXT A% code

Bitmap fonts can also be saved as streams of **VDU 23** sequences. As these include the character number that is being defined **start%** is not needed, so it can be used as a flag so the same code can read 8-byte raw BFont files and 10-byte VDU sequence BFont files: code REM BFont file loaded to mem%, length in len% REM start%=0 for VDU file, start%<>0 for raw file :   FOR A%=0 TO len% IF start% THEN IF (A% AND 7)=0 THEN VDU 23,(A% DIV 8)+start% VDU mem%?A% NEXT A% code or: code REM BFont file loaded to mem%, length in len% REM start%=0 for VDU file, start%<>0 for raw file : FOR A%=0 TO len%:IF start%:IF (A% AND 7)=0:VDU 23,(A% DIV 8)+start% VDU mem%?A%:NEXT A% code

If **len%** is not a whole multiple of 8 bytes with a raw BFont file, or a whole multiple of 10 bytes with a VDU BFont file then the code will end in the middle of a VDU sequence. You should test that **len%** is valid beforehand with code such as the following: code IF (len% MOD 8)<>0 AND ?mem%<>23 AND (mem% MOD 10)<>0 THEN PRINT "Not a valid BFont file" code 1388119694