                device pic16c71,hs_osc,wdt_off,pwrt_off,protect_off
                id 'sr01'
        include 'mheader.src'

RA3         =   ra.3
RB5         =   rb.5
            
            org     0h
            jmp     5
            org 4h            
doint       jmp     rcv
            org 5h
            clr     PCLATH
            clrb    rp0
            mov     ADCON0, #10000001b
            mov	    INTCON, #00100000b	;RTCC, INT IRQ enabled
            call    dally
            setb    rp0
            mov     TRISA, #0011b
            mov     TRISB, #00000001b
            mov     OPTION, #00000011b  ;RTCC=inst,RB pull-up, /4   
            mov     ADCON1, #00000010b
            clrb    rp0
            mov     RTCC, #fullframe
            setb    waitb
            clrb    inmsg
            clr     ra
            clr     rb
            setb    TXSWTCH
            clrb    PTX
            clr     FSR
            setb    GIE
main        nop
            setb    RA3
            nop
            clrb    RA3
            clrb    RB5
            nop
            jmp     main
rcv         mov     RTCC, #fullframe
           call    msg_demod
;           jb      waitb, mloop
;            jb      inmsg, msg_demod
intend      clrb    RTIF
            reti



mloop       jb      skipcollect, :didskip
            call    collect
            mov     real, byte1
            mov     imag, byte2
            call    adjgain
            call    collect
            mov     real2, byte1
            mov     imag2, byte2
            call    pskdemod
            jnb     bitv, :gotzero
            add     onect, #1
            cjae    onect, #3, :ones
            jmp     :next
:gotzero    mov     onect, #0
:next       movb    c, bitv
            rr      curbyte
            cje     curbyte, #preamble, :msginit
            jmp     intend
            
:didskip    clrb    skipcollect
            reti
:ones       setb    skipcollect
            jmp     intend

:msginit    setb    inmsg
            clrb    waitb
            jmp     intend



                    INCLUDE 'collect.src'
                    INCLUDE 'adjgain.src'
                    INCLUDE 'msgdemod.src'

dally		mov	tempa,#255
:l1		mov	tempb,#255
:l2		djnz	tempb,:l2
		djnz	tempa,:l1
		ret
                    
                    