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.
Why Hacker News points people here: A perennial favorite, recommended as proof that expressive modern C++ can compile to efficient code even on tiny retro hardware.
“there is a wonderful talk by Jason Turner about writing a simple Pong clone for the Commodore 64 in modern C++”HN comment, 2016
“there is a wonderful talk by Jason Turner about writing a simple Pong clone for the Commodore 64 in modern C++”
Writing a Pong clone for the Commodore 64 in modern C++.
Full comment
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
Strongly recommendsMereInterestFeb 2017
“There was a fantastic talk at CppCon last year, using C++17 to program a game for the Commodore 64.”
Standard C++ idioms compile to efficient Commodore 64 machine code.
Full comment
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
Recommendsvoltagex_Oct 2016
“C++17 for the Commodore 64.”
C++17 for the Commodore 64 listed among favorite tech talks.
Full comment
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
Recommendsbeached_whaleOct 2016
“Cool presentation too, and uses Godbolt's tool”
Shows compiler optimizing away code when const is used, via Godbolt.
Full comment
Check out the cppcon 2016 presentation by Jason Turner and watch how eager the compiler optimizes away code when const is enabled on values. Cool presentation too, and uses Godbolt's tool this video
RecommendssqeakyJan 2017
“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.”
Shows assembly at each step and functions elided by const and constexpr.
Full comment
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.
RecommendsNimelrianOct 2018
“Also highly recommended: Anything by Jason Turner and Ben Deane.”
Listed among highly recommended talks by Turner and Deane.
Full comment
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
Recommendsadev_Jul 2019
“Many of his videos / tutorials are worth a look if you are interested in C++.”
Turner is a regular CppCon presenter with worthwhile talks.
Full comment
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++.
RecommendsinetknghtMar 2020
“What blew my mind was using a modern C++ compiler to build optimized software for that old hardware.”
Modern C++ compiler building optimized software for Commodore 64.
Full comment
> 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
RecommendsmagicalhippoApr 2020
“Maybe this presentation by Jason Turner from CppCon 2016 can illustrate just what can be done in C++17.”
Illustrates what C++17 can do for fast code on a C64.
Full comment
> 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
RecommendsdhsysusbsjsiApr 2020
“Watch from 27:00 where he talks about using const wherever possible so the compiler can optimise.”
Using const cuts thousands of instructions to one.
Full comment
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!
RecommendseinpoklumMay 2022
“idiomatic C++ is very different from C”
Shows idiomatic modern C++ very different from C.
Full comment
> 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
RecommendsciroduranSep 2022
“check out this talk about coding in C++17 for the Commodore 64”
Modern C++17 tooling used to build a game for the Commodore 64.
Full comment
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
Recommends0xcde4c3dbFeb 2023
“There's a great talk [1] in which C++17 features are used to build an efficient Pong clone on C64.”
Building an efficient Pong clone on C64 using C++17 features.
Full comment
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
Cites itscooprOct 2016
Approach converting x86 asm to 6502 asm.
Full comment
I'm having hard time deciding if this is a cleaner approach than converting subset of x86 asm to 6502 asm[0]. The reassembler seems like it has smaller surface area to worry, more rigid semantics, but then again it is very platform specific.. [0] this video
Cites itgravypodFeb 2017
“using that transpiler written for that talk at the last CppCon.”
Mentions the transpiler written for this talk.
Full comment
I'd love to see this rewritten in C++ using that transpiler written for that talk at the last CppCon. this video
Cites itjcelerierDec 2018
Shows modern C++ templates and constexpr compiling for Commodore 64.
Full comment
let's keep in mind that even though Torvalds said this from the kernel point-of-view, he agreed in porting his userspace app Subsurface from C with GTK to C++ with Qt. link Besides, there's really not much point in comparing, 1991 non-standardized "vector<bool> sounds like an awesome idea but first we have to find a compiler which implements inheritance properly" C++ with 2018 "you can compile template metaprogramming and constexpr stuff on commodore 64 and windows 10 and it works fine" ( this video )
Cites itmrkeenFeb 2021
“C++17 on the Commodore 64”
Footnote citing C++17 running on the Commodore 64.
Full comment
C maps to the machine well. (Low-level programmers will probably crucify me for that.) But take its lack of closures as an example. Closures require either some kind of memory management, or clever program transformations, at which point you lose the simplicity of just having the stack and heap. As much as a generation of Java programmers (like myself) grew up thinking that C++ was old hat and Java was its natural successor, C++ has been quietly ahead of Java with regard to lambdas, generics, type-level trickery. Not to mention performance and backward-compatibility [1]. But reading C++ makes my eyes bleed. I much prefer FP for business logic and web-app development. Haskell is fast but it's no C++, and that's OK. I wouldn't want Haskell to take C/C++ market-share. I want it to compete against other languages that don't give me performance, safety or terseness. [1] C++17 on the Commodore 64: this video
Cites itMarcus10110Jun 2022
“After watching Jason Turner's CppCon talk on writing an i386 to 6502 assembly translator”
Talk on i386-to-6502 translator inspired a 6800 fork.
Full comment
I have an ET-3400 on the shelf behind me! I was just playing with it the other day. After watching Jason Turner's CppCon talk on writing an i386 to 6502 assembly translator [1][2], I started working on a fork that would target the 6800. I only got about 3 instructions working, but that's really all you need for some really simple test code with optimization turned to the max. It also turns out that someone wrote a fantastic emulator specifically for the ET-3400 trainer [3], and I managed to get my application running on it! [1] this video [2] link [3] link There is something special to me about the idea of writing modern C++, and compiling it for such early microprocessors. The 512 bytes of RAM is a pretty big limitation though. I wanted to try and emulate an EEPROM using an Arduino or FPGA, but got stalled out on the project. From time to time I like to browse through the LLVM backend documentation, but I can't seem to commit to trying to build a backend.
Cites itpjmlpSep 2024
Talk on writing C++ templates under extreme memory limits.
Full comment
"Template specialization means more generated code, which, again, must fit in 2kb." Have fun, "Rich Code for Tiny Computers: A Simple Commodore 64 Game in C++17" this video
CriticalfredsanfordOct 2016
“Take a look at the useless features and bloat in this video.”
Full comment
Take a look at the useless features and bloat in this video. Modern C++ isn't what you think it is. this video