b70cdd13c4
We're big-endian. when we have this in memory: 00 01 02 03 And we need the first byte, we load the first 16-bit word: 0x0001 The first byte is then in the upper part of the word, and requires a right shift by 8. So any load into an 8-bit typed container needs to shift stuff. So far, stores from/to the stack are exempted, they always load/store full 16-bit words. And a few othe rminor things. Like string null terminators. And escaped characters in character literals. Can you believe it's spelled 'literal', with a single t? Me neither.
54 lines
1.3 KiB
C
54 lines
1.3 KiB
C
#include "sys.h"
|
|
|
|
void init() {
|
|
square0->output_address = pdmout0;
|
|
square0->high_val = 0xffff;
|
|
square0->low_val = 0x0000;
|
|
square0->flags = SQUARE_FLAG_ENABLE_msk;
|
|
// will set the period later
|
|
}
|
|
|
|
int main() {
|
|
init();
|
|
|
|
led0->output = 42;
|
|
|
|
while(1) {
|
|
uint8_t c = uart_read(uart0);
|
|
uint16_t period;
|
|
if (c == 'c') {
|
|
led0->output = 1;
|
|
period = 1493; // C4, 262.63 Hz, maybe
|
|
uart_writen(uart0, "C4\r\n", 4);
|
|
} else if (c == 'd') {
|
|
period = 1330; // D4, 293.66 Hz, maybe
|
|
uart_writen(uart0, "D4\r\n", 4);
|
|
led0->output = 2;
|
|
} else if (c == 'e') {
|
|
period = 1185; // E4, 329.63 Hz, maybe
|
|
uart_writen(uart0, "E4\r\n", 4);
|
|
led0->output = 4;
|
|
} else if (c == 'f') {
|
|
period = 1119; // F4, 249.23 Hz, maybe
|
|
uart_writen(uart0, "F4\r\n", 4);
|
|
led0->output = 8;
|
|
} else if (c == 'g') {
|
|
period = 996; // G4, 392.00 Hz, maybe
|
|
uart_writen(uart0, "G4\r\n", 4);
|
|
led0->output = 16;
|
|
} else if (c == 'a') {
|
|
period = 887; // A4, 440.00 Hz, maybe
|
|
uart_writen(uart0, "A4\r\n", 4);
|
|
led0->output = 32;
|
|
} else if (c == 'b') {
|
|
period = 791; // B4, 493.88 Hz, maybe
|
|
uart_writen(uart0, "B4\r\n", 4);
|
|
led0->output = 64;
|
|
} else {
|
|
led0->output = 37;
|
|
}
|
|
|
|
square0->period = period;
|
|
}
|
|
}
|