; Script to parse list of movies (next month) on Sky Premier
; this month.
;
; No longer broadcast on Sky teletext, so we load a saved copy from disc
; and, pretty much, fake it from there...
;
; Basically, the active code is the same as 'MovieMonth'. Only, the way of
; getting the frames (in the first place) is different.
;
; This /could/ be written using less variables, but as we have 16 variables
; handy, might as well make best use of them!

script "MovieTest"

cache_loaddirectory("<Teletext$Dir>.frames.nextmonth")
cache_loaddirectory("<Teletext$Dir>.frames.nextmonth2")

selectframe(236)
set A to status(frames)
selectframe(237)
set B to status(frames)
selectframe(238)
set C to status(frames)
selectframe(239)
set D to status(frames)
selectframe(240)
set E to status(frames)

; F = Frame counter
; G = Line counter
; H = Page counter

set H to 236
.processpage
  set F to 1
  .processframe
    ; Choose a frame
    selectframes(H, F)
    set G to 1
    ; Remove the rubbish at the top of the frame
    .omittop
      omitline(G)
      G++
      if(G [ 8) go("omittop")

    ; In the middle, if the line does not start with
    ; green text, remove it.
    set J to 0
    .omitparse
      ; 130 = Text colour green, and keep following dates/times
      set I to char(1, G)
      if (I = 130) set J to 1
      if (I = 131) set J to 0
      if (I = 134) set J to 0
      if (I ! 130) if(J ! 1) omitline(G)
      G++
      if(G [ 21) go("omitparse")

    ; Remove the rubbish at the end
    .omitend
      omitline(G)
      G++
      if(G [ 25) go("omitend")

    ; Finished updating, store the frame
    storeframe()

    ; Increment the frame, see if now next page
    F++

    if(H = 236) if(F [ A) go("processframe")
    if(H = 237) if(F [ B) go("processframe")
    if(H = 238) if(F [ C) go("processframe")
    if(H = 239) if(F [ D) go("processframe")
    if(H = 240) if(F [ E) go("processframe")

  H++
  if(H [ 240) go("processpage")

; Open a file, and copy the frames to it as ASCII
filewrite("<Teletext$Temp>.movguide")
; Type 2 = ASCII
appendframes(236, 2)
appendframes(237, 2)
appendframes(238, 2)
appendframes(239, 2)
appendframes(240, 2)
fileclose()
filetype("<Teletext$Temp>.movguide", &FFF)

; Call the OS to execute a command
oscall("%Filer_Run <Teletext$Temp>.movguide")

lvar()

; done!
terminate()
