home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / sillies / silly10 / !Yow / !RunImage (.txt) < prev    next >
RISC OS BBC BASIC V Source  |  1994-01-11  |  6KB  |  237 lines

  1.  > !RunImage for !Yow   Copyright Denis Howe 1992
  2.  You may copy this program freely as long as this notice is
  3.  retained and you don't charge for it.  Please send comments,
  4.  bugs and suggestions to Denis Howe <dbh@doc.ic.ac.uk>.
  5.  Pick a random word from the Index file and use it as the byte
  6.  offset of the start of a text in the YowLines file.  Click
  7.  SELECT in the window to dismiss it or ADJUST to get another.
  8.  1.00 12-Aug-1990 Original program by Ian Rawlings
  9.  1.01             Rewritten by Denis Howe <dbh@doc.ic.ac.uk>
  10.  1.02 08-Sep-1991 Multiline texts terminated by a line containing
  11.                   just a CHR$0 (and a newline character).
  12.  1.03 12-Nov-1991 Merged in Unix fortune.dat.  Adjust for new text.
  13.  1.04 27-Dec-1991 Test if running under WIMP.  More from fortune.dat.
  14.  1.05 04-Nov-1992 Adapt to current screen mode.
  15.  1.06 10-Dec-1992 Fix garfield sprite width.
  16.  1.07 16-Jun-1993 Added Index file.
  17. Task$="Yow"
  18. LF%=10:CR%=13
  19. @Dir$="<Yow$Dir>":File$=Dir$+".YowLines":Index$=Dir$+".Index"
  20. HMaxLen%=55                   :
  21.  Max chars per output line before \n.
  22. $;" @";
  23.  WindB% 512, Message% 2048
  24.  b% 256                   :
  25.  For Wimp_Poll returns
  26.  blk% 256
  27.  "Wimp_ReadSysInfo",0 
  28.  Wimp%
  29. $b%="TASK"
  30.  Wimp% 
  31.  "Wimp_Initialise",200,!b%,Task$ 
  32.  ,TaskHandle%
  33.  Seed random numbers
  34. $+?b%=3:
  35.  "OS_Word",14,b%:C%=
  36. (b%!1))
  37. NewText
  38.  Wimp%=0 
  39.  "Wimp_Poll",1,b% 
  40.  reason%
  41.  reason% 
  42. Redraw
  43. -(    
  44.  "Wimp_OpenWindow",,WindB%
  45. .     
  46.  (b%!8 
  47.  1)=0 
  48. /6      !b%=WindowHandle%:
  49.  "Wimp_DeleteWindow",,b%
  50.       
  51.  "Hourglass_On"
  52.       
  53. NewText
  54.       
  55.  "Hourglass_Off"
  56.  17,18
  57.       
  58.  b%!16 
  59.       
  60.  0      :
  61.       
  62.  &400C1 :
  63.       
  64.  &400C2
  65. 8A        
  66.  b%!4<>TaskHandle% 
  67. $(b%+28),
  68. (Task$))=Task$ 
  69.       
  70.  Pick a random text from the file.
  71. NewText
  72.  C%,F%,I%,P%
  73. B1F%=
  74. (Index$):
  75.  F%=0 
  76.  0, "Can't open "+Index$
  77.  Point to random word in the Index file.
  78.  4)*4-4
  79.  Read four-byte word lsb 1st - the offset into YowLines.
  80. F'P%=0:
  81.  I%=0 
  82.  8:P%+=
  83. #F%<<I%:
  84.  Read the text.
  85. I/F%=
  86. (File$):
  87.  F%=0 
  88.  0, "Can't open "+File$
  89. #F%=P%
  90. P%=Message%
  91. #F%:?P%=C%:P%+=1:
  92.  C%=0
  93.  Break any line longer than MaxLen%
  94. Q!P%=Message%:Space%=0:Line%=P%
  95. R!Lines%=0 :
  96.  Lines in original
  97.  ?P%=
  98. " " Space%=P%
  99.  ?P%=LF% Line%=P%:Lines%+=1
  100.  P%-Line%>MaxLen% 
  101. W2    
  102.  Space% ?Space%=LF%:Line%=Space%:Space%=0
  103.   P%+=1
  104.  See if last word of longest line would fit better on the following line
  105.  but only if the original was all one or two lines.  Ie. don't reformat
  106.  multi-line input.
  107.  Lines%<3 
  108. b*    P%=Message%:Space%=0:LineStart%=P%
  109. cG    LongStart%=0:LongEnd%=0         :
  110.  Start & end of longest line.
  111. dB    WordStart%=0                    :
  112.  Start of its last word.
  113.     Reformat%=
  114. f        
  115. g$      P%+=1:
  116.  ?P%=
  117. " " Space%=P%
  118.       
  119.  ?P%=LF% 
  120.         L%=P%-LineStart%
  121. j&        
  122.  L%>LongEnd%-LongStart% 
  123. k/          LongStart%=LineStart%:LongEnd%=P%
  124.           WordStart%=Space%
  125. m$          Reformat%=
  126. :PrevMax%=
  127.         
  128. o?          
  129.  PrevMax% Reformat%=(WordStart%-LongStart% > L%)
  130.           PrevMax%=
  131.         
  132.         LineStart%=P%
  133.       
  134.  ?P%=0
  135. u2    
  136.  Reformat% ?WordStart%=LF%:?LongEnd%=
  137.  Reformat%
  138.  Replace LF with CRLF and find length of longest line.
  139. {1P%=Message%:LineStart%=P%:LongLen%=0:Lines%=0
  140.   C%=?P%
  141.  C%=LF% 
  142. 2    L%=P%-LineStart%:
  143.  L%>LongLen% LongLen%=L%
  144. 5    ?P%=CR%:Q%=P%:
  145.  Q%+=1:
  146.  C%,?Q%:
  147.  ?Q%=0:P%+=1
  148.     LineStart%=P%:Lines%+=1
  149.   P%+=1
  150.  ?P%=0
  151.  Wimp% 
  152. CreateWindow 
  153.  "OS_Write0",Message%
  154.  End of NewText
  155. CreateWindow
  156. GSprW%=170*2:SprH%=184*2                  :
  157.  Sprite size, pix*OS/pix
  158. LCharH%=36                                :
  159.  Vert. spacing between lines.
  160. <LeftMargin%=SprW%+20:TopMargin%=36       :
  161.  Text offsets
  162. )WinWidth%=16*(LongLen%+2)+LeftMargin%
  163.  WinHeight%=CharH%*(Lines%+2)
  164.  WinHeight%<SprH% WinHeight%=SprH%
  165. Wind%=WindB%+4
  166. 0Wind%!28=1<<31  :
  167.   OR 1<<10 for 256 colours
  168. Wind%?32=7
  169. IWind%?35=7+
  170. (8)                        :
  171.  work backgnd (WIMP colours)
  172.  Wind%?35=8 
  173.  Wind%?35=11 
  174.  Wind%?35=13 Wind%?34=0 
  175.  Wind%?34=7
  176. K                                         :
  177.  work foregnd (WIMP colours)
  178.  Wind%?35=191+RND(64)                 :REM work backgnd (256 colours)
  179.  Wind%?34=RND(64)-1                   :REM work foregnd (256 colours)
  180. #Wind%!40=0    :
  181.  wk area coords
  182. Wind%!44=-9999
  183. Wind%!48=9999
  184. Wind%!52=0
  185. Wind%!60=3<<12
  186. "Wind%!64=1 :
  187.  Wimp sprite area
  188. Wind%!68=&10001
  189. Wind%!84=1
  190. 7Icon%=Wind%+88 :
  191.  Sprite icon at bot left of window
  192. ;Icon%!0=0:Icon%!4=16-WinHeight%          :
  193.  icon bounds
  194. 0Icon%!8=Icon%!0+SprW%:Icon%!12=Icon%!4+SprH%
  195. <Icon%!16=1<<1 
  196.  3<<12                   :
  197.  sprite, click
  198. $(Icon%+20)="garfield"
  199.  "Wimp_CreateWindow",,Wind% 
  200.  WindowHandle%
  201. !WindB%=WindowHandle%
  202. Mode :
  203.  Sets mode dependent parts and opens win
  204.  Each line ends with CR LF.  Text ends with CR LF NUL
  205. Redraw
  206.  P%,Y%
  207.  "Wimp_RedrawWindow",,b% 
  208.  more%
  209.  more%
  210.   P%=Message%:Y%=Ytop%
  211.  Xleft%,Y%:Y%-=36
  212. .    
  213.  "OS_WriteC",?P%:P%+=1:
  214.  P%?-1=LF%
  215.  ?P%=0
  216.  "Wimp_GetRectangle",,b% 
  217.  more%
  218.  L%,N%
  219.  "OS_ReadModeVariable",-1,4 
  220.  "OS_ReadModeVariable",-1,11 
  221. ScreenWidth%=(N%+1)<<L%
  222.  "OS_ReadModeVariable",-1,5 
  223.  "OS_ReadModeVariable",-1,12 
  224. ScreenHeight%=(N%+1)<<L%
  225. &Wind%!0=(ScreenWidth%-WinWidth%)/2
  226. (Wind%!4=(ScreenHeight%-WinHeight%)/2
  227. Wind%!8=Wind%!0+WinWidth%
  228. Wind%!12=Wind%!4+WinHeight%
  229. Wind%!16=0
  230. Wind%!20=0
  231. Wind%!24=-1
  232.  "Wimp_OpenWindow",,WindB%
  233. ;Xleft%=Wind%!0+LeftMargin%               :
  234.  Text origin
  235. Ytop%=Wind%!12-TopMargin%
  236.  "Wimp_CloseDown"
  237.