diff --git a/game-ctrl/buttons.c b/game-ctrl/buttons.c index b52a99d..41f4a3e 100644 --- a/game-ctrl/buttons.c +++ b/game-ctrl/buttons.c @@ -8,6 +8,7 @@ #include "shapes.h" #include "canvas.h" #include "sound.h" +#include "eeprom.h" bool mutedFlag = true; @@ -107,6 +108,7 @@ void buttonsExec(void *handle) { canvasShow(); if (mutedFlag) { + eepromIncGameCounter(); soundCtrl(SOUND_UNMUTE); mutedFlag = false; } diff --git a/game-ctrl/config.c b/game-ctrl/config.c index a5e69b2..200290f 100644 --- a/game-ctrl/config.c +++ b/game-ctrl/config.c @@ -71,7 +71,7 @@ static void configHandleAmplitude() { } } -void (*configHandler[])(void) = { configHandleFlash, configHandleResetHighScore, configHandleBrightness,configHandleAmplitude }; +void (*configHandler[])(void) = { configHandleResetHighScore, configHandleFlash, configHandleBrightness, configHandleAmplitude }; void configExec(void *handle) { diff --git a/game-ctrl/eeprom.c b/game-ctrl/eeprom.c index 87be004..b665292 100644 --- a/game-ctrl/eeprom.c +++ b/game-ctrl/eeprom.c @@ -1,10 +1,15 @@ #include #include +#include #include "eeprom.h" #include "spi.h" +#include "scheduler.h" +#include "display.h" +#include "canvas.h" +#include "../rgb-driver/colors.h" -#define MAGIC 0xb002 +#define MAGIC 0xb003 #define HIGHSCORE_ADDR 0x00 #define DUMMY 0x00 #define CMD_READ 0b00000011 @@ -16,6 +21,7 @@ typedef struct { uint16_t magic; uint16_t highScore; + uint16_t gameCounter; uint8_t flashColor; uint8_t brightness; uint8_t amplitude; @@ -69,6 +75,35 @@ void eepromCommit() { writeBuf(); } + +void eepromShowValues() { + canvasClear(); + canvasFillRow(0, _green); + canvasShow(); + displaySetValue(buf.v.highScore); + wait(2); + canvasClear(); + canvasFillRow(1, _green); + canvasShow(); + displaySetValue(MIN(buf.v.gameCounter, 9999)); + wait(2); + canvasClear(); + canvasFillRow(2, _green); + canvasShow(); + displaySetValue(buf.v.flashColor); + wait(2); + canvasClear(); + canvasFillRow(3, _green); + canvasShow(); + displaySetValue(buf.v.brightness); + wait(2); + canvasClear(); + canvasFillRow(4, _green); + canvasShow(); + displaySetValue(buf.v.amplitude); + wait(2); +} + uint16_t eepromReadHighScore() { return buf.v.highScore; } @@ -102,3 +137,9 @@ void eepromSetAmplitude(uint8_t v) { buf.v.amplitude = v; } +void eepromIncGameCounter() { + buf.v.gameCounter += 1; + writeBuf(); +} + + diff --git a/game-ctrl/eeprom.h b/game-ctrl/eeprom.h index aa8f8e2..c44c558 100644 --- a/game-ctrl/eeprom.h +++ b/game-ctrl/eeprom.h @@ -6,6 +6,7 @@ void eepromInit(); void eepromCommit(); +void eepromShowValues(); uint16_t eepromReadHighScore(); void eepromSetHighScore(uint16_t v); uint8_t eepromReadFlashColor(); @@ -14,6 +15,7 @@ uint8_t eepromReadBrightness(); void eepromSetBrightness(uint8_t v); uint8_t eepromReadAmplitude(); void eepromSetAmplitude(uint8_t v); +void eepromIncGameCounter(); diff --git a/game-ctrl/main.c b/game-ctrl/main.c index d1ee30a..7e95d13 100644 --- a/game-ctrl/main.c +++ b/game-ctrl/main.c @@ -38,6 +38,8 @@ int main() { soundInit(); buttonsInit(); + eepromShowValues(); + if (isConfigMode()) { configInit(); } else { diff --git a/game-ctrl/scheduler.c b/game-ctrl/scheduler.c index f44e310..2b603a3 100644 --- a/game-ctrl/scheduler.c +++ b/game-ctrl/scheduler.c @@ -109,3 +109,9 @@ uint32_t getSeconds() { return s; } +void wait(uint8_t t) { + uint8_t startTime = getSeconds(); + + while (getSeconds() < (startTime + t)); +} + diff --git a/game-ctrl/scheduler.h b/game-ctrl/scheduler.h index 41eab15..4a4f35a 100644 --- a/game-ctrl/scheduler.h +++ b/game-ctrl/scheduler.h @@ -32,6 +32,6 @@ void schExec(); void schUpdate(); uint8_t schTaskCnt(); uint32_t getSeconds(); - +void wait(uint8_t t); #endif /* PONTCOOPSCHEDULER_H_ */ diff --git a/sound-driver/config.c b/sound-driver/config.c index 3112bd6..d7f6c2c 100644 --- a/sound-driver/config.c +++ b/sound-driver/config.c @@ -1,19 +1,26 @@ #include +#include #include "config.h" typedef struct { - uint8_t amplitude; + uint8_t melodyAmplitude; + uint8_t effectsAmplitude; } config_t; config_t config; void configSetAmplitude(uint8_t v) { - config.amplitude = v; + config.melodyAmplitude = MIN(v, 15); + config.effectsAmplitude = MIN(v+4, 15); } -uint8_t configGetAmplitude() { - return config.amplitude; +uint8_t *configGetMelodyAmplitudePtr() { + return &(config.melodyAmplitude); +} + +uint8_t *configGetEffectsAmplitudePtr() { + return &(config.effectsAmplitude); } diff --git a/sound-driver/config.h b/sound-driver/config.h index f3e4b95..d595317 100644 --- a/sound-driver/config.h +++ b/sound-driver/config.h @@ -5,7 +5,8 @@ #include void configSetAmplitude(uint8_t v); -uint8_t configGetAmplitude(); +uint8_t *configGetMelodyAmplitudePtr(); +uint8_t *configGetEffectsAmplitudePtr(); #endif // _CONFIG_H_ diff --git a/sound-driver/melody_pling.c b/sound-driver/melody_pling.c index ebb583e..9696eed 100644 --- a/sound-driver/melody_pling.c +++ b/sound-driver/melody_pling.c @@ -1,5 +1,4 @@ #include -#include #include #include "psg.h" #include "sequencer.h" @@ -22,14 +21,13 @@ const t_tone plingVoice1[] = { t_melodies pling = { .melodies = { { .tones = plingVoice1 } }, - .amplitude = 12, .numOfMelodies = 1, .pace = 200, .chip = 1 }; void playPling() { - pling.amplitude = MIN((configGetAmplitude() + 4), 15); + pling.amplitude = configGetEffectsAmplitudePtr(); sequencerPlayMelodies(&pling); } diff --git a/sound-driver/melody_tetris.c b/sound-driver/melody_tetris.c index f06bff6..046ed6e 100644 --- a/sound-driver/melody_tetris.c +++ b/sound-driver/melody_tetris.c @@ -1,5 +1,4 @@ #include -#include #include #include "psg.h" #include "sequencer.h" @@ -927,7 +926,6 @@ const t_tone voice3[] = { #define INITIAL_PACE 160 t_melodies tetrisTheme = { .melodies = { { .tones = voice1 }, { .tones = voice2 }, { .tones = voice3 } }, - .amplitude = 8, .numOfMelodies = 3, .pace = INITIAL_PACE, .chip = 0 @@ -935,7 +933,7 @@ t_melodies tetrisTheme = { void playMelodyTetris() { tetrisTheme.pace = INITIAL_PACE; // reset to start value each time - tetrisTheme.amplitude = MIN((configGetAmplitude() + 4), 15); + tetrisTheme.amplitude = configGetMelodyAmplitudePtr(); sequencerPlayMelodies(&tetrisTheme); } diff --git a/sound-driver/melody_tusch1.c b/sound-driver/melody_tusch1.c index 320b2e4..dec0a88 100644 --- a/sound-driver/melody_tusch1.c +++ b/sound-driver/melody_tusch1.c @@ -1,5 +1,4 @@ #include -#include #include #include "psg.h" #include "sequencer.h" @@ -74,14 +73,13 @@ const t_tone tusch1voice3[] = { t_melodies tusch1 = { .melodies = { { .tones = tusch1voice1 }, { .tones = tusch1voice2 }, { .tones = tusch1voice3 } }, - .amplitude = 12, .numOfMelodies = 3, .pace = 200, .chip = 1 }; void playTusch1() { - tusch1.amplitude = MIN((configGetAmplitude() + 4), 15); + tusch1.amplitude = configGetEffectsAmplitudePtr(); sequencerPlayMelodies(&tusch1); } diff --git a/sound-driver/sequencer.c b/sound-driver/sequencer.c index 573ea6f..7c29daf 100644 --- a/sound-driver/sequencer.c +++ b/sound-driver/sequencer.c @@ -59,7 +59,7 @@ void sequencerExec(void *handle) { if (melody->tones[melody->idx].length == e_L_EndMark) { melody->idx = 0; } - psgPlayTone(melodies->chip, channel, melodies->amplitude, melody->tones[melody->idx].octave, melody->tones[melody->idx].note); + psgPlayTone(melodies->chip, channel, *(melodies->amplitude), melody->tones[melody->idx].octave, melody->tones[melody->idx].note); melody->lengthCnt = (melody->tones[melody->idx].staccato) ? (calcLength(melodies, melody->tones[melody->idx].length) / 2) : calcLength(melodies, melody->tones[melody->idx].length); diff --git a/sound-driver/sequencer.h b/sound-driver/sequencer.h index c46a3c7..58acb75 100644 --- a/sound-driver/sequencer.h +++ b/sound-driver/sequencer.h @@ -52,7 +52,7 @@ typedef struct { typedef struct { uint8_t slotMask; uint8_t chip; - uint8_t amplitude; + uint8_t *amplitude; uint8_t taskId; uint16_t quarterLength; uint8_t numOfMelodies;