For developers

Send a command, read the answer. Done.

Programming the WiC64 is simple: the C64 sends a command over the user port, and the WiC64 replies accordingly. The firmware 4.0 speaks the familiar protocol W identically down to the byte and handshake, and adds two new ones: R and E.

Lines

LineFunction
PB0–PB7 ($DD01)8 data lines, bidirectional. Direction via $DD03.
PC2Goes low briefly on every write or read access to $DD01 and triggers an interrupt in the ESP32.
FLAG2Handshake from the WiC64: sets bit 4 in $DD0D when the byte has been read or a new one is ready.
PA2 ($DD00 bit 2)HIGH = the C64 sends, LOW = the WiC64 sends.

Protocols W, R, E

W  'W' <len lo> <len hi> <cmd> <data>           len = data + 4
   answer: <size hi> <size lo> <data>            (big endian, as before)

R  'R' <cmd> <size lo> <size hi> <data>
   answer: <status> <size lo> <size hi> <data>

E  'E' <cmd> <size 32 bit LE> <data>
   answer: <status> <size 32 bit LE> <data>

W is the protocol of all existing programs and behaves in firmware 4.0 exactly as before. R additionally returns a status. E transfers data of any size, for example uploads that are already streaming to the server while the C64 is still sending.

Byte-level sequence

  1. The C64 writes a byte to port B. PC2 triggers the interrupt, the WiC64 reads the byte and acknowledges with a short low pulse on FLAG2.
  2. For the last byte the handshake only comes once the answer is ready (immediately for R/E with payload).
  3. The C64 pulls PA2 low. The WiC64 signals “ready”, the C64 makes a dummy read, and only then does the WiC64 put the bytes on the bus one by one.
  4. PA2 goes high again. The WiC64 discards an answer that was not collected.

The firmware 4.0 works with interrupts in IRAM, without heap, with a 64 KB ring buffer: downloads are already flowing to the C64 while they are still coming in from the net.

Example in assembler

We request the IP address (command $06) and print it. First switch on send mode and send four bytes:

        lda $dd02
        ora #$04
        sta $dd02       ; PA2 as output
        lda $dd00
        ora #$04        ; PA2 HIGH: C64 sends
        sta $dd00
        lda #$ff
        sta $dd03       ; port B output

        lda #"W"        ; protocol W
        jsr write_byte
        lda #$04        ; length low ($0004 = command only)
        jsr write_byte
        lda #$00        ; length high
        jsr write_byte
        lda #$06        ; command $06: IP address
        jsr write_byte

write_byte:
        sta $dd01       ; put byte on the bus
-       lda $dd0d
        and #$10        ; FLAG2: byte collected?
        beq -
        rts

Then switch to receive, read the length and print the answer:

        lda #$00
        sta $dd03       ; port B input
        lda $dd00
        and #$fb        ; PA2 LOW: WiC64 sends
        sta $dd00

        jsr read_byte   ; dummy byte, starts the transfer
        jsr read_byte   ; length high
        tay
        jsr read_byte   ; length low
        tax
        ...             ; length 0 = no answer
loop:   jsr read_byte
        jsr $ffd2       ; print character
        dex
        bne loop        ; (for answers > 255 bytes count Y as well)

read_byte:
-       lda $dd0d
        and #$10        ; FLAG2: byte ready?
        beq -
        lda $dd01
        rts
Tip

Build a time limit into every wait loop. The tools of firmware 4.0 report an error after a timeout instead of hanging.

Commands of firmware 4.0

IDFunctionNote
$00firmware versionW: WIC64FWV:0040, R/E: 40.0.0
$01HTTP/HTTPS GET! = default server, %mac/%ser are replaced, for .prg without load address
$02set Wi-Fi (SSID $01 password)answer “Wlan config changed”
$03/$04/$05firmware update release / developer 1 / developer 2only from the official update server
$06 $10 $11 $14IP address, SSID, signal strength, MACtext
$07build date
$08 / $12set / get default server
$09text to the developer console
$0A $0B $0E $1E $1FUDP receive, send, portas before
$0C / $0DWi-Fi scan / choose network from the listthe module reconnects right after the scan
$0Fload with encoded data (chat)
$13external IP address
$15 $16 $17time (HH:MM:SS DD-MM-YYYY), set / get time zone
$18update available?0/1/2
$19 / $1Aread / write settingstored permanently in the WiC64
$20–$23 $2E $30TCP: port, connect, read, send, close, available8 KB blocks
$24HTTP POST (multipart)
$25large load with 4-byte lengthstreaming
$26W: set upload server; R/E: version bytes
$27update from addressofficial update server only
$28 / $2BHTTP POST: address / dataany size with E
$29restart the WiC64
$2Astatus message (PETSCII)
$2C / $2FWi-Fi connected? / configured?
$2D / $32transfer / server timeout for the next request
$31hardware test
$60–$6Fnetwork games: log in, list, create/join a game, exchange states, messages, log outencrypted (ECDH P-256, AES-GCM)
$63factory resetrestart

Consoles & debugging

  • Serial: USB, 115,200 baud, with any terminal program. Shows startup messages, commands and errors.
  • Telnet: port 23 on Wi-Fi, with password or PIN like the web interface.
  • Web interface: log, remote control of the C64 (with WiC64 4.0 Kernal) and uploading programs.
  • Debug firmware: the firmware update in start.prg (Config → Firmware update) offers three levels: 1 normal firmware update, 2 debug output, 3 super debug output. 2 and 3 are for programmers only. Level 3 additionally writes every byte the C64 sends and reads over the user port to the log as a hex dump (C64 >> from the C64, C64 << to the C64); switch it in the console with wic trace off and wic trace on. During very fast, large transfers the dump shows the first 4096 bytes and reports how many more were not shown.
  • Test suite: 60 explained tests covering all commands – ideal for checking your own hardware or your own firmware builds.

WiC64 Library 4.0

The WiC64 Library 4.0 handles the protocol for you: detect the firmware, send a command, fetch the answer – with a time limit instead of a hang. It has been rewritten from scratch against the interface of firmware 4.0 and is MIT licensed.

  • Assemblers: ACME, C64 Studio, KickAssembler and ca65 – generated from one common source.
  • Any firmware: original (protocol W), 2.x and 4.0 (protocols R/E). wl_detect detects the firmware and chooses the protocol.
  • Small: 891 bytes, no zero page.
  • Compatible: an extra layer understands the macro names of the 2.x library, so existing sources can still be assembled.
  • For the VIC-20 too: the same library exists as wic20lib for the VIC-20 with WiC20 by cassy-de (VIA 1 instead of CIA 2, 926 bytes). Routines, constants and request block are the same – you only include the other file. With an example for the VIC-20 with 8K RAM or more. More about the VIC-20 on the VIC-20 page.
        jsr wl_detect           ; WiC64 present? firmware?
        bcs none                ; C=1: no WiC64
        ldx #<request
        ldy #>request
        jsr wl_request          ; send and fetch the answer
        bcs timeout             ; C=1: no answer
        bne error               ; A = status, 0 = ok
request !byte WL_CMD_IP         ; command
        !word 0, 0              ; payload: address, length
        !word buffer, 64        ; answer: address, at most 64 bytes

This is what the example from the download looks like (01-ip-and-time on the C64, 03-vic20-ip-and-time on the VIC-20) – the same source, only with wic64lib or wic20lib included:

Example of the WiC64 Library 4.0 on the C64: firmware 4.0 found, IP address and time
C64: firmware, IP address, time
Example of the WiC64 Library 4.0 on the VIC-20: firmware 4.0 found, IP address and time
VIC-20: the same calls with wic20lib

To the developer area

Your own games in the toolbox look

For new games there is a library in assembler (C64 Studio / ACME syntax): header with logo and title, toolbox font, joystick in port 1 and 2, all WiC64 commands, player name, high scores, return to the toolbox and network play for up to four players with lobby and waiting room. Two small example games show how to get started – one single-player, one networked. Library and demos are in the developer area.

An entry in the toolbox menu is one line: text (up to 36 characters), file name and whether the program runs under the header or with its own screen.