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:


  1. Declare any variables that are needed

  2. Initialize the Gameboy (already done by VH)

  3. Initialize the background mode using ham_SetBgMode

  4. Initialize variables x and y to the coordinates of the pixel in the center of the screen

  5. Clear the screen with the background color using ClearScreen

  6. In the while loop, the program should do the following tests and actions

    1. Color the pixel at coordinates (x, y) using ham_PutPixel

    2. Check if the Left button has been pressed, if so update x so that (x, y) is now one pixel to the left

    3. Check if the Right button has been pressed, if so update x so that (x, y) is now one pixel to the right

    4. Check if the Up button has been pressed, if so update y so that (x, y) is now one pixel higher

    5. Check if the Down button has been pressed, if so update y so that (x, y) is now one pixel lower

    6. Check if the Select button has been pressed, if so clear the screen using ClearScreen

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


  1. Click on the File menu and choose New, then Project. This gives you the dialog box to create one.

  2. 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.

  3. 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:


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 3