home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / hf / dsp / source / persis.asm < prev    next >
Encoding:
Assembly Source File  |  1991-08-31  |  3.1 KB  |  144 lines

  1.     page    132,63,1,1
  2.     opt    rc
  3.     title    'Radio Modem Persistence Algorithm'
  4.  
  5. ;***************************************************************
  6. ;* PERSIS.ASM -- p-persistence algorithm               *
  7. ;*                                   *
  8. ;* P-persistence algorithm is based on article               *
  9. ;*    Chepponis, M., Karn, P.:                   *
  10. ;*    "The KISS TNC: A simple Host-to-TNC communications     *
  11. ;*     protocol",                                            *
  12. ;*    Proc. of the sixth ARRL computer networking conf.      *
  13. ;*                                   *
  14. ;* Copyright (C) 1990, 1991 by Alef Null. All rights reserved. *
  15. ;* Author(s): Jarkko Vuori, OH2LNS                   *
  16. ;* Modification(s):                           *
  17. ;*  1991-Apr: corrected kickx while txtail pending bug           *
  18. ;***************************************************************
  19.  
  20.     section Persistence
  21.  
  22.     xdef    sci_tim
  23.     xdef    kickx,shutx
  24.     xref    insamp
  25.  
  26.     org    p:
  27.  
  28.     nolist
  29.     include 'macros'
  30.     list
  31.  
  32. ;****************************
  33. ;* Request to start xmitter *
  34. ;****************************
  35. ; first check that no carrier is detected
  36. kickx    jset    #ptt,x:<status,alrdyx
  37.     jclr    #dcd,x:<status,airfree
  38.     bset    #req,x:<status
  39.     rts
  40.  
  41. ; we are already xmitting (tail of the packet)
  42. alrdyx    bset    #xmt,x:<status
  43.     bclr    #tim,x:<status
  44.     rts
  45.  
  46. ; no carrier, do persistence algorithm
  47. airfree bclr    #req,x:<status
  48.     move            y:<timer,a            ; first make random number
  49.     move            x:insamp,x0
  50.     add    x0,a        #>$0000ff,x0
  51.     and    x0,a        x:<P,x0
  52.     cmp    x0,a                    ; then compare it with P
  53.     jle    <xmton
  54. ; we lost random number, wait slottime before trying again
  55.     move            x:<slotime,a
  56.     jmp    <delay
  57.  
  58. ; we've won with the random number generator, keyup TX and start Txdelay timer
  59. xmton    bset    #ptt,x:<status
  60.     move            x:<txdly,a
  61.     ptton
  62.     jmp    <delay
  63.  
  64.  
  65. ;****************************
  66. ;* Request to shut down     *
  67. ;* xmitter            *
  68. ;****************************
  69. shutx    bclr    #xmt,x:<status
  70.     bset    #shut,x:<status
  71.     move            x:<txtail,a
  72.     jmp    <delay
  73.  
  74.  
  75. ;****************************
  76. ;*   Timer service request  *
  77. ;****************************
  78. ; requested time in a (in 1/baud s)
  79. delay    move            y:<timer,x0
  80.     add    x0,a
  81.     move            a1,y:<time
  82.     bset    #tim,x:<status
  83.     rts
  84.  
  85.  
  86. ;****************************
  87. ;*   SCI timer interrupt    *
  88. ;****************************
  89. ; interrupt goes here at every 1/baud s
  90. ; there are three different delays
  91. ;   wait for a new slot
  92. ;   ptt on delay
  93. ;   ptt off delay
  94. sci_tim
  95. ; save registers to be used
  96.     enter    scit
  97.  
  98. ; increment timer
  99.     move            y:<timer,a
  100.     move            #>1,x0
  101.     add    x0,a        y:<time,x0
  102.     move            a1,y:<timer
  103.  
  104. ; check if time elapsed and timer enabled
  105.     eor    x0,a
  106.     jne    <scr_end
  107.     bclr    #tim,x:<status
  108.     jcc    <scr_end
  109.  
  110. ; yes, check what to do
  111.     jset    #ptt,x:<status,scr_t1
  112.  
  113. ; -> wait a new slot
  114.     jsr    <kickx
  115.     jmp    <scr_end
  116.  
  117. scr_t1    jset    #shut,x:<status,scr_t2
  118.  
  119. ; -> start transmitting data
  120.     bset    #xmt,x:<status
  121.     jmp    <scr_end
  122.  
  123. ; -> stop transmitting
  124. scr_t2    bclr    #shut,x:<status
  125.     bclr    #ptt,x:<status
  126.     pttoff
  127.  
  128. ; restore registers
  129. scr_end leave    scit
  130.  
  131.  
  132. ;****************************
  133. ;*     DATA - AREA        *
  134. ;****************************
  135.  
  136.     org    y:
  137.  
  138. timer    ds    1
  139. time    ds    1
  140.  
  141.     endsec
  142.  
  143.     end
  144.