  ;------------------------------------------;
  ; BASIC-Extension   ColorCycle  SMmagic'88 ;
  ;------------------------------------------;
  ; Syntax: AddressRoutine WINDOW(7),from,to ;
  ; from=Start  color; tos=End color         ;
  ; Color always "from" --> "to"             ;
  ; from < to: Rotation up                   ;
  ; from > to: Rotation down                 ;
  ;------------------------------------------;
Cycle:    MOVEM.L D0-A6,-(SP) ;Reserve register from Stack
          MOVE.L 4,A6         ;get ExecBase from A6
          LEA GFXNAME,A1      ;Library-Name at A1
          MOVEQ #0,D0         ;Version is same
          JSR -552(A6)        ;OpenLibrary call
          TST.L D0            ;Test, is Base available
          BEQ.S Exit          ;When not, thend End
          MOVE.L D0,A6        ;GfxBase at A6
          MOVE.L 64(SP),A0    ;WindowBase attended to
          MOVE.L 46(A0),A0    ;ScreenBase determined
          ADD.L #44,A0        ;ViewPort of Screens in A0
          MOVE.L 4(A0),A1     ;ColorTable to A1
          MOVE.L 4(A1),A1     ;ColorMap determined
          LEA CTab,A2         ;User Buffer to A2
          MOVEQ #15,D0        ;15 Longs (32 Words)
CopyCT:  MOVE.L (A1)+,(A2)+  ;ColorMap copied          DBRA D0,CopyCT      ;(when not changed otherwize
          MOVEM.L 68(SP),D0-D1 ;get start- and End color
          ANDI.W #31,D0       ;should it be more than 31
          ANDI.W #31,D1       ;ditto
          LSL.B #1,D0         ;*2 (use as offset)
          LSL.B #1,D1         ;ditto
          LEA CTab,A1         ;Address of our buffer
          MOVE.W (A1,D1.W),D2 ;reserve last color
          CMP.B D0,D1         ;determine rotation direction
          BEQ.S ClLib         ;bboth colors same ???
          BGT.S Up            ;colors rotate up
Down:    MOVE.W 2(A1,D1.W),(A1,D1.W) ;colors then down          ADDQ.B #2,D1        ;increment Offset
          CMP.B D0,D1         ;End reached?
          BNE.S Down          ;no? then next color
          BRA.S SetLC         ;close
Up:      MOVE.W -2(A1,D1.W),(A1,D1.W) ;color downward          SUBQ.B #2,D1        ;decrement  Offset
          CMP.B D0,D1         ;bottom reached?
          BNE.S Up            ;no? then next color
SetLC:   MOVE.W D2,(A1,D1.W) ;color reserved          MOVEQ #32,D0        ;32 cloors set
          JSR -192(A6)        ;LoadRGB4 (a0=VP,a1=Ctab,d0)
ClLib:   MOVE.L A6,A1        ;GfxBase at A1          MOVE.L 4,A6         ;get  ExecBase
          JSR -414(A6)        ;Library closed
Exit:    MOVEM.L (SP)+,D0-A6 ;Register from Stack          RTS                 ;end
GFXNAME: DC.B "graphics.library",0,0 ;Library-NameCTab:    DS.W 32                     ;32 Words buffer          END

