One of the new calls in the RISC OS Sprite Extension Module makes it very easy to display text on the screen at any height and width. If you wondered how the Desktop manages to display text at 80 column width regardless of mode, it is by making use of this call, and it even works in text-only modes.
To make it simple to use, I have parcelled up the call into a procedure which will take a string of text and display it at a specified height and width in the current graphics foreground colour. The procedure, PROCtext, takes five parameters: the x and y co-ordinates of the start of the display, the horizontal and vertical magnification (to reduce, use a magnification less than one), and the text string itself.
The accompanying program contains three examples of the use of the procedure. And you will see that there is an additional function, FNspacing, which calculates the required spacing between characters for the mode in use. As you can see, the text colour is set each time using GCOL immediately before the call.
10 REM >Scaled
20 REM Program Scaled Text
30 REM Version A 0.2
40 REM Author Lee Calcraft
50 REM RISC User June 1989
60 REM Program Subject to Copyright
70 :
80 MODE12
90 DIM scale% 16
100 GCOL 3
110 PROCtext(0,700,7,7,"Scaled Text")
120 GCOL 1
130 PROCtext(0,300,4,12,"any mode")
140 GCOL 2
150 PROCtext(0,100,7,3,"any size")
160 END
170 :
180 DEFPROCtext(x,y,mx,my,text$)
190 scale%!0=mx*16:scale%!4=my*16
200 scale%!8=16:scale%!12=16
210 spacing=mx*FNspacing
220 FOR A%=1 TO LEN(text$)
230 C%=ASC(MID$(text$,A%,1))
240 SYS "OS_SpriteOp",51,C%,,x+(A%-1)*spacing,y,,scale%
250 NEXT
260 ENDPROC
270 :
280 DEFFNspacing
290 CASE MODE OF
300 WHEN 1,4,6,7,9,13:w=32
310 WHEN 2,5,10 :w=64
320 OTHERWISE w=16
330 ENDCASE
340 =w
Reason code: 51
Registers on entry:
R0 | 51 (&33) |
R1 | Character code (ASCII) |
R2 | Not used |
R3 | X co-ordinate |
R4 | Y co-ordinate |
R5 | Not used |
R6 | This must point to a 16 byte block containing four 4-byte scaling factors. For further details, see "RISC OS Sprite Calls" in the last issue. |