home *** CD-ROM | disk | FTP | other *** search
- page 132,63,1,1
- opt rc
- title 'Radio Modem Persistence Algorithm'
-
- ;***************************************************************
- ;* PERSIS.ASM -- p-persistence algorithm *
- ;* *
- ;* P-persistence algorithm is based on article *
- ;* Chepponis, M., Karn, P.: *
- ;* "The KISS TNC: A simple Host-to-TNC communications *
- ;* protocol", *
- ;* Proc. of the sixth ARRL computer networking conf. *
- ;* *
- ;* Copyright (C) 1990, 1991 by Alef Null. All rights reserved. *
- ;* Author(s): Jarkko Vuori, OH2LNS *
- ;* Modification(s): *
- ;* 1991-Apr: corrected kickx while txtail pending bug *
- ;***************************************************************
-
- section Persistence
-
- xdef sci_tim
- xdef kickx,shutx
- xref insamp
-
- org p:
-
- nolist
- include 'macros'
- list
-
- ;****************************
- ;* Request to start xmitter *
- ;****************************
- ; first check that no carrier is detected
- kickx jset #ptt,x:<status,alrdyx
- jclr #dcd,x:<status,airfree
- bset #req,x:<status
- rts
-
- ; we are already xmitting (tail of the packet)
- alrdyx bset #xmt,x:<status
- bclr #tim,x:<status
- rts
-
- ; no carrier, do persistence algorithm
- airfree bclr #req,x:<status
- move y:<timer,a ; first make random number
- move x:insamp,x0
- add x0,a #>$0000ff,x0
- and x0,a x:<P,x0
- cmp x0,a ; then compare it with P
- jle <xmton
- ; we lost random number, wait slottime before trying again
- move x:<slotime,a
- jmp <delay
-
- ; we've won with the random number generator, keyup TX and start Txdelay timer
- xmton bset #ptt,x:<status
- move x:<txdly,a
- ptton
- jmp <delay
-
-
- ;****************************
- ;* Request to shut down *
- ;* xmitter *
- ;****************************
- shutx bclr #xmt,x:<status
- bset #shut,x:<status
- move x:<txtail,a
- jmp <delay
-
-
- ;****************************
- ;* Timer service request *
- ;****************************
- ; requested time in a (in 1/baud s)
- delay move y:<timer,x0
- add x0,a
- move a1,y:<time
- bset #tim,x:<status
- rts
-
-
- ;****************************
- ;* SCI timer interrupt *
- ;****************************
- ; interrupt goes here at every 1/baud s
- ; there are three different delays
- ; wait for a new slot
- ; ptt on delay
- ; ptt off delay
- sci_tim
- ; save registers to be used
- enter scit
-
- ; increment timer
- move y:<timer,a
- move #>1,x0
- add x0,a y:<time,x0
- move a1,y:<timer
-
- ; check if time elapsed and timer enabled
- eor x0,a
- jne <scr_end
- bclr #tim,x:<status
- jcc <scr_end
-
- ; yes, check what to do
- jset #ptt,x:<status,scr_t1
-
- ; -> wait a new slot
- jsr <kickx
- jmp <scr_end
-
- scr_t1 jset #shut,x:<status,scr_t2
-
- ; -> start transmitting data
- bset #xmt,x:<status
- jmp <scr_end
-
- ; -> stop transmitting
- scr_t2 bclr #shut,x:<status
- bclr #ptt,x:<status
- pttoff
-
- ; restore registers
- scr_end leave scit
-
-
- ;****************************
- ;* DATA - AREA *
- ;****************************
-
- org y:
-
- timer ds 1
- time ds 1
-
- endsec
-
- end
-