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:

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.

Schematics

Gallery