In this lab we will use the high level I/O capabiliধes of the DE1-SoC simulator to
1. display pixels and characters using the VGA controller, and
2. accept keyboard input via the PS/2 port.
For each of these topics, we will create a driver. We will test the drivers both individually and
in tandem by means of test applications.
1. Drawing things with VGA
The DE1-SoC computer has a built-in VGA controller that can render pixels, characters or a
combination of both. The authoritative resource on these matters is Sections 4.2.1 and 4.2.4
of the DE1-SoC Computer Manual. This section of the lab provides a quick overview that
should suffice for the purpose of completing this lab.
To render pixels, the VGA controller conধnuously reads the pixel buffer, a region in memory
starting at 0xc8000000 that contains the color value of every pixel on the screen. Colors are
encoded as 16-bit integers that reserve 5 bits for the red channel, 6 bits for the green
channel and 5 bits for the blue channel. That is, every 16-bit color is encoded like so:
The pixel buffer is 320 pixels wide and 240 pixels high. Individual pixel colors can be
accessed at 0xc8000000 | (y << 10) | (x << 1) , where x and y are valid x and y coordinates.
As previously hinted, we can also render characters. To do so, we will use the character buffer,
which is analogous to the pixel buffer, but for characters. The device’s VGA controller
conধnuously reads the character buffer and renders its contents as characters in a built-in
font. The character buffer itself is a buffer of byte-sized ASCII characters at 0xc9000000 . The
buffer’s has a width of 80 characters and a height of 60 characters. An individual character
can be accessed at 0xc9000000 | (y << 7) | x .
Task: Create a VGA driver
To provide a slightly higher-level layer over the primitive functionality offered by the pixel
and character buffers, we will create a driver. That is, a set of funcধons that can be used to
control the screen.
To help get you started, we created an application that uses such functions to draw a testing
screen. Your job is to create a set of driver functions to support the application. Download
vga.s and augment it with the following four functions:
VGA_draw_point_ASM draws a point on the screen with the color as indicated in the third
argument, by accessing only the pixel buffer memory. Hint: This subroutine should only
access the pixel buffer memory.
VGA_clear_pixelbuff_ASM clears (sets to 0) all the valid memory locations in the pixel buffer.
It takes no arguments and returns nothing. Hint: You can implement this function by
calling VGA_draw_point_ASM with a color value of zero for every valid location on the screen.
VGA_write_char_ASM writes the ASCII code passed in the third argument (r2) to the screen
at the (x, y) coordinates given in the first two arguments (r0 and r1). Essentially, the
subroutine will store the value of the third argument at the address calculated with the
first two arguments. The subroutine should check that the coordinates supplied are valid,
i.e., x in [0, 79] and y in [0, 59]. Hint: This subrouধne should only access the character
VGA_clear_charbuff_ASM clears (sets to 0) all the valid memory locations in the character
buffer. It takes no arguments and returns nothing. Hint: You can implement this function
by calling VGA_write_char_ASM with a character value of zero for every valid location on the