; EuroConv

channel(5)
poll_now()                    ; let it take effect
poll_now()                    ; before channel check

.channelcheck
  channelid(A)
  if (A ! &804F) message("Please set satellite receiver to CNN.")
  if (A ! &804F) go("channelcheck")


; First we want to get the pound/euro spot (asking) rate.
; At 2003/05/12, the -Euro rate was 1.3920 and the
; Euro- rate was 0.6211. Eagle-eyes observers may
; notice a rather large discrepancy, as the -Euro
; rate, worked in reverse, comes out to be 0.7165!
; So we look for each induhvidual rate, for a "worst
; case" (and thus, more reliable) result.
getframe(734)                 ; any will do
find(B,"EUR",7)
if (B = 0) error("Can't find GBP rate")
readvalue(R,15,7)             ; pound ask in R

; Now we look for the Australian dollar rate.
getframe(733)
.getaustralia
  find(B,"AUD",12)
  if (B = 0) getframe(733)
  if (B = 0) go("getaustralia")
readvalue(T,15,12)            ; australian $ in T

; Now get the dollar/euro spot (asking) rate.
; At 2003/05/12, the $-Euro is 1.1569 and the Euro-$
; is given as 1.1569. I can only imagine both are
; quoted in the Euro-$ direction!

find(B,"USD",7)
if (B = 0) error("Can't find US$ rate")
readvalue(S,15,7)             ; dollar ask in S

; turn off polling, now, to speed it up a little
poll_nomessages()
poll_disable()

; remove mosaic characters and page count
set A to 1
.clearloop
  setchar(A,4,32)
  A++
  if (A [ 11) go("clearloop")
setchar(35,4,32)
setchar(36,4,32)
setchar(37,4,32)
setchar(38,4,32)

; open file
fileupdate("<Teletext$Temp>.EuroConv")

; the header
appendline(4,2)
filewritebyte(10)
filewritebyte(10)
filewritestring("Euro:Pound rate  : ")
filewritefloat(R,3,4)
filewritestring(" (")
div(V,1,R)
filewritefloat(V,1,4)
filewritestring(")")
filewritebyte(10)
filewritestring("Dollar:Euro rate : ")
filewritefloat(S,3,4)
filewritebyte(10)
filewritestring("Euro:Austr$ rate : ")
filewritefloat(T,3,4)
filewritebyte(10)
filewritebyte(10)

filewritestring("Euro    Pound   Dollar  Australia$")
filewritebyte(10)
filewritestring("----------------------------------")
filewritebyte(10)

; the conversion loop
set L to 5
.convloop
  div(X,L,R)                  ; Y = euro->pound
  mul(Y,L,S)                  ; X = euro->dollar
  mul(Z,L,T)                  ; Z = euro->aus$

  filewritevar(L,3)
  filewritestring("     ")
  filewritefloat(X,2,2)
  filewritestring("   ")
  filewritefloat(Y,3,2)
  filewritestring("  ")
  filewritefloat(Z,3,2)
  filewritebyte(10)

  add(L,5)
  if (L [ 100) go("convloop")

.finish
filewritebyte(10)
filewritebyte(10)
fileclose()

; re-pollify
poll_enable

; reopen "the usual" windows
getframe(100)                 ; force it back to 'index'
showviewer()
showcontrols()
poll_now()                    ; extra poll for windowopens

; ensure file is Text, then run file (loads into !Edit (etc))
filetype("<Teletext$Temp>.EuroConv", &FFF)
oscall("Filer_Run <Teletext$Temp>.EuroConv")
poll_now()                    ; poll, so file has a chance to load
pushkey(&1AE)                 ; Ctrl-cursordown

; we're done
terminate()
