One of the few ECE classes that I enjoy is ECE390. That being the only reason why I volunteered to be an undergraduate TA for the class. As a TA, sometimes I have to write a machine problem for the students. For their third machine problem this semester, I decided to write this game for them. It is a simple game of snake that involves interrupts, text video mode and data structures; all done in x86 assembly.
Since this is a class assignment, I will refrain from divulging too much about it. Suffice to say the original version that I completed in about 6 hours has about 1050 lines of code. That is a lot of code for assembly. So to help maintain the students' sanity, we decided to trim the amount of code they have to write by half. I would have wanted them to write the whole thing because there are subtle points that can only be illustrated by coding. However, since the assignment still involves writing 19 subroutines after the code trim down, I should not demand more.
What I learned while coding this machine problem was the fact that you cannot escape from the code a little test a little mentality. In fact it makes the program that much more fun and less frightening. It is hard to write everything without testing. Even more so when it involves replacing the interrupt vector table with your own interrupt service routines. Do this wrong and it is almost impossible to debug.
Here are some details about the game:
- The snake is implemented using a queue. Using a queue gives the students exposure to how data structures are done in assembly. And it helps them see the real stuff behind the abstraction that we have with higher level languages.
- The user designs the layout of the game with the mouse before playing. The walls in the picture above was generated by me before playing the game.
- All the graphics is done in text mode. This is not even the popular mode 13h. So although the graphics is crude, it fits nicely for this game since the snake is supposed to be squarish.
I can think of a few improvements for this program though:
- Make the snake wrap around the edges. Currently, if you hit the gray border, your snake dies. It would be cool to be able to get the snake to wrap around the edges.
- Let the user save the design onto a file that can be laoded. That way the user can actually generate complex mazes and save them for later.
- Improve the I/O event loop. The motion of the snake is a bit jerky and can be improved by handling the event loop in a more efficient manner.
Still this was a simple program and it is my first assignment for my students. We shall see what they think of it. At least they can actually "play" with this game.Tweet
comments powered by Disqus