Add documentation

This commit is contained in:
schmelczerandras 2020-06-07 16:00:15 +02:00
parent 62853bcedc
commit c6063e28a4
47 changed files with 1011 additions and 148750 deletions

BIN
docs/BOM.csv Normal file

Binary file not shown.
1 ID Name Designator Footprint Quantity
2 1 M02 JP3 1X02 1
3 2 10k R1,R2,R3,R4 0603' 4
4 3 74HC595 U3 DIP-16_L19.8-W6.5-P2.54-LS7.6-BL 1
5 4 TSOP4838 U4 SENSOR-TH_TSOP4X 1
6 5 2N7000 Q1 TO-92-3_L4.9-W3.7-P1.27-L 1
7 6 ATTINY85V-10SU U1 SOIC-8_L5.3-W5.3-P1.27-LS8.0-BL 1
8 7 100u C1,C2 0603' 2
9 8 D096-12864-SPI7 U5 1X07 1
10 9 XC6206P332MR-G U2 SEEED-SOT-23 1
11 10 M06 JP4 1X06 1
12 11 M05 JP2 1X05 1

BIN
docs/documentation.pdf Normal file

Binary file not shown.

BIN
docs/dokumentáció.docx Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 988 KiB

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

Binary file not shown.

View file

@ -9,12 +9,12 @@
static uint8_t const configuration[] PROGMEM = { static uint8_t const configuration[] PROGMEM = {
0xD5, 0xF0, // set clock frequency 0xD5, 0xF0, /// set clock frequency
0x8D, 0x14, // enable charge pump 0x8D, 0x14, /// enable charge pump
0x20, 0x00, // horizontal addressing mode 0x20, 0x00, /// horizontal addressing mode
0xD6, 0x01, // 2 times vertical zoom 0xD6, 0x01, /// 2 times vertical zoom
0x22, 0x00, 0x03, // only draw to the top half of the screen 0x22, 0x00, 0x03, /// only draw to the top half of the screen
0xAF // display on 0xAF /// display on
}; };
static struct { static struct {
@ -43,8 +43,8 @@ void initializeDisplay(DrawFunction drawEverything) {
setOutputPin(DISPLAY_RESET_OUTPUT_PIN, false); setOutputPin(DISPLAY_RESET_OUTPUT_PIN, false);
for (volatile uint8_t i = 0; i != 255; i++) for (volatile uint8_t i = 0; i != 255; i++)
; ;
// some time has to elapse before the next line gets called, /// some time has to elapse before the next line gets called,
// otherwise the display wont turn on /// otherwise the display wont turn on
setOutputPin(DISPLAY_RESET_OUTPUT_PIN, true); setOutputPin(DISPLAY_RESET_OUTPUT_PIN, true);
for (uint8_t i = 0; i < sizeof(configuration); i++) { for (uint8_t i = 0; i < sizeof(configuration); i++) {

View file

@ -7,51 +7,51 @@
#include "../../util/rectangle/rectangle.h" #include "../../util/rectangle/rectangle.h"
/* /**
SPI driver for D096-12864 SPI driver for D096-12864
*/ */
#define DISPLAY_RESET_OUTPUT_PIN PB0 #define DISPLAY_RESET_OUTPUT_PIN PB0
#define DISPLAY_DC_OUTPUT_PIN PB4 #define DISPLAY_DC_OUTPUT_PIN PB4
// A two-times downscaling is used for greater performance /// A two-times downscaling is used for greater performance
#define DISPLAY_WIDTH_IN_PIXELS 64 #define DISPLAY_WIDTH_IN_PIXELS 64
#define DISPLAY_HEIGHT_IN_PIXELS 32 #define DISPLAY_HEIGHT_IN_PIXELS 32
// To easily access the window size /// To easily access the window size
#define WINDOW ((Rectangle){(Vec2){0, 0}, (Vec2){DISPLAY_WIDTH_IN_PIXELS, DISPLAY_HEIGHT_IN_PIXELS}}) #define WINDOW ((Rectangle){(Vec2){0, 0}, (Vec2){DISPLAY_WIDTH_IN_PIXELS, DISPLAY_HEIGHT_IN_PIXELS}})
// To conserve RAM, drawing is done in chunks of DEFAULT_COMPOSITING_WINDOW size /// To conserve RAM, drawing is done in chunks of DEFAULT_COMPOSITING_WINDOW size
// instead of buffering the whole display and writing it out at once /// instead of buffering the whole display and writing it out at once
#define DEFAULT_COMPOSITING_WINDOW ((Rectangle){(Vec2){0, 0}, (Vec2){DISPLAY_WIDTH_IN_PIXELS, 8}}) #define DEFAULT_COMPOSITING_WINDOW ((Rectangle){(Vec2){0, 0}, (Vec2){DISPLAY_WIDTH_IN_PIXELS, 8}})
typedef void (*DrawFunction)(Rectangle); typedef void (*DrawFunction)(Rectangle);
// Call DrawFunction n times after a call to drawFrame has been made /// Call DrawFunction n times after a call to drawFrame has been made
void initializeDisplay(DrawFunction drawEverything); void initializeDisplay(DrawFunction drawEverything);
// Set a the brightness of the display /// Set a the brightness of the display
// Value can be any number between 0 and 255. /// Value can be any number between 0 and 255.
void setDisplayContrast(uint8_t value); void setDisplayContrast(uint8_t value);
// To conserve program memory, pixel based intersection test /// To conserve program memory, pixel based intersection test
// is implemented here. /// is implemented here.
// Calling draw functions after calling startIntersectionTest /// Calling draw functions after calling startIntersectionTest
// will set a wasIntersection bit appropriately. /// will set a wasIntersection bit appropriately.
// Clear buffer and wasIntersection bit /// Clear buffer and wasIntersection bit
void startIntersectionTest(); void startIntersectionTest();
// Return wasIntersection bit /// Return wasIntersection bit
bool endIntersectionTest(); bool endIntersectionTest();
// Initiate a draw sequence /// Initiate a draw sequence
void drawFrame(); void drawFrame();
// Draw a sprite of size boundingBox.size at boundingBox.position from bitmap /// Draw a sprite of size boundingBox.size at boundingBox.position from bitmap
// if isMirrored then mirror around the vertical axis /// if isMirrored then mirror around the vertical axis
// Bitmap's data is interpreted the following way: /// Bitmap's data is interpreted the following way:
/* /**
Each 16 bit word corresponds to an 8 pixel high column. Each 16 bit word corresponds to an 8 pixel high column.
(These columns are laid out horizontally from left to right. Unfortunately, (These columns are laid out horizontally from left to right. Unfortunately,
the display uses this addressing mode.) The higher 8 bits of the word is the the display uses this addressing mode.) The higher 8 bits of the word is the
@ -63,9 +63,9 @@ void drawFrame();
*/ */
void drawBitmapFromProgMem(Rectangle boundingBox, uint16_t const bitmap[boundingBox.size.x][(boundingBox.size.y + 7) / 8], bool isMirrored); void drawBitmapFromProgMem(Rectangle boundingBox, uint16_t const bitmap[boundingBox.size.x][(boundingBox.size.y + 7) / 8], bool isMirrored);
// Draw a one byte repeated texture covering the parameter box /// Draw a one byte repeated texture covering the parameter box
// for a white rectangle use these arguments: invertedMask: don't care, fill: 0xFF /// for a white rectangle use these arguments: invertedMask: don't care, fill: 0xFF
// for a black rectangle use these arguments: invertedMask: 0xFF, fill: 0x00 /// for a black rectangle use these arguments: invertedMask: 0xFF, fill: 0x00
void drawFilledRectangle(Rectangle box, uint8_t invertedMask, uint8_t fill); void drawFilledRectangle(Rectangle box, uint8_t invertedMask, uint8_t fill);
#endif #endif

View file

@ -8,11 +8,11 @@
#include "../uart/receive.h" #include "../uart/receive.h"
// (0.5625 + (0.5625 + 1.6875) / 2) / 1000 / timer interval /// (0.5625 + (0.5625 + 1.6875) / 2) / 1000 / timer interval
#define MEAN_OF_0_1_BIT_TIMES 53 #define MEAN_OF_0_1_BIT_TIMES 53
// 9 / 2 / 1000 / timer interval /// 9 / 2 / 1000 / timer interval
#define MAYBE_ONE_CHECK_TIME 141 #define MAYBE_ONE_CHECK_TIME 141
// some large value /// some large value
#define TIMEOUT 254 #define TIMEOUT 254
typedef enum { typedef enum {
@ -139,8 +139,8 @@ ISR(TIM0_COMPB_vect) {
} }
void initializeInfra(OnCommandReceived onCommandReceived) { void initializeInfra(OnCommandReceived onCommandReceived) {
setBit(PORTB, IR_PIN); // enable pull-up setBit(PORTB, IR_PIN); /// enable pull-up
setBit(PCMSK, IR_PIN); // specific pin change interrupt enable setBit(PCMSK, IR_PIN); /// specific pin change interrupt enable
setBit(GIMSK, PCIE); // global on pin change interrupt enable; setBit(GIMSK, PCIE); /// global on pin change interrupt enable;
infra.onCommandReceived = onCommandReceived; infra.onCommandReceived = onCommandReceived;
} }

View file

@ -5,7 +5,7 @@
#include <avr/io.h> #include <avr/io.h>
/* /**
Custom NEC implementation using a TSOP4838 Custom NEC implementation using a TSOP4838
*/ */
@ -15,9 +15,9 @@
typedef void (*OnCommandReceived)(uint8_t); typedef void (*OnCommandReceived)(uint8_t);
// Initialize infra and call onCommandReceived with every received byte /// Initialize infra and call onCommandReceived with every received byte
// Call onCommandReceived with the argument REPEAT_CODE if a repeat code /// Call onCommandReceived with the argument REPEAT_CODE if a repeat code
// has been received. /// has been received.
void initializeInfra(OnCommandReceived onCommandReceived); void initializeInfra(OnCommandReceived onCommandReceived);
#endif #endif

View file

@ -4,10 +4,10 @@
#include <stdbool.h> #include <stdbool.h>
#include <avr/io.h> #include <avr/io.h>
// FrameFunction gets previousFrameTime (in milliseconds) as argument /// FrameFunction gets previousFrameTime (in milliseconds) as argument
typedef bool (*FrameFunction)(uint8_t); typedef bool (*FrameFunction)(uint8_t);
// Call function every frameLengthInMilliseconds while it returns true /// Call function every frameLengthInMilliseconds while it returns true
void startFrameLoop(FrameFunction function, uint8_t frameLengthInMilliseconds); void startFrameLoop(FrameFunction function, uint8_t frameLengthInMilliseconds);
#endif #endif

View file

@ -8,7 +8,7 @@
static struct { static struct {
uint16_t message; uint16_t message;
uint8_t bitPosition; // goes from 0 to 9 uint8_t bitPosition; /// goes from 0 to 9
bool previousValue; bool previousValue;
uint8_t previousTimestamp; uint8_t previousTimestamp;
OnCommandReceived onCommandReceived; OnCommandReceived onCommandReceived;
@ -17,8 +17,8 @@ static struct {
}; };
void initializeUartReceive(OnCommandReceived onCommandReceived) { void initializeUartReceive(OnCommandReceived onCommandReceived) {
setBit(PORTB, RECEIVE_PIN); // setup pull-up setBit(PORTB, RECEIVE_PIN); /// setup pull-up
setBit(PCMSK, RECEIVE_PIN); // enable interrupt on pin setBit(PCMSK, RECEIVE_PIN); /// enable interrupt on pin
uartReceive.onCommandReceived = onCommandReceived; uartReceive.onCommandReceived = onCommandReceived;
} }

View file

@ -1,24 +1,24 @@
#ifndef RECEIVE_H #ifndef RECEIVE_H
#define RECEIVE_H #define RECEIVE_H
/* /**
Custom UART receive implementation with a baud rate of 2400 Custom UART receive implementation with a baud rate of 2400
*/ */
// 8*10^6 / 128 / 2400 /// 8*10^6 / 128 / 2400
#define BIT_TIME 26 #define BIT_TIME 26
#define RECEIVE_PIN PB3 #define RECEIVE_PIN PB3
typedef void (*OnCommandReceived)(uint8_t); typedef void (*OnCommandReceived)(uint8_t);
// Initialize UART and call onCommandReceived with every byte received /// Initialize UART and call onCommandReceived with every byte received
void initializeUartReceive(OnCommandReceived onCommandReceived); void initializeUartReceive(OnCommandReceived onCommandReceived);
// Check for change on the UART receive pin /// Check for change on the UART receive pin
// This function exist so we can use a single interrupt /// This function exist so we can use a single interrupt
// handler for both the UART receive and infra pins. /// handler for both the UART receive and infra pins.
// Unfortunately, it's not possible to use more than one handler. /// Unfortunately, it's not possible to use more than one handler.
void handlePinChangeForUartReceive(); void handlePinChangeForUartReceive();
#endif #endif

View file

@ -10,7 +10,7 @@ static struct {
char bytes[ASYNC_BUFFER_SIZE]; char bytes[ASYNC_BUFFER_SIZE];
uint8_t start; uint8_t start;
uint8_t end; uint8_t end;
// 0 - start bit, 1-8 word bits, 9 - end bit /// 0 - start bit, 1-8 word bits, 9 - end bit
uint8_t currentMaskPosition; uint8_t currentMaskPosition;
} uartTransmitter; } uartTransmitter;

View file

@ -4,30 +4,30 @@
#include <avr/io.h> #include <avr/io.h>
/* /**
Custom UART trasnmit implementation with a baud rate of 2400 Custom UART trasnmit implementation with a baud rate of 2400
*/ */
// 8*10^6 / 128 / 2400 /// 8*10^6 / 128 / 2400
#define BIT_TIME 26 #define BIT_TIME 26
// Messages cannot be longer than this many characters (including trailing zero) /// Messages cannot be longer than this many characters (including trailing zero)
#define ASYNC_BUFFER_SIZE 20 #define ASYNC_BUFFER_SIZE 20
#define UART_OUTPUT_PIN 2 #define UART_OUTPUT_PIN 2
// Start pulling-up the transmit line /// Start pulling-up the transmit line
void initializeUartTransmit(); void initializeUartTransmit();
// Send a single byte over on UART /// Send a single byte over on UART
// It's done in an asynchronous fashion using a circular buffer. /// It's done in an asynchronous fashion using a circular buffer.
void sendByteOnUartAsync(char byte); void sendByteOnUartAsync(char byte);
// Send a string over on UART /// Send a string over on UART
// It's done in an asynchronous fashion using a circular buffer. /// It's done in an asynchronous fashion using a circular buffer.
void sendTextOnUartAsync(char text[]); void sendTextOnUartAsync(char text[]);
// Send the decimal form of unsigned integer over UART /// Send the decimal form of unsigned integer over UART
void sendUintOnUartAsync(uint8_t number); void sendUintOnUartAsync(uint8_t number);
#endif #endif

View file

@ -12,40 +12,40 @@
#include "output_pins/output_pins.h" #include "output_pins/output_pins.h"
/* /**
This module contains the lowest level functions to manipulate the hardware. This module contains the lowest level functions to manipulate the hardware.
You only have to include this header file which serves as a facade. You only have to include this header file which serves as a facade.
The sub-modules' implementation can be freely changed as long as they The sub-modules' implementation can be freely changed as long as they
still implement these functions. still implement these functions.
*/ */
// Initialize every hardware element at once /// Initialize every hardware element at once
void initializeHardwareAccess(); void initializeHardwareAccess();
// Enable interrupt OCCRA for TIMER0 with a modulo of triggerInterruptInXTicks /// Enable interrupt OCCRA for TIMER0 with a modulo of triggerInterruptInXTicks
void enableTimerA(uint8_t triggerInterruptInXTicks); void enableTimerA(uint8_t triggerInterruptInXTicks);
// Enable interrupt OCCRB for TIMER0B with a modulo of triggerInterruptInXTicks /// Enable interrupt OCCRB for TIMER0B with a modulo of triggerInterruptInXTicks
void enableTimerB(uint8_t triggerInterruptInXTicks); void enableTimerB(uint8_t triggerInterruptInXTicks);
void disableTimerB(); void disableTimerB();
// Enable interrupt OCCRA for TIMER1 with a modulo of triggerInterruptInXTicks /// Enable interrupt OCCRA for TIMER1 with a modulo of triggerInterruptInXTicks
void enableFastTimerA(uint8_t triggerInterruptInXTicks); void enableFastTimerA(uint8_t triggerInterruptInXTicks);
void disableFastTimerA(); void disableFastTimerA();
// Return TCNT1 /// Return TCNT1
uint8_t getTimestampFromFastTimer(); uint8_t getTimestampFromFastTimer();
// Return the time since a timestamp returned by getTimestampFromFastTimer /// Return the time since a timestamp returned by getTimestampFromFastTimer
// Accounts for overflow. /// Accounts for overflow.
uint8_t getTimeSince(uint8_t timestamp); uint8_t getTimeSince(uint8_t timestamp);
// Send a single byte on the built-in SPI interface /// Send a single byte on the built-in SPI interface
// The transfer is done in a serial manner to achieve /// The transfer is done in a serial manner to achieve
// greater throughput. /// greater throughput.
void sendByteOnSPI(uint8_t byte); void sendByteOnSPI(uint8_t byte);
// Set the value of an output pin /// Set the value of an output pin
void setOutputPin(uint8_t id, bool value); void setOutputPin(uint8_t id, bool value);
#endif #endif

View file

@ -7,7 +7,7 @@
#define CLK_ST_PIN PB0 #define CLK_ST_PIN PB0
// Uses a 74HC595 to extend the number of digital outputs /// Uses a 74HC595 to extend the number of digital outputs
void sendCurrentValue(); void sendCurrentValue();
inline void initializeOutputPins() { inline void initializeOutputPins() {

View file

@ -6,8 +6,8 @@
inline void initializePowerSaving() { inline void initializePowerSaving() {
setBit(ACSR, ACD); // disable ADC to save power setBit(ACSR, ACD); /// disable ADC to save power
PRR = BV(PRADC); // disable power to ADC (again?) PRR = BV(PRADC); /// disable power to ADC (again?)
} }
#endif #endif

View file

@ -9,11 +9,11 @@
#define USCK_PIN PB2 #define USCK_PIN PB2
inline void initializeSPI() { inline void initializeSPI() {
DDRB |= BV(DO_PIN) | BV(USCK_PIN); // set pin directions for MOSI and SCK DDRB |= BV(DO_PIN) | BV(USCK_PIN); /// set pin directions for MOSI and SCK
} }
// This function can be used from other sibling sub-modules /// This function can be used from other sibling sub-modules
// it's required for the current outpu_pins implementation. /// it's required for the current outpu_pins implementation.
void sendByteOnSPI(uint8_t byte); void sendByteOnSPI(uint8_t byte);
#endif #endif

View file

@ -5,9 +5,9 @@
#include "bitwise.h" #include "bitwise.h"
inline void initializeTiming() { inline void initializeTiming() {
TCCR0B = BV(CS02); // CLK / 256 TCCR0B = BV(CS02); /// CLK / 256
TCCR1 = BV(CS13); // CLK / 128 TCCR1 = BV(CS13); /// CLK / 128
TIMSK = BV(OCIE0A) | BV(OCIE1A); // enable compare interrupts TIMSK = BV(OCIE0A) | BV(OCIE1A); /// enable compare interrupts
} }
#endif #endif

View file

@ -1,12 +1,12 @@
#include "mediator/mediator.h" #include "mediator/mediator.h"
// Stemming from the module oriented nature of the project /// Stemming from the module oriented nature of the project
// there is a module responsible for setting up and orchestrating /// there is a module responsible for setting up and orchestrating
// the other modules. /// the other modules.
// ///
// From the main function we only have to instruct the afromentioned /// From the main function we only have to instruct the aforementioned
// mediator module to do its job. /// mediator module to do its job.
int main(void) { int main(void) {
setupConnections(); setupConnections();

View file

@ -14,9 +14,9 @@
#include "../driver/uart/receive.h" #include "../driver/uart/receive.h"
#define TARGET_FRAME_DURATION 20 // ms #define TARGET_FRAME_DURATION 20 /// ms
#define DEATH_SCREEN_LENGTH 50 // frames #define DEATH_SCREEN_LENGTH 50 /// frames
#define REPORT_INTERVAL 50 // every x frames #define REPORT_INTERVAL 50 /// every x frames
static struct { static struct {
uint8_t contrast; uint8_t contrast;

View file

@ -4,17 +4,17 @@
#include <avr/io.h> #include <avr/io.h>
// Setup the drivers, and business layer objects and their relations /// Setup the drivers, and business layer objects and their relations
// It is kind of a very basic dependency injection. /// It is kind of a very basic dependency injection.
void setupConnections(); void setupConnections();
// Start drawing frames and ticking objects /// Start drawing frames and ticking objects
void startGame(); void startGame();
// Increase or decrease the contrast (brightness) of the display /// Increase or decrease the contrast (brightness) of the display
// by the given value /// by the given value
// The contrast can be any number between 0 and 255. /// The contrast can be any number between 0 and 255.
// The function automatically clamps the contrast. /// The function automatically clamps the contrast.
void changeDisplayContrast(int8_t by); void changeDisplayContrast(int8_t by);
#endif #endif

View file

@ -32,7 +32,7 @@ static AIAction actions[AI_ACTION_COUNT];
static Vec2 whichDirectionToMove(Object* astronaut, Vec2 position) { static Vec2 whichDirectionToMove(Object* astronaut, Vec2 position) {
bool const isTargetOnUpperFloor = isOnUpperFloor((Rectangle){position, (Vec2){0, 0}}); // else it's on the lower floor bool const isTargetOnUpperFloor = isOnUpperFloor((Rectangle){position, (Vec2){0, 0}}); /// else it's on the lower floor
Vec2 const ladder = add(LADDER_BOUNDING_BOX.position, spaceshipObject->position); Vec2 const ladder = add(LADDER_BOUNDING_BOX.position, spaceshipObject->position);

View file

@ -1,12 +1,12 @@
#ifndef AI_H #ifndef AI_H
#define AI_H #define AI_H
// Between AI astronauts do actions /// Between AI astronauts do actions
// there has to be at least this many frames /// there has to be at least this many frames
#define AI_ACTION_INTERVAL 15 #define AI_ACTION_INTERVAL 15
// If there are non player controlled astronauts /// If there are non player controlled astronauts
// control them according to some basic rule set /// control them according to some basic rule set
void handleAI(); void handleAI();
#endif #endif

View file

@ -1,17 +1,17 @@
#ifndef COMMANDS_H #ifndef COMMANDS_H
#define COMMANDS_H #define COMMANDS_H
// There can be no more than COMMAND_BUFFER_SIZE commands /// There can be no more than COMMAND_BUFFER_SIZE commands
// waiting for processing simultaneously /// waiting for processing simultaneously
#define COMMAND_BUFFER_SIZE 8 #define COMMAND_BUFFER_SIZE 8
// increaseContrast and decreaseContrast changes the contrast /// increaseContrast and decreaseContrast changes the contrast
// with this value /// with this value
#define CONTRAST_STEP 15 #define CONTRAST_STEP 15
// The possible inputs of the system /// The possible inputs of the system
// Coincidentally these are the codes of the IR remote /// Coincidentally these are the codes of the IR remote
// controller's buttons. /// controller's buttons.
typedef enum { typedef enum {
noCommand = 0, noCommand = 0,
repeat = 1, repeat = 1,
@ -24,11 +24,11 @@ typedef enum {
action = 199, action = 199,
} Command; } Command;
// Add a new command to the buffer /// Add a new command to the buffer
// It will not be processed immediately. /// It will not be processed immediately.
void addCommand(Command command); void addCommand(Command command);
// Process every command in the buffer at once in a FIFO manner /// Process every command in the buffer at once in a FIFO manner
void handleCommands(); void handleCommands();
#endif #endif

View file

@ -3,16 +3,16 @@
#define MAX_ASTEROID_COUNT 2 #define MAX_ASTEROID_COUNT 2
// For minimizing code size the position of generated objects is /// For minimizing code size the position of generated objects is
// decided randomly. If it fits then it stays. For each generated object /// decided randomly. If it fits then it stays. For each generated object
// can be a maximum of TRY_COUNT tries. /// can be a maximum of TRY_COUNT tries.
#define TRY_COUNT 16 #define TRY_COUNT 16
// Create the necessary objects in order to start the game /// Create the necessary objects in order to start the game
// These include the background, spaceship and the player's character. /// These include the background, spaceship and the player's character.
void createObjects(); void createObjects();
// Generate asteroids and astronaut randomly based on a set of conditions /// Generate asteroids and astronaut randomly based on a set of conditions
void generateEvents(); void generateEvents();
#endif #endif

View file

@ -22,7 +22,7 @@ void drawObject(Object* object, Rectangle compositingWindow) {
} }
Vec2 getSizeFromPrototype(Prototype const* prototype) { Vec2 getSizeFromPrototype(Prototype const* prototype) {
// required for casting /// required for casting
uint16_t read = pgm_read_word(&prototype->size); uint16_t read = pgm_read_word(&prototype->size);
Vec2* v = (Vec2*) &read; Vec2* v = (Vec2*) &read;
return *v; return *v;

View file

@ -16,12 +16,12 @@
#include "prototype.h" #include "prototype.h"
// Objects (they could have been called GameObjects) have a simple /// Objects (they could have been called GameObjects) have a simple
// hierarchy. A prototype/flyweight motivated system is used. /// hierarchy. A prototype/flyweight motivated system is used.
// Each type has some common data and methods which are stored /// Each type has some common data and methods which are stored
// in their respective prototype. /// in their respective prototype.
// This module provides us with the methods to easily and mostly /// This module provides us with the methods to easily and mostly
// transparently access an object's prototype. /// transparently access an object's prototype.
typedef union { typedef union {
@ -39,30 +39,30 @@ struct _object_t {
object_specific_data_t as; object_specific_data_t as;
}; };
// Set the prototype of the holder and initialize all the holder's /// Set the prototype of the holder and initialize all the holder's
// vale to zero. Return the freshly updated holder /// vale to zero. Return the freshly updated holder
Object* createObject(Prototype const* prototype, Object* holder); Object* createObject(Prototype const* prototype, Object* holder);
// Call the tick function referenced in the object's prototype /// Call the tick function referenced in the object's prototype
// on the object itself /// on the object itself
// Object might react to the elapsed time. /// Object might react to the elapsed time.
// Does nothing when called with NULL. /// Does nothing when called with NULL.
void tickObject(Object* object, uint8_t previousFrameTime); void tickObject(Object* object, uint8_t previousFrameTime);
// Call the draw function referenced in the object's prototype /// Call the draw function referenced in the object's prototype
// on the object itself. /// on the object itself.
// Does nothing when called with NULL. /// Does nothing when called with NULL.
void drawObject(Object* object, Rectangle compositingWindow); void drawObject(Object* object, Rectangle compositingWindow);
// Find out the prototype of the object and return the size of that /// Find out the prototype of the object and return the size of that
Vec2 getSize(Object const* object); Vec2 getSize(Object const* object);
Vec2 getSizeFromPrototype(Prototype const* prototype); Vec2 getSizeFromPrototype(Prototype const* prototype);
// Move the position of the object by a vector /// Move the position of the object by a vector
void move(Object* object, Vec2 value); void move(Object* object, Vec2 value);
// Get a new rectangle from the objects position and its /// Get a new rectangle from the objects position and its
// prototype's size /// prototype's size
Rectangle getBoundingBox(Object const* object); Rectangle getBoundingBox(Object const* object);
#endif #endif

View file

@ -11,11 +11,11 @@
#include "../../util/vec2/vec2.h" #include "../../util/vec2/vec2.h"
// Contain up to OBJECT_COUNT objects. /// Contain up to OBJECT_COUNT objects.
// Provide the basic functionality to access, search and modify /// Provide the basic functionality to access, search and modify
// these objects. /// these objects.
// For ease of use, there are some convenience global variables for accessing /// For ease of use, there are some convenience global variables for accessing
// objects that are very commonly accessed. /// objects that are very commonly accessed.
#define OBJECT_COUNT 10 #define OBJECT_COUNT 10
#define BACKGROUND_INDEX 0 #define BACKGROUND_INDEX 0
@ -25,34 +25,34 @@
#define spaceshipObject (objects + SPACESHIP_INDEX) #define spaceshipObject (objects + SPACESHIP_INDEX)
#define character (objects + CHARACTER_INDEX) #define character (objects + CHARACTER_INDEX)
// The actual container /// The actual container
Object objects[OBJECT_COUNT]; Object objects[OBJECT_COUNT];
// may return NULL /// may return NULL
Object* getFirstOfType(Prototype const* type); Object* getFirstOfType(Prototype const* type);
// may return NULL /// may return NULL
#define getEmptyObjectSpace() getFirstOfType(NULL) #define getEmptyObjectSpace() getFirstOfType(NULL)
// Return the number of objects with a prototype being type /// Return the number of objects with a prototype being type
uint8_t getCountOf(Prototype const* type); uint8_t getCountOf(Prototype const* type);
// Return a reference to a random object intersecting boundingBox and having /// Return a reference to a random object intersecting boundingBox and having
// a prototype of type /// a prototype of type
Object* getIntersectingObjectOfType(Rectangle boundingBox, Prototype const* type); Object* getIntersectingObjectOfType(Rectangle boundingBox, Prototype const* type);
// Call the tick method of every object /// Call the tick method of every object
// objects might respond to the elapsed time /// objects might respond to the elapsed time
void tickObjects(uint8_t previousFrameTime); void tickObjects(uint8_t previousFrameTime);
// Call the draw method of every object /// Call the draw method of every object
void drawObjects(Rectangle window); void drawObjects(Rectangle window);
// Delete the object given by its address from objects /// Delete the object given by its address from objects
// It achieves this by setting the object's prototype to NULL. /// It achieves this by setting the object's prototype to NULL.
void clearObject(Object* object); void clearObject(Object* object);
// Delete every object inside of objects /// Delete every object inside of objects
void initializeObjectContainer(); void initializeObjectContainer();
#endif #endif

View file

@ -5,17 +5,17 @@
#include "../util/rectangle/rectangle.h" #include "../util/rectangle/rectangle.h"
// See more information in object.h /// See more information in object.h
struct _object_t; struct _object_t;
typedef struct _object_t Object; typedef struct _object_t Object;
// Update the inner state of the given object /// Update the inner state of the given object
// The first argument is the object itself, the second is the elapsed /// The first argument is the object itself, the second is the elapsed
// time in milliseconds. /// time in milliseconds.
typedef void (*TickMethod)(Object*, uint8_t); typedef void (*TickMethod)(Object*, uint8_t);
// Draw the given object if its overlapping with the given rectangle /// Draw the given object if its overlapping with the given rectangle
typedef void (*DrawMethod)(Object*, Rectangle); typedef void (*DrawMethod)(Object*, Rectangle);
typedef struct { typedef struct {

View file

@ -8,8 +8,8 @@
#define ASTRONAUT_SIZE ((Vec2){5, 5}) #define ASTRONAUT_SIZE ((Vec2){5, 5})
#define MOVE_FRAME_COUNT 4 #define MOVE_FRAME_COUNT 4
// Between two consecutive actions (or movements) /// Between two consecutive actions (or movements)
// there has to be at least this many milliseconds /// there has to be at least this many milliseconds
#define TIME_BETWEEN_ACTION_CHANGE 40 #define TIME_BETWEEN_ACTION_CHANGE 40
typedef enum { typedef enum {

View file

@ -67,5 +67,5 @@ void initializeBackground() {
const Prototype Background PROGMEM = { const Prototype Background PROGMEM = {
.tick = tick, .tick = tick,
.draw = draw, .draw = draw,
.size = (Vec2){DISPLAY_WIDTH_IN_PIXELS, DISPLAY_HEIGHT_IN_PIXELS} // == WINDOW.size .size = (Vec2){DISPLAY_WIDTH_IN_PIXELS, DISPLAY_HEIGHT_IN_PIXELS} /// == WINDOW.size
}; };

View file

@ -3,7 +3,7 @@
#include <avr/eeprom.h> #include <avr/eeprom.h>
// AUTO-GENERATED /// AUTO-GENERATED
const uint16_t small_character_moving[4][5][1] EEMEM = {{{0x606},{0x1f1d},{0xf0b},{0x1f1d},{0x606}},{{0x606},{0x1f1d},{0xf0b},{0xf0d},{0x1616}},{{0x606},{0x1f1d},{0xf0b},{0x1f1d},{0x606}},{{0x606},{0xf0d},{0x1f1b},{0x1f1d},{0x606}}}; const uint16_t small_character_moving[4][5][1] EEMEM = {{{0x606},{0x1f1d},{0xf0b},{0x1f1d},{0x606}},{{0x606},{0x1f1d},{0xf0b},{0xf0d},{0x1616}},{{0x606},{0x1f1d},{0xf0b},{0x1f1d},{0x606}},{{0x606},{0xf0d},{0x1f1b},{0x1f1d},{0x606}}};
const uint16_t spaceship_idle[1][36][3] EEMEM = {{{0x404,0x1414,0x1010},{0x404,0x3e3e,0x1010},{0xceca,0xffff,0x3828},{0xee6a,0xff8a,0x3929},{0xff3b,0xff09,0x7f6f},{0xff91,0xff08,0x7f44},{0xff51,0xff08,0x7f44},{0xff31,0xff08,0x7f44},{0xff1f,0xff08,0x7f7c},{0xf111,0xff08,0x4744},{0xf010,0xff08,0x704},{0xf010,0xfff8,0x707},{0xf010,0xff28,0x705},{0xf010,0xfff8,0x707},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf414,0xff08,0x1714},{0xf414,0xff08,0x1714},{0xfc1c,0xff08,0x1f1c},{0xfc1c,0xff08,0x1f1c},{0xf818,0xff08,0xf0c},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff0c,0x704},{0xf010,0xff0a,0x704},{0xf0b0,0xff1f,0x706},{0xe020,0xff1c,0x302},{0xe060,0xff1c,0x303},{0xc0c0,0xff9c,0x101},{0x8080,0xffdd,0x0},{0x0,0x7f7f,0x0},{0x0,0x1c1c,0x0},{0x0,0x808,0x0}}}; const uint16_t spaceship_idle[1][36][3] EEMEM = {{{0x404,0x1414,0x1010},{0x404,0x3e3e,0x1010},{0xceca,0xffff,0x3828},{0xee6a,0xff8a,0x3929},{0xff3b,0xff09,0x7f6f},{0xff91,0xff08,0x7f44},{0xff51,0xff08,0x7f44},{0xff31,0xff08,0x7f44},{0xff1f,0xff08,0x7f7c},{0xf111,0xff08,0x4744},{0xf010,0xff08,0x704},{0xf010,0xfff8,0x707},{0xf010,0xff28,0x705},{0xf010,0xfff8,0x707},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf414,0xff08,0x1714},{0xf414,0xff08,0x1714},{0xfc1c,0xff08,0x1f1c},{0xfc1c,0xff08,0x1f1c},{0xf818,0xff08,0xf0c},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff08,0x704},{0xf010,0xff0c,0x704},{0xf010,0xff0a,0x704},{0xf0b0,0xff1f,0x706},{0xe020,0xff1c,0x302},{0xe060,0xff1c,0x303},{0xc0c0,0xff9c,0x101},{0x8080,0xffdd,0x0},{0x0,0x7f7f,0x0},{0x0,0x1c1c,0x0},{0x0,0x808,0x0}}};

View file

@ -4,7 +4,7 @@
#include <avr/io.h> #include <avr/io.h>
// AUTO-GENERATED /// AUTO-GENERATED
const uint16_t small_character_moving[4][5][1]; const uint16_t small_character_moving[4][5][1];
const uint16_t spaceship_idle[1][36][3]; const uint16_t spaceship_idle[1][36][3];

View file

@ -4,11 +4,11 @@
#include <avr/io.h> #include <avr/io.h>
// Mustn't be zero, should be lower than 65535 /// Mustn't be zero, should be lower than 65535
#define SEED 42 #define SEED 42
// Simple LFSR with some improvements to enhance distribution /// Simple LFSR with some improvements to enhance distribution
// while maintaining short execution time /// while maintaining short execution time
uint8_t getRandomNumber(); uint8_t getRandomNumber();
#endif #endif

View file

@ -14,13 +14,13 @@ typedef struct {
bool areIntersecting(Rectangle r1, Rectangle r2); bool areIntersecting(Rectangle r1, Rectangle r2);
// Return true only if inner is fully inside of outer /// Return true only if inner is fully inside of outer
bool isInside(Rectangle inner, Rectangle outer); bool isInside(Rectangle inner, Rectangle outer);
// Return the geometrical middle point of the given rectangle /// Return the geometrical middle point of the given rectangle
Vec2 getCenter(Rectangle r); Vec2 getCenter(Rectangle r);
// Return a new rectangle shifted by vector translate /// Return a new rectangle shifted by vector translate
Rectangle translateRectangle(Rectangle r, Vec2 translate); Rectangle translateRectangle(Rectangle r, Vec2 translate);
#endif #endif

View file

@ -13,14 +13,14 @@ typedef enum {
north, west, south, east north, west, south, east
} Direction; } Direction;
// The array directions can be indexed by a Direction and /// The array directions can be indexed by a Direction and
// it contains vectors pointing into that direction. /// it contains vectors pointing into that direction.
const Vec2 directions[4]; const Vec2 directions[4];
Vec2 add(Vec2 v1, Vec2 v2); Vec2 add(Vec2 v1, Vec2 v2);
Vec2 substract(Vec2 v1, Vec2 v2); Vec2 substract(Vec2 v1, Vec2 v2);
// Return new vector with ll components between -1 and 1 (inclusive) /// Return new vector with ll components between -1 and 1 (inclusive)
Vec2 clampVec2(Vec2 vector); Vec2 clampVec2(Vec2 vector);
#endif #endif