more configuration

This commit is contained in:
Wolfgang Hottgenroth 2024-05-21 13:43:40 +02:00
parent faf75e158a
commit 2827046b8b
14 changed files with 74 additions and 19 deletions

View File

@ -8,6 +8,7 @@
#include "shapes.h" #include "shapes.h"
#include "canvas.h" #include "canvas.h"
#include "sound.h" #include "sound.h"
#include "eeprom.h"
bool mutedFlag = true; bool mutedFlag = true;
@ -107,6 +108,7 @@ void buttonsExec(void *handle) {
canvasShow(); canvasShow();
if (mutedFlag) { if (mutedFlag) {
eepromIncGameCounter();
soundCtrl(SOUND_UNMUTE); soundCtrl(SOUND_UNMUTE);
mutedFlag = false; mutedFlag = false;
} }

View File

@ -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) { void configExec(void *handle) {

View File

@ -1,10 +1,15 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <sys/param.h>
#include "eeprom.h" #include "eeprom.h"
#include "spi.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 HIGHSCORE_ADDR 0x00
#define DUMMY 0x00 #define DUMMY 0x00
#define CMD_READ 0b00000011 #define CMD_READ 0b00000011
@ -16,6 +21,7 @@
typedef struct { typedef struct {
uint16_t magic; uint16_t magic;
uint16_t highScore; uint16_t highScore;
uint16_t gameCounter;
uint8_t flashColor; uint8_t flashColor;
uint8_t brightness; uint8_t brightness;
uint8_t amplitude; uint8_t amplitude;
@ -69,6 +75,35 @@ void eepromCommit() {
writeBuf(); 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() { uint16_t eepromReadHighScore() {
return buf.v.highScore; return buf.v.highScore;
} }
@ -102,3 +137,9 @@ void eepromSetAmplitude(uint8_t v) {
buf.v.amplitude = v; buf.v.amplitude = v;
} }
void eepromIncGameCounter() {
buf.v.gameCounter += 1;
writeBuf();
}

View File

@ -6,6 +6,7 @@
void eepromInit(); void eepromInit();
void eepromCommit(); void eepromCommit();
void eepromShowValues();
uint16_t eepromReadHighScore(); uint16_t eepromReadHighScore();
void eepromSetHighScore(uint16_t v); void eepromSetHighScore(uint16_t v);
uint8_t eepromReadFlashColor(); uint8_t eepromReadFlashColor();
@ -14,6 +15,7 @@ uint8_t eepromReadBrightness();
void eepromSetBrightness(uint8_t v); void eepromSetBrightness(uint8_t v);
uint8_t eepromReadAmplitude(); uint8_t eepromReadAmplitude();
void eepromSetAmplitude(uint8_t v); void eepromSetAmplitude(uint8_t v);
void eepromIncGameCounter();

View File

@ -38,6 +38,8 @@ int main() {
soundInit(); soundInit();
buttonsInit(); buttonsInit();
eepromShowValues();
if (isConfigMode()) { if (isConfigMode()) {
configInit(); configInit();
} else { } else {

View File

@ -109,3 +109,9 @@ uint32_t getSeconds() {
return s; return s;
} }
void wait(uint8_t t) {
uint8_t startTime = getSeconds();
while (getSeconds() < (startTime + t));
}

View File

@ -32,6 +32,6 @@ void schExec();
void schUpdate(); void schUpdate();
uint8_t schTaskCnt(); uint8_t schTaskCnt();
uint32_t getSeconds(); uint32_t getSeconds();
void wait(uint8_t t);
#endif /* PONTCOOPSCHEDULER_H_ */ #endif /* PONTCOOPSCHEDULER_H_ */

View File

@ -1,19 +1,26 @@
#include <stdint.h> #include <stdint.h>
#include <sys/param.h>
#include "config.h" #include "config.h"
typedef struct { typedef struct {
uint8_t amplitude; uint8_t melodyAmplitude;
uint8_t effectsAmplitude;
} config_t; } config_t;
config_t config; config_t config;
void configSetAmplitude(uint8_t v) { void configSetAmplitude(uint8_t v) {
config.amplitude = v; config.melodyAmplitude = MIN(v, 15);
config.effectsAmplitude = MIN(v+4, 15);
} }
uint8_t configGetAmplitude() { uint8_t *configGetMelodyAmplitudePtr() {
return config.amplitude; return &(config.melodyAmplitude);
}
uint8_t *configGetEffectsAmplitudePtr() {
return &(config.effectsAmplitude);
} }

View File

@ -5,7 +5,8 @@
#include <stdint.h> #include <stdint.h>
void configSetAmplitude(uint8_t v); void configSetAmplitude(uint8_t v);
uint8_t configGetAmplitude(); uint8_t *configGetMelodyAmplitudePtr();
uint8_t *configGetEffectsAmplitudePtr();
#endif // _CONFIG_H_ #endif // _CONFIG_H_

View File

@ -1,5 +1,4 @@
#include <stdbool.h> #include <stdbool.h>
#include <sys/param.h>
#include <stddef.h> #include <stddef.h>
#include "psg.h" #include "psg.h"
#include "sequencer.h" #include "sequencer.h"
@ -22,14 +21,13 @@ const t_tone plingVoice1[] = {
t_melodies pling = { t_melodies pling = {
.melodies = { { .tones = plingVoice1 } }, .melodies = { { .tones = plingVoice1 } },
.amplitude = 12,
.numOfMelodies = 1, .numOfMelodies = 1,
.pace = 200, .pace = 200,
.chip = 1 .chip = 1
}; };
void playPling() { void playPling() {
pling.amplitude = MIN((configGetAmplitude() + 4), 15); pling.amplitude = configGetEffectsAmplitudePtr();
sequencerPlayMelodies(&pling); sequencerPlayMelodies(&pling);
} }

View File

@ -1,5 +1,4 @@
#include <stdbool.h> #include <stdbool.h>
#include <sys/param.h>
#include <stddef.h> #include <stddef.h>
#include "psg.h" #include "psg.h"
#include "sequencer.h" #include "sequencer.h"
@ -927,7 +926,6 @@ const t_tone voice3[] = {
#define INITIAL_PACE 160 #define INITIAL_PACE 160
t_melodies tetrisTheme = { t_melodies tetrisTheme = {
.melodies = { { .tones = voice1 }, { .tones = voice2 }, { .tones = voice3 } }, .melodies = { { .tones = voice1 }, { .tones = voice2 }, { .tones = voice3 } },
.amplitude = 8,
.numOfMelodies = 3, .numOfMelodies = 3,
.pace = INITIAL_PACE, .pace = INITIAL_PACE,
.chip = 0 .chip = 0
@ -935,7 +933,7 @@ t_melodies tetrisTheme = {
void playMelodyTetris() { void playMelodyTetris() {
tetrisTheme.pace = INITIAL_PACE; // reset to start value each time tetrisTheme.pace = INITIAL_PACE; // reset to start value each time
tetrisTheme.amplitude = MIN((configGetAmplitude() + 4), 15); tetrisTheme.amplitude = configGetMelodyAmplitudePtr();
sequencerPlayMelodies(&tetrisTheme); sequencerPlayMelodies(&tetrisTheme);
} }

View File

@ -1,5 +1,4 @@
#include <stdbool.h> #include <stdbool.h>
#include <sys/param.h>
#include <stddef.h> #include <stddef.h>
#include "psg.h" #include "psg.h"
#include "sequencer.h" #include "sequencer.h"
@ -74,14 +73,13 @@ const t_tone tusch1voice3[] = {
t_melodies tusch1 = { t_melodies tusch1 = {
.melodies = { { .tones = tusch1voice1 }, { .tones = tusch1voice2 }, { .tones = tusch1voice3 } }, .melodies = { { .tones = tusch1voice1 }, { .tones = tusch1voice2 }, { .tones = tusch1voice3 } },
.amplitude = 12,
.numOfMelodies = 3, .numOfMelodies = 3,
.pace = 200, .pace = 200,
.chip = 1 .chip = 1
}; };
void playTusch1() { void playTusch1() {
tusch1.amplitude = MIN((configGetAmplitude() + 4), 15); tusch1.amplitude = configGetEffectsAmplitudePtr();
sequencerPlayMelodies(&tusch1); sequencerPlayMelodies(&tusch1);
} }

View File

@ -59,7 +59,7 @@ void sequencerExec(void *handle) {
if (melody->tones[melody->idx].length == e_L_EndMark) { if (melody->tones[melody->idx].length == e_L_EndMark) {
melody->idx = 0; 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) ? melody->lengthCnt = (melody->tones[melody->idx].staccato) ?
(calcLength(melodies, melody->tones[melody->idx].length) / 2) : (calcLength(melodies, melody->tones[melody->idx].length) / 2) :
calcLength(melodies, melody->tones[melody->idx].length); calcLength(melodies, melody->tones[melody->idx].length);

View File

@ -52,7 +52,7 @@ typedef struct {
typedef struct { typedef struct {
uint8_t slotMask; uint8_t slotMask;
uint8_t chip; uint8_t chip;
uint8_t amplitude; uint8_t *amplitude;
uint8_t taskId; uint8_t taskId;
uint16_t quarterLength; uint16_t quarterLength;
uint8_t numOfMelodies; uint8_t numOfMelodies;