Monday, January 27, 2020
Lab 3 Reflection - Part 2 (Final)
Introduction
This blog entry will describe the final results regarding the work I did on lab 3. The task for lab 3 was to create a display that showed numbers from 0 to 99. In addition the display is to be controlled using the '-' and '+' keys. The controls would increment or decrement the number being displayed. The following will cover the code used to create the application, the results, and my overall thoughts on working on this lab.
Writing Code
The code: https://gist.github.com/Megawats777/a8ac859e5f0905db83efaf76be9f26c4
Note: The font used is a custom pattern I designed.
In order to describe the code I will first start with the overall flow of logic. The first step is to check for input from the keyboard. If the '-' or '+' keys are pressed the appropriate increment or decrement procedure will be called. The second step is to actually increment and decrement the number shown and the method I chose was to have both digits be split into their own variables. In both increment and decrement routines I perform a series of checks that makes sure both digits do not get past 9 or go below zero. After the numbers are adjusted I proceeded to draw the numbers on screen. This is done by first setting values for the position and content variables which are then used by the draw function. Once the variables are set I then draw the numbers one digit at a time. Finally once the numbers are drawn I go back to checking for key presses.
A major element used in the code are named pointers. I used named pointers for each of the digits, the starting locations for the number drawing procedure, as well as determining how the numbers are drawn. They are also used to determine the width and height of each digit displayed.
How the increment procedure works can be described in the following steps. First, I increment the right digit. If the right digit reaches a value of 10 that digit is reset to 0 and the left digit is incremented. The left digit will only increment as long it is not the number 9. The decrement procedure works similarly in that the right digit is first decreased and when that digit reaches a value of 0 the left digit is then decremented and the right digit is set to the number 9. A flaw with my increment and decrement procedures is that once the limits of 0 and 99 are reached the left digit cannot be adjusted but the right digit can be edited.
The way the drawing function works is by first having the "drawNumbers" subroutine called whenever a number is changed. This procedure first clears the screen and draws each digit one by one through the use of the "startDraw" subroutine. Before each "startDraw" subroutine is called, the starting pixel position for drawing as well as the actual content to draw is set. Selecting the starting pixel position beforehand allows each digit to be placed in the correct location, such as the left digit being placed to the left of the right digit. The content to draw is chosen through an admittedly strange process. First, there is a large list of dcb values that determine the shape of each digit and that list is divided into multiple sectors. And the value "DisplayNumIndex" determines which number in each sector is drawn. For instance, if the "DisplayNumIndex" variable has a value of 64 it would retrieve the shape of a four in the second sector. The actual draw code is built upon an example on the SPO600 wiki but this time it's using the variables I set before "startDraw" is called. It is also using the correct number sector which ensures the correct number is drawn. Finally once the drawing is finished I end the subroutine.
Drawing example code: https://wiki.cdot.senecacollege.ca/wiki/6502_Emulator_Example_Code#Place_a_Graphic_on_the_Screen
Conclusion
In the end my overall thoughts on this lab are comprised of the following. First, it was easily the longest and difficult lab I have experienced as it took me a week to complete. In addition it took several revisions of ideas to finally solve the problems put in front of me. Second, this lab taught me how to use existing source code to solve my problem even if the code I found didn't make complete sense to me. In the case of this lab I didn't completely understand the example drawing code but I understood the parts I needed to know so that I could use the existing code to my benefit. Finally, on a more personal note, this lab taught me a great lesson in persistence. As I learned that as long I stuck with the problem and allowed my head to breathe I would eventually solve the issues ahead.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment