Lines
| Line | Function |
|---|---|
PB0–PB7 ($DD01) | 8 data lines, bidirectional. Direction via $DD03. |
PC2 | Goes low briefly on every write or read access to $DD01 and triggers an interrupt in the ESP32. |
FLAG2 | Handshake 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
- 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.
- For the last byte the handshake only comes once the answer is ready (immediately for
R/Ewith payload). - 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.
- 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
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
| ID | Function | Note |
|---|---|---|
$00 | firmware version | W: WIC64FWV:0040, R/E: 40.0.0 |
$01 | HTTP/HTTPS GET | ! = default server, %mac/%ser are replaced, for .prg without load address |
$02 | set Wi-Fi (SSID $01 password) | answer “Wlan config changed” |
$03/$04/$05 | firmware update release / developer 1 / developer 2 | only from the official update server |
$06 $10 $11 $14 | IP address, SSID, signal strength, MAC | text |
$07 | build date | |
$08 / $12 | set / get default server | |
$09 | text to the developer console | |
$0A $0B $0E $1E $1F | UDP receive, send, port | as before |
$0C / $0D | Wi-Fi scan / choose network from the list | the module reconnects right after the scan |
$0F | load with encoded data (chat) | |
$13 | external IP address | |
$15 $16 $17 | time (HH:MM:SS DD-MM-YYYY), set / get time zone | |
$18 | update available? | 0/1/2 |
$19 / $1A | read / write setting | stored permanently in the WiC64 |
$20–$23 $2E $30 | TCP: port, connect, read, send, close, available | 8 KB blocks |
$24 | HTTP POST (multipart) | |
$25 | large load with 4-byte length | streaming |
$26 | W: set upload server; R/E: version bytes | |
$27 | update from address | official update server only |
$28 / $2B | HTTP POST: address / data | any size with E |
$29 | restart the WiC64 | |
$2A | status message (PETSCII) | |
$2C / $2F | Wi-Fi connected? / configured? | |
$2D / $32 | transfer / server timeout for the next request | |
$31 | hardware test | |
$60–$6F | network games: log in, list, create/join a game, exchange states, messages, log out | encrypted (ECDH P-256, AES-GCM) |
$63 | factory reset | restart |
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 withwic trace offandwic 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 (protocolsR/E).wl_detectdetects 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
wic20libfor 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:


wic20libYour 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.