;
; ---------------------------------------------------------------
; Application definitions
; ---------------------------------------------------------------
;
; ------ cell structure --------
;
cell_next	equ	0
cell_prev	equ	2
cell_use	equ	4
cell_code	equ	5
cell_code2	equ	6
cell_code3	equ	7
cell_data	equ	8
cell_datalen	equ	8
cell_size	equ	cell_data+cell_datalen
;
; ------ cell pool dimensions ----
;
cellpoolnum	equ	128	; 128 cells in pool
cellpoolsize	equ	cellpoolnum*cell_size
;
; ------ cell queue structure ------
;
cque_head	equ 	0	; index of head entry pointer 
cque_tail	equ	2       ; index of tail entry pointer
cque_cbsize	equ	4	; cell queue control block size is 4 bytes
;
cque_num	equ	8	; 8 cell queues
;
; ------ key matrix definitions
;
keyrownum	equ	8	; 8 rows
keycolnum	equ	8	; 8 keys per row (= 1 byte)
;
keydrive	equ	0FF07H
keyreturn	equ	0FF07H
;
; ------ relay driver definitions ----
;
relbase		equ	0FF00H
;
reldrivnum	equ	4	; 4 byte-wide driver ports
;
; --- PULSER definitions and macros --------------------------
;
; --- PULSER states
;
psta_wevt	EQU	0
psta_delay	EQU	1
;
; PULSER events
;
pev_bron	EQU	1	; BI-relay ON
pev_broff	EQU	2	; BI-relay OFF
pev_brtog	EQU	3	; BI-relay TOGle
pev_mron	EQU	4	; MO-relay ON
pev_mroff	EQU	5	; MO-relay OFF
pev_mrtog	EQU	6	; MO-relay TOGgle
pev_mbon	EQU	7	; memorize BI-relay ON
pev_mboff	EQU	8	; memorize BI-relay OFF
pev_mmon	EQU	9	; memorize MO-relay ON
pev_mmoff	EQU	10	; memorize MO-relay OFF
;
; PULSER program commands
;
pc_end		EQU	0	; end of sequence
pc_c1be		EQU	8	; compare P1 to <BP1>, if equal, branch to <WP2>
pc_sdc		EQU	9       ; set delay counter to <WP1>
pc_nst		EQU	10	; set new state to <PP1> 
pc_delay	EQU	11	; delay for <BP1>*10ms
pc_wevt		EQU	12	; wait for event in queue 1
pc_plon		EQU	13	; set port line <P1> to ON
pc_ploff	EQU	14	; set port line <P1> to OFF
pc_bra		EQU	15	; branch to <WP1>
pc_cbro		EQU	16	; calc. BI-relay ON  line number from <P2> to <P1>
pc_cbrf         EQU	17      ; calc. BI-relay OFF line number from <P2> to <P1>
pc_mbro		EQU	18	; memorize BI-relay <P2> as ON
pc_mbrf		EQU	19	; memorize BI-relay <P2> as OFF
pc_mmro		EQU	20	; memorize MO-relay <P2> as ON
pc_mmrf		EQU	21	; memorize MO-relay <P2> as OFF
pc_cbtl		EQU	22	; calc BI-relay <P2> toggle line to <P2>
pc_mtog		EQU	23	; toggle MO-relay <P2>
pc_plon2	EQU	24	; set port line <P2> to ON
pc_ploff2	EQU	25	; set port line <P2> to OFF
;
; PULSER command macros
;
%*DEFINE(P_END)(
	DB	pc_end)
;
%*DEFINE(P_C1BE(COMPARE_VALUE,BRANCH_DESTINATION))(
	DB	pc_c1be,%COMPARE_VALUE
	DW	%BRANCH_DESTINATION)
;
%*DEFINE(P_SDC(DELAY_VALUE_MS))(
	DB	pc_sdc,%DELAY_VALUE_MS/10)
;
%*DEFINE(P_NST(NEW_STATE))(
	DB	pc_nst,%NEW_STATE)
;
%*DEFINE(P_DELAY(DELAY_VALUE_MS))(
	DB	pc_delay,%DELAY_VALUE_MS/10)
;
%*DEFINE(P_WEVT)(
	DB	pc_wevt)
;
%*DEFINE(P_PLON)(
	DB	pc_plon)
;
%*DEFINE(P_PLOFF)(
	DB	pc_ploff)
;
%*DEFINE(P_BRA(BRANCH_DESTINATION))(
	DB	pc_bra
	DW	%BRANCH_DESTINATION)
;
%*DEFINE(P_CBRO)(
	DB	pc_cbro)
;
%*DEFINE(P_CBRF)(
	DB	pc_cbrf)
;
%*DEFINE(P_MBRO)(
	DB	pc_mbro)
;
%*DEFINE(P_MBRF)(
	DB	pc_mbrf)
;
%*DEFINE(P_MMRO)(
	DB	pc_mmro)
;
%*DEFINE(P_MMRF)(
	DB	pc_mmrf)
;
%*DEFINE(P_CBTL)(
	DB	pc_cbtl)
;
%*DEFINE(P_MTOG)(
	DB	pc_mtog)
;
%*DEFINE(P_PLON2)(
	DB	pc_plon2)
;
%*DEFINE(P_PLOFF2)(
	DB	pc_ploff2)
;
; ------ basic tick timer in timer 0 ---------------------------
;
; timer 0 period is calculated as follows:
;
; reload := -((time_period in us * quartz frequency in MHz) / 12 )
;
timer_reload    equ     -9216   ; timer 0 for 10 ms tick at 11.0592 MHz    <===
;
t0divisor	equ	25	; generate 250ms from 10 ms cycle
;
; --- TASKER definitions ----------------------------------------
;
tsktra_evt	EQU	0	; offset to event
tsktra_sev	EQU	1	; offset to subevent
tsktra_act	EQU	2	; offset to action
tsktra_sac	EQU	3	; offset to sub-action
tsktrasiz	EQU	4	; size of one task transition entry
;
tsktblsiz	EQU	256*tsktrasiz	; allocate for 256 transitions
