We are exploring possibilities. Can Commodore VIC-20s and c64 access the web and use web-based services? Here is a trial made using the VICE emulator, with all the necessary tools to reproduce it.
We already know that emulated VIC-20 and c64s can communicate using their virtual RS232 over a TCP/IP connection. If it is possible to make emulated (but also physical) vintage Commodore machines to communicate with a webserver, then we can imagine how it could be having multiple c64 acting like chat clients, or it would be possible to develop a (virtually limitless) MMORPG whose map resides on a central webserver. The schema aside depicts the idea.
On this basis we have tried building a web client to be run on an emulated vintage Commodore machine and, using the socat utility as a connection bridge, we tried to communicate with a central webserver.
Try it yourself!
Here’s what you need:
- An internet-connected PC with VICE on it
- The socat utility, download from here
- Our updated vic20-networking diskette including the web7a program
- The socat utility should be kept inside a folder. Then open a CMD shell on your PC, change directory to that folder and run the following command:
socat tcp-listen:25232,fork,reuseaddr tcp:xixi.vic20reloaded.com:80
- Run the VICE emulator – VIC20 or C64, it doesn’t change. Make sure you have a few settings correctly set for using the virtual RS232 port. Namely:
- RS232 emulation must be set to ON at 1200 baud. To do this, select from the menu Settings/RS232 Settings/RS232 Userport Settings. Then “Enable RS232 userport emulation” must be checked, and Userport baud rate must be 1200 (then select any device you like, eg. device 1).
- RS232 must send data to socat on localhost. In order to do this, select from the menu Settings/RS232 Settings/RS232 Settings then type, inside each RS232 device, the following: 127.0.0.1:25232
- If using VIC-20, select the 16k expansion under Settings/VIC20 Settings,
- Attach our vic20network.d64 diskette using menu File/attach disk image-drive 8
- Finally press Alt-R to hard-reset the emulator and you’re ready to go
Running the web client
Inside the emulator, you Load and Run the software with:
(hit CTRL+SHIFT to switch LowerUppercase charset as you would do with C= and SHIFT on the actual Commodore)
The software asks you for a word, then when you press RETURN, it connects to our test webserver xixi.vic20reloaded.com, sends your word to the server inside the “m” GET parameter, and it gets the server’s reply back, printing it on the screen.
The server will simply echo the word you have just typed in. Before this reply, you will see the headers and the commands actually sent by the emulated VIC to the server.
So: The emulator has sent information out of its box, and received a reply from a website outside.
Inside the code
It is a very simple application demonstrating that both the client and the server are capable of transmitting and receiving bits of information.
This is what the server does (PHP source code):
echo "*hI, YOU SAID: $m AT ".date("Y-m-d h:i:s");
So it simply accepts a parameter “m” and echoes it back along with a timestamp.
But let’s see the web client code:
100 PRINT"YOUR MESSAGE TO THE WORLD":INPUTR$
120 PRINT ">"+B$+"<"
250 RESTORE:GOTO105.REPEAT WEBREQ
900 REM******CNVSTR*** IN A$ OUT B$
1000 REM*****CNVCHAR** IN C$ OUT D$
1020 IF C>128THEND=C-96
2000 DATA"GET /?m=$ HTTP/1.1"
2010 DATA"Host: XIXI.VIC20RELOADED.COM"
2012 DATA"Connection: close"
3002 REM REPLACES $ WITH R$
3010 REM IN X$,R$ OUT Y$ USES I AND P$
3040 RETURN:REM ABC
Line 5 opens the connection at 1200 baud, 8 bit per word, 1 parity bit.
Line 100 asks for a phrase then reads the text for the web call. We use the subroutine at 3000 to replace the dollar sign $ with the word just inputted.
The web GET request is stored inside the DATA instructions (2000-2020) and it is sent out in plain text. We had to explicitly use the CR+LF sequence for it to be correctly accepted – Hence the CHR$(13)+CHR$(10) in the BASIC program’s code, line 130.
Also, since the VIC and the general ascii chart do not match, we had to code a conversion routine (lines 900-1999) so that we can convert the outgoing text for general web-oriented use. In particular, the VIC’s lowercase chars will be seen as UPPERCASE in the web and, on the converse, uppercase chars in the VIC will be converted as lowercase for the web.
Line 232: Only the chars after the asterisk * are printed, so that you avoid seeing all the server’s headers.
Theoretically speaking, if we implemented a bit of user registration, login and some session management then this simple app would easily turn into a multi-user chat system, or even something more such as a multiplayer game.
This is just a simple experiment, not a complete working solution. Nevertheless the possibilities are endless. A few questions remain unanswered
- If you press a key after the first interaction with the webserver, the VIC/c64 will retry communicating but you will see that connection cannot be established anymore after the first dialogue. What happened? It seems everything gets back to working if you reset the emulator and re-run the software, but we cannot understand why the connection breaks after the first interaction and – most importantly – how to restore it without resetting the emulator.
- The above solution seems to work fairly well if the webserver replies with a small amount of data. If you modify the program and the instructions in order to connect another unsecured website, you will see that the received data appears as garbled on the emulated VIC. Apparently, the RS232 has some buffering problem to take into account and this severely limits the applications. Perhaps it’s something that can be solved tweking options on socat? Or replacing socat with another tool like tcpser?
Please comment if you have any information useful for this research, thank you!