Permalink
Browse files

Fixes the stuck notes when using MIDI input with the serial port.

  • Loading branch information...
1 parent f787178 commit 6f01e781c99de335909418847b8f5452800da942 @dcliche committed Sep 4, 2011
Showing with 41 additions and 23 deletions.
  1. +24 −6 src/common/io.c
  2. +17 −17 src/synth/synth.c
View
@@ -109,28 +109,46 @@ unsigned d16;
printh8(d16);
}
+/* Check if a character from the PS/2 keyboard is available */
+int checkch()
+{
+ /* Check if the keyboard is ready */
+ if (*(KBD) & 0x1)
+ return -1;
+
+ return 0;
+}
+
/* Get a character from the PS/2 keyboard */
unsigned getch()
{
unsigned c;
- /* Check if the keyboard is ready */
- if (!(*(KBD) & 0x1))
- return 0;
+ /* Wait until the keyboard is ready */
+ while (!(*(KBD) & 0x1));
/* Return the key value */
c = *(KBD + 1);
return c & 0xFF;
}
+/* Check if a character from the serial port is available */
+int scheckch()
+{
+ /* Check if the ACIA is ready */
+ if (*(ACIA) & 0x1)
+ return -1;
+
+ return 0;
+}
+
/* Get a character from the serial port */
unsigned sgetch()
{
unsigned c;
- /* Check if the ACIA is ready */
- if (!(*(ACIA) & 0x1))
- return 0;
+ /* Wait until the the ACIA is ready */
+ while (!(*(ACIA) & 0x1));
/* Return the character value */
c = *(ACIA + 1);
View
@@ -165,13 +165,13 @@ char **argv;
moveto(10, 5);
prints("Z, X: Octave +/-");
moveto(10, 6);
- prints("C, V: PhMod Carrier PhD +/- (PhMod only)");
+ prints("C, V: PM Carrier PhD +/- (PM only)");
moveto(10, 7);
- prints("B, N: Signal Gain +/- (PhMod only)");
+ prints("B, N: Message Gain +/- (Sine and PM only)");
moveto(10, 8);
- prints("M, ',': Modulation Gain +/- (PhMod only)");
+ prints("M, ',': Modulation Gain +/- (PM only)");
moveto(10, 9);
- prints("1, 2, 3, 4: Square/Saw/Sine/PhMod");
+ prints("1, 2, 3, 4: Square/Saw/Sine/PM");
moveto(10, 10);
prints("Spacebar: Quiet");
@@ -199,18 +199,18 @@ char **argv;
while (1) {
/* First, we check if we have an incoming MIDI note from the serial port */
- c = sgetch();
- if (c) {
+ if (scheckch()) {
+ c = sgetch();
if (c == 0x90) {
- while (!(c = sgetch()));
+ c = sgetch();
if (psti < PSTACK_SIZE - 1) {
psti++;
pitch = c;
pstack[psti] = pitch;
}
- while (!(c = sgetch()));
+ c = sgetch();
} else if (c == 0x80) {
- while (!(c = sgetch()));
+ c = sgetch();
for (i = 1; i < psti; i++)
if (pstack[i] == c) {
for (; i < psti; i++)
@@ -220,20 +220,20 @@ char **argv;
if (psti > 0)
psti--;
pitch = pstack[psti];
- while (!(c = sgetch()));
+ c = sgetch();
} else if (c == 0xB0) {
- while (!(c = sgetch()));
+ c = sgetch();
if (c == 0x17) {
- while (!(c = sgetch()));
+ c = sgetch();
waveform = c >> 4;
} else if (c == 0x18) {
- while (!(c = sgetch()));
+ c = sgetch();
carrphd = c << 6;
} else if (c == 0x19) {
- while (!(c = sgetch()));
+ c = sgetch();
gainmsg = c >> 1;
} else if (c == 0x1A) {
- while (!(c = sgetch()));
+ c = sgetch();
gainmod = c >> 1;
}
@@ -254,8 +254,8 @@ char **argv;
}
/* We check if we have an incoming key */
- c = getch();
- if (c) {
+ if (checkch()) {
+ c = getch();
newpitch = 1;
switch (c) {
case 'a':

0 comments on commit 6f01e78

Please sign in to comment.