					;    _____         __
					;   /  _  \_______|  | ______  ______
					;  /  /_\  \_  __ \  |/ /  _ \/  ___/
					; /    |    \  | \/    <  <_> )___ \
					; \____|__  /__|  |__|_ \____/____  >
					;         \/           \/         \/
					; Keyframer (v1)
					; Grim/Arkos^Semilanceata
					;
					; Size 53 bytes
					;
					; API
					;  kf(IX) - process an eventlist object
					;
					; In your event list, you can use two special
					; functions to operate on the keyframer.
					;
					; Set the weyframer in wait state
					;  dw kf_cmd_wait, [value]
					; Load and execute a new eventlist
					;  dw kf_cmd_load, [address of an eventlist]
					;
					; IMPORTANT NOTE
					; The routines you will call from the keyframer
					; MUST preserve HL or you will mess with the
					; eventlist pointer!
					
					
_keyframer_idx_waitcounter		equ 0
_keyframer_idx_eventlist_pointer	equ 2

					; Process an eventlist object
					;
					; Input
					;  IX=EventList object address
keyframer:
					inc (ix+_keyframer_idx_waitcounter+0)
					ret nz
					inc (ix+_keyframer_idx_waitcounter+1)
					ret nz
					
					ld h,(ix+_keyframer_idx_eventlist_pointer+1)
					ld l,(ix+_keyframer_idx_eventlist_pointer+0)
					
					push ix
					
					; Execute events from the list
_keyframer_loop				ld de,_keyframer_var_call
					ldi
					ldi
					call 0
_keyframer_var_call			equ $-2
					jr _keyframer_loop

; ******************************************************************************
; Keyframer event-list commands
; ******************************************************************************

			
kf_cmd_wait				; do not RET into the kf_loop
					pop af
					; reset wait counter
					pop ix
					ld a,(hl)	; low
					ld (ix+_keyframer_idx_waitcounter+0),a
					inc hl
					ld a,(hl)	; hi
					ld (ix+_keyframer_idx_waitcounter+1),a
					inc hl
					; save eventlist pointer
					ld (ix+_keyframer_idx_eventlist_pointer+1),h
					ld (ix+_keyframer_idx_eventlist_pointer+0),l
					; return to the calling program
					ret
					
					; load and execute a new event-list
kf_cmd_load				ld a,(hl)
					inc hl
					ld h,(hl)
					ld l,a
					ret
					
kf_cmd_exit
					pop af
					pop af
					pop af
					call kf_cmd_load
					jp (hl)
					
					
