Comment

Comment by jacquesm

Interesting metrics, you'd expect C to do a lot better in the line-count department than assembly.

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

  sudo apt-get install libsdl2-dev
Then change the include file line to

  #include <SDL2/SDL.h>
and type:

  make
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:

  cd inv1
  mv INVADERS.E invaders.e
  mv INVADERS.F invaders.f
  mv INVADERS.G invaders.g
  mv INVADERS.H invaders.h
  cd ..
Now the game should work:

  ./bin/si78c
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:

  while (num < 64)
    {
        int has = SDL_PollEvent(&event_buffer[num]);
        if (!has) break;
        num++;
    }
becomes:

  while (num < 64) {
    if (SDL_PollEvent(&event_buffer[num])) {
      break;
    }
    num++;
  }

Neat project!
parent jacquesm 7 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton