ECAD and Architecture Practical Classes
The next task is to make use of the mouse, so that when you click on a square the state changes from dead to alive, or vice-versa. This will be accomplished using assembler which will run on the MIPS processor, so you'll be pleased to know that there shouldn't be any need to re-compile the Verilog files, which takes a while.
SOPC component addresses
The SOPC component module mentioned on the previous page contains modules that the 7-segment displays and LEDs have been wired into. These have been mapped to addresses as follows:
- Red LEDs: 0xF000_0800
- Green LEDs: 0xF000_0810
- 7-segment displays: 0xF000_0820
- DPRAM (contains the grid state): 0xF000_0000
Thus, to display data on them, simply write to the relevant address, as in the code above. The frame buffer is located at base-address 0xF000_0000, with subsequent byte addresses giving each cell of the grid, left-to-right, top-to-bottom up to address 0xF000_07FF. This is the same memory module that the renderer reads out of to display the state (don't worry; it is dual-ported and dual-clocked so there's no need to worry about concurrency problems or crossing clock domains). The final component you will need to use is the one containing the mouse movement information. This contains 4 words of data, detailed below:
- Indicator whether KEY3 has been pressed to advance the state: 0xF000_0830 Note that this value changes when the key is pressed.
- Indicator whether the left mouse-button has been pressed: 0xF000_0834 Note that this value changes when the button is pressed.
- Current x position of the mouse cursor: 0xF000_0838
- Current y position of the mouse cursor: 0xF000_083C
Important: currently, if you perform 2 consecutive loads from this module, the first value returned is always zero. To fix this, place a nop in-between the load instructions.
You should now be ready to write the code that will change a cell when it is clicked on. Open up the assembly file life.S from the toolset directory, and insert your code where marked in order to perform the required task. There should be a main loop that iterates over and over checking the current value for the mouse-click, and when this changes, you should jump to a function that actually performs the change. You may find the MIPS page useful.
The grid state is stored in the Dual-Ported RAM. The MIPS sees this
starting at address
0xF000_0000, with the layout the
same as before - i.e. each cell being stored in a single byte, with
the top-left cell at address
0xF000_0000 and then
increasing left-to-right, top-to-bottom, as for the renderer.