CSSE2010 CSSE7201 Assignment Two

CSSE2010 & CSSE7201
Assignment Two
Semester Two, 2023
Due: 4:00pm, Friday 27th October (AEST)
Weighting: 20% (100 marks)
The University of Queensland
School of Electrical Engineering and Computer Science
As part of the assessment for this course, you are required to undertake an assignment which will test you against some of the more practical learning objectives of the course, namely your C programming skills applied to the ATmega324A microcontroller.
You are required to modify a program to implement additional features. The program is a basic template of the game “Guitar Hero” (described in detail on page 3). The AVR ATmega324A microcontroller runs the program and receives input from multiple sources and uses an LED matrix as a display for the game, with additional information being output to a serial terminal and – to be implemented as part of this assignment – a seven-segment display and other devices.
The version of Guitar Hero provided to you has very basic functionality – it will present a splash screen upon launch, respond to push button presses or a terminal input “s”/“S” to start the game, then display the board for the game Guitar Hero with the notes and timing area. You can add features such as playing the notes, game scoring, pausing, audio etc. The various features have different tiers of difficulty and will each contribute a certain number of marks. Note that marks are awarded based on demonstrated functionality only, regardless of how much effort or code has gone into attempting such functionality.
Don’t Panic!
You have been provided with approximately 1500 lines of code to start with – many of which are comments. Whilst this code may seem confusing, you do not need to understand all of it. The code provided does a lot of the hard work for you, e.g., interacting with the serial port and the LED matrix display. To start with, you should read the header (.h) files provided along with game.c and project.c. You may need to look at the AVR C Library documentation to understand some of the functions used. Several intro/getting started videos are available on Blackboard, which contains a demonstration of some of the expected functionality to be implemented and walks through setting the project up with the provided base code, and how to submit. Note that the requirements in this document takes priority over anything shown in the feature demonstration videos.
Grading Note
As described in the course profile, if you do not score at least 10% on this assignment (before any late penalty) then your course grade will be capped at a 3 (i.e., you will fail the course). If you do not obtain at least 50% on this assignment (before any late penalty), then your course grade will be capped at a 5. Your assignment mark (after any late penalty) will count 20% towards your final course grade.
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023 1

Academic Merit, Plagiarism, Collusion and Other Misconduct
You should read and understand the statement on academic merit, plagiarism, collusion and other misconduct contained within the course profile and the document referenced in that course profile. You must not show your code to or share your code with any other student under any circumstances. You must not post your code to public discussion forums or save your code in publicly accessible repositories. You must not look at or copy code from any other student. All submitted files will be subject to electronic plagiarism detection and misconduct proceedings will be instituted against students where plagiarism or collusion is suspected. The electronic plagiarism detection can detect similarities in code structure even if comments, variable names, formatting etc. are modified. If you copy code, you will be caught.
Program Description
The program you will be provided with has several C files which contain groups of related functions. The files provided are described below. The corresponding .h files (except for project.c) list the functions that are intended to be accessible from other files. You may modify any of the provided files. You must submit all files used to build your project, even if you have not modified some provided files. Many files make assumptions about which AVR ports are used to connect to various IO devices. You are encouraged not to change these.
• project.c – this is the main file that contains the game event loop and examples of how time- based events are implemented. You should read and understand this file.
• game.c/.h – this file contains the implementation of the game components and is used to store the state of the game. You should read this file and understand what representation is used for the game state and the note representation. You will need to modify this file to add required functionality.
• display.c/.h – this file contains the implementation for displaying the current state of the board. This file contains useful functions for displaying the board to the LED matrix.
• buttons.c/.h – this contains the code which deals with the push buttons. It sets up pin change interrupts on those pins and records rising edges (buttons being pushed).
• ledmatrix.c/.h – this contains functions which give easier access to the services provided by the LED matrix. It makes use of the SPI routines implemented in spi.c.
• pixel_colour.h – this file contains definitions of some useful colours for use with the LED matrix.
• serialio.c/.h – this file is responsible for handling serial input and output using interrupts. It also maps the C standard IO routines (e.g., printf() and fgetc()) to use the serial interface so you are able to use printf() etc. for debugging purposes if you wish. You should not need to look in this file, but you may be interested in how it works, and the buffer sizes used for input and output (and what happens when the buffers fill up).
• terminalio.c/.h – this encapsulates the sending of various escape sequences which enable some control over terminal appearance and text placement – you can call these functions (declared in terminalio.h) instead of remembering various escape sequences. Additional information about terminal IO will be provided on the course Blackboard site.
• spi.c./h – this file encapsulates all SPI communication. Note that by default, all SPI communication uses busy waiting (i.e., polling) – the “send” routine returns only when the data is sent. If you need the CPU cycles for other activities, you may wish to consider converting this to interrupt based IO, similar to the way that serial IO is handled.
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023 2

程序代写 CS代考 加微信: cstutorcs
• timer0.c/.h – sets up a timer that is used to generate an interrupt every millisecond and update a global time value that is used to time various game events (such as the Guitar Hero note movement). This can be useful for implementing any features that require precise timing.
• timer1.c/.h & timer2.c/.h – largely empty files, that can be used for features that require timers/counters one and two.
NB: When you create a new project in Microchip Studio, a main.c file will automatically be created, containing an empty main() function. project.c also contains a main() function, but Microchip Studio will preferentially look the main() function in the main.c file, if it exists. Please ensure that you delete the main.c file so that Microchip Studio will look for the main() function in project.c.
Guitar Hero Description
This assignment involves creating a replica of the classic game “Guitar Hero”. Guitar Hero is a one- player game that coarsely simulates playing a guitar, and is in a broader genre of rhythm games that also includes Rock Band and Dance Dance Revolution. There are four “lanes”, each two columns wide. Musical notes, in red, will come in from the top of the screen, and move down one row after a fixed duration. When they are in the scoring area, in yellow, the player should press a push button to play that note. The notes in the rightmost lane are played with B0, then B1, B2, and finally the notes in the leftmost lane are played with B3. The bright yellow row is the perfect timing for each note, while the darker yellow areas are less precise.
When a note is played (by pressing an IO board push button or serial terminal key, see Tier A features below), it should turn green. Notes can only be played in the scoring area (i.e., the yellow regions). The top row of the lane that the next note will appear in is coloured dark red. This is not true for the base code that has been provided; it has instead been made into the Future Notes feature.
A diagram of the LED matrix is shown in Figure 1 at the top of the next page. It contains information relevant to the initial operation, as well as the Play Notes with Push Buttons, Play Notes with Terminal Inputs, Terminal Game Score, and Audio features.
Initial Operation
The provided program has very limited functionality. It will display a splash screen which detects the rising edge on the push buttons B0, B1, B2 and B3, as well as the input terminal character “s”/“S”. Pressing any of these will start a game of Guitar Hero.
Once started, the provided program detects a rising edge on the push button B0, but no action is taken on this input (this will need to be implemented as part of the Play Notes with Push Buttons feature).
Wiring Advice
When completing this assignment, you will need to make additional connections to the ATmega324A microcontroller to implement particular features. To do this, you will need to choose which pins to make these connections to. There are multiple ways to do this, so the exact wiring configuration will be left up to you, and you should communicate this using your submitted feature summary form (included at the end of this document. A standalone version is also available on Blackboard). Hint: Before implementing any features, read through them all, and consider what peripherals each feature requires and any pin limitations this imposes. If you do not do this, you may find yourself in a situation where the pins that must be used for a peripheral for a later feature are already connected to another peripheral, requiring you to rewire your breadboard and update your code before you can use the new peripheral. Some connections are defined for you in the provided base code and are shown in grey in the table on the next page.
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023 3

程序代写 CS代考 加QQ: 749389476
Scoring Area
{ 1 point (2% duty) 2 points (10% duty) 3 points (50% duty) 2 points (90% duty) 1 point (98% duty)
Wiring Table
Port Pin 7 A
Figure 1: LED Matrix Diagram for Guitar Hero
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023
Inidcator of location of
next note to appear
}B0/“f”/“F” Lane(783.9909Hz)
} B1/“ d”/“ D”
Lane (698.4565 Hz)
} B2/“ s”/“ S”
Lane (622.2540 Hz)
} B3/“ a”/“ A”
Lane (523.2511 Hz)
SPI connection to LED matrix
Baud rate: 19200

Program Features
Marks will be awarded for features as described below. Part marks will be awarded if part of the specified functionality is demonstrated. Marks are awarded only on demonstrated functionality in the final submission – no marks are awarded for attempting to implement the functionality, no matter how much effort has gone into it. You may implement higher-tier features without implementing all lower-tier features if you like (subject to prerequisite requirements), though it is highly encouraged to implement the Manual Mode feature as soon as practical. The number of marks is not an indication of difficulty. It is much easier to earn the first 50% of marks than the second 50%, and marks may be deducted if features interact negatively with one another, and the number of potential iterations grows quadratically with the number of features implemented.
You may modify any of the code provided (unless indicated otherwise) and use any of the code from learning lab sessions and/or posted on the course Blackboard site. For some of the easier features, the description below may tell you which code to modify or there may be comments in the supplied code to guide you.
Note: The course has a pass hurdle of 10% for this assignment, which can be achieved by completing the first two features (Splash Screen and Play Notes with Push Buttons). See Grading Note for further details.
Minimum Performance Tier X: Pass/Fail
Your program must have at least the features present in the code supplied to you, i.e., it must build and run, show the splash screen, and display the initial game when a push button or “s”/“S” is pressed. No marks can be earned for other features unless this requirement is met, i.e., your assignment two mark will be zero.
Splash Screen Tier A: 4 marks
Modify the program so that when it starts (i.e., the AVR microcontroller is reset) it outputs your name and student number to the serial terminal, in the indicated location (remove the placeholder text, including the chevrons <>). Do this by modifying the function start_screen() in file project.c.
The Terminal Summary section shows all features that require printing text to the terminal. You may find it useful to read through this and plan your terminal layout to avoid running out of room or having messages collide with each other.
Play Notes with Push Buttons Tier A: 8 marks
The provided program does not allow playing notes. Modify the program so when push button B0 (connected to pin B0) is pressed, if there is a note within the scoring area (i.e., the yellow regions) of the rightmost lane, that note will turn green, and remain green as it moves down until it moves off the screen. Similarly, pressing push button B1 (connected to pin B1) should play any note in the next lane in the scoring area, push button B2 (connected to pin B2) should play any note in the next lane in the scoring area, and push button B3 (connected to pin B3) should play any note in the leftmost land in the scoring area. These push button assignments are shown in Figure 1. The process of played notes being marked green, and remaining green, is demonstrated in Figure 2.
If there is no note in the scoring area of the corresponding lane, nothing should happen at this stage (this will change when the Terminal Game Score feature is implemented).
The playing should occur once on each push button press. If a note enters the scoring area while the corresponding push button is being held down, nothing should happen; the push button will need to be released and repressed to play that note.
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023 5

Press B0 Delay
Figure 2: Behaviour of played notes and ghost notes
Hints: In the play_game() function in the file project.c, when push button B0 is pressed, the function play_note(0) in the file game.c is called. This function is currently empty; start by filling in the play_note() function (there are some hints to get you started).
NB: Playing a note for this project does not mean sounding a tone, and so audio does not need to be implemented for this feature. However, during the Audio feature later, you will implement sounding a tone when a note is played.
Important: The lanes correspond to the buttons in the same positions i.e. the leftmost button correspond to the leftmost lane, and the rightmost button correspond to the rightmost lane. This means that the buttons increase from right to left. However, the LED matrix 𝑦𝑦 axis increases from left to right, and this orientation is used when inspecting the elements of the track array. You may need to convert between these two orientations within your program.
Play Notes with Terminal Input Tier A: 4 marks
The provided program does not register any terminal inputs once the game has started. Modify the program such that pressing “a”/“A” should play a note in the leftmost lane, “s”/“S” and “d”/“D” in the next two lanes, and “f”/“F” in the rightmost lane (all in the scoring area), in a similar manner to the previous task. These key assignments are shown in Figure 1. Note that both the lower case and upper case of each letter should execute these movements as described. Also note that the inbuilt serial functionality handles keyboard inputs that are held down for you.
On the splash screen, the game can be started by pressing “s”/“S”; looking at the function start_screen() should give you an idea of how to read serial input from the terminal. Do not make other keys start the game from the splash screen.
Future Notes Tier A: 4 marks
Before the next note to appear is displayed on the screen, show a “ghost” note in dark red in the top row of the corresponding lane. You will need to define a colour for this. Exactly one ghost note should always be present, until the last note is on the screen (after which there should be no ghost note). You should ignore any number of upcoming zero elements (0x00), and show the next real note. If the Long Notes feature is implemented, you should ignore the tails of any notes, and only count the initial segments of the upcoming notes when determining where to place the ghost note. A ghost note and a real note can
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023 6

both be present in the top row. However, if a ghost note and a real note would appear in the same location, the real note should have priority. Figure 2 shows an example of a ghost note in the B2 lane.
Terminal Game Score Tier A: 8 marks
Requires Play Notes with Push Buttons and/or Play Notes with Terminal Input features to be implemented.
When the player plays a note, award them points, depending on the timing:
• If the note is in the centre row of the scoring area, award them three points;
• If the note is in the second or fourth row of the scoring area, award them two points;
• If the note is in outside rows of the scoring area, award them one point.
These values are shown in Figure 1.
If the player tries to play a note when there is no note in the corresponding lane within the scoring area, deduct one point. This includes playing a note that has already been played (i.e., a note that has already turned green). If a note slides off the end of the track without being scored (i.e., still red), deduct one point.
On the terminal, display the score, and update it whenever a point is scored. Serial data for the score should only be sent when the score changes; the game should not spam the terminal constantly. Align the score such that digits of the same magnitude always appear in the same location, regardless of how large the score is. I.e., the rightmost digit of the score should always appear in the same location, regardless of if the score is one, two, or three digits, and regardless of if the score is negative. You may assume the magnitude of the score will never exceed 999. Do not use leading zeroes to pad the score. For example, the following would all be compatible (using “·” to represent a space for visibility): Game·Score:····1 Game·Score:··123 Game·Score:··−12 Game·Score:···12 Game·Score:···−1 Game·Score:·−123
The score should not be displayed on the terminal during the splash screen.
Game Over Tier A: 4 marks
Once the last note in the track has slid off the bottom of the LED matrix, the game should end. The terminal should display an end screen that indicates this, which must be notably different from the splash screen and screen that is displayed while the game is running. When “s”/“S” or any IO board push button is pressed, the game should return to the splash screen (for both the LED matrix and terminal). There may be a delay between the last note sliding off and the end screen being shown, so long as such a delay is not unreasonably long.
Later features, namely the Game Speed and Custom Track features, allow for game configuring on the splash screen. These features should not be configurable on the end screen. The High Score feature will modify the end screen. The Seven-Segment Game Score feature also distinguishes between the splash screen and the end screen. The Terminal Summary section shows all features that require printing text to the terminal during the end screen.
Manual Mode Tier A: 8 marks
This feature is designed to assist with testing most of the other features. You are highly encouraged to implement this feature before implementing any later features.
When “m”/“M” is pressed during the game, the notes should stop moving. Until “m”/“M” is pressed again, the game is in manual mode. While in this mode, pressing “n”/“N” will move the notes one position. It should be possible to enter manual mode while a game is running, not just from the splash screen. On the splash screen, it should be possible to toggle manual mode on and off without starting
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023 7

浙大学霸代写 加微信 cstutorcs
the game. The terminal should show a message when the game is in manual mode, and clear the message upon exit from manual mode. When a game ends and the player starts a new game, you may also choose to retain the previous manual mode state, but this is not a requirement.
Unlike the Game Pause feature (below), pressing the push buttons or keys should still play notes. Game Countdown Tier A: 8 marks
Before a new game starts (after the splash screen), write “3”, “2”, “1”, “GO” on the LED matrix. You must design your own pixel typeface (or find one). The text should be oriented so that they can be read when the scoring zone is positioned at the bottom of the matrix. Each of the four texts should be displayed for the length of two playable notes, as per the game speed (i.e., for 2000ms at this stage; this will be variable when the Game Speed feature is implemented). No notes (or dark red upcoming notes, if the Future Notes feature is implemented) nor the scoring area should appear on the matrix until after “GO” has been removed. You may assume that the user will not enter any inputs while the game countdown is running. As such, you do not need to handle any inputs during this time (but you may do so if you wish). When the game countdown stats, the terminal should display all information as though the game was in progress. See the “during the game” list in the Terminal Summary.
Seven-Segment Display Game Score Tier A: 8 marks
Requires Terminal Game Score feature to be implemented.
Display the score on the seven-segment display. The seven-segment display cannot show the score on the splash screen. Once the game starts, the seven-segment display should show the score throughout the game and on the end screen.
When the player’s score is between 0 and 9, inclusive, the left digit should be blank.
When a player’s score is negative, “−” (the G segment) should be displayed on the left digit (and the score value on the right digit). If a player’s score reaches −10 or less, both digits should display “−”.
If a player’s score reaches or exceeds 100, the rightmost two digits should be displayed, including a leading zero for scores between 100 and 109, inclusive (and between 200 and 209 and so on). The terminal should still display the complete score for scores above 100.
The seven-segment display should always reflect the current score, and no display flickering or “ghosting” (where digits can be faintly seen on the opposite display) should be apparent. Both digits should be of equal brightness. Include any connections required on your submitted feature summary form.
Game Speed Tier B: 6 marks
Add the ability to toggle between different game speeds using the terminal. There should be three different game speeds:
• Normal speed should have one playable note per 1000 milliseconds and is the default game speed, already implemented;
• Fast speed should have one playable note per 500 milliseconds; and
• Extreme speed should have one playable note per 250 milliseconds.
This speed refers to the note-to-note duration. The notes should move down the lanes at five times this speed.
The game speed may be changed when on the splash screen by inputting keys with the terminal:
• Inputting “1” selects normal speed;
• Inputting “2” selects fast speed;
• Inputting “3” selects extreme speed.
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023 8

The game speed should not be changeable during the game. When a game ends and the player starts a new game, you may also choose to retain the previous game speed, but this is not a requirement. As the user changes the game speed, the splash screen animation on the LED matrix should also change speed.
The current game speed should be shown on the terminal as soon as the device is powered, and appropriate text should be added to the terminal display to indicate what the game speed is at all times. As is the case for the game score, the current game speed text should only update when the game speed changes. The text should be more descriptive than “speed 1”, “speed 2”, “speed 3” or similar.
Game Pause Tier B: 6 marks
Modify the program so that if the “p”/“P” key on the serial terminal is pressed then the game will pause. When “p” or “P” key on the serial terminal is pressed again, the game recommences. All note playing push buttons/key presses should be discarded whilst the game is paused; you will need to handle the button queue while the game is paused. You may wish to allow game features (such as entering manual mode) to function while the game is paused, but this is not required. The note update timing must be unaffected – e.g., if the pause happens 150ms before the note position is updated, when at normal speed (i.e., 200ms per movement/1000ms per playable note), then the note position should be updated 50ms after the game is resumed, not immediately upon resuming. Other functionality such as the seven- segment display should be unaffected i.e., both digits of the seven-segment display should still be shown (without ghosting etc.) if implemented.
Use LED L7 to indicate if the program is currently paused. If the game is paused LED L7 should be on, and if the game is not paused LED L7 should be off. Include any connections required on your submitted feature summary form. Also, display the message “Game Paused” on the serial terminal when the game is paused. The message should only be shown while the game is paused, so when the game is unpaused, the pause message should be erased from the terminal. The existing messages shown on the terminal (e.g., game speed, game score) should remain while the game is paused.
Audio Tier B: 6 marks
Requires Play Notes with Push Buttons and/or Play Notes with Terminal Input features to be implemented.
Add audio to the program which are to be output using the piezo buzzer. These should be tones sounded whenever the player plays a note (by pressing a push button or key). The frequencies should be (as near as practicable) as follows:
• B0 note: 783.9909Hz (G5);
• B1 note: 698.4565Hz (F5);
• B2 note: 622.254Hz (E♭5); and
• B3 note: 523.2511Hz (C5).
In addition, the duty cycle of each tone should reflect the accuracy of the played note:
• If the note is played when in the first row of the scoring area, the duty cycle should be 2%;
• If in the second row, the duty cycle should be 10%;
• If in the third/middle row, 50%;
• Fourth row, 90%; and
• Fifth/last row, 98%.
Both the frequencies and duty cycles are shown in Figure 1.
Each tone should play for the time it takes for the notes on the screen to advance five times, or until a new note would be played. This will ordinarily be for the length of the game speed (e.g., play each tone
CSSE2010/CSSE7201 Assignment Two, Semester Two, 2023 9

for 1000ms at normal speed), but while in manual mode, this will instead be until “n”/“N” is pressed five times. You should account for entering/exiting manual mode while notes are playing.
If a player attempts to play a note when there is no note in the corresponding lane, no sound should be produced, and if a tone is currently being played, that tone should stop playing.
Pausing while a tone is playing should mute that tone until the game is unpaused, at which point the tone should resume.
Combo Scoring Tier B: 6 marks
Requires Terminal Game Score feature to be implemented.
When a player plays a note that is in the centre (three point) row of the scoring area, they should increase their combo count by one. The combo starts the game at zero. Whenever they play a note in a different row, or play a note when there is no note in the corresponding lane within the scoring area, or a note slides off the end of the track, they should reset their combo count to zero. I.e., whenever the score changes, the combo count should also change. Use LEDs L0, L1 and L2 to show the combo count, using a unary system up to three i.e., light up L0 when the combo count is one, light up L0 and L1 when the combo count is two, and light up L0, L1 and L2 when the combo count is three or more (and all LEDs off when the combo count is zero). The true combo count (which can go above three) should be displayed on the terminal while the game is running.
When the combo count reaches three, all unscored notes on the LED matrix should immediately change colour to orange, and all notes (current and future) should remain orange until the combo is broken. You will need to define a colour for this, as well as a dark orange for the location of the next note to appear at the top of the matrix (if the Future Notes feature is implemented). In addition, the player scores four points instead of three whenever they play a note in the centre row of the scoring area. When the combo count resets, the notes should immediately change back to red, and scoring resets to the original method i.e., the player scores three points for notes in the centre of the scoring area. Finally, “Combo!” should be displayed on the serial, in an ASCII art typef