Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * C to assembler menu hook
- *
- */
- #include <stdio.h>
- #include <stdint.h>
- #include <ctype.h>
- #include <string.h>
- #include "common.h"
- #define kClockRate 10000000
- #define kMaxNumLights 8
- int mg_game_demo(int delay, char* pattern, int target);
- void mgGame(int action)
- {
- uint32_t delay, target;
- char pattern[kMaxNumLights + 1];
- char* pchar = NULL;
- int rc;
- if(action==CMD_SHORT_HELP) return;
- if(action==CMD_LONG_HELP) {
- printf("LED Game - Assignment 3\n\n"
- "This command tests new addition function\n"
- );
- return;
- }
- rc = fetch_uint32_arg(&delay);
- if(rc)
- {
- // Uses default delay
- delay = 1000 * (kClockRate/10000) * 1.5; // Equal to 1 second
- }
- else
- {
- delay = delay * (kClockRate/10000) * 1.5; // Converts the passed value into ms (milliseconds)
- }
- rc = fetch_string_arg(&pchar);
- if(rc)
- {
- // Uses default pattern
- strcpy(pattern, "01234567");
- }
- else
- {
- strcpy(pattern, pchar);
- if(strlen(pchar) != 8) // Check if received exactly 8 digits
- {
- printf("ERROR: Invalid number of digits for LED pattern. REQUIRED: 8 digits\n");
- return;
- }
- while(*pchar != '\0') // Check if all numbers are valid
- {
- if (*pchar == '9')
- {
- printf("ERROR: 9 is an invalid digit for the pattern. Use only 0 to 8.\n");
- return;
- }
- pchar++;
- }
- }
- rc = fetch_uint32_arg(&target);
- if(rc)
- {
- target = 5;
- }
- mg_game_demo(delay,pattern,target);
- }
- ADD_CMD("mgGame", mgGame,"\t\t LED Game for Assignment 3")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement