CS/ENGR
101: Gameboy Session
Fall 2006 – Etch-a-Sketch Project (Days 5 &
6)
Due: Monday, November 20
Etch-a-Sketch®†
Etch A Sketch® is a toy invented in 1959 by Frenchman Arthur Granjean that was introduced commercially by the Ohio Art Company in 1960. Below is a picture:

The toy works as a simplified version of a plotter. The inside surface of the glass screen is coated with aluminum powder, which is then scraped off by a movable stylus leaving a dark line on the light-gray screen. The stylus is controlled by the two large knobs, one of which moves it vertically and the other horizontally. To erase the picture, one simply turns the toy upside down and shakes it, thus recoating the surface.
Gameboy Sketch
For this project, you will write a program that will allow a user to use the Gameboy as an Etch-a-Sketch®. Instead of knobs, we will use the Left, Right, Up, and Down buttons to control drawing horizontal and vertical lines. To erase, we will clear the screen when the Select button is pressed.
Here is an outline of what the basic Gameboy sketch program should do:
Declare any variables that are needed
Initialize the Gameboy (already done by VH)
Initialize the background mode using ham_SetBgMode
Initialize variables x and y to the coordinates of the pixel in the center of the screen
Clear the screen with the background color using ClearScreen
In the while loop, the program should do the following tests and actions
Color the pixel at coordinates (x, y) using ham_PutPixel
Check if the Left button has been pressed, if so update x so that (x, y) is now one pixel to the left
Check if the Right button has been pressed, if so update x so that (x, y) is now one pixel to the right
Check if the Up button has been pressed, if so update y so that (x, y) is now one pixel higher
Check if the Down button has been pressed, if so update y so that (x, y) is now one pixel lower
Check if the Select button has been pressed, if so clear the screen using ClearScreen
Delay for some amount of time (otherwise, the lines will be drawn too rapidly to control)
Logistics
Create a new VisualHAM project for this assignment. Recall that after launching VH, the steps for doing this are:
Click on the File menu and choose New, then Project. This gives you the dialog box to create one.
In the new project dialog box, select [C] Empty, type in a project name (for example, etch), and type the folder name where you want the project to go for a location (this needs to be specified using a drive letter, for example, I:\cs101\etch). Click OK.
In the left panel, there is a tree representation of the project. The code you write goes in the main.c file. Double-clicking on the entry will bring up the file in the main edit window.
A built-in function we need for this project is ham_PutPixel. This function colors a single pixel at a specified coordinate. The arguments to this function are an x-coordinate, a y-coordinate, and a color value. Here is an example of how it is used to color the center pixel red:
ham_PutPixel (119, 79, COLOR_RED);
You will need to use it to color the pixel of the line being drawn.
Assignment
This assignment is worth 40 points. They will be awarded as follows:
25 points – Writing a program that meets the basic Gameboy sketch program outlined above.
10 points – Complete both of the following enhancements:
Add code so that when the Start button is pressed, the screen is cleared, x and y are reset to be in the middle of the screen. That is, after this action, drawing starts as if the program was just turned on.
Explore what happens when you press the drawing buttons for a long time. Modify the basic program so that drawing a line does not wrap around the screen.
5 points – Complete at least one of the following enhancements. (Do both for extra credit.) Also, the Start button action needs to be modified to reset the state of the program back to the starting state.
Add code to allow the user to change the background color and the drawing color to a random color by using two buttons.
Add code to use two buttons to control when a pixel is actually drawn. The idea is that when one button is pressed, drawing is turned “off”, but the directional buttons still work. Then when the other button is pressed, drawing is turned back “on”. This will allow the user to draw pictures with non-connected lines. When drawing is turned back on, the line color should be the same as it was before drawing was turned off.
Put your name in a comment at the beginning of your program file. Email your completed program (the main.c file, not the project file) as an attachment to the instructor (hwang@evansville.edu) no later than 4:30pm on Wednesday, October 24
†From Wikipedia, http://en.wikipedia.org/wiki/Etch_A_Sketch
10/19/06