Applesoft Network extensions - FujiNetWIFI/fujinet-firmware GitHub Wiki
To use the FujiNet Device in Applesoft, ampersand routines must be loaded into memory. This is provided by the FUJIAPPLE handler program on the FUJIAPPLE.PO disk. It is typically loaded into memory by the first lines in BASIC, before any strings are defined.
Once loaded, the handler is positioned into memory directly at HIMEM, and HIMEM is altered to protect it during use.
The following code example will see if the extensions are already loaded. If not, they will be installed.
REM *************************
REM DETERMINE IF FUJI EXTENSIONS ARE INSTALLED
REM *************************
10000 GOSUB 10030: IF R=1 THEN PRINT "EXTENSIONS ALREADY INSTALLED.": RETURN
10010 PRINT "LOADING EXTENSIONS..."
10020 PRINT CHR$ (4);"BLOAD /FUJI.APPLE/FUJIAPPLE":CALL 16384:RETURN
10030 X = PEEK(1014)+PEEK(1015)*256
10040 X = X - 1
10050 C = PEEK(X)
10060 IF C = 0 OR C > 20 THEN 10140
10070 X = X - C
10080 A$=""
10090 FOR Y = 1 TO C: A$=A$+CHR$(PEEK(X)):X=X+1:NEXT Y
10100 B$ = "FUJIAMP"
10130 IF A$=B$ THEN R=1: GOTO 10150
10140 R=0
10150 RETURN
BASIC unit, which will be shorten to unit in this documention, is defined as a number between 0 and 3, corresponding to the four available network devices. Unit 0 corresponds to SmartPort device NETWORK or NETWORK_0 Unit 1-3 corresponds to SmartPort device NETWORK_1 through NETWORK_3
Important
Device units do not correlate to Applesoft BASIC units
UNIT #01 NAME: FUJINET_DISK_0
UNIT #02 NAME: FUJINET_DISK_1
UNIT #03 NAME: NETWORK
UNIT #04 NAME: NETWORK_1
UNIT #05 NAME: NETWORK_2
In the above example, device unit #03 corresponds to BASIC unit 0
A FujiNet url is defined as:
N:<PROTO>://[HOSTNAME][:PORT]/[PATH]...
Where:
- PROTO is the desired protocol (TCP, UDP, HTTP/S, SSH, TNFS, NFS, SMB, etc.)
- HOSTNAME is the destination host name, can be omitted for listening sockets
- PORT is the port number. For listening sockets this is mandatory, otherwise it is optional
- PATH is an optional path to the desired resource
Description: Opens a specified URL for use. You will need check for success using &NSTATUS.
mode | description |
---|---|
4 | Read Only (e.g. HTTP GET) |
6 | Read Directory |
8 | Write only (e.g. HTTP PUT) |
12 | Read and Write (common with TCP and UDP) |
13 | HTTP POST |
mode | description |
---|---|
0 | No translation (usually, you want this one) |
1 | CR to CR -- (not very useful) |
2 | LF to CR |
3 | CR/LF to CR |
- To open the GNU Public License for reading from the Free Software Foundation web server:
1000 &NOPEN 0, 4, 0, "N:HTTP://www.gnu.org/licenses/gpl-3.0.txt"
- To Open a TCP listening connection on port 6502:
2000 &NOPEN 0, 12, 0, "N:TCP://:6502/"
Description: Closes a network connection.
- To close unit 0
1000 &NCLOSE 0
Description: Gets the status of the network connection. Stores the number of bytes waiting into variable named by bw. Stores the connected status (1 = connected) into variable named by connected. Stores the network error of the last operation into the variable named by nerr.
- To get the status of network unit 0
1000 &NSTATUS 0, bw, cn, ne
Description: Gets len number of bytes and puts them into string variable var$.
- To read 128 bytes of data into string variable BUF$:
1000 &NREAD 0, BUF$, 128
Note
I really want a network analog for INPUT, where we can get e.g. multiple comma separated values into variables easily, but this may be a bridge way too far - thom
Description: Gets len number of bytes and puts them into string variable var$
- To write 128 bytes from string variable BUF$ to the destination:
1000 &NWRITE 0, BUF$, 128
Description: Sends a specific control message to the network device to do a special command. The payload for this command is specified as the very last parameter.
- To accept an incoming server connection waiting on previously opened listening socket on unit
3052 &NCTRL 0, ASC("A"), ""
Description: Accept an incoming server connection waiting on previously opened listening socket.
- To accept an incoming server connection waiting on previously opened listening socket on unit 0:
3052 &NACCEPT 0
Description: Displays the SmartPort devices connected to the system. If a string variable is supplied, then a comma separated list is stored in the variable.
- To display the SmartPort units connected to the display.
3052 &NLIST
- To get the SmartPort units and store them into string A$
3052 &NLIST A$
Description: Sets the end-of-line character to look for when using &NINPUT, or the end-of-line character to use when using &NPRINT. Default setting is 13 ($0D) / ASCII carriage return.
- To set the end of line character to the Atari equivalent, which is 155 ($9B)
3052 &NSETEOL 155
Description: Transmit the contents of var$. If a semicolon is absent, then the EOL character is transmitted at the end. (See &NSETEOL).
- To send “Hello, World!” to unit 0, following by a carriage return
3052 &NPRINT "Hello, World!"
Description: Accept incoming characters until either
- The EOL character is received (see &NSETEOL) or
- 255 characters are received
and store in var$.
- To receive a line from unit 0
3052 &NINPUT 0, A$
Description: Switches JSON mode on or off on a particular channel – 1=on, 0=off.
- To open a website, change the channel for JSON parsing, request a tag, retrieve the value
20 D$="N:HTTP://api.open-notify.org/iss-now.json"
30 Q$="/MESSAGE"
100 &NOPEN 0,12,3,D$
130 &NJSON 0, 1
140 PRINT "QUERY ";Q$
150 &NQUERY 0,Q$,O$
160 &NINPUT 0,O$
170 PRINT "VALUE: ";O$
180 &NCLOSE 0
Description: Requests the value of a particular tag out of the JSON data.
See &NJSON example
Description: Gets the current time from the FujiNet device.
- To retrieve the current date and time and print them to screen
20 &NTIME YR,MO,DY,HR,MN,S
30 PRINT "FUJI DATE:";YR;" ";MO;" ";DY;" ";
40 PRINT "FUJI TIME:";HR;":";MN;".";S