home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / PACKET / RLI120.ARK / TNC.LIB < prev    next >
Text File  |  1987-05-11  |  8KB  |  495 lines

  1. ;; TNC.LIB - 5/11/87 - Macros to deal with TAPR TNC.
  2.  
  3. ;; Addresses where the time and tick counter kept.
  4.  
  5. timdef    macro
  6. timer    equ    48h
  7. sec    equ    4ah
  8. min    equ    4bh
  9. hr    equ    4ch
  10. day    equ    4dh
  11. mo    equ    4eh
  12. yr    equ    4fh
  13.     endm
  14.  
  15. tncdefs    macro
  16.  
  17. false    equ    0
  18. true    equ    not false
  19. btime    equ    1    ;; True during busy hours
  20. qtime    equ    2    ;; True during quiet (non-busy) hours
  21.  
  22. convtim    equ    2    ;; Sec wait for converse mode
  23. linktim    equ    3    ;; Seconds wait before send link msg
  24. cmdmax    equ    255    ;; Max length of text string
  25.  
  26. iobyte    equ    3    ;; IOBYTE address
  27.  
  28. ;; Command type seen from TNC.
  29.  
  30. cdata    equ    0    ;; String was data
  31. cdiscmd    equ    2    ;; Was *** DISCONNECTED
  32. ctimcmd    equ    3    ;; Nothing seen by timeout time
  33. cnull    equ    1    ;; Was a trailing LF (from CR,LF)
  34.  
  35. ;; User modes.
  36.  
  37. lmode    equ    1    ;; Local
  38. gmode    equ    2    ;; GateWay
  39. smode    equ    4    ;; Sysop
  40. umode    equ    8    ;; Normal user
  41.  
  42. ;; Misc constants.
  43.  
  44. fcbsize    equ    36    ;; File control block size
  45. secsize    equ    128    ;; Disc sector size
  46. bufsize    equ    16    ;; Sectors in file buffer.
  47.  
  48. linkcmd    equ    'W'-40h    ;; ^W = Escape from link
  49. eof    equ    'Z'-40h    ;; ^Z = End of file
  50.  
  51. ;; Values for iobyte.
  52.  
  53. ciob    equ    0    ;; Console (TTY:)
  54. raiob    equ    1    ;; TNC on comm port (CRT:)
  55. rbiob    equ    2    ;; TNC on printer port (BAT:)
  56.     endm
  57.  
  58. ;; Switch to local console.
  59.  
  60. console    macro
  61.     mvim    iobyte,ciob
  62.     endm
  63.  
  64. ;; Switch console to master TNC
  65.  
  66. master    macro
  67.     movb    iobyte,mtnc
  68.     endm
  69.  
  70. ;; Switch console to slave TNC
  71.  
  72. slave    macro
  73.     movb    iobyte,stnc
  74.     endm
  75.  
  76. asciictl    macro
  77. null    equ    0
  78. soh    equ    1
  79. stx    equ    2
  80. etx    equ    3
  81. eot    equ    4
  82. enq    equ    5
  83. ack    equ    6
  84. bel    equ    7
  85. bell    equ    7
  86. bs    equ    8
  87. ht    equ    9
  88. tab    equ    9
  89. lf    equ    0ah
  90. vt    equ    0bh
  91. ff    equ    0ch
  92. cr    equ    0dh
  93. so    equ    0eh
  94. si    equ    0fh
  95. dle    equ    10h
  96. dc1    equ    11h
  97. dc2    equ    12h
  98. dc3    equ    13h
  99. dc4    equ    14h
  100. nak    equ    15h
  101. syn    equ    16h
  102. etb    equ    17h
  103. can    equ    18h
  104. em    equ    19h
  105. subb    equ    1ah
  106. esc    equ    1bh
  107. fs    equ    1ch
  108. gs    equ    1dh
  109. rs    equ    1eh
  110. us    equ    1fh
  111. del    equ    7fh
  112.     endm
  113.  
  114. ;; Wait number of seconds in call argument.
  115. ;;    No registers altered.
  116.  
  117. wait    macro    ?m
  118.     push    hl
  119.     lxim    timer,?m
  120.     call    @wait
  121.     pop    hl
  122.     endm
  123.  
  124. ;; BDOS call codes, fixed address locations, etc.
  125.  
  126. dodosa    macro    func,addr
  127.     if    not nul func
  128.     ld    c,func
  129.     endif
  130.     if    not nul addr
  131.     ld    de,addr
  132.     endif
  133.     call    dosent
  134.     endm
  135.  
  136. dodosv    macro    func,val
  137.     if    not nul func
  138.     ld    c,func
  139.     endif
  140.     if    not nul val
  141.     ld    a,(val)
  142.     ld    e,a
  143.     endif
  144.     call    dosent
  145.     endm
  146.  
  147. bdosdef    macro
  148. defdma    equ    80h    ;; Default disk buffer.
  149. wboot    equ    0    ;; Reboot jump address
  150. dosent    equ    5    ;; BDOS entry point
  151. dfcb1    equ    5ch
  152. dfcb2    equ    6ch
  153.  
  154. ;; BDOS function codes.
  155.  
  156. reboot    equ    0    ;; Terminate program
  157. dconin    equ    1    ;; Get character from console.
  158. dconout    equ    2    ;; Put character to console.
  159. reader    equ    3    ;; Get character from reader.
  160. punch    equ    4    ;; Put character to punch.
  161. list    equ    5    ;; Put character to list device.
  162. getio    equ    7    ;; Get iobyte.
  163. setio    equ    8    ;; Set iobyte.
  164. bufout    equ    9    ;; Put string to console.
  165. bufin    equ    10    ;; Get string from console.
  166. dconst    equ    11    ;; Get console status.
  167. getver    equ    12    ;; Get CP/M version
  168. reset    equ    13    ;; Reset disk system.
  169. seldsk    equ    14    ;; Select drive.
  170. open    equ    15    ;; Open file.
  171. close    equ    16    ;; Close file.
  172. search    equ    17    ;; Search for file.
  173. next    equ    18    ;; Get next file.
  174. delete    equ    19    ;; Delete file.
  175. read    equ    20    ;; Sequential disk read.
  176. write    equ    21    ;; Sequential disk write.
  177. make    equ    22    ;; Make file.
  178. rename    equ    23    ;; Rename file.
  179. ckdsks    equ    24    ;; Get drives on line vector.
  180. ckcur    equ    25    ;; Get current drive.
  181. setdma    equ    26    ;; Set disk I/O transfer address.
  182. getalv    equ    27    ;; Get allocation vector
  183. getro    equ    29    ;; Get read only vector
  184. setatr    equ    30    ;; Set file attributes
  185. getdpb    equ    31    ;; Return dpb pointer
  186. sguser    equ    32    ;; Set/Get user code
  187. rrec    equ    33    ;; Read random
  188. wrec    equ    34    ;; Write random
  189. getend    equ    35    ;; Return file end address
  190.     endm
  191.  
  192. ntobuf    macro    adr,ct
  193.     if    not nul adr
  194.     ld    hl,adr
  195.     endif
  196.     if    not nul ct
  197.     ld    b,ct
  198.     endif
  199.     call    @ntobuf
  200.     endm
  201.  
  202. ctobuf    macro    adr
  203.     if    not nul adr
  204.     ld    hl,adr
  205.     endif
  206.     call    @ctobuf
  207.     endm
  208.  
  209. openr    macro    cb
  210.     if    not nul cb
  211.     ld    hl,cb
  212.     ld    de,rfcb
  213.     ld    bc,fcbsize
  214.     ldir
  215.     endif
  216.     call    @openr
  217.     endm
  218.  
  219. openw    macro    cb
  220.     if    not nul cb
  221.     ld    hl,cb
  222.     ld    de,wfcb
  223.     ld    bc,fcbsize
  224.     ldir
  225.     endif
  226.     call    @openw
  227.     endm
  228.  
  229. opena    macro    cb
  230.     if    not nul cb
  231.     ld    hl,cb
  232.     ld    de,wfcb
  233.     ld    bc,fcbsize
  234.     ldir
  235.     endif
  236.     call    @opena
  237.     endm
  238.  
  239. openwn    macro    cb
  240.     if    not nul cb
  241.     ld    hl,cb
  242.     ld    de,wfcb
  243.     ld    bc,fcbsize
  244.     ldir
  245.     endif
  246.     call    @openn
  247.     endm
  248.  
  249. closew    macro
  250.     call    @closew
  251.     endm
  252.  
  253. ;; Check cmd for type of string received:
  254. ;; null - either a single LF or a connect request.
  255. ;; disco - it was *** DISCONNECTED
  256. ;; tout - Timed out before getting any data.
  257.  
  258. ckcmd    macro    none,disco,tout
  259.     dec    a
  260.     jp    z,none
  261.     dec    a
  262.     jp    z,disco
  263.     dec    a
  264.     jp    z,tout
  265.     endm
  266.  
  267. retz    macro
  268.     xor    a
  269.     ret
  270.     endm
  271.  
  272. retnz    macro
  273.     xor    a
  274.     inc    a
  275.     ret
  276.     endm
  277.  
  278. ckname    macro    addr
  279.     ld    hl,addr
  280.     call    ckname
  281.     endm
  282.  
  283. upper    macro    addr,len
  284.     if    not nul addr
  285.     ld    hl,addr
  286.     endif
  287.     if    not nul len
  288.     ld    c,len
  289.     endif
  290.     call    @upper
  291.     endm
  292.  
  293. cmpm    macro    addr,dat
  294.     ld    a,(addr)
  295.     cp    dat
  296.     endm
  297.  
  298. comp    macro    fir,sec,nr
  299.     if    not nul fir
  300.     ld    hl,fir
  301.     endif
  302.     if    not nul sec
  303.     ld    de,sec
  304.     endif
  305.     if    not nul nr
  306.     ld    c,nr
  307.     endif
  308.     call    @cmp
  309.     endm
  310.  
  311. compwc    macro    fir,sec,nr
  312.     if    not nul fir
  313.     ld    hl,fir
  314.     endif
  315.     if    not nul sec
  316.     ld    de,sec
  317.     endif
  318.     if    not nul nr
  319.     ld    c,nr
  320.     endif
  321.     call    @cmpwc
  322.     endm
  323.  
  324. cmpcmd    macro    @t,@l
  325.     ld    de,@t
  326.     ld    c,@l
  327.     call    @cmpcmd
  328.     endm
  329.  
  330. ;; Create and clear a list.
  331.  
  332. maklst    macro    @l,@n,@w,@c
  333.     ld    de,(@n)        ;; # items on list
  334.     ld    c,@w        ;; Bytes / item
  335.     call    muldec        ;; Bytes in the list
  336.     ld    hl,($memry)    ;; First byte avail in pool memory
  337.     ld    (@l),hl        ;; Is start of list
  338.     add    hl,de
  339.     ld    ($memry),hl    ;; New first byte of pool memory
  340.     ld    hl,(@l)        ;; Start of list
  341.     ld    b,d
  342.     ld    c,e        ;; (BC) = bytes in list
  343.     ld    e,@c        ;; Char to clear with
  344.     call    @fill        ;; Clear the list
  345.     endm
  346.  
  347. ;; Search a list.
  348.  
  349. srclst    macro    @t,@l,@n,@w,@c
  350.     push    hl
  351.     lxim    @srct,@t    ;; Address of target string
  352.     movw    @srcl,@l    ;; Address of list
  353.     movw    @srcn,@n    ;; # items in list
  354.     lxim    @srcw,@w    ;; # bytes/item
  355.     lxim    @srcc,@c    ;; # bytes to compare
  356.     xor    a        ;; Zero says no wild cards
  357.     call    @src
  358.     pop    hl
  359.     endm
  360. ;; Search a list with wild cards
  361.  
  362. srclsw    macro    @t,@l,@n,@w,@c
  363.     push    hl
  364.     lxim    @srct,@t    ;; Address of target string
  365.     movw    @srcl,@l    ;; Address of list
  366.     movw    @srcn,@n    ;; # items in list
  367.     lxim    @srcw,@w    ;; # bytes/item
  368.     lxim    @srcc,@c    ;; # bytes to compare
  369.     xor    a        ;; Non-zero says allow wild cards
  370.     inc    a
  371.     call    @src
  372.     pop    hl
  373.     endm
  374.  
  375. ;; Add item to a list.
  376.  
  377. addlst    macro    @t,@l,@n,@m,@w,@c
  378.     lxim    @adlt,@t
  379.     movw    @adll,@l
  380.     movw    @adln,@n
  381.     movw    @adlm,@m
  382.     lxim    @adlw,@w
  383.     lxim    @adlc,@c
  384.     call    @adl
  385.     movw    @n,@adln
  386.     endm
  387.  
  388. ;; Return (HL) pointing to oldest item, remove item.
  389. ;; Return zero cleared if no items.
  390.  
  391. sublst    macro    @l,@n,@w
  392.     movw    @adll,@l
  393.     movw    @adln,@n
  394.     lxim    @adlw,@w
  395.     call    @slst
  396.     movw    @n,@adln
  397.     endm
  398.  
  399. prtx    macro    adr
  400.     if    not nul adr
  401.     ld    hl,(adr)
  402.     endif
  403.     call    @prtx
  404.     endm
  405.  
  406. docmd    macro    addr
  407.     ld    hl,(addr)
  408.     call    @docmd
  409.     endm
  410.  
  411. dtz    macro    addr
  412.     ld    hl,(addr)
  413.     ld    a,l
  414.     or    h
  415.     endm
  416.  
  417. dcxm    macro    addr
  418.     ld    hl,(addr)
  419.     dec    hl
  420.     ld    (addr),hl
  421.     endm
  422.  
  423. inxm    macro    addr
  424.     ld    hl,(addr)
  425.     inc    hl
  426.     ld    (addr),hl
  427.     endm
  428.  
  429. movb    macro    addrt,addrf
  430.     ld    a,(addrf)
  431.     ld    (addrt),a
  432.     endm
  433.  
  434. movw    macro    addrt,addrf
  435.     ld    hl,(addrf)
  436.     ld    (addrt),hl
  437.     endm
  438.  
  439. lxim    macro    addr,val
  440.     ld    hl,val
  441.     ld    (addr),hl
  442.     endm
  443.  
  444. mvim    macro    addr,val
  445.     ld    a,val
  446.     ld    (addr),a
  447.     endm
  448.  
  449. zmov    macro    to,from,n
  450.     if    not nul to
  451.     ld    de,to
  452.     endif
  453.     if    not nul from
  454.     ld    hl,from
  455.     endif
  456.     if    not nul n
  457.     ld    bc,n
  458.     endif
  459.     ldir
  460.     endm
  461.  
  462. move    macro    to,from,n
  463.     if    not nul to
  464.     ld    hl,to
  465.     endif
  466.     if    not nul from
  467.     ld    de,from
  468.     endif
  469.     if    not nul n
  470.     ld    bc,n
  471.     endif
  472.     call    @move
  473.     endm
  474.  
  475. movcmd    macro    to,off,max
  476.     if    not nul to
  477.     ld    hl,to
  478.     endif
  479.     ld    de,off
  480.     ld    bc,max
  481.     call    @mcmd
  482.     endm
  483.  
  484. fill    macro    adr,nr,ch
  485.     if    not nul adr
  486.     ld    hl,adr
  487.     endif
  488.     if    not nul nr
  489.     ld    bc,nr
  490.     endif
  491.     ld    e,ch
  492.     call    @fill
  493.     endm
  494. 
  495.