I was a bit disappointed though to see that this code used SDL for sprites and more stuff though. That’s not 1000 lines anymore imo. Still the code was an interesting read.
Thank you OP
I was a bit disappointed though to see that this code used SDL for sprites and more stuff though. That’s not 1000 lines anymore imo. Still the code was an interesting read.
Thank you OP
The only way arguably you could do it in pure C (with undefined behavior) is in enviroments that let you write straight to graphics framebuffers without any abstraction layer and even when you can't do keyboard or mouse input in C without library and/or kernel support.
Also, on older home computer systems the hardware was essentially the rendering- and audio-engine. Those systems were designed from the ground up to be convenient to program by directly writing hardware registers from assembly code (e.g. you didn't have to draw a sprite yourself, you just wrote a hardware register with a pointer to the sprite's image data in memory, and then wrote another hardware register to update the current sprite position and the video hardware did the rest). On modern hardware, providing such an interface is the job of drivers.
Back in the days of DOS I used to do this all the time :)
Double buffering was an understandable neat trick and one that would have taken me a bit longer to discover on my own. He also had a custom controller wired through the printer port and some C+ASM for interfacing with it.
I had three of his books, I think the Black Art book was constantly on my desk in the 90s.
Borland's dev tools came with "BGI" (Borlands Graphics Interface), but that's not necessary and wasn't really used for many games -- it provides abstract high-level drawing routines, like lines, circles, etc... that can be made to work on different graphics devices (CGA, VGA, ...). This was not necessary for direct graphics card access that most games used.
Whether it's worth doing is another matter.
Plenty of other comments have already disputed this. It's a reasonable mistake to make, especially if your experience is with more recent technologies and languages.
All the same if reminds me of this perennial quote from a man who really couldn't just use C for everything;
> On two occasions I have been asked, — "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" In one case a member of the Upper, and in the other a member of the Lower, House put this question. I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
- Passages from the Life of a Philosopher (1864), ch. 5 "Difference Engine No. 1"
Although I don't start new projects in C very often, I'm acutely aware how it's not turtles all the way down (as the logophiles believe), but rather C. With some infrequent exceptions the whole tower of abstraction was written in C. SDL is written in C, the compiler? C, the Linux kernel is written in C, the graphics driver was written in C, the GPU firmware was C. It might be unfeasible for you to get by without writing these yourself, but with enough C and somewhere to sit you can move the earth.
(Of course all projects have a smattering of other languages and with great effort you can bootstrap from Forth or handwrite assembly or whatever, but you can do it all in C, and very likely that's what happened.)
eg., "Q. Who is the king of france?", "A. France has no king, did you mean who was the last king of france?"
[0] https://files.osf.io/v1/resources/p4wqa/providers/osfstorage... [1] https://en.wikipedia.org/wiki/Succession_to_the_former_Frenc...
Babbage was insulting politicians who had, in the instance of his insult, a better grasp on the nature of intelligence than he had. It is a foolish quote to repeat, and reeks of the same smug obliviousness in which it was said.
If Babbage was fit to be so smug, he is fit to be called an idiot when having been so foolishly.
"Peak HN" is presumably when you can cite an oblivious smarter-than-thou Engineer at his most inastute, but not call one an idiot.
Please become familiar with the British sense of humor and the context of the writing before taking it at face value. If that is too much work, at least be prepared to give the writer the benefit of the doubt. Babbage was writing for a specific audience and with a specific intent, and I would suggest that you are probably misunderstanding him if you are inferring smugness from an isolated quote.
> I'm acutely aware how it's not turtles all the way down (as the logophiles believe)
De Chelonian Mobile
Get out of here with that monotestudonist heresy!
This is how I do fonts in one of my projects.
> I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. [...] , but you can do it all in C
If you trace the actual context of the conversation from ggp (doubtfuluser - "SDL is not 1000 lines anymore") to gp (shric - "pure C") ... it is clear that "pure C" was just an imprecise and shorthand alternative to saying the more verbose "pure ISO C Standard C with no extra external libraries such as SDL". (I.e. https://www.iso-9899.info/wiki/The_Standard ... has <stdio.h> and console printf() builtin there are no but no graphics and audio primitives)
But people just quickly type things out that seem obvious in a particular discussion e.g. "pure C" ... but can't foresee 4d chess moves ahead in how others will misinterpret phrases like that, and then the pedantic correction guns come out blazing.
<pedantic>But SDL _is_ "pure C".</pedantic> Yes, yes... I know. But one can just read gp's use of "pure C" with charity to see what he was trying to communicate.
I wouldn't even mention this, except that you've expressed a interest in avoiding misinterpretation.
This is a Linux-only situation. A significant fraction of systems code in Windows and macOS are written in fairly modern C++, including core system libraries and the kernel. A project that emerged out of Windows' C++ effort is the Windows Implementation Library[1]. I'm also certain Windows and macOS graphics drivers are written in C++.
Love this.
My original response was to the person claiming that it was basically cheating to use SDL. You need abstraction, so there is nothing wrong with having SDL in the way.
Someone said that it's C all the way down. It's not. The Linux kernel is not 100% C and it cannot possibly be.
There are no C facilities to:
- Read a keystroke and/or mouse (required for Flappy Bird) directly. C only supports reading from the stdin and stdout streams.
- Generate graphics (more on this below).
As I mentioned in the original post, some operating systems let you write straight to graphics memory.
While you can technically do this in C with a pointer to an address, you're still going to have to issue e.g. a BIOS call to set the mode to something other than the default text mode. But we can let that slide.
There is absolutely no way to do "C all the way down" when reading and writing I/O ports, executing interrupts, etc. which is required for I/O beyond just the buffered stdout and stdin streams that C provides.
Linux of course provides things in /dev, but they're also not C all the way down.
If there was a hypothetical computer which supported all graphics and other I/O via reading and writing to/from streams, then sure, but I don't think that computer exists.
I know very well what C can and cannot do, I've been using it for 40 years.
Discussed lately on HN: https://news.ycombinator.com/item?id=42010136