Applesoft BASIC Webserver Background
I got an Uthernet II
ethernet card for my Apple IIe
a while ago. While teaching ECE435 (Network Engineering) I realized
it would be a perfect time to start a network related project.
The Uthernet comes with some sample Assembly Language code, but I was
being lazy, so why not try to do the same in BASIC.
The Uthernet II has a W5100 chip in it that can do much of TCP/IP in
hardware, including up to 4 open sockets (although you can still operate
it in raw ethernet mode and do more work yourself). So most of the hard
work is done in hardware.
Yes, there's a typo, meant to say 140k disk not 160k.
I'm too lazy to re-render the video to fix it.
All source code is available. You can find it on github mixed in with
my other apple2 projects:
in the ethernet directory.
Here is the BASIC file and the disk image, although they won't work in
an emulator, you really have to have an Apple II with Uthernet card.
Theory of Operation
Ethernet card set up by a series of peeks and pokes.
Set to listen on TCP port 80
Poll, waiting for incoming packet
Incoming packet copied to RAM
Packet is "parsed" (the first line with GET request, rest is
Requested file read from disk using BLOAD to $4000.
If it doesn't exist, return 404.
Create proper header and set mime type (based on file extension),
send to ethernet
Slowly copy requested file from RAM to ethernet device.
Listen for more requests, or close connection.
Serve html, txt, jpg or png files.
Also supports favico.ico
Properly returns 400 and 404 status messages
RFC 2324 compliant
Tested to work with Firefox and wget, in theory should work with
DOS3.3 disk can only hold 140k of files
Currently files being served must be less than 8kB
It's really slow. Using a lot of string manipulation.
16 December 2016
Wrote some 6502 machine language code to speed up transmit.
While not pure BASIC, it makes a huge difference.
It is disabled currently as I didn't have a chance to test
it well before heading home for the weekend.
for comparison, a 4kb copy in BASIC using peek/poke takes 38s
where in 6502 assembly it takes less than 1s.
14 December 2016
Have the webserver mostly working! Video posted.
7 December 2016
BASIC code sent a page that firefox was able to display.
1 December 2016
Wrote a Linux/C simple webserver to use as a reference.
23 November 2016
I got ping working! Was almost trivially easy as the W5100 does
all of the hard work. Here's the code on the Apple II:
Here's the arp/ping happening from the remote machine:
A picture of the Uthernet board inside my Apple IIe platinum.
Also visible is a super-serial card and a CFFA3000 disk.
Back to vmwprod page