This is some rather strange advice. That and the rewrite dropped a '!'.
Both ways have some merit. Cuddled curly is good for ismple one-liners. Curly on next line is when the statement header is stuffed with multi-line expressions.
After all the years, I have settled on:
while (simple) {
}
while ((big || complex)
(condition && multiple && lines))
{
}
for (i = 0; i < MAX; i++) {
}
for (big_initialization;
big && step;
complex, increment++)
{
}The only way a single line deletion that contains curly braces will still compile is if it contains balanced curly braces:
if (cond)
{ foo }
stmt;
All styles which avoid this do not have an issue with the deletion of random single line that contains a curly brace.Regardless of bracing style, we can easily find lines in a program which can be deleted without causing a compile error, just not ones which open a syntax without closing it and vice versa.
Try not to randomly delete lines from your program, and inspect your "git diff" or what have you should such a thing happen.
The code is a bit terse due to a mechanical issue - my current laptop screen only gives me about 25 lines vertically.
CFLAGS := [other flags...] $(shell sdl2-config --cflags)
LDFLAGS := [other flags...] $(shell sdl2-config --libs)
That will set the correct compiler and linker flags for you installation, and you can leave the include as just "SDL.h".Imagine if every package with headers and libs had its' own "<package>-config" program! That would be a huge problem, which is why there is one program called package-config, to which packages or build systems just contribute blurbs of info in .pc files.
You would but it's worth keeping in mind this implementation is constrained by closely following the structure and logic of the original. It's like writing C but being told exactly what state you have to maintain (and where), down to the bit, in advance. It really is a 'hardware simulator' where the spec and input handed to you is the sequence of memory states (and a few other bits) of the original machine.
The C version also loses a few lines here and there for function prototypes and structured control flow.
Handwritten 8085 can be quite compact in some places due to sharing code fragments. It's a bit like self ROP.
int has = SDL_PollEvent(&event_buffer[num]);
if (!has) ...
to if (SDL_PollEvent(&event_buffer[num])) ...
because it generally makes inspecting the return value of the function, in this case SDL_PollEvent, easier to inspect in a debugger.Particularly handy in the Visual Studio debugger when working with C#.
If you don't want to remember, you can write a macro for it.
GDB probably has something builtin for this, but I gave up trying to find features in GDB a long time ago.
[edit]
Stackoverflow seems to be of the opinion that GDB doesn't have a tool for automatically showing the return value of a just-called function. However if you step into a function and execute the command "finish" you will return from the function and print the value. Properly showing the return value with source-level (rather than instruction-level) debugging is a non-trivial feature to get right.
That kind of feedback is gold.
I have updated the README with the correct Ubuntu package details.
I think the issue with the includes is likely to do with having both SDL1 and 2 installed, and the slightly dirty way I am pulling in the header (so it works on Mac too).
I will have a bit of a think about how best to resolve that issue, likely needs some ifdefing.
Not necessarily if the C code is trying to reproduce, in detail, all of the externally visible effects of the original assembly language.
rename 'y/A-Z/a-z/' *
I tried building it on Ubuntu, if you follow the instructions the SDL library include files will end up in a directory called SDL so you have to include SDL/SDL.h and even then the build fails with lots of SDL related definitions missing (SDL_Window for instance).
That's because you really should be doing
Then change the include file line to and type: The roms can be found here:http://www.freevintagegames.com/MAME/invaders.php
After downloading you'll have to rename the files because the names will all be uppercase:
Now the game should work: Some minor nitpicks about the code:- bracket your ifs and place the starting { on the same line as if/while, or one day you'll sit there staring at the screen for 8 hours trying to figure out why your code no longer works due to an accidentally deleted line.
So:
becomes: Neat project!