Difference between revisions of "Software"

From Spectrum
Jump to navigation Jump to search
Line 6: Line 6:
* [[Calling Spectranet ROM routines]] - How to access the ROM.
* [[Calling Spectranet ROM routines]] - How to access the ROM.


== Library code ==
== Library Reference ==
 
=== The socket library ===


The most important part is probably the socket library. This will provide a subset of the BSD socket library. The plans are for three equivalent libraries: an assembler library, a C library based around the [http://www.z88dk.org Z88DK], and a BASIC library. The C library will essentially be a wrapper around the assembler library (with a few extra pieces of error checking, which for asm users will be left up to the programmer).
The most important part is probably the socket library. This will provide a subset of the BSD socket library. The plans are for three equivalent libraries: an assembler library, a C library based around the [http://www.z88dk.org Z88DK], and a BASIC library. The C library will essentially be a wrapper around the assembler library (with a few extra pieces of error checking, which for asm users will be left up to the programmer).
Line 15: Line 17:


* [[socket]] (HLCALL 0x3E00) - Creates a new socket.
* [[socket]] (HLCALL 0x3E00) - Creates a new socket.
* bind - Binds a name to a socket (i.e. sets the port).
* [[bind]] - Binds a name to a socket (i.e. sets the port).
* listen - Tells an open socket that it should listen for incoming connections.
* [[listen]] - Tells an open socket that it should listen for incoming connections.
* accept - Accepts a connection that has arrived on a listening socket.
* [[accept]] - Accepts a connection that has arrived on a listening socket.
* connect - Connects to a remote host.
* [[connect]] - Connects to a remote host.
* recv - Receives data from a socket (SOCK_STREAM)
* [[recv]] - Receives data from a socket (SOCK_STREAM)
* send - Sends data to a socket (SOCK_STREAM)
* [[send]] - Sends data to a socket (SOCK_STREAM)
* recvfrom - Receives a message from a socket.
* [[recvfrom]] - Receives a message from a socket.
* sendto - Sends a message to a socket.
* [[sendto]] - Sends a message to a socket.
* poll - Waits for data on one or more sockets.
* [[poll]] - Checks for new data or a status change on a socket.
* close - Closes a socket.
* [[close]] - Closes a socket.
 
This seems like rather a lot, but in practise it's quite simple to use, and once a socket is connected, it's mainly a matter of using send, recv and poll. Certain things will be 'no ops' in C (for examaple, the htons function will be just a macro that does nothing, but provided for compatibility). Ancillary functions such as gethostbyname (which must do a DNS lookup) will also be provided, and will use the socket library to work.
 
Like the BSD library, the socket() function call will return a file decsriptor (you may prefer to call it a handle if you're a Microsoft type, if you look in the Winsock library you'll find HANDLE is in fact just an int, just like it is in Unix). The file descriptor is a simple integer, and allows the library to find the hardware registers required for performing operations on a socket. A later project may be to integrate this with the Z88DK's fcntl library.


== Utility code ==
== Utility code ==

Revision as of 20:51, 3 June 2008

There are three main categories of software for the Spectranet; library code (i.e. the socket library and peripheral functions), utility code - things like a configuration user interface, and application code - some of which will be burned into ROM. Current plans call for the following:

The Basics

Library Reference

The socket library

The most important part is probably the socket library. This will provide a subset of the BSD socket library. The plans are for three equivalent libraries: an assembler library, a C library based around the Z88DK, and a BASIC library. The C library will essentially be a wrapper around the assembler library (with a few extra pieces of error checking, which for asm users will be left up to the programmer).

The rationale for using the BSD socket interface (rather than just a simple wrapper around the W5100's TCP offload engine) is to provide an interface that's familiar to any programmer who has written net code, and also (importantly) to provide hardware independence. The BSD library has worked well for pretty much every network device that speaks TCP/IP, so I know if for some reason, a chip other than the W5100 needs to be used, or a different TCP/IP stack needs to be used, the software interface does not need to be changed - and therefore, code that people have slaved over to make the Spectranet useful won't need to be changed either.

The main functions that will be implemented for all languages are:

  • socket (HLCALL 0x3E00) - Creates a new socket.
  • bind - Binds a name to a socket (i.e. sets the port).
  • listen - Tells an open socket that it should listen for incoming connections.
  • accept - Accepts a connection that has arrived on a listening socket.
  • connect - Connects to a remote host.
  • recv - Receives data from a socket (SOCK_STREAM)
  • send - Sends data to a socket (SOCK_STREAM)
  • recvfrom - Receives a message from a socket.
  • sendto - Sends a message to a socket.
  • poll - Checks for new data or a status change on a socket.
  • close - Closes a socket.

Utility code

Certain utilities will be provided in the ROM. The most important one will be the one that allows the user to configure the device. This will provide a simple user interface for setting the IP address, netmask and gateway, and hardware address (if it needs changing from the one put in ROM on initial programming; unfortunately, joining the IEEE to get Ethernet addresses assigned to the project is prohibitively expensive).