; Script to fetch list US singles chart, on VivaPlus.
;
; Clocked at 1 minute 28 seconds on 2003/01/02, at 19:54h CET.
;
; Much of that, however, was waiting on fetching frames.
;
; Basically:
;   Get pages 142 and 143,
;   remove some stuff,
;   then output...
;   :-)
;

script "US singles"



; ************
; **  INIT  **
; ************

; Select satellite decoder (assume tuned to VivaPlus)
channel(5)

; check we are receiving
getframe(100)
set A to status(pagefound)
if (A ! 1) error("Timed out trying to fetch page - is satellite decoder switched on?")



; *****************
; **  FIRST SET  **
; *****************

getframes(142)
set A to status(frames)

; now remove the top/left/bottom
.processpage_first
  set B to 1
  .processframe_first
    ; Choose a frame
    selectframes(142, B)
    ; Remove the top of the frame
    set C to 1
    .omittop_first
      omitline(C)
      C++
      if(C [ 4) go("omittop_first")

    ; Remove the left hand side
    poll_message("Blanking left")
    poll_disable()
    set M to 5
    .omitleft_first
        smartclear(M)
        M++
      if(M [ 18) go("omitleft_first")
    ; remove "USA"
    setchar(4, 18, 32)
    setchar(5, 18, 32)
    setchar(6, 18, 32)
    poll_enable()


    ; Remove the end of the frame
    set C to 19
    .omitend_first
      omitline(C)
      C++
      if(C [ 25) go("omitend_first")

    ; Finished updating, store the frame
    storeframe()

    ; Increment the frame, see if now next page
    B++
    if(B [ A) go("processframe_first")



; ******************
; **  SECOND SET  **
; ******************

getframes(143)
set A to status(frames)

; now remove the top/left/bottom
.processpage_second
  set B to 1
  .processframe_second
    ; Choose a frame
    selectframes(143, B)
    ; Remove the top of the frame
    set C to 1
    .omittop_second
      omitline(C)
      C++
      if(C [ 4) go("omittop_second")

    ; Remove the left hand side
    poll_message("Blanking left (please be patient)")
    poll_disable()
    set M to 5
    .omitleft_second
        smartclear(M)
        M++
      if(M [ 18) go("omitleft_second")
    ; remove "USA"
    setchar(4, 18, 32)
    setchar(5, 18, 32)
    setchar(6, 18, 32)
    poll_enable()

    ; Remove the end of the frame
    set C to 19
    .omitend_second
      omitline(C)
      C++
      if(C [ 25) go("omitend_second")

    ; Finished updating, store the frame
    storeframe()

    ; Increment the frame, see if now next page
    B++
    if(B [ A) go("processframe_second")



; ******************
; **  OUTPUT SET  **
; ******************

; Open file, and copy frames to it as ASCII
filewrite("<Teletext$Temp>.us-charts")

; header
filewritestring("US singles chart")
filewritestring("================")
filewritebyte(10)

....; Type 2 = ASCII
set B to 1
.outputframes_first
  appendgivenframe(142, B, 2)
  B++
  if(B [ A) go("outputframes_first")

set B to 1
.outputframes_second
  appendgivenframe(143, B, 2)
  filewritebyte(10)
  filewritebyte(10)
  B++
  if(B [ A) go("outputframes_second")


fileclose()
filetype("<Teletext$Temp>.us-charts", &FFF)

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


; done!
terminate()

