George Sykes ELEC2645 project

Dependencies:   mbed

https://os.mbed.com/media/uploads/el18gs/pixil-frame-0.png

GHOST HUNTER

In a world of ghostly horrors there is much money to be made in underground ghost fighting rings. You've managed to get hold of a Ghostbuster, a special piece of equipment that allows you to catch, train and fight ghosts.

Instructions

Below you will find the instructions for the game. Please note that due to COVID-19 a large part of the game (fighting ghosts) could not be added as it would have required access to a second gamepad which i could not acquire.

Welcome screen

When first started you will be presented with a welcome screen

  • Pot 1 to adjust the contrast on the screen
  • Press A to continue.

Main menu

You have three options, catch ghosts (add ghosts to your inventory), inventory (sell ghosts) or settings(adjust the games settings).

  • Press X and B to move the selection up and down respectively
  • Press A to enter the selected submenu

Catch Ghost

Will now be presented with two challenges. In the first you need to find a ghost, in the second you catch it. Theses stages will start automatically.

Find ghost

Rotate the gamepad on its roll and pitch axis until all the LED's turn on. The ones on the left indicate roll and the right pitch.

  • Rotate the gamepad on it roll and pitch to light up the LED's

Catch ghost

Return the gamepad to a comfortable position and use the joystick to move the crosshairs onto the ghost sprite. When ready press the A button to catch the ghost. You will be told what kind of ghost you have captured and it will be added to your inventory.

  • Press A to catch the ghost
  • Move the joystick to move the crosshairs

Inventory

The inventory allows you to view your ghosts and sell them.

  • Use Pot 1 to scroll through the ghosts
  • Pot 2 to scroll up and down the details of the individual ghosts
  • Press X to prepare to sell a ghost and press again to confirm, if you don't press again the sale screen will disappear after 5 seconds
  • Press Start to return to the main menu

Settings

This menu allows you to adjust some of the settings of the game.

  • Press X to go up one option
  • Press B to go down one option
  • Press A to enter the selected submenu
  • Press Start to return to the main menu

Contrast

Set the contrast of the LCD screen, the contrast will adjust on this screen so you can see the effect (contrast is bounded between 0.4 and 0.6).

  • Pot 1 to increase or decrease the contrast
  • Press A to set the contrast

Button Delay

Set the minimum time between button presses; if this is too low the game will detect two button presses when there was only one, too high and the buttons will seem unresponsive. So as to ensure these issues do not occur while changing the setting button X temporarily operates on the new delay but none of the others will until A is pressed.

  • Pot 1 to increase or decrease the delay
  • Press X to test the new delay, this will toggle the small circle to be filled in or unfilled
  • Press A to save the setting
Committer:
el18gs
Date:
Fri Mar 06 19:27:12 2020 +0000
Revision:
2:eaf245af2aae
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18gs 2:eaf245af2aae 1 /* mbed Microcontroller Library
el18gs 2:eaf245af2aae 2 * Copyright (c) 2006-2012 ARM Limited
el18gs 2:eaf245af2aae 3 *
el18gs 2:eaf245af2aae 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
el18gs 2:eaf245af2aae 5 * of this software and associated documentation files (the "Software"), to deal
el18gs 2:eaf245af2aae 6 * in the Software without restriction, including without limitation the rights
el18gs 2:eaf245af2aae 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
el18gs 2:eaf245af2aae 8 * copies of the Software, and to permit persons to whom the Software is
el18gs 2:eaf245af2aae 9 * furnished to do so, subject to the following conditions:
el18gs 2:eaf245af2aae 10 *
el18gs 2:eaf245af2aae 11 * The above copyright notice and this permission notice shall be included in
el18gs 2:eaf245af2aae 12 * all copies or substantial portions of the Software.
el18gs 2:eaf245af2aae 13 *
el18gs 2:eaf245af2aae 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
el18gs 2:eaf245af2aae 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
el18gs 2:eaf245af2aae 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
el18gs 2:eaf245af2aae 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
el18gs 2:eaf245af2aae 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
el18gs 2:eaf245af2aae 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
el18gs 2:eaf245af2aae 20 * SOFTWARE.
el18gs 2:eaf245af2aae 21 */
el18gs 2:eaf245af2aae 22 #include "mbed.h"
el18gs 2:eaf245af2aae 23
el18gs 2:eaf245af2aae 24 #include "ffconf.h"
el18gs 2:eaf245af2aae 25 #include "mbed_debug.h"
el18gs 2:eaf245af2aae 26
el18gs 2:eaf245af2aae 27 #include "FATFileSystem.h"
el18gs 2:eaf245af2aae 28 #include "FATFileHandle.h"
el18gs 2:eaf245af2aae 29 #include "FATDirHandle.h"
el18gs 2:eaf245af2aae 30
el18gs 2:eaf245af2aae 31 DWORD get_fattime(void) {
el18gs 2:eaf245af2aae 32 time_t rawtime;
el18gs 2:eaf245af2aae 33 time(&rawtime);
el18gs 2:eaf245af2aae 34 struct tm *ptm = localtime(&rawtime);
el18gs 2:eaf245af2aae 35 return (DWORD)(ptm->tm_year - 80) << 25
el18gs 2:eaf245af2aae 36 | (DWORD)(ptm->tm_mon + 1 ) << 21
el18gs 2:eaf245af2aae 37 | (DWORD)(ptm->tm_mday ) << 16
el18gs 2:eaf245af2aae 38 | (DWORD)(ptm->tm_hour ) << 11
el18gs 2:eaf245af2aae 39 | (DWORD)(ptm->tm_min ) << 5
el18gs 2:eaf245af2aae 40 | (DWORD)(ptm->tm_sec/2 );
el18gs 2:eaf245af2aae 41 }
el18gs 2:eaf245af2aae 42
el18gs 2:eaf245af2aae 43 FATFileSystem *FATFileSystem::_ffs[_VOLUMES] = {0};
el18gs 2:eaf245af2aae 44
el18gs 2:eaf245af2aae 45 FATFileSystem::FATFileSystem(const char* n) : FileSystemLike(n) {
el18gs 2:eaf245af2aae 46 debug_if(FFS_DBG, "FATFileSystem(%s)\n", n);
el18gs 2:eaf245af2aae 47 for(int i=0; i<_VOLUMES; i++) {
el18gs 2:eaf245af2aae 48 if(_ffs[i] == 0) {
el18gs 2:eaf245af2aae 49 _ffs[i] = this;
el18gs 2:eaf245af2aae 50 _fsid[0] = '0' + i;
el18gs 2:eaf245af2aae 51 _fsid[1] = '\0';
el18gs 2:eaf245af2aae 52 debug_if(FFS_DBG, "Mounting [%s] on ffs drive [%s]\n", getName(), _fsid);
el18gs 2:eaf245af2aae 53 f_mount(&_fs, _fsid, 0);
el18gs 2:eaf245af2aae 54 return;
el18gs 2:eaf245af2aae 55 }
el18gs 2:eaf245af2aae 56 }
el18gs 2:eaf245af2aae 57 error("Couldn't create %s in FATFileSystem::FATFileSystem\n", n);
el18gs 2:eaf245af2aae 58 }
el18gs 2:eaf245af2aae 59
el18gs 2:eaf245af2aae 60 FATFileSystem::~FATFileSystem() {
el18gs 2:eaf245af2aae 61 for (int i=0; i<_VOLUMES; i++) {
el18gs 2:eaf245af2aae 62 if (_ffs[i] == this) {
el18gs 2:eaf245af2aae 63 _ffs[i] = 0;
el18gs 2:eaf245af2aae 64 f_mount(NULL, _fsid, 0);
el18gs 2:eaf245af2aae 65 }
el18gs 2:eaf245af2aae 66 }
el18gs 2:eaf245af2aae 67 }
el18gs 2:eaf245af2aae 68
el18gs 2:eaf245af2aae 69 FileHandle *FATFileSystem::open(const char* name, int flags) {
el18gs 2:eaf245af2aae 70 debug_if(FFS_DBG, "open(%s) on filesystem [%s], drv [%s]\n", name, getName(), _fsid);
el18gs 2:eaf245af2aae 71 char n[64];
el18gs 2:eaf245af2aae 72 sprintf(n, "%s:/%s", _fsid, name);
el18gs 2:eaf245af2aae 73
el18gs 2:eaf245af2aae 74 /* POSIX flags -> FatFS open mode */
el18gs 2:eaf245af2aae 75 BYTE openmode;
el18gs 2:eaf245af2aae 76 if (flags & O_RDWR) {
el18gs 2:eaf245af2aae 77 openmode = FA_READ|FA_WRITE;
el18gs 2:eaf245af2aae 78 } else if(flags & O_WRONLY) {
el18gs 2:eaf245af2aae 79 openmode = FA_WRITE;
el18gs 2:eaf245af2aae 80 } else {
el18gs 2:eaf245af2aae 81 openmode = FA_READ;
el18gs 2:eaf245af2aae 82 }
el18gs 2:eaf245af2aae 83 if(flags & O_CREAT) {
el18gs 2:eaf245af2aae 84 if(flags & O_TRUNC) {
el18gs 2:eaf245af2aae 85 openmode |= FA_CREATE_ALWAYS;
el18gs 2:eaf245af2aae 86 } else {
el18gs 2:eaf245af2aae 87 openmode |= FA_OPEN_ALWAYS;
el18gs 2:eaf245af2aae 88 }
el18gs 2:eaf245af2aae 89 }
el18gs 2:eaf245af2aae 90
el18gs 2:eaf245af2aae 91 FIL fh;
el18gs 2:eaf245af2aae 92 FRESULT res = f_open(&fh, n, openmode);
el18gs 2:eaf245af2aae 93 if (res) {
el18gs 2:eaf245af2aae 94 debug_if(FFS_DBG, "f_open('w') failed: %d\n", res);
el18gs 2:eaf245af2aae 95 return NULL;
el18gs 2:eaf245af2aae 96 }
el18gs 2:eaf245af2aae 97 if (flags & O_APPEND) {
el18gs 2:eaf245af2aae 98 f_lseek(&fh, fh.fsize);
el18gs 2:eaf245af2aae 99 }
el18gs 2:eaf245af2aae 100 return new FATFileHandle(fh);
el18gs 2:eaf245af2aae 101 }
el18gs 2:eaf245af2aae 102
el18gs 2:eaf245af2aae 103 int FATFileSystem::open(FileHandle **file, const char *name, int flags) {
el18gs 2:eaf245af2aae 104 FileHandle *temp = open(name, flags);
el18gs 2:eaf245af2aae 105 if (!temp) {
el18gs 2:eaf245af2aae 106 return -1;
el18gs 2:eaf245af2aae 107 }
el18gs 2:eaf245af2aae 108
el18gs 2:eaf245af2aae 109 *file = temp;
el18gs 2:eaf245af2aae 110 return 0;
el18gs 2:eaf245af2aae 111 }
el18gs 2:eaf245af2aae 112
el18gs 2:eaf245af2aae 113 int FATFileSystem::remove(const char *filename) {
el18gs 2:eaf245af2aae 114 FRESULT res = f_unlink(filename);
el18gs 2:eaf245af2aae 115 if (res) {
el18gs 2:eaf245af2aae 116 debug_if(FFS_DBG, "f_unlink() failed: %d\n", res);
el18gs 2:eaf245af2aae 117 return -1;
el18gs 2:eaf245af2aae 118 }
el18gs 2:eaf245af2aae 119 return 0;
el18gs 2:eaf245af2aae 120 }
el18gs 2:eaf245af2aae 121
el18gs 2:eaf245af2aae 122 int FATFileSystem::rename(const char *oldname, const char *newname) {
el18gs 2:eaf245af2aae 123 FRESULT res = f_rename(oldname, newname);
el18gs 2:eaf245af2aae 124 if (res) {
el18gs 2:eaf245af2aae 125 debug_if(FFS_DBG, "f_rename() failed: %d\n", res);
el18gs 2:eaf245af2aae 126 return -1;
el18gs 2:eaf245af2aae 127 }
el18gs 2:eaf245af2aae 128 return 0;
el18gs 2:eaf245af2aae 129 }
el18gs 2:eaf245af2aae 130
el18gs 2:eaf245af2aae 131 int FATFileSystem::format() {
el18gs 2:eaf245af2aae 132 FRESULT res = f_mkfs(_fsid, 0, 512); // Logical drive number, Partitioning rule, Allocation unit size (bytes per cluster)
el18gs 2:eaf245af2aae 133 if (res) {
el18gs 2:eaf245af2aae 134 debug_if(FFS_DBG, "f_mkfs() failed: %d\n", res);
el18gs 2:eaf245af2aae 135 return -1;
el18gs 2:eaf245af2aae 136 }
el18gs 2:eaf245af2aae 137 return 0;
el18gs 2:eaf245af2aae 138 }
el18gs 2:eaf245af2aae 139
el18gs 2:eaf245af2aae 140 DirHandle *FATFileSystem::opendir(const char *name) {
el18gs 2:eaf245af2aae 141 FATFS_DIR dir;
el18gs 2:eaf245af2aae 142 FRESULT res = f_opendir(&dir, name);
el18gs 2:eaf245af2aae 143 if (res != 0) {
el18gs 2:eaf245af2aae 144 return NULL;
el18gs 2:eaf245af2aae 145 }
el18gs 2:eaf245af2aae 146 return new FATDirHandle(dir);
el18gs 2:eaf245af2aae 147 }
el18gs 2:eaf245af2aae 148
el18gs 2:eaf245af2aae 149 int FATFileSystem::open(DirHandle **dir, const char *name) {
el18gs 2:eaf245af2aae 150 DirHandle *temp = opendir(name);
el18gs 2:eaf245af2aae 151 if (!temp) {
el18gs 2:eaf245af2aae 152 return -1;
el18gs 2:eaf245af2aae 153 }
el18gs 2:eaf245af2aae 154
el18gs 2:eaf245af2aae 155 *dir = temp;
el18gs 2:eaf245af2aae 156 return 0;
el18gs 2:eaf245af2aae 157 }
el18gs 2:eaf245af2aae 158
el18gs 2:eaf245af2aae 159 int FATFileSystem::mkdir(const char *name, mode_t mode) {
el18gs 2:eaf245af2aae 160 FRESULT res = f_mkdir(name);
el18gs 2:eaf245af2aae 161 return res == 0 ? 0 : -1;
el18gs 2:eaf245af2aae 162 }
el18gs 2:eaf245af2aae 163
el18gs 2:eaf245af2aae 164 int FATFileSystem::mount() {
el18gs 2:eaf245af2aae 165 FRESULT res = f_mount(&_fs, _fsid, 1);
el18gs 2:eaf245af2aae 166 return res == 0 ? 0 : -1;
el18gs 2:eaf245af2aae 167 }
el18gs 2:eaf245af2aae 168
el18gs 2:eaf245af2aae 169 int FATFileSystem::unmount() {
el18gs 2:eaf245af2aae 170 if (disk_sync())
el18gs 2:eaf245af2aae 171 return -1;
el18gs 2:eaf245af2aae 172 FRESULT res = f_mount(NULL, _fsid, 0);
el18gs 2:eaf245af2aae 173 return res == 0 ? 0 : -1;
el18gs 2:eaf245af2aae 174 }