Skip to content

Applesoft Network extensions

Norman Davie edited this page Apr 4, 2023 · 6 revisions

Fujinet overview

To use the Fujinet Device in Applesoft, ampersand routines must be loaded into memory. This is provided by the FUJIAPPLE handler program on the FUJI.APPLE disk. It is typically loaded into memory by the first lines in BASIC, before any strings are defined.

Once loaded, and the handler is positioned into memory directly at HIMEM, and HIMEM is altered to protect it during use.

Loading the Applesoft Network extensions

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

Definitions

Unit

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 NOTE: Device units do not correlate to 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

URL

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.

&NOPEN unit,mode,trans,url

Description Opens a specified URL for use. You will need check for success using &NSTATUS.

&NOPEN mode values

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

&NOPEN trans values

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

&NOPEN Examples

  • 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/"

&NCLOSE unit

Description Closes a network connection.

&NCLOSE Example

  • To close unit 0
1000 &NCLOSE 0

&NSTATUS unit, bw, connected, nerr

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

&NSTATUS Example

  • To get the status of network unit 0
1000 &NSTATUS 0, bw, cn, ne

&NREAD unit, var$, len

Description Gets len number of bytes and puts them into string variable var$

&NREAD Example

  • 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 seperated values into variables easily, but this may be a bridge way too far -thom)

&NWRITE unit, var$, len

Description Gets len number of bytes and puts them into string variable var$

&NWRITE Example

  • To write 128 bytes from string variable BUF$ to the destination:
1000 &NWRITE 0, BUF$, 128

&NCTRL unit, command, PAYLOAD$

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.

&NCTRL example:

To accept an incoming server connection waiting on previously opened listening socket on unit

3052 &NCTRL 0, ASC("A"), ""

&NACCEPT unit

Description Accept an incoming server connection waiting on previously opened listening socket

&NACCEPT example:

To accept an incoming server connection waiting on previously opened listening socket on unit 0:

3052 &NACCEPT 0

&NLIST

&NLIST str$

Description Displays the smartport devices connected to the system. If a string is supplied, then a comma separated list is stored in the string

&NLIST example:

Display the smartport units connected to the display.

3052 &NLIST

Get the smartport units and store them into string A$

3052 &NLIST A$

&NSETEOL

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.

&NSETEOL example:

Set the end of line character to the Atari equivalent, which is 155 ($9B)

3052 &NSETEOL 155

&NPRINT unit, var$[;]

Description Transmit the contents of var$. If a semicolon is absent, then the EOL character is transmitted at the end. (See &NSETEOL)

&NPRINT example:

Send "Hello, World!" to unit 0, following by a carriage return

3052 &NPRINT "Hello, World!"

&NINPUT unit, var$

Description Accept an incoming characters until either

  1. The EOL character is received (see &NSETEOL) or
  2. 255 characters are received.

&NINPUT example:

To receive a line from unit 0

3052 &NINPUT 0, A$

&NJSON unit, onoff

Description Switches JSON mode on or off on a particular channel. 1=on, 0=off

&NJSON example:

Open a website, change the channel for jason 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

&NQUERY unit, query$, value$

Description Requests the value of a particular tag out of the json data

&NQUERY example:

See &NJSON example

&NTIME YEAR,MONTH,DAY,HOUR,MINUTE,SECOND

Description Gets the current time from the Fujinet device

&NTIME example:

20 &NTIME YR,MO,DY,HR,MN,S
30 PRINT "FUJI DATE:";Y;" ";MO;" ";D;"  ";
40 PRINT "FUJI TIME:";H;":";M;".";S
Clone this wiki locally