We mentioned Retro Computer Web Servers in separate post, but this project is not related to Retro Computers, but kind of emulation ZX Spectrum. So why do we writing about it?
This time it is about how can one do things VERY difficult and VERY complicated, with goal that you can write CGI scripts for serving web pages in good old ZX Spectrum BASIC. But on very very complicated way.
Apache web server HTTPD receives the request, and runs the CGI script (written in Bash) that does the magic. CGI script generate BASIC code that provides the HTTP meta-vars as DATA statements and some code of the .basic file and writes out executable basic file. Then it uses BAS2TAP that convert BASIC program to audio tape image and it is loaded to virtual fuse-spectrum-emulator to run program from audio image.
Complicated ? Not yet?
As fuse needs display to run, it is actually runs on virtual X(vfb).
As The program runs it writes its HTTP responses to the Spectrum printer using LPRINT statements, then fuse uses very basic OCR to understand what characters are printed, and writes them into a text file,CGI script monitors the output file, waiting for a line with an end marker (“ENDSPECTRUMBASIC”) and when it finds it, it kills the emulator.
And CGI script sends the contents of the output file withoutend marker to Apache, which returns it as a response.
For all of you that think it is not complicated test it and let us know how it works.For others there is shorter way to do it with Docker. See Documentation or github source for more.
Documentation:ZX Spectrum BASIC Web Server
Source:github