Sound4Calc/src/main.c

85 lines
2.2 KiB
C

#include "main.h"
#include "sound4calc.h"
#include <display.h>
#include <keyboard.h>
#include "string.h"
//#define PI 3.141592653584
int main(void)
{
unsigned int key = 0;
unsigned short place = 0;
unsigned char str[16];
// initialisation to play
note.freq = 440;
note.wave.signal = 0;
note.duration = 2000;
note.wave.length = 16; // 2 bytes long
InitPorts();
while(1)
{
dclear();
dprint(1, 1, "frq = %d", note.freq);
dprint(1, 10, "%s", str);
dprint(1, 20, "%d", note.wave.signal);
dprint(1, 30, "%d", place);
dprint(1, 40, "length %d", note.wave.length);
DrawKeyF("not", 1);
DrawKeyF("seq", 2);
DrawKeyF("1", 5);
DrawKeyF("0", 6);
dupdate();
str[place] = 0;
note.wave.signal = atob(str, note.wave.length);
key = getkey();
switch(key)
{
case KEY_RIGHT : note.freq+=1; break;
case KEY_LEFT : note.freq-=1; break;
case KEY_UP : note.freq+=10; break;
case KEY_DOWN : note.freq-=10; break;
case KEY_F5 : str[place] = '1'; place=(place < note.wave.signal ? place + 1 : place); break;
case KEY_F6 : str[place] = '0'; place=(place < note.wave.signal ? place + 1 : place); break;
case KEY_DEL : place=(place>0 ? place - 1 : 0); break;
//case KEY_F5 : *(note.wave.signal+place++) = 255; *(note.wave.signal+place) = 0; break;
//case KEY_F6 : *(note.wave.signal+place++) = 240; *(note.wave.signal+place) = 0; break;
//case KEY_DEL : place=(place>0 ? place - 1 : 0); *(note.wave.signal+place) = 0; break;
case KEY_F1 : CallNote(); break;
case KEY_F2 : CallSequence(); break;
case KEY_EXIT : StopTimer(); return 1;
}
}
return 1; // this point is never reached
}
void DrawKeyF(char* str, unsigned char keyF)
{
dprint((keyF-1)*21 + 11 - 3*strlen(str), 55, "%s", str);
dreverse_area((keyF-1)*21 + 1 , 54, keyF * 21 - 1, 64);
}
int atob(unsigned char* str, int bit_nb)
{
unsigned int tmp = 0;
for(int i = 0; i < bit_nb; i++)
{
tmp += ((str[i] - '0') * (0x1 << (bit_nb - i - 1)));
}
return tmp;
}