Oscilloscope Snake
NOTE: The Polish version of this article is also available.
Introduction
The idea of displaying something on oscilloscope isn't really new. As you probably know, the first CRT tube based game was Pong. Still, when my friend first told me about his oscilloscope Tetris game, I was totally amazed and I decided to build something similar just to see if it's possible at all.
My initial goal was to make a Tetris, but it turned to be a bit too much of a coding challenge. I'm not a brilliant coder, and so I wrote Snake.
Design
There's not much more than a microcontroller, two DACs and a bunch of buttons. The following parts were used:
- DS89C450 - a fast (just one clock cycle per machine cycle) 8051 from Maxim/Dallas. It's 12 times faster than 'plain' 8051, but the speed turned out not to be as important as I initially thought. The choice if CPU isn't very important - I used that one simply because I had it in my toolbox at that moment.
- DAC08 from Analog Devices. They are simple plain 8-bit DACs with symmetric current outputs. It took me some time to understand the way it works, and I ended up copying the application note schematics. It would be MUCH easier to use a microcontroller with integrated DACs, but I didn't had any at that time.
- Pushbuttons. Pretty easy. Later I used a Commodore 64 joystick, it was good too.
- 8051 evaluation board - with RS232 interface, linear regulators, etc.
Operation
Implementation is rather quick and dirty - I just couldn't wait to get it done. ;-) It's an almost typical Snake implementation. See source for more details (but beware, it's very poorly commented).
Viewport is accessed by positioning the dot on a 256x256 grid. By moving the dot quickly, we can draw images. Here's the code used for drawing one square:
#define BOK 12
#define SQR 16
#define OFF 2
void vp_kwadracik(u8 x, u8 y)
{
X= x*SQR + OFF;
Y= y*SQR + OFF;
for (kw_c=BOK; kw_c; kw_c--) { X++; }
for (kw_c=BOK; kw_c; kw_c--) { Y++; }
for (kw_c=BOK; kw_c; kw_c--) { X--; }
for (kw_c=BOK; kw_c; kw_c--) { Y--; }
}
There was one more problem - random number generation. I implemented it with a simple spinning 8-bit timer. Needed 4-bit random values are acquired by splitting its value into two parts at the moment they were needed. This solution turned out to be enough to be random.
Compilation
Sources were compiled using SDCC. It's an open source compilator for small 8-bit CPUs. It's not very good (segfaults sometimes), but at least it's free.
- Firmware source [11K, GPL]
Schematics
- Evaluation board [57K]
- DAC board [19K]
Gallery
- The Hardware [93K]
- Commodore 64 Joystick [45K] - fully compatible with the OscilloSnake :]
- Evaluation Board (high res) [433K]
- Oscilloscope [40K]
- MOVIE - playing the game [2.9MB!]