home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 13 / AUCD13.iso / argonet / swiftjpeg.spk / !SwiftJPEG / Resources / SourceBas (.txt) < prev   
RISC OS BBC BASIC V Source  |  1996-04-25  |  74KB  |  2,606 lines

  1.  > !RunImage for !SwiftJPEG
  2.  A fast JPEG viewer using Acorn's
  3.  SpriteExtend module from RISC OS
  4.  v3.6 or later (module version
  5.  0.99 or later).
  6.  This source code may not run with
  7.  the WimpSlot allocated to the
  8.  crunched !RunImage; you may need
  9.  to increase the slot by the
  10.  difference in file size, rounded
  11.  up to a 4K block.
  12.  (C) Hipposoft 1995,1996
  13. closeopenfiles:
  14.  (1<<30),"Fatal startup error: "+
  15. $+" at line "+
  16. )+", click on Cancel to exit":
  17. openfh%=0
  18. returnto%=-1
  19. allfatal%=
  20. picareah%=0
  21. picsdone%=0
  22. lisareah%=0
  23. listfull%=0
  24. barmin%=12
  25. barmax%=96
  26.  loaderro% holds a value of 0 most of the time. If it has a higher
  27.  value, it refers to an offset from the pointer in the dynamic area
  28.  holding the list of files to load - namely, it points to the
  29.  byte terminator of the filename that generated the error. In this
  30.  case, FNerror will set that byte to 1. This can be used by other
  31.  routines to then skip that file should they come across it again,
  32.  rather than repeatedly generate errors.
  33. loaderro%=0
  34.  displayh% is set to -1 to signal that FNerror is not to check to
  35.  see if the display window needs remembering as it hasn't even been
  36.  created yet (when it is created, displayh% will acquire a
  37.  meaningful value in passing).
  38. displayh%=-1
  39.  fbl% ('fade block') holds variables as words, meaning -
  40.  -------+-------------------------+-------------------------
  41.  Offset | Contents                |  Values
  42.  -------+-------------------------+-------------------------
  43.  0      | Fade picture in         | 0=no, 1=fade, 2=flash
  44.  4      | Fade picture out        | 0=no, 1=fade, 2=flash
  45.  8      | Fade-in speed           | barmin% to barmax% incl.
  46.  12     | Fade-out speed          | barmin% to barmax% incl.
  47.  16     | Choices store offset 12 | As offset 12
  48.  20     | Choices store offset 16 | As offset 16
  49.  -------+-------------------------+-------------------------
  50.  The Choices stores are variables which hold the values
  51.  reflected in an open Choices window, which can't be directly
  52.  read from that window (this allows OK and Cancel buttons to
  53.  operate correctly with relative ease from a code viewpoint).
  54.  fbl% 24
  55. !fbl%=0
  56. fbl%!4=0
  57.  b% 256,s% 256,fr% 512,lca% 64
  58. H    !b%=1
  59. b%!4=2
  60. b%!8=3
  61. b%!12=4
  62. b%!16=5
  63. b%!20=&400C0
  64. b%!24=&400C1
  65. b%!28=&400C9
  66. b%!32=0
  67.  "Wimp_Initialise",350,&4B534154,"SwiftJPEG",b% 
  68.  a%,task%
  69. error 
  70. exit:
  71.  a%<350 
  72.  490,"SwiftJPEG requires RISC OS 3.50 or later to run"
  73.  "OS_CLI","RMEnsure SpriteExtend 0.99 ERROR 490 Can't find JPEG plotting SWIs - is SpriteExtend 0.99 or later running?"
  74.  "XOS_ReadVarVal","SwiftJPEG$Dir",fr%,256 
  75.  ,,a%
  76.  a%=0 
  77.  490,"'SwiftJPEG$Dir' not defined - ensure you double-click on !SwiftJPEG to run it"
  78. Z1choipath$=
  79. textuntil(fr%,32),a%)+".!Choices"
  80. initialisecode
  81.  "Hourglass_Start",1
  82. version$="1.00 (25 Apr 96)"
  83. initialisemain
  84. iconbar
  85.  "Hourglass_Off"
  86.  During the routine to find if the application was launched by
  87.  double-clicking on a JPEG file, and if so loading that file,
  88.  we need to ensure that should an error occur, the routine won't
  89.  just be run again because the error will then be regenerated.
  90.  This isn't a problem with the above code because all errors
  91.  are forced to be fatal.
  92.  Hence allfatal% is set to FALSE if the routine is to be run,
  93.  or is given a value of 1 if an error occurs. The long IF
  94.  around the routine sets allfatal% back to FALSE if it wasn't
  95.  FALSE on entry to ensure that further errors aren't forced
  96.  to be fatal.
  97. allfatal%=
  98. error 
  99. exit:
  100.  allfatal%=1
  101.  allfatal%=
  102. getp(a$)
  103.  a$<>"" 
  104. !b%=-1
  105. b%!40=
  106. filetype(a$)
  107. $(b%+44)=a$
  108. storefilename
  109. allfatal%=
  110. error 
  111. exit:
  112. quit%
  113.  -- General WIMP procedures
  114. removearea(picareah%)
  115. picareah%=0
  116. removearea(lisareah%)
  117. lisareah%=0
  118.  "XWimp_CloseDown",task%,&4B534154
  119.  PROCmemusage
  120.  DEFPROCmemusage
  121.  MODE MODE
  122.  PRINT "Memory free           : ";HIMEM-END
  123.  PRINT "Could decrease slot by: ";(((HIMEM-END) DIV 4096)*4);"K"
  124.  PRINT "That would leave free : ";(HIMEM-END)-(((HIMEM-END) DIV 4096)*4096);" bytes"
  125.  ENDPROC
  126.  "OS_ReadMonotonicTime" 
  127.  "Wimp_PollIdle",29368369,b%,a%+10000 
  128.  reason%
  129.  reason% 
  130. redraw
  131.  "Wimp_OpenWindow",,b%
  132.  !b%=-1 
  133.  lisareah%<>0 
  134. showbatch(autofull%) 
  135. closewindow
  136. click
  137. dragended
  138. keyboard
  139. menuselect
  140.  "Wimp_GetCaretPosition",,fr%:
  141.  !fr%<>lastmenh% 
  142.  !lca%=-1
  143.  17,18,19:
  144. message
  145. closewindow
  146.  !b% 
  147.  displayh%
  148.  "OS_Byte",121 
  149.  (a%<>0) 
  150.  "Wimp_CloseWindow",,b%
  151. removearea(picareah%)
  152. picareah%=0
  153. greyoutmenu(mainmenuaddr%,2)
  154. greyoutmenu(mainmenuaddr%,3)
  155.  jpegname$<>"<Wimp$Scrap>" 
  156. ungreymenu(mainmenuaddr%,4)
  157.  a%,c%,d%
  158.  (d% 
  159. a$=jpegname$
  160. (a$) 
  161. a$,a%,1)="." 
  162. a$,a%-1):a%=0:c%=
  163.  c%<>
  164.  a$<>"" 
  165.  "XOS_CLI","Filer_OpenDir "+a$
  166.  jpegname$="<Wimp$Scrap>" 
  167.  "XOS_CLI","Filer_OpenDir <Wimp$ScrapDir>"
  168.  saveash%
  169. restorecaret
  170.  "Wimp_CloseWindow",,b%
  171.  "Wimp_CloseWindow",,b%
  172. click
  173. windh%=b%!12
  174. iconh%=b%!16
  175. adju%=(b%!8) 
  176. menu%=(b%!8) 
  177. sele%=(b%!8) 
  178.  windh% 
  179. open(displayh%) 
  180.  adju%<>0 
  181. showcurrent
  182. open(displayh%) 
  183.  sele%<>0 
  184. !fr%=displayh%
  185.  "Wimp_GetWindowState",,fr%
  186. fr%!28=-1
  187.  "Wimp_OpenWindow",,fr%
  188. openmainmenu(
  189.  displayh%:
  190. openmainmenu(
  191.  zoomh%:
  192. zoomclick
  193.  choicesh%:
  194. choicesclick
  195.  saveash%:
  196. saveasclick
  197. keyboard
  198. windh%=!b%
  199. iconh%=b%!4
  200.  windh% 
  201.  zoomh%
  202.  b%!24=&00D 
  203. textuntil(!(zow%+108+32*iconh%),33))>20 
  204.  $(!(zow%+108+32*iconh%))="20":
  205. forceredraw(zoomh%,iconh%)
  206. textuntil(!(zow%+108+32*iconh%),33))<1 
  207.  $(!(zow%+108+32*iconh%))="1":
  208. forceredraw(zoomh%,iconh%)
  209.  iconh%=2 
  210.  iconh%=4:
  211. placecaretinicon(zoomh%,4,-2) 
  212.  iconh%=2:
  213.  "Wimp_CreateMenu",-1
  214. keyzoom
  215.  choicesh%
  216.  b%!24=&00D 
  217.  iconh%=13:a%=
  218.  b%!24=&01B 
  219.  iconh%=12:a%=
  220.  adju%=0:
  221. choicesclick
  222.  saveash%
  223.  b%!24=&00D 
  224.  iconh%=3:a%=
  225.  b%!24=&01B 
  226.  iconh%=2:a%=
  227.  dragging%=
  228.  "DragASprite_Stop":adju%=0:
  229. saveasclick
  230.  "Wimp_ProcessKey",b%!24
  231. message
  232.  b%!16 
  233.  0:quit%=
  234. datasave
  235. datasaveack
  236. storefilename
  237. dataloadack
  238.  b%!40=&C85 
  239. storefilename
  240.  &400C0:
  241.  b%!20=zoomh% 
  242. checkzoomfraction:
  243.  "Wimp_CreateSubMenu",,b%!20,b%!24,b%!28
  244.  &400C1:
  245. open(displayh%) 
  246. resizemainwindow 
  247. modeinfo(
  248.  &400C9:
  249.  dragging% 
  250.  "DragASprite_Stop"
  251. redraw
  252.  "Wimp_RedrawWindow",,b% 
  253.  !b%=displayh% 
  254.  "XJPEG_PlotScaled",picareab%,b%!4-b%!20,b%!16-windheig%-b%!24,sc%,jpegleng%,df%
  255.  !b%=choicesh% 
  256. redrawslider(choicesh%,40,barmin%,barmax%,fbl%!16):
  257. redrawslider(choicesh%,41,barmin%,barmax%,fbl%!20)
  258.  "Wimp_GetRectangle",,b% 
  259. redrawslider(a%,c%,d%,e%,f%)
  260.  Pass a window and icon handle, minimum, maximum, and current value.
  261.  Draws the interior of a slider based on those values.
  262.  CORRUPTS BOTH s% AND fr%.
  263. !fr%=a%
  264. fr%!4=c%
  265.  "Wimp_GetIconState",,fr%
  266. !s%=a%
  267.  "Wimp_GetWindowState",,s%
  268. s%!64=fr%!8+s%!4-s%!20
  269. s%!68=fr%!12+s%!16-s%!24
  270. s%!72=fr%!16+s%!4-s%!20
  271. s%!76=fr%!20+s%!16-s%!24
  272. D1x%=((s%!72-s%!64-16)/(e%-d%))*(f%-d%)+s%!64+8
  273. x%=((x%+1) 
  274.  2)*2
  275.  "Wimp_SetColour",1
  276.  s%!64+4,s%!68+4,s%!72-s%!64-9,3
  277.  s%!64+4,s%!76-8,s%!72-s%!64-9,3
  278.  s%!64+4,s%!68+4,3,s%!76-s%!68-9
  279.  s%!72-8,s%!68+4,3,s%!76-s%!68-9
  280.  "Wimp_SetColour",4
  281.  x%-s%!64-9>0 
  282.  s%!64+8,s%!68+8,x%-s%!64-9,s%!76-s%!68-17
  283.  "Wimp_SetColour",0
  284.  s%!72-x%-11>0 
  285.  x%,s%!68+8,s%!72-x%-9,s%!76-s%!68-17
  286. forceredraw(a%,c%)
  287.  Pass a window and icon handle. Performs a 'true' redraw
  288.  of the icon (so it might flicker a bit). Minimises this
  289.  by checking if the icon has a border, and if so, tries
  290.  not to redraw it.
  291. !fr%=a%
  292. fr%!4=c%
  293.  "Wimp_GetIconState",,fr%
  294.  (fr%!24) 
  295.  "Wimp_ForceRedraw",!fr%,fr%!8+4,fr%!12+4,fr%!16-4,fr%!20-4 
  296.  "Wimp_ForceRedraw",!fr%,fr%!8,fr%!12,fr%!16,fr%!20
  297. redrawwindow(a%)
  298.  Pass a window handle. Performs a 'true' redraw of the
  299.  window (so it will flicker a little).
  300. !fr%=a%
  301.  "Wimp_GetWindowState",,fr%
  302.  "Wimp_ForceRedraw",-1,fr%!4,fr%!8,fr%!12,fr%!16
  303. redrawtitlebar(a%)
  304. open(a%) 
  305. !s%=a%
  306.  "Wimp_GetWindowState",,s%
  307. c%=s%!16
  308. !s%=a%
  309.  "Wimp_GetWindowOutline",,s%
  310.  s%!8<c% 
  311.  s%!8=c%
  312.  "Wimp_ForceRedraw",-1,s%!4,s%!8,s%!12,s%!16
  313.  -- Initialisation procedures
  314. initialisecode
  315.  Load pre-assembled ARM code routine(s) and link
  316.  various parts as necessary.
  317.  a%,c%
  318. ~(openfh%=
  319. ("<SwiftJPEG$Dir>.ARMcode")
  320. getword(openfh%)
  321.  mc% a%-4
  322.  "OS_GBPB",4,openfh%,mc%,a%-4 
  323.  ,,,c%
  324.  gar% 256,gag% 256,gab% 256
  325.  c%<>0 
  326.  (1<<30)+2,"ARMcode file is too short or file pointers are too large"
  327.  DO NOT FORGET that words obtained from the rest of the file
  328.  are pointer OFFSETS - reference with mc% added!
  329. !!(mc%+
  330. getword(openfh%))=gar%
  331. !!(mc%+
  332. getword(openfh%))=gag%
  333. !!(mc%+
  334. getword(openfh%))=gab%
  335. %gammawrite%=mc%+
  336. getword(openfh%)
  337. #openfh%
  338. openfh%=0
  339. initialisemain
  340.  General initialisation.
  341.  Initialise general global variables and arrays
  342. quit%=
  343. returnto%=-1
  344. abortmul%=
  345. dragging%=
  346. picareab%=0
  347. lisareab%=0
  348. lisloadp%=0
  349. lisnextp%=0
  350. lismaxsi%=&80000
  351.  inw%, diw% etc. all store window definitions (see
  352.  PROCloadtemplates for which block holds which window).
  353. isp%=1856
  354.  i% isp%,ib% 32,m% 576,mi% 160
  355.  inw% 576,diw% 160,zow% 512,jiw% 448,chw% 2584,sav% 576
  356.  mos% stores the Desktop mode selector block for new-style
  357.  modes. 128 bytes is overkill but it helps future-proof
  358.  things should the maximum length of a selector block
  359.  increase in later OS versions. sc% stores the scaling
  360.  block for plotting the JPEG; mbu% stores a mode definition
  361.  string for the Full Screen Mode menu (fullmode$ holds the
  362.  string that's currently in use), and dst% stores the
  363.  basic information on position and size of the Display
  364.  window for the duration of Full Screen viewing of a
  365.  picture/several pictures so it can be correctly restored
  366.  afterwards.
  367.  mos% 128,sc% 16,mbu% 64,dst% 64
  368.  Is the Compo_ReadGamma SWI available? If so, fade routines
  369.  will read current values and take them into account. Otherwise,
  370.  if someone set up their Gamma values with !Gamma they'd have to
  371.  turn off all the fades as it would reset their gamma settings.
  372.  This isn't done through extra code in SwiftJPEG as you can only
  373.  'read' the values by sitting on the palette vector and waiting
  374.  for someone to issue new gamma settings. So if someone set up
  375.  custom gamma settings at start up and later loaded SwiftJPEG,
  376.  it couldn't know about those new settings. The !Gamma application
  377.  is the only front-end I know of that allows such things to be
  378.  done easily, so SwiftJPEG explicitly supports it. Otherwise -
  379.  no fades, I'm afraid, though you can always hack the source...
  380.  "XOS_SWINumberFromString",,"XCompo_ReadGamma" 
  381.  cgamread%;a%
  382.  (a% 
  383.  cgamread%=
  384.  pgr% 256,pgg% 256,pgb% 256
  385.  cgamread%=
  386.  a%=0 
  387. pgr%?a%=a%
  388. pgg%?a%=a%
  389. pgb%?a%=a%
  390.  cgamread%,pgr%,pgg%,pgb%
  391.  Load choices and sprites relevant to current display
  392.  resolution.
  393. loadchoices
  394. loadsprites
  395.  xbig%, ybig% and bbpp% are eventually set globally to the
  396.  x size, y size and colour depth of the largest available
  397.  screenmode; xclr%, yclr% and cbpp% to the most colourful.
  398. xbig%=0
  399. ybig%=0
  400. bbpp%=0
  401. xclr%=0
  402. yclr%=0
  403. cbpp%=0
  404.  Now the usual initialisation, loading
  405.  templates, making menus, adding submenus
  406.  and so on.
  407. templates
  408. zoomm%=1
  409. zoomd%=1
  410. $(zow%!172)="1"
  411. $(zow%!236)="1"
  412. menudata
  413. %mainmenuaddr%=
  414. makemenu(m%,mi%,1)
  415. attach(mainmenuaddr%,0,infoh%)
  416. attach(mainmenuaddr%,1,zoomh%)
  417. +picturesubmenuaddr%=
  418. makemenu(m%,mi%,1)
  419. attach(mainmenuaddr%,2,picturesubmenuaddr%)
  420. attach(picturesubmenuaddr%,0,jpeginfoh%)
  421. attach(picturesubmenuaddr%,1,saveash%)
  422. greyoutmenu(mainmenuaddr%,2)
  423. greyoutmenu(mainmenuaddr%,3)
  424. greyoutmenu(mainmenuaddr%,4)
  425. (ditheringmethod%=
  426. makemenu(m%,mi%,1)
  427. 'fullscreenmode%=
  428. makemenu(m%,mi%,1)
  429. loadchoices
  430. openfh%=
  431. (choipath$)
  432.  openfh%=0 
  433.  490,"Can't find the !Choices file"
  434. getchoice("Dithering","012",ditherit%)
  435. df%=ditherit%-(ditherit%=2)
  436. getchoice("Full Screen","01234",fullscrn%)
  437. getchoice("Special Mode","*",a%)
  438. fullmode$=
  439. #openfh%,64)
  440. fullmode$,1)="."
  441. fullmode$=
  442. fullmode$,2)
  443. getchoice("Auto Full Screen","01",autofull%)
  444. getchoice("Modes Once Only","01",modesonc%)
  445. getchoice("Close Display","01",closedis%)
  446. getchoice("Auto Filetype","01",autofilt%)
  447. getchoice("Slideshow wait","!",sldswait%)
  448. getchoice("Always 1:1","01",fixdzoom%)
  449. getchoice("Repeat pictures","01",reptpics%)
  450. getchoice("Fade-in","012",!fbl%)
  451. getchoice("Fade-in speed","!",fbl%!8)
  452. fbl%!16=fbl%!8
  453. getchoice("Fade-out","012",fbl%!4)
  454. getchoice("Fade-out speed","!",fbl%!12)
  455. fbl%!20=fbl%!12
  456. #openfh%
  457. openfh%=0
  458. closeopenfiles
  459.  openfh%<>0 
  460. #openfh%
  461. openfh%=0
  462. restoremode
  463.  returnto%<>-1 
  464.  "Wimp_SetMode",returnto%:returnto%=-1:
  465. gammanormal
  466. getchoice(b$,a$,
  467.  Pass the title of the entry in the Choices file;
  468.  if a single digit is to be returned, pass all the
  469.  digits in the second parameter as a string (e.g.
  470.  '0123') or '!' for no check, and pass a variable
  471.  into which the VAL of the string obtained from
  472.  the Choices file is placed. If '*' is given as
  473.  second parameter, then the returned number will
  474.  be irrelevant (it can be discarded) and the file
  475.  pointer will be on the line immediately after
  476.  the title. This allows text strings, rather than
  477.  numbers, to be loaded - call PROCgetchoice and
  478.  then do variable$=GET$#filehandle%.
  479.  c%,c$
  480. upper(
  481. #openfh%)=
  482. upper(b$) 
  483.  (c%=
  484. #openfh%)
  485.  490,"Can't find '"+b$+"' entry in !Choices file"
  486. a$,1)<>"*" 
  487. #openfh%
  488. a$,1)<>"!") 
  489. a$,1)<>"*") 
  490. a$,c$)=0) 
  491. (c$)<>1) 
  492.  490,b$+" option not understood in !Choices file"
  493. a$,1)<>"*" 
  494. putchoice(a$,a%)
  495.  Pass the title of the entry in the Choices file;
  496.  if a single digit is to be stored, pass the
  497.  digit as a number in the second parameter,
  498.  or for numbers between 0 and 9999 to be stored
  499.  in four digit string form (e.g. '0045'), give,
  500.  if n is the number, -(n+1) as the value. If a%
  501.  is >9 and positive it is taken as a pointer to
  502.  a control terminated string in memory.
  503.  c%,b$
  504. upper(
  505. #openfh%)
  506. upper(a$) 
  507.  (c%=
  508. #openfh%)
  509.  490,"Can't find '"+a$+"' entry in !Choices file"
  510.  (a%>=0) 
  511.  (a%<=9) 
  512. #openfh%,a%+48
  513.  a%<0 
  514.  b$="0000":
  515. (-(a%+1)):
  516. #openfh%,b$
  517.  a%>9 
  518. 64,"."):
  519. textuntil(a%,32):
  520. #openfh%,b$
  521. loadsprites
  522.  a%,a$
  523.  "OS_ReadModeVariable",-1,4 
  524.  ,,xeig%
  525.  "OS_ReadModeVariable",-1,5 
  526.  ,,yeig%
  527. a$="<SwiftJPEG$Dir>."
  528.  xeig%>1 
  529.  yeig%>1 
  530.  a$+="Sprites" 
  531.  a$+="Sprites22"
  532. filetype(a$)
  533.  a%<0 
  534.  (1<<30)+2,"Can't find Sprites file"
  535.  a%<>&FF9 
  536.  (1<<30)+2,"Sprites file doesn't have Sprite filetype &FF9"
  537. filelength(a$)
  538.  a%=-1 
  539.  (1<<30)+2,"Can't find the Sprites file"
  540.  sprites% a%+1024
  541. !sprites%=0
  542. sprites%!4=16
  543.  "OS_SpriteOp",265,sprites%
  544.  "OS_SpriteOp",266,sprites%,a$
  545. iconbar
  546. $(ib%)="iconbar"
  547. !b%=-1
  548. b%!4=0
  549. b%!8=0
  550. b%!12=68
  551. b%!16=68
  552. b%!20=&3102
  553. b%!24=ib%
  554. b%!28=sprites%
  555. b%!32=11
  556.  "Wimp_CreateIcon",,b% 
  557.  iconbarh%
  558. getp(
  559.  "OS_GetEnv" 
  560. textuntil(a%,32)
  561. a$,"""")
  562.  a%<>0 
  563. a$,a%+1)
  564. a$,""" ")
  565.  a%<>0 
  566. a$,a%+2) 
  567.  a$=""
  568.  -- Template and window handling procedures
  569. open(a%)
  570.  a%=-1 
  571. !fr%=a%
  572.  "Wimp_GetWindowState",,fr%
  573.  ((fr%!32) 
  574.  &10000)<>0 
  575. loadtemp(a%,a$,
  576.  Pass a block to load the main data into, the template name
  577.  to load, and a variable into which the created window
  578.  handle is to be placed. Requires i% as a block for
  579.  indirected data, isp% as the length of the block, and io%
  580.  as the value of i% on entry to the procedure (i% will
  581.  be changed to point to the first free space in the block,
  582.  io% stays as a reference) - these must be global.
  583.  "Wimp_LoadTemplate",,a%,i%,io%+isp%,-1,a$,0 
  584.  ,,i%
  585. a%!64=sprites%
  586.  "Wimp_CreateWindow",,a% 
  587. templates
  588.  Reads in and creates window definitions through PROCloadtemp.
  589.  a%,c%,d%,a$
  590.  "Wimp_OpenTemplate",,"<SwiftJPEG$Dir>.Templates"
  591. io%=i%
  592. loadtemp(inw%,"Info",infoh%)
  593. $(inw%!332)=version$
  594. loadtemp(diw%,"Display",displayh%)
  595. loadtemp(zow%,"Zoom",zoomh%)
  596. loadtemp(jiw%,"JPEG info",jpeginfoh%)
  597. loadtemp(chw%,"Choices",choicesh%)
  598. loadtemp(sav%,"SaveAs",saveash%)
  599. a$="file_c85"
  600.  "Wimp_BaseOfSprites" 
  601.  a%,c%
  602.  "XOS_SpriteOp",296,a%,a$ 
  603.  (d% 
  604.  "XOS_SpriteOp",296,c%,a$ 
  605.  (d% 
  606.  a$="file_xxx"
  607. )$(sav%!112)="Pptr_hand,9,5;S"+a$+
  608.  "Wimp_CloseTemplate"
  609. opencentered(f%)
  610.  a%,c%,d%,e%
  611. readscreensize(a%,c%)
  612. !fr%=f%
  613.  "Wimp_GetWindowState",,fr%
  614. d%=fr%!12-fr%!4
  615. e%=fr%!16-fr%!8
  616. xpo%=(a%-d%)/2
  617. ypo%=(c%-e%)/2
  618.  (fr%!32) 
  619.  &4000000 
  620.  ypo%-=19
  621.  (fr%!32) 
  622.  &40000000 
  623.  ypo%+=19
  624.  (fr%!32) 
  625.  &10000000 
  626.  xpo%-=19
  627. fr%!4=xpo%
  628. fr%!8=ypo%
  629. fr%!12=xpo%+d%
  630. fr%!16=ypo%+e%
  631. fr%!28=-1
  632.  "Wimp_OpenWindow",,fr%
  633. titlebarchange(a%,a$)
  634.  Pass a window handle, and a string to put in the
  635.  title bar. This is truncated to 48 characters,
  636.  with any string greater than 45 having '...' placed
  637.  in front.
  638. !fr%=a%
  639.  "Wimp_GetWindowInfo",,fr%
  640. (a$)>48 
  641.  c$="..."+
  642. a$,45) 
  643.  c$=a$
  644.  Line below - If the pathname is >48 characters, then the '...' is put
  645.  in front of the last 45. But what happens if those 45, by chance,
  646.  start with a '.' of a directory separator? The line below should remove
  647.  one dot should the string start with four of them, which indicates
  648.  that the used 45 characters did indeed start with a dot. In this case,
  649.  only 47 characters will appear in the title bar.
  650. c$,4)="...." 
  651. c$,2)
  652. $(fr%!76)=c$+
  653. redrawtitlebar(a%)
  654. zoomclick
  655.  a%,c%
  656. a%=zoomm%
  657. c%=zoomd%
  658. getopt(zoomh%,0) 
  659.  iconh%<>0 
  660. setopt(zoomh%,0,
  661. getopt(zoomh%,1) 
  662.  iconh%<>1 
  663. setopt(zoomh%,1,
  664. getopt(zoomh%,5) 
  665.  iconh%<>5 
  666. setopt(zoomh%,5,
  667. getopt(zoomh%,6) 
  668.  iconh%<>6 
  669. setopt(zoomh%,6,
  670.  adju% 
  671.  iconh% 
  672.  0:iconh%=1
  673.  1:iconh%=0
  674.  5:iconh%=6
  675.  6:iconh%=5
  676.  The double range checking implemented here may seem unnecessary (why
  677.  check for a value too low when it is being incremented rather than
  678.  decremented?) but because the user may have typed in some very odd
  679.  value first, it is still necessary to ensure that even after adding
  680.  or subtracting 1 from the value in the icon, the resulting number is
  681.  within the allowed range.
  682.  iconh% 
  683. 'zoomm%=
  684. textuntil(zow%!172,33))+1
  685.  zoomm%>20 
  686.  zoomm%=20
  687.  zoomm%<1 
  688.  zoomm%=1
  689. textuntil(zow%!172,33)<>
  690. (zoomm%) 
  691.  $(zow%!172)=
  692. (zoomm%):
  693. forceredraw(zoomh%,2)
  694. 'zoomm%=
  695. textuntil(zow%!172,33))-1
  696.  zoomm%>20 
  697.  zoomm%=20
  698.  zoomm%<1 
  699.  zoomm%=1
  700. textuntil(zow%!172,33)<>
  701. (zoomm%) 
  702.  $(zow%!172)=
  703. (zoomm%):
  704. forceredraw(zoomh%,2)
  705. 'zoomd%=
  706. textuntil(zow%!236,33))+1
  707.  zoomd%>20 
  708.  zoomd%=20
  709.  zoomd%<1 
  710.  zoomd%=1
  711. textuntil(zow%!236,33)<>
  712. (zoomd%) 
  713.  $(zow%!236)=
  714. (zoomd%):
  715. forceredraw(zoomh%,4)
  716. 'zoomd%=
  717. textuntil(zow%!236,33))-1
  718.  zoomd%>20 
  719.  zoomd%=20
  720.  zoomd%<1 
  721.  zoomd%=1
  722. textuntil(zow%!236,33)<>
  723. (zoomd%) 
  724.  $(zow%!236)=
  725. (zoomd%):
  726. forceredraw(zoomh%,4)
  727.  a%<>zoomm% 
  728.  c%<>zoomd% 
  729. open(displayh%) 
  730. resizemainwindow
  731. !fr%=displayh%
  732.  "Wimp_CloseWindow",,fr%
  733.  "Wimp_GetWindowState",,fr%
  734.  "Wimp_OpenWindow",,fr%
  735. showmenu(lastmena%,lastmenx%,lastmeny%)
  736. keyzoom
  737.  a%,c%
  738. a%=zoomm%
  739. c%=zoomd%
  740. 4%zoomm%=
  741. textuntil(zow%!172,33))
  742. 5%zoomd%=
  743. textuntil(zow%!236,33))
  744.  zoomm%<1 
  745.  zoomm%=1
  746.  zoomm%>20 
  747.  zoomm%=20
  748.  zoomd%<1 
  749.  zoomd%=1
  750.  zoomd%>20 
  751.  zoomd%=20
  752.  zoomm%<>a% 
  753.  $(zow%!172)=
  754. (zoomm%)
  755.  zoomd%<>c% 
  756.  $(zow%!236)=
  757. (zoomd%)
  758.  a%<>zoomm% 
  759.  c%<>zoomd% 
  760. open(displayh%) 
  761. resizemainwindow
  762. !fr%=displayh%
  763.  "Wimp_CloseWindow",,fr%
  764.  "Wimp_GetWindowState",,fr%
  765.  "Wimp_OpenWindow",,fr%
  766. setupchoices
  767.  Sets up, but does not open, the General Choices window,
  768.  and any items attached to it (e.g. menus). Will update
  769.  any Choices store variables with the global, applied
  770.  values. (So this can be used to implement a Cancel
  771.  button with or without window closure, or be called
  772.  generally before opening the window).
  773.  a%,a$
  774. readtick(ditheringmethod%,ditherit%)=
  775.  a%=0 
  776. settick(ditheringmethod%,a%,
  777. settick(ditheringmethod%,ditherit%,
  778.  ditherit% 
  779.  0:a$="No dithering"
  780.  1:a$="Fast but inaccurate"
  781.  2:a$="Slow but accurate"
  782. :a$="Unknown!"
  783. $(chw%!1260)=a$
  784. forceredraw(choicesh%,36)
  785. $mbu%=fullmode$
  786. readtick(fullscreenmode%,fullscrn%)=
  787.  a%=0 
  788. settick(fullscreenmode%,a%,
  789. settick(fullscreenmode%,fullscrn%,
  790.  fullscrn% 
  791.  0:a$="Use current mode"
  792.  1:a$="Best fit to picture"
  793.  2:a$="Use biggest"
  794.  3:a$="Use most colourful"
  795.  4:a$=
  796. textuntil(mbu%,32):
  797. (a$)>20 
  798. a$,17)="..."
  799. :a$="Unknown!"
  800. $(chw%!1356)=a$
  801. forceredraw(choicesh%,39)
  802. getopt(choicesh%,!fbl%)=
  803.  a%=0 
  804.  a%<>!fbl% 
  805. setopt(choicesh%,a%+2,
  806. setopt(choicesh%,a%+2,
  807. getopt(choicesh%,fbl%!4)=
  808.  a%=0 
  809.  a%<>fbl%!4 
  810. setopt(choicesh%,a%+7,
  811. setopt(choicesh%,a%+7,
  812.  fbl%!16<>fbl%!8 
  813.  fbl%!16=fbl%!8:
  814. forceredraw(choicesh%,40)
  815.  fbl%!20<>fbl%!12 
  816.  fbl%!20=fbl%!12:
  817. forceredraw(choicesh%,41)
  818.  -autofull%<>
  819. getopt(choicesh%,16) 
  820. setopt(choicesh%,16,-autofull%)
  821.  -modesonc%<>
  822. getopt(choicesh%,17) 
  823. setopt(choicesh%,17,-modesonc%)
  824.  -closedis%<>
  825. getopt(choicesh%,18) 
  826. setopt(choicesh%,18,-closedis%)
  827.  -autofilt%<>
  828. getopt(choicesh%,19) 
  829. setopt(choicesh%,19,-autofilt%)
  830. textuntil(chw%!876,33)<>
  831. (sldswait%) 
  832. $(chw%!876)=
  833. (sldswait%)
  834. forceredraw(choicesh%,24)
  835.  adju%<>0 
  836.  "Wimp_GetCaretPosition",,fr%
  837.  !fr%=choicesh% 
  838. placecaretinicon(choicesh%,24,-1):
  839. placecaretinicon(choicesh%,24,-2)
  840.  -fixdzoom%<>
  841. getopt(choicesh%,27) 
  842. setopt(choicesh%,27,-fixdzoom%)
  843.  -reptpics%<>
  844. getopt(choicesh%,42) 
  845. setopt(choicesh%,42,-reptpics%)
  846. choicesclick
  847.  a%,c%,d%,e%,a$
  848.  iconh%=10 
  849.  iconh%=11 
  850.  iconh%=12 
  851.  iconh%=13 
  852. slab(choicesh%,iconh%)
  853.  iconh%=25 
  854.  iconh%=26 
  855. getopt(choicesh%,25) 
  856.  iconh%<>25 
  857. setopt(choicesh%,25,
  858. getopt(choicesh%,26) 
  859.  iconh%<>26 
  860. setopt(choicesh%,26,
  861.  adju%<>0 
  862.  iconh% 
  863.  25:iconh%=26
  864.  26:iconh%=25
  865.  iconh% 
  866.  2,3,4
  867. getopt(choicesh%,iconh%)=
  868. getopt(choicesh%,2) 
  869. setopt(choicesh%,2,
  870. getopt(choicesh%,3) 
  871. setopt(choicesh%,3,
  872. getopt(choicesh%,4) 
  873. setopt(choicesh%,4,
  874. setopt(choicesh%,iconh%,
  875.  7,8,9
  876. getopt(choicesh%,iconh%)=
  877. getopt(choicesh%,7) 
  878. setopt(choicesh%,7,
  879. getopt(choicesh%,8) 
  880. setopt(choicesh%,8,
  881. getopt(choicesh%,9) 
  882. setopt(choicesh%,9,
  883. setopt(choicesh%,iconh%,
  884.  'Save'; store the choices as displayed in the Choices
  885.  window and OK them.
  886. openfh%=
  887. (choipath$)
  888.  openfh%=0 
  889.  490,"Can't find the !Choices file"
  890.  "Hourglass_Start",1
  891.  c%=0 
  892. readtick(ditheringmethod%,c%)=
  893.  a%=c%
  894. putchoice("Dithering",a%)
  895.  c%=0 
  896. readtick(fullscreenmode%,c%)=
  897.  a%=c%
  898. putchoice("Full Screen",a%)
  899. putchoice("Special Mode",mbu%)
  900. putchoice("Auto Full Screen",-
  901. getopt(choicesh%,16))
  902. putchoice("Modes Once Only",-
  903. getopt(choicesh%,17))
  904. putchoice("Close Display",-
  905. getopt(choicesh%,18))
  906. putchoice("Auto Filetype",-
  907. getopt(choicesh%,19))
  908. putchoice("Slideshow wait",-(
  909. textuntil(chw%!876,33))+1))
  910. putchoice("Always 1:1",-
  911. getopt(choicesh%,27))
  912. putchoice("Repeat pictures",-
  913. getopt(choicesh%,42))
  914. putchoice("Fade-in",-
  915. getopt(choicesh%,3)-2*
  916. getopt(choicesh%,4))
  917. putchoice("Fade-in speed",-fbl%!16-1)
  918. putchoice("Fade-out",-
  919. getopt(choicesh%,8)-2*
  920. getopt(choicesh%,9))
  921. putchoice("Fade-out speed",-fbl%!20-1)
  922.  "Hourglass_Off"
  923. #openfh%
  924. openfh%=0
  925. iconh%=13
  926. choicesclick
  927.  'Default'.
  928. readtick(ditheringmethod%,2)=
  929. settick(ditheringmethod%,0,
  930. settick(ditheringmethod%,1,
  931. settick(ditheringmethod%,2,
  932. $$(chw%!1260)="Slow but accurate"
  933. forceredraw(choicesh%,36)
  934. readtick(fullscreenmode%,1)=
  935.  a%=0 
  936. settick(fullscreenmode%,a%,
  937. settick(fullscreenmode%,1,
  938. &$(chw%!1356)="Best fit to picture"
  939. forceredraw(choicesh%,39)
  940. $mbu%="X800 Y600 C16M"
  941. getopt(choicesh%,2)=
  942. getopt(choicesh%,3) 
  943. setopt(choicesh%,3,
  944. setopt(choicesh%,4,
  945. setopt(choicesh%,2,
  946. getopt(choicesh%,7)=
  947. getopt(choicesh%,8) 
  948. setopt(choicesh%,8,
  949. setopt(choicesh%,9,
  950. setopt(choicesh%,7,
  951.  fbl%!16<>48 
  952.  fbl%!16=48:
  953. forceredraw(choicesh%,40)
  954.  fbl%!20<>48 
  955.  fbl%!20=48:
  956. forceredraw(choicesh%,41)
  957. getopt(choicesh%,16) 
  958. setopt(choicesh%,16,
  959. getopt(choicesh%,18) 
  960. setopt(choicesh%,18,
  961. getopt(choicesh%,17)=
  962. setopt(choicesh%,17,
  963. getopt(choicesh%,19)=
  964. setopt(choicesh%,19,
  965. textuntil(chw%!876,33)<>"0" 
  966. $(chw%!876)="0"
  967. forceredraw(choicesh%,24)
  968.  "Wimp_GetCaretPosition",,fr%
  969.  !fr%=choicesh% 
  970. placecaretinicon(choicesh%,24,-2)
  971. getopt(choicesh%,27)=
  972. setopt(choicesh%,27,
  973. getopt(choicesh%,42) 
  974. setopt(choicesh%,42,
  975.  'Cancel'; reset choices to as they were when
  976.  the window opened.
  977.  adju%=0 
  978. restorecaret:!fr%=choicesh%:
  979.  "Wimp_CloseWindow",,fr%
  980. setupchoices
  981.  'OK'; store choices internally and force the display window
  982.  to redraw if it is open, if the dithering method has changed.
  983. a%=ditherit%
  984.  c%=0 
  985. readtick(ditheringmethod%,c%) 
  986.  ditherit%=c%
  987. df%=ditherit%-(ditherit%=2)
  988.  c%=0 
  989. readtick(fullscreenmode%,c%) 
  990.  fullscrn%=c%
  991. +!fullmode$=
  992. textuntil(mbu%,32)
  993.  c%=0 
  994. getopt(choicesh%,c%+2) 
  995.  !fbl%=c%
  996.  c%=0 
  997. getopt(choicesh%,c%+7) 
  998.  fbl%!4=c%
  999. 5$autofull%=-
  1000. getopt(choicesh%,16)
  1001. 6$modesonc%=-
  1002. getopt(choicesh%,17)
  1003. 7$closedis%=-
  1004. getopt(choicesh%,18)
  1005. 8$autofilt%=-
  1006. getopt(choicesh%,19)
  1007. :(sldswait%=
  1008. textuntil(chw%!876,33))
  1009. ;$fixdzoom%=-
  1010. getopt(choicesh%,27)
  1011. <$reptpics%=-
  1012. getopt(choicesh%,42)
  1013. fbl%!8=fbl%!16
  1014. fbl%!12=fbl%!20
  1015. restorecaret
  1016. !fr%=choicesh%
  1017.  "Wimp_CloseWindow",,fr%
  1018. open(displayh%) 
  1019.  (a%<>ditherit%) 
  1020. redrawwindow(displayh%)
  1021.  25,26
  1022. H!a%=
  1023. textuntil(chw%!876,33))
  1024.  iconh%=25 
  1025.  a%-=1 
  1026.  a%+=1
  1027.  a%<0 
  1028.  a%=0
  1029.  a%>9999 
  1030.  a%=9999
  1031. $(chw%!876)=
  1032. forceredraw(choicesh%,24)
  1033.  "Wimp_GetCaretPosition",,fr%
  1034.  !fr%=choicesh% 
  1035. placecaretinicon(choicesh%,24,-2)
  1036.  Dithering Method menu button
  1037.  "Wimp_GetPointerInfo",,fr%
  1038. showmenu(ditheringmethod%,!fr%-16,fr%!4+22)
  1039.  Full Screen mode menu button
  1040. readtick(fullscreenmode%,4)=0 
  1041.  $mbu%=fullmode$
  1042.  "Wimp_GetPointerInfo",,fr%
  1043. showmenu(fullscreenmode%,!fr%-16,fr%!4+22)
  1044.  40,41
  1045.  Generalised slider code. Should have an icon with a slabbed
  1046.  border, unfilled; the twotone slider will be drawn inside it
  1047.  with a 4 OS unit gap between it and the icon's border. The
  1048.  4 OS unit gap will be filled in with colour 1 (to obscure any
  1049.  textures plotted in the window with appropriate patches or OS
  1050.  versions, as it looks bad if this isn't done).
  1051.  The routine *single tasks* during the slider drag. The part
  1052.  that extracts a numerical equivalent of the bar's position
  1053.  requires barmin% and barmax% to be set to the value the
  1054.  bar should have when dragged to the far left and far right
  1055.  respectively (may want to change this if different bars
  1056.  have different ranges, of course).
  1057.  Redraw is done by working out the value that the slider
  1058.  represents and sending this to PROCredrawslider. This ensures
  1059.  that this procedure never draws a bar in a way that is
  1060.  different from PROCredrawslider and means that should the
  1061.  whole bar width represent only a few values, it's movement
  1062.  will be quantized to certain positions. This looks better
  1063.  overall, in practice, to smooth movement.
  1064.  Because PROCredrawslider (which this calls) corrupts both
  1065.  s% and fr%, it is necessary to use b% for a local redraw
  1066.  loop - so...
  1067.  *CORRUPTS b%*
  1068. !fr%=choicesh%
  1069. fr%!4=iconh%
  1070.  "Wimp_GetIconState",,fr%
  1071. !s%=choicesh%
  1072.  "Wimp_GetWindowState",,s%
  1073. s%!64=fr%!8+s%!4-s%!20
  1074. s%!68=fr%!12+s%!16-s%!24
  1075. s%!72=fr%!16+s%!4-s%!20
  1076. s%!76=fr%!20+s%!16-s%!24
  1077.  s%!64+8,s%!68+8,s%!72-s%!64-16,s%!76-s%!68-16
  1078.  c%,c%,a%
  1079. e%=s%!72-s%!64-16
  1080. d%=c%-s%!64-8
  1081.  d%<0 
  1082.  d%=0
  1083.  d%>e% 
  1084.  d%=e%
  1085. (d%=barmin%+((barmax%-barmin%)/e%)*d%
  1086. !b%=choicesh%
  1087. b%!4=fr%!8+4
  1088. b%!8=fr%!12+4
  1089. b%!12=fr%!16-4
  1090. b%!16=fr%!20-4
  1091.  "Wimp_UpdateWindow",,b% 
  1092. redrawslider(choicesh%,iconh%,barmin%,barmax%,d%)
  1093.  "Wimp_GetRectangle",,b% 
  1094.  a%=0
  1095. readscreensize(a%,c%)
  1096.  0,0,a%-1,c%-1
  1097.  Now set the relevant variable.
  1098.  iconh%=40 
  1099.  fbl%!16=d% 
  1100.  fbl%!20=d%
  1101. saveasclick
  1102.  iconh%=2 
  1103.  iconh%=3 
  1104. slab(saveash%,iconh%)
  1105.  iconh% 
  1106. makedragbox(saveash%,0,"file_c85")
  1107.  "Wimp_CreateMenu",,-1
  1108. !fr%=saveash%
  1109.  "Wimp_CloseWindow",,fr%
  1110. textuntil(sav%!140,33),".")=0) 
  1111. textuntil(sav%!140,33),"<")=0) 
  1112.  (1<<30)+3,"To save, drag the file icon to a directory display."
  1113. savefile(
  1114. textuntil(sav%!140,33))
  1115.  "Wimp_CreateMenu",,-1
  1116. !fr%=saveash%
  1117.  "Wimp_CloseWindow",,fr%
  1118.  -- Icon handling procedures
  1119. setopt(a%,c%,d%)
  1120. getopt(a%,c%)<>d% 
  1121. !s%=a%
  1122. s%!4=c%
  1123.  "Wimp_GetIconState",,s%
  1124.  s%!8=0 
  1125.  s%!8=&200000
  1126. !s%=a%
  1127. s%!4=c%
  1128. s%!12=&200000
  1129.  "Wimp_SetIconState",,s%
  1130. slab(a%,c%)
  1131.  Pass a window and icon handle. Briefly sets that icon
  1132.  as selected then unselected. With buttons, this will
  1133.  have the effect of slabbing them in temporarily.
  1134. getopt(a%,c%)=
  1135. setopt(a%,c%,
  1136. setopt(a%,c%,
  1137. waitforrelease
  1138. storecaret
  1139.  Gets the current caret position and stores it in lca%, but only if
  1140.  the caret isn't lost. This allows e.g. a prequit window to be
  1141.  opened several times in a row and the caret will not be lost, by
  1142.  storing it after it was lost when the first prequit window got
  1143.  deleted.
  1144.  "Wimp_GetCaretPosition",,fr%
  1145.  !fr%<>-1 
  1146.  "Wimp_GetCaretPosition",,lca%
  1147. restorecaret
  1148.  Puts the caret into a window using information in the lca% block,
  1149.  checking that lca% holds valid information. Don't forget to
  1150.  invalidate lca% with !lca%=-1 on Wimp reason code 11 (LoseCaret).
  1151. !fr%=!lca%
  1152.  "XWimp_GetWindowState",,fr% 
  1153.  (a% 
  1154.  1)=0 
  1155. open(!lca%) 
  1156.  "Wimp_SetCaretPosition",!lca%,lca%!4,lca%!8,lca%!12,lca%!16,lca%!20
  1157. placecaretinicon(a%,c%,d%)
  1158.  Pass window handle, icon handle, index into string. Passing -1 puts the
  1159.  caret to the Wimp default position (wherever that might be...); passing
  1160.  -2 puts it to the end of the string in the icon; passing -3 puts it to
  1161.  the middle.
  1162. !fr%=a%
  1163. fr%!4=c%
  1164.  "Wimp_GetIconState",,fr%
  1165. !e%=(fr%!12-fr%!20) 
  1166.  &1000000
  1167.  d%=-2 
  1168. textuntil(fr%!28,32))
  1169.  d%=-3 
  1170.  d%=(
  1171. textuntil(fr%!28,32))) 
  1172.  "Wimp_GetCaretPosition",,fr%+32
  1173.  fr%!32<>a% 
  1174.  fr%!36<>c% 
  1175.  fr%!52<>d% 
  1176.  "Wimp_SetCaretPosition",a%,c%,fr%!8+16*d%,fr%!12+8,e%,d%
  1177.  -- Menu handling procedures
  1178. menudata
  1179.  "SwiftJPEG","Info","Zoom@M","Picture","Full screen...","Reload image","Next image","Choices...@D","Quit","*"
  1180.  "Picture","Info","Save","*"
  1181.  "Dithering","No dithering","Fast but inaccurate","Slow but accurate","*"
  1182.  "Full screen","Use current mode","Best fit to picture","Use biggest","Use most colourful@D","@W","mbu%","64","*"
  1183. openmainmenu(a%)
  1184.  lisareah%=0 
  1185. greyoutmenu(mainmenuaddr%,5) 
  1186. ungreymenu(mainmenuaddr%,5)
  1187. showmenu(mainmenuaddr%,!b%-116,140+7*44+24) 
  1188. showmenu(mainmenuaddr%,!b%-116,b%!4+22)
  1189. attach(a%,c%,d%)
  1190. !(a%+28+c%*24+4)=d%
  1191. showmenu(a%,x%,y%)
  1192.  a%=fullscreenmode% 
  1193. textuntil(mbu%,32):$mbu%=
  1194. *lastmena%=a%:lastmenx%=x%:lastmeny%=y%
  1195.  "Wimp_CreateMenu",,a%,x%,y% 
  1196.  lastmenh%
  1197.  a%=fullscreenmode% 
  1198.  $mbu%=a$
  1199. settick(a%,c%,d%)
  1200.  a%!(28+c%*24)=a%!(28+c%*24)
  1201.  a%!(28+c%*24)=a%!(28+c%*24)
  1202. &FFFFFFFE
  1203. greyoutmenu(a%,c%)
  1204. &/a%!(28+c%*24+8)=(a%!(28+c%*24+8)) 
  1205.  (1<<22)
  1206. ungreymenu(a%,c%)
  1207. *3a%!(28+c%*24+8)=(a%!(28+c%*24+8)) 
  1208.  (1<<22))
  1209. menuselect
  1210.  a%,c%,d%,a$
  1211.  "Wimp_GetPointerInfo",,s%
  1212. adju%=(s%!8 
  1213.  "Wimp_DecodeMenu",,lastmena%,b%,s%
  1214.  $s% 
  1215.  "Info"
  1216.  "Wimp_GetPointerInfo",,fr%
  1217.  "Wimp_CreateMenu",,infoh%,!fr%-22,fr%!4-22
  1218.  "Zoom"
  1219. checkzoomfraction
  1220.  "Wimp_GetPointerInfo",,fr%
  1221. showmenu(zoomh%,!fr%-30,fr%!4+36)
  1222.  "Picture","Picture.Info"
  1223.  "Wimp_GetPointerInfo",,fr%
  1224.  "Wimp_CreateMenu",,jpeginfoh%,!fr%-20,fr%!4-20
  1225.  "Picture.Save"
  1226.  "Wimp_GetPointerInfo",,fr%
  1227. a%=!fr%
  1228. c%=fr%!4
  1229. !fr%=saveash%
  1230.  "Wimp_GetWindowState",,fr%
  1231. fr%!12=fr%!12-fr%!4+a%-20
  1232. fr%!4=a%-20
  1233. fr%!8=fr%!8-fr%!16+c%-20
  1234. fr%!16=c%-20
  1235. fr%!28=-1
  1236.  "Wimp_OpenWindow",,fr%
  1237.  "Wimp_GetCaretPosition",,fr%
  1238.  !fr%<>saveash% 
  1239. storecaret
  1240. placecaretinicon(saveash%,1,-2)
  1241.  "Full screen..."
  1242. showcurrent
  1243.  "Reload image"
  1244. loadpicture(jpegname$)
  1245.  autofull% 
  1246. showcurrent
  1247.  "Next image"
  1248. showbatch(autofull%)
  1249.  "Choices..."
  1250.  "Wimp_GetCaretPosition",,fr%
  1251.  !fr%<>choicesh% 
  1252. storecaret
  1253. setupchoices
  1254. opencentered(choicesh%)
  1255. placecaretinicon(choicesh%,24,-2)
  1256.  "Quit"
  1257. quit%=
  1258.  "No dithering","Fast but inaccurate","Slow but accurate"
  1259. textuntil(chw%!1260,32)<>$s% 
  1260.  a%=0 
  1261. settick(ditheringmethod%,a%,
  1262. settick(ditheringmethod%,!b%,
  1263. $(chw%!1260)=$s%
  1264. forceredraw(choicesh%,36)
  1265.  "Best fit to picture","Use biggest","Use most colourful","Use current mode"
  1266. textuntil(chw%!1356,32)<>$s% 
  1267.  a%=0 
  1268. settick(fullscreenmode%,a%,
  1269. settick(fullscreenmode%,!b%,
  1270. $(chw%!1356)=$s%
  1271. forceredraw(choicesh%,39)
  1272.  (lastmena%=fullscreenmode%) 
  1273.  (!b%=4) 
  1274. textuntil(mbu%,32)
  1275. buildmode(a$,fr%)
  1276.  a%=-1 
  1277.  $mbu%=fullmode$:
  1278.  (1<<30)+1,"The specified Full Screen mode is invalid"
  1279.  a%<>0 
  1280.  "OS_ReadModeVariable",a%-1,4 
  1281.  ,,!fr%
  1282.  "OS_ReadModeVariable",a%-1,5 
  1283.  ,,fr%!4
  1284.  !fr%<>fr%!4 
  1285.  $mbu%=fullmode$:
  1286.  (1<<30)+1,"You can only use square pixel modes, such as 13 or 20"
  1287. fr%!20=-1
  1288.  "OS_ReadModeVariable",fr%,4 
  1289.  ,,fr%!128
  1290.  "OS_ReadModeVariable",fr%,5 
  1291.  ,,fr%!132
  1292.  fr%!128<>fr%!132 
  1293.  (1<<30)+1,"You can only use square pixel modes, such as 'X800 Y600 C32K'"
  1294. &a$="X"+
  1295. (fr%!4)+" Y"+
  1296. (fr%!8)+" C"
  1297.  fr%!12 
  1298.  0:a$+="2"
  1299.  1:a$+="4"
  1300.  2:a$+="16"
  1301.  3:a$+="256"
  1302.  4:a$+="32K"
  1303.  5:a$+="16M"
  1304.  fr%!16<>-1 
  1305.  a$+=" F"+
  1306. (fr%!16)
  1307.  a%=0 
  1308. settick(fullscreenmode%,a%,
  1309. settick(fullscreenmode%,4,
  1310. $mbu%=a$
  1311. (a$)>20 
  1312. a$,17)+"..."
  1313. $(chw%!1356)=a$
  1314. forceredraw(choicesh%,39)
  1315.  adju% 
  1316. showmenu(lastmena%,lastmenx%,lastmeny%)
  1317.  -- Full Screen handling procedures
  1318. fullscreen(c%)
  1319.  Plots a picture Full Screen, handling changes *into* the
  1320.  required mode and gamma changes where appropriate. Single
  1321.  tasks until the user requests it continue or it times out
  1322.  (as someone has set up some delay for the slideshow).
  1323.  Sets abortmul% as TRUE if the user pressed Escape.
  1324.  Does NOT do anything else - doesn't store the current
  1325.  Desktop mode, doesn't restore it or prompt for that to
  1326.  happen... etc - that must all be handled externally.
  1327.  Pass TRUE if you want an hourglass whilst the display
  1328.  screen mode is worked out, else FALSE.
  1329.  a%,d%,e%,x%,y%,x1%,y1%
  1330.  Read the current gamma values if Compo_ReadGamma is present.
  1331.  "XOS_SWINumberFromString",,"XCompo_ReadGamma" 
  1332.  cgamread%;a%
  1333.  (a% 
  1334.  cgamread%=
  1335.  cgamread%<>0 
  1336.  cgamread%,pgr%,pgg%,pgb%
  1337.  !fbl%=0 
  1338. gammanormal 
  1339. gammablack
  1340.  fixdzoom% 
  1341.  d%=1:e%=1 
  1342.  d%=zoomm%:e%=zoomd%
  1343. x1%=xpic%*d%/e%
  1344. y1%=ypic%*d%/e%
  1345.  "Hourglass_Start",5
  1346.  fullscrn% 
  1347.  "OS_ReadModeVariable",-1,11 
  1348.  ,,x%
  1349.  "OS_ReadModeVariable",-1,12 
  1350.  ,,y%
  1351.     x%+=1
  1352.     y%+=1
  1353. findbestfit(x1%,y1%,x%,y%,a%)
  1354.  xbig%=0 
  1355.  modesonc%=0 
  1356. findbiggest(xbig%,ybig%,bbpp%)
  1357. x%=xbig%
  1358. y%=ybig%
  1359. a%=bbpp%
  1360.  xclr%=0 
  1361.  modesonc%=0 
  1362. findcolours(xclr%,yclr%,cbpp%)
  1363. x%=xclr%
  1364. y%=yclr%
  1365. a%=cbpp%
  1366. buildmode(fullmode$,fr%)
  1367.  a%=-1 
  1368.  (1<<30)+1,"The specified Full Screen mode is invalid"
  1369.  a%=0 
  1370.  "OS_CheckModeValid",fr% 
  1371.  "OS_CheckModeValid",a%-1
  1372.  !fr%=-1 
  1373.  (1<<30)+1,"The specified Full Screen mode is not available"
  1374.  a%=0 
  1375.  "OS_ReadModeVariable",fr%,4 
  1376.  ,,fr%!128
  1377.  "OS_ReadModeVariable",fr%,5 
  1378.  ,,fr%!132
  1379.  fr%!128<>fr%!132 
  1380.  (1<<30)+1,"You can only use square pixel modes, such as 'X800 Y600 C32K'"
  1381. x%=fr%!4
  1382. y%=fr%!8
  1383. a%=fr%!12
  1384.  "OS_ReadModeVariable",a%-1,4 
  1385.  ,,!fr%
  1386.  "OS_ReadModeVariable",a%-1,5 
  1387.  ,,fr%!4
  1388.  !fr%<>fr%!4 
  1389.  (1<<30)+1,"You can only use square pixel modes, such as 13 or 20"
  1390.  "OS_ReadModeVariable",a%-1,3 
  1391.  ,,fr%!12
  1392.  "OS_ReadModeVariable",a%-1,11 
  1393.  ,,fr%!4
  1394.  "OS_ReadModeVariable",a%-1,12 
  1395.  ,,fr%!8
  1396. x%=fr%!4+1
  1397. y%=fr%!8+1
  1398. 0a%=-1*(fr%!12=3)-2*(fr%!12=15)-3*(fr%!12=63)
  1399. fr%!16=-1
  1400.  0,0,0,0
  1401. 0,0,32767
  1402.  "Hourglass_Off"
  1403.  Change to the relevant screen mode. A mode selection block
  1404.  is built, and the mode is changed into if it looks different
  1405.  to the current one.
  1406.  fullscrn%<>0 
  1407. !fr%=1
  1408. fr%!4=x%
  1409. fr%!8=y%
  1410. fr%!12=a%
  1411.  fullscrn%<>4 
  1412.  fr%!16=-1
  1413. fr%!20=-1
  1414. <=127 
  1415.  (fr%!4<>!(
  1416.  fr%!8<>!(
  1417.  fr%!12<>!(
  1418. +12)) 
  1419.  ((fullscrn%=4)*(fr%!16<>!(
  1420. +16))) 
  1421.  "Wimp_SetPalette"
  1422.  0,0,0,0
  1423. 0,0,32767
  1424. x%=x%-x1%
  1425. y%=y%-y1%
  1426. !fr%=d%
  1427. fr%!4=d%
  1428. fr%!8=e%
  1429. fr%!12=e%
  1430.  "XJPEG_PlotScaled",picareab%,x%,y%,fr%,jpegleng%,df%
  1431.  !fbl% 
  1432. gammafadeinflatten
  1433. gammaflashinbycosine
  1434. gammanormal
  1435.  abortmul%=
  1436.  "OS_Byte",121 
  1437.  a%=255 
  1438.  a%=112
  1439.  a%=112 
  1440.  abortmul%=
  1441.  abortmul%=
  1442.  "OS_Byte",121 
  1443.  (a%<>255) 
  1444. >=sldswait%*100) 
  1445.  (sldswait%<>0))
  1446.  a%=112 
  1447.  abortmul%=
  1448.  (((a%=11) 
  1449.  (sldswait%<>0)) 
  1450.  (a%=37)) 
  1451.  (abortmul%=
  1452. overlaypausesymbol
  1453.  a%=37 
  1454. overlaypictureinfo 
  1455. waitfornokeys
  1456.  "OS_Byte",121 
  1457.  (a%<>255)
  1458.  (a%<>37) 
  1459.  (c%=
  1460.  a%=112 
  1461.  abortmul%=
  1462.  ENDIF from check to see if right hand button was pressed when
  1463.  slideshow delays were turned on, or if 'I' was pressed, and that
  1464.  in any case abortmul% was FALSE, and if so overlay the pause
  1465.  symbol and/or the picture info and wait for more keys.
  1466.  abortmul%=
  1467. waitfornokeys
  1468.  fbl%!4 
  1469. gammafadeoutbycosine
  1470. gammaflashoutlinear
  1471.  ENDIF from check after fading in to see if abortmul% was set to TRUE
  1472.  0,0,0,0
  1473. 0,0,32767
  1474. gammanormal
  1475. waitforrelease
  1476.  "XOS_CLI","FX 15"
  1477. showbatch(c%)
  1478.  Pass a flag. If the flag is non-zero, then all the pictures
  1479.  in the file list (if present) will be shown full screen, one
  1480.  after another, with all the handling of the display window and
  1481.  restoration etc. of screen modes handled here (though the
  1482.  PROCfullscreen procedure handles storing the Desktop mode
  1483.  ready for an external call to PROCrestoremode).
  1484.  If the flag is zero, then a picture from the file list (again,
  1485.  if present) will be loaded and the pointer in the file list
  1486.  advanced.
  1487.  The idea is that a user can drag on a group of pictures and
  1488.  view them in the Desktop, one by one, or all Full Screen.
  1489.  (lisareah%<>0) 
  1490. showbatchfull 
  1491. showbatchdesktop
  1492. showbatchfull
  1493.  See PROCshowbatch for details.
  1494.  a%,c%,d%,a$
  1495.  Full screen views of all pictures in file list...
  1496. open(choicesh%) 
  1497.  iconh%=13:adju%=0:
  1498. choicesclick
  1499. open(displayh%) 
  1500.  !dst%=displayh%:
  1501.  "Wimp_GetWindowState",,dst%:dst%!28=-1 
  1502.  !dst%=-1
  1503. returnto%=
  1504. mos%!124=returnto%
  1505.  returnto%>127 
  1506.  a%=0 
  1507.  123 
  1508. mos%!a%=returnto%!a%
  1509. returnto%=mos%
  1510.  lisareah%<>0 
  1511.  abortmul%=
  1512.  (lisloadp%>=lisnextp%) 
  1513.  reptpics% 
  1514. lisloadp%=lisareab%
  1515. textuntil(lisloadp%,32)
  1516. a%=?(lisloadp%+
  1517. (a$))
  1518.  a%=0 
  1519. lisloadp%+=
  1520. (a$)+1
  1521.  lisloadp%>=lisnextp%
  1522. lisloadp%=lisareab%
  1523. removearea(lisareah%)
  1524. lisareah%=0
  1525.  (1<<30)+1,"None of the pictures in the group can be displayed! So can't move to another image"
  1526. textuntil(lisloadp%,32)
  1527. a%=?(lisloadp%+
  1528. (a$))
  1529. lisloadp%+=
  1530. (a$)+1
  1531.  (lisloadp%>=lisnextp%) 
  1532.  (reptpics%=0) 
  1533. removearea(lisareah%):lisareah%=0
  1534.  a%=0 
  1535. loadpicture(a$)
  1536. fullscreen(d%)
  1537.  abortmul% 
  1538.  reptpics% 
  1539. removearea(lisareah%):lisareah%=0
  1540.  returnto%<>-1 
  1541. restoremode
  1542. abortmul%=
  1543.  closedis%<>0 
  1544. !b%=displayh%:
  1545. closewindow
  1546.  !dst%=-1 
  1547. opencentered(displayh%) 
  1548.  "Wimp_OpenWindow",,dst%
  1549. showbatchdesktop
  1550.  See PROCshowbatch for details.
  1551.  a%,d%,a$
  1552. textuntil(lisloadp%,32)
  1553. a%=?(lisloadp%+
  1554. (a$))
  1555. lisloadp%+=
  1556. (a$)+1
  1557.  lisloadp%>=lisnextp% 
  1558. removearea(lisareah%):lisareah%=0
  1559.  a%=0 
  1560. loadpicture(a$)
  1561. showcurrent
  1562.  Shows the currently loaded picture Full Screen,
  1563.  handling storing and restoring the Display window
  1564.  position and restoring the previous Desktop screen
  1565.  mode.
  1566. open(choicesh%) 
  1567.  iconh%=13:adju%=0:
  1568. choicesclick
  1569. open(displayh%) 
  1570.  !dst%=displayh%:
  1571.  "Wimp_GetWindowState",,dst%:dst%!28=-1 
  1572.  !dst%=-1
  1573. returnto%=
  1574. mos%!124=returnto%
  1575.  returnto%>127 
  1576.  a%=0 
  1577.  123 
  1578. mos%!a%=returnto%!a%
  1579. returnto%=mos%
  1580. fullscreen(
  1581. restoremode
  1582. abortmul%=
  1583.  closedis%<>0 
  1584. !b%=displayh%:
  1585. closewindow
  1586.  !dst%=-1 
  1587. opencentered(displayh%) 
  1588.  "Wimp_OpenWindow",,dst%
  1589. findbiggest(
  1590.  Pass three variables into which will be
  1591.  passed the x and y sizes of a screen mode,
  1592.  and it's colour depth (as in a mode selector
  1593.  block; 0=1 bpp, 1=2bpp, 2=4bpp, 3=8bpp etc).
  1594.  The routine passes the largest mode, with
  1595.  the best colour depth available for the
  1596.  size.
  1597.  Modes where the y size is bigger than the
  1598.  x size, or where the y size when doubled is
  1599.  larger than the x size are not chosen as
  1600.  these are assumed to be in the first case,
  1601.  of undesirable aspect ratio and in the
  1602.  second case, of medium resolution (like
  1603.  mode 12, 640x256x16 colours).
  1604.  To avoid stupid resolutions like 320x250,
  1605.  which for many people will have no advantages
  1606.  over, say, 320x256 though at least the
  1607.  latter may have a 100Hz equivalent for those
  1608.  with monitors that would otherwise letterbox
  1609.  things, the x and y coordinates must both
  1610.  be divisible by 4.
  1611.  a%,d%,e%
  1612.  "OS_ScreenMode",2 
  1613.  ,,d%
  1614.  e%=0 
  1615.  (-d%)-1
  1616.  "OS_ScreenMode",2,,e%,,,,b%,64
  1617.  (b%!8>b%!12) 
  1618.  ((b%!12)*2>b%!8) 
  1619.  (b%!8 
  1620.  4=0) 
  1621.  (b%!12 
  1622.  4=0) 
  1623.  (b%!8>=x%) 
  1624.  (b%!12>=y%) 
  1625.  x%=b%!8:y%=b%!12:c%=b%!16
  1626. overlaypausesymbol
  1627.  4,255,255,255
  1628.  a%=1 
  1629.  64,64,12,24
  1630.  84,64,12,24
  1631.  64,64,12,24
  1632.  84,64,12,24
  1633. overlaypictureinfo
  1634.  0,0,0,0
  1635.  62,62,270,74
  1636.  0,255,255,255
  1637.  64,64,266,70
  1638.  68,124
  1639. 16," ")
  1640. jpegname$,16)
  1641. a$,1)<>" " 
  1642. a$,1,3)="..."
  1643. a$,4)="...." 
  1644. a$,1)=" "
  1645.  68,104
  1646. 16," ")
  1647. (xpic%)+"x"+
  1648. (ypic%),16)
  1649. a$,1)<>" " 
  1650. 16," "):
  1651. a$)="Very big picture"
  1652.  68,86
  1653. 16," ")
  1654. (jpegleng%)+" bytes",16)
  1655. a$,1)<>" " 
  1656. 16," "):
  1657. a$)="Very large file"
  1658. findcolours(
  1659.  As PROCbiggest, but returns the largest mode
  1660.  available from the list of those with the
  1661.  highest colour depth available (e.g. 640x480
  1662.  by 16.7M with 1Mb VRAM, 800x600 by 16.7M with
  1663.  2Mb).
  1664.  a%,d%,e%
  1665.  "OS_ScreenMode",2 
  1666.  ,,d%
  1667.  e%=0 
  1668.  (-d%)-1
  1669.  "OS_ScreenMode",2,,e%,,,,b%,64
  1670.  (b%!8>b%!12) 
  1671.  ((b%!12)*2>b%!8) 
  1672.  (b%!8 
  1673.  4=0) 
  1674.  (b%!12 
  1675.  4=0) 
  1676.  (b%!16>=c%) 
  1677.  (b%!8>=x%) 
  1678.  (b%!12>=y%) 
  1679.  x%=b%!8:y%=b%!12:c%=b%!16
  1680. findbestfit(x1%,y1%,
  1681.  Pass an x and y size and three variables as for
  1682.  PROCbiggest and PROCcolours. This routine returns
  1683.  the mode which is of greater or equal size to the
  1684.  x and y coordinates you pass.
  1685.  If no mode will is big enough, PROCbiggest is called
  1686.  and those values returned. If it's important, then,
  1687.  check that the returned x and y sizes really are both
  1688.  bigger than the passed x and y sizes.
  1689.  a%,d%,e%,x2%,y2%
  1690.  "OS_ScreenMode",2 
  1691.  ,,d%
  1692. K    x2%=0
  1693. L    y2%=0
  1694. x%=1E9
  1695. y%=1E9
  1696.  e%=0 
  1697.  (-d%)-1
  1698.  "OS_ScreenMode",2,,e%,,,,b%,64
  1699.  (b%!8>b%!12) 
  1700.  ((b%!12)*2>b%!8) 
  1701.  (b%!8 
  1702.  4=0) 
  1703.  (b%!12 
  1704.  4=0) 
  1705.  (b%!8>=x1%) 
  1706.  (b%!12>=y1%) 
  1707.  ((b%!8-x1%)<=x%) 
  1708.  ((b%!12-y1%)<=y%) 
  1709.  x2%=b%!8:y2%=b%!12:x%=x2%-x1%:y%=y2%-y1%:c%=b%!16
  1710.  x2%=0 
  1711. findbiggest(x2%,y2%,c%)
  1712. x%=x2%
  1713. y%=y2%
  1714.  -- JPEG handling procedures
  1715. storefilename
  1716.  a$,a%,c%
  1717.  If there was an error flagged by a call to this procedure, listfull% will be
  1718.  non-zero, so we don't want do do much of the below code.
  1719.  listfull%=0 
  1720.  If a dynamic area already exists but the flag picsdone% says some pictures have
  1721.  been loaded (or have been attempted to be loaded) then remove the file list;
  1722.  apart from anything else if one picture is causing a repeated error and the
  1723.  user tries to drag on a different one, it would just get appended to the file
  1724.  list unless this removal was done.
  1725.  (lisareah%<>0) 
  1726.  (picsdone%<>0) 
  1727. removearea(lisareah%):lisareah%=0
  1728.  If no dynamic area exists, create one, set all block pointers to its
  1729.  base address and set c% to TRUE (see later - if c% is TRUE a message
  1730.  will be sent back to this task by itself to prompt loading of the
  1731.  first picture).
  1732.  lisareah%=0 
  1733. claimarea(0,lismaxsi%,"SwiftJPEG file list",lisareah%,lisareab%):lisloadp%=lisareab%:lisnextp%=lisareab%:c%=
  1734. :picsdone%=0
  1735.  If there is still no existing area the claim failed, so flag an
  1736.  appropriate error through listfull%.
  1737.  lisareah%=0 
  1738.  listfull%=2
  1739.  If there is no error flagged, get the filename and store it in the
  1740.  file list dynamic area, extending the area if necessary. If the
  1741.  extension claim fails, an appropriate error is flagged in listfull%.
  1742.  listfull%=0 
  1743. textuntil(b%+44,33)
  1744.  "OS_ReadDynamicArea",lisareah% 
  1745.  lisnextp%-lisareab%+
  1746. (a$)+1>a% 
  1747. changearea(lisareah%,a%+
  1748. (a$)+2,a%)
  1749.  a%=-1 
  1750.  Memory claim failed - flag an error and if this was the very first
  1751.  claim (the area is 0 bytes in size) remove the area.
  1752. listfull%=1
  1753.  "OS_ReadDynamicArea",lisareah% 
  1754.  a%=0 
  1755. removearea(lisareah%):lisareah%=0
  1756.  If both the dynamic area and any extensions to it have proceeded
  1757.  without error, store the filename in the area and update the store
  1758.  pointer.
  1759.  listfull%=0 
  1760. $lisnextp%=a$
  1761. ?(lisnextp%+
  1762. (a$))=0
  1763. lisnextp%=lisnextp%+
  1764. (a$)+1
  1765.  ENDIF from overall check to see if listfull% was non-zero near the
  1766.  start ofthis procedure.
  1767.  Reply to the DataLoad message with a DataLoadAck message, if
  1768.  !b%<>-1 (this routine might be called without actually
  1769.  having a real DataLoad message, in which case !b% will be
  1770.  set to -1).
  1771.  We want to reply even if the routine fails for some reason
  1772.  as otherwise multiple copies of SwiftJPEG may end up being
  1773.  launched.
  1774.  !b%<>-1 
  1775. a%=b%!4
  1776. b%!4=task%
  1777. b%!12=b%!8
  1778. b%!16=4
  1779.  "Wimp_SendMessage",17,b%,a%
  1780.  If we couldn't even create a dynamic area we don't want to then
  1781.  prompt the Poll loop to start displaying pictures listed in it! So
  1782.  give an error (and therefore exit) before the prompt is given (see
  1783.  below).
  1784.  listfull%=1 
  1785.  (1<<30)+1,"Not enough memory to load picture, or to queue it for loading later"
  1786.  listfull%=2 
  1787.  (1<<30)+1,"Can't create an area of memory to store picture names in"
  1788.  If c% was set to true, the routine had to create a dynamic
  1789.  area before it could start storing pictures. In this case, we
  1790.  now want to send one message back to this task so that after
  1791.  all the DataLoad messages have finished coming in (as they'll
  1792.  be at the front of the queue) the Poll loop gets another
  1793.  special message which it interprets as the que to start
  1794.  displaying the picture(s).
  1795.  !fr%=-1:
  1796.  "Wimp_SendMessage",3,fr%,task%
  1797. loadpicture(a$)
  1798.  a%,c%
  1799. loaderro%=0
  1800. picsdone%=1
  1801. filelength(a$)
  1802.  a%<1 
  1803.  loaderro%=lisloadp%-1:
  1804.  (1<<30)+1,"File not found"
  1805.  Check that the file contents indicate a JPEG.
  1806.  a%>4 
  1807. openfh%=
  1808. c%+=(
  1809. #openfh%=&FF)
  1810. c%+=(
  1811. #openfh%=&D8)
  1812. c%+=(
  1813. #openfh%=&FF)
  1814. c%+=(
  1815. #openfh%=&E0)
  1816. #openfh%
  1817. openfh%=0
  1818.  c%<>-4 
  1819.  loaderro%=lisloadp%-1:
  1820.  (1<<30)+1,"This is not a JPEG file"
  1821.  c%=-4 
  1822.  If you want to allow Reload Image when the image is
  1823.  still loaded, change the PROCgreyoutmenu line to
  1824.  grey the item if the filename is <Wimp$Scrap> or
  1825.  ungrey it (PROCungreymenu) if not.
  1826. jpegname$=a$
  1827.  jpegname$="<Wimp$Scrap>" 
  1828. greyoutmenu(mainmenuaddr%,4) 
  1829. ungreymenu(mainmenuaddr%,4)
  1830. jpegleng%=a%
  1831. filetype(jpegname$)) 
  1832.  (autofilt%=1) 
  1833.  "XOS_CLI","SetType "+jpegname$+" C85"
  1834. removearea(picareah%)
  1835. claimarea(jpegleng%+256,jpegleng%+256,"SwiftJPEG picture",picareah%,picareab%)
  1836.  picareah%<>0 
  1837.  Load the file - done with OS_Find and OS_GBPB to avoid
  1838.  potential problems with OS_File and memory access to
  1839.  dynamic areas on large memory machines (an OS bug).
  1840.  "Hourglass_On"
  1841.  "OS_Find",&4F,jpegname$ 
  1842.  openfh%
  1843.  "OS_GBPB",4,openfh%,picareab%,
  1844. #openfh%
  1845.  "OS_Find",,openfh%:openfh%=0
  1846.  jpegname$="<Wimp$Scrap>" 
  1847.  jpegname$="ScrapFile"
  1848. $(sav%!140)=jpegname$
  1849.  "Hourglass_Off"
  1850.  Kill scrapfile if it was used.
  1851. textuntil(b%+44,33)="<Wimp$Scrap>" 
  1852.  "XOS_File",6,"<Wimp$Scrap>"
  1853. open(displayh%) 
  1854. !fr%=displayh%
  1855.  "Wimp_CloseWindow",,fr%
  1856. resizemainwindow
  1857. titlebarchange(displayh%,jpegname$+" ("+
  1858. (xpic%)+"x"+
  1859. (ypic%)+")")
  1860. !fr%=displayh%
  1861.  "Wimp_GetWindowInfo",,fr%
  1862. fr%!4=0
  1863. fr%!8=0
  1864. fr%!12=&7FFFFFF
  1865. fr%!16=&7FFFFFF
  1866.  "Wimp_OpenWindow",,fr%
  1867. opencentered(displayh%)
  1868. fillininfo
  1869.  ELSE from check to see if there was enough memory
  1870.  to load the file
  1871.  (1<<30)+1,"There is not enough free memory to load the picture"
  1872.  ENDIF from check to see if there was enough memory
  1873.  to load the file.
  1874.  ENDIF from check to see if the file had the JPEG
  1875.  filetype (&C85).
  1876. resizemainwindow
  1877.  "OS_ReadModeVariable",-1,4 
  1878.  ,,xeig%
  1879.  "OS_ReadModeVariable",-1,5 
  1880.  ,,yeig%
  1881.  xeig%>0 
  1882. !sc%=1
  1883. sc%!8=xeig%
  1884. !sc%=2
  1885. sc%!8=1
  1886.  yeig%>0 
  1887. sc%!4=1
  1888. sc%!12=yeig%
  1889. sc%!4=2
  1890. sc%!12=1
  1891. !sc%=(!sc%)*zoomm%
  1892. sc%!4=(sc%!4)*zoomm%
  1893. sc%!8=(sc%!8)*zoomd%
  1894. sc%!12=(sc%!12)*zoomd%
  1895.  "XJPEG_Info",,picareab%,jpegleng% 
  1896.  ,,xpic%,ypic%,xdpi%,ydpi%
  1897. !fr%=0
  1898. E$fr%!4=((-ypic%*2)*zoomm%)/zoomd%
  1899. F#fr%!8=((xpic%*2)*zoomm%)/zoomd%
  1900. fr%!12=0
  1901.  ((fr%!4) 
  1902.  2)<>0 
  1903.  fr%!4=(((fr%!4) 
  1904.  2)-1)*2
  1905.  ((fr%!8) 
  1906.  2)<>0 
  1907.  fr%!8=(((fr%!8) 
  1908.  2)+1)*2
  1909.  "Wimp_SetExtent",displayh%,fr%
  1910. windheig%=-fr%!4
  1911. modeinfo(a%)
  1912.  When passed a screen mode number, this sets the
  1913.  globals xeig% and yeig% to the number of OS units
  1914.  per pixel in the x and y directions respectively.
  1915.  "OS_ReadModeVariable",a%,4 
  1916.  ,,xeig%
  1917.  "OS_ReadModeVariable",a%,5 
  1918.  ,,yeig%
  1919. xeig%=xeig%*2
  1920. yeig%=yeig%*2
  1921. fillininfo
  1922. (jpegname$)>27 
  1923.  a$="..."+
  1924. jpegname$,24) 
  1925.  a$=jpegname$
  1926.  Line below - If the pathname is >27 characters, then the '...' is put
  1927.  in front of the last 24. But what happens if those 24, by chance,
  1928.  start with a '.' of a directory separator? The line below should remove
  1929.  one dot should the string start with four of them, which indicates
  1930.  that the used 24 characters did indeed start with a dot.
  1931. a$,4)="...." 
  1932. a$,2)
  1933. $(jiw%!108)=a$
  1934. (jpegleng%)
  1935. (a$)>7 
  1936.  a$=">9.5Mb!"
  1937. $(jiw%!236)=a$
  1938. (xpic%)
  1939. (a$)>6 
  1940.  a$="V.Wide"
  1941. $(jiw%!268)=a$
  1942. (ypic%)
  1943. (a$)>6 
  1944.  a$="V.Tall"
  1945. $(jiw%!300)=a$
  1946. ungreymenu(mainmenuaddr%,2)
  1947. ungreymenu(mainmenuaddr%,3)
  1948. savefile(a$)
  1949.  Pass a full pathname. Saves the JPEG. It is done through OS_Find and OS_GBPB
  1950.  to prevent any potential problems with OS_File and memory access in dynamic
  1951.  areas on large memory machines (an OS bug).
  1952.  "OS_Find",&8F,a$ 
  1953.  openfh%
  1954.  "OS_GBPB",2,openfh%,picareab%,jpegleng% 
  1955.  ,,,a%
  1956.  "OS_Find",,openfh%:openfh%=0
  1957.  a%<>0 
  1958.  (1<<30)+1,"Unknown error whilst saving - the JPEG has not been saved correctly"
  1959.  "OS_File",18,a$,&C85
  1960. datasave
  1961.  Call on reception of a DataSave message. Replies with the appropriate
  1962.  DataSaveAck. Only does this if the window handle isn't SwiftJPEG's
  1963.  Save box (in which case we assume the user dropped the file back to
  1964.  abort the save).
  1965.  b%!20<>saveash% 
  1966. !b%=60
  1967. a%=b%!4
  1968. b%!4=task%
  1969. b%!12=b%!8
  1970. b%!16=2
  1971. b%!36=-1
  1972.  $(b%+44)="<Wimp$Scrap>"+
  1973.  "Wimp_SendMessage",17,b%,a%
  1974. datasaveack
  1975.  On receipt of a DataSaveAck message, reply with a DataLoad
  1976.  message, first saving the picture in the path specified
  1977.  by the message.
  1978. savefile(
  1979. textuntil((b%+44),33))
  1980. b%!12=0
  1981. b%!16=3
  1982.  "Wimp_SendMessage",17,b%,b%!4
  1983. dataloadack
  1984.  On receipt of a DataLoadAck message, the save has been
  1985.  completed, so write the full pathname (assuming it wasn't
  1986.  just <Wimp$Scrap>, in which case write 'Untitled') back
  1987.  into the save box, and update the title bar and jpegname$
  1988.  variable. Close any menus open, and close the Save As
  1989.  window (this ensures that wherever the Save As window
  1990.  came from, it will be closed at this point).
  1991. "jpegname$=
  1992. textuntil(b%+44,33)
  1993.  jpegname$="<Wimp$Scrap>" 
  1994.  jpegname$="ScrapFile"
  1995. $(sav%!140)=jpegname$
  1996. titlebarchange(displayh%,jpegname$+" ("+
  1997. (xpic%)+"x"+
  1998. (ypic%)+")")
  1999.  "Wimp_CreateMenu",,-1
  2000. !fr%=saveash%
  2001.  "Wimp_CloseWindow",,fr%
  2002.  -- Gamma alteration procedures
  2003. gammanormal
  2004.  !fbl% 
  2005.  fbl%!4 
  2006.  a%=0 
  2007. gar%?a%=pgr%?a%
  2008. gag%?a%=pgg%?a%
  2009. gab%?a%=pgb%?a%
  2010.  gammawrite%
  2011. gammablack
  2012.  !fbl% 
  2013.  fbl%!4 
  2014.  a%=0 
  2015. gar%?a%=0
  2016. gag%?a%=0
  2017. gab%?a%=0
  2018.  gammawrite%
  2019. gammafadeoutspecial
  2020.  a%,c%,d%
  2021.  fbl%!4 
  2022.  c%=fbl%!12 
  2023.  a%=0 
  2024. d%=a%*c%/(fbl%!12)
  2025. gar%?a%=d%
  2026. gag%?a%=d%
  2027. gab%?a%=d%
  2028.  gammawrite%
  2029.  "OS_Byte",121 
  2030.  d%=112 
  2031.  d%=16 
  2032.  c%=-1:
  2033. gammablack:
  2034.  d%=112 
  2035.  abortmul%=
  2036. waitfornokeys
  2037. gammafadeinflatten
  2038.  a%,c,d%,d,e%
  2039.  !fbl% 
  2040. e%=fbl%!8
  2041. d=c/e%
  2042.  a%=0 
  2043. gar%?a%=(pgr%?a%)*d
  2044. gag%?a%=(pgg%?a%)*d
  2045. gab%?a%=(pgb%?a%)*d
  2046.  gammawrite%
  2047.  "OS_Byte",121 
  2048.  d%=112 
  2049.  d%=16 
  2050.  c=(fbl%!8)+1:
  2051. gammanormal:
  2052.  d%=112 
  2053.  abortmul%=
  2054. c+=(1/c)*(16+(15-c)*(c<15))
  2055. waitfornokeys
  2056. gammafadeoutbycosine
  2057.  a%,c%,c,d%,e%
  2058.  fbl%!4 
  2059. e%=fbl%!12
  2060.  c%=0 
  2061.  e%*2
  2062. c=(1+
  2063. ((90/e%)*c%))/2
  2064.  a%=0 
  2065. gar%?a%=(pgr%?a%)*c
  2066. gag%?a%=(pgg%?a%)*c
  2067. gab%?a%=(pgb%?a%)*c
  2068.  gammawrite%
  2069.  "OS_Byte",121 
  2070.  d%=112 
  2071.  d%=16 
  2072.  c%=e%*2+1:
  2073. gammablack:
  2074.  d%=112 
  2075.  abortmul%=
  2076. waitfornokeys
  2077. gammaflashoutlinear
  2078.  a%,c%,c,d%
  2079.  fbl%!4 
  2080.  c%=fbl%!12 
  2081.  a%=0 
  2082. c=c%/(fbl%!12)
  2083. gar%?a%=255-(255-pgr%?a%)*c
  2084. gag%?a%=255-(255-pgg%?a%)*c
  2085. gab%?a%=255-(255-pgb%?a%)*c
  2086.  gammawrite%
  2087.  "OS_Byte",121 
  2088.  d%=112 
  2089.  d%=16 
  2090.  c%=-1:
  2091. gammablack:
  2092.  d%=112 
  2093.  abortmul%=
  2094.  d%<>112 
  2095.  d%<>16 
  2096. a%=fbl%!12
  2097. fbl%!12=16
  2098.  0,255,255,255
  2099. gammafadeoutspecial
  2100. fbl%!12=a%
  2101. waitfornokeys
  2102. gammaflashinbycosine
  2103.  a%,c%,c,d%
  2104.  !fbl% 
  2105.  c%=(fbl%!8)*2 
  2106.     - c=(1+
  2107. ((90/(fbl%!8))*c%))/2
  2108.  a%=0 
  2109. gar%?a%=255-(255-pgr%?a%)*c
  2110. gag%?a%=255-(255-pgg%?a%)*c
  2111. gab%?a%=255-(255-pgb%?a%)*c
  2112.  gammawrite%
  2113.  "OS_Byte",121 
  2114.  d%=112 
  2115.  d%=16 
  2116.  c%=-1:
  2117. gammanormal:
  2118.  d%=112 
  2119.  abortmul%=
  2120. waitfornokeys
  2121.  -- Miscellaneous procedures
  2122. readscreensize(
  2123.  a%,c%
  2124.  "OS_ReadModeVariable",-1,11 
  2125.  ,,d%
  2126.  "OS_ReadModeVariable",-1,12 
  2127.  ,,e%
  2128.     D    d%+=1
  2129.     E    e%+=1
  2130.  "OS_ReadModeVariable",-1,4 
  2131.  ,,a%
  2132.  "OS_ReadModeVariable",-1,5 
  2133.  ,,c%
  2134. d%=d%<<a%
  2135. e%=e%<<c%
  2136. compile(a%)
  2137.  c%,a$
  2138. datapntr%=a%
  2139. $(datapntr%+c%)=a$
  2140. c%+=(
  2141. (a$)+1)
  2142.  a$="*"
  2143. $(datapntr%+c%-1)=
  2144. (0)+"*"
  2145. read(
  2146.  a%,b$
  2147.     Z    b$=""
  2148. a%=?datapntr%
  2149.  a%>31 
  2150.  b$+=
  2151. datapntr%+=1
  2152.  a%<32
  2153.     `    a$=b$
  2154. waitforrelease
  2155.  a%,c%,d%
  2156.  "Hourglass_On"
  2157.  a%,c%,d%
  2158.  d%=0
  2159.  "Hourglass_Off"
  2160. makedragbox(a%,c%,a$)
  2161.  Pass a window and icon handle. Calculates the appropriate
  2162.  drag box and uses DragASprite to initiate a solid drag
  2163.  (DragASprite will use a dotted outline drag box if the
  2164.  relevant CMOS RAM bit says solid drags are turned off).
  2165.  d%,e%
  2166. !s%=a%
  2167.  "Wimp_GetWindowState",,s%
  2168. d%=s%!4-s%!20
  2169. e%=s%!16-s%!24
  2170. !s%=a%
  2171. s%!4=c%
  2172.  "Wimp_GetIconState",,s%
  2173. !fr%=a%
  2174. fr%!4=5
  2175. fr%!8=s%!8+d%
  2176. fr%!12=s%!12+e%
  2177. fr%!16=s%!16+d%
  2178. fr%!20=s%!20+e%
  2179. fr%!24=0
  2180. fr%!28=0
  2181. readscreensize(d%,e%)
  2182. fr%!32=d%
  2183. fr%!36=e%
  2184.  "DragASprite_Start",133,1,a$,fr%+8
  2185. dragging%=
  2186. dragended
  2187.  On receiving a reason code of 7 from Wimp_Poll, calling this procedure
  2188.  will send a DataSave message to whatever the pointer was over.
  2189.  "Wimp_GetPointerInfo",,s%
  2190. dragging%=
  2191.  (s%!12<>saveash%) 
  2192. textuntil(sav%!140,33)+
  2193. a$,".") 
  2194. a$,".")+1)
  2195. a$,".")=0
  2196. (a$) 
  2197.  4)<>0
  2198. !fr%=44+
  2199. fr%!4=task%
  2200. fr%!8=0
  2201. fr%!12=0
  2202. fr%!16=1
  2203. fr%!20=s%!12
  2204. fr%!24=s%!16
  2205. fr%!28=!s%
  2206. fr%!32=s%!4
  2207. fr%!36=30178
  2208. fr%!40=&C85
  2209. $(fr%+44)=a$
  2210.  "Wimp_SendMessage",17,fr%,s%!12,s%!16
  2211. dividezoom(
  2212.  Designed to take a 'Zoom box'-style pair
  2213.  of numbers (e.g. 1,1 as in 1:1 or 2,1 as
  2214.  in 2:1) and divide them down to the lowest
  2215.  possible number; i.e., 4:2 would become
  2216.  2:1 but 8:3 would stay 8:3. Nothing really
  2217.  more than aesthetics within the zoom box,
  2218.  but worth it all in all.
  2219.  So pass the two variables holding the
  2220.  numbers from the zoom box; the divided
  2221.  form is returned in the two variables.
  2222.  d%,e%
  2223.     d%=a%
  2224.     e%=c%
  2225.  d%<e% 
  2226.  d%,e%
  2227. d%=d% 
  2228.  d%=0
  2229. a%=a% 
  2230. c%=c% 
  2231. checkzoomfraction
  2232.  Looks in the zoom box and ensures the numbers
  2233.  within have been divided down as far as possible
  2234.  (see PROCdividezoom). Intended to be run before
  2235.  the zoom box is opened, for example by use of a
  2236.  MenuWarning message.
  2237.  a%,c%
  2238. textuntil(zow%!172,33))
  2239. textuntil(zow%!236,33))
  2240. dividezoom(a%,c%)
  2241. $(zow%!172)=
  2242. (a%):zoomm%=a%
  2243. $(zow%!236)=
  2244. (c%):zoomd%=c%
  2245. waitfornokeys
  2246.  "XOS_CLI","FX 15"
  2247.  "Hourglass_On"
  2248.  "OS_Byte",121 
  2249.  (a%=255)
  2250.  "Hourglass_Off"
  2251.  -- Memory Management
  2252. claimarea(a%,f%,a$,
  2253.  Pass the current and maxium size and name of the area, and
  2254.  two variables into which the area handle and base address
  2255.  are returned.
  2256.  Creates a Dynamic Area of the requested minimum size, or
  2257.  returns with 0 as the area handle and -1 as the base address
  2258.  if the claim fails.
  2259.  "XOS_DynamicArea",,-1,a%,-1,%10000000,f%,,,a$ 
  2260.  ,c%,,d%;e%
  2261.     d%=-1
  2262.  "XOS_ReadDynamicArea",c% 
  2263.  e%<a% 
  2264. removearea(c%):c%=0:d%=-1
  2265. removearea(a%)
  2266.  Pass a Dynamic Area handle.
  2267.  Removes the specified Dynamic Area, provided the handle was non-zero.
  2268.  You *should usually set the handle to zero after calling this
  2269.  procedure*, to flag it as closed.
  2270.  a%<>0 
  2271.  "XOS_DynamicArea",1,a%
  2272. changearea(a%,c%,
  2273.  Pass an area handle and size and a variable for a returned value. Sets
  2274.  the specified area to the specified size, returning the actual
  2275.  claimed size (it will be rounded to a page boundary) if the claim
  2276.  results in an area bigger than or equal to the amount specified, or
  2277.  returns -1 if the claim fails. This can be used to extend or shrink
  2278.  an area.
  2279.  "XOS_ReadDynamicArea",a% 
  2280.  "XOS_ChangeDynamicArea",a%,c%-e%
  2281.  "XOS_ReadDynamicArea",a% 
  2282.  e%<c% 
  2283.  d%=-1 
  2284.  d%=e%
  2285.  -- General WIMP functions
  2286. error
  2287. gammanormal
  2288.  "Hourglass_Smash"
  2289. closeopenfiles
  2290. restoremode
  2291. listfull%=0
  2292.  picareah%=0 
  2293.  displayh%<>-1 
  2294. open(displayh%) 
  2295.  !fr%=displayh%:
  2296.  "Wimp_CloseWindow",,fr%
  2297.  picareah%<>0 
  2298.  closedis% 
  2299.  !b%=displayh%:
  2300. closewindow
  2301.  (loaderro%<>0) 
  2302.  (lisareah%<>0) 
  2303.  loaderro%<lisareab% 
  2304. exit:
  2305.  "WARNING!"'loaderro%:
  2306. ?loaderro%=1
  2307. 2    !b%=
  2308.  allfatal%=
  2309.  !b%=(1<<30)+2
  2310.  !b% 
  2311.  (1<<30)+1
  2312. a$="Warning from SwiftJPEG"
  2313. 9-$(b%+4)=
  2314. $+". Click OK to continue."+
  2315. :    a%=17
  2316.  (1<<30)+2
  2317. <#a$="Fatal error from SwiftJPEG"
  2318. =_$(b%+4)=
  2319. $+" (encountered at line "+
  2320. +"). SwiftJPEG must quit; click CANCEL to exit."+
  2321. >    a%=18
  2322.  (1<<30)+3
  2323. @#a$="Information from SwiftJPEG"
  2324. $(b%+4)=
  2325. B    a%=17
  2326. a$="Error from SwiftJPEG"
  2327. $)<200 
  2328.  $(b%+4)=
  2329. $+" at line "+
  2330. )+": click OK to continue, CANCEL to quit program"+
  2331.  $(b%+4)=
  2332. F    a%=19
  2333.  "Wimp_ReportError",b%,a%,a$ 
  2334. a%=(a%=2)
  2335.  -- Icon handling functions
  2336. getopt(a%,c%)
  2337. !fr%=a%:fr%!4=c%
  2338.  "Wimp_GetIconState",,fr%
  2339. =((fr%!24) 
  2340.  (1<<21))<>0
  2341.  -- Menu handling functions
  2342. makemenu(x%,y%,e%)
  2343.  Before calling there must be two blocks to hold menu data
  2344.  and menu indirected data, called m% and mi%. You also need
  2345.  to have a list of DATA statements with the menu items in,
  2346.  terminated by a '*'. There must also be a block called s%
  2347.  which will be temporarily used for storing the DATA
  2348.  statements compiled into a form readable by PROCread.
  2349.  On calling, pass a pointer to the first free byte in an area
  2350.  to hold the menu data, and a pointer to the first free byte
  2351.  for the indirected data. The third thing to pass is flags -
  2352.  bit 0 of these should be reset or set; if it is set, it
  2353.  is assumed that the DATA statements should be compiled into
  2354.  s%. If the bit is unset it is assumed that this has been
  2355.  done already and this compilation stage is omitted.
  2356.  Before exiting m% and mi% are both incremented to point to
  2357.  the first free byte in each block after the new menu data has
  2358.  been added. This allows successive calls to FNmakemenu with
  2359.  m% and mi% passed every time as pointers, assuming that the
  2360.  calls are in order of the relevant DATA statements holding
  2361.  the menu contents. If you don't want m% and mi% to be changed,
  2362.  then set bit 1 of the flags. If x%<>m% or y%<>mi%, then m%
  2363.  or mi% are not changed regardless of this bit - it's only here
  2364.  to force m% or mi% to be left alone if they were passed as
  2365.  parameters. (You don't want to increment m% or mi% if m% or
  2366.  mi% weren't used to hold the menu definition or data!).
  2367.  The function returns the address of the menu definition (i.e.
  2368.  the value required by Wimp_CreateMenu).
  2369.  So for normal use, have a list of DATA statements with, say,
  2370.  each menu's data on a single line. Call with m% and mi% as
  2371.  pointers and %01 for the flags repeatedly.
  2372.  Note that *no* check is made to ensure m% and mi% are not
  2373.  incremented past the end of any space originally allocated
  2374.  to them.
  2375.  a%,c%,d%,f%,a$,b$,c$
  2376.  (e% 
  2377. compile(s%)
  2378.  x%=m% 
  2379.  f%=f% 
  2380.  y%=mi% 
  2381.  f%=f% 
  2382.     a%=x%
  2383. read(a$)
  2384. $(a%)=a$
  2385. a%?12=7
  2386. a%?13=2
  2387. a%?14=7
  2388. a%?15=0
  2389. a%!20=44
  2390. a%!24=0
  2391. (a$)-3
  2392. x%+=28
  2393. read(c$)
  2394.  c$<>"*" 
  2395. x%!8=&07000021
  2396.     !x%=0
  2397. c$,"@")
  2398.  ul% 
  2399. (c$)-ul%)
  2400. b$,"T") 
  2401.  !x%=!x% 
  2402. b$,"D") 
  2403.  !x%=!x% 
  2404. b$,"W") 
  2405. !x%=!x% 
  2406. read(a$)
  2407.  a$="mbu%" 
  2408.  buffer%=mbu%
  2409. read(a$)
  2410. buflen%=
  2411. b$,"M") 
  2412.  !x%=!x% 
  2413. c$,ul%-1)
  2414. c$>d% 
  2415. x%!4=-1
  2416. x%!8=&0700F121
  2417. x%!12=buffer%
  2418. x%!16=-1
  2419. x%!20=buflen%
  2420. $buffer%=c$
  2421.  c$<12 
  2422. x%!8=&07000021
  2423. $(x%+12)=c$
  2424. x%!8=&07000121
  2425. x%!12=y%
  2426. x%!16=-1
  2427. x%!20=
  2428. $y%=c$
  2429. x%+=24
  2430.  c$="*"
  2431. a%!16=d%*16+32
  2432. !(x%-24)=!(x%-24) 
  2433.  (e% 
  2434.  2)=0 
  2435.  (f% 
  2436.  m%=x%
  2437.  (f% 
  2438.  mi%=y%
  2439. readtick(a%,c%)
  2440.  (a%!(28+c%*24)) 
  2441.  -- File I/O functions
  2442. filetype(a$)
  2443.  a%,c%,d%
  2444.  "OS_File",17,a$ 
  2445.  c%,,a%
  2446.  c%<>1 
  2447.     d%=-2
  2448.  (a%>>>20)=&FFF 
  2449.  d%=(a%>>>8)
  2450. &FFF 
  2451.  d%=-1
  2452. filelength(a$)
  2453. filetype(a$)<>-2 
  2454.  "OS_File",5,a$ 
  2455.  ,,,,a% 
  2456.  a%=-1
  2457.  -- Miscellaneous functions
  2458. text(c%,d%,f%)
  2459.  Pass an address, a text string length, and
  2460.  a threshold. A string is returned of the specified
  2461.  length minus characters omitted which had an ASCII
  2462.  code LESS THAN the threshold. That is, pass 32 to
  2463.  include spaces and anything with higher codes, say.
  2464.  a%,b$
  2465.     b$=""
  2466.  a%=c% 
  2467.  c%+d%-1
  2468.  ?a%>=f% 
  2469.  b$=b$+
  2470. (?a%)
  2471. textuntil(c%,d%)
  2472.  Pass an address, and a threshold. A string
  2473.  is returned of consecutive bytes from the
  2474.  address. The function exits when a byte LESS
  2475.  THAN the threshold you specified.
  2476.  a%,b$
  2477.     b$=""
  2478.     a%=c%
  2479.  ?a%>=d% 
  2480.  b$=b$+
  2481. (?a%):a%+=1
  2482.  ?a%<d% 
  2483.  b$=255
  2484. upper(a$)
  2485.  Pass a string; returns the same string, all
  2486.  in upper case characters.
  2487.  a%,b$
  2488.     b$=""
  2489.  a%=1 
  2490. a$,a%,1)>="a" 
  2491. a$,a%,1)<="z" 
  2492.  b$+=
  2493. a$,a%,1))-32) 
  2494.  b$+=
  2495. a$,a%,1)
  2496. getword(a%)
  2497.  Pass a file handle; gets four bytes from the
  2498.  file handle, and returns their value as a 32-bit
  2499.  word.
  2500. #a%)+((
  2501. #a%)<<8)+((
  2502. #a%)<<16)+((
  2503. #a%)<<24)
  2504. buildmode(a$,a%)
  2505.  Pass a mode identifier string and an address. Builds
  2506.  an appropriate mode selector block at the address,
  2507.  returning -1 if there was a problem, 0 if everything
  2508.  was OK, or a mode number plus one if a mode number was
  2509.  present (done with 'plus one' so that mode 0 is
  2510.  possible and not interpreted externally as a sucessful
  2511.  compilation of a mode string!). So if you get 0, use
  2512.  the block you passed, if you get >0, use the returned
  2513.  value minus 1 directly.
  2514.  Multiple instances of any value are rejected with a
  2515.  return code of -1.
  2516.  c%,d%,e%,x%,y%,b$,c$
  2517. /    !a%=0
  2518. a%!4=-1
  2519. a%!8=-1
  2520. a%!12=-1
  2521. a%!16=-1
  2522. e%=a%+20
  2523. upper(a$)
  2524. a$,",")
  2525. a$,","),1)=" "
  2526. a$," "))
  2527. a$," ")
  2528. a$,c%-1)+
  2529. a$,c%+1)
  2530. (a$))=a$ 
  2531.  c%<0 
  2532.  c%=-1 
  2533.  c%+=1
  2534.  c%<=
  2535. Q    c%+=1
  2536. "XYCGEF",
  2537. a$,c%,1))=0) 
  2538.  (c%<=
  2539. (a$))
  2540. S    c%+=1
  2541. a$,c%,1)
  2542.  ((b$="E") 
  2543. "XY",
  2544. a$,c%+1,1))<>0)) 
  2545. "XY",b$)<>0) 
  2546. a$,c%-1,1)<>"E")) 
  2547. "CGF",b$)<>0) 
  2548.  (c%>
  2549. (a$))
  2550. "EX EY ",
  2551. a$,c%,2)+" ") 
  2552. a$,c%+2)) 
  2553. a$,c%+1))
  2554. a$,c%+1,3)
  2555.  "X":
  2556.  a%!4=-1 
  2557.  a%!4=d% 
  2558.  ?a%=1
  2559.  "Y":
  2560.  a%!8=-1 
  2561.  a%!8=d% 
  2562.  a%?1=1
  2563.  "C","G"
  2564.  a%!12=-1 
  2565.  2:a%!12=0
  2566.  4:a%!12=1
  2567.  c$="16M" 
  2568.  a%!12=5 
  2569.  a%!12=2
  2570.  (c$="32K") 
  2571.  (c$="32T") 
  2572.  a%!12=4
  2573.  256:a%!12=3
  2574.  (b$="G") 
  2575.  (a%!12>3) 
  2576.  a%!12=-1 
  2577.  !e%=0:e%!4=128:e%!8=3:e%!12=255:e%+=16
  2578. a%?2=1
  2579. a$,c%+1,1)="X" 
  2580. !e%=4:x%+=1
  2581.  d%<0 
  2582.  d%>3 
  2583.  x%+=1
  2584. !e%=5:y%+=1
  2585.  d%<0 
  2586.  d%>3 
  2587.  y%+=1
  2588. e%!4=d%
  2589. w    e%+=8
  2590.  "F":
  2591.  a%!16=-1 
  2592.  a%!16=d% 
  2593.  a%?3=1
  2594. !e%=-1
  2595.  (a%!4<1) 
  2596.  (a%!8<1) 
  2597.  (a%!12=-1) 
  2598.  (!a%>0) 
  2599.  (x%>1) 
  2600.  (y%>1) 
  2601.  c%=-1
  2602.  (a%!4>32767) 
  2603.  (a%!8>32767) 
  2604.  c%=-1
  2605.     !a%=1
  2606.