Compare commits

..

5 Commits

15 changed files with 317 additions and 752 deletions

12
.gitignore vendored
View File

@ -4,17 +4,13 @@ dist/
build/ build/
aminet/ aminet/
Disk.info Disk.info
private-test/
stuff/ stuff/
patches/
.vamosrc
activate
test/report.txt
test/TestSuite.info
src/report.txt
src/BSDSocket_Labels.s src/BSDSocket_Labels.s
src/BSDSocket_Size.s src/BSDSocket_Size.s
src/bsdsocket_lib.fd src/bsdsocket_lib.fd
src/bsdsocket_lvo.i src/bsdsocket_lvo.i
src/*.Lib src/*.Lib
libs/ .vamosrc
activate
test/
patches/

Binary file not shown.

50
API.md
View File

@ -63,19 +63,8 @@ Create a new Internet socket for reading or writing.
#### RESULT=Socket Connect(Socket to IPAddress$, Port) #### RESULT=Socket Connect(Socket to IPAddress$, Port)
Attempt to connect to a remote IP address. Attempt to connect to a remote host. Currently doesn't
support DNS lookups.
##### Emulation vs. Physical/FPGA Amiga note
On emulated Amigas (FS-UAE) with emulated `bsdsocket.library`, a failure in
`Socket Connect` due to giving the function a bad IP address allows you to reuse
the socket. On real or FPGA-based Amiga running real TCP/IP stacks (MiamiDX,
Roadshow), the socket will be made unusable and you'll need to
`Socket Close Socket` and reopen the socket with whatever parameters necessary.
Closing and opening `bsdsocket.library` has the same effect.
Always close and re-open a socket if you have any `Socket Connect` failure and
any non-blocking polling loops time out!
##### Returns ##### Returns
@ -85,7 +74,6 @@ any non-blocking polling loops time out!
the socket with Socket Select and Socket Getsockopt Int the socket with Socket Select and Socket Getsockopt Int
to see if the connection succeeded to see if the connection succeeded
* -11 port out of range * -11 port out of range
* -13 IP address has zero length
--- ---
@ -94,7 +82,7 @@ any non-blocking polling loops time out!
Set a server socket to reuse an interface and port that had Set a server socket to reuse an interface and port that had
been used recently. You likely want this if you're building been used recently. You likely want this if you're building
something that listens on a port for connections. This calls something that listens on a port for connections. This calls
`setsockopt()` for you. setsockopt() for you.
##### Returns ##### Returns
@ -194,7 +182,6 @@ Set a socket to timeout after Wait_ms milliseconds if reading or writing doesn't
Close a socket. Close a socket.
##### Returns ##### Returns
* 0 on success * 0 on success
@ -337,6 +324,32 @@ out. There's no way to set this timeout, or cancel or override it via AMOS.
String with IP address, or blank string on error. String with IP address, or blank string on error.
---
#### RESULT=Socket Status(Socket)
Returns basic connection information about a socket.
##### Warning
Since none of the socket processing of this extension happens in the
background, you're likely better off using other means to detect
socket status.
* Disconnected: Try a recv and get zero bytes back. Check Socket Errno.
* Broken: Try a send. If it fails, check Socket Errno.
* Ready: Use the Async Wait functions.
##### Returns
Status of socket:
* 0 = Closed
* 2 = Listening
* 6 = Connecting
* 7 = Connected
---
## Low Level ## Low Level
@ -384,6 +397,8 @@ Set or clear a socket bit in an fd_set.
* Address to that particular fd_set * Address to that particular fd_set
* -1 if fd_set is out of range or socket is out of range. * -1 if fd_set is out of range or socket is out of range.
---
#### RESULT=Socket Fdset Is Set(fd_set, Socket) #### RESULT=Socket Fdset Is Set(fd_set, Socket)
See if the particular socket remained after a Socket Select call. See if the particular socket remained after a Socket Select call.
@ -392,6 +407,8 @@ See if the particular socket remained after a Socket Select call.
* True or False if the socket is set or not * True or False if the socket is set or not
---
#### RESULT=Socket Select(Max Socket, Read fd_set, Write fd_set, Error fd_set, TimeoutMS) #### RESULT=Socket Select(Max Socket, Read fd_set, Write fd_set, Error fd_set, TimeoutMS)
Wait for the specified number of milliseconds. If any of the sockets Wait for the specified number of milliseconds. If any of the sockets
@ -403,4 +420,3 @@ how many sockets were left.
* 0 on timeout * 0 on timeout
* -1 on error * -1 on error
* # of interesting sockets on success

View File

@ -130,7 +130,6 @@ Socket Library Close
* [Hop to the Top: Bunny's Revenge](https://rabbit.robsmithdev.co.uk/) * [Hop to the Top: Bunny's Revenge](https://rabbit.robsmithdev.co.uk/)
* The game uses this extension to send and receive high score information. * The game uses this extension to send and receive high score information.
I also did some of the art for the game! I also did some of the art for the game!
* [Gopherized](https://allanon71.itch.io/gopherized)
Doing something cool with the extension? Doing something cool with the extension?
[Contact me](https://theindustriousrabbit.com/about) and I'll add it to the list! [Contact me](https://theindustriousrabbit.com/about) and I'll add it to the list!
@ -153,16 +152,6 @@ Doing something cool with the extension?
timeouts using `Socket Async Wait Writing` to determine if the Internet timeouts using `Socket Async Wait Writing` to determine if the Internet
is available. is available.
## Slot 18 taken already?
I'm also building releases for slots 9, 11, and 17. They're available for
separate download from each Release version 1.1.4 and on.
Note that you won't be able to load the test AMOS programs, or any other
progaam using the Slot 18 version, because AMOS uses the extension's slot
number in the saved tile. You'll have to export and import ASCII versions
of programs.
## Versioning ## Versioning
This project uses semantic versioning. This project uses semantic versioning.
@ -179,12 +168,10 @@ throw a link to theindustriousrabbit.com somewhere! You can
also find a donate link on also find a donate link on
[the About section on The Industrious Rabbit](https://theindustriousrabbit.com/about). [the About section on The Industrious Rabbit](https://theindustriousrabbit.com/about).
## Feedback? Bug reports? Patches? ## Feedback? Bug reports?
First, run `test/TestSuite` to generate a `report.txt` file. Go to the [About section on The Industrious Rabbit](https://theindustriousrabbit.com/about)
to contact me.
Then, go to the [About section on The Industrious Rabbit](https://theindustriousrabbit.com/about)
to contact me, send the `report.txt` along with the details on your issue.
## Changelog ## Changelog
@ -220,20 +207,13 @@ to contact me, send the `report.txt` along with the details on your issue.
* `Dns Get Address By Name$` * `Dns Get Address By Name$`
* `Socket Recv$` * `Socket Recv$`
### 1.1.3 ### 1.1.3 (2024-04-17)
Internal release. * Fix bug in fdset macro where using D3 for a parameter could cause corruption
* Copy a null-terminated copy of IP address for SocketIPAddressPortToSockaddr
* Retructure API docs for easier reading
### 1.1.4 (2024-05-02) # Development
* Fix bug in fdset macro where using D3 for a parameter could cause corruption.
* Copy a null-terminated copy of IP address for `SocketIPAddressPortToSockaddr`.
* Add test suite to exercise extension functionality.
* Fix several crash bugs found due to the test suite.
* Retructure API docs for easier reading.
* Improve build and release tooling.
## Development
### Environment ### Environment
@ -265,25 +245,9 @@ Run `bin/setup` to do most of the setups above.
### Debugging ### Debugging
#### Cross-platform
Modify data in the `DebugArea` and read it by `Peek`/`Deek`/`Leek`ing from Modify data in the `DebugArea` and read it by `Peek`/`Deek`/`Leek`ing from
the base address provided by `Socket Get Debug Area`. the base address provided by `Socket Get Debug Area`.
#### WinUAE/FS-UAE
In the debugger, set a memory breakpoint at `$100` for two written bytes:
```
w 0 100 2
```
Then, in your code, clear those two bytes to stop execution at that point:
```asm
CLR.W $100
```
### Releasing ### Releasing
#### Ubuntu/Debian #### Ubuntu/Debian

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/bin/bash
for i in examples/*.amos test/*.amos; do for i in examples/*.amos; do
echo "$i" echo "$i"
~/Projects/amostools/listamos -e src/AMOSPro_BSDSocket.Lib "${i}" > "${i%.amos}.basic" 2>/dev/null ~/Projects/amostools/listamos -e AMOSPro_BSDSocket.Lib "${i}" > "${i%.amos}.basic" 2>/dev/null
done done

View File

@ -24,22 +24,6 @@ source.lines.each do |line|
end end
end end
FileUtils.cp 'src/AMOSPro_BSDSocket.Lib', 'AMOSPro_BSDSocket.Lib'
strings = []
Open3.popen2e('strings', 'AMOSPro_BSDSocket.Lib') do |stdin, stdout_and_stderr, wait_thr|
stdin.close
stdout_and_stderr.each { |l| strings << l }
wait_thr.join
end
unless strings.any? { |s| s[version] }
puts "Extension build doesn't match source version! Did you rebuild it yet on the Amiga?"
exit 1
end
FileUtils.mkdir_p 'dist' FileUtils.mkdir_p 'dist'
build_base = 'build' build_base = 'build'
@ -51,6 +35,8 @@ FileUtils.rm_rf 'aminet'
FileUtils.mkdir_p build_dir FileUtils.mkdir_p build_dir
FileUtils.mkdir_p 'aminet' FileUtils.mkdir_p 'aminet'
FileUtils.mv 'src/AMOSPro_BSDSocket.Lib', 'AMOSPro_BSDSocket.Lib' if File.exist?('src/AMOSPro_BSDSocket.Lib')
hackerbun_target = File.expand_path("dist/AMOSPro_BSDSocket_#{version}.lha") hackerbun_target = File.expand_path("dist/AMOSPro_BSDSocket_#{version}.lha")
[ [

42
src/AMOSMacros.s Normal file
View File

@ -0,0 +1,42 @@
; get the effective address of something in extension memory
Dlea MACRO
MOVE.L ExtAdr+ExtNb*16(A5),\2
ADD.W #\1-MB,\2
ENDM
; load the base of extension memory into a register
Dload MACRO
MOVE.L ExtAdr+ExtNb*16(A5),\1
ENDM
; wrap code that doesn't take arguments with these
PreserveStackInstruction MACRO
MOVEM.L A2-A6/D6-D7,-(SP)
ENDM
RestoreStackInstruction MACRO
MOVEM.L (SP)+,A2-A6/D6-D7
ENDM
; wrap code that takes arguments with these
PreserveStackFunction MACRO
MOVEM.L A2/A4-A6/D6-D7,-(SP)
ENDM
RestoreStackFunction MACRO
MOVEM.L (SP)+,A2/A4-A6/D6-D7
ENDM
; Push and pop the extension's data storage into A3
WithDataStorageToA3 MACRO
MOVE.L A3,-(SP)
Dload A3
ENDM
EndDataStorage MACRO
MOVE.L (SP)+,A3
ENDM
EvenOutStringAddress MACRO
MOVE.W \1,\2
AND.W #$0001,\2
ADD.W \2,\1
ENDM

View File

@ -5,10 +5,9 @@
; Writing this code the right way, 25 years later. ; Writing this code the right way, 25 years later.
; extension number 18 ; extension number 18
; this now comes from GenAm command line option ExtNb equ 18-1
;ExtNb equ 18-1
Version MACRO Version MACRO
dc.b "1.1.4-20240502" dc.b "1.1.3-20240417"
ENDM ENDM
VerNumber equ $1 VerNumber equ $1
@ -23,190 +22,23 @@ VerNumber equ $1
Include "+AMOS_Includes.s" Include "+AMOS_Includes.s"
Include "bsdsocket_lvo.i" Include "bsdsocket_lvo.i"
; get the effective address of something in extension memory Include "LongDivide.s"
Dlea MACRO Include "Constants.s"
MOVE.L ExtAdr+ExtNb*16(A5),\2 Include "fd_set.s"
ADD.W #\1-MB,\2 Include "AMOSMacros.s"
ENDM
; load the base of extension memory into a register
Dload MACRO
MOVE.L ExtAdr+ExtNb*16(A5),\1
ENDM
; call an AmigaOS function via LVO(A6) ; call an AmigaOS function via LVO(A6)
CALLLIB MACRO CALLLIB MACRO
JSR _LVO\1(A6) JSR _LVO\1(A6)
ENDM ENDM
; bsdsocket library stuff
; ported from the various C include headers
SOCK_STREAM EQU 1
PF_INET EQU 2
AF_INET EQU PF_INET
IPPROTO_TCP EQU 6
INADDR_ANY EQU 0 ; get the BSDSocket library ready for CALLLIB
LoadBSDSocketBaseFromA3 MACRO
FIONBIO EQU $8004667E
FIONASYNC EQU $8004667D
SOL_SOCKET EQU $FFFF
SO_REUSEADDR EQU $4
MAX_SOCKETS EQU 64
len_sockaddr_in EQU 16
sockaddr_in_sin_family EQU 1
sockaddr_in_sin_port EQU 2
sockaddr_in_sin_addr EQU 4
; global errors
Error_OtherError EQU -1
Error_LibraryNotOpen EQU -2
Error_PortOutOfRange EQU -11
Error_FdsetOutOfRange EQU -11
Error_UnableToBind EQU -12
; socket herrno and tag lists
; built from:
; * https://wiki.amigaos.net/amiga/autodocs/bsdsocket.doc.txt
; * https://github.com/deplinenoise/amiga-sdk/blob/master/netinclude/amitcp/socketbasetags.h
; * http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_2._guide/node012E.html
TAG_USER EQU (1<<31)
SBTF_REF EQU $8000
SBTB_CODE EQU 1
SBTS_CODE EQU $3FFF
SBTC_HERRNO EQU 6
HerrnoTag EQU (TAG_USER|SBTF_REF|((SBTC_HERRNO&SBTS_CODE)<<SBTB_CODE))
; wrap code that doesn't take arguments with these
PreserveStackInstruction MACRO
MOVEM.L A2-A6/D6-D7,-(SP)
ENDM
RestoreStackInstruction MACRO
MOVEM.L (SP)+,A2-A6/D6-D7
ENDM
; wrap code that takes arguments with these
PreserveStackFunction MACRO
MOVEM.L A2/A4-A6/D6-D7,-(SP)
ENDM
RestoreStackFunction MACRO
MOVEM.L (SP)+,A2/A4-A6/D6-D7
ENDM
LoadBSDSocketBase MACRO
MOVE.L BSDSocketBase-MB(A3),A6 MOVE.L BSDSocketBase-MB(A3),A6
ENDM ENDM
WithDataStorage MACRO
MOVE.L A3,-(SP)
Dload A3
ENDM
EndDataStorage MACRO
MOVE.L (SP)+,A3
ENDM
; fdset macros
EnsureValidFdset MACRO
CMP.L #MaxFd_sets,\1
BLT \2
MOVE.L #Error_FdsetOutOfRange,D3
RestoreStackFunction
Ret_Int
ENDM
EnsureValidFdsetBit MACRO
CMP.L #64,\1
BGE _EnsureValidFdsetBit_Fail\@
BRA \2
_EnsureValidFdsetBit_Fail\@:
MOVE.L \3,D3
RestoreStackFunction
Ret_Int
ENDM
LeaFdset MACRO
MOVE.L \1,-(SP)
Dlea fd_sets,\2 ; base of all, these are longs
ROL.L #3,\1 ; multiply by 8
ADD.L \1,\2 ; add to base of all
MOVE.L (SP)+,\1
ENDM
; LeaFdsetForBit fd_set reg,target address,target bit in address
LeaFdsetForBit MACRO
LeaFdset \1,\2 ; get fdset base address in \2
MOVEM.L D3-D4,-(SP)
MOVE.L \3,D3 ; Put target bit into D3
ROR.L #5,D3 ; lop off the first 5 bits
AND.L #$7,D3 ; only keep the top three
ROL.L #2,D3 ; multiply by 4
ADD.L D3,\2 ; add that value to the fdset address
MOVE.L \3,D4
AND.L #$1F,D4 ; only keep 0-31 in \3
MOVEQ #1,D3
ROL.L D4,D3 ; shift that bit left as many as target
MOVE.L D3,\3 ; put that in the target
MOVEM.L (SP)+,D3-D4
ENDM
; d0 = value to be divided
; d1 = divisor
; returns:
; d0 = divided value
; d1 = remainder
LongDivideD0ByD1 MACRO
CMP.L D0,D1
BMI _LongDivide_StartDivide\@
MOVE.L D0,D1
MOVEQ #0,D0
BRA _LongDivide_Skip\@
_LongDivide_StartDivide\@:
MOVEM.L D2-D4,-(SP)
MOVEQ #0,D2 ; remainder
MOVE.L #31,D3 ; bit tracking
; d4 tracks the status register
_LongDivide_ContinueDivide\@:
ASL.L #1,D0
SCS D4 ; bit that got rolled out
AND.L #1,D4
ROL.L #1,D2
ADD.L D4,D2 ; roll the value onto the remainder
MOVE.L D2,D4
SUB.L D1,D4
BMI _LongDivide_NotDivisible\@
ADDQ #1,D0
MOVE.L D4,D2
_LongDivide_NotDivisible\@:
DBRA D3,_LongDivide_ContinueDivide\@
MOVE.L D2,D1
MOVEM.L (SP)+,D2-D4
_LongDivide_Skip\@:
ENDM
EvenOutStringAddress MACRO
MOVE.W \1,\2
AND.W #$0001,\2
ADD.W \2,\1
ENDM
; check if we've opened the bsd socket library ; check if we've opened the bsd socket library
; we do this a lot, this could probably become something ; we do this a lot, this could probably become something
; we jsr to... ; we jsr to...
@ -458,16 +290,16 @@ End
CALLLIB OpenLibrary CALLLIB OpenLibrary
MOVE.L D0,BSDSocketBase-MB(A3) MOVE.L D0,BSDSocketBase-MB(A3)
BEQ _SocketLibraryOpen_Finish BEQ .Finish
; reserve ram for sockaddr_ins ; reserve ram for sockaddr_ins
MOVE.L #MAX_SOCKETS*len_sockaddr_in,D0 MOVE.L #MAX_SOCKETS*len_sockaddr_in,D0
Rjsr L_RamFast Rjsr L_RamFast
BEQ _SocketLibraryOpen_Finish BEQ .Finish
MOVE.L D0,sockaddr_ram-MB(A3) MOVE.L D0,sockaddr_ram-MB(A3)
_SocketLibraryOpen_Finish: .Finish:
MOVE.L BSDSocketBase-MB(A3),D3 MOVE.L BSDSocketBase-MB(A3),D3
RestoreStackInstruction RestoreStackInstruction
@ -513,7 +345,7 @@ _SocketLibraryOpen_Finish:
; ;
; Turn an IP address and port into a sockaddr_in strucure ; Turn an IP address and port into a sockaddr_in strucure
; ;
; d0 - address of sockaddr_in on success, -1 on failure ; d0 - 0 on success, -1 on failure
; - - - - - - - - ; - - - - - - - -
Lib_Def SocketIPAddressPortToSockaddr Lib_Def SocketIPAddressPortToSockaddr
@ -534,19 +366,11 @@ _ToSockaddr_PortOK:
MOVE.L sockaddr_ram-MB(A3),A0 MOVE.L sockaddr_ram-MB(A3),A0
ADD.L D3,A0 ; A0 contains our offset in ram ADD.L D3,A0 ; A0 contains our offset in ram
MOVEM.L A0-A3/D3,-(SP) MOVEM.L A1-A3/D3,-(SP)
MOVE.L D1,A1 ; ip string address MOVE.L D1,A1 ; ip string address
MOVE.W (A1)+,D3 ; string length MOVE.W (A1)+,D3 ; string length
BNE _ToSockaddr_StringHasLength
MOVEM.L (SP)+,A0-A3/D3
MOVEM.L (SP)+,A0/A3/D3
MOVE.L #-14,D0
RTS
_ToSockaddr_StringHasLength:
; temporarily store a null-terminated copy of the ip string in A0 ; temporarily store a null-terminated copy of the ip string in A0
MOVE.L A0,A2 MOVE.L A0,A2
SUBQ #1,D3 ; DBRA loop runs D3 + 1 times SUBQ #1,D3 ; DBRA loop runs D3 + 1 times
@ -573,15 +397,14 @@ _ToSockaddr_KeepCheckingString_2:
_ToSockaddr_ParseIPAddress: _ToSockaddr_ParseIPAddress:
Dload A3 Dload A3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB inet_addr CALLLIB inet_addr
_ToSockaddr_DoneParsing: _ToSockaddr_DoneParsing:
MOVEM.L (SP)+,A0-A3/D3 MOVEM.L (SP)+,A1-A3/D3
; create struct sockaddr_in ; create struct sockaddr_in
MOVE.B #len_sockaddr_in,(A0) MOVE.W #AF_INET,sockaddr_in_sin_family(A0)
MOVE.B #AF_INET,sockaddr_in_sin_family(A0)
MOVE.W D2,sockaddr_in_sin_port(A0) MOVE.W D2,sockaddr_in_sin_port(A0)
LEA sockaddr_in_sin_addr(A0),A3 LEA sockaddr_in_sin_addr(A0),A3
MOVE.L D0,(A3)+ MOVE.L D0,(A3)+
@ -617,7 +440,7 @@ _SocketCreateInetSocket_LibraryOpen:
MOVE.L #SOCK_STREAM,D1 MOVE.L #SOCK_STREAM,D1
MOVE.L #IPPROTO_TCP,D2 MOVE.L #IPPROTO_TCP,D2
Dload A3 Dload A3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB socket CALLLIB socket
MOVE.L D0,D3 MOVE.L D0,D3
@ -666,6 +489,7 @@ _SocketCreateInetSocket_Done:
Ret_Int Ret_Int
_SocketConnect_LibraryOpen: _SocketConnect_LibraryOpen:
MOVE.L D0,-(SP) ; socket id onto stack MOVE.L D0,-(SP) ; socket id onto stack
Rbsr L_SocketIPAddressPortToSockaddr Rbsr L_SocketIPAddressPortToSockaddr
@ -689,7 +513,7 @@ _SocketConnect_SockaddrIn:
; socket id is in D0 ; socket id is in D0
; sockaddr_in is in A0 ; sockaddr_in is in A0
MOVE.L #len_sockaddr_in,D1 ; len MOVE.L #len_sockaddr_in,D1 ; len
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB connect CALLLIB connect
MOVEM.L (SP)+,A0/A3 MOVEM.L (SP)+,A0/A3
@ -725,8 +549,8 @@ _SocketConnect_SockaddrIn:
_SocketSendString_LibraryOpen: _SocketSendString_LibraryOpen:
MOVEQ #0,D2 ; flags MOVEQ #0,D2 ; flags
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB send CALLLIB send
EndDataStorage EndDataStorage
@ -771,8 +595,8 @@ _SocketSendData_LibraryOpen:
_SocketSendData_NotNegative: _SocketSendData_NotNegative:
MOVEQ #0,D2 ; flags MOVEQ #0,D2 ; flags
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB send CALLLIB send
EndDataStorage EndDataStorage
@ -822,11 +646,11 @@ _SocketBind_SockaddrIn:
MOVE.L D0,A0 MOVE.L D0,A0
MOVE.L (SP)+,D0 MOVE.L (SP)+,D0
WithDataStorage WithDataStorageToA3
; socket id is in D0 ; socket id is in D0
; sockaddr_in is in A0 ; sockaddr_in is in A0
MOVE.L #len_sockaddr_in,D1 ; len MOVE.L #len_sockaddr_in,D1 ; len
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB bind CALLLIB bind
EndDataStorage EndDataStorage
@ -845,22 +669,22 @@ _SocketBind_SockaddrIn:
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Lib_Par SocketErrno Lib_Par SocketErrno
; - - - - - - - - - - - - - ; - - - - - - - - - - - - -
PreserveStackFunction PreserveStackInstruction
EnsureBSDSocketLibrary _SocketErrno_LibraryOpen EnsureBSDSocketLibrary _SocketErrno_LibraryOpen
RestoreStackFunction RestoreStackInstruction
Ret_Int Ret_Int
_SocketErrno_LibraryOpen: _SocketErrno_LibraryOpen:
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB Errno CALLLIB Errno
EndDataStorage EndDataStorage
MOVE.L D0,D3 MOVE.L D0,D3
RestoreStackFunction RestoreStackInstruction
RTS RTS
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -888,8 +712,8 @@ _SocketListen_LibraryOpen:
MOVE.L D3,D2 MOVE.L D3,D2
MOVEQ #5,D1 MOVEQ #5,D1
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB listen CALLLIB listen
EndDataStorage EndDataStorage
@ -924,10 +748,10 @@ _SocketAccept_LibraryOpen:
MOVE.L D3,D2 MOVE.L D3,D2
WithDataStorage WithDataStorageToA3
Dlea AcceptScratchArea,A0 Dlea AcceptScratchArea,A0
Dlea len_sockaddr_in_ptr,A1 Dlea len_sockaddr_in_ptr,A1
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB accept CALLLIB accept
EndDataStorage EndDataStorage
@ -990,11 +814,11 @@ _SocketSetNonblocking_IsBlocking:
_SocketSetNonblocking_Ioctl: _SocketSetNonblocking_Ioctl:
WithDataStorage WithDataStorageToA3
MOVE.L D1,IoctlSockOptScratch-MB(A3) MOVE.L D1,IoctlSockOptScratch-MB(A3)
Dlea IoctlSockOptScratch,A0 Dlea IoctlSockOptScratch,A0
MOVE.L #FIONBIO,D1 MOVE.L #FIONBIO,D1
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB IoctlSocket CALLLIB IoctlSocket
MOVE.L D0,D3 MOVE.L D0,D3
@ -1052,12 +876,12 @@ _SocketGetsockoptInt_LibraryOpen:
MOVE.L #SOL_SOCKET,D1 ; level MOVE.L #SOL_SOCKET,D1 ; level
MOVE.L A3,-(SP) MOVE.L A3,-(SP)
WithDataStorage WithDataStorageToA3
Dlea IoctlSockOptScratch,A0 ; optval Dlea IoctlSockOptScratch,A0 ; optval
MOVE.L #4,getsockopt_len-MB(A3) MOVE.L #4,getsockopt_len-MB(A3)
Dlea getsockopt_len,A1 Dlea getsockopt_len,A1
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB getsockopt CALLLIB getsockopt
EndDataStorage EndDataStorage
MOVE.L (SP)+,A3 MOVE.L (SP)+,A3
@ -1331,12 +1155,6 @@ _SocketSelect_PerformSelect
; - - - - - - - - - - - - - ; - - - - - - - - - - - - -
PreserveStackFunction PreserveStackFunction
EnsureBSDSocketLibrary _SocketGetHost_LibraryOpen
RestoreStackFunction
Ret_Int
_SocketGetHost_LibraryOpen:
MULU #len_sockaddr_in,D3 MULU #len_sockaddr_in,D3
Dload A0 Dload A0
MOVE.L sockaddr_ram-MB(A0),A0 MOVE.L sockaddr_ram-MB(A0),A0
@ -1357,13 +1175,6 @@ _SocketGetHost_LibraryOpen:
; - - - - - - - - - - - - - ; - - - - - - - - - - - - -
PreserveStackFunction PreserveStackFunction
EnsureBSDSocketLibrary _SocketGetPort_LibraryOpen
RestoreStackFunction
Ret_Int
_SocketGetPort_LibraryOpen:
MULU #len_sockaddr_in,D3 MULU #len_sockaddr_in,D3
Dload A0 Dload A0
MOVE.L sockaddr_ram-MB(A0),A0 MOVE.L sockaddr_ram-MB(A0),A0
@ -1384,17 +1195,15 @@ _SocketGetPort_LibraryOpen:
Lib_Par SocketInetNtoA Lib_Par SocketInetNtoA
; - - - - - - - - - - - - - ; - - - - - - - - - - - - -
PreserveStackFunction PreserveStackFunction
EnsureBSDSocketLibrary _SocketInetNtoa_LibraryOpen EnsureBSDSocketLibrary _SocketInetNtoA_LibraryOpen
MOVE.L ChVide(A5),D3
RestoreStackFunction RestoreStackFunction
Ret_String Ret_Int
_SocketInetNtoa_LibraryOpen: _SocketInetNtoA_LibraryOpen:
MOVE.L D3,D0 MOVE.L D3,D0
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB Inet_NtoA CALLLIB Inet_NtoA
EndDataStorage EndDataStorage
@ -1424,7 +1233,6 @@ _SocketInetNtoA_StringSizeLoop:
MOVE.W D4,(A0)+ ; length of string MOVE.W D4,(A0)+ ; length of string
SUBQ #1,D4 SUBQ #1,D4
_SocketInetNtoA_StringCopyLoop: _SocketInetNtoA_StringCopyLoop:
MOVE.B (A2,D4),(A0,D4) MOVE.B (A2,D4),(A0,D4)
DBRA D4,_SocketInetNtoA_StringCopyLoop DBRA D4,_SocketInetNtoA_StringCopyLoop
@ -1475,14 +1283,12 @@ _SocketRecvString_NotNegative:
_SocketRecvString_NotTooLong: _SocketRecvString_NotTooLong:
MOVE.L A3,-(SP) ; preserve A3 MOVE.L A3,-(SP) ; preserve A3
MOVE.L D0,-(SP) ; preserve D0 MOVE.L D0,-(SP) ; preserve D0
; reserve memory for recv buffer ; reserve memory for recv buffer
Rjsr L_RamFast ; D0 now contains memory pointer Rjsr L_RamFast ; D0 now contains memory pointer
BNE _SocketRecvString_BufferAllocated BNE _SocketRecvString_BufferAllocated
; reserve failed ; reserve failed
MOVE.L (SP)+,D0 MOVE.L (SP)+,D0
MOVE.L (SP)+,A3 MOVE.L (SP)+,A3
MOVE.L ChVide(A5),D3 ; empty string MOVE.L ChVide(A5),D3 ; empty string
@ -1496,12 +1302,10 @@ _SocketRecvString_BufferAllocated:
MOVEQ #0,D2 ; flags MOVEQ #0,D2 ; flags
MOVEM.L A0-A1/D1,-(SP) MOVEM.L A0-A1/D1,-(SP)
WithDataStorageToA3
WithDataStorage LoadBSDSocketBaseFromA3
LoadBSDSocketBase
CALLLIB recv ; D0 has received length or -1 CALLLIB recv ; D0 has received length or -1
EndDataStorage EndDataStorage
MOVEM.L (SP)+,A0-A1/D1 MOVEM.L (SP)+,A0-A1/D1
; did we receive data? if we didn't get a single byte, we're done ; did we receive data? if we didn't get a single byte, we're done
@ -1512,7 +1316,6 @@ _SocketRecvString_BufferAllocated:
MOVE.L D1,D0 MOVE.L D1,D0
MOVE.L A0,A1 MOVE.L A0,A1
Rjsr L_RamFree Rjsr L_RamFree
MOVE.L (SP)+,A3 MOVE.L (SP)+,A3
MOVE.L ChVide(A5),D3 MOVE.L ChVide(A5),D3
@ -1520,6 +1323,7 @@ _SocketRecvString_BufferAllocated:
Ret_String Ret_String
; TODO received data is wrong somewhere ; TODO received data is wrong somewhere
_SocketRecvString_DataReceived: _SocketRecvString_DataReceived:
; D0 contains socket receive length ; D0 contains socket receive length
@ -1551,7 +1355,7 @@ _SocketRecvString_CopyData:
MOVE.L A0,-(SP) MOVE.L A0,-(SP)
MOVE.L A3,A1 MOVE.L A3,A1
Rjsr L_RamFree Rjsr L_RamFree
MOVE.L (SP)+,D3 ; string return MOVE.L (SP)+,D3
MOVE.L (SP)+,A3 MOVE.L (SP)+,A3
RestoreStackFunction RestoreStackFunction
@ -1590,8 +1394,8 @@ _SocketRecvData_LibraryOpen:
Ret_Int Ret_Int
_SocketRecvData_PositiveLength: _SocketRecvData_PositiveLength:
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB recv ; D0 has received length or -1 CALLLIB recv ; D0 has received length or -1
EndDataStorage EndDataStorage
@ -1600,8 +1404,6 @@ _SocketRecvData_PositiveLength:
RestoreStackFunction RestoreStackFunction
Ret_Int Ret_Int
; actually close the library ; actually close the library
Lib_Def DoSocketLibraryClose Lib_Def DoSocketLibraryClose
@ -1616,7 +1418,6 @@ _SocketRecvData_PositiveLength:
CLR.L sockaddr_ram-MB(A3) ; prevent double free CLR.L sockaddr_ram-MB(A3) ; prevent double free
_DoSocketLibraryClose_CloseLibrary: _DoSocketLibraryClose_CloseLibrary:
MOVE.L BSDSocketBase-MB(A3),D0 MOVE.L BSDSocketBase-MB(A3),D0
BEQ _DoSocketLibraryClose_Skip BEQ _DoSocketLibraryClose_Skip
@ -1673,7 +1474,7 @@ _SocketWaitAsyncWriting_LibraryOpen:
Rbsr L_MicrosecondsToTimeval ; A3 contains timeval Rbsr L_MicrosecondsToTimeval ; A3 contains timeval
Dload A4 Dload A4
MOVEM.L D0,-(SP) MOVE.L D0,-(SP)
; set up WaitSelect ; set up WaitSelect
MOVEQ #0,D1 MOVEQ #0,D1
LeaFdset D1,A1 ; write fdset LeaFdset D1,A1 ; write fdset
@ -1695,7 +1496,7 @@ _SocketWaitAsyncWriting_LibraryOpen:
TST.L D0 TST.L D0
BEQ _SocketWaitAsyncWriting_Timeout BEQ _SocketWaitAsyncWriting_Timeout
BMI _SocketWaitAsyncWriting_Error BMI _SocketWaitAsyncWriting_Error
MOVEM.L (SP)+,D0 ; D0 contains socket again MOVE.L (SP)+,D0 ; D0 contains socket again
Dload A4 Dload A4
; a socket became interesting, check the Fdset ; a socket became interesting, check the Fdset
@ -1721,19 +1522,19 @@ _SocketWaitAsyncWriting_CheckSockopt:
MOVE.L A3,-(SP) MOVE.L A3,-(SP)
WithDataStorage WithDataStorageToA3
Dlea IoctlSockOptScratch,A0 ; optval Dlea IoctlSockOptScratch,A0 ; optval
MOVE.L #4,getsockopt_len-MB(A3) MOVE.L #4,getsockopt_len-MB(A3)
Dlea getsockopt_len,A1 Dlea getsockopt_len,A1
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB getsockopt CALLLIB getsockopt
EndDataStorage EndDataStorage
MOVE.L (SP)+,A3 MOVE.L (SP)+,A3
TST.L D0 TST.L D0
BMI _SocketWaitAsyncWriting_Error2 BMI _SocketWaitAsyncWriting_Error
Dlea IoctlSockOptScratch,A0 Dlea IoctlSockOptScratch,A0
MOVE.L (A0),D0 MOVE.L (A0),D0
@ -1755,7 +1556,6 @@ _SocketWaitAsyncWriting_Ready:
_SocketWaitAsyncWriting_Error: _SocketWaitAsyncWriting_Error:
MOVE.L (SP)+,D1 MOVE.L (SP)+,D1
_SocketWaitAsyncWriting_Error2:
MOVEM.L (SP)+,A3-A4 MOVEM.L (SP)+,A3-A4
MOVE.L #-1,D3 MOVE.L #-1,D3
@ -1837,6 +1637,7 @@ _SocketWaitAsyncReading_LibraryOpen:
BMI _SocketWaitAsyncReading_Done BMI _SocketWaitAsyncReading_Done
MOVE.L (SP)+,D0 ; D0 contains socket again MOVE.L (SP)+,D0 ; D0 contains socket again
;Dload A4
; a socket became interesting, check the Fdset ; a socket became interesting, check the Fdset
MOVE.L D0,D3 ; socket in D3 MOVE.L D0,D3 ; socket in D3
MOVEQ #0,D1 ; fdset in D1 MOVEQ #0,D1 ; fdset in D1
@ -1931,12 +1732,12 @@ _SocketReuseAddr_LibraryOpen:
MOVE.L #SOL_SOCKET,D1 ; Level MOVE.L #SOL_SOCKET,D1 ; Level
WithDataStorage WithDataStorageToA3
Dlea IoctlSockOptScratch,A0 ; optval Dlea IoctlSockOptScratch,A0 ; optval
MOVE.L D3,A0 MOVE.L D3,A0
MOVEQ #4,D3 MOVEQ #4,D3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB setsockopt CALLLIB setsockopt
EndDataStorage EndDataStorage
@ -1947,46 +1748,44 @@ _SocketReuseAddr_LibraryOpen:
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; =Dns Get Address By Name$(Name String) ; =Dns Get Address By Name$(Name String)
; ;
; Convert a host name to an IP address ; Get the status of a socket
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Lib_Par DnsGetHostAddressByName Lib_Par DnsGetHostAddressByName
PreserveStackFunction PreserveStackFunction
EnsureBSDSocketLibrary _DnsGetHostAddressByName_LibraryOpen EnsureBSDSocketLibrary .LibraryOpen
MOVE.L ChVide(A5),D3 MOVE.L ChVide(A5),D3
RestoreStackFunction RestoreStackFunction
Ret_String Ret_String
_DnsGetHostAddressByName_LibraryOpen: .LibraryOpen:
; string so you need demande, hichaine, and chvide ; string so you need demande, hichaine, and chvide
MOVE.L D3,A0 ; name MOVE.L D3,A0 ; name
MOVEQ #0,D0
MOVE.W (A0)+,D0 ; d0 contains length MOVE.W (A0)+,D0 ; d0 contains length
MOVE.L D0,D1 ; d1 also has length MOVE.L D0,D1 ; d1 also has length
MOVE.L D0,D2 ; d2 also has length MOVE.L D0,D2 ; d2 also has length
Rjsr L_RamFast ; d0 contains address Rjsr L_RamFast ; d0 contains address
BNE _DnsGetHostAddressByName_StringRamAllocated BNE .StringRamAllocated
MOVE.L ChVide(A5),D3 MOVE.L ChVide(A5),D3
RestoreStackFunction RestoreStackFunction
Ret_String Ret_String
_DnsGetHostAddressByName_StringRamAllocated: .StringRamAllocated:
MOVE.L D0,A1 ; a1 contains address MOVE.L D0,A1 ; a1 contains address
SUBQ #1,D1 ; reduce by one for DBRA SUBQ #1,D1 ; reduce by one for DBRA
.KeepCopyingAMOSString
_DnsGetHostAddressByName_KeepCopyingAMOSString:
MOVE.B (A0)+,(A1)+ ; byte copy MOVE.B (A0)+,(A1)+ ; byte copy
DBRA D1,_DnsGetHostAddressByName_KeepCopyingAMOSString ; keep copying DBRA D1,.KeepCopyingAMOSString ; keep copying
MOVE.B #0,(A1)+ ; null terminate string MOVE.B #0,(A1)+ ; null terminate string
MOVE.L D0,A0 ; first param of gethostbyname MOVE.L D0,A0 ; first param of gethostbyname
MOVEM.L A0/D2,-(SP) MOVEM.L A0/D2,-(SP)
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB gethostbyname CALLLIB gethostbyname
EndDataStorage EndDataStorage
MOVEM.L (SP)+,A0/D2 MOVEM.L (SP)+,A0/D2
@ -1999,21 +1798,21 @@ _DnsGetHostAddressByName_KeepCopyingAMOSString:
MOVE.L (SP)+,D0 MOVE.L (SP)+,D0
TST.L D0 TST.L D0
BNE _DnsGetHostAddressByName_GetIPAddress BNE .GetIPAddress
RestoreStackFunction RestoreStackFunction
MOVE.L ChVide(A5),D3 MOVE.L ChVide(A5),D3
Ret_String Ret_String
_DnsGetHostAddressByName_GetIPAddress: .GetIPAddress:
MOVE.L D0,A0 MOVE.L D0,A0
MOVE.L 16(A0),A1 ; **h_addr_list MOVE.L 16(A0),A1 ; **h_addr_list
MOVE.L (A1),A1 ; *h_addr_list MOVE.L (A1),A1 ; *h_addr_list
MOVE.L (A1),D0 ; h_addr_list[0] MOVE.L (A1),D0 ; h_addr_list[0]
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB Inet_NtoA CALLLIB Inet_NtoA
EndDataStorage EndDataStorage
@ -2021,32 +1820,27 @@ _DnsGetHostAddressByName_GetIPAddress:
MOVE.L A2,-(SP) MOVE.L A2,-(SP)
MOVEQ #0,D3 MOVEQ #0,D3
_DnsGetHostAddressByName_GetIPAddressLength: .GetIPAddressLength:
ADDQ #1,D3 ADDQ #1,D3
TST.B (A2)+ TST.B (A2)+
BNE _DnsGetHostAddressByName_GetIPAddressLength BNE .GetIPAddressLength
MOVE.L (SP)+,A2 MOVE.L (SP)+,A2
SUBQ #1,D3
MOVE.L D3,D4 MOVE.L D3,D4
AND.W #$FFFE,D3 AND.W #$FFFE,D3
ADDQ #2,D3 ADDQ #2,D3
Rjsr L_Demande ; string is in A0/A1 Rjsr L_Demande ; string is in A0/A1
LEA 2(A0,D3.W),A1 LEA 2(A0,D3.W),A1
MOVE.L A1,HiChaine(A5) MOVE.L A1,HiChaine(A5)
MOVE.L A0,A1 MOVE.L A0,D3
MOVE.W D4,(A1)+
MOVE.W D4,(A0)+
SUBQ #1,D4 SUBQ #1,D4
_DnsGetHostAddressByName_KeepCopying: .KeepCopying:
MOVE.B (A2)+,(A1)+ MOVE.B (A2,D4),(A0,D4)
DBRA D4,_DnsGetHostAddressByName_KeepCopying DBRA D4,.KeepCopying
MOVE.L A0,D3
RestoreStackFunction RestoreStackFunction
@ -2061,7 +1855,7 @@ _DnsGetHostAddressByName_KeepCopying:
; - - - - - - - - - - - - - ; - - - - - - - - - - - - -
PreserveStackFunction PreserveStackFunction
MOVE.L D3,D4 ; milliseconts MOVE.L D3,D4 ; milliseconds
MOVE.L (A3)+,D0 ; socket id MOVE.L (A3)+,D0 ; socket id
EnsureBSDSocketLibrary _SocketSetTimeout_LibraryOpen EnsureBSDSocketLibrary _SocketSetTimeout_LibraryOpen
@ -2083,7 +1877,7 @@ _SocketSetTimeout_LibraryOpen:
MOVE.L (A0)+,(A1)+ MOVE.L (A0)+,(A1)+
SUB.L #8,A1 ; go back SUB.L #8,A1 ; go back
WithDataStorage WithDataStorageToA3
; socket is d0 ; socket is d0
MOVE.L #SOL_SOCKET,D1 ; Level MOVE.L #SOL_SOCKET,D1 ; Level
MOVE.L #$1005,D2 ; SO_SNDTIMEO MOVE.L #$1005,D2 ; SO_SNDTIMEO
@ -2091,7 +1885,7 @@ _SocketSetTimeout_LibraryOpen:
MOVEQ #8,D3 MOVEQ #8,D3
MOVEM.L D0/A0,-(SP) MOVEM.L D0/A0,-(SP)
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB setsockopt CALLLIB setsockopt
TST.L D0 TST.L D0
@ -2102,7 +1896,7 @@ _SocketSetTimeout_LibraryOpen:
MOVE.L #$1006,D2 ; SO_RCVTIMEO MOVE.L #$1006,D2 ; SO_RCVTIMEO
MOVEQ #8,D3 MOVEQ #8,D3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB setsockopt CALLLIB setsockopt
EndDataStorage EndDataStorage
@ -2129,17 +1923,17 @@ _SocketSetTimeout_Fail:
Lib_Par SocketCloseSocket Lib_Par SocketCloseSocket
; - - - - - - - - - - - - - ; - - - - - - - - - - - - -
PreserveStackFunction PreserveStackFunction
EnsureBSDSocketLibrary _SocketCloseSocket_LibraryOpen EnsureBSDSocketLibrary .LibraryOpen
RestoreStackFunction RestoreStackFunction
Ret_Int Ret_Int
_SocketCloseSocket_LibraryOpen: .LibraryOpen:
MOVE.L D3,D0 MOVE.L D3,D0
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB CloseSocket CALLLIB CloseSocket
EndDataStorage EndDataStorage
@ -2156,12 +1950,7 @@ _SocketCloseSocket_LibraryOpen:
Lib_Par SocketHerrno Lib_Par SocketHerrno
; - - - - - - - - - - - - - ; - - - - - - - - - - - - -
PreserveStackFunction PreserveStackFunction
EnsureBSDSocketLibrary _SocketHerrno_LibraryOpen
RestoreStackFunction
Ret_Int
_SocketHerrno_LibraryOpen:
; set up tag list memory and place for herrno to go ; set up tag list memory and place for herrno to go
Dlea AcceptScratchArea,A0 Dlea AcceptScratchArea,A0
MOVE.L A0,A2 MOVE.L A0,A2
@ -2174,13 +1963,13 @@ _SocketHerrno_LibraryOpen:
MOVE.L 0,(A0)+ MOVE.L 0,(A0)+
MOVE.L A2,A0 MOVE.L A2,A0
WithDataStorage WithDataStorageToA3
LoadBSDSocketBase LoadBSDSocketBaseFromA3
CALLLIB SocketBaseTagList CALLLIB SocketBaseTagList
EndDataStorage EndDataStorage
TST.L D0 TST.L D0
BEQ _SocketHerrno_success BEQ .success
; failed ; failed
MOVE.L #-1,D3 MOVE.L #-1,D3
@ -2188,7 +1977,7 @@ _SocketHerrno_LibraryOpen:
RestoreStackFunction RestoreStackFunction
Ret_Int Ret_Int
_SocketHerrno_success: .success
MOVE.L (A1),D3 MOVE.L (A1),D3
RestoreStackFunction RestoreStackFunction

42
src/Constants.s Normal file
View File

@ -0,0 +1,42 @@
; bsdsocket library stuff
; ported from the various C include headers
SOCK_STREAM EQU 1
PF_INET EQU 2
AF_INET EQU PF_INET
IPPROTO_TCP EQU 6
INADDR_ANY EQU 0
FIONBIO EQU $8004667E
FIONASYNC EQU $8004667D
SOL_SOCKET EQU $FFFF
SO_REUSEADDR EQU $4
MAX_SOCKETS EQU 64
len_sockaddr_in EQU 16
sockaddr_in_sin_family EQU 0
sockaddr_in_sin_port EQU 2
sockaddr_in_sin_addr EQU 4
; global errors
Error_OtherError EQU -1
Error_LibraryNotOpen EQU -2
Error_PortOutOfRange EQU -11
Error_FdsetOutOfRange EQU -11
Error_UnableToBind EQU -12
; socket herrno and tag lists
; built from:
; * https://wiki.amigaos.net/amiga/autodocs/bsdsocket.doc.txt
; * https://github.com/deplinenoise/amiga-sdk/blob/master/netinclude/amitcp/socketbasetags.h
; * http://amigadev.elowar.com/read/ADCD_2.1/Includes_and_Autodocs_2._guide/node012E.html
TAG_USER EQU (1<<31)
SBTF_REF EQU $8000
SBTB_CODE EQU 1
SBTS_CODE EQU $3FFF
SBTC_HERRNO EQU 6
HerrnoTag EQU (TAG_USER|SBTF_REF|((SBTC_HERRNO&SBTS_CODE)<<SBTB_CODE))

43
src/LongDivide.s Normal file
View File

@ -0,0 +1,43 @@
; d0 = value to be divided
; d1 = divisor
; returns:
; d0 = divided value
; d1 = remainder
LongDivideD0ByD1 MACRO
CMP.L D0,D1
BMI _LongDivide_StartDivide\@
MOVE.L D0,D1
MOVEQ #0,D0
BRA _LongDivide_Skip\@
_LongDivide_StartDivide\@:
MOVEM.L D2-D4,-(SP)
MOVEQ #0,D2 ; remainder
MOVE.L #31,D3 ; bit tracking
; d4 tracks the status register
_LongDivide_ContinueDivide\@:
ASL.L #1,D0
SCS D4 ; bit that got rolled out
AND.L #1,D4
ROL.L #1,D2
ADD.L D4,D2 ; roll the value onto the remainder
MOVE.L D2,D4
SUB.L D1,D4
BMI _LongDivide_NotDivisible\@
ADDQ #1,D0
MOVE.L D4,D2
_LongDivide_NotDivisible\@:
DBRA D3,_LongDivide_ContinueDivide\@
MOVE.L D2,D1
MOVEM.L (SP)+,D2-D4
_LongDivide_Skip\@:
ENDM

View File

@ -2,19 +2,12 @@ echo "***Assembling AMOSPro_BSDSocket.Lib"
assign AMOSPro_System: SYS:Development/AMOS_Pro assign AMOSPro_System: SYS:Development/AMOS_Pro
assign AMOSPro_Sources: amos-pro-bsdsocket-extension:stuff/AMOS-Professional-Official assign AMOSPro_Sources: amos-pro-bsdsocket-extension:stuff/AMOS-Professional-Official
AMOSPro_Sources:c/Library_Digest BSDSocket.s AMOSPro_Sources:c/Library_Digest BSDSocket.s
AMOSPro_Sources:c/Genam FROM BSDSocket.s TO AMOSPro_BSDSocket.Lib -e ExtNb=18-1 AMOSPro_Sources:c/Genam FROM BSDSocket.s TO AMOSPro_BSDSocket.Lib
;delete >NIL: BSDSocket_Labels.s ;delete >NIL: BSDSocket_Labels.s
;delete >NIL: BSDSocket_Size.s ;delete >NIL: BSDSocket_Size.s
FAILAT 21 FAILAT 21
copy AMOSPro_System:APSystem/AMOSPro_BSDSocket.lib AMOSPro_System:APSystem/AMOSPro_BSDSocket.lib.bak copy AMOSPro_System:APSystem/AMOSPro_BSDSocket.lib AMOSPro_System:APSystem/AMOSPro_BSDSocket.lib.bak
FAILAT 10 FAILAT 10
copy AMOSPro_BSDSocket.Lib AMOSPro_System:APSystem/ copy AMOSPro_BSDSocket.Lib AMOSPro_System:APSystem/
apcmp "/test/TestSuite.amos" inclib ;use an amos file here that includes the plugin to quickly build a test program
;apcmp "aqua_test_plugin.amos" inclib
echo "Build for slot 9"
AMOSPro_Sources:c/Genam FROM BSDSocket.s TO AMOSPro_BSDSocket_Slot9.Lib -e ExtNb=9-1
echo "Build for slot 11"
AMOSPro_Sources:c/Genam FROM BSDSocket.s TO AMOSPro_BSDSocket_Slot11.Lib -e ExtNb=11-1
echo "Build for slot 17"
AMOSPro_Sources:c/Genam FROM BSDSocket.s TO AMOSPro_BSDSocket_Slot17.Lib -e ExtNb=17-1

48
src/fd_set.s Normal file
View File

@ -0,0 +1,48 @@
; fdset macros
EnsureValidFdset MACRO
CMP.L #MaxFd_sets,\1
BLT \2
MOVE.L #Error_FdsetOutOfRange,D3
RestoreStackFunction
Ret_Int
ENDM
EnsureValidFdsetBit MACRO
CMP.L #64,\1
BGE _EnsureValidFdsetBit_Fail\@
BRA \2
_EnsureValidFdsetBit_Fail\@:
MOVE.L \3,D3
RestoreStackFunction
Ret_Int
ENDM
; LeaFdset fd_set reg,target
LeaFdset MACRO
MOVE.L \1,-(SP)
Dlea fd_sets,\2 ; base of all, these are longs
ROL.L #3,\1 ; multiply by 8
ADD.L \1,\2 ; add to base of all
MOVE.L (SP)+,\1
ENDM
; LeaFdsetForBit fd_set reg,target address,target bit in address
LeaFdsetForBit MACRO
LeaFdset \1,\2 ; get fdset base address in \2
MOVEM.L D3-D4,-(SP)
MOVE.L \3,D3 ; Put target bit into D3
ROR.L #5,D3 ; lop off the first 5 bits
AND.L #$7,D3 ; only keep the top three
ROL.L #2,D3 ; multiply by 4
ADD.L D3,\2 ; add that value to the fdset address
MOVE.L \3,D4
AND.L #$1F,D4 ; only keep 0-31 in \3
MOVEQ #1,D3
ROL.L D4,D3 ; shift that bit left as many as target
MOVE.L D3,\3 ; put that in the target
MOVEM.L (SP)+,D3-D4
ENDM

Binary file not shown.

Binary file not shown.

View File

@ -1,354 +0,0 @@
' BSD Socket Extension Test Suite
'
' Exercise all known functionality of the extension and write
' a report file detailing the result.
Screen Open 0,640,200,4,Hires
_FILE_HANDLE=1
Dim _CONTEXT$(10)
_CONTEXT_INDEX=0
Global _FILE_HANDLE,_CONTEXT$(),_CONTEXT_INDEX
Procedure _ADD_TO_REPORT[MESSAGE$]
_CONTEXT_STRING$=""
For I=0 To _CONTEXT_INDEX-1
_CONTEXT_STRING$=_CONTEXT_STRING$+_CONTEXT$(I)
If I<>(_CONTEXT_INDEX-1)
_CONTEXT_STRING$=_CONTEXT_STRING$+"/"
End If
Next I
_OUTPUT$="["+_CONTEXT_STRING$+"] "+MESSAGE$
Print #_FILE_HANDLE,_OUTPUT$
Print _OUTPUT$
' ensure line is printed on screen to catch crashes
Wait Vbl
End Proc
Procedure _BEGIN_CONTEXT[NAME$]
_CONTEXT$(_CONTEXT_INDEX)=NAME$
_CONTEXT_INDEX=_CONTEXT_INDEX+1
End Proc
Procedure _END_CONTEXT
_CONTEXT_INDEX=_CONTEXT_INDEX-1
End Proc
Open Out _FILE_HANDLE,"report.txt"
_BEGIN_CONTEXT["Socket Library Open"]
_BEGIN_CONTEXT["Open Library"]
_LIBRARY_ADDRESS=Socket Library Open
_ADD_TO_REPORT[Str$(_LIBRARY_ADDRESS)]
_END_CONTEXT
If _LIBRARY_ADDRESS=0
_ADD_TO_REPORT["bsdsocket.library not available, ending tests"]
_END_CONTEXT
Goto _FINISH_SUITE
End If
_BEGIN_CONTEXT["Double open"]
_NEW_LIBRARY_ADDRESS=Socket Library Open
_ADD_TO_REPORT[Str$(_NEW_LIBRARY_ADDRESS)]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket Create Inet Socket"]
SOCKET=Socket Create Inet Socket
_ADD_TO_REPORT[Str$(SOCKET)]
_END_CONTEXT
_BEGIN_CONTEXT["Socket Reuse Addr"]
RESULT=Socket Reuse Addr(SOCKET)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Socket Set Nonblocking"]
_BEGIN_CONTEXT["False"]
RESULT=Socket Set Nonblocking(SOCKET,False)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["True"]
RESULT=Socket Set Nonblocking(SOCKET,True)
_ADD_TO_REPORT[Str$(RESULT)]
_ADD_TO_REPORT["Preserving this state for rest of tests"]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Dns Get Address By Name$"]
_BEGIN_CONTEXT["Bad domain name"]
IP$=Dns Get Address By Name$("u8dsf93jsdfoiodsoi.sdfjdsoifueru.sadfasdsdasd")
Print IP$
_ADD_TO_REPORT[IP$]
_END_CONTEXT
_BEGIN_CONTEXT["localhost"]
IP$=Dns Get Address By Name$("localhost")
_ADD_TO_REPORT[IP$]
_END_CONTEXT
_BEGIN_CONTEXT["aminet.net"]
IP$=Dns Get Address By Name$("aminet.net")
Print IP$
_ADD_TO_REPORT[IP$]
_ADD_TO_REPORT["Using this IP address for connection tests"]
_END_CONTEXT
_BEGIN_CONTEXT["Returned string can be manipulated"]
_ADD_TO_REPORT["Cat"+IP$+"Dog"]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket Connect"]
_BEGIN_CONTEXT["port too high"]
RESULT=Socket Connect(SOCKET To IP$,999999)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["blank ip"]
RESULT=Socket Connect(SOCKET To "",80)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["invalid ip -- requires reopening failed socket"]
RESULT=Socket Connect(SOCKET To "999.999.999.999",80)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Socket Close Socket"]
RESULT=Socket Close Socket(SOCKET)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
' re-set up this socket after a failed connection
SOCKET=Socket Create Inet Socket
_=Socket Set Nonblocking(SOCKET,True)
_BEGIN_CONTEXT["aminet IP ("+IP$+") from above"]
RESULT=Socket Connect(SOCKET To IP$,80)
_ADD_TO_REPORT[Str$(RESULT)+" (ok to be -1, will Wait Async Writing next)"]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket Wait Async Writing"]
_BEGIN_CONTEXT["With unconnected socket"]
OTHER_SOCKET=Socket Create Inet Socket
_=Socket Set Nonblocking(OTHER_SOCKET,True)
_BEGIN_CONTEXT["2 second timeout"]
RESULT=Socket Wait Async Writing(OTHER_SOCKET,2000)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Zero timeout"]
RESULT=Socket Wait Async Writing(OTHER_SOCKET,0)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Connected socket"]
_BEGIN_CONTEXT["Two second timeout"]
RESULT=Socket Wait Async Writing(SOCKET,2000)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Zero timeout"]
RESULT=Socket Wait Async Writing(SOCKET,0)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Attempt to get actual connection"]
For TRIES=0 To 10
RESULT=Socket Wait Async Writing(SOCKET,500)
_ADD_TO_REPORT[Str$(RESULT)]
If RESULT>0
Exit
End If
Next TRIES
_END_CONTEXT
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket Get Host"]
_BEGIN_CONTEXT["socket id too high"]
RESULT=Socket Get Host(999999)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["socket id is valid"]
RESULT=Socket Get Host(SOCKET)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket Get Port"]
_BEGIN_CONTEXT["socket id too high"]
RESULT=Socket Get Port(999999)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["socket id is valid"]
RESULT=Socket Get Port(SOCKET)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket Inet Ntoa$"]
_BEGIN_CONTEXT["Use the socket host"]
RESULT$=Socket Inet Ntoa$(Socket Get Host(SOCKET))
_ADD_TO_REPORT[RESULT$]
_END_CONTEXT
_BEGIN_CONTEXT["String can be manipulated"]
_ADD_TO_REPORT["Cat"+RESULT$+"Dog"]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket Send and Socket Send$"]
HTTP_REQUEST_HEADERS$="GET / HTTP/1.0"+Chr$(10)+"Host: amiga"+Chr$(10)+Chr$(10)
_BEGIN_CONTEXT["Socket send$ first half"]
FIRST_HALF$=Left$(HTTP_REQUEST_HEADERS$,10)
RESULT=Socket Send$(SOCKET,FIRST_HALF$)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Socket send second half"]
SECOND_HALF_START=Varptr(HTTP_REQUEST_HEADERS$)+10
SECOND_HALF_LENGTH=Len(HTTP_REQUEST_HEADERS$)-10
RESULT=Socket Send(SOCKET,SECOND_HALF_START,SECOND_HALF_LENGTH)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket wait Async Reading"]
_BEGIN_CONTEXT["With unconnected socket"]
_BEGIN_CONTEXT["2 second timeout"]
RESULT=Socket Wait Async Reading(OTHER_SOCKET,2000)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Zero timeout"]
RESULT=Socket Wait Async Reading(OTHER_SOCKET,0)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["With aminet socket"]
_BEGIN_CONTEXT["2 second timeout"]
RESULT=Socket Wait Async Reading(SOCKET,2000)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Zero timeout"]
RESULT=Socket Wait Async Reading(SOCKET,0)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_END_CONTEXT
_END_CONTEXT
'Goto _FINISH_SUITE
_BEGIN_CONTEXT["Socket Recv$ and Socket Recv"]
_BEGIN_CONTEXT["Socket Recv$"]
_BEGIN_CONTEXT["Read 20 characters"]
RESULT$=Socket Recv$(SOCKET,20)
_ADD_TO_REPORT[RESULT$]
_END_CONTEXT
_BEGIN_CONTEXT["String can be manipulated"]
_ADD_TO_REPORT["Cat"+RESULT$+"Dog"]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Socket Read"]
Reserve As Work 20,20
_BEGIN_CONTEXT["Read 20 bytes"]
RESULT=Socket Recv(SOCKET To Start(20),20)
_ADD_TO_REPORT[Str$(RESULT)]
_END_CONTEXT
_BEGIN_CONTEXT["Data was read"]
BASE$="12345678901234567890"
For I=0 To 19
Mid$(BASE$,I+1,1)=Chr$(Peek(Start(20)+I))
Next I
_ADD_TO_REPORT[BASE$]
_END_CONTEXT
Erase 20
_END_CONTEXT
_END_CONTEXT
_FINISH_SUITE:
_BEGIN_CONTEXT["Socket Library Close"]
_BEGIN_CONTEXT["Close"]
Socket Library Close
_ADD_TO_REPORT["Success"]
_END_CONTEXT
_BEGIN_CONTEXT["Double close"]
Socket Library Close
_ADD_TO_REPORT["Success"]
_END_CONTEXT
_END_CONTEXT
_BEGIN_CONTEXT["Call functions with library closed"]
_=Socket Set Nonblocking(0,True)
_ADD_TO_REPORT["Socket Set Nonblocking"]
_=Socket Reuse Addr(0)
_ADD_TO_REPORT["Socket Reuse Addr"]
_=Socket Create Inet Socket
_ADD_TO_REPORT["Socket Create Inet Socket"]
_=Socket Connect(0 To "",0)
_ADD_TO_REPORT["Socket Connect"]
_=Socket Bind(0 To "",0)
_ADD_TO_REPORT["Socket Bind"]
_=Socket Listen(0)
_ADD_TO_REPORT["Socket Listen"]
_=Socket Accept(0)
_ADD_TO_REPORT["Socket Accept"]
_=Socket Wait Async Reading(0,0)
_ADD_TO_REPORT["Socket Wait Async Reading"]
_=Socket Wait Async Writing(0,0)
_ADD_TO_REPORT["Socket Wait Async Writing"]
_=Socket Set Timeout(0,0)
_ADD_TO_REPORT["Socket Set Timeout"]
_=Socket Close Socket(0)
_ADD_TO_REPORT["Socket Close Socket"]
_=Socket Send$(0,"")
_ADD_TO_REPORT["Socket Send$"]
_=Socket Send(0,0,0)
_ADD_TO_REPORT["Socket Send"]
_$=Socket Recv$(0,0)
_ADD_TO_REPORT["Socket Recv$"]
_=Socket Recv(0 To 0,0)
_ADD_TO_REPORT["Socket Recv"]
_=Socket Get Host(0)
_ADD_TO_REPORT["Socket Get Host"]
_=Socket Get Port(0)
_ADD_TO_REPORT["Socket Get Port"]
_$=Socket Inet Ntoa$(0)
_ADD_TO_REPORT["Socket Inet Ntoa$"]
_=Socket Errno
_ADD_TO_REPORT["Socket Errno"]
_=Socket Herrno
_ADD_TO_REPORT["Socket Herrno"]
_$=Dns Get Address By Name$("")
_ADD_TO_REPORT["Dns Get Address By Name$"]
_END_CONTEXT
Close 1