--
--	Scrolling text example for Occade
--	Copyright (C) 2009 Adam Sampson
--
--	This program is free software; you can redistribute it and/or
--	modify it under the terms of the GNU General Public License as
--	published by the Free Software Foundation, either version 2 of the
--	License, or (at your option) any later version.
--
--	This program is distributed in the hope that it will be useful,
--	but WITHOUT ANY WARRANTY; without even the implied warranty of
--	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
--	General Public License for more details.
--
--	You should have received a copy of the GNU General Public License
--	along with this program.  If not, see
--	<http://www.gnu.org/licenses/>.
--

#INCLUDE "occade.module"

--{{{  PROC send.text
PROC send.text (CHAN BYTE c!)
  WHILE TRUE
    SEQ ch = 'A' FOR 26
      SEQ
        c ! BYTE ch
        occade.delay (100000)
:
--}}}

--{{{  PROC display.text
PROC display.text (SHARED OCCADE! occade, CHAN BYTE c?)
  VAL INT LEN IS 20:
  INITIAL [LEN]BYTE buf IS [i = 0 FOR LEN | ' ']:
  OCCADE.SPRITE! sprite:
  SEQ
    --{{{  start the sprite
    occade.start.sprite (occade, sprite, -1)
    sprite[req] ! load.text; buf; "images/font10x20.png"
    sprite[req] ! move; 320; 240; TRUE
    sprite[req] ! visible; TRUE
    --}}}
    WHILE TRUE
      BYTE ch:
      SEQ
        --{{{  1 - wait for new byte char to arrive on channel
        c ? ch
        --}}}
        --{{{  2 - add this new byte char to the start of my array
        SEQ i = LEN - 1 FOR LEN - 1 STEP -1
          buf[i] := buf[i - 1]
        buf[0] := ch
        --}}}
        --{{{  3 - update the sprite
        sprite[req] ! load.text; buf; "images/font10x20.png"
        --}}}
:
--}}}

--{{{  PROC main
PROC main ()
  SHARED OCCADE! occade:
  INITIAL OCCADE.PARAMS params IS occade.default.params:
  SEQ
    params[width] := 640
    params[height] := 480
    occade.start (occade, params, "Scrolly text demo")

    CHAN BYTE c:
    PAR
      send.text (c!)
      display.text (occade, c?)
:
--}}}
