;----------------------------------------------------------------------------
; ASM Function calls for bsdsocket.library functions v1.1 by Roger Light 1999.
; Thanks to Anton Reinauer for help with optimising the ASM.
;
; Only functions used in Paul Burkey's TCPFuncs.bb2 have been tested (and those
; not much...)
; Use at your own risk!
;
; Allows non-restrictive use of bsdsocket.library - ie bsdsocket.library
; doesn't have to be open on your program startup.
;
; See MiamiSDK from Nordic Global for function descriptions.
;
; Function names change as follows:
;
; socket_() changes to socket{}
;
; I recommend that you extract only the functions that you need, to save on
; executable size. If you do use any of these functions, please mention me
; in your docs ;)
;
; Contact me at rogerlight@mindless.com
;
;
; IMPORTANT!
; ==========
;
; The use of these functions has become a little bit more complicated with the
; advent of v1.1. This new version eliminates the PutReg and GetReg calls and
; therefore should be a lot quicker. However, you will probably have to include
; these functions directly into your code rather than using Include SocketIncs.bb2
; This is because of the way the PutReg and GetReg calls are eliminated.
; When you open bsdsocket.library, you need to include the following code:

; SocketBase.l=openlibrary_("bsdsocket.library",0)
; if SocketBase.l
;   GetReg a0,SocketBase.l        ; put SocketVase.l in a0
;   MOVE.l a0,bsdsocketaddress    ;  store the bsdsocket.lib address
; else
;    ; lib not opened
; endif
;
; And then at the very end of your code:
;
; bsdsocketaddress:
;   Dc.l 0            ; the address is stored here.
;
;
; If would probably not be a bad idea to do
;
; MOVE.l 0,bsdsocketaddress
;
; when you close the library as well.


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

Function.l socket{domain.l, type_.l, protocol.l}
;                   d0        d1        d2

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6
  JSR -30(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l bind{s.l, *name.l, namelen.l}
;                d0     a0      d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6
                      ; s.l in d0
  MOVE.l d1,a0        ; *name.l in a0
  MOVE.l d2,d1        ; namelen.l in d1

  JSR -36(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l listen{s.l, backlog.l}
;                  d0     d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -42(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l accept{s.l,  *addr_.l, *addrlen.l}
;                  d0     a0          a1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6
                      ; s.l in d0
  MOVE.l d1,a0        ; *addr_.l in a0
  MOVE.l d2,a1        ; *addrlen.l in a1

  JSR -48(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l connect{s.l, *name.l, namelen.l}
;                   d0    a0        d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,d1

  JSR -54(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l sendto{s.l, *buf.l, len_.l, flags.l, *to_.l, tolen.l}
;                 d0     a0      d1      d2       a1      d3

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,d1
  MOVE.l d3,d2
  MOVE.l d4,a1
  MOVE.l d5,d3

  JSR -60(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l send{s.l, *buf.l, len_.l, flags.l}
;                d0    a0      d1      d2

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,d1
  MOVE.l d3,d2

  JSR -66(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l recvfrom{s.l, *buf.l, len_.l, flags.l, *addr_.l, *addrlen.l}
;                    d0    a0      d1      d2        a1         a2

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,d1
  MOVE.l d3,d2
  MOVE.l d4,a1
  MOVE.l d5,a2

  JSR -72(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l recv{s.l, *buf.l, len_.l, flags.l}
;                d0    a0      d1      d2

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,d1
  MOVE.l d3,d2

  JSR -78(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l shutdown{s.l, how.l}
;                    d0   d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -84(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l setsockopt{s.l, level.l, optname.l, *optval.l, optlen.l}
;                      d0     d1       d2         a0        d3

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d3,a0
  MOVE.l d4,d3

  JSR -90(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getsockopt{s.l, level.l, optname.l, *optval.l, *optlen.l}
;                      d0     d1      d2          a0          a1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d3,a0
  MOVE.l d4,a1

  JSR -96(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getsockname{s.l, *name.l, *namelen.l}
;                       d0    a0        a1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,a1

  JSR -102(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getpeername{s.l, *name.l, *namelen.l}
;                       d0    a0        a1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,a1

  JSR -108(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l IoctlSocket{s.l, req.l, *argp.l}
;                       d0    d1      a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d2,a0

  JSR -114(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l CloseSocket{s.l}
;                       d0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6
                        ; s.l in d0
  JSR -120(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l WaitSelect{nfds.l, *readfds.l, *writefds.l, *exceptfds.l, *timeout.l, *signal.s}
;                       d0        a0          a1            a2           a3         d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,a1
  MOVE.l d3,a2
  MOVE.l d4,a3
  MOVE.l d5,d1

  JSR -126(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l SetSocketSignals{intmask.l, iomask.l, urgentmask.l}
;                             d0          d1          d2

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -132(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getdtablesize{}
;                       void

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -138(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l ObtainSocket{id.l, domain.l, type_.l, protocol.l}
;                        d0     d1        d2        d3

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -144(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l ReleaseSocket{s.l, id.l}
;                         d0   d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -150(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l ReleaseCopyOfSocket{s.l, id.l}
;                               d0    d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -156(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l Errno{}
;                void

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -162(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l SetErrnoPtr{*errnop.l, size.l}
;                         a0        d0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0
  MOVE.l d1,d0

  JSR -168(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l Inet_NtoA{ip.l}
;                     d0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -174(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l inet_addr{*cp.l}
;                      a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0

  JSR -180(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l Inet_LnaOf{in.l}
;                      d0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -186(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l Inet_NetOf{in.l}
;                      d0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -192(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l Inet_MakeAddr{net.l, host.l}
;                         d0      d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -198(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l inet_network{*cp.l}
;                        a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0

  JSR -204(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l gethostbyname{*name.l}
;                           a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0

  JSR -210(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l gethostbyaddr{*addr_.l, len_.l, type_.l}
;                           a0        d0      d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0
  MOVE.l d1,d0
  MOVE.l d2,d1

  JSR -216(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getnetbyname{ *name.l}
;                          a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0

  JSR -222(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getnetbyaddr{net.l, type_.l}
;                         d0      d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -228(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getservbyname{*name.l, *proto.l}
;                           a0        a1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0
  MOVE.l d1,a1

  JSR -234(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getservbyport{port.l, *proto.l}
;                           d0      a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0

  JSR -240(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getprotobyname{*name.l}
;                           a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0

  JSR -246(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l getprotobynumber{id.l}
;                            d0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -252(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l vsyslog{pri.l, *msg.l, args.l}
;                    d0     a0      a1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,a1

  JSR -258(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l Dup2Socket{olds.l, news.l}
;                       d0      d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -264(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l sendmsg{s.l, *msg.l, flags.l}
;                   d0    a0      d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,d1

  JSR -270(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l recvmsg{s.l, *msg.l, flags.l}
;                   d0    a0      d1

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d1,a0
  MOVE.l d2,d1

  JSR -276(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l gethostname{*name.l, namelen.l}
;                         a0        d0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0
  MOVE.l d1,d0

  JSR -282(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l gethostid{}
;                   void

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  JSR -288(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l SocketBaseTagList{*tags.l}
;                               a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0

  JSR -294(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function

;----

Function.l GetSocketEvents{*eventsp.l}
;                               a0

  MOVE.l a6,-(a7)
  MOVE.l bsdsocketaddress,a6

  MOVE.l d0,a0

  JSR -300(a6)

  MOVE.l (a7)+,a6
  AsmExit
End Function
