Saturday, January 30, 2016

Apple //e Webserver Running!

I have my Apple //e BASIC web server running!... sort of. Try it out. Be gentle and patient, it's only 300 BAUD!: http://162.232.186.125:8899

Code after the break.. Update: minor change in code to allow OPTIONS method

You will see some workarounds I had to make to avoid echoing the client headers. Also, I tried Chunked HTTP, but it never worked right, so it was REM'd out.


10  REM     "WEBSERVER for APPLE IIe"
20  REM    "# INPUT UTILITY@768 #"
25  LET IN$ = "X"
30  TEXT : HOME 
35  FOR J = 768 TO 788
40  READ I
45  POKE J,I
50  NEXT J
60  DATA    162,0,32,117,253,160,2
61  DATA    138,145,105,200,169,0
62  DATA    145,105,200,169,2,145
63  DATA    105,96
90  REM   "BUG IN INPUT UTIL SETS HIGH BIT"
92 MO$ =  CHR$ (207) +  CHR$ (208) +  CHR$ (212): REM  "OPT"
93 MG$ =  CHR$ (199) +  CHR$ (197) +  CHR$ (212): REM  "GET"
94 MH$ =  CHR$ (200) +  CHR$ (197) +  CHR$ (193): REM  "HEA"
100  REM  "# PREPARE #"
110  GOTO 900: REM  "NO ECHO OUT"
160  ONERR  GOTO 900
190  REM  "# HTTP #"
200  REM  "## HTTP REQUEST ##"
210 HM = 0:HC$ = "501 Not Implemented"
215  REM  HM = 0:HC$ = "405 Method Not Allowed"
220  FOR I = 0 TO 20
230  CALL 768:IN$ =  MID$ (IN$,1)
240  IF  LEN (IN$) < 3 THEN I = 20: GOTO 290
250 HR$ =  LEFT$ (IN$,3)
260  REM  "### HTTP REQ METHD ###"
264  REM  "OPTIONS"
265  IF HR$ = MO$ THEN HM = 2
266  REM   "GET"
267  IF HR$ = MG$ THEN HM = 3
268  REM   "HEAD"
269  IF HR$ = MH$ THEN HM = 4
290  NEXT I
300  PRINT  CHR$ (4);"PR#2": REM     "SSC SLOT"
350  IF (HM > 1 AND HM < 5) THEN HC$ = "200 OK": GOTO 400
360 HC$ = "405 Method Not Allowed"
400  REM  "## DOS FILE ACCESS? ##" 
490 FL$ = ""
500  REM  "## HTML ##"
510 EH$ = "<HTML><HEAD><TITLE>Apple IIe Webserver Demo</TITLE></HEAD><BO
DY>"
515 EH$ = "<!DOCTYPE HTML>" + EH$
520 EB$ = "<H1>Apple IIe Webserver - RetroChallenge 2016/01</H1>"
530 EB$ = EB$ + "You have connected to an Apple IIe (platinum) webserver
running on Applesoft BASIC, connected to the internet by a USR-232W
IFI."
580 EF$ = "</BODY></HTML>"
700  REM  "## HTTP HEAD ##"
720  PRINT "HTTP/1.1 ";HC$
725  IF HM = 2 THEN  PRINT "Allow: HEAD,GET,OPTIONS": GOTO 750
730  PRINT "Content-Type: text-html; charset=us-ascii"
735  REM  "CHUNK" PRINT "Transfer-Coding: chunked"
740  PRINT "Content-Length: "; LEN (EH$) +  LEN (EB$) +  LEN (EF$)
750  PRINT 
790  IF HM <  > 3 THEN  GOTO 950
800  REM  "## HTML OUT ##"
803  REM  "CHUNK" PRINT  LEN (EH$) +  LEN (EB$) +  LEN (EF$)
810  PRINT EH$;EB$;EF$
820  REM  "CHUNK" PRINT 0: PRINT
900  REM  "ERROR TRAP"
940  POKE 216,0
950  REM   "# NO ECHO OUT #"
980  PRINT  CHR$ (4);"PR#0":
990  GOTO 200

No comments:

Post a Comment