; STREDA - scrolling text on two seven-segment displays
; IL2PCC 8.9 / THREAD Tick
; Frames: [  ] [ S] [St] [tr] [rE] [Ed] [dA] [A ]
; 7seg bits: bit0=a, bit1=b, ... bit6=g, active high
THREAD Tick
SHEET Main {
    DEFINE INT BLANK = 0
    DEFINE INT S = 109
    DEFINE INT T = 120
    DEFINE INT R = 80
    DEFINE INT E = 121
    DEFINE INT D = 94
    DEFINE INT A = 119

    CALL PulseGen ScrollClock
    CALL Counter Position
    CALL Comparator EndCheck
    CALL ISwitch LeftTable
    CALL ISwitch RightTable
    CALL Int2Bits LeftBits
    CALL Int2Bits RightBits
    CALL Segment LeftDisplay
    CALL Segment RightDisplay
    CALL PulseGen ScanClock
    CALL ISwitch DigitMux
    CALL Int2Bits BusBits
    CALL 8xDO Display
    CALL Value PositionMonitor

    SET ScrollClock.Act 1
    SET ScrollClock.TOn 1
    SET ScrollClock.TOff 49
    ScrollClock.Out Position.Tr
    SET Position.St 1
    Position.Y EndCheck.A
    SET EndCheck.B 7
    EndCheck.AGtB Position.Rst
    Position.Y PositionMonitor.X

    SET LeftTable.INPUT_COUNT 8
    SET RightTable.INPUT_COUNT 8
    Position.Y LeftTable.IN1
    Position.Y RightTable.IN1

    SET LeftTable.IN2 BLANK
    SET LeftTable.IN3 BLANK
    SET LeftTable.IN4 S
    SET LeftTable.IN5 T
    SET LeftTable.IN6 R
    SET LeftTable.IN7 E
    SET LeftTable.IN8 D
    SET LeftTable.IN9 A

    SET RightTable.IN2 BLANK
    SET RightTable.IN3 S
    SET RightTable.IN4 T
    SET RightTable.IN5 R
    SET RightTable.IN6 E
    SET RightTable.IN7 D
    SET RightTable.IN8 A
    SET RightTable.IN9 BLANK

    LeftTable.Y LeftBits.X
    RightTable.Y RightBits.X
    LeftBits.OUT0 LeftDisplay.IN1
    LeftBits.OUT1 LeftDisplay.IN2
    LeftBits.OUT2 LeftDisplay.IN3
    LeftBits.OUT3 LeftDisplay.IN4
    LeftBits.OUT4 LeftDisplay.IN5
    LeftBits.OUT5 LeftDisplay.IN6
    LeftBits.OUT6 LeftDisplay.IN7
    RightBits.OUT0 RightDisplay.IN1
    RightBits.OUT1 RightDisplay.IN2
    RightBits.OUT2 RightDisplay.IN3
    RightBits.OUT3 RightDisplay.IN4
    RightBits.OUT4 RightDisplay.IN5
    RightBits.OUT5 RightDisplay.IN6
    RightBits.OUT6 RightDisplay.IN7

    SET ScanClock.Act 1
    SET ScanClock.TOn 1
    SET ScanClock.TOff 1
    SET DigitMux.INPUT_COUNT 2
    ScanClock.Out DigitMux.IN1
    LeftTable.Y DigitMux.IN2
    RightTable.Y DigitMux.IN3
    DigitMux.Y BusBits.X

    SET Display.ALL_PINS 1
    SET Display.IN0 1
    BusBits.OUT3 Display.IN3
    BusBits.OUT4 Display.IN4
    BusBits.OUT5 Display.IN8
    BusBits.OUT6 Display.IN9
    ScanClock.Out Display.IN10
    BusBits.OUT0 Display.IN12
    BusBits.OUT1 Display.IN13
    BusBits.OUT2 Display.IN14
}