惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
Arctic Wolf
U
Unit 42
爱范儿
爱范儿
WordPress大学
WordPress大学
博客园 - 司徒正美
腾讯CDC
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Last Week in AI
Last Week in AI
美团技术团队
博客园_首页
宝玉的分享
宝玉的分享
Hugging Face - Blog
Hugging Face - Blog
P
Palo Alto Networks Blog
H
Hacker News: Front Page
博客园 - 叶小钗
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
罗磊的独立博客
TaoSecurity Blog
TaoSecurity Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Help Net Security
Help Net Security
雷峰网
雷峰网
S
Security @ Cisco Blogs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Forbes - Security
Forbes - Security
T
Troy Hunt's Blog
V
V2EX
博客园 - 聂微东
Cloudbric
Cloudbric
大猫的无限游戏
大猫的无限游戏
Google Online Security Blog
Google Online Security Blog
S
Security Affairs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Commits to openclaw:main
Recent Commits to openclaw:main
IT之家
IT之家
S
SegmentFault 最新的问题
T
Threat Research - Cisco Blogs
J
Java Code Geeks
H
Heimdal Security Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Know Your Adversary
Know Your Adversary
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
AWS News Blog
AWS News Blog
The Cloudflare Blog
Simon Willison's Weblog
Simon Willison's Weblog
月光博客
月光博客
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

Hacker News

Introducing Claude Opus 4.7 Qwen Studio The Future of Everything is Lies, I Guess: Where Do We Go From Here? GitHub - SeanFDZ/macmind: Single-layer transformer in HyperTalk for the classic Macintosh Show HN: Agent-cache – Multi-tier LLM/tool/session caching for Valkey and Redis Moving a large-scale metrics pipeline from StatsD to OpenTelemetry / Prometheus GitHub - Nightmare-Eclipse/RedSun: The Red Sun vulnerability repository GitHub - SethPyle376/hiraeth: Local AWS emulator focused on fast integration testing, with SQS support, SQLite-backed state, and a debug-friendly web UI. GitHub - macOS26/Agent: Any AI, replaces Claude Code, Cursor, OpenClaw. Over 18 LLM providers (Claude, OpenAI, Gemini, Ollama, Zai, HF, Qwen) wired into a native Mac app that writes code, builds Xcode projects, bumps versions, manages git, automates Safari, use AppleScript, JS or Accessibility, extend Agent! w/ MCP Servers, run tasks from your iPhone via Messages. YouTube now lets you turn off Shorts I Made a Terminal Pager Burgers | マクドナルド公式 Commands — HackerNews CLI documentation ChatGPT for Excel PiCore - Raspberry Pi Port of Tiny Core Linux Live Nation illegally monopolized ticketing market, jury finds Google Broke Its Promise to Me. Now ICE Has My Data. Founding Engineer at Adaptional | Y Combinator CRISPR takes important step toward silencing Down syndrome’s extra chromosome GitHub - saffron-health/libretto: The AI toolkit for building reliable browser automations US v. Heppner (S.D.N.Y. 2026) no attorney-client privilege for AI chats [pdf] Unexpected €54k billing spike in 13 hours: Firebase browser key without API restrictions used for Gemini requests Retrofitting JIT Compilers into C Interpreters IPv6 – Google The Accursèd Alphabetical Clock Cybersecurity Looks Like Proof of Work Now Fragments: April 14 Cal.com Goes Closed Source: Why AI Security Is Forcing Our Decision | Cal.com - Scheduling Software for Online Bookings Laravel raised money and now injects ads directly into your agent When moving fast, talking is the first thing to break Too much Discussion of the XOR swap trick – Heather Cafe Introduction to Spherical Harmonics for Graphics Programmers The Grand Line Building a Z-Machine in the worst possible language High-Level Rust: Getting 80% of the Benefits with 20% of the Pain GitHub - duguyue100/midnight-captain: Inspired by Midnight Commander, tailored to my taste. How to build a `git diff` driver · Jamie Tanna | Software Engineer Center for Responsible, Decentralized Intelligence at Berkeley The Local Universe’s Expansion Rate Is Clearer Than Ever, but Still Doesn’t Add Up - A new synthesis of astronomical measurements confirms a persistent mismatch that could point to physics beyond current models The air throughout our homes is infused with microplastics. But there are things you can do to breathe less of them The disturbing white paper Red Hat is trying to erase from the internet – OSnews The Future of Everything is Lies, I Guess: Annoyances ‘Abhorrent’: the inside story of the Polymarket gamblers betting millions on war Productive procrastination — Max van IJsselmuiden maps, territory and LMs 447 Terabytes per Square Centimetre at Zero Retention Energy: Non-Volatile Memory at the Atomic Scale on Fluorographane Show HN: Pardonned.com – A searchable database of US Pardons 20 Years on AWS and Never Not My Job The Seasons are Wrong Artemis II crew splashes down near San Diego after historic moon mission We gave an AI a 3 year retail lease in SF and asked it to make a profit | Andon Labs How a dancer with ALS used brainwaves to perform live On filing the corners off my MacBooks Installing every* Firefox extension OpenClaw’s memory is unreliable, and you don’t know when it will break Steve Blank Nowhere Is Safe Chimpanzees in Uganda locked in vicious 'civil war', say researchers watgo - a WebAssembly Toolkit for Go linux/Documentation/process/coding-assistants.rst at master · torvalds/linux GitHub - callumlocke/json-formatter: Makes JSON easy to read. Founding Product Engineer at Bild AI | Y Combinator A compelling title that is cryptic enough to get you to take action on it GitHub - Keychron/Keychron-Keyboards-Hardware-Design: Industrial design files for Keychron keyboards and mice. 100+ models with CAD assets in STEP, DXF, DWG, and PDF. Source-available, with commercial use allowed for original compatible accessories within the license terms. [ANNOUNCE] WireGuardNT v0.11 and WireGuard for Windows v0.6 Released 1D-Chess Helium Is Hard to Replace Cooperative Vectors Introduction | Evolve Keeping a Postgres queue healthy — PlanetScale Our response to the Axios developer tool compromise Do Americans read print books, e-books or audiobooks more? The Zettelkasten Method in Obsidian: A Practical Setup Guide Artemis II Is Competency Porn and We Are Starving For It WeakC4 Flight Viz — Cockpit View A Mexican surveillance giant you’ve never heard of is now watching the U.S. border Surelock: Deadlock-Free Mutexes for Rust RISC-V 101 – what is it and what does it mean for Canonical? | Ubuntu The Problem That Built an Industry How Much Linear Memory Access Is Enough? | Solidean Investigating Split Locks on x86-64 Simplest hash functions Sybilproof reputation mechanisms (2005) [pdf] What is a property? How Complex is my Code? Static code analysis in Kotlin — tools overview Toffoli gates are all you need PGLite evangelism dcmake: a new CMake debugger UI Clojure on Fennel part one: Persistent Data Structures Fragments: April 2 Python Release Python install manager 26.1 The Life and Death of the Book Review - Liberties Introducing Database Traffic Control — PlanetScale Bitcoin miners are losing $19,000 on every BTC produced as difficulty drops 7.8% God sleeps in the minerals Building slogbox Apple Silicon and Virtual Machines: Beating the 2 VM Limit Who was “Not Even Wrong” first? Pokemon Evolution Vs Darwinian Evolution The APL Programming Language Source Code
GitHub - ttsiodras/3D-on-a-ZX-Spectrum-48K: Porting my 3D points renderer on a ZX Spectrum 48K
2026-05-17 · via Hacker News

The backstory

It all begun with the Speccy - the ZX Spectrum 48K+, to be precise.

I got it when I was 13 years old - the best gift ever:

Speccy

3D tinkering

An entire career has passed since then.

And one of the habits I picked up along the way, was fooling around in my free-time with SW-only 3D graphics.

In fact, a few years ago, I ported the main logic into an ATmega328P microcontroller, implementing "points-only" 3D rendering, and driving an OLED display via the SPI interface... at the magnificent resolution of 128x64 :-)

Real-time 3D on an ATmega328P

The challenge - run it on the Speccy

So the path to even more useless tinkering was clear:

I just HAD to make this work for the Speccy, too! :-)

And as you can see in this repository... I just did:

Real-time 3D on a ZX Spectrum 48K

The resulting statue.tap file is also committed in the repo, in case you just want to quickly run this in your FUSE emulator. I also added a second 3D model of a sphere - run sphere.tap in FUSE to see the result:

$ fuse -g tv3x tap/statue.tap
...
$ fuse -g tv3x tap/sphere.tap

Compiling

There's a simple Makefile driving the build process - so once you have z88dk installed, just type:

make clean all run

The cross-compiler used for the compilation is z88dk. If it's not packaged in your distribution, you can easily build it from source:

mkdir -p ~/Github/
cd ~/Github/
git clone https://github.com/z88dk/z88dk/
cd z88dk
git submodule init
git submodule update
./build.sh -p zx

You can now use the cross compiler - by just setting up your enviroment (e.g. in your .profile):

export PATH=$HOME/Github/z88dk/bin:$PATH
export ZCCCFG=$HOME/Github/z88dk/lib/config

On 3D projection and Z80 assembly

Since the Speccy's brain is even tinier than the ATmega328P's, I had to take even more liberties: I changed the computation loop to orbit the viewpoint (instead of rotating the statue), thus leading to the simplest possible equations:

int wxnew = points[i][0]-mcos;
int x = 128 + ((points[i][1]+msin)/wxnew);
int y = 96 - (points[i][2]/wxnew);

No multiplications, no shifts; just two divisions, and a few additions/subtractions.

If you're wondering how this can possibly be a valid 3D projection, you can read the full-of-math "for nerds" section below :-)

But that was not the end - if one is to reminisce, one must go all the way!

So after almost 4 decades, I re-wrote Z80 assembly - and made much better use of the Z80 registers than any C compiler can.

I also replaced the two costly divisions with two multiplications using a lookup table of reciprocals. In fact I pepper-sprayed "page-based" lookups ( mov H, hi-byte-of-table-offset; load index into L - read from (HL) ) for a final phenomenal speedup...

  • from 6.2 frames per sec (in C)
  • ...to 14.0 frames per sec (in optimised ASM)

Happiness :-)

Pre-calculating for maximum speed

I was also curious about precalculating the entire paths and the screen memory writes - you can see that code in the precompute branch.

Pre-calculated 3D animation on a ZX Spectrum 48K

As shown in the video above, this version runs 4 times faster, at 40 frames per sec. It does take a couple of minutes to precompute everything, though. Since I had all the time in the world to precompute, I used the complete equations (for rotating the statue and 3D projecting) in 8.8 fixed-point arithmetic:

3D Algebra

The reason for the insane speed, is that I precompute the target pixels' video RAM locations and pixel offsets, leaving almost nothing for the final inner loop, except extracting the memory access coordinates from 16 bits/pixel:

  • The offset within the 6K of video RAM, in the upper 13 bits
  • The pixel (0-7) within that byte, in the lower 3 bits

It's also worth noting that the inline assembly version of the "blitter" is 3.5 times faster than the C version. And I could optimise it more... but what's the point :-)

Since these are just reads, shifts and writes, I confess I did not expect to see that much of a difference... But clearly, C compilers for the Z80 need all the help they can get :-)

Addendum: For math nerds - how the projection works

Here we go: From raw floating-point data to ZX Spectrum screen pixels, with every step explained.

1. Source Data

The statue model consists of 153 3D points, stored in statue_data.py as floating-point values. These are processed by points_gen.py into a binary blob (points.bin) embedded into Speccy's memory - i.e. "burned" inside the .tap file and used as-is at runtime. There is some pre-scaling happening, to turn them into integer values (pre-scaled by S = 8960); simply put, integers are used at runtime to avoid floating point math on the Z80 - who simply doesn't support it!

1.1. Float-to-integer conversion

The scale factor S = 8960 is uniform across all three axes - for example...

{ 0.131,  0.116, -0.501 } x 8960 -> { 1174,  1039, -4488 }

Note that the actual ranges per axis are asymmetrical: the model is not centered.

2. Preprocessing (in the build pipeline)

To maximize runtime performance, the coordinates are not just scaled; they are also pre-transformed by points_gen.py before being embedded in the binary.

Here's how.

2.1. Axis swap

First, a swap:

tmp = Y; Y = Z; Z = tmp

The storage order becomes [X, Z, Y] instead of [X, Y, Z]. The per-point loop then, reading from (HL) as it goes, can compute depth and screen-Y first; and skip computing screen-X for out-of-vertical-bounds points.

It's a simple optimisation that helps performance a lot when we zoom-in enough for the statue to go out-of-bounds.

2.2. Point coordinates

The coordinates are also transformed into a "screen-ready" fixed-point space:

Component     | Raw formula              | After axis swap
--------------+--------------------------+--------------------
X'            | SE - X_raw / 14          | depth axis
Y'            | Y_raw / 9 * 64           | screen-X axis [2]
Z'            | Z_raw / 9 * 64           | screen-Y axis [1]

I know, this looks very cryptic - bear with me and keep reading :-)

With SE = 415 ( 256 + MAXX/16 ), and since we scaled by S = 8960:

X' = 415 - X_float * 640
Y' = Y_float * 63795.6
Z' = Z_float * 63795.6

This is what our transformed, final-integer-data look like.

2.3. Sine / cosine (camera orbit)

The sin/cos table is precomputed in tables_gen.py. To match the orbit radius and maintain 16-bit precision without runtime scaling, we additionally do this:

sin_val = (sin_raw / 3) * 64
cos_val = cos_raw / 3

...where the raw values are scaled by T = 256:

msin = sin(theta) * T * 64 / 3 = sin(theta) * 5461.3
mcos = cos(theta) * T / 3 = cos(theta) * 85.3

These different scale factors set the camera's orbit radius; tweaking to match the "orbit" perfectly to the model size.

But wait - why is sin scaling different to cos?

Well, in the final equations (coming up next), mcos just needs to offset the camera depth by the orbit radius - which is a modest shift. T/3 = 85.3 is right for that.

msin in contrast, gets divided by wxnew and added to the horizontal screen position. For a meaningful pixel shift, it needs to be much larger. The x64 multiplier gives T/3 x 64 = 5461.3 - which after the division yields a reasonable horizontal swing.

Simply put: the asymmetry is intentional! Both represent angles, but one controls how far the camera is (mcos -> denominator), and the other controls how far the point swings across the screen (msin -> numerator/denominator -> screen pixels).


3. The Projection Equations inside drawPoints

So in the end, our equations perform the simplest possible projection; there are no multiplications at run-time; only two divisions and a few additions.

wxnew = X'  - mcos
y     = 96  - Z' / wxnew
x     = 128 + (Y' + msin) / wxnew

How does this work? Let's see...

3.1. Full derivation in world units

96 and 128 are the mid-point of the Speccy's screen (256x192).

If we expand the equations and factor out 640 from the depth term, we get this

wxnew = X' - mcos
wxnew = (415 - X_float * 640) - (cos(theta) * 5461.3)
wxnew = 640 * (415/640 - X_float - cos(theta) * 5461.3/640)
      = 640 * (0.6484 - X_float - cos(theta) * 8.533)

Now, if we divide all numerators and denominators in the projection division by 640...

y = 96  - Z' / wxnew
x = 128 + (Y' + msin) / wxnew

...the equations become:

                            Z_float * 99.68
 y_screen = 96 - -------------------------------------------
                   0.6484 - X_float - cos(theta) * 8.533


                    Y_float * 99.68 + sin(theta) * 8.533
x_screen = 128 + ---------------------------------------------
                   0.6484 - X_float - cos(theta) * 8.533

And if we define depth as the positive distance:

depth = X_float + d * cos(theta) - d0

...and...

f  ~ 99.68 px        focal length       = S / 90
d  ~  8.53 units     orbit radius       = T * 64 / (3 * 640)
d0 ~  0.65 units     SE offset          = 415 / 640

...then the full projection equations become:

                  f * Z
y_screen = 96 - ---------
                  depth


                  f * Y + d * sin(theta)
x_screen = 128 + ------------------------
                          depth

It becomes clear now that these are the standard 3D projection equations; (see the diagram below) - with the d*sin(theta) offseting our camera's viewpoint by the rotation we apply.

3D Algebra, repeated for convenience

3.2. What each parameter means

Parameter    | Value       | Derivation                    | Role
-------------+-------------+-------------------------------+----------------------------
f            | 99.68 px    | S * 64/9 / 640 = S / 90       | Focal length, controls proj size
d            |  8.53 units | T * 64/3 / 640 = 256/30       | Camera orbit radius
d0           |  0.65 units | SE / 640 = 415 / 640          | Keeps model in front of camera
Screen centre| (128, 96)   | -                             | Half of 256 x 192
View dir     | +X          | -                             | Camera looks along +X axis

4. Camera Model

The camera goes around on a circle - around a point at a specific distance from the model.

camera_X(theta) = d * cos(theta) - d0 = 8.53 * cos(theta) - 0.65

4.1. Why SE = 415?

SE = 256 + MAXX / 16 = 256 + 2551 / 16 = 256 + 159 = 415

256      screen width, centres the model horizontally
MAXX/16  accounts for the X-range after preprocessing

Without SE, X' = -X_float * 640 could be negative for positive X, flipping the division sign and putting the model behind the camera. SE adds a constant offset so X' stays positive and depth > 0 for all model points.


5. Summary: The Full Pipeline

NOTE: the equations below are shown in their C form. The ASM version uses the same logic, substituting the two divisions with multiplications via the reciprocal lookup table.

Float data {X, Y, Z} in `statue_data.py`
       |
       |  Build Pipeline (`points_gen.py` & `tables_gen.py`)
       v
Pre-transformed coordinates in `points.bin`
(Scale S=8960, Axis swap, and Screen-space transform applied)
       |
       |  Runtime Loop
       v
X' = Precomputed depth axis
Y' = Precomputed screen-X axis (stored at [2])
Z' = Precomputed screen-Y axis (stored at [1])

msin = Precomputed sin(theta) transform
mcos = Precomputed cos(theta) transform

       |
       |  For each frame
       v

wxnew = X' - mcos         (depth from camera)
y = 96  - Z' / wxnew      (perspective -> vertical)

       |
       |  If 0 <= y < 192:
       v

x = 128 + (Y' + msin) / wxnew  (perspective -> horizontal)

byte_addr = ofs[y] + (x >> 3)  (done via scr_ofs lookup table)
bit_mask  = 128 >> (x & 7)     (done via mask lookup table
set bit in byte

Next step - the real thing

Now all I need to do is wait for my retirement... so I can use my electronics knowledge to revive my Speccy, and test this code on the real thing, not just on the Free Unix Spectrum Emulator :-)

Then again, maybe you, kind reader, can try this out on your Speccy - and tell me if it works?

Cheers! Thanassis.