CppCon 2016: Jason Turner “Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17”
CppCon13 HN recommenders · recommended in 10 months, 2016–2024
talk · intermediate · evergreen · 2016–2024 on HN
Jason Turner's CppCon 2016 talk builds a simple Commodore 64 game using C++17, showing how constexpr and const let a modern compiler produce tight 6502 code. He walks through assembly output to show abstractions being optimized away.
A perennial favorite, recommended as proof that expressive modern C++ can compile to efficient code even on tiny retro hardware.
Up next
3 mo on HNWhy Starting A Rocket Engine Is So Hard!
Everyday Astronaut
3 HN recommender · 2023–2026
3 mo on HNA4 / V2 Rocket in detail: Turbopump
Astronomy and Nature TV
3 HN recommender · 2019–2022
3 mo on HNWhy guitarists USED TO play more in tune! (Microtonal Frets)
Brandon Acker
3 HN recommender · 2022–2026
2 mo on HNSuperluminal Time Travel + Time Warp Challenge Answer
PBS Space Time
2 HN recommender · 2018–2022
2 mo on HNStrange Spheres in Higher Dimensions - Numberphile
Numberphile
2 HN recommender · 2020–2025
2 mo on HNDelvon Lamarr Organ Trio - Warm-up Set (Live on KEXP)
KEXP
2 HN recommender · 2020–2025
13 mo on HNMIT's Pathway to Fusion Energy (IAP 2017) - Zach Hartwig
MIT Plasma Science and Fusion Center
16 HN recommender · 2017–2023
7 mo on HNmRNA Translation (Advanced)
DNA Learning Center
4 HN recommender · 2014–2025
11 mo on HNCppCon 2015: Andrei Alexandrescu “std::allocator...”
CppCon
7 HN recommender · 2017–2025
12 mo on HNLexical Scanning in Go - Rob Pike
GoogleFOSSSydney
13 HN recommender · 2012–2025
10 mo on HNCppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”
CppCon
9 HN recommender · 2018–2026
9 mo on HNRustConf 2018 - Closing Keynote - Using Rust For Game Development by Catherine West
Rust Programming Language
9 HN recommender · 2018–2023
12 comments from Hacker News
Absolutely. There was a fantastic talk at CppCon last year, using C++17 to program a game for the Commodore 64. Using standard C++ idioms, the optimizer was easily able to make it compile down to efficient machine code. [1] ▶ this video
For those who haven't seen it, there is a wonderful talk by Jason Turner about writing a simple Pong clone for the Commodore 64 in modern C++: ▶ this video
There's a great talk [1] in which C++17 features are used to build an efficient Pong clone on C64. As I recall, the author wound up writing an (obviously limited) x86-to-6502 translator to get around the lack of 6502 support. [1] ▶ this video
Creativity flourishes with the right restrictions. In this case, the graphics and sound limitations. Also, just because you're targeting old platforms doesn't mean you need to use old platform's tools. Modern tools make it so much easier to develop on these old platforms, check out this talk about coding in C++17 for the Commodore 64 ▶ this video
> Nor does it have any concern for the elegance of its design. It has a lot of inelegant facilities, which, when used under the hood, allow you to express your elegant abstractions. > Hence the common practice of using a small subset C++ and pretending it's just C with Extras. That's mostly failure to use C++. Since C++11, and especially with later updates to the standard, idiomatic C++ is very different from C - even if you're not using a lot of the standard library. I'll link to a talk already linked-to in another comment in this discussion: Rich code for tiny computers / Jason Turner, CppCon 2016 ▶ this video
> I was hoping someone could prove this, actually. Maybe this presentation by Jason Turner from CppCon 2016 can illustrate just what can be done in C++17. His target in the presentation is a C64, but I think it illustrates well just what you can do with the language, and hence what tools are available for writing fast code. ▶ this video edit: If you just want a quick fix, check out what a simple keyword does here: ▶ this video
This talk proves this point exactly: ▶ this video Watch from 27:00 where he talks about using const wherever possible so the compiler can optimise. It reduces a full function call to work out a colour in 3D space from thousands of instructions to one. After watching this and a few others particularly dynamic dispatch in Swift, I find myself adding as many hints as I can and applying the most restrictions / scoping possible. Final, const, Private etc. link Even though actually it can work this out in your module!
> And once You think you’ve run hw to its limits there are plentiful demos and examples around to blow your mind watching what people have been able to do with these machines (often in obscure ways). What blew my mind was using a modern C++ compiler to build optimized software for that old hardware. Here's an example with the Commodore 64 [0]. [0]: ▶ this video
For the note: ChaiScript is from Jason Turner. He also does CPPCast ( link ) and is a regular presenter at CPPCon ( ▶ this video ). Many of his videos / tutorials are worth a look if you are interested in C++.
Also highly recommended: Anything by Jason Turner and Ben Deane. Examples: - Ben Deane - Using Types Effectively [0] - Jason Turner - Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17 [1] - Ben Deane & Jason Turner - constexpr ALL the Things! [2] [0] link [1] ▶ this video [2] link
I think this way of looking at it old. Even if the const-ness is somehow subverted without generating an error then most compilers (or at least GCC and Clang) will presume the code is compliant and make optimizations following what the standard allows. This potentially results in undefined behavior when that pointer you mentioned is used to modified a thing that ought to be const. Consider the amount of optimizations seen in the video from CppCon 2016: ▶ this video Jason Turner, the presenter, is writing code a few lines at a time and cross compiling for the Commodore 64. He shows his assembly at many steps of the way and shows how many functions are completely elided when const (and later constexpr) are used correctly. There are a ton of other good talks from CppCon 2016 including one about const and what optimizations it makes possible and several about how compilers are more willing to "break" code that is non-compliant by making its behavior undefined. None of it really shocking or new, unless you have been writing to one compiler implementation instead of to the standard.
Your second link reminded me of link (which definitely builds on some of Matt's work). ▶ this video - C++17 for the Commodore 64. Probable language warnings for my other suggestions: * Rescuing Prince of Persia from the Sands of Time link (was this talk ever given elsewhere?) * And You Shall Know Me By My Trail of Documentation - link * The History and Evolution of Computer Viruses - link