Accessing the web with an emulated VIC-20

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.

Rationale

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:

  1. An internet-connected PC with VICE on it
  2. The socat utility, download from here
  3. Our updated vic20-networking diskette including the web7a program

The steps:

  • 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:

LOAD”WEB7A”,8

(hit CTRL+SHIFT to switch LowerUppercase charset as you would do with C= and SHIFT on the actual Commodore)

RUN

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):


$m=$_GET['m'];
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:

5 OPEN2,2,0,CHR$(8)+CHR$(0)
10 GOTO100
20 GET#2,A$:PRINTA$;
30 GETA$:PRINTA$;:IFA$<>""THENS$=S$+A$
40 IFA$=CHR$(13)THENPRINT#2,S$;:S$=""
50 GOTO20
100 PRINT"YOUR MESSAGE TO THE WORLD":INPUTR$
105 READX$:GOSUB3000:A$=Y$
110 GOSUB900
120 PRINT ">"+B$+"<"
130 PRINT#2,B$;CHR$(13);CHR$(10);
220 READA$:IFA$<>"EOF"THEN110
222 G=0
230 GET#2,C$:IFC$<>""ANDG=1THENPRINTC$;:GOTO230
232 IFC$="*"THENG=1
240 GETK$:IFK$=""THEN230
250 RESTORE:GOTO105.REPEAT WEBREQ
850 END
900 REM******CNVSTR*** IN A$ OUT B$
905 B$="":FORI=1TOLEN(A$):C$=MID$(A$,I,1):GOSUB1000
910 B$=B$+D$:NEXTI
920 RETURN
999 END
1000 REM*****CNVCHAR** IN C$ OUT D$
1010 IFC$<>""THENC=ASC(C$):D=C:GOTO1020
1012 D$="":RETURN
1020 IF C>128THEND=C-96
1900 D$=CHR$(D)
1999 RETURN
2000 DATA"GET /?m=$ HTTP/1.1"
2010 DATA"Host: XIXI.VIC20RELOADED.COM"
2012 DATA"Connection: close"
2014 DATA""
2020 DATA"EOF"
3000 REM****STRREPLACE
3002 REM REPLACES $ WITH R$
3010 REM IN X$,R$ OUT Y$ USES I AND P$
3020 Y$=""
3030 FORI=1TOLEN(X$)
3032 P$=MID$(X$,I,1)
3034 IFP$="$"THENY$=Y$+R$:GOTO3038
3036 Y$=Y$+P$
3038 NEXT
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.

 

Current limits

This is just a simple experiment, not a complete working solution. Nevertheless the possibilities are endless. A few questions remain unanswered

  1. 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.
  2. 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!


1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

2 Replies to “Accessing the web with an emulated VIC-20

  1. Back in 1985 there was an article in german fanzine “64er” in which 2 VICs or C64s could communicate several meters over air using simple optical transmission with bulbs and Photo-Transistors als receiver. It also used the UART inside VIA/CIA Chips, but -naturally- at much lower speed.

    But it was impressive that time to communicate without wire from one house to another (or the hut/summer house in the garden)…

    It worked only at nighttime, but that made it much more interesting, even to our neighbours 😉

    But at that time, CB-Radio was the more convenient way of “chatting”, really good ol´ times!

Leave a Reply

Your email address will not be published. Required fields are marked *