报道正文
本文目录3 个章节
Lest
A new 3D game for the Commodore 64
"He drove out the man, and at the east of the garden he placed cherubim and a flaming sword that turned every way…"

▶ Watch the trailer · Play it in your browser
Where it started
Can an unmodified C64 run a first-person 3D game at full resolution with a decent frame rate?
That was the question. And the answer turned out to be: better than I expected.
There have been many 3D games for the C64, even up to including a port of DOOM. However they all tend to have poor frame rate (under 10 fps) and often very blocky graphics. My goal was to see if the C64 could produce something smoother and clearer. And it turned out, it can.
Lots and lots of tricks were used to make it possible:
- screen drawn in character mode instead of bitmap mode
- character map built from sampling millions of rendered frames
- vertically mirrored scene so we only have to calculate the top
- ray cast hinted from previous frame does binary search for corners only
- interpolation of wall edges between corners
- wall seams projected instead of cast
- caching so unchanged areas aren't touched even when moving
- all entities are hardware sprites
- sprites are culled with precalculated zones
- sprites are occluded with per-frame occlusion stamps
And oh so much more. Aggressive profiling and optimizing, pass after pass, taking advantage of every simplifying rule of our game format, using every 6502 programming trick, precalculating as much math as possible, aligning tables in memory... you name it, it's in there.
Playing
You can play it online right now at:
https://needlestack.github.io/lest-c64/
That plays the cartridge. Add ?disk to the address to play the disk image
instead (with its 1541 load times), or ?dvorak for the Dvorak build (see
Building).
Or if you prefer, you can use VICE with
the disk image lest-c64.d64 in this repository, or the
cartridge image lest-c64.crt (see below).
Be sure to use x64sc and enable true drive emulation under peripherals: the fast loader runs its own code inside the 1541, so it needs a real (or truly emulated) drive. The same disk runs on NTSC and PAL machines (it detects which at boot), but it plays slightly better on NTSC, so set the machine to NTSC if you can.
The cartridge. lest-c64.crt is the same game as an
EasyFlash cartridge image, for an EasyFlash 3, Kung Fu Flash, Ultimate 64 or
1541 Ultimate, or any emulator (in VICE: x64sc -cartcrt lest-c64.crt). It
needs no disk drive at all, so it is the way to play on a machine whose drive is
an SD2IEC, which the disk's fast loader cannot talk to. It loads in under a
second; the controls come up first and wait for fire or SPACE, then the opening
quote and the title hold for a few seconds each, and fire or SPACE skips them.
Controls
| keyboard | joystick (port 1 or 2) | |
|---|---|---|
| forward, back | E, D | up, down |
| turn left, right | , . (the < > keys) | left, right |
| strafe left, right | S, F | hold the button + left, right |
| pick up, put down | SPACE | button |
| start again (after you're caught, or at the end) | SPACE | button |
Picking up and putting down happen when you let go of SPACE or the button, unless you strafed while holding it.
On a real C64 the joystick works in either port. In VICE, map the cursor keys or a gamepad to either joystick port. The online version is already set up.
Building
Requirements:
- a recent Node.js (developed on 26)
- ImageMagick 7 (
magickon the path; the build fits sprite art from the images inart/) - for the music, GoatTracker 2 (v2.76) with this project's patch to its
player: the build packs every song with its
gt2reloc. Using the macOS-buildable fork:
git clone https://github.com/joelricci/goattracker2 ~/goattracker2
cd ~/goattracker2 && git checkout 3885f28 # the commit LEST is built with
cd src
patch player.s < /path/to/lest-c64/music/goattracker-player.patch
make # macOS: needs `brew install sdl12-compat` and the Xcode command-line tools(gt2reloc carries the player inside it, so the patch goes in before make.)
The build looks for ~/goattracker2/linux/gt2reloc; set GT2RELOC to use
another. A stock GoatTracker is not enough (the build checks for the patch).
MUSIC=0 builds without music, and without needing GoatTracker.
The assembler (src/asm6502.mjs) and the disk-image writer (src/d64lib.js)
are part of the project. The test tools in tools/ also need
VICE 3.9; they look for
/Applications/vice-arm64-gtk3-3.9/bin/x64sc, and X64SC names another.
node src/build-iray.mjs # the whole game, levels 1-10 -> lest-c64.d64 and lest-c64.crt
D64=build/test.d64 node src/build-iray.mjs # the same, to another disk
DVORAK=1 node src/build-iray.mjs # -> alternates/lest-c64-dvorak.d64 and .crt
HEAVYSID=1 node src/build-iray.mjs # -> alternates/lest-c64-heavysid.d64 and .crtEvery disk is the whole game, starting at level 1. D64 names the disk to write;
without it, a build replaces lest-c64.d64, or its alternate in alternates/:
DVORAK=1reads the keys a Dvorak layout puts where QWERTY has E S D F and , . -- for a keyboard that does Dvorak in its own firmware. (A Dvorak layout set in the operating system needs nothing: the emulators read the physical keys.) The online version plays it at?dvorak.HEAVYSID=1opens every filter cutoff further, for a real C64 whose 6581 SID cuts more of the top than VICE's reSID, which the game is tuned for.
The two combine (alternates/lest-c64-dvorak-heavysid.d64). Each level and each removable wall
is built as its own sub-build first, so the engine can be laid out around all of
them; the sub-builds run in parallel and are cached in build/.cache/ under a hash
of every input they read (src/, data/, art/, music/, krill/, the environment, node
and ImageMagick), so a build is about 25 s cold and 5 s when nothing they
depend on has changed. NOSUBCACHE=1 makes them all fresh; de
(注:更多技术实现细节与完整 API 文档请查阅原项目 README)