;; firmware functions we use in this example
.kl_new_fast_ticker equ &bce0
.mc_set_mode        equ &bd1c
.mc_set_inks        equ &bd25
.mc_wait_flyback    equ &bd19
.kl_new_frame_fly   equ &bcd7
.kl_init_event equ &bcef

;; this code must be in the range &4000-&bfff
;; to work correctly.
;;
;; assemble then from BASIC:
;;
;; call &8000
org &8000


;; wait for a screen refresh
;; we do this to synchronise our effect
call mc_wait_flyback

ld a,6
ld (ticker_counter),a
ld hl,colours
ld (current_colour_pointer),hl

;; install interrupt
ld hl,ticker_event_block
ld b,%10000010
ld c,&80
ld de,ticker_function
call kl_new_fast_ticker

;; return to BASIC
ret

;; this is initialised by
;; the firmware; holds runtime state of ticker interrupt
.ticker_event_block
defs 10

;; this is the function called each 1/300th of a second
.ticker_function
push af
push hl

;; The 1/300th of a second interrupt effectively splits
;; the screen into 6 sections of equal height. Each section
;; spans the entire width of the screen.
;;
;; We want to ensure that the effect is stationary so we reset
;; every 6 calls of this function.
ld a,(ticker_counter)
dec a
ld (ticker_counter),a
or a
jr nz,ticker_function2
ld a,6
ld (ticker_counter),a
ld hl,colours
ld (current_colour_pointer),hl

.ticker_function2

;; setting the colours will occur immeditately.

;; get pointer to current colours
ld de,(current_colour_pointer)
call mc_set_inks

;; update colours pointer
ld hl,(current_colour_pointer)
ld bc,17
add hl,bc
ld (current_colour_pointer),hl


pop af
pop hl
ret

.ticker_counter defb 0

.current_colour_pointer defw colours

;; The 1/300th of a second interrupt effectively splits
;; the screen into 6 sections of equal height. Each section
;; spans the entire width of the screen.
;;
;; video mode for each of the 6 sections of the screen.

.colours

;; colours for 1st section
;; border colour, followed by pen 0, pen 1 up to pen 15
;; NOTE: These are hardware colour numbers
defb &04,&04,&0a,&13,&0c,&0b,&14,&15,&0d,&06,&1e,&1f,&07,&12,&19,&04,&17
;; colours for 2nd section
defb &03,&04,&0a,&13,&0c,&0b,&14,&15,&0d,&06,&1e,&1f,&07,&12,&19,&04,&17
;; colours for 3rd section
defb &11,&04,&0a,&13,&0c,&0b,&14,&15,&0d,&06,&1e,&1f,&07,&12,&19,&04,&17
;; colours for 4th section
defb &0c,&04,&0a,&13,&0c,&0b,&14,&15,&0d,&06,&1e,&1f,&07,&12,&19,&04,&17
;; colours for 5th section
defb &12,&04,&0a,&13,&0c,&0b,&14,&15,&0d,&06,&1e,&1f,&07,&12,&19,&04,&17
;; colours for 6th section
defb &1f,&04,&0a,&13,&0c,&0b,&14,&15,&0d,&06,&1e,&1f,&07,&12,&19,&04,&17