编程与软件工程youtube.com
Crash Bandicoot 如何“黑”进初代 PlayStation
How Crash Bandicoot hacked the original Playstation (2020) [video]
2020 — 2022,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这个视频(及其扩展版)讲述《古惑狼》的开发团队 Naughty Dog 如何在原版 PlayStation 上通过各种非正统的技术手段(hack)实现流畅的 3D 平台游戏效果。评论区补充了当时 PS1 开发者手写 MIPS 汇编、利用垂直空白中断做准多任务、以及用 Lisp 构建游戏逻辑等一手细节。
为什么经久不衰:它展示了在极端硬件约束下开发者如何靠创造力与底层 hack 突破极限,加上 Andy Gavin 的详细记录和亲历者回忆,使这段历史每隔一两年就被重新提起。
HN 评论精选
PS1 时代开发者靠手写汇编、填充加载延迟槽等极端手段榨取性能,作者亲历过这种开发方式。
当年做过 PS1 开发的人,都得靠各种疯狂 hack 来提升性能或省内存。我第一个项目里,图形引擎和动画系统有 C 版本作参考,同时还有一份超级优化的 MIPS 汇编版本。我把整个引擎和动画系统塞进 4K,好装进 CPU 指令缓存,整个帧更新周期的代码都不必访问主内存。另外,从主内存加载很慢(4 个周期),芯片又是 RISC(每周期一条操作),Load 指令后需要 3 个 NOP 寄存器才能加载完成;据我记忆,C 编译器从不会用有用的东西填满这 3 个 NOP。所以我手写 MIPS 汇编并发,在 NOP 里加载其它需要的东西——处理 3 维向量或 4 维矩阵时尤其有效。把超级优化的手写汇编并发一直记在脑子里是种挑战,不推荐这么做!不过引擎的吞吐量超过了索尼宣称的机器性能。每一点性能提升都意味着比其它游戏多一分优势。后来游戏被 Eidos 砍了。作为第一份行业工作,这打击挺大 :/
louthy查看英文原文
Anybody who did PS1 dev back in the day will have had to do some crazy hacking stuff to get performance or memory. The first project [1] I worked on I had a C version of my graphics engine and animation system, and in parallel I'd have a MIPS assembly version which was super optimised (the C version was effectively a reference). I made the whole engine and animation system fit in 4K so it would fit into the instruction cache of the CPU. The whole frame update cycle wouldn't need to touch main memory (for the code). Also, because loading from main memory was slow (4 cycles) and the chip was RISC (1 operation per cycle), you'd need 3 NOPs after the Load-op for the register to be loaded. The C compiler (if I remember right) never really filled those 3 NOPs with useful stuff. So, I'd do hand written concurrency (in MIPS assembly) by loading other stuff I'd need into those NOPs - this was particularly effective when working with 3 dimensional vectors or 4 dimensional matrices. Trying to keep super-optimised hand-written concurrency in assembly, in my head, was a challenge and not something I'd recommend! Still, the engine had more throughput than Sony claimed of their machine. Every bit of performance gained would mean an edge over the other games. Then the game was canned by Eidos. Pretty devastating for my first industry job :/ [1] https://www.unseen64.net/2020/11/16/lunatik-pure-entertainment-cancelled/
另一位开发者分享了自己在 PS1 上用垂直空白中断实现准抢占式多任务、让物理引擎等时运行的 hack。
说来远不如那个 YouTube 视频彻底/酷,但我们曾在原版 PlayStation 上做了一个有限的抢占式多任务系统,以恒定频率运行物理引擎。索尼美国和日本都说这不可能。我们最终想到用垂直空白中断保存所有寄存器,修改返回地址让中断返回到我们的物理代码,物理代码运行(不在中断上下文中),然后恢复寄存器并 longjmp 回原本被垂直空白中断打断的主游戏代码。这不是通用抢占,只有屏幕刷新率的固定除数可用,但足以让物理引擎接近等时运行。附注:我们的游戏相对很糟,我记得当时对 Crash 团队在玩法 and 图形上的成就充满敬畏。
sokoloff查看英文原文
Admittedly way less thorough/cool than the YouTube video, but we created a limited pre-emptive multi-tasking system on the original Playstation to run our physics engine at a constant frequency. Sony US and Sony Japan said it couldn't be done. We eventually figured out how to use the vertical blank interrupt to save all the registers, modify the return addres to return from the interrupt to our physics code, then our physics code would run (not in the interrupt context), then restore the registers and longjmp back to the main game code which had been originally interrupted by the vertical blank interrupt. This wasn't general-purpose pre-emption and had only fixed divisors of the screen refresh rate available, but was enough to get our physics engine to run close to isochronously. Side note: our game was comparatively terrible and I remember being in awe of what the Crash Bandicoot team accomplished in gameplay and graphics.
老游戏普遍靠 hack 主机来突破硬件限制,现代主机更像 PC,不再需要这种极端技巧。
很多 2000 年前的老世代游戏都是靠 'hack' 主机工作的——如果 hack 指的是以不该用的方式使用它、或让它做完全无关的事。从 8 位时代游戏电脑绕过 CPU 或 CRT 屏幕做出本不可能的效果(demo scene 里也很流行),到 Saturn 游戏被迫把一堆杂七杂八的芯片发挥到极致(比如用音频芯片跑部分图形计算),他们都得物尽其用。不是现代开发者能力不行,而是现代主机可塑性强得多、相对性能也强得多。基本就是 PC。最后一个需要特殊技巧的主机是 PS3,因为 Cell 架构很怪,完全不适合主要单核的游戏,开发者只好尽力让它跑好。看老东西时,与其说 '哇他们在这么差的硬件上做到了',不如说 '我真不认为用可用资源能做到那一步'。所以他们作弊了。或者叫 hack,随便你怎么称呼。Saturn 和 PSX 上有一些疯狂的东西。去看看 PSX 的技术规格,然后作为开发者告诉我,你觉得让《合金装备》《古惑狼》这类游戏跑在那上面合理吗?
nolok查看英文原文
Many, many games of the older gens (before 2000) worked by "hacking" their console, if by hacking you mean using part of it in ways it wasn't supposed to or to do something entirely different from what it was supposed to do. From very old 8 bit era "gaming computer" cheating around their CPUs or CRT screens to achieve effects that shouldn't be possible (also very popular in the demo scene), to games on the Saturn being forced to use the mashup of random chips to their best advantage (like running some graphics computation on one of the audio chips), they had to make with what they had. It's not so much that modern dev are not as capable, but modern console are much more malleable and offer much more power relatively speaking. Basically they're PC. The last console which required special tricks was the PS3, because the Cell was a weird ass architecture totally unsuited to mainly single core games, so devs had to do what they could to make it run well. When you look at old stuff, it's less "wow they were great to achieve that with such poor hardware" and more "I genuinely don't think it's possible to do that with the resources available ..." So they cheated. Or hacked. Whatever you want to call it. The Saturn and PSX had some insane stuff. Go look at the tech specs of the PSX and tell me as a dev you think it's reasonnable to expect games like Metal Gear Solid, Crash Bandicoot, etc ... To run on that thing. But still, the crown of "dev has to cheat around to do anything that wasn't 2d" remains with the Saturn, the best worst design ever for a console. On PC we have few equivalent because our chips have always been very multi purpose, historically they were merely vastly underpowered compared to specialized hardware console had (which is why Carmack's 2d and 3d marvels in the early 90s were so impressive, getting an engine similar to keen or wolfenstein or doom isn't very hard, getting it to run fast on the hardware of the time ... Well there is a reason the guy's name is known the way it is). War stories of developpers of that era are some of the best things to read as a non-dev game that enjoy reading about doing stuff you shouldn't be able to do. I remember reading such a thing about Panzer Dragoon II Zwei on the Saturn and it was so great, but apparently I didn't save the link and can't find it back.
Naughty Dog 用 Lisp(GOOL)构建游戏逻辑,这段记录对作者学习 Lisp 影响很大。
对我来说最有趣的是他们用了 Lisp:https://all-things-andy-gavin.com/2011/03/12/making-crash-bandicoot-gool-part-9/。读这篇对我的自我教育是很重要的资源。一个人看起来像接在 emacs 上、打字快到屏幕都跟不上,用这种我无法理解的 '巫师语言' 解决问题比我快几个数量级,让我见识了 Lisp 的威力。这既震撼又让人困惑,于是我开始找能一步步消化的 Lisp 材料(加上我买的书),非常有用,因为它讲的是真实问题,而不是书里那种过度简化的例子。
pritovido查看英文原文
The most interesting thing for me was the use of Lisp they did: https://all-things-andy-gavin.com/2011/03/12/making-crash-bandicoot-gool-part-9/ To read this was a very important resource for my own education. I was shown the power of Lisp by a man that looked wired to emacs and so fast typing I could not follow him on the screen that solved problems orders of magnitude faster than me using this "wizard language" I could not understand. It was mind blowing but at the same time very confusing, so I started searching material over Lisp that I could digest one step at a time and(combined with books I bought) that was very useful because it talked about real problems, not super simple simplifications like books did.
历次讨论
同类还值得读
开源应用架构
The Architecture of Open Source Applications
《开源软件架构》(AOSA)是一本在线免费书,邀请知名开源项目的作者亲自剖析其内部设计,涵盖 SQLAlchemy、LLVM、Audacity、Apache、Bash 等系统。
编程与软件工程上首页 9 次 · 2011–2024aosabook.org编辑精选编程语言简史:简短、不完整且多半错误
A Brief, Incomplete, and Mostly Wrong History of Programming Languages
一篇以戏谑、故意不准确的方式回顾编程语言史的博客文章,用夸张轶事和讽刺定义串起 Lisp、C、C++、Java、JavaScript、PHP 等语言。
编程与软件工程上首页 8 次 · 2009–2021james-iry.blogspot.comSQLite 是如何测试的
How SQLite is tested
SQLite 官方文档页,系统介绍 SQLite 的测试体系:多种测试方法(TCL 测试、模糊测试、回归测试、静态分析等)和海量测试用例,展示了这个小型开源项目如何靠极致测试获得…
编程与软件工程上首页 8 次 · 2009–2025sqlite.org编辑精选高级编程语言(2009)
Advanced programming languages (2009)
Matt Might 的经典文章,按用途推荐“高级编程语言”:如果追求就业就选主流语言,如果追求表达力、学术研究或创业,则推荐 Haskell、OCaml、Scala 等函数式语…
编程与软件工程上首页 8 次 · 2009–2022matt.might.net我的 Forth 与栈机器经历
Yosefk - My history with Forth & stack machines
作者以亲身经历回顾了使用 Forth 语言和栈式机器的历程:既赞叹其简洁优雅、代码量小、可自举的优点,也坦率指出栈操作在实际编程中的痛苦,以及 Forth 社区文化中的问题。
编程与软件工程上首页 8 次 · 2010–2024yosefk.com编辑精选