Sound4Calc/src/main.c

84 lines
2.4 KiB
C

#include "main.h"
#include "sound4calc.h"
#include <display.h>
#include <keyboard.h>
#include "string.h"
//#define PI 3.141592653584
unsigned char *itoa(int n, unsigned char* str, int base)
{
int i=1, j=0, x;
if(n<0) str[j++] = '-', n = -n;
for(x=n;x;x/=base) j++;
for(x=n;x;x/=base) str[j-i++] = x%base + '0' + 39*(x%base>9);
str[j] = 0;
return str;
}
int main(void)
{
unsigned int key = 0;
unsigned short place = 0;
unsigned char str[33];
// initialisation to play
note.freq = 440;
note.wave.signal = 0;
note.duration = 2000;
note.wave.length = 32; // 4 bytes long
InitPorts();
while(1)
{
dclear();
dprint(1, 1, "frq = %d", note.freq);
dprint(1, 10, "%s", itoa(note.wave.signal, str, 16));
dprint(1, 20, "%d", note.wave.signal);
dprint(1, 30, "%d", place);
dprint(1, 40, "length %d", note.wave.length);
// dprint(50, 50, "clk : %d", clock_setting(note.freq * note.wave.length, clock_Hz));
DrawKeyF("not", 1);
DrawKeyF("seq", 2);
dupdate();
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_1 : note.wave.signal = note.wave.signal | (0x01 << place); place = (place < note.wave.length - 1 ? place + 1 : place); break;
case KEY_0 : note.wave.signal = (note.wave.signal & ~(0x0 << place)); place = (place < note.wave.length - 1 ? place + 1 : place); break;
case KEY_DEL : place = 0; note.wave.signal = 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 : frequency = 0; Note(); break;
case KEY_F2 : Sequence(); break;
case KEY_EXIT : StopTimer(); return 1;
}
note.wave.signal &= 0x7FFFFFFF;
}
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);
}