Richard Russell
Administrator
member is offline


Posts: 803
|
 |
VDU stream 'icons'
« Thread started on: Sep 5th, 2016, 1:19pm » |
|
One of the unusual features of BBC BASIC, which it inherits from the original 1982 BBC Microcomputer, is that graphics are drawn by outputting special codes to the 'VDU stream'. This allows you to store graphics objects in string variables, which can occasionally be useful.
I took advantage of this feature in the file selector of SDLIDE. I wanted to be able to display a simple icon alongside each entry, indicating whether it is a BBC BASIC program or a directory. Modifying my listbox emulation to support such icons would have been a lot of work, so instead I incorporated the icon in the filename string! Now, simply printing the filename (in VDU 5 mode) automatically plots the icon alongside.
If you're not familiar with this feature of BBC BASIC the end result can seem a bit like magic! Try running the program below to see what I mean:
Code: VDU 23,22,640;512;8,16,16,128 REM Create the 'icon' as a VDU stream in string variable BBfile$: C% = (1.5 * @vdu%!220 + 7) AND -8 VDU 21 OSCLI "spool """ + @tmp$ + "bbfile.vdu""" GCOL 11+128 PLOT 0,C%,0 : PLOT 99,C%*0.75,-C%*0.75 : PLOT 0,C%/4,C%/4 : PLOT 0,-C%*0.75,0 PLOT 115,-C%/2,-C%/2 : PLOT 0,C%/4,C%/4 : PLOT 98,C%*0.75,C%*0.75 : PLOT 0,0,-C%/2 PLOT 1,C%/4,0 : PLOT 1,-C%/2,-C%/2 : PLOT 1,-C%*0.75,0 : PLOT 1,C%/4,C%/4 PLOT 0,C%*1.25,C%*0.75 *spool VDU 6 F% = OPENIN(@tmp$ + "bbfile.vdu") BBfile$ = GET$#F% BY EXT#F% CLOSE #F% REM Now demonstrate plotting the 'icon': VDU 5 REPEAT MOVE RND(1000), RND(1000) PRINT BBfile$ " Hello icon!" WAIT 100 UNTIL FALSE Obviously this technique is not well suited to complex graphics, but it works well for simple line drawings.
Richard.
|