			; File rcsc_sx28_16.inc
			; Retargetable Concurrent Small C compiler
			; startup code and runtime routines 16bit
			; all runtime labels must start with a letter
			; so not to interfere with user labels that
			; always start with underscore

device			SX28,oschs1,turbo,stackx,optionx
irc_cal			IRC_SLOW
id			'RCSCSX28'
reset			reset_entry
freq			20_000_000
RESONATOR		equ	20	; set to freq/1_000_000

;-----------------------------------------------------------------------------------------
; uart constants (example)
;-----------------------------------------------------------------------------------------

if RESONATOR=75
;uartfs=384*1200=460800
;intperiod=75000000/460800=163
;384*1200=4*96*1200=4*48*2400=4*24*4800=4*12*9600=4*6*19200=4*4*28800=4*3*38400=4*2*57600
uartfs			euq	460800	; uart's basic frequency 384 * 1200 = 460800
intperiod		equ	163	; used as seed for uart baud rate.
endif

if RESONATOR=50
;uartfs=256*1200=307200
;intperiod=50000000/307200=163
;256*1200=4*64*1200=4*32*2400=4*16*4800=4*8*9600=4*4*19200=4*2*38400
uartfs			equ	307200	; uart's basic frequency 256 * 1200 = 307200
intperiod		equ	163	; used as seed for uart baud rate.
endif

if RESONATOR=20
;uartfs=128*1200=153600
;intperiod=20000000/153600=130
;128*1200=4*32*1200=4*16*2400=4*8*4800=4*4*9600=4*2*19200
uartfs			equ	153600	; uart's basic frequency 128 * 1200 = 153600
intperiod		equ	130	; used as seed for uart baud rate.
endif

THREADS			equ	4	; Each thread is executed once every 4 interrupts

;The following baudrates are available

	uart_baud0	equ	1200
	uart_baud1	equ	2400
	uart_baud2	equ	4800
	uart_baud3	equ	9600
	uart_baud4	equ	19200
	uart_baud5	equ	38400	;only for resonator=50 and resonator=75
	uart_baud6	equ	57600	;only for resonator=75

	uart_divide0	equ	uartfs / (uart_baud0 * THREADS)
        uart_StDelay0 	equ	uart_divide0 + (uart_divide0 / 2)

	uart_divide1	equ	uartfs / (uart_baud1 * THREADS)
        uart_StDelay1 	equ	uart_divide1 + (uart_divide1 / 2)

	uart_divide2	equ	uartfs / (uart_baud2 * THREADS)
        uart_StDelay2 	equ	uart_divide2 + (uart_divide2 / 2)

	uart_divide3	equ	uartfs / (uart_baud3 * THREADS)
        uart_StDelay3 	equ	uart_divide3 + (uart_divide3 / 2)

	uart_divide4	equ	uartfs / (uart_baud4 * THREADS)
        uart_StDelay4 	equ	uart_divide4 + (uart_divide4 / 2)

	uart_divide5	equ	uartfs / (uart_baud5 * THREADS)
        uart_StDelay5 	equ	uart_divide5 + (uart_divide5 / 2)

	uart_divide6	equ	uartfs / (uart_baud6 * THREADS)
        uart_StDelay6 	equ	uart_divide6 + (uart_divide6 / 2)

;-----------------------------------------------------------------------------------------

RA_latch		equ	%00000000	;port A output latch init 1=high 0=low
RA_tris			equ	%11111111	;port A direction register 1=input 0=output
RA_plp			equ	%00000000	;port A pull up register 1=off 0=on
RA_lvl			equ	%11111111	;port A level register 1=ttl 0=cmos

RB_latch		equ	%00000000	;port B output latch 1=high 0=low
RB_tris			equ	%11111111	;port B direction register 1=input 0=output
RB_plp			equ	%00000000	;port B pull up register 1=off 0=on
RB_lvl			equ	%00000000	;port B level register 1=ttl 0=cmos
RB_st			equ	%11111111	;port B schmitt trigger register 1=off 0=on
RB_wken			equ	%11111111	;port B wake up enable register 1=off 0=on
RB_wked			equ	%11111111	;port B wake up edge register 1=neg 0=pos

RC_latch		equ	%00000000	;port C output latch 1=high 0=low
RC_tris			equ	%11111111	;port C direction register 1=input 0=output
RC_plp			equ	%00000000	;port C pull up register 1=off 0=on
RC_lvl			equ	%11111111	;port C level register 1=ttl 0=cmos
RC_st			equ	%11111111	;port C schmitt trigger register 1=off 0=on

			;Leave globals $08 and $09 for RD and RE (SX48/52)
			;fsr is used to access ram
			;8086 registers are mapped in global ram and CPU bank
			;ram banks 0-7 are user ram: logical byte addresses 0-120 (121-127 are regs)
			;during interrupt AX, BX, CX and DX are saved in the FIFO
USERBYTES		equ	121		;number of bytes for users
AL			equ	$0A		;primary register lo byte
AH			equ	$0B		;primary register hi byte
BL			equ	$0C		;secondary register lo byte
BH			equ	$0D		;secondary register hi byte
temp			equ	$0E		;byte for memory transfer
tempsave		equ	$0F		;save temp here during interrupt
CPU			equ	$F0		;bank CPU
CPU_STAT		equ	$F9		;status byte for CPU
						;bit0: set if inside ISR
						;other  bits reserved
CL			equ	$FA		;auxiliary register #1 lo byte
CH			equ	$FB		;auxiliary register #1 hi byte
DL			equ	$FC		;auxiliary register #2 lo byte
DH			equ	$FD		;auxiliary register #2 hi byte
BP			equ	$FE		;base pointer register
SP			equ	$FF		;stack pointer register
						;SP points to last byte written
						;so dec SP before push: this way interrupt
						;cannot overwrite last written value

M_WKED			equ	$0A		;values for mode register
M_WKEN			equ	$0B
M_ST			equ	$0C
M_LVL			equ	$0D
M_PLP			equ	$0E
M_TRIS			equ	$0F

			; option register constants
RTCC_ON			equ	%10000000	;Enables RTCC at address $01 (RTW hi)
						;*WREG at address $01 (RTW lo) by default
RTCC_ID			equ	%01000000	;Disables RTCC edge interrupt (RTE_IE hi)
						;*RTCC edge interrupt (RTE_IE lo) enabled by default
RTCC_INC_EXT		equ	%00100000	;Sets RTCC increment on RTCC pin transition (RTS hi)
						;*RTCC increment on internal instruction (RTS lo) is defalut
RTCC_FE			equ	%00010000	;Sets RTCC to increment on falling edge (RTE_ES hi)
						;*RTCC to increment on rising edge (RTE_ES lo) is default
RTCC_PS_ON		equ	%00000000	;Assigns prescaler to RTCC (PSA lo)
RTCC_PS_OFF		equ	%00001000	;Assigns prescaler to WDT (PSA hi)
RTCC_PS_000		equ	%00000000	;RTCC = 1:2, WDT = 1:1
RTCC_PS_001		equ	%00000001	;RTCC = 1:4, WDT = 1:2
RTCC_PS_010		equ	%00000010	;RTCC = 1:8, WDT = 1:4
RTCC_PS_011		equ	%00000011	;RTCC = 1:16, WDT = 1:8
RTCC_PS_100		equ	%00000100	;RTCC = 1:32, WDT = 1:16
RTCC_PS_101		equ	%00000101	;RTCC = 1:64, WDT = 1:32
RTCC_PS_110		equ	%00000110	;RTCC = 1:128, WDT = 1:64
RTCC_PS_111		equ	%00000111	;RTCC = 1:256, WDT = 1:128

		;logical address of next byte to allocate
		;start at -18 to allocate predefined named globals
		;unsigned char _RADIR,_RBDIR,_RCDIR,_RDDIR,_REDIR
		;unsigned char _RA,_RB,_RC,_RD,_RE
		;unsigned int _RBCDIR,_RDEDIR
		;unsigned int _RBC,_RDE
		;the GNU macro assembler M4 maps these globals to port registers
logic			=	-18		;keep track of logical address
physic			=	-34		;keep track of physical address

			; define byte storage macro for logical addressing
			; usage:	label	equ	logic
			;	 	a_label	equ	physic
			;			dfs	number_of_bytes
dfs			macro	1
  local1 = \1
  rept local1
    if logic = USERBYTES
      error ("out of ram memory")
    else
      logic = logic + 1
      physic = (physic + 1)|10h
    endif
  endr
endm

			; define word storage macro for logical addressing
			; usage:	label	equ	logic
			;		a_label	equ	physic
			;			dfw	number_of_words
dfw			macro	1
  local2 = \1
  rept local2
    if logic = USERBYTES
      error ("out of ram memory")
    else
      logic = logic + 1
      physic = (physic+1)|10h
    endif
    if logic = USERBYTES
      error ("out of ram memory")
    else
      logic = logic + 1
      physic = (physic+1)|10h
    endif
  endr
endm

joff = 0		; keep track of calculated offsets for jump macros

			; do jump on not zero macro
			; usage:	dojnz label
dojnz			macro	address
  myAddress = address-joff
  if myAddress/$200 == $/$200
    if myAddress > $
      joff = joff+1
      myAddress = myAddress-1
    endif
  endif
  if myAddress/$200 == $/$200
	jnz	??\1-joff
  else
	jnz	@??\1-joff
  endif
endm

			; do jump on zero macro
			; usage:	dojz label
dojz			macro	address
  myAddress = address-joff
  if myAddress/$200 == $/$200
    if myAddress > $
      joff = joff+1
      myAddress = myAddress-1
    endif
  endif
  if myAddress/$200 == $/$200
	jz	??\1-joff
  else
	jz	@??\1-joff
  endif
endm

			; do jump macro
			; usage:	dojmp label
dojmp			macro	address
  myAddress = address-joff
  if myAddress/$200 == $/$200
    if myAddress > $
      joff = joff+1
      myAddress = myAddress-1
    endif
  endif
  if myAddress/$200 == $/$200
	jmp	??\1-joff
  else
	jmp	@??\1-joff
  endif
endm

			; secret instruction fifo
fifo			macro
			dw	$47
endm

			; secret instruction pushW
pushW			macro
			dw	$48
endm

			; secret instruction pushST
pushST			macro
			dw	$49
endm

			; secret instruction pushFSR
pushFSR			macro
			dw	$4A
endm

			; secret instruction pushPC
pushPC			macro
			dw	$4B
endm

			; secret instruction popW
popW			macro
			dw	$4C
endm

			; secret instruction popST
popST			macro
			dw	$4D
endm

			; secret instruction popFSR
popFSR			macro
			dw	$4E
endm

			; secret instruction popPC
popPC			macro
			dw	$4F
endm

			;//////////  CODE START  //////////
			org	$0

interrupt		jmp	sxintrpt
reset_entry		jmp	@init

;P-code entries called from main code
add12			jmp	x_add12		; add sr to pr
add21			jmp	x_add21		; add pr to sr
addbpn			jmp	x_addbpn	; add n to memory byte through sr pointer
addwpn			jmp	x_addwpn	; add n to memory word through sr pointer
aneg1			jmp	x_aneg1		; arithmetically negate pr
asl12			jmp	x_asl12		; arithmetically shift left sr by pr into pr
asr12			jmp	x_asr12		; arithmetically shift right sr by pr into pr
prnul			jmp	x_prnul		; test if pr == 0
prpos			jmp	x_prpos		; test if pr > 0
dbl1			jmp	x_dbl1		; double pr
dbl2			jmp	x_dbl2		; double sr
decbp			jmp	x_decbp		; decrement memory byte through sr pointer
decwp			jmp	x_decwp		; decrement memory word through sr pointer
div12			jmp	x_div12		; divide pr by sr
div12u			jmp	x_div12u	; divide pr by sr (unsigned)
mod12			jmp	x_mod12		; modulo pr by sr
mod12u			jmp	x_mod12u	; modulo pr by sr (unsigned)
move21			jmp	x_move21	; move pr to sr
enter			jmp	x_enter		; set stack frame upon function entry
eq12			jmp	x_eq12		; set pr true if (sr == pr)
ge12			jmp	x_ge12		; set pr true if (sr >= pr)
ge12u			jmp	x_ge12u		; set pr true if (sr >= pr) (unsigned)
getb1m			jmp	x_getb1m	; get byte into pr from memory through label
getb1mu			jmp	x_getb1mu	; get unsigned byte into pr from memory through label
getb1p			jmp	x_getb1p	; get byte into pr from memory through sr pointer
getb1pu			jmp	x_getb1pu	; get unsigned byte into pr from memory through sr pointer
getb1s			jmp	x_getb1s	; get byte into pr from stack
getb1su			jmp	x_getb1su	; get unsigned byte into pr from stack
getw1p			jmp	x_getw1p	; get word into pr from memory through sr pointer
getw1s			jmp	x_getw1s	; get word into pr from stack
getw1m			jmp	x_getw1m	; get word into pr from memory through label
getw2p			jmp	x_getw2p	; get word into sr from memory through sr pointer
getw2s			jmp	x_getw2s	; get word into sr from stack
getw2m			jmp	x_getw2m	; get word into sr from memory through label
lneg1			jmp	x_lneg1		; logical negation of pr
gt12			jmp	x_gt12		; set pr true if (sr > pr)
gt12u			jmp	x_gt12u		; set pr true if (sr > pr) (unsigned)
incbp			jmp	x_incbp		; increment byte in memory through sr pointer
incwp			jmp	x_incwp		; increment word in memory through sr pointer
le12			jmp	x_le12		; set pr true if (sr <= pr)
le12u			jmp	x_le12u		; set pr true if (sr <= pr) (unsigned)
lt12			jmp	x_lt12		; set pr true if (sr < pr)
lt12u			jmp	x_lt12u		; set pr true if (sr < pr) (unsigned)
ne12			jmp	x_ne12		; set pr true if (sr != pr)
mul12			jmp	x_mul12		; multiply pr by sr
mul12u			jmp	x_mul12u	; multiply pr by sr (unsigned)
pop2			jmp	x_pop2		; pop stack into sr
push1			jmp	x_push1		; push pr onto stack
push2			jmp	x_push2		; push sr onto stack
pushm			jmp	x_pushm		; push word from memory through label
pushp			jmp	x_pushp		; push word from memory through sr pointer
pushs			jmp	x_pushs		; push word from stack
putbp1			jmp	x_putbp1	; put pr byte into memory through sr pointer
putwm1			jmp	x_putwm1	; put pr word into memory through label
putwp1			jmp	x_putwp1	; put pr word into memory through sr pointer
return			jmp	x_return	; restore stack and return
sub12			jmp	x_sub12		; subtract sr from pr
subbpn			jmp	x_subbpn	; subtract n from memory byte through sr pointer
subwpn			jmp	x_subwpn	; subtract n from memory word through sr pointer
swap12			jmp	x_swap12	; swap pr and sr
swap1s			jmp	x_swap1s	; swap pr and top of stack
xor12			jmp	x_xor12		; xor pr with sr
and12			jmp	x_and12		; and pr with sr
or12			jmp	x_or12		; or pr with sr
callf			jmp	x_callf		; call function through pr
switch			jmp	x_switch	; scan switch table to find case
;P-code entries not called from main code
add1n			jmp	x_add1n		; add n to pr
add2n			jmp	x_add2n		; add n to sr
;addbmn			jmp	x_addbmn	; add n to memory byte through label
;addwmn			jmp	x_addwmn	; add n to memory word through label
;putbmn			jmp	x_putbmn	; put n into memory byte through label
;putbm1			jmp	x_putbm1	; put pr byte into memory through label
;putwmn			jmp	x_putwmn	; put n into memory word through label
;sub1n			jmp	x_sub1n		; subtract n from pr
;subbmn			jmp	x_subbmn	; subtract n from memory byte through label
;subwmn			jmp	x_subwmn	; subtract n from memory word through label
;not P-code entries
pushDX			jmp	x_pushDX	; push DX to stack

sxintrpt
			mov	tempsave,temp		;save temp
			call	dofifo			;save AX,BX,CX,DX
			;at this point CPU regs are accessible
			setb	CPU_STAT.0		;mark ISR active
			;do call _sxintrpt using C call convention
			clr	CL			;no args
			;no need to set target and return address
			jmp	x_callf			;call sxintrpt
intrpt_ret
			call	dofifo			;restore AX,BX,CX,DX
			clrb	CPU_STAT.0		;mark ISR inactive
			mov	temp,tempsave		;restore temp
			mov	w,#(-intperiod)&255
			retiw				;return from interrupt

	; save current AX, BX, CX and DX into fifo
	; and load AX, BX, CX and DX from fifo
	; called from isr
	; returns with CPU bank accessable
dofifo
			mov	fsr,#AL
			call	savefour	;save AX and BX
			mov	fsr,#CL
savefour
			mov	temp,#4
savefour_1
			mov	w,indf		;get register
			fifo			;save in fifo
			mov	indf,w		;load register with value from fifo
			inc	fsr
			dec	temp
			jnz	savefour_1
			retp

	; double pr
x_dbl1
			clc
	; rotate AX to the left
rlAX
			rl	AL
			rl	AH
			retp
	; double sr
x_dbl2
			clc
	; rotate BX to the left
rlBX
			rl	BL
			rl	BH
			retp

;*********************   RAM ACCESS ROUTINES   *********************

	; get word from memory, CL=address, word returned in DH:DL
getword
			call	getbyte
			mov	DL,w
			inc	CL
			call	getbyte
			mov	DH,w
			dec	CL		;restore CL
			retp
	; get byte from memory, CL=address, byte returned in w
getbyte
			mov	fsr,CL		; setfsr, CL = logical address 0-127 for ram banks 0 to 7
			and	w,#$70
			add	fsr,w
			add	fsr,#$10	; bank 0 is at $10
			mov	w,indf
			jmp	sysret
	; push pr onto stack
x_push1
			call	move41
	; push DX to stack
x_pushDX
			sub	SP,#2		;decrement SP before write
			mov	CL,SP
	; put word into memory
	; entry: CL=address, DH:DL=word
putword
			mov	w,DL
			call	putbyte
			inc	CL
			mov	w,DH
			call	putbyte
			dec	CL		;restore CL
			retp
	; put pr byte into memory through sr pointer
	; entry: AL=n
x_putbp1
			mov	CL,BL
	; put pr byte into memory through label
	; entry: CL=address, AL=n
x_putbm1
			mov	w,AL
	; put byte into memory
	; entry: CL=address, w=byte (uses temp)
putbyte
			mov	temp,w
			mov	fsr,CL		; setfsr, CL = logical address 0-127 for ram banks 0 to 7
			and	w,#$70
			add	fsr,w
			add	fsr,#$10	; bank 0 is at $10
			mov	indf,temp
	; memory access exit point
sysret
			bank	CPU		; always return with CPU bank accessable
			retp

;*******************************************************************

	; increment CX
incCX
			inc	CL
			snz
			inc	CH
			retp
	; do iread with CX=addr
x_iread
			mov	m,CH
			mov	w,CL
			iread
			retp
	;compare AX to BX
compare
			clr	temp
			mov	w,BL
			mov	w,AL-w
			sz
			setb	temp.0		;BX != AX
			mov	w,BH
			sc			;skip if BL <= AL
			mov	w,++BH
			mov	w,AH-w
			sz
			setb	temp.0
			sc			;skip if BH <= AH
			inc	temp
			mov	w,temp
			test	w		;set Z if BX == AX
			retp			;BX == AX (w=0), BX < AX (w=1), BX > AX (w=2)
	; negate DH:DL
negDX
			not	DL
			not	DH
	; increment DH:DL
incDX
			inc	DL
			snz
			inc	DH
			retp
	;set pr to false
x_false
			clr	AL
			clr	AH
			retp
	;set pr to true
x_true
			call	x_false
			inc	AL
			retp

;*******************************************************************

	; pop top of stack into DX
popDX
			mov	CL,SP
			call	getword
			add	SP,#2		;increment SP after read
			retp
	; move pr to DX
move41
			mov	DL,AL
			mov	DH,AH
			retp
	; move sr to DX
move42
			mov	DL,BL
			mov	DH,BH
			retp
	; swap pr and top of stack
x_swap1s
			call	popDX
			call	push1
	; move DX to pr
move14
			mov	AL,DL
			mov	AH,DH
			retp
	; swap pr and sr
x_swap12
			call	push1
			call	move12
	; pop stack into sr
x_pop2
			call	popDX
	; move DX to sr
move24
			mov	BL,DL
			mov	BH,DH
			retp
	; move sr to pr
move12
			mov	AL,BL
			mov	AH,BH
			retp
	; move pr to sr
x_move21
			mov	BL,AL
			mov	BH,AH
			retp

;*******************************************************************

	; get byte into pr from stack
	; entry: CL=offset to BP
x_getb1s
			call	getb1su
			jmp	x_getb1_1
	; get byte into pr from memory through sr pointer
	; entry: CL=offset to sr pointer
x_getb1p
			call	getb1pu
			jmp	x_getb1_1
	; get byte into pr from memory through label
	; entry: CL=address
x_getb1m
			call	getb1mu
x_getb1_1
			snb	AL.7
			dec	AH
			retp
	; get unsigned byte into pr from stack
	; entry: CL=pffset to BP
x_getb1su
			add	CL,BP
			jmp	x_getb1mu
	; get unsigned byte into pr from memory through sr pointer
	; entry: CL=offset to sr pointer
x_getb1pu
			add	CL,BL
	; get unsigned byte into pr from memory through label
	; entry: CL=address
x_getb1mu
			call	getbyte
x_getbl_2
			mov	AL,w
			clr	AH
			retp
	; get word into pr from stack
	; entry: CL=offset to BP
x_getw1s
			add	CL,BP
			jmp	x_getw1m
	; get word into pr from memory through sr pointer
	; entry: CL=offset to sr pointer
x_getw1p
			add	CL,BL
	; get word into pr from memory through label
	; entry: CL = address
x_getw1m
			call	getbyte
			mov	AL,w
			inc	CL
			call	getbyte
			mov	AH,w
			retp
	; get word into sr from stack
	; entry: CL=oddset to BP
x_getw2s
			add	CL,BP
			jmp	x_getw2m
	; get word into sr from memory through sr pointer
	; entry: CL=offset to sr pointer
x_getw2p
			add	CL,BL
	; get word into sr from memory through label
x_getw2m
			call	getbyte
			mov	BL,w
			inc	CL
			call	getbyte
			mov	BH,w
			retp

;*******************************************************************

;	; put n into memory byte through label
;	; entry: CL=address, DL=n
;x_putbmn
;			mov	w,DL
;			jmp	putbyte
	; put pr word into memory through sr pointer
	; entry: AH:AL=n
x_putwp1
			mov	CL,BL
	; put pr word into memory through label
	; entry: CL=address, AH:AL=n
x_putwm1
			mov	w,AL
			call	putbyte
			inc	CL
			mov	w,AH
			jmp	putbyte
;	; put n into memory word through label
;	; entry: CL=address, DH:DL=n
;x_putwmn
;			mov	w,DL
;			call	putbyte
;			inc	CL
;			mov	w,DH
;			jmp	putbyte

;*******************************************************************

	; push sr onto stack
x_push2
			call	move42
			jmp	x_pushDX
	; push word from stack
	; entry: CL=offset to BP
x_pushs
			add	CL,BP
			jmp	x_pushm
	; push word from memory through sr pointer
	; entry: CL=offset to sr pointer
x_pushp
			add	CL,BL
	; push word from memory through label
	; entry: CL=address
x_pushm
			call	getword
			jmp	x_pushDX

;*******************************************************************

	; these compares do not touch AX and BX

	; test if pr == 0
x_prnul
			mov	w,AL
			or	w,AH
			retp			; Z set if pr == 0
	; test if pr > 0
x_prpos
			call	prnul
			snz
			retp			; Z set (pr==0)
			snb	AH.7
			setb	Z		; Z set (pr<0)
			retp			; Z set if pr <= 0

;*******************************************************************

	; logical negation of pr
x_lneg1
			call	prnul
			jmp	x_lt12u_2
	; set pr true if (sr != pr)
x_ne12
			call	compare
			jz	x_false
			jmp	x_true
	; set pr true if (sr == pr)
x_eq12
			call	compare
			jmp	x_lt12u_2
	; set pr true if (sr >= pr)
x_ge12
	; set pr true if (sr >= pr) (unsigned)
x_ge12u
			call	compare
			jz	x_true
			jmp	x_gt12u_1
	; set pr true if (sr > pr)
x_gt12
	; set pr true if (sr > pr) (unsigned)
x_gt12u
			call	compare
x_gt12u_1
			xor	w,#2
			jmp	x_lt12u_2
	; set pr true if (sr <= pr)
x_le12
	; set pr true if (sr <= pr) (unsigned)
x_le12u
			call	compare
			jz	x_true
			jmp	x_lt12u_1
	; set pr true if (sr < pr)
x_lt12
	; set pr true if (sr < pr) (unsigned)
x_lt12u
			call	compare
x_lt12u_1
			xor	w,#1
x_lt12u_2
			jz	x_true
			jmp	x_false

;*******************************************************************

	; add sr to pr
x_add12
			call	move42
	; add n to pr
	; entry: DH:DL=n
x_add1n
			add	AL,DL
			snc
			inc	AH
			add	AH,DH
			retp
	; add pr to sr
x_add21
			call	move41
	; add n to sr
	; entry: DH:DL=n
x_add2n
			add	BL,DL
			snc
			inc	BH
			add	BH,DH
			retp
	; subtract n from memory byte through sr pointer
x_subbpn
			call	negDX
	; add n to memory byte through sr pointer
	; entry: DL=n
x_addbpn
			mov	CL,BL
	; add n to memory byte through label
	; entry: CL=address, DL=n
x_addbmn
			call	getbyte			;get memory byte
			add	w,DL			;result in w
			jmp	putbyte			;result to memory
	; subtract n from memory word through sr pointer
x_subwpn
			call	negDX
	; add n to memory word through sr pointer
	; entry: DH:DL=n
x_addwpn
			mov	CL,BL
	; add n to memory word through label
	; entry: CL=address, DH:DL=n
x_addwmn
			call	push2			;save BX
			call	move24			;move DX to BX
			call	getword			;get memory word in DX
			call	add2n			;BX=BX+DX
			call	move42			;result in DX
			call	putword			;result to memory
			jmp	pop2			;restore BX
	; subtract sr from pr
x_sub12
			call	move42
	; subtract n from pr
x_sub1n
			call	negDX			;negate DX -> m-DX == m+(-DX)
			jmp	add1n
;	; subtract n from memory byte through label
;	; entry: CL=addr, DL=n
;x_subbmn
;			call	negDX
;			jmp	x_addbmn
;	; subtract n from memory word through label
;	; entry: CL=address, DH:DL=n
;x_subwmn
;			call	negDX
;			jmp	x_addwmn

;*******************************************************************

	; decrement memory byte through sr pointer
x_decbp
			mov	DL,#$FF
			jmp	x_addbpn
	; decrement memory word through sr pointer
x_decwp
			mov	DL,#$FF
			mov	DH,#$FF
			jmp	x_addwpn
	; increment byte in memory through sr pointer
x_incbp
			mov	DL,#1
			jmp	x_addbpn
	; increment word in memory through sr pointer
x_incwp
			mov	DL,#1
			clr	DH
			jmp	x_addwpn

;*******************************************************************

	; xor pr with sr
x_xor12
			xor	AL,BL
			xor	AH,BH
			retp
	; and pr with sr
x_and12
			and	AL,BL
			and	AH,BH
			retp
	; or pr with sr
x_or12
			or	AL,BL
			or	AH,BH
			retp

;*******************************************************************

	; arithmetically negate pr
x_aneg1
			call	move41
			call	negDX
			jmp	move14
	; arithmetically shift left sr by pr into pr
x_asl12
			mov	DL,AL
			call	move12
x_asl12_1
			call	x_dbl1
			dec	DL
			jnz	x_asl12_1
			retp
	; arithmetically shift right sr by pr into pr
x_asr12
			mov	DL,AL
			call	move12
x_asr12_1
			clc
			rr	AH
			rr	AL
			dec	DL
			jnz	x_asr12_1
			retp

;*******************************************************************

	; set stack frame upon function entry
x_enter
			mov	DL,BP
			call	pushDX		;push BP
			mov	BP,SP
			retp
	; restore stack and return
x_return
			mov	SP,BP
			call	popDX			;pop BP
			mov	BP,DL
			call	popDX			;pop return address
			jb	CPU_STAT.0,intrpt_ret	;we are in ISR
			jmp	x_callf_1

	; scan swtch table
	;entry: AH:AL=compare value, CH:CL=table address
x_switch
			call	x_iread		;load jump address for case
			mov	DL,w
			mov	w,m
			mov	DH,w
			or	w,DL
			jz	x_switch_2	;call addr == 0 then do default
			call	incCX
			call	x_iread		;read case value lo byte
			call	incCX
			xor	w,AL		;compare wirh compare value lo byte
			jnz	x_switch_1
			call	x_iread		;read case value hi byte
			xor	w,AH
			jz	x_switch_3	;if match then do addr
x_switch_1
			call	incCX
			jmp	x_switch	;next case
x_switch_2
			call	incCX		;now CH:CL points to default jmp after table
			mov	DL,CL
			mov	DH,CH
x_switch_3
			call	move14
			mov	m,#$0F		;restore M register

	; call to AH:AL
x_callf
			;DH:DL holds return address (which is NOT on call stack since we jump to here)
			;CL holds argument count upon function entry, AX holds return value upon function exit
			;so neither CL or AX must be touched
			call	pushDX			;save return address (popped by x_return)
			call	move41			;move target address into DX
			jb	CPU_STAT.0,@_sxintrpt	;we are in ISR
x_callf_1
			pushST			;align shadow stack
			pushW
			mov	w,fsr		;save fsr state
			pushFSR
			mov	m,DH		;get our dest into m:w
			mov	w,DL
			pushPC			;push m:w onto shadow stack
			reti			;pops all registers and jump to dest

;*******************************************************************

	;Inputs:
	;   Dividend - CH:AH:AL
	;   Divisor  - BH:BL
	;Temporary:
	;   Counter  - CL
	;   Remainder- DH:DL
	;Output:
	;   Quotient - CH:AH:AL
	;   Remainder- DH:DL

	; divide pr by sr
x_div12
	; divide pr by sr (unsigned)
	; Source from sxlist.com: by Nikolai Golovchenko
x_div12u
			clr	CH
			clr	DH
			clr	DL
			mov	CL,#24
x_div12u_1
			call	rlAX		;shift left divider to pass next bit to remainder
						;and shift in next bit of result
			rl	CH

			rl	DL		;shift carry into remainder
			rl	DH

			rl	CL		;save carry in counter

			mov	w,BL		;substract divisor from remainder
			sub	DL,w
			mov	w,BH
			sb	C
			movsz	w,++BL
			mov	w,DH-w		;keep that byte in W untill we make sure about borrow

			snb	C		;if no borrow
			setb	CL.0		;set bit 0 of counter (saved carry)

			snb	CL.0		;if no borrow
			jmp	x_div12u_2	;jump

			mov	w,BL		;restore remainder if borrow
			add	DL,w
			mov	w,DH		;read high byte of remainder to W
        					;to not change it by next instruction
x_div12u_2
			mov	DH,w		;store high byte of remainder
			clrb	C		;copy bit 0 to carry
			rr	CL		;and restore counter
			decsz	CL		;decrement counter
			jmp	x_div12u_1	;and repeat loop if not zero

			call	rlAX		;shift in last bit of result
			rl	CH
			retp

	; modulo pr by sr
x_mod12
	; modulo pr by sr (unsigned)
x_mod12u
			call	div12u
			jmp	move14

x_mul12
	; multiply pr by sr (unsigned)
x_mul12u
		; Adapted sxlist.com source
		; Clyde Smith-Stubbs
		; HI-TECH Software,
		; The main multiply thingo. Called with one operand in AX and the
		; other in BX. It really does not matter which one is where.
		; The multiplier is copied to CX, and the product built up in
		; AX where it belongs
			mov	CL,AL
			mov	CH,AH
			call	x_false		;initialize product
x_mul12u_1
			clc			;clear carry again
			rr	CH		;shift multiplier down
			rr	CL
			sc			;skip if multiplier lsb not set
			jmp	x_mul12u_2
			call	add12		;add multiplicand to product
x_mul12u_2
			call	x_dbl2
			mov	w,CL
			or	w,CH
			jnz	x_mul12u_1	;not all done yet
			retp

;*******************************************************************

			org	200h

_cscinit
			retp

	; program initialization
init
			mov	m,#M_WKED	; point mode to WKED
			mov	!rb,#RB_wked
			mov	m,#M_WKEN	; point mode to WKEN
			mov	!rb,#RB_wken
			mov	m,#M_ST		; point mode to ST
			mov	!rc,#RC_st
			mov	!rb,#RB_st
			mov	m,#M_LVL	; point mode to LVL
			mov	!rc,#RC_lvl
			mov	!rb,#RB_lvl
			mov	!ra,#RA_lvl
			mov	m,#M_PLP	; point mode to PLP
			mov	!rc,#RC_plp
			mov	!rb,#RB_plp
			mov	!ra,#RA_plp
			mov	rc,#RC_latch	; init latches
			mov	rb,#RB_latch
			mov	ra,#RA_latch
			mov	m,#M_TRIS	; point mode to TRIS");
			mov	!rc,#RC_tris
			mov	!rb,#RB_tris
			mov	!ra,#RA_tris
	;clear all ram
			mov	fsr,#$08
:zero_global
			clr	indf
			inc	fsr
			cjne	fsr,#$10,:zero_global
:zero_ram
			clr	indf
			inc	fsr
			jz	:zero_end
			setb	fsr.4
			jmp	:zero_ram
:zero_end
			bank	CPU
			mov	SP,#USERBYTES	;set variables stack to highest ram available
	;setup option register
			mov	w,#RTCC_PS_001	;RTCC prescaler 1:4
			mov	!option,w
			jmp	@_main
user						;here starts user code



 	;CODE SEGMENT PUBLIC
	;Retargetable Concurrent Small C compiler
	;CODE ENDS
 	;DATA SEGMENT PUBLIC
	;PUBLIC _RADIR


_RADIR	equ	logic
L__RADIR	equ	physic
	dfs	1

	;PUBLIC _RBDIR


_RBDIR	equ	logic
L__RBDIR	equ	physic
	dfs	1

	;PUBLIC _RCDIR


_RCDIR	equ	logic
L__RCDIR	equ	physic
	dfs	1

	;PUBLIC _RDDIR


_RDDIR	equ	logic
L__RDDIR	equ	physic
	dfs	1

	;PUBLIC _REDIR


_REDIR	equ	logic
L__REDIR	equ	physic
	dfs	1

	;PUBLIC _RA


_RA	equ	logic
L__RA	equ	physic
	dfs	1

	;PUBLIC _RB


_RB	equ	logic
L__RB	equ	physic
	dfs	1

	;PUBLIC _RC


_RC	equ	logic
L__RC	equ	physic
	dfs	1

	;PUBLIC _RD


_RD	equ	logic
L__RD	equ	physic
	dfs	1

	;PUBLIC _RE


_RE	equ	logic
L__RE	equ	physic
	dfs	1

	;PUBLIC _RBCDIR


_RBCDIR	equ	logic
L__RBCDIR	equ	physic
H__RBCDIR	equ	(physic+1)|10h
	dfw	1

	;PUBLIC _RDEDIR


_RDEDIR	equ	logic
L__RDEDIR	equ	physic
H__RDEDIR	equ	(physic+1)|10h
	dfw	1

	;PUBLIC _RBC


_RBC	equ	logic
L__RBC	equ	physic
H__RBC	equ	(physic+1)|10h
	dfw	1

	;PUBLIC _RDE


_RDE	equ	logic
L__RDE	equ	physic
H__RDE	equ	(physic+1)|10h
	dfw	1

	;PUBLIC _ca


_ca	equ	logic
L__ca	equ	physic
	dfs	32

	;PUBLIC _i


_i	equ	logic
L__i	equ	physic
H__i	equ	(physic+1)|10h
	dfw	1

	;PUBLIC _j


_j	equ	logic
L__j	equ	physic
H__j	equ	(physic+1)|10h
	dfw	1

	;PUBLIC _ia


_ia	equ	logic
L__ia	equ	physic
H__ia	equ	(physic+1)|10h
	dfw	10

	;DATA ENDS
 	;CODE SEGMENT PUBLIC
	;PUBLIC _sxintrpt
_sxintrpt
;;ENTER
	call	@enter
;;RETURN(0)
	jmp	@return
	;PUBLIC _main
_main
;;ENTER
	call	@enter
;;CSCINIT
	call	@_cscinit
;;ADDSP(-17)
	add	SP,#-17&255
;;POINT2s(-1)
	mov	BL,#-1&255
	add	BL,BP
	clr	BH
;;GETw1n(65)
	mov	AL,#65&255
	mov	AH,#65>>8
;;PUTbp1
	call	@putbp1
;;PUT_m_COMMAn(_RBC , 4660)
	mov	RB,#4660&255
	mov	RC,#4660>>8
;;GETw1m(_RBC)
	mov	AL,RB
	mov	AH,RC
;;PUTwm1
	mov	RD,AL
	mov	RE,AH
;;GETb1mu(_RA)
	mov	AL,RA
	clr	AH
;;SUB1n(5)
	sub	AL,#5&255
	sc
	dec	AH
	sub	AH,#5>>8
;;PUTbm1(_RA)
	mov	RA,AL
;;PUT_m_COMMAn(_RB , 12)
	mov	RB,#12
;;PUT_m_COMMAn(_RCDIR , 14)
	mov	!RC,#14
;;PUT_m_COMMAn(_RBCDIR , 443)
	mov	!RB,#443&255
	mov	!RC,#443>>8
;;POINT1s(-3)
	mov	AL,#-3&255
	add	AL,BP
	clr	AH
;;PUSH1
	call	@push1
;;ARGCNTn(1)
	mov	CL,#1&255
;;CALLm(_test2)
	mov	AL,#_test2&255	;addr to call
	mov	AH,#_test2>>8
	mov	DL,#($+6)&255	;ret addr
	mov	DH,#($+4)>>8
	jmp	@callf
;;ADDSP(2)
	add	SP,#2&255
;;ARGCNTn(0)
	clr	CL
;;CALLm(_test3)
	mov	AL,#_test3&255	;addr to call
	mov	AH,#_test3>>8
	mov	DL,#($+6)&255	;ret addr
	mov	DH,#($+4)>>8
	jmp	@callf
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;PUTwp1
	call	@putwp1
;;GETw1s(-3)
	mov	CL,#-3&255
	call	@getw1s
;;PUTwm1
	mov	CL,#_i&255
	call	@putwm1
;;GETw1s(-5)
	mov	CL,#-5&255
	call	@getw1s
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;ADD12
	call	@add12
;;POINT2m(_ia)
	mov	BL,#_ia&255
	mov	BH,#_ia>>8
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;rINC1(2)
	add	AL,#2&255
	snc
	inc	AH
	add	AH,#2>>8
;;PUSH1
	call	@push1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;SUB12
	call	@sub12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;ADD1n(4)
	add	AL,#4&255
	snc
	inc	AH
	add	AH,#4>>8
;;PUSH1
	call	@push1
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;NUL12
	call	@mul12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;ADD1n(6)
	add	AL,#6&255
	snc
	inc	AH
	add	AH,#6>>8
;;PUSH1
	call	@push1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;DIV12
	call	@div12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;ADD1n(8)
	add	AL,#8&255
	snc
	inc	AH
	add	AH,#8>>8
;;PUSH1
	call	@push1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;MOD12
	call	@mod12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;ADD1n(10)
	add	AL,#10&255
	snc
	inc	AH
	add	AH,#10>>8
;;PUSH1
	call	@push1
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;XOR12
	call	@xor12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;ADD1n(12)
	add	AL,#12&255
	snc
	inc	AH
	add	AH,#12>>8
;;PUSH1
	call	@push1
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;AND12
	call	@and12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;ADD1n(14)
	add	AL,#14&255
	snc
	inc	AH
	add	AH,#14>>8
;;PUSH1
	call	@push1
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;OR12
	call	@or12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;ADD1n(16)
	add	AL,#16&255
	snc
	inc	AH
	add	AH,#16>>8
;;PUSH1
	call	@push1
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;ASL12
	call	@asl12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;POINT1m(_ia)
	mov	AL,#_ia&255
	mov	AH,#_ia>>8
;;ADD1n(18)
	add	AL,#18&255
	snc
	inc	AH
	add	AH,#18>>8
;;PUSH1
	call	@push1
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;ASR12
	call	@asr12
;;POP2
	call	@pop2
;;PUTwp1
	call	@putwp1
;;PUT_m_COMMAn(_j , 1)
ifdef H__j 
	bank	L__j 
	mov	L__j ,#1&255
	bank	H__j 
	mov	H__j ,#1>>8
	bank	CPU
else
	bank	L__j 
	mov	L__j ,#1&255
	bank	CPU
endif
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;rINC1(1)
	inc	AL
	snz
	inc	AH
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;GETw1m(_j)
	mov	CL,#_j&255
	call	@getw1m
;;rDEC1(1)
	sub	AL,#1
	sc
	dec	AH
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1n(2)
	mov	AL,#2&255
	mov	AH,#2>>8
;;NUL12
	call	@mul12
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1n(2)
	mov	AL,#2&255
	mov	AH,#2>>8
;;SWAP12
	call	@swap12
;;DIV12
	call	@div12
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1n(8)
	mov	AL,#8&255
	mov	AH,#8>>8
;;SWAP12
	call	@swap12
;;MOD12
	call	@mod12
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1n(7)
	mov	AL,#7&255
	mov	AH,#7>>8
;;XOR12
	call	@xor12
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1n(3)
	mov	AL,#3&255
	mov	AH,#3>>8
;;AND12
	call	@and12
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;GETw2m(_j)
	mov	CL,#_j&255
	call	@getw2m
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;OR12
	call	@or12
;;PUTwm1
	mov	CL,#_j&255
	call	@putwm1
;;PUT_m_COMMAn(_i , 10)
ifdef H__i 
	bank	L__i 
	mov	L__i ,#10&255
	bank	H__i 
	mov	H__i ,#10>>8
	bank	CPU
else
	bank	L__i 
	mov	L__i ,#10&255
	bank	CPU
endif
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;LT12
	call	@lt12
;;NE10f
	call	@prnul
	dojz	_3
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(0)
	clr	AL
	clr	AH
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_3:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;GT12
	call	@gt12
;;NE10f
	call	@prnul
	dojz	_4
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_4:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;LE12
	call	@le12
;;NE10f
	call	@prnul
	dojz	_5
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(2)
	mov	AL,#2&255
	mov	AH,#2>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_5:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;GE12
	call	@ge12
;;NE10f
	call	@prnul
	dojz	_6
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(3)
	mov	AL,#3&255
	mov	AH,#3>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_6:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;EQ12
	call	@eq12
;;NE10f
	call	@prnul
	dojz	_7
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(4)
	mov	AL,#4&255
	mov	AH,#4>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_7:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;NE12
	call	@ne12
;;NE10f
	call	@prnul
	dojz	_8
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(5)
	mov	AL,#5&255
	mov	AH,#5>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_8:
;;PUT_m_COMMAn(_i , 11)
ifdef H__i 
	bank	L__i 
	mov	L__i ,#11&255
	bank	H__i 
	mov	H__i ,#11>>8
	bank	CPU
else
	bank	L__i 
	mov	L__i ,#11&255
	bank	CPU
endif
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;LT12
	call	@lt12
;;NE10f
	call	@prnul
	dojz	_9
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(8)
	mov	AL,#8&255
	mov	AH,#8>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_9:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;GT12
	call	@gt12
;;NE10f
	call	@prnul
	dojz	_10
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(9)
	mov	AL,#9&255
	mov	AH,#9>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_10:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;LE12
	call	@le12
;;NE10f
	call	@prnul
	dojz	_11
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(10)
	mov	AL,#10&255
	mov	AH,#10>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_11:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;GE12
	call	@ge12
;;NE10f
	call	@prnul
	dojz	_12
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_12:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;EQ12
	call	@eq12
;;NE10f
	call	@prnul
	dojz	_13
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(12)
	mov	AL,#12&255
	mov	AH,#12>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_13:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;NE12
	call	@ne12
;;NE10f
	call	@prnul
	dojz	_14
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(13)
	mov	AL,#13&255
	mov	AH,#13>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_14:
;;PUT_m_COMMAn(_i , 12)
ifdef H__i 
	bank	L__i 
	mov	L__i ,#12&255
	bank	H__i 
	mov	H__i ,#12>>8
	bank	CPU
else
	bank	L__i 
	mov	L__i ,#12&255
	bank	CPU
endif
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;LT12
	call	@lt12
;;NE10f
	call	@prnul
	dojz	_15
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(16)
	mov	AL,#16&255
	mov	AH,#16>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_15:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;GT12
	call	@gt12
;;NE10f
	call	@prnul
	dojz	_16
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(17)
	mov	AL,#17&255
	mov	AH,#17>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_16:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;LE12
	call	@le12
;;NE10f
	call	@prnul
	dojz	_17
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(18)
	mov	AL,#18&255
	mov	AH,#18>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_17:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;GE12
	call	@ge12
;;NE10f
	call	@prnul
	dojz	_18
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(19)
	mov	AL,#19&255
	mov	AH,#19>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_18:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;EQ12
	call	@eq12
;;NE10f
	call	@prnul
	dojz	_19
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(20)
	mov	AL,#20&255
	mov	AH,#20>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_19:
;;GETw2m(_i)
	mov	CL,#_i&255
	call	@getw2m
;;GETw1n(11)
	mov	AL,#11&255
	mov	AH,#11>>8
;;NE12
	call	@ne12
;;NE10f
	call	@prnul
	dojz	_20
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(21)
	mov	AL,#21&255
	mov	AH,#21>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_20:
;;PUT_m_COMMAn(_i , -2)
ifdef H__i 
	bank	L__i 
	mov	L__i ,#-2&255
	bank	H__i 
	mov	H__i ,#-2>>8
	bank	CPU
else
	bank	L__i 
	mov	L__i ,#-2&255
	bank	CPU
endif
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;LT10f
	jnb	AH.7,@_21
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(24)
	mov	AL,#24&255
	mov	AH,#24>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_21:
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;GT10f
	call	@prpos
	dojz	_22
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(25)
	mov	AL,#25&255
	mov	AH,#25>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_22:
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;LE10f
	call	@prpos
	dojnz	_23
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(26)
	mov	AL,#26&255
	mov	AH,#26>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_23:
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;GE10f
	jb	AH.7,@_24
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(27)
	mov	AL,#27&255
	mov	AH,#27>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_24:
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;EQ10f
	call	@prnul
	dojnz	_25
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(28)
	mov	AL,#28&255
	mov	AH,#28>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_25:
;;GETw1m(_i)
	mov	CL,#_i&255
	call	@getw1m
;;NE10f
	call	@prnul
	dojz	_26
;;POINT2s(-5)
	mov	BL,#-5&255
	add	BL,BP
	clr	BH
;;GETw1n(29)
	mov	AL,#29&255
	mov	AH,#29>>8
;;PUTwp1
	call	@putwp1
;;POINT2m(_ca)
	mov	BL,#_ca&255
	mov	BH,#_ca>>8
;;ADD21
	call	@add21
;;GETw1n(1)
	mov	AL,#1&255
	mov	AH,#1>>8
;;PUTbp1
	call	@putbp1
_26:
_27:
;;JMPm(_27)
	dojmp	_27
_28:
;;RETURN(17)
	jmp	@return
	;PUBLIC _test2
_test2
;;ENTER
	call	@enter
;;GETw2s(4)
	mov	CL,#4&255
	call	@getw2s
;;GETw1n(128)
	mov	AL,#128&255
	mov	AH,#128>>8
;;PUTwp1
	call	@putwp1
;;RETURN(0)
	jmp	@return
	;PUBLIC _test3
_test3
;;ENTER
	call	@enter
;;GETw1n(4)
	mov	AL,#4&255
	mov	AH,#4>>8
;;RETURN(0)
	jmp	@return
;extrn	_cscinit
	;MNTRSEG SEGMENT PUBLIC
	;dw	1a1ah
	;MNTRSEG ENDS
	;TASKSEG SEGMENT PUBLIC
	;dw	1a1ah
	;TASKSEG ENDS
	;INTRSEG SEGMENT PUBLIC
	;dw	1a1ah
	;INTRSEG ENDS
	;CODE ENDS
END
