How BomberNet is built, how the code is organised, how the network works and how it is tested. The player's view is in the README.
The continuous integration (GitHub Actions) builds every machine on each pull
request (.github/workflows/build.yml), runs the deterministic tests
(test.yml) and the real emulators (emulators.yml, also nightly), and a
tag v* drafts a release with every machine's files (release.yml).
Pinned tool versions: tools/ci/toolchains.env.
Z80 builds use z88dk (sccz80, z88dk.zcc, e.g. the snap package) and CMake;
-DPLATFORM selects the machine (default mz).
mkdir -p build/c && cd build/c && cmake ../../c && make # -> build/c/bomber.mzf
mkdir -p build/zx && cd build/zx && cmake -DPLATFORM=zx ../../c && make # -> build/zx/bomber.tap
mkdir -p build/zx128 && cd build/zx128 && cmake -DPLATFORM=zx128 ../../c && make # -> 128K + ESP-01: bomber.tap (in progress)
mkdir -p build/cpc && cd build/cpc && cmake -DPLATFORM=cpc ../../c && make # -> build/cpc/bomber.cpc, bomber.dsk (in progress)
tools/build_host.sh && c/build/sim 30000 2 # the game on a PC (key bot)
tools/build_amiga.py --adf # -> build/amiga/bomber, bombernet.adf (bebbo's gcc in Docker)
tools/build_st.py --st # -> build/st/BOMBER.PRG, bombernet.st (m68k-atari-mint-gcc)
tools/build_pc.py --img # -> build/pc/BOMBER.EXE, bombernet.img (OpenWatcom v2)
tools/build_web.py # -> build/web/bombernet.html, .js, .wasm (Emscripten)
The MZ build uses the environment of the MZPico-800-Manager (+mz target,
REGISTER_SP=0xd000, output renamed to .mzf); the Spectrum build loads at
24000 and keeps its hot code above the contended RAM.
c/core/ the game, identical everywhere: no hardware addresses, no assembly
c/common/ shared building blocks: network devices, Z80 assembly loops
c/platform/ one directory per machine: mz, zx, host (the PC simulator)
| path | content |
|---|---|
c/core/game.h |
constants, records (player_t, enemy_t, bomb_t, ftimer_t), globals, prototypes, GAME_VERSION, BUILD_ID (bump on any change of the simulation or the protocol) |
c/core/platform.h |
what a port implements: key sets, joysticks, text-entry key, frame sync, tone, screen flush, player colour, menu texts naming the machine's keys; optional assembly versions of core loops |
c/core/netdev.h |
the network as ten calls: status, create, join, leave, ready, send, poll, hash, message send and receive |
c/core/bomber.c |
title and menu, lobby, stage life cycle, status line, frame order as in the original main loop |
c/core/netplay.c |
the lockstep match over the network device |
c/core/input.c, video.c |
input sampled once per frame; layers, 2x2 tiles, digits and text |
c/core/map.c, enemy.c, bomb.c, player.c |
stage layout, enemies, bombs and blast, players |
c/core/data.c/.h |
generated by tools/extract_data.py from bomber.mzf: logo (tools/make_logo.py), blast pattern, strings |
c/common/netdev_card.c, uc.h |
the network device as a Unicard-compatible card (MZPico with Wi-Fi, Unicard NET firmware): detection by the INFO feature bit, the ten calls as card commands |
c/common/netdev_soft.c, ws.c, tcp.h |
the network device in software, on the machine itself: room state, input window, messages, JSON lines over a small WebSocket client over any tcp.h |
c/common/netdev_none.c |
the network device of a build without network |
c/cpu/z80/ |
faster Z80 versions of shared C (playfield copy, hash loop, text and digits, the network's input lines), used where plat_config.h asks; the C stays the reference (portability.md) |
c/platform/mz/ |
Sharp MZ-700/800: keyboard matrix, joysticks, tones through the monitor, 8253 frame limiter, screen flush through the display-code tables; uc_mz.c is the card transport on ports 50h/51h |
c/platform/zx/ |
ZX Spectrum 48K: keys and joysticks, frame sync on the ROM's frame counter, beeper, the 6 x 8 pixel screen routine in assembly; tcp_spectranet.c is tcp.h over the Spectranet socket calls |
c/platform/zx/bank6.c, tcp_bank6.c, tcp_esp01*.c |
the 128K build (PLATFORM=zx128, port-zx128-esp01.md): the network driver in RAM bank 6 (the ESP-01's, by Milan Stava, or the Spectranet's), the game's tcp.h pages it in; the same build on a ZX Spectrum Next (port-zx-next.md) |
c/platform/cpc/ |
Amstrad CPC (port in progress, port-amstrad-cpc.md): Mode 1 in four inks, cells rendered in advance from the MZ characters (tools/make_cpc_tables.py), keyboard and joysticks through the PPI, AY tones |
c/platform/host/ |
the PC: sim.c (the whole game with a key bot, recording, replay and a stub network card), tcp_posix.c and softnet_test.c (the software network device on a PC) |
c/platform/*/tables.c/.h |
generated: logical cell codes to the machine's characters and colours (tools/make_zx_tables.py for the Spectrum) |
c/platform/*/plat_config.h |
the platform's constants: text rows, joystick kinds, which assembly versions exist |
Adding a machine means a new c/platform/<name>/ with platform.h
implemented, a plat_config.h, character tables, and a network device: the
card protocol if the machine has such a card, otherwise netdev_soft.c with a
tcp.h for its network interface, or netdev_none.c. The core draws 40 x 25
logical cells (rows 0..23 the field, row 24 the status line); a machine with
24 text rows shows the status line on the bottom wall in its flush routine.
Every machine must simulate the same frames: a frame is 60 ms, and recordings
made on the PC replay on each build with identical state hashes.
port-zx-spectrum.md records how the Spectrum port was planned and
measured.
| Device | Machine | Transport to the relay |
|---|---|---|
| MZPico, NET extension | Sharp MZ-800 | WebSocket from the card's firmware (WiFi), production relay |
| Browser player | mzpico.com | the page's WebSocket, production relay |
| Spectranet / Spectranext | ZX Spectrum 48K, 128K | WebSocket from the Spectrum itself (netdev_soft.c) |
| ESP-01 (eLeMeNt ZX) | ZX Spectrum 128K | the same, over the ESP-01's AT commands |
| M4 board | Amstrad CPC | the same, over the M4's sockets |
| FujiNet | Atari XL/XE | the same, over FujiNet's N: device on SIO |
| WiC64, or an Ultimate's own network | Commodore 64 | the same, over the WiC64's TCP commands or the Ultimate Command Interface (Ultimate 64, Ultimate-II+; enabled in its menu) |
| any TCP/IP stack (Roadshow, AmiTCP, Miami, ...) | Amiga | the same, over bsdsocket.library; WinUAE and FS-UAE bring their own |
| WiFi modem on the serial port (ESP8266, Hayes commands) | Atari ST | the same, over ATDT host:port at 19200 bps (in progress) |
| Ethernet with a DOS packet driver, or a WiFi modem on COM1/COM2 | IBM PC (DOS) | the same, over our own small TCP/IP (DHCP, DNS) or ATDT host:port |
| Unicard, NET firmware | Sharp MZ-800 | JSON lines over TCP: a self-hosted relay/relay.py (LAN), not the production relay |
The production relay is ws://api.mzpico.com/net (Cloudflare, one Durable
Object per room). relay/relay.py is the reference relay for local tests and
self-hosting: WebSocket on 8765, JSON lines over TCP on 8766
(RELAY_TCP_HOST=0.0.0.0 opens the TCP port to the LAN).
cd relay && uvicorn relay:app --host 0.0.0.0 --port 8765
Every machine can play through a relay/relay.py on a LAN (the Unicard
only there). Start it on a PC with both ports open to the LAN:
cd relay && RELAY_TCP_HOST=0.0.0.0 uvicorn relay:app --host 0.0.0.0 --port 8765
Then point each machine at that PC (192.168.1.10 here):
| Machine | Where the relay is set |
|---|---|
| IBM PC (DOS) | BOMBER /RELAY=192.168.1.10 (the port 8765 unless given as host:port) |
| ZX Spectrum, CPC, Atari, C64, Amiga, Atari ST | tools/set_relay.py bomber.tap 192.168.1.10 rewrites the release file (.tap, .dsk, .cpc, .xex, .prg, .d64, the Amiga's executable or .adf, the ST's .PRG or .st; the port is 8765 unless given as host:port); without an address it shows the file's relay; api.mzpico.com:80 sets production again |
| MZ-800 with an MZPico | mzpico.ini: [cloud] net_relay = 192.168.1.10, net_port = 8765 |
| MZ-800 with a Unicard | /unicard/network.cfg: NETRELAYADDR, NETRELAYPORT (8766, the TCP port) |
The browser player stays on mzpico.com's relay. On a LAN the input delay settles at one or two frames.
A match is lockstep: every frame each machine sends its keys for frame F + d
and waits for everybody's keys of frame F. The host chooses d from the lobby's
round trips (ceil(rtt / 2) frames of 60 ms, 2 to 8); hashes of the game state
are compared every 16 frames. Protocol: net-protocol.md. Timing
measurements and the reasoning behind the delay rule: net-timing.md.
| tool | what it checks |
|---|---|
c/build/sim (SIM_RECORD, SIM_REPLAY) |
records a bot session on the PC and replays it with a state hash per frame |
tools/replay.py, tools/replay_zx.py |
the same recording on the MZ build (mz800emu) and the Spectrum build: identical hashes |
tools/lockstep_test.py, tools/nettest.py |
two MZ-800s (mz800emu, MZPico card emulated) through the local relay |
tools/lockstep_zx.py |
two Spectrums (tools/zxemu.py, Spectranet emulated at its programming interface) through the local relay or production |
tools/replay_cpc.py, tools/lockstep_cpc.py |
the same recordings on the Amstrad CPC build; two CPCs with M4 boards (tools/cpcemu.py) through the local relay or production |
tools/crossplay.py |
two different machines in one match: MZ-800, Spectrum, CPC, the 128K with its ESP-01 (esp), C64, Amiga, Atari ST, PC (PC_NET=pkt: over Ethernet), the browser build (web) |
tools/st_test.py, tools/st_play.py, tools/st_match.py, tools/st_modem.py, tools/st_netplay.py |
the Atari ST build in Hatari: a recording replayed, the inputs and the sound, two STs in a match; a WiFi modem emulated on Hatari's serial port; the networked game in a window to play by hand |
tools/pc_test.py, tools/pc_play.py, tools/pc_match.py |
the PC build in DOSBox-X: a recording replayed and timed, the inputs and the sound (speaker or FM), two PCs in a match (the modem, or PC_NET=pkt Ethernet) |
tools/web_test.py, tools/web_match.py, tools/webpage.py |
the browser build: every recording replayed in Node.js, two browser tabs in a match (Chromium over its DevTools port), the tab driver |
tools/fusex_match.py |
two FuseX with the real Spectranet firmware (tools/fusex.py drives FuseX through its GDB server) |
tools/softnet_test.sh |
the software network device on a PC: two processes in one room |
tools/set_relay.py |
not a test: points a release file (Spectrum, CPC, Atari, C64, Amiga) at another relay |
tools/amiga_test.py, tools/amiga_play.py, tools/amiga_match.py, tools/amiga_icon_test.py |
the Amiga build in FS-UAE: a recording replayed (from DH0: or the ADF), the inputs played, two Amigas in a match, the icons and a start from Workbench |
tools/test_portable.sh |
the PC simulator natively and on big-endian PowerPC (qemu), replaying tests/recordings: the core's byte-order check |
tools/sim6502.py |
the core on a 6502 (llvm-mos and its simulator, c/platform/sim6502): a recording replayed with its hashes checked, frames timed in cycles |
tools/netbench.py |
network timing of a real-time match, local relay or production, including the play page (tools/web_join.mjs, tools/netproxy.py) |
tools/browser_match.mjs |
two browser tabs play a match on the site |
tools/emu.py |
drives a headless mz800emu over its MCP pipe: load, keys, frame benchmarks, screenshots |
tools/cpcemu.py, tools/cpcemu_selftest.py |
a scripted Amstrad CPC with an M4 board (sockets emulated at its port interface) for the CPC port, and its self-test |
SIM_MODE=1 SIM_PLAYERS=2 SIM_SEED=0x1234 SIM_RECORD=build/replay/dm.bnr c/build/sim 3000 7
SIM_REPLAY=build/replay/dm.bnr c/build/sim 3000 99 # PC replay, different bot seed
tools/replay.py build/replay/dm.bnr # the same recording on the MZ build
tools/replay_zx.py build/replay/dm.bnr # and on the Spectrum build
The emulator paths come from $MZ800EMU (default
~/src/mz800emu/build/build-mz800emu/mz800emu) and $FUSEX. The network tests
need the local relay (above); FuseX needs a virtual display (Xvfb :97).
Building FuseX and its quirks: port-zx-spectrum.md.
bomber.asm is the complete, commented disassembly of the 1983 tape
(bomber.mzf, not in the repository: Hudson Soft's game). ./build.sh
reassembles it with pasmo, and with the tape in the repository root it
checks that the result is byte-identical. Memory map, rendering model, data structures, quirks, what the C port
changed on purpose and how fast it runs: original.md.
| file | content |
|---|---|
original.md |
the 1983 original: memory map, rendering, data structures, quirks; the C port's deliberate changes and performance |
net-protocol.md |
the network device (card commands, ten calls) and the relay protocol |
net-timing.md |
network timing measurements and the 0.2.0 fixes |
port-zx-spectrum.md |
the ZX Spectrum port: feasibility, plan, measurements, FuseX |
port-amstrad-cpc.md |
the Amstrad CPC port with the M4 board: feasibility and plan |
port-atari-xl.md |
the Atari XL/XE port, the first 6502 one: plan and progress |
port-c64.md |
the Commodore 64 port (WiC64 or an Ultimate's network): plan, measurements, VICE as the test bench |
port-amiga.md |
the Amiga port (any 68000 Amiga, bsdsocket.library): plan, measurements, FS-UAE with a free AROS ROM as the test bench |
port-atari-st.md |
the Atari ST port (a WiFi modem on the serial port): plan, measurements, Hatari with EmuTOS as the test bench |
port-pc.md |
the IBM PC port (DOS; CGA, EGA, VGA; Ethernet or a WiFi modem; AdLib/Sound Blaster): plan, measurements, DOSBox-X as the test bench |
setup/ |
the players' setup guides, one per platform, and network play (rooms, the delay, a relay of your own, the messages) |
port-web.md |
the game compiled to WebAssembly for the browser (no emulator): plan, results, the page on mzpico.com |
portability.md |
the rules that keep one C game for Z80, 6502 and 68000 machines |
port-zx128-esp01.md |
the 128K Spectrum with an ESP-01 (Milan Stava's port, brought in step by step): plan and progress |
port-zx-next.md |
the ZX Spectrum Next: the 128K build and its ESP driver on the Next's UART; plan and progress |
../PLAN.md |
the multiplayer plan the C port followed |