I haven't made it into a function, but this is how I would do it.
string$="This is a test! "
font$="Gungsuh"
size=24
color as dword
color=rgb(255,0,0)
box_width=25
randomize timer()
backdrop off
sync on
sync rate 0
hide mouse
set bitmap format 21
set text font font$
set text size size
ink color,0
textwidth=text width(string$)
create bitmap 1,textwidth,text height(string$)
text 0,0,string$
get image 1,0,0,textwidth,text height(string$),3
set current bitmap 0
delete bitmap 1
width=box_width
height=text height(string$)
make memblock 2,width*height*32*4+12
write memblock dword 2,0,width
write memblock dword 2,4,height
write memblock dword 2,8,32
make memblock from image 1,1
make image from memblock 2,2
sprite 1,0,0,2
set sprite 1,0,1
left=0
do
if delay+50<timer()
for x=0 to width-1
for y=0 to height-1
write memblock dword 2,(y*width+x)*4+12,memblock dword(1,(y*textwidth+wrap(x+l,textwidth-1))*4+12)
next y
next x
make image from memblock 2,2
inc l
delay=timer()
endif
offset sprite 1,-mousex(),-mousey()
sync
cls
loop
end
function wrap(value,maximum)
while value>maximum
dec value,maximum
endwhile
endfunction value