--- eringson.c- Mon Mar 15 09:32:08 1999 +++ eringson.c Fri Dec 17 11:17:30 1999 @@ -16,6 +16,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * + * File modified December 1999 by Jim Rees + * */ #include @@ -656,51 +658,45 @@ } +#define DURATION 120 /* note duration, milliseconds */ +short freqs[] = {466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, + 1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976, + 2093, 2217, 2349, 2489}; +short notePos[] = {1, 2, 4, 6, 7, 9, 11, 13, 14, 16, 18, 19, 21, 23, 25}; static void -PlayMelody() +PlayMelody(char song[], short songLen) { - Err comErr = 0; - Char data[BUFSIZE]; - int yo; + int i, note, ticks; + SndCommandType cmd; - // open the IR port - comErr = ComsOpen(BAUDRATE); - if (comErr != 0) - { - MessageDisplay("Error %x, could not open the serial port.", comErr); - return; - } + ticks = SysTicksPerSecond() * DURATION / 1000; - // no probing needed, just order the phone to play back the current - // melody - data[0] = '\0'; - StrCopy(data, "\rat*erip=6,31\r"); - yo = ATDialog(300, (CharPtr)&data, BUFSIZE); - if (yo!=0) // have we got data? - { - if (StrStr(data, "OK")) // have we got the right data? - { - SerReceiveFlush(comRefNum, 100); - } - else - { - yo=0; // force the if (yo==0) clause below - } - } + cmd.cmd = sndCmdFreqDurationAmp; + cmd.param3 = sndDefaultAmp; - if (yo==0) - { - PRINTF("Hey, the phone doesn't react to AT commands?"); + for (i = 0; i < songLen; i++) { + if ((song[i] & 0xf) == 15) { + /* rest */ + SysTaskDelay((song[i] & 0x40) ? ticks * 2 : ticks); + } else { + /* note */ + note = notePos[song[i] & 0xf]; + if (song[i] & 0x10) + note--; + else if (song[i] & 0x20) + note++; + cmd.param1 = freqs[note]; + cmd.param2 = DURATION; + if (song[i] & 0x40) + cmd.param2 *= 2; + SndDoCmd(NULL, &cmd, 0); + } } - - // clean up - ComsClose(); } - static void PasteBitmap(int winIndex, Short x, Short y, ScrOperation mode) { @@ -1445,8 +1441,9 @@ break; case btnMainPlay: - PlayMelody(); - handled=true; + if (uiMode==MODE_GRAPHIC) + PlayMelody(curSong, curSongLen); + handled=true; break; case btnMainSwitch: --- eringson.rcp- Mon Mar 15 09:00:58 1999 +++ eringson.rcp Fri Dec 17 11:17:28 1999 @@ -1,3 +1,4 @@ +// File modified December 1999 by Jim Rees #include "eringson.h" FORM frmMain 2 2 156 156 @@ -8,8 +9,9 @@ BEGIN TITLE "Eringson v0.4.2" FIELD fldMainContent 5 20 145 116 UNDERLINED MULTIPLELINES MAXCHARS 1024 FONT 0 - BUTTON "Install & Play" ID btnMainInstall AT (4 BOTTOM@152 AUTO AUTO) + BUTTON "Install" ID btnMainInstall AT (4 BOTTOM@152 AUTO AUTO) BUTTON "Fetch" ID btnMainFetch AT (PREVRIGHT+4 PREVTOP AUTO AUTO) + BUTTON "Play" ID btnMainPlay AT (PREVRIGHT+4 PREVTOP AUTO AUTO) BUTTON "Mode" ID btnMainSwitch AT (PREVRIGHT+4 PREVTOP AUTO AUTO) GADGET ID gdgMainGraphic AT (5 16 145 88) USABLE LABEL "" ID lblMainStatus AT (PREVRIGHT+4 PREVTOP) @@ -17,8 +19,6 @@ BUTTON "\002" ID btnMainL AT (5 104 AUTO AUTO) FONT 4 BUTTON "\003" ID btnMainR AT (RIGHT@152 PREVTOP AUTO AUTO) FONT 4 END - -// BUTTON "Play" ID btnMainPlay AT (PREVRIGHT+4 PREVTOP AUTO AUTO) MENU mnuMainMenu